Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -0,0 +1,47 @@
<?php
/**
* @brief Advertisement locations extension
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 16 Jan 2018
*/
namespace IPS\gallery\extensions\core\AdvertisementLocations;
/* 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;
}
/**
* Advertisement locations extension
*/
class _ImageLightbox
{
/**
* Get the locations and the additional settings
*
* @param array $settings Current setting values
* @return array Array with two elements: 'locations' which should have keys as the location keys and values as the fields to toggle, and 'settings' which are additional fields to add to the form
*/
public function getSettings( $settings )
{
return array( 'locations' => array( 'ad_image_lightbox' => array() ), 'settings' => array() );
}
/**
* Return an array of setting values to store
*
* @param array $values Values from the form submission
* @return array Array of setting key => value to store
*/
public function parseSettings( $values )
{
return array();
}
}
@@ -68,6 +68,7 @@ class _Gallery
return new \IPS\Helpers\Table\Content( $className, $url, $where );
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_browse.js', 'gallery' ) );
\IPS\gallery\Application::outputCss();
$table = new \IPS\gallery\Image\Table( $className, $url, $where );
@@ -30,12 +30,19 @@ class _gallery
*/
public function getItems()
{
if ( \IPS\gallery\Category::canOnAny( 'add' ) )
if ( \IPS\gallery\Category::canOnAny( 'add', NULL, \IPS\Settings::i()->club_nodes_in_apps ? array() : array( array( 'category_club_id IS NULL' ) ) ) )
{
return array(
'gallery_image' => array(
'link' => \IPS\Http\Url::internal( "app=gallery&module=gallery&controller=submit&_new=1", 'front', 'gallery_submit' ),
'extraData' => array( 'data-ipsDialog-size' => "fullscreen", 'data-ipsDialog' => true )
'extraData' => array(
'data-ipsDialog-size' => "medium",
'data-ipsDialog' => 'true',
'data-ipsDialog-destructOnClose' => 'true',
'data-ipsDialog-close' => 'false',
'data-ipsDialog-extraClass' => 'cGalleryDialog_outer',
'data-ipsDialog-remoteSubmit' => 'true',
)
)
);
}
@@ -70,7 +70,7 @@ class _Images
foreach ( \IPS\Db::i()->select( '*', 'gallery_images', $where, 'image_date DESC', array( ( $page - 1 ) * $limit, $limit ) ) as $row )
{
$image = \IPS\gallery\Image::load( $row['image_id'] );
$obj = \IPS\File::get( 'gallery_Images', $row['image_masked_file_name'] );
$obj = \IPS\File::get( 'gallery_Images', $row['image_original_file_name'] );
$obj->contextInfo = $image->caption;
$return[ (string) $image->url() ] = $obj;
}
@@ -47,19 +47,6 @@ class _Images
$image = \IPS\Db::i()->select( '*', 'gallery_images', array(), 'image_id', array( $offset, 1 ) )->first();
$update = array();
if( $image['image_thumb_file_name'] )
{
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'gallery_Images', $image['image_thumb_file_name'] )->move( $storageConfiguration );
$update['image_thumb_file_name'] = (string) $file;
}
catch( \Exception $e )
{
/* Any issues are logged */
}
}
if( $image['image_small_file_name'] )
{
try
@@ -93,26 +80,6 @@ class _Images
}
}
if( $image['image_medium_file_name'] )
{
if( $image['image_medium_file_name'] == $image['image_masked_file_name'] AND isset( $update['image_masked_file_name'] ) )
{
$update['image_medium_file_name'] = $update['image_masked_file_name'];
}
else
{
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'gallery_Images', $image['image_medium_file_name'] )->move( $storageConfiguration );
$update['image_medium_file_name'] = (string) $file;
}
catch( \Exception $e )
{
/* Any issues are logged */
}
}
}
if( $image['image_original_file_name'] )
{
if( $image['image_original_file_name'] == $image['image_masked_file_name'] AND isset( $update['image_masked_file_name'] ) )
@@ -161,7 +128,7 @@ class _Images
$image = \IPS\Db::i()->select( '*', 'gallery_images', array(), 'image_id', array( $offset, 1 ) )->first();
$update = array();
foreach( array( 'image_thumb_file_name', 'image_small_file_name', 'image_masked_file_name', 'image_medium_file_name', 'image_original_file_name' ) as $key )
foreach( array( 'image_small_file_name', 'image_masked_file_name', 'image_original_file_name' ) as $key )
{
if( $image[ $key ] )
{
@@ -188,7 +155,7 @@ class _Images
{
try
{
$record = \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_masked_file_name=? OR image_medium_file_name=? OR image_original_file_name=? OR image_thumb_file_name=? OR image_small_file_name=?', (string) $file, (string) $file, (string) $file, (string) $file, (string) $file ) )->first();
$record = \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_masked_file_name=? OR image_original_file_name=? OR image_small_file_name=?', (string) $file, (string) $file, (string) $file ) )->first();
return TRUE;
}
@@ -207,49 +174,16 @@ class _Images
{
foreach( \IPS\Db::i()->select( '*', 'gallery_images' ) as $image )
{
if( $image['image_masked_file_name'] )
foreach( array( 'image_masked_file_name', 'image_original_file_name', 'image_small_file_name' ) as $size )
{
try
if( $image[ $size ] )
{
\IPS\File::get( 'gallery_Images', $image['image_masked_file_name'] )->delete();
try
{
\IPS\File::get( 'gallery_Images', $image[ $size ] )->delete();
}
catch( \Exception $e ){}
}
catch( \Exception $e ){}
}
if( $image['image_original_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_original_file_name'] )->delete();
}
catch( \Exception $e ){}
}
if( $image['image_medium_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_medium_file_name'] )->delete();
}
catch( \Exception $e ){}
}
if( $image['image_thumb_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_thumb_file_name'] )->delete();
}
catch( \Exception $e ){}
}
if( $image['image_small_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_small_file_name'] )->delete();
}
catch( \Exception $e ){}
}
}
}
@@ -37,7 +37,7 @@ class _Album
'exclude' => array(),
'lessIsMore' => array(),
'neg1IsBest' => array(),
'zeroIsBest' => array( 'g_album_limit' ),
'zeroIsBest' => array( 'g_album_limit', 'g_img_album_limit', 'g_max_upload', 'g_max_transfer', 'g_max_views' ),
);
}
}
@@ -0,0 +1,85 @@
<?php
/**
* @brief Member ACP Profile - Content Statistics Tab: Gallery
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 30 Nov 2017
*/
namespace IPS\gallery\extensions\core\MemberACPProfileContentTab;
/* 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;
}
/**
* @brief Member ACP Profile - Content Statistics Tab: Gallery
*/
class _Gallery extends \IPS\core\MemberACPProfile\Block
{
/**
* Get output
*
* @return string
*/
public function output()
{
$imageCount = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_member_id=?', $this->member->member_id ) )->first();
$diskspaceUsed = \IPS\Db::i()->select( 'SUM(image_file_size)', 'gallery_images', array( 'image_member_id=?', $this->member->member_id ) )->first();
$numberOfViews = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_bandwidth', array( 'member_id=?', $this->member->member_id ) )->first();
$bandwidthUsed = \IPS\Db::i()->select( 'SUM(bsize)', 'gallery_bandwidth', array( 'member_id=?', $this->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();
return \IPS\Theme::i()->getTemplate( 'stats', 'gallery' )->information( $this->member, \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=?', $this->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_link', FALSE, array( 'htmlsprintf' => array(
\IPS\Output\Plugin\Filesize::humanReadableFilesize( $bandwidthUsed ),
\IPS\Member::loggedIn()->language()->formatNumber( ( ( $totalBandwidth ? ( 100 / $totalBandwidth ) : 0 ) * $bandwidthUsed ), 2 ),
\IPS\Theme::i()->getTemplate( 'stats', 'gallery' )->bandwidthButton( $this->member ) ) )
)
) ) );
}
/**
* Edit Window
*
* @return string
*/
public function edit()
{
$bandwidthChart = new \IPS\Helpers\Chart\Database( \IPS\Http\Url::internal( "app=core&module=members&controller=members&do=editBlock&block=IPS\\gallery\\extensions\\core\\MemberACPProfileContentTab\\Gallery&id={$this->member->member_id}&chart=downloads&_graph=1" ), 'gallery_bandwidth', 'bdate', '', array( 'vAxis' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack( 'filesize_raw_k' ) ) ), 'LineChart', 'daily' );
$bandwidthChart->groupBy = 'bdate';
$bandwidthChart->where[] = array( 'member_id=?', $this->member->member_id );
$bandwidthChart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('bandwidth_use'), 'number', 'ROUND((SUM(bsize)/1024),2)', FALSE );
return ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->_graph ) ) ? (string) $bandwidthChart : \IPS\Theme::i()->getTemplate( 'stats', 'gallery' )->graphs( (string) $bandwidthChart );
}
}
@@ -1,52 +1,3 @@
<?php
/**
* @brief Admin CP Member Form
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 07 Mar 2014
*/
namespace IPS\gallery\extensions\core\MemberForm;
/* 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;
}
/**
* Admin CP Member Form
*/
class _Images
{
/**
* Process Form
*
* @param \IPS\Helpers\Form $form The form
* @param \IPS\Member $member Existing Member
* @return void
*/
public function process( &$form, $member )
{
$form->addMessage( "<a href='" . \IPS\Http\Url::internal( 'app=gallery&module=stats&controller=member&do=images&id=' . $member->member_id ) . "'>" . \IPS\Member::loggedIn()->language()->addToStack('gallery_stats') . '</a>', '', FALSE );
$form->add( new \IPS\Helpers\Form\YesNo( 'remove_gallery_access', !$member->members_bitoptions['remove_gallery_access'], NULL, array( 'togglesOn' => array( 'remove_gallery_upload' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'remove_gallery_upload', !$member->members_bitoptions['remove_gallery_upload'], NULL, array(), NULL, NULL, NULL, 'remove_gallery_upload' ) );
}
/**
* Save
*
* @param array $values Values from form
* @param \IPS\Member $member The member
* @return void
*/
public function save( $values, &$member )
{
$member->members_bitoptions['remove_gallery_access'] = !$values['remove_gallery_access'];
$member->members_bitoptions['remove_gallery_upload'] = !$values['remove_gallery_upload'];
}
}
// Removed
@@ -0,0 +1,103 @@
<?php
/**
* @brief Member Restrictions: Gallery
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 30 Nov 2017
*/
namespace IPS\gallery\extensions\core\MemberRestrictions;
/* 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;
}
/**
* @brief Member Restrictions: Gallery
*/
class _Gallery extends \IPS\core\MemberACPProfile\Restriction
{
/**
* Modify Edit Restrictions form
*
* @param \IPS\Helpers\Form $form The form
* @return void
*/
public function form( \IPS\Helpers\Form $form )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'remove_gallery_access', !$this->member->members_bitoptions['remove_gallery_access'], FALSE, array( 'togglesOn' => array( 'remove_gallery_upload' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'remove_gallery_upload', !$this->member->members_bitoptions['remove_gallery_upload'], FALSE, array(), NULL, NULL, NULL, 'remove_gallery_upload' ) );
}
/**
* Save Form
*
* @param array $values Values from form
* @return array
*/
public function save( $values )
{
$return = array();
if ( $this->member->members_bitoptions['remove_gallery_access'] == $values['remove_gallery_access'] )
{
$return['remove_gallery_access'] = array( 'old' => $this->member->members_bitoptions['remove_gallery_access'], 'new' => !$values['remove_gallery_access'] );
$this->member->members_bitoptions['remove_gallery_access'] = !$values['remove_gallery_access'];
}
if ( $this->member->members_bitoptions['remove_gallery_upload'] == $values['remove_gallery_upload'] )
{
$return['remove_gallery_upload'] = array( 'old' => $this->member->members_bitoptions['remove_gallery_upload'], 'new' => !$values['remove_gallery_upload'] );
$this->member->members_bitoptions['remove_gallery_upload'] = !$values['remove_gallery_upload'];
}
return $return;
}
/**
* What restrictions are active on the account?
*
* @return array
*/
public function activeRestrictions()
{
$return = array();
if ( $this->member->members_bitoptions['remove_gallery_access'] )
{
$return[] = 'restriction_no_gallery_access';
}
elseif ( $this->member->members_bitoptions['remove_gallery_upload'] )
{
$return[] = 'restriction_no_gallery_uploads';
}
return $return;
}
/**
* Get details of a change to show on history
*
* @param array $changes Changes as set in save()
* @return array
*/
public static function changesForHistory( $changes )
{
$return = array();
foreach ( array( 'remove_gallery_access', 'remove_gallery_upload' ) as $k )
{
if ( isset( $changes[ $k ] ) )
{
$return[] = \IPS\Member::loggedIn()->language()->addToStack( 'history_restrictions_' . $k . '_' . intval( $changes[ $k ]['new'] ) );
}
}
return $return;
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @brief Template Plugin - Gallery: Background image formatting
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Content
* @since 12 March 2014
*/
namespace IPS\gallery\extensions\core\OutputPlugins;
/* 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;
}
/**
* Template Plugin - Gallery: Background image formatting
*/
class _Backgroundimage
{
/**
* @brief Can be used when compiling CSS
*/
public static $canBeUsedInCss = TRUE;
/**
* Run the plug-in
*
* @param string $data The initial data from the tag
* @param array $options Array of options
* @return string Code to eval
*/
public static function runPlugin( $data, $options )
{
return "str_replace( array( '(', ')' ), array( '\(', '\)' ), " . $data . " );";
}
}
@@ -0,0 +1,159 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 06 Mar 2018
*/
namespace IPS\gallery\extensions\core\Queue;
/* 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;
}
/**
* Background Task
*/
class _CleanUpGalleryImages
{
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
try
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images' )->first();
}
catch( \Exception $ex )
{
throw new \OutOfRangeException;
}
if( $data['count'] == 0 )
{
return null;
}
$data['did'] = 0;
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( $data, $offset )
{
if ( !\IPS\Application::appIsEnabled( 'gallery' ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$last = NULL;
foreach( \IPS\Db::i()->select( '*', 'gallery_images', NULL, 'image_id ASC', array( $offset, 100 ) ) as $image )
{
$data['did']++;
/* Update the sizes array to remove the images we no longer support */
$sizes = json_decode( $image['image_data'], true );
if( isset( $sizes['thumb'] ) )
{
unset( $sizes['thumb'] );
}
if( isset( $sizes['medium'] ) )
{
unset( $sizes['medium'] );
}
$update = array( 'image_data' => json_encode( $sizes ) );
/* If we have a medium but no large image, or a thumb but no small image, adapt as appropriate */
$keepMedium = FALSE;
if( !$image['image_masked_file_name'] AND $image['image_medium_file_name'] )
{
$image['image_masked_file_name'] = $image['image_medium_file_name'];
$update['image_masked_file_name'] = $image['image_masked_file_name'];
$keepMedium = TRUE;
}
$keepThumb = FALSE;
if( !$image['image_small_file_name'] AND $image['image_thumb_file_name'] )
{
$image['image_small_file_name'] = $image['image_thumb_file_name'];
$update['image_small_file_name'] = $image['image_small_file_name'];
$keepThumb = TRUE;
}
\IPS\Db::i()->update( 'gallery_images', $update, array( 'image_id=?', $image['image_id'] ) );
/* Delete the images we don't need now */
if( !$keepMedium AND $image['image_medium_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_medium_file_name'] )->delete();
}
catch( \Exception $e ) {}
}
if( !$keepThumb AND $image['image_thumb_file_name'] )
{
try
{
\IPS\File::get( 'gallery_Images', $image['image_thumb_file_name'] )->delete();
}
catch( \Exception $e ) {}
}
$last = $image['image_id'];
}
if ( $last === NULL )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $last;
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('cleaning_up_gallery_images'), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['did'], 2 ) ) : 100 );
}
/**
* Perform post-completion processing
*
* @param array $data
* @return void
*/
public function postComplete( $data )
{
\IPS\Db::i()->query( "ALTER TABLE `" . \IPS\Db::i()->prefix . "gallery_images` DROP COLUMN image_thumb_file_name, DROP COLUMN image_medium_file_name" );
}
}
@@ -0,0 +1,112 @@
<?php
/**
* @brief Background Task
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 04 Dec 2017
*/
namespace IPS\gallery\extensions\core\Queue;
/* 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;
}
/**
* Background Task
*/
class _RebuildGalleryImages
{
/**
* @brief Number of content items to rebuild per cycle
*/
public $rebuild = 20;
/**
* Parse data before queuing
*
* @param array $data
* @return array
*/
public function preQueueData( $data )
{
try
{
$data['count'] = \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images', array( 'image_media=?', 0 ) )->first();
}
catch( \Exception $ex )
{
throw new \OutOfRangeException;
}
if( $data['count'] == 0 )
{
return null;
}
$data['indexed'] = 0;
return $data;
}
/**
* Run Background Task
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return int New offset
* @throws \IPS\Task\Queue\OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function run( &$data, $offset )
{
if ( !\IPS\Application::appIsEnabled( 'gallery' ) )
{
throw new \IPS\Task\Queue\OutOfRangeException;
}
$iterator = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_images', array( array( 'image_media=? AND image_id>?', 0, $offset ) ), 'image_id ASC', array( 0, $this->rebuild ) ), 'IPS\\gallery\\Image' );
$last = NULL;
foreach( $iterator as $image )
{
try
{
$image->deleteThumbnails();
$image->buildThumbnails();
$image->save();
}
catch ( \Exception $e ) {}
$last = $image->id;
$data['indexed']++;
}
if( $last === NULL )
{
\IPS\Session::i()->log( 'acplogs__gallery_rebuilt' );
throw new \IPS\Task\Queue\OutOfRangeException;
}
return $last;
}
/**
* Get Progress
*
* @param mixed $data Data as it was passed to \IPS\Task::queue()
* @param int $offset Offset
* @return array( 'text' => 'Doing something...', 'complete' => 50 ) Text explaining task and percentage complete
* @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete
*/
public function getProgress( $data, $offset )
{
return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_gallery_images' ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $data['indexed'], 2 ) ) : 100 );
}
}
@@ -0,0 +1,163 @@
<?php
/**
* @brief Support Images in sitemaps
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 09 Feb 2018
*/
namespace IPS\gallery\extensions\core\Sitemap;
/* 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;
}
/**
* Support Images in sitemaps
*/
class _Images
{
/**
* @brief Recommended Settings
*/
public $recommendedSettings = array();
/**
* Add settings for ACP configuration to the form
*
* @return array
*/
public function settings()
{
return array();
}
/**
* Get the sitemap filename(s)
*
* @return array
*/
public function getFilenames()
{
$count = \IPS\gallery\Image::getItemsWithPermission( array( 'image_media=?', 0 ), NULL, 10, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$files = array();
$count = ceil( $count / \IPS\Sitemap::MAX_PER_FILE );
for( $i=1; $i <= $count; $i++ )
{
$files[] = 'sitemap_imagesitemap_' . $i;
}
return $files;
}
/**
* Generate the sitemap
*
* @param string $filename The sitemap file to build (should be one returned from getFilenames())
* @param \IPS\Sitemap $sitemap Sitemap object reference
* @return void
*/
public function generateSitemap( $filename, $sitemap )
{
$entries = array();
$lastId = 0;
$settings = \IPS\Settings::i()->sitemap_content_settings ? json_decode( \IPS\Settings::i()->sitemap_content_settings, TRUE ) : array();
$class = 'IPS\\gallery\\Image';
$exploded = explode( '_', $filename );
$block = (int) array_pop( $exploded );
$totalLimit = isset( $settings["sitemap_{$class::$title}_count"] ) AND $settings["sitemap_{$class::$title}_count"] ? $settings["sitemap_{$class::$title}_count"] : \IPS\core\extensions\core\Sitemap\Content::RECOMMENDED_ITEM_LIMIT;
$offset = ( $block - 1 ) * \IPS\Sitemap::MAX_PER_FILE;
$limit = \IPS\Sitemap::MAX_PER_FILE;
if ( $totalLimit > -1 and ( $offset + $limit ) > $totalLimit )
{
$limit = $totalLimit - $offset;
}
/* Create limit clause */
$limitClause = array( $offset, $limit );
$where = $class::sitemapWhere();
$where[] = array( 'image_media=?', 0 );
/* Try to fetch the highest ID built in the last sitemap, if it exists */
try
{
$lastId = \IPS\Db::i()->select( 'last_id', 'core_sitemap', array( array( 'sitemap=?', implode( '_', $exploded ) . '_' . ( $block - 1 ) ) ) )->first();
if( $lastId > 0 )
{
$where[] = array( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId . ' > ?', $lastId );
$limitClause = $limit;
}
}
catch( \UnderflowException $e ){}
$idColumn = $class::$databaseColumnId;
foreach ( $class::getItemsWithPermission( $where, $class::$databasePrefix . $class::$databaseColumnId .' ASC', $limitClause, 'read', \IPS\Content\Hideable::FILTER_PUBLIC_ONLY, \IPS\Content\Item::SELECT_IDS_FIRST, new \IPS\Member, TRUE ) as $item )
{
if( !$item->canView( new \IPS\Member ) )
{
continue;
}
$data = array( 'url' => $item->url() );
$lastMod = NULL;
if ( isset( $item::$databaseColumnMap['last_comment'] ) )
{
$lastCommentField = $item::$databaseColumnMap['last_comment'];
if ( is_array( $lastCommentField ) )
{
foreach ( $lastCommentField as $column )
{
$lastMod = \IPS\DateTime::ts( $item->$column );
}
}
else
{
$lastMod = \IPS\DateTime::ts( $item->$lastCommentField );
}
}
if ( $lastMod )
{
$data['lastmod'] = $lastMod;
}
/* Image sitemap data */
$data['image:image'] = array(
'image:loc' => (string) \IPS\File::get( 'gallery_Images', $item->masked_file_name )->url,
'image:caption' => $item->mapped('title'),
'image:title' => $item->mapped('title')
);
if( \IPS\GeoLocation::enabled() AND $item->gps_show )
{
$data['image:image']['image:geo_location'] = $item->loc_short;
}
$priority = ( $item->sitemapPriority() ?: ( intval( isset( $settings["sitemap_{$class::$title}_priority"] ) ? $settings["sitemap_{$class::$title}_priority"] : \IPS\core\extensions\core\Sitemap\Content::RECOMMENDED_ITEM_PRIORITY ) ) );
if ( $priority !== -1 )
{
$data['priority'] = $priority;
$entries[] = $data;
}
$lastId = $item->$idColumn;
}
$sitemap->buildSitemapFile( $filename, $entries, $lastId, array( 'image' => 'http://www.google.com/schemas/sitemap-image/1.1' ) );
return $lastId;
}
}
@@ -0,0 +1,169 @@
<?php
/**
* @brief Support Videos in sitemaps
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Gallery
* @since 09 Feb 2018
*/
namespace IPS\gallery\extensions\core\Sitemap;
/* 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;
}
/**
* Support Videos in sitemaps
*/
class _Videos
{
/**
* @brief Recommended Settings
*/
public $recommendedSettings = array();
/**
* Add settings for ACP configuration to the form
*
* @return array
*/
public function settings()
{
return array();
}
/**
* Get the sitemap filename(s)
*
* @return array
*/
public function getFilenames()
{
$count = \IPS\gallery\Image::getItemsWithPermission( array( 'image_media=?', 1 ), NULL, 10, 'read', \IPS\Content\Hideable::FILTER_AUTOMATIC, 0, NULL, FALSE, FALSE, FALSE, TRUE );
$files = array();
$count = ceil( $count / \IPS\Sitemap::MAX_PER_FILE );
for( $i=1; $i <= $count; $i++ )
{
$files[] = 'sitemap_videositemap_' . $i;
}
return $files;
}
/**
* Generate the sitemap
*
* @param string $filename The sitemap file to build (should be one returned from getFilenames())
* @param \IPS\Sitemap $sitemap Sitemap object reference
* @return void
*/
public function generateSitemap( $filename, $sitemap )
{
$entries = array();
$lastId = 0;
$settings = \IPS\Settings::i()->sitemap_content_settings ? json_decode( \IPS\Settings::i()->sitemap_content_settings, TRUE ) : array();
$class = 'IPS\\gallery\\Image';
$exploded = explode( '_', $filename );
$block = (int) array_pop( $exploded );
$totalLimit = isset( $settings["sitemap_{$class::$title}_count"] ) AND $settings["sitemap_{$class::$title}_count"] ? $settings["sitemap_{$class::$title}_count"] : \IPS\core\extensions\core\Sitemap\Content::RECOMMENDED_ITEM_LIMIT;
$offset = ( $block - 1 ) * \IPS\Sitemap::MAX_PER_FILE;
$limit = \IPS\Sitemap::MAX_PER_FILE;
if ( $totalLimit > -1 and ( $offset + $limit ) > $totalLimit )
{
$limit = $totalLimit - $offset;
}
/* Create limit clause */
$limitClause = array( $offset, $limit );
$where = $class::sitemapWhere();
$where[] = array( 'image_media=?', 1 );
/* Try to fetch the highest ID built in the last sitemap, if it exists */
try
{
$lastId = \IPS\Db::i()->select( 'last_id', 'core_sitemap', array( array( 'sitemap=?', implode( '_', $exploded ) . '_' . ( $block - 1 ) ) ) )->first();
if( $lastId > 0 )
{
$where[] = array( $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId . ' > ?', $lastId );
$limitClause = $limit;
}
}
catch( \UnderflowException $e ){}
$idColumn = $class::$databaseColumnId;
foreach ( $class::getItemsWithPermission( $where, $class::$databasePrefix . $class::$databaseColumnId .' ASC', $limitClause, 'read', \IPS\Content\Hideable::FILTER_PUBLIC_ONLY, \IPS\Content\Item::SELECT_IDS_FIRST, new \IPS\Member, TRUE ) as $item )
{
if( !$item->canView( new \IPS\Member ) )
{
continue;
}
$data = array( 'url' => $item->url() );
$lastMod = NULL;
if ( isset( $item::$databaseColumnMap['last_comment'] ) )
{
$lastCommentField = $item::$databaseColumnMap['last_comment'];
if ( is_array( $lastCommentField ) )
{
foreach ( $lastCommentField as $column )
{
$lastMod = \IPS\DateTime::ts( $item->$column );
}
}
else
{
$lastMod = \IPS\DateTime::ts( $item->$lastCommentField );
}
}
if ( $lastMod )
{
$data['lastmod'] = $lastMod;
}
/* Video sitemap data */
$data['video:video'] = array(
'video:content_loc' => (string) \IPS\File::get( 'gallery_Images', $item->original_file_name )->url,
'video:description' => $item->mapped('content'),
'video:title' => $item->mapped('title'),
'video:rating' => $item->mapped('rating_average'),
'video:view_count' => $item->mapped('views'),
'video:publication_date' => \IPS\DateTime::ts( $item->date )->rfc3339(),
'video:category' => \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( $item->container()->_titleLanguageKey ),
'video:gallery_loc' => array( 0 => (string) $item->directContainer()->url(), 'title' => $item->directContainer()->_title ),
'video:uploader' => array( 0 => $item->author()->name, 'info' => (string) $item->author()->url() ),
);
if( $item->masked_file_name )
{
$data['video:video']['video:thumbnail_loc'] = (string) \IPS\File::get( 'gallery_Images', $item->masked_file_name )->url;
}
$priority = ( $item->sitemapPriority() ?: ( intval( isset( $settings["sitemap_{$class::$title}_priority"] ) ? $settings["sitemap_{$class::$title}_priority"] : \IPS\core\extensions\core\Sitemap\Content::RECOMMENDED_ITEM_PRIORITY ) ) );
if ( $priority !== -1 )
{
$data['priority'] = $priority;
$entries[] = $data;
}
$lastId = $item->$idColumn;
}
$sitemap->buildSitemapFile( $filename, $entries, $lastId, array( 'video' => 'http://www.google.com/schemas/sitemap-video/1.1' ) );
return $lastId;
}
}