Advertising.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\ProfessionalServices; |
| 10 | |
| 11 | use Piwik\Plugin; |
| 12 | use Piwik\Config; |
| 13 | use Piwik\Url; |
| 14 | /** |
| 15 | * Advertising for providers of Professional Support for Piwik. |
| 16 | * |
| 17 | * Lets you for example check whether advertising is enabled, generate links for different landing pages etc. |
| 18 | * |
| 19 | * @since 2.16.0 |
| 20 | */ |
| 21 | class Advertising |
| 22 | { |
| 23 | public const CAMPAIGN_NAME_PROFESSIONAL_SERVICES = 'App_ProfessionalServices'; |
| 24 | /** |
| 25 | * @var Plugin\Manager |
| 26 | */ |
| 27 | private $pluginManager; |
| 28 | /** |
| 29 | * @var Config |
| 30 | */ |
| 31 | private $config; |
| 32 | public function __construct(Plugin\Manager $pluginManager, Config $config) |
| 33 | { |
| 34 | $this->pluginManager = $pluginManager; |
| 35 | $this->config = $config; |
| 36 | } |
| 37 | /** |
| 38 | * Returns true if it is ok to show some advertising in the Piwik UI. |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function areAdsForProfessionalServicesEnabled() |
| 42 | { |
| 43 | return self::isAdsEnabledInConfig($this->config->General); |
| 44 | } |
| 45 | /** |
| 46 | * Get URL for promoting Professional Services for Piwik |
| 47 | * |
| 48 | * @param string $campaignMedium |
| 49 | * @param string $campaignContent |
| 50 | * @return string |
| 51 | */ |
| 52 | public function getPromoUrlForProfessionalServices($campaignMedium, $campaignContent = '') |
| 53 | { |
| 54 | return Url::addCampaignParametersToMatomoLink('https://matomo.org/support-plans/', self::CAMPAIGN_NAME_PROFESSIONAL_SERVICES, null, $campaignMedium); |
| 55 | } |
| 56 | /** |
| 57 | * Appends campaign parameters to the given URL for promoting any Professional Support for Piwik service. |
| 58 | * |
| 59 | * @param string $url |
| 60 | * @param string $campaignName |
| 61 | * @param string $campaignMedium |
| 62 | * @param string $campaignContent |
| 63 | * @param string $campaignSource |
| 64 | * @return string |
| 65 | */ |
| 66 | public function addPromoCampaignParametersToUrl($url, $campaignName, $campaignMedium, $campaignContent = '', $campaignSource = null) |
| 67 | { |
| 68 | if (empty($url)) { |
| 69 | return ''; |
| 70 | } |
| 71 | return Url::addCampaignParametersToMatomoLink($url, $campaignName, $campaignSource, $campaignMedium . ($campaignContent !== '' ? '.' . $campaignContent : '')); |
| 72 | } |
| 73 | /** |
| 74 | * @deprecated |
| 75 | * Generates campaign URL parameters that can be used with promoting Professional Support service. |
| 76 | * |
| 77 | * @param string $campaignName |
| 78 | * @param string $campaignMedium |
| 79 | * @param string $campaignContent Optional |
| 80 | * @return string URL parameters without a leading ? or & |
| 81 | */ |
| 82 | private function getCampaignParametersForPromoUrl($campaignName, $campaignMedium, $campaignContent = '') |
| 83 | { |
| 84 | $campaignName = sprintf('pk_campaign=%s&pk_medium=%s&pk_source=Matomo_App', $campaignName, $campaignMedium); |
| 85 | if (!empty($campaignContent)) { |
| 86 | $campaignName .= '&pk_content=' . $campaignContent; |
| 87 | } |
| 88 | return $campaignName; |
| 89 | } |
| 90 | /** |
| 91 | * @param $configGeneralSection |
| 92 | * @return bool |
| 93 | */ |
| 94 | public static function isAdsEnabledInConfig($configGeneralSection) |
| 95 | { |
| 96 | $oldSettingValue = \false; |
| 97 | if (isset($configGeneralSection['piwik_pro_ads_enabled'])) { |
| 98 | $oldSettingValue = @$configGeneralSection['piwik_pro_ads_enabled']; |
| 99 | } |
| 100 | $newSettingValue = @$configGeneralSection['piwik_professional_support_ads_enabled']; |
| 101 | return (bool) ($newSettingValue || $oldSettingValue); |
| 102 | } |
| 103 | } |
| 104 |