update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -9,14 +9,16 @@
|
|||
namespace Piwik;
|
||||
|
||||
use Exception;
|
||||
use Piwik\Cache as PiwikCache;
|
||||
|
||||
/**
|
||||
* Contains helper methods that can be used to get common Piwik settings.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class SettingsPiwik
|
||||
{
|
||||
const OPTION_PIWIK_URL = 'piwikUrl';
|
||||
|
||||
/**
|
||||
* Get salt from [General] section
|
||||
*
|
||||
|
|
@ -41,13 +43,6 @@ class SettingsPiwik
|
|||
return Config::getInstance()->General['disable_checks_usernames_attributes'] == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see getKnownSegmentsToArchive
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $cachedKnownSegmentsToArchive = null;
|
||||
|
||||
/**
|
||||
* Returns every stored segment to pre-process for each site during cron archiving.
|
||||
*
|
||||
|
|
@ -55,83 +50,98 @@ class SettingsPiwik
|
|||
*/
|
||||
public static function getKnownSegmentsToArchive()
|
||||
{
|
||||
if (self::$cachedKnownSegmentsToArchive === null) {
|
||||
$segments = Config::getInstance()->Segments;
|
||||
$segmentsToProcess = isset($segments['Segments']) ? $segments['Segments'] : array();
|
||||
|
||||
/**
|
||||
* Triggered during the cron archiving process to collect segments that
|
||||
* should be pre-processed for all websites. The archiving process will be launched
|
||||
* for each of these segments when archiving data.
|
||||
*
|
||||
* This event can be used to add segments to be pre-processed. If your plugin depends
|
||||
* on data from a specific segment, this event could be used to provide enhanced
|
||||
* performance.
|
||||
*
|
||||
* _Note: If you just want to add a segment that is managed by the user, use the
|
||||
* SegmentEditor API._
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* Piwik::addAction('Segments.getKnownSegmentsToArchiveAllSites', function (&$segments) {
|
||||
* $segments[] = 'country=jp;city=Tokyo';
|
||||
* });
|
||||
*
|
||||
* @param array &$segmentsToProcess List of segment definitions, eg,
|
||||
*
|
||||
* array(
|
||||
* 'browserCode=ff;resolution=800x600',
|
||||
* 'country=jp;city=Tokyo'
|
||||
* )
|
||||
*
|
||||
* Add segments to this array in your event handler.
|
||||
*/
|
||||
Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
|
||||
|
||||
self::$cachedKnownSegmentsToArchive = array_unique($segmentsToProcess);
|
||||
$cacheId = 'KnownSegmentsToArchive';
|
||||
$cache = PiwikCache::getTransientCache();
|
||||
if ($cache->contains($cacheId)) {
|
||||
return $cache->fetch($cacheId);
|
||||
}
|
||||
|
||||
return self::$cachedKnownSegmentsToArchive;
|
||||
$segments = Config::getInstance()->Segments;
|
||||
$segmentsToProcess = isset($segments['Segments']) ? $segments['Segments'] : array();
|
||||
|
||||
/**
|
||||
* Triggered during the cron archiving process to collect segments that
|
||||
* should be pre-processed for all websites. The archiving process will be launched
|
||||
* for each of these segments when archiving data.
|
||||
*
|
||||
* This event can be used to add segments to be pre-processed. If your plugin depends
|
||||
* on data from a specific segment, this event could be used to provide enhanced
|
||||
* performance.
|
||||
*
|
||||
* _Note: If you just want to add a segment that is managed by the user, use the
|
||||
* SegmentEditor API._
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* Piwik::addAction('Segments.getKnownSegmentsToArchiveAllSites', function (&$segments) {
|
||||
* $segments[] = 'country=jp;city=Tokyo';
|
||||
* });
|
||||
*
|
||||
* @param array &$segmentsToProcess List of segment definitions, eg,
|
||||
*
|
||||
* array(
|
||||
* 'browserCode=ff;resolution=800x600',
|
||||
* 'country=jp;city=Tokyo'
|
||||
* )
|
||||
*
|
||||
* Add segments to this array in your event handler.
|
||||
*/
|
||||
Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
|
||||
|
||||
$segmentsToProcess = array_unique($segmentsToProcess);
|
||||
|
||||
$cache->save($cacheId, $segmentsToProcess);
|
||||
return $segmentsToProcess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of stored segments to pre-process for an individual site when executing
|
||||
* cron archiving.
|
||||
*
|
||||
*
|
||||
* @param int $idSite The ID of the site to get stored segments for.
|
||||
* @return string The list of stored segments that apply to the requested site.
|
||||
* @return string[] The list of stored segments that apply to the requested site.
|
||||
*/
|
||||
public static function getKnownSegmentsToArchiveForSite($idSite)
|
||||
{
|
||||
$segments = array();
|
||||
$cacheId = 'KnownSegmentsToArchiveForSite' . $idSite;
|
||||
$cache = PiwikCache::getTransientCache();
|
||||
if ($cache->contains($cacheId)) {
|
||||
return $cache->fetch($cacheId);
|
||||
}
|
||||
|
||||
$segments = array();
|
||||
/**
|
||||
* Triggered during the cron archiving process to collect segments that
|
||||
* should be pre-processed for one specific site. The archiving process will be launched
|
||||
* for each of these segments when archiving data for that one site.
|
||||
*
|
||||
*
|
||||
* This event can be used to add segments to be pre-processed for one site.
|
||||
*
|
||||
*
|
||||
* _Note: If you just want to add a segment that is managed by the user, you should use the
|
||||
* SegmentEditor API._
|
||||
*
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
*
|
||||
* Piwik::addAction('Segments.getKnownSegmentsToArchiveForSite', function (&$segments, $idSite) {
|
||||
* $segments[] = 'country=jp;city=Tokyo';
|
||||
* });
|
||||
*
|
||||
*
|
||||
* @param array &$segmentsToProcess List of segment definitions, eg,
|
||||
*
|
||||
*
|
||||
* array(
|
||||
* 'browserCode=ff;resolution=800x600',
|
||||
* 'country=JP;city=Tokyo'
|
||||
* )
|
||||
*
|
||||
*
|
||||
* Add segments to this array in your event handler.
|
||||
* @param int $idSite The ID of the site to get segments for.
|
||||
*/
|
||||
Piwik::postEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
|
||||
|
||||
$segments = array_unique($segments);
|
||||
|
||||
$cache->save($cacheId, $segments);
|
||||
|
||||
return $segments;
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +169,7 @@ class SettingsPiwik
|
|||
|
||||
$isPiwikCoreDispatching = defined('PIWIK_ENABLE_DISPATCH') && PIWIK_ENABLE_DISPATCH;
|
||||
if (Common::isPhpCliMode()
|
||||
// in case archive.php is triggered with domain localhost
|
||||
// in case core:archive command is triggered (often with localhost domain)
|
||||
|| SettingsServer::isArchivePhpTriggered()
|
||||
// When someone else than core is dispatching this request then we return the URL as it is read only
|
||||
|| !$isPiwikCoreDispatching
|
||||
|
|
@ -169,17 +179,23 @@ class SettingsPiwik
|
|||
|
||||
$currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
|
||||
|
||||
// when script is called from /misc/cron/archive.php, Piwik URL is /index.php
|
||||
$currentUrl = str_replace("/misc/cron", "", $currentUrl);
|
||||
|
||||
if (empty($url)
|
||||
// if URL changes, always update the cache
|
||||
|| $currentUrl != $url
|
||||
) {
|
||||
if (strlen($currentUrl) >= strlen('http://a/')) {
|
||||
$host = Url::getHostFromUrl($url);
|
||||
|
||||
if (strlen($currentUrl) >= strlen('http://a/')
|
||||
&& !Url::isLocalHost($host)) {
|
||||
self::overwritePiwikUrl($currentUrl);
|
||||
}
|
||||
$url = $currentUrl;
|
||||
}
|
||||
|
||||
if(ProxyHttp::isHttps()) {
|
||||
if (ProxyHttp::isHttps()) {
|
||||
$url = str_replace("http://", "https://", $url);
|
||||
}
|
||||
return $url;
|
||||
|
|
@ -191,11 +207,29 @@ class SettingsPiwik
|
|||
*/
|
||||
public static function isPiwikInstalled()
|
||||
{
|
||||
$config = Config::getInstance()->getLocalConfigPath();
|
||||
$config = Config::getInstance()->getLocalPath();
|
||||
$exists = file_exists($config);
|
||||
|
||||
// Piwik is installed if the config file is found
|
||||
return $exists;
|
||||
if (!$exists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$general = Config::getInstance()->General;
|
||||
|
||||
$isInstallationInProgress = false;
|
||||
if (array_key_exists('installation_in_progress', $general)) {
|
||||
$isInstallationInProgress = (bool) $general['installation_in_progress'];
|
||||
}
|
||||
if ($isInstallationInProgress) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the database section is really set, ie. file is not empty
|
||||
if (empty(Config::getInstance()->database['username'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -212,7 +246,7 @@ class SettingsPiwik
|
|||
|
||||
/**
|
||||
* Returns true if unique visitors should be processed for the given period type.
|
||||
*
|
||||
*
|
||||
* Unique visitor processing is controlled by the `[General] enable_processing_unique_visitors_...`
|
||||
* INI config options. By default, unique visitors are processed only for day/week/month periods.
|
||||
*
|
||||
|
|
@ -237,38 +271,31 @@ class SettingsPiwik
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Piwik uses per-domain config file, also make tmp/ folder per-domain
|
||||
* @param $path
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function rewriteTmpPathWithHostname($path)
|
||||
{
|
||||
$tmp = '/tmp/';
|
||||
$path = self::rewritePathAppendHostname($path, $tmp);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* If Piwik uses per-domain config file, make sure CustomLogo is unique
|
||||
* @param $path
|
||||
* @return mixed
|
||||
*/
|
||||
public static function rewriteMiscUserPathWithHostname($path)
|
||||
public static function rewriteMiscUserPathWithInstanceId($path)
|
||||
{
|
||||
$tmp = 'misc/user/';
|
||||
$path = self::rewritePathAppendHostname($path, $tmp);
|
||||
$path = self::rewritePathAppendPiwikInstanceId($path, $tmp);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the Piwik server appears to be working.
|
||||
*
|
||||
* If the Piwik server is in an error state (eg. some directories are not writable and Piwik displays error message),
|
||||
* or if the Piwik server is "offline",
|
||||
* this will return false..
|
||||
*
|
||||
* @param $piwikServerUrl
|
||||
* @param bool $acceptInvalidSSLCertificates
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
static public function checkPiwikServerWorking($piwikServerUrl, $acceptInvalidSSLCertificates = false)
|
||||
public static function checkPiwikServerWorking($piwikServerUrl, $acceptInvalidSSLCertificates = false)
|
||||
{
|
||||
// Now testing if the webserver is running
|
||||
try {
|
||||
|
|
@ -285,9 +312,22 @@ class SettingsPiwik
|
|||
} catch (Exception $e) {
|
||||
$fetched = "ERROR fetching: " . $e->getMessage();
|
||||
}
|
||||
$expectedString = 'plugins/CoreHome/images/favicon.ico';
|
||||
// this will match when Piwik not installed yet, or favicon not customised
|
||||
$expectedStringAlt = 'plugins/CoreHome/images/favicon.png';
|
||||
|
||||
if (strpos($fetched, $expectedString) === false) {
|
||||
// this will match when Piwik is installed and favicon has been customised
|
||||
$expectedString = 'misc/user/';
|
||||
|
||||
// see checkPiwikIsNotInstalled()
|
||||
$expectedStringAlreadyInstalled = 'piwik-is-already-installed';
|
||||
|
||||
$expectedStringNotFound = strpos($fetched, $expectedString) === false
|
||||
&& strpos($fetched, $expectedStringAlt) === false
|
||||
&& strpos($fetched, $expectedStringAlreadyInstalled) === false;
|
||||
|
||||
$hasError = false !== strpos($fetched, PAGE_TITLE_WHEN_ERROR);
|
||||
|
||||
if ($hasError || $expectedStringNotFound) {
|
||||
throw new Exception("\nPiwik should be running at: "
|
||||
. $piwikServerUrl
|
||||
. " but this URL returned an unexpected response: '"
|
||||
|
|
@ -295,10 +335,21 @@ class SettingsPiwik
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Piwik is deployed using git
|
||||
* FAQ: http://piwik.org/faq/how-to-install/faq_18271/
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isGitDeployment()
|
||||
{
|
||||
return file_exists(PIWIK_INCLUDE_PATH . '/.git/HEAD');
|
||||
}
|
||||
|
||||
public static function getCurrentGitBranch()
|
||||
{
|
||||
$file = PIWIK_INCLUDE_PATH . '/.git/HEAD';
|
||||
if(!file_exists($file)) {
|
||||
if (!file_exists($file)) {
|
||||
return '';
|
||||
}
|
||||
$firstLineOfGitHead = file($file);
|
||||
|
|
@ -321,10 +372,10 @@ class SettingsPiwik
|
|||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function rewritePathAppendHostname($pathToRewrite, $leadingPathToAppendHostnameTo)
|
||||
protected static function rewritePathAppendPiwikInstanceId($pathToRewrite, $leadingPathToAppendHostnameTo)
|
||||
{
|
||||
$hostname = self::getConfigHostname();
|
||||
if (empty($hostname)) {
|
||||
$instanceId = self::getPiwikInstanceId();
|
||||
if (empty($instanceId)) {
|
||||
return $pathToRewrite;
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +383,7 @@ class SettingsPiwik
|
|||
throw new Exception("The path $pathToRewrite was expected to contain the string $leadingPathToAppendHostnameTo");
|
||||
}
|
||||
|
||||
$tmpToReplace = $leadingPathToAppendHostnameTo . $hostname . '/';
|
||||
$tmpToReplace = $leadingPathToAppendHostnameTo . $instanceId . '/';
|
||||
|
||||
// replace only the latest occurrence (in case path contains twice /tmp)
|
||||
$pathToRewrite = substr_replace($pathToRewrite, $tmpToReplace, $posTmp, strlen($leadingPathToAppendHostnameTo));
|
||||
|
|
@ -340,18 +391,30 @@ class SettingsPiwik
|
|||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
* @throws \Exception
|
||||
* @return string or False if not set
|
||||
*/
|
||||
protected static function getConfigHostname()
|
||||
protected static function getPiwikInstanceId()
|
||||
{
|
||||
$configByHost = false;
|
||||
try {
|
||||
$configByHost = Config::getInstance()->getConfigHostnameIfSet();
|
||||
return $configByHost;
|
||||
} catch (Exception $e) {
|
||||
// Config file not found
|
||||
// until Piwik is installed, we use hostname as instance_id
|
||||
if (!self::isPiwikInstalled()
|
||||
&& Common::isPhpCliMode()) {
|
||||
// enterprise:install use case
|
||||
return Config::getHostname();
|
||||
}
|
||||
return $configByHost;
|
||||
|
||||
// config.ini.php not ready yet, instance_id will not be set
|
||||
if (!Config::getInstance()->existsLocalConfig()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$instanceId = @Config::getInstance()->General['instance_id'];
|
||||
if (!empty($instanceId)) {
|
||||
return $instanceId;
|
||||
}
|
||||
|
||||
// do not rewrite the path as Piwik uses the standard config.ini.php file
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -367,6 +430,20 @@ class SettingsPiwik
|
|||
*/
|
||||
public static function isHttpsForced()
|
||||
{
|
||||
if (!SettingsPiwik::isPiwikInstalled()) {
|
||||
// Only enable this feature after Piwik is already installed
|
||||
return false;
|
||||
}
|
||||
return Config::getInstance()->General['force_ssl'] == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this config settig is also checked in the InterSites plugin
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSameFingerprintAcrossWebsites()
|
||||
{
|
||||
return (bool)Config::getInstance()->Tracker['enable_fingerprinting_across_websites'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue