Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,33 +12,52 @@
|
||||
namespace IPS\blog\Blog;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\blog\Blog;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Table\Table as TableHelper;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog Table Helper
|
||||
*/
|
||||
class _Table extends \IPS\Helpers\Table\Table
|
||||
class Table extends TableHelper
|
||||
{
|
||||
/**
|
||||
* @brief Container
|
||||
*/
|
||||
protected $container;
|
||||
protected ?Model $container = NULL;
|
||||
|
||||
/**
|
||||
* @brief Where clauses
|
||||
*/
|
||||
public ?array $where;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\Http\Url $url Base URL
|
||||
* @param Url|null $url Base URL
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( \IPS\Http\Url $url=NULL )
|
||||
public function __construct( Url $url=NULL )
|
||||
{
|
||||
/* Init */
|
||||
parent::__construct( $url );
|
||||
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'browse', 'blog' ), 'rows' );
|
||||
$this->rowsTemplate = array( Theme::i()->getTemplate( 'browse', 'blog' ), 'rows' );
|
||||
|
||||
/* Set available sort options */
|
||||
foreach ( array( 'last_edate', 'rating_total', 'num_views' ) as $k )
|
||||
@@ -55,44 +74,40 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
/**
|
||||
* Set owner
|
||||
*
|
||||
* @param \IPS\Member $member The member to filter by
|
||||
* @param Member $member The member to filter by
|
||||
* @return void
|
||||
*/
|
||||
public function setOwner( \IPS\Member $member )
|
||||
public function setOwner( Member $member ) : void
|
||||
{
|
||||
$this->where[] = array( '(' . \IPS\Db::i()->findInSet( 'blog_groupblog_ids', $member->groups ) . ' OR ' . 'blog_member_id=? )', $member->member_id );
|
||||
$this->where[] = array( '(' . Db::i()->findInSet( 'blog_groupblog_ids', $member->groups ) . ' OR ' . 'blog_member_id=? )', $member->member_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rows
|
||||
*
|
||||
* @param array $advancedSearchValues Values from the advanced search form
|
||||
* @param array|null $advancedSearchValues Values from the advanced search form
|
||||
* @return array
|
||||
*/
|
||||
public function getRows( $advancedSearchValues )
|
||||
public function getRows( array $advancedSearchValues = NULL ): array
|
||||
{
|
||||
/* Init */
|
||||
$class = "IPS\\blog\\Blog";
|
||||
$subquery = NULL;
|
||||
|
||||
/* Check sortBy */
|
||||
$this->sortBy = \in_array( $this->sortBy, $this->sortOptions ) ? $this->sortBy : 'blog_name';
|
||||
$this->sortBy = in_array( $this->sortBy, $this->sortOptions ) ? $this->sortBy : 'blog_name';
|
||||
|
||||
/* What are we sorting by? */
|
||||
$sortBy = 'blog_pinned DESC, ' . $this->sortBy . ' ' . ( mb_strtolower( $this->sortDirection ) == 'asc' ? 'asc' : 'desc' );
|
||||
$sortBy = 'blog_pinned DESC, ' . $this->sortBy . ' ' . ( ( $this->sortDirection and mb_strtolower( $this->sortDirection ) == 'asc' ) ? 'asc' : 'desc' );
|
||||
|
||||
/* Specify filter in where clause */
|
||||
$where = isset( $this->where ) ? \is_array( $this->where ) ? $this->where : array( $this->where ) : array();
|
||||
$where = isset( $this->where ) ? is_array( $this->where ) ? $this->where : array( $this->where ) : array();
|
||||
$where[] = array( 'blog_disabled=0' );
|
||||
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 ] );
|
||||
}
|
||||
|
||||
/* Exclude private blogs unless we have permission to view them */
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
if ( Member::loggedIn()->member_id )
|
||||
{
|
||||
$where[] = array( '( blog_social_group IS NULL OR blog_member_id=? OR blog_social_group IN(?) )', \IPS\Member::loggedIn()->member_id, \IPS\Db::i()->select( 'group_id', 'core_sys_social_group_members', array( 'member_id=?', \IPS\Member::loggedIn()->member_id ) ) );
|
||||
$where[] = array( '( blog_social_group IS NULL OR blog_member_id=? OR blog_social_group IN(?) )', Member::loggedIn()->member_id, Db::i()->select( 'group_id', 'core_sys_social_group_members', array( 'member_id=?', Member::loggedIn()->member_id ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -100,21 +115,21 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
}
|
||||
|
||||
/* Exclude club blogs unless we have permission to view them */
|
||||
if ( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
if ( Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
if ( Member::loggedIn()->member_id )
|
||||
{
|
||||
$where[] = array(
|
||||
'( blog_club_id IS NULL OR blog_club_id IN(?) OR blog_club_id IN(?) )',
|
||||
\IPS\Db::i()->select( 'id', 'core_clubs', array( \IPS\Db::i()->in( 'type', array( \IPS\Member\Club::TYPE_PUBLIC, \IPS\Member\Club::TYPE_OPEN, \IPS\Member\Club::TYPE_READONLY ) ) ) ),
|
||||
\IPS\Db::i()->select( 'club_id', 'core_clubs_memberships', array( "member_id=? AND status IN('" . \IPS\Member\Club::STATUS_MEMBER . "','" . \IPS\Member\Club::STATUS_MODERATOR . "','" . \IPS\Member\Club::STATUS_LEADER . "')", \IPS\Member::loggedIn()->member_id ) ),
|
||||
Db::i()->select( 'id', 'core_clubs', array( Db::i()->in( 'type', array( Club::TYPE_PUBLIC, Club::TYPE_OPEN, Club::TYPE_READONLY ) ) ) ),
|
||||
Db::i()->select( 'club_id', 'core_clubs_memberships', array( "member_id=? AND status IN('" . Club::STATUS_MEMBER . "','" . Club::STATUS_MODERATOR . "','" . Club::STATUS_LEADER . "')", Member::loggedIn()->member_id ) ),
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array(
|
||||
'( blog_club_id IS NULL OR blog_club_id IN(?) )',
|
||||
\IPS\Db::i()->select( 'id', 'core_clubs', array( \IPS\Db::i()->in( 'type', array( \IPS\Member\Club::TYPE_PUBLIC, \IPS\Member\Club::TYPE_OPEN, \IPS\Member\Club::TYPE_READONLY ) ) ) ),
|
||||
Db::i()->select( 'id', 'core_clubs', array( Db::i()->in( 'type', array( Club::TYPE_PUBLIC, Club::TYPE_OPEN, Club::TYPE_READONLY ) ) ) ),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -124,16 +139,16 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
}
|
||||
|
||||
/* Get Count */
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*) as cnt', 'blog_blogs', $where )->first();
|
||||
$count = Db::i()->select( 'COUNT(*) as cnt', 'blog_blogs', $where )->first();
|
||||
$this->pages = ceil( $count / $this->limit );
|
||||
|
||||
/* Get results */
|
||||
$it = \IPS\Db::i()->select( '*', 'blog_blogs', $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ) );
|
||||
$it = Db::i()->select( '*', 'blog_blogs', $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ) );
|
||||
$rows = iterator_to_array( $it );
|
||||
|
||||
foreach( $rows as $index => $row )
|
||||
{
|
||||
$rows[ $index ] = \IPS\blog\Blog::constructFromData( $row );
|
||||
$rows[ $index ] = Blog::constructFromData( $row );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
@@ -146,7 +161,7 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
* @param array|NULL $advancedSearchValues Advanced search values
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders( $advancedSearchValues )
|
||||
public function getHeaders( array $advancedSearchValues=NULL ): array
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user