Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,10 @@
|
||||
/**
|
||||
* @brief Database Dispatcher
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Content
|
||||
* @since 16 April 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -61,7 +62,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
/**
|
||||
* @brief Output to return
|
||||
*/
|
||||
public $output = NULL;
|
||||
public $output = "";
|
||||
|
||||
/**
|
||||
* Set Database ID
|
||||
@@ -206,7 +207,6 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
try
|
||||
{
|
||||
$record = $recordClass::loadFromSlug( $slug );
|
||||
|
||||
\IPS\Output::i()->redirect( $record->url(), NULL, 301 );
|
||||
}
|
||||
catch ( \OutOfRangeException $ex )
|
||||
@@ -216,7 +216,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
{
|
||||
$record = $recordClass::loadFromSlugHistory( $slug );
|
||||
|
||||
\IPS\Output::i()->redirect( $record->url(), NULL, 301 );
|
||||
$this->_redirectToCorrectUrl( $record->url() );
|
||||
}
|
||||
catch ( \OutOfRangeException $ex )
|
||||
{
|
||||
@@ -239,7 +239,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
/* Find the record */
|
||||
try
|
||||
{
|
||||
$record = $recordClass::loadFromSlug( $whatsLeft );
|
||||
$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;
|
||||
@@ -251,7 +251,7 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
{
|
||||
$record = $recordClass::loadFromSlugHistory( $whatsLeft );
|
||||
|
||||
\IPS\Output::i()->redirect( $record->url(), NULL, 301 );
|
||||
$this->_redirectToCorrectUrl( $record->url() );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
@@ -259,6 +259,12 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure the URL is correct, for instance, it could have moved categories */
|
||||
if ( $database->use_categories AND $this->categoryId != $record->category_id )
|
||||
{
|
||||
$this->_redirectToCorrectUrl( $record->url() );
|
||||
}
|
||||
|
||||
$this->module = 'record';
|
||||
}
|
||||
else
|
||||
@@ -295,6 +301,34 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
return $this->finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the "correct" URL (for example if the category slug is incorrect)
|
||||
* while retaining any query string parameters in the request URL
|
||||
* For example, an embed to a record might be example.com/records/cat-1/record/?do=embed
|
||||
* 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
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirectToCorrectUrl( $correctUrl )
|
||||
{
|
||||
$paramsToSet = array();
|
||||
foreach ( \IPS\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 ) )
|
||||
{
|
||||
$correctUrl = $correctUrl->setQueryString( $paramsToSet );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $correctUrl, NULL, 301 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish
|
||||
*
|
||||
@@ -302,6 +336,6 @@ class _Dispatcher extends \IPS\Dispatcher
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
return $this->output;
|
||||
return (string) $this->output;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user