Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -121,6 +121,11 @@ class _Content extends Table
|
||||
* @brief Get reactions for content item if supported
|
||||
*/
|
||||
protected $getReactions = FALSE;
|
||||
|
||||
/**
|
||||
* @brief If passing a container, limit content by that container
|
||||
*/
|
||||
protected $limitByContainer = TRUE;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -139,7 +144,7 @@ class _Content extends Table
|
||||
* @param bool $getReactions Get reactions 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, $callback=NULL, $getFirstComment=FALSE, $getFollowerCount=FALSE, $getReactions=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, $limitByContainer=TRUE )
|
||||
{
|
||||
/* Init */
|
||||
$this->include = array();
|
||||
@@ -154,7 +159,8 @@ class _Content extends Table
|
||||
$this->getFirstComment = $getFirstComment;
|
||||
$this->getFollowerCount = $getFollowerCount;
|
||||
$this->getReactions = $getReactions;
|
||||
|
||||
$this->limitByContainer = $limitByContainer;
|
||||
|
||||
/* Init */
|
||||
parent::__construct( $baseUrl );
|
||||
|
||||
@@ -163,7 +169,11 @@ class _Content extends Table
|
||||
/* Set container */
|
||||
if ( $container !== NULL )
|
||||
{
|
||||
$this->where[] = array( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['container'] . '=?', $container->_id );
|
||||
if ( $this->limitByContainer )
|
||||
{
|
||||
$this->where[] = array($class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['container'] . '=?', $container->_id);
|
||||
}
|
||||
|
||||
$this->sortDirection = ( $this->sortDirection !== NULL ) ? $this->sortDirection : $container->_sortOrder;
|
||||
|
||||
if ( !$this->sortBy and ! empty( $container->_sortBy ) )
|
||||
@@ -210,6 +220,7 @@ class _Content extends Table
|
||||
\IPS\Output::i()->metaTags['og:title'] = $container->metaTitle();
|
||||
\IPS\Output::i()->metaTags['og:description'] = $container->metaDescription();
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) $canonicalUrl;
|
||||
\IPS\Output::i()->metaTags['og:url'] = (string) $canonicalUrl;
|
||||
}
|
||||
|
||||
/* Set available sort options */
|
||||
@@ -280,7 +291,7 @@ 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 )
|
||||
if ( ( $this->container and $this->limitByContainer ) and $this->permCheck )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -338,8 +349,8 @@ class _Content extends Table
|
||||
}
|
||||
|
||||
/* Get results */
|
||||
$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->count = $class::getItemsWithPermission( $where, $sortBy, NULL, $this->permCheck, $this->includeHiddenContent, 0, NULL, $this->joinContainer, $this->joinComments, $this->joinReviews, TRUE, $this->joins, ( $this->container and $this->limitByContainer ) ? $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 and $this->limitByContainer ) ? $this->container : FALSE, TRUE, TRUE, TRUE, $this->showMovedLinks );
|
||||
$this->pages = ceil( $this->count / $this->limit );
|
||||
$rows = iterator_to_array( $it );
|
||||
$idField = $class::$databaseColumnId;
|
||||
@@ -347,19 +358,49 @@ class _Content extends Table
|
||||
|
||||
if ( isset( $this->getFirstComment ) and isset( $class::$databaseColumnMap['first_comment_id'] ) and $class::$firstCommentRequired )
|
||||
{
|
||||
|
||||
$commentIds = array();
|
||||
$archivedCommentIds = [];
|
||||
$firstCommentField = $class::$databaseColumnMap['first_comment_id'];
|
||||
|
||||
|
||||
foreach( $rows as $item )
|
||||
{
|
||||
$commentIds[ $item->$idField ] = $item->$firstCommentField;
|
||||
/* Get us the archived comment ids*/
|
||||
if ( isset( $class::$archiveClass ) and method_exists( $class, 'isArchived' ) AND $item->isArchived() )
|
||||
{
|
||||
$archivedCommentIds[ $item->$idField ] = $item->$firstCommentField;
|
||||
}
|
||||
else
|
||||
{
|
||||
$commentIds[ $item->$idField ] = $item->$firstCommentField;
|
||||
}
|
||||
}
|
||||
$comments = array();
|
||||
|
||||
if ( \count( $archivedCommentIds ) )
|
||||
{
|
||||
$archivedCommentClass = $class::$archiveClass;
|
||||
$commentField = $archivedCommentClass::$databaseColumnId;
|
||||
|
||||
foreach( $archivedCommentClass::getItemsWithPermission( array( \IPS\Db::i()->in( $archivedCommentClass::$databasePrefix . $commentField, array_values( $archivedCommentIds ) ) ), NULL, $this->limit ) as $cObj )
|
||||
{
|
||||
$comments[ $cObj->$commentField ] = $cObj;
|
||||
}
|
||||
|
||||
foreach( $rows as $id => $item )
|
||||
{
|
||||
if ( isset( $archivedCommentIds[ $item->$idField ] ) and isset( $comments[ $archivedCommentIds[ $item->$idField ] ] ) )
|
||||
{
|
||||
$rows[ $id ]->firstComment = $comments[ $archivedCommentIds[ $item->$idField ] ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ class _Custom extends Table
|
||||
* @param array $dataSource Data source
|
||||
* @param \IPS\Http\Url $baseUrl Base URL
|
||||
*/
|
||||
public function __construct( $dataSource, \IPS\Http\Url $baseUrl )
|
||||
public function __construct( $dataSource, \IPS\Http\Url $baseUrl, $count = NULL )
|
||||
{
|
||||
$this->dataSource = $dataSource;
|
||||
$this->count = \count( $this->dataSource );
|
||||
@@ -107,7 +107,7 @@ class _Custom extends Table
|
||||
}
|
||||
|
||||
/* Do we need to sort? */
|
||||
if( !empty( $rows ) and $this->sortBy and isset( $rows[ key( $rows ) ][ $this->sortBy ] ) )
|
||||
if( $this->parseSource and !empty( $rows ) and $this->sortBy and isset( $rows[ key( $rows ) ][ $this->sortBy ] ) )
|
||||
{
|
||||
$sortBy = $this->sortBy;
|
||||
$sortDirection = $this->sortDirection;
|
||||
@@ -125,7 +125,7 @@ class _Custom extends Table
|
||||
}
|
||||
|
||||
/* Limit */
|
||||
if ( $this->limit and $this->count > $this->limit )
|
||||
if ( $this->limit and $this->count > $this->limit and $this->parseSource )
|
||||
{
|
||||
$rows = \array_slice( $rows, ( $this->limit * ( $this->page - 1 ) ), $this->limit, TRUE );
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ class _Db extends Table
|
||||
*/
|
||||
public $keyField = NULL;
|
||||
|
||||
/**
|
||||
* @brief Group by key
|
||||
*/
|
||||
public $groupBy = NULL;
|
||||
|
||||
/**
|
||||
* @brief The database we will query against
|
||||
*/
|
||||
@@ -320,9 +325,10 @@ class _Db extends Table
|
||||
}
|
||||
}
|
||||
$count = $count->first();
|
||||
$selectPrefix = ( $this->groupBy ) ? '' : $this->table . '.*, ';
|
||||
|
||||
/* Now get column headers */
|
||||
$query = $this->db->select( ( \count( $selects ) ) ? $this->table . '.*, ' . implode( ', ', $selects ) : '*', $this->table, NULL, NULL, array( 0, 1 ) );
|
||||
$query = $this->db->select( ( \count( $selects ) ) ? $selectPrefix . implode( ', ', $selects ) : '*', $this->table, NULL, NULL, array( 0, 1 ), $this->groupBy );
|
||||
|
||||
if ( \count( $this->joins ) )
|
||||
{
|
||||
@@ -380,11 +386,12 @@ class _Db extends Table
|
||||
/* Run query */
|
||||
$rows = array();
|
||||
$select = $this->db->select(
|
||||
( \count( $selects ) ) ? $this->table . '.*, ' . implode( ', ', $selects ) : '*',
|
||||
( \count( $selects ) ) ? $selectPrefix . implode( ', ', $selects ) : '*',
|
||||
$this->table,
|
||||
$where,
|
||||
$orderBy,
|
||||
array( ( $this->limit * ( $this->page - 1 ) ), $limit )
|
||||
array( ( $this->limit * ( $this->page - 1 ) ), $limit ),
|
||||
$this->groupBy
|
||||
);
|
||||
|
||||
if ( $this->index )
|
||||
|
||||
@@ -138,6 +138,11 @@ abstract class _Table
|
||||
* @brief Language key for table title
|
||||
*/
|
||||
public $title = '';
|
||||
|
||||
/**
|
||||
* @brief Use realtime features within the table?
|
||||
*/
|
||||
public $enableRealtime = false;
|
||||
|
||||
/**
|
||||
* @brief Parsers
|
||||
@@ -609,7 +614,7 @@ abstract class _Table
|
||||
$return[ $k ] = $v->_id;
|
||||
}
|
||||
}
|
||||
else if( isset( $this->advancedSearch[ mb_substr( $k, mb_strlen( $this->langPrefix ) ) ] ) and $this->advancedSearch[ mb_substr( $k, mb_strlen( $this->langPrefix ) ) ] === \IPS\Helpers\Table\SEARCH_BOOL )
|
||||
else if( isset( $this->advancedSearch[ mb_substr( $k, mb_strlen( $this->langPrefix ) ) ][0] ) and $this->advancedSearch[ mb_substr( $k, mb_strlen( $this->langPrefix ) ) ][0] === \IPS\Helpers\Table\SEARCH_BOOL )
|
||||
{
|
||||
$return[ $k . '_checkbox' ] = $v;
|
||||
}
|
||||
@@ -618,6 +623,7 @@ abstract class _Table
|
||||
$return[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user