Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,10 @@
/**
* @brief Templates Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Content
* @since 25 Feb 2014
* @version SVN_VERSION_NUMBER
*/
@@ -47,6 +48,11 @@ class _Templates extends \IPS\Patterns\ActiveRecord
* @brief [ActiveRecord] Database ID Fields
*/
protected static $databaseIdFields = array( 'template_key', 'template_id' );
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
/**
* @brief Retusn all types
@@ -92,7 +98,74 @@ class _Templates extends \IPS\Patterns\ActiveRecord
* @brief Return both IN_DEV and database templates
*/
const RETURN_DATABASE_AND_IN_DEV = 256;
/**
* @brief Default database template group names
*/
public static $databaseDefaults = array(
'featured' => 'category_articles',
'form' => 'form',
'display' => 'display',
'listing' => 'listing',
'categories' => 'category_index'
);
/**
* Ensure that the template is calling the correct groups
*
* @param string $group Group to load templates from
* @return void
*/
public static function fixTemplateTags( $group )
{
$templates = iterator_to_array( \IPS\Db::i()->select( '*', 'cms_templates', array( array( 'template_group=?', $group ) ) )->setKeyField('template_title') );
foreach( $templates as $template )
{
$save = array();
/* Make sure template tags call the correct group */
if ( mb_stristr( $template['template_content'], '{template' ) )
{
preg_match_all( '/\{([a-z]+?=([\'"]).+?\\2 ?+)}/', $template['template_content'], $matches, PREG_SET_ORDER );
/* Work out the plugin and the values to pass */
foreach( $matches as $index => $array )
{
preg_match_all( '/(.+?)=' . $array[ 2 ] . '(.+?)' . $array[ 2 ] . '\s?/', $array[ 1 ], $submatches );
$plugin = array_shift( $submatches[ 1 ] );
if ( $plugin == 'template' )
{
$value = array_shift( $submatches[ 2 ] );
$options = array();
foreach ( $submatches[ 1 ] as $k => $v )
{
$options[ $v ] = $submatches[ 2 ][ $k ];
}
if ( isset( $options['app'] ) and $options['app'] == 'cms' and isset( $options['location'] ) and $options['location'] == 'database' and isset( $options['group'] ) and $options['group'] != $template['template_original_group'] )
{
if ( in_array( $value, array_keys( $templates ) ) )
{
$options['group'] = $group;
$replace = '{template="' . $value . '" app="' . $options['app'] . '" location="' . $options['location'] . '" group="' . $options['group'] . '" params="' . ( isset($options['params']) ? $options['params'] : NULL ) . '"}';
$save['template_content'] = str_replace( $matches[$index][0], $replace, $template['template_content'] );
}
}
if ( count( $save ) )
{
\IPS\Db::i()->update( 'cms_templates', $save, array( 'template_id=?', $template['template_id'] ) );
}
}
}
}
}
}
/**
* Load Record
* Overloaded so we can force loading by key by default but still retain the template_id field as the primary key so
@@ -395,7 +468,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
$newTemplate->save();
/* Create a unique key */
$newTemplate->key = $newTemplate->location . '_' . \IPS\Http\Url::seoTitle( $newTemplate->title ) . '_' . $newTemplate->id;
$newTemplate->key = $newTemplate->location . '_' . \IPS\Http\Url\Friendly::seoTitle( $newTemplate->title ) . '_' . $newTemplate->id;
/* Make sure there's no double __ in there */
foreach( array( 'group', 'title', 'key' ) as $field )
@@ -490,7 +563,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
}
/* Open XML file */
$xml = new \XMLReader;
$xml = new \IPS\Xml\XMLReader;
$xml->open( $file );
$xml->read();
@@ -548,13 +621,15 @@ class _Templates extends \IPS\Patterns\ActiveRecord
*/
public function delete()
{
if ( $this->user_added )
\IPS\cms\Theme::deleteCompiledTemplate( 'cms', $this->location, $this->group );
if ( $this->user_created )
{
\IPS\Db::i()->delete( 'cms_templates', array( 'template_key=? AND template_user_added=?', $this->key, 1 ) );
if ( isset( static::$multitons[ $this->key ] ) )
\IPS\Db::i()->delete( 'cms_templates', array( 'template_key=? AND template_user_created=?', $this->key, 1 ) );
if ( isset( static::$multitons[ $this->id ] ) )
{
unset( static::$multitons[ $this->key ] );
unset( static::$multitons[ $this->id ] );
}
}
else
@@ -562,10 +637,10 @@ class _Templates extends \IPS\Patterns\ActiveRecord
if ( $this->user_edited )
{
\IPS\Db::i()->delete( 'cms_templates', array( 'template_key=? AND template_user_edited=?', $this->key, 1 ) );
if ( isset( static::$multitons[ $this->key ] ) )
if ( isset( static::$multitons[ $this->id ] ) )
{
unset( static::$multitons[ $this->key ] );
unset( static::$multitons[ $this->id ] );
}
}
else
@@ -606,7 +681,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
$content = $this->content;
/* Build on demand */
if ( mb_stristr( $this->content, "{block=" ) )
if ( $this->type != 'js' and ( mb_stristr( $this->content, "{block=" ) or mb_stristr( $this->content, "{{if" ) ) )
{
$functionName = 'css_' . uniqid();
\IPS\Theme::makeProcessFunction( str_replace( '\\', '\\\\', $content ), $functionName );