717 lines
27 KiB
PHP
Executable File
717 lines
27 KiB
PHP
Executable File
<?php
|
|
/*
|
|
* 2007-2011 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Open Software License (OSL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/osl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
*
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
* @copyright 2007-2011 PrestaShop SA
|
|
* @version Release: $Revision: 7483 $
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
|
|
class FrontControllerCore extends Controller
|
|
{
|
|
public $errors = array();
|
|
|
|
/**
|
|
* @deprecated Deprecated shortcuts as of 1.5 - Use $context->var instead
|
|
*/
|
|
protected static $smarty, $cookie, $link, $cart;
|
|
|
|
public $iso;
|
|
|
|
public $orderBy;
|
|
public $orderWay;
|
|
public $p;
|
|
public $n;
|
|
|
|
public $auth = false;
|
|
public $guestAllowed = false;
|
|
public $authRedirection = false;
|
|
public $ssl = false;
|
|
|
|
protected $restrictedCountry = false;
|
|
protected $maintenance = false;
|
|
|
|
public static $initialized = false;
|
|
|
|
protected static $currentCustomerGroups;
|
|
|
|
public $nb_items_per_page;
|
|
|
|
public function __construct()
|
|
{
|
|
global $useSSL;
|
|
|
|
parent::__construct();
|
|
$useSSL = $this->ssl;
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
/*
|
|
* Globals are DEPRECATED as of version 1.5.
|
|
* Use the Context to access objects instead.
|
|
* Example: $this->context->cart
|
|
*/
|
|
global $useSSL, $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;
|
|
|
|
if (self::$initialized)
|
|
return;
|
|
self::$initialized = true;
|
|
|
|
// For compatibility with globals, DEPRECATED as of version 1.5
|
|
$css_files = $this->css_files;
|
|
$js_files = $this->js_files;
|
|
|
|
if ($this->ssl AND !Tools::usingSecureMode() AND Configuration::get('PS_SSL_ENABLED'))
|
|
{
|
|
header('HTTP/1.1 301 Moved Permanently');
|
|
header('Location: '.Tools::getShopDomainSsl(true).$_SERVER['REQUEST_URI']);
|
|
exit();
|
|
}
|
|
|
|
ob_start();
|
|
|
|
// Switch language if needed and init cookie language
|
|
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
|
|
$_GET['id_lang'] = $id_lang;
|
|
|
|
Tools::switchLanguage();
|
|
Tools::setCookieLanguage($this->context->cookie);
|
|
$currency = Tools::setCurrency($this->context->cookie);
|
|
|
|
if (Validate::isLoadedObject($currency))
|
|
$this->context->smarty->ps_currency = $currency;
|
|
|
|
$this->context->smarty->ps_language = $this->context->language;
|
|
|
|
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR Tools::usingSecureMode()) ? 'https://' : 'http://';
|
|
$useSSL = ((isset($this->ssl) AND $this->ssl AND Configuration::get('PS_SSL_ENABLED')) OR Tools::usingSecureMode()) ? true : false;
|
|
$protocol_content = ($useSSL) ? 'https://' : 'http://';
|
|
$link = new Link($protocol_link, $protocol_content);
|
|
$this->context->link = $link;
|
|
|
|
if ($this->auth AND !$this->context->customer->isLogged($this->guestAllowed))
|
|
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
|
|
|
|
/* Theme is missing or maintenance */
|
|
if (!is_dir(_PS_THEME_DIR_))
|
|
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
|
|
elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE')))
|
|
$this->maintenance = true;
|
|
elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
|
|
if (($newDefault = $this->geolocationManagement($this->context->country)) && Validate::isLoadedObject($newDefault))
|
|
$this->context->country = $newDefault;
|
|
|
|
if (isset($_GET['logout']) OR ($this->context->customer->logged AND Customer::isBanned($this->context->customer->id)))
|
|
{
|
|
$this->context->customer->logout();
|
|
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
|
|
}
|
|
elseif (isset($_GET['mylogout']))
|
|
{
|
|
$this->context->customer->mylogout();
|
|
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
|
|
}
|
|
|
|
$_MODULES = array();
|
|
|
|
/* Cart already exists */
|
|
if ((int)$this->context->cookie->id_cart)
|
|
{
|
|
$cart = new Cart($this->context->cookie->id_cart);
|
|
if ($cart->OrderExists())
|
|
unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
|
|
/* Delete product of cart, if user can't make an order from his country */
|
|
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) AND
|
|
!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) AND
|
|
$cart->nbProducts() AND intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 AND
|
|
!self::isInWhitelistForGeolocation())
|
|
unset($this->context->cookie->id_cart, $cart);
|
|
// update cart values
|
|
elseif ($this->context->cookie->id_customer != $cart->id_customer OR $this->context->cookie->id_lang != $cart->id_lang OR $currency->id != $cart->id_currency)
|
|
{
|
|
if ($this->context->cookie->id_customer)
|
|
$cart->id_customer = (int)($this->context->cookie->id_customer);
|
|
$cart->id_lang = (int)($this->context->cookie->id_lang);
|
|
$cart->id_currency = (int)$currency->id;
|
|
$cart->update();
|
|
}
|
|
/* Select an address if not set */
|
|
if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 ||
|
|
!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer)
|
|
{
|
|
$to_update = false;
|
|
if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0)
|
|
{
|
|
$to_update = true;
|
|
$cart->id_address_delivery = (int)Address::getFirstCustomerAddressId($cart->id_customer);
|
|
}
|
|
if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0)
|
|
{
|
|
$to_update = true;
|
|
$cart->id_address_invoice = (int)Address::getFirstCustomerAddressId($cart->id_customer);
|
|
}
|
|
if ($to_update)
|
|
$cart->update();
|
|
}
|
|
}
|
|
|
|
if (!isset($cart) OR !$cart->id)
|
|
{
|
|
$cart = new Cart();
|
|
$cart->id_lang = (int)($this->context->cookie->id_lang);
|
|
$cart->id_currency = (int)($this->context->cookie->id_currency);
|
|
$cart->id_guest = (int)($this->context->cookie->id_guest);
|
|
$cart->id_group_shop = (int)$this->context->shop->getGroupID();
|
|
$cart->id_shop = $this->context->shop->getID(true);
|
|
if ($this->context->cookie->id_customer)
|
|
{
|
|
$cart->id_customer = (int)($this->context->cookie->id_customer);
|
|
$cart->id_address_delivery = (int)(Address::getFirstCustomerAddressId($cart->id_customer));
|
|
$cart->id_address_invoice = $cart->id_address_delivery;
|
|
}
|
|
else
|
|
{
|
|
$cart->id_address_delivery = 0;
|
|
$cart->id_address_invoice = 0;
|
|
}
|
|
}
|
|
if (!$cart->nbProducts())
|
|
$cart->id_carrier = NULL;
|
|
|
|
$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')).'_'.strtoupper(Configuration::get('PS_LOCALE_COUNTRY').'.UTF-8');
|
|
setlocale(LC_COLLATE, $locale);
|
|
setlocale(LC_CTYPE, $locale);
|
|
setlocale(LC_TIME, $locale);
|
|
setlocale(LC_NUMERIC, 'en_US.UTF-8');
|
|
|
|
$this->context->smarty->ps_language = $this->context->language;
|
|
|
|
/* get page name to display it in body id */
|
|
// @todo check here
|
|
$page_name = Dispatcher::getInstance()->getController();
|
|
$page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name;
|
|
|
|
// Arf we in a module ?
|
|
if (preg_match('#^'.preg_quote($this->context->shop->getPhysicalURI(), '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m))
|
|
$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
|
|
|
|
$this->context->smarty->assign(Tools::getMetaTags($this->context->language->id, $page_name));
|
|
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
|
|
|
|
/* Breadcrumb */
|
|
$navigationPipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
|
|
$this->context->smarty->assign('navigationPipe', $navigationPipe);
|
|
|
|
if (!defined('_PS_BASE_URL_'))
|
|
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
|
if (!defined('_PS_BASE_URL_SSL_'))
|
|
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
|
|
|
|
// Automatically redirect to the canonical URL if needed
|
|
if (isset($this->php_self) && !empty($this->php_self) && !Tools::getValue('ajax'))
|
|
$this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
|
|
|
|
Product::initPricesComputation();
|
|
|
|
$display_tax_label = $this->context->country->display_tax_label;
|
|
if ($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
|
|
{
|
|
$infos = Address::getCountryAndState((int)($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
|
$country = new Country((int)$infos['id_country']);
|
|
if (Validate::isLoadedObject($country))
|
|
$display_tax_label = $country->display_tax_label;
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'link' => $link,
|
|
'cart' => $cart,
|
|
'currency' => $currency,
|
|
'cookie' => $this->context->cookie,
|
|
'page_name' => $page_name,
|
|
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
|
|
'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,
|
|
'content_dir' => $protocol_content.(($useSSL)?Tools::getShopDomainSsl():Tools::getShopDomain()).__PS_BASE_URI__,
|
|
'tpl_dir' => _PS_THEME_DIR_,
|
|
'modules_dir' => _MODULE_DIR_,
|
|
'mail_dir' => _MAIL_DIR_,
|
|
'lang_iso' => $this->context->language->iso_code,
|
|
'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))),
|
|
'cart_qties' => (int)$cart->nbProducts(),
|
|
'currencies' => Currency::getCurrencies(),
|
|
'languages' => Language::getLanguages(),
|
|
'priceDisplay' => Product::getTaxCalculationMethod(),
|
|
'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
|
|
'shop_name' => Configuration::get('PS_SHOP_NAME'),
|
|
'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
|
|
'use_taxes' => (int)Configuration::get('PS_TAX'),
|
|
'display_tax_label' => (bool)$display_tax_label,
|
|
'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
|
|
'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
|
|
'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE'),
|
|
));
|
|
|
|
// Deprecated
|
|
$this->context->smarty->assign(array(
|
|
'id_currency_cookie' => (int)$currency->id,
|
|
'logged' => $this->context->customer->isLogged(),
|
|
'customerName' => ($this->context->customer->logged ? $this->context->cookie->customer_firstname.' '.$this->context->cookie->customer_lastname : false)
|
|
));
|
|
|
|
// TODO for better performances (cache usage), remove these assign and use a smarty function to get the right media server in relation to the full ressource name
|
|
$assignArray = array(
|
|
'img_ps_dir' => _PS_IMG_,
|
|
'img_cat_dir' => _THEME_CAT_DIR_,
|
|
'img_lang_dir' => _THEME_LANG_DIR_,
|
|
'img_prod_dir' => _THEME_PROD_DIR_,
|
|
'img_manu_dir' => _THEME_MANU_DIR_,
|
|
'img_sup_dir' => _THEME_SUP_DIR_,
|
|
'img_ship_dir' => _THEME_SHIP_DIR_,
|
|
'img_store_dir' => _THEME_STORE_DIR_,
|
|
'img_col_dir' => _THEME_COL_DIR_,
|
|
'img_dir' => _THEME_IMG_DIR_,
|
|
'css_dir' => _THEME_CSS_DIR_,
|
|
'js_dir' => _THEME_JS_DIR_,
|
|
'pic_dir' => _THEME_PROD_PIC_DIR_
|
|
);
|
|
|
|
foreach ($assignArray as $assignKey => $assignValue)
|
|
if (substr($assignValue, 0, 1) == '/' OR $protocol_content == 'https://')
|
|
$this->context->smarty->assign($assignKey, $protocol_content.Tools::getMediaServer($assignValue).$assignValue);
|
|
else
|
|
$this->context->smarty->assign($assignKey, $assignValue);
|
|
|
|
/*
|
|
* These shortcuts are DEPRECATED as of version 1.5.
|
|
* Use the Context to access objects instead.
|
|
* Example: $this->context->cart
|
|
*/
|
|
self::$cookie = $this->context->cookie;
|
|
self::$cart = $cart;
|
|
self::$smarty = $this->context->smarty;
|
|
self::$link = $link;
|
|
$defaultCountry = $this->context->country;
|
|
|
|
if ($this->maintenance)
|
|
$this->displayMaintenancePage();
|
|
if ($this->restrictedCountry)
|
|
$this->displayRestrictedCountryPage();
|
|
|
|
//live edit
|
|
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
|
if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad))
|
|
die(Tools::displayError());
|
|
|
|
$this->iso = $iso;
|
|
$this->setMedia();
|
|
|
|
if($this->context->cookie->id_country)
|
|
$customer->geoloc_id_country = (int)$this->context->cookie->id_country;
|
|
if($this->context->cookie->id_state)
|
|
$customer->geoloc_id_state = (int)$this->context->cookie->id_state;
|
|
if($this->context->cookie->postcode)
|
|
$customer->geoloc_postcode = (int)$this->context->cookie->postcode;
|
|
|
|
$this->context->cart = $cart;
|
|
$this->context->currency = $currency;
|
|
$this->context->controller = $this;
|
|
|
|
$this->displayHeader();
|
|
$this->displayFooter();
|
|
}
|
|
|
|
public function action()
|
|
{
|
|
// For retrocompatibility
|
|
if (method_exists($this, 'preProcess'))
|
|
{
|
|
Tools::displayAsDeprecated('Method preProcess() is deprecated in controllers, use method postProcess() instead');
|
|
$this->preProcess();
|
|
}
|
|
|
|
if (Tools::getValue('ajax') == 'true')
|
|
{
|
|
$this->displayHeader(false);
|
|
$this->displayFooter(false);
|
|
$this->ajaxProcess();
|
|
}
|
|
else
|
|
$this->postProcess();
|
|
|
|
// Prepare generation of page display
|
|
$this->processHeader();
|
|
$this->process();
|
|
$this->processFooter();
|
|
}
|
|
|
|
public function ajaxProcess()
|
|
{
|
|
}
|
|
|
|
public function postProcess()
|
|
{
|
|
}
|
|
|
|
public function process()
|
|
{
|
|
}
|
|
|
|
public function display()
|
|
{
|
|
if ($this->displayHeader)
|
|
$this->context->smarty->display(_PS_THEME_DIR_.'header.tpl');
|
|
|
|
if ($this->template)
|
|
$this->context->smarty->display($this->template);
|
|
|
|
if ($this->displayFooter)
|
|
$this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl');
|
|
|
|
// live edit
|
|
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
|
{
|
|
$this->context->smarty->assign(array('ad' => $ad, 'live_edit' => true));
|
|
$this->context->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
|
|
}
|
|
}
|
|
|
|
/* Display a maintenance page if shop is closed */
|
|
protected function displayMaintenancePage()
|
|
{
|
|
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))
|
|
{
|
|
header('HTTP/1.1 503 temporarily overloaded');
|
|
$this->context->smarty->display(_PS_THEME_DIR_.'maintenance.tpl');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/* Display a specific page if the user country is not allowed */
|
|
protected function displayRestrictedCountryPage()
|
|
{
|
|
header('HTTP/1.1 503 temporarily overloaded');
|
|
$this->context->smarty->display(_PS_THEME_DIR_.'restricted-country.tpl');
|
|
exit;
|
|
}
|
|
|
|
protected function canonicalRedirection($canonicalURL = '')
|
|
{
|
|
if (!$canonicalURL || !Configuration::get('PS_CANONICAL_REDIRECT'))
|
|
return;
|
|
|
|
$matchUrl = (($this->ssl && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/', $matchUrl))
|
|
{
|
|
$params = array();
|
|
$excludedKey = array('isolang', 'id_lang', 'controller');
|
|
foreach ($_GET as $key => $value)
|
|
if (!in_array($key, $excludedKey))
|
|
$params[] = $key.'='.$value;
|
|
|
|
$strParams = '';
|
|
if ($params)
|
|
$strParams = ((strpos($canonicalURL, '?') === false) ? '?' : '&').implode('&', $params);
|
|
|
|
header('HTTP/1.0 301 Moved');
|
|
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $_SERVER['REQUEST_URI'] != __PS_BASE_URI__)
|
|
die('[Debug] This page has moved<br />Please use the following URL instead: <a href="'.$canonicalURL.$strParams.'">'.$canonicalURL.$strParams.'</a>');
|
|
Tools::redirectLink($canonicalURL.$strParams);
|
|
}
|
|
}
|
|
|
|
protected function geolocationManagement($defaultCountry)
|
|
{
|
|
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
|
|
{
|
|
/* Check if Maxmind Database exists */
|
|
if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat'))
|
|
{
|
|
if (!isset($this->context->cookie->iso_code_country) OR (isset($this->context->cookie->iso_code_country) AND !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))))
|
|
{
|
|
include_once(_PS_GEOIP_DIR_.'geoipcity.inc');
|
|
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
|
|
|
|
$gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD);
|
|
$record = geoip_record_by_addr($gi, '81.57.72.226');//Tools::getRemoteAddr());
|
|
|
|
if (is_object($record))
|
|
{
|
|
if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) AND !self::isInWhitelistForGeolocation())
|
|
{
|
|
if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
|
|
$this->restrictedCountry = true;
|
|
elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
|
|
$this->context->smarty->assign(array(
|
|
'restricted_country_mode' => true,
|
|
'geolocation_country' => $record->country_name
|
|
));
|
|
}
|
|
else
|
|
{
|
|
$this->context->cookie->iso_code_country = strtoupper($record->country_code);
|
|
$hasBeenSet = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country))))
|
|
{
|
|
/* Update defaultCountry */
|
|
if($defaultCountry->iso_code != $this->context->cookie->iso_code_country)
|
|
$defaultCountry = new Country($id_country);
|
|
if (isset($hasBeenSet) AND $hasBeenSet)
|
|
$this->context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
|
|
return $defaultCountry;
|
|
}
|
|
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
|
|
$this->restrictedCountry = true;
|
|
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
|
|
$this->context->smarty->assign(array(
|
|
'restricted_country_mode' => true,
|
|
'geolocation_country' => 'Undefined'
|
|
));
|
|
}
|
|
/* If not exists we disabled the geolocation feature */
|
|
else
|
|
Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function setMedia()
|
|
{
|
|
$this->addCSS(_THEME_CSS_DIR_.'global.css', 'all');
|
|
$this->addJS(array(_PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js', _PS_JS_DIR_.'tools.js'));
|
|
if (Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
|
{
|
|
$this->addJS(array(
|
|
_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js',
|
|
_PS_JS_DIR_.'jquery/jquery.fancybox-1.3.4.js',
|
|
_PS_JS_DIR_.'hookLiveEdit.js')
|
|
);
|
|
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css');
|
|
}
|
|
if ($this->context->language->is_rtl)
|
|
$this->addCSS(_THEME_CSS_DIR_.'rtl.css');
|
|
}
|
|
|
|
public function processHeader()
|
|
{
|
|
// P3P Policies (http://www.w3.org/TR/2002/REC-P3P-20020416/#compact_policies)
|
|
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
|
|
|
|
Tools::safePostVars();
|
|
$this->context->smarty->assign('errors', $this->errors);
|
|
|
|
/* Hooks are volontary out the initialize array (need those variables already assigned) */
|
|
$this->context->smarty->assign(array(
|
|
'time' => time(),
|
|
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
|
|
'static_token' => Tools::getToken(false),
|
|
'token' => Tools::getToken(),
|
|
'logo_image_width' => Configuration::get('SHOP_LOGO_WIDTH'),
|
|
'logo_image_height' => Configuration::get('SHOP_LOGO_HEIGHT'),
|
|
'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
|
|
'content_only' => (int)Tools::getValue('content_only')
|
|
));
|
|
$this->context->smarty->assign(array(
|
|
'HOOK_HEADER' => Module::hookExec('header'),
|
|
'HOOK_TOP' => Module::hookExec('top'),
|
|
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
|
|
));
|
|
|
|
if ((Configuration::get('PS_CSS_THEME_CACHE') OR Configuration::get('PS_JS_THEME_CACHE')) AND is_writable(_PS_THEME_DIR_.'cache'))
|
|
{
|
|
// CSS compressor management
|
|
if (Configuration::get('PS_CSS_THEME_CACHE'))
|
|
$this->css_files = Tools::cccCSS($this->css_files);
|
|
|
|
//JS compressor management
|
|
if (Configuration::get('PS_JS_THEME_CACHE'))
|
|
$this->js_files = Tools::cccJs($this->js_files);
|
|
}
|
|
|
|
$this->context->smarty->assign('css_files', $this->css_files);
|
|
$this->context->smarty->assign('js_files', array_unique($this->js_files));
|
|
}
|
|
|
|
public function processFooter()
|
|
{
|
|
$this->context->smarty->assign(array(
|
|
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),
|
|
'HOOK_FOOTER' => Module::hookExec('footer'),
|
|
));
|
|
}
|
|
|
|
public function productSort()
|
|
{
|
|
// $this->orderBy = Tools::getProductsOrder('by', Tools::getValue('orderby'));
|
|
// $this->orderWay = Tools::getProductsOrder('way', Tools::getValue('orderway'));
|
|
// 'orderbydefault' => Tools::getProductsOrder('by'),
|
|
// 'orderwayposition' => Tools::getProductsOrder('way'), // Deprecated: orderwayposition
|
|
// 'orderwaydefault' => Tools::getProductsOrder('way'),
|
|
|
|
$stock_management = (int)(Configuration::get('PS_STOCK_MANAGEMENT')) ? true : false; // no display quantity order if stock management disabled
|
|
$orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity');
|
|
$orderWayValues = array(0 => 'asc', 1 => 'desc');
|
|
$this->orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));
|
|
$this->orderWay = Tools::strtolower(Tools::getValue('orderway', $orderWayValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_WAY'))]));
|
|
if (!in_array($this->orderBy, $orderByValues))
|
|
$this->orderBy = $orderByValues[0];
|
|
if (!in_array($this->orderWay, $orderWayValues))
|
|
$this->orderWay = $orderWayValues[0];
|
|
|
|
$this->context->smarty->assign(array(
|
|
'orderby' => $this->orderBy,
|
|
'orderway' => $this->orderWay,
|
|
'orderbydefault' => $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))],
|
|
'orderwayposition' => $orderWayValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_WAY'))], // Deprecated: orderwayposition
|
|
'orderwaydefault' => $orderWayValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_WAY'))],
|
|
'stock_management' => (int)($stock_management)));
|
|
}
|
|
|
|
public function pagination($nbProducts = 10)
|
|
{
|
|
if (!self::$initialized)
|
|
$this->init();
|
|
elseif (!$this->context)
|
|
$this->context = Context::getContext();
|
|
|
|
$nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 10 ? array((int)(Configuration::get('PS_PRODUCTS_PER_PAGE')), 10, 20, 50) : array(10, 20, 50);
|
|
asort($nArray);
|
|
$this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) AND $this->context->cookie->nb_item_per_page >= 10) ? $this->context->cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));
|
|
$this->p = abs((int)(Tools::getValue('p', 1)));
|
|
|
|
$current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
|
|
//delete parameter page
|
|
$current_url = preg_replace('/(\?)?(&)?p=\d+/', '$1', $current_url);
|
|
|
|
$range = 2; /* how many pages around page selected */
|
|
|
|
if ($this->p < 0)
|
|
$this->p = 0;
|
|
|
|
if (isset($this->context->cookie->nb_item_per_page) AND $this->n != $this->context->cookie->nb_item_per_page AND in_array($this->n, $nArray))
|
|
$this->context->cookie->nb_item_per_page = $this->n;
|
|
|
|
if ($this->p > ($nbProducts / $this->n))
|
|
$this->p = ceil($nbProducts / $this->n);
|
|
$pages_nb = ceil($nbProducts / (int)($this->n));
|
|
|
|
$start = (int)($this->p - $range);
|
|
if ($start < 1)
|
|
$start = 1;
|
|
$stop = (int)($this->p + $range);
|
|
if ($stop > $pages_nb)
|
|
$stop = (int)($pages_nb);
|
|
$this->context->smarty->assign('nb_products', $nbProducts);
|
|
$pagination_infos = array(
|
|
'pages_nb' => (int)($pages_nb),
|
|
'p' => (int)($this->p),
|
|
'n' => (int)($this->n),
|
|
'nArray' => $nArray,
|
|
'range' => (int)($range),
|
|
'start' => (int)($start),
|
|
'stop' => (int)($stop),
|
|
'current_url' => $current_url
|
|
);
|
|
$this->context->smarty->assign($pagination_infos);
|
|
}
|
|
|
|
public static function getCurrentCustomerGroups()
|
|
{
|
|
if (!Group::isFeatureActive())
|
|
return array();
|
|
|
|
$context = Context::getContext();
|
|
if (!$context->customer->id)
|
|
return array();
|
|
if (!is_array(self::$currentCustomerGroups))
|
|
{
|
|
self::$currentCustomerGroups = array();
|
|
$result = Db::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$context->customer->id);
|
|
foreach ($result as $row)
|
|
self::$currentCustomerGroups[] = $row['id_group'];
|
|
}
|
|
return self::$currentCustomerGroups;
|
|
}
|
|
|
|
protected static function isInWhitelistForGeolocation()
|
|
{
|
|
$allowed = false;
|
|
$userIp = Tools::getRemoteAddr();
|
|
$ips = explode(';', Configuration::get('PS_GEOLOCATION_WHITELIST'));
|
|
if (is_array($ips) && sizeof($ips))
|
|
foreach ($ips as $ip)
|
|
if (!empty($ip) && strpos($userIp, $ip) === 0)
|
|
$allowed = true;
|
|
return $allowed;
|
|
}
|
|
|
|
/**
|
|
* Add one or several CSS for front, checking if css files are overriden in theme/css/modules/ directory
|
|
*
|
|
* @see Controller::addCSS()
|
|
*/
|
|
public function addCSS($css_uri, $css_media_type = 'all')
|
|
{
|
|
if (!is_array($css_uri))
|
|
$css_uri = array($css_uri => $css_media_type);
|
|
|
|
$list_uri = array();
|
|
foreach ($css_uri as $file => $media)
|
|
{
|
|
$different = 0;
|
|
$override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/css/modules/', $file, $different);
|
|
if ($different && file_exists($override_path))
|
|
$file = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $file, $different);
|
|
$list_uri[$file] = $media;
|
|
}
|
|
|
|
return parent::addCSS($list_uri, $css_media_type);
|
|
}
|
|
|
|
/**
|
|
* Add one or several JS files for front, checking if js files are overriden in theme/js/modules/ directory
|
|
*
|
|
* @see Controller::addJS()
|
|
*/
|
|
public function addJS($js_uri)
|
|
{
|
|
if (!is_array($js_uri))
|
|
$js_uri = array($js_uri);
|
|
|
|
foreach ($js_uri as $key => &$file)
|
|
{
|
|
if (!preg_match('/^http(s?):\/\//i', $file))
|
|
{
|
|
$different = 0;
|
|
$override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/js/modules/', $file, $different);
|
|
if ($different && file_exists($override_path))
|
|
$file = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/js/modules/', $file, $different);
|
|
}
|
|
}
|
|
|
|
return parent::addJS($js_uri);
|
|
}
|
|
}
|
|
|