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,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
@@ -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 ) );
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user