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,40 +11,65 @@
|
||||
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\Rank;
|
||||
use IPS\core\Achievements\Rule;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
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\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use IPS\Xml\SimpleXML;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function intval;
|
||||
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 ranks
|
||||
*/
|
||||
class _ranks extends \IPS\Node\Controller
|
||||
class ranks extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Cached counts
|
||||
*/
|
||||
public static $counts = [];
|
||||
public static array $counts = [];
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\core\Achievements\Rank';
|
||||
protected string $nodeClass = 'IPS\core\Achievements\Rank';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'ranks_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'ranks_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -53,51 +78,48 @@ class _ranks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* If the members table is very large, this can take the whole thing down,
|
||||
so let's skip it. */
|
||||
if( !\IPS\Db::i()->recommendManualQuery( 'core_members' ) )
|
||||
static::$counts = [];
|
||||
$previousCount = NULL;
|
||||
|
||||
$allRanks = array_values( Rank::getStore() );
|
||||
$totalRanks = count( $allRanks );
|
||||
for ( $i = 0; $i < $totalRanks; $i++ )
|
||||
{
|
||||
static::$counts = [];
|
||||
$previousCount = NULL;
|
||||
|
||||
$allRanks = array_values( \IPS\core\Achievements\Rank::getStore() );
|
||||
$totalRanks = \count( $allRanks );
|
||||
for ( $i = 0; $i < $totalRanks; $i++ )
|
||||
$where = [];
|
||||
$where[] = [ 'achievements_points>=' . intval( $allRanks[ $i ]->points ) ];
|
||||
if ( isset( $allRanks[ $i + 1 ] ) )
|
||||
{
|
||||
$where = [];
|
||||
$where[] = [ 'achievements_points>=' . \intval( $allRanks[ $i ]->points ) ];
|
||||
if ( isset( $allRanks[ $i + 1 ] ) )
|
||||
{
|
||||
$where[] = [ 'achievements_points<' . \intval( $allRanks[ $i + 1 ]->points ) ];
|
||||
}
|
||||
static::$counts[ $allRanks[ $i ]->id ] = \IPS\Db::i()->select( 'COUNT(*)', 'core_members', $where )->first();
|
||||
$where[] = [ 'achievements_points<' . intval( $allRanks[ $i + 1 ]->points ) ];
|
||||
}
|
||||
static::$counts[ $allRanks[ $i ]->id ] = Db::i()->select( 'COUNT(*)', 'core_members', $where )->first();
|
||||
}
|
||||
|
||||
if( $data = \IPS\core\Achievements\Rule::getRebuildProgress() )
|
||||
if( $data = Rule::getRebuildProgress() )
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'achievements' )->rebuildProgress( $data, TRUE );
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'achievements' )->rebuildProgress( $data, TRUE );
|
||||
}
|
||||
|
||||
\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=ranks&do=export'),
|
||||
'link' => Url::internal('app=core&module=achievements&controller=ranks&do=export'),
|
||||
'data' => [],
|
||||
'title' => 'acp_achievements_export',
|
||||
);
|
||||
|
||||
\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=ranks&do=importForm'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('acp_achievements_import') ),
|
||||
'link' => Url::internal('app=core&module=achievements&controller=ranks&do=importForm'),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('acp_achievements_import') ),
|
||||
'title' => 'acp_achievements_import',
|
||||
);
|
||||
|
||||
return parent::manage();
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'cheev_ranks_blurb' );
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,11 +127,11 @@ class _ranks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function importForm()
|
||||
public function importForm() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'acp_achievements_import' );
|
||||
$form = new Form( 'form', 'acp_achievements_import' );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'acp_achievements_import_option', 'replace', FALSE, [ 'options' =>
|
||||
$form->add( new Radio( 'acp_achievements_import_option', 'replace', FALSE, [ 'options' =>
|
||||
[
|
||||
'wipe' => 'acp_achievements_import_option_wipe',
|
||||
'replace' => 'acp_achievements_import_option_replace'
|
||||
@@ -117,28 +139,28 @@ class _ranks extends \IPS\Node\Controller
|
||||
'toggles' => [ 'wipe' => [ 'acp_achievements_import_option_wipe_sure' ] ]
|
||||
] ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'acp_achievements_import_option_wipe_sure', 0, FALSE, [], NULL, NULL, NULL, 'acp_achievements_import_option_wipe_sure' ) );
|
||||
$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->add( new YesNo( 'acp_achievements_import_option_wipe_sure', 0, FALSE, [], NULL, NULL, NULL, 'acp_achievements_import_option_wipe_sure' ) );
|
||||
$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() )
|
||||
{
|
||||
if ( $values['acp_achievements_import_option'] == 'wipe' and empty( $values['acp_achievements_import_option_wipe_sure'] ) )
|
||||
{
|
||||
$form->error = \IPS\Member::loggedIn()->language()->addToStack( 'acp_achievements_import_error' );
|
||||
$form->error = Member::loggedIn()->language()->addToStack( 'acp_achievements_import_error' );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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=ranks&do=import' )->setQueryString( array('option' => $values['acp_achievements_import_option'], 'file' => $tempFile, 'key' => md5_file( $tempFile )) )->csrf() );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=achievements&controller=ranks&do=import' )->setQueryString( array('option' => $values['acp_achievements_import_option'], '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 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,47 +168,47 @@ class _ranks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function import()
|
||||
public function import() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
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\Rank::importXml( \IPS\Request::i()->file, \IPS\Request::i()->option );
|
||||
Rank::importXml( Request::i()->file, Request::i()->option );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '2C423/1', 403, '' );
|
||||
Output::i()->error( $e->getMessage(), '2C423/1', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__imported_ranks' );
|
||||
Session::i()->log( 'acplogs__imported_ranks' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=achievements&controller=ranks' ), 'completed' );
|
||||
Output::i()->redirect( Url::internal( 'app=core&module=achievements&controller=ranks' ), 'completed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Export ranks with images 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('ranks');
|
||||
$xml = SimpleXML::create('ranks');
|
||||
$langs = [];
|
||||
|
||||
foreach( \IPS\Db::i()->select('word_key, word_default', 'core_sys_lang_words', [ "lang_id=? AND word_key LIKE 'core_member_rank_%'", \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_member_rank_%'", Member::loggedIn()->language()->id ] ) as $row )
|
||||
{
|
||||
$langs[ \mb_substr( $row['word_key'], 17 ) ] = $row['word_default'];
|
||||
$langs[ mb_substr( $row['word_key'], 17 ) ] = $row['word_default'];
|
||||
}
|
||||
|
||||
/* Ranks */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_member_ranks') as $row )
|
||||
foreach ( Db::i()->select( '*', 'core_member_ranks') as $row )
|
||||
{
|
||||
$forXml = [
|
||||
'title' => $langs[$row['id']] ?? NULL,
|
||||
@@ -197,19 +219,19 @@ class _ranks extends \IPS\Node\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
$icon = \IPS\File::get( 'core_Ranks', $row['icon'] );
|
||||
$icon = File::get( 'core_Ranks', $row['icon'] );
|
||||
$forXml['icon_name'] = $icon->originalFilename;
|
||||
$forXml['icon_data'] = base64_encode( $icon->contents() );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
$xml->addChild( 'rank', $forXml );
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__exported_ranks' );
|
||||
Session::i()->log( 'acplogs__exported_ranks' );
|
||||
|
||||
\IPS\Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', "Achievement_Ranks.xml" ) ) );
|
||||
Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => Output::getContentDisposition( 'attachment', "Achievement_Ranks.xml" ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,16 +240,10 @@ class _ranks extends \IPS\Node\Controller
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
public function _getRowHtml( object $node ): ?string
|
||||
{
|
||||
/* If the counts are empty, then the table was too large, so ignore this. */
|
||||
if( empty( static::$counts ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::internal("app=core&module=members&controller=members&advanced_search_submitted=1&members_achievements_points={$node->id}")->csrf();
|
||||
$url = Url::internal("app=core&module=members&controller=members&advanced_search_submitted=1&members_achievements_points={$node->id}")->csrf();
|
||||
|
||||
return \IPS\Theme::i()->getTemplate('achievements')->memberCount( $url, static::$counts[ $node->id ] );
|
||||
return Theme::i()->getTemplate('achievements')->memberCount( $url, static::$counts[ $node->id ] );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user