Version 4.7.8

This commit is contained in:
Neo committed 2025-12-19 16:10:42 -08:00
1 parent 7b7404e741
commit fd22d99e69
688 files changed
+19814 -10890

No files matched your search

+75 -29
View File
@@ -80,6 +80,18 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
*/
public static $contentItemClass = 'IPS\gallery\Image';
/* These are required to be declared here as well as the asItem class for embeds.
/**
* @brief Review Class
*/
public static $reviewClass = 'IPS\gallery\Album\Review';
/**
* @brief Comment Class
*/
public static $commentClass = 'IPS\gallery\Album\Comment';
/**
* @brief [Node] If the node can be "owned", the owner "type" (typically "member" or "group") and the associated database column
*/
@@ -473,13 +485,28 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
*/
public static function formFields( \IPS\gallery\Album $album = NULL, $forOther = FALSE, $required = TRUE )
{
/* Save my sanity here.... load the category if we have one */
$category = NULL;
if( $album AND $album->category_id )
{
$category = $album->category();
}
elseif( !$album AND ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) )
{
try
{
$category = \IPS\gallery\Category::load( (int)\IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category );
}
catch( \OutOfRangeException $e ){}
}
$return = array();
$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 ) );
$return[] = new \IPS\Helpers\Form\Node( 'album_category', ( $album and $album->category_id ) ? \IPS\gallery\Category::load( $album->category_id ) : NULL, $required ?: NULL, array(
$return[] = new \IPS\Helpers\Form\Node( 'album_category', $category ? $category->id : NULL, $required ?: NULL, array(
'class' => 'IPS\gallery\Category',
'disabled' => false,
'permissionCheck' => function( $node )
@@ -541,19 +568,9 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
);
/* Is the category in a club */
if( $album AND $album->category_id )
if( $category !== NULL AND $club = $category->club() )
{
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';
}
$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' );
@@ -561,25 +578,25 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
$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\CheckboxSet( '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' => '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\Select( 'album_sort_options', ( ( $album and $album->sort_options ) ? $album->sort_options : ( ( $category AND $category->sort_options_img ) ? $category->sort_options_img : '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 );
if( ( ( $album and $album->category_id ) and ( \IPS\gallery\Category::load( $album->category_id )->allow_comments ) ) or ( ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) and \IPS\gallery\Category::load( (int) \IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category )->allow_comments ) )
if( $category AND $category->allow_comments )
{
$return[] = new \IPS\Helpers\Form\YesNo('album_allow_comments', $album ? $album->allow_comments : TRUE, FALSE);
}
if( ( ( $album and $album->category_id ) and ( \IPS\gallery\Category::load( $album->category_id )->allow_reviews ) ) or ( ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) and \IPS\gallery\Category::load( (int) \IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category )->allow_reviews ) )
if( $category AND $category->allow_reviews )
{
$return[] = new \IPS\Helpers\Form\YesNo('album_allow_reviews', $album ? $album->allow_reviews : TRUE, FALSE);
}
if( ( ( $album and $album->category_id ) and ( \IPS\gallery\Category::load( $album->category_id )->allow_comments ) ) or ( ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) and \IPS\gallery\Category::load( (int) \IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category )->allow_comments ) )
if( $category AND $category->allow_comments )
{
$return[] = new \IPS\Helpers\Form\YesNo('album_use_comments', $album ? $album->use_comments : TRUE, FALSE );
}
if( ( ( $album and $album->category_id ) and ( \IPS\gallery\Category::load( $album->category_id )->allow_reviews ) ) or ( ( isset( \IPS\Request::i()->chosenCategory ) or isset( \IPS\Request::i()->category ) ) and \IPS\gallery\Category::load( (int) \IPS\Request::i()->chosenCategory ?: \IPS\Request::i()->category )->allow_reviews ) )
if( $category AND $category->allow_reviews )
{
$return[] = new \IPS\Helpers\Form\YesNo('album_use_reviews', $album ? $album->use_reviews : TRUE, FALSE );
}
@@ -1160,16 +1177,7 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
{
if( $this->coverPhoto === NULL )
{
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();
}
$this->coverPhoto = $this->coverPhotoObject();
}
if( $this->coverPhoto !== NULL )
@@ -1186,6 +1194,44 @@ class _Album extends \IPS\Node\Model implements \IPS\Node\Ratings, \IPS\Content\
return NULL;
}
/**
* Retrieve a cover photo object
*
* @return \IPS\gallery\Image|null
*/
public function coverPhotoObject()
{
/* If we have an explicit cover photo set, make sure it's valid and load/cache it */
if( $this->cover_img_id )
{
if( $this->coverPhoto === NULL )
{
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();
}
}
}
if( $this->coverPhoto !== NULL )
{
return $this->coverPhoto;
}
if( $lastImage = $this->lastImage() AND !$lastImage->media )
{
return $lastImage;
}
return NULL;
}
/**
* Load record based on a URL
*
@@ -699,4 +699,24 @@ class _Item extends \IPS\Content\Item implements
return $lastMod;
}
/**
* Return query WHERE clause to use for getItemsWithPermission when excluding club content
*
* @return array
*/
public static function clubAlbumExclusion(): array
{
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' ) )
) );
}
}
}
@@ -698,6 +698,35 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
$property = $size . "_file_name";
/* If we have an explicit cover photo set, make sure it's valid and load/cache it */
if( $this->cover_img_id )
{
if( $this->coverPhoto === NULL )
{
$this->coverPhoto = $this->coverPhotoObject();
}
}
if( $this->coverPhoto !== NULL )
{
return (string) \IPS\File::get( 'gallery_Images', $this->coverPhoto->$property )->url;
}
if( $lastImage = $this->lastImage() )
{
return (string) \IPS\File::get( 'gallery_Images', $lastImage->$property )->url;
}
return NULL;
}
/**
* Retrieve a cover photo object
*
* @return \IPS\gallery\Image|null
*/
public function coverPhotoObject()
{
/* If we have an explicit cover photo set, make sure it's valid and load/cache it */
if( $this->cover_img_id )
{
@@ -706,6 +735,11 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
try
{
$this->coverPhoto = \IPS\gallery\Image::load( $this->cover_img_id );
if( $this->coverPhoto !== NULL )
{
return $this->coverPhoto;
}
}
catch( \OutOfRangeException $e )
{
@@ -714,16 +748,11 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
$this->save();
}
}
if( $this->coverPhoto !== NULL )
{
return (string) \IPS\File::get( 'gallery_Images', $this->coverPhoto->$property )->url;
}
}
if( $lastImage = $this->lastImage() )
{
return (string) \IPS\File::get( 'gallery_Images', $lastImage->$property )->url;
return $lastImage;
}
return NULL;
@@ -970,7 +999,7 @@ class _Category extends \IPS\Node\Model implements \IPS\Node\Permissions
if( $club->type == 'closed' )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'club_node_public', $this->id ? $this->isPublic() : FALSE ) );
$form->add( new \IPS\Helpers\Form\Radio( 'club_node_public', $this->id ? $this->isPublic() : 0, TRUE, array( 'options' => array( '0' => 'club_node_public_no', '1' => 'club_node_public_view', '2' => 'club_node_public_participate' ) ) ) );
}
}
@@ -91,11 +91,6 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
* @brief [Content] Key for hide reasons
*/
public static $hideLogKey = 'gallery-images';
/**
* @brief Whether to track the sentiment scores in cloud_sentiment_scores for this content
*/
public $trackSentimentScore = true;
/**
* Get items with permission check
+86 -9
View File
@@ -149,6 +149,7 @@ class _Image extends \IPS\Content\Item implements
$return[] = 'image_small_file_name';
$return[] = 'image_album_id';
$return[] = 'image_copyright';
$return[] = 'image_nsfw';
return $return;
}
@@ -938,6 +939,11 @@ class _Image extends \IPS\Content\Item implements
$sortBy = static::$databaseColumnMap[ $this->directContainer()->sort_options_img ?: 'updated' ];
}
if( $sortBy == 'caption' )
{
$direction = ( $direction == 'ASC' ) ? 'DESC' : 'ASC';
}
foreach( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $sortBy . ' ' . $direction . ', image_id ' . $direction, 1 ) as $image )
{
return $image;
@@ -970,16 +976,34 @@ class _Image extends \IPS\Content\Item implements
$sortBy = static::$databaseColumnMap[ $this->directContainer()->sort_options_img ?: 'updated' ];
}
$where['id'] = array( 'image_id' . $dir . '?', $this->id );
if( $sortBy == 'caption' )
$where['id'] = array( 'image_id<>?', $this->id );
if( in_array( $sortBy, array( 'caption', 'rating' ) ) )
{
$direction = ( $direction == 'ASC' ) ? 'DESC' : 'ASC';
$dir = ( $dir == '>' ) ? '<' : '>';
if( $sortBy == 'caption' )
{
$direction = ( $direction == 'ASC' ) ? 'DESC' : 'ASC';
$dir = ( $dir == '>' ) ? '<' : '>';
}
/* We need to sort on a unique value */
$sortValue = $this->$sortBy . $this->updated;
$sortBy = 'CONCAT(image_' . $sortBy . ',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)';
}
else
{
$sortValue = $this->$sortBy;
$sortBy = static::$databasePrefix . $sortBy;
}
$where['date'] = array( static::$databasePrefix . $sortBy . " {$dir}= ?", $this->$sortBy );
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $sortBy . ' ' . $direction . ', image_id ' . $direction, $count ) );
$where['date'] = array( $sortBy . " {$dir}= ?", $sortValue );
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, $sortBy . ' ' . $direction . ', image_id ' . $direction, $count ) );
}
/**
@@ -1158,6 +1182,11 @@ class _Image extends \IPS\Content\Item implements
$return['credit_info'] = new \IPS\Helpers\Form\TextArea( 'image_credit_info', $item ? $item->credit_info : NULL, FALSE );
$return['copyright'] = new \IPS\Helpers\Form\Text( 'image_copyright', $item ? $item->copyright : NULL, FALSE, array( 'maxLength' => 255 ) );
if( \IPS\Settings::i()->gallery_nsfw )
{
$return['nsfw'] = new \IPS\Helpers\Form\YesNo( 'image_nsfw', $item ? $item->nsfw : FALSE );
}
/* If we are editing, return the appropriate fields */
if( $item )
{
@@ -1245,6 +1274,11 @@ class _Image extends \IPS\Content\Item implements
{
$this->credit_info = $values['image_credit_info'];
}
if ( isset( $values['image_nsfw'] ) )
{
$this->nsfw = $values['image_nsfw'];
}
/* If we are editing and have a movie, update it */
if( isset( $values['mediaLocation'] ) )
@@ -1252,6 +1286,11 @@ class _Image extends \IPS\Content\Item implements
$values['imageLocation'] = $values['mediaLocation'];
}
if ( isset( $values['labels'] ) )
{
$this->labels = $values['labels'];
}
/* Get the file... */
$file = NULL;
if( isset( $values['imageLocation'] ) AND $values['imageLocation'] )
@@ -1757,6 +1796,7 @@ class _Image extends \IPS\Content\Item implements
* @apiresponse bool pinned Image is pinned
* @apiresponse string url URL
* @apiresponse float rating Average Rating
* @apiresponse bool nsfw Not safe for work
*/
public function apiOutput( \IPS\Member $authorizedMember = NULL )
{
@@ -1790,6 +1830,7 @@ class _Image extends \IPS\Content\Item implements
'pinned' => (bool) $this->mapped('pinned'),
'url' => (string) $this->url(),
'rating' => $this->averageRating(),
'nsfw' => $this->nsfw
);
}
@@ -2010,7 +2051,9 @@ class _Image extends \IPS\Content\Item implements
*/
public function canSetAsAlbumCover( $member=NULL )
{
if( ( $this->album_id AND $this->canEdit() ) OR static::modPermission( 'edit', $member, $this->container() ) )
$member = $member ?: \IPS\Member::loggedIn();
/* Allow album owners to always change the album cover */
if( ( $this->album_id AND $album = \IPS\gallery\Album::load( $this->album_id ) AND $member->member_id AND $album->owner_id == $member->member_id ) OR static::modPermission( 'edit', $member, $this->container() ) )
{
return TRUE;
}
@@ -2433,7 +2476,7 @@ class _Image extends \IPS\Content\Item implements
*
* @return array
*/
public static function clubImageExclusion()
public static function clubImageExclusion(): array
{
if( \IPS\Settings::i()->club_nodes_in_apps )
{
@@ -2447,4 +2490,38 @@ class _Image extends \IPS\Content\Item implements
) );
}
}
/**
* Returns the labels from image scanner for search
*
* @return array|NULL
* @throws \BadMethodCallException
*/
public function imageLabelsForSearch()
{
$return = [];
$labels = $this->labels ? json_decode( $this->labels, TRUE ) : array();
if( $labels and \count( $labels ) )
{
foreach( $labels as $label )
{
$return[] = $label['Name'];
}
}
return $return;
}
/**
* Is the image NSFW?
*
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
* @return bool
*/
public function nsfw()
{
return (bool) $this->nsfw;
}
}
@@ -96,11 +96,6 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
*/
public static $hideLogKey = 'gallery-image-review';
/**
* @brief Whether to track the sentiment scores in cloud_sentiment_scores for this content
*/
public $trackSentimentScore = true;
/**
* Get URL for doing stuff
*