Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+97 -97
View File
@@ -11,30 +11,50 @@
namespace IPS\core\modules\admin\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use IPS\DateTime;
use IPS\Db;
use IPS\Db\Select;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Chart;
use IPS\Helpers\Chart\Callback;
use IPS\Helpers\Chart\Database;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Club;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use function defined;
use function in_array;
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;
}
/**
* Statistics
*/
class _stats extends \IPS\Dispatcher\Controller
class stats extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'stats_manage' );
Dispatcher::i()->checkAcpPermission( 'stats_manage' );
parent::execute();
}
@@ -43,40 +63,40 @@ class _stats extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* If clubs are not enabled, stop now */
if ( !\IPS\Settings::i()->clubs )
if ( !Settings::i()->clubs )
{
$availableTypes = array();
foreach ( \IPS\Member\Club::availableNodeTypes( NULL ) as $class )
foreach ( Club::availableNodeTypes() as $class )
{
$availableTypes[] = \IPS\Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
$availableTypes[] = Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
}
$availableTypes = \IPS\Member::loggedIn()->language()->formatList( $availableTypes );
$availableTypes = Member::loggedIn()->language()->formatList( $availableTypes );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
Output::i()->output = Theme::i()->getTemplate( 'clubs' )->disabled( $availableTypes );
return;
}
/* Generate the tabs */
$tabs = array( 'overview' => 'overview', 'total' => 'stats_club_activity', 'byclub' => 'stats_club_club_activity' );
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'overview';
$activeTab = ( isset( Request::i()->tab ) and array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'overview';
/* Get the HTML to output */
$method = '_' . $activeTab;
$output = $this->$method();
/* And then print it */
if ( \IPS\Request::i()->isAjax() )
if ( Request::i()->isAjax() )
{
\IPS\Output::i()->output = (string) $output;
Output::i()->output = (string) $output;
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_clubs_stats');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, \IPS\Http\Url::internal( "app=core&module=clubs&controller=stats" ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_clubs_stats');
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, Url::internal( "app=core&module=clubs&controller=stats" ) );
}
}
@@ -85,23 +105,23 @@ class _stats extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _overview()
protected function _overview() : string
{
$clubTypePieChart = $this->_getClubTypePieChart();
$clubSignups = $this->_getClubSignups();
$clubCreations = $this->_getClubCreations();
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->statsOverview( $clubTypePieChart, $clubSignups, $clubCreations );
return Theme::i()->getTemplate( 'clubs', 'core' )->statsOverview( $clubTypePieChart, $clubSignups, $clubCreations );
}
/**
* Get line chart showing club signups
*
* @return \IPS\Helpers\Chart
* @return Chart
*/
protected function _getClubSignups()
protected function _getClubSignups() : Chart
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&fetch=signups' ), 'core_clubs_memberships', 'joined', '', array(
$chart = new Database( Url::internal( 'app=core&module=clubs&controller=stats&fetch=signups' ), 'core_clubs_memberships', 'joined', '', array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
@@ -112,17 +132,17 @@ class _stats extends \IPS\Dispatcher\Controller
$chart->joins[] = array( 'core_clubs', 'core_clubs.id=core_clubs_memberships.club_id' );
$chart->groupBy = 'club_id';
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
{
$chart->addSeries( $club->name, 'number', 'COUNT(*)', TRUE, $club->id );
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_signups');
$chart->title = Member::loggedIn()->language()->addToStack('stats_clubs_signups');
$chart->availableTypes = array( 'ColumnChart', 'BarChart' );
if( \IPS\Request::i()->fetch == 'signups' AND \IPS\Request::i()->isAjax() )
if( Request::i()->fetch == 'signups' AND Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
Output::i()->sendOutput( (string) $chart );
}
return $chart;
@@ -131,11 +151,11 @@ class _stats extends \IPS\Dispatcher\Controller
/**
* Get line chart showing club creations
*
* @return \IPS\Helpers\Chart
* @return Chart
*/
protected function _getClubCreations()
protected function _getClubCreations() : Chart
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&fetch=clubs' ), 'core_clubs', 'created', '', array(
$chart = new Database( Url::internal( 'app=core&module=clubs&controller=stats&fetch=clubs' ), 'core_clubs', 'created', '', array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e' ),
@@ -143,13 +163,13 @@ class _stats extends \IPS\Dispatcher\Controller
'lineWidth' => 1,
'areaOpacity' => 0.4
), 'ColumnChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array(), 'signups' );
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_creations'), 'number', 'COUNT(*)', FALSE );
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_creations');
$chart->addSeries( Member::loggedIn()->language()->addToStack('stats_clubs_creations'), 'number', 'COUNT(*)', FALSE );
$chart->title = Member::loggedIn()->language()->addToStack('stats_clubs_creations');
$chart->availableTypes = array( 'ColumnChart', 'BarChart' );
if( \IPS\Request::i()->fetch == 'clubs' AND \IPS\Request::i()->isAjax() )
if( Request::i()->fetch == 'clubs' AND Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
Output::i()->sendOutput( (string) $chart );
}
return $chart;
@@ -158,15 +178,15 @@ class _stats extends \IPS\Dispatcher\Controller
/**
* Get pie chart showing club types
*
* @return \IPS\Helpers\Chart
* @return string
*/
protected function _getClubTypePieChart()
protected function _getClubTypePieChart() : string
{
$percentages = array();
$counts = array();
$total = 0;
foreach( \IPS\Db::i()->select( 'type, COUNT(*) as total', 'core_clubs', array(), NULL, NULL, array( 'type' ) ) as $clubs )
foreach( Db::i()->select( 'type, COUNT(*) as total', 'core_clubs', array(), NULL, NULL, array( 'type' ) ) as $clubs )
{
$counts[ $clubs['type'] ] = $clubs['total'];
$total += $clubs['total'];
@@ -177,18 +197,18 @@ class _stats extends \IPS\Dispatcher\Controller
$percentages[ $type ] = number_format( round( 100 / $total * $typeTotal, 2 ), 2 );
}
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubTypesBar( $percentages, $counts );
return Theme::i()->getTemplate( 'clubs', 'core' )->clubTypesBar( $percentages, $counts );
}
/**
* Total club activity
*
* @return \IPS\Helpers\Chart\Dynamic
* @return Callback
*/
protected function _total()
protected function _total() : Chart
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=total' ),
$chart = new Callback(
Url::internal( 'app=core&module=clubs&controller=stats&tab=total' ),
array( $this, 'getResults' ),
'',
array(
@@ -200,17 +220,17 @@ class _stats extends \IPS\Dispatcher\Controller
),
'ColumnChart',
'monthly',
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
array( 'start' => ( new DateTime )->sub( new DateInterval('P6M') ), 'end' => DateTime::create() ),
'total'
);
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
foreach( Club::availableNodeTypes() as $nodeType )
{
$contentClass = $nodeType::$contentItemClass;
$chart->addSeries( \IPS\Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ), 'number', TRUE );
$chart->addSeries( Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ), 'number');
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_club_activity' );
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_club_activity' );
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
return $chart;
@@ -221,10 +241,10 @@ class _stats extends \IPS\Dispatcher\Controller
*
* @return string
*/
protected function _byclub()
protected function _byclub() : string
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=byclub' ),
$chart = new Callback(
Url::internal( 'app=core&module=clubs&controller=stats&tab=byclub' ),
array( $this, 'getResults' ),
'',
array(
@@ -236,16 +256,16 @@ class _stats extends \IPS\Dispatcher\Controller
),
'ColumnChart',
'monthly',
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
array( 'start' => ( new DateTime )->sub( new DateInterval('P6M') ), 'end' => DateTime::create() ),
'byclub'
);
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
{
$chart->addSeries( $club->name, 'number', TRUE );
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_club_club_activity' );
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_club_club_activity' );
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
return $chart;
@@ -254,13 +274,13 @@ class _stats extends \IPS\Dispatcher\Controller
/**
* Fetch the results
*
* @param \IPS\Helpers\Chart\Callback $chart Chart object
* @param Callback $chart Chart object
* @return array
*/
public function getResults( $chart )
public function getResults( Callback $chart ) : array
{
/* Get the info we need */
$nodeTypes = \IPS\Member\Club::availableNodeTypes( NULL );
$nodeTypes = Club::availableNodeTypes();
$clubNodes = array();
$classes = array();
$classMap = array();
@@ -292,7 +312,7 @@ class _stats extends \IPS\Dispatcher\Controller
{
$clubNodeMap = array();
foreach( \IPS\Db::i()->select( '*', 'core_clubs_node_map' ) as $nodeMap )
foreach( Db::i()->select( '*', 'core_clubs_node_map' ) as $nodeMap )
{
$nodeClass = $nodeMap['node_class'];
$nodeClass = $nodeClass::$contentItemClass;
@@ -322,21 +342,15 @@ class _stats extends \IPS\Dispatcher\Controller
$where = array();
$join = NULL;
/* Get our container IDs */
$containerIds = array();
foreach( $clubNodes[ $classMap[ $class ] ] as $node )
{
$containerIds[] = $node->id;
}
if( is_subclass_of( $class, '\IPS\Content\Comment' ) )
{
/* We're going to need a subquery... */
$parentClass = $class::$itemClass;
/* @var array $databaseColumnMap */
$where[] = array(
$class::$databasePrefix . $class::$databaseColumnMap['item'] . " IN(" .
(string) \IPS\Db::i()->select( $parentClass::$databasePrefix . $parentClass::$databaseColumnId, $parentClass::$databaseTable, array( \IPS\Db::i()->in( $parentClass::$databasePrefix . $parentClass::$databaseColumnMap['container'], $containerIds ) ) )
Db::i()->select( $parentClass::$databasePrefix . $parentClass::$databaseColumnId, $parentClass::$databaseTable, array( Db::i()->in( $parentClass::$databasePrefix . $parentClass::$databaseColumnMap['container'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) ) )
. ")"
);
@@ -354,7 +368,8 @@ class _stats extends \IPS\Dispatcher\Controller
}
else
{
$where[] = array( \IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], $containerIds ) );
/* @var array $databaseColumnMap */
$where[] = array( Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) );
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
@@ -364,11 +379,11 @@ class _stats extends \IPS\Dispatcher\Controller
$stmt = $this->getSqlResults(
$class::$databaseTable,
$class::$databasePrefix . ( isset( $class::$databaseColumnMap['updated'] ) ? $class::$databaseColumnMap['updated'] : $class::$databaseColumnMap['date'] ),
$class::$databasePrefix . ( $class::$databaseColumnMap['updated'] ?? $class::$databaseColumnMap['date'] ),
$class::$databasePrefix . $class::$databaseColumnMap['author'],
$chart,
$where,
$groupByContainer,
( $groupByContainer ?? false ),
$join
);
@@ -382,25 +397,19 @@ class _stats extends \IPS\Dispatcher\Controller
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
foreach( Club::clubs( NULL, NULL, 'name' ) as $club )
{
$results[ $row['time'] ][ $club->name ] = 0;
}
}
else
{
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
foreach( Club::availableNodeTypes() as $nodeType )
{
$contentClass = $nodeType::$contentItemClass;
$languageKey = \IPS\Member::loggedIn()->language()->words[ $contentClass::$title . '_pl'];
/* Pages Databases may need the language string parsing */
if( mb_substr( $contentClass, 0, 15 ) === 'IPS\cms\Records' )
{
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $languageKey );
}
$results[ $row['time'] ][ $languageKey ] = 0;
$key = Member::loggedIn()->language()->get( $contentClass::$title . '_pl' );
Member::loggedIn()->language()->parseOutputForDisplay( $key );
$results[ $row['time'] ][ $key ] = 0;
}
}
}
@@ -409,24 +418,14 @@ class _stats extends \IPS\Dispatcher\Controller
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
try
{
$results[ $row['time'] ][ \IPS\Member\Club::load( $clubNodeMap[ $class::$databaseTable . '-' . $row['container'] ] )->name ] += $row['total'];
}
catch( \OutOfRangeException $e ){}
$results[ $row['time'] ][ Club::load( $clubNodeMap[ $class::$databaseTable . '-' . $row['container'] ] )->name ] += $row['total'];
}
else
{
$languageKey = \IPS\Member::loggedIn()->language()->words[ $contentClass::$title . '_pl'];
/* Pages Databases may need the language string parsing */
if( mb_substr( $contentClass, 0, 15 ) === 'IPS\cms\Records' )
{
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $languageKey );
}
$contentClass = $classMap[ $class ]::$contentItemClass;
$results[ $row['time'] ][ $languageKey ] += $row['total'];
$key = Member::loggedIn()->language()->get( $contentClass::$title . '_pl' );
Member::loggedIn()->language()->parseOutputForDisplay( $key );
$results[ $row['time'] ][ $key ] += $row['total'];
}
}
}
@@ -445,9 +444,9 @@ class _stats extends \IPS\Dispatcher\Controller
* @param array $where Where clause
* @param bool|string $groupByContainer If a string is provided, it must be a column name to group by in addition to time
* @param NULL|array $join Join data, if needed (only used when $groupByContainer is set)
* @return array
* @return Select
*/
protected function getSqlResults( $table, $date, $author, $chart, $where = array(), $groupByContainer = FALSE, $join = NULL )
protected function getSqlResults( string $table, string $date, string $author, object $chart, array $where = array(), bool|string $groupByContainer = FALSE, ?array $join = NULL ) : Select
{
/* What's our SQL time? */
switch ( $chart->timescale )
@@ -461,6 +460,7 @@ class _stats extends \IPS\Dispatcher\Controller
break;
case 'monthly':
default:
$timescale = '%Y-%c';
break;
}
@@ -478,14 +478,14 @@ class _stats extends \IPS\Dispatcher\Controller
/* First we need to get search index activity */
$fromUnixTime = "FROM_UNIXTIME( IFNULL( {$date}, 0 ) )";
if ( !$chart->timezoneError and \IPS\Member::loggedIn()->timezone and \in_array( \IPS\Member::loggedIn()->timezone, \IPS\DateTime::getTimezoneIdentifiers() ) )
if ( !$chart->timezoneError and Member::loggedIn()->timezone and in_array( Member::loggedIn()->timezone, DateTime::getTimezoneIdentifiers() ) )
{
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . \IPS\Db::i()->escape_string( \IPS\Member::loggedIn()->timezone ) . "' )";
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . Db::i()->escape_string( Member::loggedIn()->timezone ) . "' )";
}
if( $groupByContainer !== FALSE )
{
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total, {$groupByContainer} as container", $table, $where, 'time ASC', NULL, array( 'time', 'container' ) );
$stmt = Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total, {$groupByContainer} as container", $table, $where, 'time ASC', NULL, array( 'time', 'container' ) );
if( $join !== NULL )
{
@@ -494,7 +494,7 @@ class _stats extends \IPS\Dispatcher\Controller
}
else
{
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total", $table, $where, 'time ASC', NULL, array( 'time' ) );
$stmt = Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total", $table, $where, 'time ASC', NULL, array( 'time' ) );
}
return $stmt;