Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

@@ -0,0 +1,191 @@
<?php
/**
* @brief Keyword Tracking
* @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 27 Mar 2017
*/
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;
}
/**
* Keyword Tracking
*/
class _keywords extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'keywords_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Show button to adjust settings */
\IPS\Output::i()->sidebar['actions']['settings'] = array(
'icon' => 'cog',
'primary' => TRUE,
'title' => 'manage_keywords',
'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'];
$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'];
$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 */
\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 );
}
/**
* Prune Settings
*
* @return void
*/
protected function settings()
{
$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') ) );
if ( $values = $form->values() )
{
$values['stats_keywords'] = json_encode( $values['stats_keywords'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplog__statskeywords_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=keywords' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'settings', $form, FALSE );
}
}
@@ -0,0 +1,157 @@
<?php
/**
* @brief memberactivity
* @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 23 Mar 2017
*/
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;
}
/**
* memberactivity
*/
class _memberactivity extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'memberactivity_manage' );
parent::execute();
}
/**
* Show a graph of user activity
*
* @return void
* @note Activity includes posting, following, reacting
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Callback(
\IPS\Http\Url::internal( 'app=core&module=activitystats&controller=memberactivity' ),
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' );
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = (string) $chart;
return;
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_memberactivity');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'stats' )->activitymessage();
\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();
$results = array_replace_recursive( $results, $this->getSqlResults( 'core_search_index', 'index_date_updated', 'index_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 = '%Y-%u';
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, \DateTimeZone::listIdentifiers() ) )
{
$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;
}
}