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

+35 -31
View File
@@ -12,31 +12,40 @@
namespace IPS\cms\Theme;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use IPS\cms\Theme;
use IPS\Db;
use IPS\Theme\Template as ThemeTemplate;
use UnderflowException;
use function defined;
use function function_exists;
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;
}
/**
* Magic Template Class for IN_DEV mode
*/
class _Template extends \IPS\Theme\Template
class Template extends ThemeTemplate
{
/**
* @brief Source Folder
*/
public $sourceFolder = NULL;
public ?string $sourceFolder = NULL;
/**
* Extract the data object from the param tag
* @note We always assume the tag is in the format of <ips:template parameters="" data="" />
*
* @param string $tag <ips:template> tag
* @param string $key Data key to fetch
* @return null|array
* @param string $tag <ips:template> tag
* @param string $key Data key to fetch
* @return string|null
*/
public static function extractDataFromTag( $tag, $key="data" )
public static function extractDataFromTag( string $tag, string $key="data" ): ?string
{
if ( ! preg_match( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', $tag, $matches ) )
{
@@ -55,10 +64,10 @@ class _Template extends \IPS\Theme\Template
* Extract the data object from the param tag
* @note We always assume the tag is in the format of <ips:template parameters="" data="" />
*
* @param string $tag <ips:template> tag
* @return null|array
* @param string $tag <ips:template> tag
* @return null|string
*/
public static function extractParamsFromTag( $tag )
public static function extractParamsFromTag( string $tag ): ?string
{
if ( ! preg_match( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', $tag, $matches ) )
{
@@ -76,18 +85,14 @@ class _Template extends \IPS\Theme\Template
* @param string $templateName Template Name
* @return void
*/
public function __construct( $app, $templateLocation, $templateName )
public function __construct( string $app, string $templateLocation, string $templateName )
{
parent::__construct( $app, $templateLocation, $templateName );
$this->app = $app;
$this->templateLocation = $templateLocation;
$this->templateName = $templateName;
if ( \IPS\Theme::designersModeEnabled() )
{
$this->sourceFolder = \IPS\ROOT_PATH . "/themes/cms/{$templateLocation}/{$templateName}/";
}
else if ( \IPS\IN_DEV )
if ( \IPS\IN_DEV )
{
$this->sourceFolder = \IPS\ROOT_PATH . "/applications/{$app}/dev/html/{$templateLocation}/{$templateName}/";
}
@@ -96,36 +101,35 @@ class _Template extends \IPS\Theme\Template
/**
* Magic Method: Call Template Bit
*
* @param string $bit Template Bit Name
* @param array $params Parameters
* @return string
* @param string $bit Template Bit Name
* @param array $params Parameters
*/
public function __call( $bit, $params )
public function __call( string $bit, array $params )
{
if ( \IPS\IN_DEV or \IPS\Theme::designersModeEnabled() )
if ( \IPS\IN_DEV )
{
/* What are we calling this? */
$functionName = "theme_{$this->app}_{$this->templateLocation}_{$this->templateName}_{$bit}";
/* If it doesn't exist, build it */
if( !\function_exists( 'IPS\\Theme\\'.$functionName ) )
if( !function_exists( 'IPS\\Theme\\'.$functionName ) )
{
/* Find the file */
$file = $this->sourceFolder . $bit . '.phtml';
/* Get the content */
if ( $file === NULL or !file_exists( $file ) )
if ( !file_exists( $file ) )
{
/* Try the database */
try
{
$template = \IPS\Db::i()->select( '*', 'cms_templates', array( 'template_location=? and LOWER(template_group)=? and template_title=?', $this->templateLocation, $this->templateName, $bit ) )->first();
$template = Db::i()->select( '*', 'cms_templates', array( 'template_location=? and LOWER(template_group)=? and template_title=?', $this->templateLocation, $this->templateName, $bit ) )->first();
\IPS\cms\Theme::makeProcessFunction( $template['template_content'], $functionName, $template['template_params'], TRUE );
Theme::makeProcessFunction( $template['template_content'], $functionName, $template['template_params'], TRUE );
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
throw new \BadMethodCallException( 'NO_TEMPLATE_FILE - ' . $file );
throw new BadMethodCallException( 'NO_TEMPLATE_FILE - ' . $file );
}
}
else
@@ -136,14 +140,14 @@ class _Template extends \IPS\Theme\Template
/* Parse the header tag */
if ( !preg_match( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', $output, $matches ) )
{
throw new \BadMethodCallException( 'NO_HEADER - ' . $file );
throw new BadMethodCallException( 'NO_HEADER - ' . $file );
}
/* Strip it */
$output = preg_replace( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', '', $output );
/* Make it into a lovely function */
\IPS\cms\Theme::makeProcessFunction( $output, $functionName, ( isset( $matches[1] ) ? $matches[1] : '' ), TRUE );
Theme::makeProcessFunction( $output, $functionName, ( $matches[1] ?? '' ), TRUE );
}
}