[*] BO #PSFV-94 : Added AdminStatsController && AdminStatsTabController && norm of statistic modules
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10004 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -30,43 +30,43 @@ if (!defined('_PS_VERSION_'))
|
||||
|
||||
class Pagesnotfound extends Module
|
||||
{
|
||||
private $_html = '';
|
||||
private $_html = '';
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->name = 'pagesnotfound';
|
||||
$this->tab = 'analytics_stats';
|
||||
$this->version = 1.0;
|
||||
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.');
|
||||
}
|
||||
parent::__construct();
|
||||
|
||||
function install()
|
||||
$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() OR !$this->registerHook('top') OR !$this->registerHook('AdminStatsModules'))
|
||||
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_group_shop 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`)
|
||||
id_pagenotfound INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
id_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\',
|
||||
id_group_shop 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;');
|
||||
}
|
||||
|
||||
function uninstall()
|
||||
{
|
||||
return (parent::uninstall() AND Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'pagenotfound`'));
|
||||
}
|
||||
public function uninstall()
|
||||
{
|
||||
return (parent::uninstall() && Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'pagenotfound`'));
|
||||
}
|
||||
|
||||
private function getPages()
|
||||
{
|
||||
@@ -81,7 +81,7 @@ class Pagesnotfound extends Module
|
||||
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']) OR empty($row['http_referer']))
|
||||
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);
|
||||
@@ -92,14 +92,14 @@ class Pagesnotfound extends Module
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function hookAdminStatsModules()
|
||||
{
|
||||
public function hookAdminStatsModules()
|
||||
{
|
||||
if (Tools::isSubmit('submitTruncatePNF'))
|
||||
{
|
||||
Db::getInstance()->execute('TRUNCATE `'._DB_PREFIX_.'pagenotfound`');
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found has been emptied.').'</div>';
|
||||
}
|
||||
elseif (Tools::isSubmit('submitDeletePNF'))
|
||||
else if (Tools::isSubmit('submitDeletePNF'))
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'pagenotfound`
|
||||
@@ -107,12 +107,12 @@ class Pagesnotfound extends Module
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found have been deleted.').'</div>';
|
||||
}
|
||||
|
||||
$this->_html .= '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
|
||||
$this->_html .= '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
|
||||
if (!file_exists(dirname(__FILE__).'/../../.htaccess'))
|
||||
$this->_html .= '<div class="warning warn">'.$this->l('You <b>must</b> use a .htaccess file to redirect 404 errors to the page "404.php"').'</div>';
|
||||
|
||||
|
||||
$pages = $this->getPages();
|
||||
if (sizeof($pages))
|
||||
if (count($pages))
|
||||
{
|
||||
$this->_html .= '
|
||||
<table class="table" cellpadding="0" cellspacing="0">
|
||||
@@ -137,42 +137,52 @@ class Pagesnotfound extends Module
|
||||
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('No pages registered').'</div>';
|
||||
|
||||
$this->_html .= '</fieldset>';
|
||||
if (sizeof($pages))
|
||||
if (count($pages))
|
||||
$this->_html .= '<div class="clear"> </div>
|
||||
<fieldset class="width3"><legend><img src="../img/admin/delete.gif" /> '.$this->l('Empty database').'</legend>
|
||||
<fieldset><legend><img src="../img/admin/delete.gif" /> '.$this->l('Empty database').'</legend>
|
||||
<form action="'.Tools::htmlEntitiesUtf8($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<input type="submit" class="button" name="submitDeletePNF" value="'.$this->l('Empty ALL pages not found in this period').'">
|
||||
<input type="submit" class="button" name="submitTruncatePNF" value="'.$this->l('Empty ALL pages not found').'">
|
||||
</form>
|
||||
</fieldset>';
|
||||
$this->_html .= '<div class="clear"> </div>
|
||||
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
|
||||
$this->_html .= '<br />
|
||||
<fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
|
||||
<h2>'.$this->l('404 errors').'</h2>
|
||||
<p>'.$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.').'</p>
|
||||
<p>'.$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.').'</p>
|
||||
<h3>'.$this->l('How to catch these errors?').'</h3>
|
||||
<p>'.$this->l('If your webhost supports the <i>.htaccess</i> file, you can create it in the root directory of PrestaShop and insert the following line inside:').' <i>ErrorDocument 404 '.__PS_BASE_URI__.'404.php</i>. '.$this->l('A user requesting a page which doesn\'t exist will be redirected to the page.').' <i>'.__PS_BASE_URI__.'404.php</i>. '.$this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.').'</p><br />
|
||||
<p>'.$this->l('If your webhost supports the <i>.htaccess</i> file, you can create it in the root directory of PrestaShop and insert the following line inside:').'
|
||||
<i>ErrorDocument 404 '.__PS_BASE_URI__.'404.php</i>. '.
|
||||
$this->l('A user requesting a page which doesn\'t exist will be redirected to the page.').' <i>'.__PS_BASE_URI__.'404.php</i>. '.
|
||||
$this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.').'</p><br />
|
||||
</fieldset>';
|
||||
|
||||
return $this->_html;
|
||||
}
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
function hookTop($params)
|
||||
public function hookTop($params)
|
||||
{
|
||||
if (strstr($_SERVER['REQUEST_URI'], '404.php') AND isset($_SERVER['REDIRECT_URL']))
|
||||
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']) OR strstr($_SERVER['REQUEST_URI'], '-admin404'))
|
||||
if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) || strstr($_SERVER['REQUEST_URI'], '-admin404'))
|
||||
return;
|
||||
if (strstr($_SERVER['PHP_SELF'], '404.php') AND !strstr($_SERVER['REQUEST_URI'], '404.php'))
|
||||
if (strstr($_SERVER['PHP_SELF'], '404.php') && !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`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')');
|
||||
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_group_shop`)
|
||||
VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pnfSort($a, $b) {
|
||||
if ($a['nb'] == $b['nb'])
|
||||
return 0;
|
||||
return ($a['nb'] > $b['nb']) ? -1 : 1;
|
||||
function pnfSort($a, $b)
|
||||
{
|
||||
if ($a['nb'] == $b['nb'])
|
||||
return 0;
|
||||
return ($a['nb'] > $b['nb']) ? -1 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user