Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,25 +12,34 @@
namespace IPS\gallery\extensions\core\FileStorage;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Db;
use IPS\Extensions\FileStorageAbstract;
use IPS\File;
use UnderflowException;
use function count;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* File Storage Extension: Images
*/
class _Images
class Images extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'gallery_images' )->first();
return Db::i()->select( 'COUNT(*)', 'gallery_images' )->first();
}
/**
@@ -39,22 +48,22 @@ class _Images
* @param int $offset This will be sent starting with 0, increasing to get all files stored by this extension
* @param int $storageConfiguration New storage configuration ID
* @param int|NULL $oldConfiguration Old storage configuration ID
* @throws \Underflowexception When file record doesn't exist. Indicating there are no more files to move
* @throws Underflowexception When file record doesn't exist. Indicating there are no more files to move
* @return void
*/
public function move( $offset, $storageConfiguration, $oldConfiguration=NULL )
public function move( int $offset, int $storageConfiguration, int $oldConfiguration=NULL ) : void
{
$image = \IPS\Db::i()->select( '*', 'gallery_images', array(), 'image_id', array( $offset, 1 ) )->first();
$image = Db::i()->select( '*', 'gallery_images', array(), 'image_id', array( $offset, 1 ) )->first();
$update = array();
if( $image['image_small_file_name'] )
{
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'gallery_Images', $image['image_small_file_name'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'gallery_Images', $image['image_small_file_name'] )->move( $storageConfiguration );
$update['image_small_file_name'] = (string) $file;
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
@@ -70,10 +79,10 @@ class _Images
{
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'gallery_Images', $image['image_masked_file_name'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'gallery_Images', $image['image_masked_file_name'] )->move( $storageConfiguration );
$update['image_masked_file_name'] = (string) $file;
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
@@ -90,76 +99,48 @@ class _Images
{
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'gallery_Images', $image['image_original_file_name'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'gallery_Images', $image['image_original_file_name'] )->move( $storageConfiguration );
$update['image_original_file_name'] = (string) $file;
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
}
if ( \count( $update ) )
if ( count( $update ) )
{
foreach( $update as $k => $v )
{
if ( $update[ $k ] == $image[ $k ] )
if ( $v == $image[ $k ] )
{
unset( $update[ $k ] );
}
}
if ( \count( $update ) )
if ( count( $update ) )
{
\IPS\Db::i()->update( 'gallery_images', $update, array( 'image_id=?', $image['image_id'] ) );
Db::i()->update( 'gallery_images', $update, array( 'image_id=?', $image['image_id'] ) );
}
}
}
/**
* Fix all URLs
*
* @param int $offset This will be sent starting with 0, increasing to get all files stored by this extension
* @return void
*/
public function fixUrls( $offset )
{
$image = \IPS\Db::i()->select( '*', 'gallery_images', array(), 'image_id', array( $offset, 1 ) )->first();
$update = array();
foreach( array( 'image_small_file_name', 'image_masked_file_name', 'image_original_file_name' ) as $key )
{
if( $image[ $key ] )
{
if ( $new = \IPS\File::repairUrl( $image[ $key ] ) )
{
$update[ $key ] = $new;
}
}
}
if ( \count( $update ) )
{
\IPS\Db::i()->update( 'gallery_images', $update, array( 'image_id=?', $image['image_id'] ) );
}
}
/**
* Check if a file is valid
*
* @param string $file The file path to check
* @param File|string $file The file path to check
* @return bool
*/
public function isValidFile( $file )
public function isValidFile( File|string $file ): bool
{
try
{
$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();
$record = 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;
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return FALSE;
}
@@ -170,9 +151,9 @@ class _Images
*
* @return void
*/
public function delete()
public function delete() : void
{
foreach( \IPS\Db::i()->select( '*', 'gallery_images' ) as $image )
foreach( Db::i()->select( '*', 'gallery_images' ) as $image )
{
foreach( array( 'image_masked_file_name', 'image_original_file_name', 'image_small_file_name' ) as $size )
{
@@ -180,9 +161,9 @@ class _Images
{
try
{
\IPS\File::get( 'gallery_Images', $image[ $size ] )->delete();
File::get( 'gallery_Images', $image[ $size ] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}