Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

File diff suppressed because it is too large. Load diff
+64 -65
View File
@@ -12,43 +12,67 @@
namespace IPS\gallery\Album;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Anonymous;
use IPS\Content\Comment as ContentComment;
use IPS\Content\EditHistory;
use IPS\Content\Embeddable;
use IPS\Content\Filter;
use IPS\Content\Hideable;
use IPS\Content\Featurable;
use IPS\Content\Reactable;
use IPS\Content\Reportable;
use IPS\Content\Shareable;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Theme;
use function defined;
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;
}
/**
* Album Comment Model
*/
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable, \IPS\Content\Anonymous
class Comment extends ContentComment implements Embeddable,
Filter
{
use \IPS\Content\Reactable, \IPS\Content\Reportable;
use Reactable,
Reportable,
Anonymous,
Shareable,
EditHistory,
Hideable,
Featurable;
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\gallery\Album\Item';
public static ?string $itemClass = 'IPS\gallery\Album\Item';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'gallery_album_comments';
public static ?string $databaseTable = 'gallery_album_comments';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'comment_';
public static string $databasePrefix = 'comment_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'item' => 'album_id',
'author' => 'author_id',
'author_name' => 'author_name',
@@ -65,54 +89,54 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
/**
* @brief Application
*/
public static $application = 'gallery';
public static string $application = 'gallery';
/**
* @brief Title
*/
public static $title = 'gallery_album_comment';
public static string $title = 'gallery_album_comment';
/**
* @brief Icon
*/
public static $icon = 'camera';
public static string $icon = 'camera';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'gallery-albums';
public static ?string $hideLogKey = 'gallery-albums';
/**
* Get items with permisison check
*
* @note We override in order to provide checking against album restrictions
* @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 $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
* @param mixed $includeHiddenItems Include hidden comments? 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
* @return array|NULL|\IPS\Content\Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
* @note We override in order to provide checking against album restrictions
* @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|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
* @param mixed $includeHiddenComments
* @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
* @return array|NULL|Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
*/
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 )
public static function getItemsWithPermission( array $where=array(), string $order= null, int|array|null $limit=10, string|null $permissionKey='read', mixed $includeHiddenComments= Filter::FILTER_AUTOMATIC, int $queryFlags=0, Member|null $member= null, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, array|null $joins= null ): mixed
{
$where[] = \IPS\gallery\Album\Item::getItemsWithPermissionWhere( $where, $member, $joins );
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
$where[] = Item::getItemsWithPermissionWhere( $where, $member, $joins );
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenComments, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
}
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @return Url
*/
public function url( $action='find' )
public function url( ?string $action='find' ): Url
{
return parent::url( $action )->setQueryString( 'tab', 'comments' );
}
@@ -122,7 +146,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
*
* @return void
*/
public function postCreate()
public function postCreate(): void
{
parent::postCreate();
@@ -130,37 +154,12 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
$this->item()->asNode()->save();
}
/**
* 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( \IPS\gallery\Album\Item::$urlBase . $indexData['index_item_id'], 'front', \IPS\gallery\Album\Item::$urlTemplate, \IPS\Http\Url\Friendly::seoTitle( $indexData['index_title'] ?: $itemData[ \IPS\gallery\Album\Item::$databasePrefix . \IPS\gallery\Album\Item::$databaseColumnMap['title'] ] ) );
$images = ( isset( $itemData['extra'] ) AND \count( $itemData['extra'] ) ) ? $itemData['extra'] : array();
return \IPS\Theme::i()->getTemplate( 'global', 'gallery', 'front' )->searchResultAlbumCommentSnippet( $indexData, $itemData, $images, $url, $reviewRating, $view == 'condensed' );
}
/**
* @brief A classname applied to the search result block
*/
public static $searchResultClassName = 'cGalleryAlbumSearchResult';
/**
* Reaction Type
*
* @return string
*/
public static function reactionType()
public static function reactionType(): string
{
return 'album_comment';
}
@@ -171,10 +170,10 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
* @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' )->embedAlbumComment( $this, $this->item(), $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' )->embedAlbumComment( $this, $this->item(), $this->url()->setQueryString( $params ) );
}
/**
@@ -184,7 +183,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
* @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';
}
@@ -194,7 +193,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
*
* @return array
*/
public function attachmentIds()
public function attachmentIds(): array
{
$return = parent::attachmentIds();
$return[] = 'album';
+239 -223
View File
@@ -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;
}
}
+44 -45
View File
@@ -12,43 +12,64 @@
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\EditHistory;
use IPS\Content\Embeddable;
use IPS\Content\Filter;
use IPS\Content\Hideable;
use IPS\Content\Reactable;
use IPS\Content\Reportable;
use IPS\Content\Review as ContentReview;
use IPS\Content\Shareable;
use IPS\Http\Url;
use IPS\Http\Url\Exception;
use IPS\Output;
use IPS\Theme;
use function defined;
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;
}
/**
* Album Review Model
*/
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
class Review extends ContentReview implements Embeddable,
Filter
{
use \IPS\Content\Reactable, \IPS\Content\Reportable;
use Reactable,
Reportable,
Shareable,
EditHistory,
Hideable;
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\gallery\Album\Item';
public static ?string $itemClass = 'IPS\gallery\Album\Item';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'gallery_album_reviews';
public static ?string $databaseTable = 'gallery_album_reviews';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'review_';
public static string $databasePrefix = 'review_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'item' => 'album_id',
'author' => 'author',
'author_name' => 'author_name',
@@ -69,32 +90,32 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
/**
* @brief Application
*/
public static $application = 'gallery';
public static string $application = 'gallery';
/**
* @brief Title
*/
public static $title = 'gallery_album_review';
public static string $title = 'gallery_album_review';
/**
* @brief Icon
*/
public static $icon = 'camera';
public static string $icon = 'images';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'gallery-album-review';
public static ?string $hideLogKey = 'gallery-album-review';
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @throws \BadMethodCallException
* @throws \IPS\Http\Url\Exception
* @return Url
* @throws BadMethodCallException
* @throws Exception
*/
public function url( $action='find' )
public function url( ?string $action='find' ): Url
{
return parent::url( $action )->setQueryString( 'tab', 'reviews' );
}
@@ -104,7 +125,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
*
* @return void
*/
public function postCreate()
public function postCreate(): void
{
parent::postCreate();
@@ -112,34 +133,12 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
$this->item()->asNode()->save();
}
/**
* 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 )
{
return \IPS\gallery\Album\Comment::searchResultSnippet( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $view );
}
/**
* @brief A classname applied to the search result block
*/
public static $searchResultClassName = 'cGalleryAlbumSearchResult';
/**
* Reaction Type
*
* @return string
*/
public static function reactionType()
public static function reactionType(): string
{
return 'album_review';
}
@@ -150,10 +149,10 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
* @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' )->embedAlbumReview( $this, $this->item(), $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' )->embedAlbumReview( $this, $this->item(), $this->url()->setQueryString( $params ) );
}
/**
@@ -163,7 +162,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
* @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';
}
+40 -24
View File
@@ -12,57 +12,73 @@
namespace IPS\gallery\Album;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\gallery\Album;
use IPS\gallery\Image;
use IPS\Helpers\Table\Content;
use IPS\Http\Url;
use IPS\Member;
use IPS\Node\Model;
use IPS\Theme;
use function count;
use function defined;
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;
}
/**
* Table Builder for Gallery albums
*/
class _Table extends \IPS\Helpers\Table\Content
class Table extends Content
{
/**
* @brief Container
*/
protected $container;
protected ?Model $container = NULL;
/**
* @brief Additional CSS classes to apply to columns
*/
public $classes = array( 'cGalleryAlbums' );
public array $classes = array( 'cGalleryAlbums' );
/**
* @brief Pagination parameter
*/
protected $paginationKey = 'albumPage';
protected string $paginationKey = 'albumPage';
/**
* @brief Table resort parameter
*/
public $resortKey = 'albumResort';
public string $resortKey = 'albumResort';
/**
* @brief No Moderate
*/
public $noModerate = TRUE;
public bool $noModerate = TRUE;
/**
* @brief Where clauses
*/
public ?array $where;
/**
* Constructor
*
* @param \IPS\Http\Url|NULL $url Base URL (defaults to container URL)
* @param \IPS\Node\Model|NULL $container The container
* @param Url|NULL $url Base URL (defaults to container URL)
* @param Model|NULL $container The container
* @return void
*/
public function __construct( \IPS\Http\Url $url=NULL, \IPS\Node\Model $container=NULL )
public function __construct( Url $url=NULL, Model $container=NULL )
{
/* Set container */
if ( $container !== NULL )
{
if ( !$this->sortBy and $container->_sortBy )
{
$this->sortBy = \IPS\gallery\Album::$databasePrefix . $container->_sortBy;
$this->sortBy = Album::$databasePrefix . $container->_sortBy;
$this->sortDirection = $container->_sortOrder;
}
@@ -80,18 +96,18 @@ class _Table extends \IPS\Helpers\Table\Content
/* Init */
parent::__construct( '\\IPS\\gallery\\Album\\Item', ( $url !== NULL ) ? $url : $container->url(), NULL, $container );
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery' ), 'albums' );
$this->rowsTemplate = array( Theme::i()->getTemplate( 'browse', 'gallery' ), 'albums' );
/* If we can't moderate in this category, restrict results */
if( $container === NULL OR !\IPS\gallery\Image::modPermission( 'edit', NULL, $container ) )
if( $container === NULL OR !Image::modPermission( 'edit', NULL, $container ) )
{
if( \count( \IPS\Member::loggedIn()->socialGroups() ) )
if( count( Member::loggedIn()->socialGroups() ) )
{
$this->where[] = array( '( album_type=1 OR ( album_type=2 AND album_owner_id=? ) OR ( album_type=3 AND ( album_owner_id=? OR ( album_allowed_access IS NOT NULL AND album_allowed_access IN(' . implode( ',', \IPS\Member::loggedIn()->socialGroups() ) . ') ) ) ) )', \IPS\Member::loggedIn()->member_id, \IPS\Member::loggedIn()->member_id );
$this->where[] = array( '( album_type=1 OR ( album_type=2 AND album_owner_id=? ) OR ( album_type=3 AND ( album_owner_id=? OR ( album_allowed_access IS NOT NULL AND album_allowed_access IN(' . implode( ',', Member::loggedIn()->socialGroups() ) . ') ) ) ) )', Member::loggedIn()->member_id, Member::loggedIn()->member_id );
}
else
{
$this->where[] = array( '( album_type=1 OR ( album_type IN (2,3) AND album_owner_id=? ) )', \IPS\Member::loggedIn()->member_id );
$this->where[] = array( '( album_type=1 OR ( album_type IN (2,3) AND album_owner_id=? ) )', Member::loggedIn()->member_id );
}
}
else
@@ -122,10 +138,10 @@ class _Table extends \IPS\Helpers\Table\Content
/**
* 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( 'album_owner_id=?', $member->member_id );
}
@@ -136,7 +152,7 @@ class _Table extends \IPS\Helpers\Table\Content
* @param array|NULL $advancedSearchValues Advanced search values
* @return array
*/
public function getHeaders( $advancedSearchValues )
public function getHeaders( array $advancedSearchValues=NULL ): array
{
return array();
}
@@ -144,10 +160,10 @@ class _Table extends \IPS\Helpers\Table\Content
/**
* Does the user have permission to use the multi-mod checkboxes?
*
* @param string|null $action Specific action to check (hide/unhide, etc.) or NULL for a generic check
* @param string|null $action Specific action to check (hide/unhide, etc.) or NULL for a generic check
* @return bool
*/
public function canModerate( $action=NULL )
public function canModerate( string $action=NULL ): bool
{
return FALSE;
}
@@ -156,10 +172,10 @@ class _Table extends \IPS\Helpers\Table\Content
* Return the sort direction to use for links
*
* @note Abstracted so other table helper instances can adjust as needed
* @param string $column Sort by string
* @param string $column Sort by string
* @return string [asc|desc]
*/
public function getSortDirection( $column )
public function getSortDirection( string $column ): string
{
if( $column == 'album_name' )
{
File diff suppressed because it is too large. Load diff
+85 -71
View File
@@ -12,53 +12,83 @@
namespace IPS\gallery\Image;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Anonymous;
use IPS\Content\Comment as ContentComment;
use IPS\Content\EditHistory;
use IPS\Content\Embeddable;
use IPS\Content\Filter;
use IPS\Content\Hideable;
use IPS\Content\Featurable;
use IPS\Content\Reactable;
use IPS\Content\Reportable;
use IPS\Content\Shareable;
use IPS\gallery\Album;
use IPS\gallery\Image;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Theme;
use function count;
use function defined;
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;
}
/**
* Image Comment Model
*/
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable, \IPS\Content\Anonymous
class Comment extends ContentComment implements Embeddable,
Filter
{
use \IPS\Content\Reactable, \IPS\Content\Reportable;
use Reactable,
Reportable,
Anonymous,
Shareable,
EditHistory,
Featurable,
Hideable {
Hideable::onHide as public _onHide;
Hideable::onUnhide as public _onUnhide;
}
/**
* @brief [Content\Comment] Form Template
*/
public static $formTemplate = array( array( 'forms', 'gallery', 'front' ), 'commentTemplate' );
public static array $formTemplate = array( array( 'forms', 'gallery', 'front' ), 'commentTemplate' );
/**
* @brief [Content\Comment] Comment Template
*/
public static $commentTemplate = array( array( 'global', 'gallery', 'front' ), 'commentContainer' );
public static array $commentTemplate = array( array( 'global', 'gallery', 'front' ), 'commentContainer' );
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\gallery\Image';
public static ?string $itemClass = 'IPS\gallery\Image';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'gallery_comments';
public static ?string $databaseTable = 'gallery_comments';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'comment_';
public static string $databasePrefix = 'comment_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'item' => 'img_id',
'author' => 'author_id',
'author_name' => 'author_name',
@@ -75,57 +105,57 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
/**
* @brief Application
*/
public static $application = 'gallery';
public static string $application = 'gallery';
/**
* @brief Title
*/
public static $title = 'gallery_image_comment';
public static string $title = 'gallery_image_comment';
/**
* @brief Icon
*/
public static $icon = 'camera';
public static string $icon = 'camera';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'gallery-images';
public static ?string $hideLogKey = 'gallery-images';
/**
* 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 $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
* @param mixed $includeHiddenItems Include hidden comments? 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
* @return array|NULL|\IPS\Content\Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
* @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|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
* @param mixed $includeHiddenComments
* @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
* @return array|NULL|Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
*/
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 )
public static function getItemsWithPermission( array $where=array(), string $order= null, int|array|null $limit=10, string|null $permissionKey='read', mixed $includeHiddenComments= Filter::FILTER_AUTOMATIC, int $queryFlags=0, Member|null $member= null, bool $joinContainer=FALSE, bool $joinComments=FALSE, bool $joinReviews=FALSE, bool $countOnly=FALSE, array|null $joins= null ): mixed
{
if( $itemsWhere = \IPS\gallery\Image::getItemsWithPermissionWhere( $where, $member, $joins ) AND \count( $itemsWhere ) )
if( $itemsWhere = Image::getItemsWithPermissionWhere( $where, $member, $joins ) AND count( $itemsWhere ) )
{
$where[] = $itemsWhere;
}
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenComments, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins );
}
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @return Url
*/
public function url( $action='find' )
public function url( ?string $action='find' ): Url
{
return parent::url( $action )->setQueryString( 'tab', 'comments' );
}
@@ -135,7 +165,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
*
* @return void
*/
public function postCreate()
public function postCreate(): void
{
parent::postCreate();
@@ -144,19 +174,22 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
if( $item->album_id )
{
$album = $item->directContainer();
$album->setLastComment( $this, $item );
/* We need to increment the counters here because the parent method will increment
the category but not the album */
if ( !$item->hidden() and ! $item->approvedButHidden() and !$item->isFutureDate() )
if( !$item->approvedButHidden() )
{
$album->_comments = ( $album->_comments + 1 );
}
elseif ( !$item->approvedButHidden() AND $this->hidden() == 1 )
{
$album->_unapprovedComments = ( $album->_unapprovedComments >= 0 ) ? ( $album->_unapprovedComments + 1 ) : 0;
if( $this->hidden() == 0 and !$item->hidden() )
{
$album->_comments = ( $album->_comments + 1 );
}
elseif( $this->hidden() == 1 )
{
$album->_unapprovedComments = ( $album->_unapprovedComments >= 0 ) ? ( $album->_unapprovedComments + 1 ) : 1;
}
}
$album->setLastComment( $this, $item );
$album->save();
}
}
@@ -164,12 +197,12 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
/**
* Syncing to run when hiding
*
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @param Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onHide( $member )
public function onHide( Member|null|bool $member ): void
{
parent::onHide( $member );
$this->_onHide( $member );
$item = $this->item();
if( $item->album_id )
@@ -185,12 +218,12 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
* Syncing to run when unhiding
*
* @param bool $approving If true, is being approved for the first time
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @param Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onUnhide( $approving, $member )
public function onUnhide( bool $approving, Member|null|bool $member ): void
{
parent::onUnhide( $approving, $member );
$this->_onUnhide( $approving, $member );
$item = $this->item();
if( $item->album_id )
@@ -205,32 +238,13 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
$album->save();
}
}
/**
* 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( \IPS\gallery\Image::$urlBase . $indexData['index_item_id'], 'front', \IPS\gallery\Image::$urlTemplate, \IPS\Http\Url\Friendly::seoTitle( $indexData['index_title'] ?: $itemData[ \IPS\gallery\Image::$databasePrefix . \IPS\gallery\Image::$databaseColumnMap['title'] ] ) );
return \IPS\Theme::i()->getTemplate( 'global', 'gallery', 'front' )->searchResultCommentSnippet( $indexData, $itemData, $itemData['image_small_file_name'], $url, $reviewRating, $view == 'condensed' );
}
/**
* Reaction Type
*
* @return string
*/
public static function reactionType()
public static function reactionType(): string
{
return 'comment_id';
}
@@ -241,9 +255,9 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
* @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' )->embedImageComment( $this, $this->item(), $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' )->embedImageComment( $this, $this->item(), $this->url()->setQueryString( $params ) );
}
}
File diff suppressed because it is too large. Load diff
+44 -40
View File
@@ -12,53 +12,74 @@
namespace IPS\gallery\Image;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use IPS\Content\EditHistory;
use IPS\Content\Embeddable;
use IPS\Content\Filter;
use IPS\Content\Hideable;
use IPS\Content\Reactable;
use IPS\Content\Reportable;
use IPS\Content\Review as ContentReview;
use IPS\Content\Shareable;
use IPS\Http\Url;
use IPS\Http\Url\Exception;
use IPS\Output;
use IPS\Theme;
use function defined;
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;
}
/**
* Image Review Model
*/
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
class Review extends ContentReview implements Embeddable,
Filter
{
use \IPS\Content\Reactable, \IPS\Content\Reportable;
use Reactable,
Reportable,
Shareable,
EditHistory,
Hideable;
/**
* @brief [Content\Comment] Form Template
*/
public static $formTemplate = array( array( 'forms', 'gallery', 'front' ), 'reviewTemplate' );
public static array $formTemplate = array( array( 'forms', 'gallery', 'front' ), 'reviewTemplate' );
/**
* @brief [Content\Comment] Comment Template
*/
public static $commentTemplate = array( array( 'global', 'gallery', 'front' ), 'reviewContainer' );
public static array $commentTemplate = array( array( 'global', 'gallery', 'front' ), 'reviewContainer' );
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [Content\Comment] Item Class
*/
public static $itemClass = 'IPS\gallery\Image';
public static ?string $itemClass = 'IPS\gallery\Image';
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'gallery_reviews';
public static ?string $databaseTable = 'gallery_reviews';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'review_';
public static string $databasePrefix = 'review_';
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'item' => 'image_id',
'author' => 'author',
'author_name' => 'author_name',
@@ -79,59 +100,42 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
/**
* @brief Application
*/
public static $application = 'gallery';
public static string $application = 'gallery';
/**
* @brief Title
*/
public static $title = 'gallery_image_review';
public static string $title = 'gallery_image_review';
/**
* @brief Icon
*/
public static $icon = 'camera';
public static string $icon = 'camera';
/**
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'gallery-image-review';
public static ?string $hideLogKey = 'gallery-image-review';
/**
* Get URL for doing stuff
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
* @throws \BadMethodCallException
* @throws \IPS\Http\Url\Exception
* @return Url
* @throws BadMethodCallException
* @throws Exception
*/
public function url( $action='find' )
public function url( ?string $action='find' ): Url
{
return parent::url( $action )->setQueryString( 'tab', 'reviews' );
}
/**
* 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 )
{
return \IPS\gallery\Image\Comment::searchResultSnippet( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $view );
}
/**
* Reaction Type
*
* @return string
*/
public static function reactionType()
public static function reactionType(): string
{
return 'review_id';
}
@@ -142,9 +146,9 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
* @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' )->embedImageReview( $this, $this->item(), $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' )->embedImageReview( $this, $this->item(), $this->url()->setQueryString( $params ) );
}
}
+71 -46
View File
@@ -12,52 +12,77 @@
namespace IPS\gallery\Image;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use DomainException;
use IPS\Content\Filter;
use IPS\Content\Item;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\gallery\Album;
use IPS\gallery\Category;
use IPS\gallery\Image;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Table\Content;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\Node\Model;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfBoundsException;
use function defined;
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;
}
/**
* Custom table helper for gallery images to override move menu
*/
class _Table extends \IPS\Helpers\Table\Content
class Table extends Content
{
/**
* Constructor
*
* @param array $class Database table
* @param \IPS\Http\Url $baseUrl Base URL
* @param string $class Database table
* @param Url $baseUrl Base URL
* @param array|null $where WHERE clause (To restrict to a node, use $container instead)
* @param \IPS\Node\Model|NULL $container The container
* @param Model|NULL $container The container
* @param bool|null $includeHidden Flag to pass to getItemsWithPermission() method for $includeHiddenContent, defaults to NULL
* @param string|NULL $permCheck Permission key to check
* @param bool $honorPinned Honor pinned status (show pinned items first)
* @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 )
public function __construct( string $class, Url $baseUrl, ?array $where=NULL, ?Model $container=NULL, ?bool $includeHidden= Filter::FILTER_AUTOMATIC, ?string $permCheck='view', bool $honorPinned=TRUE )
{
/* Are we changing the thumbnail viewing size? */
if( isset( \IPS\Request::i()->thumbnailSize ) )
if( isset( Request::i()->thumbnailSize ) )
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
\IPS\Request::i()->setCookie( 'thumbnailSize', \IPS\Request::i()->thumbnailSize, \IPS\DateTime::ts( time() )->add( new \DateInterval( 'P1Y' ) ) );
Request::i()->setCookie( 'thumbnailSize', Request::i()->thumbnailSize, DateTime::ts( time() )->add( new DateInterval( 'P1Y' ) ) );
/* Do a 303 redirect to prevent indexing of the CSRF link */
\IPS\Output::i()->redirect( \IPS\Request::i()->url(), '', 303 );
Output::i()->redirect( Request::i()->url(), '', 303 );
}
return parent::__construct( $class, $baseUrl, $where, $container, $includeHidden, $permCheck, $honorPinned );
parent::__construct( $class, $baseUrl, $where, $container, $includeHidden, $permCheck, $honorPinned );
}
/**
* 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
{
$this->sortOptions['title'] = $this->sortOptions['title'] . ' ASC, image_id ';
@@ -67,29 +92,29 @@ class _Table extends \IPS\Helpers\Table\Content
/**
* Build the form to move images
*
* @param \IPS\Node\Model $currentContainer Current image container
* @param Model $currentContainer Current image container
* @param string $class Class to use
* @param array $extraAlbumOptions Additional options to use for the album helper (e.g. to force owner)
* @param \IPS\Member|NULL $member Member to check, or NULL for currently logged in member.
* @return \IPS\Helpers\Form
* @param Member|NULL $member Member to check, or NULL for currently logged in member.
* @return Form
*/
static public function buildMoveForm( $currentContainer, $class, $extraAlbumOptions=array(), $member=NULL )
static public function buildMoveForm( Model $currentContainer, string $class, array $extraAlbumOptions=array(), ?Member $member=NULL ) : Form
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
$form = new \IPS\Helpers\Form( 'form', 'move' );
$form->class = 'ipsForm_vertical';
if ( \IPS\gallery\Category::canOnAny('add') and \IPS\gallery\Album::canOnAny('add') )
$form = new Form( 'form', 'move' );
$form->class = 'ipsForm--vertical ipsForm--move-images';
if ( Category::canOnAny('add') and Album::canOnAny('add') )
{
$options = array( 'category' => 'image_category', 'album' => 'image_album' );
$toggles = array( 'category' => array( 'move_to_category' ), 'album' => array( 'move_to_album' ) );
$extraFields = array();
if ( \IPS\gallery\Image::modPermission( 'edit', NULL, NULL ) and \IPS\Db::i()->select( 'COUNT(*)', 'gallery_categories', array( array( 'category_allow_albums>0' ), array( '(' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'], \IPS\Member::loggedIn()->groups ) . ' OR ' . 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'] . '=? )', '*' ) ) )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . \IPS\gallery\Category::$databaseTable . "." . \IPS\gallery\Category::$databasePrefix . \IPS\gallery\Category::$databaseColumnId, \IPS\gallery\Category::$permApp, \IPS\gallery\Category::$permType ) )->first() )
if ( Image::modPermission( 'edit' ) and Db::i()->select( 'COUNT(*)', 'gallery_categories', array( array( 'category_allow_albums>0' ), array( '(' . Db::i()->findInSet( 'core_permission_index.perm_' . Category::$permissionMap['add'], Member::loggedIn()->groups ) . ' OR ' . 'core_permission_index.perm_' . Category::$permissionMap['add'] . '=? )', '*' ) ) )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . Category::$databaseTable . "." . Category::$databasePrefix . Category::$databaseColumnId, Category::$permApp, Category::$permType ) )->first() )
{
$options['new_album'] = 'move_to_new_album';
foreach ( \IPS\gallery\Album::formFields( NULL, TRUE, \IPS\Request::i()->move_to === 'new_album' ) as $field )
foreach ( Album::formFields( NULL, TRUE, Request::i()->move_to === 'new_album' ) as $field )
{
if ( !$field->htmlId )
{
@@ -101,20 +126,20 @@ class _Table extends \IPS\Helpers\Table\Content
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'move_to', NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
$form->add( new Radio( 'move_to', NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
foreach ( $extraFields as $field )
{
$form->add( $field );
}
}
$form->add( new \IPS\Helpers\Form\Node( 'move_to_category', NULL, NULL, array(
$form->add( new Node( 'move_to_category', NULL, NULL, array(
'clubs' => true,
'class' => 'IPS\\gallery\\Category',
'permissionCheck' => function( $node ) use ( $currentContainer, $class, $member )
{
/* If the image is in the same category already, we can't move it there */
if( $currentContainer instanceof \IPS\gallery\Category and $currentContainer->id == $node->id )
if( $currentContainer instanceof Category and $currentContainer->id == $node->id )
{
return false;
}
@@ -129,12 +154,13 @@ class _Table extends \IPS\Helpers\Table\Content
try
{
/* If the item is in a club, only allow moving to other clubs that you moderate */
if ( $currentContainer and \IPS\IPS::classUsesTrait( $currentContainer, 'IPS\Content\ClubContainer' ) and $currentContainer->club() )
if ( $currentContainer and IPS::classUsesTrait( $currentContainer, 'IPS\Content\ClubContainer' ) and $currentContainer->club() )
{
return $class::modPermission( 'move', \IPS\Member::loggedIn(), $node ) and $node->can( 'add' ) ;
/* @var Item $class */
return $class::modPermission( 'move', Member::loggedIn(), $node ) and $node->can( 'add' ) ;
}
}
catch( \OutOfBoundsException $e ) { }
catch( OutOfBoundsException ) { }
/* Can we add in this category? */
if ( $node->can( 'add', $member ) )
@@ -145,18 +171,18 @@ class _Table extends \IPS\Helpers\Table\Content
return false;
}
), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'category' )
if ( !$val and isset( Request::i()->move_to ) and Request::i()->move_to == 'category' )
{
throw new \DomainException('form_required');
throw new DomainException('form_required');
}
}, NULL, NULL, 'move_to_category' ) );
$form->add( new \IPS\Helpers\Form\Node( 'move_to_album', NULL, NULL, array_merge( array(
$form->add( new Node( 'move_to_album', NULL, NULL, array_merge( array(
'class' => 'IPS\\gallery\\Album',
'permissionCheck' => function( $node ) use ( $currentContainer, $member )
{
/* If the image is in the same album already, we can't move it there */
if( $currentContainer instanceof \IPS\gallery\Album and $currentContainer->id == $node->id )
if( $currentContainer instanceof Album and $currentContainer->id == $node->id )
{
return false;
}
@@ -176,9 +202,9 @@ class _Table extends \IPS\Helpers\Table\Content
return true;
}
), $extraAlbumOptions ), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'album' )
if ( !$val and isset( Request::i()->move_to ) and Request::i()->move_to == 'album' )
{
throw new \DomainException('form_required');
throw new DomainException('form_required');
}
}, NULL, NULL, 'move_to_album' ) );
@@ -190,7 +216,7 @@ class _Table extends \IPS\Helpers\Table\Content
*
* @return string|array
*/
protected function getMoveForm()
protected function getMoveForm(): array|string
{
$class = $this->class;
$params = array();
@@ -210,18 +236,18 @@ class _Table extends \IPS\Helpers\Table\Content
unset( $albumValues['move_to_category'] );
unset( $albumValues['move_to_album'] );
$target = new \IPS\gallery\Album;
$target = new Album;
$target->saveForm( $target->formatFormValues( $albumValues ) );
$target->save();
}
else
{
$target = ( \IPS\Request::i()->move_to == 'category' ) ? $values['move_to_category'] : $values['move_to_album'];
$target = ( Request::i()->move_to == 'category' ) ? $values['move_to_category'] : $values['move_to_album'];
}
}
else
{
$target = isset( $values['move_to_category'] ) ? $values['move_to_category'] : $values['move_to_album'];
$target = $values['move_to_category'] ?? $values['move_to_album'];
}
$params[] = $target;
@@ -230,16 +256,15 @@ class _Table extends \IPS\Helpers\Table\Content
return $params;
}
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
if ( \IPS\Request::i()->isAjax() )
if ( Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( \IPS\Output::i()->output );
Output::i()->sendOutput( Output::i()->output );
}
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' );
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Output::i()->title, Output::i()->output, array( 'app' => Dispatcher::i()->application->directory, 'module' => Dispatcher::i()->module->key, 'controller' => Dispatcher::i()->controller ) ) );
}
return;
}
}