From 55ee922b165072303f0dfe2622bacc22fef49dac Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Wed, 27 Jul 2011 09:01:00 +0000 Subject: [PATCH] // Context part 22 --- classes/CMSCategory.php | 16 +++++++++------- classes/Connection.php | 12 ++++++------ classes/ConnectionsSource.php | 10 +++++----- classes/Contact.php | 8 ++++---- classes/Country.php | 17 ++++++++++------- classes/Customer.php | 32 ++++++++++++++++---------------- 6 files changed, 50 insertions(+), 45 deletions(-) diff --git a/classes/CMSCategory.php b/classes/CMSCategory.php index 2c33273e3..af7c5846a 100644 --- a/classes/CMSCategory.php +++ b/classes/CMSCategory.php @@ -177,12 +177,14 @@ class CMSCategoryCore extends ObjectModel ); } - static public function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, Context $context = null) + static public function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, Link $link = null, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); - - $id_lang = is_null($id_lang) ? $context->language->id : (int)$id_lang; + if (!$link) + $link = Context::getContext()->link; + if (!$shop) + $shop = Context::getContext()->shop; + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; $sql = 'SELECT c.`id_cms_category`, c.`id_parent`, c.`level_depth`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms_category` c @@ -201,7 +203,7 @@ class CMSCategoryCore extends ObjectModel $sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms` c - '.$context->shop->sqlAsso('cms', 'c', false).' + '.$shop->sqlAsso('cms', 'c', false).' JOIN `'._DB_PREFIX_.'cms_lang` cl ON c.`id_cms` = cl.`id_cms` WHERE `id_cms_category` = '.(int)$current.' AND cl.`id_lang` = '.$id_lang.($active ? ' AND c.`active` = 1' : '').' @@ -211,7 +213,7 @@ class CMSCategoryCore extends ObjectModel { $category['link'] = $context->link->getCMSCategoryLink($current, $category['link_rewrite']); foreach($category['cms'] as $key => $cms) - $category['cms'][$key]['link'] = $context->link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); + $category['cms'][$key]['link'] = $link->getCMSLink($cms['id_cms'], $cms['link_rewrite']); } return $category; } diff --git a/classes/Connection.php b/classes/Connection.php index 9fd7031cf..e11d9c6f4 100644 --- a/classes/Connection.php +++ b/classes/Connection.php @@ -91,11 +91,11 @@ class ConnectionCore extends ObjectModel 'time_start' => $time_start); } - public static function setNewConnection($cookie, Context $context = null) + public static function setNewConnection($cookie, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); - + if (!$shop) + $shop = Context::getContext()->shop; + if (isset($_SERVER['HTTP_USER_AGENT']) AND preg_match('/BotLink|ahoy|AlkalineBOT|anthill|appie|arale|araneo|AraybOt|ariadne|arks|ATN_Worldwide|Atomz|bbot|Bjaaland|Ukonline|borg\-bot\/0\.9|boxseabot|bspider|calif|christcrawler|CMC\/0\.01|combine|confuzzledbot|CoolBot|cosmos|Internet Cruiser Robot|cusco|cyberspyder|cydralspider|desertrealm, desert realm|digger|DIIbot|grabber|downloadexpress|DragonBot|dwcp|ecollector|ebiness|elfinbot|esculapio|esther|fastcrawler|FDSE|FELIX IDE|ESI|fido|H�m�h�kki|KIT\-Fireball|fouineur|Freecrawl|gammaSpider|gazz|gcreep|golem|googlebot|griffon|Gromit|gulliver|gulper|hambot|havIndex|hotwired|htdig|iajabot|INGRID\/0\.1|Informant|InfoSpiders|inspectorwww|irobot|Iron33|JBot|jcrawler|Teoma|Jeeves|jobo|image\.kapsi\.net|KDD\-Explorer|ko_yappo_robot|label\-grabber|larbin|legs|Linkidator|linkwalker|Lockon|logo_gif_crawler|marvin|mattie|mediafox|MerzScope|NEC\-MeshExplorer|MindCrawler|udmsearch|moget|Motor|msnbot|muncher|muninn|MuscatFerret|MwdSearch|sharp\-info\-agent|WebMechanic|NetScoop|newscan\-online|ObjectsSearch|Occam|Orbsearch\/1\.0|packrat|pageboy|ParaSite|patric|pegasus|perlcrawler|phpdig|piltdownman|Pimptrain|pjspider|PlumtreeWebAccessor|PortalBSpider|psbot|Getterrobo\-Plus|Raven|RHCS|RixBot|roadrunner|Robbie|robi|RoboCrawl|robofox|Scooter|Search\-AU|searchprocess|Senrigan|Shagseeker|sift|SimBot|Site Valet|skymob|SLCrawler\/2\.0|slurp|ESI|snooper|solbot|speedy|spider_monkey|SpiderBot\/1\.0|spiderline|nil|suke|http:\/\/www\.sygol\.com|tach_bw|TechBOT|templeton|titin|topiclink|UdmSearch|urlck|Valkyrie libwww\-perl|verticrawl|Victoria|void\-bot|Voyager|VWbot_K|crawlpaper|wapspider|WebBandit\/1\.0|webcatcher|T\-H\-U\-N\-D\-E\-R\-S\-T\-O\-N\-E|WebMoose|webquest|webreaper|webs|webspider|WebWalker|wget|winona|whowhere|wlm|WOLP|WWWC|none|XGET|Nederland\.zoek/i', $_SERVER['HTTP_USER_AGENT'])) { @@ -103,7 +103,7 @@ class ConnectionCore extends ObjectModel $sql = 'SELECT `id_connections` FROM `'._DB_PREFIX_.'connections` WHERE ip_address = '.ip2long(Tools::getRemoteAddr()).' AND DATE_ADD(`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\' - '.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER).' + '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER).' ORDER BY `date_add` DESC'; if ($id_connections = Db::getInstance()->getValue($sql)) { @@ -117,7 +117,7 @@ class ConnectionCore extends ObjectModel FROM `'._DB_PREFIX_.'connections` WHERE `id_guest` = '.(int)($cookie->id_guest).' AND DATE_ADD(`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\' - '.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER).' + '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER).' ORDER BY `date_add` DESC'; $result = Db::getInstance()->getRow($sql); if (!$result['id_guest'] AND (int)($cookie->id_guest)) diff --git a/classes/ConnectionsSource.php b/classes/ConnectionsSource.php index d6e64a51b..7f824f589 100644 --- a/classes/ConnectionsSource.php +++ b/classes/ConnectionsSource.php @@ -59,11 +59,11 @@ class ConnectionsSourceCore extends ObjectModel return $result; } - public static function logHttpReferer(Context $context = null) + public static function logHttpReferer(Cookie $cookie = null) { - if (!$context) - $context = Context::getContext(); - if (!isset($context->cookie->id_connections) OR !Validate::isUnsignedId($context->cookie->id_connections)) + if (!$cookie) + $cookie = Context::getContext()->cookie; + if (!isset($cookie->id_connections) OR !Validate::isUnsignedId($cookie->id_connections)) return false; if (!isset($_SERVER['HTTP_REFERER']) AND !Configuration::get('TRACKING_DIRECT_TRAFFIC')) return false; @@ -85,7 +85,7 @@ class ConnectionsSourceCore extends ObjectModel } } - $source->id_connections = (int)$context->cookie->id_connections; + $source->id_connections = (int)$cookie->id_connections; $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REDIRECT_URL'])) $source->request_uri .= strval($_SERVER['REDIRECT_URL']); diff --git a/classes/Contact.php b/classes/Contact.php index bc11e41b8..a873c0662 100644 --- a/classes/Contact.php +++ b/classes/Contact.php @@ -76,14 +76,14 @@ class ContactCore extends ObjectModel * @param Context * @return array Contacts */ - static public function getContacts($id_lang, Context $context = null) + static public function getContacts($id_lang, Shop $shop = null) { - if (!$context) - $context = Context::getContext(); + if (!$shop) + $shop = Context::getContext()->shop; $sql = 'SELECT * FROM `'._DB_PREFIX_.'contact` c - '.$context->shop->sqlAsso('contact', 'c', false).' + '.$shop->sqlAsso('contact', 'c', false).' LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (c.`id_contact` = cl.`id_contact`) WHERE cl.`id_lang` = '.(int)$id_lang.' ORDER BY `name` ASC'; diff --git a/classes/Country.php b/classes/Country.php index 9474ce345..772d585ca 100644 --- a/classes/Country.php +++ b/classes/Country.php @@ -118,14 +118,14 @@ class CountryCore extends ObjectModel * @param boolean $active return only active coutries * @return array Countries and corresponding zones */ - static public function getCountries($id_lang, $active = false, $containStates = NULL, Context $context = null) + static public function getCountries($id_lang, $active = false, $containStates = NULL, Shop $shop = null) { if (!Validate::isBool($active)) die(Tools::displayError()); - if (!$context) - $context = Context::getContext(); - + if (!$shop) + $shop = Context::getContext()->shop; + $states = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT s.* FROM `'._DB_PREFIX_.'state` s @@ -133,7 +133,7 @@ class CountryCore extends ObjectModel $sql = 'SELECT cl.*,c.*, cl.`name` AS country, z.`name` AS zone FROM `'._DB_PREFIX_.'country` c - '.$context->shop->sqlAsso('country', 'c', false).' + '.$shop->sqlAsso('country', 'c', false).' LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'zone` z ON z.`id_zone` = c.`id_zone` WHERE 1' @@ -291,14 +291,17 @@ class CountryCore extends ObjectModel return Context::getContext()->country->id; } - public static function getCountriesByZoneId($id_zone, $id_lang, Context $context = null) + public static function getCountriesByZoneId($id_zone, $id_lang, Shop $shop = null) { if (empty($id_zone) OR empty($id_lang)) die(Tools::displayError()); + + if (!$shop) + $shop = Context::getContext()->shop; $sql = ' SELECT DISTINCT c.*, cl.* FROM `'._DB_PREFIX_.'country` c - '.$context->shop->sqlAsso('country', 'c', false).' + '.$shop->sqlAsso('country', 'c', false).' LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_country` = c.`id_country`) LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`) WHERE (c.`id_zone` = '.(int)$id_zone.' OR s.`id_zone` = '.(int)$id_zone.') diff --git a/classes/Customer.php b/classes/Customer.php index 944787c28..773e52c31 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -204,15 +204,14 @@ class CustomerCore extends ObjectModel * * @return array Customers */ - static public function getCustomers(Context $context = null) + static public function getCustomers(Shop $shop = null) { - if (!$context) - $context = Context::getContext(); - + if (!$shop) + $shop = Context::getContext()->shop; + $sql = 'SELECT `id_customer`, `email`, `firstname`, `lastname` FROM `'._DB_PREFIX_.'customer` - WHERE 1 - '.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER).' + WHERE 1 '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER).' ORDER BY `id_customer` ASC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql); } @@ -224,19 +223,19 @@ class CustomerCore extends ObjectModel * @param string $passwd Password is also checked if specified * @return Customer instance */ - public function getByEmail($email, $passwd = NULL, Context $context = null) + public function getByEmail($email, $passwd = NULL, Shop $shop = null) { if (!Validate::isEmail($email) OR ($passwd AND !Validate::isPasswd($passwd))) die (Tools::displayError()); - - if (!$context) - $context = Context::getContext(); + + if (!$shop) + $shop = Context::getContext()->shop; $sql = 'SELECT * FROM `'._DB_PREFIX_ .'customer` WHERE `active` = 1 AND `email` = \''.pSQL($email).'\' - '.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER).' + '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER).' '.(isset($passwd) ? 'AND `passwd` = \''.md5(_COOKIE_KEY_.$passwd).'\'' : '').' AND `deleted` = 0 AND `is_guest` = 0'; @@ -280,18 +279,18 @@ class CustomerCore extends ObjectModel * @param $ignoreGuest boolean, for exclure guest customer * @return Customer ID if found, false otherwise */ - static public function customerExists($email, $return_id = false, $ignoreGuest = true, Context $context = null) + static public function customerExists($email, $return_id = false, $ignoreGuest = true, Shop $shop = null) { if (!Validate::isEmail($email)) die (Tools::displayError()); - if (!$context) - $context = Context::getContext(); - + if (!$shop) + $shop = Context::getContext()->shop; + $sql = 'SELECT `id_customer` FROM `'._DB_PREFIX_.'customer` WHERE `email` = \''.pSQL($email).'\' - '.$context->shop->sqlRestriction(Shop::SHARE_CUSTOMER). + '.$shop->sqlRestriction(Shop::SHARE_CUSTOMER). ($ignoreGuest ? 'AND `is_guest` = 0' : ''); $result = Db::getInstance()->getRow($sql); @@ -367,6 +366,7 @@ class CustomerCore extends ObjectModel /** * Returns customer last connections * + * @deprecated * @param integer $nb Number of connections wanted * @return array Connections */