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\nexus\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 defined;
use function in_array;
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;
}
/**
* Editor Extension: Advertisement Images
*/
class _Ads
class Ads extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) )->first();
return Db::i()->select( 'COUNT(*)', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) )->first();
}
/**
@@ -39,70 +48,47 @@ class _Ads
* @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
{
$record = \IPS\Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ), 'ad_id', array( $offset, 1 ) )->first();
$record = Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ), 'ad_id', array( $offset, 1 ) )->first();
$images = json_decode( $record['ad_images'], TRUE );
foreach ( $images as $key => $location )
{
try
{
$images[ $key ] = (string) \IPS\File::get( $oldConfiguration ?: 'nexus_Ads', $location )->move( $storageConfiguration );
$images[ $key ] = (string) File::get( $oldConfiguration ?: 'nexus_Ads', $location )->move( $storageConfiguration );
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
\IPS\Db::i()->update( 'core_advertisements', array( 'ad_images' => json_encode( $images ) ), array( 'ad_id=?', $record['ad_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 )
{
$record = \IPS\Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ), 'ad_id', array( $offset, 1 ) )->first();
$images = json_decode( $record['ad_images'], TRUE );
foreach ( $images as $key => $location )
{
if ( $new = \IPS\File::repairUrl( $location ) )
{
$images[ $key ] = $new;
}
}
\IPS\Db::i()->update( 'core_advertisements', array( 'ad_images' => json_encode( $images ) ), array( 'ad_id=?', $record['ad_id'] ) );
Db::i()->update( 'core_advertisements', array( 'ad_images' => json_encode( $images ) ), array( 'ad_id=?', $record['ad_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
{
foreach ( \IPS\Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) ) as $ad )
foreach ( Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) ) as $ad )
{
if ( \in_array( (string) $file, json_decode( $ad['ad_images'], TRUE ) ) )
if ( in_array( (string) $file, json_decode( $ad['ad_images'], TRUE ) ) )
{
return TRUE;
}
}
}
catch ( \UnderflowException $e ) { }
catch ( UnderflowException ) { }
return FALSE;
}
@@ -112,17 +98,17 @@ class _Ads
*
* @return void
*/
public function delete()
public function delete() : void
{
foreach( \IPS\Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) ) as $ad )
foreach( Db::i()->select( '*', 'core_advertisements', array( 'ad_member<>0 or ad_member IS NULL' ) ) as $ad )
{
foreach ( json_decode( $ad['ad_images'], TRUE ) as $key => $location )
{
try
{
\IPS\File::get( 'nexus_Products', $location )->delete();
File::get( 'nexus_Products', $location )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -12,35 +12,45 @@
namespace IPS\nexus\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 IPS\nexus\Customer\CustomField;
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: Customer Fields
*/
class _Customer
class Customer extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
$where = array();
foreach ( \IPS\nexus\Customer\CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
foreach ( CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
{
$where[] = "field_{$field->id}<>''";
}
if ( !\count( $where ) )
if ( !count( $where ) )
{
return 0;
}
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customers', implode( ' OR ', $where ) )->first();
return Db::i()->select( 'COUNT(*)', 'nexus_customers', implode( ' OR ', $where ) )->first();
}
/**
@@ -49,38 +59,38 @@ class _Customer
* @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
{
$ids = array();
$where = array();
foreach ( \IPS\nexus\Customer\CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
foreach ( CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
{
$ids[] = $field->id;
$where[] = "field_{$field->id}<>''";
}
if ( !\count( $where ) )
if ( !count( $where ) )
{
throw new \Underflowexception;
throw new Underflowexception;
}
$customer = \IPS\Db::i()->select( '*', 'nexus_customers', implode( ' OR ', $where ) )->first();
$customer = Db::i()->select( '*', 'nexus_customers', implode( ' OR ', $where ) )->first();
$update = array();
foreach ( $ids as $id )
{
try
{
$update[ 'field_' . $id ] = (string) \IPS\File::get( $oldConfiguration ?: 'nexus_Customer', $update[ 'field_' . $id ] )->move( $storageConfiguration );
$update[ 'field_' . $id ] = (string) File::get( $oldConfiguration ?: 'nexus_Customer', $update[ 'field_' . $id ] )->move( $storageConfiguration );
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
if ( \count( $update ) )
if ( count( $update ) )
{
foreach( $update as $k => $v )
{
@@ -90,48 +100,9 @@ class _Customer
}
}
if ( \count( $update ) )
if ( count( $update ) )
{
\IPS\Db::i()->update( 'nexus_customers', $update, array( 'member_id=?', $customer['member_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 )
{
$ids = array();
$where = array();
foreach ( \IPS\nexus\Customer\CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
{
$ids[] = $field->id;
$where[] = "field_{$field->id}<>''";
}
if ( !\count( $where ) )
{
throw new \Underflowexception;
}
$customer = \IPS\Db::i()->select( '*', 'nexus_customers', implode( ' OR ', $where ) )->first();
$update = array();
foreach ( $ids as $id )
{
if ( $new = \IPS\File::repairUrl( $customer[ 'field_' . $id ] ) )
{
$update[ 'field_' . $id ] = $new;
}
}
if ( \count( $update ) )
{
if ( \count( $update ) )
{
\IPS\Db::i()->update( 'nexus_customers', $update, array( 'member_id=?', $customer['member_id'] ) );
Db::i()->update( 'nexus_customers', $update, array( 'member_id=?', $customer['member_id'] ) );
}
}
}
@@ -139,25 +110,25 @@ class _Customer
/**
* 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
{
$_where = array();
foreach ( \IPS\nexus\Customer\CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
foreach ( CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
{
$_where[] = "field_{$field->id}=?";
}
if ( !\count( $_where ) )
if ( !count( $_where ) )
{
return FALSE;
}
$where = array_fill( 0, \count( $_where ), (string) $file );
$where = array_fill( 0, count( $_where ), (string) $file );
array_unshift( $where, implode( ' OR ', $_where ) );
return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customers', $where )->first();
return (bool) Db::i()->select( 'COUNT(*)', 'nexus_customers', $where )->first();
}
/**
@@ -165,29 +136,29 @@ class _Customer
*
* @return void
*/
public function delete()
public function delete() : void
{
$ids = array();
$where = array();
foreach ( \IPS\nexus\Customer\CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
foreach ( CustomField::roots( NULL, NULL, array( 'f_type=?', 'Upload' ) ) as $field )
{
$ids[] = $field->id;
$where[] = "field_{$field->id}<>''";
}
if ( !\count( $where ) )
if ( !count( $where ) )
{
return;
}
foreach ( \IPS\Db::i()->select( '*', 'nexus_customers', implode( ' OR ', $where ) ) as $customer )
foreach ( Db::i()->select( '*', 'nexus_customers', implode( ' OR ', $where ) ) as $customer )
{
foreach ( $ids as $id )
{
try
{
\IPS\File::get( 'nexus_Customer', $customer[ 'field_' . $id ] )->delete();
File::get( 'nexus_Customer', $customer[ 'field_' . $id ] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -12,25 +12,33 @@
namespace IPS\nexus\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 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: Gateways
*/
class _Gateways
class Gateways extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_paymethods', array( 'm_validationfile<>?', '' ) )->first();
return Db::i()->select( 'COUNT(*)', 'nexus_paymethods', array( 'm_validationfile<>?', '' ) )->first();
}
/**
@@ -39,23 +47,23 @@ class _Gateways
* @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
* @return void|int An offset integer to use on the next cycle, or nothing
* @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
{
$record = \IPS\Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile<>?', '' ), 'm_id', array( $offset, 1 ) )->first();
$record = Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile<>?', '' ), 'm_id', array( $offset, 1 ) )->first();
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'nexus_Gateways', $record['m_id'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'nexus_Gateways', $record['m_id'] )->move( $storageConfiguration );
if ( (string) $file != $record['m_validationfile'] )
{
\IPS\Db::i()->update( 'nexus_paymethods', array( 'm_validationfile' => (string) $file ), array( 'm_id=?', $record['m_id'] ) );
Db::i()->update( 'nexus_paymethods', array( 'm_validationfile' => (string) $file ), array( 'm_id=?', $record['m_id'] ) );
}
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
@@ -64,17 +72,17 @@ class _Gateways
/**
* 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
{
\IPS\Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile=?', (string) $file ) )->first();
Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile=?', $file ) )->first();
return TRUE;
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return FALSE;
}
@@ -85,15 +93,15 @@ class _Gateways
*
* @return void
*/
public function delete()
public function delete() : void
{
foreach( \IPS\Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile<>?', '' ) ) as $product )
foreach( Db::i()->select( '*', 'nexus_paymethods', array( 'm_validationfile<>?', '' ) ) as $product )
{
try
{
\IPS\File::get( 'nexus_Gateways', $product['m_validationfile'] )->delete();
File::get( 'nexus_Gateways', $product['m_validationfile'] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -12,25 +12,33 @@
namespace IPS\nexus\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 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: Package Groups
*/
class _PackageGroups
class PackageGroups extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_groups', array( 'pg_image<>?', '' ) )->first();
return Db::i()->select( 'COUNT(*)', 'nexus_package_groups', array( 'pg_image<>?', '' ) )->first();
}
/**
@@ -39,58 +47,42 @@ class _PackageGroups
* @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
{
$record = \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image<>?', '' ), 'pg_id', array( $offset, 1 ) )->first();
$record = Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image<>?', '' ), 'pg_id', array( $offset, 1 ) )->first();
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'nexus_PackageGroups', $record['pg_image'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'nexus_PackageGroups', $record['pg_image'] )->move( $storageConfiguration );
if ( (string) $file != $record['pg_image'] )
{
\IPS\Db::i()->update( 'nexus_package_groups', array( 'pg_image' => (string) $file ), array( 'pg_id=?', $record['pg_id'] ) );
Db::i()->update( 'nexus_package_groups', array( 'pg_image' => (string) $file ), array( 'pg_id=?', $record['pg_id'] ) );
}
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
/**
* 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 )
{
$record = \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image<>?', '' ), 'pg_id', array( $offset, 1 ) )->first();
if ( $new = \IPS\File::repairUrl( $record['pg_image'] ) )
{
\IPS\Db::i()->update( 'nexus_package_groups', array( 'pg_image' => $new ), array( 'pg_id=?', $record['pg_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
{
\IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image=?', (string) $file ) )->first();
Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image=?', (string) $file ) )->first();
return TRUE;
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return FALSE;
}
@@ -101,15 +93,15 @@ class _PackageGroups
*
* @return void
*/
public function delete()
public function delete() : void
{
foreach( \IPS\Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image<>?', '' ) ) as $product )
foreach( Db::i()->select( '*', 'nexus_package_groups', array( 'pg_image<>?', '' ) ) as $product )
{
try
{
\IPS\File::get( 'nexus_PackageGroups', $product['pg_image'] )->delete();
File::get( 'nexus_PackageGroups', $product['pg_image'] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -12,25 +12,33 @@
namespace IPS\nexus\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 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: Package Images
*/
class _Products
class Products extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_images' )->first();
return Db::i()->select( 'COUNT(*)', 'nexus_package_images' )->first();
}
/**
@@ -39,58 +47,42 @@ class _Products
* @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
{
$record = \IPS\Db::i()->select( '*', 'nexus_package_images', array(), 'image_id', array( $offset, 1 ) )->first();
$record = Db::i()->select( '*', 'nexus_package_images', array(), 'image_id', array( $offset, 1 ) )->first();
try
{
$file = \IPS\File::get( $oldConfiguration ?: 'nexus_Products', $record['image_location'] )->move( $storageConfiguration );
$file = File::get( $oldConfiguration ?: 'nexus_Products', $record['image_location'] )->move( $storageConfiguration );
if ( (string) $file != $record['image_location'] )
{
\IPS\Db::i()->update( 'nexus_package_images', array( 'image_location' => (string) $file ), array( 'image_id=?', $record['image_id'] ) );
Db::i()->update( 'nexus_package_images', array( 'image_location' => (string) $file ), array( 'image_id=?', $record['image_id'] ) );
}
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
/**
* 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 )
{
$record = \IPS\Db::i()->select( '*', 'nexus_package_images', array(), 'image_id', array( $offset, 1 ) )->first();
if ( $new = \IPS\File::repairUrl( $record['image_location'] ) )
{
\IPS\Db::i()->update( 'nexus_package_images', array( 'image_location' => $new ), array( 'image_id=?', $record['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
{
\IPS\Db::i()->select( '*', 'nexus_package_images', array( 'image_location=?', (string) $file ) )->first();
Db::i()->select( '*', 'nexus_package_images', array( 'image_location=?', (string) $file ) )->first();
return TRUE;
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return FALSE;
}
@@ -101,15 +93,15 @@ class _Products
*
* @return void
*/
public function delete()
public function delete() : void
{
foreach( \IPS\Db::i()->select( '*', 'nexus_package_images', "image_location IS NOT NULL" ) as $product )
foreach( Db::i()->select( '*', 'nexus_package_images', "image_location IS NOT NULL" ) as $product )
{
try
{
\IPS\File::get( 'nexus_Products', $product['image_location'] )->delete();
File::get( 'nexus_Products', $product['image_location'] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -12,25 +12,35 @@
namespace IPS\nexus\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 IPS\nexus\Package\CustomField;
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: Purchase Custom Fields
*/
class _PurchaseFields
class PurchaseFields extends FileStorageAbstract
{
/**
* Count stored files
*
* @return int
*/
public function count()
public function count(): int
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_fields', array( 'cf_type=?', 'upload' ) )->first();
return Db::i()->select( 'COUNT(*)', 'nexus_package_fields', array( 'cf_type=?', 'upload' ) )->first();
}
/**
@@ -39,13 +49,13 @@ class _PurchaseFields
* @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
{
$customFields = \IPS\nexus\Package\CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( \count( $customFields ) )
$customFields = CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( count( $customFields ) )
{
$packages = array();
foreach ( $customFields as $field )
@@ -56,10 +66,10 @@ class _PurchaseFields
}
}
$purchase = \IPS\Db::i()->select( '*', 'nexus_purchases', array(
$purchase = Db::i()->select( '*', 'nexus_purchases', array(
array( 'ps_app=?', 'nexus' ),
array( 'ps_type=?', 'package' ),
array( \IPS\Db::i()->in( 'ps_item_id', array_unique( $packages ) ) )
array( Db::i()->in( 'ps_item_id', array_unique( $packages ) ) )
), 'ps_id', array( $offset, 1 ) )->first();
$fieldValues = json_decode( $purchase['ps_custom_fields'], TRUE );
@@ -69,77 +79,33 @@ class _PurchaseFields
{
try
{
$fieldValues[ $k ] = \IPS\File::get( $oldConfiguration ?: 'nexus_PurchaseFields', $fieldValues[ $k ] )->move( $storageConfiguration );
$fieldValues[ $k ] = File::get( $oldConfiguration ?: 'nexus_PurchaseFields', $fieldValues[ $k ] )->move( $storageConfiguration );
}
catch( \Exception $e )
catch( Exception )
{
/* Any issues are logged */
}
}
}
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_custom_fields' => json_encode( $fieldValues ) ), array( 'ps_id=?', $purchase['ps_id'] ) );
Db::i()->update( 'nexus_purchases', array( 'ps_custom_fields' => json_encode( $fieldValues ) ), array( 'ps_id=?', $purchase['ps_id'] ) );
}
throw new \UnderflowException;
}
/**
* 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 )
{
$customFields = \IPS\nexus\Package\CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( \count( $customFields ) )
{
$packages = array();
foreach ( $customFields as $field )
{
if ( $field->packages )
{
$packages = array_merge( $packages, explode( ',', $field->packages ) );
}
}
$purchase = \IPS\Db::i()->select( '*', 'nexus_purchases', array(
array( 'ps_app=?', 'nexus' ),
array( 'ps_type=?', 'package' ),
array( \IPS\Db::i()->in( 'ps_item_id', array_unique( $packages ) ) )
), 'ps_id', array( $offset, 1 ) )->first();
$fieldValues = json_decode( $purchase['ps_custom_fields'], TRUE );
foreach ( $fieldValues as $k => $v )
{
if ( array_key_exists( $k, $customFields ) )
{
if ( $new = \IPS\File::repairUrl( $fieldValues[ $k ] ) )
{
$fieldValues[ $k ] = $new;
}
}
}
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_custom_fields' => json_encode( $fieldValues ) ), array( 'ps_id=?', $purchase['ps_id'] ) );
}
throw new \UnderflowException;
throw new UnderflowException;
}
/**
* 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
{
$customFields = \IPS\nexus\Package\CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( \count( $customFields ) )
$customFields = CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( count( $customFields ) )
{
foreach ( \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_custom_fields LIKE ?", "%" . str_replace( '\\', '\\\\\\', trim( json_encode( (string) $file ), '"' ) . "%" ) ) ) as $purchase )
foreach ( Db::i()->select( '*', 'nexus_purchases', array( "ps_custom_fields LIKE ?", "%" . str_replace( '\\', '\\\\\\', trim( json_encode( (string) $file ), '"' ) . "%" ) ) ) as $purchase )
{
$fieldValues = json_decode( $purchase['ps_custom_fields'], TRUE );
foreach ( $customFields as $field )
@@ -159,10 +125,10 @@ class _PurchaseFields
*
* @return void
*/
public function delete()
public function delete() : void
{
$customFields = \IPS\nexus\Package\CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( \count( $customFields ) )
$customFields = CustomField::roots( NULL, NULL, array( 'cf_type=?', 'upload' ) );
if ( count( $customFields ) )
{
$packages = array();
foreach ( $customFields as $field )
@@ -176,10 +142,10 @@ class _PurchaseFields
$where = array(
array( 'ps_app=?', 'nexus' ),
array( 'ps_type=?', 'package' ),
array( \IPS\Db::i()->in( 'ps_item_id', array_unique( $packages ) ) )
array( Db::i()->in( 'ps_item_id', array_unique( $packages ) ) )
);
foreach( \IPS\Db::i()->select( '*', 'nexus_purchases', $where ) as $purchase )
foreach( Db::i()->select( '*', 'nexus_purchases', $where ) as $purchase )
{
$fieldValues = json_decode( $purchase['ps_custom_fields'], TRUE );
foreach ( $fieldValues as $k => $v )
@@ -188,9 +154,9 @@ class _PurchaseFields
{
try
{
\IPS\File::get( 'nexus_PurchaseFields', $fieldValues[ $k ] )->delete();
File::get( 'nexus_PurchaseFields', $fieldValues[ $k ] )->delete();
}
catch( \Exception $e ){}
catch( Exception ){}
}
}
}
@@ -1,216 +0,0 @@
<?php
/**
* @brief File Storage Extension: Support Custom Fields
* @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 Nexus
* @since 17 Apr 2014
*/
namespace IPS\nexus\extensions\core\FileStorage;
/* 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;
}
/**
* File Storage Extension: Support Custom Fields
*/
class _Support
{
/**
* Count stored files
*
* @return int
*/
public function count()
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_fields', array( 'sf_type=?', 'upload' ) )->first();
}
/**
* Move stored files
*
* @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
* @return void
*/
public function move( $offset, $storageConfiguration, $oldConfiguration=NULL )
{
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( 'sf_type=?', 'upload' ) );
if ( \count( $customFields ) )
{
$where = array();
$departments = array();
foreach ( $customFields as $field )
{
if ( $field->departments and $field->departments !== '*' )
{
$departments = array_merge( $departments, explode( ',', $field->departments ) );
}
else
{
$where = NULL;
break;
}
}
if ( $where !== NULL )
{
$where = \IPS\Db::i()->in( 'r_department', array_unique( $departments ) );
}
$request = \IPS\Db::i()->select( '*', 'nexus_support_requests', $where, 'r_id', array( $offset, 1 ) )->first();
$fieldValues = json_decode( $request['r_cfields'], TRUE );
foreach ( $fieldValues as $k => $v )
{
if ( array_key_exists( $k, $customFields ) )
{
try
{
$fieldValues[ $k ] = \IPS\File::get( $oldConfiguration ?: 'nexus_Support', $fieldValues[ $k ] )->move( $storageConfiguration );
}
catch( \Exception $e )
{
/* Any issues are logged */
}
}
}
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_cfields' => json_encode( $fieldValues ) ), array( 'r_id=?', $request['r_id'] ) );
}
throw new \UnderflowException;
}
/**
* 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 )
{
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( 'sf_type=?', 'upload' ) );
if ( \count( $customFields ) )
{
$where = array();
$departments = array();
foreach ( $customFields as $field )
{
if ( $field->departments and $field->departments !== '*' )
{
$departments = array_merge( $departments, explode( ',', $field->departments ) );
}
else
{
$where = NULL;
break;
}
}
if ( $where !== NULL )
{
$where = \IPS\Db::i()->in( 'r_department', array_unique( $departments ) );
}
$request = \IPS\Db::i()->select( '*', 'nexus_support_requests', $where, 'r_id', array( $offset, 1 ) )->first();
$fieldValues = json_decode( $request['r_cfields'], TRUE );
foreach ( $fieldValues as $k => $v )
{
if ( array_key_exists( $k, $customFields ) )
{
if ( $new = \IPS\File::repairUrl( $fieldValues[ $k ] ) )
{
$fieldValues[ $k ] = $new;
}
}
}
\IPS\Db::i()->update( 'nexus_support_requests', array( 'r_cfields' => json_encode( $fieldValues ) ), array( 'r_id=?', $request['r_id'] ) );
}
throw new \UnderflowException;
}
/**
* Check if a file is valid
*
* @param string $file The file path to check
* @return bool
*/
public function isValidFile( $file )
{
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( 'sf_type=?', 'upload' ) );
if ( \count( $customFields ) )
{
foreach ( \IPS\Db::i()->select( '*', 'nexus_support_requests', array( "r_cfields LIKE ?", "%" . str_replace( '\\', '\\\\\\', trim( json_encode( (string) $file ), '"' ) . "%" ) ) ) as $request )
{
$fieldValues = json_decode( $request['r_cfields'], TRUE );
foreach ( $customFields as $field )
{
if ( $fieldValues[ $field->id ] == (string) $file )
{
return TRUE;
}
}
}
}
return FALSE;
}
/**
* Delete all stored files
*
* @return void
*/
public function delete()
{
$customFields = \IPS\nexus\Support\CustomField::roots( NULL, NULL, array( 'sf_type=?', 'upload' ) );
if ( \count( $customFields ) )
{
$where = array();
$departments = array();
foreach ( $customFields as $field )
{
if ( $field->departments and $field->departments !== '*' )
{
$departments = array_merge( $departments, explode( ',', $departments ) );
}
else
{
$where = NULL;
break;
}
}
if ( $where !== NULL )
{
$where = \IPS\Db::i()->in( 'r_department', array_unique( $departments ) );
}
foreach( \IPS\Db::i()->select( '*', 'nexus_support_requests', $where ) as $request )
{
$fieldValues = json_decode( $request['r_cfields'], TRUE );
foreach ( $fieldValues as $k => $v )
{
if ( array_key_exists( $k, $customFields ) )
{
try
{
\IPS\File::get( 'nexus_Support', $fieldValues[ $k ] )->delete();
}
catch( \Exception $e ){}
}
}
}
}
}
}