Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+21 -14
View File
@@ -11,7 +11,7 @@
namespace IPS\core\modules\admin\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -22,6 +22,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _clubs extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -119,7 +124,7 @@ class _clubs extends \IPS\Dispatcher\Controller
$return['approve'] = array(
'title' => 'approve',
'icon' => 'check',
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=approve&id={$row['id']}")
'link' => \IPS\Http\Url::internal("app=core&module=clubs&controller=clubs&do=approve&id={$row['id']}")->csrf()
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'clubs', 'clubs_delete' ) )
@@ -183,11 +188,10 @@ class _clubs extends \IPS\Dispatcher\Controller
protected function enable()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_settings_manage' );
\IPS\Session::i()->csrfCheck();
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => TRUE ), array( 'conf_key=?', 'clubs' ) );
\IPS\Settings::i()->clubs = TRUE;
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->changeValues( array( 'clubs' => true ) );
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'clubrebuild' ) );
\IPS\Session::i()->log( 'acplog__club_settings' );
@@ -198,6 +202,7 @@ class _clubs extends \IPS\Dispatcher\Controller
/**
* Edit
*
* @csrfChecked Uses node form() 7 Oct 2019
* @return void
*/
protected function edit()
@@ -284,6 +289,7 @@ class _clubs extends \IPS\Dispatcher\Controller
protected function approve()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'clubs_edit' );
\IPS\Session::i()->csrfCheck();
/* Load Club */
try
@@ -329,7 +335,7 @@ class _clubs extends \IPS\Dispatcher\Controller
/* Ask what to do with each node */
$nodes = $club->nodes();
if ( count( $nodes ) )
if ( \count( $nodes ) )
{
$form = new \IPS\Helpers\Form( 'form', 'delete' );
$form->addMessage( 'club_delete_blurb' );
@@ -368,15 +374,16 @@ class _clubs extends \IPS\Dispatcher\Controller
}
foreach ( $nodesToQueue as $_node )
{
{
$_values = array();
if ( $v )
{
\IPS\Task::queue( 'core', 'DeleteOrMoveContent', array( 'class' => $nodeClass, 'id' => $_node->_id, 'moveToClass' => $nodeClass, 'moveTo' => $v->_id, 'deleteWhenDone' => TRUE, 'additional' => array() ) );
}
else
{
\IPS\Task::queue( 'core', 'DeleteOrMoveContent', array( 'class' => $nodeClass, 'id' => $_node->_id, 'deleteWhenDone' => TRUE, 'additional' => array() ) );
$_values['node_move_children'] = $v;
$_values['node_move_content'] = $v;
}
$_node->deleteOrMoveFormSubmit( $_values );
}
}
catch ( \Exception $e ) {}
@@ -510,7 +517,7 @@ class _clubs extends \IPS\Dispatcher\Controller
/* Do we have any children or content? */
if ( $node->hasChildren( NULL, NULL, TRUE ) or $node->showDeleteOrMoveForm() )
{
$form = $node->deleteOrMoveForm( FALSE, TRUE );
$form = $node->deleteOrMoveForm( FALSE );
if ( $values = $form->values() )
{
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $nodeClass, $node->_id ) );
@@ -12,7 +12,7 @@
namespace IPS\core\modules\admin\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _fields extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
Whitespace-only changes.
@@ -11,7 +11,7 @@
namespace IPS\core\modules\admin\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -22,6 +22,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _settings extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -42,7 +47,7 @@ class _settings extends \IPS\Dispatcher\Controller
{
$form = new \IPS\Helpers\Form;
$form->addHeader( 'club_settings' );
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_enabled_setting', \IPS\Settings::i()->clubs, FALSE, array( 'togglesOn' => array( 'clubs_default_sort', 'clubs_header', 'clubs_locations', 'clubs_modperms', 'clubs_require_approval', 'form_header_club_display_settings', 'form_header_club_moderation', 'clubs_default_view', 'clubs_allow_view_change', 'club_nodes_in_apps', 'form_header_clubs_paid_settings', 'clubs_paid_on' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_enabled_setting', \IPS\Settings::i()->clubs, FALSE, array( 'togglesOn' => array( 'clubs_default_sort', 'clubs_header', 'clubs_locations', 'clubs_modperms', 'clubs_require_approval', 'form_header_club_display_settings', 'form_header_club_moderation', 'clubs_default_view', 'clubs_allow_view_change', 'club_nodes_in_apps', 'form_header_clubs_paid_settings', 'clubs_paid_on', '_allow_club_moderators' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_require_approval', \IPS\Settings::i()->clubs_require_approval, FALSE, array(), NULL, NULL, NULL, 'clubs_require_approval' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'clubs_locations', \IPS\Settings::i()->clubs_locations, FALSE, array(), NULL, NULL, NULL, 'clubs_locations' ) );
if ( \IPS\Application::appIsEnabled( 'nexus' ) )
@@ -76,7 +81,8 @@ class _settings extends \IPS\Dispatcher\Controller
'1' => 'club_nodes_in_apps_on',
) ), NULL, NULL, NULL, 'club_nodes_in_apps' ) );
$form->addHeader( 'club_moderation' );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'clubs_modperms', explode( ',', \IPS\Settings::i()->clubs_modperms ), FALSE, array( 'options' => array(
$form->add( new \IPS\Helpers\Form\YesNo( '_allow_club_moderators', ( \IPS\Settings::i()->clubs_modperms != -1 ), FALSE, array( 'togglesOn' => array( 'clubs_modperms' ) ), NULL, NULL, NULL, '_allow_club_moderators' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'clubs_modperms', ( \IPS\Settings::i()->clubs_modperms != -1 ) ? explode( ',', \IPS\Settings::i()->clubs_modperms ) : array(), FALSE, array( 'options' => array(
'pin' => 'club_modperm_pin',
'unpin' => 'club_modperm_unpin',
'edit' => 'club_modperm_edit',
@@ -94,19 +100,29 @@ class _settings extends \IPS\Dispatcher\Controller
) ), NULL, NULL, NULL, 'clubs_modperms' ) );
if ( $values = $form->values() )
{
{
$values['clubs'] = $values['clubs_enabled_setting'];
unset( $values['clubs_enabled_setting'] );
$values['clubs_modperms'] = implode( ',', $values['clubs_modperms'] );
/* If this setting is set to "No" then we're going to wipe out moderator permissions */
if( !$values['_allow_club_moderators'] )
{
$values['clubs_modperms'] = array();
}
$values['clubs_modperms'] = ( \count( $values['clubs_modperms'] ) ) ? implode( ',', $values['clubs_modperms'] ) : -1;
/* Get rid of fake settings */
unset( $values['clubs_enabled_setting'], $values['_allow_club_moderators'] );
if ( \IPS\Application::appIsEnabled( 'nexus' ) )
{
$values['clubs_paid_tax'] = $values['clubs_paid_tax'] ? $values['clubs_paid_tax']->id : 0;
$values['clubs_paid_gateways'] = is_array( $values['clubs_paid_gateways'] ) ? implode( ',', array_keys( $values['clubs_paid_gateways'] ) ) : $values['clubs_paid_gateways'];
$values['clubs_paid_gateways'] = \is_array( $values['clubs_paid_gateways'] ) ? implode( ',', array_keys( $values['clubs_paid_gateways'] ) ) : $values['clubs_paid_gateways'];
}
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplog__club_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=clubs&controller=settings') );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=clubs&controller=settings'), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_clubs_settings');
@@ -0,0 +1,475 @@
<?php
/**
* @brief Statistics
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 06 Dec 2019
*/
namespace IPS\core\modules\admin\clubs;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Statistics
*/
class _stats extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'stats_manage' );
parent::execute();
}
/**
* Display the statistics
*
* @return void
*/
protected function manage()
{
/* If clubs are not enabled, stop now */
if ( !\IPS\Settings::i()->clubs )
{
$availableTypes = array();
foreach ( \IPS\Member\Club::availableNodeTypes( NULL ) as $class )
{
$availableTypes[] = \IPS\Member::loggedIn()->language()->addToStack( $class::clubAcpTitle() );
}
$availableTypes = \IPS\Member::loggedIn()->language()->formatList( $availableTypes );
\IPS\Output::i()->output = \IPS\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';
/* Get the HTML to output */
$method = '_' . $activeTab;
$output = $this->$method();
/* And then print it */
if ( \IPS\Request::i()->isAjax() )
{
\IPS\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" ) );
}
}
/**
* Club activity overview
*
* @return string
*/
protected function _overview()
{
$clubTypePieChart = $this->_getClubTypePieChart();
$clubSignups = $this->_getClubSignups();
$clubCreations = $this->_getClubCreations();
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->statsOverview( $clubTypePieChart, $clubSignups, $clubCreations );
}
/**
* Get line chart showing club signups
*
* @return \IPS\Helpers\Chart
*/
protected function _getClubSignups()
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\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' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
), 'ColumnChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array( 'club_id', 'name' ), 'signups' );
$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 )
{
$chart->addSeries( $club->name, 'number', 'COUNT(*)', TRUE, $club->id );
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_clubs_signups');
$chart->availableTypes = array( 'ColumnChart', 'BarChart' );
if( \IPS\Request::i()->fetch == 'signups' AND \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
}
return $chart;
}
/**
* Get line chart showing club creations
*
* @return \IPS\Helpers\Chart
*/
protected function _getClubCreations()
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&fetch=clubs' ), 'core_clubs', 'created', '', array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'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->availableTypes = array( 'ColumnChart', 'BarChart' );
if( \IPS\Request::i()->fetch == 'clubs' AND \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( (string) $chart, 200 );
}
return $chart;
}
/**
* Get pie chart showing club types
*
* @return \IPS\Helpers\Chart
*/
protected function _getClubTypePieChart()
{
$percentages = array();
$counts = array();
$total = 0;
foreach( \IPS\Db::i()->select( 'type, COUNT(*) as total', 'core_clubs', array(), NULL, NULL, array( 'type' ) ) as $clubs )
{
$counts[ $clubs['type'] ] = $clubs['total'];
$total += $clubs['total'];
}
foreach( $counts as $type => $typeTotal )
{
$percentages[ $type ] = number_format( round( 100 / $total * $typeTotal, 2 ), 2 );
}
return \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->clubTypesBar( $percentages, $counts );
}
/**
* Total club activity
*
* @return \IPS\Helpers\Chart\Dynamic
*/
protected function _total()
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=total' ),
array( $this, 'getResults' ),
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'ColumnChart',
'monthly',
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
'total'
);
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
{
$contentClass = $nodeType::$contentItemClass;
$chart->addSeries( \IPS\Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ), 'number', TRUE );
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_club_activity' );
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
return $chart;
}
/**
* Activity by club
*
* @return string
*/
protected function _byclub()
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=clubs&controller=stats&tab=byclub' ),
array( $this, 'getResults' ),
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'ColumnChart',
'monthly',
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P6M') ), 'end' => \IPS\DateTime::create() ),
'byclub'
);
foreach( \IPS\Member\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->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
return $chart;
}
/**
* Fetch the results
*
* @param \IPS\Helpers\Chart\Callback $chart Chart object
* @return array
*/
public function getResults( $chart )
{
/* Get the info we need */
$nodeTypes = \IPS\Member\Club::availableNodeTypes( NULL );
$clubNodes = array();
$classes = array();
$classMap = array();
$results = array();
foreach( $nodeTypes as $nodeType )
{
$clubNodes[ $nodeType ] = $nodeType::clubNodes( NULL );
$itemClass = $nodeType::$contentItemClass;
$classes[] = $itemClass;
$classMap[ $itemClass ] = $nodeType;
if( isset( $itemClass::$commentClass ) )
{
$classes[] = $itemClass::$commentClass;
$classMap[ $itemClass::$commentClass ] = $nodeType;
}
if( isset( $itemClass::$reviewClass ) )
{
$classes[] = $itemClass::$reviewClass;
$classMap[ $itemClass::$reviewClass ] = $nodeType;
}
}
/* If we are fetching by club, we need to build a map of containers to clubs */
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
$clubNodeMap = array();
foreach( \IPS\Db::i()->select( '*', 'core_clubs_node_map' ) as $nodeMap )
{
$nodeClass = $nodeMap['node_class'];
$nodeClass = $nodeClass::$contentItemClass;
$clubNodeMap[ $nodeClass::$databaseTable . '-' . $nodeMap['node_id'] ] = $nodeMap['club_id'];
if( isset( $nodeClass::$commentClass ) )
{
$commentClass = $nodeClass::$commentClass;
$clubNodeMap[ $commentClass::$databaseTable . '-' . $nodeMap['node_id'] ] = $nodeMap['club_id'];
}
if( isset( $nodeClass::$reviewClass ) )
{
$reviewClass = $nodeClass::$reviewClass;
$clubNodeMap[ $reviewClass::$databaseTable . '-' . $nodeMap['node_id'] ] = $nodeMap['club_id'];
}
}
}
else
{
$groupByContainer = FALSE;
}
/* Get results */
foreach ( $classes as $class )
{
$where = array();
$join = NULL;
if( is_subclass_of( $class, '\IPS\Content\Comment' ) )
{
/* We're going to need a subquery... */
$parentClass = $class::$itemClass;
$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'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) ) )
. ")"
);
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
$groupByContainer = $parentClass::$databaseTable . '.' . $parentClass::$databasePrefix . $parentClass::$databaseColumnMap['container'];
$join = array( $parentClass::$databaseTable, $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['item'] . '=' . $parentClass::$databaseTable . '.' . $parentClass::$databasePrefix . $parentClass::$databaseColumnId );
}
/* We need to account for topic + first post not counting as two posts */
if( $parentClass::$firstCommentRequired === TRUE AND isset( $class::$databaseColumnMap['first'] ) )
{
$where[] = array( $class::$databasePrefix . $class::$databaseColumnMap['first'] . '=?', 0 );
}
}
else
{
$where[] = array( \IPS\Db::i()->in( $class::$databasePrefix . $class::$databaseColumnMap['container'], array_keys( $clubNodes[ $classMap[ $class ] ] ) ) );
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
$groupByContainer = $class::$databasePrefix . $class::$databaseColumnMap['container'];
}
}
$stmt = $this->getSqlResults(
$class::$databaseTable,
$class::$databasePrefix . ( isset( $class::$databaseColumnMap['updated'] ) ? $class::$databaseColumnMap['updated'] : $class::$databaseColumnMap['date'] ),
$class::$databasePrefix . $class::$databaseColumnMap['author'],
$chart,
$where,
$groupByContainer,
$join
);
foreach( $stmt as $row )
{
if( !isset( $results[ $row['time'] ] ) )
{
$results[ $row['time'] ] = array(
'time' => $row['time']
);
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
foreach( \IPS\Member\Club::clubs( NULL, NULL, 'name' ) as $club )
{
$results[ $row['time'] ][ $club->name ] = 0;
}
}
else
{
foreach( \IPS\Member\Club::availableNodeTypes( NULL ) as $nodeType )
{
$contentClass = $nodeType::$contentItemClass;
$results[ $row['time'] ][ \IPS\Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ) ] = 0;
}
}
}
$classType = $classMap[ $class ];
if( mb_strpos( $chart->identifier, 'byclub' ) !== FALSE )
{
$results[ $row['time'] ][ \IPS\Member\Club::load( $clubNodeMap[ $class::$databaseTable . '-' . $row['container'] ] )->name ] += $row['total'];
}
else
{
$contentClass = $classMap[ $class ]::$contentItemClass;
$results[ $row['time'] ][ \IPS\Member::loggedIn()->language()->get( $contentClass::$title . '_pl' ) ] += $row['total'];
}
}
}
return $results;
}
/**
* Get SQL query/results
*
* @note Consolidated to reduce duplicated code
* @param string $table Database table
* @param string $date Date column
* @param string $author Author column
* @param object $chart Chart
* @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
*/
protected function getSqlResults( $table, $date, $author, $chart, $where = array(), $groupByContainer = FALSE, $join = NULL )
{
/* What's our SQL time? */
switch ( $chart->timescale )
{
case 'daily':
$timescale = '%Y-%c-%e';
break;
case 'weekly':
$timescale = '%x-%v';
break;
case 'monthly':
$timescale = '%Y-%c';
break;
}
$where[] = array( "{$date}>?", 0 );
if ( $chart->start )
{
$where[] = array( "{$date}>?", $chart->start->getTimestamp() );
}
if ( $chart->end )
{
$where[] = array( "{$date}<?", $chart->end->getTimestamp() );
}
/* 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() ) )
{
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . \IPS\Db::i()->escape_string( \IPS\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' ) );
if( $join !== NULL )
{
$stmt = $stmt->join( ...$join );
}
}
else
{
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, COUNT(*) as total", $table, $where, 'time ASC', NULL, array( 'time' ) );
}
return $stmt;
}
}