* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class StatsOrigin extends ModuleGraph { private $_html; function __construct() { $this->name = 'statsorigin'; $this->tab = 'analytics_stats'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Visitors origin'); $this->description = $this->l('Display the websites your visitors come from.'); } function install() { return (parent::install() AND $this->registerHook('AdminStatsModules')); } private function getOrigins($dateBetween) { $directLink = $this->l('Direct link'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT c.http_referer FROM '._DB_PREFIX_.'connections c WHERE c.date_add BETWEEN '.$dateBetween, false); $websites = array($directLink => 0); while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) { if (!isset($row['http_referer']) OR empty($row['http_referer'])) ++$websites[$directLink]; else { $website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST)); if (!isset($websites[$website])) $websites[$website] = 1; else ++$websites[$website]; } } arsort($websites); return $websites; } function hookAdminStatsModules() { $websites = $this->getOrigins(ModuleGraph::getDateBetween()); if (Tools::getValue('export')) if (Tools::getValue('exportType') == 'top') $this->csvExport(array('type' => 'pie')); $this->_html = '