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,23 +12,34 @@
namespace IPS\cms\Theme\Advanced;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DirectoryIterator;
use IPS\cms\Theme as SystemTheme;
use IPS\Data\Store;
use IPS\Db;
use IPS\Theme\Dev\Theme as DevTheme;
use IPS\Theme\Setup\Theme as SetupTheme;
use function count;
use function defined;
use function strtolower;
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;
}
/**
* Designer's Mode Theme
*/
class _Theme extends \IPS\cms\Theme
class Theme extends SystemTheme
{
/**
* Get currently logged in member's theme
*
* @return static
* @return static|SetupTheme|DevTheme
*/
public static function i()
public static function i() : static|SetupTheme|DevTheme
{
return new self;
}
@@ -38,9 +49,9 @@ class _Theme extends \IPS\cms\Theme
*
* @return void
*/
public static function export()
public static function export() : void
{
foreach( \IPS\Db::i()->select(
foreach( Db::i()->select(
"*, MD5( CONCAT(template_location, ',', template_group, ',', template_title) ) as bit_key",
'cms_templates',
NULL,
@@ -56,20 +67,20 @@ class _Theme extends \IPS\cms\Theme
*
* @return void
*/
public static function import()
public static function import() : void
{
$seen = array();
foreach( array( 'block', 'page', 'database', 'js', 'css' ) as $location )
{
$templates = iterator_to_array( \IPS\Db::i()->select(
$templates = iterator_to_array( Db::i()->select(
"*, MD5( CONCAT(template_location, ',', template_group, ',', template_title) ) as bit_key",
'cms_templates',
array( 'template_location=?', $location ),
'template_user_edited ASC' /* Ensure we get edited versions, not the master version if one exists */
)->setKeyField('bit_key') );
$master = iterator_to_array( \IPS\Db::i()->select(
$master = iterator_to_array( Db::i()->select(
"*, MD5( CONCAT(template_location, ',', template_group, ',', template_title) ) as bit_key",
'cms_templates',
array( 'template_master=1 and template_location=?', $location )
@@ -79,7 +90,7 @@ class _Theme extends \IPS\cms\Theme
if ( is_dir( $path ) )
{
foreach( new \DirectoryIterator( $path ) as $group )
foreach( new DirectoryIterator( $path ) as $group )
{
if ( $group->isDot() || mb_substr( $group->getFilename(), 0, 1 ) === '.' )
{
@@ -90,7 +101,7 @@ class _Theme extends \IPS\cms\Theme
{
$seen = array();
foreach( new \DirectoryIterator( $path . '/' . $group->getFilename() ) as $file )
foreach( new DirectoryIterator( $path . '/' . $group->getFilename() ) as $file )
{
if ( $file->isDot() || ( mb_substr( $file->getFilename(), -6 ) !== '.phtml' and mb_substr( $file->getFilename(), -3 ) !== '.js' and mb_substr( $file->getFilename(), -4 ) !== '.css' ) )
{
@@ -136,7 +147,7 @@ class _Theme extends \IPS\cms\Theme
if ( ! $templates[ $key ]['template_master'] )
{
$added = TRUE;
\IPS\Db::i()->update( 'cms_templates', array(
Db::i()->update( 'cms_templates', array(
'template_content' => $html,
'template_params' => ( isset($params[1]) ) ? $params[1] : '',
'template_file_object' => NULL
@@ -158,7 +169,7 @@ class _Theme extends \IPS\cms\Theme
}
/* New template */
\IPS\Db::i()->insert( 'cms_templates', array(
Db::i()->insert( 'cms_templates', array(
'template_key' => $location . '_' . $group->getFilename() . '_' . $title,
'template_title' => $title,
'template_desc' => '',
@@ -176,19 +187,19 @@ class _Theme extends \IPS\cms\Theme
}
/* remove compiled version */
$key = \strtolower( 'template_cms_' .static::makeBuiltTemplateLookupHash( 'cms', $location, $group->getFilename() ) . '_' . static::cleanGroupName( $group->getFilename() ) );
$key = strtolower( 'template_cms_' .static::makeBuiltTemplateLookupHash( 'cms', $location, $group->getFilename() ) . '_' . static::cleanGroupName( $group->getFilename() ) );
if ( isset( \IPS\Data\Store::i()->$key ) )
if ( isset( Store::i()->$key ) )
{
unset(\IPS\Data\Store::i()->$key);
unset(Store::i()->$key);
}
}
}
/* Remove any templates we've not imported for this location/group */
if ( \count( $seen ) )
if ( count( $seen ) )
{
\IPS\Db::i()->delete( 'cms_templates', array('template_master=0 and template_location=? and template_group=? and ' . \IPS\Db::i()->in( 'template_title', $seen, TRUE ), $location, $group->getFilename() ) );
Db::i()->delete( 'cms_templates', array('template_master=0 and template_location=? and template_group=? and ' . Db::i()->in( 'template_title', $seen, TRUE ), $location, $group->getFilename() ) );
}
}
}
@@ -202,7 +213,7 @@ class _Theme extends \IPS\cms\Theme
* @param string|null $path Path or Filename
* @return string
*/
protected static function _getHtmlPath( $app, $location=null, $path=null )
protected static function _getHtmlPath( string $app, ?string $location=null, ?string $path=null ) : string
{
return rtrim( \IPS\ROOT_PATH . "/themes/cms/{$location}/{$path}", '/' ) . '/';
}