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

+95 -75
View File
@@ -12,26 +12,47 @@
namespace IPS\cms\Pages;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Data\Store;
use IPS\Db;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Text;
use IPS\Http\Url;
use IPS\Http\Url\Friendly;
use IPS\Member;
use IPS\Node\Model;
use IPS\Request;
use IPS\Session;
use OutOfRangeException;
use function count;
use function defined;
use function func_get_args;
use function get_called_class;
use function get_class;
use function intval;
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;
}
/**
* @brief Folder Model
*/
class _Folder extends \IPS\Node\Model
class Folder extends Model
{
/**
* Munge different record types
*
* @return array
*/
public static function munge()
public static function munge() : array
{
$rows = array();
$args = \func_get_args();
$args = func_get_args();
foreach( $args as $arg )
{
@@ -49,73 +70,73 @@ class _Folder extends \IPS\Node\Model
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'cms_folders';
public static ?string $databaseTable = 'cms_folders';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'folder_';
public static string $databasePrefix = 'folder_';
/**
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'id';
public static string $databaseColumnId = 'id';
/**
* @brief [ActiveRecord] Database ID Fields
*/
protected static $databaseIdFields = array('folder_name', 'folder_path');
protected static array $databaseIdFields = array('folder_name', 'folder_path');
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
protected static array $multitonMap = array();
/**
* @brief [Node] Parent ID Database Column
*/
public static $databaseColumnParent = 'parent_id';
public static ?string $databaseColumnParent = 'parent_id';
/**
* @brief [Node] Parent ID Root Value
* @note This normally doesn't need changing though some legacy areas use -1 to indicate a root node
*/
public static $databaseColumnParentRootValue = 0;
public static int $databaseColumnParentRootValue = 0;
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'path';
public static ?string $databaseColumnOrder = 'path';
/**
* @brief [Node] Automatically set position for new nodes
*/
public static $automaticPositionDetermination = FALSE;
public static bool $automaticPositionDetermination = FALSE;
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'folder';
public static string $nodeTitle = 'folder';
/**
* @brief [Node] Subnode class
*/
public static $subnodeClass = 'IPS\cms\Pages\Page';
public static ?string $subnodeClass = 'IPS\cms\Pages\Page';
/**
* @brief [Node] Show forms modally?
*/
public static $modalForms = TRUE;
public static bool $modalForms = TRUE;
/**
* @brief [Node] Restrictions
*/
protected static $restrictions = array(
protected static ?array $restrictions = array(
'app' => 'cms',
'module' => 'pages',
'all' => 'page_manage',
@@ -125,9 +146,9 @@ class _Folder extends \IPS\Node\Model
/**
* [Node] Get Title
*
* @return string|null
* @return string
*/
protected function get__title()
protected function get__title(): string
{
return $this->name;
}
@@ -137,7 +158,7 @@ class _Folder extends \IPS\Node\Model
*
* @return string
*/
public function getSortableName()
public function getSortableName() : string
{
return $this->name;
}
@@ -145,11 +166,11 @@ class _Folder extends \IPS\Node\Model
/**
* [Node] Get buttons to display in tree
*
* @param string $url Base URL
* @param bool $subnode Is this a subnode?
* @return array
* @param Url $url Base URL
* @param bool $subnode Is this a subnode?
* @return array
*/
public function getButtons( $url, $subnode=FALSE )
public function getButtons( Url $url, bool $subnode=FALSE ): array
{
$buttons = parent::getButtons( $url, $subnode );
$return = array();
@@ -163,14 +184,13 @@ class _Folder extends \IPS\Node\Model
{
$buttons['add']['icon'] = 'folder-open';
$buttons['add']['title'] = 'content_add_folder';
$buttons['add']['data'] = array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_folder') );
$buttons['add']['data'] = array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('content_add_folder') );
$buttons['add']['link'] = $url->setQueryString( array( 'subnode' => 0, 'do' => 'form', 'parent' => $this->_id ) );
$buttons['add_page'] = array(
'icon' => 'plus-circle',
'title' => 'content_add_page',
'link' => $url->setQueryString( array( 'subnode' => 1, 'do' => 'add', 'parent' => $this->_id ) ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_page') )
'link' => $url->setQueryString( array( 'subnode' => 1, 'do' => 'form', 'parent' => $this->_id ) )
);
}
@@ -195,10 +215,10 @@ class _Folder extends \IPS\Node\Model
if ( $this->getItemCount() )
{
$return['delete'] = array(
'icon' => 'trash-o',
'icon' => 'trash',
'title' => 'empty',
'link' => $url->setQueryString( array( 'do' => 'delete', 'id' => $this->_id ) ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('empty') ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('empty') ),
'hotkey'=> 'd'
);
}
@@ -214,52 +234,52 @@ class _Folder extends \IPS\Node\Model
/**
* [Node] Add/Edit Form
*
* @param \IPS\Helpers\Form $form The form
* @param Form $form The form
* @return void
*/
public function form( &$form )
public function form( Form &$form ) : void
{
/* Build form */
$form->add( new \IPS\Helpers\Form\Text( 'folder_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ), function( $val )
$form->add( new Text( 'folder_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ), function( $val )
{
try
{
$testPage = \IPS\cms\Pages\Page::load( $val, 'page_seo_name' );
$testPage = Page::load( $val, 'page_seo_name' );
/* Ok, we have a folder, but is it on the same tree as us ?*/
if ( \intval( \IPS\Request::i()->folder_parent_id ) == $testPage->folder_id )
if ( intval( Request::i()->folder_parent_id ) == $testPage->folder_id )
{
/* Yep, this will break designers' mode and may confuse the FURL engine so we cannot allow this */
throw new \InvalidArgumentException('content_folder_name_furl_collision_folder');
throw new InvalidArgumentException('content_folder_name_furl_collision_folder');
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
/* Nothing with the same name, so that's proper good that is */
}
try
{
$test = \IPS\cms\Pages\Folder::load( ( $val === '.well-known' ) ? $val : \IPS\Http\Url\Friendly::seoTitle( $val ), 'folder_name' );
$test = Folder::load( ( $val === '.well-known' ) ? $val : Friendly::seoTitle( $val ), 'folder_name' );
if ( empty( \IPS\Request::i()->id ) or $test->id != \IPS\Request::i()->id )
if ( empty( Request::i()->id ) or $test->id != Request::i()->id )
{
throw new \InvalidArgumentException('content_folder_name_in_use');
throw new InvalidArgumentException('content_folder_name_in_use');
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
/* If we hit here, we don't have an existing folder by that name so check for a collision */
if ( \IPS\Request::i()->folder_parent_id == 0 AND \IPS\cms\Pages\Page::isFurlCollision( ( $val === '.well-known' ) ? $val : \IPS\Http\Url\Friendly::seoTitle( $val ) ) )
if ( Request::i()->folder_parent_id == 0 AND Page::isFurlCollision( ( $val === '.well-known' ) ? $val : Friendly::seoTitle( $val ) ) )
{
throw new \InvalidArgumentException('content_folder_name_furl_collision');
throw new InvalidArgumentException('content_folder_name_furl_collision');
}
}
} ) );
$class = \get_called_class();
$class = get_called_class();
$form->add( new \IPS\Helpers\Form\Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
$form->add( new Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
'class' => '\IPS\cms\Pages\Folder',
'zeroVal' => 'node_no_parent',
'permissionCheck' => function( $node ) use ( $class )
@@ -269,7 +289,7 @@ class _Folder extends \IPS\Node\Model
return FALSE;
}
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\Request::i()->id ) ) );
return !isset( Request::i()->id ) or ( $node->id != Request::i()->id and !$node->isChildOf( $node::load( Request::i()->id ) ) );
}
) ) );
}
@@ -280,7 +300,7 @@ class _Folder extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
$isNew = $this->_new;
@@ -307,7 +327,7 @@ class _Folder extends \IPS\Node\Model
}
else
{
$values['name'] = \IPS\Http\Url\Friendly::seoTitle( $values['folder_name'] );
$values['name'] = Friendly::seoTitle( $values['folder_name'] );
}
unset( $values['folder_name'] );
}
@@ -323,12 +343,12 @@ class _Folder extends \IPS\Node\Model
/**
* @brief Original parent ID
*/
protected $origParentId;
protected ?int $origParentId = null;
/**
* @brief Original Name
*/
protected $origName;
protected ?string $origName = null;
/**
* [Node] Perform actions after saving the form
@@ -336,7 +356,7 @@ class _Folder extends \IPS\Node\Model
* @param array $values Values from the form
* @return void
*/
public function postSaveForm( $values )
public function postSaveForm( array $values ) : void
{
if ( $this->origParentId !== $values['parent_id'] OR $this->origName !== $values['name'] )
{
@@ -349,9 +369,9 @@ class _Folder extends \IPS\Node\Model
*
* @return void
*/
public function storeUrl()
public function storeUrl() : void
{
\IPS\Db::i()->insert( 'cms_url_store', array(
Db::i()->insert( 'cms_url_store', array(
'store_path' => $this->path,
'store_current_id' => $this->_id,
'store_type' => 'folder'
@@ -363,7 +383,7 @@ class _Folder extends \IPS\Node\Model
*
* @return void
*/
public function save()
public function save(): void
{
$this->last_modified = time();
@@ -373,12 +393,12 @@ class _Folder extends \IPS\Node\Model
/**
* Retrieve item \count(if applicable) for a node.
*
* @return int|bool
* @return int
*/
public function getItemCount()
public function getItemCount() : int
{
$pages = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_pages', array( 'page_folder_id=?', $this->id ) )->first();
$subFolders = (int) \IPS\Db::i()->select( 'COUNT(*)', 'cms_folders', array( 'folder_parent_id=?', $this->id ) )->first();
$pages = (int) Db::i()->select( 'COUNT(*)', 'cms_pages', array( 'page_folder_id=?', $this->id ) )->first();
$subFolders = (int) Db::i()->select( 'COUNT(*)', 'cms_folders', array( 'folder_parent_id=?', $this->id ) )->first();
return $pages + $subFolders;
}
@@ -387,19 +407,19 @@ class _Folder extends \IPS\Node\Model
* Form to delete or move content
*
* @param bool $showMoveToChildren If TRUE, will show "move to children" even if there are no children
* @return \IPS\Helpers\Form
* @return Form
*/
public function deleteOrMoveForm( $showMoveToChildren=FALSE )
public function deleteOrMoveForm( bool $showMoveToChildren=FALSE ): Form
{
$hasContent = $this->getItemCount();
$form = new \IPS\Helpers\Form( 'form', 'delete' );
$form = new Form( 'form', 'delete' );
if ( $hasContent )
{
$form->add( new \IPS\Helpers\Form\Node( 'cms_move_pages', 0, TRUE, array( 'class' => \get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
$form->add( new Node( 'cms_move_pages', 0, TRUE, array( 'class' => get_class( $this ), 'disabled' => array( $this->_id ), 'disabledLang' => 'node_move_delete', 'zeroVal' => 'cms_move_to_root', 'subnodes' => FALSE, 'permissionCheck' => function( $node )
{
return \IPS\Request::i()->id != $node->id;
return Request::i()->id != $node->id;
} ) ) );
}
@@ -412,7 +432,7 @@ class _Folder extends \IPS\Node\Model
* @param array $values Values from form
* @return void
*/
public function deleteOrMoveFormSubmit( $values )
public function deleteOrMoveFormSubmit( array $values ) : void
{
if ( $values['cms_move_pages'] )
{
@@ -423,17 +443,17 @@ class _Folder extends \IPS\Node\Model
$folderId = 0;
}
\IPS\Db::i()->update( 'cms_pages', array( 'page_folder_id' => $folderId ), array( 'page_folder_id=?', $this->_id ) );
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_id=?', $this->_id ) );
\IPS\Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_parent_id=?', $this->_id ) );
Db::i()->update( 'cms_pages', array( 'page_folder_id' => $folderId ), array( 'page_folder_id=?', $this->_id ) );
Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_id=?', $this->_id ) );
Db::i()->update( 'cms_folders', array( 'folder_parent_id' => $folderId ), array( 'folder_parent_id=?', $this->_id ) );
unset( \IPS\Data\Store::i()->pages_page_urls );
unset( Store::i()->pages_page_urls );
/* Update pages */
\IPS\cms\Pages\Page::resetPath( $folderId );
Page::resetPath( $folderId );
/* Delete it */
\IPS\Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $this->titleForLog() => FALSE ) );
Session::i()->log( 'acplog__node_deleted', array( $this->title => TRUE, $this->titleForLog() => FALSE ) );
$this->delete();
}
@@ -443,7 +463,7 @@ class _Folder extends \IPS\Node\Model
* @param boolean $recursivelyCheck Recursively reset up and down the tree
* @return void
*/
public function resetPath( $recursivelyCheck=true )
public function resetPath( bool $recursivelyCheck=true ) : void
{
$path = array();
@@ -452,13 +472,13 @@ class _Folder extends \IPS\Node\Model
$path[] = $obj->name;
}
$this->path = ( \count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
$this->path = ( count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
/* Save path update */
parent::save();
/* Update pages */
\IPS\cms\Pages\Page::resetPath( $this->id );
Page::resetPath( $this->id );
if ( $recursivelyCheck === true )
{
@@ -482,7 +502,7 @@ class _Folder extends \IPS\Node\Model
*
* @return void
*/
protected function _recursivelyResetChildPaths()
protected function _recursivelyResetChildPaths() : void
{
foreach( $this->children( NULL, NULL, FALSE ) as $child )
{
File diff suppressed because it is too large. Load diff
+32 -197
View File
@@ -12,272 +12,107 @@
namespace IPS\cms\Pages;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Item;
use IPS\Content\ViewUpdates;
use IPS\Http\Url;
use IPS\Node\Model;
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;
}
/**
* Package Item Model
*/
class _PageItem extends \IPS\Content\Item implements \IPS\Content\Searchable
class PageItem extends Item
{
use \IPS\Content\ViewUpdates;
use ViewUpdates;
/**
* @brief Application
*/
public static $application = 'cms';
public static string $application = 'cms';
/**
* @brief Module
*/
public static $module = 'pages';
public static string $module = 'pages';
/**
* @brief Database Table
*/
public static $databaseTable = 'cms_pages';
public static ?string $databaseTable = 'cms_pages';
/**
* @brief Database Prefix
*/
public static $databasePrefix = 'page_';
public static string $databasePrefix = 'page_';
/**
* @brief Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief Database Column Map
*/
public static $databaseColumnMap = array(
public static array $databaseColumnMap = array(
'views' => 'views'
);
/**
* @brief Title
*/
public static $title = 'cms_page';
public static string $title = 'cms_page';
/**
* @brief Icon
*/
public static $icon = 'files-o';
public static string $icon = 'file';
/**
* @brief Include In Sitemap
*/
public static $includeInSitemap = FALSE;
public static bool $includeInSitemap = FALSE;
/**
* @brief Can this content be moderated normally from the front-end (will be FALSE for things like Pages and Commerce Products)
*/
public static $canBeModeratedFromFrontend = FALSE;
public static bool $canBeModeratedFromFrontend = FALSE;
/**
* Columns needed to query for search result / stream view
*
* @return array
*/
public static function basicDataColumns()
public static function basicDataColumns(): array
{
return array( 'page_id', 'page_folder_id', 'page_full_path', 'page_default' );
}
/**
* Get URL from index data
*
* @param array $indexData Data from the search index
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param string|NULL $action Action
* @return \IPS\Http\Url
*/
public static function urlFromIndexData( $indexData, $itemData, $action = NULL )
{
if ( \IPS\Application::load('cms')->default AND $itemData['page_default'] AND !$itemData['page_folder_id'] )
{
/* No - that's easy */
return \IPS\Http\Url::internal( '', 'front' );
}
else
{
return \IPS\Http\Url::internal( 'app=cms&module=pages&controller=page&path=' . $itemData['page_full_path'], 'front', 'content_page_path', array( $itemData['page_full_path'] ) );
}
}
/**
* Get HTML for search result display
*
* @param array $indexData Data from the search index
* @param array $authorData Basic data about the author. Only includes columns returned by \IPS\Member::columnsForPhoto()
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param array|NULL $containerData Basic data about the container. Only includes columns returned by container::basicDataColumns()
* @param array $reputationData Array of people who have given reputation and the reputation they gave
* @param int|NULL $reviewRating If this is a review, the rating
* @param bool $iPostedIn If the user has posted in the item
* @param string $view 'expanded' or 'condensed'
* @param bool $asItem Displaying results as items?
* @param bool $canIgnoreComments Can ignore comments in the result stream? Activity stream can, but search results cannot.
* @param array $template Optional custom template
* @param array $reactions Reaction Data
* @return string
*/
public static function searchResult( array $indexData, array $authorData, array $itemData, ?array $containerData, array $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments=FALSE, $template=NULL, $reactions=array() )
{
$indexData['index_title'] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_page_' . $indexData['index_item_id'] );
return parent::searchResult( $indexData, $authorData, $itemData, $containerData, $reputationData, $reviewRating, $iPostedIn, $view, $asItem, $canIgnoreComments, $template, $reactions );
}
/**
* Title for search index
*
* @return string
*/
public function searchIndexTitle()
{
$titles = array();
foreach ( \IPS\Lang::languages() as $lang )
{
$titles[] = $lang->get("cms_page_{$this->id}");
}
return implode( ' ', $titles );
}
/**
* Content for search index
*
* @return string
*/
public function searchIndexContent()
{
if ( $this->type == 'builder' )
{
$content = array();
foreach( \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=?', $this->id ) ) as $widgetArea )
{
foreach ( json_decode( $widgetArea['area_widgets'], TRUE ) as $widget )
{
if ( $widget['app'] == 'cms' and $widget['key'] == 'Wysiwyg' )
{
$content[] = trim( $widget['configuration']['content'] );
}
}
}
return implode( ' ', $content );
}
else
{
/* Remove {tags="foo"} */
$this->content = preg_replace( '#\{([a-z]+?=([\'"]).+?\\2 ?+)}#', '', $this->content );
/* Convert {{}} logic into html tags */
$this->content = preg_replace( '#{{(if|foreach)([^{]+?)}}#', '<ips$1 data="$2">', $this->content );
$this->content = preg_replace( '#{{end(if|foreach)}}#', '</ips$1>', $this->content );
/* Remove custom PHP {{$foo = $this->test();}} */
$this->content = preg_replace( '#{{(.+?)}}#', '', $this->content );
$source = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
$source->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $this->content ) );
/* And then remove the HTML logic */
$domElemsToRemove = array();
foreach ( $source->getElementsByTagname('ipsif') as $domElement )
{
$domElemsToRemove[] = $domElement;
}
foreach ( $source->getElementsByTagname('ipsforeach') as $domElement )
{
$domElemsToRemove[] = $domElement;
}
foreach( $domElemsToRemove as $domElement )
{
$domElement->parentNode->removeChild($domElement);
}
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $source );
return $content;
}
}
/**
* Search Index Permissions
*
* @return string Comma-delimited values or '*'
* @li Number indicates a group
* @li Number prepended by "m" indicates a member
* @li Number prepended by "s" indicates a social group
*/
public function searchIndexPermissions()
{
try
{
return \IPS\Db::i()->select( 'perm_view', 'core_permission_index', array( "app='cms' AND perm_type='pages' AND perm_type_id=?", $this->id ) )->first();
}
catch ( \UnderflowException $e )
{
return '';
}
}
/**
* Should posting this increment the poster's post count?
*
* @param \IPS\Node\Model|NULL $container Container
* @return void
* @param Model|NULL $container Container
* @return bool
*/
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
public static function incrementPostCount( Model $container = NULL ): bool
{
return FALSE;
}
/**
* Title for Analytics
* Get URL
*
* @return string
* @param string|null $action Action
* @return Url
*/
public function titleForAnalytics(): string
public function url( ?string $action=NULL ): Url
{
try
{
return \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->get( \IPS\cms\Pages\Page::$titleLangPrefix . $this->id );
}
catch( \OutOfRangeException | \UnderflowException )
{
return \IPS\cms\Pages\Page::$titleLangPrefix . $this->id;
}
}
/**
* Get node
*
* @return \IPS\cms\Pages\Page
*/
public function node()
{
$data = array();
foreach ( $this->_data as $k => $v )
{
$data[ 'page_' . $k ] = $v;
}
return \IPS\cms\Pages\Page::constructFromData( $data );
}
/**
* URL
*
* @param string|NULL $action Action
* @return \IPS\Http\Url
*/
public function url( $action = null )
{
return $this->node()->url();
return Page::constructFromData( $this->_data )->url();
}
}
+28 -17
View File
@@ -12,37 +12,48 @@
namespace IPS\cms\Pages;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use InvalidArgumentException;
use IPS\cms\Categories;
use IPS\cms\Records;
use IPS\Db;
use IPS\Http\Url;
use IPS\Patterns\ActiveRecord;
use OutOfRangeException;
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;
}
/**
* @brief Page Model
*/
class _Router extends \IPS\Patterns\ActiveRecord
class Router extends ActiveRecord
{
/**
* Load Pages Thing based on a URL.
* The URL is sometimes complex to figure out, so this will help
*
* @param \IPS\Http\Url $url URL to load from
* @return \IPS\cms\Pages\Page
* @throws \InvalidArgumentException
* @throws \OutOfRangeException
* @param Url $url URL to load from
* @return mixed
* @throws InvalidArgumentException
* @throws OutOfRangeException
*/
public static function loadFromUrl( \IPS\Http\Url $url )
public static function loadFromUrl( Url $url ): mixed
{
if ( ! isset( $url->queryString['path'] ) )
{
throw new \OutOfRangeException();
throw new OutOfRangeException();
}
$path = $url->queryString['path'];
/* First, we need a page */
$page = \IPS\cms\Pages\Page::loadFromPath( $path );
$page = Page::loadFromPath( $path );
/* What do we have left? */
$whatsLeft = trim( preg_replace( '#' . $page->full_path . '#', '', $path, 1 ), '/' );
@@ -50,23 +61,23 @@ class _Router extends \IPS\Patterns\ActiveRecord
if ( $whatsLeft )
{
/* Check databases */
$databases = iterator_to_array( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_page_id > 0' ) ) );
$databases = iterator_to_array( Db::i()->select( '*', 'cms_databases', array( 'database_page_id > 0' ) ) );
foreach( $databases as $db )
{
$classToTry = 'IPS\cms\Records' . $db['database_id'];
/* @var $classToTry Records */
try
{
$record = $classToTry::loadFromSlug( $whatsLeft, FALSE, FALSE );
return $record;
return $classToTry::loadFromSlug( $whatsLeft, FALSE, FALSE );
}
catch( \Exception $ex ) { }
catch( Exception $ex ) { }
}
/* Check categories */
foreach( $databases as $db )
{
$classToTry = 'IPS\cms\Categories' . $db['database_id'];
/* @var $classToTry Categories */
try
{
$category = $classToTry::loadFromPath( $whatsLeft );
@@ -76,7 +87,7 @@ class _Router extends \IPS\Patterns\ActiveRecord
return $category;
}
}
catch( \Exception $ex ) { }
catch( Exception $ex ) { }
}
}
else
@@ -86,6 +97,6 @@ class _Router extends \IPS\Patterns\ActiveRecord
}
/* No idea, sorry */
throw new \InvalidArgumentException;
throw new InvalidArgumentException;
}
}