Version 4.7.23
This commit is contained in:
1 parent
7124a02564
commit
25ddeb65d6
1791 files changed
+76990
-44452
No files matched your search
@@ -12,6 +12,9 @@
|
||||
namespace IPS\gallery;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Content\Comment;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
@@ -20,9 +23,13 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
/**
|
||||
* Album Node
|
||||
*
|
||||
* @note SELECT_FROM_WRITE_SERVER all instances added in 214656fad607b29fb87e99be2bf5e3099108d661 "One common reproduction of this is being able to see a topic title and link for a topic that has been deleted."
|
||||
*/
|
||||
class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\Embeddable
|
||||
{
|
||||
use \IPS\Node\DelayedCount;
|
||||
|
||||
/**
|
||||
* @brief Define view access levels
|
||||
*/
|
||||
@@ -884,13 +891,19 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/**
|
||||
* Set last comment
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The latest comment or NULL to work it out
|
||||
* @return int
|
||||
* @note We actually want to set the last image info, not the last comment, so we ignore $comment
|
||||
* @param Comment|null $comment The latest comment or NULL to work it out
|
||||
* @param Item|null $updatedItem We sometimes run setLastComment() when an item has been edited, if so, that item will be here
|
||||
* @return void
|
||||
*/
|
||||
public function setLastComment( \IPS\Content\Comment $comment=NULL )
|
||||
public function _setLastComment( \IPS\Content\Comment $comment=NULL, \IPS\Content\Item $updatedItem=NULL )
|
||||
{
|
||||
$this->setLastImage();
|
||||
/* If this updated comment is older than the last shown on the node, do nothing */
|
||||
if( $updatedItem !== NULL AND $updatedItem->mapped('last_comment') < $this->last_img_date )
|
||||
{
|
||||
$updatedItem = null;
|
||||
}
|
||||
|
||||
$this->setLastImage( $updatedItem );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -915,42 +928,55 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
*/
|
||||
public function setLastImage( \IPS\gallery\Image $image=NULL, $sortBy='image_date DESC' )
|
||||
{
|
||||
/* Figure out our latest images in this album */
|
||||
$_latestImages = array();
|
||||
|
||||
$this->last_img_date = 0;
|
||||
$this->last_img_id = 0;
|
||||
foreach( \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_album_id=? AND image_approved=1', $this->id ), $sortBy, array( 0, 20 ), NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER ) as $image )
|
||||
/* Make sure the image is actually the latest */
|
||||
if( $image !== null and $image->date < $this->last_img_date )
|
||||
{
|
||||
if( $image['image_date'] > $this->last_img_date )
|
||||
{
|
||||
$this->last_img_date = $image['image_date'];
|
||||
$this->last_img_id = $image['image_id'];
|
||||
}
|
||||
|
||||
$_latestImages[] = $image['image_id'];
|
||||
$image = null;
|
||||
}
|
||||
|
||||
$this->last_x_images = json_encode( $_latestImages );
|
||||
/* If we have one, just use it */
|
||||
if( $image !== null )
|
||||
{
|
||||
$this->last_img_date = $image->date;
|
||||
$this->last_img_id = $image->id;
|
||||
|
||||
/* Now get the counts and set them for our images */
|
||||
$this->_items = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_album_id=? AND image_approved=1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->_unapprovedItems = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_album_id=? AND image_approved=0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$_latestImages = json_decode( $this->last_x_images, true );
|
||||
if( !is_array($_latestImages ) )
|
||||
{
|
||||
$_latestImages = [];
|
||||
}
|
||||
if( !in_array( $image->id, $_latestImages ) )
|
||||
{
|
||||
array_unshift( $_latestImages, $image->id );
|
||||
if( count( $_latestImages ) > 20 )
|
||||
{
|
||||
array_pop( $_latestImages );
|
||||
}
|
||||
$this->last_x_images = json_encode( $_latestImages );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Figure out our latest images in this album */
|
||||
$_latestImages = array();
|
||||
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_approved=1 AND gallery_images.image_approved=1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
$this->_unapprovedComments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_approved=0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
|
||||
$this->_reviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_album_id=? AND review_approved=1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
$this->_unapprovedReviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_album_id=? AND review_approved=0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
$this->last_img_date = 0;
|
||||
$this->last_img_id = 0;
|
||||
foreach( \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_album_id=? AND image_approved=1', $this->id ), $sortBy, array( 0, 20 ) ) as $image )
|
||||
{
|
||||
if( $image['image_date'] > $this->last_img_date )
|
||||
{
|
||||
$this->last_img_date = $image['image_date'];
|
||||
$this->last_img_id = $image['image_id'];
|
||||
}
|
||||
|
||||
/* And then get counts/latest data for the direct comments/reviews */
|
||||
$this->comments = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->comments_unapproved = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->comments_hidden = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=-1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
|
||||
$this->reviews = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->reviews_unapproved = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=0', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->reviews_hidden = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=-1', $this->id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$_latestImages[] = $image['image_id'];
|
||||
}
|
||||
|
||||
$this->last_x_images = json_encode( $_latestImages );
|
||||
}
|
||||
|
||||
$this->save();
|
||||
|
||||
/* Save and then make sure search index is updated */
|
||||
\IPS\Content\Search\Index::i()->index( $this->asItem() );
|
||||
@@ -1558,4 +1584,43 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count all comments, items, etc
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function recount()
|
||||
{
|
||||
/* Now get the counts and set them for our images */
|
||||
$this->_items = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_album_id=? AND image_approved=1', $this->id ) )->first();
|
||||
$this->_unapprovedItems = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_album_id=? AND image_approved=0', $this->id ) )->first();
|
||||
|
||||
if( $this->allow_comments )
|
||||
{
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_approved=1 AND gallery_images.image_approved=1', $this->id ) )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
$this->_unapprovedComments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_approved=0', $this->id ) )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
}
|
||||
|
||||
if( $this->use_comments )
|
||||
{
|
||||
/* And then get counts/latest data for the direct comments/reviews */
|
||||
$this->comments = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=1', $this->id ) )->first();
|
||||
$this->comments_unapproved = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=0', $this->id ) )->first();
|
||||
$this->comments_hidden = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_comments', array( 'comment_album_id=? AND comment_approved=-1', $this->id ) )->first();
|
||||
}
|
||||
|
||||
if( $this->allow_reviews )
|
||||
{
|
||||
$this->_reviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_album_id=? AND review_approved=1', $this->id ) )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
$this->_unapprovedReviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_album_id=? AND review_approved=0', $this->id ) )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
}
|
||||
|
||||
if( $this->use_reviews )
|
||||
{
|
||||
$this->reviews = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=1', $this->id ) )->first();
|
||||
$this->reviews_unapproved = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=0', $this->id ) )->first();
|
||||
$this->reviews_hidden = (int) \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_album_reviews', array( 'review_album_id=? AND review_approved=-1', $this->id ) )->first();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -701,6 +701,12 @@ class _Item extends \IPS\Content\Item implements
|
||||
return $lastMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store club node IDs so we can save on queries
|
||||
* @var array|null
|
||||
*/
|
||||
protected static ?array $_clubNodeIds = null;
|
||||
|
||||
/**
|
||||
* Return query WHERE clause to use for getItemsWithPermission when excluding club content
|
||||
*
|
||||
@@ -708,16 +714,23 @@ class _Item extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function clubAlbumExclusion(): array
|
||||
{
|
||||
if( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
if( !\IPS\Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
return array( array(
|
||||
'gallery_albums.album_category_id NOT IN(?)',
|
||||
\IPS\Db::i()->select( 'node_id', 'core_clubs_node_map', array( 'node_class=?', 'IPS\gallery\Category' ) )
|
||||
) );
|
||||
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' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if( \count( static::$_clubNodeIds ) )
|
||||
{
|
||||
return array(
|
||||
array( \IPS\Db::i()->in( 'gallery_albums.album_category_id', static::$_clubNodeIds, true ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@
|
||||
namespace IPS\gallery;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Content\Comment;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
@@ -23,7 +26,7 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
use \IPS\Content\ClubContainer, \IPS\Content\ViewUpdates;
|
||||
use \IPS\Content\ClubContainer, \IPS\Content\ViewUpdates, \IPS\Node\DelayedCount;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -284,6 +287,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$class = \get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'gcategory_parent_id', $this->id ? $this->parent_id : ( \IPS\Request::i()->parent ?: 0 ), FALSE, array(
|
||||
'disableCopy' => true,
|
||||
'class' => '\IPS\gallery\Category',
|
||||
'disabled' => false,
|
||||
'zeroVal' => 'node_no_parentg',
|
||||
@@ -558,17 +562,23 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Lang::deleteCustom( 'gallery', "gallery_category_{$this->id}_rules" );
|
||||
\IPS\Lang::deleteCustom( 'gallery', "gallery_category_{$this->id}_permerror" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set last comment
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The latest comment or NULL to work it out
|
||||
* @return int
|
||||
* @note We actually want to set the last image info, not the last comment, so we ignore $comment
|
||||
* @param Comment|null $comment The latest comment or NULL to work it out
|
||||
* @param Item|null $updatedItem We sometimes run setLastComment() when an item has been edited, if so, that item will be here
|
||||
* @return void
|
||||
*/
|
||||
public function setLastComment( \IPS\Content\Comment $comment=NULL )
|
||||
public function _setLastComment( \IPS\Content\Comment $comment=NULL, \IPS\Content\Item $updatedItem=NULL )
|
||||
{
|
||||
$this->setLastImage();
|
||||
/* If this updated comment is older than the last shown on the node, do nothing */
|
||||
if( $updatedItem !== NULL AND $updatedItem->mapped('last_comment') < $this->last_img_date )
|
||||
{
|
||||
$updatedItem = null;
|
||||
}
|
||||
|
||||
$this->setLastImage( $updatedItem );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,37 +589,44 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function setLastImage( \IPS\gallery\Image $image=NULL )
|
||||
{
|
||||
/* Reset counts */
|
||||
$this->resetCommentCounts();
|
||||
$this->commentCountsReset = TRUE;
|
||||
/* Make sure the image is actually the latest */
|
||||
if( $image !== null and $image->date < $this->last_img_date )
|
||||
{
|
||||
$image = null;
|
||||
}
|
||||
|
||||
/* Reset last image */
|
||||
if( $image === NULL )
|
||||
/* If we have one, just use it */
|
||||
if( $image !== null )
|
||||
{
|
||||
$this->last_img_date = $image->date;
|
||||
$this->last_img_id = $image->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$result = \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_category_id=? AND image_approved=1 AND ( image_album_id = 0 OR album_type NOT IN ( 2, 3 ) )', $this->id ), 'image_date DESC', 1, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->join(
|
||||
$result = \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_category_id=? AND image_approved=1 AND ( image_album_id = 0 OR album_type NOT IN ( 2, 3 ) )', $this->id ), 'image_date DESC', 1 )->join(
|
||||
'gallery_albums',
|
||||
"image_album_id=album_id"
|
||||
)->first();
|
||||
|
||||
$image = \IPS\gallery\Image::constructFromData( $result );
|
||||
$this->last_img_id = $image->id;
|
||||
$this->last_img_date = $image->date;
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$this->last_img_id = 0;
|
||||
$this->last_img_date = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->last_img_id = $image->id;
|
||||
$this->last_img_date = $image->date;
|
||||
|
||||
$this->save();
|
||||
|
||||
if( $image->album_id )
|
||||
{
|
||||
$album = \IPS\gallery\Album::constructFromData( $result );
|
||||
$album->setLastImage();
|
||||
$album = isset( $result ) ? \IPS\gallery\Album::constructFromData( $result ) : $image->directContainer();
|
||||
$album->setLastImage( $image );
|
||||
$album->save();
|
||||
}
|
||||
}
|
||||
@@ -638,7 +655,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
$consolidated = \IPS\Db::i()->select( 'SUM(album_comments) as comments, SUM(album_comments_unapproved) as unapproved_comments', 'gallery_albums', array( 'album_category_id=?', $this->_id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$consolidated = \IPS\Db::i()->select( 'SUM(album_comments) as comments, SUM(album_comments_unapproved) as unapproved_comments', 'gallery_albums', array( 'album_category_id=?', $this->_id ) )->first();
|
||||
|
||||
$this->_comments = $this->count_comments + $consolidated['comments'];
|
||||
$this->_unapprovedComments = $this->count_comments_hidden + $consolidated['unapproved_comments'];
|
||||
@@ -1070,4 +1087,34 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count all comments, items, etc
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function recount()
|
||||
{
|
||||
/* Now get the counts and set them for our images */
|
||||
$this->_items = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_category_id=? AND image_approved=1', $this->id ) )->first();
|
||||
$this->_unapprovedItems = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_images', array( 'image_category_id=? AND image_approved=0', $this->id ) )->first();
|
||||
|
||||
if( $this->allow_comments )
|
||||
{
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_category_id=? AND comment_approved=1 AND gallery_images.image_approved=1', $this->id ) )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
$this->_unapprovedComments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_category_id=? AND comment_approved=0', $this->id ) )->join( 'gallery_images', 'image_id=comment_img_id' )->first();
|
||||
|
||||
/* And then get counts/latest data for the direct comments/reviews */
|
||||
$this->_comments += (int) \IPS\Db::i()->select( 'sum(album_comments)', 'gallery_albums', array( 'album_category_id=?', $this->id ) )->first();
|
||||
$this->_unapprovedComments += (int) \IPS\Db::i()->select( 'sum(album_comments_unapproved)', 'gallery_albums', array( 'album_category_id=?', $this->id ) )->first();
|
||||
}
|
||||
|
||||
if( $this->allow_reviews )
|
||||
{
|
||||
$this->_reviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_category_id=? AND review_approved=1', $this->id ) )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
$this->_unapprovedReviews = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_reviews', array( 'gallery_images.image_category_id=? AND review_approved=0', $this->id ) )->join( 'gallery_images', 'image_id=review_image_id' )->first();
|
||||
|
||||
$this->_reviews += (int) \IPS\Db::i()->select( 'sum(album_reviews)', 'gallery_albums', array( 'album_category_id=?', $this->id ) )->first();
|
||||
$this->_unapprovedReviews += (int) \IPS\Db::i()->select( 'sum(album_reviews_unapproved)', 'gallery_albums', array( 'album_category_id=?', $this->id ) )->first();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,66 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
|
||||
if( $item->album_id )
|
||||
{
|
||||
\IPS\gallery\Album::load( $item->album_id )->setLastComment();
|
||||
\IPS\gallery\Album::load( $item->album_id )->save();
|
||||
$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() )
|
||||
{
|
||||
$album->_comments = ( $album->_comments + 1 );
|
||||
}
|
||||
elseif ( !$item->approvedButHidden() AND $this->hidden() == 1 )
|
||||
{
|
||||
$album->_unapprovedComments = ( $album->_unapprovedComments >= 0 ) ? ( $album->_unapprovedComments + 1 ) : 0;
|
||||
}
|
||||
|
||||
$album->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return void
|
||||
*/
|
||||
public function onHide( $member )
|
||||
{
|
||||
parent::onHide( $member );
|
||||
|
||||
$item = $this->item();
|
||||
if( $item->album_id )
|
||||
{
|
||||
$album = $item->directContainer();
|
||||
$album->setLastComment();
|
||||
$album->_comments = ( $album->_comments - 1 );
|
||||
$album->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @return void
|
||||
*/
|
||||
public function onUnhide( $approving, $member )
|
||||
{
|
||||
parent::onUnhide( $approving, $member );
|
||||
|
||||
$item = $this->item();
|
||||
if( $item->album_id )
|
||||
{
|
||||
$album = $item->directContainer();
|
||||
$album->setLastComment( $this );
|
||||
$album->_comments = ( $album->_comments + 1 );
|
||||
if( $approving )
|
||||
{
|
||||
$album->_unapprovedComments = ( $album->_unapprovedComments > 0 ) ? ( $album->_unapprovedComments - 1 ) : 0;
|
||||
}
|
||||
$album->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -987,22 +987,24 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
/* We need to sort on a unique value */
|
||||
$sortValue = $this->$sortBy . $this->updated;
|
||||
$sortBy = 'CONCAT(image_' . $sortBy . ',image_updated)';
|
||||
$where['date'] = array( "CONCAT(image_{$sortBy},image_updated) {$dir}= ?", $sortValue );
|
||||
$sortBy = 'image_' . $sortBy . ' ' . $direction. ',image_updated';
|
||||
}
|
||||
elseif( in_array( $sortBy, array( 'date', 'updated' ) ) )
|
||||
{
|
||||
/* We need to sort on a unique value */
|
||||
$sortValue = $this->$sortBy . $this->id;
|
||||
$sortBy = 'CONCAT(image_' . $sortBy . ',image_id)';
|
||||
$where['date'] = array( "CONCAT(image_{$sortBy},image_id) {$dir}= ?", $sortValue );
|
||||
$sortBy = 'image_' . $sortBy . ' ' . $direction. ',image_id';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortValue = $this->$sortBy;
|
||||
$sortBy = static::$databasePrefix . $sortBy;
|
||||
$where['date'] = array( $sortBy . " {$dir}= ?", $sortValue );
|
||||
}
|
||||
|
||||
$where['date'] = array( $sortBy . " {$dir}= ?", $sortValue );
|
||||
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, $sortBy . ' ' . $direction . ', image_id ' . $direction, $count ) );
|
||||
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, $sortBy . ' ' . $direction, $count, 'read', null, 0, null, false, false, false, false, null, false, false, false, false ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1231,6 +1233,31 @@ class _Image extends \IPS\Content\Item implements
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process created object AFTER the object has been created
|
||||
*
|
||||
* @param \IPS\Content\Comment|NULL $comment The first comment
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
protected function processAfterCreate( $comment, $values )
|
||||
{
|
||||
parent::processAfterCreate( $comment, $values );
|
||||
|
||||
if( $this->album_id and !$this->isFutureDate() )
|
||||
{
|
||||
if( $this->hidden() === 0 and !$this->isFutureDate() )
|
||||
{
|
||||
$this->directContainer()->_items = ( $this->directContainer()->_items + 1 );
|
||||
}
|
||||
elseif( $this->hidden() === 1 )
|
||||
{
|
||||
$this->directContainer()->_unapprovedItems = ( $this->directContainer()->_unapprovedItems + 1 );
|
||||
}
|
||||
$this->directContainer()->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process after the object has been edited on the front-end
|
||||
*
|
||||
@@ -1292,7 +1319,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
/* Get the file... */
|
||||
$file = NULL;
|
||||
if( isset( $values['imageLocation'] ) AND $values['imageLocation'] )
|
||||
if( isset( $values['imageLocation'] ) AND $values['imageLocation'] and $values['imageLocation'] != $this->original_file_name)
|
||||
{
|
||||
$file = \IPS\File::get( 'gallery_Images', $values['imageLocation'] );
|
||||
if ( isset( $values['imageRequiresModeration'] ) )
|
||||
@@ -1907,6 +1934,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
if( $previousAlbum )
|
||||
{
|
||||
$album = \IPS\gallery\Album::load( $previousAlbum );
|
||||
$album->_items = $album->_items -1;
|
||||
$album->setLastImage();
|
||||
$album->save();
|
||||
}
|
||||
@@ -1915,6 +1943,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
if( $this->album_id )
|
||||
{
|
||||
$album = \IPS\gallery\Album::load( $this->album_id );
|
||||
$album->_items = $album->_items +1;
|
||||
$album->setLastImage();
|
||||
$album->save();
|
||||
}
|
||||
@@ -2084,37 +2113,51 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function getItemsWithPermissionWhere( $where, $member, &$joins )
|
||||
{
|
||||
/* Then we need to make sure we can access the album the image is in, if applicable */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$restricted = $member->socialGroups();
|
||||
|
||||
/* If you can edit images in a category you can see images in private albums in that category. We can only really check globally at this stage, however. */
|
||||
if( \IPS\gallery\Image::modPermission( 'edit', $member ) )
|
||||
/* If we already filtered by a specific album, we can stop right here */
|
||||
if( array_key_exists( 'album', $where ) )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if( \count( $restricted ) )
|
||||
/* Then we need to make sure we can access the album the image is in, if applicable */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* Skip permissions for guests */
|
||||
if( !$member->member_id )
|
||||
{
|
||||
$subQuery = array( "( album_type=1 OR ( album_type=2 AND album_owner_id=? ) OR ( album_type=3 AND ( album_owner_id=? OR album_allowed_access IN (" . implode( ',', $restricted ) . ") ) ) )", $member->member_id, $member->member_id );
|
||||
$subQuery = array( "album_type=1 AND album_hidden=0" );
|
||||
}
|
||||
else
|
||||
{
|
||||
$subQuery = array( "( album_type=1 OR ( album_type=2 AND album_owner_id=? ) )", $member->member_id );
|
||||
}
|
||||
|
||||
/* Make sure the images aren't in hidden albums, unless we can view hidden albums */
|
||||
$hiddenContainers = \IPS\gallery\Album\Item::canViewHiddenItemsContainers( $member );
|
||||
|
||||
if( $hiddenContainers !== TRUE )
|
||||
{
|
||||
if( \is_array( $hiddenContainers ) AND \count( $hiddenContainers ) )
|
||||
/* If you can edit images in a category you can see images in private albums in that category. We can only really check globally at this stage, however. */
|
||||
if( \IPS\gallery\Image::modPermission( 'edit', $member ) )
|
||||
{
|
||||
$subQuery[0] .= " AND ( album_hidden=0 OR album_category_id IN(" . implode( ',', $hiddenContainers ) . ") )";
|
||||
return array();
|
||||
}
|
||||
|
||||
$restricted = $member->socialGroups();
|
||||
if( \count( $restricted ) )
|
||||
{
|
||||
$subQuery = array( "( album_type=1 OR ( album_type=2 AND album_owner_id=? ) OR ( album_type=3 AND ( album_owner_id=? OR album_allowed_access IN (" . implode( ',', $restricted ) . ") ) ) )", $member->member_id, $member->member_id );
|
||||
}
|
||||
else
|
||||
{
|
||||
$subQuery[0] .= " AND album_hidden=0";
|
||||
$subQuery = array( "( album_type=1 OR ( album_type=2 AND album_owner_id=? ) )", $member->member_id );
|
||||
}
|
||||
|
||||
/* Make sure the images aren't in hidden albums, unless we can view hidden albums */
|
||||
$hiddenContainers = \IPS\gallery\Album\Item::canViewHiddenItemsContainers( $member );
|
||||
|
||||
if( $hiddenContainers !== TRUE )
|
||||
{
|
||||
if( \is_array( $hiddenContainers ) AND \count( $hiddenContainers ) )
|
||||
{
|
||||
$subQuery[0] .= " AND ( album_hidden=0 OR album_category_id IN(" . implode( ',', $hiddenContainers ) . ") )";
|
||||
}
|
||||
else
|
||||
{
|
||||
$subQuery[0] .= " AND album_hidden=0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2470,6 +2513,12 @@ class _Image extends \IPS\Content\Item implements
|
||||
return $member->group['g_download_original'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Store club node IDs so we can save on queries
|
||||
* @var array|null
|
||||
*/
|
||||
protected static ?array $_clubNodeIds = null;
|
||||
|
||||
/**
|
||||
* Return query WHERE clause to use for getItemsWithPermission when excluding club content
|
||||
*
|
||||
@@ -2477,17 +2526,22 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public static function clubImageExclusion(): array
|
||||
{
|
||||
if( \IPS\Settings::i()->club_nodes_in_apps )
|
||||
if( !\IPS\Settings::i()->club_nodes_in_apps )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
else
|
||||
{
|
||||
return array( array(
|
||||
'gallery_images.image_category_id NOT IN(?)',
|
||||
\IPS\Db::i()->select( 'node_id', 'core_clubs_node_map', array( 'node_class=?', 'IPS\gallery\Category' ) )
|
||||
) );
|
||||
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' ) ) );
|
||||
}
|
||||
|
||||
if( \count( static::$_clubNodeIds ) )
|
||||
{
|
||||
return array(
|
||||
array( \IPS\Db::i()->in( 'gallery_images.image_category_id', static::$_clubNodeIds, true ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user