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,73 +12,109 @@
|
||||
namespace IPS\gallery\Album;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use BadMethodCallException;
|
||||
use IPS\Content\ContentMenuLink;
|
||||
use IPS\Content\Embeddable;
|
||||
use IPS\Content\Filter;
|
||||
use IPS\Content\Hideable;
|
||||
use IPS\Content\Item as ContentItem;
|
||||
use IPS\Content\Lockable;
|
||||
use IPS\Content\MetaData;
|
||||
use IPS\Content\Featurable;
|
||||
use IPS\Content\Reactable;
|
||||
use IPS\Content\ReadMarkers;
|
||||
use IPS\Content\Reportable;
|
||||
use IPS\Content\Shareable;
|
||||
use IPS\Content\Statistics;
|
||||
use IPS\Content\ViewUpdates;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\gallery\Album;
|
||||
use IPS\gallery\Application;
|
||||
use IPS\gallery\Category;
|
||||
use IPS\gallery\Image;
|
||||
use IPS\Helpers\Menu;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function array_slice;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* File Model
|
||||
*/
|
||||
class _Item extends \IPS\Content\Item implements
|
||||
\IPS\Content\Permissions,
|
||||
\IPS\Content\ReadMarkers,
|
||||
\IPS\Content\Ratings,
|
||||
\IPS\Content\Searchable,
|
||||
\IPS\Content\Shareable,
|
||||
\IPS\Content\Embeddable,
|
||||
\IPS\Content\Hideable,
|
||||
\IPS\Content\Featurable,
|
||||
\IPS\Content\Lockable,
|
||||
\IPS\Content\MetaData
|
||||
class Item extends ContentItem implements Embeddable,
|
||||
Filter
|
||||
{
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable, \IPS\Content\Statistics, \IPS\Content\ViewUpdates;
|
||||
use Reactable,
|
||||
Reportable,
|
||||
Lockable,
|
||||
MetaData,
|
||||
Shareable,
|
||||
ReadMarkers,
|
||||
Hideable,
|
||||
Statistics,
|
||||
ViewUpdates,
|
||||
Featurable;
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'gallery';
|
||||
public static string $application = 'gallery';
|
||||
|
||||
/**
|
||||
* @brief Module
|
||||
*/
|
||||
public static $module = 'gallery';
|
||||
public static string $module = 'gallery';
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'gallery_albums';
|
||||
public static ?string $databaseTable = 'gallery_albums';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'album_';
|
||||
public static string $databasePrefix = 'album_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief Node Class
|
||||
*/
|
||||
public static $containerNodeClass = 'IPS\gallery\Category';
|
||||
public static ?string $containerNodeClass = 'IPS\gallery\Category';
|
||||
|
||||
/**
|
||||
* @brief Review Class
|
||||
*/
|
||||
public static $reviewClass = 'IPS\gallery\Album\Review';
|
||||
public static string $reviewClass = 'IPS\gallery\Album\Review';
|
||||
|
||||
/**
|
||||
* @brief Comment Class
|
||||
*/
|
||||
public static $commentClass = 'IPS\gallery\Album\Comment';
|
||||
public static ?string $commentClass = 'IPS\gallery\Album\Comment';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'title' => 'name',
|
||||
'content' => 'description',
|
||||
'container' => 'category_id',
|
||||
@@ -107,29 +143,29 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'gallery_album';
|
||||
public static string $title = 'gallery_album';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'file-photo-o';
|
||||
public static string $icon = 'images';
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
*/
|
||||
public static $hideLogKey = 'gallery-album';
|
||||
public static ?string $hideLogKey = 'gallery-album';
|
||||
|
||||
/**
|
||||
* @brief Used for the datalayer
|
||||
*/
|
||||
public static $contentType = 'album_item';
|
||||
public static string $contentType = 'album_item';
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title()
|
||||
public function get_title() : string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -137,9 +173,9 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get album as node
|
||||
*
|
||||
* @return array
|
||||
* @return Album
|
||||
*/
|
||||
public function asNode()
|
||||
public function asNode() : Album
|
||||
{
|
||||
$data = $this->_data;
|
||||
|
||||
@@ -148,56 +184,52 @@ class _Item extends \IPS\Content\Item implements
|
||||
$data['album_' . $k ] = $v;
|
||||
}
|
||||
|
||||
return \IPS\gallery\Album::constructFromData( $data, FALSE );
|
||||
return Album::constructFromData( $data, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief URL Base
|
||||
*/
|
||||
public static $urlBase = 'app=gallery&module=gallery&controller=browse&album=';
|
||||
public static string $urlBase = 'app=gallery&module=gallery&controller=browse&album=';
|
||||
|
||||
/**
|
||||
* @brief URL Base
|
||||
*/
|
||||
public static $urlTemplate = 'gallery_album';
|
||||
public static string $urlTemplate = 'gallery_album';
|
||||
|
||||
/**
|
||||
* @brief SEO Title Column
|
||||
*/
|
||||
public static $seoTitleColumn = 'name_seo';
|
||||
public static string $seoTitleColumn = 'name_seo';
|
||||
|
||||
/**
|
||||
* Can review?
|
||||
* Check if a specific action is available for this Content.
|
||||
* Default to TRUE, but used for overrides in individual Item/Comment classes.
|
||||
*
|
||||
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
|
||||
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
|
||||
* @return bool
|
||||
* @param string $action
|
||||
* @param Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canReview( $member=NULL, $considerPostBeforeRegistering = TRUE )
|
||||
public function actionEnabled( string $action, ?Member $member=null ) : bool
|
||||
{
|
||||
if ( !$this->use_reviews )
|
||||
switch( $action )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::canReview( $member, $considerPostBeforeRegistering );
|
||||
}
|
||||
case 'comment':
|
||||
if( !$this->use_comments )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
/**
|
||||
* Can comment?
|
||||
*
|
||||
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
|
||||
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
|
||||
* @return bool
|
||||
*/
|
||||
public function canComment( $member=NULL, $considerPostBeforeRegistering = TRUE )
|
||||
{
|
||||
if ( !$this->use_comments )
|
||||
{
|
||||
return FALSE;
|
||||
case 'review':
|
||||
if( !$this->use_reviews )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::canComment( $member, $considerPostBeforeRegistering );
|
||||
|
||||
return parent::actionEnabled( $action, $member );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +237,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function supportedMetaDataTypes()
|
||||
public static function supportedMetaDataTypes(): array
|
||||
{
|
||||
return array( 'core_ContentMessages' );
|
||||
}
|
||||
@@ -213,17 +245,25 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get image for embed
|
||||
*
|
||||
* @return \IPS\File|NULL
|
||||
* @return File|NULL
|
||||
*/
|
||||
public function embedImage()
|
||||
public function embedImage(): ?File
|
||||
{
|
||||
if( $this->cover_img_id OR $this->last_img_id )
|
||||
if( ( $this->cover_img_id or $this->last_img_id ) )
|
||||
{
|
||||
return \IPS\File::get( 'gallery_Images', \IPS\gallery\Image::load( $this->cover_img_id ?: $this->last_img_id )->small_file_name );
|
||||
$image = Image::load( $this->cover_img_id ?: $this->last_img_id );
|
||||
if ( $image->small_file_name )
|
||||
{
|
||||
return File::get( 'gallery_Images', $image->small_file_name );
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,11 +272,19 @@ class _Item extends \IPS\Content\Item implements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function shareImage()
|
||||
public function shareImage(): string
|
||||
{
|
||||
if( $this->cover_img_id OR $this->last_img_id )
|
||||
if( ( $this->cover_img_id or $this->last_img_id ) )
|
||||
{
|
||||
return (string) \IPS\File::get( 'gallery_Images', \IPS\gallery\Image::load( $this->cover_img_id ?: $this->last_img_id )->masked_file_name )->url;
|
||||
$image = Image::load( $this->cover_img_id ?: $this->last_img_id );
|
||||
if ( $image->masked_file_name )
|
||||
{
|
||||
return (string)File::get( 'gallery_Images', $image->masked_file_name )->url;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -247,31 +295,31 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get items with permission check
|
||||
*
|
||||
* @param array $where Where clause
|
||||
* @param string $order MySQL ORDER BY clause (NULL to order by date)
|
||||
* @param int|array $limit Limit clause
|
||||
* @param string|NULL $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
|
||||
* @param mixed $includeHiddenItems Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
|
||||
* @param int $queryFlags Select bitwise flags
|
||||
* @param \IPS\Member $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $countOnly If true will return the count
|
||||
* @param array|null $joins Additional arbitrary joins for the query
|
||||
* @param mixed $skipPermission If you are getting records from a specific container, pass the container to reduce the number of permission checks necessary or pass TRUE to skip conatiner-based permission. You must still specify this in the $where clause
|
||||
* @param bool $joinTags If true, will join the tags table
|
||||
* @param bool $joinAuthor If true, will join the members table for the author
|
||||
* @param bool $joinLastCommenter If true, will join the members table for the last commenter
|
||||
* @param bool $showMovedLinks If true, moved item links are included in the results
|
||||
* @param array|null $location Array of item lat and long
|
||||
* @return \IPS\Patterns\ActiveRecordIterator|int
|
||||
* @param array $where Where clause
|
||||
* @param string|null $order MySQL ORDER BY clause (NULL to order by date)
|
||||
* @param int|array|null $limit Limit clause
|
||||
* @param string $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
|
||||
* @param int|bool|null $includeHiddenItems Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
|
||||
* @param int $queryFlags Select bitwise flags
|
||||
* @param Member|null $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $countOnly If true will return the count
|
||||
* @param array|null $joins Additional arbitrary joins for the query
|
||||
* @param bool|Model $skipPermission If you are getting records from a specific container, pass the container to reduce the number of permission checks necessary or pass TRUE to skip conatiner-based permission. You must still specify this in the $where clause
|
||||
* @param bool $joinTags If true, will join the tags table
|
||||
* @param bool $joinAuthor If true, will join the members table for the author
|
||||
* @param bool $joinLastCommenter If true, will join the members table for the last commenter
|
||||
* @param bool $showMovedLinks If true, moved item links are included in the results
|
||||
* @param array|null $location Array of item lat and long
|
||||
* @return ActiveRecordIterator|int
|
||||
*/
|
||||
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=\IPS\Content\Hideable::FILTER_AUTOMATIC, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL, $skipPermission=FALSE, $joinTags=TRUE, $joinAuthor=TRUE, $joinLastCommenter=TRUE, $showMovedLinks=FALSE, $location=NULL )
|
||||
public static function getItemsWithPermission( array $where=array(), string $order=NULL, int|array|null $limit=10, string $permissionKey='read', int|bool|null $includeHiddenItems= Filter::FILTER_AUTOMATIC, int $queryFlags=0, Member $member=NULL, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, array|null $joins=NULL, bool|Model $skipPermission=FALSE, bool $joinTags=TRUE, bool $joinAuthor=TRUE, bool $joinLastCommenter=TRUE, bool $showMovedLinks=FALSE, array|null $location=null ): ActiveRecordIterator|int
|
||||
{
|
||||
if( $permissionKey == 'add' )
|
||||
{
|
||||
$where[] = static::submitRestrictionWhere( $member, \IPS\gallery\Category::load( $where[0][1] ) );
|
||||
$where[] = static::submitRestrictionWhere( $member, Category::load( $where[0][1] ) );
|
||||
}
|
||||
|
||||
$where[] = static::getItemsWithPermissionWhere( $where, $member, $joins );
|
||||
@@ -282,37 +330,37 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Additional WHERE clauses for finding albums the user can submit to
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Member to check
|
||||
* @param \IPS\gallery\Category $category Category we are submitted in
|
||||
* @param Member|NULL $member Member to check
|
||||
* @param Category $category Category we are submitted in
|
||||
* @return string
|
||||
*/
|
||||
public static function submitRestrictionWhere( $member, \IPS\gallery\Category $category ) : string
|
||||
public static function submitRestrictionWhere( ?Member $member, Category $category ) : string
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
/* Guests can't create albums so we can skip all the member specific stuff */
|
||||
if( !$member->member_id )
|
||||
{
|
||||
return '(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_PUBLIC . ')';
|
||||
return '(album_submit_type=' . Album::AUTH_SUBMIT_PUBLIC . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For starters, allow us to submit to public albums and our own albums */
|
||||
$wheres = array(
|
||||
'(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_OWNER . ' and album_owner_id=' . $member->member_id . ')',
|
||||
'(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_PUBLIC . ')'
|
||||
'(album_submit_type=' . Album::AUTH_SUBMIT_OWNER . ' and album_owner_id=' . $member->member_id . ')',
|
||||
'(album_submit_type=' . Album::AUTH_SUBMIT_PUBLIC . ')'
|
||||
);
|
||||
|
||||
/* Now allow us to submit to albums that allow group submissions */
|
||||
$wheres[] = '(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_GROUPS . ' AND ' . \IPS\Db::i()->findInSet( 'album_submit_access', $member->groups ) . ')';
|
||||
$wheres[] = '(album_submit_type=' . Album::AUTH_SUBMIT_GROUPS . ' AND ' . Db::i()->findInSet( 'album_submit_access', $member->groups ) . ')';
|
||||
|
||||
/* And where we as an individual member are allowed to submit */
|
||||
$wheres[] = '(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_MEMBERS . ' AND (' . \IPS\Db::i()->findInSet( 'album_submit_access', $member->socialGroups() ) . ' OR album_owner_id=' . $member->member_id . ' ) )';
|
||||
$wheres[] = '(album_submit_type=' . Album::AUTH_SUBMIT_MEMBERS . ' AND (' . Db::i()->findInSet( 'album_submit_access', $member->socialGroups() ) . ' OR album_owner_id=' . $member->member_id . ' ) )';
|
||||
|
||||
/* And finally, if we're in a club and we allow anyone in the club to submit, handle that */
|
||||
if( $category->club() AND \in_array( $category->club()->id, $member->clubs() ) )
|
||||
if( $category->club() AND in_array( $category->club()->id, $member->clubs() ) )
|
||||
{
|
||||
$wheres[] = '(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_CLUB . ')';
|
||||
$wheres[] = '(album_submit_type=' . Album::AUTH_SUBMIT_CLUB . ')';
|
||||
}
|
||||
|
||||
return '(album_owner_id=' . $member->member_id . ' OR ' . implode( ' OR ', $wheres ) . ')';
|
||||
@@ -322,26 +370,26 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* @brief Cached groups the member can access
|
||||
*/
|
||||
protected static $_availableGroups = array();
|
||||
protected static array $_availableGroups = array();
|
||||
|
||||
/**
|
||||
* @brief Cached URLs
|
||||
*/
|
||||
protected $_url = array();
|
||||
protected mixed $_url = array();
|
||||
|
||||
/**
|
||||
* WHERE clause for getItemsWithPermission
|
||||
*
|
||||
* @param array $where Current WHERE clause
|
||||
* @param \IPS\Member $member The member (NULL to use currently logged in member)
|
||||
* @param bool $joins Additional joins
|
||||
* @return array
|
||||
* @param array $where Current WHERE clause
|
||||
* @param Member|null $member The member (NULL to use currently logged in member)
|
||||
* @param array|null $joins Additional joins
|
||||
* @return array
|
||||
*/
|
||||
public static function getItemsWithPermissionWhere( $where, $member, &$joins )
|
||||
public static function getItemsWithPermissionWhere( array $where, ?Member $member, ?array &$joins ) : array
|
||||
{
|
||||
/* We need to make sure we can access the album */
|
||||
$restricted = array( 0 );
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if( isset( static::$_availableGroups[ $member->member_id ] ) )
|
||||
{
|
||||
@@ -351,7 +399,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
{
|
||||
if( $member->member_id )
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'member_id=?', $member->member_id ) ) as $group )
|
||||
foreach( Db::i()->select( '*', 'core_sys_social_group_members', array( 'member_id=?', $member->member_id ) ) as $group )
|
||||
{
|
||||
$restricted[] = $group['group_id'];
|
||||
}
|
||||
@@ -361,7 +409,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
}
|
||||
|
||||
/* If you can edit images in a category you can see private albums in that category. We can only really check globally at this stage, however. */
|
||||
if( \IPS\gallery\Image::modPermission( 'edit', $member ) )
|
||||
if( Image::modPermission( 'edit', $member ) )
|
||||
{
|
||||
return array( "( gallery_albums.album_type IN(1,2) OR ( gallery_albums.album_type=3 AND ( gallery_albums.album_owner_id=? OR gallery_albums.album_allowed_access IN (" . implode( ',', $restricted ) . ") ) ) )", $member->member_id );
|
||||
}
|
||||
@@ -378,35 +426,22 @@ class _Item extends \IPS\Content\Item implements
|
||||
* @param array $joins Other joins
|
||||
* @return array
|
||||
*/
|
||||
public static function followWhere( &$joinContainer, &$joins )
|
||||
public static function followWhere( bool &$joinContainer, array &$joins ): array
|
||||
{
|
||||
return array_merge( parent::followWhere( $joinContainer, $joins ), array( static::getItemsWithPermissionWhere( array(), \IPS\Member::loggedIn(), $joins ) ) );
|
||||
return array_merge( parent::followWhere( $joinContainer, $joins ), array( static::getItemsWithPermissionWhere( array(), Member::loggedIn(), $joins ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Move
|
||||
*
|
||||
* @param \IPS\Node\Model $container Container to move to
|
||||
* @param bool $keepLink If TRUE, will keep a link in the source
|
||||
* @param Model $container Container to move to
|
||||
* @param bool $keepLink If TRUE, will keep a link in the source
|
||||
* @return void
|
||||
* @note We need to update the image category references too
|
||||
*/
|
||||
public function move( \IPS\Node\Model $container, $keepLink=FALSE )
|
||||
public function move( Model $container, bool $keepLink=FALSE ): void
|
||||
{
|
||||
return $this->asNode()->moveTo( $container, $this->container() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Index Permissions
|
||||
*
|
||||
* @return string Comma-delimited values or '*'
|
||||
* @li Number indicates a group
|
||||
* @li Number prepended by "m" indicates a member
|
||||
* @li Number prepended by "s" indicates a social group
|
||||
*/
|
||||
public function searchIndexPermissions()
|
||||
{
|
||||
return $this->asNode()->searchIndexPermissions();
|
||||
$this->asNode()->moveTo( $container, $this->container() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,7 +449,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function basicDataColumns()
|
||||
public static function basicDataColumns(): array
|
||||
{
|
||||
$return = parent::basicDataColumns();
|
||||
$return[] = 'album_last_x_images';
|
||||
@@ -429,7 +464,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
* @param array $items Item data (will be an array containing values from basicDataColumns())
|
||||
* @return array
|
||||
*/
|
||||
public static function searchResultExtraData( $items )
|
||||
public static function searchResultExtraData( array $items ): array
|
||||
{
|
||||
$imageIds = array();
|
||||
foreach ( $items as $itemData )
|
||||
@@ -450,18 +485,18 @@ class _Item extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $imageIds ) )
|
||||
if ( count( $imageIds ) )
|
||||
{
|
||||
if( \IPS\Dispatcher::hasInstance() )
|
||||
if( Dispatcher::hasInstance() )
|
||||
{
|
||||
\IPS\gallery\Application::outputCss();
|
||||
Application::outputCss();
|
||||
}
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach ( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_id IN(' . implode( ',', $imageIds ) . ')' ) ), NULL, NULL ) as $image )
|
||||
foreach ( Image::getItemsWithPermission( array( array( 'image_id IN(' . implode( ',', $imageIds ) . ')' ) ), NULL, NULL ) as $image )
|
||||
{
|
||||
if( isset( $return[ $image->album_id] ) AND \count( $return[ $image->album_id ] ) > 19 )
|
||||
if( isset( $return[ $image->album_id] ) AND count( $return[ $image->album_id ] ) > 19 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -475,63 +510,14 @@ class _Item extends \IPS\Content\Item implements
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get snippet HTML for search result display
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
|
||||
* @param array $reputationData Array of people who have given reputation and the reputation they gave
|
||||
* @param int|NULL $reviewRating If this is a review, the rating
|
||||
* @param string $view 'expanded' or 'condensed'
|
||||
* @return callable
|
||||
*/
|
||||
public static function searchResultSnippet( array $indexData, array $authorData, array $itemData, ?array $containerData, array $reputationData, $reviewRating, $view )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( static::$urlBase . $indexData['index_item_id'], 'front', static::$urlTemplate, \IPS\Http\Url\Friendly::seoTitle( $indexData['index_title'] ?: $itemData[ static::$databasePrefix . static::$databaseColumnMap['title'] ] ) );
|
||||
$images = ( isset( $itemData['extra'] ) AND \count( $itemData['extra'] ) ) ? $itemData['extra'] : array();
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'gallery', 'front' )->searchResultAlbumSnippet( $indexData, $itemData, $images, $url, $view == 'condensed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the language string key to use in search results
|
||||
*
|
||||
* @note Normally we show "(user) posted a (thing) in (area)" but sometimes this may not be accurate, so this is abstracted to allow
|
||||
* content classes the ability to override
|
||||
* @param array $authorData Author data
|
||||
* @param array $articles Articles language strings
|
||||
* @param array $indexData Search index data
|
||||
* @param array $itemData Data about the item
|
||||
* @param bool $includeLinks Include links to member profile
|
||||
* @return string
|
||||
*/
|
||||
public static function searchResultSummaryLanguage( $authorData, $articles, $indexData, $itemData, $includeLinks = TRUE )
|
||||
{
|
||||
if( !\in_array( 'IPS\Content\Comment', class_parents( $indexData['index_class'] ) ) )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( "album_user_own_activity_item", FALSE, array( 'sprintf' => array( $articles['indefinite'] ), 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->userLinkFromData( $authorData['member_id'], $authorData['name'], $authorData['members_seo_name'], $authorData['member_group_id'] ?? \IPS\Settings::i()->guest_group ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::searchResultSummaryLanguage( $authorData, $articles, $indexData, $itemData );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A classname applied to the search result block
|
||||
*/
|
||||
public static $searchResultClassName = 'cGalleryAlbumSearchResult';
|
||||
|
||||
/**
|
||||
* Are comments supported by this class?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL to not check permission
|
||||
* @param \IPS\Node\Model|NULL $container The container to check in, or NULL for any container
|
||||
* @param Member|NULL $member The member to check for or NULL to not check permission
|
||||
* @param Model|NULL $container The container to check in, or NULL for any container
|
||||
* @return bool
|
||||
*/
|
||||
public static function supportsComments( \IPS\Member $member = NULL, \IPS\Node\Model $container = NULL )
|
||||
public static function supportsComments( Member $member = NULL, Model $container = NULL ): bool
|
||||
{
|
||||
if( $container !== NULL )
|
||||
{
|
||||
@@ -539,18 +525,18 @@ class _Item extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::supportsComments() and ( !$member or \IPS\gallery\Category::countWhere( 'read', $member, array( 'category_allow_comments=1' ) ) );
|
||||
return parent::supportsComments() and ( !$member or Category::countWhere( 'read', $member, array( 'category_allow_comments=1' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Are reviews supported by this class?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL to not check permission
|
||||
* @param \IPS\Node\Model|NULL $container The container to check in, or NULL for any container
|
||||
* @param Member|NULL $member The member to check for or NULL to not check permission
|
||||
* @param Model|NULL $container The container to check in, or NULL for any container
|
||||
* @return bool
|
||||
*/
|
||||
public static function supportsReviews( \IPS\Member $member = NULL, \IPS\Node\Model $container = NULL )
|
||||
public static function supportsReviews( Member $member = NULL, Model $container = NULL ): bool
|
||||
{
|
||||
if( $container !== NULL )
|
||||
{
|
||||
@@ -558,20 +544,20 @@ class _Item extends \IPS\Content\Item implements
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::supportsReviews() and ( !$member or \IPS\gallery\Category::countWhere( 'read', $member, array( 'category_allow_reviews=1' ) ) );
|
||||
return parent::supportsReviews() and ( !$member or Category::countWhere( 'read', $member, array( 'category_allow_reviews=1' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template for content tables
|
||||
*
|
||||
* @return callable
|
||||
* @return array
|
||||
*/
|
||||
public static function contentTableTemplate()
|
||||
public static function contentTableTemplate(): array
|
||||
{
|
||||
\IPS\gallery\Application::outputCss();
|
||||
Application::outputCss();
|
||||
|
||||
return array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery', 'front' ), 'albums' );
|
||||
return array( Theme::i()->getTemplate( 'browse', 'gallery', 'front' ), 'albums' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,17 +565,17 @@ class _Item extends \IPS\Content\Item implements
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function commentReviewTabs()
|
||||
public function commentReviewTabs(): array
|
||||
{
|
||||
$tabs = array();
|
||||
|
||||
if ( $this->container()->allow_reviews AND $this->use_reviews )
|
||||
{
|
||||
$tabs['reviews'] = \IPS\Member::loggedIn()->language()->addToStack( 'image_review_count', TRUE, array( 'pluralize' => array( $this->mapped('num_reviews') ) ) );
|
||||
$tabs['reviews'] = Member::loggedIn()->language()->addToStack( 'image_review_count', TRUE, array( 'pluralize' => array( $this->mapped('num_reviews') ) ) );
|
||||
}
|
||||
if ( $this->container()->allow_comments AND $this->use_comments )
|
||||
{
|
||||
$tabs['comments'] = \IPS\Member::loggedIn()->language()->addToStack( 'image_comment_count', TRUE, array( 'pluralize' => array( $this->mapped('num_comments') ) ) );
|
||||
$tabs['comments'] = Member::loggedIn()->language()->addToStack( 'image_comment_count', TRUE, array( 'pluralize' => array( $this->mapped('num_comments') ) ) );
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
@@ -598,18 +584,18 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get comment/review output
|
||||
*
|
||||
* @param string $tab Active tab
|
||||
* @return string
|
||||
* @param string|null $tab Active tab
|
||||
* @return string
|
||||
*/
|
||||
public function commentReviews( $tab )
|
||||
public function commentReviews( string $tab=NULL ): string
|
||||
{
|
||||
if ( $tab === 'reviews' AND $this->container()->allow_reviews AND $this->use_reviews )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('browse')->albumReviews( $this );
|
||||
return (string) Theme::i()->getTemplate('browse')->albumReviews( $this );
|
||||
}
|
||||
elseif( $tab === 'comments' AND $this->container()->allow_comments AND $this->use_comments )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('browse')->albumComments( $this );
|
||||
return (string) Theme::i()->getTemplate('browse')->albumComments( $this );
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -620,7 +606,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function reactionType()
|
||||
public static function reactionType(): string
|
||||
{
|
||||
return 'album_id';
|
||||
}
|
||||
@@ -631,10 +617,10 @@ class _Item extends \IPS\Content\Item implements
|
||||
* @param array $params Additional parameters to add to URL
|
||||
* @return string
|
||||
*/
|
||||
public function embedContent( $params )
|
||||
public function embedContent( array $params ): string
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'embed.css', 'gallery', 'front' ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'gallery' )->embedAlbums( $this, $this->asNode(), $this->url()->setQueryString( $params ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'embed.css', 'gallery', 'front' ) );
|
||||
return Theme::i()->getTemplate( 'global', 'gallery' )->embedAlbums( $this, $this->asNode(), $this->url()->setQueryString( $params ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -644,7 +630,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
* @note By default we will return NULL and the container check will execute against Node::$contentItemClass, however
|
||||
* in some situations we may need to override this (i.e. for Gallery Albums)
|
||||
*/
|
||||
protected static function getContainerModPermissionClass()
|
||||
protected static function getContainerModPermissionClass(): ?string
|
||||
{
|
||||
return 'IPS\gallery\Album\Item';
|
||||
}
|
||||
@@ -655,26 +641,26 @@ class _Item extends \IPS\Content\Item implements
|
||||
* @param int|null $limit Number of attachments to fetch, or NULL for all
|
||||
* @param bool $ignorePermissions If set to TRUE, permission to view the images will not be checked
|
||||
* @return array|NULL
|
||||
* @throws \BadMethodCallException
|
||||
* @throws BadMethodCallException
|
||||
*/
|
||||
public function contentImages( $limit = NULL, $ignorePermissions = FALSE )
|
||||
public function contentImages( int $limit = NULL, bool $ignorePermissions = FALSE ): array|null
|
||||
{
|
||||
$images = array();
|
||||
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_album_id=?', $this->id ) ), NULL, $limit ? $limit : 10, $ignorePermissions ? NULL : 'read' ) as $image )
|
||||
foreach( Image::getItemsWithPermission( array( array( 'image_album_id=?', $this->id ) ), NULL, $limit ?: 10, $ignorePermissions ? NULL : 'read' ) as $image )
|
||||
{
|
||||
$images[] = array( 'gallery_Images' => $image->masked_file_name );
|
||||
}
|
||||
|
||||
return \count( $images ) ? \array_slice( $images, 0, $limit ) : NULL;
|
||||
return count( $images ) ? array_slice( $images, 0, $limit ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
@@ -686,16 +672,16 @@ class _Item extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get the last modification date for the sitemap
|
||||
*
|
||||
* @return \IPS\DateTime|null Timestamp of the last modification time for the sitemap
|
||||
* @return DateTime|null Timestamp of the last modification time for the sitemap
|
||||
*/
|
||||
public function lastModificationDate()
|
||||
public function lastModificationDate(): DateTime|NULL
|
||||
{
|
||||
/* Returns the last last comment date */
|
||||
$lastMod = parent::lastModificationDate();
|
||||
|
||||
if( !$lastMod AND $this->last_img_date OR ( $lastMod AND $this->last_img_date AND $this->last_img_date > $lastMod->getTimestamp() ) )
|
||||
{
|
||||
$lastMod = \IPS\DateTime::ts( $this->last_img_date );
|
||||
$lastMod = DateTime::ts( $this->last_img_date );
|
||||
}
|
||||
|
||||
return $lastMod;
|
||||
@@ -714,23 +700,53 @@ class _Item extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function clubAlbumExclusion(): array
|
||||
{
|
||||
if( !\IPS\Settings::i()->club_nodes_in_apps )
|
||||
if( ! Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
if( static::$_clubNodeIds === null )
|
||||
{
|
||||
static::$_clubNodeIds = iterator_to_array(
|
||||
\IPS\Db::i()->select( 'node_id', 'core_clubs_node_map', array( 'node_class=?', 'IPS\gallery\Category' ) )
|
||||
Db::i()->select( 'node_id', 'core_clubs_node_map', array( 'node_class=?', 'IPS\gallery\Category' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if( \count( static::$_clubNodeIds ) )
|
||||
if( count( static::$_clubNodeIds ) )
|
||||
{
|
||||
return array(
|
||||
array( \IPS\Db::i()->in( 'gallery_albums.album_category_id', static::$_clubNodeIds, true ) )
|
||||
array( Db::i()->in( 'gallery_albums.album_category_id', static::$_clubNodeIds, true ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the moderation menu links
|
||||
*
|
||||
* @param Member|null $member
|
||||
* @return Menu
|
||||
*/
|
||||
public function menu( Member $member = null ): Menu
|
||||
{
|
||||
$member = $member ?: Member::loggedIn();
|
||||
$menu = parent::menu( $member );
|
||||
|
||||
if ( $this->canEdit( $member ) )
|
||||
{
|
||||
$editLink = new ContentMenuLink( url: $this->url()->setQueryString( array( 'do' => 'editAlbum' ) ), languageString: Member::loggedIn()->language()->addToStack( 'edit_album'), id: 'edit_album' );
|
||||
$editLink->opensDialog( 'edit_album' );
|
||||
$menu->add( $editLink )->moveToStart( $editLink );
|
||||
}
|
||||
|
||||
if ( isset( $menu->elements['delete'] ) )
|
||||
{
|
||||
$menu->elements['delete']->url = $this->url()->csrf()->setQueryString( array( 'do' => 'deleteAlbum' ) );
|
||||
$menu->elements['delete']->title = Member::loggedIn()->language()->addToStack( 'delete_album' );
|
||||
$menu->elements['delete']->dataAttributes = [
|
||||
"data-ipsDialog" => "true",
|
||||
"data-ipsDialog-title" => Member::loggedIn()->language()->addToStack( 'delete_album' )
|
||||
];
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user