Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\activitystats;
|
||||
|
||||
/* 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 _communityactivity extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -113,7 +118,7 @@ class _communityactivity extends \IPS\Dispatcher\Controller
|
||||
|
||||
foreach( $results as $date => $members )
|
||||
{
|
||||
$finalResults[ $date ] = array( 'time' => $date, \IPS\Member::loggedIn()->language()->get('activity') => count( $members ) );
|
||||
$finalResults[ $date ] = array( 'time' => $date, \IPS\Member::loggedIn()->language()->get('activity') => \count( $members ) );
|
||||
}
|
||||
|
||||
return $finalResults;
|
||||
@@ -139,7 +144,7 @@ class _communityactivity extends \IPS\Dispatcher\Controller
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
$timescale = '%Y-%u';
|
||||
$timescale = '%x-%v';
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
@@ -161,7 +166,7 @@ class _communityactivity 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 \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 ) . "' )";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Email 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 31 Oct 2018
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Email statistics
|
||||
*/
|
||||
class _emailstats extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'emailstats_manage' );
|
||||
|
||||
/* We can only view the stats if we have logging enabled */
|
||||
if( \IPS\Settings::i()->prune_log_emailstats == 0 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'emaillogs_not_enabled', '1C395/1', 403, '' );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the charts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$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' );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_emailstats');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $this->_getAvailableTabs(), $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=core&module=activitystats&controller=emailstats" ), 'tab', '', 'ipsPad' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ] = $row['value_1'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active tab
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getActiveTab()
|
||||
{
|
||||
return ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $this->_getAvailableTabs() ) ) ? \IPS\Request::i()->tab : 'emails';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the possible tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getAvailableTabs()
|
||||
{
|
||||
return array(
|
||||
'emails' => 'stats_emailstats_emails',
|
||||
'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 );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\activitystats;
|
||||
|
||||
/* 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;
|
||||
@@ -21,7 +21,12 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* Keyword Tracking
|
||||
*/
|
||||
class _keywords extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -60,7 +65,7 @@ class _keywords extends \IPS\Dispatcher\Controller
|
||||
/* Draw a chart */
|
||||
$options = json_decode( \IPS\Settings::i()->stats_keywords, true );
|
||||
|
||||
if( !is_array( $options ) )
|
||||
if( !\is_array( $options ) )
|
||||
{
|
||||
$options = array();
|
||||
}
|
||||
@@ -88,7 +93,7 @@ class _keywords extends \IPS\Dispatcher\Controller
|
||||
$chart->where = array( array( 'type=?', 'keyword' ) );
|
||||
$chart->groupBy = 'value_4';
|
||||
|
||||
if ( is_array( $options ) )
|
||||
if ( \is_array( $options ) )
|
||||
{
|
||||
foreach( $options as $k => $v )
|
||||
{
|
||||
@@ -96,10 +101,9 @@ class _keywords extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$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() )
|
||||
@@ -188,11 +192,11 @@ class _keywords extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'stats_keywords', \IPS\Settings::i()->stats_keywords ? json_decode( \IPS\Settings::i()->stats_keywords, true ) : array(), FALSE, array( 'stackFieldType' => 'Text' ), NULL, NULL, NULL, 'stats_keywords' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'stats_keywords_prune', \IPS\Settings::i()->stats_keywords_prune, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days') ) );
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'stats_keywords_prune', \IPS\Settings::i()->stats_keywords_prune, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$values['stats_keywords'] = json_encode( $values['stats_keywords'] );
|
||||
$values['stats_keywords'] = json_encode( array_unique( $values['stats_keywords'] ) );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplog__statskeywords_settings' );
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Content overview 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 09 Jan 2020
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content overview statistics
|
||||
*/
|
||||
class _overview extends \IPS\core\modules\admin\stats\overview
|
||||
{
|
||||
/**
|
||||
* @brief Template group to use to output
|
||||
*/
|
||||
protected $templateGroup = 'activitystats';
|
||||
|
||||
/**
|
||||
* Create the general page layout, but we will load the individual cells via AJAX to ensure there are no performance concerns loading the page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$formHtml = $this->form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'stats' ), 'filtersOverviewForm' ) );
|
||||
$blocks = \IPS\Application::allExtensions( 'core', 'OverviewStatistics', TRUE, 'core', 'Registrations' );
|
||||
|
||||
$excludedApps = array();
|
||||
|
||||
if( isset( \IPS\Request::i()->cookie['overviewExcludedApps'] ) )
|
||||
{
|
||||
try {
|
||||
$excludedApps = json_decode( \IPS\Request::i()->cookie['overviewExcludedApps'] );
|
||||
|
||||
if( !\is_array( $excludedApps ) )
|
||||
{
|
||||
$excludedApps = array();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_stats.js', 'core' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/statistics.css', 'core', 'admin' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_stats_overview');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( $this->templateGroup )->overview( $formHtml, $blocks, $excludedApps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the filter configuration form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loadBlockForm()
|
||||
{
|
||||
$blocks = \IPS\Application::allExtensions( 'core', 'OverviewStatistics', TRUE, 'core', 'Registrations' );
|
||||
|
||||
if( !isset( $blocks[ \IPS\Request::i()->blockKey ] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'stats_overview_block_not_found', '2C416/1', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $blocks[ \IPS\Request::i()->blockKey ]->getBlockForm( \IPS\Request::i()->subBlockKey );
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\activitystats;
|
||||
|
||||
/* 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 _reactions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -89,6 +94,43 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $activeTab == 'givers' OR $activeTab == 'getters' )
|
||||
{
|
||||
$start = NULL;
|
||||
$end = NULL;
|
||||
|
||||
$defaults = array( 'start' => \IPS\DateTime::create()->setDate( date('Y'), date('m'), 1 ), 'end' => new \IPS\DateTime );
|
||||
|
||||
if( isset( \IPS\Request::i()->repDateStart ) AND isset( \IPS\Request::i()->repDateEnd ) )
|
||||
{
|
||||
$defaults = array( 'start' => \IPS\DateTime::ts( \IPS\Request::i()->repDateStart ), 'end' => \IPS\DateTime::ts( \IPS\Request::i()->repDateEnd ) );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( $activeTab, 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'date', $defaults, TRUE ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
/* Determine start and end time */
|
||||
$startTime = $values['date']['start']->getTimestamp();
|
||||
$endTime = $values['date']['end']->getTimestamp();
|
||||
|
||||
$start = $values['date']['start']->html();
|
||||
$end = $values['date']['end']->html();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Determine start and end time */
|
||||
$startTime = $defaults['start']->getTimestamp();
|
||||
$endTime = $defaults['end']->getTimestamp();
|
||||
|
||||
$start = $defaults['start']->html();
|
||||
$end = $defaults['end']->html();
|
||||
}
|
||||
|
||||
$where = array( array( 'rep_date BETWEEN ? AND ?', $startTime, $endTime ) );
|
||||
}
|
||||
|
||||
/* Database table helpers don't support grouping, so we will manually fetch the results and then let the table helper display */
|
||||
$contentWhere = array();
|
||||
$idToRatingMap = array();
|
||||
@@ -99,11 +141,11 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
elseif( $activeTab == 'givers' )
|
||||
{
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', NULL, 'rating DESC', array( 0, 20 ), array( 'member_id' ) );
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', $where, 'rating DESC', array( 0, 20 ), array( 'member_id' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', NULL, 'rating DESC', array( 0, 20 ), array( 'member_received' ) );
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', $where, 'rating DESC', array( 0, 20 ), array( 'member_received' ) );
|
||||
}
|
||||
|
||||
foreach( $query as $reputation )
|
||||
@@ -129,6 +171,8 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
$column = ( $activeTab == 'givers' ) ? 'member_id' : 'member_received';
|
||||
$chart->include = array( $column, 'rep_date', 'rating' );
|
||||
$chart->mainColumn = $column;
|
||||
|
||||
$chart->baseUrl = $chart->baseUrl->setQueryString( array( 'repDateStart' => $startTime, 'repDateEnd' => $endTime, 'tab' => $activeTab ) );
|
||||
}
|
||||
|
||||
$chart->noSort = array( 'member_id', 'type_id', 'rep_date', 'rating' );
|
||||
@@ -165,7 +209,7 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'activitystats' )->contentCell( $item );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
}
|
||||
@@ -173,12 +217,18 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
);
|
||||
}
|
||||
|
||||
if( $activeTab == 'givers' OR $activeTab == 'getters' )
|
||||
{
|
||||
$formHtml = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'stats' ), 'filtersFormTemplate' ) );
|
||||
$chart = \IPS\Theme::i()->getTemplate( 'activitystats', 'core' )->repWrapper( $formHtml, \count( $contentWhere ), (string) $chart );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_reactions');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reactions" ), 'tab', '', 'ipsPad' );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Search 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 20 Dec 2019
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Statistics
|
||||
*/
|
||||
class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Default limit to number of graphed results
|
||||
*/
|
||||
protected $defaultLimit = 25;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'search_stats_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* View search statistics
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
/* Show button to adjust settings */
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'icon' => 'cog',
|
||||
'primary' => TRUE,
|
||||
'title' => 'manage_searchstats',
|
||||
'link' => \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=search&do=settings' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('settings') )
|
||||
);
|
||||
|
||||
/* 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';
|
||||
|
||||
foreach( $this->getTerms( $chart->searchTerm ) as $v )
|
||||
{
|
||||
$chart->addSeries( $v, 'number', 'COUNT(*)', FALSE );
|
||||
}
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('search_stats_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=search' ), array( array( 'type=?', 'search' ) ) );
|
||||
$table->langPrefix = 'searchstats_';
|
||||
$table->quickSearch = 'value_4';
|
||||
|
||||
/* Columns we need */
|
||||
$table->include = array( 'value_4', 'value_2', 'time' );
|
||||
$table->mainColumn = 'value_4';
|
||||
|
||||
$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();
|
||||
}
|
||||
);
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_search');
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table, TRUE, 'ipsPad ipsSpacer_top' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @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( '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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'stats_search_prune', \IPS\Settings::i()->stats_search_prune, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplog__statssearch_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=search' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'settings', $form, FALSE );
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\admin\activitystats;
|
||||
|
||||
/* 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 _tags extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user