Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+194 -43
View File
@@ -11,7 +11,7 @@
namespace IPS\Helpers\Table;
/* 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;
@@ -101,7 +101,27 @@ class _Content extends Table
* @brief Array of item IDs the current $member has posted in
*/
public $contentPostedIn = array();
/**
* @brief Callback method to adjust rows
*/
protected $callback = NULL;
/**
* @brief Get first comment
*/
protected $getFirstComment = FALSE;
/**
* @brief Get follower count
*/
protected $getFollowerCount = FALSE;
/**
* @brief Get reactions for content item if supported
*/
protected $getReactions = FALSE;
/**
* Constructor
*
@@ -113,9 +133,12 @@ class _Content extends Table
* @param string|NULL $permCheck Permission key to check
* @param bool $honorPinned Show pinned topics at the top of the table
* @param bool $showMovedLinks Show moved links in the result set.
* @param NULL|callable $callback Method to call to prepare the returned rows
* @param bool $getFirstComment Get the first comment for this item
* @param bool $getFollowerCount Get the follower counts for this item
* @return void
*/
public function __construct( $class, \IPS\Http\Url $baseUrl, $where=NULL, \IPS\Node\Model $container=NULL, $includeHidden=\IPS\Content\Hideable::FILTER_AUTOMATIC, $permCheck='view', $honorPinned=TRUE, $showMovedLinks=FALSE )
public function __construct( $class, \IPS\Http\Url $baseUrl, $where=NULL, \IPS\Node\Model $container=NULL, $includeHidden=\IPS\Content\Hideable::FILTER_AUTOMATIC, $permCheck='view', $honorPinned=TRUE, $showMovedLinks=FALSE, $callback=NULL, $getFirstComment=FALSE, $getFollowerCount=FALSE, $getReactions=FALSE )
{
/* Init */
$this->include = array();
@@ -126,6 +149,10 @@ class _Content extends Table
$this->honorPinned = $honorPinned;
$this->showMovedLinks = $showMovedLinks;
$this->permCheck = $permCheck;
$this->callback = $callback;
$this->getFirstComment = $getFirstComment;
$this->getFollowerCount = $getFollowerCount;
$this->getReactions = $getReactions;
/* Init */
parent::__construct( $baseUrl );
@@ -155,15 +182,7 @@ class _Content extends Table
/* Set breadcrumb */
if ( \IPS\IPS::classUsesTrait( $container, 'IPS\Content\ClubContainer' ) and $club = $container->club() )
{
\IPS\core\FrontNavigation::$clubTabActive = TRUE;
\IPS\Output::i()->breadcrumb = array();
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=clubs&controller=directory', 'front', 'clubs_list' ), \IPS\Member::loggedIn()->language()->addToStack('module__core_clubs') );
\IPS\Output::i()->breadcrumb[] = array( $club->url(), $club->name );
if ( \IPS\Settings::i()->clubs_header == 'sidebar' )
{
\IPS\Output::i()->sidebar['contextual'] = \IPS\Theme::i()->getTemplate( 'clubs', 'core' )->header( $club, $container, 'sidebar' );
}
$club->setBreadcrumbs( $container );
}
else
{
@@ -171,16 +190,25 @@ class _Content extends Table
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( NULL, $container->_title );
}
\IPS\Output::i()->breadcrumb[] = array( NULL, $container->_title );
/* We do want the page in the canonical link otherwise Google won't index past page 1 */
$canonicalUrl = $baseUrl;
if ( $this->page > 1 )
{
$canonicalUrl = $canonicalUrl->setPage( $this->paginationKey, $this->page );
}
/* Meta tags */
\IPS\Output::i()->title = ( $this->page > 1 ) ? \IPS\Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( $container->metaTitle(), $this->page ) ) ) : $container->metaTitle();
\IPS\Output::i()->metaTags['title'] = $container->metaTitle();
\IPS\Output::i()->metaTags['description'] = $container->metaDescription();
\IPS\Output::i()->metaTags['og:title'] = $container->metaTitle();
\IPS\Output::i()->metaTags['og:description'] = $container->metaDescription();
\IPS\Output::i()->linkTags['canonical'] = (string) $baseUrl;
\IPS\Output::i()->linkTags['canonical'] = (string) $canonicalUrl;
}
/* Set available sort options */
@@ -188,9 +216,13 @@ class _Content extends Table
{
if ( isset( $class::$databaseColumnMap[ $k ] ) and !isset( $this->sortOptions[ $k ] ) )
{
$column = is_array( $class::$databaseColumnMap[ $k ] ) ? array_shift( $class::$databaseColumnMap[ $k ] ) : $class::$databaseColumnMap[ $k ];
$this->sortOptions[ $k ] = $class::$databasePrefix . $column;
$column = \is_array( $class::$databaseColumnMap[ $k ] ) ? $class::$databaseColumnMap[ $k ][0] : $class::$databaseColumnMap[ $k ];
/* In some circumstances `updated` and `last_comment` may be the same column, but we don't want two sort options */
if( !\in_array( $class::$databasePrefix . $column, $this->sortOptions ) )
{
$this->sortOptions[$k] = $class::$databasePrefix . $column;
}
}
}
if ( !$this->sortBy )
@@ -201,7 +233,7 @@ class _Content extends Table
}
elseif ( isset( $class::$databaseColumnMap['last_comment'] ) )
{
$this->sortBy = $class::$databaseTable . '.' . $class::$databasePrefix . ( is_array( $class::$databaseColumnMap['last_comment'] ) ? $class::$databaseColumnMap['last_comment'][0] : $class::$databaseColumnMap['last_comment'] );
$this->sortBy = $class::$databaseTable . '.' . $class::$databasePrefix . ( \is_array( $class::$databaseColumnMap['last_comment'] ) ? $class::$databaseColumnMap['last_comment'][0] : $class::$databaseColumnMap['last_comment'] );
}
else
{
@@ -233,7 +265,7 @@ class _Content extends Table
{
if ( isset( $class::$databaseColumnMap[ $k ] ) )
{
if ( is_array( $class::$databaseColumnMap[ $k ] ) )
if ( \is_array( $class::$databaseColumnMap[ $k ] ) )
{
$cols = $class::$databaseColumnMap[ $k ];
$defaultSort = $class::$databaseTable . '.' . $class::$databasePrefix . array_pop( $cols );
@@ -246,6 +278,24 @@ class _Content extends Table
}
}
/* If we are limiting to a single container, check to see if this user can view them */
if ( $this->container and $this->permCheck )
{
try
{
if ( ! $this->container->can( $this->permCheck ) )
{
$this->count = 0;
return array();
}
}
catch( \OutOfBoundsException $e )
{
$this->count = 0;
return array();
}
}
$compareSortBy = $this->sortBy;
$lookFor = $class::$databaseTable . '.' . $class::$databasePrefix;
@@ -253,38 +303,134 @@ class _Content extends Table
{
$compareSortBy = mb_substr( $this->sortBy, mb_strlen( $lookFor ) );
}
$this->sortBy = in_array( $compareSortBy, $this->sortOptions ) ? $this->sortBy :
if( $this->sortBy AND \in_array( $this->sortBy, $class::$databaseColumnMap ) )
{
$len = mb_strlen( $class::$databaseTable );
$this->sortBy = ( mb_substr( $this->sortBy, 0, $len ) == $class::$databaseTable ) ? $this->sortBy : $class::$databaseTable . '.' . $this->sortBy;
}
$this->sortBy = \in_array( $compareSortBy, $this->sortOptions ) ? $this->sortBy :
( array_key_exists( $compareSortBy, $this->sortOptions ) ? $this->sortOptions[ $compareSortBy ] : $defaultSort );
/* Callback? */
if ( $this->advancedSearchCallback and !empty( $advancedSearchValues ) )
{
$obj = $this;
call_user_func( $this->advancedSearchCallback, $obj, $advancedSearchValues );
$advancedSearchCallback = $this->advancedSearchCallback;
$advancedSearchCallback( $obj, $advancedSearchValues );
}
/* What are we sorting by? */
$sortBy = $this->sortBy . ' ' . ( mb_strtolower( $this->sortDirection ) == 'asc' ? 'asc' : 'desc' );
if ( in_array( 'IPS\Content\Pinnable', class_implements( $class ) ) and $this->honorPinned )
if ( \in_array( 'IPS\Content\Pinnable', class_implements( $class ) ) and $this->honorPinned )
{
$column = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['pinned'];
$sortBy = "{$column} DESC, {$sortBy}";
}
/* Specify filter in where clause */
$where = $this->where ? is_array( $this->where ) ? $this->where : array( $this->where ) : array();
$where = $this->where ? \is_array( $this->where ) ? $this->where : array( $this->where ) : array();
if ( $this->filter and isset( $this->filters[ $this->filter ] ) )
{
$where[] = is_array( $this->filters[ $this->filter ] ) ? $this->filters[ $this->filter ] : array( $this->filters[ $this->filter ] );
$where[] = \is_array( $this->filters[ $this->filter ] ) ? $this->filters[ $this->filter ] : array( $this->filters[ $this->filter ] );
}
/* Get results */
$this->count = $class::getItemsWithPermission( $where, $sortBy, NULL, $this->permCheck, $this->includeHiddenContent, 0, NULL, $this->joinContainer, $this->joinComments, $this->joinReviews, TRUE, $this->joins, FALSE, TRUE, TRUE, TRUE, $this->showMovedLinks );
$it = $class::getItemsWithPermission( $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ), $this->permCheck, $this->includeHiddenContent, 0, NULL, $this->joinContainer, $this->joinComments, $this->joinReviews, FALSE, $this->joins, FALSE, TRUE, TRUE, TRUE, $this->showMovedLinks );
$this->count = $class::getItemsWithPermission( $where, $sortBy, NULL, $this->permCheck, $this->includeHiddenContent, 0, NULL, $this->joinContainer, $this->joinComments, $this->joinReviews, TRUE, $this->joins, ( $this->container ) ? $this->container : FALSE, TRUE, TRUE, TRUE, $this->showMovedLinks );
$it = $class::getItemsWithPermission( $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ), $this->permCheck, $this->includeHiddenContent, 0, NULL, $this->joinContainer, $this->joinComments, $this->joinReviews, FALSE, $this->joins, ( $this->container ) ? $this->container : FALSE, TRUE, TRUE, TRUE, $this->showMovedLinks );
$this->pages = ceil( $this->count / $this->limit );
$rows = iterator_to_array( $it );
$idField = $class::$databaseColumnId;
if ( isset( $this->getFirstComment ) and isset( $class::$databaseColumnMap['first_comment_id'] ) and $class::$firstCommentRequired )
{
$commentIds = array();
$firstCommentField = $class::$databaseColumnMap['first_comment_id'];
foreach( $rows as $item )
{
$commentIds[ $item->$idField ] = $item->$firstCommentField;
}
if ( \count( $commentIds ) )
{
$commentClass = $class::$commentClass;
$commentField = $commentClass::$databaseColumnId;
$comments = array();
foreach( $commentClass::getItemsWithPermission( array( \IPS\Db::i()->in( $commentClass::$databasePrefix . $commentField, array_values( $commentIds ) ) ), NULL, $this->limit ) as $cObj )
{
$comments[ $cObj->$commentField ] = $cObj;
}
foreach( $rows as $id => $item )
{
if ( isset( $commentIds[ $item->$idField ] ) and isset( $comments[ $commentIds[ $item->$idField ] ] ) )
{
$rows[ $id ]->firstComment = $comments[ $commentIds[ $item->$idField ] ];
}
}
}
}
if ( $this->getFollowerCount and \in_array( 'IPS\Content\Followable', class_implements( $class ) ) )
{
$followers = array();
foreach( $class::followersCounts( $rows ) as $follow )
{
$followers[ $follow['follow_rel_id'] ] = $follow['count'];
}
foreach( $rows as $id => $item )
{
if ( isset( $followers[ $item->$idField ] ) )
{
$rows[ $id ]->followerCount = $followers[ $item->$idField ];
}
else
{
$rows[ $id ]->followerCount = 0;
}
}
}
if ( $this->getReactions and \IPS\IPS::classUsesTrait( $class, 'IPS\Content\Reactable' ) )
{
/* Get enabled reactions */
$reactions = array();
$itemIds = array();
foreach( $rows as $item )
{
$itemIds[] = $item->$idField;
}
foreach( \IPS\Db::i()->select( '*', 'core_reputation_index', array( 'rep_class=? AND ' . \IPS\Db::i()->in( 'item_id', $itemIds ), $class::$commentClass ) ) as $react )
{
$reactions[ $react['item_id'] ][] = $react;
}
foreach( $rows as $id => $item )
{
if ( isset( $reactions[ $item->$idField ] ) )
{
$rows[ $id ]->reputation = array();
foreach( $reactions[ $item->$idField ] as $itemRow )
{
$reputation[ $itemRow['member_id'] ] = $itemRow['reaction'];
}
$rows[ $id ]->reputation = $reputation;
}
else
{
$rows[ $id ]->reputation = array();
}
}
}
/* Pre load the contentPostedIn data to save separate DISTINCT queries later and a query for each unread item */
if ( isset( $class::$databaseColumnMap['container'] ) )
{
@@ -309,13 +455,18 @@ class _Content extends Table
catch( \OutOfRangeException $ex ) {}
}
}
/* Pull in extra data */
if ( method_exists( $class, 'tableGetRows' ) )
{
$class::tableGetRows( $rows );
}
if ( $this->callback != NULL and \is_callable( $this->callback ) )
{
$rows = \call_user_func( $this->callback, $rows );
}
/* Return */
return $rows;
}
@@ -513,7 +664,7 @@ class _Content extends Table
$params = array();
/* Permission check for the items we have specific actions for here, modActions will take care of permissions for the rest */
if( in_array( \IPS\Request::i()->modaction, array( 'hide', 'move', 'merge' ) ) )
if( \in_array( \IPS\Request::i()->modaction, array( 'hide', 'move', 'merge' ) ) )
{
$options = array();
$ids = array_keys( \IPS\Request::i()->moderate );
@@ -530,7 +681,7 @@ class _Content extends Table
}
/* The user doesn't have permission to perform the action on any of the content */
if ( !count( $options ) )
if ( !\count( $options ) )
{
throw new \OutOfRangeException;
}
@@ -543,7 +694,7 @@ class _Content extends Table
$params = $this->getMoveForm();
/* This is the form instead */
if( !is_array( $params ) )
if( !\is_array( $params ) )
{
return $params;
}
@@ -563,7 +714,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -571,7 +722,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
return;
}
@@ -580,7 +731,7 @@ class _Content extends Table
/* Merge: what's the master? */
if ( \IPS\Request::i()->modaction == 'merge' )
{
if ( count( $options ) === 1 )
if ( \count( $options ) === 1 )
{
foreach ( $options as $id => $title )
{
@@ -594,7 +745,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -602,7 +753,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
}
}
@@ -613,7 +764,7 @@ class _Content extends Table
$form->class = 'ipsForm_vertical';
$form->hiddenValues['modaction'] = 'merge';
$form->hiddenValues['moderate'] = \IPS\Request::i()->moderate;
$form->add( new \IPS\Helpers\Form\Radio( 'merge_master', NULL, TRUE, array( 'options' => $options, 'descriptions' => $descriptions ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'merge_master', NULL, TRUE, array( 'options' => $options, 'descriptions' => $descriptions, 'parse' => 'normal' ) ) );
if ( isset( $class::$databaseColumnMap['moved_to'] ) )
{
$form->add( new \IPS\Helpers\Form\Checkbox( 'move_keep_link' ) );
@@ -638,7 +789,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -646,7 +797,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
return;
}
@@ -704,7 +855,7 @@ class _Content extends Table
'url' => \IPS\Request::i()->url()->setQueryString( 'modaction', 'move' ),
'permissionCheck' => function( $node ) use ( $currentContainer, $class )
{
if( $currentContainer->id != $node->id )
if( !$currentContainer or $currentContainer->id != $node->id )
{
try
{
@@ -746,7 +897,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
{
@@ -754,7 +905,7 @@ class _Content extends Table
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
return;
}