Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+349 -149
View File
@@ -2,9 +2,9 @@
/**
* @brief Image Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -226,7 +226,34 @@ class _Image extends \IPS\Content\Item implements
{
return is_array( $this->_data['notes'] ) ? $this->_data['notes'] : ( $this->_data['notes'] ? json_decode( $this->_data['notes'], TRUE ) : array() );
}
/**
* Returns a JSON string of the notes data made safe for decoding in javascript.
*
* @return string
*/
public function get__notes_json()
{
/* We want to essentially double encode the entities so that when javascript decodes the JSON it is safe */
if( $this->_notes and is_array( $this->_notes ) )
{
$notes = $this->_notes;
array_walk( $notes, function( &$v, $k )
{
if ( ! empty( $v['NOTE'] ) )
{
$v['NOTE'] = htmlspecialchars( $v['NOTE'], \IPS\HTMLENTITIES, 'UTF-8', TRUE );
}
} );
}
else
{
$notes = array();
}
return json_encode( $notes );
}
/**
* Set any image notes stored
*
@@ -273,7 +300,7 @@ class _Image extends \IPS\Content\Item implements
public function set_caption( $name )
{
$this->_data['caption'] = $name;
$this->_data['caption_seo'] = \IPS\Http\Url::seoTitle( $name );
$this->_data['caption_seo'] = \IPS\Http\Url\Friendly::seoTitle( $name );
}
/**
@@ -285,11 +312,11 @@ class _Image extends \IPS\Content\Item implements
{
if( !$this->_data['caption_seo'] )
{
$this->caption_seo = \IPS\Http\Url::seoTitle( $this->caption );
$this->caption_seo = \IPS\Http\Url\Friendly::seoTitle( $this->caption );
$this->save();
}
return $this->_data['caption_seo'] ?: \IPS\Http\Url::seoTitle( $this->caption );
return $this->_data['caption_seo'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->caption );
}
/**
@@ -356,84 +383,87 @@ class _Image extends \IPS\Content\Item implements
$unread = FALSE;
/* Some generic moderator permissions */
if( $this->canMove() )
if ( $this->canSeeMultiModTools() )
{
$modActions[] = "move";
}
if( $this->canDelete() )
{
$modActions[] = "delete";
}
if( $this->mapped('locked') )
{
if( $this->canUnlock() )
if( $this->canMove() )
{
$modActions[] = 'unlock';
$modActions[] = "move";
}
$modStates[] = 'locked';
}
else if( $this->canLock() )
{
$modActions[] = 'lock';
}
if ( $this->mapped('featured') )
{
if( $this->canUnfeature() )
if( $this->canDelete() )
{
$modActions[] = 'unfeature';
$modActions[] = "delete";
}
$state['featured'] = TRUE;
$modStates[] = 'featured';
}
else if( $this->canFeature() )
{
$modActions[] = 'feature';
}
if ( $this->mapped('pinned') )
{
if( $this->canUnpin() )
if( $this->mapped('locked') )
{
$modActions[] = 'unpin';
if( $this->canUnlock() )
{
$modActions[] = 'unlock';
}
$modStates[] = 'locked';
}
$state['pinned'] = TRUE;
$modStates[] = 'pinned';
}
else if( $this->canPin() )
{
$modActions[] = 'pin';
}
/* Approve, hide or unhide */
if ( $this->hidden() === -1 )
{
if( $this->canUnhide() )
else if( $this->canLock() )
{
$modActions[] = 'unhide';
$modActions[] = 'lock';
}
$state['hidden'] = TRUE;
$modStates[] = 'hidden';
}
elseif ( $this->hidden() === 1 )
{
if( $this->canUnhide() )
if ( $this->mapped('featured') )
{
$modActions[] = 'approve';
if( $this->canUnfeature() )
{
$modActions[] = 'unfeature';
}
$state['featured'] = TRUE;
$modStates[] = 'featured';
}
else if( $this->canFeature() )
{
$modActions[] = 'feature';
}
if ( $this->mapped('pinned') )
{
if( $this->canUnpin() )
{
$modActions[] = 'unpin';
}
$state['pinned'] = TRUE;
$modStates[] = 'pinned';
}
else if( $this->canPin() )
{
$modActions[] = 'pin';
}
/* Approve, hide or unhide */
if ( $this->hidden() === -1 )
{
if( $this->canUnhide() )
{
$modActions[] = 'unhide';
}
$state['hidden'] = TRUE;
$modStates[] = 'hidden';
}
elseif ( $this->hidden() === 1 )
{
if( $this->canUnhide() )
{
$modActions[] = 'approve';
}
$state['pending'] = TRUE;
$modStates[] = 'unapproved';
}
else if( $this->canHide() )
{
$modActions[] = 'hide';
}
$state['pending'] = TRUE;
$modStates[] = 'unapproved';
}
else if( $this->canHide() )
{
$modActions[] = 'hide';
}
/* Set read or unread status */
@@ -465,12 +495,12 @@ class _Image extends \IPS\Content\Item implements
'date' => \IPS\DateTime::ts( $this->mapped('date') )->relative(),
'hasState' => count( $state ) ? TRUE : FALSE,
'state' => $state,
'container' => ( $this->directContainer() instanceof \IPS\gallery\Category ) ? \IPS\Member::loggedIn()->language()->addToStack( "gallery_category_{$this->directContainer()->_id}", FALSE, array( 'json' => TRUE, 'escape' => TRUE ) ) : mb_substr( json_encode( str_replace( "'", "&pos;", htmlspecialchars( $this->directContainer()->_title, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ) ), 1, -1 ),
'container' => ( $this->directContainer() instanceof \IPS\gallery\Category ) ? \IPS\Member::loggedIn()->language()->addToStack( "gallery_category_{$this->directContainer()->_id}", FALSE, array( 'json' => TRUE, 'escape' => TRUE ) ) : mb_substr( json_encode( str_replace( "'", "&apos;", htmlspecialchars( str_replace( '&quot;', '"', $this->directContainer()->_title ), \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ), JSON_UNESCAPED_UNICODE ), 1, -1 ),
'id' => $this->_data['id'],
'url' => (string) $this->url(),
'author' => array(
'photo' => (string) $this->author()->photo,
'name' => str_replace( "'", "&pos;", htmlspecialchars( $this->author()->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) )
'photo' => str_replace( "'", "&apos;", htmlspecialchars( (string) $this->author()->photo, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ),
'name' => str_replace( "'", "&apos;", htmlspecialchars( $this->author()->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) )
),
'modActions' => $modActions,
'modStates' => $modStates,
@@ -541,11 +571,11 @@ class _Image extends \IPS\Content\Item implements
{
$tabs = array();
if ( $this->directContainer()->allow_reviews )
if ( $this->container()->allow_reviews AND $this->directContainer()->allow_reviews )
{
$tabs['reviews'] = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get( 'image_review_count' ), array( $this->mapped('num_reviews') ) );
}
if ( $this->directContainer()->allow_comments )
if ( $this->container()->allow_comments AND $this->directContainer()->allow_comments )
{
$tabs['comments'] = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get( 'image_comment_count' ), array( $this->mapped('num_comments') ) );
}
@@ -561,11 +591,11 @@ class _Image extends \IPS\Content\Item implements
*/
public function commentReviews( $tab )
{
if ( $tab === 'reviews' )
if ( $tab === 'reviews' AND $this->container()->allow_reviews AND $this->directContainer()->allow_reviews )
{
return \IPS\Theme::i()->getTemplate('view')->reviews( $this );
}
elseif( $tab === 'comments' )
elseif( $tab === 'comments' AND $this->container()->allow_comments AND $this->directContainer()->allow_comments )
{
return \IPS\Theme::i()->getTemplate('view')->comments( $this );
}
@@ -591,12 +621,14 @@ class _Image extends \IPS\Content\Item implements
}
/**
* Users to receieve immediate notifications
* Users to receive immediate notifications
*
* @param int|array $limit LIMIT clause
* @param int|array $limit LIMIT clause
* @param string|NULL $extra Additional data
* @param boolean $countOnly Just return the count
* @return \IPS\Db\Select
*/
public function notificationRecipients( $limit=array( 0, 25 ), $extra=NULL )
public function notificationRecipients( $limit=array( 0, 25 ), $extra=NULL, $countOnly=FALSE )
{
$unions = array( static::containerFollowers( $this->container(), 3, array( 'immediate' ), $this->mapped('date'), NULL, NULL, 0 ) );
@@ -609,8 +641,20 @@ class _Image extends \IPS\Content\Item implements
{
$unions[] = $followersQuery;
}
return \IPS\Db::i()->union( $unions, 'follow_added', $limit, 'follow_member_id', FALSE, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
if ( $countOnly )
{
$return = 0;
foreach ( $unions as $query )
{
$return += $query->count();
}
return $return;
}
else
{
return \IPS\Db::i()->union( $unions, 'follow_added', $limit, NULL, FALSE, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
}
}
/**
@@ -725,7 +769,7 @@ class _Image extends \IPS\Content\Item implements
}
}
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'unapproved_content_bulk', $directContainer, array( $directContainer, $member, $directContainer::$contentItemClass ) );
$notification = new \IPS\Notification( \IPS\Application::load('core'), 'unapproved_content_bulk', $directContainer, array( $directContainer, $member, $directContainer::$contentItemClass ), array( $member->member_id ) );
foreach ( \IPS\Db::i()->select( '*', 'core_members', ( count( $moderators['m'] ) ? \IPS\Db::i()->in( 'member_id', $moderators['m'] ) . ' OR ' : '' ) . \IPS\Db::i()->in( 'member_group_id', $moderators['g'] ) . ' OR ' . \IPS\Db::i()->findInSet( 'mgroup_others', $moderators['g'] ) ) as $moderator )
{
$notification->recipients->attach( \IPS\Member::constructFromData( $moderator ) );
@@ -761,9 +805,9 @@ class _Image extends \IPS\Content\Item implements
$notification->recipients->attach( $followMember );
}
}
$notification->send();
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_sent' => time() ), \IPS\Db::i()->in( 'follow_id', $followIds ) );
$notification->send();
$newOffset = $offset + static::NOTIFICATIONS_PER_BATCH;
if ( $newOffset > $followers->count( TRUE ) )
@@ -795,6 +839,7 @@ class _Image extends \IPS\Content\Item implements
else
{
$where[] = array( 'image_category_id=?', $this->category_id );
$where[] = array( 'image_album_id=?', 0 );
}
$where['id'] = array( 'image_id<>?', $this->id );
@@ -867,6 +912,7 @@ class _Image extends \IPS\Content\Item implements
else
{
$where[] = array( 'image_category_id=?', $this->category_id );
$where[] = array( 'image_album_id=?', 0 );
}
$where['id'] = array( 'image_id<>?', $this->id );
@@ -1005,11 +1051,13 @@ class _Image extends \IPS\Content\Item implements
/**
* Get elements for add/edit form
*
* @param \IPS\Content\Item|NULL $item The current item if editing or NULL if creating
* @param int $container Container (e.g. forum) ID, if appropriate
* @param \IPS\Content\Item|NULL $item The current item if editing or NULL if creating
* @param int $container Container (e.g. forum) ID, if appropriate
* @param int|NULL $currentlyEditing If this is for a new submission, the index ID of the image in the array
* @param int|NULL $tempId If this is for a new submission, the temporary image ID
* @return array
*/
public static function formElements( $item=NULL, \IPS\Node\Model $container=NULL )
public static function formElements( $item=NULL, \IPS\Node\Model $container=NULL, $currentlyEditing=NULL, $tempId=NULL )
{
/* Init */
$return = parent::formElements( $item, $container );
@@ -1018,7 +1066,13 @@ class _Image extends \IPS\Content\Item implements
unset( $return['container'] );
/* Some other details */
$return['description'] = new \IPS\Helpers\Form\Editor( 'image_description', $item ? $item->description : NULL, FALSE, array( 'app' => 'gallery', 'key' => 'Images', 'autoSaveKey' => ( $item === NULL ? ( 'newContentItem-' . static::$application . '/' . static::$module . '-' . ( $container ? $container->_id : 0 ) ) : ( 'contentEdit-' . static::$application . '/' . static::$module . '-' . $item->id ) ), 'attachIds' => ( $item === NULL ? NULL : array( $item->id ) ) ) );
$return['description'] = new \IPS\Helpers\Form\Editor( 'image_description', $item ? $item->description : NULL, FALSE, array(
'app' => 'gallery',
'key' => 'Images',
'autoSaveKey' => ( $item === NULL ? ( 'newContentItem-' . static::$application . '/' . static::$module . '-' . ( $tempId ?: 0 ) . '-' . ( $container ? $container->_id : 0 ) ) : ( 'contentEdit-' . static::$application . '/' . static::$module . '-' . $item->id ) ),
'attachIds' => ( $item === NULL ? NULL : array( $item->id ) ),
'editorId' => "filedata_{$currentlyEditing}_image_description"
) );
$return['credit'] = 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 ) );
@@ -1028,7 +1082,7 @@ class _Image extends \IPS\Content\Item implements
/* Is this a media file, or an image? */
if( $item->media )
{
$return['imageLocation'] = new \IPS\Helpers\Form\Upload( 'mediaLocation', \IPS\File::get( 'gallery_Images', $item->original_file_name ), FALSE, array(
$return['imageLocation'] = new \IPS\Helpers\Form\Upload( 'mediaLocation', \IPS\File::get( 'gallery_Images', $item->original_file_name ), TRUE, array(
'storageExtension' => 'gallery_Images',
'allowedFileTypes' => array( 'flv', 'f4v', 'wmv', 'mpg', 'mpeg', 'mp4', 'mkv', 'm4a', 'm4v', '3gp', 'mov', 'avi', 'webm', 'ogg' ),
'multiple' => FALSE,
@@ -1050,7 +1104,7 @@ class _Image extends \IPS\Content\Item implements
}
else
{
$return['imageLocation'] = new \IPS\Helpers\Form\Upload( 'imageLocation', \IPS\File::get( 'gallery_Images', $item->original_file_name ), FALSE, array(
$return['imageLocation'] = new \IPS\Helpers\Form\Upload( 'imageLocation', \IPS\File::get( 'gallery_Images', $item->original_file_name ), TRUE, array(
'storageExtension' => 'gallery_Images',
'image' => TRUE,
'multiple' => FALSE,
@@ -1212,8 +1266,8 @@ class _Image extends \IPS\Content\Item implements
if( $this->album_id )
{
$album = \IPS\gallery\Album::load( $this->album_id );
$album->setLastImage();
$album->save();
}
}
@@ -1222,7 +1276,7 @@ class _Image extends \IPS\Content\Item implements
*
* @return void
*/
protected function parseGeolocation()
public function parseGeolocation()
{
if( isset( $this->metadata['GPS.GPSLatitudeRef'] ) && isset( $this->metadata['GPS.GPSLatitude'] ) && isset( $this->metadata['GPS.GPSLongitudeRef'] ) && isset( $this->metadata['GPS.GPSLongitude'] ) )
{
@@ -1277,6 +1331,40 @@ class _Image extends \IPS\Content\Item implements
}
}
}
/**
* Delete existing thumbnails prior to rebuilding or deleting (does not delete the main image in original_file_name)
*
* @return void
*/
public function deleteThumbnails()
{
$possibleImagesToDelete = array( 'masked_file_name', 'medium_file_name', 'small_file_name', 'thumb_file_name' );
$imagesToDelete = array();
/* Usually the masked_file_name and the original_file_name are different, however with many upgrades they are not, and if we delete
the original file (which would be mapped in both original_file_name AND masked_file_name) then we cannot rebuild thumbnails after
and the image will be broken */
foreach( $possibleImagesToDelete as $image )
{
if( $this->$image != $this->original_file_name )
{
$imagesToDelete[] = $image;
}
}
foreach ( $imagesToDelete as $k )
{
if ( $this->$k )
{
try
{
\IPS\File::get( 'gallery_Images', $this->$k )->delete();
}
catch( \Exception $e ){}
}
}
}
/**
* Build the copies of the image with watermark as appropriate
@@ -1292,24 +1380,25 @@ class _Image extends \IPS\Content\Item implements
}
$thumbnailDimensions = array();
$watermarks = explode( ',', \IPS\Settings::i()->gallery_watermark_images );
/* Create the various thumbnails */
$largeImage = \IPS\File::create( 'gallery_Images', 'large.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_large_dims ) ) );
$largeImage = \IPS\File::create( 'gallery_Images', 'large.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_large_dims ), FALSE, in_array( 'large', $watermarks ) ) );
$this->masked_file_name = (string) $largeImage;
$thumbnailDimensions['large'] = $largeImage->getImageDimensions();
$mediumImage = \IPS\File::create( 'gallery_Images', 'medium.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_medium_dims ) ) );
$mediumImage = \IPS\File::create( 'gallery_Images', 'medium.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_medium_dims ), FALSE, in_array( 'medium', $watermarks ) ) );
$this->medium_file_name = (string) $mediumImage;
$thumbnailDimensions['medium'] = $mediumImage->getImageDimensions();
$smallImage = \IPS\File::create( 'gallery_Images', 'small.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_small_dims ) ) );
$smallImage = \IPS\File::create( 'gallery_Images', 'small.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_small_dims ), FALSE, in_array( 'small', $watermarks ) ) );
$this->small_file_name = (string) $smallImage;
$thumbnailDimensions['small'] = $smallImage->getImageDimensions();
$thumbImage = \IPS\File::create( 'gallery_Images', 'thumb.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_thumb_dims ), \IPS\Settings::i()->gallery_use_square_thumbnails ) );
$thumbImage = \IPS\File::create( 'gallery_Images', 'thumb.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_thumb_dims ), \IPS\Settings::i()->gallery_use_square_thumbnails, in_array( 'thumbnail', $watermarks ) ) );
$this->thumb_file_name = (string) $thumbImage;
$thumbnailDimensions['thumb'] = $thumbImage->getImageDimensions();
@@ -1323,9 +1412,10 @@ class _Image extends \IPS\Content\Item implements
* @param \IPS\File $file Base file to create from
* @param array $dimensions Dimensions to resize to
* @param bool $crop Whether to crop (true) or resize (false)
* @param bool $watermark Watermark the created image
* @return \IPS\Image
*/
protected function _createImage( $file, $dimensions, $crop=FALSE )
protected function _createImage( $file, $dimensions, $crop=FALSE, $watermark=TRUE )
{
$image = \IPS\Image::create( $file->contents() );
@@ -1338,7 +1428,7 @@ class _Image extends \IPS\Content\Item implements
$image->resizeToMax( $dimensions[0], $dimensions[1] );
}
if( \IPS\Settings::i()->gallery_watermark_path AND $this->container()->watermark )
if( $watermark and \IPS\Settings::i()->gallery_use_watermarks and \IPS\Settings::i()->gallery_watermark_path AND $this->container()->watermark )
{
try
{
@@ -1409,9 +1499,10 @@ class _Image extends \IPS\Content\Item implements
public function sizes()
{
$return = array();
if( !empty( $this->_dimensions ) )
$data = json_decode( $this->data, TRUE );
if( !empty( $data ) )
{
foreach ( $this->_dimensions as $k => $v )
foreach ( $data as $k => $v )
{
if ( !in_array( $v, $return ) )
{
@@ -1424,7 +1515,7 @@ class _Image extends \IPS\Content\Item implements
{
unset( $return['thumb'] );
}
return $return;
}
@@ -1436,22 +1527,9 @@ class _Image extends \IPS\Content\Item implements
public function delete()
{
parent::delete();
try
{
\IPS\File::get( 'gallery_Images', $this->masked_file_name )->delete();
}
catch( \Exception $e ){}
if( $this->medium_file_name )
{
try
{
\IPS\File::get( 'gallery_Images', $this->medium_file_name )->delete();
}
catch( \Exception $e ){}
}
/* Delete files */
$this->deleteThumbnails();
if( $this->original_file_name )
{
try
@@ -1461,24 +1539,6 @@ class _Image extends \IPS\Content\Item implements
catch( \Exception $e ){}
}
if( $this->thumb_file_name )
{
try
{
\IPS\File::get( 'gallery_Images', $this->thumb_file_name )->delete();
}
catch( \Exception $e ){}
}
if( $this->small_file_name )
{
try
{
\IPS\File::get( 'gallery_Images', $this->small_file_name )->delete();
}
catch( \Exception $e ){}
}
/* Delete bandwidth logs */
\IPS\Db::i()->delete( 'gallery_bandwidth', array( 'image_id=?', $this->id ) );
@@ -1490,8 +1550,8 @@ class _Image extends \IPS\Content\Item implements
if( $this->album_id )
{
$album = \IPS\gallery\Album::load( $this->album_id );
$album->setLastImage();
$album->save();
}
$category = \IPS\gallery\Category::load( $this->category_id );
@@ -1505,7 +1565,7 @@ class _Image extends \IPS\Content\Item implements
* @param array $indexData Data from the search index
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the author. Only includes columns returned by container::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @param array $reputationData Array of people who have given reputation and the reputation they gave
* @param int|NULL $reviewRating If this is a review, the rating
* @param string $view 'expanded' or 'condensed'
@@ -1514,7 +1574,7 @@ class _Image extends \IPS\Content\Item implements
public static function searchResultSnippet( array $indexData, array $authorData, array $itemData, array $containerData = NULL, array $reputationData, $reviewRating, $view )
{
$image = $itemData['image_medium_file_name'] ?: $itemData['image_masked_file_name'];
$url = \IPS\Http\Url::internal( static::$urlBase . $indexData['index_item_id'], 'front', static::$urlTemplate, \IPS\Http\Url::seoTitle( $indexData['index_title'] ?: $itemData[ static::$databasePrefix . static::$databaseColumnMap['title'] ] ) );
$url = \IPS\Http\Url::internal( static::$urlBase . $indexData['index_item_id'], 'front', static::$urlTemplate, \IPS\Http\Url\Friendly::seoTitle( $indexData['index_title'] ?: $itemData[ static::$databasePrefix . static::$databaseColumnMap['title'] ] ) );
$albumData = isset( $itemData['extra'] ) ? $itemData['extra'] : NULL;
@@ -1542,6 +1602,73 @@ class _Image extends \IPS\Content\Item implements
{
return parent::supportsReviews() and ( !$member or \IPS\gallery\Category::countWhere( 'read', $member, array( 'category_allow_reviews=1' ) ) );
}
/**
* Get output for API
*
* @return array
* @apiresponse int id ID number
* @apiresponse string caption Caption
* @apiresponse string description Description
* @apiresponse string filename Original file name (e.g. 'image.png')
* @apiresponse int filesize Original file size, in bytes
* @apiresponse object images URLs to where the images are stored. Keys are 'original', 'large', 'medium', 'small' and 'thumb' and values are URLs to the corresponding images
* @apiresponse \IPS\gallery\Album album The album, if in one
* @apiresponse \IPS\gallery\Category category The category (if in an album, this will be the category that the album is in)
* @apiresponse \IPS\Member author The author
* @apiresponse string copyright Copyright
* @apiresponse string credit Credit
* @apiresponse \IPS\GeoLocation location The location where the picture was taken, if it was able to be retreived from the EXIF data
* @apiresponse object exif The raw EXIF data
* @apiresponse datetime date Date image was uploaded
* @apiresponse int comments Number of comments
* @apiresponse int reviews Number of reviews
* @apiresponse int views Number of views
* @apiresponse string prefix The prefix tag, if there is one
* @apiresponse [string] tags The tags
* @apiresponse bool locked Image is locked
* @apiresponse bool hidden Image is hidden
* @apiresponse bool featured Image is featured
* @apiresponse bool pinned Image is pinned
* @apiresponse string url URL
* @apiresponse float rating Average Rating
*/
public function apiOutput()
{
return array(
'id' => $this->id,
'caption' => $this->caption,
'description' => $this->description,
'filename' => $this->file_name,
'filesize' => $this->file_size,
'images' => array(
'original' => (string) \IPS\File::get( 'gallery_Images', $this->original_file_name )->url,
'large' => (string) \IPS\File::get( 'gallery_Images', $this->masked_file_name )->url,
'medium' => (string) \IPS\File::get( 'gallery_Images', $this->medium_file_name )->url,
'small' => (string) \IPS\File::get( 'gallery_Images', $this->small_file_name )->url,
'thumb' => (string) \IPS\File::get( 'gallery_Images', $this->thumb_file_name )->url,
),
'album' => $this->album_id ? $this->directContainer()->apiOutput() : null,
'category' => $this->container()->apiOutput(),
'author' => $this->author()->apiOutput(),
'copyright' => $this->copyright ?: null,
'credit' => $this->credit_info ?: null,
'location' => $this->gps_raw ? \IPS\GeoLocation::buildFromJson( $this->gps_raw ) : null,
'exif' => $this->metadata ?: null,
'date' => \IPS\DateTime::ts( $this->date )->rfc3339(),
'comments' => $this->comments,
'reviews' => $this->reviews,
'views' => $this->views,
'prefix' => $this->prefix(),
'tags' => $this->tags(),
'locked' => (bool) $this->locked(),
'hidden' => (bool) $this->hidden(),
'featured' => (bool) $this->mapped('featured'),
'pinned' => (bool) $this->mapped('pinned'),
'url' => (string) $this->url(),
'rating' => $this->averageRating(),
);
}
/* !Tags */
@@ -1617,8 +1744,8 @@ class _Image extends \IPS\Content\Item implements
if( $previousAlbum )
{
$album = \IPS\gallery\Album::load( $previousAlbum );
$album->setLastImage();
$album->save();
}
/* Rebuild new album */
@@ -1626,6 +1753,7 @@ class _Image extends \IPS\Content\Item implements
{
$album = \IPS\gallery\Album::load( $this->album_id );
$album->setLastImage();
$album->save();
}
/* And return */
@@ -1684,6 +1812,11 @@ class _Image extends \IPS\Content\Item implements
/* This will throw an exception of the row does not exist */
try
{
if( !$member->member_id )
{
throw new \OutOfRangeException;
}
$member = \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=? AND member_id=?', $this->directcontainer()->allowed_access, $member->member_id ) )->first();
}
catch( \OutOfRangeException $e )
@@ -1729,16 +1862,19 @@ class _Image extends \IPS\Content\Item implements
}
else
{
foreach( \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'member_id=?', $member->member_id ) ) as $group )
if( $member->member_id )
{
$restricted[] = $group['group_id'];
foreach( \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'member_id=?', $member->member_id ) ) as $group )
{
$restricted[] = $group['group_id'];
}
}
static::$_availableGroups[ $member->member_id ] = $restricted;
}
/* If you can edit images in a category you can see images in private albums in that category. We can only really check globally at this stage, however. */
if( \IPS\gallery\Image::modPermission( 'edit' ) )
if( \IPS\gallery\Image::modPermission( 'edit', $member ) )
{
return array( "( gallery_albums.album_id IS NULL OR gallery_albums.album_type IN(1,2) OR ( gallery_albums.album_type=3 AND ( gallery_albums.album_owner_id=? OR gallery_albums.album_allowed_access IN (" . implode( ',', $restricted ) . ") ) ) )", $member->member_id );
}
@@ -1755,7 +1891,7 @@ class _Image extends \IPS\Content\Item implements
* @param string $order MySQL ORDER BY clause (NULL to order by date)
* @param int|array $limit Limit clause
* @param string|NULL $permissionKey A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
* @param bool|NULL $includeHiddenItems Include hidden files? Boolean or NULL to detect if currently logged member has permission
* @param mixed $includeHiddenItems Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
* @param int $queryFlags Select bitwise flags
* @param \IPS\Member $member The member (NULL to use currently logged in member)
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
@@ -1767,9 +1903,10 @@ class _Image extends \IPS\Content\Item implements
* @param bool $joinTags If true, will join the tags table
* @param bool $joinAuthor If true, will join the members table for the author
* @param bool $joinLastCommenter If true, will join the members table for the last commenter
* @param bool $showMovedLinks If true, moved item links are included in the results
* @return \IPS\Patterns\ActiveRecordIterator|int
*/
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=NULL, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL, $skipPermission=FALSE, $joinTags=TRUE, $joinAuthor=TRUE, $joinLastCommenter=TRUE )
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=NULL, $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 ( $order === NULL )
{
@@ -1798,7 +1935,7 @@ class _Image extends \IPS\Content\Item implements
$order = implode( ', ', $newOrders );
$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 );
return parent::getItemsWithPermission( $where, $order, $limit, $permissionKey, $includeHiddenItems, $queryFlags, $member, $joinContainer, $joinComments, $joinReviews, $countOnly, $joins, $skipPermission, $joinTags, $joinAuthor, $joinLastCommenter, $showMovedLinks );
}
/**
@@ -1832,7 +1969,7 @@ class _Image extends \IPS\Content\Item implements
return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
}
$count = static::getItemsWithPermission( array( array( 'gallery_images.image_category_id=?', $container->_id ) ), NULL, 1, 'read', NULL, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$count = static::getItemsWithPermission( array( array( 'gallery_images.image_category_id=?', $container->_id ) ), NULL, 1, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$_key = md5( get_class( $container ) . $container->_id );
static::$itemCounts[ $_key ][ $container->_id ] = $count;
@@ -1877,4 +2014,67 @@ class _Image extends \IPS\Content\Item implements
return $return;
}
/**
* Hide
*
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @param string $reason Reason
* @return void
*/
public function hide( $member, $reason = NULL )
{
parent::hide( $member, $reason );
$this->directContainer()->setLastImage();
$this->directContainer()->save();
}
/**
* Unhide
*
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function unhide( $member )
{
parent::unhide( $member );
$this->directContainer()->setLastImage();
$this->directContainer()->save();
}
/**
* Get preview image for share services
*
* @return string
*/
public function shareImage()
{
return (string) \IPS\File::get( 'gallery_Images', $this->masked_file_name )->url;
}
/**
* Can comment?
*
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
* @return bool
*/
public function canComment( $member=NULL )
{
$member = $member ?: \IPS\Member::loggedIn();
return parent::canComment( $member ) and $this->container()->allow_comments and $this->directContainer()->allow_comments;
}
/**
* Can review?
*
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
* @return bool
*/
public function canReview( $member = NULL )
{
$member = $member ?: \IPS\Member::loggedIn();
return parent::canReview( $member ) and $this->container()->allow_reviews and $this->directContainer()->allow_reviews;
}
}