Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,57 @@
<?php
/**
* @brief Categories
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\admin\gallery;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Categories
*/
class _categories extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\gallery\Category';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'categories_manage' );
parent::execute();
}
protected function form()
{
parent::form();
if ( \IPS\Request::i()->id )
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('edit_category') . ': ' . \IPS\Output::i()->title;
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('add_category');
}
}
}
Whitespace-only changes.
@@ -0,0 +1,128 @@
<?php
/**
* @brief Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\admin\gallery;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* settings
*/
class _settings extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
parent::execute();
}
/**
* Manage settings
*
* @return void
*/
protected function manage()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
$form = new \IPS\Helpers\Form;
$form->addHeader( 'gallery_images' );
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack('gallery_dims_explanation'), '', FALSE );
$large = ( isset( \IPS\Settings::i()->gallery_large_dims ) ) ? explode( 'x', \IPS\Settings::i()->gallery_large_dims ) : array( 1600, 1200 );
$medium = ( isset( \IPS\Settings::i()->gallery_medium_dims ) ) ? explode( 'x', \IPS\Settings::i()->gallery_medium_dims ) : array( 640, 480 );
$small = ( isset( \IPS\Settings::i()->gallery_small_dims ) ) ? explode( 'x', \IPS\Settings::i()->gallery_small_dims ) : array( 240, 240 );
$thumb = ( isset( \IPS\Settings::i()->gallery_thumb_dims ) ) ? explode( 'x', \IPS\Settings::i()->gallery_thumb_dims ) : array( 100, 100 );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'gallery_large_dims', $large, TRUE, array( 'resizableDiv' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'gallery_medium_dims', $medium, TRUE, array( 'resizableDiv' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'gallery_small_dims', $small, TRUE, array( 'resizableDiv' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\WidthHeight( 'gallery_thumb_dims', $thumb, TRUE, array( 'resizableDiv' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'gallery_use_square_thumbnails', \IPS\Settings::i()->gallery_use_square_thumbnails ) );
$form->add( new \IPS\Helpers\Form\Upload( 'gallery_watermark_path', \IPS\Settings::i()->gallery_watermark_path ? \IPS\File::get( 'core_Theme', \IPS\Settings::i()->gallery_watermark_path ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Theme' ) ) );
$form->addHeader( 'gallery_bandwidth' );
$form->add( new \IPS\Helpers\Form\YesNo( 'gallery_detailed_bandwidth', \IPS\Settings::i()->gallery_detailed_bandwidth ) );
$form->add( new \IPS\Helpers\Form\Number( 'gallery_bandwidth_period', \IPS\Settings::i()->gallery_bandwidth_period, FALSE, array( 'unlimited' => -1 ) ) );
$form->addHeader( 'gallery_options' );
$form->add( new \IPS\Helpers\Form\YesNo( 'gallery_rss_enabled', \IPS\Settings::i()->gallery_rss_enabled ) );
if ( $values = $form->values() )
{
$form->saveAsSettings( array(
'gallery_large_dims' => implode( 'x', $values['gallery_large_dims'] ),
'gallery_medium_dims' => implode( 'x', $values['gallery_medium_dims'] ),
'gallery_small_dims' => implode( 'x', $values['gallery_small_dims'] ),
'gallery_thumb_dims' => implode( 'x', $values['gallery_thumb_dims'] ),
'gallery_use_square_thumbnails' => $values['gallery_use_square_thumbnails'],
'gallery_watermark_path' => $values['gallery_watermark_path'],
'gallery_detailed_bandwidth' => $values['gallery_detailed_bandwidth'],
'gallery_bandwidth_period' => $values['gallery_bandwidth_period'],
'gallery_rss_enabled' => $values['gallery_rss_enabled'],
) );
\IPS\Session::i()->log( 'acplogs__gallery_settings' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('settings');
\IPS\Output::i()->output = $form;
}
/**
* Rebuild gallery images
*
* @return void
*/
protected function rebuildImages()
{
$perGo = 5;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('gallery_rebuildimages');
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=settings&do=rebuildImages' ), function( $doneSoFar ) use( $perGo )
{
$select = \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_media=?', 0 ), 'image_id', array( $doneSoFar, $perGo ), NULL, NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS );
$total = $select->count( TRUE );
if ( !$select->count() )
{
return NULL;
}
foreach ( $select as $row )
{
try
{
$image = \IPS\gallery\Image::constructFromData( $row );
$image->buildThumbnails();
$image->save();
}
catch ( \Exception $e ) {}
}
$doneSoFar += $perGo;
return array( $doneSoFar, \IPS\Member::loggedIn()->language()->addToStack('rebuilding'), ( 100 * $doneSoFar ) / $total );
}, function()
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=settings' ), 'completed' );
} );
}
}
Whitespace-only changes.
@@ -0,0 +1,87 @@
<?php
/**
* @brief Gallery bandwidth statistics
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\admin\stats;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Gallery bandwidth statistics
*/
class _bandwidth extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'bandwidth_manage' );
parent::execute();
}
/**
* Gallery bandwidth statistics
*
* @return void
*/
protected function manage()
{
$chart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=gallery&module=stats&controller=bandwidth" ), 'gallery_bandwidth', 'bdate', '', array( 'vAxis' => array( 'title' => '(kB)' ) ), 'LineChart', 'daily', array( 'start' => 0, 'end' => 0 ), array( 'member_id', 'image_id', 'bdate', 'bsize' ) );
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('bandwidth'), 'number', 'ROUND((SUM(bsize)/1024),2)', FALSE );
$chart->tableParsers = array(
'member_id' => function( $val )
{
try
{
$member = \IPS\Member::load( $val );
return "<a href='" . \IPS\Http\Url::internal( "app=gallery&module=stats&controller=member&do=images&id={$member->member_id}" ) . "'>{$member->name}</a>";
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack('deleted_member');
}
},
'image_id' => function( $val )
{
try
{
$image = \IPS\gallery\Image::load( $val );
return "<a href='{$image->url()}' target='_blank'>{$image->caption}</a>";
}
catch ( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack('deleted_image');
}
},
'bdate' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
},
'bsize' => function( $val )
{
return \IPS\Output\Plugin\Filesize::humanReadableFilesize( $val );
}
);
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('bandwidth_stats');
\IPS\Output::i()->output = (string) $chart;
}
}
@@ -0,0 +1,102 @@
<?php
/**
* @brief Top uploaders
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\admin\stats;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Top uploaders
*/
class _diskspace extends \IPS\Dispatcher\Controller
{
const PER_PAGE = 25;
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'diskspace_manage' );
parent::execute();
}
/**
* Show top uploaders
*
* @return void
*/
protected function manage()
{
$values = NULL;
$where = array();
if ( isset( \IPS\Request::i()->form ) )
{
$form = new \IPS\Helpers\Form( 'form', 'go' );
$form->add( new \IPS\Helpers\Form\DateRange( 'stats_date_range' ) );
if ( $values = $form->values() )
{
if ( $values['stats_date_range']['start'] )
{
$where[] = array( 'image_date>?', $values['stats_date_range']['start']->getTimestamp() );
}
if ( $values['stats_date_range']['end'] )
{
$where[] = array( 'image_date<?', $values['stats_date_range']['end']->getTimestamp() );
}
}
else
{
\IPS\Output::i()->output = $form;
return;
}
}
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
if( $page < 1 )
{
$page = 1;
}
$select = \IPS\Db::i()->select( 'image_member_id, COUNT(*) as images, core_members.*', 'gallery_images', $where, 'images DESC', array( ( $page - 1 ) * static::PER_PAGE, static::PER_PAGE ), 'image_member_id', NULL, \IPS\Db::SELECT_SQL_CALC_FOUND_ROWS )->join( 'core_members', 'core_members.member_id=gallery_images.image_member_id' );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination(
\IPS\Http\Url::internal( 'app=gallery&module=stats&controller=diskspace' )->setQueryString( $values ),
ceil( $select->count( TRUE ) / static::PER_PAGE ),
$page,
static::PER_PAGE,
FALSE
);
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'stats_date_range',
'icon' => 'calendar',
'link' => \IPS\Http\Url::internal( 'app=gallery&module=stats&controller=diskspace&form=1' )->setQueryString( $values ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('stats_date_range') )
)
);
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('stats')->uploadersTable( $select, $pagination );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__gallery_stats_diskspace');
}
}
Whitespace-only changes.
@@ -0,0 +1,109 @@
<?php
/**
* @brief Member Stats
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\admin\stats;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Member Stats
*/
class _member extends \IPS\Dispatcher\Controller
{
/**
* Images
*
* @return void
*/
protected function images()
{
/* Get member */
try
{
$member = \IPS\Member::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G192/1', 404, '' );
}
/* Build chart */
$tabs = array( 'information' => 'information', 'bandwidth_use' => 'bandwidth_use' );
$activeTab = \IPS\Request::i()->tab ?: 'information';
switch ( $activeTab )
{
case 'information':
$imageCount = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_member_id=?', $member->member_id ) )->first();
$diskspaceUsed = \IPS\Db::i()->select( 'SUM(image_file_size)', 'gallery_images', array( 'image_member_id=?', $member->member_id ) )->first();
$numberOfViews = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_bandwidth', array( 'member_id=?', $member->member_id ) )->first();
$bandwidthUsed = \IPS\Db::i()->select( 'SUM(bsize)', 'gallery_bandwidth', array( 'member_id=?', $member->member_id ) )->first();
$allImages = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images' )->first();
$totalFilesize = \IPS\Db::i()->select( 'SUM(image_file_size)', 'gallery_images' )->first();
$allBandwidth = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_bandwidth' )->first();
$totalBandwidth = \IPS\Db::i()->select( 'SUM(bsize)', 'gallery_bandwidth' )->first();
$activeTabContents = \IPS\Theme::i()->getTemplate( 'stats' )->information( \IPS\Theme::i()->getTemplate( 'global', 'core' )->definitionTable( array(
'images_submitted' =>
\IPS\Member::loggedIn()->language()->addToStack( 'images_stat_of_total', FALSE, array( 'sprintf' => array(
\IPS\Member::loggedIn()->language()->formatNumber( $imageCount ),
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $allImages ? ( 100 / $allImages ) : 0 ) * $imageCount ), 2 ) ) )
),
'gdiskspace_used' =>
\IPS\Member::loggedIn()->language()->addToStack( 'images_stat_of_total', FALSE, array( 'sprintf' => array(
\IPS\Output\Plugin\Filesize::humanReadableFilesize( $diskspaceUsed ),
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $totalFilesize ? ( 100 / $totalFilesize ) : 0 ) * $diskspaceUsed ), 2 ) ) )
),
'gaverage_filesize' =>
\IPS\Member::loggedIn()->language()->addToStack( 'images_stat_average' , FALSE, array( 'sprintf' => array(
\IPS\Output\Plugin\Filesize::humanReadableFilesize( \IPS\Db::i()->select( 'AVG(image_file_size)', 'gallery_images', array( 'image_member_id=?', $member->member_id ) )->first() ),
\IPS\Output\Plugin\Filesize::humanReadableFilesize( \IPS\Db::i()->select( 'AVG(image_file_size)', 'gallery_images' )->first() ) ) )
),
'number_of_views' =>
\IPS\Member::loggedIn()->language()->addToStack( 'images_stat_of_total', FALSE, array( 'sprintf' => array(
\IPS\Member::loggedIn()->language()->formatNumber( $numberOfViews ),
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $allBandwidth ? ( 100 / $allBandwidth ) : 0 ) * $imageCount ), 2 ) ))
),
'gallery_bandwidth_used' =>
\IPS\Member::loggedIn()->language()->addToStack( 'images_stat_of_total', FALSE, array( 'sprintf' => array(
\IPS\Output\Plugin\Filesize::humanReadableFilesize( $bandwidthUsed ),
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $totalBandwidth ? ( 100 / $totalBandwidth ) : 0 ) * $bandwidthUsed ), 2 ) ) )
)
) ) );
break;
case 'bandwidth_use':
$bandwidthChart = new \IPS\Helpers\Chart\Dynamic( \IPS\Http\Url::internal( "app=gallery&module=stats&controller=member&do=images&id={$member->member_id}&tab=bandwidth_use&_graph=1" ), 'gallery_bandwidth', 'bdate', '', array( 'vAxis' => array( 'title' => '(kB)' ) ), 'LineChart', 'daily' );
$bandwidthChart->where[] = array( 'member_id=?', $member->member_id );
$bandwidthChart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('bandwidth_use'), 'number', 'ROUND((SUM(bsize)/1024),2)', FALSE );
$activeTabContents = ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->_graph ) ) ? (string) $bandwidthChart : \IPS\Theme::i()->getTemplate( 'stats' )->graphs( (string) $bandwidthChart );
break;
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('member_images_chart', FALSE, array( 'sprintf' => array( $member->name ) ) );
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
}
else
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=gallery&module=stats&controller=member&do=images&id={$member->member_id}" ) );
}
}
}
@@ -0,0 +1,569 @@
<?php
/**
* @brief Browse the gallery
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\front\gallery;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Browse the gallery
*/
class _browse extends \IPS\Dispatcher\Controller
{
/**
* [Content\Controller] Class
*/
protected static $contentModel = 'IPS\gallery\Category';
/**
* Execute
*
* @return void
*/
public function execute()
{
if( isset( \IPS\Request::i()->album ) )
{
static::$contentModel = 'IPS\gallery\Album';
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_browse.js', 'gallery' ) );
parent::execute();
}
/**
* Determine what to show
*
* @return void
*/
protected function manage()
{
/* Legacy 3.x redirect */
if ( isset( \IPS\Request::i()->image ) )
{
try
{
\IPS\Output::i()->redirect( \IPS\gallery\Image::loadAndCheckPerms( \IPS\Request::i()->image )->url(), '', 301 );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/A', 404, '' );
}
}
/* Add RSS feed */
if ( \IPS\Settings::i()->gallery_rss_enabled )
{
\IPS\Output::i()->rssFeeds['gallery_rss_title'] = \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse&do=rss', 'front', 'gallery_rss' );
}
/* And load data and display */
if ( isset( \IPS\Request::i()->category ) )
{
try
{
$category = \IPS\gallery\Category::loadAndCheckPerms( \IPS\Request::i()->category, 'view' );
\IPS\Output::i()->rssFeeds[ \IPS\Member::loggedIn()->language()->addToStack( 'gallery_rss_title_container', FALSE, array( 'sprintf' => array( $category->_title ) ) ) ] = \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse&do=rss&category=' . $category->id, 'front', 'gallery_rss' );
$this->_category( $category );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/1', 404, '' );
}
}
else if ( isset( \IPS\Request::i()->album ) )
{
try
{
$album = \IPS\gallery\Album::loadAndCheckPerms( \IPS\Request::i()->album, 'view' );
\IPS\Output::i()->rssFeeds[ \IPS\Member::loggedIn()->language()->addToStack( 'gallery_rss_title_container', FALSE, array( 'sprintf' => array( $album->_title ) ) ) ] = \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse&do=rss&album=' . $album->id, 'front', 'gallery_rss' );
$this->_album( $album );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/2', 404, '' );
}
}
else
{
$this->_index();
}
}
/**
* Show Index
*
* @return void
*/
protected function _index()
{
/* Get stuff */
$featured = iterator_to_array( \IPS\gallery\Image::featured( 20, '_rand' ) );
$new = iterator_to_array( \IPS\gallery\Image::getItemsWithPermission( array(), NULL, 30 ) );
/* Online User Location */
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=gallery', 'front', 'gallery' ), array(), 'loc_gallery_browsing' );
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('gallery_title');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->index( $featured, $new );
}
/**
* Show a category listing
*
* @return void
*/
protected function categories()
{
/* Online User Location */
\IPS\Session::i()->setLocation( \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse&do=categories', 'front', 'gallery_categories' ), array(), 'loc_gallery_browsing_categories' );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('__app_gallery');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->categories();
}
/**
* Show Category
*
* @param \IPS\gallery\Category $category The category to show
* @return void
*/
protected function _category( $category )
{
/* Online User Location */
$permissions = $category->permissions();
\IPS\Session::i()->setLocation( $category->url(), explode( ",", $permissions['perm_view'] ), 'loc_gallery_viewing_category', array( "gallery_category_{$category->id}" => TRUE ) );
/* Output */
\IPS\Output::i()->title = $category->_title;
/* Need to show albums too */
$albums = NULL;
if( $category->allow_albums )
{
$albums = new \IPS\gallery\Album\Table( NULL, $category );
$albums->title = 'albums';
$albums->classes = array( 'ipsDataList_large' );
$albums = ( $category->hasAlbums() ) ? (string) $albums : NULL;
}
if( !count( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_category_id=? AND image_album_id=?', $category->_id, 0 ) ) ) ) )
{
$table = ( $category->childrenCount() or $albums ) ? '' : \IPS\Theme::i()->getTemplate( 'browse' )->noImages( $category );
\IPS\Output::i()->breadcrumb = array();
\IPS\Output::i()->breadcrumb['module'] = array( \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse', 'front', 'gallery' ), \IPS\Dispatcher::i()->module->_title );
$parents = iterator_to_array( $category->parents() );
if ( count( $parents ) )
{
foreach( $parents AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
}
\IPS\Output::i()->breadcrumb[] = array( NULL, $category->_title );
}
else
{
/* Build table */
$table = new \IPS\gallery\Image\Table( 'IPS\gallery\Image', $category->url(), array( array( 'image_album_id=?', 0 ) ), $category );
$table->limit = 50;
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'browse' ), 'imageTable' );
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'browse' ), $this->getTableRowsTemplate() );
$table->title = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('num_images'), array( $category->count_imgs ) );
if( !$category->allow_comments )
{
unset( $table->sortOptions['num_comments'] );
unset( $table->sortOptions['last_comments'] );
}
if( !$category->allow_rating )
{
unset( $table->sortOptions['rating'] );
}
}
\IPS\Output::i()->contextualSearchOptions[ \IPS\Member::loggedIn()->language()->addToStack( 'search_contextual_item', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'category' ) ) ) ) ] = array( 'type' => 'gallery_image', 'nodes' => $category->_id );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->category( $category, $albums, (string) $table );
}
/**
* Show Album
*
* @param \IPS\gallery\Album $album The album to show
* @return void
*/
protected function _album( $album )
{
if( !count( \IPS\gallery\Image::getItemsWithPermission( array( array( 'image_album_id=?', $album->id ) ) ) ) )
{
/* Show a 'no images' template if there's nothing to display */
$table = \IPS\Theme::i()->getTemplate( 'browse' )->noImages( $album );
}
else
{
/* Build table */
$table = new \IPS\gallery\Image\Table( 'IPS\gallery\Image', $album->url(), array( array( 'image_album_id=?', $album->id ) ), $album->category() );
$table->limit = 50;
$table->sortBy = \IPS\Request::i()->sortby ? $table->sortBy : $album->_sortBy;
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'browse' ), 'imageTable' );
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'browse' ), $this->getTableRowsTemplate() );
$table->title = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('num_images'), array( $album->count_imgs ) );
if( !$album->allow_comments )
{
unset( $table->sortOptions['num_comments'] );
unset( $table->sortOptions['last_comments'] );
}
if( !$album->allow_rating )
{
unset( $table->sortOptions['rating'] );
}
}
/* Online User Location */
$permissions = $album->category()->permissions();
\IPS\Session::i()->setLocation( $album->url(), explode( ",", $permissions['perm_view'] ), 'loc_gallery_viewing_album', array( $album->_title => FALSE ) );
/* Output */
\IPS\Output::i()->title = $album->_title;
\IPS\Output::i()->breadcrumb = array();
\IPS\Output::i()->breadcrumb['module'] = array( \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse', 'front', 'gallery' ), \IPS\Dispatcher::i()->module->_title );
$parents = iterator_to_array( $album->category()->parents() );
if ( count( $parents ) )
{
foreach( $parents AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
}
\IPS\Output::i()->breadcrumb[] = array( $album->category()->url(), $album->category()->_title );
\IPS\Output::i()->breadcrumb[] = array( NULL, $album->_title );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'browse' )->album( $album, (string) $table );
}
/**
* Determine which table rows template to use
*
* @return string
*/
protected function getTableRowsTemplate()
{
if( isset( \IPS\Request::i()->cookie['thumbnailSize'] ) AND \IPS\Request::i()->cookie['thumbnailSize'] == 'large' AND \IPS\Request::i()->controller != 'search' )
{
return 'tableRowsLarge';
}
else if( isset( \IPS\Request::i()->cookie['thumbnailSize'] ) AND \IPS\Request::i()->cookie['thumbnailSize'] == 'rows' AND \IPS\Request::i()->controller != 'search' )
{
return 'tableRowsRows';
}
else
{
return 'tableRowsThumbs';
}
}
/**
* Retrieve some images, used for the slider on the image view page
*
* @return void
*/
protected function getImages()
{
$startingPoint = \IPS\gallery\Image::load( \IPS\Request::i()->image );
$count = intval( \IPS\Request::i()->count );
if( \IPS\Request::i()->direction == 'next' )
{
$results = $startingPoint->nextImages( $count );
}
else
{
$results = $startingPoint->previousImages( $count );
}
$toSend = array();
foreach( $results as $result )
{
$toSend[] = \IPS\Theme::i()->getTemplate( 'view' )->imageThumbnail( $result );
}
/* Respond or redirect */
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( $toSend );
}
else
{
\IPS\Output::i()->redirect( $startingPoint->url() );
}
}
/**
* Latest images RSS
*
* @return void
* @note We use a template so that we can embed image directly into feed while still allowing it to be customized
*/
protected function rss()
{
if( !\IPS\Settings::i()->gallery_rss_enabled )
{
\IPS\Output::i()->error( 'gallery_rss_offline', '2G189/3', 403, 'gallery_rss_offline_admin' );
}
$where = array();
if( isset( \IPS\Request::i()->category ) )
{
try
{
$category = \IPS\gallery\Category::loadAndCheckPerms( \IPS\Request::i()->category, 'read' );
$where[] = array( 'image_category_id=?', $category->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/8', 404, '' );
}
}
else if ( isset( \IPS\Request::i()->album ) )
{
try
{
$album = \IPS\gallery\Album::loadAndCheckPerms( \IPS\Request::i()->album, 'read' );
$where[] = array( 'image_album_id=?', $album->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/9', 404, '' );
}
}
$document = \IPS\Xml\Rss::newDocument( isset( $category ) ? $category->url() : ( isset( $album ) ? $album->url() : \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse', 'front', 'gallery' ) ), \IPS\Member::loggedIn()->language()->addToStack('gallery_rss_title'), \IPS\Member::loggedIn()->language()->addToStack('gallery_rss_title') );
foreach ( \IPS\gallery\Image::getItemsWithPermission( $where ) as $image )
{
$document->addItem( $image->caption, $image->url(), \IPS\Theme::i()->getTemplate( 'view' )->rssContent( $image ), \IPS\DateTime::ts( $image->updated ), $image->id );
}
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
}
/**
* Edit album
*
* @return void
*/
protected function editAlbum()
{
/* Load album and check permissions */
try
{
$album = \IPS\gallery\Album::loadAndCheckPerms( \IPS\Request::i()->album, 'read' );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/5', 404, '' );
}
if( !$album->canEdit() )
{
\IPS\Output::i()->error( 'node_error', '2G189/4', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Build form */
$form = new \IPS\Helpers\Form;
$form->class .= 'ipsForm_vertical';
$album->form( $form, TRUE );
/* Handle submissions */
if ( $values = $form->values() )
{
$values['album_owner'] = ( isset( $values['album_owner'] ) ) ? $values['album_owner'] : \IPS\Member::loggedIn();
if( !$values['album_name'] OR !$values['album_category'] )
{
if( !$values['album_name'] )
{
$form->elements['']['album_name']->error = \IPS\Member::loggedIn()->language()->addToStack('form_required');
}
if( !$values['album_category'] )
{
$form->elements['']['album_category']->error = \IPS\Member::loggedIn()->language()->addToStack('form_required');
}
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
return;
}
$album->saveForm( $album->formatFormValues( $values ) );
\IPS\Output::i()->redirect( $album->url() );
}
/* Display form */
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
}
/**
* Delete album
*
* @return void
*/
protected function deleteAlbum()
{
/* Load album and check permissions */
try
{
$album = \IPS\gallery\Album::loadAndCheckPerms( \IPS\Request::i()->album, 'read' );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G189/6', 404, '' );
}
if( !$album->canDelete() )
{
\IPS\Output::i()->error( 'node_error', '2G189/7', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Build form to move or delete images */
$form = new \IPS\Helpers\Form;
$form->class .= 'ipsForm_vertical';
$form->add( new \IPS\Helpers\Form\YesNo( "delete_images", TRUE, FALSE, array( 'togglesOff' => array( 'move_image_category', 'move_image_album' ) ) ) );
$form->add( new \IPS\Helpers\Form\Node( 'move_image_category', NULL, FALSE, array(
'class' => 'IPS\gallery\Category',
'permissionCheck' => 'add',
), NULL, NULL, NULL, 'move_image_category' ) );
$form->add( new \IPS\Helpers\Form\Node( 'move_image_album', NULL, FALSE, array(
'class' => 'IPS\gallery\Album',
'permissionCheck' => function( $node ) use ( $album )
{
/* Do we have permission to add? */
if( !$node->can( 'add' ) )
{
return false;
}
/* This isn't the album we are deleting right? */
if ( $node->id == $album->id )
{
return false;
}
return true;
}
), NULL, NULL, NULL, 'move_image_album' ) );
/* Handle submissions */
if ( $values = $form->values() )
{
$category = $album->category();
/* Update the count */
if( $album->type == $album::AUTH_TYPE_PUBLIC )
{
$category->public_albums = $category->public_albums - 1;
}
else
{
$category->nonpublic_albums = $category->nonpublic_albums - 1;
}
$category->save();
/* Hide the album */
$album->type = 4;
$album->save();
/* Are we moving the images? */
if( !$values['delete_images'] )
{
if( ( !isset( $values['move_image_category'] ) OR !( $values['move_image_category'] instanceof \IPS\Node\Model ) ) AND
( !isset( $values['move_image_album'] ) OR !( $values['move_image_album'] instanceof \IPS\Node\Model ) ) )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('gallery_cat_or_album');
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
return;
}
$moveData = array( 'class' => 'IPS\gallery\Album', 'id' => $album->_id, 'deleteWhenDone' => TRUE );
if( isset( $values['move_image_category'] ) AND $values['move_image_category'] instanceof \IPS\Node\Model )
{
$moveData['moveToClass'] = 'IPS\gallery\Category';
$moveData['moveTo'] = $values['move_image_category']->_id;
}
else
{
$moveData['moveToClass'] = 'IPS\gallery\Album';
$moveData['moveTo'] = $values['move_image_album']->_id;
}
\IPS\Task::queue( 'core', 'DeleteOrMoveContent', $moveData );
}
else
{
\IPS\Task::queue( 'core', 'DeleteOrMoveContent', array( 'class' => 'IPS\gallery\Album', 'id' => $album->_id, 'deleteWhenDone' => TRUE ) );
}
/* And then redirect */
if( isset( $moveTo ) )
{
\IPS\Output::i()->redirect( $moveTo->url() );
}
else
{
\IPS\Output::i()->redirect( $album->category()->url() );
}
}
/* Display form */
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
}
/**
* Embed
*
* @return void
*/
protected function embed()
{
\IPS\Request::i()->id = \IPS\Request::i()->album;
return parent::embed();
}
}
Whitespace-only changes.
@@ -0,0 +1,186 @@
<?php
/**
* @brief Store and retrieve image notes
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 21 Mar 2014
* @version SVN_VERSION_NUMBER
* @note This is available via javascript-only by the nature of the feature in question.
* @note This is a custom callback script for the jQuery-Notes plugin
* @link <a href='http://jquery-notes.rydygel.de/'>http://jquery-notes.rydygel.de/</a>
*/
namespace IPS\gallery\modules\front\gallery;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Store and retrieve image notes
*/
class _notes extends \IPS\Dispatcher\Controller
{
/**
* Determine what to show
*
* @return void
*/
protected function manage()
{
try
{
$this->image = \IPS\gallery\Image::load( \IPS\Request::i()->imageId );
if ( !$this->image->canView( \IPS\Member::loggedIn() ) )
{
\IPS\Output::i()->error( 'node_error', '2G191/1', 403, '' );
}
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G191/2', 404, '' );
}
$response = NULL;
/* jQuery-Notes will send 'image' parameter which we can ignore */
$noteId = \IPS\Request::i()->id;
$position = \IPS\Request::i()->position;
$note = strip_tags( \IPS\Request::i()->note );
if( \IPS\Request::i()->get )
{
$response = $this->image->_notes;
}
else if( \IPS\Request::i()->add )
{
$response = $this->_addNote( $position, $note );
}
else if( \IPS\Request::i()->delete )
{
$response = $this->_deleteNote( $noteId );
}
else if( \IPS\Request::i()->edit )
{
$response = $this->_editNote( $noteId, $position, $note );
}
\IPS\Output::i()->json( $response );
}
/**
* Delete an image note
*
* @param int $id Note ID to delete
* @return bool
*/
protected function _deleteNote( $id )
{
$notes = $this->image->_notes;
foreach( $notes as $key => $note )
{
if( $note['ID'] == $id )
{
unset( $notes[ $key ] );
break;
}
}
$this->image->_notes = $notes;
$this->image->save();
return 'ok';
}
/**
* Add an image note
*
* @param mixed $position Note position
* @param string $note Note text
* @return bool
*/
protected function _addNote( $position, $note )
{
$notes = $this->image->_notes;
$position = explode( ',', $position );
if( count( $position ) != 4 )
{
return FALSE;
}
$maxNoteId = 0;
foreach( $notes as $_note )
{
if( $_note['ID'] > $maxNoteId )
{
$maxNoteId = $_note['ID'];
}
}
$notes[] = array(
'ID' => $maxNoteId + 1,
'LEFT' => round( $position[0], 5 ),
'TOP' => round( $position[1], 5 ),
'WIDTH' => round( $position[2], 5 ),
'HEIGHT' => round( $position[3], 5 ),
'NOTE' => trim( str_replace( "\n", ' ', str_replace( ' ', ' ', $note ) ) ),
);
$this->image->_notes = $notes;
$this->image->save();
return array( 'id' => $maxNoteId + 1 );
}
/**
* Edit an image note
*
* @param int $id Note ID to edit
* @param mixed $position Note position
* @param string $note Note text
* @return bool
*/
protected function _editNote( $id, $position='', $noteText='' )
{
$notes = $this->image->_notes;
$position = explode( ',', $position );
foreach( $notes as $key => $note )
{
if( $note['ID'] == $id )
{
$notes[ $key ] = $note;
if( $noteText )
{
$notes[ $key ]['NOTE'] = trim( str_replace( "\n", ' ', str_replace( ' ', ' ', $noteText ) ) );
}
if( count( $position ) == 4 )
{
$notes[ $key ]['LEFT'] = round( $position[0], 5 );
$notes[ $key ]['TOP'] = round( $position[1], 5 );
$notes[ $key ]['WIDTH'] = round( $position[2], 5 );
$notes[ $key ]['HEIGHT'] = round( $position[3], 5 );
}
break;
}
}
$this->image->_notes = $notes;
$this->image->save();
return 'ok';
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,554 @@
<?php
/**
* @brief View image
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Gallery
* @since 04 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\gallery\modules\front\gallery;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* View image or movie
*/
class _view extends \IPS\Content\Controller
{
/**
* [Content\Controller] Class
*/
protected static $contentModel = 'IPS\gallery\Image';
/**
* Init
*
* @return void
*/
public function execute()
{
if ( \IPS\Request::i()->do != 'embed' )
{
try
{
$this->image = \IPS\gallery\Image::load( \IPS\Request::i()->id );
if ( !$this->image->canView( \IPS\Member::loggedIn() ) )
{
\IPS\Output::i()->error( $this->image->container()->errorMessage(), '2G188/1', 404, '' );
}
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2G188/2', 404, '' );
}
}
parent::execute();
}
/**
* View Image
*
* @return void
* @link http://www.videojs.com/projects/mimes.html
* @note Only HTML5 and some flash-based video formats will work. MP4, webm and ogg are relatively safe bets but anything else isn't likely to play correctly.
* The above link will allow you to check what is supported in the browser you are using.
* @note As of RC1 we fall back to a generic 'embed' for non-standard formats for better upgrade compatibility...need to look into transcoding in the future
*/
protected function manage()
{
/* Init */
parent::manage();
/* Check restrictions */
if( \IPS\Settings::i()->gallery_detailed_bandwidth AND ( \IPS\Member::loggedIn()->group['g_max_transfer'] OR \IPS\Member::loggedIn()->group['g_max_views'] ) )
{
$lastDay = \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp();
if( \IPS\Member::loggedIn()->group['g_max_views'] )
{
if( \IPS\Db::i()->select( 'COUNT(*) as total', 'gallery_bandwidth', array( 'member_id=? AND bdate > ?', (int) \IPS\Member::loggedIn()->member_id, $lastDay ) )->first() >= \IPS\Member::loggedIn()->group['g_max_views'] )
{
\IPS\Output::i()->error( 'maximum_daily_views', '1G188/7', 403, 'maximum_daily_views_admin' );
}
}
if( \IPS\Member::loggedIn()->group['g_max_transfer'] )
{
if( \IPS\Db::i()->select( 'SUM(bsize) as total', 'gallery_bandwidth', array( 'member_id=? AND bdate > ?', (int) \IPS\Member::loggedIn()->member_id, $lastDay ) )->first() >= ( \IPS\Member::loggedIn()->group['g_max_transfer'] * 1024 ) )
{
\IPS\Output::i()->error( 'maximum_daily_transfer', '1G188/8', 403, 'maximum_daily_transfer_admin' );
}
}
}
/* Set some meta tags */
if( $this->image->media )
{
\IPS\Output::i()->metaTags['og:video'] = $this->image->original_file_name;
\IPS\Output::i()->metaTags['og:video:type'] = $this->image->file_type;
\IPS\Output::i()->metaTags['og:type'] = 'video';
if( count( $this->image->tags() ) )
{
\IPS\Output::i()->metaTags['og:video:tag'] = $this->image->tags();
}
if( $this->image->medium_file_name )
{
\IPS\Output::i()->metaTags['og:image'] = \IPS\File::get( 'gallery_Images', $this->image->medium_file_name )->url;
}
}
else
{
\IPS\Output::i()->metaTags['og:image'] = \IPS\File::get( 'gallery_Images', $this->image->masked_file_name )->url;
\IPS\Output::i()->metaTags['og:image:type'] = $this->image->file_type;
if( count( $this->image->tags() ) )
{
\IPS\Output::i()->metaTags['og:object:tag'] = $this->image->tags();
}
}
/* Set the session location */
\IPS\Session::i()->setLocation( $this->image->url(), $this->image->onlineListPermissions(), 'loc_gallery_viewing_image', array( $this->image->caption => FALSE ) );
/* Get next 2 and previous 2 images in the container for slider */
$slider = array(
'previous' => $this->image->previousImages( 4 ),
'next' => $this->image->nextImages( 4 ),
);
$hasNext = TRUE;
$hasPrev = TRUE;
if( count( $slider['previous'] ) < 4 )
{
$hasPrev = FALSE;
}
else
{
$slider['previous'] = array_slice( $slider['previous'], 0, -1 );
}
if( count( $slider['next'] ) < 4 )
{
$hasNext = FALSE;
}
else
{
$slider['next'] = array_slice( $slider['next'], 0, -1 );
}
/* If this is a video, grab the necessary javascript */
if( $this->image->media )
{
if( \IPS\IN_DEV )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'videojs/video.dev.js', 'gallery', 'interface' ) );
}
else
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'videojs/video.js', 'gallery', 'interface' ) );
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'videojs/videojs-loadswf.js', 'gallery', 'interface' ) );
}
/* Store bandwidth log */
if( \IPS\Settings::i()->gallery_detailed_bandwidth )
{
if( $this->image->media AND ( \IPS\Request::i()->imageSize == 'medium' OR !\IPS\Request::i()->imageSize ) AND $this->image->medium_file_name )
{
$displayedImage = \IPS\File::get( 'gallery_Images', $this->image->medium_file_name );
}
elseif( \IPS\Request::i()->imageSize == 'large' )
{
$displayedImage = \IPS\File::get( 'gallery_Images', $this->image->masked_file_name );
/* We hide the sidebar when displaying the large image */
\IPS\Output::i()->sidebar['enabled'] = FALSE;
}
elseif( \IPS\Request::i()->imageSize == 'small' )
{
$displayedImage = \IPS\File::get( 'gallery_Images', $this->image->small_file_name );
}
elseif( \IPS\Request::i()->imageSize == 'thumb' )
{
$displayedImage = \IPS\File::get( 'gallery_Images', $this->image->thumb_file_name );
}
\IPS\Db::i()->insert( 'gallery_bandwidth', array(
'member_id' => (int) \IPS\Member::loggedIn()->member_id,
'bdate' => time(),
'bsize' => (int) ( ( isset( $displayedImage ) AND $displayedImage->filesize() ) ? $displayedImage->filesize() : $this->image->file_size ),
'image_id' => $this->image->id
) );
}
/* Display */
if( isset( \IPS\Request::i()->imageSize ) )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_view.js', 'gallery' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->imageSizes( $this->image, $this->image->sizes() );
}
elseif( \IPS\Request::i()->isAjax() && isset( \IPS\Request::i()->browse ) )
{
$return = array(
'image' => \IPS\Theme::i()->getTemplate( 'view' )->imageFrame( $this->image, $slider, $this->image->nextItem(), $this->image->prevItem() ),
'info' => \IPS\Theme::i()->getTemplate( 'view' )->imageInfo( $this->image, $slider, $this->image->nextItem(), $this->image->prevItem() ),
'slider' => \IPS\Theme::i()->getTemplate( 'view' )->imageSlider( $this->image, $slider, $this->image->nextItem(), $this->image->prevItem(), $hasNext, $hasPrev )
);
if( $this->image->directContainer()->allow_comments )
{
$return['comments'] = \IPS\Theme::i()->getTemplate( 'view' )->comments( $this->image );
}
\IPS\Output::i()->json( $return );
}
else
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array( \IPS\Http\Url::internal( 'applications/gallery/interface/videojs/video-js.min.css', 'none' ) ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_view.js', 'gallery' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->image( $this->image, $slider, $this->image->nextItem(), $this->image->prevItem(), $hasNext, $hasPrev );
}
}
/**
* View all of the metadata for this image
*
* @return void
*/
protected function metadata()
{
/* Set navigation and title */
$this->_setBreadcrumbAndTitle( $this->image );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('gallery_metadata');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'view' )->metadata( $this->image );
}
/**
* Set this image as a cover photo
*
* @return void
*/
protected function cover()
{
if( ( !$this->image->album_id OR !$this->image->canEdit() ) AND !\IPS\gallery\Image::modPermission( 'edit', NULL, $this->image->container() ) )
{
\IPS\Output::i()->error( 'node_error', '2G188/5', 403, '' );
}
\IPS\Session::i()->csrfCheck();
$lang = '';
if( ( $this->image->album_id AND $this->image->canEdit() ) && ( \IPS\Request::i()->set == 'album' or \IPS\Request::i()->set == 'both' ) )
{
$this->image->directContainer()->cover_img_id = $this->image->id;
$this->image->directContainer()->save();
$lang = \IPS\Member::loggedIn()->language()->addToStack('set_as_album_done');
}
if( ( \IPS\gallery\Image::modPermission( 'edit', NULL, $this->image->container() ) ) && ( \IPS\Request::i()->set == 'category' or \IPS\Request::i()->set == 'both' ) )
{
$this->image->container()->cover_img_id = $this->image->id;
$this->image->container()->save();
if( $lang )
{
$lang = \IPS\Member::loggedIn()->language()->addToStack('set_as_both_done');
}
else
{
$lang = \IPS\Member::loggedIn()->language()->addToStack('set_as_category_done');
}
}
/* Redirect back to image */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array( 'message' => $lang ) );
}
else
{
\IPS\Output::i()->redirect( $this->image->url() );
}
}
/**
* Rotate image
*
* @return void
*/
protected function rotate()
{
/* Check permission */
if( !$this->image->canEdit() )
{
\IPS\Output::i()->error( 'node_error', '2G188/3', 403, '' );
}
/* Determine angle to rotate */
if( \IPS\Request::i()->direction == 'right' )
{
$angle = 270;
}
else
{
$angle = 90;
}
/* Rotate the image and rebuild thumbnails */
$file = \IPS\File::get( 'gallery_Images', $this->image->original_file_name );
$image = \IPS\Image::create( $file->contents() );
$image->rotate( $angle );
$file->replace( (string) $image );
$this->image->buildThumbnails( $file );
$this->image->original_file_name = (string) $file;
$this->image->save();
/* Respond or redirect */
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( 'OK' );
}
else
{
\IPS\Output::i()->redirect( $this->image->url() );
}
}
/**
* Change Author
*
* @return void
*/
public function changeAuthor()
{
/* Permission check */
if ( !$this->image->canChangeAuthor() )
{
\IPS\Output::i()->error( 'no_module_permission', '2G188/6', 403, '' );
}
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Member( 'author', NULL, TRUE ) );
$form->class .= 'ipsForm_vertical';
/* Handle submissions */
if ( $values = $form->values() )
{
$this->image->member_id = $values['author']->member_id;
$this->image->save();
\IPS\Output::i()->redirect( $this->image->url() );
}
/* Display form */
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
}
/**
* Set this image as a profile image
*
* @return void
*/
public function setAsPhoto()
{
/* Permission check */
if ( !\IPS\Member::loggedIn()->member_id )
{
\IPS\Output::i()->error( 'no_module_permission', '2G188/9', 403, '' );
}
/* Only images... */
if ( $this->image->media )
{
\IPS\Output::i()->error( 'no_photo_for_media', '2G188/A', 403, '' );
}
\IPS\Session::i()->csrfCheck();
/* Update profile photo */
$file = \IPS\File::get( 'gallery_Images', $this->image->medium_file_name );
$image = \IPS\Image::create( $file->contents() );
$photo = \IPS\File::create( 'core_Profile', $file->filename, (string) $image );
\IPS\Member::loggedIn()->pp_main_photo = (string) $photo;
\IPS\Member::loggedIn()->pp_thumb_photo = (string) $photo->thumbnail( 'core_Profile', \IPS\PHOTO_THUMBNAIL_SIZE, \IPS\PHOTO_THUMBNAIL_SIZE );
\IPS\Member::loggedIn()->pp_photo_type = "custom";
\IPS\Member::loggedIn()->save();
/* Redirect back to image */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array( 'message' => \IPS\Member::loggedIn()->language()->addToStack('set_as_profile_photo') ) );
}
else
{
\IPS\Output::i()->redirect( $this->image->url() );
}
}
/**
* Move
*
* @return void
* @note Overridden so we can show an album selector as well
*/
protected function move()
{
try
{
$class = static::$contentModel;
$item = $class::loadAndCheckPerms( \IPS\Request::i()->id );
if ( !$item->canMove() )
{
throw new \DomainException;
}
$form = new \IPS\Helpers\Form( 'form', 'move' );
$form->class = 'ipsForm_vertical';
if ( \IPS\gallery\Category::canOnAny('add') and \IPS\gallery\Album::canOnAny('add') )
{
$options = array( 'category' => 'image_category', 'album' => 'image_album' );
$toggles = array( 'category' => array( 'move_to_category' ), 'album' => array( 'move_to_album' ) );
if ( \IPS\gallery\Image::modPermission( 'edit', NULL, NULL ) and \IPS\Db::i()->select( 'COUNT(*)', 'gallery_categories', array( array( 'category_allow_albums=1' ), array( '(' . \IPS\Db::i()->findInSet( 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'], \IPS\Member::loggedIn()->groups ) . ' OR ' . 'core_permission_index.perm_' . \IPS\gallery\Category::$permissionMap['add'] . '=? )', '*' ) ) )->join( 'core_permission_index', array( "core_permission_index.app=? AND core_permission_index.perm_type=? AND core_permission_index.perm_type_id=" . \IPS\gallery\Category::$databaseTable . "." . \IPS\gallery\Category::$databasePrefix . \IPS\gallery\Category::$databaseColumnId, \IPS\gallery\Category::$permApp, \IPS\gallery\Category::$permType ) )->first() )
{
$options['new_album'] = 'move_to_new_album';
$extraFields = array();
foreach ( \IPS\gallery\Album::formFields( NULL, TRUE, \IPS\Request::i()->move_to === 'new_album' ) as $field )
{
if ( !$field->htmlId )
{
$field->htmlId = $field->name . '_id';
}
$toggles['new_album'][] = $field->htmlId;
$extraFields[] = $field;
}
}
$form->add( new \IPS\Helpers\Form\Radio( 'move_to', NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
foreach ( $extraFields as $field )
{
$form->add( $field );
}
}
$form->add( new \IPS\Helpers\Form\Node( 'move_to_category', NULL, NULL, array( 'class' => 'IPS\\gallery\\Category', 'permissionCheck' => 'add' ), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'category' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'move_to_category' ) );
$form->add( new \IPS\Helpers\Form\Node( 'move_to_album', NULL, NULL, array(
'class' => 'IPS\\gallery\\Album',
'permissionCheck' => function( $node )
{
/* Do we have permission to add? */
if( !$node->can( 'add' ) )
{
return false;
}
/* Have we hit an images per album limit? */
if( $node->owner()->group['g_img_album_limit'] AND ( $node->count_imgs + $node->count_imgs_hidden ) >= $node->owner()->group['g_img_album_limit'] )
{
return false;
}
return true;
},
'forceOwner' => $item->author()
), function( $val ) {
if ( !$val and isset( \IPS\Request::i()->move_to ) and \IPS\Request::i()->move_to == 'album' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'move_to_album' ) );
if ( $values = $form->values() )
{
if ( isset( $values['move_to'] ) )
{
if ( $values['move_to'] == 'new_album' )
{
$albumValues = $values;
unset( $albumValues['move_to'] );
unset( $albumValues['move_to_category'] );
unset( $albumValues['move_to_album'] );
$target = new \IPS\gallery\Album;
$target->saveForm( $target->formatFormValues( $albumValues ) );
$target->save();
}
else
{
$target = ( \IPS\Request::i()->move_to == 'category' ) ? $values['move_to_category'] : $values['move_to_album'];
}
}
else
{
$target = isset( $values['move_to_category'] ) ? $values['move_to_category'] : $values['move_to_album'];
}
$item->move( $target, FALSE );
\IPS\Output::i()->redirect( $item->url() );
}
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'node_error', '2S136/D', 403, '' );
}
}
/**
* Set the breadcrumb and title
*
* @param \IPS\Content\Item $item Content item
* @param bool $link Link the content item element in the breadcrumb
* @return void
*/
protected function _setBreadcrumbAndTitle( $item, $link=TRUE )
{
$container = NULL;
try
{
$container = $this->image->container();
foreach ( $container->parents() as $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $container->url(), $container->_title );
}
catch ( \Exception $e ) { }
/* Add album */
if( $this->image->album_id )
{
\IPS\Output::i()->breadcrumb[] = array( $this->image->directContainer()->url(), $this->image->directContainer()->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $link ? $this->image->url() : NULL, $this->image->mapped('title') );
$title = ( isset( \IPS\Request::i()->page ) and \IPS\Request::i()->page > 1 ) ? \IPS\Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( $this->image->mapped('title'), intval( \IPS\Request::i()->page ) ) ) ) : $this->image->mapped('title');
\IPS\Output::i()->title = $container ? ( $title . ' - ' . $container->_title ) : $title;
}
}
Whitespace-only changes.
Whitespace-only changes.