Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,67 +12,88 @@
|
||||
namespace IPS\cms\modules\admin\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\cms\Blocks\Block;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Templates;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_numeric;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Members AJAX actions
|
||||
*/
|
||||
class _ajax extends \IPS\Dispatcher\Controller
|
||||
class ajax extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Return a CSS or HTML menu
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadMenu()
|
||||
public function loadMenu() : void
|
||||
{
|
||||
$request = array(
|
||||
't_location' => ( isset( \IPS\Request::i()->t_location ) ) ? \IPS\Request::i()->t_location : null,
|
||||
't_group' => ( isset( \IPS\Request::i()->t_group ) ) ? \IPS\Request::i()->t_group : null,
|
||||
't_key' => ( isset( \IPS\Request::i()->t_key ) ) ? \IPS\Request::i()->t_key : null,
|
||||
't_type' => ( isset( \IPS\Request::i()->t_type ) ) ? \IPS\Request::i()->t_type : 'templates',
|
||||
't_location' => ( isset( Request::i()->t_location ) ) ? Request::i()->t_location : null,
|
||||
't_group' => ( isset( Request::i()->t_group ) ) ? Request::i()->t_group : null,
|
||||
't_key' => ( isset( Request::i()->t_key ) ) ? Request::i()->t_key : null,
|
||||
't_type' => ( isset( Request::i()->t_type ) ) ? Request::i()->t_type : 'templates',
|
||||
);
|
||||
|
||||
switch( $request['t_type'] )
|
||||
{
|
||||
default:
|
||||
case 'template':
|
||||
$flag = \IPS\cms\Templates::RETURN_ONLY_TEMPLATE;
|
||||
$flag = Templates::RETURN_ONLY_TEMPLATE;
|
||||
break;
|
||||
case 'js':
|
||||
$flag = \IPS\cms\Templates::RETURN_ONLY_JS;
|
||||
$flag = Templates::RETURN_ONLY_JS;
|
||||
break;
|
||||
case 'css':
|
||||
$flag = \IPS\cms\Templates::RETURN_ONLY_CSS;
|
||||
$flag = Templates::RETURN_ONLY_CSS;
|
||||
break;
|
||||
}
|
||||
|
||||
$templates = \IPS\cms\Templates::buildTree( \IPS\cms\Templates::getTemplates( $flag + \IPS\cms\Templates::RETURN_DATABASE_ONLY ) );
|
||||
$templates = Templates::buildTree( Templates::getTemplates( $flag + Templates::RETURN_DATABASE_ONLY ) );
|
||||
|
||||
$current = new \IPS\cms\Templates;
|
||||
$current = new Templates;
|
||||
|
||||
if ( ! empty( $request['t_key'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$current = \IPS\cms\Templates::load( $request['t_key'] );
|
||||
$current = Templates::load( $request['t_key'] );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'templates' )->menu( $templates, $current, $request );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'templates' )->menu( $templates, $current, $request );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,31 +101,23 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadTemplate()
|
||||
public function loadTemplate() : void
|
||||
{
|
||||
$t_location = \IPS\Request::i()->t_location;
|
||||
$t_key = \IPS\Request::i()->t_key;
|
||||
$t_location = Request::i()->t_location;
|
||||
$t_key = Request::i()->t_key;
|
||||
|
||||
if ( $t_location === 'block' and $t_key === '_default_' and isset( \IPS\Request::i()->block_key ) )
|
||||
if ( $t_location === 'block' and $t_key === '_default_' and isset( Request::i()->block_key ) )
|
||||
{
|
||||
/* Find it from the normal template system */
|
||||
if ( isset( \IPS\Request::i()->block_app ) )
|
||||
{
|
||||
$plugin = \IPS\Widget::load( \IPS\Application::load( \IPS\Request::i()->block_app ), \IPS\Request::i()->block_key, mt_rand() );
|
||||
}
|
||||
else
|
||||
{
|
||||
$plugin = \IPS\Widget::load( \IPS\Plugin::load( \IPS\Request::i()->block_plugin ), \IPS\Request::i()->block_key, mt_rand() );
|
||||
}
|
||||
|
||||
|
||||
$plugin = Widget::load( Application::load( Request::i()->block_app ), Request::i()->block_key, mt_rand() );
|
||||
$location = $plugin->getTemplateLocation();
|
||||
|
||||
$templateBits = \IPS\Theme::master()->getRawTemplates( $location['app'], $location['location'], $location['group'], \IPS\Theme::RETURN_ALL );
|
||||
$templateBits = Theme::master()->getAllTemplates( $location['app'], $location['location'], $location['group'], Theme::RETURN_ALL );
|
||||
$templateBit = $templateBits[ $location['app'] ][ $location['location'] ][ $location['group'] ][ $location['name'] ];
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->noencode ) OR ! \IPS\Request::i()->noencode )
|
||||
if ( ! isset( Request::i()->noencode ) OR ! Request::i()->noencode )
|
||||
{
|
||||
$templateBit['template_content'] = htmlentities( $templateBit['template_content'], ENT_DISALLOWED, 'UTF-8', TRUE );
|
||||
$templateBit['template_content'] = htmlentities( $templateBit['template_content'], ENT_DISALLOWED, 'UTF-8' );
|
||||
}
|
||||
|
||||
$templateArray = array(
|
||||
@@ -126,18 +139,18 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( \is_numeric( $t_key ) )
|
||||
if ( is_numeric( $t_key ) )
|
||||
{
|
||||
$template = \IPS\cms\Templates::load( $t_key, 'template_id' );
|
||||
$template = Templates::load( $t_key, 'template_id' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$template = \IPS\cms\Templates::load( $t_key );
|
||||
$template = Templates::load( $t_key );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
\IPS\Output::i()->json( array( 'error' => true ) );
|
||||
Output::i()->json( array( 'error' => true ) );
|
||||
}
|
||||
|
||||
if ( $template !== null )
|
||||
@@ -147,7 +160,7 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
'template_key' => $template->key,
|
||||
'template_title' => $template->title,
|
||||
'template_desc' => $template->desc,
|
||||
'template_content' => ( isset( \IPS\Request::i()->noencode ) AND \IPS\Request::i()->noencode ) ? $template->content : htmlentities( $template->content, ENT_DISALLOWED, 'UTF-8', TRUE ),
|
||||
'template_content' => ( isset( Request::i()->noencode ) AND Request::i()->noencode ) ? $template->content : htmlentities( $template->content, ENT_DISALLOWED, 'UTF-8' ),
|
||||
'template_location' => $template->location,
|
||||
'template_group' => $template->group,
|
||||
'template_container' => $template->container,
|
||||
@@ -159,13 +172,13 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->show == 'json' )
|
||||
if ( Request::i()->show == 'json' )
|
||||
{
|
||||
\IPS\Output::i()->json( $templateArray );
|
||||
Output::i()->json( $templateArray );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( \IPS\Theme::i()->getTemplate( 'templates', 'cms', 'admin' )->viewTemplate( $templateArray ) ), 200, 'text/html' );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( Theme::i()->getTemplate( 'templates', 'cms', 'admin' )->viewTemplate( $templateArray ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,32 +187,32 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function searchtemplates()
|
||||
public function searchtemplates() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'template_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'template_manage' );
|
||||
|
||||
$where = array();
|
||||
if ( \IPS\Request::i()->term )
|
||||
if ( Request::i()->term )
|
||||
{
|
||||
$where[] = array( '( LOWER(template_title) LIKE ? OR LOWER(template_content) LIKE ? )', '%' . mb_strtolower( \IPS\Request::i()->term ) . '%', '%' . mb_strtolower( \IPS\Request::i()->term ) . '%' );
|
||||
$where[] = array( '( LOWER(template_title) LIKE ? OR LOWER(template_content) LIKE ? )', '%' . mb_strtolower( Request::i()->term ) . '%', '%' . mb_strtolower( Request::i()->term ) . '%' );
|
||||
}
|
||||
|
||||
if ( ! \in_array( 'custom', explode( ',', \IPS\Request::i()->filters ) ) )
|
||||
if ( ! in_array( 'custom', explode( ',', Request::i()->filters ) ) )
|
||||
{
|
||||
$where[] = array( 'template_master=1 OR (template_user_created=1 and template_user_edited=0)' );
|
||||
}
|
||||
|
||||
if ( ! \in_array( 'unmodified', explode( ',', \IPS\Request::i()->filters ) ) )
|
||||
if ( ! in_array( 'unmodified', explode( ',', Request::i()->filters ) ) )
|
||||
{
|
||||
$where[] = array( 'template_user_created=1 and template_user_edited=1' );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->type ) )
|
||||
if ( isset( Request::i()->type ) )
|
||||
{
|
||||
$where[] = array( 'template_type=?', \IPS\Request::i()->type );
|
||||
$where[] = array( 'template_type=?', Request::i()->type );
|
||||
}
|
||||
|
||||
$select = \IPS\Db::i()->select(
|
||||
$select = Db::i()->select(
|
||||
'*',
|
||||
'cms_templates',
|
||||
$where,
|
||||
@@ -212,7 +225,7 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
$return[ $result['template_location'] ][ $result['template_group'] ][ $result['template_key'] ] = $result['template_title'];
|
||||
}
|
||||
|
||||
\IPS\Output::i()->json( $return );
|
||||
Output::i()->json( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,30 +233,30 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadTags()
|
||||
public function loadTags() : void
|
||||
{
|
||||
$page = NULL;
|
||||
if ( isset( \IPS\Request::i()->pageId ) )
|
||||
if ( isset( Request::i()->pageId ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::load( \IPS\Request::i()->pageId );
|
||||
$page = Page::load( Request::i()->pageId );
|
||||
}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
catch( OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
$tags = array();
|
||||
$tagLinks = array();
|
||||
|
||||
if ( $page and $page->id == \IPS\Settings::i()->cms_error_page )
|
||||
if ( $page and $page->id == 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';
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_use' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_use' ) )
|
||||
{
|
||||
foreach ( \IPS\cms\Databases::roots( NULL, NULL ) as $id => $db )
|
||||
foreach ( Databases::roots( NULL ) as $id => $db )
|
||||
{
|
||||
if ( !$db->page_id )
|
||||
{
|
||||
@@ -252,33 +265,33 @@ class _ajax extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
foreach( \IPS\cms\Blocks\Block::roots( NULL, NULL ) as $id => $block )
|
||||
foreach( Block::roots( NULL ) as $id => $block )
|
||||
{
|
||||
$tags['cms_tag_blocks']['{block="' . $block->key . '"}'] = $block->_title;
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'cms_pages', NULL, 'page_full_path ASC', array( 0, 50 ) ) as $page )
|
||||
foreach( 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( \IPS\cms\Pages\Page::$titleLangPrefix . $page['page_id'] );
|
||||
$tags['cms_tag_pages']['{pageurl="' . $page['page_full_path'] . '"}' ] = Member::loggedIn()->language()->addToStack( Page::$titleLangPrefix . $page['page_id'] );
|
||||
}
|
||||
|
||||
/* If we can manage words, then the header needs to always show */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'languages', 'lang_words' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'languages', 'lang_words' ) )
|
||||
{
|
||||
$tags['cms_tag_lang'] = array();
|
||||
$tagLinks['cms_tag_lang'] = array(
|
||||
'icon' => 'plus',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack('add_word'),
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=addWord" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'add_word' ), 'ipsDialog-remoteSubmit' => TRUE, 'action' => "wordForm" )
|
||||
'title' => Member::loggedIn()->language()->addToStack('add_word'),
|
||||
'link' => Url::internal( "app=core&module=languages&controller=languages&do=addWord" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'add_word' ), 'ipsDialog-remoteSubmit' => TRUE, 'action' => "wordForm" )
|
||||
);
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( "word_is_custom=? AND lang_id=?", 1, \IPS\Member::loggedIn()->language()->_id ) ) AS $lang )
|
||||
foreach( Db::i()->select( '*', 'core_sys_lang_words', array( "word_is_custom=? AND lang_id=?", 1, Member::loggedIn()->language()->_id ) ) AS $lang )
|
||||
{
|
||||
$tags['cms_tag_lang']['{lang="' . $lang['word_key'] . '"}'] = $lang['word_custom'] ?: $lang['word_default'];
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorTags( $tags, $tagLinks ) ), 200, 'text/html' );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorTags( $tags, $tagLinks ) ) );
|
||||
}
|
||||
}
|
||||
@@ -12,35 +12,57 @@
|
||||
namespace IPS\cms\modules\admin\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\cms\Blocks\Block;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use UnexpectedValueException;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* blocks
|
||||
*/
|
||||
class _blocks extends \IPS\Node\Controller
|
||||
class blocks extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\cms\Blocks\Container';
|
||||
protected string $nodeClass = '\IPS\cms\Blocks\Container';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'block_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'block_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -49,30 +71,32 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_blocks');
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__cms_pages_blocks');
|
||||
|
||||
/* @var Model $nodeClass */
|
||||
$nodeClass = $this->nodeClass;
|
||||
|
||||
if ( $nodeClass::canAddRoot() )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add_meow'] = array(
|
||||
Output::i()->sidebar['actions']['add_meow'] = array(
|
||||
'primary' => true,
|
||||
'icon' => 'plus',
|
||||
'title' => 'content_block_cat_add',
|
||||
'link' => $this->url->setQueryString( 'do', 'form' ),
|
||||
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_block_cat_add') ) : array() )
|
||||
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('content_block_cat_add') ) : array() )
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'block_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'block_add' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add_block'] = array(
|
||||
Output::i()->sidebar['actions']['add_block'] = array(
|
||||
'primary' => true,
|
||||
'icon' => 'puzzle-piece',
|
||||
'title' => 'content_block_block_add',
|
||||
'link' => $this->url->setQueryString( array( 'do' => 'addBlockType', 'subnode' => 1 ) ),
|
||||
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add') ) : array() )
|
||||
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('content_block_block_add') ) : array() )
|
||||
);
|
||||
}
|
||||
parent::manage();
|
||||
@@ -83,12 +107,12 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
if ( isset( Request::i()->id ) )
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\IPS\cms\Blocks\Block::deleteCompiled( \IPS\Request::i()->id );
|
||||
Session::i()->csrfCheck();
|
||||
Block::deleteCompiled( Request::i()->id );
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
@@ -99,12 +123,9 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
public function _getRootButtons(): array
|
||||
{
|
||||
$nodeClass = $this->nodeClass;
|
||||
$buttons = array();
|
||||
|
||||
return $buttons;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,9 +134,9 @@ class _blocks extends \IPS\Node\Controller
|
||||
* @param object $node Node returned from $nodeClass::load()
|
||||
* @return NULL|string
|
||||
*/
|
||||
public function _getRowHtml( $node )
|
||||
public function _getRowHtml( object $node ): ?string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'blocks', 'cms', 'admin' )->rowHtml( $node );
|
||||
return Theme::i()->getTemplate( 'blocks', 'cms', 'admin' )->rowHtml( $node );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,99 +144,86 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addBlockType()
|
||||
public function addBlockType() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'block_add' );
|
||||
Dispatcher::i()->checkAcpPermission( 'block_add' );
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'block_add_first_step', 'next');
|
||||
$form = new Form( 'block_add_first_step', 'next');
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'content_block_add_type', 'plugin', FALSE, array(
|
||||
$form->add( new Radio( 'content_block_add_type', 'plugin', FALSE, array(
|
||||
'options' => array(
|
||||
'plugin' => 'content_block_add_type_plugin',
|
||||
'custom' => 'content_block_add_type_custom'
|
||||
'editor' => 'content_block_add_custom_type_wysiwyg',
|
||||
'html' => 'content_block_add_custom_type_html',
|
||||
),
|
||||
'toggles' => array(
|
||||
'plugin' => array( 'content_block_add_type_plugin' ),
|
||||
'custom' => array( 'content_block_add_custom_type' )
|
||||
'plugin' => array( 'content_block_add_type_plugin' )
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
$plugins = array();
|
||||
foreach ( \IPS\Db::i()->select( "*", 'core_widgets', array( 'embeddable=1') ) as $widget )
|
||||
foreach ( Db::i()->select( "*", 'core_widgets', array( 'embeddable=1') ) as $widget )
|
||||
{
|
||||
/* Skip the RecordFeed */
|
||||
if( $widget['app'] == 'cms' and $widget['key'] == 'RecordFeed' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( $widget['app'] )
|
||||
{
|
||||
$app = \IPS\Application::load( $widget['app'] );
|
||||
$app = Application::load( $widget['app'] );
|
||||
if ( $app->enabled )
|
||||
{
|
||||
$plugins[ $app->_title ][ 'app__' . $widget['app'] . '__' . $widget['key'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
|
||||
$plugins[ $app->_title ][ 'app__' . $widget['app'] . '__' . $widget['key'] ] = Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$plugin = \IPS\Plugin::load( $widget['plugin'] );
|
||||
if ( $plugin->enabled )
|
||||
{
|
||||
$plugins[ $plugin->_title ][ 'plugin__' . $widget['plugin'] . '__' . $widget['key'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \UnexpectedValueException $e ) { }
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
catch ( UnexpectedValueException | OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
$disabled = array();
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_use' ) )
|
||||
|
||||
$disabled = [];
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_use' ) )
|
||||
{
|
||||
foreach ( \IPS\cms\Databases::databases() as $db )
|
||||
foreach ( Databases::databases() as $db )
|
||||
{
|
||||
if ( $db->page_id )
|
||||
{
|
||||
$plugins[\IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_title' )]['db_feed_' . $db->id] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_block_with_name', FALSE, array('sprintf' => array($db->_title)) );
|
||||
$plugins[Member::loggedIn()->language()->addToStack( 'cms_db_feed_title' )]['db_feed_' . $db->id] = Member::loggedIn()->language()->addToStack( 'cms_db_feed_block_with_name', FALSE, array('sprintf' => array($db->_title)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$disabled[] = 'db_feed_' . $db->id;
|
||||
$plugins[\IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_title' )]['db_feed_' . $db->id] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_block_with_name_disabled', FALSE, array('sprintf' => array($db->_title)) );
|
||||
$plugins[Member::loggedIn()->language()->addToStack( 'cms_db_feed_title' )]['db_feed_' . $db->id] = Member::loggedIn()->language()->addToStack( 'cms_db_feed_block_with_name_disabled', FALSE, array('sprintf' => array($db->_title)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'content_block_add_type_plugin', null, false, array( 'options' => $plugins, 'disabled' => $disabled ), NULL, NULL, NULL, 'content_block_add_type_plugin' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'content_block_add_custom_type', 'editor', TRUE, array(
|
||||
'options' => array( 'editor' => 'content_block_add_custom_type_wysiwyg',
|
||||
'html' => 'content_block_add_custom_type_html',
|
||||
'php' => 'content_block_add_custom_type_php'
|
||||
) ), NULL, NULL, NULL, 'content_block_add_custom_type' ) );
|
||||
$form->add( new Select( 'content_block_add_type_plugin', null, false, array( 'options' => $plugins, 'disabled' => $disabled ), NULL, NULL, NULL, 'content_block_add_type_plugin' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( $values['content_block_add_type'] !== 'custom' )
|
||||
if ( $values['content_block_add_type'] == 'plugin' )
|
||||
{
|
||||
if ( mb_substr( $values['content_block_add_type_plugin'], 0, 8 ) === 'db_feed_' )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $values['content_block_add_type_plugin'] . '&block_plugin_app=cms&parent=' . \IPS\Request::i()->parent ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $values['content_block_add_type_plugin'] . '&block_plugin_app=cms&parent=' . Request::i()->parent ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
list( $type, $value, $key ) = explode( '__', $values['content_block_add_type_plugin'] );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $key . "&block_plugin_{$type}={$value}" . '&parent=' . \IPS\Request::i()->parent ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $key . "&block_plugin_{$type}={$value}" . '&parent=' . Request::i()->parent ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=' . $values['content_block_add_type'] . '&block_editor=' . $values['content_block_add_custom_type'] . '&parent=' . \IPS\Request::i()->parent ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=custom&block_editor=' . $values['content_block_add_type'] . '&parent=' . Request::i()->parent ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add'), $form, FALSE );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add');
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( Member::loggedIn()->language()->addToStack('content_block_block_add'), $form, FALSE );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('content_block_block_add');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,42 +231,42 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function embedOptions()
|
||||
public function embedOptions() : void
|
||||
{
|
||||
$block = \IPS\cms\Blocks\Block::load( \IPS\Request::i()->id );
|
||||
$block = Block::load( Request::i()->id );
|
||||
$embedKey = md5( $block->key . time() );
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('block_embed_title');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( '', \IPS\Theme::i()->getTemplate( 'blocks', 'cms', 'admin' )->embedCode( $block, $embedKey ) );;
|
||||
}
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('block_embed_title');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( '', Theme::i()->getTemplate( 'blocks', 'cms', 'admin' )->embedCode( $block, $embedKey ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load tags
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadTags()
|
||||
public function loadTags() : void
|
||||
{
|
||||
$tags = array();
|
||||
$tagLinks = array();
|
||||
|
||||
/* If we can manage words, then the header needs to always show */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'languages', 'lang_words' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'languages', 'lang_words' ) )
|
||||
{
|
||||
$tags['cms_tag_lang'] = array();
|
||||
$tagLinks['cms_tag_lang'] = array(
|
||||
'icon' => 'plus',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack('add_word'),
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=languages&controller=languages&do=addWord" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'add_word' ), 'ipsDialog-remoteSubmit' => TRUE )
|
||||
'title' => Member::loggedIn()->language()->addToStack('add_word'),
|
||||
'link' => Url::internal( "app=core&module=languages&controller=languages&do=addWord" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'add_word' ), 'ipsDialog-remoteSubmit' => TRUE )
|
||||
);
|
||||
}
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( "word_is_custom=? AND lang_id=?", 1, \IPS\Member::loggedIn()->language()->_id ) ) AS $lang )
|
||||
foreach( Db::i()->select( '*', 'core_sys_lang_words', array( "word_is_custom=? AND lang_id=?", 1, Member::loggedIn()->language()->_id ) ) AS $lang )
|
||||
{
|
||||
$tags['cms_tag_lang']['{lang="' . $lang['word_key'] . '"}'] = $lang['word_custom'] ?: $lang['word_default'];
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( \IPS\Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorTags( $tags, $tagLinks ) ), 200, 'text/html' );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( Theme::i()->getTemplate( 'forms', 'core', 'global' )->editorTags( $tags, $tagLinks ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,26 +274,26 @@ class _blocks extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeTemporaryBlock()
|
||||
protected function storeTemporaryBlock() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
$key = md5( mt_rand() );
|
||||
|
||||
while( isset( \IPS\Data\Store::i()->$key ) )
|
||||
while( isset( Store::i()->$key ) )
|
||||
{
|
||||
$key = md5( mt_rand() );
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach( \IPS\Request::i() as $k => $v )
|
||||
foreach( Request::i() as $k => $v )
|
||||
{
|
||||
$data[ $k ] = $v;
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->$key = $data;
|
||||
Store::i()->$key = $data;
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=pages&controller=builder&do=previewBlock&_key=" . $key, 'front' ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=builder&do=previewBlock&_key=" . $key, 'front' ) );
|
||||
}
|
||||
}
|
||||
@@ -12,41 +12,65 @@
|
||||
namespace IPS\cms\modules\admin\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\cms\Media as MediaClass;
|
||||
use IPS\cms\Media\Folder;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Templates;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Helpers\Tree\Tree;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Output\Plugin\Filesize;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* media
|
||||
*/
|
||||
class _media extends \IPS\Node\Controller
|
||||
class media extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\cms\Media\Folder';
|
||||
protected string $nodeClass = '\IPS\cms\Media\Folder';
|
||||
|
||||
/**
|
||||
* @var string[] Additional allowed FileTypes for the media field.
|
||||
*/
|
||||
public static $additionalAllowedMediaFileTypes = array( 'pdf', 'svg' );
|
||||
|
||||
public static array $additionalAllowedMediaFileTypes = array( 'pdf', 'svg', 'woff', 'woff2', 'ttf', 'eot' );
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'media_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'media_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -55,24 +79,24 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
public function _getRootButtons(): array
|
||||
{
|
||||
$buttons = array();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
{
|
||||
$buttons['add_folder'] = array(
|
||||
'icon' => 'folder-open',
|
||||
'title' => 'cms_add_media_folder',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_add_media_folder') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=media&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('cms_add_media_folder') )
|
||||
);
|
||||
|
||||
$buttons['add_page'] = array(
|
||||
'icon' => 'plus-circle',
|
||||
'title' => 'cms_add_media',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media&subnode=1&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_add_media') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=media&subnode=1&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('cms_add_media') )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,19 +108,19 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteByFileIds()
|
||||
public function deleteByFileIds() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
if ( isset( \IPS\Request::i()->fileIds ) )
|
||||
if ( isset( Request::i()->fileIds ) )
|
||||
{
|
||||
$ids = \IPS\Request::i()->fileIds;
|
||||
$ids = Request::i()->fileIds;
|
||||
|
||||
if ( ! \is_array( $ids ) )
|
||||
if ( ! is_array( $ids ) )
|
||||
{
|
||||
$try = json_decode( $ids, TRUE );
|
||||
|
||||
if ( ! \is_array( $try ) )
|
||||
if ( ! is_array( $try ) )
|
||||
{
|
||||
$ids = array( $ids );
|
||||
}
|
||||
@@ -106,11 +130,11 @@ class _media extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $ids ) )
|
||||
if ( count( $ids ) )
|
||||
{
|
||||
\IPS\cms\Media::deleteByFileIds( $ids );
|
||||
MediaClass::deleteByFileIds( $ids );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_deleted_media', array( \count( $ids ) => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_deleted_media', array( count( $ids ) => FALSE ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,104 +142,97 @@ class _media extends \IPS\Node\Controller
|
||||
/**
|
||||
* Show the pages tree
|
||||
*
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
if ( \IPS\Theme::designersModeEnabled() )
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Display the table */
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__cms_pages_media');
|
||||
$output = new Tree( $url, 'menu__cms_pages_media',
|
||||
/* Get Roots */
|
||||
function () use ( $url )
|
||||
{
|
||||
$data = media::getRowsForTree( 0 );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( ( Request::i()->isAjax() && $row instanceof MediaClass ) || !Request::i()->isAjax() )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof MediaClass) ? media::getItemRow( $row, $url ) : media::getFolderRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
/* Get Row */
|
||||
function ( $id, $root ) use ( $url )
|
||||
{
|
||||
if ( $root )
|
||||
{
|
||||
return media::getFolderRow( Folder::load( $id ), $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
return media::getItemRow( MediaClass::load( $id ), $url );
|
||||
}
|
||||
},
|
||||
/* Get Row Parent ID*/
|
||||
function ()
|
||||
{
|
||||
return NULL;
|
||||
},
|
||||
/* Get Children */
|
||||
function ( $id ) use ( $url )
|
||||
{
|
||||
$rows = array();
|
||||
$data = media::getRowsForTree( $id );
|
||||
|
||||
if ( ! isset( Request::i()->subnode ) )
|
||||
{
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( Request::i()->get == 'folders' && !( $row instanceof MediaClass ) )
|
||||
{
|
||||
$rows[ $id ] = media::getFolderRow( $row, $url );
|
||||
}
|
||||
elseif ( Request::i()->get == 'files' && $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( Request::i()->isAjax() ){
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
},
|
||||
array( $this, '_getRootButtons' ),
|
||||
TRUE,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_media.js', 'cms' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'media/media.css', 'cms', 'admin' ) );
|
||||
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
$link = \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmode' );
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'cms_media_designer_mode_warning', FALSE, array( 'sprintf' => array( $link ) ) ), 'information', NULL, FALSE );
|
||||
Output::i()->sendOutput( $output );
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Display the table */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_media');
|
||||
$output = new \IPS\Helpers\Tree\Tree( $url, 'menu__cms_pages_media',
|
||||
/* Get Roots */
|
||||
function () use ( $url )
|
||||
{
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( 0 );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( ( \IPS\Request::i()->isAjax() && $row instanceof \IPS\cms\Media ) || !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof \IPS\cms\Media) ? \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url ) : \IPS\cms\modules\admin\pages\media::getFolderRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() ){
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
/* Get Row */
|
||||
function ( $id, $root ) use ( $url )
|
||||
{
|
||||
if ( $root )
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\media::getFolderRow( \IPS\cms\Media\Folder::load( $id ), $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\media::getItemRow( \IPS\cms\Media::load( $id ), $url );
|
||||
}
|
||||
},
|
||||
/* Get Row Parent ID*/
|
||||
function ()
|
||||
{
|
||||
return NULL;
|
||||
},
|
||||
/* Get Children */
|
||||
function ( $id ) use ( $url )
|
||||
{
|
||||
$rows = array();
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $id );
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->subnode ) )
|
||||
{
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( \IPS\Request::i()->get == 'folders' && !( $row instanceof \IPS\cms\Media ) )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getFolderRow( $row, $url );
|
||||
}
|
||||
elseif ( \IPS\Request::i()->get == 'files' && $row instanceof \IPS\cms\Media )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() ){
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
},
|
||||
array( $this, '_getRootButtons' ),
|
||||
TRUE,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_media.js', 'cms' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'media/media.css', 'cms', 'admin' ) );
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $output, 200, 'text/html' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->media( $output );
|
||||
}
|
||||
Output::i()->output = Theme::i()->getTemplate( 'media', 'cms', 'admin' )->media( $output );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,26 +241,26 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function replace()
|
||||
public function replace() : void
|
||||
{
|
||||
if( !isset( \IPS\Request::i()->id ) OR !\IPS\Request::i()->id )
|
||||
if( !isset( Request::i()->id ) OR !Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'missing_media_file', '3T334/2', 404, '' );
|
||||
Output::i()->error( 'missing_media_file', '3T334/2', 404, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$media = \IPS\cms\Media::load( \IPS\Request::i()->id );
|
||||
$media = MediaClass::load( Request::i()->id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'missing_media_file', '3T334/3', 404, '' );
|
||||
Output::i()->error( 'missing_media_file', '3T334/3', 404, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form = new Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--replace-file ipsForm_noLabels';
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( \IPS\File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => FALSE, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
$form->add( new Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => FALSE, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -253,7 +270,7 @@ class _media extends \IPS\Node\Controller
|
||||
/* If we have the same extension, we will just retain the same filename */
|
||||
if( $existingFileExtension == $newFileExtension )
|
||||
{
|
||||
$media->file_object = (string) \IPS\File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
$media->file_object = (string) File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
}
|
||||
/* Otherwise we need to update the rest of the file info too */
|
||||
else
|
||||
@@ -261,10 +278,10 @@ class _media extends \IPS\Node\Controller
|
||||
$media->is_image = $values['media_filename']->isImage();
|
||||
$media->filename = $values['media_filename']->originalFilename;
|
||||
$media->filename_stored = $media->parent . '_' . $media->filename;
|
||||
$media->file_object = (string) \IPS\File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
$media->file_object = (string) File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
}
|
||||
|
||||
$media->setFullPath( ( $media->parent ? \IPS\cms\Media\Folder::load( $media->parent )->path : '' ) );
|
||||
$media->setFullPath( ( $media->parent ? Folder::load( $media->parent )->path : '' ) );
|
||||
$media->save();
|
||||
|
||||
/* Remove the original as we created a copy with a slightly altered filename */
|
||||
@@ -272,37 +289,37 @@ class _media extends \IPS\Node\Controller
|
||||
{
|
||||
$values['media_filename']->delete();
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( Exception $ex ) { }
|
||||
|
||||
/* Wipe out included JS just in case we're using this media thing */
|
||||
\IPS\cms\Templates::deleteCompiledFiles();
|
||||
\IPS\cms\Pages\Page::deleteCachedIncludes();
|
||||
Templates::deleteCompiledFiles();
|
||||
Page::deleteCachedIncludes();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_replaced_media', array( $values['media_filename']->originalFilename => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_replaced_media', array( $values['media_filename']->originalFilename => FALSE ) );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $media->parent );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = media::getRowsForTree( $media->parent );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if ( $row instanceof \IPS\cms\Media )
|
||||
if ( $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'fileID' => $media->id, 'folderID' => $media->parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'fileID' => $media->id, 'folderID' => $media->parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
}
|
||||
|
||||
|
||||
@@ -311,23 +328,23 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function upload()
|
||||
public function upload() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form = new Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--upload-items ipsForm_noLabels';
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( \IPS\File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => true, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
$form->add( new Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => true, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->media_parent ) and ! \IPS\Request::i()->media_parent )
|
||||
if ( ! isset( Request::i()->media_parent ) and ! Request::i()->media_parent )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'media_parent', 0, FALSE, array(
|
||||
$form->add( new Node( 'media_parent', 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Media\Folder',
|
||||
'zeroVal' => 'node_no_parent'
|
||||
) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->hiddenValues['media_parent_inline'] = \IPS\Request::i()->media_parent;
|
||||
$form->hiddenValues['media_parent_inline'] = Request::i()->media_parent;
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
@@ -358,7 +375,7 @@ class _media extends \IPS\Node\Controller
|
||||
$filename = mb_substr( $filename, mb_strlen( $prefix ) );
|
||||
}
|
||||
|
||||
$new = new \IPS\cms\Media;
|
||||
$new = new MediaClass;
|
||||
$new->filename = $filename;
|
||||
$new->filename_stored = $parent . '_' . $filename;
|
||||
$new->is_image = $media->isImage();
|
||||
@@ -367,41 +384,41 @@ class _media extends \IPS\Node\Controller
|
||||
$new->file_object = (string) $media;
|
||||
$new->save();
|
||||
|
||||
$new->setFullPath( ( $parent ? \IPS\cms\Media\Folder::load( $parent )->path : '' ) );
|
||||
$new->setFullPath( ( $parent ? Folder::load( $parent )->path : '' ) );
|
||||
$new->save();
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
/* Wipe out included JS just in case we're using this media thing */
|
||||
\IPS\cms\Templates::deleteCompiledFiles();
|
||||
\IPS\cms\Pages\Page::deleteCachedIncludes();
|
||||
Templates::deleteCompiledFiles();
|
||||
Page::deleteCachedIncludes();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_uploaded_media', array( $count => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_uploaded_media', array( $count => FALSE ) );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $parent );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = media::getRowsForTree( $parent );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if ( $row instanceof \IPS\cms\Media )
|
||||
if ( $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'count' => $count, 'folderID' => $parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'count' => $count, 'folderID' => $parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,13 +426,13 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function search()
|
||||
protected function search() : void
|
||||
{
|
||||
$rows = array();
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Get results */
|
||||
$items = \IPS\cms\Media::search( 'media_filename', \IPS\Request::i()->input, 'media_filename' );
|
||||
$items = MediaClass::search( 'media_filename', Request::i()->input, 'media_filename' );
|
||||
|
||||
/* Convert to HTML */
|
||||
foreach ( $items as $id => $result )
|
||||
@@ -423,13 +440,13 @@ class _media extends \IPS\Node\Controller
|
||||
$rows[ $id ] = $this->getItemRow( $result, $url );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,21 +455,21 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getFileInfo()
|
||||
protected function getFileInfo() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$row = \IPS\cms\Media::load( \IPS\Request::i()->id );
|
||||
$fileObject = \IPS\File::get( 'cms_Media', $row->file_object );
|
||||
$row = MediaClass::load( Request::i()->id );
|
||||
$fileObject = File::get( 'cms_Media', $row->file_object );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make a human-readable size */
|
||||
$filesize = \IPS\Output\Plugin\Filesize::humanReadableFilesize( $fileObject->filesize() );
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $filesize );
|
||||
$filesize = Filesize::humanReadableFilesize( $fileObject->filesize() );
|
||||
Member::loggedIn()->language()->parseOutputForDisplay( $filesize );
|
||||
|
||||
$output = array(
|
||||
'fileSize' => $filesize,
|
||||
@@ -466,60 +483,61 @@ class _media extends \IPS\Node\Controller
|
||||
$output['dimensions'] = $dimensions[0] . ' x ' . $dimensions[1];
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( $output ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( $output ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a page row
|
||||
*
|
||||
* @param array $item Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @param MediaClass $item Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getItemRow( $item, $url )
|
||||
public static function getItemRow( MediaClass $item, object $url ): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->fileListing( $url, $item );
|
||||
return Theme::i()->getTemplate( 'media', 'cms', 'admin' )->fileListing( $url, $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a folder row
|
||||
*
|
||||
* @param array $folder Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @param MediaClass|Folder $folder Row data
|
||||
* @param Url $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getFolderRow( $folder, $url )
|
||||
public static function getFolderRow( MediaClass|Folder $folder, Url $url ): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->folderRow( $url, $folder );
|
||||
return Theme::i()->getTemplate( 'media', 'cms', 'admin' )->folderRow( $url, $folder );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch rows of folders/pages
|
||||
*
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @return array
|
||||
*/
|
||||
public static function getRowsForTree( $folderId=0 )
|
||||
public static function getRowsForTree( int $folderId=0 ) : array
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $folderId === 0 )
|
||||
{
|
||||
$folders = \IPS\cms\Media\Folder::roots();
|
||||
$folders = Folder::roots();
|
||||
}
|
||||
else
|
||||
{
|
||||
$folders = \IPS\cms\Media\Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
$folders = Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
$folders = array();
|
||||
}
|
||||
|
||||
$media = \IPS\cms\Media::getChildren( $folderId );
|
||||
$media = MediaClass::getChildren( $folderId );
|
||||
|
||||
return \IPS\cms\Media\Folder::munge( $folders, $media );
|
||||
return Folder::munge( $folders, $media );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,40 +13,69 @@
|
||||
namespace IPS\cms\modules\admin\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Pages\Folder;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Badge;
|
||||
use IPS\Helpers\Badge\Icon;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Tree\Tree;
|
||||
use IPS\Http\url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function strpos;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page management
|
||||
*/
|
||||
class _pages extends \IPS\Node\Controller
|
||||
class pages extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\cms\Pages\Folder';
|
||||
protected string $nodeClass = '\IPS\cms\Pages\Folder';
|
||||
|
||||
/**
|
||||
* Store the database page map to prevent many queries
|
||||
*/
|
||||
protected static $pageToDatabaseMap = NULL;
|
||||
protected static ?array $pageToDatabaseMap = NULL;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'page_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'page_manage' );
|
||||
|
||||
static::$pageToDatabaseMap = iterator_to_array( Db::i()->select( 'database_id, database_page_id', 'cms_databases', array( 'database_page_id > 0' ) )->setKeyField('database_page_id')->setValueField('database_id') );
|
||||
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -55,36 +84,32 @@ class _pages extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
public function _getRootButtons(): array
|
||||
{
|
||||
$nodeClass = $this->nodeClass;
|
||||
$buttons = array();
|
||||
|
||||
return $buttons;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the pages tree
|
||||
*
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" );
|
||||
static::$pageToDatabaseMap = iterator_to_array( \IPS\Db::i()->select( 'database_id, database_page_id', 'cms_databases', array( 'database_page_id > 0' ) )->setKeyField('database_page_id')->setValueField('database_id') );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=pages" );
|
||||
|
||||
/* Display the table */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_pages');
|
||||
\IPS\Output::i()->output = new \IPS\Helpers\Tree\Tree( $url, 'menu__cms_pages_pages',
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__cms_pages_pages');
|
||||
Output::i()->output = new Tree( $url, 'menu__cms_pages_pages',
|
||||
/* Get Roots */
|
||||
function () use ( $url )
|
||||
{
|
||||
$data = \IPS\cms\modules\admin\pages\pages::getRowsForTree( 0 );
|
||||
$data = pages::getRowsForTree( 0 );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof \IPS\cms\Pages\Page ) ? \IPS\cms\modules\admin\pages\pages::getPageRow( $row, $url ) : \IPS\cms\modules\admin\pages\pages::getFolderRow( $row, $url );
|
||||
$rows[ $id ] = ( $row instanceof Page ) ? pages::getPageRow( $row, $url ) : pages::getFolderRow( $row, $url );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
@@ -94,11 +119,11 @@ class _pages extends \IPS\Node\Controller
|
||||
{
|
||||
if ( $root )
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\pages::getFolderRow( \IPS\cms\Pages\Folder::load( $id ), $url );
|
||||
return pages::getFolderRow( Folder::load( $id ), $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\pages::getPageRow( \IPS\cms\Pages\Page::load( $id ), $url );
|
||||
return pages::getPageRow( Page::load( $id ), $url );
|
||||
}
|
||||
},
|
||||
/* Get Row Parent ID*/
|
||||
@@ -110,13 +135,13 @@ class _pages extends \IPS\Node\Controller
|
||||
function ( $id ) use ( $url )
|
||||
{
|
||||
$rows = array();
|
||||
$data = \IPS\cms\modules\admin\pages\pages::getRowsForTree( $id );
|
||||
$data = pages::getRowsForTree( $id );
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->subnode ) )
|
||||
if ( ! isset( Request::i()->subnode ) )
|
||||
{
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof \IPS\cms\Pages\Page ) ? \IPS\cms\modules\admin\pages\pages::getPageRow( $row, $url ) : \IPS\cms\modules\admin\pages\pages::getFolderRow( $row, $url );
|
||||
$rows[ $id ] = ( $row instanceof Page ) ? pages::getPageRow( $row, $url ) : pages::getFolderRow( $row, $url );
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
@@ -127,22 +152,21 @@ class _pages extends \IPS\Node\Controller
|
||||
FALSE
|
||||
);
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['add_folder'] = array(
|
||||
Output::i()->sidebar['actions']['add_folder'] = array(
|
||||
'primary' => true,
|
||||
'icon' => 'folder-open',
|
||||
'title' => 'content_add_folder',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_folder') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=pages&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('content_add_folder') )
|
||||
);
|
||||
|
||||
\IPS\Output::i()->sidebar['actions']['add_page'] = array(
|
||||
Output::i()->sidebar['actions']['add_page'] = array(
|
||||
'primary' => true,
|
||||
'icon' => 'plus-circle',
|
||||
'title' => 'content_add_page',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&subnode=1&do=add' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_page') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=pages&subnode=1&do=form&subnode=1' )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -152,12 +176,12 @@ class _pages extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function htaccess()
|
||||
protected function htaccess() : void
|
||||
{
|
||||
$dir = str_replace( \IPS\CP_DIRECTORY . '/index.php', '', $_SERVER['PHP_SELF'] );
|
||||
$dir = str_replace( 'admin/index.php', '', $_SERVER['PHP_SELF'] );
|
||||
$dirs = explode( '/', trim( $dir, '/' ) );
|
||||
|
||||
if ( \count( $dirs ) )
|
||||
if ( count( $dirs ) )
|
||||
{
|
||||
array_pop( $dirs );
|
||||
$dir = implode( '/', $dirs );
|
||||
@@ -170,7 +194,7 @@ class _pages extends \IPS\Node\Controller
|
||||
|
||||
$path = $dir . 'index.php';
|
||||
|
||||
if( \strpos( $dir, ' ' ) !== FALSE )
|
||||
if( strpos( $dir, ' ' ) !== FALSE )
|
||||
{
|
||||
$dir = '"' . $dir . '"';
|
||||
$path = '"' . $path . '"';
|
||||
@@ -191,42 +215,39 @@ RewriteRule . {$path} [L]
|
||||
</IfModule>
|
||||
FILE;
|
||||
|
||||
\IPS\Output::i()->sendOutput( $htaccess, 200, 'application/x-htaccess', array( 'Content-Disposition' => 'attachment; filename=.htaccess' ) );
|
||||
Output::i()->sendOutput( $htaccess, 200, 'application/x-htaccess', array( 'Content-Disposition' => 'attachment; filename=.htaccess' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Page content form
|
||||
* Add/Edit Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function add()
|
||||
protected function form() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'page_add' );
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'next' );
|
||||
$form->hiddenValues['parent'] = ( isset( \IPS\Request::i()->parent ) ) ? \IPS\Request::i()->parent : 0;
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio(
|
||||
'page_type',
|
||||
NULL,
|
||||
FALSE,
|
||||
array( 'options' => array( 'builder' => 'page_type_builder', 'html' => 'page_type_manual' ),
|
||||
'descriptions' => array( 'builder' => 'page_type_builder_desc', 'html' => 'page_type_manual_custom_desc' ) ),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'page_type'
|
||||
) );
|
||||
|
||||
|
||||
if ( $values = $form->values() )
|
||||
/* If this is a database page, redirect to database form */
|
||||
if( isset( static::$pageToDatabaseMap[ Request::i()->id ] ) )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&do=form&subnode=1&page_type=' . $values['page_type'] . '&parent=' . \IPS\Request::i()->parent ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=databases&do=form&id=" . static::$pageToDatabaseMap[ Request::i()->id ] ) );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( \IPS\Member::loggedIn()->language()->addToStack('content_add_page'), $form, FALSE );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_add_page');
|
||||
parent::form();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permissions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function permissions() : void
|
||||
{
|
||||
/* If this is a database page, redirect to database permissions */
|
||||
if( isset( static::$pageToDatabaseMap[ Request::i()->id ] ) )
|
||||
{
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=databases&controller=databases&do=permissions&id=" . static::$pageToDatabaseMap[ Request::i()->id ] ) );
|
||||
}
|
||||
|
||||
parent::permissions();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,15 +255,21 @@ FILE;
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
/* Database pages cannot be deleted from here */
|
||||
if( isset( static::$pageToDatabaseMap[ Request::i()->id ] ) )
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\IPS\cms\Pages\Page::deleteCompiled( \IPS\Request::i()->id );
|
||||
Output::i()->error( Member::loggedIn()->language()->addToStack( 'content_acp_err_page_db_delete' ), '3T260/1', 403 );
|
||||
}
|
||||
|
||||
return parent::delete();
|
||||
if ( isset( Request::i()->id ) )
|
||||
{
|
||||
Session::i()->csrfCheck();
|
||||
Page::deleteCompiled( Request::i()->id );
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,11 +277,11 @@ FILE;
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setAsDefault()
|
||||
protected function setAsDefault() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\IPS\cms\Pages\Page::load( \IPS\Request::i()->id )->setAsDefault();
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
|
||||
Session::i()->csrfCheck();
|
||||
Page::load( Request::i()->id )->setAsDefault();
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,11 +289,11 @@ FILE;
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function toggleDefaultError()
|
||||
protected function toggleDefaultError() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
\IPS\Settings::i()->changeValues( array( 'cms_error_page' => \IPS\Request::i()->id ? \IPS\Request::i()->id : NULL ) );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
|
||||
Session::i()->csrfCheck();
|
||||
Settings::i()->changeValues( array( 'cms_error_page' => Request::i()->id ? Request::i()->id : NULL ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,120 +301,128 @@ FILE;
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function search()
|
||||
protected function search() : void
|
||||
{
|
||||
$rows = array();
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=pages" );
|
||||
|
||||
/* Get results */
|
||||
$folders = \IPS\cms\Pages\Folder::search( 'folder_name' , \IPS\Request::i()->input, 'folder_name' );
|
||||
$pages = \IPS\cms\Pages\Page::search( 'page_seo_name', \IPS\Request::i()->input, 'page_seo_name' );
|
||||
$folders = Folder::search( 'folder_name' , Request::i()->input, 'folder_name' );
|
||||
$pages = Page::search( 'page_seo_name', Request::i()->input, 'page_seo_name' );
|
||||
|
||||
$results = \IPS\cms\Pages\Folder::munge( $folders, $pages );
|
||||
$results = Folder::munge( $folders, $pages );
|
||||
|
||||
/* Convert to HTML */
|
||||
foreach ( $results as $id => $result )
|
||||
{
|
||||
$rows[ $id ] = ( $result instanceof \IPS\cms\Pages\Page ) ? $this->getPageRow( $result, $url ) : $this->getFolderRow( $result, $url );
|
||||
$rows[ $id ] = ( $result instanceof Page ) ? $this->getPageRow( $result, $url ) : $this->getFolderRow( $result, $url );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a page row
|
||||
*
|
||||
* @param array $page Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
* @param Page $page Row data
|
||||
* @param url $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getPageRow( $page, $url )
|
||||
public static function getPageRow( Page $page, Url $url ): string
|
||||
{
|
||||
$badge = NULL;
|
||||
$description = "";
|
||||
|
||||
if ( isset( static::$pageToDatabaseMap[ $page->id ] ) )
|
||||
{
|
||||
$badge = array( 0 => 'style7', 1 => \IPS\Member::loggedIn()->language()->addToStack( 'page_database_display', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('content_db_' . static::$pageToDatabaseMap[ $page->id ] ) ) ) ) );
|
||||
$badge = array( 0 => 'style7', 1 => Member::loggedIn()->language()->addToStack( 'page_database_display', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack('content_db_' . static::$pageToDatabaseMap[ $page->id ] ) ) ) ) );
|
||||
|
||||
$description = "<i class='fa-solid fa-triangle-exclamation i-margin-end_icon'></i> " .
|
||||
Member::loggedIn()->language()->addToStack( 'page_database_edit_message', true, array(
|
||||
'sprintf' => array( Url::internal( "app=cms&module=databases&controller=databases&do=form&id=" . static::$pageToDatabaseMap[ $page->id ] ) )
|
||||
) );
|
||||
}
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $page->id, $page->seo_name, false, $page->getButtons( \IPS\Http\Url::internal('app=cms&module=pages&controller=pages'), true ), \IPS\Member::loggedIn()->language()->addToStack( 'num_views_with_number', NULL, array( 'pluralize' => array( $page->views ) ) ), 'file-text-o', NULL, FALSE, NULL, NULL, $badge, FALSE, FALSE, FALSE );
|
||||
return Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $page->id, $page->seo_name, false, $page->getButtons( \IPS\Http\Url::internal('app=cms&module=pages&controller=pages'), true ), Member::loggedIn()->language()->addToStack( 'num_views_with_number', NULL, array( 'pluralize' => array( $page->views ) ) ), 'file-text-o', NULL, FALSE, NULL, NULL, $badge, FALSE, FALSE, FALSE );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a folder row
|
||||
*
|
||||
* @param array $folder Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @param Folder $folder Row data
|
||||
* @param Url $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getFolderRow( $folder, $url )
|
||||
public static function getFolderRow( Folder $folder, Url $url ): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $folder->id, $folder->name, true, $folder->getButtons( \IPS\Http\Url::internal('app=cms&module=pages&controller=pages') ), "", 'folder-o', NULL );
|
||||
return Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $folder->id, $folder->name, true, $folder->getButtons( Url::internal('app=cms&module=pages&controller=pages') ), "", 'folder', NULL );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch rows of folders/pages
|
||||
*
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @return array
|
||||
*/
|
||||
public static function getRowsForTree( $folderId=0 )
|
||||
public static function getRowsForTree( int $folderId=0 ) : array
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $folderId === 0 )
|
||||
{
|
||||
$folders = \IPS\cms\Pages\Folder::roots();
|
||||
$folders = Folder::roots();
|
||||
}
|
||||
else
|
||||
{
|
||||
$folders = \IPS\cms\Pages\Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
$folders = Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
$folders = array();
|
||||
}
|
||||
|
||||
$pages = \IPS\cms\Pages\Page::getChildren( $folderId );
|
||||
$pages = Page::getChildren( $folderId );
|
||||
|
||||
return \IPS\cms\Pages\Folder::munge( $folders, $pages );
|
||||
return Folder::munge( $folders, $pages );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
|
||||
* @param \IPS\Node\Model $new The node now
|
||||
* @param string $lastUsedTab The tab last used in the form
|
||||
* @return void
|
||||
* @param Model|null $old A clone of the node as it was before or NULL if this is a creation
|
||||
* @param Model $new The node now
|
||||
* @param string|bool $lastUsedTab The tab last used in the form
|
||||
* @return void
|
||||
*/
|
||||
protected function _afterSave( ?\IPS\Node\Model $old, \IPS\Node\Model $new, $lastUsedTab = FALSE )
|
||||
protected function _afterSave( ?Model $old, Model $new, mixed $lastUsedTab=FALSE ): void
|
||||
{
|
||||
/* Is there a default page in the folder? */
|
||||
try
|
||||
{
|
||||
$existingDefault = \IPS\Db::i()->select( 'page_id', 'cms_pages', array( 'page_folder_id=? and page_default=? and page_id <> ?', $new->folder_id, 1, $new->id ) )->first();
|
||||
$existingDefault = Db::i()->select( 'page_id', 'cms_pages', array( 'page_folder_id=? and page_default=? and page_id <> ?', $new->folder_id, 1, $new->id ) )->first();
|
||||
|
||||
/* If this page was the default in a folder, and it was moved to a new folder that already has a default, we need to unset the
|
||||
default page flag or there will be two defaults in the destination folder */
|
||||
if( $old !== NULL AND $old->folder_id != $new->folder_id AND $old->default )
|
||||
{
|
||||
\IPS\Db::i()->update( 'cms_pages', array( 'page_default' => 0 ), array( 'page_id=?', $new->id ) );
|
||||
Db::i()->update( 'cms_pages', array( 'page_default' => 0 ), array( 'page_id=?', $new->id ) );
|
||||
|
||||
\IPS\cms\Pages\Page::buildPageUrlStore();
|
||||
Page::buildPageUrlStore();
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* No default found in destination folder, make this the default */
|
||||
\IPS\Db::i()->update( 'cms_pages', array( 'page_default' => 1 ), array( 'page_id=?', $new->id ) );
|
||||
Db::i()->update( 'cms_pages', array( 'page_default' => 1 ), array( 'page_id=?', $new->id ) );
|
||||
|
||||
\IPS\cms\Pages\Page::buildPageUrlStore();
|
||||
Page::buildPageUrlStore();
|
||||
}
|
||||
|
||||
/* If page filename changes or the folder ID changes, we need to clear front navigation cache*/
|
||||
if( $old !== NULL AND ( $old->folder_id != $new->folder_id OR $old->seo_name != $new->seo_name ) )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->pages_page_urls );
|
||||
unset( Store::i()->pages_page_urls );
|
||||
}
|
||||
|
||||
parent::_afterSave( $old, $new, $lastUsedTab );
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user