Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+8
View File
@@ -1,5 +1,11 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Database extends _HOOK_CLASS_
{
@@ -12,6 +18,8 @@ class cms_hook_Database extends _HOOK_CLASS_
public function __construct()
{
$this->initLoad[] = 'cms_menu';
$this->initLoad[] = 'cms_databases';
$this->initLoad[] = 'pages_page_urls';
/* Hand over to normal method */
parent::__construct();
+147
View File
@@ -0,0 +1,147 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_FriendlyUrl extends _HOOK_CLASS_
{
/**
* Create a friendly URL from a full URL, working out friendly URL data
*
* This is overridden so that when we are examing a raw URL (such as from \IPS\Http\Url::createFromString()), Pages
* can appropriately claim the URL as belonging to it
*
* @param array $components An array of components as returned by componentsFromUrlString()
* @param string $potentialFurl The potential FURL slug (e.g. "topic/1-test")
* @return \IPS\Http\Url\Friendly|NULL
*/
public static function createFriendlyUrlFromComponents( $components, $potentialFurl )
{
/* If the normal URL handling has it, or this is the root page, use normal handling, unless Pages is the default app, in which case we'll fallback to it */
if ( $return = call_user_func_array( 'parent::createFriendlyUrlFromComponents', func_get_args() ) or !$potentialFurl )
{
if ( !\IPS\Application::load('cms')->default )
{
return $return;
}
}
/* Try to find a page */
try
{
$page = \IPS\cms\Pages\Page::loadFromPath( $potentialFurl );
return static::createFromComponents( $components[ static::COMPONENT_HOST ], $components[ static::COMPONENT_SCHEME ], $components[ static::COMPONENT_PATH ], $components[ static::COMPONENT_QUERY ], $components[ static::COMPONENT_PORT ], $components[ static::COMPONENT_USERNAME ], $components[ static::COMPONENT_PASSWORD ], $components[ static::COMPONENT_FRAGMENT ] )
->setFriendlyUrlData( 'content_page_path', array( $potentialFurl ), array( 'path' => $potentialFurl ), $potentialFurl );
}
/* Couldn't find one? Don't accept responsibility */
catch ( \OutOfRangeException $e )
{
return $return;
}
}
/**
* Create a friendly URL from a query string with known friendly URL data
*
* @param string $queryString The query string
* @param string $seoTemplate The key for making this a friendly URL
* @param string|array $seoTitles The title(s) needed for the friendly URL
* @param int $protocol Protocol (one of the PROTOCOL_* constants)
* @return \IPS\Http\Url\Friendly
* @throws \IPS\Http\Url\Exception
*/
public static function friendlyUrlFromQueryString( $queryString, $seoTemplate, $seoTitles, $protocol )
{
if ( $seoTemplate === 'content_page_path' )
{
/* Get the friendly URL component */
$friendlyUrlComponent = static::buildFriendlyUrlComponentFromData( $queryString, $seoTemplate, $seoTitles );
/* Return */
return static::friendlyUrlFromComponent( $protocol, $friendlyUrlComponent, $queryString )->setFriendlyUrlData( $seoTemplate, $seoTitles, array( 'path' => $friendlyUrlComponent ), $friendlyUrlComponent );
}
return call_user_func_array( 'parent::friendlyUrlFromQueryString', func_get_args() );
}
/**
* Set friendly URL data
*
* This is overriden so when we are creating a friendly URL with known data (such as from \IPS\Http\Url::internal()),
* Pages can set the data for it's URLs properly
*
* @param string $seoTemplate The key for making this a friendly URL
* @param string|array $seoTitles The title(s) needed for the friendly URL
* @param array $matchedParams The values for hidden query string properties
* @param string $friendlyUrlComponent The friendly URL component, which may be for the path or the query string (e.g. "topic/1-test")
* @return \IPS\Http\Url\Friendly
* @throws \IPS\Http\Url\Exception
*/
protected function setFriendlyUrlData( $seoTemplate, $seoTitles, $matchedParams=array(), $friendlyUrlComponent )
{
if ( $seoTemplate === 'content_page_path' )
{
/* If we want to use a gateway script, adjust accordingly */
if ( \IPS\Settings::i()->cms_use_different_gateway )
{
$baseUrl = static::baseUrl( $this->data[ static::COMPONENT_SCHEME ] );
if ( mb_substr( $this->url, 0, mb_strlen( $baseUrl ) ) === $baseUrl ) // Only if it isn't already, such as from |IPS\Request::i()->url()
{
$this->url = \IPS\Settings::i()->cms_root_page_url . mb_substr( $this->url, mb_strlen( $baseUrl ) );
$this->data = static::componentsFromUrlString( $this->url );
$this->queryString = $this->data['query'];
$this->data['query'] = static::convertQueryAsArrayToString( $this->queryString );
}
}
/* Set basic properties */
$this->seoTemplate = 'content_page_path';
$this->seoTitles = is_string( $seoTitles ) ? array( $seoTitles ) : $seoTitles;
$this->friendlyUrlComponent = $friendlyUrlComponent;
/* Set hidden query string */
$this->hiddenQueryString = array( 'app' => 'cms', 'module' => 'pages', 'controller' => 'page' ) + $matchedParams;
/* Return */
return $this;
}
return call_user_func_array( 'parent::setFriendlyUrlData', func_get_args() );
}
/**
* Get friendly URL data from a query string and SEO template
*
* This is overriden so when we are creating a friendly URL with known data (such as from \IPS\Http\Url::internal()),
* Pages can set the data for it's URLs properly
*
* @param string $queryString The query string - is passed by reference and any parts used are removed, which can be used to detect extraneous parts
* @param string $seoTemplate The key for making this a friendly URL
* @param string|array $seoTitles The title(s) needed for the friendly URL
* @return string
* @throws \IPS\Http\Url\Exception
*/
public static function buildFriendlyUrlComponentFromData( &$queryString, $seoTemplate, $seoTitles )
{
if ( $seoTemplate === 'content_page_path' )
{
parse_str( $queryString, $queryString );
unset( $queryString['app'] );
unset( $queryString['module'] );
unset( $queryString['controller'] );
unset( $queryString['page'] );
$return = $queryString['path'];
unset( $queryString['path'] );
return $return;
}
return parent::buildFriendlyUrlComponentFromData( $queryString, $seoTemplate, $seoTitles );
}
}
+55
View File
@@ -0,0 +1,55 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_InternalUrl extends _HOOK_CLASS_
{
/**
* Get the friendly URL for this URL if there is one
*
* @return mixed The friendly URL if there is one, TRUE if there isn't, or NULL if not sure
*/
public function correctFriendlyUrl()
{
/* Check what the normal handling thinks... */
$return = parent::correctFriendlyUrl();
/* If it it thinks it belongs to "pages", we might be able to be more accurate */
if ( $return instanceof \IPS\Http\Url\Friendly and $return->seoTemplate === 'pages' and isset( $this->queryString['path'] ) )
{
/* Try to find a page */
try
{
/* Create it */
$correctUrl = \IPS\cms\Pages\Page::loadFromPath( $this->queryString['path'] )->url();
/* Set extra stuff in our query string */
$paramsToSet = array();
foreach ( $this->queryString as $k => $v )
{
if ( !array_key_exists( $k, $correctUrl->queryString ) and !array_key_exists( $k, $correctUrl->hiddenQueryString ) )
{
$paramsToSet[ $k ] = $v;
}
}
if ( count( $paramsToSet ) )
{
$correctUrl = $correctUrl->setQueryString( $paramsToSet );
}
/* Return */
return $correctUrl;
}
/* Couldn't find one? Don't accept responsibility */
catch ( \OutOfRangeException $e ){}
}
/* Return */
return $return;
}
}
+75
View File
@@ -0,0 +1,75 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Lang extends _HOOK_CLASS_
{
/**
* Set words
*
* @return void
*/
public function languageInit()
{
/* Language, is it? */
parent::languageInit();
/* Don't do this during setup */
if ( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation == 'setup' )
{
return;
}
/* Ensure applications set up correctly before task is executed. Pages, for example, needs to set up spl autoloaders first */
\IPS\Application::applications();
/* Add in the database specific language bits and bobs */
foreach( \IPS\cms\Databases::getDatabaseDataFromStore() as $database )
{
$this->words['__indefart_content_record_comments_title_' . $database['database_id'] ] = $this->addToStack( '__indefart_content_record_comments_title' );
$this->words['__indefart_content_record_reviews_title_' . $database['database_id'] ] = $this->addToStack( '__indefart_content_record_reviews_title' );
$this->words['__indefart_content_db_lang_su_' . $database['database_id'] ] = $this->addToStack( 'content_db_lang_ia_' . $database['database_id'] );
$this->words['__defart_content_record_comments_title_' . $database['database_id'] ] = $this->addToStack( '__defart_content_record_comments_title' );
$this->words['__defart_content_record_reviews_title_' . $database['database_id'] ] = $this->addToStack( '__defart_content_record_reviews_title' );
$this->words['__defart_content_db_lang_su_' . $database['database_id'] ] = $this->addToStack( 'content_db_lang_sl_' . $database['database_id'] );
$this->words['content_record_comments_title_' . $database['database_id'] ] = $this->addToStack( 'content_record_comment_title', FALSE, array( 'sprintf' => array( $this->recordWord( 1, TRUE, $database['database_id'] ) ) ) );
$this->words['content_record_reviews_title_' . $database['database_id'] ] = $this->addToStack( 'content_record_review_title', FALSE, array( 'sprintf' => array( $this->recordWord( 1, TRUE, $database['database_id'] ) ) ) );
$this->words['content_record_comments_title_' . $database['database_id'] . '_pl' ] = $this->addToStack( 'content_record_comments_title', FALSE, array( 'sprintf' => array( $this->recordWord( 1, TRUE, $database['database_id'] ) ) ) );
$this->words['content_record_comments_title_' . $database['database_id'] . '_pl_lc' ] = $this->addToStack( 'content_record_comments_title_lc', FALSE, array( 'sprintf' => array( $this->recordWord( 1, FALSE, $database['database_id'] ) ) ) );
$this->words['content_record_reviews_title_' . $database['database_id'] . '_pl' ] = $this->addToStack( 'content_record_reviews_title', FALSE, array( 'sprintf' => array( $this->recordWord( 1, TRUE, $database['database_id'] ) ) ) );
$this->words['content_record_reviews_title_' . $database['database_id'] . '_pl_lc' ] = $this->addToStack( 'content_record_reviews_title_lc', FALSE, array( 'sprintf' => array( $this->recordWord( 1, FALSE, $database['database_id'] ) ) ) );
$this->words['content_db_lang_su_' . $database['database_id'] . '_pl' ] = $this->addToStack( 'content_db_lang_pu_' . $database['database_id'] );
$this->words['content_db_lang_su_' . $database['database_id'] . '_pl_lc' ] = $this->addToStack( 'content_db_lang_pl_' . $database['database_id'] );
$this->words['content_db_lang_sl_' . $database['database_id'] . '_pl_lc' ] = $this->addToStack( 'content_db_lang_pl_' . $database['database_id'] );
$fieldsClass = '\IPS\cms\Fields' . $database['database_id'];
$customFields = $fieldsClass::databaseFieldIds();
foreach ( $customFields AS $id )
{
$this->words['sort_field_' . $id] = $this->addToStack( 'content_field_' . $id );
}
}
}
/**
* "Records" / "Record" word
*
* @param int $number Number
* @param bool $upper ucfirst string
* @return string
*/
public function recordWord( $number = 2, $upper = FALSE, $databaseId )
{
$case = $upper ? 'u' : 'l';
return $number == 1 ? $this->addToStack("content_db_lang_s{$case}_{$databaseId}") : $this->addToStack("content_db_lang_p{$case}_{$databaseId}");
}
}
+16 -10
View File
@@ -1,23 +1,29 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Output extends _HOOK_CLASS_
{
/**
* Display Error Screen
*
* @param string $message language key for error message
* @param mixed $code Error code
* @param int $httpStatusCode HTTP Status Code
* @param string $adminMessage language key for error message to show to admins
* @param array $httpHeaders Additional HTTP Headers
* @param string $extra Additional information (such as API error)
* @return void
* @param string $message language key for error message
* @param mixed $code Error code
* @param int $httpStatusCode HTTP Status Code
* @param string $adminMessage language key for error message to show to admins
* @param array $httpHeaders Additional HTTP Headers
* @param string $extra Additional information (such backtrace or API error) which will be shown to admins
* @param int|string|NULL $faultyAppOrHookId The 3rd party application or the hook id, which caused this error, NULL if it was a core application
*/
public function error( $message, $code, $httpStatusCode=500, $adminMessage=NULL, $httpHeaders=array(), $extra=NULL )
public function error( $message, $code, $httpStatusCode=500, $adminMessage=NULL, $httpHeaders=array(), $extra=NULL, $faultyAppOrHookId=NULL )
{
if ( ! isset( \IPS\Settings::i()->cms_error_page ) or ! \IPS\Settings::i()->cms_error_page )
{
parent::error( $message, $code, $httpStatusCode, $adminMessage, $httpHeaders, $extra );
parent::error( $message, $code, $httpStatusCode, $adminMessage, $httpHeaders, $extra, $faultyAppOrHookId );
}
/* If we just logged out, we don't want to show a "no permission" error */
@@ -75,7 +81,7 @@ class cms_hook_Output extends _HOOK_CLASS_
if( \IPS\Settings::i()->error_notify_level and $level >= \IPS\Settings::i()->error_notify_level )
{
\IPS\Email::buildFromTemplate( 'core', 'error_log', array( $code, $message ) )->send( \IPS\Settings::i()->email_in );
\IPS\Email::buildFromTemplate( 'core', 'error_log', array( $code, $message ), \IPS\Email::TYPE_LIST )->send( \IPS\Settings::i()->email_in );
}
}
+42 -19
View File
@@ -1,22 +1,30 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Post extends _HOOK_CLASS_
{
/**
* Create comment
*
* @param \IPS\Content\Item $item The content item just created
* @param string $comment The comment
* @param bool $first Is the first comment?
* @param string $guestName If author is a guest, the name to use
* @param \IPS\Content\Item $item The content item just created
* @param string $comment The comment
* @param bool $first Is the first comment?
* @param string $guestName If author is a guest, the name to use
* @param bool|NULL $incrementPostCount Increment post count? If NULL, will use static::incrementPostCount()
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
* @param \IPS\DateTime|NULL $time The time
* @param string|NULL $ipAddress The IP address or NULL to detect automatically
* @param int|NULL $hiddenStatus NULL to set automatically or override: 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @return static
*/
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL )
public static function create( $item, $comment, $first=FALSE, $guestName=NULL, $incrementPostCount=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL )
{
$comment = parent::create( $item, $comment, $first, $guestName, $incrementPostCount, $member, $time );
$comment = parent::create( $item, $comment, $first, $guestName, $incrementPostCount, $member, $time, $ipAddress, $hiddenStatus );
static::recordSync( $item );
@@ -32,17 +40,23 @@ class cms_hook_Post extends _HOOK_CLASS_
{
parent::delete();
static::recordSync( $this->item() );
/* It is possible to delete a post that is orphaned, so let's try to protect against that */
try
{
static::recordSync( $this->item() );
}
catch( \OutOfRangeException $e ){}
}
/**
/**
* Syncing to run when hiding
*
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onHide()
public function onHide( $member )
{
parent::onHide();
parent::onHide( $member );
static::recordSync( $this->item() );
}
@@ -50,12 +64,13 @@ class cms_hook_Post extends _HOOK_CLASS_
/**
* Syncing to run when unhiding
*
* @param bool $approving If true, is being approved for the first time
* @param bool $approving If true, is being approved for the first time
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onUnhide( $approving )
public function onUnhide( $approving, $member )
{
parent::onUnhide( $approving );
parent::onUnhide( $approving, $member );
static::recordSync( $this->item() );
}
@@ -71,27 +86,35 @@ class cms_hook_Post extends _HOOK_CLASS_
{
$synced = array();
foreach( \IPS\Db::i()->select( '*', 'cms_database_categories', array( 'category_forum_record=? AND category_forum_forum=? AND category_forum_comments=?', 1, $item->forum_id, 1 ) ) as $category )
/* We used to restrict by forum ID in these two queries, but if you move a topic to a new forum then the counts no longer sync properly */
foreach( \IPS\Db::i()->select( '*', 'cms_database_categories', array( 'category_forum_record=? AND category_forum_comments=?', 1, 1 ) ) as $category )
{
try
{
$synced[] = $category['category_database_id'];
$class = '\IPS\cms\Records' . $category['category_database_id'];
$class::load( $item->tid, 'record_topicid' )->syncRecordFromTopic( $item );
if ( ! in_array( $category['category_database_id'], $synced ) )
{
$class = '\IPS\cms\Records' . $category['category_database_id'];
$object = $class::load( $item->tid, 'record_topicid' );
$object->syncRecordFromTopic( $item );
/* Successful sync (no exception thrown, so lets skip this database from now on */
$synced[] = $category['category_database_id'];
}
}
catch( \Exception $ex )
{
}
}
foreach( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_forum_record=? AND database_forum_forum=? AND database_forum_comments=?', 1, $item->forum_id, 1 ) ) as $database )
foreach( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_forum_record=? AND database_forum_comments=?', 1, 1 ) ) as $database )
{
try
{
if ( ! in_array( $database['database_id'], $synced ) )
{
$class = '\IPS\cms\Records' . $database['database_id'];
$class::load( $item->tid, 'record_topicid' )->syncRecordFromTopic( $item );
$object = $class::load( $item->tid, 'record_topicid' );
$object->syncRecordFromTopic( $item );
}
}
catch( \Exception $ex )
+24
View File
@@ -0,0 +1,24 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Theme extends _HOOK_CLASS_
{
/**
* This method is executed when theme settings have changed from saveForm()
*
* @param int $setId Theme set id
* @erturn void
*/
public static function themeSettingsHaveChanged( $setId )
{
\IPS\cms\Pages\Page::deleteCachedIncludes();
parent::themeSettingsHaveChanged( $setId );
}
}
+50 -29
View File
@@ -1,5 +1,11 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Topic extends _HOOK_CLASS_
{
/**
@@ -15,43 +21,58 @@ class cms_hook_Topic extends _HOOK_CLASS_
{
if ( $action === 'delete' )
{
$databaseId = NULL;
try
{
$database = \IPS\Db::i()->select( '*', 'cms_databases', array( array( 'database_forum_forum=? AND database_forum_comments=1', $this->forum_id ) ) )->first();
$databaseId = $database['database_id'];
}
catch( \UnderflowException $ex )
/* We used to restrict by forum ID but if you move a topic to a new forum then the forum ID will no longer match */
foreach( \IPS\Db::i()->select( '*', 'cms_database_categories', array( 'category_forum_record=? AND category_forum_comments=?', 1, 1 ) ) as $category )
{
try
{
$category = \IPS\Db::i()->select( '*', 'cms_database_categories', array( array( 'category_forum_forum=? AND category_forum_comments=1', $this->forum_id ) ) )->first();
$databaseId = $category['category_database_id'];
$class = '\IPS\cms\Records' . $category['category_database_id'];
if( class_exists( $class ) )
{
$class::load( $this->tid, 'record_topicid' );
$database = \IPS\cms\Databases::load( $category['category_database_id'] );
\IPS\Member::loggedIn()->language()->words['cms_delete_linked_topic'] = sprintf( \IPS\Member::loggedIn()->language()->get('cms_delete_linked_topic'), $database->recordWord( 1 ) );
\IPS\Output::i()->error( 'cms_delete_linked_topic', '1T281/1', 403, '' );
}
}
catch( \UnderflowException $ex )
catch( \Exception $ex ) { }
}
foreach( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_forum_record=? AND database_forum_comments=?', 1, 1 ) ) as $database )
{
try
{
return parent::modAction( $action, $member, $reason );
$class = '\IPS\cms\Records' . $database['database_id'];
$class::load( $this->tid, 'record_topicid' );
$database = \IPS\cms\Databases::constructFromData( $database );
\IPS\Member::loggedIn()->language()->words['cms_delete_linked_topic'] = sprintf( \IPS\Member::loggedIn()->language()->get('cms_delete_linked_topic'), $database->recordWord( 1 ) );
\IPS\Output::i()->error( 'cms_delete_linked_topic', '1T281/1', 403, '' );
}
catch( \Exception $ex ) { }
}
}
else if ( $action === 'lock' or $action === 'unlock' )
{
foreach( \IPS\Db::i()->select( '*', 'cms_databases', array( 'database_forum_record=? AND database_forum_comments=?', 1, 1 ) ) as $database )
{
try
{
$class = '\IPS\cms\Records' . $database['database_id'];
$record = $class::load( $this->tid, 'record_topicid' );
$record->record_locked = ( $action === 'lock' ) ? 1 : 0;
$record->save();
}
catch( \Exception $ex ) { }
}
/* Still here? */
$class = '\IPS\cms\Records' . $databaseId;
try
{
$class::load( $this->tid, 'record_topicid' );
$database = \IPS\cms\Databases::load( $databaseId );
\IPS\Member::loggedIn()->language()->words['cms_delete_linked_topic'] = sprintf( \IPS\Member::loggedIn()->language()->get('cms_delete_linked_topic'), $database->recordWord( 1 ) );
\IPS\Output::i()->error( 'cms_delete_linked_topic', '1T281/1', 403, '' );
}
catch( \OutOfRangeException $ex )
{
/* Not attached to a database record */
return parent::modAction( $action, $member, $reason );
}
}
return parent::modAction( $action, $member, $reason );
+66 -117
View File
@@ -1,135 +1,84 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_Url extends _HOOK_CLASS_
{
protected static $gatewayDir = NULL;
/**
* Get friendly URL data
* Create from string
*
* @param bool $verify If TRUE, will check URL uses correct SEO title
* @return array Parameters
* @throws \OutOfRangeException Invalid URL
* @throws \DomainException URL does not have correct SEO title (exception message will contain correct URL)
* This is overridden so that when we are examing a raw URL the "Gateway File" feature
* can appropriately claim the URL as belonging to it
*
* @param string $url A valid URL as per our definition (see phpDoc on class)
* @param bool $couldBeFriendly If the URL is known to not be friendly, FALSE can be passed here to save the performance implication of checking the URL
* @param bool $autoEncode If true, any invalid components will be automatically encoded rather than an exception thrown - useful if the entire link is user-provided
* @return \IPS\Http\Url
*/
public function getFriendlyUrlData( $verify=false )
public static function createFromString( $url, $couldBeFriendly=TRUE, $autoEncode=FALSE )
{
try
{
return call_user_func_array( 'parent::getFriendlyUrlData', func_get_args() );
}
catch( \OutOfRangeException $ex )
{
/* Pass to IP.Content to handle */
$baseUrl = parse_url( \IPS\Settings::i()->base_url );
if ( \IPS\Settings::i()->htaccess_mod_rewrite )
{
$query = ( isset( $this->data['path'] ) ? $this->data['path'] : '' );
}
else
{
if ( isset( $this->data['path'] ) and mb_strpos( $this->data['path'], 'index.php?' ) )
{
$query = ( isset( $this->data['query'] ) ? ltrim( $this->data['query'], '/' ) : '' );
}
else
{
$query = '';
}
}
/* Because pages can have "nothing" in the URL for SEO reasons, we need to capture query strings first before sending to the parent class */
$queryString = '';
if( mb_strpos( $query, '&' ) !== FALSE )
{
$queryString = ltrim( mb_substr( $query, mb_strpos( $query, '&' ) ), '&' );
$query = mb_substr( $query, 0, mb_strpos( $query, '&' ) );
}
$set = array();
/* See what normal handling makes of it... */
$return = parent::createFromString( $url, $couldBeFriendly, $autoEncode );
/* Need to remember the template we use for FURL verification */
$usedTemplate = NULL;
/* Get furl definition */
$furlDefinition = array('cms_page' => array(
'friendly' => '{@path}',
'real' => 'app=cms&module=pages&controller=page'
) );
$query = preg_replace( '#^(' . preg_quote( rtrim( $baseUrl['path'], '/' ), '#' ) . ')/(index.php)?(?:(?:\?/|\?))?(.+?)?$#', '$3', $query );
$this->examineFurl( $furlDefinition, $query, $set, $usedTemplate );
/* Now set the query string back */
if( $queryString )
/* If the normal handling doesn't recognise it as an internal URL and we
have a gateway file, check that */
if ( !( $return instanceof \IPS\Http\Url\Internal ) and \IPS\Settings::i()->cms_root_page_url )
{
/* Decode it */
$components = static::componentsFromUrlString( $url, $autoEncode );
/* Is it underneath the gateway? */
$gatewayUrlComponents = static::componentsFromUrlString( \IPS\Settings::i()->cms_root_page_url );
if ( $components[ static::COMPONENT_HOST ] === $gatewayUrlComponents[ static::COMPONENT_HOST ] and
$components[ static::COMPONENT_USERNAME ] === $gatewayUrlComponents[ static::COMPONENT_USERNAME ] and
$components[ static::COMPONENT_PASSWORD ] === $gatewayUrlComponents[ static::COMPONENT_PASSWORD ] and
$components[ static::COMPONENT_PORT ] === $gatewayUrlComponents[ static::COMPONENT_PORT ] and
mb_substr( $components[ static::COMPONENT_PATH ], 0, mb_strlen( $gatewayUrlComponents[ static::COMPONENT_PATH ] ) ) === $gatewayUrlComponents[ static::COMPONENT_PATH ]
)
{
$queryString = explode( '&', $queryString );
foreach( $queryString as $k => $v )
$pathFromGatewayUrl = mb_substr( $components[ static::COMPONENT_PATH ], mb_strlen( $gatewayUrlComponents[ static::COMPONENT_PATH ] ) );
$fallback = FALSE;
if ( !$pathFromGatewayUrl or $pathFromGatewayUrl === 'index.php' )
{
$set[ $k ] = $v;
}
}
if ( count( $set ) )
{
if ( ! \IPS\Settings::i()->htaccess_mod_rewrite and isset( $set['path'] ) )
{
/* Is the path URL encoded?
@note this only affects when not using mod_rewrite. We specifically do not urldecode the query string in \IPS\Request::i()->url()
for other reasons, presumaly, hence this code here as it only affects Pages */
if ( str_replace( '%2F', '/', urlencode( urldecode( $set['path'] ) ) ) === $set['path'] )
if ( !$pathFromGatewayUrl )
{
$set['path'] = urldecode( $set['path'] );
}
$fallback = TRUE;
}
$queryString = \IPS\Http\Url::convertQueryAsArrayToString( $components[ static::COMPONENT_QUERY ] );
$pathFromGatewayUrl = trim( mb_substr( $queryString, 0, mb_strpos( $queryString, '&' ) ?: NULL ), '/' );
}
/* Try to find a page */
$page = NULL;
try
{
$page = \IPS\cms\Pages\Page::loadFromPath( $pathFromGatewayUrl );
return \IPS\Http\Url\Friendly::createFromComponents( $components[ static::COMPONENT_HOST ], $components[ static::COMPONENT_SCHEME ], $components[ static::COMPONENT_PATH ], $components[ static::COMPONENT_QUERY ], $components[ static::COMPONENT_PORT ], $components[ static::COMPONENT_USERNAME ], $components[ static::COMPONENT_PASSWORD ], $components[ static::COMPONENT_FRAGMENT ] )
->setFriendlyUrlData( 'content_page_path', array( $pathFromGatewayUrl ), array( 'path' => $pathFromGatewayUrl ), $pathFromGatewayUrl );
}
/* Couldn't find one? Don't accept responsibility, unless there was no $pathFromGatewayUrl and this is the gateway URL */
catch ( \OutOfRangeException $e )
{
if ( $fallback and (string) $return->stripQueryString() === \IPS\Settings::i()->cms_root_page_url )
{
try
{
$page = \IPS\cms\Pages\Page::loadFromPath( '' );
return \IPS\Http\Url\Friendly::createFromComponents( $components[ static::COMPONENT_HOST ], $components[ static::COMPONENT_SCHEME ], $components[ static::COMPONENT_PATH ], $components[ static::COMPONENT_QUERY ], $components[ static::COMPONENT_PORT ], $components[ static::COMPONENT_USERNAME ], $components[ static::COMPONENT_PASSWORD ], $components[ static::COMPONENT_FRAGMENT ] )
->setFriendlyUrlData( 'content_page_path', array( '' ), array( 'path' => '' ), '' );
}
catch ( \OutOfRangeException $e ) { }
}
}
return $set;
}
else
{
throw new \OutOfRangeException();
}
}
}
/**
* Make friendly
*
* @param string|array $seoTemplate The key for making this a friendly URL; or a manual FURL definition
* @param string|array $seoTitles The title(s) needed for the friendly URL
* @param bool $forceHttps Force HTTPS
* @return parent
*/
public function makeFriendly( $seoTemplate, $seoTitles, $forceHttps=FALSE )
{
$called = $seoTemplate;
if ( $seoTemplate === 'content_page_path' )
{
$seoTemplate = array(
'friendly' => '{@path}',
'real' => 'app=cms&module=pages&controller=page'
);
}
parent::makeFriendly( $seoTemplate, $seoTitles, $forceHttps );
if ( $called === 'content_page_path' and \IPS\Settings::i()->cms_use_different_gateway )
{
if ( static::$gatewayDir === NULL )
{
static::$gatewayDir = preg_replace( '#^/?(.+?)/?$#', '\1', str_replace( \IPS\Settings::i()->cms_root_page_url, '', \IPS\Settings::i()->base_url ) );
}
/* If $gatewayDir is empty, we do not want to do this as it will remove all slashes from the entire path */
if ( !empty( static::$gatewayDir ) )
{
$this->data['path'] = str_replace( '/' . static::$gatewayDir, '', $this->data['path'] );
}
$this->url = str_replace( static::baseUrl(), \IPS\Settings::i()->cms_root_page_url, $this->url );
}
/* Return */
return $return;
}
}
+6
View File
@@ -1,5 +1,11 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
abstract class cms_hook_Widget extends _HOOK_CLASS_
{
/**
+6 -10
View File
@@ -1,5 +1,11 @@
//<?php
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class cms_hook_websiteUrl extends _HOOK_CLASS_
{
@@ -26,14 +32,4 @@ public static function hookData() {
}