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
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief ajax
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Pages
|
||||
* @since 13 Dec 2023
|
||||
*/
|
||||
|
||||
namespace IPS\cms\modules\front\pages;
|
||||
|
||||
use IPS\cms\Categories;
|
||||
use IPS\cms\Pages\Folder;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\Db;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Theme;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* ajax
|
||||
*/
|
||||
class ajax extends \IPS\cms\modules\admin\pages\ajax
|
||||
{
|
||||
/**
|
||||
* Load navigation items
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loadItems() : void
|
||||
{
|
||||
if( Request::i()->navType == 'folder' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$folder = Folder::load( Request::i()->container );
|
||||
$items = iterator_to_array(
|
||||
new ActiveRecordIterator(
|
||||
Db::i()->select( '*', 'cms_pages', [ 'page_folder_id=?', $folder->id ] ),
|
||||
Page::class
|
||||
)
|
||||
);
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->folderNavigationItems( $items ) );
|
||||
}
|
||||
catch( OutOfRangeException ){}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* @var Categories $containerClass */
|
||||
$containerClass = 'IPS\cms\Categories' . Request::i()->navId;
|
||||
try
|
||||
{
|
||||
$container = $containerClass::load( Request::i()->container );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'widgets', 'cms', 'front' )->databaseNavigationItems( $container->getContentItems( null, null ) ) );
|
||||
}
|
||||
catch( OutOfRangeException ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,278 +12,52 @@
|
||||
namespace IPS\cms\modules\front\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Blocks\Block;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Widget;
|
||||
use IPS\cms\widgets\Blocks;
|
||||
use IPS\core\modules\front\system\widgets;
|
||||
use IPS\Db;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Widget\Area;
|
||||
use OutOfRangeException;
|
||||
use Throwable;
|
||||
use UnderFlowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function var_export;
|
||||
|
||||
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
|
||||
*/
|
||||
class _builder extends \IPS\core\modules\front\system\widgets
|
||||
class builder extends widgets
|
||||
{
|
||||
|
||||
/**
|
||||
* Get Output For Adding A New Block
|
||||
* The widget class to use for configuration
|
||||
*
|
||||
* @return void
|
||||
* @var string
|
||||
*/
|
||||
protected function getBlock()
|
||||
{
|
||||
$key = $block = explode( "_", \IPS\Request::i()->blockID );
|
||||
|
||||
if ( isset( \IPS\Request::i()->pageID ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=?', \IPS\Request::i()->pageID ) ) as $item )
|
||||
{
|
||||
$blocks = json_decode( $item['area_widgets'], TRUE );
|
||||
|
||||
foreach( $blocks as $block )
|
||||
{
|
||||
if( $block['key'] == $key[2] AND $block['unique'] == $key[3] )
|
||||
{
|
||||
if ( isset( $block['app'] ) and $block['app'] == $key[1] )
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Application::load( $block['app'] ), $block['key'], $block['unique'], $block['configuration'], null, \IPS\Request::i()->orientation );
|
||||
}
|
||||
elseif ( isset( $block['plugin'] ) and $block['plugin'] == $key[1] )
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Plugin::load( $block['plugin'] ), $block['key'], $block['unique'], $block['configuration'], null, \IPS\Request::i()->orientation );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
protected string $widgetClass = Widget::class;
|
||||
|
||||
/* Make sure the current page is set so the widgets have database/page scope */
|
||||
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID );
|
||||
|
||||
/* Have we got a database for this page? */
|
||||
$database = \IPS\cms\Pages\Page::$currentPage->getDatabase();
|
||||
|
||||
if ( $database )
|
||||
{
|
||||
\IPS\cms\Databases\Dispatcher::i()->setDatabase( $database->id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !isset( $widget ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Application::load( $key[1] ), $key[2], $key[3], array(), null, \IPS\Request::i()->orientation );
|
||||
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Plugin::load( $key[1] ), $key[2], $key[3], array(), null, \IPS\Request::i()->orientation );
|
||||
}
|
||||
}
|
||||
|
||||
$output = (string) $widget;
|
||||
|
||||
\IPS\Output::i()->output = ( $output ) ? $output : \IPS\Theme::i()->getTemplate( 'widgets', 'core', 'front' )->blankWidget( $widget );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Configuration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getConfiguration()
|
||||
{
|
||||
/* Standard widget area, allow the core stuff to handle this */
|
||||
if( \in_array( \IPS\Request::i()->area, array( 'sidebar', 'header', 'footer' ) ) )
|
||||
{
|
||||
return parent::getConfiguration();
|
||||
}
|
||||
|
||||
$key = explode( "_", \IPS\Request::i()->block );
|
||||
$blocks = array( 'area_widgets' => NULL );
|
||||
|
||||
/* CMS only stuff */
|
||||
try
|
||||
{
|
||||
$blocks = \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=? AND area_area=?', \IPS\Request::i()->pageID, \IPS\Request::i()->pageArea ) )->first();
|
||||
|
||||
$where = ( $key[0] ) == 'app' ? '`key`=? AND `app`=?' : '`key`=? AND `plugin`=?';
|
||||
$widgetMaster = \IPS\Db::i()->select( '*', 'core_widgets', array( $where, $key[2], $key[1] ) )->first();
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
}
|
||||
|
||||
$blocks = json_decode( $blocks['area_widgets'], TRUE );
|
||||
$widget = NULL;
|
||||
|
||||
if( !empty( $blocks ) )
|
||||
{
|
||||
foreach ( $blocks as $k => $block )
|
||||
{
|
||||
if ( $block['key'] == $key[2] AND $block['unique'] == $key[3] )
|
||||
{
|
||||
if ( isset( $block['app'] ) and $block['app'] == $key[1] )
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Application::load( $block['app'] ), $block['key'], $block['unique'], $block['configuration'] );
|
||||
$widget->menuStyle = $widgetMaster['menu_style'];
|
||||
}
|
||||
elseif ( isset( $block['plugin'] ) and $block['plugin'] == $key[1] )
|
||||
{
|
||||
$widget = \IPS\Widget::load( \IPS\Plugin::load( $block['plugin'] ), $block['key'], $block['unique'], $block['configuration'] );
|
||||
$widget->menuStyle = $widgetMaster['menu_style'];
|
||||
}
|
||||
}
|
||||
|
||||
if( $widget !== NULL AND method_exists( $widget, 'configuration' ) )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'saveSettings' );
|
||||
if ( $widget->configuration( $form ) !== NULL )
|
||||
{
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( method_exists( $widget, 'preConfig' ) )
|
||||
{
|
||||
$values = $widget->preConfig( $values );
|
||||
}
|
||||
|
||||
/* Special advanced builder stuff */
|
||||
if ( \in_array( 'IPS\Widget\Builder', class_implements( $widget ) ) )
|
||||
{
|
||||
if( isset( $values['widget_adv__background_custom_image'] ) and $values['widget_adv__background_custom_image'] )
|
||||
{
|
||||
$values['widget_adv__background_custom_image'] = (string) $values['widget_adv__background_custom_image'];
|
||||
}
|
||||
}
|
||||
|
||||
$blocks[ $k ]['configuration'] = $values;
|
||||
\IPS\Db::i()->insert( 'cms_page_widget_areas', array( 'area_page_id' => \IPS\Request::i()->pageID, 'area_area' => \IPS\Request::i()->pageArea, 'area_widgets' => json_encode( $blocks ) ), TRUE );
|
||||
|
||||
/* Reindex the page any time the blocks are updated */
|
||||
try
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( \IPS\cms\Pages\PageItem::load( \IPS\Request::i()->pageID ) );
|
||||
}
|
||||
catch( \OutOfRangeException ){}
|
||||
|
||||
\IPS\Output::i()->json( 'OK' );
|
||||
}
|
||||
\IPS\Output::i()->output = $widget->configuration()->customTemplate( array( \IPS\Theme::i()->getTemplate( 'widgets', 'core' ), 'formTemplate' ), $widget );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder Blocks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function saveOrder()
|
||||
protected function saveOrder() : void
|
||||
{
|
||||
$newOrder = array();
|
||||
$seen = array();
|
||||
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$currentConfig = \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=? AND area_area=?', \IPS\Request::i()->pageID, \IPS\Request::i()->area ) )->first();
|
||||
$widgets = json_decode( $currentConfig['area_widgets'], TRUE );
|
||||
if( !is_countable( $widgets ) )
|
||||
{
|
||||
throw new \UnderflowException;
|
||||
}
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$widgets = array();
|
||||
}
|
||||
|
||||
/* Loop over the new order and merge in current blocks so we don't lose config */
|
||||
if ( isset ( \IPS\Request::i()->order ) )
|
||||
{
|
||||
foreach ( \IPS\Request::i()->order as $block )
|
||||
{
|
||||
$block = explode( "_", $block );
|
||||
|
||||
$added = FALSE;
|
||||
foreach( $widgets as $widget )
|
||||
{
|
||||
if ( $widget['key'] == $block[2] and $widget['unique'] == $block[3] )
|
||||
{
|
||||
$seen[] = $widget['unique'];
|
||||
$newOrder[] = $widget;
|
||||
$added = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !$added )
|
||||
{
|
||||
$newBlock = array();
|
||||
|
||||
if ( $block[0] == 'app' )
|
||||
{
|
||||
$newBlock['app'] = $block[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$newBlock['plugin'] = $block[1];
|
||||
}
|
||||
|
||||
$newBlock['key'] = $block[2];
|
||||
$newBlock['unique'] = $block[3];
|
||||
$newBlock['configuration'] = array();
|
||||
|
||||
/* Make sure this widget doesn't have configuration in another area */
|
||||
$newBlock['configuration'] = \IPS\cms\Widget::getConfiguration( $newBlock['unique'] );
|
||||
|
||||
$seen[] = $block[3];
|
||||
$newOrder[] = $newBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Anything to update? */
|
||||
if ( \count( $widgets ) > \count( $newOrder ) )
|
||||
{
|
||||
/* No items left in area, or one has been removed */
|
||||
foreach( $widgets as $widget )
|
||||
{
|
||||
/* If we haven't seen this widget, it's been removed, so add to trash */
|
||||
if ( ! \in_array( $widget['unique'], $seen ) )
|
||||
{
|
||||
\IPS\Widget::trash( $widget['unique'], $widget );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check core_widget_areas to ensure that the block wasn't added there */
|
||||
if ( isset( \IPS\Request::i()->exclude ) and ! empty( \IPS\Request::i()->exclude ) )
|
||||
{
|
||||
$bits = explode( "_", \IPS\Request::i()->exclude );
|
||||
$this->_checkAndDeleteFromCoreWidgets( $bits[3], $seen );
|
||||
}
|
||||
|
||||
/* Expire Caches so up to date information displays */
|
||||
\IPS\Widget::deleteCaches();
|
||||
|
||||
/* Save to database */
|
||||
$orientation = ( isset( \IPS\Request::i()->orientation ) and \IPS\Request::i()->orientation === 'vertical' ) ? 'vertical' : 'horizontal';
|
||||
\IPS\Db::i()->replace( 'cms_page_widget_areas', array( 'area_orientation' => $orientation, 'area_page_id' => \IPS\Request::i()->pageID, 'area_widgets' => json_encode( $newOrder ), 'area_area' => \IPS\Request::i()->area ) );
|
||||
|
||||
/* Reindex the page any time the blocks are updated */
|
||||
try
|
||||
{
|
||||
\IPS\Content\Search\Index::i()->index( \IPS\cms\Pages\PageItem::load( \IPS\Request::i()->pageID ) );
|
||||
}
|
||||
catch( \OutOfRangeException ){}
|
||||
|
||||
\IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID )->postWidgetOrderSave();
|
||||
parent::saveOrder();
|
||||
$page = Page::load( Request::i()->pageID );
|
||||
$page->postSaveArea();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,18 +65,18 @@ class _builder extends \IPS\core\modules\front\system\widgets
|
||||
* It may be that the CMS JS mixin doesn't load so the core ajax URLs are used (system/widgets.php) and not the cms widget (page/builder.php).
|
||||
* This method ensures that any widgets in the core table are removed
|
||||
*
|
||||
* @param string $uniqueId The unique key of the widget (eg: wzsj1233)
|
||||
* @param array $widgets Current widgets (eg from core_widget_areas.widgets (json decoded))
|
||||
* @param string $uniqueId The unique key of the widget (eg: wzsj1233)
|
||||
* @param array $widgets Current widgets (eg from core_widget_areas.widgets (json decoded))
|
||||
* @return bool True if something removed, false if not
|
||||
*/
|
||||
protected function _checkAndDeleteFromCoreWidgets( $uniqueId, $widgets )
|
||||
protected function _checkAndDeleteFromCoreWidgets( string $uniqueId, array $widgets ): bool
|
||||
{
|
||||
if ( ! \in_array( $uniqueId, $widgets ) )
|
||||
if ( ! in_array( $uniqueId, $widgets ) )
|
||||
{
|
||||
/* This widget hasn't been seen, so it isn't in the cms table */
|
||||
try
|
||||
{
|
||||
$cmsWidget = \IPS\Db::i()->select( '*', 'core_widget_areas', array( 'app=? and module=? and controller=? and area=?', 'cms', 'pages', 'page', \IPS\Request::i()->area ) )->first();
|
||||
$cmsWidget = Db::i()->select( '*', 'core_widget_areas', array( 'app=? and module=? and controller=? and area=?', 'cms', 'pages', 'page', Request::i()->area ) )->first();
|
||||
$cmsWidgets = json_decode( $cmsWidget['widgets'], TRUE );
|
||||
$newWidgets = array();
|
||||
|
||||
@@ -315,23 +89,86 @@ class _builder extends \IPS\core\modules\front\system\widgets
|
||||
}
|
||||
|
||||
/* Anything to save? */
|
||||
if ( \count( $newWidgets ) )
|
||||
if ( count( $newWidgets ) )
|
||||
{
|
||||
\IPS\Db::i()->replace( 'core_widget_areas', array( 'app' => 'cms', 'module' => 'pages', 'controller' => 'page', 'widgets' => json_encode( $newWidgets ), 'area' => \IPS\Request::i()->area ) );
|
||||
Db::i()->replace( 'core_widget_areas', array( 'app' => 'cms', 'module' => 'pages', 'controller' => 'page', 'widgets' => json_encode( $newWidgets ), 'area' => Request::i()->area ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just remove the entire row */
|
||||
\IPS\Db::i()->delete( 'core_widget_areas', array( 'app=? and module=? and controller=? and area=?', 'cms', 'pages', 'page', \IPS\Request::i()->area ) );
|
||||
Db::i()->delete( 'core_widget_areas', array( 'app=? and module=? and controller=? and area=?', 'cms', 'pages', 'page', Request::i()->area ) );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
catch( \UnderFlowException $ex )
|
||||
catch( UnderFlowException $ex )
|
||||
{
|
||||
/* Well, it isn't there either... */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array containing all the areas in this page
|
||||
*
|
||||
* @param string|null $area The area to filter by; by default (null) it will get all areas
|
||||
*
|
||||
* @return Area[] Returns an array mapping the widget areas to the widgets in that area
|
||||
*/
|
||||
public function getAreasFromDatabase( ?string $area=null ) : array
|
||||
{
|
||||
$page = Page::load( Request::i()->pageID );
|
||||
return $page->getAreasFromDatabase( $area );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an area to the database and link it to the page
|
||||
*
|
||||
* @param Area $area
|
||||
* @return void
|
||||
*/
|
||||
public function saveArea( Area $area ) : void
|
||||
{
|
||||
$page = Page::load( Request::i()->pageID );
|
||||
$page->saveArea( $area );
|
||||
|
||||
/* Clear caches */
|
||||
Widget::deleteCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the content of a custom block
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getCustomBlockContent() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$block = Block::load( Request::i()->id );
|
||||
|
||||
try
|
||||
{
|
||||
$widget = $block->widget();
|
||||
}
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
$widget = new Blocks( "", ['cms_widget_custom_block' => $block->key] );
|
||||
}
|
||||
Output::i()->json( [ "content" => (string) $widget, "configuration" => $widget->dataAttributes(), 'block_key' => $block->key ], 200 );
|
||||
}
|
||||
catch ( UnderFlowException|OutOfRangeException $e )
|
||||
{
|
||||
Output::i()->json( [ "message" => "could not find block" ], 404 );
|
||||
}
|
||||
catch ( Throwable $e )
|
||||
{
|
||||
if ( \IPS\IN_DEV )
|
||||
{
|
||||
Output::i()->json( [ "error" => var_export( $e, true ) ], 500 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,24 +12,39 @@
|
||||
namespace IPS\cms\modules\front\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\cms\Databases\Dispatcher;
|
||||
use IPS\cms\Pages\Page as PageClass;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Log;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
use ParseError;
|
||||
use function defined;
|
||||
use function func_get_args;
|
||||
|
||||
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
|
||||
*/
|
||||
class _page extends \IPS\Dispatcher\Controller
|
||||
class page extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Determine which method to load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
$this->view();
|
||||
}
|
||||
@@ -39,46 +54,46 @@ class _page extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
protected function view() : void
|
||||
{
|
||||
$page = $this->getPage();
|
||||
$page = $this::getPage();
|
||||
|
||||
/* Database specific checks */
|
||||
if ( isset( \IPS\Request::i()->advancedSearchForm ) AND isset( \IPS\Request::i()->d ) )
|
||||
if ( isset( Request::i()->advancedSearchForm ) AND isset( Request::i()->d ) )
|
||||
{
|
||||
/* showTableSearchForm just triggers __call which returns the database dispatcher HTML as we
|
||||
* do not want the page content around the actual database */
|
||||
\IPS\Output::i()->output = $this->showTableSearchForm();
|
||||
Output::i()->output = $this->showTableSearchForm();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->path == $page->full_path )
|
||||
if ( Request::i()->path == $page->full_path )
|
||||
{
|
||||
/* Are we using Friendly URL's at all? */
|
||||
if ( \IPS\Settings::i()->use_friendly_urls )
|
||||
if ( Settings::i()->use_friendly_urls )
|
||||
{
|
||||
/* Did we have a trailing slash? */
|
||||
if ( \IPS\Settings::i()->htaccess_mod_rewrite and mb_substr( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_PATH ], -1 ) != '/' )
|
||||
if ( Settings::i()->htaccess_mod_rewrite and mb_substr( Request::i()->url()->data[ Url::COMPONENT_PATH ], -1 ) != '/' )
|
||||
{
|
||||
$url = $page->url();
|
||||
|
||||
foreach( \IPS\Request::i()->url()->queryString as $k => $v )
|
||||
foreach( Request::i()->url()->queryString as $k => $v )
|
||||
{
|
||||
$url = $url->setQueryString( $k, $v );
|
||||
}
|
||||
|
||||
if ( ! empty( \IPS\Request::i()->url()->fragment ) )
|
||||
if ( ! empty( Request::i()->url()->fragment ) )
|
||||
{
|
||||
$url = $url->setFragment( \IPS\Request::i()->url()->fragment );
|
||||
$url = $url->setFragment( Request::i()->url()->fragment );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url, NULL, 301 );
|
||||
Output::i()->redirect( $url );
|
||||
}
|
||||
else if ( ! \IPS\Settings::i()->htaccess_mod_rewrite and ! mb_strstr( \IPS\Request::i()->url()->data[ \IPS\Http\Url::COMPONENT_QUERY ], $page->url()->data[ \IPS\Http\Url::COMPONENT_QUERY ] ) )
|
||||
else if ( ! Settings::i()->htaccess_mod_rewrite and ! mb_strstr( Request::i()->url()->data[ Url::COMPONENT_QUERY ], $page->url()->data[ Url::COMPONENT_QUERY ] ) )
|
||||
{
|
||||
$url = $page->url();
|
||||
|
||||
foreach( \IPS\Request::i()->url()->queryString as $k => $v )
|
||||
foreach( Request::i()->url()->queryString as $k => $v )
|
||||
{
|
||||
if ( mb_substr( $k, 0, 1 ) == '/' and mb_substr( $k, -1 ) != '/' )
|
||||
{
|
||||
@@ -88,79 +103,79 @@ class _page extends \IPS\Dispatcher\Controller
|
||||
|
||||
$url = $url->setQueryString( $k, $v );
|
||||
|
||||
if ( ! empty( \IPS\Request::i()->url()->fragment ) )
|
||||
if ( ! empty( Request::i()->url()->fragment ) )
|
||||
{
|
||||
$url = $url->setFragment( \IPS\Request::i()->url()->fragment );
|
||||
$url = $url->setFragment( Request::i()->url()->fragment );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url, NULL, 301 );
|
||||
Output::i()->redirect( $url );
|
||||
}
|
||||
}
|
||||
|
||||
/* Just viewing this page, no database categories or records */
|
||||
$permissions = $page->permissions();
|
||||
\IPS\Session::i()->setLocation( $page->url(), explode( ",", $permissions['perm_view'] ), 'loc_cms_viewing_page', array( 'cms_page_' . $page->_id => TRUE ) );
|
||||
Session::i()->setLocation( $page->url(), explode( ",", $permissions['perm_view'] ), 'loc_cms_viewing_page', array( 'cms_page_' . $page->_id => TRUE ) );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$page->output();
|
||||
}
|
||||
catch ( \ParseError $e )
|
||||
catch ( ParseError $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'page_error' );
|
||||
\IPS\Output::i()->error( 'content_err_page_500', '2T187/4', 500, 'content_err_page_500_admin', array(), $e );
|
||||
Log::log( $e, 'page_error' );
|
||||
Output::i()->error( 'content_err_page_500', '2T187/4', 500, 'content_err_page_500_admin', array(), $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page
|
||||
*
|
||||
* @return \IPS\cms\Pages\Page
|
||||
* @return PageClass|null
|
||||
*/
|
||||
public function getPage()
|
||||
public static function getPage(): ?PageClass
|
||||
{
|
||||
$page = null;
|
||||
if ( isset( \IPS\Request::i()->page_id ) )
|
||||
if ( isset( Request::i()->page_id ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::load( \IPS\Request::i()->page_id );
|
||||
$page = PageClass::load( Request::i()->page_id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T187/1', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T187/1', 404, '' );
|
||||
}
|
||||
}
|
||||
else if ( isset( \IPS\Request::i()->path ) AND \IPS\Request::i()->path != '/' )
|
||||
else if ( isset( Request::i()->path ) AND Request::i()->path != '/' )
|
||||
{
|
||||
/* Sort out pagination for pages */
|
||||
list( $path, $pageNumber ) = \IPS\cms\Pages\Page::getStrippedPagePath( \IPS\Request::i()->path );
|
||||
if( $pageNumber AND !\IPS\Request::i()->page )
|
||||
list( $path, $pageNumber ) = PageClass::getStrippedPagePath( Request::i()->path );
|
||||
if( $pageNumber AND !Request::i()->page )
|
||||
{
|
||||
\IPS\Request::i()->page = $pageNumber;
|
||||
Request::i()->page = $pageNumber;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::loadFromPath( $path );
|
||||
$page = PageClass::loadFromPath( $path );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::getUrlFromHistory( \IPS\Request::i()->path, ( isset( \IPS\Request::i()->url()->data['query'] ) ? \IPS\Request::i()->url()->data['query'] : NULL ) );
|
||||
$page = PageClass::getUrlFromHistory( Request::i()->path, ( isset( Request::i()->url()->data['query'] ) ? Request::i()->url()->data['query'] : NULL ) );
|
||||
|
||||
if( (string) $page == (string) \IPS\Request::i()->url() )
|
||||
if( (string) $page == (string) Request::i()->url() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T187/3', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T187/3', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $page, NULL, 301 );
|
||||
Output::i()->redirect( $page );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T187/2', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T187/2', 404, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,31 +183,31 @@ class _page extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::getDefaultPage();
|
||||
$page = PageClass::getDefaultPage();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T257/1', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T257/1', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $page === NULL )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T257/2', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T257/2', 404, '' );
|
||||
}
|
||||
|
||||
if ( ! $page->can('view') )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_403', '2T187/3', 403, '' );
|
||||
Output::i()->error( 'content_err_page_403', '2T187/3', 403, '' );
|
||||
}
|
||||
|
||||
if ( \IPS\IPS::classUsesTrait( $page->item(), 'IPS\Content\ViewUpdates' ) )
|
||||
if ( IPS::classUsesTrait( $page->item(), 'IPS\Content\ViewUpdates' ) )
|
||||
{
|
||||
$page->item()->updateViews();
|
||||
}
|
||||
|
||||
/* Set the current page, so other blocks, DBs, etc don't have to figure out where they are */
|
||||
\IPS\cms\Pages\Page::$currentPage = $page;
|
||||
PageClass::$currentPage = $page;
|
||||
|
||||
return $page;
|
||||
}
|
||||
@@ -200,34 +215,37 @@ class _page extends \IPS\Dispatcher\Controller
|
||||
/**
|
||||
* Capture database specific things
|
||||
*
|
||||
* @param string $method Desired method
|
||||
* @param array $args Arguments
|
||||
* @return void
|
||||
* @param string $method Desired method
|
||||
* @param array $args Arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call( $method, $args )
|
||||
public function __call( string $method, array $args ) : mixed
|
||||
{
|
||||
$page = $this->getPage();
|
||||
$page = $this::getPage();
|
||||
$page->setTheme();
|
||||
$databaseId = ( isset( \IPS\Request::i()->d ) ) ? \IPS\Request::i()->d : $page->getDatabase()->_id;
|
||||
$databaseId = ( isset( Request::i()->d ) ) ? Request::i()->d : $page->getDatabase()->_id;
|
||||
|
||||
if ( $databaseId !== NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
return \IPS\cms\Databases\Dispatcher::i()->setDatabase( $databaseId )->run();
|
||||
Dispatcher::i()->setDatabase( $databaseId )->run();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->output();
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'content_err_page_404', '2T257/3', 404, '' );
|
||||
Output::i()->error( 'content_err_page_404', '2T257/3', 404, '' );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,8 +253,8 @@ class _page extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function embed()
|
||||
protected function embed() : void
|
||||
{
|
||||
return $this->__call( 'embed', \func_get_args() );
|
||||
$this->__call( 'embed', func_get_args() );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user