public static function logHttpReferer() { global $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; } $source = new ConnectionsSource(); if (isset($_SERVER['HTTP_REFERER']) and Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { if (preg_replace('/^www./', '', parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) and !strncmp(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH), parse_url('http://' . Tools::getHttpHost(false, false) . __PS_BASE_URI__, PHP_URL_PATH), strlen(__PS_BASE_URI__))) { return false; } if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER']))) { $source->http_referer = strval($_SERVER['HTTP_REFERER']); $source->keywords = trim(SearchEngine::getKeywords(strval($_SERVER['HTTP_REFERER']))); if (!Validate::isMessage($source->keywords)) { return false; } } } $source->id_connections = intval($cookie->id_connections); $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REDIRECT_URL'])) { $source->request_uri .= strval($_SERVER['REDIRECT_URL']); } elseif (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= strval($_SERVER['REQUEST_URI']); } if (!Validate::isUrl($source->request_uri)) { unset($source->request_uri); } return $source->add(); }
public static function setNewConnection($cookie) { // The old connections details are removed from the database in order to spare some memory Connection::cleanConnectionsPages(); // A new connection is created if the guest made no actions during 30 minutes $result = Db::getInstance()->getRow(' SELECT c.`id_guest` FROM `' . _DB_PREFIX_ . 'connections` c LEFT JOIN `' . _DB_PREFIX_ . 'connections_page` cp ON c.`id_connections` = cp.`id_connections` WHERE c.`id_guest` = ' . intval($cookie->id_guest) . ' AND DATE_ADD(cp.`time_start`, INTERVAL 30 MINUTE) > \'' . pSQL(date('Y-m-d H:i:s')) . '\' ORDER BY cp.`time_start` DESC'); if (!$result['id_guest'] and intval($cookie->id_guest)) { $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (preg_replace('/^www./', '', parse_url($referer, PHP_URL_HOST)) == preg_replace('/^www./', '', $_SERVER['HTTP_HOST'])) { $referer = ''; } $connection = new Connection(); $connection->id_guest = intval($cookie->id_guest); $connection->id_page = Page::getCurrentId(); $connection->ip_address = isset($_SERVER['REMOTE_ADDR']) ? ip2long($_SERVER['REMOTE_ADDR']) : ''; if (Validate::isAbsoluteUrl($referer)) { $connection->http_referer = $referer; } $connection->add(); $cookie->id_connections = $connection->id; return $connection->id_page; } }
function update_carrier_url() { // Get all carriers $sql = ' SELECT c.`id_carrier`, c.`url` FROM `' . _DB_PREFIX_ . 'carrier` c'; $carriers = Db::getInstance()->ExecuteS($sql); // Check each one and erase carrier URL if not correct URL foreach ($carriers as $carrier) { if (!Validate::isAbsoluteUrl($carrier['url'])) { Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'carrier` SET `url` = \'\' WHERE `id_carrier`= ' . (int) $carrier['id_carrier']); } } }
public function getContent() { $output = '<h2>' . $this->displayName . '</h2>'; if (Tools::isSubmit('submitBlockRss')) { $errors = array(); $urlfeed = Tools::getValue('urlfeed'); $title = Tools::getValue('title'); $nbr = (int) Tools::getValue('nbr'); if ($urlfeed and !Validate::isAbsoluteUrl($urlfeed)) { $errors[] = $this->l('Invalid feed URL'); } elseif (!$title or empty($title) or !Validate::isGenericName($title)) { $errors[] = $this->l('Invalid title'); } elseif (!$nbr or $nbr <= 0 or !Validate::isInt($nbr)) { $errors[] = $this->l('Invalid number of feeds'); } elseif (stristr($urlfeed, $_SERVER['HTTP_HOST'] . __PS_BASE_URI__)) { $errors[] = $this->l('You have selected a feed URL on your own website. Please choose another URL'); } elseif (!($contents = Tools::file_get_contents($urlfeed))) { $errors[] = $this->l('Feed is unreachable, check your URL'); } else { try { $xmlFeed = new XML_Feed_Parser($contents); } catch (XML_Feed_Parser_Exception $e) { $errors[] = $this->l('Invalid feed:') . ' ' . $e->getMessage(); } } if (!sizeof($errors)) { Configuration::updateValue('RSS_FEED_URL', $urlfeed); Configuration::updateValue('RSS_FEED_TITLE', $title); Configuration::updateValue('RSS_FEED_NBR', $nbr); $output .= $this->displayConfirmation($this->l('Settings updated')); } else { $output .= $this->displayError(implode('<br />', $errors)); } } else { $errors = array(); if (stristr(Configuration::get('RSS_FEED_URL'), $_SERVER['HTTP_HOST'] . __PS_BASE_URI__)) { $errors[] = $this->l('You have selected a feed URL on your own website. Please choose another URL'); } if (sizeof($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } } return $output . $this->displayForm(); }
public static function logHttpReferer(Cookie $cookie = null) { if (!$cookie) { $cookie = Context::getContext()->cookie; } if (!isset($cookie->id_connections) || !Validate::isUnsignedId($cookie->id_connections)) { return false; } // If the referrer is not correct, we drop the connection if (isset($_SERVER['HTTP_REFERER']) && !Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { return false; } // If there is no referrer and we do not want to save direct traffic (as opposed to referral traffic), we drop the connection if (!isset($_SERVER['HTTP_REFERER']) && !Configuration::get('TRACKING_DIRECT_TRAFFIC')) { return false; } $source = new ConnectionsSource(); // There are a few more operations if there is a referrer if (isset($_SERVER['HTTP_REFERER'])) { // If the referrer is internal (i.e. from your own website), then we drop the connection $parsed = parse_url($_SERVER['HTTP_REFERER']); $parsed_host = parse_url(Tools::getProtocol() . Tools::getHttpHost(false, false) . __PS_BASE_URI__); if (!isset($parsed['host']) || (!isset($parsed['path']) || !isset($parsed_host['path']))) { return false; } if (preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) && !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__))) { return false; } $source->http_referer = substr($_SERVER['HTTP_REFERER'], 0, ConnectionsSource::$uri_max_size); $source->keywords = substr(trim(SearchEngine::getKeywords($_SERVER['HTTP_REFERER'])), 0, ConnectionsSource::$uri_max_size); } $source->id_connections = (int) $cookie->id_connections; $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= $_SERVER['REQUEST_URI']; } elseif (isset($_SERVER['REDIRECT_URL'])) { $source->request_uri .= $_SERVER['REDIRECT_URL']; } if (!Validate::isUrl($source->request_uri)) { $source->request_uri = ''; } $source->request_uri = substr($source->request_uri, 0, ConnectionsSource::$uri_max_size); return $source->add(); }
public static function logHttpReferer(Cookie $cookie = null) { if (!$cookie) { $cookie = Context::getContext()->cookie; } if (!isset($cookie->id_connections) || !Validate::isUnsignedId($cookie->id_connections)) { return false; } if (!isset($_SERVER['HTTP_REFERER']) && !Configuration::get('TRACKING_DIRECT_TRAFFIC')) { return false; } $source = new ConnectionsSource(); if (isset($_SERVER['HTTP_REFERER']) && Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { $parsed = parse_url($_SERVER['HTTP_REFERER']); $parsed_host = parse_url(Tools::getProtocol() . Tools::getHttpHost(false, false) . __PS_BASE_URI__); if (preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) && !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__))) { return false; } if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER']))) { $source->http_referer = substr(strval($_SERVER['HTTP_REFERER']), 0, ConnectionsSource::$uri_max_size); $source->keywords = trim(SearchEngine::getKeywords(strval($_SERVER['HTTP_REFERER']))); if (!Validate::isMessage($source->keywords)) { return false; } } } $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']); } elseif (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= strval($_SERVER['REQUEST_URI']); } if (!Validate::isUrl($source->request_uri)) { $source->request_uri = ''; } $source->request_uri = substr($source->request_uri, 0, ConnectionsSource::$uri_max_size); return $source->add(); }
/** * 下载文件保存到指定位置 * * @param $url * @param $filepath * * @return bool */ public static function saveFile($url, $filepath) { if (Validate::isAbsoluteUrl($url) && !empty($filepath)) { $file = self::file_get_contents($url); $fp = @fopen($filepath, 'w'); if ($fp) { @fwrite($fp, $file); @fclose($fp); return $filepath; } } return false; }
/** * Adds a media file(s) (CSS, JS) to page header * * @param string|array $media_uri Path to file, or an array of paths like: array(array(uri => media_type), ...) * @param string|null $css_media_type CSS media type * @param int|null $offset * @param bool $remove If True, removes media files * @param bool $check_path If true, checks if files exists * @return true|void */ public function addMedia($media_uri, $css_media_type = null, $offset = null, $remove = false, $check_path = true) { if (!is_array($media_uri)) { if ($css_media_type) { $media_uri = array($media_uri => $css_media_type); } else { $media_uri = array($media_uri); } } $list_uri = array(); foreach ($media_uri as $file => $media) { if (!Validate::isAbsoluteUrl($media)) { $different = 0; $different_css = 0; $type = 'css'; if (!$css_media_type) { $type = 'js'; $file = $media; } if (strpos($file, __PS_BASE_URI__ . 'modules/') === 0) { $override_path = str_replace(__PS_BASE_URI__ . 'modules/', _PS_ROOT_DIR_ . '/themes/' . _THEME_NAME_ . '/' . $type . '/modules/', $file, $different); if (strrpos($override_path, $type . '/' . basename($file)) !== false) { $override_path_css = str_replace($type . '/' . basename($file), basename($file), $override_path, $different_css); } if ($different && @filemtime($override_path)) { $file = str_replace(__PS_BASE_URI__ . 'modules/', __PS_BASE_URI__ . 'themes/' . _THEME_NAME_ . '/' . $type . '/modules/', $file, $different); } elseif ($different_css && @filemtime($override_path_css)) { $file = $override_path_css; } if ($css_media_type) { $list_uri[$file] = $media; } else { $list_uri[] = $file; } } else { $list_uri[$file] = $media; } } else { $list_uri[$file] = $media; } } if ($remove) { if ($css_media_type) { return parent::removeCSS($list_uri, $css_media_type); } return parent::removeJS($list_uri); } if ($css_media_type) { return parent::addCSS($list_uri, $css_media_type, $offset, $check_path); } return parent::addJS($list_uri, $check_path); }
public function postProcess() { if (Tools::isSubmit('submitSettings')) { if (isset($_POST['login'])) { Configuration::updateValue('PS_TRUST_EMAIL', $_POST['email']); } if (isset($_POST['passwd'])) { Configuration::updateValue('PS_TRUST_PASSWD', $_POST['passwd']); } if ($activity = Tools::getValue('shop_activity')) { Configuration::updateValue('PS_SHOP_ACTIVITY', $activity); } $carriers_configuration = array(); $payments_configuration = array(); foreach ($_POST as $field => $val) { if (preg_match('/^carrier_([0-9]+)$/Ui', $field, $res)) { $carriers_configuration[$res[1]] = $val; } elseif (preg_match('/^paymentmodule_([0-9]+)$/Ui', $field, $pay_res)) { $payments_configuration[$pay_res[1]] = $val; } } $this->_setCarriersConfiguration($carriers_configuration); $this->_setPaymentsConfiguration($payments_configuration); } elseif (Tools::isSubmit('submitCreateAccount')) { if (!Validate::isEmail($email = Tools::getValue('email'))) { $this->_errors[] = $this->l('Email is invalid'); } if (!Validate::isAbsoluteUrl($shop_url = Tools::getValue('shop_url'))) { $this->_errors[] = $this->l('Shop URL is invalid'); } if (!count($this->_errors)) { if ($this->_createAccount($email, $shop_url)) { $this->_html .= $this->displayConfirmation('Account successfull created'); } } } if (sizeof($this->_errors)) { $err = ''; foreach ($this->_errors as $error) { $err .= $error . '<br />'; } $this->_html .= $this->displayError($err); } }
function hookTop($params) { if (strstr($_SERVER['REQUEST_URI'], '404.php') and isset($_SERVER['REDIRECT_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL']; } if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) or strstr($_SERVER['REQUEST_URI'], '-admin404')) { return; } if (strstr($_SERVER['PHP_SELF'], '404.php') and !strstr($_SERVER['REQUEST_URI'], '404.php')) { $http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (empty($http_referer) or Validate::isAbsoluteUrl($http_referer)) { Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'pagenotfound` (`request_uri`,`http_referer`,`date_add`) VALUES (\'' . pSQL($request_uri) . '\',\'' . pSQL($http_referer) . '\',NOW())'); } } }
/** * Combine Compress and Cache (ccc) JS calls * * @param array js_files * @return array processed js_files */ public static function cccJS($js_files) { //inits $compressed_js_files_not_found = array(); $js_files_infos = array(); $js_files_date = 0; $compressed_js_filename = ''; $js_external_files = array(); $protocol_link = Tools::getCurrentUrlProtocolPrefix(); $cache_path = _PS_THEME_DIR_ . 'cache/'; // get js files infos foreach ($js_files as $filename) { if (Validate::isAbsoluteUrl($filename)) { $js_external_files[] = $filename; } else { $infos = array(); $infos['uri'] = $filename; $url_data = parse_url($filename); $infos['path'] = _PS_ROOT_DIR_ . Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']); if (!@filemtime($info['path'])) { $infos['path'] = _PS_CORE_DIR_ . Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']); } $js_files_infos[] = $infos; $js_files_date = max(file_exists($infos['path']) ? @filemtime($infos['path']) : 0, $js_files_date); $compressed_js_filename .= $filename; } } // get compressed js file infos $compressed_js_filename = md5($compressed_js_filename); $version = (int) Configuration::get('PS_CCCJS_VERSION'); $compressed_js_path = $cache_path . 'v_' . $version . '_' . $compressed_js_filename . '.js'; $compressed_js_file_date = file_exists($compressed_js_path) ? @filemtime($compressed_js_path) : 0; // aggregate and compress js files content, write new caches files if ($js_files_date > $compressed_js_file_date) { if ($compressed_js_file_date) { Configuration::updateValue('PS_CCCJS_VERSION', ++$version); } $compressed_js_path = $cache_path . 'v_' . $version . '_' . $compressed_js_filename . '.js'; $content = ''; foreach ($js_files_infos as $file_infos) { if (file_exists($file_infos['path'])) { $tmp_content = file_get_contents($file_infos['path']); if (preg_match('@\\.(min|pack)\\.[^/]+$@', $file_infos['path'], $matches)) { $content .= preg_replace('/\\/\\/@\\ssourceMappingURL\\=[_a-zA-Z0-9-.]+\\.' . $matches[1] . '\\.map\\s+/', '', $tmp_content); } else { $content .= Media::packJS($tmp_content); } } else { $compressed_js_files_not_found[] = $file_infos['path']; } } if (!empty($compressed_js_files_not_found)) { $content = '/* WARNING ! file(s) not found : "' . implode(',', $compressed_js_files_not_found) . '" */' . "\n" . $content; } file_put_contents($compressed_js_path, $content); chmod($compressed_js_path, 0777); } // rebuild the original js_files array if (strpos($compressed_js_path, _PS_ROOT_DIR_) !== false) { $url = str_replace(_PS_ROOT_DIR_ . '/', __PS_BASE_URI__, $compressed_js_path); } if (strpos($compressed_js_path, _PS_CORE_DIR_) !== false) { $url = str_replace(_PS_CORE_DIR_ . '/', __PS_BASE_URI__, $compressed_js_path); } return array_merge(array($protocol_link . Tools::getMediaServer($url) . $url), $js_external_files); }
private function _createAccount() { if (!($email = Tools::getValue('email')) or !Validate::isEmail($email)) { $this->_errors[] = $this->l('Email is invalid'); } if (!($shop_url = Tools::getValue('shop_url')) or !Validate::isAbsoluteUrl($shop_url)) { $this->_errors[] = $this->l('Shop URL is invalid'); } if (sizeof($this->_errors)) { return false; } $root = new SimpleXMLElement("<?xml version=\"1.0\"?><fraud_monitor></fraud_monitor>"); $xml = $root->addChild('create_account'); $xml->addChild('email', $email); $xml->addChild('shop_url', $shop_url); $result = $this->_pushDatas($root->asXml()); if ($result == 'nok' || !($xml_result = simplexml_load_string($result))) { $this->_errors[] = $this->l('Impossible to create a new account, please report this bug on http://forge.prestashop.com/'); return false; } if (!(int) $xml_result->create_account->result) { $this->_errors[] = (string) $xml_result->create_account->errors; return false; } Configuration::updateValue('PS_TRUST_SHOP_ID', (string) $xml_result->create_account->shop_id); Configuration::updateValue('PS_TRUST_SHOP_KEY', (string) $xml_result->create_account->shop_key); $this->_html .= $this->displayConfirmation('Account successfull created'); }
private function checkPostedDatas() { $mail = Tools::getValue('email'); $website = Tools::getValue('website'); if ($mail and !preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $mail)) { $this->_html .= parent::displayError($this->l('There is an error in your e-mail syntax!')); } else { if ($website and (!Validate::isURL($website) or !Validate::isAbsoluteUrl($website))) { $this->_html .= parent::displayError($this->l('There is an error in your URL syntax!')); } else { if (!$this->checkVersionsAndCompatibility() or !$this->checkNames() or !$this->checkDocumentation()) { return false; } else { return true; } } } return false; }
public function validateBlog() { if (empty($_POST['title'])) { $this->errors[] = Tools::displayError('Title is required!'); } if (mb_strlen($_POST['short_description']) < 10) { $this->errors[] = Tools::displayError('Short description should be atleast 10 characters!'); } if (!Validate::isAbsoluteUrl($_POST['youtube'])) { $this->errors[] = Tools::displayError('Invalid URL!'); } }
public function getKeywords($url) { if (!Validate::isAbsoluteUrl($url)) { return false; } $parsedUrl = parse_url($url); if (!isset($parsedUrl['query']) && isset($parsedUrl['fragment'])) { $parsedUrl['query'] = $parsedUrl['fragment']; } if (!isset($parsedUrl['query'])) { return false; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `server`, `getvar` FROM `' . _DB_PREFIX_ . 'search_engine`'); foreach ($result as $index => $row) { $host =& $row['server']; $varname =& $row['getvar']; if (strstr($parsedUrl['host'], $host)) { $kArray = array(); preg_match('/[^a-z]' . $varname . '=.+\\&' . '/U', $parsedUrl['query'], $kArray); if (!isset($kArray[0]) || empty($kArray[0])) { preg_match('/[^a-z]' . $varname . '=.+$' . '/', $parsedUrl['query'], $kArray); } if (!isset($kArray[0]) || empty($kArray[0])) { return false; } $kString = urldecode(str_replace('+', ' ', ltrim(substr(rtrim($kArray[0], '&'), strlen($varname) + 1), '='))); return $kString; } } }
private function checkPostedDatas() { $mail = Tools::getValue('email'); $website = Tools::getValue('website'); if ($mail && !preg_match('#^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$#', $mail)) { $this->errors[] = $this->l('There is an error in your e-mail syntax!'); } elseif ($website && (!Validate::isURL($website) || !Validate::isAbsoluteUrl($website))) { $this->errors[] = $this->l('There is an error in your URL syntax!'); } elseif (!$this->checkVersionsAndCompatibility() || !$this->checkNames() || !$this->checkDocumentation()) { return false; } else { return true; } return false; }
private function _linkValidation($linkString) { if (!Validate::isAbsoluteUrl($linkString)) { $this->_postErrors[] = $this->l('Invalid URL: "' . strip_tags(nl2br2($linkString)) . '". Hint: start with http://'); } }
public static function setNewConnection($cookie) { 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'])) { // This is a bot and we have to retrieve its connection ID if ($id_connections = Db::getInstance()->getValue(' SELECT `id_connections` FROM `' . _DB_PREFIX_ . 'connections` c WHERE ip_address = ' . ip2long(Tools::getRemoteAddr()) . ' AND DATE_ADD(c.`date_add`, INTERVAL 30 MINUTE) > \'' . pSQL(date('Y-m-d H:i:00')) . '\' ORDER BY c.`date_add` DESC')) { $cookie->id_connections = (int) $id_connections; return Page::getCurrentId(); } } // A new connection is created if the guest made no actions during 30 minutes $result = Db::getInstance()->getRow(' SELECT c.`id_guest` FROM `' . _DB_PREFIX_ . 'connections` c WHERE c.`id_guest` = ' . (int) $cookie->id_guest . ' AND DATE_ADD(c.`date_add`, INTERVAL 30 MINUTE) > \'' . pSQL(date('Y-m-d H:i:00')) . '\' ORDER BY c.`date_add` DESC'); if (!$result['id_guest'] and (int) $cookie->id_guest) { // The old connections details are removed from the database in order to spare some memory Connection::cleanConnectionsPages(); $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $arrayUrl = parse_url($referer); if (!isset($arrayUrl['host']) or preg_replace('/^www./', '', $arrayUrl['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false))) { $referer = ''; } $connection = new Connection(); $connection->id_guest = (int) $cookie->id_guest; $connection->id_page = Page::getCurrentId(); $connection->ip_address = Tools::getRemoteAddr() ? ip2long(Tools::getRemoteAddr()) : ''; if (Validate::isAbsoluteUrl($referer)) { $connection->http_referer = $referer; } $connection->add(); $cookie->id_connections = $connection->id; return $connection->id_page; } }
public function hookTop($params) { if (strstr($_SERVER['REQUEST_URI'], '404.php') && isset($_SERVER['REDIRECT_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL']; } if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) || strstr($_SERVER['REQUEST_URI'], '-admin404')) { return; } if (get_class(Context::getContext()->controller) == 'PageNotFoundController') { $http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (empty($http_referer) || Validate::isAbsoluteUrl($http_referer)) { Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_shop_group`) VALUES (\'' . pSQL($request_uri) . '\', \'' . pSQL($http_referer) . '\', NOW(), ' . (int) $this->context->shop->id . ', ' . (int) $this->context->shop->id_shop_group . ') '); } } }