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

@@ -752,7 +752,6 @@ class themes extends Controller
Db::i()->insert( 'core_sys_lang_words', array(
'lang_id' => $langId,
'word_app' => NULL,
'word_plugin' => NULL,
'word_theme' => Request::i()->id,
'word_key' => $xml->getAttribute('key'),
'word_default' => $default,
@@ -781,13 +780,30 @@ class themes extends Controller
{
if ( $xml->name == 'template' )
{
Db::i()->delete( 'core_theme_templates_custom', [ 'template_set_id=? and template_name=? and template_hookpoint=? and template_hookpoint_type=?', Request::i()->id, $xml->getAttribute('name'), $xml->getAttribute('hookpoint'), $xml->getAttribute('hookpoint_type') ] );
$hookPoint = $xml->getAttribute( 'hookpoint' );
$key = $xml->getAttribute( 'key' );
$where = [
[ 'template_set_id=?', Request::i()->id ],
[ 'template_name=?', $xml->getAttribute('name') ],
[ 'template_hookpoint_type=?', $xml->getAttribute( 'hookpoint_type' ) ]
];
if( empty( $hookPoint ) )
{
$where[] = [ 'template_hookpoint is null'];
}
else
{
$where[] = [ 'template_hookpoint=?', $hookPoint ];
}
Db::i()->delete( 'core_theme_templates_custom', $where );
Db::i()->insert( 'core_theme_templates_custom', [
'template_set_id' => Request::i()->id,
'template_name' => $xml->getAttribute('name'),
'template_hookpoint' => $xml->getAttribute('hookpoint'),
'template_hookpoint' => ( $hookPoint ?: null ),
'template_hookpoint_type' => $xml->getAttribute('hookpoint_type'),
'template_key' => $xml->getAttribute('key'),
'template_key' => ( $key ?: null ),
'template_version' => $xml->getAttribute('version'),
'template_content' => $xml->readString(),
'template_updated' => time(),
@@ -815,9 +831,10 @@ class themes extends Controller
File::get( 'core_Theme', $set->logo[ $type ]['url'] )->delete();
}
File::$safeFileExtensions[] = 'svg';
$url = (string) File::create( 'core_Theme', $name, base64_decode( $xml->readString() ) );
$set->saveSet( array( 'logo' => array( $type => array( 'url' => $url, 'height' => $xml->getAttribute('height') ?? 100 ) ) ) );
$set->saveSet( array( 'logo' => array( $type => array( 'filename' => $name, 'setting_height' => $xml->getAttribute('height') ?? 100 ) ) ) );
}
break;
}
@@ -829,21 +846,22 @@ class themes extends Controller
},
function()
{
$set = Theme::load( Request::i()->id );
/* Do we need to clean up orphaned CSS files? */
if ( $_SESSION['theme_import']['isNewSet'] === false and isset( $_SESSION['theme_import']['css'] ) )
{
Db::i()->delete( 'core_theme_css', array( Db::i()->in( 'css_id', $_SESSION['theme_import']['css'], true ) ) );
Db::i()->delete( 'core_theme_css', array(
array( Db::i()->in( 'css_id', $_SESSION['theme_import']['css'], true ) ),
array( 'css_set_id=?', $set->id )
) );
}
$set = Theme::load( Request::i()->id );
Theme::deleteCompiledResources( null, null, null, null, $set->id );
Theme::deleteCompiledTemplate( null, null, null, $set->id );
Theme::deleteCompiledCss( null, null, null, null, $set->id );
Store::i()->delete( 'core_theme_import_' . md5_file( Request::i()->file ) );
unset( Store::i()->themes );
unset( Store::i()->custom_templates_rows );
@unlink( Request::i()->file );
@@ -853,6 +871,9 @@ class themes extends Controller
$app->installThemeEditorSettings();
}
/* Clear the entire data store, there are too many to list here */
Store::i()->clearAll();
Output::i()->redirect( Url::internal( 'app=core&module=customization&controller=themes' ) );
}
);
@@ -998,15 +1019,13 @@ class themes extends Controller
$xml->endElement();
/* Copy logos */
if( $themeSet->logo_data )
if( $logos = $themeSet->logo )
{
$logos = json_decode( $themeSet->logo_data, TRUE );
if( is_array( $logos ) )
{
foreach ( $logos as $file => $data )
{
if( isset( $data['url'] ) )
if( isset( $data['filename'] ) )
{
/* Start the XML */
$xml->startElement('logo');
@@ -1015,10 +1034,10 @@ class themes extends Controller
$xml->text( $file );
$xml->endAttribute();
if( isset( $data['height'] ) )
if( isset( $data['setting_height'] ) )
{
$xml->startAttribute('height');
$xml->text( $data['height'] );
$xml->text( $data['setting_height'] );
$xml->endAttribute();
}
@@ -1026,7 +1045,7 @@ class themes extends Controller
$original = File::get( 'core_Theme', $data['url'] );
$xml->startAttribute('name');
$xml->text( $original->originalFilename );
$xml->text( $data['filename'] );
$xml->endAttribute();
$xml->text( base64_encode( $original->contents() ) );
@@ -1063,7 +1082,7 @@ class themes extends Controller
}
$xml->startElement( 'name' );
$xml->text( $cat['cat_name'] );
$xml->text( (string) $cat['cat_name'] );
$xml->endElement();
$xml->startElement( 'icon' );
@@ -1107,11 +1126,11 @@ class themes extends Controller
}
$xml->startElement( 'name' );
$xml->text( $setting['setting_name'] );
$xml->text( (string) $setting['setting_name'] );
$xml->endElement();
$xml->startElement( 'desc' );
$xml->writeCdata( $setting['setting_desc'] );
$xml->writeCdata( (string) $setting['setting_desc'] );
$xml->endElement();
$xml->startElement( 'data' );
@@ -1498,4 +1517,143 @@ class themes extends Controller
Output::i()->redirect( Url::internal( 'app=core&module=customization&controller=themes' ), 'theme_set_revert_done' );
}
/**
* Copy
*
* @return void
*/
protected function copy() : void
{
Session::i()->csrfCheck();
try
{
$theme = Theme::load( Request::i()->id );
}
catch( OutOfRangeException )
{
Output::i()->error( 'node_error', '2S101/Z', 404 );
}
Output::i()->output = new MultipleRedirect(
$this->url->setQueryString( [ 'do' => 'copy', 'id' => $theme->id, 'csrfKey' => Session::i()->csrfKey ] ),
function( $data ) use ( $theme )
{
if( !is_array( $data ) or !$data['newId'] )
{
$newTheme = clone $theme;
$data['newId'] = $newTheme->id;
$data['step'] = 'templates';
$data['resources'] = (int) Db::i()->select( 'count(*)', 'core_theme_resources', array( 'resource_set_id=?', $theme->id ) )->first();
$data['offset'] = 0;
}
if( !isset( $newTheme ) )
{
$newTheme = Theme::load( $data['newId'] );
}
switch( $data['step'] )
{
case 'templates':
/* Dynamically produce insert list, so we don't have to update each time the table changes */
$templateTable = Db::i()->getTableDefinition( 'core_theme_templates', TRUE );
$templateFields = array_keys( (array)$templateTable['columns'] );
array_walk( $templateFields, function( &$name, $i, $setId )
{
switch( $name )
{
case 'template_id':
$name = 'null';
break;
case 'template_set_id':
$name = $setId;
break;
}
}, $newTheme->id );
/* Copy across any template bits */
Db::i()->insert( 'core_theme_templates', Db::i()->select( implode(',', $templateFields ), 'core_theme_templates', array( 'template_set_id=?', $theme->id ) ) );
$data['step'] = 'css';
break;
case 'css':
$cssTable = Db::i()->getTableDefinition( 'core_theme_css', TRUE );
$cssFields = array_keys( (array)$cssTable['columns'] );
array_walk( $cssFields, function( &$name, $i, $setId )
{
switch( $name )
{
case 'css_id':
$name = 'null';
break;
case 'css_set_id':
$name = $setId;
break;
}
}, $newTheme->id );
/* Copy across any CSS bits */
Db::i()->insert( 'core_theme_css', Db::i()->select( implode(',', $cssFields ), 'core_theme_css', array( 'css_set_id=?', $theme->id ) ) );
$data['step'] = 'resources';
break;
case 'resources':
/* Resources are the sloweest on cloud, so we're going to loop through */
$offset = $data['offset'] ?? 0;
if( $data['offset'] == 0 )
{
Db::i()->delete( 'core_theme_resources', array( 'resource_set_id=?', $newTheme->id ) );
$newTheme->resource_map = [];
}
$limit = 15;
$newTheme->copyResourcesFromSet( $theme->id, $offset, $limit );
$data['offset'] = $offset + $limit;
if( $data['offset'] >= $data['resources'] )
{
$data['step'] = 'lang';
}
break;
case 'lang':
/* Copy any language keys */
foreach(Db::i()->select( '*', 'core_sys_lang_words', array( 'word_theme=?', $theme->id ) ) AS $word )
{
$word['word_theme'] = $newTheme->id;
unset( $word['word_id'] );
Db::i()->insert( 'core_sys_lang_words', $word );
}
$data['step'] = 'logo';
break;
case 'logo':
$newTheme->logo_data = NULL;
$newTheme->copyLogosFromSet( $theme->id );
$data['step'] = 'editor';
break;
case 'editor':
/* Copy custom settings and categories */
$newTheme->copyEditorSettings( $theme->id );
$data['step'] = 'customtemplates';
break;
case 'customtemplates':
/* Copy custom templates and hooks */
$newTheme->copyCustomTemplates( $theme->id );
return null;
}
return array( $data, Member::loggedIn()->language()->addToStack('copying__theme_' . $data['step']) );
},
function() use ( $theme )
{
Session::i()->log( 'acplog__node_copied_c', array( $theme->title => TRUE, $theme->titleForLog() => FALSE ) );
Output::i()->redirect( $this->url, 'saved' );
});
}
}