diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
commit | 7e1b5d6b762340cbff1bb928d15815980c7649a7 (patch) | |
tree | e07da179b9e1372866d2349777bd1cc6b4c9e8cf /plugins/SitesManager/SitesManager.php | |
parent | 999f46479294713104c962bfe7469e9b6e7a4bbf (diff) | |
parent | c98ea06f2cccec81c6ccce49162a583494e44d91 (diff) |
Diffstat (limited to 'plugins/SitesManager/SitesManager.php')
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 106 |
1 files changed, 92 insertions, 14 deletions
diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index b2542e966c..dfca3e2c6f 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -19,11 +19,10 @@ class Piwik_SitesManager extends Piwik_Plugin public function getInformation() { $info = array( - 'name' => 'Sites Management', - 'description' => 'Websites Management in Piwik: Add a new Website, Edit an existing one, Show the Javascript code to include on your pages. All the actions are also available through the API.', + 'description' => Piwik_Translate('SitesManager_PluginDescription'), 'author' => 'Piwik', - 'homepage' => 'http://piwik.org/', - 'version' => '0.1', + 'author_homepage' => 'http://piwik.org/', + 'version' => Piwik_Version::VERSION, ); return $info; } @@ -33,21 +32,105 @@ class Piwik_SitesManager extends Piwik_Plugin return array( 'template_css_import' => 'css', 'AdminMenu.add' => 'addMenu', - 'Common.fetchWebsiteAttributes' => 'recordWebsiteHostsInCache', + 'Common.fetchWebsiteAttributes' => 'recordWebsiteDataInCache', ); } + function addMenu() + { + Piwik_AddAdminMenu('SitesManager_MenuSites', + array('module' => 'SitesManager', 'action' => 'index'), + Piwik::isUserHasSomeAdminAccess(), + $order = 5); + } + function css() { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"themes/default/styles.css\" />\n"; } - function recordWebsiteHostsInCache($notification) + /** + * Hooks when a website tracker cache is flushed (website updated, cache deleted, or empty cache) + * Will record in the tracker config file all data needed for this website in Tracker. + * + * @param $notification + * @return void + */ + function recordWebsiteDataInCache($notification) { - $idsite = $notification->getNotificationInfo(); + $idSite = $notification->getNotificationInfo(); // add the 'hosts' entry in the website array $array =& $notification->getNotificationObject(); - $urls = Piwik_SitesManager_API::getSiteUrlsFromId($idsite); + $array['hosts'] = $this->getTrackerHosts($idSite); + $array['excluded_ips'] = $this->getTrackerExcludedIps($idSite); + $array['excluded_parameters'] = $this->getTrackerExcludedQueryParameters($idSite); + } + + /** + * Returns the array of excluded IPs to save in the config file + * @param $idSite + * @return array + */ + private function getTrackerExcludedIps($idSite) + { + $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + $excludedIps = $website['excluded_ips']; + $globalExcludedIps = Piwik_SitesManager_API::getInstance()->getExcludedIpsGlobal(); + + $excludedIps .= ',' . $globalExcludedIps; + + $ipRanges = array(); + foreach(explode(',', $excludedIps) as $ip) + { + $ipMin = $ipMax = $ip; + if(substr_count($ip, '*') > 0) + { + $ipMin = str_replace('*', '0', $ip); + $ipMax = str_replace('*', '255', $ip); + } + $ipRange = array( ip2long($ipMin), ip2long($ipMax)); + + // we can still get invalid IPs at this stage (eg. ip2long(555.1.1.1) would return false) + if($ipRange[0] === false || $ipRange[1] === false) + { + continue; + } + + // long data type is signed; convert to stringified unsigned number + $ipRange[0] = sprintf("%u", $ipRange[0]); + $ipRange[1] = sprintf("%u", $ipRange[1]); + + $ipRanges[] = $ipRange; + } + return $ipRanges; + } + + /** + * Returns the array of URL query parameters to exclude from URLs + * @param $idSite + * @return array + */ + private function getTrackerExcludedQueryParameters($idSite) + { + $website = Piwik_SitesManager_API::getInstance()->getSiteFromId($idSite); + $excludedQueryParameters = $website['excluded_parameters']; + $globalExcludedQueryParameters = Piwik_SitesManager_API::getInstance()->getExcludedQueryParametersGlobal(); + + $excludedQueryParameters .= ',' . $globalExcludedQueryParameters; + $parameters = explode(',', $excludedQueryParameters); + $parameters = array_filter($parameters, 'strlen'); + $parameters = array_unique($parameters); + return $parameters; + } + + /** + * Returns the hosts alias URLs + * @param $idSite + * @return array + */ + private function getTrackerHosts($idSite) + { + $urls = Piwik_SitesManager_API::getInstance()->getSiteUrlsFromId($idSite); $hosts = array(); foreach($urls as $url) { @@ -57,12 +140,7 @@ class Piwik_SitesManager extends Piwik_Plugin $hosts[] = $url['host']; } } - $array['hosts'] = $hosts; + return $hosts; } - function addMenu() - { - Piwik_AddAdminMenu('SitesManager_MenuSites', array('module' => 'SitesManager', 'action' => 'index')); - } } - |