Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions core/Tracker/PageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

namespace Piwik\Tracker;

use Piwik\Cache;
use Piwik\CacheId;
use Piwik\Tracker\Cache as TrackerCache;
use Piwik\Common;
use Piwik\Config;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\UrlHelper;

class PageUrl
Expand Down Expand Up @@ -80,7 +84,7 @@ public static function getQueryParametersToExclude($idSite)
$campaignTrackingParameters[1] // campaign keyword parameters
);

$website = Cache::getCacheWebsiteAttributes($idSite);
$website = TrackerCache::getCacheWebsiteAttributes($idSite);
$excludedParameters = self::getExcludedParametersFromWebsite($website);

$parametersToExclude = array_merge($excludedParameters,
Expand Down Expand Up @@ -127,7 +131,7 @@ protected static function getUrlParameterNamesToExcludeFromUrl()
*/
public static function shouldRemoveURLFragmentFor($idSite)
{
$websiteAttributes = Cache::getCacheWebsiteAttributes($idSite);
$websiteAttributes = TrackerCache::getCacheWebsiteAttributes($idSite);
return empty($websiteAttributes['keep_url_fragment']);
}

Expand Down Expand Up @@ -335,6 +339,44 @@ public static function reconstructNormalizedUrl($url, $prefixId)
return $fullUrl;
}

/**
* Returns if the given host is also configured as https in page urls of given site
*
* @param $idSite
* @param $host
* @return false|mixed
* @throws \Exception
*/
public static function shouldUseHttpsHost($idSite, $host)
{
$cache = Cache::getTransientCache();

$cacheKeySiteUrls = CacheId::siteAware('siteurls', [$idSite]);
$cacheKeyHttpsForHost = CacheId::siteAware(sprintf('shouldusehttps-%s', $host), [$idSite]);

$siteUrlCache = $cache->fetch($cacheKeySiteUrls);

if (empty($siteUrlCache)) {
$siteUrlCache = APISitesManager::getInstance()->getSiteUrlsFromId($idSite);
$cache->save($cacheKeySiteUrls, $siteUrlCache);
}

if (!$cache->contains($cacheKeyHttpsForHost)) {
$hostSiteCache = false;

foreach ($siteUrlCache as $siteUrl) {
if (strpos(Common::mb_strtolower($siteUrl), Common::mb_strtolower('https://' . $host)) === 0) {
$hostSiteCache = true;
break;
}
}

$cache->save($cacheKeyHttpsForHost, $hostSiteCache);
}

return $cache->fetch($cacheKeyHttpsForHost);
}

/**
* Extract the prefix from a URL.
* Return the prefix ID and the rest.
Expand Down
9 changes: 9 additions & 0 deletions plugins/Actions/DataTable/Filter/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Piwik\DataTable;
use Piwik\Plugins\Actions\ArchivingHelper;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;

class Actions extends BaseFilter
{
Expand Down Expand Up @@ -66,6 +67,14 @@ public function filter($table)
$label = $row->getColumn('label');
if ($url) {
$row->setMetadata('segmentValue', urlencode($url));

if ($site && strpos($url, 'http://') === 0) {
$host = parse_url($url, PHP_URL_HOST);

if ($host && PageUrl::shouldUseHttpsHost($site->getId(), $host)) {
$row->setMetadata('url', 'https://' . Common::mb_substr($url, 7 /* = strlen('http://') */));
}
}
} else if ($folderUrlStart) {
$row->setMetadata('segment', 'pageUrl=^' . urlencode(urlencode($folderUrlStart)));
} else if ($pageTitlePath) {
Expand Down
10 changes: 10 additions & 0 deletions plugins/Actions/VisitorDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace Piwik\Plugins\Actions;

use Piwik\Cache;
use Piwik\Common;
use Piwik\Config;
use Piwik\Date;
Expand All @@ -16,6 +17,7 @@
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\Live\VisitorDetailsAbstract;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Site;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;
Expand Down Expand Up @@ -160,6 +162,14 @@ public function extendActionDetails(&$action, $nextAction, $visitorDetails)
unset($action['url_prefix']);
}

if (array_key_exists('url', $action) && strpos($action['url'], 'http://') === 0) {
$host = parse_url($action['url'], PHP_URL_HOST);

if ($host && PageUrl::shouldUseHttpsHost($visitorDetails['idSite'], $host)) {
$action['url'] = 'https://' . Common::mb_substr($action['url'], 7 /* = strlen('http://') */);
}
}

switch ($action['type']) {
case 'goal':
$action['icon'] = 'plugins/Morpheus/images/goal.png';
Expand Down
2 changes: 1 addition & 1 deletion plugins/ImageGraph/StaticGraph/GridGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function initGridChart(
}
}

if (($bottomRightYValue - $topLeftYValue) <= ($ordinateAxisLength / 2)) {
if ($ordinateAxisLength <= 0 || $bottomRightYValue - $topLeftYValue <= 0) {
throw new InvalidDimensionException('Error: the graph dimension is not valid. Please try larger width and height values or use 0 for default values.');
}

Expand Down
15 changes: 15 additions & 0 deletions plugins/Live/tests/System/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Piwik\Plugins\Live\tests\System;

use Piwik\Cache;
use Piwik\Config;
use Piwik\Plugins\API\API;
use Piwik\Plugins\Live\SystemSettings;
Expand Down Expand Up @@ -163,6 +164,20 @@ public function testApiWithLowerMaxVisitsLimit()
]);
}

public function testApiWithHttpsHost()
{
\Piwik\Plugins\SitesManager\API::getInstance()->updateSite(1, 'Piwik test', ['http://piwik.net', 'https://example.org', 'http://example.org']);
Cache::getTransientCache()->flushAll();

$this->runApiTests('Live.getLastVisitsDetails', [
'idSite' => 1,
'date' => self::$fixture->dateTime,
'periods' => ['day'],
'testSuffix' => 'httpshost',
]);
}


/**
* @dataProvider getApiForTestingDisabledFeatures
*/
Expand Down
Loading