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

+104 -76
View File
@@ -12,75 +12,95 @@
namespace IPS\cms\Databases;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\cms\Categories;
use IPS\cms\Databases;
use IPS\cms\Pages\Page;
use IPS\cms\Records;
use IPS\core\DataLayer;
use IPS\Dispatcher as SystemDispatcher;
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function intval;
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;
}
/**
* Database Dispatcher
*/
class _Dispatcher extends \IPS\Dispatcher
class Dispatcher extends SystemDispatcher
{
/**
* @brief Singleton Instance (So we don't re-use the regular dispatcher)
*/
protected static $instance = NULL;
protected static mixed $instance = NULL;
/**
* @brief Controller location
*/
public $controllerLocation = 'front';
public string $controllerLocation = 'front';
/**
* @brief Database Id
*/
public $databaseId = NULL;
public ?int $databaseId = NULL;
/**
* @brief Category Id
*/
public $categoryId = NULL;
public ?int $categoryId = NULL;
/**
* @brief Record Id
*/
public $recordId = NULL;
public ?int $recordId = NULL;
/**
* @brief Url
*/
public $url = NULL;
public mixed $url = NULL;
/**
* @brief Module
*/
public $module = NULL;
public ?string $module = NULL;
/**
* @brief Output to return
*/
public $output = "";
public string $output = "";
/**
* Set Database ID
*
* @param mixed $databaseId Database key or ID
* @return \IPS\Dispatcher
* @return Dispatcher
*/
public function setDatabase( $databaseId )
public function setDatabase( mixed $databaseId ): Dispatcher
{
/* Other areas rely on $this->databaseId being numeric */
if ( !\is_numeric( $databaseId ) )
if ( !is_numeric( $databaseId ) )
{
$database = \IPS\cms\Databases::load( $databaseId, 'database_key' );
$database = Databases::load( $databaseId, 'database_key' );
$databaseId = $database->id;
}
$this->databaseId = $databaseId;
$database = \IPS\cms\Databases::load( $databaseId );
$database = Databases::load( $databaseId );
if ( ! $database->use_categories )
{
$this->categoryId = $database->_default_category;
@@ -93,9 +113,9 @@ class _Dispatcher extends \IPS\Dispatcher
* Set Category ID
*
* @param mixed $categoryId Category ID
* @return \IPS\Dispatcher
* @return Dispatcher
*/
public function setCategory( $categoryId )
public function setCategory( mixed $categoryId ): Dispatcher
{
$this->categoryId = $categoryId;
return $this;
@@ -106,11 +126,11 @@ class _Dispatcher extends \IPS\Dispatcher
*
* @return void
*/
public function init()
public function init() : void
{
if ( ( \IPS\cms\Pages\Page::$currentPage AND ! ( \IPS\Application::load('cms')->default AND ! \IPS\cms\Pages\Page::$currentPage->folder_id AND \IPS\cms\Pages\Page::$currentPage->default ) ) )
if ( ( Page::$currentPage AND ! ( Application::load('cms')->default AND ! Page::$currentPage->folder_id AND Page::$currentPage->default ) ) )
{
\IPS\Output::i()->breadcrumb['module'] = array( \IPS\cms\Pages\Page::$currentPage->url(), \IPS\cms\Pages\Page::$currentPage->_title );
Output::i()->breadcrumb['module'] = array( Page::$currentPage->url(), Page::$currentPage->_title );
}
}
@@ -119,60 +139,62 @@ class _Dispatcher extends \IPS\Dispatcher
*
* @return void
*/
public function run()
public function run() : void
{
/* Coming from a widget? */
if ( isset( \IPS\Request::i()->pageID ) and isset( \IPS\Request::i()->blockID ) )
if ( isset( Request::i()->pageID ) and isset( Request::i()->blockID ) )
{
if ( \IPS\cms\Pages\Page::$currentPage === NULL )
if ( Page::$currentPage === NULL )
{
/* make sure this is a valid widgetized page to stop tampering */
try
{
foreach ( \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=?', \IPS\Request::i()->pageID ) ) as $item )
$page = Page::load( Request::i()->pageID );
foreach( $page->getAreasFromDatabase() as $area )
{
foreach( json_decode( $item['area_widgets'], TRUE ) as $block )
foreach( $area->getAllWidgets() as $block )
{
if ( $block['key'] === 'Database' and isset( $block['configuration']['database'] ) and \intval( $block['configuration']['database'] ) === $this->databaseId )
if ( $block['key'] === 'Database' and isset( $block['configuration']['database'] ) and intval( $block['configuration']['database'] ) === $this->databaseId )
{
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID );
Page::$currentPage = $page;
break;
}
}
}
}
catch( \UnderflowException $e ) { }
catch( UnderflowException $e ) { }
}
/* Try again */
if ( \IPS\cms\Pages\Page::$currentPage === NULL )
if ( Page::$currentPage === NULL )
{
\IPS\Output::i()->error( 'page_doesnt_exist', '2T251/1', 404 );
Output::i()->error( 'page_doesnt_exist', '2T251/1', 404 );
}
/* Unset do query param otherwise it confuses the controller->execute(); */
\IPS\Request::i()->do = NULL;
Request::i()->do = NULL;
}
$url = 'app=cms&module=pages&controller=page&path=' . \IPS\cms\Pages\Page::$currentPage->full_path;
$url = 'app=cms&module=pages&controller=page&path=' . Page::$currentPage->full_path;
try
{
$database = \IPS\cms\Databases::load( $this->databaseId );
$database = Databases::load( $this->databaseId );
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'page_doesnt_exist', '2T251/2', 404 );
Output::i()->error( 'page_doesnt_exist', '2T251/2', 404 );
}
$path = trim( preg_replace( '#' . \IPS\cms\Pages\Page::$currentPage->full_path . '#', '', \IPS\Request::i()->path, 1 ), '/' );
$path = trim( preg_replace( '#' . Page::$currentPage->full_path . '#', '', Request::i()->path, 1 ), '/' );
/* If we visited the default page in a folder, the full_path will be like folder/page but the request path will just be folder */
if( \IPS\Request::i()->path . '/' . \IPS\cms\Pages\Page::$currentPage->seo_name == \IPS\cms\Pages\Page::$currentPage->full_path )
if( Request::i()->path . '/' . Page::$currentPage->seo_name == Page::$currentPage->full_path )
{
$path = '';
}
list( $path, $pageNumber ) = \IPS\cms\Pages\Page::getStrippedPagePath( $path );
list( $path, $pageNumber ) = Page::getStrippedPagePath( $path );
$this->databaseId = $database->id;
@@ -182,13 +204,13 @@ class _Dispatcher extends \IPS\Dispatcher
}
/* Got a specific category ID? */
if ( $this->categoryId !== NULL and ! $path and ( ( $database->use_categories and $database->cat_index_type !== 1 ) OR ( ! $database->use_categories and isset( \IPS\Request::i()->do ) ) ) )
if ( $this->categoryId !== NULL and ! $path and ( ( $database->use_categories and $database->cat_index_type !== 1 ) OR ( ! $database->use_categories and isset( Request::i()->do ) ) ) )
{
$this->module = 'category';
}
else if ( isset( \IPS\Request::i()->c ) AND \is_numeric( \IPS\Request::i()->c ) )
else if ( isset( Request::i()->c ) AND is_numeric( Request::i()->c ) )
{
$this->categoryId = \IPS\Request::i()->c;
$this->categoryId = Request::i()->c;
$this->module = 'category';
}
else if ( empty( $path ) )
@@ -198,11 +220,14 @@ class _Dispatcher extends \IPS\Dispatcher
else
{
$url .= '/' . $path;
/* @var Records $recordClass */
$recordClass = '\IPS\cms\Records' . $database->id;
$isLegacyCategoryUrl = FALSE;
if ( $database->use_categories )
{
/* @var Categories $catClass */
$catClass = '\IPS\cms\Categories' . $database->id;
$category = $catClass::loadFromPath( $path, $database->id );
@@ -231,7 +256,7 @@ class _Dispatcher extends \IPS\Dispatcher
$this->_redirectToCorrectUrl( $record->url() );
}
catch ( \OutOfRangeException $ex )
catch ( OutOfRangeException $ex )
{
/* Check slug history */
try
@@ -240,9 +265,9 @@ class _Dispatcher extends \IPS\Dispatcher
$this->_redirectToCorrectUrl( $record->url() );
}
catch ( \OutOfRangeException $ex )
catch ( OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'page_doesnt_exist', '2T251/4', 404 );
Output::i()->error( 'page_doesnt_exist', '2T251/4', 404 );
}
}
}
@@ -264,9 +289,9 @@ class _Dispatcher extends \IPS\Dispatcher
$record = $recordClass::loadFromSlug( $whatsLeft, TRUE, $this->categoryId );
/* Make the Content controller all kinds of happy */
\IPS\Request::i()->id = $this->recordId = $record->primary_id_field;
Request::i()->id = $this->recordId = $record->primary_id_field;
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
/* Check slug history */
try
@@ -275,15 +300,15 @@ class _Dispatcher extends \IPS\Dispatcher
$this->_redirectToCorrectUrl( $record->url() );
}
catch( \OutOfRangeException $ex )
catch( OutOfRangeException $ex )
{
/* We are absolutely certain this is not a record, but we have found a legacy category - redirect */
if ( $isLegacyCategoryUrl === TRUE )
{
\IPS\Output::i()->redirect( $category->url() );
Output::i()->redirect( $category->url() );
}
\IPS\Output::i()->error( 'page_doesnt_exist', '2T251/5', 404 );
Output::i()->error( 'page_doesnt_exist', '2T251/5', 404 );
}
}
@@ -302,56 +327,57 @@ class _Dispatcher extends \IPS\Dispatcher
}
}
$this->url = \IPS\Http\Url::internal( $url, 'front', 'content_page_path' );
$this->url = Url::internal( $url, 'front', 'content_page_path' );
$className = '\\IPS\\cms\\modules\\front\\database\\' . $this->module;
/* Init class */
if( !class_exists( $className ) )
{
\IPS\Output::i()->error( 'page_doesnt_exist', '2T251/6', 404 );
Output::i()->error( 'page_doesnt_exist', '2T251/6', 404 );
}
$controller = new $className;
if( !( $controller instanceof \IPS\Dispatcher\Controller ) )
if( !( $controller instanceof Controller ) )
{
\IPS\Output::i()->error( 'page_not_found', '3T251/7', 500, '' );
Output::i()->error( 'page_not_found', '3T251/7', 500, '' );
}
\IPS\Dispatcher::i()->dispatcherController = $controller;
Dispatcher::i()->dispatcherController = $controller;
/* Is this the default application? Default app should search all */
if ( ! \IPS\Application::load('cms')->default )
if ( ! Application::load('cms')->default )
{
/* If database doesn't allow search, default to all */
if ( ! $database->search )
{
\IPS\Output::i()->defaultSearchOption = array( 'all', 'search_everything' );
Output::i()->defaultSearchOption = array( 'all', 'search_everything' );
}
else
{
\IPS\Output::i()->defaultSearchOption = array( "cms_records{$this->databaseId}", "cms_records{$this->databaseId}_pl" );
Output::i()->defaultSearchOption = array( "cms_records{$this->databaseId}", "cms_records{$this->databaseId}_pl" );
}
}
else
{
\IPS\Output::i()->defaultSearchOption = array( 'all', 'search_everything' );
Output::i()->defaultSearchOption = array( 'all', 'search_everything' );
}
/* Add database key to body classes for easier database specific themeing */
\IPS\Output::i()->bodyClasses[] = 'cCmsDatabase_' . $database->key;
Output::i()->bodyClasses[] = 'cCmsDatabase_' . $database->key;
/* Execute */
$controller->execute();
/* Data Layer Context */
if ( $this->databaseId AND \IPS\Settings::i()->core_datalayer_enabled )
if ( $this->databaseId AND Settings::i()->core_datalayer_enabled )
{
try
{
$databaseOrCategory = \IPS\cms\Databases::load( $this->databaseId );
$databaseOrCategory = Databases::load( $this->databaseId );
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
return $this->finish();
$this->finish();
return;
}
/* Use the category instead of the database if there is one */
@@ -359,24 +385,25 @@ class _Dispatcher extends \IPS\Dispatcher
{
try
{
/* @var Categories $catClass */
$catClass = '\IPS\cms\Categories' . $this->databaseId;
$databaseOrCategory = $catClass::load( $this->categoryId );
}
catch ( \UnderflowException $e ) {}
catch ( UnderflowException $e ) {}
}
/* Add the database's/category's data layer properties to the page context */
foreach ( $databaseOrCategory->getDataLayerProperties() as $key => $property )
{
\IPS\core\DataLayer::i()->addContextProperty( $key, $property, true );
DataLayer::i()->addContextProperty( $key, $property );
if ( $key === 'content_area' )
{
\IPS\core\DataLayer::i()->addContextProperty( 'community_area', $property, true );
DataLayer::i()->addContextProperty( 'community_area', $property );
}
}
}
return $this->finish();
$this->finish();
}
/**
@@ -386,25 +413,25 @@ class _Dispatcher extends \IPS\Dispatcher
* If the record is moved so the URL is cat-2, the embed needs to redirect while retaining
* the /?do=embed
*
* @param \IPS\Http\Url $correctUrl The URL for the record
* @param Url $correctUrl The URL for the record
* @return void
*/
protected function _redirectToCorrectUrl( $correctUrl )
protected function _redirectToCorrectUrl( Url $correctUrl ) : void
{
$paramsToSet = array();
foreach ( \IPS\Request::i()->url()->queryString as $k => $v )
foreach ( Request::i()->url()->queryString as $k => $v )
{
if ( !array_key_exists( $k, $correctUrl->queryString ) and !array_key_exists( $k, $correctUrl->hiddenQueryString ) )
{
$paramsToSet[ $k ] = $v;
}
}
if ( \count( $paramsToSet ) )
if ( count( $paramsToSet ) )
{
$correctUrl = $correctUrl->setQueryString( $paramsToSet );
}
\IPS\Output::i()->redirect( $correctUrl, NULL, 301 );
Output::i()->redirect( $correctUrl, NULL );
}
/**
@@ -412,8 +439,9 @@ class _Dispatcher extends \IPS\Dispatcher
*
* @return void
*/
public function finish()
public function finish() : void
{
return (string) $this->output ?: \IPS\Output::i()->output;
Output::i()->output = $this->output ?: Output::i()->output;
parent::finish();
}
}