Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,37 +11,60 @@
|
||||
namespace IPS\core\modules\admin\achievements;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\Achievements\Rule;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use IPS\Xml\SimpleXML;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function mb_substr;
|
||||
use const IPS\TEMP_DIRECTORY;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Achievement rules
|
||||
*/
|
||||
class _rules extends \IPS\Node\Controller
|
||||
class rules extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\core\Achievements\Rule';
|
||||
protected string $nodeClass = 'IPS\core\Achievements\Rule';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_manage' );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'achievements/achievements.css', 'core', 'admin' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_members.js', 'core' ) );
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_manage' );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'achievements/achievements.css', 'core', 'admin' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_members.js', 'core' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -50,79 +73,79 @@ class _rules extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
$baseUrl = \IPS\Http\Url::internal('app=core&module=achievements&controller=rules');
|
||||
$baseUrl = Url::internal('app=core&module=achievements&controller=rules');
|
||||
$perPage = 25;
|
||||
$totalCount = \IPS\Db::i()->select( 'COUNT(*)', 'core_achievements_rules' )->first();
|
||||
$totalCount = Db::i()->select( 'COUNT(*)', 'core_achievements_rules' )->first();
|
||||
$totalPages = ceil( $totalCount / $perPage );
|
||||
$page = \IPS\Request::i()->page ?? 1;
|
||||
$page = Request::i()->page ?? 1;
|
||||
|
||||
$query = \IPS\Db::i()->select( '*', 'core_achievements_rules', NULL, 'action, milestone ASC', [ ( $perPage * ( $page - 1 ) ), $perPage ] );
|
||||
$rules = new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\core\Achievements\Rule' );
|
||||
$pagination = $totalPages > 1 ? \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, $totalPages, $page, $perPage ) : '';
|
||||
$query = Db::i()->select( '*', 'core_achievements_rules', NULL, 'action, milestone ASC', [ ( $perPage * ( $page - 1 ) ), $perPage ] );
|
||||
$rules = new ActiveRecordIterator( $query, 'IPS\core\Achievements\Rule' );
|
||||
$pagination = $totalPages > 1 ? Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, $totalPages, $page, $perPage ) : '';
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->json([
|
||||
'rows' => \IPS\Theme::i()->getTemplate( 'achievements' )->rulesListRows( $rules ),
|
||||
Output::i()->json([
|
||||
'rows' => Theme::i()->getTemplate( 'achievements' )->rulesListRows( $rules ),
|
||||
'pagination' => $pagination
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['export'] = array(
|
||||
Output::i()->sidebar['actions']['export'] = array(
|
||||
'primary' => false,
|
||||
'icon' => 'cloud-download',
|
||||
'link' => \IPS\Http\Url::internal('app=core&module=achievements&controller=rules&do=export'),
|
||||
'link' => Url::internal('app=core&module=achievements&controller=rules&do=export'),
|
||||
'data' => [],
|
||||
'title' => 'acp_achievements_export',
|
||||
);
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'achievements', 'rules_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'achievements', 'rules_add' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['import'] = array(
|
||||
Output::i()->sidebar['actions']['import'] = array(
|
||||
'primary' => false,
|
||||
'icon' => 'cloud-upload',
|
||||
'link' => \IPS\Http\Url::internal('app=core&module=achievements&controller=rules&do=importForm'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('acp_achievements_import') ),
|
||||
'link' => Url::internal('app=core&module=achievements&controller=rules&do=importForm'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('acp_achievements_import') ),
|
||||
'title' => 'acp_achievements_import',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'achievements' )->rulesList( $rules, $pagination, $this->_getRootButtons() );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'cheev_rules_blurb' ) . Theme::i()->getTemplate( 'achievements' )->rulesList( $rules, $pagination, $this->_getRootButtons() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form as returned by _addEditForm()
|
||||
* @param Form $form The form as returned by _addEditForm()
|
||||
* @return string
|
||||
*/
|
||||
protected function _showForm( \IPS\Helpers\Form $form )
|
||||
protected function _showForm( Form $form ): string
|
||||
{
|
||||
\IPS\Output::i()->hiddenElements = array('acpHeader');
|
||||
Output::i()->hiddenElements = array('acpHeader');
|
||||
|
||||
if ( \IPS\Request::i()->id )
|
||||
if ( Request::i()->id )
|
||||
{
|
||||
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_edit' );
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_edit' );
|
||||
try
|
||||
{
|
||||
$form->hiddenValues['rule_enabled'] = \IPS\core\Achievements\Rule::load( \IPS\Request::i()->id )->enabled;
|
||||
$form->hiddenValues['rule_enabled'] = Rule::load( Request::i()->id )->enabled;
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_achievements_rules');
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_achievements_rules');
|
||||
|
||||
return $form->customTemplate( [ \IPS\Theme::i()->getTemplate( 'achievements' ), 'rulesForm' ] );
|
||||
return $form->customTemplate( [ Theme::i()->getTemplate( 'achievements' ), 'rulesForm' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,32 +153,32 @@ class _rules extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function toggleEnabled()
|
||||
protected function toggleEnabled() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_edit' );
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_edit' );
|
||||
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$rule = \IPS\core\Achievements\Rule::load( \IPS\Request::i()->id );
|
||||
$rule->enabled = (int) \IPS\Request::i()->enable;
|
||||
$rule = Rule::load( Request::i()->id );
|
||||
$rule->enabled = (int) Request::i()->enable;
|
||||
$rule->save();
|
||||
|
||||
if ( \IPS\Request::i()->enable )
|
||||
if ( Request::i()->enable )
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__rule_enabled', array( $rule->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__rule_enabled', array( $rule->id => FALSE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Session::i()->log( 'acplogs__rule_disabled', array( $rule->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__rule_disabled', array( $rule->id => FALSE ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=achievements&controller=rules' ), 'updated' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=achievements&controller=rules' ), 'updated' );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2T353/3', 404, '' ); /* @todo error code */
|
||||
Output::i()->error( 'node_error', '2T353/3', 404, '' ); /* @todo error code */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,21 +186,21 @@ class _rules extends \IPS\Node\Controller
|
||||
* Export rules with badges as an XML file (XML is better at potentially large values from raw image data)
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function export()
|
||||
public function export() : void
|
||||
{
|
||||
$xml = \IPS\Xml\SimpleXML::create('rules');
|
||||
$xml = SimpleXML::create('rules');
|
||||
$badgeMap = [];
|
||||
|
||||
$langs = [];
|
||||
foreach( \IPS\Db::i()->select( 'word_key, word_default', 'core_sys_lang_words', [ 'lang_id=? AND (word_key LIKE \'core_award_subject_badge_%\' OR word_key LIKE \'core_award_other_badge_%\')', \IPS\Member::loggedIn()->language()->id ] ) as $row )
|
||||
foreach( Db::i()->select( 'word_key, word_default', 'core_sys_lang_words', [ 'lang_id=? AND (word_key LIKE \'core_award_subject_badge_%\' OR word_key LIKE \'core_award_other_badge_%\')', Member::loggedIn()->language()->id ] ) as $row )
|
||||
{
|
||||
$langs[ $row['word_key'] ] = $row['word_default'];
|
||||
}
|
||||
|
||||
/* Rules */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_achievements_rules') as $row )
|
||||
foreach ( Db::i()->select( '*', 'core_achievements_rules') as $row )
|
||||
{
|
||||
$forXml = [];
|
||||
foreach( $row as $k => $v )
|
||||
@@ -214,19 +237,19 @@ class _rules extends \IPS\Node\Controller
|
||||
}
|
||||
|
||||
/* Badges */
|
||||
if ( \count( $badgeMap ) )
|
||||
if ( count( $badgeMap ) )
|
||||
{
|
||||
$langs = [];
|
||||
foreach( \IPS\Db::i()->select('word_key, word_default', 'core_sys_lang_words', [ \IPS\Db::i()->like( 'word_key', 'core_badges_') ] ) as $row )
|
||||
foreach( Db::i()->select('word_key, word_default', 'core_sys_lang_words', [ Db::i()->like( 'word_key', 'core_badges_') ] ) as $row )
|
||||
{
|
||||
$langs[ \mb_substr( $row['word_key'], 12 ) ] = $row['word_default'];
|
||||
$langs[ mb_substr( $row['word_key'], 12 ) ] = $row['word_default'];
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select('*', 'core_badges', [ \IPS\Db::i()->in( '`id`', array_keys( $badgeMap ) ) ] ) as $badge )
|
||||
foreach( Db::i()->select('*', 'core_badges', [ Db::i()->in( '`id`', array_keys( $badgeMap ) ) ] ) as $badge )
|
||||
{
|
||||
try
|
||||
{
|
||||
$icon = \IPS\File::get( 'core_Badges', $badge['image'] );
|
||||
$icon = File::get( 'core_Badges', $badge['image'] );
|
||||
|
||||
$xml->addChild( 'badge', [
|
||||
'manually_awarded' => $badge['manually_awarded'],
|
||||
@@ -236,13 +259,13 @@ class _rules extends \IPS\Node\Controller
|
||||
'icon_data' => base64_encode( $icon->contents() )
|
||||
] );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__rules_exported' );
|
||||
Session::i()->log( 'acplogs__rules_exported' );
|
||||
|
||||
\IPS\Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', "Achievement_Rules.xml" ) ) );
|
||||
Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => Output::getContentDisposition( 'attachment', "Achievement_Rules.xml" ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,27 +273,27 @@ class _rules extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function importForm()
|
||||
public function importForm() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
$form = new \IPS\Helpers\Form( 'form', 'acp_achievements_import' );
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
$form = new Form( 'form', 'acp_achievements_import' );
|
||||
|
||||
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'acp_achievements_import_rules_message'), 'ipsMessage ipsMessage_info');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'acp_achievements_import_option_rule_wipe', 0, FALSE, [], NULL, NULL, NULL, 'acp_achievements_import_option_rule_wipe' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'acp_achievements_import_xml', NULL, FALSE, [ 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ], NULL, NULL, NULL, 'acp_achievements_import_xml' ) );
|
||||
$form->addMessage( Member::loggedIn()->language()->addToStack( 'acp_achievements_import_rules_message'), 'ipsMessage ipsMessage--info');
|
||||
$form->add( new YesNo( 'acp_achievements_import_option_rule_wipe', 0, FALSE, [], NULL, NULL, NULL, 'acp_achievements_import_option_rule_wipe' ) );
|
||||
$form->add( new Upload( 'acp_achievements_import_xml', NULL, FALSE, [ 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ], NULL, NULL, NULL, 'acp_achievements_import_xml' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* Move it to a temporary location */
|
||||
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
|
||||
$tempFile = tempnam( TEMP_DIRECTORY, 'IPS' );
|
||||
move_uploaded_file( $values['acp_achievements_import_xml'], $tempFile );
|
||||
|
||||
/* Initate a redirector */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=achievements&controller=rules&do=import' )->setQueryString( array('wipe' => $values['acp_achievements_import_option_rule_wipe'], 'file' => $tempFile, 'key' => md5_file( $tempFile )) )->csrf() );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=achievements&controller=rules&do=import' )->setQueryString( array('wipe' => $values['acp_achievements_import_option_rule_wipe'], 'file' => $tempFile, 'key' => md5_file( $tempFile )) )->csrf() );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Member::loggedIn()->language()->addToStack('acp_achievements_import'), $form, FALSE );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global' )->block( Member::loggedIn()->language()->addToStack('acp_achievements_import'), $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,27 +301,27 @@ class _rules extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function import()
|
||||
public function import() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'rules_add' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
if ( !file_exists( \IPS\Request::i()->file ) or md5_file( \IPS\Request::i()->file ) !== \IPS\Request::i()->key )
|
||||
if ( !file_exists( Request::i()->file ) or md5_file( Request::i()->file ) !== Request::i()->key )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '3C130/1', 500, '' );
|
||||
Output::i()->error( 'generic_error', '3C130/1', 500, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\core\Achievements\Rule::importXml( \IPS\Request::i()->file, ( ! empty( \IPS\Request::i()->wipe ) ) );
|
||||
Rule::importXml( Request::i()->file, ( ! empty( Request::i()->wipe ) ) );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '2C424/1', 403, '' );
|
||||
Output::i()->error( $e->getMessage(), '2C424/1', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__rules_imported' );
|
||||
Session::i()->log( 'acplogs__rules_imported' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=achievements&controller=rules' ), 'completed' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=achievements&controller=rules' ), 'completed' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user