Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,49 +12,66 @@
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\Statistics\Chart;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\forums\Topic\Post;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\DateRange;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use Throwable;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* posts
|
||||
*/
|
||||
class _posts extends \IPS\Dispatcher\Controller
|
||||
class posts extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Allow MySQL RW separation for efficiency
|
||||
*/
|
||||
public static $allowRWSeparation = TRUE;
|
||||
public static bool $allowRWSeparation = TRUE;
|
||||
|
||||
/**
|
||||
* Show solved posts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function showSolvedPosts()
|
||||
protected function showSolvedPosts() : void
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_solved_index', \IPS\Http\Url::internal( 'app=forums&module=stats&controller=posts&do=showSolvedPosts' ), [ 'solved_date BETWEEN ? AND ?', \IPS\Request::i()->startTime, \IPS\Request::i()->endTime ] );
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_solved_index', Url::internal( 'app=forums&module=stats&controller=posts&do=showSolvedPosts' ), [ 'solved_date BETWEEN ? AND ? AND type=?', Request::i()->startTime, Request::i()->endTime, 'solved' ] );
|
||||
$table->quickSearch = NULL;
|
||||
$table->sortBy = $table->sortBy ?: 'solved_date';
|
||||
$table->sortDirection = $table->sortDirection ?: 'asc';
|
||||
$table->langPrefix = 'stats_posts_type_';
|
||||
$table->include = [ 'comment_id', 'solved_date' ];
|
||||
$table->widths = array( 'solved_date' => 25, 'comment_id' => 75 );
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'startTime' => \IPS\Request::i()->startTime, 'endTime' => \IPS\Request::i()->endTime, 'tab' => 'bytype' ) );
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'startTime' => Request::i()->startTime, 'endTime' => Request::i()->endTime, 'tab' => 'bytype' ) );
|
||||
|
||||
/* Custom parsers */
|
||||
$table->parsers = array(
|
||||
'solved_date' => function( $val, $row )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val )->html();
|
||||
return DateTime::ts( $val )->html();
|
||||
},
|
||||
'comment_id' => function( $val, $row )
|
||||
{
|
||||
@@ -64,16 +81,16 @@ class _posts extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$item = $class::load( $row['comment_id'] );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'activitystats', 'core' )->contentCell( $item );
|
||||
return Theme::i()->getTemplate( 'activitystats', 'core' )->contentCell( $item );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
catch ( Throwable $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
return Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global', 'core')->block( NULL, (string) $table, TRUE, 'ipsPad' );
|
||||
Output::i()->output = Theme::i()->getTemplate('global', 'core')->block( NULL, (string) $table, TRUE, 'i-padding_3' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,23 +98,23 @@ class _posts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function showRecommendedPosts()
|
||||
protected function showRecommendedPosts() : void
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_content_meta', \IPS\Http\Url::internal( 'app=forums&module=stats&controller=posts&do=showRecommendedPosts' ), [ 'meta_type=? AND meta_added BETWEEN ? AND ?', 'core_FeaturedComments', \IPS\Request::i()->startTime, \IPS\Request::i()->endTime ] );
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_content_meta', Url::internal( 'app=forums&module=stats&controller=posts&do=showRecommendedPosts' ), [ 'meta_type=? AND meta_added BETWEEN ? AND ?', 'core_FeaturedComments', Request::i()->startTime, Request::i()->endTime ] );
|
||||
$table->quickSearch = NULL;
|
||||
$table->sortBy = $table->sortBy ?: 'meta_added';
|
||||
$table->sortDirection = $table->sortDirection ?: 'asc';
|
||||
$table->langPrefix = 'stats_posts_type_';
|
||||
$table->include = [ 'meta_data', 'meta_added' ];
|
||||
$table->widths = array( 'meta_added' => 25, 'meta_data' => 75 );
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'startTime' => \IPS\Request::i()->startTime, 'endTime' => \IPS\Request::i()->endTime, 'tab' => 'bytype' ) );
|
||||
$table->baseUrl = $table->baseUrl->setQueryString( array( 'startTime' => Request::i()->startTime, 'endTime' => Request::i()->endTime, 'tab' => 'bytype' ) );
|
||||
|
||||
/* Custom parsers */
|
||||
$table->parsers = array(
|
||||
'meta_added' => function( $val, $row )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val )->html();
|
||||
return DateTime::ts( $val )->html();
|
||||
},
|
||||
'meta_data' => function( $val, $row )
|
||||
{
|
||||
@@ -105,18 +122,18 @@ class _posts extends \IPS\Dispatcher\Controller
|
||||
|
||||
try
|
||||
{
|
||||
$item = \IPS\forums\Topic\Post::load( $data['comment'] );
|
||||
$item = Post::load( $data['comment'] );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'activitystats', 'core' )->contentCell( $item );
|
||||
return Theme::i()->getTemplate( 'activitystats', 'core' )->contentCell( $item );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
catch ( Throwable $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
return Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global', 'core')->block( NULL, (string) $table, TRUE, 'ipsPad' );
|
||||
Output::i()->output = Theme::i()->getTemplate('global', 'core')->block( NULL, (string) $table, TRUE, 'i-padding_3' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,25 +141,25 @@ class _posts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'posts_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'posts_manage' );
|
||||
|
||||
$tabs = array( 'total' => 'stats_posts_tab_total', 'bytype' => 'stats_posts_by_type', 'byforum' => 'stats_posts_tab_byforum' );
|
||||
\IPS\Request::i()->tab ??= 'total';
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'total';
|
||||
Request::i()->tab ??= 'total';
|
||||
$activeTab = ( isset( Request::i()->tab ) and array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'total';
|
||||
|
||||
if ( $activeTab === 'bytype' )
|
||||
{
|
||||
$defaults = array( 'start' => \IPS\DateTime::create()->setDate( date('Y'), date('m'), 1 ), 'end' => new \IPS\DateTime );
|
||||
$defaults = array( 'start' => DateTime::create()->setDate( date('Y'), date('m'), 1 ), 'end' => new DateTime );
|
||||
|
||||
if( isset( \IPS\Request::i()->badgeDateStart ) AND isset( \IPS\Request::i()->badgeDateEnd ) )
|
||||
if( isset( Request::i()->badgeDateStart ) AND isset( Request::i()->badgeDateEnd ) )
|
||||
{
|
||||
$defaults = array( 'start' => \IPS\DateTime::ts( \IPS\Request::i()->badgeDateStart ), 'end' => \IPS\DateTime::ts( \IPS\Request::i()->badgeDateEnd ) );
|
||||
$defaults = array( 'start' => DateTime::ts( Request::i()->badgeDateStart ), 'end' => DateTime::ts( Request::i()->badgeDateEnd ) );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( $activeTab, 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'date', $defaults, TRUE ) );
|
||||
$form = new Form( $activeTab, 'continue' );
|
||||
$form->add( new DateRange( 'date', $defaults, TRUE ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
@@ -164,37 +181,38 @@ class _posts extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Get a count of solved posts in this time */
|
||||
$solvedCount = \IPS\Db::i()->select( 'count(*)', 'core_solved_index', [
|
||||
$solvedCount = Db::i()->select( 'count(*)', 'core_solved_index', [
|
||||
[ 'solved_date BETWEEN ? AND ?', $startTime, $endTime ],
|
||||
[ 'comment_class=?', 'IPS\forums\Topic\Post' ]
|
||||
[ 'comment_class=?', 'IPS\forums\Topic\Post' ],
|
||||
[ 'type=?', 'solved' ]
|
||||
] )->first();
|
||||
|
||||
/* Get a count of recommended posts in this time */
|
||||
$recommendedCount = \IPS\Db::i()->select( 'count(*)', 'core_content_meta', [
|
||||
$recommendedCount = Db::i()->select( 'count(*)', 'core_content_meta', [
|
||||
[ 'meta_added BETWEEN ? AND ?', $startTime, $endTime ],
|
||||
[ 'meta_type=?', 'core_FeaturedComments' ]
|
||||
] )->first();
|
||||
|
||||
$formHtml = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'stats', 'core' ), 'filtersFormTemplate' ) );
|
||||
$chart = \IPS\Theme::i()->getTemplate( 'stats', 'forums' )->statsTypeWrapper( $formHtml, $solvedCount, $recommendedCount, $startTime, $endTime );
|
||||
$formHtml = $form->customTemplate( array( Theme::i()->getTemplate( 'stats', 'core' ), 'filtersFormTemplate' ) );
|
||||
$chart = Theme::i()->getTemplate( 'stats', 'forums' )->statsTypeWrapper( $formHtml, $solvedCount, $recommendedCount, $startTime, $endTime );
|
||||
}
|
||||
else if ( $activeTab === 'total' )
|
||||
{
|
||||
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'forums', 'Posts' )->getChart( \IPS\Http\Url::internal( "app=forums&module=stats&controller=posts&tab={$activeTab}" ) );
|
||||
$chart = Chart::loadFromExtension( 'forums', 'Posts' )->getChart( Url::internal( "app=forums&module=stats&controller=posts&tab={$activeTab}" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'forums', 'PostsByForum' )->getChart( \IPS\Http\Url::internal( "app=forums&module=stats&controller=posts&tab={$activeTab}" ) );
|
||||
$chart = Chart::loadFromExtension( 'forums', 'PostsByForum' )->getChart( Url::internal( "app=forums&module=stats&controller=posts&tab={$activeTab}" ) );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__forums_stats_posts');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=forums&module=stats&controller=posts" ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__forums_stats_posts');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, Url::internal( "app=forums&module=stats&controller=posts" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user