// Context part 8

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7633 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-07-15 16:41:39 +00:00
parent 20276404a8
commit 311e8ab964
10 changed files with 163 additions and 161 deletions
+8 -8
View File
@@ -100,7 +100,7 @@ class FrontControllerCore
ob_start();
$cookie = new Cookie('ps');
$context->cookie = $cookie;
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
@@ -110,7 +110,7 @@ class FrontControllerCore
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() && Validate::isLoadedObject($newDefault))
if (($newDefault = $this->geolocationManagement($defaultCountry)) && Validate::isLoadedObject($newDefault))
$defaultCountry = $newDefault;
// Switch language if needed and init cookie language
@@ -388,10 +388,10 @@ class FrontControllerCore
}
}
protected function geolocationManagement()
protected function geolocationManagement($defaultCountry)
{
$context = Context::getContext();
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
{
/* Check if Maxmind Database exists */
@@ -403,7 +403,7 @@ class FrontControllerCore
include_once(_PS_GEOIP_DIR_.'geoipregionvars.php');
$gi = geoip_open(realpath(_PS_GEOIP_DIR_.'GeoLiteCity.dat'), GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, Tools::getRemoteAddr());
$record = geoip_record_by_addr($gi, '81.57.72.226');//Tools::getRemoteAddr());
if (is_object($record))
{
@@ -425,11 +425,11 @@ class FrontControllerCore
}
}
if (isset($context->cookie->iso_code_country)
&& (int)($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
if (isset($context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country))))
{
/* Update defaultCountry */
$defaultCountry = new Country($id_country);
if($defaultCountry->iso_code != $context->cookie->iso_code_country)
$defaultCountry = new Country($id_country);
if (isset($hasBeenSet) AND $hasBeenSet)
$context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
return $defaultCountry;
+1 -2
View File
@@ -208,7 +208,6 @@ class SceneCore extends ObjectModel
*/
public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, $context = null)
{
global $link;
if (!$context)
$context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
@@ -223,7 +222,7 @@ class SceneCore extends ObjectModel
foreach ($products AS &$product)
{
$product['details'] = new Product($product['id_product'], !$liteResult, $id_lang);
$product['link'] = $link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13);
$product['link'] = $context->link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13);
$cover = Product::getCover($product['details']->id);
if(is_array($cover))
$product = array_merge($cover, $product);
-2
View File
@@ -113,8 +113,6 @@ class SupplierCore extends ObjectModel
*/
static public function getSuppliers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
{
global $cookie;
if (!$id_lang)
$id_lang = Configuration::get('PS_LANG_DEFAULT');
$query = 'SELECT s.*, sl.`description`';
+5 -5
View File
@@ -78,11 +78,11 @@ class TabCore extends ObjectModel
return false;
}
static public function initAccess($id_tab)
static public function initAccess($id_tab, $context = null)
{
/* Cookie's loading */
global $cookie;
if (!is_object($cookie) OR !$cookie->profile)
if (!$context)
$context = Context::getContext();
if (!$context->employee->id_profile)
return false;
/* Profile selection */
$profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile');
@@ -92,7 +92,7 @@ class TabCore extends ObjectModel
$query = 'INSERT INTO `'._DB_PREFIX_.'access` VALUES ';
foreach ($profiles AS $profile)
{
$rights = (((int)($profile['id_profile']) == 1 OR (int)($profile['id_profile']) == $cookie->profile) ? 1 : 0);
$rights = (((int)($profile['id_profile']) == 1 OR (int)($profile['id_profile']) == $context->employee->id_profile) ? 1 : 0);
$query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)($profile['id_profile']).', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')';
}
return Db::getInstance()->Execute($query);
+4 -3
View File
@@ -161,10 +161,11 @@ class TagCore extends ObjectModel
return $result;
}
public function getProducts($associated = true)
public function getProducts($associated = true, $context = null)
{
global $cookie;
$id_lang = $this->id_lang ? $this->id_lang : $cookie->id_lang;
if (!$context)
$context = Context::getContext();
$id_lang = $this->id_lang ? $this->id_lang : $context->language->id;
if (!$this->id AND $associated)
return array();
-2
View File
@@ -231,8 +231,6 @@ class TaxCore extends ObjectModel
public static function getApplicableTaxRate($id_tax, $productTax, $id_address = NULL)
{
Tools::displayAsDeprecated();
global $cart, $cookie, $defaultCountry;
return $productTax;
}
+45 -44
View File
@@ -55,11 +55,10 @@ class ToolsCore
* @param string $url Desired URL
* @param string $baseUri Base URI (optional)
*/
public static function redirect($url, $baseUri = __PS_BASE_URI__)
public static function redirect($url, $baseUri = __PS_BASE_URI__, $context = null)
{
if (strpos($url, 'http://') === FALSE && strpos($url, 'https://') === FALSE)
{
global $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) {
@@ -69,7 +68,7 @@ class ToolsCore
}
$explode = explode('?', $url);
$url = $link->getPageLink($explode[0], true);
$url = $context->link->getPageLink($explode[0], true);
if (isset($explode[1]))
$url .= '?'.$explode[1];
$baseUri = '';
@@ -91,17 +90,15 @@ class ToolsCore
{
if (!preg_match('@^https?://@i', $url))
{
global $link;
if (strpos($url, __PS_BASE_URI__) !== FALSE && strpos($url, __PS_BASE_URI__) == 0)
$url = substr($url, strlen(__PS_BASE_URI__));
if (strpos($url, 'index.php?controller=') !== FALSE && strpos($url, 'index.php/') == 0)
$url = substr($url, strlen('index.php?controller='));
$explode = explode('?', $url);
$url = $link->getPageLink($explode[0]);
$url = $context->link->getPageLink($explode[0]);
if (isset($explode[1]))
$url .= '?'.$explode[1];
}
header('Location: '.$url);
exit;
}
@@ -528,12 +525,11 @@ class ToolsCore
*
* @param integer $code Error code
*/
public static function displayError($string = 'Fatal error', $htmlentities = true)
public static function displayError($string = 'Fatal error', $htmlentities = true, $context = null)
{
global $_ERRORS, $cookie;
global $_ERRORS;
$iso = strtolower(Language::getIsoById((is_object($cookie) AND $cookie->id_lang) ? (int)$cookie->id_lang : (int)Configuration::get('PS_LANG_DEFAULT')));
@include_once(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
@include_once(_PS_TRANSLATIONS_DIR_.$context->language->iso_code.'/errors.php');
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $string == 'Fatal error')
return ('<pre>'.print_r(debug_backtrace(), true).'</pre>');
@@ -715,8 +711,6 @@ class ToolsCore
*/
public static function getHomeMetaTags($id_lang, $page_name)
{
global $cookie;
/* Metas-tags */
$metas = Meta::getMetaByPage($page_name, $id_lang);
$ret['meta_title'] = (isset($metas['title']) AND $metas['title']) ? $metas['title'].' - '.Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME');
@@ -726,16 +720,17 @@ class ToolsCore
}
public static function completeMetaTags($metaTags, $defaultValue)
public static function completeMetaTags($metaTags, $defaultValue, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
if ($metaTags['meta_title'] == NULL)
$metaTags['meta_title'] = $defaultValue.' - '.Configuration::get('PS_SHOP_NAME');
if ($metaTags['meta_description'] == NULL)
$metaTags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', (int)($cookie->id_lang)) ? Configuration::get('PS_META_DESCRIPTION', (int)($cookie->id_lang)) : '';
$metaTags['meta_description'] = Configuration::get('PS_META_DESCRIPTION', $context->language->id) ? Configuration::get('PS_META_DESCRIPTION', $context->language->id) : '';
if ($metaTags['meta_keywords'] == NULL)
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', (int)($cookie->id_lang)) ? Configuration::get('PS_META_KEYWORDS', (int)($cookie->id_lang)) : '';
$metaTags['meta_keywords'] = Configuration::get('PS_META_KEYWORDS', $context->language->id) ? Configuration::get('PS_META_KEYWORDS', $context->language->id) : '';
return $metaTags;
}
@@ -754,13 +749,14 @@ class ToolsCore
*
* @param string $token token to encrypt
*/
public static function getToken($page = true)
public static function getToken($page = true, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
if ($page === true)
return (self::encrypt($cookie->id_customer.$cookie->passwd.$_SERVER['SCRIPT_NAME']));
return (self::encrypt($context->customer->id.$context->customer->passwd.$_SERVER['SCRIPT_NAME']));
else
return (self::encrypt($cookie->id_customer.$cookie->passwd.$page));
return (self::encrypt($context->customer->id.$context->customer->passwd.$page));
}
/**
@@ -772,10 +768,11 @@ class ToolsCore
{
return !empty($string) ? self::encrypt($string) : false;
}
public static function getAdminTokenLite($tab)
public static function getAdminTokenLite($tab, $context = null)
{
global $cookie;
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$cookie->id_employee);
if (!$context)
$context = Context::getContext();
return Tools::getAdminToken($tab.(int)Tab::getIdFromClassName($tab).(int)$context->employee->id);
}
/**
@@ -786,10 +783,11 @@ class ToolsCore
* @param boolean $linkOntheLastItem Put or not a link on the current category
* @param string [optionnal] $categoryType defined what type of categories is used (products or cms)
*/
public static function getPath($id_category, $path = '', $linkOntheLastItem = false, $categoryType = 'products')
public static function getPath($id_category, $path = '', $linkOntheLastItem = false, $categoryType = 'products', $context = null)
{
global $link, $cookie;
if (!$context)
$context = Context::getContext();
if ($id_category == 1)
return '<span class="navigation_end">'.$path.'</span>';
@@ -812,7 +810,7 @@ class ToolsCore
SELECT c.id_category, cl.name, cl.link_rewrite
FROM '._DB_PREFIX_.'category c
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category)
WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)($cookie->id_lang).' AND c.id_category != 1
WHERE c.nleft <= '.(int)$category['nleft'].' AND c.nright >= '.(int)$category['nright'].' AND cl.id_lang = '.(int)$context->language->id.' AND c.id_category != 1
ORDER BY c.level_depth ASC
LIMIT '.(int)$category['level_depth']);
@@ -821,7 +819,7 @@ class ToolsCore
foreach ($categories AS $category)
{
$fullPath .=
(($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
(($n < $nCategories OR $linkOntheLastItem) ? '<a href="'.self::safeOutput($context->link->getCategoryLink((int)$category['id_category'], $category['link_rewrite'])).'" title="'.htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').'">' : '').
htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8').
(($n < $nCategories OR $linkOntheLastItem) ? '</a>' : '').
(($n++ != $nCategories OR !empty($path)) ? '<span class="navigation-pipe">'.$pipe.'</span>' : '');
@@ -832,10 +830,10 @@ class ToolsCore
}
elseif ($categoryType === 'CMS')
{
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang));
$category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category))
die(self::displayError());
$categoryLink = $link->getCMSCategoryLink($category);
$categoryLink = $context->link->getCMSCategoryLink($category);
if ($path != $category->name)
$fullPath .= '<a href="'.self::safeOutput($categoryLink).'">'.htmlentities($category->name, ENT_NOQUOTES, 'UTF-8').'</a><span class="navigation-pipe">'.$pipe.'</span>'.$path;
@@ -849,16 +847,17 @@ class ToolsCore
/**
* @param string [optionnal] $type_cat defined what type of categories is used (products or cms)
*/
public static function getFullPath($id_category, $end, $type_cat = 'products')
public static function getFullPath($id_category, $end, $type_cat = 'products', $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$pipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>');
if($type_cat === 'products')
$category = new Category((int)($id_category), (int)($cookie->id_lang));
$category = new Category($id_category, $context->language->id);
else if ($type_cat === 'CMS')
$category = new CMSCategory((int)($id_category), (int)($cookie->id_lang));
$category = new CMSCategory($id_category, $context->language->id);
if (!Validate::isLoadedObject($category))
$id_category = 1;
@@ -914,11 +913,10 @@ class ToolsCore
*/
public static function historyc_l($key, $translations)
{
global $cookie;
if (!$translations OR !is_array($translations))
die(self::displayError());
$iso = strtoupper(Language::getIsoById($cookie->id_lang));
$lang = key_exists($iso, $translations) ? $translations[$iso] : false;
$lang = key_exists($context->language->iso_code, $translations) ? $translations[$context->language->iso_code] : false;
return (($lang AND is_array($lang) AND key_exists($key, $lang)) ? stripslashes($lang[$key]) : $key);
}
@@ -1375,7 +1373,7 @@ class ToolsCore
public static function replaceByAbsoluteURL($matches)
{
global $current_css_file, $protocol_link;
global $current_css_file;
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
@@ -1857,10 +1855,11 @@ FileETag INode MTime Size
}
}
public static function enableCache($level = 1)
public static function enableCache($level = 1, $context = null)
{
global $smarty;
if (!$context)
$context = Context::getContext();
$smarty = $context->controller->smarty;
if (!Configuration::get('PS_SMARTY_CACHE'))
return;
if ($smarty->force_compile == 0 AND $smarty->caching == $level)
@@ -1871,10 +1870,12 @@ FileETag INode MTime Size
$smarty->caching = (int)($level);
}
public static function restoreCacheSettings()
public static function restoreCacheSettings($context = null)
{
global $smarty;
if (!$context)
$context = Context::getContext();
$smarty = $context->controller->smarty;
if (isset(self::$_forceCompile))
$smarty->force_compile = (int)(self::$_forceCompile);
if (isset(self::$_caching))