// Context part 19

This commit is contained in:
tDidierjean committed 2011-07-25 16:42:48 +00:00
1 parent 2c4f27f1be
commit a96064b13d
4 files changed
+38 -41

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ $link = new Link($protocol_link, $protocol_content);
define('_PS_BASE_URL_', Tools::getShopDomain(true)); define('_PS_BASE_URL_', Tools::getShopDomain(true));
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true)); define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$employee = new Employee((int)$cookie->id_employee); $employee = new Employee($cookie->id_employee);
$cookie->id_lang = (int)$employee->id_lang; $cookie->id_lang = (int)$employee->id_lang;
$language = new Language($cookie->id_lang ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT')); $language = new Language($cookie->id_lang ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'));
$iso = $language->iso_code; $iso = $language->iso_code;
+1 -2
View File
@@ -264,7 +264,6 @@ class AdminCustomers extends AdminTab
$context = Context::getContext(); $context = Context::getContext();
$irow = 0; $irow = 0;
$defaultLanguage = $context->language->id; $defaultLanguage = $context->language->id;
$defaultCurrency = $context->currency->id;
if (!($customer = $this->loadObject())) if (!($customer = $this->loadObject()))
return; return;
$customerStats = $customer->getStats(); $customerStats = $customer->getStats();
@@ -440,7 +439,7 @@ class AdminCustomers extends AdminTab
$orderFoot = '</table>'; $orderFoot = '</table>';
if ($countOK = sizeof($ordersOK)) if ($countOK = sizeof($ordersOK))
{ {
echo '<div style="float:left;margin-right:20px"><h3 style="color:green;font-weight:700">'.$this->l('Valid orders:').' '.$countOK.' '.$this->l('for').' '.Tools::displayPrice($totalOK, new Currency($defaultCurrency)).'</h3>'.$orderHead; echo '<div style="float:left;margin-right:20px"><h3 style="color:green;font-weight:700">'.$this->l('Valid orders:').' '.$countOK.' '.$this->l('for').' '.Tools::displayPrice($totalOK, $context->currency->id).'</h3>'.$orderHead;
foreach ($ordersOK AS $order) foreach ($ordersOK AS $order)
echo '<tr '.($irow++ % 2 ? 'class="alt_row"' : '').' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order='.$order['id_order'].'&vieworder&token='.$tokenOrders.'\'"> echo '<tr '.($irow++ % 2 ? 'class="alt_row"' : '').' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order='.$order['id_order'].'&vieworder&token='.$tokenOrders.'\'">
<td class="center">'.$order['id_order'].'</td> <td class="center">'.$order['id_order'].'</td>
+30 -30
View File
@@ -85,7 +85,7 @@ class FrontControllerCore
* Use the Context to access objects instead. * Use the Context to access objects instead.
* Example: $this->context->cart * Example: $this->context->cart
*/ */
global $link, $cookie, $cart, $smarty, $iso, $defaultCountry; global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files, $currency;
if (self::$initialized) if (self::$initialized)
return; return;
@@ -103,7 +103,11 @@ class FrontControllerCore
$this->css_files = array(); $this->css_files = array();
$this->js_files = array(); $this->js_files = array();
// For compatibility with globals, DEPRECATED as of version 1.5
$css_files = $this->css_files;
$js_files = $this->js_files;
if ($this->ssl AND (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') AND Configuration::get('PS_SSL_ENABLED')) if ($this->ssl AND (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off') AND Configuration::get('PS_SSL_ENABLED'))
{ {
header('HTTP/1.1 301 Moved Permanently'); header('HTTP/1.1 301 Moved Permanently');
@@ -116,11 +120,6 @@ class FrontControllerCore
$cookie = new Cookie('ps'); $cookie = new Cookie('ps');
$this->context->cookie = $cookie; $this->context->cookie = $cookie;
$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://';
$link = new Link($protocol_link, $protocol_content);
$this->context->link = $link;
if ($this->auth AND !$cookie->isLogged($this->guestAllowed)) if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : '')); Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
@@ -371,7 +370,7 @@ class FrontControllerCore
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))
{ {
header('HTTP/1.1 503 temporarily overloaded'); header('HTTP/1.1 503 temporarily overloaded');
self::$smarty->display(_PS_THEME_DIR_.'maintenance.tpl'); $this->context->smarty->display(_PS_THEME_DIR_.'maintenance.tpl');
exit; exit;
} }
} }
@@ -380,7 +379,7 @@ class FrontControllerCore
protected function displayRestrictedCountryPage() protected function displayRestrictedCountryPage()
{ {
header('HTTP/1.1 503 temporarily overloaded'); header('HTTP/1.1 503 temporarily overloaded');
self::$smarty->display(_PS_THEME_DIR_.'restricted-country.tpl'); $this->context->smarty->display(_PS_THEME_DIR_.'restricted-country.tpl');
exit; exit;
} }
@@ -428,7 +427,7 @@ class FrontControllerCore
if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
$this->restrictedCountry = true; $this->restrictedCountry = true;
elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
self::$smarty->assign(array( $this->context->smarty->assign(array(
'restricted_country_mode' => true, 'restricted_country_mode' => true,
'geolocation_country' => $record->country_name 'geolocation_country' => $record->country_name
)); ));
@@ -453,7 +452,7 @@ class FrontControllerCore
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
$this->restrictedCountry = true; $this->restrictedCountry = true;
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
self::$smarty->assign(array( $this->context->smarty->assign(array(
'restricted_country_mode' => true, 'restricted_country_mode' => true,
'geolocation_country' => 'Undefined' 'geolocation_country' => 'Undefined'
)); ));
@@ -491,7 +490,7 @@ class FrontControllerCore
public function displayContent() public function displayContent()
{ {
Tools::safePostVars(); Tools::safePostVars();
self::$smarty->assign('errors', $this->errors); $this->context->smarty->assign('errors', $this->errors);
} }
public function displayHeader() public function displayHeader()
@@ -502,7 +501,7 @@ class FrontControllerCore
header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'); 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) */ /* Hooks are volontary out the initialize array (need those variables already assigned) */
self::$smarty->assign(array( $this->context->smarty->assign(array(
'time' => time(), 'time' => time(),
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'), 'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'static_token' => Tools::getToken(false), 'static_token' => Tools::getToken(false),
@@ -512,7 +511,7 @@ class FrontControllerCore
'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
'content_only' => (int)Tools::getValue('content_only') 'content_only' => (int)Tools::getValue('content_only')
)); ));
self::$smarty->assign(array( $this->context->smarty->assign(array(
'HOOK_HEADER' => Module::hookExec('header'), 'HOOK_HEADER' => Module::hookExec('header'),
'HOOK_TOP' => Module::hookExec('top'), 'HOOK_TOP' => Module::hookExec('top'),
'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn') 'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn')
@@ -529,9 +528,9 @@ class FrontControllerCore
$this->js_files = Tools::cccJs($this->js_files); $this->js_files = Tools::cccJs($this->js_files);
} }
self::$smarty->assign('css_files', $this->css_files); $this->context->smarty->assign('css_files', $this->css_files);
self::$smarty->assign('js_files', array_unique($this->js_files)); $this->context->smarty->assign('js_files', array_unique($this->js_files));
self::$smarty->display(_PS_THEME_DIR_.'header.tpl'); $this->context->smarty->display(_PS_THEME_DIR_.'header.tpl');
} }
public function displayFooter() public function displayFooter()
@@ -539,16 +538,16 @@ class FrontControllerCore
if (!self::$initialized) if (!self::$initialized)
$this->init(); $this->init();
self::$smarty->assign(array( $this->context->smarty->assign(array(
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => self::$cart)), 'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),
'HOOK_FOOTER' => Module::hookExec('footer'), 'HOOK_FOOTER' => Module::hookExec('footer'),
'content_only' => (int)(Tools::getValue('content_only')))); 'content_only' => (int)(Tools::getValue('content_only'))));
self::$smarty->display(_PS_THEME_DIR_.'footer.tpl'); $this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl');
//live edit //live edit
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_))) 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)); $this->context->smarty->assign(array('ad' => $ad, 'live_edit' => true));
self::$smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl'); $this->context->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl');
} }
else else
Tools::displayError(); Tools::displayError();
@@ -575,7 +574,7 @@ class FrontControllerCore
if (!in_array($this->orderWay, $orderWayValues)) if (!in_array($this->orderWay, $orderWayValues))
$this->orderWay = $orderWayValues[0]; $this->orderWay = $orderWayValues[0];
self::$smarty->assign(array( $this->context->smarty->assign(array(
'orderby' => $this->orderBy, 'orderby' => $this->orderBy,
'orderway' => $this->orderWay, 'orderway' => $this->orderWay,
'orderbydefault' => $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))], 'orderbydefault' => $orderByValues[(int)(Configuration::get('PS_PRODUCTS_ORDER_BY'))],
@@ -591,15 +590,15 @@ class FrontControllerCore
$nArray = (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')) != 10 ? array((int)(Configuration::get('PS_PRODUCTS_PER_PAGE')), 10, 20, 50) : array(10, 20, 50); $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); asort($nArray);
$this->n = abs((int)(Tools::getValue('n', ((isset(self::$cookie->nb_item_per_page) AND self::$cookie->nb_item_per_page >= 10) ? self::$cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE')))))); $this->n = abs((int)(Tools::getValue('n', ((isset($this->context->cookie->nb_item_per_page) AND $this->context->cookie->nb_item_per_page >= 10) ? self::$this->context->cookie->nb_item_per_page : (int)(Configuration::get('PS_PRODUCTS_PER_PAGE'))))));
$this->p = abs((int)(Tools::getValue('p', 1))); $this->p = abs((int)(Tools::getValue('p', 1)));
$range = 2; /* how many pages around page selected */ $range = 2; /* how many pages around page selected */
if ($this->p < 0) if ($this->p < 0)
$this->p = 0; $this->p = 0;
if (isset(self::$cookie->nb_item_per_page) AND $this->n != self::$cookie->nb_item_per_page AND in_array($this->n, $nArray)) 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))
self::$cookie->nb_item_per_page = $this->n; $this->context->cookie->nb_item_per_page = $this->n;
if ($this->p > ($nbProducts / $this->n)) if ($this->p > ($nbProducts / $this->n))
$this->p = ceil($nbProducts / $this->n); $this->p = ceil($nbProducts / $this->n);
@@ -611,7 +610,7 @@ class FrontControllerCore
$stop = (int)($this->p + $range); $stop = (int)($this->p + $range);
if ($stop > $pages_nb) if ($stop > $pages_nb)
$stop = (int)($pages_nb); $stop = (int)($pages_nb);
self::$smarty->assign('nb_products', $nbProducts); $this->context->smarty->assign('nb_products', $nbProducts);
$pagination_infos = array( $pagination_infos = array(
'pages_nb' => (int)($pages_nb), 'pages_nb' => (int)($pages_nb),
'p' => (int)($this->p), 'p' => (int)($this->p),
@@ -621,17 +620,18 @@ class FrontControllerCore
'start' => (int)($start), 'start' => (int)($start),
'stop' => (int)($stop) 'stop' => (int)($stop)
); );
self::$smarty->assign($pagination_infos); $this->context->smarty->assign($pagination_infos);
} }
public static function getCurrentCustomerGroups() public static function getCurrentCustomerGroups()
{ {
if (!isset(self::$cookie) || !self::$cookie->id_customer) $context = Context::getContext();
if (!$context->customer->id)
return array(); return array();
if (!is_array(self::$currentCustomerGroups)) if (!is_array(self::$currentCustomerGroups))
{ {
self::$currentCustomerGroups = array(); self::$currentCustomerGroups = array();
$result = Db::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)self::$cookie->id_customer); $result = Db::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.(int)$context->customer->id);
foreach ($result as $row) foreach ($result as $row)
self::$currentCustomerGroups[] = $row['id_group']; self::$currentCustomerGroups[] = $row['id_group'];
} }
+6 -8
View File
@@ -134,12 +134,10 @@ class StatsCatalog extends Module
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
{ {
global $cookie; $context = Context::getContext();
$categories = Category::getCategories((int)($cookie->id_lang), true, false); $categories = Category::getCategories($context->language->id, true, false);
$productToken = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)); $productToken = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$context->employee->id);
$currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT'));
$link = new Link();
$irow = 0; $irow = 0;
if ($id_category = (int)(Tools::getValue('id_category'))) if ($id_category = (int)(Tools::getValue('id_category')))
@@ -155,7 +153,7 @@ class StatsCatalog extends Module
$totalPictures = $result1['images']; $totalPictures = $result1['images'];
$averagePictures = $total ? $totalPictures / $total : 0; $averagePictures = $total ? $totalPictures / $total : 0;
$neverBought = $this->getProductsNB((int)($cookie->id_lang)); $neverBought = $this->getProductsNB($context->language->id);
$totalNB = $neverBought['total']; $totalNB = $neverBought['total'];
$productsNB = $neverBought['result']; $productsNB = $neverBought['result'];
@@ -189,7 +187,7 @@ class StatsCatalog extends Module
<div class="clear space"></div> <div class="clear space"></div>
<table> <table>
'.$this->returnLine($this->l('Products available:'), (int)($total)).' '.$this->returnLine($this->l('Products available:'), (int)($total)).'
'.$this->returnLine($this->l('Average price (base price):'), Tools::displayPrice($averagePrice, $currency)).' '.$this->returnLine($this->l('Average price (base price):'), Tools::displayPrice($averagePrice, $context->currency)).'
'.$this->returnLine($this->l('Product pages viewed:'), (int)($totalPageViewed)).' '.$this->returnLine($this->l('Product pages viewed:'), (int)($totalPageViewed)).'
'.$this->returnLine($this->l('Products bought:'), (int)($totalBought)).' '.$this->returnLine($this->l('Products bought:'), (int)($totalBought)).'
'.$this->returnLine($this->l('Average number of page visits:'), number_format((float)($averageViewed), 2, '.', '')).' '.$this->returnLine($this->l('Average number of page visits:'), number_format((float)($averageViewed), 2, '.', '')).'
@@ -219,7 +217,7 @@ class StatsCatalog extends Module
<td style="width: 400px;">'.$product['name'].'</td> <td style="width: 400px;">'.$product['name'].'</td>
<td style="text-align: right"> <td style="text-align: right">
<a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&addproduct&token='.$productToken.'" target="_blank"><img src="../modules/'.$this->name.'/page_edit.png" /></a> <a href="index.php?tab=AdminCatalog&id_product='.$product['id_product'].'&addproduct&token='.$productToken.'" target="_blank"><img src="../modules/'.$this->name.'/page_edit.png" /></a>
<a href="'.$link->getProductLink($product['id_product'], $product['link_rewrite']).'" target="_blank"><img src="../modules/'.$this->name.'/application_home.png" /></a> <a href="'.$context->link->getProductLink($product['id_product'], $product['link_rewrite']).'" target="_blank"><img src="../modules/'.$this->name.'/application_home.png" /></a>
</td> </td>
</tr>'; </tr>';
$html .= ' $html .= '