Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2016-01-28 23:59:59 +0300
committerThomas Steur <thomas.steur@gmail.com>2016-01-28 23:59:59 +0300
commit03b077db293640ca325aa04a617a26c22d757ba8 (patch)
treec390e1051f644a91846b2764a62e106739245ccc
parentf8d3e6fad11413cbeef5eb71080773dadf944012 (diff)
fixes #9648 New sentence presenting Piwik PRO after a successful Piwik installation
-rw-r--r--config/global.ini.php4
-rwxr-xr-xcore/Twig.php57
-rw-r--r--core/View.php7
-rw-r--r--plugins/Installation/lang/en.json2
-rw-r--r--plugins/Installation/templates/finished.twig10
-rw-r--r--tests/PHPUnit/Framework/Mock/FakeConfig.php28
-rw-r--r--tests/PHPUnit/Framework/Mock/Plugin/Manager.php23
-rw-r--r--tests/PHPUnit/Integration/PiwikPro/AdvertisingTest.php139
8 files changed, 269 insertions, 1 deletions
diff --git a/config/global.ini.php b/config/global.ini.php
index afa6a03c87..88dfe74664 100644
--- a/config/global.ini.php
+++ b/config/global.ini.php
@@ -562,6 +562,10 @@ pivot_by_filter_enable_fetch_by_segment = 0
; on a per-request basis;
pivot_by_filter_default_column_limit = 10
+; If set to 0 it will disable Piwik Pro advertisements in some places. For example in the installation screen, the
+; Piwik Pro Ad widget will be removed etc.
+piwik_pro_ads_enabled = 1
+
[Tracker]
; Piwik uses "Privacy by default" model. When one of your users visit multiple of your websites tracked in this Piwik,
diff --git a/core/Twig.php b/core/Twig.php
index 5968b965eb..ab76791490 100755
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -87,6 +87,9 @@ class Twig
$this->addFilter_percentage();
$this->addFilter_percent();
$this->addFilter_percentEvolution();
+ $this->addFilter_piwikProAdLink();
+ $this->addFilter_piwikProOnPremisesAdLink();
+ $this->addFilter_piwikProCloudAdLink();
$this->addFilter_prettyDate();
$this->addFilter_safeDecodeRaw();
$this->addFilter_number();
@@ -321,6 +324,60 @@ class Twig
$this->twig->addFilter($percentage);
}
+ protected function addFilter_piwikProAdLink()
+ {
+ $twigEnv = $this->getTwigEnvironment();
+ $ads = $this->getPiwikProAdvertising();
+
+ $piwikProAd = new Twig_SimpleFilter('piwikProPromoLink', function ($url, $campaignName, $campaignMedium, $campaignContent = '') use ($twigEnv, $ads) {
+
+ $campaign = $ads->getCampaignParametersForPromoLink($campaignName, $campaignMedium, $campaignContent);
+
+ if (strpos($url, '?') === false) {
+ $url .= '?' . $campaign;
+ } else {
+ $url .= '&' . $campaign;
+ }
+
+ return twig_escape_filter($twigEnv, $url, 'html_attr');
+
+ }, array('is_safe' => array('html_attr')));
+ $this->twig->addFilter($piwikProAd);
+ }
+
+ protected function addFilter_piwikProOnPremisesAdLink()
+ {
+ $twigEnv = $this->getTwigEnvironment();
+ $ads = $this->getPiwikProAdvertising();
+ $piwikProAd = new Twig_SimpleFilter('piwikProOnPremisesPromoLink', function ($medium, $content = '') use ($twigEnv, $ads) {
+
+ $url = $ads->getPromoLinkForOnPremises($medium, $content);
+
+ return twig_escape_filter($twigEnv, $url, 'html_attr');
+
+ }, array('is_safe' => array('html_attr')));
+ $this->twig->addFilter($piwikProAd);
+ }
+
+ protected function addFilter_piwikProCloudAdLink()
+ {
+ $twigEnv = $this->getTwigEnvironment();
+ $ads = $this->getPiwikProAdvertising();
+ $piwikProAd = new Twig_SimpleFilter('piwikProCloudPromoLink', function ($medium, $content = '') use ($twigEnv, $ads) {
+
+ $url = $ads->getPromoLinkForCloud($medium, $content);
+
+ return twig_escape_filter($twigEnv, $url, 'html_attr');
+
+ }, array('is_safe' => array('html_attr')));
+ $this->twig->addFilter($piwikProAd);
+ }
+
+ private function getPiwikProAdvertising()
+ {
+ return StaticContainer::get('Piwik\PiwikPro\Advertising');
+ }
+
protected function addFilter_number()
{
$formatter = new Twig_SimpleFilter('number', function ($string, $minFractionDigits = 0, $maxFractionDigits = 0) {
diff --git a/core/View.php b/core/View.php
index bc8ccf075a..a05a9a7204 100644
--- a/core/View.php
+++ b/core/View.php
@@ -10,6 +10,7 @@ namespace Piwik;
use Exception;
use Piwik\AssetManager\UIAssetCacheBuster;
+use Piwik\Container\StaticContainer;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\View\ViewInterface;
use Twig_Environment;
@@ -85,6 +86,7 @@ if (!defined('PIWIK_USER_PATH')) {
* which is outputted in the template, eg, `{{ postEvent('MyPlugin.event') }}`
* - **isPluginLoaded**: Returns true if the supplied plugin is loaded, false if otherwise.
* `{% if isPluginLoaded('Goals') %}...{% endif %}`
+ * - **arePiwikProAdsEnabled**: Returns true if it is ok to show some Piwik PRO advertising in the UI
*
* ### Examples
*
@@ -226,7 +228,10 @@ class View implements ViewInterface
$this->latest_version_available = UpdateCheck::isNewestVersionAvailable();
$this->disableLink = Common::getRequestVar('disableLink', 0, 'int');
$this->isWidget = Common::getRequestVar('widget', 0, 'int');
-
+
+ $piwikProAds = StaticContainer::get('Piwik\PiwikPro\Advertising');
+ $this->arePiwikProAdsEnabled = $piwikProAds->arePiwikProAdsEnabled();
+
if (Development::isEnabled()) {
$cacheBuster = rand(0, 10000);
} else {
diff --git a/plugins/Installation/lang/en.json b/plugins/Installation/lang/en.json
index 049d191fb4..22a41c2206 100644
--- a/plugins/Installation/lang/en.json
+++ b/plugins/Installation/lang/en.json
@@ -42,6 +42,8 @@
"PasswordDoNotMatch": "password do not match",
"PasswordRepeat": "Password (repeat)",
"PercentDone": "%s %% Done",
+ "PiwikProAdTitle": "Advanced Analytics & Services",
+ "PiwikProAdText": "Add premium functionality and unlock the full power with %1$sPiwik PRO On-Premises%2$s, or get your own hassle-free Piwik hosted in the %3$sPiwik PRO Cloud%4$s.",
"PleaseFixTheFollowingErrors": "Please fix the following errors",
"DefaultSettings": "Default Piwik settings",
"DefaultSettingsHelp": "Piwik comes with default settings. You can customize them now or do so later in the admin screen.",
diff --git a/plugins/Installation/templates/finished.twig b/plugins/Installation/templates/finished.twig
index 636e8d397c..3ea30999a2 100644
--- a/plugins/Installation/templates/finished.twig
+++ b/plugins/Installation/templates/finished.twig
@@ -17,6 +17,16 @@
<p>{{ 'Installation_WeHopeYouWillEnjoyPiwik'|translate }}</p>
<p><i>{{ 'Installation_HappyAnalysing'|translate }}</i></p>
+ {% if arePiwikProAdsEnabled %}
+ <h3>{{ 'Installation_PiwikProAdTitle'|translate }}</h3>
+ <p>
+ {% set linkOnPremises = 'Installation_End'|piwikProOnPremisesPromoLink %}
+ {% set linkOnCloud = 'Installation_End'|piwikProCloudPromoLink %}
+
+ {{ 'Installation_PiwikProAdText'|translate('<a rel="noreferrer" target="_blank" href="' ~ linkOnPremises ~ '">','</a>', '<a rel="noreferrer" target="_blank" href="' ~ linkOnCloud ~ '">','</a>')|raw }}
+ </p>
+ {% endif %}
+
<h3>{{ 'Installation_DefaultSettings'|translate }}</h3>
<p>{{ 'Installation_DefaultSettingsHelp'|translate }}</p>
diff --git a/tests/PHPUnit/Framework/Mock/FakeConfig.php b/tests/PHPUnit/Framework/Mock/FakeConfig.php
new file mode 100644
index 0000000000..cab4955a13
--- /dev/null
+++ b/tests/PHPUnit/Framework/Mock/FakeConfig.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Piwik\Tests\Framework\Mock;
+
+use Piwik\Config;
+
+class FakeConfig extends Config
+{
+ private $configValues = array();
+
+ public function __construct($configValues = array())
+ {
+ $this->configValues = $configValues;
+ }
+
+ public function &__get($name)
+ {
+ if (isset($this->configValues[$name])) {
+ return $this->configValues[$name];
+ }
+ }
+
+ public function __set($name, $value)
+ {
+ $this->configValues[$name] = $value;
+ }
+
+}
diff --git a/tests/PHPUnit/Framework/Mock/Plugin/Manager.php b/tests/PHPUnit/Framework/Mock/Plugin/Manager.php
new file mode 100644
index 0000000000..3f79065ad6
--- /dev/null
+++ b/tests/PHPUnit/Framework/Mock/Plugin/Manager.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Piwik\Tests\Framework\Mock\Plugin;
+
+class Manager extends \Piwik\Plugin\Manager
+{
+ private $installedPlugins = array();
+
+ public function __construct()
+ {
+ }
+
+ public function setInstalledPlugins($pluginsList)
+ {
+ $this->installedPlugins = $pluginsList;
+ }
+
+ public function isPluginInstalled($pluginName)
+ {
+ return in_array($pluginName, $this->installedPlugins);
+ }
+
+}
diff --git a/tests/PHPUnit/Integration/PiwikPro/AdvertisingTest.php b/tests/PHPUnit/Integration/PiwikPro/AdvertisingTest.php
new file mode 100644
index 0000000000..79992bda3b
--- /dev/null
+++ b/tests/PHPUnit/Integration/PiwikPro/AdvertisingTest.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Tests\Integration\PiwikPro;
+
+use Piwik\Config;
+use Piwik\PiwikPro\Advertising;
+use Piwik\Plugin;
+use Piwik\Tests\Framework\Mock\FakeConfig;
+use Piwik\Tests\Framework\Mock\Plugin\Manager;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group PiwikPro
+ * @group Advertising
+ * @group Integration
+ */
+class AdvertisingTest extends IntegrationTestCase
+{
+ /**
+ * @var Advertising
+ */
+ private $advertising;
+
+ /**
+ * @var Config
+ */
+ private $config;
+
+ /**
+ * @var Manager
+ */
+ private $pluginManager;
+
+ public function setUp()
+ {
+ $this->config = new FakeConfig(array('General' => array('piwik_pro_ads_enabled' => '1')));
+ $this->pluginManager = new Manager();
+
+ $this->advertising = $this->buildAdvertising($this->config);
+ }
+
+ public function test_arePiwikProAdsEnabled_ActuallyEnabled()
+ {
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+
+ $this->assertTrue($enabled);
+ }
+
+ public function test_arePiwikProAdsEnabled_Disabled()
+ {
+ $this->config->General = array('piwik_pro_ads_enabled' => '0');
+
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+
+ $this->assertFalse($enabled);
+ }
+
+ public function test_arePiwikProAdsEnabled_shouldBeDisabledWhenCloudPluginIsInstalled()
+ {
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+ $this->assertTrue($enabled);
+
+ $this->pluginManager->setInstalledPlugins(array('CloudAdmin'));
+
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+ $this->assertFalse($enabled);
+ }
+
+ public function test_arePiwikProAdsEnabled_shouldBeDisabledWhenEnterprisePluginIsInstalled()
+ {
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+ $this->assertTrue($enabled);
+
+ $this->pluginManager->setInstalledPlugins(array('EnterpriseAdmin'));
+
+ $enabled = $this->advertising->arePiwikProAdsEnabled();
+ $this->assertFalse($enabled);
+ }
+
+ public function test_shouldBeEnabledByDefault()
+ {
+ $enabled = $this->buildAdvertising(Config::getInstance());
+
+ $this->assertTrue($enabled->arePiwikProAdsEnabled());
+ }
+
+ public function test_getPromoLinkForOnPremises_WithoutContent()
+ {
+ $link = $this->advertising->getPromoLinkForOnPremises('Installation_End');
+
+ $this->assertSame('https://piwik.pro/c/upgrade/?pk_campaign=Upgrade_to_Pro&pk_medium=Installation_End&pk_source=Piwik_App', $link);
+ }
+
+ public function test_getPromoLinkForOnPremises_WithContent()
+ {
+ $link = $this->advertising->getPromoLinkForOnPremises('Installation_End', 'TestContent');
+
+ $this->assertSame('https://piwik.pro/c/upgrade/?pk_campaign=Upgrade_to_Pro&pk_medium=Installation_End&pk_source=Piwik_App&pk_content=TestContent', $link);
+ }
+
+ public function test_getPromoLinkForCloud_WithoutContent()
+ {
+ $link = $this->advertising->getPromoLinkForCloud('Installation_End');
+
+ $this->assertSame('https://piwik.pro/cloud/?pk_campaign=Upgrade_to_Cloud&pk_medium=Installation_End&pk_source=Piwik_App', $link);
+ }
+
+ public function test_getPromoLinkForCloud_WithContent()
+ {
+ $link = $this->advertising->getPromoLinkForCloud('Installation_End', 'TestContent');
+
+ $this->assertSame('https://piwik.pro/cloud/?pk_campaign=Upgrade_to_Cloud&pk_medium=Installation_End&pk_source=Piwik_App&pk_content=TestContent', $link);
+ }
+
+ public function test_getCampaignParametersForPromoLink_withoutContent()
+ {
+ $link = $this->advertising->getCampaignParametersForPromoLink('MyName', 'Installation_Start');
+
+ $this->assertSame('pk_campaign=MyName&pk_medium=Installation_Start&pk_source=Piwik_App', $link);
+ }
+
+ public function test_getCampaignParametersForPromoLink_withContent()
+ {
+ $link = $this->advertising->getCampaignParametersForPromoLink('MyName', 'Installation_Start', 'MyContent');
+
+ $this->assertSame('pk_campaign=MyName&pk_medium=Installation_Start&pk_source=Piwik_App&pk_content=MyContent', $link);
+ }
+
+ private function buildAdvertising($config)
+ {
+ return new Advertising($this->pluginManager, $config);
+ }
+}