Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -25,7 +25,6 @@ class _Image extends \IPS\Content\Item implements
|
||||
\IPS\Content\Permissions,
|
||||
\IPS\Content\Tags,
|
||||
\IPS\Content\Followable,
|
||||
\IPS\Content\ReportCenter,
|
||||
\IPS\Content\ReadMarkers,
|
||||
\IPS\Content\Views,
|
||||
\IPS\Content\Hideable, \IPS\Content\Featurable, \IPS\Content\Pinnable, \IPS\Content\Lockable,
|
||||
@@ -35,7 +34,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
\IPS\Content\Embeddable,
|
||||
\IPS\Content\MetaData
|
||||
{
|
||||
use \IPS\Content\Reactable;
|
||||
use \IPS\Content\Reactable, \IPS\Content\Reportable;
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
@@ -142,9 +141,9 @@ class _Image extends \IPS\Content\Item implements
|
||||
public static function basicDataColumns()
|
||||
{
|
||||
$return = parent::basicDataColumns();
|
||||
$return[] = 'image_medium_file_name';
|
||||
$return[] = 'image_masked_file_name';
|
||||
$return[] = 'image_original_file_name';
|
||||
$return[] = 'image_small_file_name';
|
||||
$return[] = 'image_album_id';
|
||||
$return[] = 'image_copyright';
|
||||
return $return;
|
||||
@@ -239,7 +238,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
{
|
||||
if ( ! empty( $v['NOTE'] ) )
|
||||
{
|
||||
$v['NOTE'] = htmlspecialchars( $v['NOTE'], \IPS\HTMLENTITIES, 'UTF-8', TRUE );
|
||||
$v['NOTE'] = htmlspecialchars( $v['NOTE'], ENT_DISALLOWED, 'UTF-8', TRUE );
|
||||
}
|
||||
} );
|
||||
}
|
||||
@@ -315,17 +314,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
return $this->_data['caption_seo'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->caption );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Medium File Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_medium_file_name()
|
||||
{
|
||||
return $this->_data['medium_file_name'] ?: $this->_data['masked_file_name'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Small File Name
|
||||
*
|
||||
@@ -333,17 +322,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function get_small_file_name()
|
||||
{
|
||||
return $this->_data['small_file_name'] ?: $this->_data['medium_file_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Thumbnail File Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_thumb_file_name()
|
||||
{
|
||||
return $this->_data['thumb_file_name'] ?: $this->_data['small_file_name'];
|
||||
return $this->_data['small_file_name'] ?: $this->_data['masked_file_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,9 +348,10 @@ class _Image extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Return selection of image data as a JSON-encoded string (used for patchwork)
|
||||
*
|
||||
* @param array $parameters Optional key => value array of additional query string parameters to use with the image URL
|
||||
* @return string
|
||||
*/
|
||||
public function json()
|
||||
public function json( $parameters=array() )
|
||||
{
|
||||
$imageSizes = json_decode( $this->_data['data'], true );
|
||||
$state = array();
|
||||
@@ -453,6 +433,11 @@ class _Image extends \IPS\Content\Item implements
|
||||
{
|
||||
$modActions[] = 'approve';
|
||||
}
|
||||
|
||||
if( $this->canHide() )
|
||||
{
|
||||
$modActions[] = 'hide';
|
||||
}
|
||||
|
||||
$state['pending'] = TRUE;
|
||||
$modStates[] = 'unapproved';
|
||||
@@ -485,26 +470,26 @@ class _Image extends \IPS\Content\Item implements
|
||||
return json_encode( array(
|
||||
'filenames' => array(
|
||||
'small' => array( $this->_data['small_file_name'] ? (string) \IPS\File::get( 'gallery_Images', $this->_data['small_file_name'] )->url : null, $imageSizes['small'][0], $imageSizes['small'][1] ),
|
||||
'medium' => array( $this->_data['medium_file_name'] ? (string) \IPS\File::get( 'gallery_Images', $this->_data['medium_file_name'] )->url : null, $imageSizes['medium'][0], $imageSizes['medium'][1] )
|
||||
'large' => array( $this->_data['masked_file_name'] ? (string) \IPS\File::get( 'gallery_Images', $this->_data['masked_file_name'] )->url : null, $imageSizes['large'][0], $imageSizes['large'][1] )
|
||||
),
|
||||
/* We do not use ENT_QUOTES as this replaces " to " which browsers turn back into " again which breaks the JSON string as it needs to be \", single quotes break the data-attribute='' boundaries */
|
||||
'caption' => str_replace( "'", "'", htmlspecialchars( $this->_data['caption'], \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ),
|
||||
'caption' => $this->_data['caption'],
|
||||
'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( "'", "'", htmlspecialchars( str_replace( '"', '"', $this->directContainer()->_title ), \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ), JSON_UNESCAPED_UNICODE ), 1, -1 ),
|
||||
'container' => ( $this->directContainer() instanceof \IPS\gallery\Category ) ? \IPS\Member::loggedIn()->language()->addToStack( "gallery_category_{$this->directContainer()->_id}", false, array( 'json' => true, 'jsonEscape' => true ) ) : $this->directContainer()->_title,
|
||||
'id' => $this->_data['id'],
|
||||
'url' => (string) $this->url(),
|
||||
'url' => (string) $this->url()->setQueryString( $parameters ),
|
||||
'author' => array(
|
||||
'photo' => str_replace( "'", "'", htmlspecialchars( (string) $this->author()->photo, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) ),
|
||||
'name' => str_replace( "'", "'", htmlspecialchars( $this->author()->name, \IPS\HTMLENTITIES, 'UTF-8', FALSE ) )
|
||||
'photo' => (string) $this->author()->photo,
|
||||
'name' => $this->author()->name
|
||||
),
|
||||
'modActions' => $modActions,
|
||||
'modStates' => $modStates,
|
||||
'allowComments' => (boolean) $this->directContainer()->allow_comments,
|
||||
'comments' => ( $this->directContainer()->allow_comments ) ? $this->_data['comments'] : 0,
|
||||
'views' => $this->_data['views']
|
||||
) );
|
||||
), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -541,7 +526,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
{
|
||||
\IPS\gallery\Application::outputCss();
|
||||
|
||||
return array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery' ), 'tableRowsRows' );
|
||||
return array( \IPS\Theme::i()->getTemplate( 'browse', 'gallery', 'front' ), 'tableRowsRows' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,18 +563,19 @@ class _Image extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get comment/review output
|
||||
*
|
||||
* @param string $tab Active tab
|
||||
* @param string $tab Active tab
|
||||
* @param bool $condensed Use condensed style
|
||||
* @return string
|
||||
*/
|
||||
public function commentReviews( $tab )
|
||||
public function commentReviews( $tab, $condensed=FALSE )
|
||||
{
|
||||
if ( $tab === 'reviews' AND $this->container()->allow_reviews AND $this->directContainer()->allow_reviews )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('view')->reviews( $this );
|
||||
return \IPS\Theme::i()->getTemplate('view')->reviews( $this, $condensed );
|
||||
}
|
||||
elseif( $tab === 'comments' AND $this->container()->allow_comments AND $this->directContainer()->allow_comments )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('view')->comments( $this );
|
||||
return \IPS\Theme::i()->getTemplate('view')->comments( $this, $condensed );
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -771,7 +757,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
$queueData['album_id'] = $album->$albumIdColumn;
|
||||
}
|
||||
|
||||
\IPS\Task::queue( 'gallery', 'Follow', $queueData );
|
||||
\IPS\Task::queue( 'gallery', 'Follow', $queueData, 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -874,14 +860,16 @@ class _Image extends \IPS\Content\Item implements
|
||||
protected $imagesSameDate = NULL;
|
||||
|
||||
/**
|
||||
* Get the next 5 images in the container
|
||||
* Get the next or previous 5 images in the container
|
||||
*
|
||||
* @param int $count (Maximum) number of images to return
|
||||
* @param int $count (Maximum) number of images to return
|
||||
* @param string $direction DESC or ASC
|
||||
* @return array
|
||||
*/
|
||||
public function nextImages( $count )
|
||||
public function fetchNextOrPreviousImages( $count, $direction = 'DESC' )
|
||||
{
|
||||
$where = array();
|
||||
$dir = $direction == 'DESC' ? '<' : '>';
|
||||
|
||||
if( $this->album_id )
|
||||
{
|
||||
@@ -905,8 +893,8 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
if( !$this->imagesSameDate )
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . ' >= ?', $this->$column );
|
||||
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ASC', $count ) );
|
||||
$where['date'] = array( static::$databasePrefix . $column . " {$dir}= ?", $this->$column );
|
||||
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ' . $direction, $count ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -916,7 +904,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
$results = array();
|
||||
$seen = FALSE;
|
||||
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ASC', NULL ) as $image )
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ' . $direction, NULL ) as $image )
|
||||
{
|
||||
if( !$seen )
|
||||
{
|
||||
@@ -938,81 +926,8 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
if( count( $results ) < $count )
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . ' > ?', $this->$column );
|
||||
$results = array_merge( $results, iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ASC', $count - count( $results ) ) ) );
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous 5 images in the container
|
||||
*
|
||||
* @param int $count (Maximum) number of images to return
|
||||
* @return array
|
||||
*/
|
||||
public function previousImages( $count )
|
||||
{
|
||||
$where = array();
|
||||
|
||||
if( $this->album_id )
|
||||
{
|
||||
$where[] = array( 'image_album_id=?', $this->album_id );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'image_category_id=?', $this->category_id );
|
||||
$where[] = array( 'image_album_id=?', 0 );
|
||||
}
|
||||
|
||||
$where['id'] = array( 'image_id<>?', $this->id );
|
||||
|
||||
$column = $this->getDateColumn();
|
||||
|
||||
if( $this->imagesSameDate === NULL )
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . '= ?', $this->$column );
|
||||
$this->imagesSameDate = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', $where )->first();
|
||||
}
|
||||
|
||||
if( !$this->imagesSameDate )
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . ' <= ?', $this->$column );
|
||||
return iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' DESC', $count ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . '= ?', $this->$column );
|
||||
unset( $where['id'] );
|
||||
|
||||
$results = array();
|
||||
$seen = FALSE;
|
||||
|
||||
foreach( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' DESC', NULL ) as $image )
|
||||
{
|
||||
if( !$seen )
|
||||
{
|
||||
if( $image->id == $this->id )
|
||||
{
|
||||
$seen = TRUE;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[] = $image;
|
||||
|
||||
if( count( $results ) == $count )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $results ) < $count )
|
||||
{
|
||||
$where['date'] = array( static::$databasePrefix . $column . ' < ?', $this->$column );
|
||||
$results = array_merge( $results, iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' DESC', $count - count( $results ) ) ) );
|
||||
$where['date'] = array( static::$databasePrefix . $column . " {$dir} ?", $this->$column );
|
||||
$results = array_merge( $results, iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( $where, static::$databasePrefix . $column . ' ' . $direction, $count - count( $results ) ) ) );
|
||||
}
|
||||
|
||||
return $results;
|
||||
@@ -1022,11 +937,46 @@ class _Image extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get Next Item
|
||||
*
|
||||
* @param string|NULL $context Context to consider next/previous from
|
||||
* @return \IPS\Content\Item|NULL
|
||||
*/
|
||||
public function nextItem()
|
||||
public function nextItem( $context=NULL )
|
||||
{
|
||||
$result = $this->nextImages( 1 );
|
||||
if( $context !== NULL )
|
||||
{
|
||||
$results = NULL;
|
||||
switch( $context )
|
||||
{
|
||||
case 'featured':
|
||||
$results = iterator_to_array( static::featured( 20, NULL ) );
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$results = iterator_to_array( static::getItemsWithPermission( ( \IPS\Settings::i()->club_nodes_in_apps ? array() : array( array( 'category_club_id IS NULL' ) ) ), NULL, 30, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, !\IPS\Settings::i()->club_nodes_in_apps ) );
|
||||
break;
|
||||
}
|
||||
|
||||
if( $results !== NULL )
|
||||
{
|
||||
$returnNext = FALSE;
|
||||
foreach( $results as $imageResult )
|
||||
{
|
||||
if( $returnNext === TRUE )
|
||||
{
|
||||
return $imageResult;
|
||||
}
|
||||
|
||||
if( $imageResult->id == $this->id )
|
||||
{
|
||||
$returnNext = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = $this->fetchNextOrPreviousImages( 1, 'DESC' );
|
||||
|
||||
if( is_array( $result ) )
|
||||
{
|
||||
@@ -1037,11 +987,43 @@ class _Image extends \IPS\Content\Item implements
|
||||
/**
|
||||
* Get Previous Item
|
||||
*
|
||||
* @param string|NULL $context Context to consider next/previous from
|
||||
* @return \IPS\Content\Item|NULL
|
||||
*/
|
||||
public function prevItem()
|
||||
public function prevItem( $context=NULL )
|
||||
{
|
||||
$result = $this->previousImages( 1 );
|
||||
if( $context !== NULL )
|
||||
{
|
||||
$results = NULL;
|
||||
switch( $context )
|
||||
{
|
||||
case 'featured':
|
||||
$results = iterator_to_array( static::featured( 20, NULL ) );
|
||||
break;
|
||||
|
||||
case 'new':
|
||||
$results = iterator_to_array( static::getItemsWithPermission( ( \IPS\Settings::i()->club_nodes_in_apps ? array() : array( array( 'category_club_id IS NULL' ) ) ), NULL, 30, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, !\IPS\Settings::i()->club_nodes_in_apps ) );
|
||||
break;
|
||||
}
|
||||
|
||||
if( $results !== NULL )
|
||||
{
|
||||
$previousResult = NULL;
|
||||
foreach( $results as $imageResult )
|
||||
{
|
||||
if( $imageResult->id == $this->id )
|
||||
{
|
||||
return $previousResult;
|
||||
}
|
||||
|
||||
$previousResult = $imageResult;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = $this->fetchNextOrPreviousImages( 1, 'ASC' );
|
||||
|
||||
if( is_array( $result ) )
|
||||
{
|
||||
@@ -1060,7 +1042,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
{
|
||||
if ( $container and $container->approve_img and !$member->group['g_avoid_q'] )
|
||||
{
|
||||
return TRUE;
|
||||
return !static::modPermission( 'approve', $member, $container );
|
||||
}
|
||||
|
||||
return parent::moderateNewItems( $member, $container );
|
||||
@@ -1124,7 +1106,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
'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['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 we are editing, return the appropriate fields */
|
||||
@@ -1177,7 +1159,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
* @return void
|
||||
*/
|
||||
public function processForm( $values )
|
||||
{
|
||||
{
|
||||
parent::processForm( $values );
|
||||
|
||||
/* Set a few details */
|
||||
@@ -1242,7 +1224,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
{
|
||||
$val = utf8_encode( $val );
|
||||
} );
|
||||
//$this->metadata = array_map( 'utf8_encode', $this->metadata );
|
||||
|
||||
$this->metadata = json_encode( $metadata );
|
||||
}
|
||||
|
||||
@@ -1266,12 +1248,11 @@ class _Image extends \IPS\Content\Item implements
|
||||
/* Or was the thumbnail removed? */
|
||||
elseif( !$this->_new AND $this->masked_file_name )
|
||||
{
|
||||
foreach( array( 'masked_file_name', 'medium_file_name', 'small_file_name', 'thumb_file_name' ) as $key )
|
||||
foreach( array( 'masked_file_name', 'small_file_name' ) as $key )
|
||||
{
|
||||
if( $this->$key )
|
||||
{
|
||||
$file = \IPS\File::get( 'gallery_Images', $this->$key );
|
||||
$file->delete();
|
||||
\IPS\File::get( 'gallery_Images', $this->$key )->delete();
|
||||
|
||||
$this->$key = NULL;
|
||||
}
|
||||
@@ -1390,27 +1371,13 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
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 )
|
||||
foreach( array( 'masked_file_name', 'small_file_name' ) as $size )
|
||||
{
|
||||
if( $this->$image != $this->original_file_name )
|
||||
{
|
||||
$imagesToDelete[] = $image;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $imagesToDelete as $k )
|
||||
{
|
||||
if ( $this->$k )
|
||||
if( isset( $this->_data[ $size ] ) AND $this->$size AND $this->$size != $this->original_file_name )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'gallery_Images', $this->$k )->delete();
|
||||
\IPS\File::get( 'gallery_Images', $this->$size )->delete();
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
@@ -1425,6 +1392,8 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function buildThumbnails( $file=NULL )
|
||||
{
|
||||
$this->deleteThumbnails();
|
||||
|
||||
if( $file === NULL )
|
||||
{
|
||||
$file = \IPS\File::get( 'gallery_Images', $this->original_file_name );
|
||||
@@ -1439,21 +1408,11 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
$thumbnailDimensions['large'] = $largeImage->getImageDimensions();
|
||||
|
||||
$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 ), FALSE, in_array( 'small', $watermarks ) ) );
|
||||
$smallImage = \IPS\File::create( 'gallery_Images', 'small.' . $file->originalFilename, $this->_createImage( $file, explode( 'x', \IPS\Settings::i()->gallery_small_dims ), \IPS\Settings::i()->gallery_use_square_thumbnails, 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, in_array( 'thumbnail', $watermarks ) ) );
|
||||
$this->thumb_file_name = (string) $thumbImage;
|
||||
|
||||
$thumbnailDimensions['thumb'] = $thumbImage->getImageDimensions();
|
||||
|
||||
$this->_dimensions = $thumbnailDimensions;
|
||||
}
|
||||
|
||||
@@ -1472,7 +1431,8 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
if( $crop )
|
||||
{
|
||||
$image->crop( $dimensions[0], $dimensions[1] );
|
||||
//$image->crop( $dimensions[0], $dimensions[1] );
|
||||
$image->resizeToMax( $dimensions[0], $dimensions[0] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1549,8 +1509,9 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function sizes()
|
||||
{
|
||||
$return = array();
|
||||
$data = json_decode( $this->data, TRUE );
|
||||
$return = array();
|
||||
$data = json_decode( $this->data, TRUE );
|
||||
|
||||
if( !empty( $data ) )
|
||||
{
|
||||
foreach ( $data as $k => $v )
|
||||
@@ -1561,15 +1522,29 @@ class _Image extends \IPS\Content\Item implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $return['large'] ) and isset( $return['thumb'] ) and $return['large'][0] < $return['thumb'][0] and $return['large'][1] < $return['thumb'][1] )
|
||||
{
|
||||
unset( $return['thumb'] );
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log for deletion later
|
||||
*
|
||||
* \IPS\Member|NULL $member The member or NULL for currently logged in
|
||||
* @return void
|
||||
*/
|
||||
public function logDelete( $member = NULL )
|
||||
{
|
||||
parent::logDelete( $member );
|
||||
|
||||
/* Now we need to update "last image" info */
|
||||
if( $this->album_id )
|
||||
{
|
||||
$album = \IPS\gallery\Album::load( $this->album_id );
|
||||
$album->setLastImage();
|
||||
$album->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
@@ -1624,12 +1599,9 @@ 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\Friendly::seoTitle( $indexData['index_title'] ?: $itemData[ static::$databasePrefix . static::$databaseColumnMap['title'] ] ) );
|
||||
|
||||
$albumData = isset( $itemData['extra'] ) ? $itemData['extra'] : NULL;
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'gallery', 'front' )->searchResultImageSnippet( $indexData, $itemData, $albumData, $image, $url, $view == 'condensed' );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'gallery', 'front' )->searchResultImageSnippet( $indexData, $itemData, ( isset( $itemData['extra'] ) ? $itemData['extra'] : NULL ), $itemData['image_small_file_name'], $url, $view == 'condensed' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1673,13 +1645,14 @@ class _Image extends \IPS\Content\Item implements
|
||||
/**
|
||||
* 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 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 object images URLs to where the images are stored. Keys are 'original', 'large', and 'small', 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
|
||||
@@ -1700,7 +1673,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
* @apiresponse string url URL
|
||||
* @apiresponse float rating Average Rating
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
@@ -1711,9 +1684,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
'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(),
|
||||
@@ -1850,6 +1821,38 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check permissions
|
||||
*
|
||||
* @param mixed $permission 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
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @return bool
|
||||
* @throws \OutOfBoundsException If $permission does not exist in map
|
||||
*/
|
||||
public function can( $permission, $member=NULL )
|
||||
{
|
||||
if ( !parent::can( $permission, $member ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( !$this->directContainer()->can( $permission, $member ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
/* If the direct container is lost, assume we can do nothing. @see \IPS\Content\Item::can() */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Still here? It must be okay */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can view?
|
||||
@@ -1871,13 +1874,13 @@ class _Image extends \IPS\Content\Item implements
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* Is this a private album we can't access? */
|
||||
if( $this->directContainer()->type == 2 AND $this->directContainer()->owner() != $member )
|
||||
if( $this->directContainer()->type == \IPS\gallery\Album::AUTH_TYPE_PRIVATE AND $this->directContainer()->owner() != $member )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Is this a restricted album we can't access? */
|
||||
if( $this->directContainer()->type == 3 AND $this->directContainer()->owner() != $member )
|
||||
if( $this->directContainer()->type == \IPS\gallery\Album::AUTH_TYPE_RESTRICTED AND $this->directContainer()->owner() != $member )
|
||||
{
|
||||
/* This will throw an exception of the row does not exist */
|
||||
try
|
||||
@@ -1887,7 +1890,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
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();
|
||||
$member = \IPS\Member::constructFromData( \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 )
|
||||
{
|
||||
@@ -1913,6 +1916,36 @@ class _Image extends \IPS\Content\Item implements
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can set as album coverphoto?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canSetAsAlbumCover( $member=NULL )
|
||||
{
|
||||
if( ( $this->album_id AND $this->canEdit() ) OR static::modPermission( 'edit', $member, $this->container() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can set as category coverphoto?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canSetAsCategoryCover( $member=NULL )
|
||||
{
|
||||
if( static::modPermission( 'edit', $member, $this->container() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached groups the member can access
|
||||
*/
|
||||
@@ -1955,7 +1988,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
/* 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', $member ) )
|
||||
{
|
||||
$result = 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 );
|
||||
$result = array( "( gallery_albums.album_id IS NULL OR gallery_albums.album_type IN(1,2,3) )" );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2011,7 +2044,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
/* We have to fix order by for images */
|
||||
$orders = explode( ',', $order );
|
||||
$newOrder = array();
|
||||
$newOrders = array();
|
||||
|
||||
foreach( $orders as $_order )
|
||||
{
|
||||
@@ -2030,7 +2063,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
$order = implode( ', ', $newOrders );
|
||||
|
||||
$where[] = static::getItemsWithPermissionWhere( $where, $member, $joins );
|
||||
$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 );
|
||||
}
|
||||
|
||||
@@ -2065,10 +2098,12 @@ 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', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
|
||||
|
||||
$_key = md5( get_class( $container ) . $container->_id );
|
||||
static::$itemCounts[ $_key ][ $container->_id ] = $count;
|
||||
|
||||
if( !isset( static::$itemCounts[ $_key ][ $container->_id ] ) )
|
||||
{
|
||||
static::$itemCounts[ $_key ][ $container->_id ] = 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 );
|
||||
}
|
||||
|
||||
return parent::contentCount( $container, $includeItems, $includeComments, $includeReviews, $depth );
|
||||
}
|
||||
@@ -2082,7 +2117,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
*/
|
||||
public function embedImage()
|
||||
{
|
||||
return \IPS\File::get( 'gallery_Images', $this->thumb_file_name );
|
||||
return \IPS\File::get( 'gallery_Images', $this->small_file_name );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2108,7 +2143,7 @@ class _Image extends \IPS\Content\Item implements
|
||||
public function searchIndexPermissions()
|
||||
{
|
||||
/* If this is a private album, only the author can view in search */
|
||||
if ( $this->directContainer() instanceof \IPS\gallery\Album and $this->directContainer()->type != 1 )
|
||||
if ( $this->directContainer() instanceof \IPS\gallery\Album and $this->directContainer()->type != \IPS\gallery\Album::AUTH_TYPE_PUBLIC )
|
||||
{
|
||||
if ( $this->member_id )
|
||||
{
|
||||
@@ -2219,4 +2254,26 @@ class _Image extends \IPS\Content\Item implements
|
||||
|
||||
return $sortOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
$result = parent::contentImages( $limit );
|
||||
|
||||
if( $result === NULL )
|
||||
{
|
||||
$result = array();
|
||||
}
|
||||
|
||||
$result[] = array( 'gallery_Images' => $this->masked_file_name );
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user