Version 4.7.23
This commit is contained in:
1 parent
7124a02564
commit
25ddeb65d6
1791 files changed
+76990
-44452
No files matched your search
@@ -11,8 +11,32 @@
|
||||
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\core\Statistics\Chart;
|
||||
use IPS\Member;
|
||||
use IPS\Theme;
|
||||
use IPS\Helpers\Table\Db as TableDb;
|
||||
use IPS\Session;
|
||||
use IPS\Db;
|
||||
use IPS\Task;
|
||||
use IPS\forums\Forum;
|
||||
use Exception;
|
||||
|
||||
use function defined;
|
||||
use function header;
|
||||
use function array_key_exists;
|
||||
|
||||
use const IPS\Helpers\Table\SEARCH_NODE;
|
||||
use const IPS\Helpers\Table\SEARCH_MEMBER;
|
||||
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
|
||||
/* 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 +45,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* solved
|
||||
*/
|
||||
class _solved extends \IPS\Dispatcher\Controller
|
||||
class _solved extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
@@ -40,7 +64,7 @@ class _solved extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'topics_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'topics_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -62,52 +86,176 @@ class _solved extends \IPS\Dispatcher\Controller
|
||||
$tabs = array(
|
||||
'time' => 'forums_solved_stats_time',
|
||||
'percentage' => 'forums_solved_stats_percentage',
|
||||
'solved' => 'stats_topics_tab_solved'
|
||||
'solved' => 'stats_topics_tab_solved',
|
||||
'groups' => 'stats_topics_tab_groups',
|
||||
'unsolved' => 'stats_topics_tab_unsolved'
|
||||
);
|
||||
|
||||
/* Show button to adjust settings */
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
Output::i()->sidebar['actions']['settings'] = array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'solved_stats_rebuild_button',
|
||||
'link' => \IPS\Http\Url::internal( 'app=forums&module=stats&controller=solved&do=rebuildStats' )->csrf(),
|
||||
'link' => Url::internal( 'app=forums&module=stats&controller=solved&do=rebuildStats' )->csrf(),
|
||||
'data' => array( 'confirm' => '' )
|
||||
);
|
||||
|
||||
\IPS\Request::i()->tab ??= 'time';
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'time';
|
||||
Request::i()->tab ??= 'time';
|
||||
$activeTab = ( isset( Request::i()->tab ) and array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'time';
|
||||
|
||||
$url = \IPS\Http\Url::internal( "app=forums&module=stats&controller=solved&tab={$activeTab}" );
|
||||
$chart = match( $activeTab ) {
|
||||
'percentage' => \IPS\core\Statistics\Chart::loadFromExtension( 'forums', 'PercentageSolved' )->getChart( $url ),
|
||||
'solved' => \IPS\core\Statistics\Chart::loadFromExtension( 'forums', 'SolvedByForum' )->getChart( $url ),
|
||||
default => \IPS\core\Statistics\Chart::loadFromExtension( 'forums', 'TimeSolved' )->getChart( $url )
|
||||
$url = Url::internal( "app=forums&module=stats&controller=solved&tab={$activeTab}" );
|
||||
$output = match( $activeTab ) {
|
||||
'percentage' => Chart::loadFromExtension( 'forums', 'PercentageSolved' )->getChart( $url ),
|
||||
'solved' => Chart::loadFromExtension( 'forums', 'SolvedByForum' )->getChart( $url ),
|
||||
'groups' => CHart::LoadFromExtension( 'forums', 'SolvedByGroup' )->getChart( $url ),
|
||||
'unsolved' => $this->_unsolved(),
|
||||
default => Chart::loadFromExtension( 'forums', 'TimeSolved' )->getChart( $url )
|
||||
};
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string)$chart;
|
||||
Output::i()->output = (string) $output;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'menu__forums_stats_solved' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string)$chart, \IPS\Http\Url::internal( "app=forums&module=stats&controller=solved" ), 'tab', '', 'ipsPad' );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'menu__forums_stats_solved' );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, Url::internal( "app=forums&module=stats&controller=solved" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsolved Topics
|
||||
*
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
*/
|
||||
protected function _unsolved(): TableDb
|
||||
{
|
||||
/* Load Forums into Memory */
|
||||
Forum::loadIntoMemory( NULL );
|
||||
|
||||
$table = new TableDb( 'forums_topics', Url::internal( "app=forums&module=stats&controller=solved&tab=unsolved" ), static::_unsolvedWHere() );
|
||||
$table->langPrefix = 'topics_noposts_';
|
||||
$table->include = array( 'tid', 'title', 'state', 'start_date', 'starter_id', 'views', 'forum_id', 'approved' );
|
||||
|
||||
$table->parsers = array(
|
||||
'title' => function( $val, $row )
|
||||
{
|
||||
/* Manually construct URL to save on queries */
|
||||
$url = Url::internal( "app=forums&module=forums&controller=topic&id={$row['tid']}", 'front', 'forums_topic', array( $row['title_seo'] ) );
|
||||
return Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $url, TRUE, $val );
|
||||
},
|
||||
'state' => function( $val )
|
||||
{
|
||||
return match( $val ) {
|
||||
'open' => Member::loggedIn()->language()->addToStack('open'),
|
||||
'closed' => Member::loggedIn()->language()->addToStack('locked')
|
||||
};
|
||||
},
|
||||
'start_date' => function( $val )
|
||||
{
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'starter_id' => function( $val, $row )
|
||||
{
|
||||
if ( $val )
|
||||
{
|
||||
$url = Url::internal( "app=core&module=members&controller=profile&id={$val}", 'front', 'profile', array( Friendly::seoTitle( $row['starter_name'] ) ) );
|
||||
return Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $url, TRUE, $row['starter_name'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $row['is_anon'] )
|
||||
{
|
||||
return Member::loggedIn()->language()->addToStack( 'post_anonymously_placename' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$guest = new Member;
|
||||
if ( $row['starter_name'] )
|
||||
{
|
||||
$guest->name = $row['starter_name'];
|
||||
}
|
||||
|
||||
return $guest->name;
|
||||
}
|
||||
}
|
||||
},
|
||||
'views' => function( $val )
|
||||
{
|
||||
return Member::loggedIn()->language()->formatNumber( $val );
|
||||
},
|
||||
'forum_id' => function( $val )
|
||||
{
|
||||
$forum = Forum::load( $val );
|
||||
if ( $club = $forum->club() )
|
||||
{
|
||||
$title = Member::loggedIn()->language()->addToStack( 'club_container_title', FALSE, array( 'sprintf' => array( $club->name, $forum->_title ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = $forum->_title;
|
||||
}
|
||||
|
||||
return Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $forum->url(), TRUE, $title );
|
||||
},
|
||||
'approved' => function( $val )
|
||||
{
|
||||
if ( $val )
|
||||
{
|
||||
return "✓";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "✗";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$table->filters = array(
|
||||
'open' => "state='open'",
|
||||
'locked' => "state='closed'",
|
||||
'approved' => "approved=1",
|
||||
'unapproved' => "approved=0"
|
||||
);
|
||||
|
||||
$table->advancedSearch['forum_id'] = array( SEARCH_NODE, array( 'class' => 'IPS\\forums\\Forum', 'clubs' => TRUE ) );
|
||||
$table->advancedSearch['starter_id'] = SEARCH_MEMBER;
|
||||
$table->advancedSearch['start_date'] = SEARCH_DATE_RANGE;
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Unsolved Topics Where Clause
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function _unsolvedWhere(): array
|
||||
{
|
||||
$where = array();
|
||||
$where[] = array( "topic_answered_pid=?", 0 ); // Looks weird, but this is the correct way to see topics with no replies.
|
||||
$where[] = array( "pinned=?", 0 );
|
||||
$where[] = array( "featured=?", 0 );
|
||||
$where[] = array( Db::i()->in( 'approved', array( 0, 1 ) ) );
|
||||
$where[] = array( Db::i()->in( 'forum_id', Db::i()->select( 'id', 'forums_forums' ) ) );
|
||||
$where[] = array( Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) );
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kick off a rebuild of the stats
|
||||
*
|
||||
*/
|
||||
public function rebuildStats()
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ) ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ) ) as $forum )
|
||||
{
|
||||
\IPS\Task::queue( 'forums', 'RebuildSolvedStats', array( 'forum_id' => $forum['id'] ) );
|
||||
Task::queue( 'forums', 'RebuildSolvedStats', array( 'forum_id' => $forum['id'] ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=forums&module=stats&controller=solved'), 'solved_stats_rebuild_started' );
|
||||
Output::i()->redirect( \IPS\Http\Url::internal('app=forums&module=stats&controller=solved'), 'solved_stats_rebuild_started' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,13 +267,13 @@ class _solved extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$validForumIds = [];
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
foreach( Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
{
|
||||
try
|
||||
{
|
||||
$validForumIds[ $forumId ] = \IPS\forums\Forum::load( $forumId );
|
||||
$validForumIds[ $forumId ] = Forum::load( $forumId );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return $validForumIds;
|
||||
|
||||
Reference in new issue
Block a user