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