Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Commit

Permalink
[*] FO: Allow to enable SSL on all the pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rGaillard committed Sep 18, 2013
1 parent 3aec242 commit 0452979
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 53 deletions.
73 changes: 22 additions & 51 deletions classes/Link.php
Expand Up @@ -91,12 +91,8 @@ public function getProductLink($product, $alias = null, $category = null, $ean13
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && $id_shop !== null)
$shop = new Shop($id_shop);
else
$shop = Context::getContext()->shop;

$url = 'http://'.$shop->domain.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);

$url = $this->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);

if (!is_object($product))
{
Expand Down Expand Up @@ -163,11 +159,7 @@ public function getCategoryLink($category, $alias = null, $id_lang = null, $sele
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);
$url = 'http://'.$shop->domain.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);
$url = $this->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);

if (!is_object($category))
$category = new Category($category, $id_lang);
Expand Down Expand Up @@ -206,11 +198,7 @@ public function getCMSCategoryLink($cms_category, $alias = null, $id_lang = null
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);
$url = 'http://'.$shop->domain.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);
$url = $this->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);

$dispatcher = Dispatcher::getInstance();
if (!is_object($cms_category))
Expand Down Expand Up @@ -243,15 +231,8 @@ public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null, $
{
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);

$base = (($ssl && $this->ssl_enable) ? 'https://'.$shop->domain_ssl : 'http://'.$shop->domain);
$url = $base.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);

$url = $this->getBaseLink($id_shop, $ssl).$this->getLangLink($id_lang, null, $id_shop);

$dispatcher = Dispatcher::getInstance();
if (!is_object($cms))
Expand Down Expand Up @@ -290,11 +271,8 @@ public function getSupplierLink($supplier, $alias = null, $id_lang = null, $id_s
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);
$url = 'http://'.$shop->domain.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);

$url = $this->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);

$dispatcher = Dispatcher::getInstance();
if (!is_object($supplier))
Expand Down Expand Up @@ -327,11 +305,7 @@ public function getManufacturerLink($manufacturer, $alias = null, $id_lang = nul
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);
$url = 'http://'.$shop->domain.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);
$url = $this->getBaseLink($id_shop).$this->getLangLink($id_lang, null, $id_shop);

$dispatcher = Dispatcher::getInstance();
if (!is_object($manufacturer))
Expand Down Expand Up @@ -365,13 +339,7 @@ public function getModuleLink($module, $controller = 'default', array $params =
if (!$id_lang)
$id_lang = Context::getContext()->language->id;

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);

$base = (($ssl && $this->ssl_enable) ? 'https://'.$shop->domain_ssl : 'http://'.$shop->domain);
$url = $base.$shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop);
$url = $this->getBaseLink($id_shop, $ssl).$this->getLangLink($id_lang, null, $id_shop);

// If the module has its own route ... just use it !
if (Dispatcher::getInstance()->hasRoute('module-'.$module.'-'.$controller, $id_lang, $id_shop))
Expand Down Expand Up @@ -456,7 +424,6 @@ public function getMediaLink($filepath)
public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null)
{
$controller = Tools::strReplaceFirst('.php', '', $controller);

if (!$id_lang)
$id_lang = (int)Context::getContext()->language->id;

Expand All @@ -469,17 +436,9 @@ public function getPageLink($controller, $ssl = false, $id_lang = null, $request
parse_str($request, $request);
}

if ($id_shop === null)
$shop = Context::getContext()->shop;
else
$shop = new Shop($id_shop);

$uri_path = Dispatcher::getInstance()->createUrl($controller, $id_lang, $request, false, '', $id_shop);

$url = ($ssl && $this->ssl_enable) ? 'https://'.$shop->domain_ssl : 'http://'.$shop->domain;
$url .= $shop->getBaseURI().$this->getLangLink($id_lang, null, $id_shop).ltrim($uri_path, '/');

return $url;
return $this->getBaseLink($id_shop, $ssl).$this->getLangLink($id_lang, null, $id_shop).ltrim($uri_path, '/');
}

public function getCatImageLink($name, $id_category, $type = null)
Expand Down Expand Up @@ -643,5 +602,17 @@ protected function getLangLink($id_lang = null, Context $context = null, $id_sho

return Language::getIsoById($id_lang).'/';
}

protected function getBaseLink($id_shop = null, $ssl = true)
{
if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && $id_shop !== null)
$shop = new Shop($id_shop);
else
$shop = Context::getContext()->shop;

$base = (($ssl && $this->ssl_enable) ? 'https://'.$shop->domain_ssl : 'http://'.$shop->domain);

return $base.$shop->getBaseURI();
}
}

5 changes: 4 additions & 1 deletion classes/controller/FrontController.php
Expand Up @@ -65,6 +65,9 @@ public function __construct()

parent::__construct();

if (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'))
$this->ssl = true;

if (isset($useSSL))
$this->ssl = $useSSL;
else
Expand Down Expand Up @@ -597,7 +600,7 @@ protected function canonicalRedirection($canonical_url = '')
if (!$canonical_url || !Configuration::get('PS_CANONICAL_REDIRECT') || strtoupper($_SERVER['REQUEST_METHOD']) != 'GET' || Tools::getValue('live_edit'))
return;

$match_url = (($this->ssl && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$match_url = (($this->ssl) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$match_url = rawurldecode($match_url);
if (!preg_match('/^'.Tools::pRegexp(rawurldecode($canonical_url), '/').'([&?].*)?$/', $match_url))
{
Expand Down
15 changes: 14 additions & 1 deletion controllers/admin/AdminPreferencesController.php
Expand Up @@ -86,6 +86,19 @@ public function __construct()
'type' => 'bool',
'default' => '0'
),
);

if (Configuration::get('PS_SSL_ENABLED'))
$fields['PS_SSL_ENABLED_EVERYWHERE'] = array(
'title' => $this->l('Force the SSL on all the pages'),
'desc' => $this->l('Force all your store to use SSL'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
);

$fields = array_merge($fields, array(
'PS_TOKEN_ENABLE' => array(
'title' => $this->l('Increase Front Office security'),
'desc' => $this->l('Enable or disable token in the Front Office to improve PrestaShop\'s security.'),
Expand Down Expand Up @@ -135,7 +148,7 @@ public function __construct()
'list' => $activities2,
'identifier' => 'value'
),
);
));

// No HTTPS activation if you haven't already.
if (!Tools::usingSecureMode() && !Configuration::get('PS_SSL_ENABLED'))
Expand Down

1 comment on commit 0452979

@KevinNash
Copy link

@KevinNash KevinNash commented on 0452979 Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello I compared with the files and these lines are missing here on github after line 607 in Link. php

	static $force_ssl = null;
	
	if ($ssl === null)
	{
		if ($force_ssl === null)
			$force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
		$ssl = $force_ssl;
	}

Please sign in to comment.