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