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
@@ -11,100 +11,126 @@
|
||||
namespace IPS\core\modules\front\discover;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\Content\Reaction;
|
||||
use IPS\Content\Search\ContentFilter;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\Content\Search\Query;
|
||||
use IPS\Content\Search\Results;
|
||||
use IPS\core\DataLayer;
|
||||
use IPS\Data\Store;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\DateRange;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Platform\Bridge;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function array_slice;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function is_numeric;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Most popular things
|
||||
*/
|
||||
class _popular extends \IPS\Dispatcher\Controller
|
||||
class popular extends Controller
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
/* Ensure that the rep system is enabled and the leaderboard is enabled */
|
||||
if ( ! \IPS\Settings::i()->reputation_enabled or ! \IPS\Settings::i()->reputation_leaderboard_on )
|
||||
if ( ! Settings::i()->reputation_enabled or ! Settings::i()->reputation_leaderboard_on )
|
||||
{
|
||||
\IPS\Output::i()->error( 'module_no_permission', '2C343/1', 403, '' );
|
||||
Output::i()->error( 'module_no_permission', '2C343/1', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/search.css' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/leaderboard.css' ) );
|
||||
|
||||
if ( \IPS\Theme::i()->settings['responsive'] )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/search_responsive.css' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/leaderboard_responsive.css' ) );
|
||||
}
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'styles/search.css' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'styles/leaderboard.css' ) );
|
||||
|
||||
/* Make sure default tab is first */
|
||||
$tabs = array( \IPS\Settings::i()->reputation_leaderboard_default_tab );
|
||||
$tabs = array( Settings::i()->reputation_leaderboard_default_tab );
|
||||
|
||||
foreach( array( 'leaderboard', 'history', 'members' ) as $addTab )
|
||||
{
|
||||
if ( $addTab != \IPS\Settings::i()->reputation_leaderboard_default_tab )
|
||||
if ( $addTab != Settings::i()->reputation_leaderboard_default_tab )
|
||||
{
|
||||
$tabs[] = $addTab;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \IPS\Application::appIsEnabled('cloud') and \IPS\cloud\Application::trendingIsEnabled( alwaysOn: FALSE ) )
|
||||
if ( Application::appIsEnabled('cloud') and \IPS\cloud\Application::featureIsEnabled('trending') )
|
||||
{
|
||||
$tabs[] = 'trending';
|
||||
}
|
||||
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and \in_array(\IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : \IPS\Settings::i()->reputation_leaderboard_default_tab;
|
||||
$activeTab = ( isset( Request::i()->tab ) and in_array(Request::i()->tab, $tabs ) ) ? Request::i()->tab : Settings::i()->reputation_leaderboard_default_tab;
|
||||
|
||||
/* Initiate the breadcrumb */
|
||||
\IPS\Output::i()->breadcrumb = array( array( \IPS\Http\Url::internal( "app=core&module=discover&controller=popular&tab=" . $activeTab, 'front', 'leaderboard_' . $activeTab ), \IPS\Member::loggedIn()->language()->addToStack('leaderboard_title') ) );
|
||||
Output::i()->breadcrumb = array( array( Url::internal( "app=core&module=discover&controller=popular&tab=" . $activeTab, 'front', 'leaderboard_' . $activeTab ), Member::loggedIn()->language()->addToStack('leaderboard_title') ) );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_tabs_' . $activeTab );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'leaderboard_tabs_' . $activeTab );
|
||||
|
||||
$content = $this->$activeTab();
|
||||
|
||||
/* Data Layer Context Property */
|
||||
if ( \IPS\Settings::i()->core_datalayer_enabled AND ! \IPS\Request::i()->isAjax() )
|
||||
if ( Settings::i()->core_datalayer_enabled AND ! Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\core\DataLayer::i()->addContextProperty( 'community_area', 'leaderboard', true );
|
||||
DataLayer::i()->addContextProperty( 'community_area', 'leaderboard' );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $content ), 200, 'text/html' );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $content ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('popular')->tabs( $tabs, $activeTab, $content );
|
||||
Output::i()->output = Theme::i()->getTemplate('popular')->tabs( $tabs, $activeTab, $content );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* View top members
|
||||
*
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
protected function members()
|
||||
protected function members() : string
|
||||
{
|
||||
/* Get filters */
|
||||
$filters = array_merge( array( 'overview' => \IPS\Member::loggedIn()->language()->addToStack('overview') ), \IPS\Member::topMembersOptions( \IPS\Member::TOP_MEMBERS_FILTERS ) );
|
||||
$filters = array_merge( array( 'overview' => Member::loggedIn()->language()->addToStack('overview') ), Member::topMembersOptions( Member::TOP_MEMBERS_FILTERS ) );
|
||||
$activeFilter = 'overview';
|
||||
if ( isset( \IPS\Request::i()->filter ) )
|
||||
if ( isset( Request::i()->filter ) )
|
||||
{
|
||||
if ( array_key_exists( \IPS\Request::i()->filter, $filters ) )
|
||||
if ( array_key_exists( Request::i()->filter, $filters ) )
|
||||
{
|
||||
$activeFilter = \IPS\Request::i()->filter;
|
||||
$activeFilter = Request::i()->filter;
|
||||
}
|
||||
else
|
||||
{
|
||||
$possibleFilter = 'IPS\\' . str_replace( '_', '\\', \IPS\Request::i()->filter );
|
||||
$possibleFilter = 'IPS\\' . str_replace( '_', '\\', Request::i()->filter );
|
||||
if ( array_key_exists( $possibleFilter, $filters ) )
|
||||
{
|
||||
$activeFilter = $possibleFilter;
|
||||
@@ -115,80 +141,80 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
/* Get results */
|
||||
if ( $activeFilter == 'overview' )
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('popular')->topMembersOverview( \IPS\Member::topMembersOptions( \IPS\Member::TOP_MEMBERS_OVERVIEW ) );
|
||||
$output = Theme::i()->getTemplate('popular')->topMembersOverview( Member::topMembersOptions( Member::TOP_MEMBERS_OVERVIEW ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('popular')->topMembersResults( $activeFilter, NULL, \IPS\Member::topMembers( $activeFilter, \IPS\Settings::i()->reputation_max_members ) );
|
||||
$output = Theme::i()->getTemplate('popular')->topMembersResults( $activeFilter, NULL, Member::topMembers( $activeFilter, Settings::i()->reputation_max_members ) );
|
||||
}
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) \IPS\Http\Url::internal( "app=core&module=discover&controller=popular&tab=members", 'front', 'leaderboard_members' );
|
||||
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->topMembers )
|
||||
Output::i()->linkTags['canonical'] = (string) Url::internal( "app=core&module=discover&controller=popular&tab=members", 'front', 'leaderboard_members' );
|
||||
if ( Request::i()->isAjax() and Request::i()->topMembers )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'rows' => $output, 'extraHtml' => $filters[ $activeFilter ] ) );
|
||||
Output::i()->json( array( 'rows' => $output, 'extraHtml' => $filters[ $activeFilter ] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('popular')->topMembers( \IPS\Http\Url::internal( 'app=core&module=discover&controller=popular&tab=members', 'front', 'leaderboard_members' ), $filters, $activeFilter, $output );
|
||||
return Theme::i()->getTemplate('popular')->topMembers( Url::internal( 'app=core&module=discover&controller=popular&tab=members', 'front', 'leaderboard_members' ), $filters, $activeFilter, $output );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* View past leaders
|
||||
*
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
protected function history()
|
||||
protected function history() : string
|
||||
{
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_reputation_leaderboard_history', \IPS\Http\Url::internal( "app=core&module=discover&controller=popular&tab=history", 'front', 'leaderboard_history' ) );
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_reputation_leaderboard_history', Url::internal( "app=core&module=discover&controller=popular&tab=history", 'front', 'leaderboard_history' ) );
|
||||
$table->where = array( 'leader_position <= 3' );
|
||||
$table->limit = 21;
|
||||
$table->limit = 60;
|
||||
$table->selects = array( 'leader_member_id, leader_position, leader_rep_total', 'ABS(leader_date - leader_position) as leader_date' );
|
||||
$table->joins = array( array( 'select' => 'core_members.*', 'from' => 'core_members', 'where' => 'core_reputation_leaderboard_history.leader_member_id=core_members.member_id' ) );
|
||||
$table->include = array( 'leader_member_id', 'leader_date', 'leader_position', 'leader_rep_total' );
|
||||
$table->noSort = array( 'leader_member_id', 'leader_position', 'leader_rep_total' );
|
||||
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'popular', 'core', 'front' ), 'popularTable' );
|
||||
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'popular', 'core', 'front' ), 'popularRows' );
|
||||
$table->tableTemplate = array( Theme::i()->getTemplate( 'popular', 'core', 'front' ), 'popularTable' );
|
||||
$table->rowsTemplate = array( Theme::i()->getTemplate( 'popular', 'core', 'front' ), 'popularRows' );
|
||||
$table->title = 'leaderboard_history';
|
||||
$table->mainColumn = 'leader_date';
|
||||
$table->sortBy = $table->sortBy ?: 'leader_date';
|
||||
$table->sortDirection = $table->sortDirection ?: 'DESC';
|
||||
|
||||
/* Like or what? */
|
||||
if ( \IPS\Content\Reaction::isLikeMode() )
|
||||
if ( Reaction::isLikeMode() )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['leader_rep_total'] = \IPS\Member::loggedIn()->language()->addToStack( 'leader_rep_total_likes' );
|
||||
\IPS\Member::loggedIn()->language()->words['leaderboard_history__desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_history_desc', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_history_likes') ) ) );
|
||||
Member::loggedIn()->language()->words['leader_rep_total'] = Member::loggedIn()->language()->addToStack( 'leader_rep_total_likes' );
|
||||
Member::loggedIn()->language()->words['leaderboard_history__desc'] = Member::loggedIn()->language()->addToStack( 'leaderboard_history_desc', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( 'leaderboard_history_likes') ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['leader_rep_total'] = \IPS\Member::loggedIn()->language()->addToStack( 'leader_rep_total_rep' );
|
||||
\IPS\Member::loggedIn()->language()->words['leaderboard_history__desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_history_desc', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_history_rep') ) ) );
|
||||
Member::loggedIn()->language()->words['leader_rep_total'] = Member::loggedIn()->language()->addToStack( 'leader_rep_total_rep' );
|
||||
Member::loggedIn()->language()->words['leaderboard_history__desc'] = Member::loggedIn()->language()->addToStack( 'leaderboard_history_desc', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( 'leaderboard_history_rep') ) ) );
|
||||
}
|
||||
|
||||
/* Parsers */
|
||||
$table->parsers = array(
|
||||
'leader_member_id' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Member::constructFromData( $row );
|
||||
return Member::constructFromData( $row );
|
||||
},
|
||||
'leader_date' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val )->setTimezone( new \DateTimeZone( \IPS\Settings::i()->reputation_timezone ) );
|
||||
return DateTime::ts( $val )->setTimezone( new DateTimeZone( Settings::i()->reputation_timezone ) );
|
||||
}
|
||||
);
|
||||
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) \IPS\Http\Url::internal( "app=core&module=discover&controller=popular&tab=history", 'front', 'leaderboard_history' );
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
Output::i()->linkTags['canonical'] = (string) Url::internal( "app=core&module=discover&controller=popular&tab=history", 'front', 'leaderboard_history' );
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $table ), 200, 'text/html' );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $table ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $table->page > 1 )
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( \IPS\Output::i()->title, $table->page ) ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( Output::i()->title, $table->page ) ) );
|
||||
}
|
||||
|
||||
return (string) $table;
|
||||
@@ -204,28 +230,28 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
* 3) Fetch the search engine data and then...
|
||||
* 4) Manually sort in PHP
|
||||
*
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
protected function leaderboard()
|
||||
protected function leaderboard() : string
|
||||
{
|
||||
/* Figure out dates */
|
||||
$dates = array();
|
||||
$timezone = new \DateTimeZone( \IPS\Settings::i()->reputation_timezone );
|
||||
$endDate = \IPS\DateTime::ts( time() )->setTimezone( $timezone );
|
||||
$timezone = new DateTimeZone( Settings::i()->reputation_timezone );
|
||||
$endDate = DateTime::ts( time() )->setTimezone( $timezone );
|
||||
|
||||
$firstRepDate = \IPS\Db::i()->select( 'MIN(rep_date)', 'core_reputation_index' )->first();
|
||||
$firstIndexDate = \IPS\Content\Search\Index::i()->firstIndexDate();
|
||||
$firstRepDate = intval( Db::i()->select( 'MIN(rep_date)', 'core_reputation_index' )->first() );
|
||||
$firstIndexDate = intval( Index::i()->firstIndexDate() );
|
||||
$appWhere = null;
|
||||
$descApp = \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_in_all_apps' );
|
||||
$descApp = Member::loggedIn()->language()->addToStack( 'leaderboard_in_all_apps' );
|
||||
|
||||
$dates[ 'oldest' ] = \IPS\DateTime::ts( ( $firstRepDate > $firstIndexDate ) ? $firstRepDate : $firstIndexDate );
|
||||
$dates[ 'oldest' ] = DateTime::ts( ( $firstRepDate > $firstIndexDate ) ? $firstRepDate : $firstIndexDate );
|
||||
$oldestStamp = $dates[ 'oldest' ]->getTimeStamp();
|
||||
$date = $dates[ 'oldest' ];
|
||||
|
||||
$aYearAgo = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P1Y' ) );
|
||||
$month = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P1M' ) )->setTime( 0, 0 );
|
||||
$week = \IPS\DateTime::create()->setTimezone( $timezone )->sub( new \DateInterval( 'P7D' ) )->setTime( 0, 0 );
|
||||
$today = \IPS\DateTime::create()->setTimezone( $timezone )->setTime( 0, 0 );
|
||||
$aYearAgo = DateTime::create()->setTimezone( $timezone )->sub( new DateInterval( 'P1Y' ) );
|
||||
$month = DateTime::create()->setTimezone( $timezone )->sub( new DateInterval( 'P1M' ) )->setTime( 0, 0 );
|
||||
$week = DateTime::create()->setTimezone( $timezone )->sub( new DateInterval( 'P7D' ) )->setTime( 0, 0 );
|
||||
$today = DateTime::create()->setTimezone( $timezone )->setTime( 0, 0 );
|
||||
|
||||
if ( $aYearAgo->getTimeStamp() > $oldestStamp )
|
||||
{
|
||||
@@ -248,20 +274,20 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Got a date? */
|
||||
if ( isset( \IPS\Request::i()->time ) and isset( $dates[ \IPS\Request::i()->time ] ) )
|
||||
if ( isset( Request::i()->time ) and isset( $dates[ Request::i()->time ] ) )
|
||||
{
|
||||
$date = $dates[ \IPS\Request::i()->time ];
|
||||
$date = $dates[ Request::i()->time ];
|
||||
}
|
||||
else if ( isset( $dates[ 'month' ] ) )
|
||||
{
|
||||
/* Set the default to month */
|
||||
\IPS\Request::i()->time = 'month';
|
||||
Request::i()->time = 'month';
|
||||
$date = $dates[ 'month' ];
|
||||
}
|
||||
|
||||
/* Applications */
|
||||
$classes = array();
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'ContentRouter', TRUE ) as $object )
|
||||
foreach ( Application::allExtensions( 'core', 'ContentRouter' ) as $object )
|
||||
{
|
||||
$classes = array_merge( $object->classes, $classes );
|
||||
}
|
||||
@@ -272,70 +298,69 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
$commentClass = NULL;
|
||||
$reviewClass = NULL;
|
||||
|
||||
if ( \IPS\IPS::classUsesTrait( $item, 'IPS\Content\Reactable' ) )
|
||||
if ( IPS::classUsesTrait( $item, 'IPS\Content\Reactable' ) )
|
||||
{
|
||||
$areas[ $item::$application . '-' . $item::reactionType() ] = array( $item, \IPS\Member::loggedIn()->language()->addToStack( "{$item::$title}_pl" ) );
|
||||
$areas[ $item::$application . '-' . $item::reactionType() ] = array( $item, Member::loggedIn()->language()->addToStack( "{$item::$title}_pl" ) );
|
||||
}
|
||||
|
||||
if ( $item::supportsComments( \IPS\Member::loggedIn() ) and $commentClass = $item::$commentClass and \IPS\IPS::classUsesTrait( $commentClass, 'IPS\Content\Reactable' ) )
|
||||
if ( $item::supportsComments( Member::loggedIn() ) and $commentClass = $item::$commentClass and IPS::classUsesTrait( $commentClass, 'IPS\Content\Reactable' ) )
|
||||
{
|
||||
$commentClass = $item::$commentClass;
|
||||
$supportsComments = \IPS\IPS::classUsesTrait( $commentClass, 'IPS\Content\Reactable' ) and $item::supportsComments( \IPS\Member::loggedIn() );
|
||||
$supportsComments = IPS::classUsesTrait( $commentClass, 'IPS\Content\Reactable' ) and $item::supportsComments( Member::loggedIn() );
|
||||
if ( $supportsComments )
|
||||
{
|
||||
$areas[ $item::$application . '-' . $commentClass::reactionType() ] = array( $commentClass, \IPS\Member::loggedIn()->language()->addToStack( "{$commentClass::$title}_pl" ) );
|
||||
$areas[ $item::$application . '-' . $commentClass::reactionType() ] = array( $commentClass, Member::loggedIn()->language()->addToStack( "{$commentClass::$title}_pl" ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $item::supportsReviews( \IPS\Member::loggedIn() ) and $reviewClass = $item::$reviewClass and \IPS\IPS::classUsesTrait( $reviewClass, 'IPS\Content\Reactable' ) )
|
||||
if ( $item::supportsReviews( Member::loggedIn() ) and $reviewClass = $item::$reviewClass and IPS::classUsesTrait( $reviewClass, 'IPS\Content\Reactable' ) )
|
||||
{
|
||||
$areas[ $item::$application . '-' . $reviewClass::reactionType() ] = array( $reviewClass, \IPS\Member::loggedIn()->language()->addToStack( "{$reviewClass::$title}_pl" ) );
|
||||
$areas[ $item::$application . '-' . $reviewClass::reactionType() ] = array( $reviewClass, Member::loggedIn()->language()->addToStack( "{$reviewClass::$title}_pl" ) );
|
||||
}
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'popular_date', 'continue' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$customStart = ( isset( \IPS\Request::i()->custom_date_start ) and \is_numeric( \IPS\Request::i()->custom_date_start ) ) ? (int) \IPS\Request::i()->custom_date_start : NULL;
|
||||
$customEnd = ( isset( \IPS\Request::i()->custom_date_end ) and \is_numeric( \IPS\Request::i()->custom_date_end ) ) ? (int) \IPS\Request::i()->custom_date_end : NULL;
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'custom_date', array( 'start' => $customStart, 'end' => $customEnd ), FALSE, array( 'start' => array( 'min' => $dates[ 'oldest' ], 'time' => false ) ) ) );
|
||||
$form = new Form( 'popular_date', 'continue' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--leaderboard';
|
||||
$customStart = ( isset( Request::i()->custom_date_start ) and is_numeric( Request::i()->custom_date_start ) ) ? (int) Request::i()->custom_date_start : NULL;
|
||||
$customEnd = ( isset( Request::i()->custom_date_end ) and is_numeric( Request::i()->custom_date_end ) ) ? (int) Request::i()->custom_date_end : NULL;
|
||||
|
||||
$form->add( new DateRange( 'custom_date', array( 'start' => $customStart, 'end' => $customEnd ), FALSE, array( 'start' => array( 'min' => $dates[ 'oldest' ], 'time' => false ) ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$url = \IPS\Request::i()->url()->stripQueryString( 'time' );
|
||||
$url = Request::i()->url()->stripQueryString( 'time' );
|
||||
|
||||
if ( isset( $values[ 'custom_date' ][ 'start' ] ) and $values[ 'custom_date' ][ 'start' ] instanceof \IPS\DateTime )
|
||||
if ( isset( $values[ 'custom_date' ][ 'start' ] ) and $values[ 'custom_date' ][ 'start' ] instanceof DateTime )
|
||||
{
|
||||
$url = $url->setQueryString( 'custom_date_start', $values[ 'custom_date' ][ 'start' ]->getTimeStamp() );
|
||||
}
|
||||
|
||||
if ( isset( $values[ 'custom_date' ][ 'end' ] ) and $values[ 'custom_date' ][ 'end' ] instanceof \IPS\DateTime )
|
||||
if ( isset( $values[ 'custom_date' ][ 'end' ] ) and $values[ 'custom_date' ][ 'end' ] instanceof DateTime )
|
||||
{
|
||||
$url = $url->setQueryString( 'custom_date_end', $values[ 'custom_date' ][ 'end' ]->getTimeStamp() );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
Output::i()->redirect( $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $customStart )
|
||||
{
|
||||
$date = \IPS\DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 );
|
||||
$date = DateTime::ts( $customStart )->setTimezone( $timezone )->setTime( 0, 0, 1 );
|
||||
}
|
||||
|
||||
if ( $customEnd )
|
||||
{
|
||||
$endDate = \IPS\DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 );
|
||||
$endDate = DateTime::ts( $customEnd )->setTimezone( $timezone )->setTime( 23, 59, 59 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Do we want results for a specific app */
|
||||
$customApp = FALSE;
|
||||
|
||||
if ( isset( \IPS\Request::i()->in ) and isset( $areas[ \IPS\Request::i()->in ] ) )
|
||||
if ( isset( Request::i()->in ) and isset( $areas[ Request::i()->in ] ) )
|
||||
{
|
||||
$appWhere = " AND rep_class='" . \IPS\Db::i()->escape_string( $areas[ \IPS\Request::i()->in ][ 0 ] ) . "'";
|
||||
$descApp = \IPS\Member::loggedIn()->language()->addToStack( 'leaderboard_in_app', FALSE, array( 'sprintf' => array( $areas[ \IPS\Request::i()->in ][ 1 ] ) ) );
|
||||
$appWhere = " AND rep_class='" . Db::i()->escape_string( $areas[ Request::i()->in ][ 0 ] ) . "'";
|
||||
$descApp = Member::loggedIn()->language()->addToStack( 'leaderboard_in_app', FALSE, array( 'sprintf' => array( $areas[ Request::i()->in ][ 1 ] ) ) );
|
||||
$customApp = TRUE;
|
||||
}
|
||||
else
|
||||
@@ -346,18 +371,18 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
$repAreas[] = $area[0] ;
|
||||
}
|
||||
|
||||
$appWhere = " AND " . \IPS\Db::i()->in( 'rep_class', $repAreas );
|
||||
$appWhere = " AND " . Db::i()->in( 'rep_class', $repAreas );
|
||||
}
|
||||
|
||||
$storeKey = NULL;
|
||||
$hashes = NULL;
|
||||
if ( ! $customStart and ! $customEnd AND ! $customApp )
|
||||
{
|
||||
$storeKey = 'leaderHashes_' . \IPS\Request::i()->time . '-' . md5( implode( ',', \IPS\Member::loggedIn()->groups ) );
|
||||
$storeKey = 'leaderHashes_' . Request::i()->time . '-' . md5( implode( ',', Member::loggedIn()->groups ) );
|
||||
|
||||
if ( isset( \IPS\Data\Store::i()->$storeKey ) )
|
||||
if ( isset( Store::i()->$storeKey ) )
|
||||
{
|
||||
$stored = \IPS\Data\Store::i()->$storeKey;
|
||||
$stored = Store::i()->$storeKey;
|
||||
|
||||
if ( isset( $stored['hashes'] ) and isset( $stored['time'] ) and $stored['time'] > ( time() - 900 ) )
|
||||
{
|
||||
@@ -372,22 +397,22 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
/* Prevent race condition */
|
||||
if ( $storeKey )
|
||||
{
|
||||
\IPS\Data\Store::i()->$storeKey = array( 'time' => time(), 'hashes' => array() );
|
||||
Store::i()->$storeKey = array( 'time' => time(), 'hashes' => array() );
|
||||
}
|
||||
|
||||
/* Get rep hashes */
|
||||
$inner = \IPS\Db::i()->select( 'class_type_id_hash, SUM(rep_rating) as total_rep', array( 'core_reputation_index', 'x' ), array( 'rep_date BETWEEN ' . $date->getTimeStamp() . ' AND ' . $endDate->getTimeStamp() . $appWhere ), NULL, NULL, 'class_type_id_hash' );
|
||||
$repHashes = iterator_to_array( \IPS\Db::i()->select( 'class_type_id_hash, total_rep', $inner, NULL, 'x.total_rep desc', array( 0, 500 ) )->setKeyField('class_type_id_hash') );
|
||||
$inner = Db::i()->select( 'class_type_id_hash, SUM(rep_rating) as total_rep', array( 'core_reputation_index', 'x' ), array( 'rep_date BETWEEN ' . $date->getTimeStamp() . ' AND ' . $endDate->getTimeStamp() . $appWhere ), NULL, NULL, 'class_type_id_hash' );
|
||||
$repHashes = iterator_to_array( Db::i()->select( 'class_type_id_hash, total_rep', $inner, NULL, 'x.total_rep desc', array( 0, 500 ) )->setKeyField('class_type_id_hash') );
|
||||
|
||||
/* Now filter through permissions */
|
||||
$searchHashes = \IPS\Content\Search\Index::i()->hashesWithPermission( array_keys( $repHashes ), \IPS\Member::loggedIn(), 500 );
|
||||
$searchHashes = Index::i()->hashesWithPermission( array_keys( $repHashes ), Member::loggedIn(), 500 );
|
||||
|
||||
/* Filter out rep hashes not in search results */
|
||||
$hashes = \array_slice( array_intersect_key( $repHashes, $searchHashes ), 0, 50 );
|
||||
$hashes = array_slice( array_intersect_key( $repHashes, $searchHashes ), 0, 50 );
|
||||
|
||||
if ( $storeKey )
|
||||
{
|
||||
\IPS\Data\Store::i()->$storeKey = array( 'time' => time(), 'hashes' => $hashes );
|
||||
Store::i()->$storeKey = array( 'time' => time(), 'hashes' => $hashes );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,10 +422,10 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
$results = array();
|
||||
$preLoadMembers = array();
|
||||
|
||||
if ( \count( $hashes ) )
|
||||
if ( count( $hashes ) )
|
||||
{
|
||||
/* Now get the reputation data */
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_reputation_index', array( \IPS\Db::i()->in( 'class_type_id_hash', array_keys( $hashes ) ) ) ) as $data )
|
||||
foreach( Db::i()->select( '*', 'core_reputation_index', array( Db::i()->in( 'class_type_id_hash', array_keys( $hashes ) ) ) ) as $data )
|
||||
{
|
||||
$data['total_rep'] = $hashes[ $data['class_type_id_hash'] ]['total_rep'];
|
||||
$repData[ $data['rep_class'] . '-' . $data['type_id'] ] = $data;
|
||||
@@ -409,12 +434,12 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
|
||||
foreach( $classes as $class => $ids )
|
||||
{
|
||||
$or[] = \IPS\Content\Search\ContentFilter::initWithSpecificClass( $class )->onlyInIds( $ids );
|
||||
$or[] = ContentFilter::initWithSpecificClass( $class )->onlyInIds( $ids );
|
||||
}
|
||||
|
||||
/* Query and manually sort */
|
||||
$sorted = array();
|
||||
$search = \IPS\Content\Search\Query::init();
|
||||
$search = Query::init();
|
||||
|
||||
/* Set the result to get as 50, as we pass in 50 unique hashes and the default is only 25, which means some may be missed as they are not sorted by rep count until after fetching */
|
||||
$search->resultsToGet = 50;
|
||||
@@ -432,7 +457,7 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
unset( $array );
|
||||
krsort( $sorted, SORT_NUMERIC );
|
||||
|
||||
$results = new \IPS\Content\Search\Results( $sorted, \count( $sorted ) );
|
||||
$results = new Results( $sorted, count( $sorted ) );
|
||||
|
||||
/* Load data we need like the authors, etc */
|
||||
$results->init();
|
||||
@@ -442,40 +467,40 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
$topContributors = array();
|
||||
|
||||
$innerQueryWhere = array();
|
||||
$innerQueryWhere[] = array( 'member_received>0 ' . $appWhere . ' and rep_date BETWEEN ' . \intval( $date->getTimeStamp() ) . ' AND ' . \intval( $endDate->getTimeStamp() ) );
|
||||
$innerQueryWhere[] = array( 'member_received>0 ' . $appWhere . ' and rep_date BETWEEN ' . $date->getTimeStamp() . ' AND ' . $endDate->getTimeStamp() );
|
||||
|
||||
if( \IPS\Settings::i()->leaderboard_excluded_groups )
|
||||
if( Settings::i()->leaderboard_excluded_groups )
|
||||
{
|
||||
$innerQueryWhere[] = \IPS\Db::i()->in( 'member_group_id', explode( ',', \IPS\Settings::i()->leaderboard_excluded_groups ), TRUE );
|
||||
$innerQueryWhere[] = Db::i()->in( 'member_group_id', explode( ',', Settings::i()->leaderboard_excluded_groups ), TRUE );
|
||||
|
||||
$innerQuery = \IPS\Db::i()->select( 'core_reputation_index.member_received as themember, SUM(rep_rating) as rep', 'core_reputation_index', $innerQueryWhere, NULL, NULL, 'themember' )->join( 'core_members', array( 'core_reputation_index.member_received = core_members.member_id' ) );
|
||||
$innerQuery = Db::i()->select( 'core_reputation_index.member_received as themember, SUM(rep_rating) as rep', 'core_reputation_index', $innerQueryWhere, NULL, NULL, 'themember' )->join( 'core_members', array( 'core_reputation_index.member_received = core_members.member_id' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$innerQuery = \IPS\Db::i()->select( 'core_reputation_index.member_received as themember, SUM(rep_rating) as rep', 'core_reputation_index', $innerQueryWhere, NULL, NULL, 'themember' );
|
||||
$innerQuery = Db::i()->select( 'core_reputation_index.member_received as themember, SUM(rep_rating) as rep', 'core_reputation_index', $innerQueryWhere, NULL, NULL, 'themember' );
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'themember, rep', array( $innerQuery, 'in' ), NULL, 'rep DESC', 4 )->setKeyField('themember')->setValueField('rep') as $member => $rep )
|
||||
foreach( Db::i()->select( 'themember, rep', array( $innerQuery, 'in' ), NULL, 'rep DESC', 4 )->setKeyField('themember')->setValueField('rep') as $member => $rep )
|
||||
{
|
||||
$topContributors[ $member ] = $rep;
|
||||
}
|
||||
|
||||
if ( \count( $topContributors ) )
|
||||
if ( count( $topContributors ) )
|
||||
{
|
||||
$preLoadMembers = array_merge( $preLoadMembers, array_keys( $topContributors ) );
|
||||
}
|
||||
|
||||
/* Load their data */
|
||||
if ( \count( $preLoadMembers ) )
|
||||
if ( count( $preLoadMembers ) )
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_members', \IPS\Db::i()->in( 'member_id', array_unique( $preLoadMembers ) ) ) as $member )
|
||||
foreach ( Db::i()->select( '*', 'core_members', Db::i()->in( 'member_id', array_unique( $preLoadMembers ) ) ) as $member )
|
||||
{
|
||||
\IPS\Member::constructFromData( $member );
|
||||
Member::constructFromData( $member );
|
||||
}
|
||||
}
|
||||
|
||||
/* Work out the description for popular content */
|
||||
if ( \IPS\Content\Reaction::isLikeMode() )
|
||||
if ( Reaction::isLikeMode() )
|
||||
{
|
||||
$popularResultsSingle = 'popular_results_single_desc';
|
||||
$popularResultsMany = 'popular_results_desc';
|
||||
@@ -486,28 +511,33 @@ class _popular extends \IPS\Dispatcher\Controller
|
||||
$popularResultsMany = 'popular_results_desc_rep';
|
||||
}
|
||||
|
||||
$description = \IPS\Member::loggedIn()->language()->addToStack( ( $date->localeDate() == $endDate->localeDate() ) ? $popularResultsSingle : $popularResultsMany, NULL, array( 'sprintf' => array( $date->localeDate(), $descApp ) ) );
|
||||
$description = Member::loggedIn()->language()->addToStack( ( $date->localeDate() == $endDate->localeDate() ) ? $popularResultsSingle : $popularResultsMany, NULL, array( 'sprintf' => array( $date->localeDate(), $descApp ) ) );
|
||||
|
||||
/* Are our offsets different? */
|
||||
$tzOffsetDifference = NULL;
|
||||
try
|
||||
{
|
||||
if ( \IPS\DateTime::ts( time() )->getOffset() != \IPS\DateTime::ts( time() )->setTimezone( $timezone )->getOffset() )
|
||||
if ( DateTime::ts( time() )->getOffset() != DateTime::ts( time() )->setTimezone( $timezone )->getOffset() )
|
||||
{
|
||||
$tzOffsetDifference = \IPS\DateTime::ts( time() )->setTimezone( $timezone )->format('P');
|
||||
$tzOffsetDifference = DateTime::ts( time() )->setTimezone( $timezone )->format('P');
|
||||
}
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( Exception $ex ) { }
|
||||
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) \IPS\Http\Url::internal( "app=core&module=discover&controller=popular&tab=leaderboard", 'front', 'leaderboard_leaderboard' );
|
||||
Output::i()->linkTags['canonical'] = (string) Url::internal( "app=core&module=discover&controller=popular&tab=leaderboard", 'front', 'leaderboard_leaderboard' );
|
||||
|
||||
/* If there are no results tell search engines not to index the page */
|
||||
if( !\count( $results ) )
|
||||
if( !count( $results ) )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['robots'] = 'noindex';
|
||||
Output::i()->metaTags['robots'] = 'noindex';
|
||||
}
|
||||
|
||||
/* Display */
|
||||
return \IPS\Theme::i()->getTemplate('popular')->popularWrapper( $results, $areas, $topContributors, $dates, $description, $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ), $tzOffsetDifference );
|
||||
return Theme::i()->getTemplate('popular')->popularWrapper( $results, $areas, $topContributors, $dates, $description, $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) ), $tzOffsetDifference );
|
||||
}
|
||||
|
||||
protected function trending(): string
|
||||
{
|
||||
return Bridge::i()->popularTrending();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user