Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Blocks;
|
||||
|
||||
/* 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;
|
||||
@@ -161,7 +161,7 @@ class _Block extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( is_numeric( $block ) )
|
||||
if ( \is_numeric( $block ) )
|
||||
{
|
||||
$block = static::load( $block );
|
||||
}
|
||||
@@ -213,11 +213,12 @@ class _Block extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
unset( \IPS\Data\Store::i()->$functionName );
|
||||
}
|
||||
|
||||
$html = call_user_func( 'IPS\\Theme\\'. $functionName );
|
||||
$themeFunction = 'IPS\\Theme\\'. $functionName;
|
||||
$html = $themeFunction();
|
||||
|
||||
if( $block->getConfig('editor') == 'editor' )
|
||||
{
|
||||
$html = \IPS\Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->Wysiwyg( $html, $orientation );
|
||||
$html = \IPS\Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->Wysiwyg( \IPS\Member::loggedIn()->language()->addToStack( "cms_block_content_{$block->id}" ), $orientation );
|
||||
}
|
||||
|
||||
return $html;
|
||||
@@ -238,7 +239,7 @@ class _Block extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$block->widget()->template( array( $block, 'getTemplate' ) );
|
||||
}
|
||||
|
||||
return $block->widget()->render();
|
||||
return \IPS\Widget::parseOutput( $block->widget()->render() );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
@@ -254,13 +255,13 @@ class _Block extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$args = \func_get_args();
|
||||
$functionName = 'content_template_for_block_' . $this->id;
|
||||
|
||||
unset( \IPS\Data\Store::i()->$functionName );
|
||||
|
||||
/* Still here */
|
||||
if ( ! in_array( $functionName, array_keys( static::$calledTemplates ) ) )
|
||||
if ( ! \in_array( $functionName, array_keys( static::$calledTemplates ) ) )
|
||||
{
|
||||
if ( ! isset( \IPS\Data\Store::i()->$functionName ) )
|
||||
{
|
||||
@@ -321,7 +322,7 @@ EOF;
|
||||
{
|
||||
$ids = iterator_to_array( \IPS\Db::i()->select( 'block_id', 'cms_blocks' )->setValueField('block_id') );
|
||||
}
|
||||
else if ( is_numeric( $ids ) )
|
||||
else if ( \is_numeric( $ids ) )
|
||||
{
|
||||
$ids = array( $ids );
|
||||
}
|
||||
@@ -433,13 +434,12 @@ EOF;
|
||||
*/
|
||||
public function get__plugin_config()
|
||||
{
|
||||
return ( $this->plugin_config ? ( is_array( $this->plugin_config ) ? $this->plugin_config : json_decode( $this->plugin_config, TRUE ) ) : array() );
|
||||
return ( $this->plugin_config ? ( \is_array( $this->plugin_config ) ? $this->plugin_config : json_decode( $this->plugin_config, TRUE ) ) : array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
@@ -560,7 +560,7 @@ EOF;
|
||||
|
||||
if ( mb_substr( $block_plugin, 0, 8 ) === 'db_feed_' )
|
||||
{
|
||||
$databaseId = intval( mb_substr( $block_plugin, 8 ) );
|
||||
$databaseId = \intval( mb_substr( $block_plugin, 8 ) );
|
||||
$this->plugin = 'RecordFeed';
|
||||
$this->plugin_config = array( 'cms_rf_database' => $databaseId );
|
||||
|
||||
@@ -583,7 +583,7 @@ EOF;
|
||||
throw new \LogicException( 'cms_error_block_plugin_not_found' );
|
||||
}
|
||||
|
||||
if ( is_callable( array( $this->widget(), 'configuration' ) ) )
|
||||
if ( \is_callable( array( $this->widget(), 'configuration' ) ) )
|
||||
{
|
||||
$form->addTab( 'content_block_form_tab__feed' );
|
||||
$this->widget()->configuration( $form );
|
||||
@@ -615,7 +615,7 @@ EOF;
|
||||
$useHow = NULL;
|
||||
if ( $this->id )
|
||||
{
|
||||
if ( intval( $this->template ) or ( ! intval( $this->template ) and ! $this->content ) )
|
||||
if ( \intval( $this->template ) or ( ! \intval( $this->template ) and ! $this->content ) )
|
||||
{
|
||||
$useHow = 'use';
|
||||
}
|
||||
@@ -638,15 +638,20 @@ EOF;
|
||||
|
||||
if ( $block_editor === 'editor' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'block_content', $this->content, FALSE, array(
|
||||
'app' => 'cms',
|
||||
'key' => 'BlockContent',
|
||||
'autoSaveKey' => 'block-content-' . ( $this->id ? $this->id : 'new' ),
|
||||
'attachIds' => ( $this->id ) ? array( $this->id ) : NULL ), NULL, NULL, NULL, 'block_content_editor' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'block_content', NULL, FALSE, array(
|
||||
'key' => ( $this->id ) ? "cms_block_content_{$this->id}" : NULL,
|
||||
'editor' => array(
|
||||
'app' => 'cms',
|
||||
'key' => 'BlockContent',
|
||||
'autoSaveKey' => 'block-content-' . ( $this->id ? $this->id : 'new' ),
|
||||
'attachIds' => ( $this->id ) ? array( $this->id ) : NULL
|
||||
)
|
||||
) ) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'block_content', htmlentities( $this->content, ENT_DISALLOWED, 'UTF-8', TRUE ), FALSE, array(), function( $val ) {
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'block_content', htmlentities( $this->content, ENT_DISALLOWED, 'UTF-8', TRUE ), FALSE, array( 'tagSource' => \IPS\Http\Url::internal( "app=cms&module=pages&controller=blocks&do=loadTags" ) ), function( $val ) {
|
||||
if ( \IPS\Request::i()->block_editor == 'php' )
|
||||
{
|
||||
try
|
||||
@@ -754,7 +759,7 @@ EOF;
|
||||
{
|
||||
if ( ! $values['block_key'] )
|
||||
{
|
||||
if ( is_array( $values['block_name'] ) )
|
||||
if ( \is_array( $values['block_name'] ) )
|
||||
{
|
||||
reset( $values['block_name'] );
|
||||
$values['block_key'] = \IPS\Http\Url\Friendly::seoTitle( $values['block_name'][ key( $values['block_name'] ) ] );
|
||||
@@ -767,7 +772,7 @@ EOF;
|
||||
/* Now test it */
|
||||
try
|
||||
{
|
||||
$block = \IPS\cms\Blocks\Block::load( $this->key, 'block_key');
|
||||
$block = \IPS\cms\Blocks\Block::load( $values['block_key'], 'block_key');
|
||||
|
||||
/* It's taken... */
|
||||
if ( $this->id != $block->id )
|
||||
@@ -787,17 +792,33 @@ EOF;
|
||||
$values['plugin_app'] = \IPS\Request::i()->block_plugin_app;
|
||||
|
||||
/* configure widget related values */
|
||||
if ( is_callable( array( $this->widget(), 'preConfig' ) ) )
|
||||
if ( \is_callable( array( $this->widget(), 'preConfig' ) ) )
|
||||
{
|
||||
$values = $this->widget()->preConfig( $values );
|
||||
}
|
||||
|
||||
/* Special advanced builder stuff */
|
||||
if ( \in_array( 'IPS\Widget\Builder', class_implements( $this->widget() ) ) )
|
||||
{
|
||||
if( isset( $values['widget_adv__background_custom_image'] ) and $values['widget_adv__background_custom_image'] )
|
||||
{
|
||||
$values['widget_adv__background_custom_image'] = (string) $values['widget_adv__background_custom_image'];
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $values['show_on_all_devices'] ) and $values['show_on_all_devices'] )
|
||||
{
|
||||
$values['devices_to_show'] = array( 'Phone', 'Tablet', 'Desktop' );
|
||||
}
|
||||
|
||||
unset( $values['show_on_all_devices'] );
|
||||
|
||||
/* Store config */
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if ( ! in_array( $k, array( 'block_name', 'block_key', 'block_description', 'block_category', 'block_template_id', 'block_template_use_how', 'block_content', 'block_save_as_template', 'block_save_as_template_name' ) ) )
|
||||
if ( ! \in_array( $k, array( 'block_name', 'block_key', 'block_description', 'block_category', 'block_template_id', 'block_template_use_how', 'block_content', 'block_save_as_template', 'block_save_as_template_name' ) ) )
|
||||
{
|
||||
if ( is_array( $v ) )
|
||||
if ( \is_array( $v ) )
|
||||
{
|
||||
$theValue = NULL;
|
||||
foreach( $v as $eachKey => $eachValue )
|
||||
@@ -916,7 +937,7 @@ EOF;
|
||||
$newTemplate = \IPS\cms\Templates::add( $templateArray );
|
||||
|
||||
$values['content'] = null;
|
||||
$values['template'] = $newTemplate->id;
|
||||
$values['template'] = $newTemplate->key;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -929,6 +950,11 @@ EOF;
|
||||
else if( isset( $values['block_content'] ) )
|
||||
{
|
||||
$values['template'] = 0;
|
||||
if ( \IPS\Request::i()->block_editor === 'editor' )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_block_content_{$this->id}", $values['block_content'] );
|
||||
$values['block_content'] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $values['block_category'] ) AND ( ! empty( $values['block_category'] ) OR $values['block_category'] === 0 ) )
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Blocks;
|
||||
|
||||
/* 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;
|
||||
@@ -106,17 +106,17 @@ class _Container extends \IPS\Node\Model
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
|
||||
{
|
||||
return parent::roots( $permissionCheck, $member, array( array('container_type=?', 'block' ) ) );
|
||||
return parent::roots( $permissionCheck, $member, array( array( 'container_type=?', 'block' ) ), $limit );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
@@ -195,7 +195,7 @@ class _Container extends \IPS\Node\Model
|
||||
/* Build form */
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'container_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ) ) );
|
||||
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'container_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Blocks\Container',
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -128,7 +128,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* @brief [Node] Type for permission index
|
||||
*/
|
||||
public static $permType = 'categories';
|
||||
public static $permType = NULL;
|
||||
|
||||
/**
|
||||
* @brief The map of permission columns
|
||||
@@ -235,7 +235,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* Test to see if this is a valid container ID
|
||||
*
|
||||
* @param int $id Container ID
|
||||
* @reply boolean
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidContainerId( $id )
|
||||
{
|
||||
@@ -244,7 +244,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
static::$containerIds = iterator_to_array( \IPS\Db::i()->select( 'category_id', static::$databaseTable, array( array( 'category_database_id=?', static::$customDatabaseId ) ) ) );
|
||||
}
|
||||
|
||||
return in_array( $id, static::$containerIds );
|
||||
return \in_array( $id, static::$containerIds );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,16 +258,17 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
|
||||
{
|
||||
if ( static::$customDatabaseId !== NULL )
|
||||
{
|
||||
$where[] = array('category_database_id=?', static::$customDatabaseId );
|
||||
$where[] = array( 'category_database_id=?', static::$customDatabaseId );
|
||||
}
|
||||
|
||||
return parent::roots( $permissionCheck, $member, $where );
|
||||
return parent::roots( $permissionCheck, $member, $where, $limit );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,7 +321,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$root = $bits[0];
|
||||
|
||||
/* _ is here due to IP.Board 3.x using that to denote the articles database (eg. articles.html/_/category/record-r1/), which we need to redirect from for records and articles. */
|
||||
if ( in_array( $root, array( 'submit', '_' ) ) )
|
||||
if ( \in_array( $root, array( 'submit', '_' ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -336,7 +337,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function set_fields( $value )
|
||||
{
|
||||
$this->_data['fields'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['fields'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,7 +466,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'key' => ( $this->id ? "content_cat_name_" . $this->id . "_desc" : NULL )
|
||||
) ) );
|
||||
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'category_parent_id', ( ! $this->id ) ? ( isset( \IPS\Request::i()->parent ) ? \IPS\Request::i()->parent : 0 ) : $this->parent_id, FALSE, array(
|
||||
'class' => '\IPS\cms\Categories' . \IPS\Request::i()->database_id,
|
||||
@@ -576,7 +577,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $options ) )
|
||||
if ( \count( $options ) )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'category_fields', $cats, FALSE, array(
|
||||
'multiple' => true,
|
||||
@@ -607,6 +608,9 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
$values['category_database_id'] = $this->database_id;
|
||||
}
|
||||
|
||||
/* Need this for later */
|
||||
$_new = $this->_new;
|
||||
|
||||
if ( ! $this->id )
|
||||
{
|
||||
@@ -614,7 +618,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$this->save();
|
||||
}
|
||||
|
||||
if ( isset( $values['category_name'] ) AND is_array( $values['category_name'] ) )
|
||||
if ( isset( $values['category_name'] ) AND \is_array( $values['category_name'] ) )
|
||||
{
|
||||
$name = $values['category_name'][ \IPS\Lang::defaultLanguage() ];
|
||||
}
|
||||
@@ -679,6 +683,12 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
else if( isset( $values['category_furl_name'] ) )
|
||||
{
|
||||
$values['furl_name'] = \IPS\Http\Url\Friendly::seoTitle( $values['category_furl_name'] );
|
||||
|
||||
/* We cannot have numeric furl_names 'cos you could do page/2/ and it will confuse SEO pagination. This is not possible with other areas as it is always /id-furl/ */
|
||||
if ( \is_numeric( $values['furl_name'] ) )
|
||||
{
|
||||
$values['furl_name'] = 'n' . $values['furl_name'];
|
||||
}
|
||||
}
|
||||
|
||||
if( array_key_exists( 'category_furl_name_choice', $values ) )
|
||||
@@ -719,6 +729,17 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
unset( $values[ 'database_' . $field ] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Are we changing where comments go? */
|
||||
if ( !$_new AND ( (int) $this->forum_record != (int) $values['forum_record'] OR (int) $this->forum_comments != (int) $values['forum_comments'] ) )
|
||||
{
|
||||
\IPS\Task::queue( 'cms', 'MoveComments', array(
|
||||
'databaseId' => $this->database()->id,
|
||||
'categoryId' => $this->_id,
|
||||
'to' => ( $values['forum_comments'] AND $values['forum_record'] ) ? 'forums' : 'pages',
|
||||
'deleteTopics' => (bool) ( !$values['forum_record'] )
|
||||
), 1, array( 'databaseId', 'to', 'categoryId' ) );
|
||||
}
|
||||
|
||||
if ( isset( $values['database_forum_forum'] ) )
|
||||
{
|
||||
@@ -768,7 +789,13 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$catPerms = $this->permissions(); /* Called to ensure it has a perm row */
|
||||
$dbPerms = \IPS\cms\Databases::load( $this->database_id )->permissions();
|
||||
|
||||
$this->_permissions = array_merge( $dbPerms, array( 'perm_id' => $catPerms['perm_id'], 'perm_type_id' => $this->_id, 'perm_type' => 'categories' ) );
|
||||
$this->_permissions = array_merge( $dbPerms, array( 'perm_id' => $catPerms['perm_id'], 'perm_type_id' => $this->_id, 'perm_type' => 'categories_' . $this->database_id ) );
|
||||
|
||||
if( $this->_permissions['perm_view'] === NULL )
|
||||
{
|
||||
$this->_permissions['perm_view'] = '';
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_permission_index', $this->_permissions, array( 'perm_id=?', $catPerms['perm_id'] ) );
|
||||
|
||||
/* Update tags permission cache */
|
||||
@@ -821,15 +848,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Db::i()->delete( 'core_tags_perms', array( 'tag_perm_aap_lookup=?', $aap ) );
|
||||
|
||||
/* Delete category follows */
|
||||
\IPS\Db::i()->delete( 'core_follow', array( "follow_app=? AND follow_area=? AND follow_rel_id=?", static::$permApp, static::$permType . $this->database()->id, $this->_id ) );
|
||||
|
||||
if( $this->hasChildren() )
|
||||
{
|
||||
foreach ( $this->children( NULL, NULL, TRUE ) as $child )
|
||||
{
|
||||
$child->delete();
|
||||
}
|
||||
}
|
||||
\IPS\Db::i()->delete( 'core_follow', array( "follow_app=? AND follow_area=? AND follow_rel_id=?", 'cms', 'categories' . $this->database()->id, $this->_id ) );
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
@@ -885,7 +904,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
foreach ( \IPS\Member\Group::groups() as $group )
|
||||
{
|
||||
if ( ! in_array( $group->g_id, $db ) )
|
||||
if ( ! \in_array( $group->g_id, $db ) )
|
||||
{
|
||||
$disabled[ $group->g_id ][] = $perm;
|
||||
}
|
||||
@@ -1064,7 +1083,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
public static function urlFromIndexData( $indexData, $itemData, $containerData )
|
||||
{
|
||||
$recordClass = $indexData['index_class'];
|
||||
if ( in_array( 'IPS\Content\Comment', class_parents( $recordClass ) ) )
|
||||
if ( \in_array( 'IPS\Content\Comment', class_parents( $recordClass ) ) )
|
||||
{
|
||||
$recordClass = $recordClass::$itemClass;
|
||||
}
|
||||
@@ -1088,29 +1107,30 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
* @param array|NULL $containerData Basic data about the author. Only includes columns returned by container::basicDataColumns()
|
||||
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
|
||||
* @param bool $escape If the title should be escaped for HTML output
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public static function titleFromIndexData( $indexData, $itemData, $containerData )
|
||||
public static function titleFromIndexData( $indexData, $itemData, $containerData, $escape = TRUE )
|
||||
{
|
||||
$recordClass = $indexData['index_class'];
|
||||
if ( in_array( 'IPS\Content\Comment', class_parents( $recordClass ) ) )
|
||||
if ( \in_array( 'IPS\Content\Comment', class_parents( $recordClass ) ) )
|
||||
{
|
||||
$recordClass = $recordClass::$itemClass;
|
||||
}
|
||||
|
||||
if ( $recordClass::database()->use_categories )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $indexData['index_container_id'] );
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $indexData['index_container_id'], NULL, $escape ? array( 'escape' => $escape ) : array() );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $recordClass::database()->_title;
|
||||
return $escape ? $recordClass::database()->_title : $recordClass::database()->getTitleForLanguage( \IPS\Member::loggedIn()->language() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Page Title for use in <title> tag
|
||||
* Get Page Title for use in `<title>` tag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -1154,6 +1174,24 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
return parent::get__title();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title for a node using the specified language object
|
||||
* This is commonly used where we cannot use the logged in member's language, such as sending emails
|
||||
*
|
||||
* @param \IPS\Lang $language Language object to fetch the title with
|
||||
* @param array $options What options to use for language parsing
|
||||
* @return string
|
||||
*/
|
||||
public function getTitleForLanguage( $language, $options=array() )
|
||||
{
|
||||
if ( ! \IPS\cms\Databases::load( $this->database_id )->use_categories )
|
||||
{
|
||||
return $language->addToStack( 'content_db_' . $this->database_id, NULL, $options );
|
||||
}
|
||||
|
||||
return parent::getTitleForLanguage( $language, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get Title language key, not added to a language stack
|
||||
@@ -1417,7 +1455,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'*',
|
||||
'cms_custom_database_' . $this->database_id,
|
||||
array( 'category_id=? AND record_approved=1 AND record_future_date=0', $this->id ),
|
||||
'record_last_comment DESC',
|
||||
'record_last_comment DESC, primary_id_field DESC', /* Just in case RSS imports the exact same time */
|
||||
array( 0, 1 ),
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -1471,7 +1509,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if ( $comment !== NULL and ( $database->_comment_bump & \IPS\cms\Databases::BUMP_ON_COMMENT ) )
|
||||
{
|
||||
$this->last_record_date = $comment->mapped('date');
|
||||
$this->last_record_member = intval( $comment->author()->member_id );
|
||||
$this->last_record_member = \intval( $comment->author()->member_id );
|
||||
$this->last_record_name = $comment->author()->member_id ? $comment->author()->name : NULL;
|
||||
$this->last_record_seo_name = \IPS\Http\Url\Friendly::seoTitle( $this->last_poster_name );
|
||||
$this->last_title = mb_substr( $comment->item()->mapped('title'), 0, 255 );
|
||||
@@ -1656,7 +1694,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_moderators' ) as $moderator )
|
||||
{
|
||||
if ( $moderator['perms'] === '*' or in_array( 'can_content_view_others_records', explode( ',', $moderator['perms'] ) ) )
|
||||
if ( $moderator['perms'] === '*' or \in_array( 'can_content_view_others_records', explode( ',', $moderator['perms'] ) ) )
|
||||
{
|
||||
if( $moderator['type'] === 'g' )
|
||||
{
|
||||
@@ -1671,7 +1709,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
$return = ( $normal == '*' ) ? array_unique( $return ) : array_intersect( explode( ',', $normal ), array_unique( $return ) );
|
||||
|
||||
if( count( $members ) )
|
||||
if( \count( $members ) )
|
||||
{
|
||||
$return = array_merge( $return, $members );
|
||||
}
|
||||
@@ -1709,7 +1747,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
$saved = json_decode( \IPS\Request::i()->cookie['cms_filters'], TRUE );
|
||||
|
||||
if ( array_key_exists( $this->id, $saved ) and count( $saved[ $this->id ] ) )
|
||||
if ( array_key_exists( $this->id, $saved ) and \count( $saved[ $this->id ] ) )
|
||||
{
|
||||
return $saved[ $this->id ];
|
||||
}
|
||||
@@ -1741,7 +1779,7 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$toSave = array();
|
||||
foreach( $values AS $key => $data )
|
||||
{
|
||||
if ( count( $data ) )
|
||||
if ( \is_numeric( $key ) or $key == 'cms_record_i_started' )
|
||||
{
|
||||
$toSave[$key] = $data;
|
||||
}
|
||||
@@ -1776,12 +1814,13 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* Check permissions
|
||||
*
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
|
||||
* @return bool
|
||||
* @throws \OutOfBoundsException If $permission does not exist in static::$permissionMap
|
||||
*/
|
||||
public function can( $permission, $member=NULL )
|
||||
public function can( $permission, $member=NULL, $considerPostBeforeRegistering = TRUE )
|
||||
{
|
||||
$_member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
@@ -1790,6 +1829,24 @@ class _Categories extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::can( $permission, $member );
|
||||
return parent::can( $permission, $member, $considerPostBeforeRegistering );
|
||||
}
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @param string $column Column to search
|
||||
* @param string $query Search query
|
||||
* @param string|null $order Column to order by
|
||||
* @param mixed $where Where clause
|
||||
* @return array
|
||||
*/
|
||||
public static function search( $column, $query, $order, $where=array() )
|
||||
{
|
||||
$results = parent::search( $column, $query, $order, $where );
|
||||
|
||||
return array_filter( $results, function( $node ){
|
||||
return $node->database_id == static::$customDatabaseId;
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Databases;
|
||||
|
||||
/* 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;
|
||||
@@ -38,7 +38,7 @@ abstract class _Controller extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
if ( $url === NULL )
|
||||
{
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
$exploded = explode( '\\', $class );
|
||||
$this->url = \IPS\Http\Url::internal( "app=cms&module=database", 'front' ); /* @todo fix URL */
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -27,6 +27,12 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'database_reciprocal_links', 'cms_databases' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
@@ -155,7 +161,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/**
|
||||
* @brief Page title
|
||||
*/
|
||||
protected static $pageTitle = NULL;
|
||||
protected $pageTitle = NULL;
|
||||
|
||||
/**
|
||||
* Return all databases
|
||||
@@ -169,7 +175,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* Avoid using SHOW TABLES LIKE / checkForTable() */
|
||||
try
|
||||
{
|
||||
foreach( static::getDatabaseDataFromStore() as $db )
|
||||
foreach( static::getStore() as $db )
|
||||
{
|
||||
$id = $db[ static::$databasePrefix . static::$databaseColumnId ];
|
||||
static::$multitons[ $id ] = static::constructFromData( $db );
|
||||
@@ -188,7 +194,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDatabaseDataFromStore()
|
||||
public static function getStore()
|
||||
{
|
||||
if ( ! isset( \IPS\Data\Store::i()->cms_databases ) )
|
||||
{
|
||||
@@ -231,6 +237,41 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can this database accept RSS imports?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canImportRss(): bool
|
||||
{
|
||||
if ( ! $this->page_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$fieldsClass = '\IPS\cms\Fields' . $this->id;
|
||||
|
||||
try
|
||||
{
|
||||
if ( ! \in_array( mb_ucfirst( $fieldsClass::load( $this->field_title )->type ), array( 'Text', 'TextArea', 'Editor' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! \in_array( mb_ucfirst( $fieldsClass::load( $this->field_content )->type ), array( 'TextArea', 'Editor' ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return data for the ACP Menu
|
||||
@@ -242,14 +283,15 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$menu = array();
|
||||
|
||||
foreach(
|
||||
\IPS\Db::i()->select( '*, core_sys_lang_words.word_custom as database_name', 'cms_databases', NULL, 'core_sys_lang_words.word_custom' )->join(
|
||||
'core_sys_lang_words', "core_sys_lang_words.word_key=CONCAT( 'content_db_', cms_databases.database_id ) AND core_sys_lang_words.lang_id=" . \IPS\Member::loggedIn()->language()->id
|
||||
)
|
||||
\IPS\Db::i()->select( '*, core_sys_lang_words.word_custom as database_name, core_sys_lang_words2.word_custom as record_name', 'cms_databases', NULL, 'core_sys_lang_words.word_custom' )
|
||||
->join( 'core_sys_lang_words', "core_sys_lang_words.word_key=CONCAT( 'content_db_', cms_databases.database_id ) AND core_sys_lang_words.lang_id=" . \IPS\Member::loggedIn()->language()->id )
|
||||
->join( array( 'core_sys_lang_words', 'core_sys_lang_words2' ), "core_sys_lang_words2.word_key=CONCAT( 'content_db_lang_pu_', cms_databases.database_id ) AND core_sys_lang_words2.lang_id=" . \IPS\Member::loggedIn()->language()->id )
|
||||
as $row )
|
||||
{
|
||||
$menu[] = array(
|
||||
'id' => $row['database_id'],
|
||||
'title' => $row['database_name'],
|
||||
'record_name' => $row['record_name'],
|
||||
'use_categories' => $row['database_use_categories']
|
||||
);
|
||||
}
|
||||
@@ -308,7 +350,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
$changes[] = "DROP " . \IPS\Db::i()->escape_string( $key );
|
||||
$changes[] = "DROP KEY `" . \IPS\Db::i()->escape_string( $key ) . "`";
|
||||
}
|
||||
|
||||
$changes[] = \IPS\Db::i()->buildIndex( $tableName, $data );
|
||||
@@ -317,14 +359,14 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
/* We collect all the changes so we can run one database query instead of, potentially, dozens */
|
||||
if( count( $changes ) )
|
||||
if( \count( $changes ) )
|
||||
{
|
||||
\IPS\Db::i()->query( "ALTER TABLE " . \IPS\Db::i()->prefix . $tableName . " " . implode( ', ', $changes ) );
|
||||
}
|
||||
|
||||
return $fixes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new database
|
||||
*
|
||||
@@ -439,7 +481,8 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
), array( 'perm_id=?', $perms['perm_id']) );
|
||||
|
||||
/* Create a category */
|
||||
$category = new \IPS\cms\Categories;
|
||||
$categoryClass = '\IPS\cms\Categories' . $database->id;
|
||||
$category = new $categoryClass;
|
||||
$category->database_id = $database->id;
|
||||
|
||||
$category->saveForm( $category->formatFormValues( array(
|
||||
@@ -543,10 +586,10 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
$roots = $categoryClass::roots( NULL );
|
||||
|
||||
if ( ! count( $roots ) )
|
||||
if ( ! \count( $roots ) )
|
||||
{
|
||||
/* Create a category */
|
||||
$category = new \IPS\cms\Categories;
|
||||
$category = new $categoryClass;
|
||||
$category->database_id = $this->id;
|
||||
|
||||
$catTitle = array();
|
||||
@@ -596,12 +639,12 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function get_fixed_field_perms()
|
||||
{
|
||||
if ( ! is_array( $this->_data['fixed_field_perms'] ) )
|
||||
if ( ! \is_array( $this->_data['fixed_field_perms'] ) )
|
||||
{
|
||||
$this->_data['fixed_field_perms'] = json_decode( $this->_data['fixed_field_perms'], true );
|
||||
}
|
||||
|
||||
if ( is_array( $this->_data['fixed_field_perms'] ) )
|
||||
if ( \is_array( $this->_data['fixed_field_perms'] ) )
|
||||
{
|
||||
return $this->_data['fixed_field_perms'];
|
||||
}
|
||||
@@ -617,7 +660,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function set_fixed_field_perms( $value )
|
||||
{
|
||||
$this->_data['fixed_field_perms'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['fixed_field_perms'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,12 +670,12 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function get_fixed_field_settings()
|
||||
{
|
||||
if ( ! is_array( $this->_data['fixed_field_settings'] ) )
|
||||
if ( ! \is_array( $this->_data['fixed_field_settings'] ) )
|
||||
{
|
||||
$this->_data['fixed_field_settings'] = json_decode( $this->_data['fixed_field_settings'], true );
|
||||
}
|
||||
|
||||
if ( is_array( $this->_data['fixed_field_settings'] ) )
|
||||
if ( \is_array( $this->_data['fixed_field_settings'] ) )
|
||||
{
|
||||
return $this->_data['fixed_field_settings'];
|
||||
}
|
||||
@@ -648,7 +691,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function set_fixed_field_settings( $value )
|
||||
{
|
||||
$this->_data['fixed_field_settings'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['fixed_field_settings'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,12 +701,12 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function get_featured_settings()
|
||||
{
|
||||
if ( ! is_array( $this->_data['featured_settings'] ) )
|
||||
if ( ! \is_array( $this->_data['featured_settings'] ) )
|
||||
{
|
||||
$this->_data['featured_settings'] = json_decode( $this->_data['featured_settings'], true );
|
||||
}
|
||||
|
||||
if ( is_array( $this->_data['featured_settings'] ) )
|
||||
if ( \is_array( $this->_data['featured_settings'] ) )
|
||||
{
|
||||
return $this->_data['featured_settings'];
|
||||
}
|
||||
@@ -679,7 +722,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function set_featured_settings( $value )
|
||||
{
|
||||
$this->_data['featured_settings'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['featured_settings'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -689,49 +732,83 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function pageTitle()
|
||||
{
|
||||
if ( static::$pageTitle === NULL )
|
||||
if ( $this->pageTitle === NULL )
|
||||
{
|
||||
if ( $this->use_as_page_title )
|
||||
{
|
||||
static::$pageTitle = $this->_title;
|
||||
$this->pageTitle = $this->_title;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
static::$pageTitle = \IPS\cms\Pages\Page::load( $this->page_id )->getHtmlTitle();
|
||||
$this->pageTitle = \IPS\cms\Pages\Page::load( $this->page_id )->getHtmlTitle();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
return static::$pageTitle;
|
||||
return $this->pageTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check permissions
|
||||
*
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index
|
||||
* @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member)
|
||||
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
|
||||
* @return bool
|
||||
* @throws \OutOfBoundsException If $permission does not exist in static::$permissionMap
|
||||
*/
|
||||
public function can( $permission, $member=NULL )
|
||||
public function can( $permission, $member=NULL, $considerPostBeforeRegistering = TRUE )
|
||||
{
|
||||
/* If we're looking from the front, make sure the database page also passes */
|
||||
if ( $permission === 'view' and \IPS\Dispatcher::hasInstance() and \IPS\Dispatcher::i()->controllerLocation === 'front' and $this->page_id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return parent::can( 'view', $member ) AND \IPS\cms\Pages\Page::load( $this->page_id )->can( 'view', $member );
|
||||
return parent::can( 'view', $member, $considerPostBeforeRegistering ) AND \IPS\cms\Pages\Page::load( $this->page_id )->can( 'view', $member, $considerPostBeforeRegistering );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
return parent::can( 'view', $member );
|
||||
return parent::can( 'view', $member, $considerPostBeforeRegistering );
|
||||
}
|
||||
}
|
||||
|
||||
return parent::can( $permission, $member );
|
||||
return parent::can( $permission, $member, $considerPostBeforeRegistering );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disabled permissions
|
||||
* Allow node classes to define permissions that are unselectable in the permission matrix
|
||||
*
|
||||
* @return array array( {group_id} => array( 'read', 'view', 'perm_7' );
|
||||
* @throws UnderflowException (if guest group ID is invalid)
|
||||
*/
|
||||
public function disabledPermissions()
|
||||
{
|
||||
$disabled = array();
|
||||
|
||||
try
|
||||
{
|
||||
$permissions = \IPS\cms\Pages\Page::load( $this->page_id )->permissions();
|
||||
|
||||
if( $permissions['perm_view'] != '*' )
|
||||
{
|
||||
$pageViewPermissions = explode( ',', $permissions['perm_view'] );
|
||||
|
||||
foreach ( \IPS\Member\Group::groups() as $group )
|
||||
{
|
||||
if ( ! \in_array( $group->g_id, $pageViewPermissions ) )
|
||||
{
|
||||
$disabled[ $group->g_id ] = array( 'view', 2, 3, 4, 5, 6, 7 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
|
||||
return $disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -764,7 +841,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Member::loggedIn()->language()->words['can_' . $lang . '_content_db_lang_sl_' . $this->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'can_' . $lang . '_record', FALSE, array( 'sprintf' => array( $this->recordWord( 1 ) ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['can_' . $lang . '_content_db_lang_su_' . $this->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'can_' . $lang . '_record', FALSE, array( 'sprintf' => array( $this->recordWord( 1, TRUE ) ) ) );
|
||||
|
||||
if ( in_array( $lang, array( 'edit', 'hide', 'unhide', 'view_hidden', 'delete' ) ) )
|
||||
if ( \in_array( $lang, array( 'edit', 'hide', 'unhide', 'view_hidden', 'delete' ) ) )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['can_' . $lang . '_content_record_comments_title_' . $this->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'can_' . $lang . '_rcomment', FALSE, array( 'sprintf' => array( $this->recordWord( 1 ) ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['can_' . $lang . '_content_record_reviews_title_' . $this->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'can_' . $lang . '_rreview', FALSE, array( 'sprintf' => array( $this->recordWord( 1 ) ) ) );
|
||||
@@ -811,9 +888,6 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
parent::save();
|
||||
|
||||
/* Clear cache */
|
||||
unset( \IPS\Data\Store::i()->cms_databases );
|
||||
|
||||
/* If this database isn't searchable, make sure its content is not in the search index */
|
||||
if( $removeSearchIndex )
|
||||
{
|
||||
@@ -876,7 +950,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* Delete notifications */
|
||||
$memberIds = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'member', 'core_notifications', array( 'item_class=? ', 'IPS\cms\Records' . $this->id ) ) as $member )
|
||||
foreach( \IPS\Db::i()->select( '`member`', 'core_notifications', array( 'item_class=? ', 'IPS\cms\Records' . $this->id ) ) as $member )
|
||||
{
|
||||
$memberIds[ $member ] = $member;
|
||||
}
|
||||
@@ -927,9 +1001,6 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
/* Delete the database record */
|
||||
parent::delete();
|
||||
|
||||
/* Best remove the stored data */
|
||||
unset( \IPS\Data\Store::i()->database_reciprocal_links, \IPS\Data\Store::i()->cms_databases );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -947,7 +1018,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$resaveBlock = NULL;
|
||||
foreach( $pageBlocks as $id => $pageBlock )
|
||||
{
|
||||
if( $pageBlock['app'] == 'cms' AND in_array( $pageBlock['key'], $databaseWidgets ) AND ! empty( $pageBlock['configuration']['database'] ) )
|
||||
if( $pageBlock['app'] == 'cms' AND \in_array( $pageBlock['key'], $databaseWidgets ) AND ! empty( $pageBlock['configuration']['database'] ) )
|
||||
{
|
||||
if ( $pageBlock['configuration']['database'] == $this->id )
|
||||
{
|
||||
@@ -968,12 +1039,11 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* Set the permission index permissions
|
||||
*
|
||||
* @param array $insert Permission data to insert
|
||||
* @param \IPS\Helpers\Form\Matrix $matrix \IPS\Helpers\Form\Matrix
|
||||
* @return void
|
||||
*/
|
||||
public function setPermissions( $insert, \IPS\Helpers\Form\Matrix $matrix )
|
||||
public function setPermissions( $insert )
|
||||
{
|
||||
parent::setPermissions( $insert, $matrix );
|
||||
parent::setPermissions( $insert );
|
||||
|
||||
/* Clear cache */
|
||||
unset( \IPS\Data\Store::i()->cms_databases );
|
||||
@@ -1060,7 +1130,7 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_array( $values ) )
|
||||
if ( \is_array( $values ) )
|
||||
{
|
||||
foreach( $values as $id => $fields )
|
||||
{
|
||||
@@ -1102,4 +1172,63 @@ class _Databases extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns database data from the store
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public static function getDatabaseDataFromStore()
|
||||
{
|
||||
return static::getStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
* @apiresponse bool useCategories If this database uses categories
|
||||
* @clientapiresponse [\IPS\cms\Fields] fields The fields
|
||||
* @apiresponse string url URL
|
||||
* @clientapiresponse object|null permissions Node permissions
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
$return = array(
|
||||
'id' => $this->id,
|
||||
'name' => $this->_title,
|
||||
'useCategories' => (bool) $this->use_categories,
|
||||
);
|
||||
|
||||
if ( $authorizedMember === NULL )
|
||||
{
|
||||
$return['fields'] = array();
|
||||
$fieldsClass = '\IPS\cms\Fields' . $this->id;
|
||||
foreach ( $fieldsClass::roots() as $field )
|
||||
{
|
||||
$return['fields'][] = $field->apiOutput( $authorizedMember );
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$pagePath = \IPS\cms\Pages\Page::loadByDatabaseId( $this->id )->full_path;
|
||||
$return['url'] = (string) \IPS\Http\Url::internal( "app=cms&module=pages&controller=page&path=" . $pagePath, 'front', 'content_page_path' );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
$return['url'] = NULL;
|
||||
}
|
||||
|
||||
if( $authorizedMember === NULL )
|
||||
{
|
||||
$return['permissions'] = \in_array( 'IPS\Node\Permissions', class_implements( \get_class( $this ) ) ) ? $this->permissions() : NULL;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Databases;
|
||||
|
||||
/* 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;
|
||||
@@ -72,7 +72,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
public function setDatabase( $databaseId )
|
||||
{
|
||||
/* Other areas rely on $this->databaseId being numeric */
|
||||
if ( ! is_numeric( $databaseId ) )
|
||||
if ( !\is_numeric( $databaseId ) )
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $databaseId, 'database_key' );
|
||||
$databaseId = $database->id;
|
||||
@@ -133,7 +133,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
{
|
||||
foreach( json_decode( $item['area_widgets'], TRUE ) as $block )
|
||||
{
|
||||
if ( $block['key'] === 'Database' and isset( $block['configuration']['database'] ) and intval( $block['configuration']['database'] ) === $this->databaseId )
|
||||
if ( $block['key'] === 'Database' and isset( $block['configuration']['database'] ) and \intval( $block['configuration']['database'] ) === $this->databaseId )
|
||||
{
|
||||
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID );
|
||||
}
|
||||
@@ -171,7 +171,9 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
{
|
||||
$path = '';
|
||||
}
|
||||
|
||||
|
||||
list( $path, $pageNumber ) = \IPS\cms\Pages\Page::getStrippedPagePath( $path );
|
||||
|
||||
$this->databaseId = $database->id;
|
||||
|
||||
if ( ! $database->use_categories )
|
||||
@@ -184,7 +186,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
{
|
||||
$this->module = 'category';
|
||||
}
|
||||
else if ( isset( \IPS\Request::i()->c ) AND is_numeric( \IPS\Request::i()->c ) )
|
||||
else if ( isset( \IPS\Request::i()->c ) AND \is_numeric( \IPS\Request::i()->c ) )
|
||||
{
|
||||
$this->categoryId = \IPS\Request::i()->c;
|
||||
$this->module = 'category';
|
||||
@@ -347,7 +349,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
$paramsToSet[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
if ( count( $paramsToSet ) )
|
||||
if ( \count( $paramsToSet ) )
|
||||
{
|
||||
$correctUrl = $correctUrl->setQueryString( $paramsToSet );
|
||||
}
|
||||
@@ -362,6 +364,6 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
return (string) $this->output;
|
||||
return (string) $this->output ?: \IPS\Output::i()->output;
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @todo: Shared media field type
|
||||
* @todo Shared media field type
|
||||
*
|
||||
*/
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -184,7 +184,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* @brief Fields that can be filtered on the front end. These appear in \Table advanced search and also in the DatabaseFilters widget.
|
||||
*/
|
||||
protected static $filterableFields = array( 'CheckboxSet', 'Radio', 'Select', 'YesNo', 'Date' );
|
||||
protected static $filterableFields = array( 'CheckboxSet', 'Radio', 'Select', 'YesNo', 'Date', 'Member' );
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
@@ -213,18 +213,19 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array() )
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
|
||||
{
|
||||
$permissionCheck = ( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation === 'admin' ) ? NULL : $permissionCheck;
|
||||
|
||||
if ( ! isset( static::$cache[ static::$customDatabaseId ][ $permissionCheck ] ) )
|
||||
{
|
||||
$langToLoad = array();
|
||||
$where[] = array('field_database_id=?', static::$customDatabaseId );
|
||||
$where[] = array( 'field_database_id=?', static::$customDatabaseId );
|
||||
|
||||
static::$cache[ static::$customDatabaseId ][ $permissionCheck ] = parent::roots( $permissionCheck, $member, $where );
|
||||
static::$cache[ static::$customDatabaseId ][ $permissionCheck ] = parent::roots( $permissionCheck, $member, $where, $limit );
|
||||
|
||||
foreach( static::$cache[ static::$customDatabaseId ][ $permissionCheck ] as $id => $obj )
|
||||
{
|
||||
@@ -239,7 +240,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$langToLoad[] = static::$langKey . '_' . $obj->id . '_warning';
|
||||
}
|
||||
|
||||
if ( count( $langToLoad ) AND \IPS\Dispatcher::hasInstance() and \IPS\Dispatcher::i()->controllerLocation !== 'setup' )
|
||||
if ( \count( $langToLoad ) AND \IPS\Dispatcher::hasInstance() and \IPS\Dispatcher::i()->controllerLocation !== 'setup' )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->get( $langToLoad );
|
||||
}
|
||||
@@ -285,7 +286,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $container->fields !== '*' AND $container->fields !== NULL )
|
||||
{
|
||||
if ( ! in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
if ( ! \in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -337,7 +338,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $container->fields !== '*' AND $container->fields !== NULL )
|
||||
{
|
||||
if ( ! in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
if ( ! \in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -400,7 +401,19 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$customValidationCode = function( $val ) use ( $database, $row, $record )
|
||||
{
|
||||
call_user_func_array( 'IPS\cms\Fields' . static::$customDatabaseId . '::validateUnique', array( $val, $row, $record ) );
|
||||
$class = 'IPS\cms\Fields' . static::$customDatabaseId;
|
||||
$class::validateUnique( $val, $row, $record );
|
||||
};
|
||||
}
|
||||
|
||||
if( $row->id == $database->field_title AND $row->type === 'Select' )
|
||||
{
|
||||
$customValidationCode = function( $val )
|
||||
{
|
||||
if( $val === NULL )
|
||||
{
|
||||
throw new \DomainException( 'form_required' );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -436,7 +449,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $container->fields !== '*' AND $container->fields !== NULL )
|
||||
{
|
||||
if ( ! in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
if ( ! \in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -479,7 +492,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $container->fields !== '*' AND $container->fields !== NULL )
|
||||
{
|
||||
if ( ! in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
if ( ! \in_array( $row->id, $container->fields ) AND $row->id != $database->field_title AND $row->id != $database->field_content )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -556,7 +569,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
* @param mixed $value Processed value
|
||||
* @param mixed $formValue Raw form value
|
||||
* @param string $type Type of display (listing/display/raw/processed).
|
||||
* @param NULL|\IPS\cms\Record $record Record showing this field
|
||||
* @param NULL|\IPS\cms\Records $record Record showing this field
|
||||
* @note Raw means the value saved from the input field, processed has the form display value method called. Listing and display take the options set by the field (badges, custom, etc)
|
||||
*
|
||||
* @return mixed|string
|
||||
@@ -584,7 +597,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
if ( $this->type === 'Item' )
|
||||
{
|
||||
if ( ! is_array( $formValue ) and mb_strstr( $formValue, ',' ) )
|
||||
if ( ! \is_array( $formValue ) and mb_strstr( $formValue, ',' ) )
|
||||
{
|
||||
$value = explode( ',', $formValue );
|
||||
}
|
||||
@@ -593,7 +606,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$value = array( $formValue );
|
||||
}
|
||||
|
||||
if ( count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
|
||||
if ( \count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
|
||||
{
|
||||
$results = array();
|
||||
$class = '\IPS\cms\Records' . $this->extra['database'];
|
||||
@@ -652,7 +665,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
if ( isset( $options[ $type ]['method'] ) AND $options[ $type ]['method'] !== 'simple' )
|
||||
{
|
||||
if ( in_array( $this->type, static::$mediaFields ) )
|
||||
if ( \in_array( $this->type, static::$mediaFields ) )
|
||||
{
|
||||
$template = mb_strtolower( $this->type );
|
||||
|
||||
@@ -747,7 +760,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
$parsed = array();
|
||||
foreach( $files as $file )
|
||||
foreach( $files as $idx => $file )
|
||||
{
|
||||
$file = \IPS\File::get( static::$uploadStorageExtension, (string) $file );
|
||||
|
||||
@@ -755,17 +768,44 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
\IPS\Output::i()->metaTags['og:image:url'][] = (string) $file->url;
|
||||
}
|
||||
|
||||
$downloadUrl = \IPS\Http\Url::internal( 'applications/core/interface/file/cfield.php', 'none' )->setqueryString( array(
|
||||
|
||||
$fileKey = \IPS\Text\Encrypt::fromPlaintext( (string) $file )->tag();
|
||||
$downloadUrl = \IPS\Http\Url::internal( 'applications/core/interface/file/cfield.php', 'none' )->setqueryString( array(
|
||||
'storage' => $file->storageExtension,
|
||||
'path' => (string) $file,
|
||||
'path' => (string) $file->originalFilename,
|
||||
'fileKey' => $fileKey
|
||||
) );
|
||||
|
||||
$parsed[] = \IPS\Theme::i()->getTemplate( 'global', 'cms', 'front' )->uploadDisplay( \IPS\File::get( static::$uploadStorageExtension, $file ), $record, $downloadUrl );
|
||||
$parsed[] = \IPS\Theme::i()->getTemplate( 'global', 'cms', 'front' )->uploadDisplay( \IPS\File::get( static::$uploadStorageExtension, $file ), $record, $downloadUrl, $fileKey );
|
||||
}
|
||||
|
||||
$value = implode( " ", $parsed );
|
||||
}
|
||||
else if ( $this->type === 'Member' )
|
||||
{
|
||||
if ( mb_strstr( $value, "\n" ) )
|
||||
{
|
||||
$members = explode( "\n", $formValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
$members = array( $formValue );
|
||||
}
|
||||
|
||||
$parsed = array();
|
||||
|
||||
foreach( $members as $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$parsed[] = \IPS\Member::load( $id )->link();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$value = implode( ", ", $parsed );
|
||||
|
||||
}
|
||||
|
||||
$value = \IPS\Theme::i()->getTemplate( 'records', 'cms', 'global' )->fieldBadge( $this->_title, $value, $class );
|
||||
}
|
||||
@@ -788,7 +828,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$files = array( $value );
|
||||
}
|
||||
|
||||
if ( count( $files ) )
|
||||
if ( \count( $files ) )
|
||||
{
|
||||
$parsed = array();
|
||||
foreach( $files AS $file )
|
||||
@@ -809,7 +849,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* Parse custom HTML
|
||||
*
|
||||
* @parse string $type Type of display
|
||||
* @param string $type Type of display
|
||||
* @param string $template The HTML to parse
|
||||
* @param string $formValue The form value (key of select box, for example)
|
||||
* @param string $value The display value
|
||||
@@ -834,7 +874,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $this->type === 'Upload' )
|
||||
{
|
||||
if ( is_array( $value ) )
|
||||
if ( \is_array( $value ) )
|
||||
{
|
||||
foreach( $value as $idx => $val )
|
||||
{
|
||||
@@ -859,7 +899,8 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
\IPS\Theme::runProcessFunction( $template, $functionName );
|
||||
|
||||
return call_user_func( 'IPS\\Theme\\'. $functionName, $value, $formValue, $this->_title, $record );
|
||||
$themeFunction = 'IPS\\Theme\\'. $functionName;
|
||||
return $themeFunction( $value, $formValue, $this->_title, $record );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -875,7 +916,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$fixedFields = \IPS\cms\Databases::load( static::$customDatabaseId )->fixed_field_perms;
|
||||
$perm = ( $where === 'form' ) ? 'perm_2' : 'perm_view';
|
||||
|
||||
if ( ! in_array( $field, array_keys( $fixedFields ) ) )
|
||||
if ( ! \in_array( $field, array_keys( $fixedFields ) ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -896,7 +937,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/* Finally check permissions */
|
||||
if( $member instanceof \IPS\Member\Group )
|
||||
{
|
||||
return ( $permissions[ $perm ] === '*' or ( $permissions[ $perm ] and in_array( $member->g_id, explode( ',', $permissions[ $perm ] ) ) ) );
|
||||
return ( $permissions[ $perm ] === '*' or ( $permissions[ $perm ] and \in_array( $member->g_id, explode( ',', $permissions[ $perm ] ) ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -914,7 +955,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$fixedFields = \IPS\cms\Databases::load( static::$customDatabaseId )->fixed_field_perms;
|
||||
|
||||
if ( $field !== NULL AND in_array( $field, array_keys( $fixedFields ) ) )
|
||||
if ( $field !== NULL AND \in_array( $field, array_keys( $fixedFields ) ) )
|
||||
{
|
||||
return $fixedFields[ $field ];
|
||||
}
|
||||
@@ -961,9 +1002,10 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
/**
|
||||
* Magic method to capture validateInput_{id} callbacks
|
||||
* @param string $name Name of method called
|
||||
* @param mixed $arguments Args passed
|
||||
* @param string $name Name of method called
|
||||
* @param mixed $arguments Args passed
|
||||
* @throws \InvalidArgumentException
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
@@ -971,7 +1013,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$id = mb_substr( $name, 14 );
|
||||
|
||||
if ( is_numeric( $id ) )
|
||||
if ( \is_numeric( $id ) )
|
||||
{
|
||||
$field = static::load( $id );
|
||||
}
|
||||
@@ -993,11 +1035,17 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
* @param string $val The value to check
|
||||
* @param \IPS\cms\Fields $field The field
|
||||
* @param \IPS\cms\Records $record The record (if any)
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public static function validateUnique( $val, $field, $record )
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( static::$customDatabaseId );
|
||||
|
||||
if( $field->type == 'Member' AND $val instanceof \IPS\Member )
|
||||
{
|
||||
$val = $val->member_id;
|
||||
}
|
||||
|
||||
$where = array( array( 'field_' . $field->id . '=?', $val ) );
|
||||
|
||||
@@ -1051,7 +1099,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
* Field custom template name
|
||||
*
|
||||
* @param string $type Type of name to fetch
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function fieldTemplateName( $type )
|
||||
{
|
||||
@@ -1061,12 +1109,12 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* Set the "display json" field
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_display_json( $value )
|
||||
{
|
||||
$this->_data['display_json'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['display_json'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1076,18 +1124,18 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function get_display_json()
|
||||
{
|
||||
return ( is_array( $this->_data['display_json'] ) ) ? $this->_data['display_json'] : json_decode( $this->_data['display_json'], TRUE );
|
||||
return ( \is_array( $this->_data['display_json'] ) ) ? $this->_data['display_json'] : json_decode( $this->_data['display_json'], TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "Format Options" field
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_format_opts( $value )
|
||||
{
|
||||
$this->_data['format_opts'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['format_opts'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1103,23 +1151,23 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* Set the "extra" field
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_extra( $value )
|
||||
{
|
||||
$this->_data['extra'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['extra'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "allowed_extensions" field
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function set_allowed_extensions( $value )
|
||||
{
|
||||
$this->_data['allowed_extensions'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['allowed_extensions'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1283,6 +1331,12 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
switch( mb_ucfirst( $this->type ) )
|
||||
{
|
||||
case 'Upload':
|
||||
/* We need to return NULL if there's no value, File::get will return an URL object even if $value is empty */
|
||||
if ( empty( $value ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return \IPS\File::get( 'cms_Records', $value )->url;
|
||||
break;
|
||||
case 'Text':
|
||||
@@ -1320,12 +1374,12 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$this->extra = $extra;
|
||||
}
|
||||
|
||||
if ( ! is_array( $value ) )
|
||||
if ( ! \is_array( $value ) )
|
||||
{
|
||||
$value = explode( ',', $value );
|
||||
}
|
||||
|
||||
if ( is_array( $value ) )
|
||||
if ( \is_array( $value ) )
|
||||
{
|
||||
$return = array();
|
||||
foreach( $value as $key )
|
||||
@@ -1347,10 +1401,16 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
return implode( ', ', array_map( function( $id )
|
||||
$links = array();
|
||||
|
||||
$value = \is_array( $value ) ? $value : ( ( $value instanceof \IPS\Member ) ? array( $value ) : explode( "\n", $value ) );
|
||||
|
||||
foreach( $value as $id )
|
||||
{
|
||||
return \IPS\Member::load( $id )->link();
|
||||
}, explode( "\n", $value ) ) );
|
||||
$links[] = ( $id instanceof \IPS\Member ) ? $id->link() : \IPS\Member::load( $id )->link();
|
||||
}
|
||||
|
||||
return implode( ', ', $links );
|
||||
}
|
||||
break;
|
||||
case 'Url':
|
||||
@@ -1361,7 +1421,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
break;
|
||||
case 'Date':
|
||||
case 'DateRange':
|
||||
if ( is_numeric( $value ) )
|
||||
if ( \is_numeric( $value ) )
|
||||
{
|
||||
$time = \IPS\DateTime::ts( $value );
|
||||
|
||||
@@ -1384,10 +1444,10 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
return \IPS\Lang::wordbreak( $this->extra['time'] ? (string) $time : $time->localeDate() );
|
||||
return $this->extra['time'] ? (string) $time : $time->localeDate();
|
||||
}
|
||||
|
||||
if ( ! is_array( $value ) )
|
||||
if ( ! \is_array( $value ) )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('field_no_value_entered');
|
||||
}
|
||||
@@ -1398,7 +1458,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( isset( $value[ $t ] ) )
|
||||
{
|
||||
$time = ( is_integer( $value[ $t ] ) ) ? \IPS\DateTime::ts( $value[ $t ], TRUE ) : $value[ $t ];
|
||||
$time = ( \is_integer( $value[ $t ] ) ) ? \IPS\DateTime::ts( $value[ $t ], TRUE ) : $value[ $t ];
|
||||
if ( isset( $this->extra['timezone'] ) and $this->extra['timezone'] )
|
||||
{
|
||||
try
|
||||
@@ -1430,7 +1490,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
break;
|
||||
case 'Item':
|
||||
if ( ! is_array( $value ) and mb_strstr( $value, ',' ) )
|
||||
if ( ! \is_array( $value ) and mb_strstr( $value, ',' ) )
|
||||
{
|
||||
$value = explode( ',', $value );
|
||||
}
|
||||
@@ -1439,7 +1499,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$value = array( $value );
|
||||
}
|
||||
|
||||
if ( count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
|
||||
if ( \count( $value ) and isset( $this->extra['database'] ) and $this->extra['database'] )
|
||||
{
|
||||
$results = array();
|
||||
$class = '\IPS\cms\Records' . $this->extra['database'];
|
||||
@@ -1477,7 +1537,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function applyFormatter( $value )
|
||||
{
|
||||
if ( is_array( $this->format_opts ) and count( $this->format_opts ) )
|
||||
if ( \is_array( $this->format_opts ) and \count( $this->format_opts ) )
|
||||
{
|
||||
foreach( $this->format_opts as $id => $type )
|
||||
{
|
||||
@@ -1548,7 +1608,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$buttons['set_as_title'] = array(
|
||||
'icon' => 'list-ul',
|
||||
'title' => 'cms_set_field_as_title',
|
||||
'link' => $url->setQueryString( array( 'do' => 'setAsTitle', 'id' => $this->_id ) ),
|
||||
'link' => $url->setQueryString( array( 'do' => 'setAsTitle', 'id' => $this->_id ) )->csrf(),
|
||||
'data' => array()
|
||||
);
|
||||
}
|
||||
@@ -1558,7 +1618,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$buttons['set_as_content'] = array(
|
||||
'icon' => 'file-text-o',
|
||||
'title' => 'cms_set_field_as_content',
|
||||
'link' => $url->setQueryString( array( 'do' => 'setAsContent', 'id' => $this->_id ) ),
|
||||
'link' => $url->setQueryString( array( 'do' => 'setAsContent', 'id' => $this->_id ) )->csrf(),
|
||||
'data' => array()
|
||||
);
|
||||
}
|
||||
@@ -1575,7 +1635,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function canBeTitleField()
|
||||
{
|
||||
if ( $this->is_multiple or in_array( mb_ucfirst( $this->type ), static::$cannotBeTitleFields ) )
|
||||
if ( $this->is_multiple or \in_array( mb_ucfirst( $this->type ), static::$cannotBeTitleFields ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1592,7 +1652,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$no = array();
|
||||
|
||||
if ( $this->is_multiple or in_array( mb_ucfirst( $this->type ), static::$cannotBeContentFields ) )
|
||||
if ( $this->is_multiple or \in_array( mb_ucfirst( $this->type ), static::$cannotBeContentFields ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1788,7 +1848,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$databases[ $db->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_relational_with_name_disabled', NULL, array( 'sprintf' => array( $db->_title ) ) );
|
||||
}
|
||||
}
|
||||
if ( ! count( $databases ) )
|
||||
if ( ! \count( $databases ) )
|
||||
{
|
||||
$databases[0] = \IPS\Member::loggedIn()->language()->addToStack('cms_relational_field_no_dbs');
|
||||
$disabled[] = 0;
|
||||
@@ -1848,7 +1908,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$tzValue = 'UTC';
|
||||
if ( isset( $this->extra['timezone'] ) and $this->extra['timezone'] )
|
||||
{
|
||||
if ( ! in_array( $this->extra['timezone'], array( 'UTC', 'user' ) ) )
|
||||
if ( ! \in_array( $this->extra['timezone'], array( 'UTC', 'user' ) ) )
|
||||
{
|
||||
$tzValue = 'set';
|
||||
}
|
||||
@@ -1895,7 +1955,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'field_max_length', $this->id ? $this->max_length : NULL, FALSE, array( 'unlimited' => 0 ), NULL, NULL, NULL, 'field_max_length' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'field_validator', $this->id ? intval( $this->validator ) : 0, FALSE, array(
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'field_validator', $this->id ? \intval( $this->validator ) : 0, FALSE, array(
|
||||
'togglesOn' =>array( 'field_validator_custom', 'field_validator_error' )
|
||||
), NULL, NULL, NULL, 'field_validator' ) );
|
||||
|
||||
@@ -2046,7 +2106,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'field_display_listing', $this->id ? $this->display_listing : 1, FALSE, array( 'togglesOn' => array('field_truncate', 'field_display_listing_json_badge') ), NULL, NULL, NULL, 'field_display_listing' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'field_display_listing_json_badge', $listingDefault, FALSE, array( 'options' => $listingOptions, 'toggles' => $listingToggles ), NULL, NULL, NULL, 'field_display_listing_json_badge' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'field_display_listing_json_badge', $listingDefault, FALSE, array( 'options' => $listingOptions, 'toggles' => $listingToggles, 'parse' => 'raw' ), NULL, NULL, NULL, 'field_display_listing_json_badge' ) );
|
||||
|
||||
if ( ! $isTitleOrContent )
|
||||
{
|
||||
@@ -2086,7 +2146,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'field_display_display', $this->id ? $this->display_display : 1, FALSE, array( 'togglesOn' => array( 'field_display_display_json_badge' ) ), NULL, NULL, NULL, 'field_display_display' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'field_display_display_json_badge', $displayDefault, FALSE, array( 'options' => $displayOptions, 'toggles' => $displayToggles ), NULL, NULL, NULL, 'field_display_display_json_badge' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'field_display_display_json_badge', $displayDefault, FALSE, array( 'options' => $displayOptions, 'toggles' => $displayToggles, 'parse' => 'raw' ), NULL, NULL, NULL, 'field_display_display_json_badge' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'field_show_map_display', $mapDisplay, FALSE, array(), NULL, NULL, NULL, 'field_show_map_display' ) );
|
||||
$form->add( new \IPS\Helpers\Form\WidthHeight( 'field_show_map_display_dims', $mapDisplayDims, FALSE, array( 'resizableDiv' => FALSE ), NULL, NULL, NULL, 'field_show_map_display_dims' ) );
|
||||
@@ -2138,7 +2198,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @todo Separate out the need for $this->save() to be called by moving the database table field creation to postSaveForm()
|
||||
* @todo Separate out the need for `$this->save()` to be called by moving the database table field creation to postSaveForm()
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
@@ -2146,7 +2206,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
static::$contentDatabaseTable = 'cms_custom_database_' . static::$customDatabaseId;
|
||||
|
||||
$values['field_max_length'] = ( isset( $values['field_max_length'] ) ) ? intval( $values['field_max_length'] ) : 0;
|
||||
$values['field_max_length'] = ( isset( $values['field_max_length'] ) ) ? \intval( $values['field_max_length'] ) : 0;
|
||||
|
||||
/* Work out the column definition */
|
||||
if( isset( $values['field_type'] ) )
|
||||
@@ -2159,7 +2219,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
case 'Radio':
|
||||
case 'Select':
|
||||
/* Reformat keyValue pairs */
|
||||
if ( isset( $values['field_extra'] ) AND is_array( $values['field_extra'] ) )
|
||||
if ( isset( $values['field_extra'] ) AND \is_array( $values['field_extra'] ) )
|
||||
{
|
||||
$extra = array();
|
||||
foreach( $values['field_extra'] as $row )
|
||||
@@ -2170,7 +2230,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $extra ) )
|
||||
if ( \count( $extra ) )
|
||||
{
|
||||
$values['field_extra'] = $extra;
|
||||
}
|
||||
@@ -2189,7 +2249,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
case 'Spotify':
|
||||
case 'Soundcloud':
|
||||
/* Reformat keyValue pairs */
|
||||
if ( isset( $values['media_params'] ) AND is_array( $values['media_params'] ) )
|
||||
if ( isset( $values['media_params'] ) AND \is_array( $values['media_params'] ) )
|
||||
{
|
||||
$extra = array();
|
||||
foreach( $values['media_params'] as $row )
|
||||
@@ -2200,7 +2260,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $extra ) )
|
||||
if ( \count( $extra ) )
|
||||
{
|
||||
$values['field_extra'] = $extra;
|
||||
}
|
||||
@@ -2304,7 +2364,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
if ( \in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
{
|
||||
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
|
||||
}
|
||||
@@ -2343,7 +2403,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
if ( \in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
{
|
||||
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
|
||||
}
|
||||
@@ -2379,7 +2439,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
if ( \in_array( $columnDefinition['type'], array( 'TEXT', 'MEDIUMTEXT' ) ) )
|
||||
{
|
||||
\IPS\Db::i()->addIndex( static::$contentDatabaseTable, array( 'type' => 'fulltext', 'name' => "field_{$this->id}", 'columns' => array( "field_{$this->id}" ) ) );
|
||||
}
|
||||
@@ -2424,7 +2484,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
if ( isset( $values['field_key'] ) AND ! $values['field_key'] )
|
||||
{
|
||||
if ( is_array( $values['field_title'] ) )
|
||||
if ( \is_array( $values['field_title'] ) )
|
||||
{
|
||||
/* We need to make sure the internal pointer on the array is on the first element */
|
||||
reset( $values['field_title'] );
|
||||
@@ -2459,7 +2519,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$displayJson = array( 'display' => array( 'method' => NULL ), 'listing' => array( 'method' => NULL ) );
|
||||
|
||||
/* Listing */
|
||||
if ( in_array( $values['field_type'], static::$mediaFields ) )
|
||||
if ( \in_array( $values['field_type'], static::$mediaFields ) )
|
||||
{
|
||||
$displayJson['listing']['method'] = $values['media_display_listing_method'];
|
||||
$displayJson['display']['method'] = $values['media_display_display_method'];
|
||||
@@ -2630,7 +2690,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
/* Remove the filter flag if this field cannot be filtered */
|
||||
if ( isset( $values['field_type'] ) AND isset( $values['field_filter'] ) AND $values['field_filter'] and ! in_array( $values['field_type'], static::$filterableFields ) )
|
||||
if ( isset( $values['field_type'] ) AND isset( $values['field_filter'] ) AND $values['field_filter'] and ! \in_array( $values['field_type'], static::$filterableFields ) )
|
||||
{
|
||||
$values['field_filter'] = false;
|
||||
}
|
||||
@@ -2682,7 +2742,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$custom = array( 'Youtube', 'Spotify', 'Soundcloud', 'Relational' );
|
||||
|
||||
if ( ! in_array( $this->type, $custom ) )
|
||||
if ( ! \in_array( $this->type, $custom ) )
|
||||
{
|
||||
return parent::canKeepValueOnChange( $newType );
|
||||
}
|
||||
@@ -2690,13 +2750,13 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
switch ( $this->type )
|
||||
{
|
||||
case 'Youtube':
|
||||
return in_array( $newType, array( 'Youtube', 'Text', 'TextArea' ) );
|
||||
return \in_array( $newType, array( 'Youtube', 'Text', 'TextArea' ) );
|
||||
|
||||
case 'Spotify':
|
||||
return in_array( $newType, array( 'Spotify', 'Text', 'TextArea' ) );
|
||||
return \in_array( $newType, array( 'Spotify', 'Text', 'TextArea' ) );
|
||||
|
||||
case 'Soundcloud':
|
||||
return in_array( $newType, array( 'Soundcloud', 'Text', 'TextArea' ) );
|
||||
return \in_array( $newType, array( 'Soundcloud', 'Text', 'TextArea' ) );
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@@ -2725,13 +2785,6 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->$functionName );
|
||||
}
|
||||
|
||||
$key = 'cms_fieldids_' . static::$customDatabaseId;
|
||||
|
||||
if ( isset( \IPS\Data\Store::i()->$key ) )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->$key );
|
||||
}
|
||||
|
||||
parent::save();
|
||||
}
|
||||
@@ -2746,20 +2799,10 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
static::$contentDatabaseTable = 'cms_custom_database_' . static::$customDatabaseId;
|
||||
static::$cache = array();
|
||||
|
||||
$key = 'cms_fieldids_' . static::$customDatabaseId;
|
||||
|
||||
if ( isset( \IPS\Data\Store::i()->$key ) )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->$key );
|
||||
}
|
||||
|
||||
/* Remove reciprocal map data */
|
||||
\IPS\Db::i()->delete( 'cms_database_fields_reciprocal_map', array( 'map_origin_database_id=? AND map_field_id=? ', static::$customDatabaseId, $this->id ) );
|
||||
|
||||
/* Best remove the stored data */
|
||||
unset( \IPS\Data\Store::i()->database_reciprocal_links );
|
||||
|
||||
parent::delete();
|
||||
|
||||
if( $skipDrop === TRUE )
|
||||
@@ -2785,11 +2828,11 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
*
|
||||
* @param mixed $value The value
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param \IPS\cms\Records|NULL $record The record
|
||||
* @param \IPS\cms\Records|NULL $content The record
|
||||
* @param int $flags Bit flags
|
||||
* @return \IPS\Helpers\Form\FormAbstract
|
||||
*/
|
||||
public function buildHelper( $value=NULL, $customValidationCode=NULL, \IPS\cms\Records $record = NULL, $flags=0 )
|
||||
public function buildHelper( $value=NULL, $customValidationCode=NULL, \IPS\Content $content = NULL, $flags=0 )
|
||||
{
|
||||
if ( class_exists( '\IPS\cms\Fields\\' . mb_ucfirst( $this->type ) ) )
|
||||
{
|
||||
@@ -2800,7 +2843,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$class = '\IPS\Helpers\Form\\' . mb_ucfirst( $this->type );
|
||||
|
||||
if ( !is_array( $this->extra ) )
|
||||
if ( !\is_array( $this->extra ) )
|
||||
{
|
||||
if ( method_exists( $class, 'formatOptions' ) )
|
||||
{
|
||||
@@ -2826,8 +2869,8 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$options['app'] = 'cms';
|
||||
$options['key'] = 'Records' . static::$customDatabaseId;
|
||||
$options['allowAttachments'] = $this->allow_attachments;
|
||||
$options['autoSaveKey'] = 'RecordField_' . ( $record === NULL ? 'new' : $record->_id ) . '_' . $this->id;
|
||||
$options['attachIds'] = ( $record === NULL ) ? NULL : array( $record->_id, $this->id, static::$customDatabaseId );
|
||||
$options['autoSaveKey'] = 'RecordField_' . ( $content === NULL ? 'new' : $content->_id ) . '_' . $this->id;
|
||||
$options['attachIds'] = ( $content === NULL ) ? NULL : array( $content->_id, $this->id, static::$customDatabaseId );
|
||||
break;
|
||||
case 'Email':
|
||||
case 'Password':
|
||||
@@ -2845,6 +2888,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
if ( $this->extra['type'] === 'image' )
|
||||
{
|
||||
$options['allowStockPhotos'] = TRUE;
|
||||
$options['image'] = array( 'maxWidth' => $this->extra['maxsize'][0], 'maxHeight' => $this->extra['maxsize'][1] );
|
||||
}
|
||||
else
|
||||
@@ -2862,7 +2906,7 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$options['multiple'] = TRUE;
|
||||
}
|
||||
|
||||
if( $value and ! is_array( $value ) )
|
||||
if( $value and ! \is_array( $value ) )
|
||||
{
|
||||
if ( mb_strstr( $value, ',' ) )
|
||||
{
|
||||
@@ -2908,15 +2952,15 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
$this->required = false;
|
||||
}
|
||||
|
||||
if ( $options['multiple'] and ! is_array( $value ) )
|
||||
if ( $options['multiple'] and ! \is_array( $value ) )
|
||||
{
|
||||
$exp = explode( ',', $value );
|
||||
$value = array();
|
||||
foreach( $exp as $val )
|
||||
{
|
||||
if ( is_numeric( $val ) and intval( $val ) == $val )
|
||||
if ( \is_numeric( $val ) and \intval( $val ) == $val )
|
||||
{
|
||||
$value[] = intval( $val );
|
||||
$value[] = \intval( $val );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2926,9 +2970,9 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( is_numeric( $value ) and intval( $value ) == $value )
|
||||
if ( \is_numeric( $value ) and \intval( $value ) == $value )
|
||||
{
|
||||
$value = intval( $value );
|
||||
$value = \intval( $value );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2949,19 +2993,20 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$value = NULL;
|
||||
}
|
||||
|
||||
|
||||
$options['multiple'] = $this->is_multiple ? NULL : 1;
|
||||
|
||||
if ( is_string( $value ) )
|
||||
|
||||
if ( \is_string( $value ) )
|
||||
{
|
||||
$value = array_map( function( $id )
|
||||
{
|
||||
return \IPS\Member::load( $id );
|
||||
return \IPS\Member::load( \intval( $id ) );
|
||||
}, explode( "\n", $value ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case 'Date':
|
||||
if ( is_numeric( $value ) )
|
||||
if ( \is_numeric( $value ) )
|
||||
{
|
||||
/* We want to normalize based on user time zone here */
|
||||
$value = \IPS\DateTime::ts( $value );
|
||||
@@ -3006,6 +3051,12 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
{
|
||||
$options['decimals'] = $this->extra['places'];
|
||||
}
|
||||
|
||||
if( !$this->required )
|
||||
{
|
||||
$options['unlimited'] = '';
|
||||
$options['unlimitedLang'] = 'cms_number_none';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3018,11 +3069,11 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
if ( $this->unique )
|
||||
{
|
||||
$field = $this;
|
||||
$customValidationCode = function( $val ) use ( $field, $record )
|
||||
$customValidationCode = function( $val ) use ( $field, $content )
|
||||
{
|
||||
call_user_func_array( 'IPS\cms\Fields' . static::$customDatabaseId . '::validateUnique', array( $val, $field, $record ) );
|
||||
\call_user_func_array( 'IPS\cms\Fields' . static::$customDatabaseId . '::validateUnique', array( $val, $field, $content ) );
|
||||
|
||||
return call_user_func( 'IPS\cms\Fields' . static::$customDatabaseId . '::validateInput_' . $field->id, $val );
|
||||
return \call_user_func( 'IPS\cms\Fields' . static::$customDatabaseId . '::validateInput_' . $field->id, $val );
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -3035,4 +3086,32 @@ class _Fields extends \IPS\CustomField implements \IPS\Node\Permissions
|
||||
|
||||
return new $class( 'content_field_' . $this->id, $value, $this->required, $options, $customValidationCode );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string title Title
|
||||
* @apiresponse string|null description Description
|
||||
* @apiresponse string type The field type - e.g. "Text", "Editor", "Radio"
|
||||
* @apiresponse string|null default The default value
|
||||
* @apiresponse bool required If the field is required
|
||||
* @apiresponse object|null options If the field has certain options (for example, it is a select field), the possible values
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'id' => $this->_id,
|
||||
'title' => $this->_title,
|
||||
'description' => $this->_description ?: NULL,
|
||||
'type' => $this->type,
|
||||
'default' => $this->default_value ?: NULL,
|
||||
'required' => (bool) $this->required,
|
||||
'options' => $this->extra
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Fields;
|
||||
|
||||
/* 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;
|
||||
@@ -32,17 +32,23 @@ class _Soundcloud extends \IPS\Helpers\Form\Text
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Sets that the field is required if there is a minimum length and vice-versa
|
||||
*
|
||||
* @see \IPS\Helpers\Form\Abstract::__construct
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
$this->childDefaultOptions['placeholder'] = \IPS\Member::loggedIn()->language()->addToStack('field_placeholder_soundcloud');
|
||||
|
||||
/* Call parent constructor */
|
||||
call_user_func_array( 'parent::__construct', func_get_args() );
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
$this->formType = 'text';
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Fields;
|
||||
|
||||
/* 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;
|
||||
@@ -32,17 +32,23 @@ class _Spotify extends \IPS\Helpers\Form\Text
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Sets that the field is required if there is a minimum length and vice-versa
|
||||
*
|
||||
* @see \IPS\Helpers\Form\Abstract::__construct
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
$this->childDefaultOptions['placeholder'] = \IPS\Member::loggedIn()->language()->addToStack('field_placeholder_spotify');
|
||||
|
||||
/* Call parent constructor */
|
||||
call_user_func_array( 'parent::__construct', func_get_args() );
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
$this->formType = 'text';
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Fields;
|
||||
|
||||
/* 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;
|
||||
@@ -32,17 +32,23 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Sets that the field is required if there is a minimum length and vice-versa
|
||||
*
|
||||
* @see \IPS\Helpers\Form\Abstract::__construct
|
||||
* @param string $name Name
|
||||
* @param mixed $defaultValue Default value
|
||||
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
|
||||
* @param array $options Type-specific options
|
||||
* @param callback $customValidationCode Custom validation code
|
||||
* @param string $prefix HTML to show before input field
|
||||
* @param string $suffix HTML to show after input field
|
||||
* @param string $id The ID to add to the row
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
|
||||
{
|
||||
$this->childDefaultOptions['placeholder'] = \IPS\Member::loggedIn()->language()->addToStack('field_placeholder_youtube');
|
||||
|
||||
/* Call parent constructor */
|
||||
call_user_func_array( 'parent::__construct', func_get_args() );
|
||||
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
|
||||
|
||||
$this->formType = 'text';
|
||||
}
|
||||
@@ -85,7 +91,8 @@ class _Youtube extends \IPS\Helpers\Form\Text
|
||||
|
||||
if ( ! isset( $params['height'] ) )
|
||||
{
|
||||
$params['height'] = 390;
|
||||
/* Videos on Youtube are in a 16:9 resolution ratio, but we need to give some extra space hence the 30px addition */
|
||||
$params['height'] = ( $params['width'] * ( 9 / 16 ) ) + 30;
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::external( $url )->setQueryString( $params );
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Media;
|
||||
|
||||
/* 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;
|
||||
@@ -26,13 +26,12 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* Munge different record types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function munge()
|
||||
{
|
||||
$rows = array();
|
||||
$args = func_get_args();
|
||||
$args = \func_get_args();
|
||||
|
||||
foreach( $args as $arg )
|
||||
{
|
||||
@@ -112,7 +111,10 @@ class _Folder extends \IPS\Node\Model
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
|
||||
|
||||
/**
|
||||
* @brief [Node] Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'cms',
|
||||
'module' => 'pages',
|
||||
@@ -142,8 +144,7 @@ class _Folder extends \IPS\Node\Model
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
@@ -299,7 +300,7 @@ class _Folder extends \IPS\Node\Model
|
||||
* Resets the stored path
|
||||
*
|
||||
* @param boolean $recursivelyCheck Recursively reset up and down the tree
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function resetPath( $recursivelyCheck=true )
|
||||
{
|
||||
@@ -310,7 +311,7 @@ class _Folder extends \IPS\Node\Model
|
||||
$path[] = $obj->name;
|
||||
}
|
||||
|
||||
$this->path = ( count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
$this->path = ( \count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
|
||||
/* Save path update */
|
||||
parent::save();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -150,7 +150,7 @@ class _Media extends \IPS\Node\Model
|
||||
public static function getChildren( $folderId=0 )
|
||||
{
|
||||
$children = array();
|
||||
foreach( \IPS\Db::i()->select( '*', static::$databaseTable, array( 'media_parent=?', intval( $folderId ) ), 'media_filename ASC' ) as $child )
|
||||
foreach( \IPS\Db::i()->select( '*', static::$databaseTable, array( 'media_parent=?', \intval( $folderId ) ), 'media_filename ASC' ) as $child )
|
||||
{
|
||||
$children[ $child[ static::$databasePrefix . static::$databaseColumnId ] ] = static::load( $child[ static::$databasePrefix . static::$databaseColumnId ] );
|
||||
}
|
||||
@@ -214,8 +214,7 @@ class _Media extends \IPS\Node\Model
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
@@ -438,7 +437,7 @@ class _Media extends \IPS\Node\Model
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! in_array( $currentParent, $folders ) )
|
||||
if ( ! \in_array( $currentParent, $folders ) )
|
||||
{
|
||||
$folders[] = $currentParent;
|
||||
}
|
||||
@@ -473,6 +472,8 @@ class _Media extends \IPS\Node\Model
|
||||
/**
|
||||
* Import media from disk for designer's mode recursive method
|
||||
*
|
||||
* @param array $seen Files we've seen already
|
||||
* @param string $path Path to look in
|
||||
* @return void
|
||||
*/
|
||||
public static function importDesignersModeMediaRecurse( &$seen, $path )
|
||||
@@ -538,7 +539,7 @@ class _Media extends \IPS\Node\Model
|
||||
$filename = array_pop( $exploded );
|
||||
$folderId = 0;
|
||||
|
||||
if ( count( $exploded ) )
|
||||
if ( \count( $exploded ) )
|
||||
{
|
||||
$testDir = trim( implode( '/', $exploded ), '/' );
|
||||
try
|
||||
|
||||
Whitespace-only changes.
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* 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;
|
||||
@@ -26,13 +26,12 @@ class _Folder extends \IPS\Node\Model
|
||||
/**
|
||||
* Munge different record types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function munge()
|
||||
{
|
||||
$rows = array();
|
||||
$args = func_get_args();
|
||||
$args = \func_get_args();
|
||||
|
||||
foreach( $args as $arg )
|
||||
{
|
||||
@@ -113,6 +112,9 @@ class _Folder extends \IPS\Node\Model
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'cms',
|
||||
'module' => 'pages',
|
||||
@@ -142,8 +144,7 @@ class _Folder extends \IPS\Node\Model
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
*
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
@@ -226,7 +227,7 @@ class _Folder extends \IPS\Node\Model
|
||||
$testPage = \IPS\cms\Pages\Page::load( $val, 'page_seo_name' );
|
||||
|
||||
/* Ok, we have a folder, but is it on the same tree as us ?*/
|
||||
if ( intval( \IPS\Request::i()->folder_parent_id ) == $testPage->folder_id )
|
||||
if ( \intval( \IPS\Request::i()->folder_parent_id ) == $testPage->folder_id )
|
||||
{
|
||||
/* Yep, this will break designers' mode and may confuse the FURL engine so we cannot allow this */
|
||||
throw new \InvalidArgumentException('content_folder_name_furl_collision_folder');
|
||||
@@ -256,7 +257,7 @@ class _Folder extends \IPS\Node\Model
|
||||
}
|
||||
} ) );
|
||||
|
||||
$class = get_called_class();
|
||||
$class = \get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Pages\Folder',
|
||||
@@ -362,7 +363,7 @@ class _Folder extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item count (if applicable) for a node.
|
||||
* Retrieve item \count(if applicable) for a node.
|
||||
*
|
||||
* @return int|bool
|
||||
*/
|
||||
@@ -388,7 +389,7 @@ class _Folder extends \IPS\Node\Model
|
||||
|
||||
if ( $hasContent )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cms_move_pages', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'cms_move_pages', 0, TRUE, array( 'class' => \get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
|
||||
{
|
||||
return \IPS\Request::i()->id != $node->id;
|
||||
} ) ) );
|
||||
@@ -443,7 +444,7 @@ class _Folder extends \IPS\Node\Model
|
||||
$path[] = $obj->name;
|
||||
}
|
||||
|
||||
$this->path = ( count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
$this->path = ( \count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
|
||||
/* Save path update */
|
||||
parent::save();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* 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;
|
||||
@@ -27,7 +27,13 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'frontNavigation' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
@@ -192,14 +198,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if ( isset( $qs['id'] ) )
|
||||
{
|
||||
if ( method_exists( get_called_class(), 'loadAndCheckPerms' ) )
|
||||
{
|
||||
return static::loadAndCheckPerms( $qs['id'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return static::load( $qs['id'] );
|
||||
}
|
||||
return static::load( $qs['id'] );
|
||||
}
|
||||
else if ( isset( $qs['path'] ) )
|
||||
{
|
||||
@@ -264,7 +263,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
public static function getChildren( $folderId=0 )
|
||||
{
|
||||
$children = array();
|
||||
foreach( \IPS\Db::i()->select( '*', static::$databaseTable, array( 'page_folder_id=?', intval( $folderId ) ), 'page_seo_name ASC' ) as $child )
|
||||
foreach( \IPS\Db::i()->select( '*', static::$databaseTable, array( 'page_folder_id=?', \intval( $folderId ) ), 'page_seo_name ASC' ) as $child )
|
||||
{
|
||||
$children[ $child[ static::$databasePrefix . static::$databaseColumnId ] ] = static::load( $child[ static::$databasePrefix . static::$databaseColumnId ] );
|
||||
}
|
||||
@@ -316,7 +315,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$bits = explode( '/', $path );
|
||||
$pathsToTry = array();
|
||||
|
||||
while( count( $bits ) )
|
||||
while( \count( $bits ) )
|
||||
{
|
||||
$pathsToTry[] = implode( '/', $bits );
|
||||
|
||||
@@ -370,7 +369,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @param string $slug Thing that lives in the garden and eats your plants
|
||||
* @param string|NULL $queryString Any query string to add to the end
|
||||
* @return \IPS\cms\Pages\Page
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public static function getUrlFromHistory( $slug, $queryString=NULL )
|
||||
{
|
||||
@@ -409,7 +408,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* Do we have a page with this path? */
|
||||
try
|
||||
{
|
||||
return static::load( $newPath, 'page_full_path' );
|
||||
return static::load( $newPath, 'page_full_path' )->url();
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
@@ -441,7 +440,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* Try the easiest method first */
|
||||
try
|
||||
{
|
||||
static::$defaultPage[ $folderId ] = \IPS\cms\Pages\Page::load( \IPS\Db::i()->select( 'page_id', static::$databaseTable, array( 'page_default=? AND page_folder_id=?', 1, intval( $folderId ) ) )->first() );
|
||||
static::$defaultPage[ $folderId ] = \IPS\cms\Pages\Page::load( \IPS\Db::i()->select( 'page_id', static::$databaseTable, array( 'page_default=? AND page_folder_id=?', 1, \intval( $folderId ) ) )->first() );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
@@ -477,7 +476,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public static function deleteCompiled( $ids )
|
||||
{
|
||||
if ( is_numeric( $ids ) )
|
||||
if ( \is_numeric( $ids ) )
|
||||
{
|
||||
$ids = array( $ids );
|
||||
}
|
||||
@@ -595,7 +594,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$testFolder = \IPS\cms\Pages\Folder::load( $val, 'folder_name' );
|
||||
|
||||
/* Ok, we have a folder, but is it on the same tree as us ?*/
|
||||
if ( intval( \IPS\Request::i()->page_folder_id ) == $testFolder->parent_id )
|
||||
if ( \intval( \IPS\Request::i()->page_folder_id ) == $testFolder->parent_id )
|
||||
{
|
||||
/* Yep, this will break designers' mode and may confuse the FURL engine so we cannot allow this */
|
||||
throw new \InvalidArgumentException('content_folder_name_furl_collision_pages');
|
||||
@@ -626,7 +625,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
/* Not us */
|
||||
if ( intval( \IPS\Request::i()->page_folder_id ) == $test->folder_id )
|
||||
if ( \intval( \IPS\Request::i()->page_folder_id ) == $test->folder_id )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'content_page_file_name_in_use' );
|
||||
}
|
||||
@@ -638,7 +637,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}, NULL, NULL, 'page_seo_name' );
|
||||
|
||||
$return['page_folder_id'] = new \IPS\Helpers\Form\Node( 'page_folder_id', ( $item ? intval( $item->folder_id ) : ( ( isset( \IPS\Request::i()->parent ) and \IPS\Request::i()->parent ) ? \IPS\Request::i()->parent : 0 ) ), FALSE, array(
|
||||
$return['page_folder_id'] = new \IPS\Helpers\Form\Node( 'page_folder_id', ( $item ? \intval( $item->folder_id ) : ( ( isset( \IPS\Request::i()->parent ) and \IPS\Request::i()->parent ) ? \IPS\Request::i()->parent : 0 ) ), FALSE, array(
|
||||
'class' => 'IPS\cms\Pages\Folder',
|
||||
'zeroVal' => 'node_no_parent',
|
||||
'subnodes' => false
|
||||
@@ -666,7 +665,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
'options' => $wrapperTemplates
|
||||
), NULL, NULL, \IPS\Theme::i()->getTemplate( 'pages', 'cms', 'admin' )->previewTemplateLink(), 'page_wrapper_template' );
|
||||
|
||||
if ( count( \IPS\Theme::themes() ) > 1 )
|
||||
if ( \count( \IPS\Theme::themes() ) > 1 )
|
||||
{
|
||||
$themes = array( 0 => 'cms_page_theme_id_default' );
|
||||
foreach ( \IPS\Theme::themes() as $theme )
|
||||
@@ -692,12 +691,12 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$js = \IPS\cms\Templates::getTemplates( \IPS\cms\Templates::RETURN_ONLY_JS + \IPS\cms\Templates::RETURN_DATABASE_ONLY );
|
||||
$css = \IPS\cms\Templates::getTemplates( \IPS\cms\Templates::RETURN_ONLY_CSS + \IPS\cms\Templates::RETURN_DATABASE_ONLY );
|
||||
|
||||
if ( count( $js ) OR count( $css ) )
|
||||
if ( \count( $js ) OR \count( $css ) )
|
||||
{
|
||||
$return['tab_js_css'] = array( 'content_page_form_tab__includes', NULL, NULL, 'ipsForm_horizontal' );
|
||||
$return['msg_js_css'] = array( 'cms_page_includes_message', 'ipsMessage ipsMessage_info ipsCmsIncludesMessage' );
|
||||
|
||||
if ( count( $js ) )
|
||||
if ( \count( $js ) )
|
||||
{
|
||||
$jsincludes = array();
|
||||
foreach( $js as $obj )
|
||||
@@ -709,7 +708,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$return['page_includes_js'] = new \IPS\Helpers\Form\CheckboxSet( 'page_includes_js', $item ? $item->js_includes : FALSE, FALSE, array( 'options' => $jsincludes, 'multiple' => true ), NULL, NULL, NULL, 'page_includes_js' );
|
||||
}
|
||||
|
||||
if ( count( $css ) )
|
||||
if ( \count( $css ) )
|
||||
{
|
||||
$cssincludes = array();
|
||||
foreach( $css as $obj )
|
||||
@@ -725,34 +724,14 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if ( $pageType === 'html' )
|
||||
{
|
||||
$return['tab_content'] = array( 'content_page_form_tab__content', NULL, NULL, 'ipsForm_vertical' );
|
||||
|
||||
$tags = array();
|
||||
|
||||
if ( $item and $item->id == \IPS\Settings::i()->cms_error_page )
|
||||
{
|
||||
$tags['cms_error_page']['{error_message}'] = 'cms_error_page_message';
|
||||
$tags['cms_error_page']['{error_code}'] = 'cms_error_page_code';
|
||||
}
|
||||
|
||||
foreach( \IPS\cms\Databases::roots( NULL, NULL ) as $id => $db )
|
||||
{
|
||||
if ( ! $db->page_id )
|
||||
{
|
||||
$tags['cms_tag_databases']['{database="' . $db->key . '"}'] = $db->_title;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( \IPS\cms\Blocks\Block::roots( NULL, NULL ) as $id => $block )
|
||||
$tagSource = \IPS\Http\Url::internal( "app=cms&module=pages&controller=ajax&do=loadTags" );
|
||||
if ( $item )
|
||||
{
|
||||
$tags['cms_tag_blocks']['{block="' . $block->key . '"}'] = $block->_title;
|
||||
$tagSource = $tagSource->setQueryString( 'pageId', $item->id );
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_pages', NULL, 'page_full_path ASC', array( 0, 50 ) ) as $page )
|
||||
{
|
||||
$tags['cms_tag_pages']['{pageurl="' . $page['page_full_path'] . '"}' ] = \IPS\Member::loggedIn()->language()->addToStack( static::$titleLangPrefix . $page['page_id'] );
|
||||
}
|
||||
|
||||
$return['page_content'] = new \IPS\Helpers\Form\Codemirror( 'page_content', $item ? htmlentities( $item->content, ENT_DISALLOWED, 'UTF-8', TRUE ) : NULL, FALSE, array( 'tags' => $tags, 'height' => 600 ), function( $val )
|
||||
$return['page_content'] = new \IPS\Helpers\Form\Codemirror( 'page_content', $item ? htmlentities( $item->content, ENT_DISALLOWED, 'UTF-8', TRUE ) : NULL, FALSE, array( 'tagSource' => $tagSource, 'height' => 600 ), function( $val )
|
||||
{
|
||||
/* Test */
|
||||
try
|
||||
@@ -770,26 +749,34 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
preg_match( '#{database="([^"]+?)"#', $val, $matches );
|
||||
if ( isset( $matches[1] ) )
|
||||
{
|
||||
try
|
||||
$database = NULL;
|
||||
|
||||
if ( \is_numeric( $matches[1] ) )
|
||||
{
|
||||
if ( is_numeric( $matches[1] ) )
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( intval( $matches[1] ) );
|
||||
$database = \IPS\cms\Databases::load( \intval( $matches[1] ) );
|
||||
}
|
||||
else
|
||||
catch( \OutOfRangeException $ex ){}
|
||||
}
|
||||
|
||||
if( $database === NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( $matches[1], 'database_key' );
|
||||
}
|
||||
|
||||
if ( $database->page_id )
|
||||
{
|
||||
throw new \LogicException('cms_err_db_in_use_other_page');
|
||||
}
|
||||
catch( \OutOfRangeException $ex ){}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
|
||||
if( $database === NULL )
|
||||
{
|
||||
throw new \LogicException('cms_err_db_does_not_exist');
|
||||
}
|
||||
elseif( $database->page_id )
|
||||
{
|
||||
throw new \LogicException('cms_err_db_in_use_other_page');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, NULL, NULL, 'page_content' );
|
||||
@@ -846,6 +833,12 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Cannot have /page/ as it confuses SEO pagination */
|
||||
if ( mb_strstr( '/' . $path . '/', '/page/' ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$defaultApplication = \IPS\Db::i()->select( 'app_directory', 'core_applications', 'app_default=1' )->first();
|
||||
|
||||
foreach( \IPS\Application::applications() as $key => $app )
|
||||
@@ -942,6 +935,8 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->pages_page_urls = $store;
|
||||
|
||||
\IPS\Member::clearCreateMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -949,7 +944,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPageUrlStore()
|
||||
public static function getStore()
|
||||
{
|
||||
if ( ! isset( \IPS\Data\Store::i()->pages_page_urls ) )
|
||||
{
|
||||
@@ -958,6 +953,53 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
return \IPS\Data\Store::i()->pages_page_urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns (and builds if required) the pages id => url datastore
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public static function getPageUrlStore()
|
||||
{
|
||||
return static::getStore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page path, returning stripped path and current page number
|
||||
*
|
||||
* @param string $path Page path
|
||||
* @return array Current path, Current page number
|
||||
*/
|
||||
public static function getStrippedPagePath( string $path ): array
|
||||
{
|
||||
/* Have a bash at pagination as it's not like we've much else to do */
|
||||
$stripped = \IPS\Http\Url\Friendly::stripPageComponent( '/' . trim( $path, '/' ) . '/' );
|
||||
|
||||
if ( trim( $path, '/' ) != trim( $stripped, '/' ) )
|
||||
{
|
||||
if ( $stripped !== '/' )
|
||||
{
|
||||
$pageStuff = str_replace( ltrim( $stripped, '/' ), '', $path );
|
||||
}
|
||||
else
|
||||
{
|
||||
$pageStuff = $path;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return array( $path, NULL );
|
||||
}
|
||||
|
||||
$bomb = explode( '/', $pageStuff );
|
||||
if ( !empty( $bomb[1] ) )
|
||||
{
|
||||
return array( trim( $stripped, '/' ), $bomb[1] );
|
||||
}
|
||||
|
||||
return array( $path, NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set JS/CSS include keys
|
||||
@@ -967,7 +1009,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
public function set__js_css_ids( $value )
|
||||
{
|
||||
$this->_data['js_css_ids'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['js_css_ids'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -977,12 +1019,12 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
*/
|
||||
protected function get__js_css_ids()
|
||||
{
|
||||
if ( ! is_array( $this->_data['js_css_ids'] ) )
|
||||
if ( ! \is_array( $this->_data['js_css_ids'] ) )
|
||||
{
|
||||
$this->_data['js_css_ids'] = json_decode( $this->_data['js_css_ids'], true );
|
||||
}
|
||||
|
||||
return ( is_array( $this->_data['js_css_ids'] ) ) ? $this->_data['js_css_ids'] : array();
|
||||
return ( \is_array( $this->_data['js_css_ids'] ) ) ? $this->_data['js_css_ids'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1035,7 +1077,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
foreach( array( 'js', 'css' ) as $thing )
|
||||
{
|
||||
$includeKey = $thing . '_includes';
|
||||
if ( count( $this->$includeKey ) )
|
||||
if ( \count( $this->$includeKey ) )
|
||||
{
|
||||
/* Build a file object for each thing */
|
||||
foreach( $this->$includeKey as $key )
|
||||
@@ -1069,7 +1111,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
\IPS\Theme::lock( "page_object_build" . $this->id );
|
||||
|
||||
if ( count( $this->js_includes ) )
|
||||
if ( \count( $this->js_includes ) )
|
||||
{
|
||||
/* Build a file object for each JS */
|
||||
foreach( $this->js_includes as $key )
|
||||
@@ -1088,7 +1130,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $this->css_includes ) )
|
||||
if ( \count( $this->css_includes ) )
|
||||
{
|
||||
/* Build a file object for each JS */
|
||||
foreach( $this->css_includes as $key )
|
||||
@@ -1123,7 +1165,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
foreach( $return as $type => $data )
|
||||
{
|
||||
if ( is_array( $data ) )
|
||||
if ( \is_array( $data ) )
|
||||
{
|
||||
foreach( $data as $key => $object )
|
||||
{
|
||||
@@ -1154,7 +1196,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
$extension = mb_substr( $this->seo_name, ( mb_strrpos( $this->seo_name, '.' ) + 1 ) );
|
||||
|
||||
if ( in_array( $extension, array_keys( $map ) ) )
|
||||
if ( \in_array( $extension, array_keys( $map ) ) )
|
||||
{
|
||||
return $map[ $extension ];
|
||||
}
|
||||
@@ -1215,7 +1257,8 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Theme::runProcessFunction( \IPS\Data\Store::i()->$functionName, $functionName );
|
||||
}
|
||||
|
||||
return call_user_func( 'IPS\\Theme\\'. $functionName );
|
||||
$themeFunction = 'IPS\\Theme\\'. $functionName;
|
||||
return $themeFunction();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1259,8 +1302,9 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $widgets ) )
|
||||
if( \count( $widgets ) )
|
||||
{
|
||||
$googleFonts = array();
|
||||
foreach ( $widgets as $areaKey => $area )
|
||||
{
|
||||
foreach ( $area as $widget )
|
||||
@@ -1285,9 +1329,25 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
$_widget = \IPS\Widget::load( $appOrPlugin, $widget['key'], $widget['unique'], ( isset( $widget['configuration'] ) ) ? $widget['configuration'] : array(), ( isset( $widget['restrict'] ) ? $widget['restrict'] : null ), $orientation );
|
||||
|
||||
if ( \in_array( 'IPS\Widget\Builder', class_implements( $_widget ) ) )
|
||||
{
|
||||
if ( ! empty( $_widget->configuration['widget_adv__font'] ) and $_widget->configuration['widget_adv__font'] !== 'inherit' )
|
||||
{
|
||||
$font = $_widget->configuration['widget_adv__font'];
|
||||
|
||||
if ( \mb_substr( $font, -6 ) === ' black' )
|
||||
{
|
||||
$fontWeight = 900;
|
||||
$font = \mb_substr( $font, 0, -6 ) . ':400,900';
|
||||
}
|
||||
|
||||
$googleFonts[ $font ] = $font;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( in_array( $areaKey, array('header', 'footer', 'sidebar' ) ) )
|
||||
if ( \in_array( $areaKey, array('header', 'footer', 'sidebar' ) ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['widgets'][ $areaKey ][] = $_widget;
|
||||
}
|
||||
@@ -1300,6 +1360,11 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $googleFonts ) )
|
||||
{
|
||||
\IPS\Output::i()->linkTags['googlefonts'] = array('rel' => 'stylesheet', 'href' => "https://fonts.googleapis.com/css?family=" . implode( "|", array_values( $googleFonts ) ) . "&display=swap");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cachedWidgets;
|
||||
@@ -1364,7 +1429,16 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$return['default'] = array(
|
||||
'icon' => $this->default ? 'star' : 'star-o',
|
||||
'title' => 'content_default_page',
|
||||
'link' => $url->setQueryString( array( 'id' => $this->id, 'subnode' => 1, 'do' => 'setAsDefault' ) )
|
||||
'link' => $url->setQueryString( array( 'id' => $this->id, 'subnode' => 1, 'do' => 'setAsDefault' ) )->csrf()
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_edit' ) and $this->type !== 'builder' )
|
||||
{
|
||||
$return['default_error'] = array(
|
||||
'icon' => \IPS\Settings::i()->cms_error_page == $this->id ? 'exclamation-circle' : 'exclamation',
|
||||
'title' => \IPS\Settings::i()->cms_error_page == $this->id ? 'content_remove_error_page' : 'content_default_error_page',
|
||||
'link' => $url->setQueryString( array( 'id' => \IPS\Settings::i()->cms_error_page ? 0 : $this->id, 'subnode' => 1, 'do' => 'toggleDefaultError' ) )->csrf()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1411,25 +1485,25 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
foreach( static::formElements( $this ) as $name => $field )
|
||||
{
|
||||
if ( $pageType !== 'html' and in_array( $name, array( 'page_ipb_wrapper', 'page_show_sidebar', 'page_wrapper_template' ) ) )
|
||||
if ( $pageType !== 'html' and \in_array( $name, array( 'page_ipb_wrapper', 'page_show_sidebar', 'page_wrapper_template' ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $pageType === 'html' and in_array( $name, array( 'page_template' ) ) )
|
||||
if ( $pageType === 'html' and \in_array( $name, array( 'page_template' ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( is_array( $field ) )
|
||||
if ( \is_array( $field ) )
|
||||
{
|
||||
if ( mb_substr( $name, 0, 4 ) === 'tab_' )
|
||||
{
|
||||
call_user_func_array( array( $form, 'addTab' ), $field );
|
||||
$form->addTab( ...$field );
|
||||
}
|
||||
else if ( mb_substr( $name, 0, 4 ) === 'msg_' )
|
||||
{
|
||||
call_user_func_array( array( $form, 'addMessage' ), $field );
|
||||
$form->addMessage( ...$field );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1440,7 +1514,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if ( ! $this->id )
|
||||
{
|
||||
$form->addTab( 'content_page_form_tab__menu' );
|
||||
$form->addTab( 'content_page_form_tab__menu', NULL, NULL, 'ipsForm_horizontal' );
|
||||
$toggles = array( 'menu_manager_access_type', 'menu_parent' );
|
||||
$formFields = array();
|
||||
|
||||
@@ -1523,7 +1597,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if( isset( $values['page_name'] ) )
|
||||
{
|
||||
$_copied = $values['page_name'];
|
||||
$values['page_seo_name'] = empty( $values['page_seo_name'] ) ? ( is_array( $_copied ) ? array_shift( $_copied ) : $_copied ) : $values['page_seo_name'];
|
||||
$values['page_seo_name'] = empty( $values['page_seo_name'] ) ? ( \is_array( $_copied ) ? array_shift( $_copied ) : $_copied ) : $values['page_seo_name'];
|
||||
|
||||
$bits = explode( '.', $values['page_seo_name'] );
|
||||
foreach( $bits as $i => $v )
|
||||
@@ -1621,8 +1695,6 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_menu', array( 'config' => json_encode( $config ) ), array( 'id=?', $id ) );
|
||||
|
||||
unset( \IPS\Data\Store::i()->frontNavigation );
|
||||
}
|
||||
|
||||
unset( $values['page_add_to_menu'], $values['menu_title_page_type'], $values['menu_title_page'], $values['menu_parent'], $values['menu_manager_access'], $values['menu_manager_access_type'] );
|
||||
@@ -1700,9 +1772,9 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if ( isset( $matches[1] ) )
|
||||
{
|
||||
if ( is_numeric( $matches[1] ) )
|
||||
if ( \is_numeric( $matches[1] ) )
|
||||
{
|
||||
return intval( $matches[1] );
|
||||
return \intval( $matches[1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1735,19 +1807,10 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
if( $this->_url === NULL )
|
||||
{
|
||||
if ( ( \IPS\Application::load('cms')->default OR \IPS\Settings::i()->cms_use_different_gateway ) AND $this->default AND ! $this->folder_id )
|
||||
if ( \IPS\Application::load('cms')->default AND $this->default AND ! $this->folder_id )
|
||||
{
|
||||
/* Are we using the gateway file? */
|
||||
if ( \IPS\Settings::i()->cms_use_different_gateway )
|
||||
{
|
||||
/* Yes, work out the proper URL. */
|
||||
$this->_url = \IPS\Http\Url::createFromString( \IPS\Settings::i()->cms_root_page_url, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No - that's easy */
|
||||
$this->_url = \IPS\Http\Url::internal( '', 'front' );
|
||||
}
|
||||
/* No - that's easy */
|
||||
$this->_url = \IPS\Http\Url::internal( '', 'front' );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1808,7 +1871,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
try
|
||||
{
|
||||
call_user_func( array( $pluginClass, $method ), $value, $options, $this );
|
||||
$pluginClass::$method( $value, $options, $this );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
@@ -1835,7 +1898,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
}
|
||||
catch( \LogicException $e ) { }
|
||||
|
||||
$this->mapToDatabase( intval( $database->id ) );
|
||||
$this->mapToDatabase( \intval( $database->id ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1912,7 +1975,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
if ( $databaseUsed !== NULL )
|
||||
{
|
||||
$this->mapToDatabase( intval( $databaseUsed ) );
|
||||
$this->mapToDatabase( \intval( $databaseUsed ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1943,7 +2006,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* is this page already in use */
|
||||
$database = \IPS\cms\Databases::load( $this->id, 'database_page_id' );
|
||||
|
||||
if ( $database->id === $databaseId )
|
||||
if ( $database->id == $databaseId )
|
||||
{
|
||||
/* Nothing to update as this page is mapped to this database */
|
||||
return TRUE;
|
||||
@@ -1951,7 +2014,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
else
|
||||
{
|
||||
/* We're using another DB on this page */
|
||||
throw new \LogicException('cms_err_db_already_on_page');
|
||||
throw new \LogicException('cms_err_db_already_on_page' );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
@@ -1972,6 +2035,10 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
/* Restore content in the search index */
|
||||
\IPS\Task::queue( 'core', 'RebuildSearchIndex', array( 'class' => 'IPS\cms\Records' . $database->id ) );
|
||||
|
||||
/* Restore content in social promote table */
|
||||
$class = 'IPS\cms\Records' . $database->id;
|
||||
\IPS\core\Promote::changeHiddenByClass( new $class, FALSE );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -1993,6 +2060,10 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
/* Remove from search */
|
||||
\IPS\Content\Search\Index::i()->removeClassFromSearchIndex( 'IPS\cms\Records' . $database->id );
|
||||
|
||||
/* Remove content in social promote table */
|
||||
$class = 'IPS\cms\Records' . $database->id;
|
||||
\IPS\core\Promote::changeHiddenByClass( new $class, TRUE );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
@@ -2019,13 +2090,11 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
|
||||
$delete = $this->getMenuItemIds();
|
||||
|
||||
if ( count( $delete ) )
|
||||
if ( \count( $delete ) )
|
||||
{
|
||||
\IPS\Db::i()->delete( 'core_menu', \IPS\Db::i()->in( 'id', $delete ) );
|
||||
}
|
||||
|
||||
unset( \IPS\Data\Store::i()->frontNavigation );
|
||||
|
||||
|
||||
/* Remove any widgets for this page */
|
||||
\IPS\Db::i()->delete( 'cms_page_widget_areas', array( 'area_page_id=?', $this->id ) );
|
||||
|
||||
@@ -2067,12 +2136,11 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
* Set the permission index permissions
|
||||
*
|
||||
* @param array $insert Permission data to insert
|
||||
* @param object \IPS\Helpers\Form\Matrix
|
||||
* @return void
|
||||
*/
|
||||
public function setPermissions( $insert, \IPS\Helpers\Form\Matrix $matrix )
|
||||
public function setPermissions( $insert )
|
||||
{
|
||||
parent::setPermissions( $insert, $matrix );
|
||||
parent::setPermissions( $insert );
|
||||
static::buildPageUrlStore();
|
||||
|
||||
/* Update perms if we have a child database */
|
||||
@@ -2114,7 +2182,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if ( $this->full_path and \IPS\Theme::designersModeEnabled() )
|
||||
{
|
||||
static::exportDesignersMode( $this->id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2166,7 +2234,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
$includes = $this->getIncludes();
|
||||
|
||||
if ( isset( $includes['js'] ) and is_array( $includes['js'] ) )
|
||||
if ( isset( $includes['js'] ) and \is_array( $includes['js'] ) )
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, array_values( $includes['js'] ) );
|
||||
}
|
||||
@@ -2180,7 +2248,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Output::i()->title = $this->getHtmlTitle();
|
||||
|
||||
/* This has to be done after setTheme(), otherwise \IPS\Theme::switchTheme() can wipe out CSS includes */
|
||||
if ( isset( $includes['css'] ) and is_array( $includes['css'] ) )
|
||||
if ( isset( $includes['css'] ) and \is_array( $includes['css'] ) )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array_values( $includes['css'] ) );
|
||||
}
|
||||
@@ -2208,15 +2276,31 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
if ( $this->meta_description AND ( !isset( \IPS\Output::i()->metaTags['description'] ) OR !\IPS\Output::i()->metaTags['description'] ) )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['description'] = $this->meta_description;
|
||||
\IPS\Output::i()->metaTags['og:description'] = $this->meta_description;
|
||||
}
|
||||
|
||||
/* If this is a default page, we may be accessing this from the folder only. The isset() check is to ensure canonical
|
||||
tags for more specific things (like databases) are not overridden. */
|
||||
if ( $this->default AND !isset( \IPS\Output::i()->linkTags['canonical'] ) )
|
||||
if ( !isset( \IPS\Output::i()->linkTags['canonical'] ) )
|
||||
{
|
||||
\IPS\Output::i()->linkTags['canonical'] = (string) $this->url();
|
||||
}
|
||||
|
||||
if ( !isset( \IPS\Output::i()->metaTags['og:url'] ) )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['og:url'] = (string) $this->url();
|
||||
}
|
||||
|
||||
if ( !isset( \IPS\Output::i()->metaTags['og:title'] ) )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['og:title'] = \IPS\Output::i()->title;
|
||||
}
|
||||
|
||||
if ( !isset( \IPS\Output::i()->metaTags['og:type'] ) )
|
||||
{
|
||||
\IPS\Output::i()->metaTags['og:type'] = 'website';
|
||||
}
|
||||
|
||||
/* Can only disable sidebar if HTML page */
|
||||
if ( ! $this->show_sidebar and $this->type === 'html' )
|
||||
{
|
||||
@@ -2243,7 +2327,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( \IPS\Output::i()->title );
|
||||
|
||||
/* Send straight to the output engine */
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), ( $httpStatusCode ? $httpStatusCode : 200 ), 'text/html', ( $httpHeaders ? $httpHeaders : \IPS\Output::i()->httpHeaders ) );
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), ( $httpStatusCode ? $httpStatusCode : 200 ), 'text/html', ( $httpHeaders ? $httpHeaders : array() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2257,7 +2341,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
{
|
||||
$this->setTheme();
|
||||
|
||||
if ( isset( $includes['css'] ) and is_array( $includes['css'] ) )
|
||||
if ( isset( $includes['css'] ) and \is_array( $includes['css'] ) )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array_values( $includes['css'] ) );
|
||||
}
|
||||
@@ -2285,7 +2369,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
list( $group, $name, $key ) = explode( '__', $this->wrapper_template );
|
||||
$content = $content ?: $this->getHtmlContent();
|
||||
$content .= $mfa;
|
||||
\IPS\Output::i()->sendOutput( \IPS\cms\Theme::i()->getTemplate($group, 'cms', 'page')->$name( $content, $this->getHtmlTitle() ), 200, $this->getContentType(), \IPS\Output::i()->httpHeaders );
|
||||
\IPS\Output::i()->sendOutput( \IPS\cms\Theme::i()->getTemplate($group, 'cms', 'page')->$name( $content, $this->getHtmlTitle() ), 200, $this->getContentType() );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -2300,7 +2384,7 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
/* Send straight to the output engine */
|
||||
$content = $content ?: $this->getHtmlContent();
|
||||
$content .= $mfa;
|
||||
\IPS\Output::i()->sendOutput( $content, ( $httpStatusCode ? $httpStatusCode : 200 ), $this->getContentType(), ( $httpHeaders ? $httpHeaders : \IPS\Output::i()->httpHeaders ) );
|
||||
\IPS\Output::i()->sendOutput( $content, ( $httpStatusCode ? $httpStatusCode : 200 ), $this->getContentType(), ( $httpHeaders ? $httpHeaders : array() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2378,11 +2462,11 @@ class _Page extends \IPS\Node\Model implements \IPS\Node\Permissions
|
||||
$databasePaths[] = $page['page_full_path'];
|
||||
}
|
||||
|
||||
if ( count( $diskPaths ) )
|
||||
if ( \count( $diskPaths ) )
|
||||
{
|
||||
foreach( $diskPaths as $path )
|
||||
{
|
||||
if ( ! in_array( $path, $databasePaths ) )
|
||||
if ( ! \in_array( $path, $databasePaths ) )
|
||||
{
|
||||
@unlink( \IPS\ROOT_PATH . "/themes/cms/pages/" . $path );
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* 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;
|
||||
@@ -90,23 +90,15 @@ class _PageItem extends \IPS\Content\Item implements \IPS\Content\Searchable
|
||||
*
|
||||
* @param array $indexData Data from the search index
|
||||
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public static function urlFromIndexData( $indexData, $itemData )
|
||||
public static function urlFromIndexData( $indexData, $itemData, $action = NULL )
|
||||
{
|
||||
if ( ( \IPS\Application::load('cms')->default OR \IPS\Settings::i()->cms_use_different_gateway ) AND $itemData['page_default'] AND !$itemData['page_folder_id'] )
|
||||
if ( \IPS\Application::load('cms')->default AND $itemData['page_default'] AND !$itemData['page_folder_id'] )
|
||||
{
|
||||
/* Are we using the gateway file? */
|
||||
if ( \IPS\Settings::i()->cms_use_different_gateway )
|
||||
{
|
||||
/* Yes, work out the proper URL. */
|
||||
return \IPS\Http\Url::createFromString( \IPS\Settings::i()->cms_root_page_url, TRUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No - that's easy */
|
||||
return \IPS\Http\Url::internal( '', 'front' );
|
||||
}
|
||||
/* No - that's easy */
|
||||
return \IPS\Http\Url::internal( '', 'front' );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -199,4 +191,15 @@ class _PageItem extends \IPS\Content\Item implements \IPS\Content\Searchable
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should posting this increment the poster's post count?
|
||||
*
|
||||
* @param \IPS\Node\Model|NULL $container Container
|
||||
* @return void
|
||||
*/
|
||||
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* 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;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* 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;
|
||||
@@ -94,16 +94,39 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
*/
|
||||
public static $customDatabaseId = NULL;
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
*/
|
||||
public static $hideLogKey = 'ccs-records';
|
||||
|
||||
/**
|
||||
* @brief Store generated search index titles for efficiency
|
||||
*/
|
||||
protected static $searchIndexTitles = array();
|
||||
|
||||
|
||||
/**
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
if ( static::commentWhere() !== NULL )
|
||||
{
|
||||
if( $extraWhereClause === NULL )
|
||||
{
|
||||
$extraWhereClause = array( static::commentWhere() );
|
||||
}
|
||||
else
|
||||
{
|
||||
$extraWhereClause[] = static::commentWhere();
|
||||
}
|
||||
}
|
||||
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Post count for member
|
||||
*
|
||||
@@ -139,7 +162,9 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
* @param bool $joinContainer If true, will join container data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinComments If true, will join comment data (set to TRUE if your $where clause depends on this data)
|
||||
* @param bool $joinReviews If true, will join review data (set to TRUE if your $where clause depends on this data)
|
||||
* @return \IPS\Patterns\ActiveRecordIterator|int
|
||||
* @param bool $countOnly If true will return the count
|
||||
* @param array|null $joins Additional arbitrary joins for the query
|
||||
* @return array|NULL|\IPS\Content\Comment If $limit is 1, will return \IPS\Content\Comment or NULL for no results. For any other number, will return an array.
|
||||
*/
|
||||
public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=\IPS\Content\Hideable::FILTER_AUTOMATIC, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL )
|
||||
{
|
||||
@@ -229,7 +254,8 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
{
|
||||
$template = static::$commentTemplate[1];
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
return call_user_func_array( array( \IPS\cms\Theme::i(), 'getTemplate' ), static::$commentTemplate[0] )->$template( $this->item(), $this );
|
||||
|
||||
return \IPS\cms\Theme::i()->getTemplate( static::$commentTemplate[0][0], static::$commentTemplate[0][1], static::$commentTemplate[0][2] )->$template( $this->item(), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +288,7 @@ class _Comment extends \IPS\Content\Comment implements \IPS\Content\EditHistory,
|
||||
$item = $this->item();
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
$commentIdColumn = static::$databaseColumnId;
|
||||
return array( $this->item()->$idColumn, $this->$commentIdColumn, static::$customDatabaseId );
|
||||
return array( $this->item()->$idColumn, $this->$commentIdColumn, static::$customDatabaseId . '-comment' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* 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;
|
||||
@@ -147,7 +147,8 @@ class _CommentTopicSync extends \IPS\cms\Records\Comment
|
||||
$comment = \IPS\forums\Topic\Post::load( $this->pid );
|
||||
$template = static::$commentTemplate[1];
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
return call_user_func_array( array( \IPS\cms\Theme::i(), 'getTemplate' ), static::$commentTemplate[0] )->$template( $comment->item(), $comment );
|
||||
|
||||
return \IPS\cms\Theme::i()->getTemplate( static::$commentTemplate[0][0], static::$commentTemplate[0][1], static::$commentTemplate[0][2] )->$template( $comment->item(), $comment );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* 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;
|
||||
@@ -95,11 +95,31 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
* @brief Database ID
|
||||
*/
|
||||
public static $customDatabaseId = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* @brief [Content] Key for hide reasons
|
||||
* Load Record
|
||||
*
|
||||
* @see \IPS\Db::build
|
||||
* @param int|string $id ID
|
||||
* @param string $idField The database column that the $id parameter pertains to (NULL will use static::$databaseColumnId)
|
||||
* @param mixed $extraWhereClause Additional where clause(s) (see \IPS\Db::build for details) - if used will cause multiton store to be skipped and a query always ran
|
||||
* @return static
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \OutOfRangeException
|
||||
*/
|
||||
public static $hideLogKey = 'ccs-records-review';
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
if( $extraWhereClause === NULL )
|
||||
{
|
||||
$extraWhereClause = array( static::commentWhere() );
|
||||
}
|
||||
else
|
||||
{
|
||||
$extraWhereClause[] = static::commentWhere();
|
||||
}
|
||||
|
||||
return parent::load( $id, $idField, $extraWhereClause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create first comment (created with content item)
|
||||
@@ -118,10 +138,16 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*/
|
||||
public static function create( $item, $comment, $first=FALSE, $rating=NULL, $guestName=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL )
|
||||
{
|
||||
$review = call_user_func_array( 'parent::create', func_get_args() );
|
||||
$review = parent::create( $item, $comment, $first, $rating, $guestName, $member, $time, $ipAddress, $hiddenStatus );
|
||||
|
||||
$review->database_id = static::$customDatabaseId;
|
||||
$review->save();
|
||||
|
||||
/* Have to do these AFTER database id is set */
|
||||
$ratingField = $item::$databaseColumnMap['rating'];
|
||||
|
||||
$review->item()->$ratingField = $review->item()->averageReviewRating() ?: 0;
|
||||
$review->item()->save();
|
||||
|
||||
return $review;
|
||||
}
|
||||
@@ -145,7 +171,9 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
public function html()
|
||||
{
|
||||
$template = static::$commentTemplate[1];
|
||||
return call_user_func_array( array( \IPS\cms\Theme::i(), 'getTemplate' ), static::$commentTemplate[0] )->$template( $this->item(), $this );
|
||||
static::$commentTemplate[0][0] = $this->item()->database()->template_display;
|
||||
|
||||
return \IPS\cms\Theme::i()->getTemplate( static::$commentTemplate[0][0], static::$commentTemplate[0][1], static::$commentTemplate[0][2] )->$template( $this->item(), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,8 +181,10 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @throws \BadMethodCallException
|
||||
* @throws \IPS\Http\Url\Exception
|
||||
*/
|
||||
public function url( $action=NULL )
|
||||
public function url( $action='find' )
|
||||
{
|
||||
$url = parent::url( $action );
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Records;
|
||||
|
||||
/* 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;
|
||||
@@ -121,7 +121,7 @@ class _Revisions extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function set_data( $value )
|
||||
{
|
||||
$this->_data['data'] = ( is_array( $value ) ? json_encode( $value ) : $value );
|
||||
$this->_data['data'] = ( \is_array( $value ) ? json_encode( $value ) : $value );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Selector;
|
||||
|
||||
/* 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;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Selector;
|
||||
|
||||
/* 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;
|
||||
|
||||
Whitespace-only changes.
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Templates;
|
||||
|
||||
/* 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;
|
||||
|
||||
@@ -12,7 +12,10 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Pages\Page;
|
||||
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -20,6 +23,14 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
/**
|
||||
* @brief Template Model
|
||||
* @notes Rules of a template:
|
||||
* user_created: this means the user has creating a new set of templates (via import or Add New)
|
||||
* user_edited: this means the user has edited a template so it no longer matches the master template
|
||||
*
|
||||
* CUSTOM FLAG: True when user_created is true, user_edited is false, original_group != any of the master original_groups (if original group is the same as any of the master groups then it is a default template still)
|
||||
* MODIFIED FLAG: True when user_edited is true
|
||||
*
|
||||
* Updating templates: Update where user_edited is FALSE and user_created is FALSE OR user_created is TRUE and original_group is in master groups
|
||||
*/
|
||||
class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
@@ -52,6 +63,16 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief Master groups
|
||||
*/
|
||||
protected static $masterGroups = NULL;
|
||||
|
||||
/**
|
||||
* @brief Master templates
|
||||
*/
|
||||
protected static $masterTemplates = NULL;
|
||||
|
||||
/**
|
||||
* @brief Retusn all types
|
||||
@@ -146,7 +167,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
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 ) ) )
|
||||
if ( \in_array( $value, array_keys( $templates ) ) )
|
||||
{
|
||||
$options['group'] = $group;
|
||||
|
||||
@@ -155,7 +176,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $save ) )
|
||||
if ( \count( $save ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'cms_templates', $save, array( 'template_id=?', $template['template_id'] ) );
|
||||
}
|
||||
@@ -180,12 +201,12 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public static function load( $id, $idField=NULL, $extraWhereClause=NULL )
|
||||
{
|
||||
if ( ! is_numeric( $id ) and $idField === NULL )
|
||||
if ( !\is_numeric( $id ) and $idField === NULL )
|
||||
{
|
||||
$idField = 'template_key';
|
||||
}
|
||||
|
||||
if ( ! is_numeric( $id ) and ( \IPS\IN_DEV or \IPS\Theme::designersModeEnabled() ) )
|
||||
if ( !\is_numeric( $id ) and ( \IPS\IN_DEV or \IPS\Theme::designersModeEnabled() ) )
|
||||
{
|
||||
$templates = \IPS\cms\Theme::i()->getRawTemplates( NULL, NULL, NULL, \IPS\cms\Theme::RETURN_AS_OBJECT );
|
||||
|
||||
@@ -224,7 +245,64 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
return ucwords( str_replace( array( '-', '_' ), ' ', $name ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get master templates
|
||||
*
|
||||
* This returns an array of all template groups that are considered IPS defaults
|
||||
* @return array
|
||||
*/
|
||||
public static function getMasterTemplates() : array
|
||||
{
|
||||
if ( static::$masterTemplates === NULL )
|
||||
{
|
||||
static::$masterTemplates = iterator_to_array( \IPS\Db::i()->select( '*, MD5( CONCAT( template_location, \'.\', template_group, \'.\', template_title ) ) as bit_key', 'cms_templates', array( 'template_master=1' ) )->setKeyField( 'bit_key' ) );
|
||||
}
|
||||
|
||||
return static::$masterTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the master template version of this template
|
||||
*
|
||||
* @return \IPS\cms\Templates|NULL
|
||||
*/
|
||||
public function getMasterOfThis()
|
||||
{
|
||||
if ( $this->master )
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$key = md5( $this->location . '.'. $this->original_group . '.' . $this->title );
|
||||
if ( \in_array( $key, array_keys( static::getMasterTemplates() ) ) )
|
||||
{
|
||||
return static::constructFromData( static::$masterTemplates[ $key ] );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get master group names
|
||||
*
|
||||
* This returns an array of all template groups that are considered IPS defaults
|
||||
* @return array
|
||||
*/
|
||||
public static function getMasterGroups() : array
|
||||
{
|
||||
if ( static::$masterGroups === NULL )
|
||||
{
|
||||
static::$masterGroups = array();
|
||||
foreach( \IPS\Db::i()->select( 'template_group', static::$databaseTable, array( 'template_master=1 and template_original_group=template_group' ), 'template_group ASC', NULL, 'template_group' ) as $template )
|
||||
{
|
||||
static::$masterGroups[ $template ] = $template;
|
||||
}
|
||||
}
|
||||
|
||||
return static::$masterGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all template group
|
||||
*
|
||||
@@ -237,7 +315,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
$return = array();
|
||||
$locations = NULL;
|
||||
|
||||
if ( is_string( $returnType ) )
|
||||
if ( \is_string( $returnType ) )
|
||||
{
|
||||
switch( $returnType )
|
||||
{
|
||||
@@ -279,7 +357,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
$locations[] = 'database';
|
||||
}
|
||||
|
||||
if ( ! count( $locations ) )
|
||||
if ( ! \count( $locations ) )
|
||||
{
|
||||
throw new \UnexpectedValueException();
|
||||
}
|
||||
@@ -381,7 +459,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
$locations[] = 'database';
|
||||
}
|
||||
|
||||
if ( !count( $locations ) )
|
||||
if ( !\count( $locations ) )
|
||||
{
|
||||
throw new \UnexpectedValueException();
|
||||
}
|
||||
@@ -416,7 +494,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
$where = array( array( $idField . '=?', $id ) );
|
||||
if( $extraWhereClause !== NULL )
|
||||
{
|
||||
if ( !is_array( $extraWhereClause ) or !is_array( $extraWhereClause[0] ) )
|
||||
if ( !\is_array( $extraWhereClause ) or !\is_array( $extraWhereClause[0] ) )
|
||||
{
|
||||
$extraWhereClause = array( $extraWhereClause );
|
||||
}
|
||||
@@ -461,7 +539,7 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
$newTemplate->_new = TRUE;
|
||||
$newTemplate->user_created = 1;
|
||||
$newTemplate->user_edited = 1;
|
||||
$newTemplate->user_edited = 0;
|
||||
$newTemplate->master = 0;
|
||||
|
||||
$newTemplate->save();
|
||||
@@ -501,6 +579,179 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
\IPS\Db::i()->update( 'cms_templates', array( 'template_file_object' => NULL ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Export form for CMS Templates
|
||||
*
|
||||
* @param bool $appPluginBuild TRUE to customise form for app/plugin builds
|
||||
* @param array $preSelected Array of default values for checkboxSet
|
||||
* @return \IPS\Helpers\Form
|
||||
*/
|
||||
public static function exportForm( bool $appPluginBuild=FALSE, array $preSelected=array() ): \IPS\Helpers\Form
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', $appPluginBuild ? 'save' : 'next' );
|
||||
if( !$appPluginBuild )
|
||||
{
|
||||
$form->addMessage( 'cms_templates_export_description', 'ipsMessage ipsMessage_information' );
|
||||
$form->addButton( 'cms_templates_export_return', 'link', \IPS\Http\Url::internal( "app=cms&module=pages&controller=templates" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->addMessage( 'cms_templates_export_description_app', 'ipsMessage ipsMessage_general' );
|
||||
}
|
||||
|
||||
foreach( \IPS\cms\Templates::getTemplates( \IPS\cms\Templates::RETURN_DATABASE_ONLY + \IPS\cms\Templates::RETURN_ALL ) as $template )
|
||||
{
|
||||
$title = \IPS\cms\Templates::readableGroupName( $template->group );
|
||||
|
||||
if ( $template->location === 'database' )
|
||||
{
|
||||
$templates['database'][ $template->group ] = $title;
|
||||
}
|
||||
else if ( $template->location === 'block' )
|
||||
{
|
||||
$templates['block'][ $template->key ] = $title . ' > ' . $template->title;
|
||||
}
|
||||
else if ( $template->location === 'page' )
|
||||
{
|
||||
$templates['page'][ $template->key ] = $title . ' > ' . $template->title;
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $templates as $location => $data )
|
||||
{
|
||||
$defaultValue = $preSelected[ 'templates_' . $location ] ?? FALSE;
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'templates_' . $location, $defaultValue, FALSE, array( 'options' => $data ) ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export requested templates as XML
|
||||
*
|
||||
* @param array $values Checkbox set values
|
||||
* @return \XMLWriter|null
|
||||
*/
|
||||
public static function exportAsXml( array $values ):? \XMLWriter
|
||||
{
|
||||
$templates = array();
|
||||
foreach( \IPS\cms\Templates::getTemplates( \IPS\cms\Templates::RETURN_DATABASE_ONLY + \IPS\cms\Templates::RETURN_ALL ) as $template )
|
||||
{
|
||||
$templates[ $template->location ][ $template->group ] = $template->title;
|
||||
}
|
||||
$exportTemplates = array();
|
||||
foreach ( $templates as $location => $data )
|
||||
{
|
||||
if ( isset( $values[ 'templates_' . $location ] ) and \count( $values[ 'templates_' . $location ] ) )
|
||||
{
|
||||
if ( $location === 'database' )
|
||||
{
|
||||
$tmp = \IPS\cms\Theme::i()->getRawTemplates( 'cms', array( 'database' ), array_values( $values[ 'templates_' . $location ] ), \IPS\cms\Theme::RETURN_DATABASE_ONLY + \IPS\cms\Theme::RETURN_ALL );
|
||||
|
||||
foreach ( $tmp['cms'] as $loc => $data )
|
||||
{
|
||||
if ( $loc === $location )
|
||||
{
|
||||
foreach ( $data as $key => $tdata )
|
||||
{
|
||||
foreach ( $tdata as $tkey => $tkdata )
|
||||
{
|
||||
$exportTemplates['cms'][ $location ][ $key ][ $tkey ] = $tkdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmp = \IPS\cms\Theme::i()->getRawTemplates( 'cms', array( $location ), NULL, \IPS\cms\Theme::RETURN_DATABASE_ONLY + \IPS\cms\Theme::RETURN_ALL );
|
||||
|
||||
foreach ( $tmp['cms'] as $loc => $data )
|
||||
{
|
||||
if ( $loc === $location )
|
||||
{
|
||||
foreach ( $data as $key => $tdata )
|
||||
{
|
||||
foreach ( $tdata as $tkey => $tkdata )
|
||||
{
|
||||
if ( \in_array( $tkey, $values[ 'templates_' . $location ] ) )
|
||||
{
|
||||
$exportTemplates['cms'][ $location ][ $key ][ $tkey ] = $tkdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $exportTemplates ) )
|
||||
{
|
||||
/* Init */
|
||||
$xml = new \XMLWriter;
|
||||
$xml->openMemory();
|
||||
$xml->setIndent( TRUE );
|
||||
$xml->startDocument( '1.0', 'UTF-8' );
|
||||
|
||||
/* Root tag */
|
||||
$xml->startElement( 'templates' );
|
||||
|
||||
foreach ( $exportTemplates as $app => $location )
|
||||
{
|
||||
foreach ( $location as $key => $data )
|
||||
{
|
||||
foreach ( $data as $group => $template )
|
||||
{
|
||||
foreach ( $template as $key => $templateData )
|
||||
{
|
||||
/* Initiate the <template> tag */
|
||||
$xml->startElement( 'template' );
|
||||
|
||||
foreach ( $templateData as $k => $v )
|
||||
{
|
||||
if ( !\in_array( \substr( $k, 9 ), array( 'content', 'params' ) ) )
|
||||
{
|
||||
$xml->startAttribute( $k );
|
||||
$xml->text( $v );
|
||||
$xml->endAttribute();
|
||||
}
|
||||
}
|
||||
|
||||
/* Write (potential) HTML fields */
|
||||
foreach ( array( 'template_params', 'template_content' ) as $field )
|
||||
{
|
||||
if ( isset( $templateData[ $field ] ) )
|
||||
{
|
||||
$xml->startElement( $field );
|
||||
if ( preg_match( '/<|>|&/', $templateData[ $field ] ) )
|
||||
{
|
||||
$xml->writeCData( str_replace( ']]>', ']]]]><![CDATA[>', $templateData[ $field ] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$xml->text( $templateData[ $field ] );
|
||||
}
|
||||
$xml->endElement();
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the <template> tag */
|
||||
$xml->endElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Finish */
|
||||
$xml->endDocument();
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is suitable to be used for a custom wrapper?
|
||||
@@ -535,6 +786,220 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user_edited flag if it is different from the master template
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDifferentFromMaster() : bool
|
||||
{
|
||||
if ( $master = $this->getMasterOfThis() )
|
||||
{
|
||||
if ( md5( preg_replace( '#\s#', '', $this->content ) ) != md5( preg_replace( '#\s#', '', $master->content ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import User Template XML
|
||||
*
|
||||
* @param string $filePath Path to XML file
|
||||
* @param string $fileContents XML Contents as string
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \BadMethodCallException
|
||||
* @return \IPS\Http\Url\Internal|null
|
||||
*/
|
||||
public static function importUserTemplateXml( string $filePath=NULL, string $fileContents=NULL ):? \IPS\Http\Url\Internal
|
||||
{
|
||||
/* Open XML file */
|
||||
$xml = new \IPS\Xml\XMLReader;
|
||||
|
||||
if( $filePath )
|
||||
{
|
||||
$xml->open( $filePath );
|
||||
}
|
||||
elseif( $fileContents )
|
||||
{
|
||||
if( !$xml->xml( $fileContents ) )
|
||||
{
|
||||
throw \UnexpectedValueException('bad_xml_string');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \BadMethodCallException('path_or_data_missing');
|
||||
}
|
||||
|
||||
$conflictKey = md5( microtime() );
|
||||
|
||||
$templates = \IPS\cms\Theme::i()->getRawTemplates( 'cms', NULL, NULL, \IPS\cms\Theme::RETURN_DATABASE_ONLY + \IPS\cms\Theme::RETURN_ALL );
|
||||
|
||||
if ( ! @$xml->read() )
|
||||
{
|
||||
throw new \UnexpectedValueException('xml_file_bad_format');
|
||||
}
|
||||
$xml->read();
|
||||
while ( $xml->read() )
|
||||
{
|
||||
if ( $xml->name === 'template' )
|
||||
{
|
||||
$node = new \SimpleXMLElement( $xml->readOuterXML() );
|
||||
$attrs = array();
|
||||
|
||||
foreach( $node->attributes() as $k => $v )
|
||||
{
|
||||
$attrs[ $k ] = (string) $v;
|
||||
}
|
||||
|
||||
/* Any kids of your own? */
|
||||
foreach( $node->children() as $k => $v )
|
||||
{
|
||||
$tryJson = json_decode( $v, TRUE );
|
||||
$attrs[ $k ] = ( $tryJson ) ? $tryJson : (string) $v;
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $attrs['template_title'] ) and isset( $attrs['template_location'] ) and isset( $attrs['template_group'] ) )
|
||||
{
|
||||
/* Got this template? */
|
||||
$exists = NULL;
|
||||
if ( isset( $templates['cms'][ $attrs['template_location'] ][ $attrs['template_group'] ] ) )
|
||||
{
|
||||
foreach ( $templates['cms'][ $attrs['template_location'] ][ $attrs['template_group'] ] as $key => $template )
|
||||
{
|
||||
if ( $template['template_title'] === $attrs['template_title'] )
|
||||
{
|
||||
$exists = $template;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Should we update it or log it as a conflict? */
|
||||
if ( $exists !== NULL )
|
||||
{
|
||||
if ( $exists['template_master'] )
|
||||
{
|
||||
/* This is a master template bit, so it's totes fine to create a new one, as it will 'overload' this one */
|
||||
$obj = new \IPS\cms\Templates;
|
||||
$obj->location = $attrs['template_location'];
|
||||
$obj->group = $attrs['template_group'];
|
||||
$obj->title = $attrs['template_title'];
|
||||
$obj->params = $attrs['template_params'];
|
||||
$obj->content = $attrs['template_content'];
|
||||
$obj->original_group = $attrs['template_original_group'];
|
||||
$obj->type = $attrs['template_type'];
|
||||
$obj->user_created = 1;
|
||||
$obj->user_edited = (int) $obj->isDifferentFromMaster();
|
||||
$obj->desc = '';
|
||||
$obj->key = $exists['template_key']; // We need to re-use the already stored key so database mappings remain intact
|
||||
$obj->save();
|
||||
}
|
||||
elseif ( $exists['template_user_created'] == 1 )
|
||||
{
|
||||
/* Ok, so this is a non-stIt useandard template. Has it been edited by this user at all? */
|
||||
if ( $exists['template_user_edited'] )
|
||||
{
|
||||
/* User has edited this, so we should just log a conflict... */
|
||||
\IPS\Db::i()->insert( 'cms_template_conflicts', array(
|
||||
'conflict_key' => $conflictKey,
|
||||
'conflict_item_id' => $exists['template_id'],
|
||||
'conflict_type' => $attrs['template_type'],
|
||||
'conflict_location' => $attrs['template_location'],
|
||||
'conflict_group' => $attrs['template_group'],
|
||||
'conflict_original_group' => $attrs['template_original_group'],
|
||||
'conflict_title' => $attrs['template_title'],
|
||||
'conflict_data' => $attrs['template_params'],
|
||||
'conflict_content' => $attrs['template_content'],
|
||||
'conflict_date' => time()
|
||||
) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not edited, so just update */
|
||||
try
|
||||
{
|
||||
$template = \IPS\cms\Templates::load( $exists['template_key'], 'template_key' );
|
||||
$template->params = $attrs['template_params'];
|
||||
$template->content = $attrs['template_content'];
|
||||
$template->save();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an overloaded master template, so just update */
|
||||
$template = \IPS\cms\Templates::load( $exists['template_key'], 'template_key' );
|
||||
$template->user_edited = 1;
|
||||
$template->params = $attrs['template_params'];
|
||||
$template->content = $attrs['template_content'];
|
||||
$template->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $exists === NULL )
|
||||
{
|
||||
$obj = new \IPS\cms\Templates;
|
||||
$obj->location = $attrs['template_location'];
|
||||
$obj->group = $attrs['template_group'];
|
||||
$obj->title = $attrs['template_title'];
|
||||
$obj->params = $attrs['template_params'];
|
||||
$obj->content = $attrs['template_content'];
|
||||
$obj->original_group = $attrs['template_original_group'];
|
||||
$obj->type = $attrs['template_type'];
|
||||
$obj->user_created = 1; # Created
|
||||
$obj->user_edited = (int) $obj->isDifferentFromMaster();
|
||||
$obj->desc = '';
|
||||
$obj->save();
|
||||
|
||||
/* Lets try and re-use the original key if we can */
|
||||
$key = NULL;
|
||||
if ( isset( $attrs['template_key'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$check = \IPS\Db::i()->select( 'template_id', 'cms_templates', array( 'template_key=?', $attrs['template_key'] ) )->first();
|
||||
|
||||
if ( $check['template_master'] == 1 and \in_array( $attrs['template_group'], \IPS\cms\Templates::getMasterGroups() ) )
|
||||
{
|
||||
/* it's OK to overload this with a user edited version */
|
||||
$obj->user_created = 0;
|
||||
$obj->user_edited = 1;
|
||||
|
||||
$key = $attrs['template_key'];
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* It doesn't exist! */
|
||||
$key = $attrs['template_key'];
|
||||
}
|
||||
}
|
||||
|
||||
$obj->key = ( $key ) ? $key : $obj->location . \IPS\Http\Url\Friendly::seoTitle( $obj->group ) . '_' . \IPS\Http\Url\Friendly::seoTitle( $obj->title ) . '_' . $obj->id;
|
||||
$obj->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xml->next();
|
||||
}
|
||||
|
||||
/* Check for conflicts */
|
||||
$conflicts = \IPS\Db::i()->select( 'count(*)', 'cms_template_conflicts', array( 'conflict_key=?', $conflictKey ) )->first();
|
||||
if( $conflicts )
|
||||
{
|
||||
return \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates&do=conflicts&key=' . $conflictKey );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import templates from an XML file
|
||||
*
|
||||
@@ -607,11 +1072,79 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static::$masterGroups = NULL;
|
||||
static::$masterTemplates = NULL;
|
||||
|
||||
static::updateAllInheritedMasterTemplates();
|
||||
}
|
||||
|
||||
return $worked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all inherited master templates with the new master templates
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function updateAllInheritedMasterTemplates()
|
||||
{
|
||||
/* Update existing template bits */
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_templates', array( 'template_master=0 and template_user_created=1 and template_user_edited=0' ) ) as $key => $template )
|
||||
{
|
||||
$obj = static::constructFromData( $template );
|
||||
|
||||
if ( $master = $obj->getMasterOfThis() )
|
||||
{
|
||||
$obj->content = $master->content;
|
||||
$obj->params = $master->params;
|
||||
$obj->save();
|
||||
}
|
||||
}
|
||||
|
||||
/* Now go through the original groups and make sure we have template bits for all */
|
||||
$masterByGroup = array();
|
||||
|
||||
foreach( static::getMasterTemplates() as $template )
|
||||
{
|
||||
$masterByGroup[ $template['template_group'] ][ $template['template_title'] ] = $template;
|
||||
}
|
||||
|
||||
$customGroups = iterator_to_array( \IPS\Db::i()->select( 'template_group, MIN(template_original_group) as template_original_group', static::$databaseTable, array( 'template_master=0 and template_original_group != template_group' ), 'template_group ASC', NULL, 'template_group' )->setKeyField('template_group')->setValueField('template_original_group') );
|
||||
|
||||
foreach( $customGroups as $customGroup => $masterGroup )
|
||||
{
|
||||
if ( $masterGroup )
|
||||
{
|
||||
$groupByGroup = array();
|
||||
foreach ( \IPS\Db::i()->select( '*', static::$databaseTable, array('template_group=?', $customGroup) ) as $bit )
|
||||
{
|
||||
$groupByGroup[$bit['template_title']] = $bit;
|
||||
}
|
||||
|
||||
/* Now, see if we're missing any */
|
||||
foreach( $masterByGroup[ $masterGroup ] as $title => $template )
|
||||
{
|
||||
if ( ! \in_array( $title, array_keys( $groupByGroup ) ) )
|
||||
{
|
||||
$copy = $template;
|
||||
foreach( array( 'template_id', 'template_file_object', 'bit_key' ) as $field )
|
||||
{
|
||||
unset( $copy[ $field ] );
|
||||
}
|
||||
|
||||
$copy['template_master'] = 0;
|
||||
$copy['template_user_created'] = 1;
|
||||
$copy['template_group'] = $customGroup;
|
||||
$copy['template_key'] = $copy['template_location'] . '_' . $customGroup . '_' . $title;
|
||||
|
||||
\IPS\Db::i()->insert( 'cms_templates', $copy );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
* Overloaded to protect inheritence
|
||||
@@ -656,10 +1189,14 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function get__inherited()
|
||||
{
|
||||
if ( $this->user_created )
|
||||
if ( $this->user_created and ! \in_array( $this->original_group, static::getMasterGroups() ) )
|
||||
{
|
||||
return 'custom';
|
||||
}
|
||||
elseif ( $this->user_created and ! $this->user_edited )
|
||||
{
|
||||
return 'inherit';
|
||||
}
|
||||
elseif ( $this->user_edited )
|
||||
{
|
||||
return 'changed';
|
||||
@@ -720,31 +1257,10 @@ class _Templates extends \IPS\Patterns\ActiveRecord
|
||||
$this->file_object = NULL;
|
||||
}
|
||||
|
||||
/* Should we copy this to a new template and then save it? */
|
||||
if ( ! $this->user_edited )
|
||||
{
|
||||
/* Infinite loop is only cool as Apple's address */
|
||||
$clone = new \IPS\cms\Templates;
|
||||
|
||||
$clone->_data = $this->_data;
|
||||
$clone->changed = $this->changed;
|
||||
|
||||
$clone->id = NULL;
|
||||
$clone->user_edited = 1;
|
||||
$clone->master = 0;
|
||||
$clone->_new = TRUE;
|
||||
$clone->save();
|
||||
|
||||
$key = \strtolower( 'template_cms_' . \IPS\cms\Theme::makeBuiltTemplateLookupHash( 'cms', $clone->location, $clone->group ) . '_' . $clone->group );
|
||||
}
|
||||
else
|
||||
{
|
||||
$key = \strtolower( 'template_cms_' . \IPS\cms\Theme::makeBuiltTemplateLookupHash( 'cms', $this->location, $this->group ) . '_' . $this->group );
|
||||
|
||||
parent::save();
|
||||
}
|
||||
parent::save();
|
||||
|
||||
/* Clear store */
|
||||
$key = \strtolower( 'template_cms_' . \IPS\cms\Theme::makeBuiltTemplateLookupHash( 'cms', $this->location, $this->group ) . '_' . $this->group );
|
||||
unset( \IPS\Data\Store::i()->$key );
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Theme\Advanced;
|
||||
|
||||
/* 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;
|
||||
@@ -26,7 +26,7 @@ class _Theme extends \IPS\cms\Theme
|
||||
/**
|
||||
* Get currently logged in member's theme
|
||||
*
|
||||
* @return \IPS\Theme
|
||||
* @return static
|
||||
*/
|
||||
public static function i()
|
||||
{
|
||||
@@ -36,7 +36,7 @@ class _Theme extends \IPS\cms\Theme
|
||||
/**
|
||||
* Write files to disk
|
||||
*
|
||||
* return void
|
||||
* @return void
|
||||
*/
|
||||
public static function export()
|
||||
{
|
||||
@@ -186,7 +186,7 @@ class _Theme extends \IPS\cms\Theme
|
||||
}
|
||||
|
||||
/* 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() ) );
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms\Theme;
|
||||
|
||||
/* 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;
|
||||
@@ -108,7 +108,7 @@ class _Template extends \IPS\Theme\Template
|
||||
$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';
|
||||
@@ -149,7 +149,8 @@ class _Template extends \IPS\Theme\Template
|
||||
|
||||
/* Run it */
|
||||
ob_start();
|
||||
$return = call_user_func_array( 'IPS\\Theme\\'.$functionName, $params );
|
||||
$template = 'IPS\\Theme\\'.$functionName;
|
||||
$return = $template( ...$params );
|
||||
if( $error = ob_get_clean() )
|
||||
{
|
||||
echo "<strong>{$functionName}</strong><br>{$error}<br><br><pre>{$output}";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -280,9 +280,9 @@ class _Theme extends \IPS\Theme
|
||||
public function getRawTemplates( $app=array(), $location=array(), $group=array(), $returnType=null, $returnThisSetOnly=false )
|
||||
{
|
||||
$returnType = ( $returnType === null ) ? self::RETURN_ALL : $returnType;
|
||||
$app = ( is_string( $app ) AND $app != '' ) ? array( $app ) : $app;
|
||||
$location = ( is_string( $location ) AND $location != '' ) ? array( $location ) : $location;
|
||||
$group = ( is_string( $group ) AND $group != '' ) ? array( $group ) : $group;
|
||||
$app = ( \is_string( $app ) AND ! empty( $app ) ) ? array( $app ) : $app;
|
||||
$location = ( \is_string( $location ) AND ! empty( $location ) ) ? array( $location ) : $location;
|
||||
$group = ( \is_string( $group ) AND ! empty( $group ) ) ? array( $group ) : $group;
|
||||
$where = array();
|
||||
$templates = array();
|
||||
|
||||
@@ -294,7 +294,7 @@ class _Theme extends \IPS\Theme
|
||||
|
||||
foreach( new \DirectoryIterator( static::_getHtmlPath('cms') ) as $location )
|
||||
{
|
||||
if ( ! in_array( $location->getFilename(), $fixedLocations ) AND $location->isDir() AND mb_substr( $location->getFilename(), 0, 1 ) !== '.' )
|
||||
if ( ! \in_array( $location->getFilename(), $fixedLocations ) AND $location->isDir() AND mb_substr( $location->getFilename(), 0, 1 ) !== '.' )
|
||||
{
|
||||
$allowedLocations = array();
|
||||
if ( $returnType & static::RETURN_ONLY_TEMPLATE )
|
||||
@@ -329,7 +329,7 @@ class _Theme extends \IPS\Theme
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $allowedLocations ) and ! in_array( $location->getFilename(), $allowedLocations ) )
|
||||
if ( \count( $allowedLocations ) and ! \in_array( $location->getFilename(), $allowedLocations ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ class _Theme extends \IPS\Theme
|
||||
{
|
||||
if ( $file->isDir() AND mb_substr( $file->getFilename(), 0, 1 ) !== '.' )
|
||||
{
|
||||
if ( $group === NULL or ! count( $group ) or ( in_array( $file->getFilename(), $group ) ) )
|
||||
if ( $group === NULL or ! \count( $group ) or ( \in_array( $file->getFilename(), $group ) ) )
|
||||
{
|
||||
foreach( new \DirectoryIterator( static::_getHtmlPath( 'cms', $location->getFilename(), $file->getFilename() ) ) as $template )
|
||||
{
|
||||
@@ -353,7 +353,7 @@ class _Theme extends \IPS\Theme
|
||||
$params = \IPS\cms\Theme\Template::extractParamsFromTag( $contents );
|
||||
$container = NULL;
|
||||
|
||||
if ( in_array( $key, $seenKeys ) )
|
||||
if ( \in_array( $key, $seenKeys ) )
|
||||
{
|
||||
$key .= filemtime( static::_getHtmlPath( 'cms', $location->getFilename(), $file->getFilename() ) . '/' . $template->getFilename() ) . mt_rand();
|
||||
}
|
||||
@@ -416,12 +416,12 @@ class _Theme extends \IPS\Theme
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( is_array( $location ) AND count( $location ) )
|
||||
if ( \is_array( $location ) AND \count( $location ) )
|
||||
{
|
||||
$where[] = "template_location IN ('" . implode( "','", $location ) . "')";
|
||||
}
|
||||
|
||||
if ( is_array( $group ) AND count( $group ) )
|
||||
if ( \is_array( $group ) AND \count( $group ) )
|
||||
{
|
||||
$where[] = "template_group IN ('" . implode( "','", $group ) . "')";
|
||||
}
|
||||
@@ -435,7 +435,7 @@ class _Theme extends \IPS\Theme
|
||||
{
|
||||
$where[] = "template_type='js'";
|
||||
}
|
||||
|
||||
|
||||
$templateNames = array();
|
||||
$rawTemplates = array();
|
||||
$originalGroups = array();
|
||||
@@ -455,7 +455,7 @@ class _Theme extends \IPS\Theme
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $originalGroups ) )
|
||||
if ( \count( $originalGroups ) )
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_templates', array( array( 'template_original_group = template_group '), array( \IPS\Db::i()->in( 'template_original_group', $originalGroups ) ) ) ) as $row )
|
||||
{
|
||||
@@ -471,7 +471,7 @@ class _Theme extends \IPS\Theme
|
||||
{
|
||||
foreach( $names as $name )
|
||||
{
|
||||
if ( ! in_array( $name, $templateNames[ $group ] ) )
|
||||
if ( ! \in_array( $name, $templateNames[ $group ] ) )
|
||||
{
|
||||
$rawTemplates[] = array_merge( $originalTemplates[ $group . '_' . $name ], array( 'template_group' => $groupMap[ $group ]) );
|
||||
}
|
||||
@@ -562,7 +562,7 @@ class _Theme extends \IPS\Theme
|
||||
{
|
||||
if ( ! isset( $this->templates[ $app ][ $location ][ $group ] ) )
|
||||
{
|
||||
if ( $app === 'cms' AND ! in_array( $location, array( 'admin', 'front', 'global' ) ) )
|
||||
if ( $app === 'cms' AND ! \in_array( $location, array( 'admin', 'front', 'global' ) ) )
|
||||
{
|
||||
$this->templates[ $app ][ $location ][ $group ] = new \IPS\cms\Theme\Template( $app, $location, $group );
|
||||
}
|
||||
@@ -579,7 +579,7 @@ class _Theme extends \IPS\Theme
|
||||
/* Group is saved clean */
|
||||
$group = static::cleanGroupName( $group );
|
||||
|
||||
if ( ( $app !== 'cms' ) OR ( $app === 'cms' AND in_array( $location, array( 'admin', 'front', 'global' ) ) ) )
|
||||
if ( ( $app !== 'cms' ) OR ( $app === 'cms' AND \in_array( $location, array( 'admin', 'front', 'global' ) ) ) )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( $group, $app, $location );
|
||||
}
|
||||
@@ -587,7 +587,7 @@ class _Theme extends \IPS\Theme
|
||||
$key = \strtolower( 'template_cms_' .static::makeBuiltTemplateLookupHash( $app, $location, $group ) . '_' . static::cleanGroupName( $group ) );
|
||||
|
||||
/* Still here */
|
||||
if ( !in_array( $key, array_keys( static::$calledTemplates ) ) )
|
||||
if ( !\in_array( $key, array_keys( static::$calledTemplates ) ) )
|
||||
{
|
||||
/* If we don't have a compiled template, do that now */
|
||||
if ( !isset( \IPS\Data\Store::i()->$key ) )
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\cms;
|
||||
|
||||
/* 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;
|
||||
@@ -37,7 +37,7 @@ class _Widget extends \IPS\Widget
|
||||
{
|
||||
$widgets = json_decode( $item['area_widgets'], TRUE );
|
||||
|
||||
if( is_array( $widgets ) )
|
||||
if( \is_array( $widgets ) )
|
||||
{
|
||||
foreach( $widgets as $widget )
|
||||
{
|
||||
@@ -87,7 +87,7 @@ class _Widget extends \IPS\Widget
|
||||
$blocks[ $row['block_key'] ] = $row;
|
||||
}
|
||||
|
||||
if ( count( $blocks ) )
|
||||
if ( \count( $blocks ) )
|
||||
{
|
||||
$uniqueIds = array();
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_page_widget_areas' ) as $item )
|
||||
@@ -96,9 +96,9 @@ class _Widget extends \IPS\Widget
|
||||
|
||||
foreach( $widgets as $widget )
|
||||
{
|
||||
if ( $widget['app'] === 'cms' and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
|
||||
if ( ( isset( $widget['app'] ) and $widget['app'] === 'cms' ) and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
|
||||
{
|
||||
if ( in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
|
||||
if ( \in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
|
||||
{
|
||||
$uniqueIds[] = $widget['unique'];
|
||||
}
|
||||
@@ -112,9 +112,9 @@ class _Widget extends \IPS\Widget
|
||||
|
||||
foreach( $widgets as $widget )
|
||||
{
|
||||
if ( $widget['app'] === 'cms' and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
|
||||
if ( ( isset( $widget['app'] ) and $widget['app'] === 'cms' ) and $widget['key'] === 'Blocks' and isset( $widget['unique'] ) and isset( $widget['configuration'] ) and isset( $widget['configuration']['cms_widget_custom_block'] ) )
|
||||
{
|
||||
if ( in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
|
||||
if ( \in_array( $widget['configuration']['cms_widget_custom_block'], array_keys( $blocks ) ) )
|
||||
{
|
||||
$uniqueIds[] = $widget['unique'];
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class _Widget extends \IPS\Widget
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $uniqueIds ) )
|
||||
if ( \count( $uniqueIds ) )
|
||||
{
|
||||
$widgetRow = \IPS\Db::i()->select( '*', 'core_widgets', array( '`key`=? and app=?', 'Blocks', 'cms' ) )->first();
|
||||
|
||||
@@ -130,7 +130,7 @@ class _Widget extends \IPS\Widget
|
||||
{
|
||||
$caches = json_decode( $widgetRow['caches'], TRUE );
|
||||
|
||||
if ( is_array( $caches ) )
|
||||
if ( \is_array( $caches ) )
|
||||
{
|
||||
$save = $caches;
|
||||
foreach( $caches as $key => $time )
|
||||
@@ -149,9 +149,9 @@ class _Widget extends \IPS\Widget
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $save ) !== count( $caches ) )
|
||||
if ( \count( $save ) !== \count( $caches ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_widgets', array( 'caches' => ( count( $save ) ? json_encode( $save ) : NULL ) ), array( 'id=?', $widgetRow['id'] ) );
|
||||
\IPS\Db::i()->update( 'core_widgets', array( 'caches' => ( \count( $save ) ? json_encode( $save ) : NULL ) ), array( 'id=?', $widgetRow['id'] ) );
|
||||
unset( \IPS\Data\Store::i()->widgets );
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class _Widget extends \IPS\Widget
|
||||
{
|
||||
$data = json_decode( $row['area_widgets'], TRUE );
|
||||
|
||||
if ( count( $data ) )
|
||||
if ( \count( $data ) )
|
||||
{
|
||||
foreach( $data as $widget )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user