Skip to content
Extraits de code Groupes Projets
Valider f6476fa9 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

Check whether known URL starts with path if defined, do no longer match subdomains

parent 82ce0b5a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,6 +13,7 @@ use Piwik\Common; ...@@ -13,6 +13,7 @@ use Piwik\Common;
use Piwik\DeviceDetectorFactory; use Piwik\DeviceDetectorFactory;
use Piwik\Network\IP; use Piwik\Network\IP;
use Piwik\Piwik; use Piwik\Piwik;
use Piwik\Plugins\SitesManager\SiteUrls;
use Piwik\Tracker\Visit\ReferrerSpamFilter; use Piwik\Tracker\Visit\ReferrerSpamFilter;
/** /**
...@@ -290,14 +291,17 @@ class VisitExcluded ...@@ -290,14 +291,17 @@ class VisitExcluded
{ {
$site = Cache::getCacheWebsiteAttributes($this->idSite); $site = Cache::getCacheWebsiteAttributes($this->idSite);
if (!empty($site['exclude_unknown_urls']) && !empty($site['hosts'])) { if (!empty($site['exclude_unknown_urls']) && !empty($site['urls'])) {
$trackingHost = parse_url($this->request->getParam('url'), PHP_URL_HOST); $url = $this->request->getParam('url');
foreach ($site['hosts'] as $siteHost) { $parsedUrl = parse_url($url);
if ($trackingHost == $siteHost || (substr($trackingHost, -strlen($siteHost) - 1) === ('.' . $siteHost))) {
return false; $trackingUrl = new SiteUrls();
} $urls = $trackingUrl->groupUrlsByHost(array($this->idSite => $site['urls']));
}
return true; $idSites = $trackingUrl->getIdSitesMatchingUrl($parsedUrl, $urls);
$isUrlExcluded = !isset($idSites) || !in_array($this->idSite, $idSites);
return $isUrlExcluded;
} }
return false; return false;
......
...@@ -114,8 +114,11 @@ class SitesManager extends \Piwik\Plugin ...@@ -114,8 +114,11 @@ class SitesManager extends \Piwik\Plugin
{ {
$idSite = (int) $idSite; $idSite = (int) $idSite;
$urls = API::getInstance()->getSiteUrlsFromId($idSite);
// add the 'hosts' entry in the website array // add the 'hosts' entry in the website array
$array['hosts'] = $this->getTrackerHosts($idSite); $array['urls'] = $urls;
$array['hosts'] = $this->getTrackerHosts($urls);
$website = API::getInstance()->getSiteFromId($idSite); $website = API::getInstance()->getSiteFromId($idSite);
$array['exclude_unknown_urls'] = $website['exclude_unknown_urls']; $array['exclude_unknown_urls'] = $website['exclude_unknown_urls'];
...@@ -252,9 +255,8 @@ class SitesManager extends \Piwik\Plugin ...@@ -252,9 +255,8 @@ class SitesManager extends \Piwik\Plugin
* @param int $idSite * @param int $idSite
* @return array * @return array
*/ */
private function getTrackerHosts($idSite) private function getTrackerHosts($urls)
{ {
$urls = API::getInstance()->getSiteUrlsFromId($idSite);
$hosts = array(); $hosts = array();
foreach ($urls as $url) { foreach ($urls as $url) {
$url = parse_url($url); $url = parse_url($url);
......
...@@ -118,15 +118,37 @@ class VisitTest extends IntegrationTestCase ...@@ -118,15 +118,37 @@ class VisitTest extends IntegrationTestCase
'http://x.com' => true, 'http://x.com' => true,
)), )),
array(array('http://test.com', 'http://sub.test2.com'), true, array( array(array('http://test.com', 'http://sub.test2.com'), true, array(
'http://sub.test.com' => true, 'http://sub.test.com' => false, // we do not match subdomains
'http://sub.sub.test.com' => true, 'http://sub.sub.test.com' => false,
'http://subtest.com' => false, 'http://subtest.com' => false,
'http://test.com.org' => false, 'http://test.com.org' => false,
'http://test2.com' => false,
'http://sub.test2.com' => true, 'http://sub.test2.com' => true,
'http://x.sub.test2.com' => true, 'http://test.com' => true,
'http://x.sub.test2.com' => false,
'http://xsub.test2.com' => false, 'http://xsub.test2.com' => false,
'http://sub.test2.com.org' => false, 'http://sub.test2.com.org' => false,
)), )),
array(array('http://test.com/path', 'http://test2.com/sub/dir'), true, array(
'http://test.com/path' => true, // test matching path
'http://test.com/path/' => true,
'http://test.com/path/test' => true,
'http://test.com/path1' => false,
'http://test.com/' => false,
'http://test.com' => false,
'http://test.com/foo' => false,
'http://sub.test.com/path' => false, // we still do not match subdomains
'http://test2.com/sub/dir' => true,
'http://test2.com/sub/dir/' => true,
'http://test2.com/sub/dir/test' => true,
'http://test2.com/sub/foo/' => false,
'http://test2.com/sub/' => false,
'http://test2.com/' => false,
'http://test2.com/dir/sub' => false,
)),
); );
} }
...@@ -142,7 +164,7 @@ class VisitTest extends IntegrationTestCase ...@@ -142,7 +164,7 @@ class VisitTest extends IntegrationTestCase
'rec' => 1, 'rec' => 1,
'url' => $url 'url' => $url
))); )));
$this->assertEquals($isTracked, !$visitExclude->isExcluded()); $this->assertEquals($isTracked, !$visitExclude->isExcluded(), $url . ' is not returning expected result');
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter