// Context - first commit
This commit is contained in:
+150
-30
@@ -28,7 +28,7 @@
|
||||
class FrontControllerCore
|
||||
{
|
||||
public $errors = array();
|
||||
protected static $smarty;
|
||||
public $smarty;
|
||||
protected static $cookie;
|
||||
protected static $link;
|
||||
protected static $cart;
|
||||
@@ -52,6 +52,10 @@ class FrontControllerCore
|
||||
public static $initialized = false;
|
||||
|
||||
protected static $currentCustomerGroups;
|
||||
|
||||
public $css_files;
|
||||
public $js_files;
|
||||
public $nb_items_per_page;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -72,7 +76,7 @@ class FrontControllerCore
|
||||
|
||||
public function init()
|
||||
{
|
||||
global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
|
||||
global $link, $cookie, $cart, $smarty, $iso, $defaultCountry;
|
||||
|
||||
if (self::$initialized)
|
||||
return;
|
||||
@@ -81,8 +85,8 @@ class FrontControllerCore
|
||||
$this->id_current_shop = (int)Shop::getCurrentShop();
|
||||
$this->id_current_group_shop = (int)Shop::getCurrentGroupShop();
|
||||
|
||||
$css_files = array();
|
||||
$js_files = array();
|
||||
$this->css_files = array();
|
||||
$this->js_files = array();
|
||||
|
||||
if ($this->ssl AND (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') AND Configuration::get('PS_SSL_ENABLED'))
|
||||
{
|
||||
@@ -97,7 +101,6 @@ class FrontControllerCore
|
||||
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
$cookie = new Cookie('ps');
|
||||
$link = new Link();
|
||||
|
||||
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
|
||||
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
|
||||
@@ -115,7 +118,7 @@ class FrontControllerCore
|
||||
$_GET['id_lang'] = $id_lang;
|
||||
|
||||
Tools::switchLanguage();
|
||||
Tools::setCookieLanguage();
|
||||
Tools::setCookieLanguage($cookie);
|
||||
|
||||
/* attribute id_lang is often needed, so we create a constant for performance reasons */
|
||||
if (!defined('_USER_ID_LANG_'))
|
||||
@@ -133,7 +136,7 @@ class FrontControllerCore
|
||||
}
|
||||
|
||||
global $currency;
|
||||
$currency = Tools::setCurrency();
|
||||
$currency = Tools::setCurrency($cookie);
|
||||
|
||||
$_MODULES = array();
|
||||
|
||||
@@ -224,11 +227,14 @@ class FrontControllerCore
|
||||
|
||||
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
|
||||
$protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
|
||||
|
||||
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));
|
||||
|
||||
$link = new Link($protocol_link, $protocol_content);
|
||||
|
||||
$link->preloadPageLinks();
|
||||
$this->canonicalRedirection();
|
||||
|
||||
@@ -305,7 +311,7 @@ class FrontControllerCore
|
||||
// setting properties from global var
|
||||
self::$cookie = $cookie;
|
||||
self::$cart = $cart;
|
||||
self::$smarty = $smarty;
|
||||
$this->smarty = $smarty;
|
||||
self::$link = $link;
|
||||
|
||||
if ($this->maintenance)
|
||||
@@ -321,6 +327,29 @@ class FrontControllerCore
|
||||
|
||||
$this->iso = $iso;
|
||||
$this->setMedia();
|
||||
|
||||
|
||||
//$defaultCountry
|
||||
if (isset($cookie->id_customer) && (int)$cookie->id_customer)
|
||||
$customer = new Customer($cookie->id_customer);
|
||||
else
|
||||
$customer = new Customer();
|
||||
|
||||
if($cookie->id_country)
|
||||
$customer->geoloc_id_country = (int)$cookie->id_country;
|
||||
if($cookie->id_state)
|
||||
$customer->geoloc_id_state = (int)$cookie->id_state;
|
||||
if($cookie->postcode)
|
||||
$customer->geoloc_postcode = (int)$cookie->postcode;
|
||||
|
||||
$context = Context::getContext();
|
||||
$context->customer = $customer;
|
||||
$context->cart = $cart;
|
||||
$context->link = $link;
|
||||
$context->cookie = $cookie;
|
||||
$context->currency = $currency;
|
||||
$context->controller = $this;
|
||||
$context->language = $ps_language;
|
||||
}
|
||||
|
||||
/* Display a maintenance page if shop is closed */
|
||||
@@ -329,7 +358,7 @@ class FrontControllerCore
|
||||
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))
|
||||
{
|
||||
header('HTTP/1.1 503 temporarily overloaded');
|
||||
self::$smarty->display(_PS_THEME_DIR_.'maintenance.tpl');
|
||||
$this->smarty->display(_PS_THEME_DIR_.'maintenance.tpl');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -431,16 +460,16 @@ class FrontControllerCore
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
Tools::addCSS(_THEME_CSS_DIR_.'global.css', 'all');
|
||||
Tools::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'));
|
||||
$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 $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
{
|
||||
Tools::addJS(array(
|
||||
$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')
|
||||
);
|
||||
Tools::addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css');
|
||||
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,13 +480,11 @@ class FrontControllerCore
|
||||
public function displayContent()
|
||||
{
|
||||
Tools::safePostVars();
|
||||
self::$smarty->assign('errors', $this->errors);
|
||||
$this->smarty->assign('errors', $this->errors);
|
||||
}
|
||||
|
||||
public function displayHeader()
|
||||
{
|
||||
global $css_files, $js_files;
|
||||
|
||||
if (!self::$initialized)
|
||||
$this->init();
|
||||
|
||||
@@ -465,7 +492,7 @@ class FrontControllerCore
|
||||
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');
|
||||
|
||||
/* Hooks are volontary out the initialize array (need those variables already assigned) */
|
||||
self::$smarty->assign(array(
|
||||
$this->smarty->assign(array(
|
||||
'time' => time(),
|
||||
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
|
||||
'static_token' => Tools::getToken(false),
|
||||
@@ -475,7 +502,7 @@ class FrontControllerCore
|
||||
'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
|
||||
'content_only' => (int)Tools::getValue('content_only')
|
||||
));
|
||||
self::$smarty->assign(array(
|
||||
$this->smarty->assign(array(
|
||||
'HOOK_HEADER' => Module::hookExec('header'),
|
||||
'HOOK_TOP' => Module::hookExec('top'),
|
||||
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
|
||||
@@ -485,16 +512,16 @@ class FrontControllerCore
|
||||
{
|
||||
// CSS compressor management
|
||||
if (Configuration::get('PS_CSS_THEME_CACHE'))
|
||||
Tools::cccCss();
|
||||
$this->css_files = Tools::cccCSS($this->css_files);
|
||||
|
||||
//JS compressor management
|
||||
if (Configuration::get('PS_JS_THEME_CACHE'))
|
||||
Tools::cccJs();
|
||||
$this->js_files = Tools::cccJs($this->js_files);
|
||||
}
|
||||
|
||||
self::$smarty->assign('css_files', $css_files);
|
||||
self::$smarty->assign('js_files', array_unique($js_files));
|
||||
self::$smarty->display(_PS_THEME_DIR_.'header.tpl');
|
||||
$this->smarty->assign('css_files', $this->css_files);
|
||||
$this->smarty->assign('js_files', array_unique($this->js_files));
|
||||
$this->smarty->display(_PS_THEME_DIR_.'header.tpl');
|
||||
}
|
||||
|
||||
public function displayFooter()
|
||||
@@ -503,16 +530,16 @@ class FrontControllerCore
|
||||
if (!self::$initialized)
|
||||
$this->init();
|
||||
|
||||
self::$smarty->assign(array(
|
||||
$this->smarty->assign(array(
|
||||
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => self::$cart)),
|
||||
'HOOK_FOOTER' => Module::hookExec('footer'),
|
||||
'content_only' => (int)(Tools::getValue('content_only'))));
|
||||
self::$smarty->display(_PS_THEME_DIR_.'footer.tpl');
|
||||
$this->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_)))
|
||||
{
|
||||
self::$smarty->assign(array('ad' => $ad, 'live_edit' => true));
|
||||
self::$smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
|
||||
$this->smarty->assign(array('ad' => $ad, 'live_edit' => true));
|
||||
$this->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
|
||||
}
|
||||
else
|
||||
Tools::displayError();
|
||||
@@ -539,7 +566,7 @@ class FrontControllerCore
|
||||
if (!in_array($this->orderWay, $orderWayValues))
|
||||
$this->orderWay = $orderWayValues[0];
|
||||
|
||||
self::$smarty->assign(array(
|
||||
$this->smarty->assign(array(
|
||||
'orderby' => $this->orderBy,
|
||||
'orderway' => $this->orderWay,
|
||||
'orderbydefault' => $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))],
|
||||
@@ -575,7 +602,7 @@ class FrontControllerCore
|
||||
$stop = (int)($this->p + $range);
|
||||
if ($stop > $pages_nb)
|
||||
$stop = (int)($pages_nb);
|
||||
self::$smarty->assign('nb_products', $nbProducts);
|
||||
$this->smarty->assign('nb_products', $nbProducts);
|
||||
$pagination_infos = array(
|
||||
'pages_nb' => (int)($pages_nb),
|
||||
'p' => (int)($this->p),
|
||||
@@ -585,7 +612,7 @@ class FrontControllerCore
|
||||
'start' => (int)($start),
|
||||
'stop' => (int)($stop)
|
||||
);
|
||||
self::$smarty->assign($pagination_infos);
|
||||
$this->smarty->assign($pagination_infos);
|
||||
}
|
||||
|
||||
public static function getCurrentCustomerGroups()
|
||||
@@ -613,5 +640,98 @@ class FrontControllerCore
|
||||
$allowed = true;
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* addCSS allows you to add stylesheet at any time.
|
||||
*
|
||||
* @param mixed $css_uri
|
||||
* @param string $css_media_type
|
||||
* @return true
|
||||
*/
|
||||
public function addCSS($css_uri, $css_media_type = 'all')
|
||||
{
|
||||
if (is_array($css_uri))
|
||||
{
|
||||
foreach ($css_uri as $file => $media_type)
|
||||
$this->addCSS($file, $media_type);
|
||||
return true;
|
||||
}
|
||||
|
||||
//overriding of modules css files
|
||||
$different = 0;
|
||||
$override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
|
||||
if ($different && file_exists($override_path))
|
||||
$css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
|
||||
else
|
||||
{
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($css_uri);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
// check if css files exists
|
||||
if (!file_exists($file_uri))
|
||||
return true;
|
||||
}
|
||||
|
||||
// detect mass add
|
||||
$css_uri = array($css_uri => $css_media_type);
|
||||
|
||||
// adding file to the big array...
|
||||
if (is_array($this->css_files))
|
||||
$this->css_files = array_merge($this->css_files, $css_uri);
|
||||
else
|
||||
$this->css_files = $css_uri;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* addJS load a javascript file in the header
|
||||
*
|
||||
* @param mixed $js_uri
|
||||
* @return void
|
||||
*/
|
||||
public function addJS($js_uri)
|
||||
{
|
||||
if(!isset($this->js_files))
|
||||
$this->js_files = array();
|
||||
// avoid useless operation...
|
||||
if (in_array($js_uri, $this->js_files))
|
||||
return true;
|
||||
|
||||
// detect mass add
|
||||
if (!is_array($js_uri) && !in_array($js_uri, $this->js_files))
|
||||
$js_uri = array($js_uri);
|
||||
else
|
||||
foreach($js_uri as $key => $js)
|
||||
if (in_array($js, $this->js_files))
|
||||
unset($js_uri[$key]);
|
||||
|
||||
//overriding of modules js files
|
||||
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);
|
||||
else
|
||||
{
|
||||
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
|
||||
$url_data = parse_url($file);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
// check if js files exists
|
||||
if (!file_exists($file_uri))
|
||||
unset($js_uri[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adding file to the big array...
|
||||
$this->js_files = array_merge($this->js_files, $js_uri);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user