Version 4.7.23
This commit is contained in:
1 parent
7124a02564
commit
25ddeb65d6
1791 files changed
+76990
-44452
No files matched your search
@@ -633,23 +633,33 @@ class _settings extends \IPS\Dispatcher\Controller
|
||||
|
||||
$form->addHeader('topic_settings');
|
||||
|
||||
|
||||
$popularNowMaximum = 14400000;
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'forums_popular_now', json_decode( \IPS\Settings::i()->forums_popular_now, TRUE ), FALSE, array(
|
||||
'getHtml' => function( $obj ) use ( $popularNowMaximum )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('settings')->popularNow( $obj->name, $obj->value, $popularNowMaximum );
|
||||
},
|
||||
/* If popular now time is greater than 10,000 days */
|
||||
'validate' => function( $obj ) use ( $popularNowMaximum )
|
||||
{
|
||||
|
||||
if( isset( $obj->value['minutes'] ) AND $obj->value['minutes'] > $popularNowMaximum )
|
||||
/* We no longer use popular time for cloud */
|
||||
$popularNowMaximum = 14400000;
|
||||
if( !\IPS\CIC )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'forums_popular_now', json_decode( \IPS\Settings::i()->forums_popular_now, TRUE ), FALSE, array(
|
||||
'getHtml' => function( $obj ) use ( $popularNowMaximum )
|
||||
{
|
||||
throw new \LengthException( \IPS\Member::loggedIn()->language()->addToStack('form_number_max', FALSE, array( 'sprintf' => array( $popularNowMaximum ) ) ) );
|
||||
return \IPS\Theme::i()->getTemplate('settings')->popularNow( $obj->name, $obj->value, $popularNowMaximum );
|
||||
},
|
||||
/* If popular now time is greater than 10,000 days */
|
||||
'validate' => function( $obj ) use ( $popularNowMaximum )
|
||||
{
|
||||
|
||||
if( isset( $obj->value['minutes'] ) AND $obj->value['minutes'] > $popularNowMaximum )
|
||||
{
|
||||
throw new \LengthException( \IPS\Member::loggedIn()->language()->addToStack('form_number_max', FALSE, array( 'sprintf' => array( $popularNowMaximum ) ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
) ) );
|
||||
) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$popularSettings = json_decode( \IPS\Settings::i()->forums_popular_now, TRUE );
|
||||
\IPS\Member::loggedIn()->language()->words['forums_popular_now_desc'] = \IPS\Member::loggedIn()->language()->addToStack('forums_popular_now_cloud_desc');
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'forums_popular_now', $popularSettings['minutes'] ?? 0, FALSE, [ 'min' => 1, 'max' => $popularNowMaximum, 'valueAs' => \IPS\Helpers\Form\Interval::MINUTES, 'unlimitedLang' => 'never', 'unlimited' => 0 ], NULL, \IPS\Member::loggedIn()->language()->addToStack('forums_popular_now_cloud_prefix'), NULL ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'forums_posts_per_page', \IPS\Settings::i()->forums_posts_per_page , TRUE, array( 'min' => 2, 'max' => 250 ) ) );
|
||||
|
||||
@@ -686,14 +696,24 @@ class _settings extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/* This setting needs to be reversed */
|
||||
$values['forums_mod_actions_anon'] = !$values['forums_mod_actions_anon'];
|
||||
|
||||
if ( isset( $values['forums_popular_now']['never'] ) )
|
||||
if( array_key_exists( 'forums_popular_now', $values ) )
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( array( 'posts' => 0, 'minutes' => 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( $values['forums_popular_now'] );
|
||||
/* This is handled slightly different for Cloud */
|
||||
if( \IPS\CIC )
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( array( 'posts' => 0, 'minutes' => (int) $values['forums_popular_now'] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $values['forums_popular_now']['never'] ) )
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( array( 'posts' => 0, 'minutes' => 0 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$values['forums_popular_now'] = json_encode( $values['forums_popular_now'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['forums_default_view_choose'] ) )
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief solvers
|
||||
* @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
|
||||
* @subpackage Forums
|
||||
* @since 14 Dec 2023
|
||||
*/
|
||||
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Table\Db as TableDb;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Theme;
|
||||
use IPS\Output;
|
||||
|
||||
use function defined;
|
||||
use function header;
|
||||
|
||||
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
use const IPS\Helpers\Table\SEARCH_SELECT;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* solvers
|
||||
*/
|
||||
class _solvers extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Allow MySQL RW separation for efficiency
|
||||
*/
|
||||
public static $allowRWSeparation = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'solvers_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
$table = new TableDb( 'core_solved_index', Url::internal( "app=forums&module=stats&controller=solvers" ) );
|
||||
$table->langPrefix = 'top_solvers_';
|
||||
$table->groupBy = array( 'core_members.member_id', 'core_members.name', 'core_members.member_group_id' );
|
||||
$table->selects = array( 'COUNT(core_members.member_id) AS count', 'core_members.member_id', 'core_members.name', 'MAX(core_solved_index.solved_date) AS date', 'core_members.member_group_id' );
|
||||
$table->joins = array( array( 'from' => 'core_members', 'where' => 'core_solved_index.member_id=core_members.member_id', 'type' => 'RIGHT' ) );
|
||||
$table->include = array( 'name', 'count', 'date', 'member_group_id' );
|
||||
$table->parsers = array(
|
||||
'name' => function( $val, $row ) {
|
||||
return Theme::i()->getTemplate( 'global', 'core' )->userLinkWithPhoto( \IPS\Member::load( $row['member_id'] ) );
|
||||
},
|
||||
'count' => function( $val, $row ) {
|
||||
$url = Url::internal( "app=core&module=members&controller=profile&id={$row['member_id']}&do=solutions", 'front', 'profile_solutions', array( Friendly::seoTitle( $row['name'] ) ) );
|
||||
$count = Member::loggedIn()->language()->formatNumber( $val );
|
||||
return Theme::i()->getTemplate( 'global', 'core', 'global' )->basicUrl( $url, TRUE, $count );
|
||||
},
|
||||
'date' => function( $val ) {
|
||||
return (string) \IPS\DateTime::ts( $val );
|
||||
},
|
||||
'member_group_id' => function( $val ) {
|
||||
return \IPS\Member\Group::load( $val )->name;
|
||||
}
|
||||
);
|
||||
|
||||
$groups = array();
|
||||
foreach( \IPS\Member\Group::groups( showGuestGroups: FALSE ) AS $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
$table->advancedSearch['solved_date'] = SEARCH_DATE_RANGE;
|
||||
$table->advancedSearch['member_group_id'] = array( SEARCH_SELECT, array( 'options' => $groups, 'multiple' => TRUE, 'noDefault' => TRUE ) );
|
||||
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'top_solvers' );
|
||||
Output::i()->output = (string) $table;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,29 @@
|
||||
|
||||
namespace IPS\forums\modules\admin\stats;
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Db;
|
||||
use IPS\Request;
|
||||
use IPS\core\Statistics\Chart;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Output;
|
||||
use IPS\Member;
|
||||
use IPS\Theme;
|
||||
use IPS\Helpers\Table\Db as TableDb;
|
||||
use IPS\forums\Forum;
|
||||
|
||||
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 +42,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* topics
|
||||
*/
|
||||
class _topics extends \IPS\Dispatcher\Controller
|
||||
class _topics extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
@@ -40,28 +61,157 @@ class _topics extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'topics_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'topics_manage' );
|
||||
|
||||
$tabs = array( 'total' => 'stats_topics_tab_total' );
|
||||
|
||||
if( \IPS\Db::i()->select( 'COUNT(*)', 'forums_forums', array( 'topics>?', 0 ) )->first() )
|
||||
if( Db::i()->select( 'COUNT(*)', 'forums_forums', array( 'topics>?', 0 ) )->first() )
|
||||
{
|
||||
$tabs[ 'byforum'] = 'stats_topics_tab_byforum';
|
||||
$tabs['byforum'] = 'stats_topics_tab_byforum';
|
||||
}
|
||||
|
||||
if ( Db::i()->select( 'COUNT(*)', 'forums_topics', static::_noPostsWhere() )->first() )
|
||||
{
|
||||
$tabs['noposts'] = 'stats_topics_tab_noposts';
|
||||
}
|
||||
|
||||
\IPS\Request::i()->tab ??= 'total';
|
||||
$activeTab = ( array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'total';
|
||||
Request::i()->tab ??= 'total';
|
||||
$activeTab = ( array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'total';
|
||||
|
||||
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'forums', ( $activeTab === 'total' ) ? 'Topics' : 'TopicsByForum' )->getChart( \IPS\Http\Url::internal( "app=forums&module=stats&controller=topics&tab={$activeTab}" ) );
|
||||
$output = match( $activeTab ) {
|
||||
'total' => Chart::loadFromExtension( 'forums', 'Topics' )->getChart( Url::internal( "app=forums&module=stats&controller=topics&tab=total" ) ),
|
||||
'byforum' => Chart::loadFromExtension( 'forums', 'TopicsByForum' )->getChart( Url::internal( "app=forums&module=stats&controller=topics&tab=byforum" ) ),
|
||||
'noposts' => $this->_noPostsTable()
|
||||
};
|
||||
|
||||
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_topics');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=forums&module=stats&controller=topics" ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__forums_stats_topics');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $output, Url::internal( "app=forums&module=stats&controller=topics" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Topics with No Posts Table
|
||||
*
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
*/
|
||||
protected function _noPostsTable(): TableDb
|
||||
{
|
||||
/* Load Forums into Memory */
|
||||
Forum::loadIntoMemory( NULL );
|
||||
|
||||
$table = new TableDb( 'forums_topics', Url::internal( "app=forums&module=stats&controller=topics&tab=noposts" ), static::_noPostsWhere() );
|
||||
$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 No Posts Where Clause
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function _noPostsWhere(): array
|
||||
{
|
||||
$where = array();
|
||||
$where[] = array( "posts=?", 1 ); // 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;
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ class _forums extends \IPS\Dispatcher\Controller
|
||||
|
||||
$hasModOptions = false;
|
||||
|
||||
$canHide = ( \IPS\Member::loggedIn()->group['g_hide_own_posts'] == '1' or \in_array( 'IPS\forums\Topics', explode( ',', \IPS\Member::loggedIn()->group['g_hide_own_posts'] ) ) );
|
||||
$canHide = ( \IPS\Member::loggedIn()->group['g_hide_own_posts'] == '1' or \in_array( 'IPS\forums\Topic', explode( ',', \IPS\Member::loggedIn()->group['g_hide_own_posts'] ) ) );
|
||||
if ( \IPS\forums\Topic::modPermission( 'lock', NULL, $forum ) or
|
||||
\IPS\forums\Topic::modPermission( 'pin', NULL, $forum ) or
|
||||
\IPS\forums\Topic::modPermission( 'hide', NULL, $forum ) or
|
||||
|
||||
@@ -116,7 +116,6 @@ class _index extends \IPS\Dispatcher\Controller
|
||||
if ( \IPS\forums\Forum::isSimpleView() )
|
||||
{
|
||||
$where = array();
|
||||
|
||||
if ( \IPS\forums\Forum::customPermissionNodes() )
|
||||
{
|
||||
$where = array( 'container' => array( array( 'forums_forums.password IS NULL' ) ) );
|
||||
@@ -142,6 +141,7 @@ class _index extends \IPS\Dispatcher\Controller
|
||||
/* Inline forum IDs? */
|
||||
if ( \count( $ids ) )
|
||||
{
|
||||
$toUnset = [];
|
||||
foreach( $ids as $id )
|
||||
{
|
||||
try
|
||||
@@ -163,7 +163,16 @@ class _index extends \IPS\Dispatcher\Controller
|
||||
$forumIds[] = $forum->id;
|
||||
}
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( \Exception $ex ) {
|
||||
$toUnset[] = $id;
|
||||
}
|
||||
}
|
||||
/* Redirect to a page with valid forum ids */
|
||||
if( $ids and count($forumIds ) AND $toUnset )
|
||||
{
|
||||
$newUrl = $this->url;
|
||||
$newUrl = $newUrl->setQueryString( 'forumId', implode( ',', array_diff( $ids, $toUnset ) ) );
|
||||
\IPS\Output::i()->redirect( $newUrl );
|
||||
}
|
||||
|
||||
if ( \count( $forumIds ) )
|
||||
|
||||
@@ -354,7 +354,7 @@ class _topic extends \IPS\Content\Controller
|
||||
}
|
||||
|
||||
/* Sidebar? */
|
||||
if ( $topic->showSummaryOnDesktop() == 'sidebar' )
|
||||
if ( !$topic->isArchived() AND $topic->showSummaryOnDesktop() == 'sidebar' )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'topics' )->activity( $topic, 'sidebar' );
|
||||
}
|
||||
@@ -372,7 +372,10 @@ class _topic extends \IPS\Content\Controller
|
||||
/* Add Json-LD */
|
||||
$isQuestion = ( $topic->isQuestion() or $topic->isSolved() );
|
||||
|
||||
if ( $isQuestion )
|
||||
/* The purpose of QAPage is to provide data on the question and suggested answer (if avaiable), or all comments if there is no answer.
|
||||
However, a very large topic that has not been solved, is likely to confuse Google ("The QAPage type indicates that the page is focused on a specific question and its answer(s)"),
|
||||
so if the topic is very long, we will only show this metadata if the topic has been solved. */
|
||||
if ( $isQuestion and ( $topic->posts < \IPS\LARGE_TOPIC_REPLIES or $topic->isSolved() ) )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['topic'] = array(
|
||||
'@context' => "http://schema.org",
|
||||
@@ -381,17 +384,23 @@ class _topic extends \IPS\Content\Controller
|
||||
'url' => (string) $topic->url(),
|
||||
'mainEntity' => [
|
||||
'@type' => "Question",
|
||||
'answerCount' => $topic->posts ? $topic->posts - 1 : 0,
|
||||
'name' => $topic->title,
|
||||
'text' => $topic->comments( 1, 0 )->truncated( TRUE, NULL ),
|
||||
'answerCount' => $topic->posts ? $topic->posts - 1 : 0,
|
||||
'dateCreated' => \IPS\DateTime::ts( $topic->start_date )->format( \IPS\DateTime::ISO8601 ),
|
||||
'author' => [
|
||||
'@type' => 'Person',
|
||||
'name' => $topic->author()->name
|
||||
'@type' => 'Person',
|
||||
'name' => $topic->author()->name,
|
||||
'image' => $topic->author()->get_photo( TRUE, TRUE )
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
if( $topic->author()->member_id )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['topic']['mainEntity']['author']['url'] = (string) $topic->author()->url();
|
||||
}
|
||||
|
||||
if( $topic->topic_answered_pid )
|
||||
{
|
||||
try
|
||||
@@ -437,6 +446,32 @@ class _topic extends \IPS\Content\Controller
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
}
|
||||
else if ( $topic->posts > 1 )
|
||||
{
|
||||
/* We have no accepted answer, but we have replies, so google still wants to see here some meta data, so let's show the last comment https://developers.google.com/search/docs/appearance/structured-data/qapage#answercount */
|
||||
try
|
||||
{
|
||||
$lastComment = $topic->comments( 1, 0, 'date', 'desc' );
|
||||
|
||||
/* Set up our column names */
|
||||
$authorIdColumn = $lastComment::$databaseColumnMap['author'];
|
||||
$dateColumn = $lastComment::$databaseColumnMap['date'];
|
||||
|
||||
\IPS\Output::i()->jsonLd['topic']['mainEntity']['suggestedAnswer'] = array(
|
||||
'@type' => 'Answer',
|
||||
'text' => $lastComment->truncated( TRUE, NULL ),
|
||||
'url' => (string) $lastComment->url(),
|
||||
'dateCreated' => \IPS\DateTime::ts( $lastComment->$dateColumn )->format( \IPS\DateTime::ISO8601 ),
|
||||
'upvoteCount' => ( $topic->isArchived() ) ? $lastComment->field_int : $lastComment->post_field_int,
|
||||
'author' => array(
|
||||
'@type' => 'Person',
|
||||
'name' => \IPS\Member::load( $lastComment->$authorIdColumn )->name,
|
||||
'image' => \IPS\Member::load( $lastComment->$authorIdColumn )->get_photo( TRUE, TRUE )
|
||||
),
|
||||
);
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -587,15 +622,19 @@ class _topic extends \IPS\Content\Controller
|
||||
'@type' => 'InteractionCounter',
|
||||
'interactionType' => "http://schema.org/CommentAction",
|
||||
'userInteractionCount' => $topic->posts - 1 // We subtract one to account for the "first post"
|
||||
),
|
||||
array(
|
||||
'@type' => 'InteractionCounter',
|
||||
'interactionType' => "http://schema.org/FollowAction",
|
||||
'userInteractionCount' => $topic->followersCount()
|
||||
),
|
||||
)
|
||||
)
|
||||
), \IPS\Output::i()->jsonLd['topic'] );
|
||||
|
||||
if( !$topic->isArchived() )
|
||||
{
|
||||
\IPS\Output::i()->jsonLd['topic']['interactionStatistic'][] = [
|
||||
'@type' => 'InteractionCounter',
|
||||
'interactionType' => "http://schema.org/FollowAction",
|
||||
'userInteractionCount' => $topic->followersCount()
|
||||
];
|
||||
}
|
||||
|
||||
/* Add og:image meta tags */
|
||||
if( count( $file = $topic->imageAttachments(1 ) ) )
|
||||
{
|
||||
@@ -873,6 +912,7 @@ class _topic extends \IPS\Content\Controller
|
||||
}
|
||||
|
||||
/* Rebuild count */
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition added in 2fe7e3e434068a6a845106fbefd08821d05e60e4 */
|
||||
$question->question_rating = \IPS\Db::i()->select( 'SUM(rating)', 'forums_question_ratings', array( 'topic=?', $question->tid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$question->save();
|
||||
|
||||
@@ -898,13 +938,14 @@ class _topic extends \IPS\Content\Controller
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2F173/4', 404, '' );
|
||||
}
|
||||
|
||||
if ( !$answer->item()->can('read') or !$answer->canVote() )
|
||||
|
||||
$rating = \intval( \IPS\Request::i()->rating );
|
||||
|
||||
if ( !$answer->item()->can('read') or !$answer->canVote( $rating ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '2F173/5', 403, '' );
|
||||
}
|
||||
|
||||
$rating = \intval( \IPS\Request::i()->rating );
|
||||
|
||||
if ( $rating !== 1 and $rating !== -1 )
|
||||
{
|
||||
\IPS\Output::i()->error( 'form_bad_value', '2F173/6', 403, '' );
|
||||
@@ -927,6 +968,7 @@ class _topic extends \IPS\Content\Controller
|
||||
), TRUE );
|
||||
}
|
||||
|
||||
/* @note SELECT_FROM_WRITE_SERVER race condition added in 9f4aa84545f6f9838143253050520180dfce5ef2 */
|
||||
$answer->post_field_int = (int) \IPS\Db::i()->select( 'SUM(rating)', 'forums_answer_ratings', array( 'post=?', $answer->pid ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$answer->save();
|
||||
|
||||
@@ -1316,20 +1358,4 @@ class _topic extends \IPS\Content\Controller
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split Comment
|
||||
*
|
||||
* @param string $commentClass The comment/review class
|
||||
* @param \IPS\Content\Comment $comment The comment/review
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
*/
|
||||
protected function _split( $commentClass, $comment, $item )
|
||||
{
|
||||
parent::_split( $commentClass, $comment, $item );
|
||||
|
||||
$item->rebuildPopularTime();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user