add icons for Character groups
This commit is contained in:
commit
2d9a41a5fe
3461 changed files with 594457 additions and 0 deletions
40
www/analytics/plugins/Provider/API.php
Normal file
40
www/analytics/plugins/Provider/API.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\Provider;
|
||||
|
||||
use Piwik\Archive;
|
||||
use Piwik\Metrics;
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* @see plugins/Provider/functions.php
|
||||
*/
|
||||
require_once PIWIK_INCLUDE_PATH . '/plugins/Provider/functions.php';
|
||||
|
||||
/**
|
||||
* The Provider API lets you access reports for your visitors Internet Providers.
|
||||
*
|
||||
* @method static \Piwik\Plugins\Provider\API getInstance()
|
||||
*/
|
||||
class API extends \Piwik\Plugin\API
|
||||
{
|
||||
public function getProvider($idSite, $period, $date, $segment = false)
|
||||
{
|
||||
Piwik::checkUserHasViewAccess($idSite);
|
||||
$archive = Archive::build($idSite, $period, $date, $segment);
|
||||
$dataTable = $archive->getDataTable(Archiver::PROVIDER_RECORD_NAME);
|
||||
$dataTable->filter('Sort', array(Metrics::INDEX_NB_VISITS));
|
||||
$dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', __NAMESPACE__ . '\getHostnameUrl'));
|
||||
$dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPrettyProviderName'));
|
||||
$dataTable->queueFilter('ReplaceColumnNames');
|
||||
$dataTable->queueFilter('ReplaceSummaryRowLabel');
|
||||
return $dataTable;
|
||||
}
|
||||
}
|
||||
|
||||
29
www/analytics/plugins/Provider/Archiver.php
Normal file
29
www/analytics/plugins/Provider/Archiver.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\Provider;
|
||||
|
||||
use Piwik\Metrics;
|
||||
|
||||
class Archiver extends \Piwik\Plugin\Archiver
|
||||
{
|
||||
const PROVIDER_RECORD_NAME = 'Provider_hostnameExt';
|
||||
const PROVIDER_FIELD = "location_provider";
|
||||
|
||||
public function aggregateDayReport()
|
||||
{
|
||||
$metrics = $this->getLogAggregator()->getMetricsFromVisitByDimension(self::PROVIDER_FIELD)->asDataTable();
|
||||
$report = $metrics->getSerialized($this->maximumRows, null, Metrics::INDEX_NB_VISITS);
|
||||
$this->getProcessor()->insertBlobRecord(self::PROVIDER_RECORD_NAME, $report);
|
||||
}
|
||||
|
||||
public function aggregateMultipleReports()
|
||||
{
|
||||
$this->getProcessor()->aggregateDataTableRecords(array(self::PROVIDER_RECORD_NAME), $this->maximumRows);
|
||||
}
|
||||
}
|
||||
27
www/analytics/plugins/Provider/Controller.php
Normal file
27
www/analytics/plugins/Provider/Controller.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\Provider;
|
||||
|
||||
use Piwik\ViewDataTable\Factory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Controller extends \Piwik\Plugin\Controller
|
||||
{
|
||||
/**
|
||||
* Provider
|
||||
* @return string|void
|
||||
*/
|
||||
public function getProvider()
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
236
www/analytics/plugins/Provider/Provider.php
Normal file
236
www/analytics/plugins/Provider/Provider.php
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\Provider;
|
||||
|
||||
use Exception;
|
||||
use Piwik\ArchiveProcessor;
|
||||
use Piwik\Common;
|
||||
use Piwik\Config;
|
||||
|
||||
use Piwik\Db;
|
||||
use Piwik\FrontController;
|
||||
use Piwik\IP;
|
||||
use Piwik\Menu\MenuMain;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ViewDataTable;
|
||||
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig;
|
||||
use Piwik\WidgetsList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Provider extends \Piwik\Plugin
|
||||
{
|
||||
/**
|
||||
* @see Piwik\Plugin::getListHooksRegistered
|
||||
*/
|
||||
public function getListHooksRegistered()
|
||||
{
|
||||
$hooks = array(
|
||||
'Tracker.newVisitorInformation' => 'enrichVisitWithProviderInfo',
|
||||
'WidgetsList.addWidgets' => 'addWidget',
|
||||
'Menu.Reporting.addItems' => 'addMenu',
|
||||
'API.getReportMetadata' => 'getReportMetadata',
|
||||
'API.getSegmentDimensionMetadata' => 'getSegmentsMetadata',
|
||||
'ViewDataTable.configure' => 'configureViewDataTable',
|
||||
);
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
public function getReportMetadata(&$reports)
|
||||
{
|
||||
$reports[] = array(
|
||||
'category' => Piwik::translate('General_Visitors'),
|
||||
'name' => Piwik::translate('Provider_ColumnProvider'),
|
||||
'module' => 'Provider',
|
||||
'action' => 'getProvider',
|
||||
'dimension' => Piwik::translate('Provider_ColumnProvider'),
|
||||
'documentation' => Piwik::translate('Provider_ProviderReportDocumentation', '<br />'),
|
||||
'order' => 50
|
||||
);
|
||||
}
|
||||
|
||||
public function getSegmentsMetadata(&$segments)
|
||||
{
|
||||
$segments[] = array(
|
||||
'type' => 'dimension',
|
||||
'category' => 'Visit Location',
|
||||
'name' => Piwik::translate('Provider_ColumnProvider'),
|
||||
'segment' => 'provider',
|
||||
'acceptedValues' => 'comcast.net, proxad.net, etc.',
|
||||
'sqlSegment' => 'log_visit.location_provider'
|
||||
);
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
// add column hostname / hostname ext in the visit table
|
||||
$query = "ALTER IGNORE TABLE `" . Common::prefixTable('log_visit') . "` ADD `location_provider` VARCHAR( 100 ) NULL";
|
||||
|
||||
// if the column already exist do not throw error. Could be installed twice...
|
||||
try {
|
||||
Db::exec($query);
|
||||
} catch (Exception $e) {
|
||||
if (!Db::get()->isErrNo($e, '1060')) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
// add column hostname / hostname ext in the visit table
|
||||
$query = "ALTER TABLE `" . Common::prefixTable('log_visit') . "` DROP `location_provider`";
|
||||
Db::exec($query);
|
||||
}
|
||||
|
||||
public function addWidget()
|
||||
{
|
||||
WidgetsList::add('General_Visitors', 'Provider_WidgetProviders', 'Provider', 'getProvider');
|
||||
}
|
||||
|
||||
public function addMenu()
|
||||
{
|
||||
MenuMain::getInstance()->rename('General_Visitors', 'UserCountry_SubmenuLocations',
|
||||
'General_Visitors', 'Provider_SubmenuLocationsProvider');
|
||||
}
|
||||
|
||||
public function postLoad()
|
||||
{
|
||||
Piwik::addAction('Template.footerUserCountry', array('Piwik\Plugins\Provider\Provider', 'footerUserCountry'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the provider in the log_visit table
|
||||
*/
|
||||
public function enrichVisitWithProviderInfo(&$visitorInfo, \Piwik\Tracker\Request $request)
|
||||
{
|
||||
// if provider info has already been set, abort
|
||||
if (!empty($visitorInfo['location_provider'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$privacyConfig = new PrivacyManagerConfig();
|
||||
$ip = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp());
|
||||
|
||||
// In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
|
||||
if (substr($ip, -2, 2) == '.0') {
|
||||
Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
|
||||
return;
|
||||
}
|
||||
|
||||
$hostname = $this->getHost($ip);
|
||||
$hostnameExtension = $this->getCleanHostname($hostname);
|
||||
|
||||
// add the provider value in the table log_visit
|
||||
$visitorInfo['location_provider'] = $hostnameExtension;
|
||||
$visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100);
|
||||
|
||||
// improve the country using the provider extension if valid
|
||||
$hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.'));
|
||||
if ($hostnameDomain == 'uk') {
|
||||
$hostnameDomain = 'gb';
|
||||
}
|
||||
if (array_key_exists($hostnameDomain, Common::getCountriesList())) {
|
||||
$visitorInfo['location_country'] = $hostnameDomain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hostname extension (site.co.jp in fvae.VARG.ceaga.site.co.jp)
|
||||
* given the full hostname looked up from the IP
|
||||
*
|
||||
* @param string $hostname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCleanHostname($hostname)
|
||||
{
|
||||
$extToExclude = array(
|
||||
'com', 'net', 'org', 'co'
|
||||
);
|
||||
|
||||
$off = strrpos($hostname, '.');
|
||||
$ext = substr($hostname, $off);
|
||||
|
||||
if (empty($off) || is_numeric($ext) || strlen($hostname) < 5) {
|
||||
return 'Ip';
|
||||
} else {
|
||||
$cleanHostname = null;
|
||||
|
||||
/**
|
||||
* Triggered when prettifying a hostname string.
|
||||
*
|
||||
* This event can be used to customize the way a hostname is displayed in the
|
||||
* Providers report.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* public function getCleanHostname(&$cleanHostname, $hostname)
|
||||
* {
|
||||
* if ('fvae.VARG.ceaga.site.co.jp' == $hostname) {
|
||||
* $cleanHostname = 'site.co.jp';
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param string &$cleanHostname The hostname string to display. Set by the event
|
||||
* handler.
|
||||
* @param string $hostname The full hostname.
|
||||
*/
|
||||
Piwik::postEvent('Provider.getCleanHostname', array(&$cleanHostname, $hostname));
|
||||
if ($cleanHostname !== null) {
|
||||
return $cleanHostname;
|
||||
}
|
||||
|
||||
$e = explode('.', $hostname);
|
||||
$s = sizeof($e);
|
||||
|
||||
// if extension not correct
|
||||
if (isset($e[$s - 2]) && in_array($e[$s - 2], $extToExclude)) {
|
||||
return $e[$s - 3] . "." . $e[$s - 2] . "." . $e[$s - 1];
|
||||
} else {
|
||||
return $e[$s - 2] . "." . $e[$s - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hostname given the IP address string
|
||||
*
|
||||
* @param string $ip IP Address
|
||||
* @return string hostname (or human-readable IP address)
|
||||
*/
|
||||
private function getHost($ip)
|
||||
{
|
||||
return trim(strtolower(@IP::getHostByAddr($ip)));
|
||||
}
|
||||
|
||||
static public function footerUserCountry(&$out)
|
||||
{
|
||||
$out = '<div>
|
||||
<h2>' . Piwik::translate('Provider_WidgetProviders') . '</h2>';
|
||||
$out .= FrontController::getInstance()->fetchDispatch('Provider', 'getProvider');
|
||||
$out .= '</div>';
|
||||
}
|
||||
|
||||
public function configureViewDataTable(ViewDataTable $view)
|
||||
{
|
||||
switch ($view->requestConfig->apiMethodToRequestDataTable) {
|
||||
case 'Provider.getProvider':
|
||||
$this->configureViewForGetProvider($view);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function configureViewForGetProvider(ViewDataTable $view)
|
||||
{
|
||||
$view->requestConfig->filter_limit = 5;
|
||||
$view->config->addTranslation('label', Piwik::translate('Provider_ColumnProvider'));
|
||||
}
|
||||
}
|
||||
80
www/analytics/plugins/Provider/functions.php
Normal file
80
www/analytics/plugins/Provider/functions.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Plugins\Provider;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Return hostname portion of a domain name
|
||||
*
|
||||
* @param string $in
|
||||
* @return string Host name, IP (if IP address didn't resolve), or Unknown
|
||||
*/
|
||||
function getHostnameName($in)
|
||||
{
|
||||
if (empty($in)) {
|
||||
return Piwik::translate('General_Unknown');
|
||||
}
|
||||
if (strtolower($in) === 'ip') {
|
||||
return "IP";
|
||||
}
|
||||
if (($positionDot = strpos($in, '.')) !== false) {
|
||||
return ucfirst(substr($in, 0, $positionDot));
|
||||
}
|
||||
return $in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return URL for a given domain name
|
||||
*
|
||||
* @param string $in hostname
|
||||
* @return string URL
|
||||
*/
|
||||
function getHostnameUrl($in)
|
||||
{
|
||||
if ($in == DataTable::LABEL_SUMMARY_ROW) {
|
||||
return false;
|
||||
}
|
||||
if (empty($in)
|
||||
|| strtolower($in) === 'ip'
|
||||
) {
|
||||
// link to "what does 'IP' mean?"
|
||||
return "http://piwik.org/faq/general/#faq_52";
|
||||
}
|
||||
|
||||
// if the name looks like it can be used in a URL, use it in one, otherwise link to startpage
|
||||
if (preg_match("/^[-a-zA-Z0-9_.]+$/", $in)) {
|
||||
return "http://www." . $in . "/";
|
||||
} else {
|
||||
return "https://startpage.com/do/search?q=" . urlencode($in);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a pretty provider name for a given domain name
|
||||
*
|
||||
* @param string $in hostname
|
||||
* @return string Real ISP name, IP (if IP address didn't resolve), or Unknown
|
||||
*/
|
||||
function getPrettyProviderName($in)
|
||||
{
|
||||
$providerName = getHostnameName($in);
|
||||
|
||||
$prettyNames = Common::getProviderNames();
|
||||
|
||||
if (is_array($prettyNames)
|
||||
&& array_key_exists(strtolower($providerName), $prettyNames)
|
||||
) {
|
||||
$providerName = $prettyNames[strtolower($providerName)];
|
||||
}
|
||||
|
||||
return $providerName;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue