Merge branch 'bootstrap' of https://github.com/PrestaShop/PrestaShop into bootstrap

This commit is contained in:
Vincent Augagneur
2013-09-12 10:08:32 +02:00
36 changed files with 882 additions and 440 deletions
+57 -44
View File
@@ -79,12 +79,14 @@ class Dashactivity extends Module
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
$visits = $unique_visitors = 0;
$visits = $unique_visitors = $online_visitor = 0;
if ($result = $gapi->requestReportData('', 'ga:visits,ga:visitors', $params['date_from'], $params['date_to'], null, null, 1, 1))
{
$visits = $result[0]['metrics']['visits'];
$unique_visitors = $result[0]['metrics']['visitors'];
}
if ($result = $gapi->requestReportData('', 'ga:activeVisitors', null, null, null, null, 1, 1))
$online_visitor = $result[0]['metrics']['activeVisitors'];
}
else
{
@@ -94,6 +96,24 @@ class Dashactivity extends Module
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
'.Shop::addSqlRestriction(false));
extract($row);
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
FROM `'._DB_PREFIX_.'connections` c
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
AND cp.`time_end` IS NULL
'.Shop::addSqlRestriction(false, 'c').'
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
else
$sql = 'SELECT COUNT(*)
FROM `'._DB_PREFIX_.'connections`
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
'.Shop::addSqlRestriction(false).'
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
}
$order_nbr = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
@@ -129,25 +149,7 @@ class Dashactivity extends Module
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON ct.id_customer_thread = cm.id_customer_thread
WHERE cm.`date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
'.Shop::addSqlRestriction(false, 'ct'));
if ($maintenance_ips = Configuration::get('PS_MAINTENANCE_IP'))
$maintenance_ips = implode(',', array_map('ip2long', array_map('trim', explode(',', $maintenance_ips))));
if (Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
FROM `'._DB_PREFIX_.'connections` c
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
AND cp.`time_end` IS NULL
'.Shop::addSqlRestriction(false, 'c').'
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
else
$sql = 'SELECT COUNT(*)
FROM `'._DB_PREFIX_.'connections`
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
'.Shop::addSqlRestriction(false).'
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
$active_shopping_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'cart`
@@ -208,7 +210,7 @@ class Dashactivity extends Module
'orders_trends' => array('way' => 'down', 'value' => 0.42),
),
'data_list_small' => array(
'dash_traffic_source' => $this->getReferer($params['date_from'], $params['date_to']),
'dash_traffic_source' => $this->getReferer($params['date_from'], $params[ 'date_to']),
),
'data_chart' => array(
'dash_trends_chart1' => $this->getChartTrafficSource($params['date_from'], $params['date_to']),
@@ -228,31 +230,42 @@ class Dashactivity extends Module
public function getReferer($date_from, $date_to, $limit = 10)
{
$directLink = $this->l('Direct link');
$sql = 'SELECT http_referer
FROM '._DB_PREFIX_.'connections
WHERE 1
'.Shop::addSqlRestriction().'
AND date_add BETWEEN '.$date_from.' AND '.$date_to.'
LIMIT 0, '.(int)$limit;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
if (!isset($row['http_referer']) || 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];
}
$websites = array();
if ($result = $gapi->requestReportData('ga:source', 'ga:visitors', $date_from, $date_to, '-ga:visitors', null, 1, 3))
foreach ($result as $row)
$websites[$row['dimensions']['source']] = $row['metrics']['visitors'];
}
else
{
$directLink = $this->l('Direct link');
$sql = 'SELECT http_referer
FROM '._DB_PREFIX_.'connections
WHERE 1
'.Shop::addSqlRestriction().'
AND date_add BETWEEN '.$date_from.' AND '.$date_to.'
LIMIT 0, '.(int)$limit;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
{
if (!isset($row['http_referer']) || 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);
}
arsort($websites);
return $websites;
}
+1 -1
View File
@@ -93,7 +93,7 @@ class Dashtrends extends Module
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
{
if ($result = $gapi->requestReportData('ga:date', 'ga:visits', $params['date_from'], $params['date_to'], null, null, 1, 1))
if ($result = $gapi->requestReportData('ga:date', 'ga:visits', $params['date_from'], $params['date_to'], null, null, 1, 9999))
foreach ($result as $row)
$tmp_data['visits_score'][strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-$3', $row['dimensions']['date']))] = $row['metrics']['visits'];
}
+22 -21
View File
@@ -29,8 +29,8 @@ if (!defined('_PS_VERSION_'))
class Gapi extends Module
{
public function __construct($type = null)
{
public function __construct()
{
$this->name = 'gapi';
$this->tab = 'administration';
$this->version = 0.9;
@@ -40,8 +40,8 @@ class Gapi extends Module
parent::__construct();
$this->displayName = $this->l('Google Analytics API');
}
}
public function isConfigured()
{
return ($this->active && $this->api_3_0_isConfigured());
@@ -64,7 +64,7 @@ class Gapi extends Module
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('You are not allowed to open external URLs').'</li>').'
'.(($curl && $allow_url_fopen) ? '' : '<li>'.$this->l('cURL is not enabled').'</li>').'
'.($openssl ? '' : '<li>'.$this->l('OpenSSL is not enabled').'</li>').'
'.(($allow_url_fopen AND $openssl AND !$ping) ? '<li>'.$this->l('Google is unreachable').' ('.$this->l('check your firewall').')</li>' : '').'
'.(($allow_url_fopen && $openssl && !$ping) ? '<li>'.$this->l('Google is unreachable').' ('.$this->l('check your firewall').')</li>' : '').'
'.($online ? '' : '<li>'.$this->l('Your store is not online').'</li>').'
</ul>');
}
@@ -73,7 +73,7 @@ class Gapi extends Module
return $html.$this->api_3_0_getContent();
}
public function requestReportData($dimensions, $metrics, $date_from, $date_to, $sort = null, $filters = null, $start = 1, $limit = 30)
public function requestReportData($dimensions, $metrics, $date_from = null, $date_to = null, $sort = null, $filters = null, $start = 1, $limit = 30)
{
// You can switch to the 1.3 API by replacing the following function call by $this->api_1_3_requestReportData()
return $this->api_3_0_requestReportData($dimensions, $metrics, $date_from, $date_to, $sort, $filters, $start, $limit);
@@ -93,7 +93,7 @@ class Gapi extends Module
);
Tools::redirectLink('https://accounts.google.com/o/oauth2/auth?'.http_build_query($params));
}
public function api_3_0_refreshtoken()
{
$params = array(
@@ -179,7 +179,7 @@ class Gapi extends Module
$html .= $this->displayConfirmation(sprintf($this->l('Yesterday, your store received the visit of %d people for a total of %d unique page views.'), $result_test[0]['metrics']['visits'], $result_test[0]['metrics']['uniquePageviews']));
}
}
if ($display_slider)
{
$slides = array(
@@ -195,7 +195,7 @@ class Gapi extends Module
'Google API - 10 - Profile ID.png' => $this->l('Now you need the ID of the Analytics Profile you want to connect. In order to find you Profile ID, connect to the Analytics dashboard look at the URL in the address bar. Your Profile ID is the number following a "p", as shown underlined in red on the screenshot')
);
$first_slide = key($slides);
$html .= '
<a id="screenshots_button" href="#screenshots"><button class="btn btn-default"><i class="icon-question-sign"></i> How to configure Google Analytics API</button></a>
<div style="display:none">
@@ -264,7 +264,7 @@ class Gapi extends Module
return $html.$helper->generateOptions($fields_options);
}
public function api_3_0_oauth2callback()
{
if (!Tools::getValue('state'))
@@ -326,9 +326,10 @@ class Gapi extends Module
'timeout' => 5,
)
));
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/ga?'.$content, false, $stream_context))
$api = ($date_from && $date_to) ? 'ga' : 'realtime';
if (!$response_json = Tools::file_get_contents('https://www.googleapis.com/analytics/v3/data/'.$api.'?'.$content, false, $stream_context))
return false;
// https://developers.google.com/analytics/devguides/reporting/core/v3/reference
$response = Tools::jsonDecode($response_json, true);
@@ -337,7 +338,7 @@ class Gapi extends Module
{
$metrics = array();
$dimensions = array();
foreach($row as $key => $value)
foreach ($row as $key => $value)
if ($response['columnHeaders'][$key]['columnType'] == 'DIMENSION')
$dimensions[str_replace('ga:', '', $response['columnHeaders'][$key]['name'])] = $value;
elseif ($response['columnHeaders'][$key]['columnType'] == 'METRIC')
@@ -351,7 +352,7 @@ class Gapi extends Module
{
return (Configuration::get('PS_GAPI13_EMAIL') && Configuration::get('PS_GAPI13_PASSWORD') && Configuration::get('PS_GAPI13_PROFILE'));
}
public function api_1_3_getContent()
{
$html = '';
@@ -448,17 +449,17 @@ class Gapi extends Module
if ($filters !== null)
$params['filters'] = $filters;
$content = str_replace('&amp;', '&', urldecode(http_build_query($params)));
$stream_context = stream_context_create(array(
'http' => array(
'method'=> 'GET',
'header' => "Authorization: GoogleLogin auth=".$this->auth_token."\r\n",
'header' => 'Authorization: GoogleLogin auth='.$this->auth_token."\r\n",
'timeout' => 5,
)
));
if (!$response = Tools::file_get_contents('https://www.google.com/analytics/feeds/data?'.$content, false, $stream_context))
return false;
$xml = simplexml_load_string($response);
/* Meta data not useful at this time */
@@ -485,21 +486,21 @@ class Gapi extends Module
$metrics = array();
foreach ($entry->children('http://schemas.google.com/analytics/2009')->metric as $metric)
{
$key = str_replace('ga:','',$metric->attributes()->name);
$key = str_replace('ga:', '', $metric->attributes()->name);
$metric_value = strval($metric->attributes()->value);
if (preg_match('/^(\d+\.\d+)|(\d+E\d+)|(\d+.\d+E\d+)$/',$metric_value))
if (preg_match('/^(\d+\.\d+)|(\d+E\d+)|(\d+.\d+E\d+)$/', $metric_value))
$metrics[$key] = floatval($metric_value);
else
$metrics[$key] = intval($metric_value);
}
$dimensions = array();
foreach($entry->children('http://schemas.google.com/analytics/2009')->dimension as $dimension)
foreach ($entry->children('http://schemas.google.com/analytics/2009')->dimension as $dimension)
$dimensions[str_replace('ga:', '', $dimension->attributes()->name)] = strval($dimension->attributes()->value);
$result[] = array('metrics' => $metrics, 'dimensions' => $dimensions);
}
return $result;
}
}
+24
View File
@@ -1,4 +1,28 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/gapi.php');