Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -144,44 +144,15 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
{
|
||||
$obj = parent::loadAndCheckPerms( $id );
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if ( !$obj->can( $perm ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
if ( $obj->type == static::AUTH_TYPE_DELETED )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/* If we don't have edit permission in the category, check album restrictions */
|
||||
if( !\IPS\gallery\Image::modPermission( 'edit', NULL, $obj->category() ) )
|
||||
if ( !$obj->can( $perm ) )
|
||||
{
|
||||
/* Throw exception if this is a private album we can't access */
|
||||
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() != $member )
|
||||
{
|
||||
/* This will throw an exception if the row does not exist... but we need it to throw an OutOfRangeException */
|
||||
try
|
||||
{
|
||||
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, $member->member_id ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@@ -342,6 +313,16 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
return $this->count_comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get number of content comments (for display)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get__commentsForDisplay()
|
||||
{
|
||||
return $this->_comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get number of content reviews
|
||||
*
|
||||
@@ -539,7 +520,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
if( \IPS\Member::loggedIn()->group['g_create_albums_fo'] )
|
||||
{
|
||||
$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' );
|
||||
$return[] = new \IPS\Helpers\Form\SocialGroup( 'album_allowed_access', $album ? (int) $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(
|
||||
@@ -567,7 +548,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
|
||||
$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' );
|
||||
$return[] = new \IPS\Helpers\Form\SocialGroup( 'album_submit_access_members', ( $album AND $album->submit_type == static::AUTH_SUBMIT_MEMBERS ) ? (int) $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' );
|
||||
|
||||
@@ -922,7 +903,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
$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 ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->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 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();
|
||||
@@ -1218,11 +1199,6 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if( $this->owner_id == \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->group['g_delete_own_albums'] )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $this->asItem()->canDelete();
|
||||
}
|
||||
|
||||
@@ -1243,68 +1219,129 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
|
||||
/* Figure out member */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If we are checking 'add' permission, verify if we can add */
|
||||
if( $permission == 'add' )
|
||||
/* Are we looking at a member? */
|
||||
if( $member instanceof \IPS\Member )
|
||||
{
|
||||
/* First check we can submit to this album based on the "Submissions" setting */
|
||||
switch ( $this->submit_type )
|
||||
/* If we don't have edit permission in the category, check album restrictions */
|
||||
if( !\IPS\gallery\Image::modPermission( 'edit', $member, $this->category() ) )
|
||||
{
|
||||
/* Owner */
|
||||
case static::AUTH_SUBMIT_OWNER:
|
||||
if ( $this->owner_id != $member->member_id )
|
||||
/* Deny access if the album is private and we aren't the owner */
|
||||
if( $this->type == static::AUTH_TYPE_PRIVATE AND $this->owner() != $member )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If this is a restricted album, check that we're "on the list" */
|
||||
if( $this->type == static::AUTH_TYPE_RESTRICTED AND $this->owner() != $member )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !$member->member_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=? AND member_id=?', $this->allowed_access, $member->member_id ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
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 )
|
||||
|
||||
/* If we are checking 'add' permission, verify if we can add */
|
||||
if( $permission == 'add' )
|
||||
{
|
||||
return FALSE;
|
||||
/* 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() ) AND $this->owner_id != $member->member_id )
|
||||
{
|
||||
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( $member->group['g_img_album_limit'] AND $member->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() )
|
||||
{
|
||||
if( !$asItem->canView( $member ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$methodToCheck = "can" . \ucwords( $permission );
|
||||
|
||||
if( method_exists( $asItem, $methodToCheck ) )
|
||||
{
|
||||
return $asItem->$methodToCheck( $member );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $asItem->can( $permission, $member );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Albums can be hidden, so make sure to test permissions */
|
||||
if( $asItem->hidden() )
|
||||
/* Or are we looking at a group? */
|
||||
else
|
||||
{
|
||||
if( !$asItem->canView( $member ) )
|
||||
if( $permission == 'add' )
|
||||
{
|
||||
return FALSE;
|
||||
/* Verify if the group is in the submit list */
|
||||
if( $this->submit_type == static::AUTH_SUBMIT_GROUPS AND !in_array( $member->g_id, explode( ',', $this->submit_access ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Verify if we can add any more files to this album */
|
||||
if( $member->g_img_album_limit AND $member->g_img_album_limit - ( $this->count_imgs + $this->count_imgs_hidden ) < 1 )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$methodToCheck = "can" . \ucwords( $permission );
|
||||
/* Albums can be hidden, so make sure to test permissions */
|
||||
if( $asItem->hidden() )
|
||||
{
|
||||
if( !$asItem->can( 'view', $member ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( method_exists( $asItem, $methodToCheck ) )
|
||||
{
|
||||
return $asItem->$methodToCheck( $member );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $asItem->can( $permission, $member );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user