Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -11,7 +11,7 @@
namespace IPS\core\modules\admin\customization;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -22,6 +22,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _themes extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -31,6 +36,11 @@ class _themes extends \IPS\Node\Controller
* @brief If true, will prevent any item from being moved out of its current parent, only allowing them to be reordered within their current parent
*/
protected $lockParents = TRUE;
/**
* Title can contain HTML?
*/
public $_titleHtml = TRUE;
/**
* Description can contain HTML?
@@ -72,18 +82,30 @@ class _themes extends \IPS\Node\Controller
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('theme_designers_mode_title') )
);
}
\IPS\Output::i()->sidebar['actions']['add'] = array(
'primary' => true,
'icon' => 'plus',
'title' => 'theme_set_add_button',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=add' ),
'title' => 'add',
'link' => \IPS\Http\Url::internal( ( \IPS\DEMO_MODE ) ? 'app=core&module=customization&controller=themes&do=form&type=vse' : 'app=core&module=customization&controller=themes&do=add' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('theme_set_add_button') )
);
parent::manage();
}
/**
* Allow overloading to change how the title is displayed in the tree
*
* @param $node \IPS\Node Node
* @return string
*/
protected static function nodeTitle( $node )
{
return \IPS\Theme::i()->getTemplate('customization')->themeRowTitle( $node );
}
/**
* Get Root Buttons
*
@@ -101,6 +123,8 @@ class _themes extends \IPS\Node\Controller
*/
public function revertThemeSetting()
{
\IPS\Session::i()->csrfCheck();
$theme = \IPS\Theme::load( \IPS\Request::i()->id );
$setting = NULL;
$value = NULL;
@@ -191,7 +215,7 @@ class _themes extends \IPS\Node\Controller
/* Switching on */
if ( isset( $values['theme_designers_mode'] ) and $values['theme_designers_mode'] )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeon' ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeon' )->csrf() );
}
else
{
@@ -200,7 +224,7 @@ class _themes extends \IPS\Node\Controller
\IPS\Data\Store::i()->designers_mode_theme_sync = ( $values['theme_designers_themes'] == 0 ) ? NULL : array_keys( $values['theme_designers_themes'] );
\IPS\Data\Store::i()->designers_mode_theme_wipe = $values['theme_designers_mode_wipe'];
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeoff' ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeoff' )->csrf() );
}
else
{
@@ -223,25 +247,32 @@ class _themes extends \IPS\Node\Controller
*/
public function designersmodeoff()
{
\IPS\Session::i()->csrfCheck();
if ( \IPS\NO_WRITES or \IPS\CIC )
{
\IPS\Output::i()->error( 'no_writes', '1C163/B', 403, '' );
}
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeoff' ),
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeoff' )->csrf(),
function( $data )
{
/* Is this the first cycle? */
if ( ! is_array( $data ) )
if ( ! \is_array( $data ) )
{
$toImport = array();
foreach( \IPS\Theme::themes() as $id => $theme )
{
if( !$theme->id )
{
continue;
}
if ( isset( \IPS\Data\Store::i()->designers_mode_theme_sync ) )
{
if ( \IPS\Data\Store::i()->designers_mode_theme_sync !== NULL and ! in_array( $id, \IPS\Data\Store::i()->designers_mode_theme_sync ) )
if ( \IPS\Data\Store::i()->designers_mode_theme_sync !== NULL and ! \in_array( $id, \IPS\Data\Store::i()->designers_mode_theme_sync ) )
{
continue;
}
@@ -257,11 +288,11 @@ class _themes extends \IPS\Node\Controller
$extensions = array();
foreach ( \IPS\Application::allExtensions( 'core', 'DesignersMode', NULL, NULL, NULL, TRUE ) as $class )
{
$extensions[] = get_class( $class );
$extensions[] = \get_class( $class );
}
/* Start importing */
$data = array( 'toImport' => count( $toImport ) ? true : false, 'extensions' => $extensions, 'extra' => array() );
$data = array( 'toImport' => \count( $toImport ) ? true : false, 'extensions' => $extensions, 'extra' => array() );
/* Could be too large for a simple URL */
$_SESSION['theme_dev_import'] = $toImport;
@@ -269,7 +300,7 @@ class _themes extends \IPS\Node\Controller
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('processing') );
}
if ( count( $data['extensions'] ) )
if ( \count( $data['extensions'] ) )
{
/* Do this first */
$array = $data['extensions'];
@@ -298,11 +329,11 @@ class _themes extends \IPS\Node\Controller
reset( $toImport );
$themeId = key( $toImport );
$theme = \IPS\Theme::load( $themeId );
$theme = \IPS\Theme\Advanced\Theme::load( $themeId );
$app = key( $toImport[ $themeId ] );
$type = array_shift( $toImport[ $themeId ][ $app ] );
if( !count( $toImport[ $themeId ][ $app ] ) )
if( !\count( $toImport[ $themeId ][ $app ] ) )
{
unset( $toImport[ $themeId ][ $app ] );
}
@@ -353,22 +384,22 @@ class _themes extends \IPS\Node\Controller
}
break;
case 'html':
\IPS\Theme::i()->importDevHtml( $app, $themeId );
$theme->importDevHtml( $app, $themeId );
break;
case 'css':
\IPS\Theme::i()->importDevCss( $app, $themeId );
$theme->importDevCss( $app, $themeId );
break;
case 'resources':
\IPS\Theme::i()->importDevResources( $app, $themeId );
$theme->importDevResources( $app, $themeId );
break;
}
if ( ! count( $toImport[ $themeId ] ) )
if ( ! \count( $toImport[ $themeId ] ) )
{
unset( $toImport[ $themeId ] );
}
if ( ! count( $toImport ) )
if ( ! \count( $toImport ) )
{
$data['toImport'] = false;
}
@@ -394,7 +425,7 @@ class _themes extends \IPS\Node\Controller
{
\IPS\Theme\Advanced\Theme::removeThemeDirectory( \IPS\ROOT_PATH . "/themes" );
}
else if ( is_array( \IPS\Data\Store::i()->designers_mode_theme_sync ) )
else if ( \is_array( \IPS\Data\Store::i()->designers_mode_theme_sync ) )
{
foreach( \IPS\Data\Store::i()->designers_mode_theme_sync as $id )
{
@@ -426,6 +457,8 @@ class _themes extends \IPS\Node\Controller
*/
public function designersmodeon()
{
\IPS\Session::i()->csrfCheck();
if ( \IPS\NO_WRITES or \IPS\CIC )
{
\IPS\Output::i()->error( 'no_writes', '1C163/A', 403, '' );
@@ -463,11 +496,11 @@ class _themes extends \IPS\Node\Controller
}
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeon' ),
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmodeon' )->csrf(),
function( $data )
{
/* Is this the first cycle? */
if ( !is_array( $data ) )
if ( !\is_array( $data ) )
{
if ( ! is_dir( \IPS\ROOT_PATH . "/themes" ) )
{
@@ -493,6 +526,11 @@ class _themes extends \IPS\Node\Controller
{
foreach ( \IPS\Theme\Advanced\Theme::getToBuild() as $id )
{
if( !$id )
{
continue;
}
$toBuild[$id] = array( 'html' => 'html', 'css' => 'css', 'resources' => 'resources' );
}
}
@@ -503,21 +541,21 @@ class _themes extends \IPS\Node\Controller
{
if ( $class->toBuild() === TRUE )
{
$extensions[] = get_class( $class );
$extensions[] = \get_class( $class );
}
}
/* Start importing */
$data = array( 'buildingDesignersFiles' => true, 'toBuild' => $toBuild, 'extensions' => $extensions, 'totalItems' => count( array_keys( $toBuild ) ) + count( array_keys( $extensions ) ), 'totalDone' => 0, 'extra' => array() );
$data = array( 'buildingDesignersFiles' => true, 'toBuild' => $toBuild, 'extensions' => $extensions, 'totalItems' => \count( array_keys( $toBuild ) ) + \count( array_keys( $extensions ) ), 'totalDone' => 0, 'extra' => array() );
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('theme_dm_building') );
}
/* Grab something to build */
$msg = NULL;
if ( count( $data['extensions'] ) or count( $data['toBuild'] ) )
if ( \count( $data['extensions'] ) or \count( $data['toBuild'] ) )
{
if ( count( $data['extensions'] ) )
if ( \count( $data['extensions'] ) )
{
/* Do this first */
$array = $data['extensions'];
@@ -541,14 +579,14 @@ class _themes extends \IPS\Node\Controller
$msg = \IPS\Member::loggedIn()->language()->addToStack( 'theme_dm_building_extensions' );
}
else if ( count( $data['toBuild'] ) )
else if ( \count( $data['toBuild'] ) )
{
reset( $data['toBuild'] );
$themeId = key( $data['toBuild'] );
$type = array_shift( $data['toBuild'][$themeId] );
if( !count( $data['toBuild'][ $themeId ] ) )
if( !\count( $data['toBuild'][ $themeId ] ) )
{
unset( $data['toBuild'][ $themeId ] );
}
@@ -577,7 +615,8 @@ class _themes extends \IPS\Node\Controller
$data['totalDone']++;
}
return array( $data, $msg, ( $data['totalDone'] / $data['totalItems'] * 100 ) );
$percent = ( $data['totalDone'] / $data['totalItems'] * 100 );
return array( $data, $msg, ( $percent <= 100 ? $percent : 100 ) );
}
else
{
@@ -603,7 +642,7 @@ class _themes extends \IPS\Node\Controller
*/
public function resources()
{
$setId = intval( \IPS\Request::i()->set_id );
$setId = \intval( \IPS\Request::i()->set_id );
try
{
@@ -625,7 +664,7 @@ class _themes extends \IPS\Node\Controller
$table->parsers = array(
'resource_data' => function( $val, $row ) use ($set)
{
if ( in_array( mb_substr( $row['resource_name'], mb_strrpos( $row['resource_name'], '.' ) + 1 ), \IPS\Image::$imageExtensions ) )
if ( \in_array( mb_substr( $row['resource_name'], mb_strrpos( $row['resource_name'], '.' ) + 1 ), array_merge( \IPS\Image::$imageExtensions, array( 'svg' ) ) ) )
{
$row['resource_filename'] = $set->resource( ltrim( $row['resource_path'], '/' ) . $row['resource_name'], $row['resource_app'], $row['resource_location'] );
}
@@ -634,7 +673,8 @@ class _themes extends \IPS\Node\Controller
},
'resource_name' => function( $val, $row ) use ($set)
{
if ( in_array( mb_substr( $row['resource_name'], mb_strrpos( $row['resource_name'], '.' ) + 1 ), \IPS\Image::$imageExtensions ) )
if ( \in_array( mb_substr( $row['resource_name'], mb_strrpos( $row['resource_name'], '.' ) + 1 ), array_merge( \IPS\Image::$imageExtensions, array( 'svg' ) ) ) )
{
$row['resource_filename'] = $set->resource( ltrim( $row['resource_path'], '/' ) . $row['resource_name'], $row['resource_app'], $row['resource_location'] );
}
@@ -701,7 +741,7 @@ class _themes extends \IPS\Node\Controller
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
try
{
@@ -751,7 +791,7 @@ class _themes extends \IPS\Node\Controller
*/
public function resourceForm()
{
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
try
{
@@ -906,6 +946,8 @@ class _themes extends \IPS\Node\Controller
*/
public function launchvse()
{
\IPS\Session::i()->csrfCheck();
$theme = \IPS\Theme::load( \IPS\Request::i()->id );
if ( $theme->by_skin_gen AND \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'customization', 'theme_easy_editor' ) )
@@ -929,6 +971,13 @@ class _themes extends \IPS\Node\Controller
*/
public function convertToCustom()
{
if ( \IPS\DEMO_MODE )
{
\IPS\Output::i()->error( 'demo_mode_function_blocked', '1C163/J', 403, '' );
}
\IPS\Session::i()->csrfCheck();
$theme = \IPS\Theme::load( \IPS\Request::i()->id );
$theme->by_skin_gen = 0;
$theme->save();
@@ -943,6 +992,53 @@ class _themes extends \IPS\Node\Controller
}
}
/**
* Manual Theme Upload
*
* @return void
*/
public function upload()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_download_upload' );
$form = new \IPS\Helpers\Form( 'form', 'next' );
$form->addMessage('themes_manual_install_warning');
$form->add(
new \IPS\Helpers\Form\Upload(
'core_theme_set_new_import', NULL, FALSE, array(
'allowedFileTypes' => array( 'xml' ),
'temporary' => TRUE
), NULL, NULL, NULL, 'core_theme_set_new_import'
)
);
if ( $values = $form->values() )
{
/* Move it to a temporary location */
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
move_uploaded_file( $values['core_theme_set_new_import'], $tempFile );
$max = \IPS\Db::i()->select( 'MAX(set_order)', 'core_themes' )->first();
/* Create a default theme */
$theme = new \IPS\Theme;
$theme->parent_array = '[]';
$theme->child_array = '[]';
$theme->parent_id = 0;
$theme->by_skin_gen = 0;
$theme->editor_skin = 'ips';
$theme->order = $max + 1;
$theme->save();
$theme->copyResourcesFromSet();
/* Initate a redirector */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'id' => $theme->id ) )->csrf() );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'theme_set_add_button', $form, FALSE );
}
/**
* Add a theme dialog
*
@@ -950,63 +1046,30 @@ class _themes extends \IPS\Node\Controller
*/
public function add()
{
$form = new \IPS\Helpers\Form( 'form', 'next' );
$form->addTab( 'core_theme_add_new' );
$form->add( new \IPS\Helpers\Form\Radio(
'core_theme_add_theme_type',
NULL,
FALSE,
array( 'options'=> array( 'vse' => 'core_theme_add_theme_vse', 'custom' => 'core_theme_add_theme_custom' ),
'descriptions' => array( 'vse' => 'core_theme_add_theme_vse_desc', 'custom' => 'core_theme_add_theme_custom_desc' ) ),
NULL,
NULL,
NULL,
'core_theme_add_theme_type'
) );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'customization', 'theme_download_upload' ) )
if ( \IPS\DEMO_MODE )
{
$form->addTab( 'core_theme_add_upload' );
$form->add(
new \IPS\Helpers\Form\Upload(
'core_theme_set_new_import', NULL, FALSE, array(
'allowedFileTypes' => array( 'xml' ),
'temporary' => TRUE
), NULL, NULL, NULL, 'core_theme_set_new_import'
)
);
/* We only allow easy mode themes */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=form&type=vse' ) );
}
$form = new \IPS\Helpers\Form( 'form', 'next' );
$form->addMessage('themes_create_blurb');
$form->add( new \IPS\Helpers\Form\Radio(
'core_theme_add_theme_type',
NULL,
FALSE,
array( 'options'=> array( 'vse' => 'core_theme_add_theme_vse', 'custom' => 'core_theme_add_theme_custom' ),
'descriptions' => array( 'vse' => 'core_theme_add_theme_vse_desc', 'custom' => 'core_theme_add_theme_custom_desc' ) ),
NULL,
NULL,
NULL,
'core_theme_add_theme_type'
) );
if ( $values = $form->values() )
{
if ( isset( $values['core_theme_set_new_import'] ) and $values['core_theme_set_new_import'] )
{
/* Move it to a temporary location */
$tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'IPS' );
move_uploaded_file( $values['core_theme_set_new_import'], $tempFile );
$max = \IPS\Db::i()->select( 'MAX(set_order)', 'core_themes' )->first();
/* Create a default theme */
$theme = new \IPS\Theme;
$theme->parent_array = '[]';
$theme->child_array = '[]';
$theme->parent_id = 0;
$theme->by_skin_gen = 0;
$theme->editor_skin = 'ips';
$theme->order = $max + 1;
$theme->save();
$theme->copyResourcesFromSet();
/* Initate a redirector */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'id' => $theme->id ) ) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=form&type=' . $values['core_theme_add_theme_type'] ) );
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=form&type=' . $values['core_theme_add_theme_type'] ) );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'theme_set_add_button', $form, FALSE );
@@ -1019,13 +1082,15 @@ class _themes extends \IPS\Node\Controller
*/
public function import()
{
\IPS\Session::i()->csrfCheck();
if ( !file_exists( \IPS\Request::i()->file ) or md5_file( \IPS\Request::i()->file ) !== \IPS\Request::i()->key )
{
\IPS\Output::i()->error( 'generic_error', '3C130/1', 500, '' );
}
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => \IPS\Request::i()->file, 'key' => \IPS\Request::i()->key, 'id' => \IPS\Request::i()->id ) ),
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => \IPS\Request::i()->file, 'key' => \IPS\Request::i()->key, 'id' => \IPS\Request::i()->id ) )->csrf(),
function( $data )
{
$set = \IPS\Theme::load( \IPS\Request::i()->id );
@@ -1047,7 +1112,7 @@ class _themes extends \IPS\Node\Controller
}
/* Is this the first batch? */
if ( !is_array( $data ) )
if ( !\is_array( $data ) )
{
$_SESSION['theme_import'] = array( 'css' => array(), 'isNewSet' => false );
@@ -1206,7 +1271,7 @@ class _themes extends \IPS\Node\Controller
}
}
if ( count( $files ) )
if ( \count( $files ) )
{
$value = implode( ',', $files );
}
@@ -1312,7 +1377,7 @@ class _themes extends \IPS\Node\Controller
/* Theme resources should be raw binary data everywhere (filesystem and DB) except in the theme XML download where they are base64 encoded. */
$content = base64_decode( $xml->readString() );
$name = \IPS\Theme::makeBuiltTemplateLookupHash( $appKey, $xml->getAttribute('location'), $xml->getAttribute('path') ) . '_' . $xml->getAttribute('name');
$fileName = (string) \IPS\File::create( 'core_Theme', $name, $content, 'set_resources_' . \IPS\Request::i()->id, FALSE, NULL, FALSE );
$fileName = (string) \IPS\File::create( 'core_Theme', $name, $content, 'set_resources_' . \IPS\Request::i()->id, TRUE, NULL, FALSE );
try
{
@@ -1343,7 +1408,7 @@ class _themes extends \IPS\Node\Controller
'resource_data' => $content,
'resource_added' => time(),
'resource_filename' => $fileName,
'resource_user_edited' => intval( $xml->getAttribute('user_edited') )
'resource_user_edited' => \intval( $xml->getAttribute('user_edited') )
) );
break;
}
@@ -1414,26 +1479,22 @@ class _themes extends \IPS\Node\Controller
$type = $xml->getAttribute('type');
$name = $xml->getAttribute('name');
if( $set->logo[ $type ]['url'] !== null )
/* Sharer logo and favicons may be present from themes generated in 4.3 and earlier, but are no longer used */
if( $type != 'sharer' AND $type != 'favicon' )
{
\IPS\File::get( 'core_Theme', $set->logo[ $type ]['url'] )->delete();
}
if( $set->logo[ $type ]['url'] !== null )
{
\IPS\File::get( 'core_Theme', $set->logo[ $type ]['url'] )->delete();
}
$url = (string) \IPS\File::create( 'core_Theme', $name, base64_decode( $xml->readString() ) );
$url = (string) \IPS\File::create( 'core_Theme', $name, base64_decode( $xml->readString() ) );
if( $type != 'favicon' )
{
$image = \IPS\Image::create( base64_decode( $xml->readString() ) );
$width = $image->width;
$height = $image->height;
}
else
{
$width = 0;
$height = 0;
}
$set->saveSet( array( 'logo' => array( $type => array( 'url' => $url, 'width' => $width, 'height' => $height ) ) ) );
$set->saveSet( array( 'logo' => array( $type => array( 'url' => $url, 'width' => $width, 'height' => $height ) ) ) );
}
$xml->next();
}
@@ -1465,12 +1526,18 @@ class _themes extends \IPS\Node\Controller
}
\IPS\Theme::setThemeCustomized( $set->id );
$set->resetCacheKey();
/* Conflicts to fix? */
if ( \IPS\Db::i()->select( 'count(*)', 'core_theme_conflict', array( 'conflict_set_id=?', \IPS\Request::i()->id ) )->first() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=conflicts&id=' . \IPS\Request::i()->id ) );
}
elseif( $set->marketplace_id )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=marketplace&controller=marketplace&do=viewFile&id=' . $set->marketplace_id ), 'theme_now_installed' );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes' ) );
@@ -1489,7 +1556,7 @@ class _themes extends \IPS\Node\Controller
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
$form = new \IPS\Helpers\Form( 'form', 'theme_conflict_save' );
$themeSet = \IPS\Theme::load( $id );
$templates = array();
@@ -1503,7 +1570,7 @@ class _themes extends \IPS\Node\Controller
$conflicts[ $data['conflict_type'] ][ $key ] = $data;
}
if ( isset( $conflicts['template'] ) AND count( $conflicts['template'] ) )
if ( isset( $conflicts['template'] ) AND \count( $conflicts['template'] ) )
{
$templates = iterator_to_array( \IPS\Db::i()->select(
'*, MD5( CONCAT( template_app, \'.\', template_location, \'.\', template_group, \'.\', template_name ) ) as bit_key',
@@ -1516,7 +1583,7 @@ class _themes extends \IPS\Node\Controller
$conflicts['template'] = array();
}
if ( isset( $conflicts['css'] ) AND count( $conflicts['css'] ) )
if ( isset( $conflicts['css'] ) AND \count( $conflicts['css'] ) )
{
$css = iterator_to_array( \IPS\Db::i()->select(
'*, MD5( CONCAT( css_app, \'.\', css_location, \'.\', css_path, \'.\', css_name ) ) as bit_key',
@@ -1593,7 +1660,7 @@ class _themes extends \IPS\Node\Controller
}
}
if ( count( $conflictIds ) )
if ( \count( $conflictIds ) )
{
/* Get conflict data */
foreach( \IPS\Db::i()->select( '*', 'core_theme_conflict', \IPS\Db::i()->in( 'conflict_id', array_keys( $conflictIds ) ) )->setKeyField( 'conflict_id' ) as $cid => $data )
@@ -1604,7 +1671,7 @@ class _themes extends \IPS\Node\Controller
}
}
if ( isset( $conflicts['template'] ) AND count( $conflicts['template'] ) )
if ( isset( $conflicts['template'] ) AND \count( $conflicts['template'] ) )
{
$templates = iterator_to_array( \IPS\Db::i()->select(
'*, MD5( CONCAT( template_app, \'.\', template_location, \'.\', template_group, \'.\', template_name ) ) as bit_key',
@@ -1613,7 +1680,7 @@ class _themes extends \IPS\Node\Controller
)->setKeyField( 'bit_key' ) );
}
if ( isset( $conflicts['css'] ) AND count( $conflicts['css'] ) )
if ( isset( $conflicts['css'] ) AND \count( $conflicts['css'] ) )
{
$css = iterator_to_array( \IPS\Db::i()->select(
'*, MD5( CONCAT( css_app, \'.\', css_location, \'.\', css_path, \'.\', css_name ) ) as bit_key',
@@ -1660,7 +1727,7 @@ class _themes extends \IPS\Node\Controller
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes' ), 'completed' );
}
if ( count( $conflicts['css'] ) OR count( $conflicts['template'] ) )
if ( \count( $conflicts['css'] ) OR \count( $conflicts['template'] ) )
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/diff.css', 'core', 'admin' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'codemirror/codemirror.js', 'core', 'interface' ) );
@@ -1687,7 +1754,7 @@ class _themes extends \IPS\Node\Controller
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
/* Build form */
$form = new \IPS\Helpers\Form();
@@ -1758,7 +1825,7 @@ class _themes extends \IPS\Node\Controller
if ( $values = $form->values() )
{
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
$save = array( 'app' => $values['theme_css_app'],
'location' => $values['theme_css_location'],
'path' => ( $values['theme_css_group_type'] == 'existing' ) ? $values['theme_css_group_existing'] : $values['theme_css_group_new'],
@@ -1798,13 +1865,18 @@ class _themes extends \IPS\Node\Controller
*/
public function importForm()
{
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_download_upload' );
$themeSet = \IPS\Theme::load( $id );
$apps = array();
if( $themeSet->marketplace_id )
{
\IPS\Output::i()->error( 'app_upload_marketplace_only', '2C163/K', 403, '' );
}
foreach( \IPS\Application::applications() as $key => $data )
{
@@ -1823,7 +1895,7 @@ class _themes extends \IPS\Node\Controller
move_uploaded_file( $values['core_theme_set_new_import'], $tempFile );
/* Initate a redirector */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'id' => \IPS\Request::i()->id) ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=import' )->setQueryString( array( 'file' => $tempFile, 'key' => md5_file( $tempFile ), 'id' => \IPS\Request::i()->id) )->csrf() );
}
/* Display */
@@ -1837,7 +1909,7 @@ class _themes extends \IPS\Node\Controller
*/
public function exportForm()
{
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_download_upload' );
@@ -1853,7 +1925,7 @@ class _themes extends \IPS\Node\Controller
$form = new \IPS\Helpers\Form( 'form', 'theme_set_export_button' );
$storedAuthor = ( isset( \IPS\Data\Store::i()->theme_stored_author ) AND is_array( \IPS\Data\Store::i()->theme_stored_author ) ) ? \IPS\Data\Store::i()->theme_stored_author : null;
$storedAuthor = ( isset( \IPS\Data\Store::i()->theme_stored_author ) AND \is_array( \IPS\Data\Store::i()->theme_stored_author ) ) ? \IPS\Data\Store::i()->theme_stored_author : null;
$form->addHeader( \IPS\Member::loggedIn()->language()->addToStack('theme_set_export_title', FALSE, array( 'sprintf' => array( $themeSet->_title ) ) ) );
@@ -1861,7 +1933,7 @@ class _themes extends \IPS\Node\Controller
{
if ( ! isset( \IPS\Request::i()->rebuildDone ) )
{
$url = \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=devImportBeforeExport&id=' . $id );
$url = \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=devImportBeforeExport&id=' . $id )->csrf();
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack('theme_export_designer_mode_build_message', NULL, array( 'sprintf' => array( $url ) ) ), 'ipsMessage ipsMessage_info', FALSE );
}
@@ -1878,7 +1950,7 @@ class _themes extends \IPS\Node\Controller
$authorName = $values['theme_template_export_author_name'] ? $values['theme_template_export_author_name'] : $themeSet->author_name;
$authorUrl = $values['theme_template_export_author_url'] ? $values['theme_template_export_author_url'] : $themeSet->author_url;
$version = $values['theme_template_export_version'] ? $values['theme_template_export_version'] : $themeSet->version;
$longVersion = is_int( $values['theme_template_export_long_version'] ) ? $values['theme_template_export_long_version'] : $themeSet->long_version;
$longVersion = \is_int( $values['theme_template_export_long_version'] ) ? $values['theme_template_export_long_version'] : $themeSet->long_version;
$updateCheck = $values['theme_update_check'] ? $values['theme_update_check'] : $themeSet->update_check;
\IPS\Data\Store::i()->theme_stored_author = array(
@@ -1929,7 +2001,7 @@ class _themes extends \IPS\Node\Controller
{
$logos = json_decode( $themeSet->logo_data, TRUE );
if( is_array( $logos ) )
if( \is_array( $logos ) )
{
foreach ( $logos as $file => $data )
{
@@ -1981,7 +2053,7 @@ class _themes extends \IPS\Node\Controller
/* Templates */
$templates = $themeSet->getRawTemplates( $appDir, '', '', \IPS\Theme::RETURN_ALL );
if ( isset( $templates[ $appDir->directory ] ) AND count( $templates[ $appDir->directory ] ) )
if ( isset( $templates[ $appDir->directory ] ) AND \count( $templates[ $appDir->directory ] ) )
{
foreach( $templates[ $appDir->directory ] as $loc => $lv )
{
@@ -2006,7 +2078,7 @@ class _themes extends \IPS\Node\Controller
foreach( $templates[ $appDir->directory ][ $loc ][ $group ][ $name ] as $k => $v )
{
if ( in_array( \substr( $k, 9 ), array( 'location', 'group', 'name', 'data' ) ) )
if ( \in_array( \substr( $k, 9 ), array( 'location', 'group', 'name', 'data' ) ) )
{
$xml->startAttribute($k);
$xml->text( $v );
@@ -2050,7 +2122,7 @@ class _themes extends \IPS\Node\Controller
foreach( $css[ $appDir->directory ][ $loc ][ $path ][ $name ] as $k => $v )
{
if ( in_array( \substr( $k, 4 ), array( 'location', 'path', 'name', 'attributes' ) ) )
if ( \in_array( \substr( $k, 4 ), array( 'location', 'path', 'name', 'attributes' ) ) )
{
$xml->startAttribute($k);
$xml->text( $v );
@@ -2130,7 +2202,7 @@ class _themes extends \IPS\Node\Controller
/* Custom fields */
$settings = \IPS\Db::i()->select( '*', 'core_theme_settings_fields', array( 'sc_set_id=? AND sc_app=?', $themeSet->id, $appDir->directory ) )->join( 'core_theme_settings_values', 'sc_id=sv_id' );
if ( count( $settings ) )
if ( \count( $settings ) )
{
foreach ( $settings as $row )
{
@@ -2141,7 +2213,7 @@ class _themes extends \IPS\Node\Controller
foreach( $row as $k => $v )
{
if ( !in_array( $k, array( 'sc_updated', 'sv_value', 'sc_app', 'sv_id' ) ) )
if ( !\in_array( $k, array( 'sc_updated', 'sv_value', 'sc_app', 'sv_id' ) ) )
{
$xml->startAttribute( $k );
$xml->text( $v );
@@ -2269,10 +2341,12 @@ class _themes extends \IPS\Node\Controller
}
catch ( \OutOfRangeException $e ) {}
$parentResult = parent::delete();
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
return parent::delete();
return $parentResult;
}
/**
@@ -2286,7 +2360,7 @@ class _themes extends \IPS\Node\Controller
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
$locations = array();
$groups = array();
@@ -2361,7 +2435,7 @@ class _themes extends \IPS\Node\Controller
if ( $values = $form->values() )
{
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
$save = array( 'set_id' => $id,
'app' => $values['theme_template_app'],
'location' => $values['theme_template_location'],
@@ -2410,6 +2484,8 @@ class _themes extends \IPS\Node\Controller
*/
public function build()
{
\IPS\Session::i()->csrfCheck();
$set = \IPS\Theme::load( \IPS\Request::i()->id );
/* Resources has to come before CSS otherwise CSS url()s are out of date as resource build changes resource URL after CSS has been built */
@@ -2435,8 +2511,8 @@ class _themes extends \IPS\Node\Controller
\IPS\Request::i()->confirmedDelete();
$type = \IPS\Request::i()->t_type;
$id = intval( \IPS\Request::i()->id );
$item_id = intval( \IPS\Request::i()->t_item_id );
$id = \intval( \IPS\Request::i()->id );
$item_id = \intval( \IPS\Request::i()->t_item_id );
try
{
@@ -2503,6 +2579,8 @@ class _themes extends \IPS\Node\Controller
*/
public function saveTemplate()
{
\IPS\Session::i()->csrfCheck();
$type = \IPS\Request::i()->t_type;
$editorName = 'editor_' . \IPS\Request::i()->t_key;
$url = array();
@@ -2512,8 +2590,8 @@ class _themes extends \IPS\Node\Controller
'location' => \IPS\Request::i()->t_location,
'group' => \IPS\Request::i()->t_group,
'name' => \IPS\Request::i()->t_name,
'set_id' => intval( \IPS\Request::i()->id ),
'item_id' => intval( \IPS\Request::i()->t_item_id ),
'set_id' => \intval( \IPS\Request::i()->id ),
'item_id' => \intval( \IPS\Request::i()->t_item_id ),
'key' => \IPS\Request::i()->t_key,
'content' => \IPS\Request::i()->$editorName );
try
@@ -2561,7 +2639,7 @@ class _themes extends \IPS\Node\Controller
foreach( $save as $k => $v )
{
if ( in_array( $k, array( 'app', 'location', 'group', 'name' ) ) )
if ( \in_array( $k, array( 'app', 'location', 'group', 'name' ) ) )
{
$url[] = 't_' . $k . '=' . $v;
$log[ $k . ': ' . $v ] = FALSE;
@@ -2611,12 +2689,14 @@ class _themes extends \IPS\Node\Controller
*/
public function devImportMultipleRedirect( $finalUrl=NULL )
{
\IPS\Session::i()->csrfCheck();
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=devImportMultipleRedirect&id=' . \IPS\Request::i()->id . '&finalUrl=' . base64_encode( $finalUrl ) ),
\IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=devImportMultipleRedirect&id=' . \IPS\Request::i()->id . '&finalUrl=' . base64_encode( $finalUrl ) )->csrf(),
function( $data )
{
/* Is this the first cycle? */
if ( ! is_array( $data ) )
if ( ! \is_array( $data ) )
{
$toImport = array();
@@ -2632,7 +2712,7 @@ class _themes extends \IPS\Node\Controller
}
/* Grab something to build */
if ( count( $data['toImport'] ) )
if ( \count( $data['toImport'] ) )
{
reset( $data['toImport'] );
$app = key( $data['toImport'] );
@@ -2643,18 +2723,43 @@ class _themes extends \IPS\Node\Controller
switch( $type )
{
case 'html':
\IPS\Theme::i()->importDevHtml( $app, ( ( \IPS\Theme::designersModeEnabled() !== true ) ? 0 : \IPS\Request::i()->id ) );
\IPS\Theme::load( ( ( \IPS\IN_DEV AND ! \IPS\Request::i()->id ) ? 1 : \IPS\Request::i()->id ) )->compileTemplates( $app );
if( \IPS\Theme::designersModeEnabled() !== true )
{
\IPS\Theme::i()->importDevHtml( $app, 0 );
\IPS\Theme::load( 1 )->compileTemplates( $app );
}
else
{
\IPS\Theme\Advanced\Theme::load( \IPS\Request::i()->id )->importDevHtml( $app, \IPS\Request::i()->id );
\IPS\Theme::load( \IPS\Request::i()->id )->compileTemplates( $app );
}
unset( $data['toImport'][ $app ][0] );
break;
case 'css':
\IPS\Theme::i()->importDevCss( $app, ( ( \IPS\Theme::designersModeEnabled() !== true ) ? 0 : \IPS\Request::i()->id ) );
\IPS\Theme::load( ( ( \IPS\IN_DEV AND ! \IPS\Request::i()->id ) ? 1 : \IPS\Request::i()->id ) )->compileCss( $app );
if( \IPS\Theme::designersModeEnabled() !== true )
{
\IPS\Theme::i()->importDevCss( $app, 0 );
\IPS\Theme::load( 1 )->compileCss( $app );
}
else
{
\IPS\Theme\Advanced\Theme::load( \IPS\Request::i()->id )->importDevCss( $app, \IPS\Request::i()->id );
\IPS\Theme::load( \IPS\Request::i()->id )->compileCss( $app );
}
unset( $data['toImport'][ $app ][1] );
break;
case 'resources':
\IPS\Theme::i()->importDevResources( $app, ( ( \IPS\Theme::designersModeEnabled() !== true ) ? 1 : \IPS\Request::i()->id ) );
\IPS\Theme::load( ( ( \IPS\IN_DEV AND ! \IPS\Request::i()->id ) ? 1 : \IPS\Request::i()->id ) )->buildResourceMap( $app );
if( \IPS\Theme::designersModeEnabled() !== true )
{
\IPS\Theme::i()->importDevResources( $app, 0 );
\IPS\Theme::load( 1 )->buildResourceMap( $app );
}
else
{
\IPS\Theme\Advanced\Theme::load( \IPS\Request::i()->id )->importDevResources( $app, \IPS\Request::i()->id );
\IPS\Theme::load( \IPS\Request::i()->id )->buildResourceMap( $app );
}
/* All done */
unset( $data['toImport'][ $app ] );
break;
@@ -2688,7 +2793,7 @@ class _themes extends \IPS\Node\Controller
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
/* Grab groups */
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
if ( $id === 1 AND \IPS\IN_DEV )
{
@@ -2735,7 +2840,7 @@ class _themes extends \IPS\Node\Controller
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
/* Grab groups */
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
if ( $id === 1 AND \IPS\IN_DEV )
{
@@ -2789,7 +2894,7 @@ class _themes extends \IPS\Node\Controller
\IPS\Dispatcher::i()->checkAcpPermission( 'theme_templates_manage' );
/* Grab groups */
$id = intval( \IPS\Request::i()->id );
$id = \intval( \IPS\Request::i()->id );
$t_type = \IPS\Request::i()->t_type ?: 'templates';
$t_app = \IPS\Request::i()->t_app ?: 'core';
$t_location = \IPS\Request::i()->t_location ?: ( ( \IPS\Request::i()->t_app ) ? false : 'front' );