Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

@@ -46,7 +46,10 @@ use function get_class;
use function in_array;
use function intval;
use function is_array;
use function json_decode;
use function json_encode;
use function sprintf;
use function str_replace;
use const IPS\CIC;
use const IPS\ROOT_PATH;
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
@@ -562,7 +565,7 @@ class files extends Controller
} );
/* If we already have a storage configuration, we cannot create any new ones */
if( $totalConfigurations - $cicConfigurations == 0 )
if( $totalConfigurations - $cicConfigurations < 2 )
{
$table->rootButtons = array( 'add' => array(
'icon' => 'plus',
@@ -570,7 +573,6 @@ class files extends Controller
'link' => Url::internal( "app=core&module=overview&controller=files&do=configurationForm" )
) );
}
$settings = json_decode( Settings::i()->upload_settings, TRUE );
$table->rowButtons = function( $row ) use ( $settings )
{
@@ -587,6 +589,11 @@ class files extends Controller
}
$buttons = array(
'edit' => array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( "app=core&module=overview&controller=files&do=configurationForm&id={$row['id']}" )
),
'log' => array(
'icon' => 'search',
'title' => 'file_config_log_title',
@@ -611,7 +618,7 @@ class files extends Controller
return $buttons;
};
$activeTabContents = $table;
}
@@ -641,9 +648,9 @@ class files extends Controller
else
{
$message = '';
if( $totalConfigurations - $cicConfigurations > 1 )
if( $totalConfigurations - $cicConfigurations >= 2 )
{
$message = Theme::i()->getTemplate( 'global', 'core' )->message( Member::loggedIn()->language()->addToStack( 'multiple_filestorage_deprecated' ), 'warning' );
$message = Theme::i()->getTemplate( 'global', 'core' )->message( Member::loggedIn()->language()->addToStack( 'multiple_filestorage_error' ), 'info' );
}
Output::i()->output = $message . Theme::i()->getTemplate( 'global' )->tabs( $tabs, $activeTab, $activeTabContents, Url::internal( "app=core&module=overview&controller=files&do=settings" ) );
@@ -718,6 +725,7 @@ class files extends Controller
}
$form = new Form( 'form', 'move' );
$form->addMessage( 'filestorage_moveall_info', 'ipsMessage ipsMessage--warning' );
$form->addHeader( sprintf( Member::loggedIn()->language()->get( 'filestorage_moveall_from' ), $currentDisplayName ) );
if( count( $configurations ) )
{
@@ -881,10 +889,9 @@ class files extends Controller
}
/* Display */
$message = Theme::i()->getTemplate( 'global', 'core' )->message( Member::loggedIn()->language()->addToStack( 'filestorage_moveall_info' ), 'warning' );
Output::i()->title = Member::loggedIn()->language()->addToStack('storage_settings');
Output::i()->breadcrumb[] = array( Url::internal( "&app=core&module=overview&controller=files&do=settings&tab=configurations" ), 'filestorage_settings' );
Output::i()->output = $message . $form;
Output::i()->output = $form;
}
/**
@@ -895,15 +902,45 @@ class files extends Controller
protected function configurationForm() : void
{
/* Are we allowed to create a new location? */
$totalConfigurations = (int) Db::i()->select( 'count(*)', 'core_file_storage' )->first();
$cicConfigurations = 0;
if( CIC )
if ( ! isset( Request::i()->id ) )
{
$cicConfigurations = (int) Db::i()->select( 'count(*)', 'core_file_storage', array( "method=?", 'Cloud' ) )->first();
$totalConfigurations = (int) Db::i()->select( 'count(*)', 'core_file_storage' )->first();
$cicConfigurations = 0;
if( CIC )
{
$cicConfigurations = (int) Db::i()->select( 'count(*)', 'core_file_storage', array( "method=?", 'Cloud' ) )->first();
}
if( $totalConfigurations - $cicConfigurations > 2 )
{
Output::i()->error( 'multiple_filestorage_error', '2C158/3', 403 );
}
}
if( $totalConfigurations - $cicConfigurations > 0 )
else
{
Output::i()->error( 'multiple_filestorage_error', '2C158/3', 403 );
/* Before we edit any details, check to make sure we're not processing files in this location */
foreach ( Db::i()->select( 'data', 'core_queue', array( '`key`=?', 'MoveFiles' ) ) as $data )
{
$data = json_decode( $data, true );
if ( $data['oldConfiguration'] == Request::i()->id )
{
Output::i()->error( 'file_storage_move_out', '1C158/3', 403, '' );
}
elseif ( $data['newConfiguration'] == Request::i()->id )
{
Output::i()->error( 'file_storage_move_in', '1C158/4', 403, '' );
}
}
}
try
{
$current = Db::i()->select( '*', 'core_file_storage', ['id=?', intval( Request::i()->id )] )->first();
$currentHandlerSettings = json_decode( $current['configuration'], true );
}
catch ( \UnderflowException $e )
{
$current = NULL;
$currentHandlerSettings = array();
}
/* Get handlers */
@@ -912,19 +949,19 @@ class files extends Controller
$toggles = array();
foreach ( File::storageHandlers( NULL ) as $key => $class )
{
if ( CIC AND $key == 'Cloud' AND !\IPS\Member::loggedIn()->members_bitoptions['is_support_account'] )
if ( CIC AND $key == 'Cloud' AND ! Member::loggedIn()->members_bitoptions['is_support_account'] )
{
continue;
}
$handlers[ $key ] = 'filehandler__' . $key;
foreach ( $class::settings() as $k => $v )
foreach ( $class::settings( $currentHandlerSettings ) as $k => $v )
{
if ( is_array( $v ) )
{
$settingClass = '\IPS\Helpers\Form\\' . $v['type'];
$default = NULL;
$default = isset( $currentHandlerSettings[ $k ] ) ? str_replace( '{root}', ROOT_PATH, $currentHandlerSettings[ $k ] ) : NULL;
if ( isset( $v['default'] ) and !$default )
{
$default = str_replace( '{root}', ROOT_PATH, $v['default'] );
@@ -940,10 +977,18 @@ class files extends Controller
$toggles[ $key ][ $k ] = "{$key}_{$k}";
}
}
/* Build form */
$form = new Form;
$form->add( new Radio( 'filestorage_method', ( CIC ? 'Cloud' : 'FileSystem' ), TRUE, array( 'options' => $handlers, 'toggles' => $toggles ) ) );
if ( $current )
{
$form->addMessage( Member::loggedIn()->language()->addToStack( "filestorage_config_edit_warning", null, [
'sprintf' => Url::internal( 'app=core&module=overview&controller=files&do=configurationMove&id=' . $current['id'] ),
] ), 'ipsMessage ipsMessage--warning' );
}
$form->add( new Radio( 'filestorage_method', $current ? $current['method'] : ( CIC ? 'Amazon' : 'FileSystem' ), TRUE, array( 'disabled' => ( isset( Request::i()->id ) ), 'options' => $handlers, 'toggles' => $toggles ) ) );
foreach ( $handlerSettings as $handlerKey => $settings )
{
foreach ( $settings as $setting )
@@ -980,7 +1025,7 @@ class files extends Controller
$existingConfiguration = json_decode( $existing['configuration'], true );
foreach( $existingConfiguration as $k => $v )
{
$v = str_replace( ROOT_PATH, '{root}', $v );
$v = str_replace( ROOT_PATH, '{root}', (string) $v );
if ( array_key_exists( $k, $currentHandlerSettings ) )
{
@@ -992,16 +1037,25 @@ class files extends Controller
}
}
if ( $existingWithSameConfig )
if ( $existingWithSameConfig and ! Request::i()->id )
{
/* Let's not allow this to be saved as someone can start a move to the same location, which will end up deleting the files */
throw new DomainException( Member::loggedIn()->language()->addToStack( 'file_config_is_the_same_as_existing', FALSE ) );
}
$insertId = Db::i()->insert( 'core_file_storage', array(
'method' => $values['filestorage_method'],
'configuration' => json_encode( $currentHandlerSettings ),
) );
if ( Request::i()->id )
{
Db::i()->update( 'core_file_storage', [
'configuration' => json_encode( $currentHandlerSettings ),
], array( 'id=?', Request::i()->id ) );
}
else
{
Db::i()->insert( 'core_file_storage', [
'method' => $values['filestorage_method'],
'configuration' => json_encode( $currentHandlerSettings ),
] );
}
unset( Store::i()->storageConfigurations );
/* Log the storage addition */
@@ -1016,9 +1070,6 @@ class files extends Controller
}
}
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_files.js', 'core' ) );
Output::i()->globalControllers[] = 'core.admin.files.form';
/* Display */
Output::i()->title = Member::loggedIn()->language()->addToStack('storage_settings');
Output::i()->output = $form;
@@ -1058,47 +1109,6 @@ class files extends Controller
Output::i()->redirect( Url::internal( "app=core&module=overview&controller=files&do=settings&tab=configurations" ) );
}
/**
* Determine if a move is needed (ajax method)
*
* @return void
*/
protected function checkMoveNeeded() : void
{
try
{
$current = Db::i()->select( '*', 'core_file_storage', array( 'id=?', intval( Request::i()->id ) ) )->first();
}
catch( UnderflowException $e )
{
Output::i()->json( array( 'needsMoving' => FALSE ) );
}
$currentConf = json_decode( $current['configuration'], TRUE );
$needsMoving = FALSE;
if ( in_array( intval( Request::i()->id ), json_decode( Settings::i()->upload_settings, TRUE ) ) )
{
foreach ( $currentConf as $k => $v )
{
$checkKey = 'filehandler__' . $current['method'] . '_' . $k;
if ( isset( Request::i()->$checkKey ) )
{
$currentHandlerSettings[ $k ] = str_replace( ROOT_PATH, '{root}', Request::i()->$checkKey );
}
}
$handlers = File::storageHandlers( $current );
$classname = $handlers[ $current['method'] ];
/* Do we really need to create and move? */
$needsMoving = $classname::moveCheck( $currentHandlerSettings, $currentConf );
}
Output::i()->json( array( 'needsMoving' => (boolean) $needsMoving ) );
}
/**
* View logs for this configuration
*