Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+94 -86
View File
@@ -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' ) );
}
}