* @copyright 2007-2012 PrestaShop SA * @version Release: $Revision: 7307 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class Pagesnotfound extends Module { private $_html = ''; public function __construct() { $this->name = 'pagesnotfound'; $this->tab = 'analytics_stats'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Pages not found'); $this->description = $this->l('Display the pages requested by your visitors but not found.'); } public function install() { if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('AdminStatsModules')) return false; return Db::getInstance()->execute(' CREATE TABLE `'._DB_PREFIX_.'pagenotfound` ( id_pagenotfound INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, id_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\', id_shop_group INTEGER UNSIGNED NOT NULL DEFAULT \'1\', request_uri VARCHAR(256) NOT NULL, http_referer VARCHAR(256) NOT NULL, date_add DATETIME NOT NULL, PRIMARY KEY(id_pagenotfound), INDEX (`date_add`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); } public function uninstall() { return (parent::uninstall() && Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'pagenotfound`')); } private function getPages() { $sql = 'SELECT http_referer, request_uri, COUNT(*) as nb FROM `'._DB_PREFIX_.'pagenotfound` WHERE date_add BETWEEN '.ModuleGraph::getDateBetween() .Shop::addSqlRestriction(). 'GROUP BY http_referer, request_uri'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $pages = array(); foreach ($result as $row) { $row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST).parse_url($row['http_referer'], PHP_URL_PATH); if (!isset($row['http_referer']) || empty($row['http_referer'])) $row['http_referer'] = '--'; if (!isset($pages[$row['request_uri']])) $pages[$row['request_uri']] = array('nb' => 0); $pages[$row['request_uri']][$row['http_referer']] = $row['nb']; $pages[$row['request_uri']]['nb'] += $row['nb']; } uasort($pages, 'pnfSort'); return $pages; } public function hookAdminStatsModules() { if (Tools::isSubmit('submitTruncatePNF')) { Db::getInstance()->execute('TRUNCATE `'._DB_PREFIX_.'pagenotfound`'); $this->_html .= '
| '.$this->l('Page').' | '.$this->l('Referrer').' | '.$this->l('Counter').' |
|---|---|---|
| '.wordwrap($ru, 30, ' ', true).' |
'.wordwrap($hr, 40, ' ', true).' |
'.$counter.' |
'.$this->l('A 404 error is an HTTP error code which means that the file requested by the user cannot be found. In your case it means that one of your visitors entered a wrong URL in the address bar or that you or another website has a dead link. When it is available, the referrer is shown so you can find the page which contains the dead link. If not, it means generally that it is a direct access, so someone may have bookmarked a link which doesn\'t exist anymore.').'
'.$this->l('If your webhost supports the .htaccess file, you can create it in the root directory of PrestaShop and insert the following line inside:').' ErrorDocument 404 '.__PS_BASE_URI__.'404.php. '. $this->l('A user requesting a page which doesn\'t exist will be redirected to the page.').' '.__PS_BASE_URI__.'404.php. '. $this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.').'