Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -24,12 +24,21 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\Embeddable
|
||||
{
|
||||
/**
|
||||
* @brief Define access levels
|
||||
* @brief Define view access levels
|
||||
*/
|
||||
const AUTH_TYPE_PUBLIC = 1;
|
||||
const AUTH_TYPE_PRIVATE = 2;
|
||||
const AUTH_TYPE_RESTRICTED = 3;
|
||||
const AUTH_TYPE_DELETED = 4;
|
||||
|
||||
/**
|
||||
* @brief Define submit access levels
|
||||
*/
|
||||
const AUTH_SUBMIT_OWNER = 0;
|
||||
const AUTH_SUBMIT_PUBLIC = 1;
|
||||
const AUTH_SUBMIT_GROUPS = 2;
|
||||
const AUTH_SUBMIT_MEMBERS = 3;
|
||||
const AUTH_SUBMIT_CLUB = 4;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -124,16 +133,19 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/**
|
||||
* [Node] Load and check permissions
|
||||
*
|
||||
* @param mixed $id ID
|
||||
* @param string $perm Permission Key
|
||||
* @param mixed $id ID
|
||||
* @param string $perm Permission Key
|
||||
* @param \IPS\Member|NULL $member Member, or NULL for logged in member
|
||||
* @return static
|
||||
* @throws \OutOfRangeException
|
||||
* @note Album 'add' permissions are properly checked via the can() method
|
||||
*/
|
||||
public static function loadAndCheckPerms( $id, $perm='view' )
|
||||
public static function loadAndCheckPerms( $id, $perm='view', \IPS\Member $member = NULL )
|
||||
{
|
||||
$obj = parent::loadAndCheckPerms( $id );
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if ( !$obj->category()->can( $perm ) )
|
||||
if ( !$obj->can( $perm ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
@@ -147,23 +159,23 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
if( !\IPS\gallery\Image::modPermission( 'edit', NULL, $obj->category() ) )
|
||||
{
|
||||
/* Throw exception if this is a private album we can't access */
|
||||
if( $obj->type == static::AUTH_TYPE_PRIVATE AND $obj->owner() != \IPS\Member::loggedIn() )
|
||||
if( $obj->type == static::AUTH_TYPE_PRIVATE AND $obj->owner() != $member )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Throw exception if this is a restricted album we can't access */
|
||||
if( $obj->type == static::AUTH_TYPE_RESTRICTED AND $obj->owner() != \IPS\Member::loggedIn() )
|
||||
if( $obj->type == static::AUTH_TYPE_RESTRICTED AND $obj->owner() != $member )
|
||||
{
|
||||
/* This will throw an exception if the row does not exist... but we need it to throw an OutOfRangeException */
|
||||
try
|
||||
{
|
||||
if( !\IPS\Member::loggedIn()->member_id )
|
||||
if( !$member->member_id )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
$member = \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=? AND member_id=?', $obj->allowed_access, \IPS\Member::loggedIn()->member_id ) )->first();
|
||||
$member = \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=? AND member_id=?', $obj->allowed_access, $member->member_id ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
@@ -174,6 +186,27 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all albums we can submit to
|
||||
*
|
||||
* @param \IPS\gallery\Category $category Category we are submitting in
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function loadForSubmit( $category )
|
||||
{
|
||||
$ownedAlbums = static::loadByOwner( NULL, array( array( 'album_category_id=?', $category->id ) ) );
|
||||
$permittedAlbums = \IPS\gallery\Album\Item::getItemsWithPermission( array( array( 'album_category_id=?', $category->id ) ), NULL, NULL, 'add' );
|
||||
$finalAlbums = $ownedAlbums;
|
||||
|
||||
foreach( $permittedAlbums as $album )
|
||||
{
|
||||
$finalAlbums[ $album->id ] = $album->asNode();
|
||||
}
|
||||
|
||||
return $finalAlbums;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all nodes owned by a given user
|
||||
@@ -196,7 +229,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
protected $_approvedMembers = FALSE;
|
||||
|
||||
/**
|
||||
* Get members with access to restricted album
|
||||
* Get members with access to view restricted album
|
||||
*
|
||||
* @return array|null
|
||||
* @note This list will NOT include the album owner, who also inherently has access
|
||||
@@ -288,6 +321,17 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
return $this->count_imgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items count language string
|
||||
*
|
||||
* @return string
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function get__countLanguageString()
|
||||
{
|
||||
return 'num_images';
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get number of content comments
|
||||
*
|
||||
@@ -442,7 +486,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\Text( 'album_name', $album ? $album->name : '', $required ?: NULL );
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\Editor( 'album_description', $album ? $album->description : '', FALSE, array( 'app' => 'gallery', 'key' => 'Albums', 'autoSaveKey' => ( $album ? "gallery_album_{$album->id}_desc" : "gallery-new-album" ), 'attachIds' => $album ? array( $album->id, NULL, 'description' ) : NULL, 'minimize' => 'cdesc_placeholder' ) );
|
||||
$return[] = new \IPS\Helpers\Form\Editor( 'album_description', $album ? $album->description : '', FALSE, array( 'app' => 'gallery', 'key' => 'Albums', 'autoSaveKey' => ( $album ? "gallery_album_{$album->id}_desc" : "gallery-new-album" ), 'attachIds' => $album ? array( $album->id, NULL, 'description' ) : NULL ) );
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\Node( 'album_category', ( $album and $album->category_id ) ? \IPS\gallery\Category::load( $album->category_id ) : NULL, $required ?: NULL, array(
|
||||
'class' => 'IPS\gallery\Category',
|
||||
@@ -463,7 +507,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
}
|
||||
) );
|
||||
|
||||
if( $forOther or \IPS\gallery\Image::modPermission( 'edit', NULL, ( $album ? $album->category() : NULL ) ) )
|
||||
if( $forOther or \IPS\gallery\Album\Item::modPermission( 'edit', NULL, ( $album ? $album->category() : NULL ) ) )
|
||||
{
|
||||
if ( !$forOther )
|
||||
{
|
||||
@@ -497,8 +541,37 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
{
|
||||
$return[] = new \IPS\Helpers\Form\SocialGroup( 'album_allowed_access', $album ? $album->allowed_access : NULL, FALSE, array( 'owner' => $album ? \IPS\Member::load( $album->owner_id ) : ( \IPS\Request::i()->album_owner ? \IPS\Member::load( \IPS\Request::i()->album_owner, 'name' ) : \IPS\Member::loggedIn() ) ), NULL, NULL, NULL, 'album_allowed_access' );
|
||||
}
|
||||
|
||||
$submitTypes = array(
|
||||
static::AUTH_SUBMIT_OWNER => 'album_submittype_owner',
|
||||
static::AUTH_SUBMIT_PUBLIC => 'album_submittype_public',
|
||||
static::AUTH_SUBMIT_GROUPS => 'album_submittype_groups',
|
||||
static::AUTH_SUBMIT_MEMBERS => 'album_submittype_members'
|
||||
);
|
||||
|
||||
/* Is the category in a club */
|
||||
if( $album AND $album->category_id )
|
||||
{
|
||||
if( $album->category()->club() )
|
||||
{
|
||||
$submitTypes[ static::AUTH_SUBMIT_CLUB ] = 'album_submittype_club';
|
||||
}
|
||||
}
|
||||
elseif( !$album AND ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) )
|
||||
{
|
||||
if( \IPS\gallery\Category::load( (int) \IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category )->club() )
|
||||
{
|
||||
$submitTypes[ static::AUTH_SUBMIT_CLUB ] = 'album_submittype_club';
|
||||
}
|
||||
}
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\Radio( 'album_submit_type', ( $album and $album->submit_type ) ? $album->submit_type : static::AUTH_SUBMIT_OWNER, FALSE, array( 'options' => $submitTypes, 'toggles' => array( static::AUTH_SUBMIT_MEMBERS => array( 'album_submit_access_members' ), static::AUTH_SUBMIT_GROUPS => array( 'album_submit_access_groups' ) ) ), NULL, NULL, NULL, 'album_submit_type' );
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\SocialGroup( 'album_submit_access_members', ( $album AND $album->submit_type == static::AUTH_SUBMIT_MEMBERS ) ? $album->submit_access : NULL, FALSE, array( 'owner' => $album ? \IPS\Member::load( $album->owner_id ) : ( \IPS\Request::i()->album_owner ? \IPS\Member::load( \IPS\Request::i()->album_owner, 'name' ) : \IPS\Member::loggedIn() ) ), NULL, NULL, NULL, 'album_submit_access_members' );
|
||||
$groups = array_combine( array_keys( \IPS\Member\Group::groups( TRUE, FALSE ) ), array_map( function( $_group ) { return (string) $_group; }, \IPS\Member\Group::groups( TRUE, FALSE ) ) );
|
||||
$return[] = new \IPS\Helpers\Form\Select( 'album_submit_access_groups', ( $album and $album->submit_type == static::AUTH_SUBMIT_GROUPS ) ? explode( ',', $album->submit_access ) : NULL, FALSE, array( 'options' => $groups, 'multiple' => true ), NULL, NULL, NULL, 'album_submit_access_groups' );
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\Select( 'album_sort_options', ( $album and $album->sort_options ) ? $album->sort_options : 'updated', FALSE, array( 'options' => array( 'updated' => 'sort_updated', 'last_comment' => 'sort_last_comment', 'title' => 'sort_title', 'rating' => 'sort_rating', 'date' => 'sort_date', 'num_comments' => 'sort_num_comments', 'num_reviews' => 'sort_num_reviews', 'views' => 'sort_views' ) ), NULL, NULL, NULL, 'album_sort_options' );
|
||||
$return[] = new \IPS\Helpers\Form\Select( 'album_sort_options', ( $album and $album->sort_options ) ? $album->sort_options : 'updated', FALSE, array( 'options' => array( 'updated' => 'sort_updated', 'last_comment' => 'sort_last_comment', 'title' => 'album_sort_caption', 'rating' => 'sort_rating', 'date' => 'sort_date', 'num_comments' => 'sort_num_comments', 'num_reviews' => 'sort_num_reviews', 'views' => 'sort_views' ) ), NULL, NULL, NULL, 'album_sort_options' );
|
||||
|
||||
$return[] = new \IPS\Helpers\Form\YesNo( 'album_allow_rating', $album ? $album->allow_rating : TRUE, FALSE );
|
||||
|
||||
@@ -624,11 +697,25 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
$values['owner_id'] = ( $values['album_owner'] instanceof \IPS\Member ) ? $values['album_owner']->member_id : $values['album_owner'];
|
||||
unset( $values['album_owner'] );
|
||||
}
|
||||
else
|
||||
else if ( !$this->postSaveIsEdit )
|
||||
{
|
||||
$values['owner_id'] = \IPS\Member::loggedIn()->member_id;
|
||||
}
|
||||
|
||||
switch( $values['album_submit_type'] )
|
||||
{
|
||||
case static::AUTH_SUBMIT_GROUPS:
|
||||
$values['submit_access'] = implode( ',', $values['album_submit_access_groups'] );
|
||||
break;
|
||||
|
||||
case static::AUTH_SUBMIT_MEMBERS:
|
||||
$values['submit_access'] = $values['album_submit_access_members'];
|
||||
break;
|
||||
}
|
||||
|
||||
unset( $values['album_submit_access_members'] );
|
||||
unset( $values['album_submit_access_groups'] );
|
||||
|
||||
/* Send to parent */
|
||||
return $values;
|
||||
}
|
||||
@@ -656,6 +743,8 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
{
|
||||
\IPS\File::claimAttachments( 'gallery-new-album', $this->id );
|
||||
|
||||
/* Update counts in categories if we move the album */
|
||||
if( $this->postSaveIsEdit and $this->postSaveCategory != $values['category_id'] )
|
||||
{
|
||||
@@ -732,6 +821,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
/* Update caches */
|
||||
$asItem->expireWidgetCaches();
|
||||
$asItem->adjustSessions();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -815,7 +905,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
$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 )
|
||||
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 )
|
||||
{
|
||||
if( $image['image_date'] > $this->last_img_date )
|
||||
{
|
||||
@@ -829,23 +919,23 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
$this->last_x_images = json_encode( $_latestImages );
|
||||
|
||||
/* 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();
|
||||
$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();
|
||||
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_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();
|
||||
$this->_comments = \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_comments', array( 'gallery_images.image_album_id=? AND comment_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 ) )->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();
|
||||
$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();
|
||||
|
||||
/* 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();
|
||||
$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 ) )->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();
|
||||
$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();
|
||||
|
||||
/* Save and then make sure search index is updated */
|
||||
\IPS\Content\Search\Index::i()->index( $this->asItem() );
|
||||
@@ -861,14 +951,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
*/
|
||||
public function contentImages( $limit = NULL )
|
||||
{
|
||||
$images = array();
|
||||
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_album_id=?', $this->id ) ), NULL, $limit ? $limit : 10 ) as $image )
|
||||
{
|
||||
$images[] = array( 'gallery_Images' => $image->medium_file_name );
|
||||
}
|
||||
|
||||
return count( $images ) ? $images : NULL;
|
||||
$this->asItem()->contentImages( $limit );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1047,45 +1130,53 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/**
|
||||
* Retrieve a cover photo
|
||||
*
|
||||
* @param string $size One of full, medium, small or thumb
|
||||
* @param string $size Masked or small
|
||||
* @return string|null
|
||||
*/
|
||||
public function coverPhoto( $size='thumb' )
|
||||
public function coverPhoto( $size='small' )
|
||||
{
|
||||
/* Can we view the images in this album? */
|
||||
if ( !$this->can( 'read' ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( $size == 'full' )
|
||||
/* Make sure it's a valid size */
|
||||
if( !in_array( $size, array( 'masked', 'small' ) ) )
|
||||
{
|
||||
$size = 'masked';
|
||||
throw new \InvalidArgumentException;
|
||||
}
|
||||
|
||||
$property = $size . "_file_name";
|
||||
|
||||
if( !$this->cover_img_id )
|
||||
/* If we have an explicit cover photo set, make sure it's valid and load/cache it */
|
||||
if( $this->cover_img_id )
|
||||
{
|
||||
if( $lastImage = $this->lastImage() )
|
||||
if( $this->coverPhoto === NULL )
|
||||
{
|
||||
return (string) \IPS\File::get( 'gallery_Images', $lastImage->$property )->url;
|
||||
try
|
||||
{
|
||||
$this->coverPhoto = \IPS\gallery\Image::load( $this->cover_img_id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
/* Cover photo isn't valid, reset album automatically */
|
||||
$this->cover_img_id = 0;
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if( $this->coverPhoto !== NULL )
|
||||
{
|
||||
return (string) \IPS\File::get( 'gallery_Images', $this->coverPhoto->$property )->url;
|
||||
}
|
||||
}
|
||||
|
||||
if( !in_array( $size, array( 'masked', 'medium', 'small', 'thumb' ) ) )
|
||||
if( $lastImage = $this->lastImage() AND !$lastImage->media )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
return (string) \IPS\File::get( 'gallery_Images', $lastImage->$property )->url;
|
||||
}
|
||||
|
||||
if( $this->coverPhoto === NULL )
|
||||
{
|
||||
$this->coverPhoto = \IPS\gallery\Image::load( $this->cover_img_id );
|
||||
}
|
||||
|
||||
return (string) \IPS\File::get( 'gallery_Images', $this->coverPhoto->$property )->url;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1132,7 +1223,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return $this->asItem()->canDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1149,6 +1240,55 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/* Load the item */
|
||||
$asItem = $this->asItem();
|
||||
|
||||
/* Figure out member */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If we are checking 'add' permission, verify if we can add */
|
||||
if( $permission == 'add' )
|
||||
{
|
||||
/* First check we can submit to this album based on the "Submissions" setting */
|
||||
switch ( $this->submit_type )
|
||||
{
|
||||
/* Owner */
|
||||
case static::AUTH_SUBMIT_OWNER:
|
||||
if ( $this->owner_id != $member->member_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Chosen groups */
|
||||
case static::AUTH_SUBMIT_GROUPS:
|
||||
if ( !$member->inGroup( explode( ',', $this->submit_access ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Chosen members */
|
||||
case static::AUTH_SUBMIT_MEMBERS:
|
||||
if ( !in_array( $this->submit_access, $member->socialGroups() ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Club */
|
||||
case static::AUTH_SUBMIT_CLUB:
|
||||
if ( $club = $this->category()->club() and !in_array( $club->id, $member->clubs() ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Verify if we can add any more files to this album */
|
||||
if( \IPS\Member::loggedIn()->group['g_img_album_limit'] AND \IPS\Member::loggedIn()->group['g_img_album_limit'] - ( $this->count_imgs + $this->count_imgs_hidden ) < 1 )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Albums can be hidden, so make sure to test permissions */
|
||||
if( $asItem->hidden() )
|
||||
{
|
||||
@@ -1190,7 +1330,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
*/
|
||||
public function searchIndexPermissions()
|
||||
{
|
||||
$return = parent::searchIndexPermissions();
|
||||
$return = $this->category()->searchIndexPermissions();
|
||||
|
||||
if ( $this->type != static::AUTH_TYPE_PUBLIC )
|
||||
{
|
||||
@@ -1250,6 +1390,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
@@ -1261,17 +1402,17 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
* @apiresponse int images Number of images
|
||||
* @apiresponse string url URL
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'category' => $this->category()->apiOutput(),
|
||||
'owner' => $this->owner()->apiOutput(),
|
||||
'category' => $this->category()->apiOutput( $authorizedMember ),
|
||||
'owner' => $this->owner()->apiOutput( $authorizedMember ),
|
||||
'privacy' => ( $this->type == static::AUTH_TYPE_PUBLIC ) ? 'public' : ( $this->type == static::AUTH_TYPE_PRIVATE ? 'private' : ( $this->type == static::AUTH_TYPE_RESTRICTED ? 'restricted' : null ) ),
|
||||
'approvedMembers' => $this->approvedMembers ? array_map( function( $val ) {
|
||||
return $val->apiOutput();
|
||||
'approvedMembers' => $this->approvedMembers ? array_map( function( $val ) use ( $authorizedMember ) {
|
||||
return $val->apiOutput( $authorizedMember );
|
||||
}, $this->approvedMembers ) : null,
|
||||
'images' => $this->count_imgs,
|
||||
'url' => (string) $this->url()
|
||||
|
||||
@@ -21,9 +21,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Album Comment Model
|
||||
*/
|
||||
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\ReportCenter, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
{
|
||||
use \IPS\Content\Reactable;
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -123,7 +123,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
{
|
||||
parent::postCreate();
|
||||
|
||||
$this->item()->asNode()->setLastComment();
|
||||
$this->item()->asNode()->setLastComment( $this );
|
||||
$this->item()->asNode()->save();
|
||||
}
|
||||
|
||||
@@ -173,4 +173,16 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
\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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container item class to use for mod permission checks
|
||||
*
|
||||
* @return string|NULL
|
||||
* @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()
|
||||
{
|
||||
return 'IPS\gallery\Album\Item';
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,9 @@ class _Item extends \IPS\Content\Item implements
|
||||
\IPS\Content\Hideable,
|
||||
\IPS\Content\Featurable,
|
||||
\IPS\Content\Lockable,
|
||||
\IPS\Content\ReportCenter,
|
||||
\IPS\Content\MetaData
|
||||
{
|
||||
use \IPS\Content\Reactable;
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
@@ -230,7 +229,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
{
|
||||
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 )->thumb_file_name );
|
||||
return \IPS\File::get( 'gallery_Images', \IPS\gallery\Image::load( $this->cover_img_id ?: $this->last_img_id )->small_file_name );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -279,10 +278,48 @@ class _Item extends \IPS\Content\Item implements
|
||||
*/
|
||||
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 )
|
||||
{
|
||||
if( $permissionKey == 'add' )
|
||||
{
|
||||
$where[] = static::submitRestrictionWhere( $member, \IPS\gallery\Category::load( $where[0][1] ) );
|
||||
}
|
||||
|
||||
$where[] = static::getItemsWithPermissionWhere( $where, $member, $joins );
|
||||
|
||||
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins, $skipPermission, $joinTags, $joinAuthor, $joinLastCommenter, $showMovedLinks );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return string
|
||||
*/
|
||||
public static function submitRestrictionWhere( $member, $category )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* 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 . ')'
|
||||
);
|
||||
|
||||
/* 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 ) . ')';
|
||||
|
||||
/* 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() ) . ')';
|
||||
|
||||
/* 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() ) )
|
||||
{
|
||||
$wheres[] = '(album_submit_type=' . \IPS\gallery\Album::AUTH_SUBMIT_CLUB . ')';
|
||||
}
|
||||
|
||||
return '(album_owner_id=' . $member->member_id . ' OR ' . implode( ' OR ', $wheres ) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached groups the member can access
|
||||
*/
|
||||
@@ -368,24 +405,6 @@ class _Item extends \IPS\Content\Item implements
|
||||
return $this->asNode()->searchIndexPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Can edit?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
|
||||
* @return bool
|
||||
*/
|
||||
public function canEdit( $member=NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if( $member->member_id == $this->mapped('author') )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return parent::canEdit( $member );
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns needed to query for search result / stream view
|
||||
*
|
||||
@@ -433,8 +452,13 @@ class _Item extends \IPS\Content\Item implements
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach ( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_id IN(' . implode( ',', $imageIds ) . ')' ) ), NULL, 20 ) as $image )
|
||||
foreach ( \IPS\gallery\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 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$return[ $image->album_id ][] = $image;
|
||||
}
|
||||
|
||||
@@ -464,6 +488,29 @@ class _Item extends \IPS\Content\Item implements
|
||||
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
|
||||
* @return string
|
||||
*/
|
||||
public static function searchResultSummaryLanguage( $authorData, $articles, $indexData, $itemData )
|
||||
{
|
||||
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( $authorData['name'], $articles['indefinite'] ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::searchResultSummaryLanguage( $authorData, $articles, $indexData, $itemData );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief A classname applied to the search result block
|
||||
*/
|
||||
@@ -516,7 +563,7 @@ class _Item extends \IPS\Content\Item implements
|
||||
{
|
||||
\IPS\gallery\Application::outputCss();
|
||||
|
||||
return array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery' ), 'albums' );
|
||||
return array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery', 'front' ), 'albums' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -581,4 +628,36 @@ class _Item extends \IPS\Content\Item implements
|
||||
\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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container item class to use for mod permission checks
|
||||
*
|
||||
* @return string|NULL
|
||||
* @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()
|
||||
{
|
||||
return 'IPS\gallery\Album\Item';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content images
|
||||
*
|
||||
* @param int|null $limit Number of attachments to fetch, or NULL for all
|
||||
*
|
||||
* @return array|NULL If array, then array( 'core_Attachment' => 'month_x/foo.gif', ... );
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function contentImages( $limit = NULL )
|
||||
{
|
||||
$images = array();
|
||||
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_album_id=?', $this->id ) ), NULL, $limit ? $limit : 10 ) as $image )
|
||||
{
|
||||
$images[] = array( 'gallery_Images' => $image->masked_file_name );
|
||||
}
|
||||
|
||||
return count( $images ) ? $images : NULL;
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,9 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
/**
|
||||
* Album Review Model
|
||||
*/
|
||||
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\ReportCenter, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \IPS\Content\Hideable, \IPS\Content\Searchable, \IPS\Content\Embeddable
|
||||
{
|
||||
use \IPS\Content\Reactable;
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
@@ -63,6 +63,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
'votes_helpful' => 'votes_helpful',
|
||||
'votes_data' => 'votes_data',
|
||||
'approved' => 'approved',
|
||||
'author_response' => 'author_response',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -105,7 +106,7 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
{
|
||||
parent::postCreate();
|
||||
|
||||
$this->item()->asNode()->setLastComment();
|
||||
$this->item()->asNode()->setLastReview( $this );
|
||||
$this->item()->asNode()->save();
|
||||
}
|
||||
|
||||
@@ -152,4 +153,16 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
\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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container item class to use for mod permission checks
|
||||
*
|
||||
* @return string|NULL
|
||||
* @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()
|
||||
{
|
||||
return 'IPS\gallery\Album\Item';
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class _Table extends \IPS\Helpers\Table\Content
|
||||
{
|
||||
if ( !$this->sortBy and $container->_sortBy )
|
||||
{
|
||||
$this->sortBy = '`' . \IPS\gallery\Album::$databaseTable . '`.`' . \IPS\gallery\Album::$databasePrefix . $container->_sortBy . '`';
|
||||
$this->sortBy = \IPS\gallery\Album::$databasePrefix . $container->_sortBy;
|
||||
$this->sortDirection = $container->_sortOrder;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class _Table extends \IPS\Helpers\Table\Content
|
||||
$this->filter = $container->_filter;
|
||||
}
|
||||
|
||||
if ( $this->sortBy === 'name' )
|
||||
if ( $this->sortBy === 'album_name' )
|
||||
{
|
||||
$this->sortDirection = 'asc';
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class _Table extends \IPS\Helpers\Table\Content
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->sortOptions[ 'album_' . $k ] = $k;
|
||||
$this->sortOptions[ 'album_' . $k ] = 'album_' . $k;
|
||||
}
|
||||
|
||||
unset( $this->sortOptions['date'] );
|
||||
@@ -151,4 +151,21 @@ class _Table extends \IPS\Helpers\Table\Content
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return string [asc|desc]
|
||||
*/
|
||||
public function getSortDirection( $column )
|
||||
{
|
||||
if( $column == 'album_name' )
|
||||
{
|
||||
return 'asc';
|
||||
}
|
||||
|
||||
return 'desc';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user