Version 4.7.13

This commit is contained in:
Neo committed 2025-12-19 16:14:56 -08:00
1 parent fd22d99e69
commit 7124a02564
954 files changed
+29277 -59308

No files matched your search

@@ -0,0 +1,48 @@
<?php
/**
* @brief ajax
* @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 09 May 2023
*/
namespace IPS\core\modules\admin\activitystats;
/* 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;
}
/**
* ajax
*/
class _ajax extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
parent::execute();
}
/**
* ...
*
* @return void
*/
protected function manage()
{
// This is the default method if no 'do' parameter is specified
}
// Create new methods with the same name as the 'do' parameter which should execute it
}
@@ -51,25 +51,7 @@ class _communityactivity extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=communityactivity' ),
array( $this, 'getResults' ),
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e', '#ea7963' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'AreaChart',
'weekly',
array( 'start' => \IPS\DateTime::create()->sub( new \DateInterval( 'P90D' ) ), 'end' => \IPS\DateTime::ts( time() ) )
);
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('activity'), 'number', FALSE );
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('member_activity_timeperiod');
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'CommunityActivity' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=communityactivity" ) );
if( \IPS\Request::i()->isAjax() )
{
@@ -82,107 +64,5 @@ class _communityactivity extends \IPS\Dispatcher\Controller
\IPS\Output::i()->output .= (string) $chart;
}
/**
* Fetch the results
*
* @param \IPS\Helpers\Chart\Callback $chart Chart object
* @return array
*/
public function getResults( $chart )
{
/* Get results */
$results = array();
if ( \IPS\Settings::i()->search_method == 'mysql' )
{
$results = array_replace_recursive( $results, $this->getSqlResults( 'core_search_index', 'index_date_updated', 'index_author', $chart ) );
}
else
{
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter' ) as $contentRouter )
{
foreach ( $contentRouter->classes as $class )
{
if ( isset( $class::$databaseColumnMap['author'] ) )
{
$results = array_replace_recursive( $results, $this->getSqlResults(
$class::$databaseTable,
$class::$databasePrefix . ( isset( $class::$databaseColumnMap['updated'] ) ? $class::$databaseColumnMap['updated'] : $class::$databaseColumnMap['date'] ),
$class::$databasePrefix . $class::$databaseColumnMap['author'],
$chart
) );
}
}
}
}
$results = array_replace_recursive( $results, $this->getSqlResults( 'core_reputation_index', 'rep_date', 'member_id', $chart ) );
$results = array_replace_recursive( $results, $this->getSqlResults( 'core_follow', 'follow_added', 'follow_member_id', $chart ) );
/* Reformat now */
$finalResults = array();
foreach( $results as $date => $members )
{
$finalResults[ $date ] = array( 'time' => $date, \IPS\Member::loggedIn()->language()->get('activity') => \count( $members ) );
}
return $finalResults;
}
/**
* 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
* @return array
*/
protected function getSqlResults( $table, $date, $author, $chart )
{
/* 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;
}
$results = array();
$where = array( array( "{$date}>?", 0 ) );
$where[] = array( "{$author}>?", 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 ) . "' )";
}
$stmt = \IPS\Db::i()->select( "DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time, {$author}", $table, $where, 'time ASC', NULL, array( $author, 'time' ) );
foreach( $stmt as $row )
{
$results[ $row['time'] ][ $row[ $author ] ] = 1;
}
return $results;
}
}
@@ -46,34 +46,7 @@ class _deletedcontent extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=deletedcontent' ), 'core_deletion_log', 'dellog_deleted_date', '', array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
), 'LineChart', 'monthly', array( 'start' => 0, 'end' => 0 ), array( 'dellog_content_class', 'dellog_deleted_date' ), 'deletedcontent' );
$chart->groupBy = 'dellog_content_class';
$types = \IPS\Db::i()->select( 'DISTINCT(dellog_content_class)', 'core_deletion_log' );
foreach( $types as $class )
{
$lang = $class::$title;
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack( $lang ), 'number', 'COUNT(*)', TRUE, $class );
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_deletedcontent_title');
$chart->availableTypes = array( 'LineChart', 'AreaChart', 'ColumnChart', 'BarChart' );
$chart->tableParsers = array(
'dellog_deleted_date' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
}
);
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'DeletedContent' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=deletedcontent" ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_deletedcontent');
\IPS\Output::i()->output = (string) $chart;
}
@@ -59,68 +59,7 @@ class _emailstats extends \IPS\Dispatcher\Controller
{
$activeTab = $this->_getActiveTab();
/* Determine minimum date */
$minimumDate = NULL;
if( \IPS\Settings::i()->prune_log_emailstats > 0 )
{
$minimumDate = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->prune_log_emailstats . 'D' ) );
}
/* We can't retrieve any stats prior to the new tracking being implemented */
try
{
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'emails_sent' ) )->first();
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
{
$minimumDate = \IPS\DateTime::ts( $oldestLog );
}
}
catch( \UnderflowException $e )
{
/* We have nothing tracked, set minimum date to today */
$minimumDate = \IPS\DateTime::create();
}
$startDate = \IPS\DateTime::ts( time() - ( 60 * 60 * 24 * 30 ) );
/* If our start date is older than our minimum date, use that as the start date instead */
if ( $startDate->getTimestamp() < $minimumDate->getTimestamp() )
{
$startDate = $minimumDate;
}
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=emailstats&tab=' . $activeTab ),
array( $this, 'getResults' ),
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4,
'height' => 450
),
'LineChart',
'daily',
array( 'start' => $startDate, 'end' => \IPS\DateTime::create() ),
'',
$minimumDate
);
$chart->availableTypes = array( 'LineChart', 'ColumnChart', 'BarChart' );
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_emailstats_' . $activeTab);
/* Force the notice that the chart is displayed in the server time zone */
$chart->timezoneError = TRUE;
$chart->hideTimezoneLink = TRUE;
foreach( $this->_getEmailTypes() as $series )
{
$chart->addSeries( $series, 'number' );
}
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', ( $activeTab === 'emails' ) ? 'Emails' : 'EmailClicks' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=emailstats&tab={$activeTab}" ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -133,85 +72,6 @@ class _emailstats extends \IPS\Dispatcher\Controller
}
}
/**
* Fetch the results
*
* @param \IPS\Helpers\Chart\Callback $chart Chart object
* @return array
*/
public function getResults( $chart )
{
$activeTab = $this->_getActiveTab();
$where = array( array( "time>?", 0 ) );
switch( $activeTab )
{
case 'emails':
$where[] = array( 'type=?', 'emails_sent' );
break;
case 'clicks':
$where[] = array( 'type=?', 'email_clicks' );
break;
}
if ( $chart->start )
{
$where[] = array( "value_4>=?", $chart->start->format('Y-m-d') );
}
if ( $chart->end )
{
$where[] = array( "value_4<=?", $chart->end->format('Y-m-d') );
}
$results = array();
foreach( \IPS\Db::i()->select( '*', 'core_statistics', $where, 'value_4 ASC' ) as $row )
{
/* We need to use month/days NOT prefixed with '0' - i.e. 2019-2-12 instead of 2019-02-12 - to match the chart helper */
$_date = new \IPS\DateTime( $row['value_4'] );
switch( $chart->timescale )
{
case 'daily':
$_date = $_date->format( 'Y-n-j' );
break;
case 'weekly':
$_date = $_date->format( 'o-W' );
break;
case 'monthly':
$_date = $_date->format( 'Y-n' );
break;
}
if( !isset( $results[ $_date ] ) )
{
$results[ $_date ] = array( 'time' => $_date );
foreach( $this->_getEmailTypes() as $series )
{
$results[ $_date ][ $series ] = 0;
}
}
$lang = $row['extra_data'];
try
{
$lang = \IPS\Member::loggedIn()->language()->get( 'emailstats__' . $row['extra_data'] );
}
catch( \UnderflowException $e ){}
$results[ $_date ][ $lang ] += (int) $row['value_1'];
}
return $results;
}
/**
* Get the active tab
*
@@ -219,7 +79,8 @@ class _emailstats extends \IPS\Dispatcher\Controller
*/
protected function _getActiveTab()
{
return ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $this->_getAvailableTabs() ) ) ? \IPS\Request::i()->tab : 'emails';
\IPS\Request::i()->tab ??= 'emails';
return ( array_key_exists( \IPS\Request::i()->tab, $this->_getAvailableTabs() ) ) ? \IPS\Request::i()->tab : 'emails';
}
/**
@@ -234,37 +95,4 @@ class _emailstats extends \IPS\Dispatcher\Controller
'clicks' => 'stats_emailstats_clicks',
);
}
/**
* @brief Cached email types
*/
protected $_emailTypes = NULL;
/**
* Get all possible email types logged
*
* @return array
*/
protected function _getEmailTypes()
{
if( $this->_emailTypes === NULL )
{
$this->_emailTypes = array();
foreach( \IPS\Db::i()->select( 'extra_data', 'core_statistics', array( 'type=?', 'emails_sent' ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_DISTINCT ) as $series )
{
$lang = $series;
try
{
$lang = \IPS\Member::loggedIn()->language()->get( 'emailstats__' . $series );
}
catch( \UnderflowException $e ){}
$this->_emailTypes[] = $lang;
}
}
return array_unique( $this->_emailTypes );
}
}
@@ -58,134 +58,100 @@ class _keywords extends \IPS\Dispatcher\Controller
'link' => \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords&do=settings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('settings') )
);
/* Determine minimum date */
$minimumDate = NULL;
if( \IPS\Settings::i()->stats_keywords_prune )
{
$minimumDate = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->stats_keywords_prune . 'D' ) );
}
/* Draw a chart */
$options = json_decode( \IPS\Settings::i()->stats_keywords, true );
if( !\is_array( $options ) )
{
$options = array();
}
$chart = new \IPS\Helpers\Chart\Database(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords' ),
'core_statistics',
'time',
'',
array(
'isStacked' => TRUE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e', '#ea7963', '#de6470', '#6b9dde', '#b09be4', '#eec766', '#9fc973', '#e291bf', '#55c1a6', '#5fb9da' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'LineChart',
'daily',
array( 'start' => \IPS\DateTime::create()->sub( new \DateInterval( 'P90D' ) ), 'end' => \IPS\DateTime::ts( time() ) ),
array(),
'',
$minimumDate
);
$chart->where = array( array( 'type=?', 'keyword' ) );
$chart->groupBy = 'value_4';
if ( \is_array( $options ) )
{
foreach( $options as $k => $v )
{
$chart->addSeries( $v, 'number', 'COUNT(*)' );
}
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('keyword_usage_chart');
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
\IPS\Output::i()->output = (string) $chart;
if( \IPS\Request::i()->noheader AND \IPS\Request::i()->isAjax() )
{
return;
}
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_statistics', \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords' ), array( array( 'type=?', 'keyword' ) ) );
$table->langPrefix = 'keywordstats_';
$table->quickSearch = 'value_4';
/* Columns we need */
$table->include = array( 'value_4', 'extra_data', 'author', 'time' );
$table->mainColumn = 'value_4';
$table->noSort = array( 'extra_data' );
$table->sortBy = $table->sortBy ?: 'time';
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Custom parsers */
$table->parsers = array(
'time' => function( $val, $row )
{
return \IPS\DateTime::ts( $val )->localeDate();
},
'author' => function( $val, $row )
{
$data = json_decode( $row['extra_data'], TRUE );
try
{
$class = $data['class'];
/* Check that the class exists */
if( !class_exists( $class ) )
{
throw new \InvalidArgumentException;
}
$item = $class::load( $data['id'] );
return $item->author()->link();
}
catch( \Exception $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'unknown' );
}
},
'extra_data' => function( $val, $row )
{
$data = json_decode( $val, TRUE );
try
{
$class = $data['class'];
/* Check that the class exists */
if( !class_exists( $class ) )
{
throw new \InvalidArgumentException;
}
$item = $class::load( $data['id'] );
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $item->url(), TRUE, ( $item instanceof \IPS\Content\Comment ) ? $item->item()->mapped('title') : $item->mapped('title'), TRUE );
}
catch( \Exception $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'content_deleted' );
}
},
$tabs = array(
'time' => 'keywords_usage_over_time',
'list' => 'keywords_usage_list',
);
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_keywords');
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table, TRUE, 'ipsPad ipsSpacer_top' );
\IPS\Request::i()->tab ??= 'time';
$activeTab = ( array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'time';
if ( $activeTab === 'time' )
{
$output = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'Keywords' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=keywords&tab=time" ) );
}
else
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_statistics', \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords&tab=list' ), array( array( 'type=?', 'keyword' ) ) );
$table->langPrefix = 'keywordstats_';
$table->quickSearch = 'value_4';
/* Columns we need */
$table->include = array( 'value_4', 'extra_data', 'author', 'time' );
$table->mainColumn = 'value_4';
$table->noSort = array( 'extra_data' );
$table->sortBy = $table->sortBy ?: 'time';
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Custom parsers */
$table->parsers = array(
'time' => function( $val, $row )
{
return \IPS\DateTime::ts( $val )->localeDate();
},
'author' => function( $val, $row )
{
$data = json_decode( $row['extra_data'], TRUE );
try
{
$class = $data['class'];
/* Check that the class exists */
if( !class_exists( $class ) )
{
throw new \InvalidArgumentException;
}
$item = $class::load( $data['id'] );
return $item->author()->link();
}
catch( \Exception $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'unknown' );
}
},
'extra_data' => function( $val, $row )
{
$data = json_decode( $val, TRUE );
try
{
$class = $data['class'];
/* Check that the class exists */
if( !class_exists( $class ) )
{
throw new \InvalidArgumentException;
}
$item = $class::load( $data['id'] );
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $item->url(), TRUE, ( $item instanceof \IPS\Content\Comment ) ? $item->item()->mapped('title') : $item->mapped('title'), TRUE );
}
catch( \Exception $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'content_deleted' );
}
},
);
/* Display */
$output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table, TRUE, 'ipsPad ipsSpacer_top' );
}
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = (string) $output;
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_keywords');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, \IPS\Http\Url::internal( "app=core&module=activitystats&controller=keywords" ), 'tab', '', 'ipsPad' );
}
}
/**
@@ -211,4 +177,28 @@ class _keywords extends \IPS\Dispatcher\Controller
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'settings', $form, FALSE );
}
/**
* Rebuild
*
* @return void
*/
protected function rebuild()
{
if ( !\IPS\Settings::i()->stats_keywords )
{
\IPS\Output::i()->error( 'no_keywords_to_rebuild', '2C433/1', 403, '' );
}
\IPS\Session::i()->csrfCheck();
\IPS\Db::i()->delete( 'core_statistics', array( 'type=?', 'keyword' ) );
foreach( \IPS\Content::routedClasses() AS $class )
{
\IPS\Task::queue( 'core', 'RebuildKeywords', array( 'class' => $class ) );
}
\IPS\Session::i()->log( 'acplog__statskeywords_rebuilt' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords' ), 'saved' );
}
}
@@ -51,7 +51,8 @@ class _overview extends \IPS\core\modules\admin\stats\overview
if( isset( \IPS\Request::i()->cookie['overviewExcludedApps'] ) )
{
try {
try
{
$excludedApps = json_decode( \IPS\Request::i()->cookie['overviewExcludedApps'] );
if( !\is_array( $excludedApps ) )
@@ -57,45 +57,12 @@ class _reactions extends \IPS\Dispatcher\Controller
'givers' => 'stats_reactions_top_givers',
'getters' => 'stats_reactions_top_receivers',
);
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'type';
\IPS\Request::i()->tab ??= 'type';
$activeTab = ( array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'type';
if ( $activeTab === 'type' OR $activeTab === 'app' )
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reactions&tab=" . $activeTab ), 'core_reputation_index', 'rep_date', '', array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e', '#ea7963', '#de6470', '#6b9dde', '#b09be4', '#eec766', '#9fc973', '#e291bf', '#55c1a6', '#5fb9da' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'PieChart',
'monthly',
array( 'start' => 0, 'end' => 0 ),
array(),
$activeTab
);
if ( $activeTab === 'type' )
{
$chart->groupBy = 'reaction';
foreach( \IPS\Content\Reaction::roots() as $reaction )
{
$chart->addSeries( $reaction->_title, 'number', 'COUNT(*)', TRUE, $reaction->id );
}
}
else
{
$chart->groupBy = 'app';
foreach( \IPS\Application::roots() as $app )
{
$chart->addSeries( $app->_title, 'number', 'COUNT(*)', TRUE, $app->directory );
}
}
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart', 'PieChart' );
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', ( $activeTab === 'type' ) ? 'Reactions' : 'ReactionsApp' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reactions&tab=" . $activeTab ) );
}
else
{
@@ -41,19 +41,7 @@ class _reports extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=reports' ), 'core_rc_reports', 'date_reported', '', array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
) );
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('stats_reports'), 'number', 'COUNT(*)', FALSE );
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_reports_title');
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'Reports' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reports" ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_reports');
\IPS\Output::i()->output = (string) $chart;
}
@@ -22,11 +22,6 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _search extends \IPS\Dispatcher\Controller
{
/**
* @brief Default limit to number of graphed results
*/
protected $defaultLimit = 25;
/**
* @brief Has been CSRF-protected
*/
@@ -69,53 +64,8 @@ class _search extends \IPS\Dispatcher\Controller
'title' => 'searchstats_log',
'link' => \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=search&do=log' ),
);
/* Determine minimum date */
$minimumDate = NULL;
if( \IPS\Settings::i()->stats_search_prune )
{
$minimumDate = \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->stats_search_prune . 'D' ) );
}
$chart = new \IPS\Helpers\Chart\Database(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=search' ),
'core_statistics',
'time',
'',
array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'colors' => array( '#10967e', '#ea7963', '#de6470', '#6b9dde', '#b09be4', '#eec766', '#9fc973', '#e291bf', '#55c1a6', '#5fb9da' ),
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4,
'limitSearch' => 'stats_search_term_menu',
),
'LineChart',
'daily',
array( 'start' => \IPS\DateTime::create()->sub( new \DateInterval( 'P90D' ) ), 'end' => \IPS\DateTime::ts( time() ) ),
array(),
'',
$minimumDate
);
$chart->where = array( array( 'type=?', 'search' ) );
$chart->groupBy = 'value_4';
$terms = [];
foreach( $this->getTerms( $chart->searchTerm ) as $v )
{
$terms[] = $v;
$chart->addSeries( $v, 'number', 'COUNT(*)', FALSE );
}
if ( \count( $terms ) )
{
$chart->where[] = [ \IPS\Db::i()->in( 'value_4', $terms ) ];
}
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('search_stats_chart');
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'Search' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=search" ) );
\IPS\Output::i()->output = (string) $chart;
@@ -128,39 +78,6 @@ class _search extends \IPS\Dispatcher\Controller
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_search');
}
/**
* @brief Cached top search terms
*/
protected $_topSearchTerms = array();
/**
* Get the top search terms
*
* @param string|null $term Term we searched for
* @return array
*/
public function getTerms( $term=NULL )
{
if( !isset( $this->_topSearchTerms[ $term ] ) )
{
$this->_topSearchTerms[ $term ] = array();
$where = array( array( 'type=?', 'search' ) );
if( $term !== NULL )
{
$where[] = \IPS\Db::i()->like( 'value_4', $term, TRUE, TRUE, TRUE );
}
foreach( \IPS\Db::i()->select( 'SQL_BIG_RESULT value_4, COUNT(*) as total', 'core_statistics', $where, 'total DESC', $this->defaultLimit, 'value_4' ) as $searchedValue )
{
$this->_topSearchTerms[ $term ][] = $searchedValue['value_4'];
}
}
return $this->_topSearchTerms[ $term ];
}
/**
* Prune Settings
*
@@ -50,39 +50,7 @@ class _tags extends \IPS\Dispatcher\Controller
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=tags" ), 'core_tags', 'tag_added', '', array(
'isStacked' => FALSE,
'backgroundColor' => '#ffffff',
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
'lineWidth' => 1,
'areaOpacity' => 0.4
),
'AreaChart',
'daily',
array( 'start' => \IPS\DateTime::create()->sub( new \DateInterval( 'P1M' ) ), 'end' => 0 )
);
$chart->groupBy = 'tag_text';
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart', 'PieChart' );
$where = $chart->where;
$where[] = array( "tag_added>?", 0 );
if ( $chart->start )
{
$where[] = array( "tag_added>?", $chart->start->getTimestamp() );
}
if ( $chart->end )
{
$where[] = array( "tag_added<?", $chart->end->getTimestamp() );
}
/* Only get visible tags */
$where[] = array( 'tag_aai_lookup IN(?)', \IPS\Db::i()->select( 'tag_perm_aai_lookup', 'core_tags_perms', [ 'tag_perm_visible=1' ] ) );
foreach( \IPS\Db::i()->select( 'tag_text', 'core_tags', $where, NULL, NULL, array( 'tag_text' ) ) as $tag )
{
$chart->addSeries( $tag, 'number', 'COUNT(*)', TRUE, $tag );
}
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', 'Tags' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=tags" ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_tags');
\IPS\Output::i()->output = (string) $chart;
}