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,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