Skip to content

Commit

Permalink
// Root old files now keep full $_REQUEST parameters in redirection (…
Browse files Browse the repository at this point in the history
…not only $_GET) in order to keep full retrocompatibility with 1.4
  • Loading branch information
raphaelMalie committed Jan 17, 2012
1 parent e0414c5 commit ba0a2ee
Show file tree
Hide file tree
Showing 40 changed files with 78 additions and 205 deletions.
6 changes: 1 addition & 5 deletions address.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=address'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=address'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions addresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=addresses'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=addresses'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=attachment'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=attachment'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=authentication'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=authentication'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions best-sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=best-sales'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=best-sales'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=cart'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=cart'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions category.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=category'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=category'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions changecurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=change-currency'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=change-currency'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
45 changes: 30 additions & 15 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,32 @@ public static function passwdGen($length = 8, $flag = 'ALPHANUMERIC')
return $passwd;
}

public static function strReplaceFirst($search, $replace, $subject, $cur=0) {
public static function strReplaceFirst($search, $replace, $subject, $cur = 0)
{
return (strpos($subject, $search, $cur))?substr_replace($subject, $replace, (int)strpos($subject, $search, $cur), strlen($search)):$subject;
}

/**
* Redirect user to another page
*
* @param string $url Desired URL
* @param string $baseUri Base URI (optional)
*/
public static function redirect($url, $baseUri = __PS_BASE_URI__, Link $link = null)
* Redirect user to another page
*
* @param string $url Desired URL
* @param string $baseUri Base URI (optional)
* @param Link $link
* @param string|array $headers A list of headers to send before redirection
*/
public static function redirect($url, $base_uri = __PS_BASE_URI__, Link $link = null, $headers = null)
{
if (!$link)
$link = Context::getContext()->link;
if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE)

if (strpos($url, 'http://') === false && strpos($url, 'https://') === false && $link)
{
if (strpos($url, $baseUri) !== FALSE && strpos($url, $baseUri) == 0)
$url = substr($url, strlen($baseUri));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0) {
if (strpos($url, $base_uri) === 0)
$url = substr($url, strlen($base_uri));
if (strpos($url, 'index.php?controller=') !== false && strpos($url, 'index.php/') == 0)
{
$url = substr($url, strlen('index.php?controller='));
if((int)(Configuration::get('PS_REWRITING_SETTINGS') == 1))
if (Configuration::get('PS_REWRITING_SETTINGS'))
$url = self::strReplaceFirst('&', '?' , $url);
}

Expand All @@ -89,13 +94,23 @@ public static function redirect($url, $baseUri = __PS_BASE_URI__, Link $link = n
$url = $link->getPageLink($explode[0], $useSSL);
if (isset($explode[1]))
$url .= '?'.$explode[1];
$baseUri = '';
$base_uri = '';
}

// Send additional headers
if ($headers)
{
if (!is_array($headers))
$headers = array($headers);

foreach ($headers as $header)
header($header);
}

if (isset($_SERVER['HTTP_REFERER']) AND ($url == $_SERVER['HTTP_REFERER']))
if (isset($_SERVER['HTTP_REFERER']) && $url == $_SERVER['HTTP_REFERER'])
header('Location: '.$_SERVER['HTTP_REFERER']);
else
header('Location: '.$baseUri.$url);
header('Location: '.$base_uri.$url);
exit;
}

Expand Down
6 changes: 1 addition & 5 deletions cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=cms'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=cms'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=contact'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=contact'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=discount'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=discount'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions get-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=get-file'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=get-file'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions guest-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=guest-tracking'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=guest-tracking'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions history.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=history'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=history'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=identity'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=identity'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
*/

require(dirname(__FILE__).'/config/config.inc.php');
/*$countries = new Collection('Country', 1);
$countries->where('zone.name', '=', 'Asia');
echo '<pre>';
$countries->getAll(true);
exit;
foreach ($countries->getAll(true) as $country)
echo $country->name.'<br />';
exit;*/
Dispatcher::getInstance()->dispatch();
6 changes: 1 addition & 5 deletions manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=manufacturer'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=manufacturer'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions my-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=my-account'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=my-account'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions new-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=new-products'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=new-products'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-confirmation'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-confirmation'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-detail'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-detail'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-follow.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-follow'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-follow'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-opc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-opc'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-opc'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-return.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-return'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-return'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order-slip.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order-slip'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order-slip'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions order.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=order'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=order'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
6 changes: 1 addition & 5 deletions password.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@
require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();

// init front controller in order to use Tools::redirect
$controller = new FrontController();
$controller->init();

Tools::redirect('index.php?controller=password'.(($_SERVER['QUERY_STRING']) ? '&'.$_SERVER['QUERY_STRING'] : ''));
Tools::redirect('index.php?controller=password'.($_REQUEST ? '&'.http_build_query($_REQUEST) : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');
Loading

0 comments on commit ba0a2ee

Please sign in to comment.