From f3d040adbd7decdd2cdd93d83f0dbf1833b1429f Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 3 Jul 2023 11:29:46 +0200 Subject: [PATCH 01/35] refactor site content detection and no data page --- core/SiteContentDetector.php | 137 +++++------ plugins/Installation/Controller.php | 2 - plugins/SitesManager/Controller.php | 223 +++++++++--------- plugins/SitesManager/GtmSiteTypeGuesser.php | 186 --------------- .../SiteContentDetection/Cloudflare.php | 77 ++++++ .../SiteContentDetection/Drupal.php | 45 ++++ .../SiteContentDetection/GoogleAnalytics3.php | 48 ++++ .../SiteContentDetection/GoogleAnalytics4.php | 45 ++++ .../SiteContentDetection/GoogleTagManager.php | 96 ++++++++ .../SiteContentDetection/Joomla.php | 40 ++++ .../SiteContentDetection/MatomoTagManager.php | 68 ++++++ .../SiteContentDetection/ReactJs.php | 99 ++++++++ .../SiteContentDetection/Sharepoint.php | 35 +++ .../SiteContentDetection/Shopify.php | 35 +++ .../SiteContentDetectionAbstract.php | 102 ++++++++ .../SiteContentDetection/SpaPwa.php | 60 +++++ .../SiteContentDetection/Squarespace.php | 35 +++ .../SiteContentDetection/VueJs.php | 121 ++++++++++ .../SiteContentDetection/Webflow.php | 35 +++ .../SitesManager/SiteContentDetection/Wix.php | 35 +++ .../SiteContentDetection/Wordpress.php | 92 ++++++++ plugins/SitesManager/SitesManager.php | 73 +----- .../templates/_cloudflareTabInstructions.twig | 25 ++ .../templates/_gtmTabInstructions.twig | 9 + .../templates/_siteWithoutDataTabs.twig | 191 ++------------- plugins/SitesManager/templates/_spa.twig | 6 - .../templates/_trackingCodeEmail.twig | 14 +- .../templates/_vueTabInstructions.twig | 9 + .../templates/_wordpressTabInstructions.twig | 4 + .../PHPUnit/Unit/SiteContentDetectorTest.php | 52 +--- 30 files changed, 1334 insertions(+), 665 deletions(-) delete mode 100644 plugins/SitesManager/GtmSiteTypeGuesser.php create mode 100644 plugins/SitesManager/SiteContentDetection/Cloudflare.php create mode 100644 plugins/SitesManager/SiteContentDetection/Drupal.php create mode 100644 plugins/SitesManager/SiteContentDetection/GoogleAnalytics3.php create mode 100644 plugins/SitesManager/SiteContentDetection/GoogleAnalytics4.php create mode 100644 plugins/SitesManager/SiteContentDetection/GoogleTagManager.php create mode 100644 plugins/SitesManager/SiteContentDetection/Joomla.php create mode 100644 plugins/SitesManager/SiteContentDetection/MatomoTagManager.php create mode 100644 plugins/SitesManager/SiteContentDetection/ReactJs.php create mode 100644 plugins/SitesManager/SiteContentDetection/Sharepoint.php create mode 100644 plugins/SitesManager/SiteContentDetection/Shopify.php create mode 100644 plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php create mode 100644 plugins/SitesManager/SiteContentDetection/SpaPwa.php create mode 100644 plugins/SitesManager/SiteContentDetection/Squarespace.php create mode 100644 plugins/SitesManager/SiteContentDetection/VueJs.php create mode 100644 plugins/SitesManager/SiteContentDetection/Webflow.php create mode 100644 plugins/SitesManager/SiteContentDetection/Wix.php create mode 100644 plugins/SitesManager/SiteContentDetection/Wordpress.php create mode 100644 plugins/SitesManager/templates/_cloudflareTabInstructions.twig delete mode 100644 plugins/SitesManager/templates/_spa.twig diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index d551164c2f5..14a7f82932a 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -12,7 +12,11 @@ use Matomo\Cache\Lazy; use Piwik\Config\GeneralConfig; -use Piwik\Plugins\SitesManager\GtmSiteTypeGuesser; +use Piwik\Container\StaticContainer; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\Plugins\SitesManager\SitesManager; /** @@ -48,13 +52,16 @@ class SiteContentDetector public $consentManagerName; // Display name of the detected consent manager, eg. 'Osano' public $consentManagerUrl; // Url for the configuration guide for the detected consent manager public $isConnected = false; // True if the detected consent manager is already connected with Matomo - public $ga3; // True if GA3 was detected on the site - public $ga4; // True if GA4 was detected on the site - public $gtm; // True if GTM was detected on the site - public $cms; // The CMS that was detected on the site - public $cloudflare; // true if website is hosted on cloudflare - public $jsFramework; // The JS framework that was detected on the site + /** + * @var array> + */ + public $detectedContent = [ + SiteContentDetectionAbstract::TYPE_TRACKER => [], + SiteContentDetectionAbstract::TYPE_CMS => [], + SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK => [], + SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER => [], + ]; private $siteResponse = [ 'data' => '', 'headers' => [] @@ -63,11 +70,6 @@ class SiteContentDetector /** @var Lazy */ private $cache; - /** - * @var GtmSiteTypeGuesser - */ - private $siteGuesser; - public function __construct(?Lazy $cache = null) { if ($cache === null) { @@ -75,7 +77,47 @@ public function __construct(?Lazy $cache = null) } else { $this->cache = $cache; } - $this->siteGuesser = new GtmSiteTypeGuesser(); + } + + + /** + * @return array + */ + public function getSiteContentDetectionsByType() + { + $instancesByType = []; + $classes = $this->getAllSiteContentDetectionClasses(); + + foreach ($classes as $className) { + $instancesByType[$className::getContentType()][] = StaticContainer::get($className); + } + + return $instancesByType; + } + + /** + * @param string $id + * @return SiteContentDetectionAbstract|null + */ + public function getSiteContentDetectionById(string $id): ?SiteContentDetectionAbstract + { + $classes = $this->getAllSiteContentDetectionClasses(); + + foreach ($classes as $className) { + if ($className::getId() === $id) { + return StaticContainer::get($className); + } + } + + return null; + } + + /** + * @return string[] + */ + protected function getAllSiteContentDetectionClasses(): array + { + return Plugin\Manager::getInstance()->findMultipleComponents('SiteContentDetection', SiteContentDetectionAbstract::class); } /** @@ -89,12 +131,6 @@ private function resetDetectionProperties(): void $this->consentManagerUrl = null; $this->consentManagerName = null; $this->isConnected = false; - $this->ga3 = false; - $this->ga4 = false; - $this->gtm = false; - $this->cms = SitesManager::SITE_TYPE_UNKNOWN; - $this->cloudflare = false; - $this->jsFramework = SitesManager::JS_FRAMEWORK_UNKNOWN; } /** @@ -181,26 +217,6 @@ private function getRequiredProperties(array $detectContent): array $requiredProperties = array_merge($requiredProperties, ['consentManagerId', 'consentManagerName', 'consentManagerUrl', 'isConnected']); } - if (in_array(SiteContentDetector::GA3, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $requiredProperties[] = 'ga3'; - } - - if (in_array(SiteContentDetector::GA4, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $requiredProperties[] = 'ga4'; - } - - if (in_array(SiteContentDetector::GTM, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $requiredProperties[] = 'gtm'; - } - - if (in_array(SiteContentDetector::CMS, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $requiredProperties[] = 'cms'; - } - - if (in_array(SiteContentDetector::JS_FRAMEWORK, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $requiredProperties[] = 'jsFramework'; - } - return $requiredProperties; } @@ -282,35 +298,20 @@ private function detectionChecks($detectContent): void $this->detectConsentManager(); } - if (in_array(SiteContentDetector::GA3, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $this->ga3 = $this->siteGuesser->detectGA3FromResponse($this->siteResponse); - } - - if (in_array(SiteContentDetector::GA4, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $this->ga4 = $this->siteGuesser->detectGA4FromResponse($this->siteResponse); - } - - if (in_array(SiteContentDetector::GTM, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $this->gtm = $this->siteGuesser->guessGtmFromResponse($this->siteResponse); - } - - if (in_array(SiteContentDetector::CMS, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $this->cms = $this->siteGuesser->guessSiteTypeFromResponse($this->siteResponse); - } - - if (in_array(SiteContentDetector::JS_FRAMEWORK, $detectContent) || in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) { - $this->jsFramework = $this->siteGuesser->guessJsFrameworkFromResponse($this->siteResponse); - } - - if ( - (!empty($this->siteResponse['headers']['server']) && stripos($this->siteResponse['headers']['server'], 'cloudflare') !== false) || - (!empty($this->siteResponse['headers']['Server']) && stripos($this->siteResponse['headers']['Server'], 'cloudflare') !== false) || - (!empty($this->siteResponse['headers']['SERVER']) && stripos($this->siteResponse['headers']['SERVER'], 'cloudflare') !== false) || - !empty($this->siteResponse['headers']['cf-ray']) || - !empty($this->siteResponse['headers']['Cf-Ray']) || - !empty($this->siteResponse['headers']['CF-RAY']) - ) { - $this->cloudflare = true; + $detections = $this->getSiteContentDetectionsByType(); + + foreach ($detections as $type => $typeDetections) { + foreach ($typeDetections as $typeDetection) { + if (in_array($type, $detectContent) || + in_array($typeDetection::getId(), $detectContent) || + in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) + { + if (!$typeDetection->showInstructionTabOnlyOnDetection() || + $typeDetection->detectSiteByContent($this->siteResponse['data'], $this->siteResponse['headers'])) { + $this->detectedContent[$type][] = $typeDetection::getId(); + } + } + } } } diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index 04ab0a06096..cb84af57137 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -411,7 +411,6 @@ public function trackingCode() 'ga3Used' => $this->siteContentDetector->ga3, 'ga4Used' => $this->siteContentDetector->ga4, 'cloudflare' => $this->siteContentDetector->cloudflare, - 'jsFramework' => $this->siteContentDetector->jsFramework, 'consentManagerName' => $this->siteContentDetector->consentManagerName, 'consentManagerUrl' => $this->siteContentDetector->consentManagerUrl, 'consentManagerIsConnected' => $this->siteContentDetector->isConnected @@ -430,7 +429,6 @@ public function trackingCode() $viewTrackingHelp->ga3Used = $this->siteContentDetector->ga3; $viewTrackingHelp->ga4Used = $this->siteContentDetector->ga4; $viewTrackingHelp->cloudflare = $this->siteContentDetector->cloudflare; - $viewTrackingHelp->jsFramework = $this->siteContentDetector->jsFramework; $viewTrackingHelp->consentManagerName = $this->siteContentDetector->consentManagerName; $viewTrackingHelp->consentManagerUrl = $this->siteContentDetector->consentManagerUrl; $viewTrackingHelp->consentManagerIsConnected = $this->siteContentDetector->isConnected; diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 3921a25a44c..4b2a98d62ca 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -20,6 +20,14 @@ use Piwik\Plugin; use Piwik\Plugins\CustomVariables\CustomVariables; use Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker; +use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\ReactJs; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; +use Piwik\Plugins\SitesManager\SiteContentDetection\VueJs; +use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; use Piwik\Site; use Piwik\SiteContentDetector; use Piwik\Session; @@ -27,22 +35,17 @@ use Piwik\Tracker\TrackerCodeGenerator; use Piwik\Translation\Translator; use Piwik\Url; -use Matomo\Cache\Lazy; /** * */ class Controller extends \Piwik\Plugin\ControllerAdmin { - /** @var Lazy */ - private $cache; - /** @var SiteContentDetector */ private $siteContentDetector; - public function __construct(Lazy $cache, SiteContentDetector $siteContentDetector) + public function __construct(SiteContentDetector $siteContentDetector) { - $this->cache = $cache; $this->siteContentDetector = $siteContentDetector; parent::__construct(); @@ -163,25 +166,16 @@ public function siteWithoutData() 'trackingUrl' => $trackingUrl, 'idSite' => $this->idSite, 'consentManagerName' => false, - 'cloudflare' => false, - 'ga3Used' => false, - 'ga4Used' => false, - 'gtmUsed' => false, - 'cms' => false, - 'jsFramework' => false, ]; - $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT]); + $this->siteContentDetector->detectContent(); if ($this->siteContentDetector->consentManagerId) { $emailTemplateData['consentManagerName'] = $this->siteContentDetector->consentManagerName; $emailTemplateData['consentManagerUrl'] = $this->siteContentDetector->consentManagerUrl; } - $emailTemplateData['ga3Used'] = $this->siteContentDetector->ga3; - $emailTemplateData['ga4Used'] = $this->siteContentDetector->ga4; - $emailTemplateData['gtmUsed'] = $this->siteContentDetector->gtm; - $emailTemplateData['cloudflare'] = $this->siteContentDetector->cloudflare; - $emailTemplateData['cms'] = $this->siteContentDetector->cms; - $emailTemplateData['jsFramework'] = $this->siteContentDetector->jsFramework; + $emailTemplateData['cms'] = $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS]; + $emailTemplateData['jsFrameworks'] = $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK]; + $emailTemplateData['trackers'] = $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER]; $emailContent = $this->renderTemplateAs('@SitesManager/_trackingCodeEmail', $emailTemplateData, $viewType = 'basic'); $inviteUserLink = $this->getInviteUserLink(); @@ -192,7 +186,6 @@ public function siteWithoutData() 'piwikUrl' => $piwikUrl, 'emailBody' => $emailContent, 'siteWithoutDataStartTrackingTranslationKey' => StaticContainer::get('SitesManager.SiteWithoutDataStartTrackingTranslation'), - 'SiteWithoutDataVueFollowStepNote2Key' => StaticContainer::get('SitesManager.SiteWithoutDataVueFollowStepNote2'), 'inviteUserLink' => $inviteUserLink ], $viewType = 'basic'); } @@ -227,10 +220,6 @@ public function siteWithoutDataTabs() Piwik::postEvent('SitesManager.siteWithoutData.customizeImporterMessage', [&$googleAnalyticsImporterMessage]); } - $tagManagerActive = false; - if (Manager::getInstance()->isPluginActivated('TagManager')) { - $tagManagerActive = true; - } $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT], $this->idSite); $dntChecker = new DoNotTrackHeaderChecker(); @@ -240,18 +229,12 @@ public function siteWithoutDataTabs() 'jsTag' => $jsTag, 'piwikUrl' => $piwikUrl, 'showMatomoLinks' => $showMatomoLinks, - 'siteType' => $this->siteContentDetector->cms, - 'instruction' => SitesManager::getInstructionByCms($this->siteContentDetector->cms), - 'gtmUsed' => $this->siteContentDetector->gtm, - 'ga3Used' => $this->siteContentDetector->ga3, - 'ga4Used' => $this->siteContentDetector->ga4, + 'cms' => $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS], + 'trackers' => $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER], + 'jsFrameworks' => $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK], + 'instruction' => $this->getCmsInstruction(), 'googleAnalyticsImporterMessage' => $googleAnalyticsImporterMessage, - 'tagManagerActive' => $tagManagerActive, 'consentManagerName' => false, - 'cloudflare' => $this->siteContentDetector->cloudflare, - 'jsFramework' => $this->siteContentDetector->jsFramework, - 'cms' => $this->siteContentDetector->cms, - 'SiteWithoutDataVueFollowStepNote2Key' => StaticContainer::get('SitesManager.SiteWithoutDataVueFollowStepNote2'), 'defaultSiteDecoded' => [ 'id' => $this->idSite, 'name' => Common::unsanitizeInputValue(Site::getNameFor($this->idSite)), @@ -261,42 +244,109 @@ public function siteWithoutDataTabs() 'isJsTrackerInstallCheckAvailable' => Manager::getInstance()->isPluginActivated('JsTrackerInstallCheck'), ]; - $templateData['showGAImportTab'] = $this->shouldShowGAImportTab($templateData); - if ($this->siteContentDetector->consentManagerId) { $templateData['consentManagerName'] = $this->siteContentDetector->consentManagerName; $templateData['consentManagerUrl'] = $this->siteContentDetector->consentManagerUrl; $templateData['consentManagerIsConnected'] = $this->siteContentDetector->isConnected; } - $templateData['activeTab'] = $this->getActiveTabOnLoad($templateData); - - if ($this->siteContentDetector->jsFramework === SitesManager::JS_FRAMEWORK_VUE) { - $templateData['vue3Code'] = $this->getVueInitializeCode(3); - $templateData['vue2Code'] = $this->getVueInitializeCode(2); + $templateData['tabs'] = []; + $templateData['instructionUrls'] = []; + $templateData['othersInstructions'] = []; + + foreach ($this->siteContentDetector->getSiteContentDetectionsByType() as $detections) { + foreach ($detections as $obj) { + $tabContent = $obj->renderInstructionsTab(); + $othersInstruction = $obj->renderOthersInstruction(); + $instructionUrl = $obj->getInstructionUrl(); + + Piwik::postEvent('Template.siteWithoutDataTab.' . $obj::getId() . '.content', [&$tabContent]); + + if (!empty($tabContent) && in_array($obj::getId(), $this->siteContentDetector->detectedContent[$obj::getContentType()])) { + $templateData['tabs'][] = [ + 'id' => $obj::getId(), + 'name' => $obj::getName(), + 'type' => $obj::getContentType(), + 'content' => $tabContent, + 'priority' => $obj::getPriority(), + ]; + } + + if (!empty($othersInstruction)) { + $templateData['othersInstructions'][] = [ + 'id' => $obj::getId(), + 'name' => $obj::getName(), + 'type' => $obj::getContentType(), + 'othersInstruction' => $obj->renderOthersInstruction(), + ]; + } + + if (!empty($instructionUrl)) { + $templateData['instructionUrls'][] = [ + 'id' => $obj::getId(), + 'name' => $obj::getName(), + 'type' => $obj::getContentType(), + 'instructionUrl' => $obj::getInstructionUrl(), + ]; + } + } } + usort($templateData['tabs'], function($a, $b) { + return strcmp($a['priority'], $b['priority']); + }); + + usort($templateData['othersInstructions'], function($a, $b) { + return strnatcmp($a['name'], $b['name']); + }); + + usort($templateData['instructionUrls'], function($a, $b) { + return strnatcmp($a['name'], $b['name']); + }); + + $templateData['activeTab'] = $this->getActiveTabOnLoad($templateData); $this->mergeMultipleNotification($templateData); return $this->renderTemplateAs('_siteWithoutDataTabs', $templateData, $viewType = 'basic'); } + private function getCmsInstruction() + { + if (empty($this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS]) + || in_array(Wordpress::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS])) { + return ''; + } + + $detectedCms = $this->siteContentDetector->getSiteContentDetectionById(reset($this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS])); + + if (null === $detectedCms) { + return ''; + } + + Piwik::translate( + 'SitesManager_SiteWithoutDataDetectedSite', + [ + $detectedCms::getName(), + '', + '' + ] + ); + } + private function getActiveTabOnLoad($templateData) { $tabToDisplay = ''; - if (!empty($templateData['gtmUsed'])) { - $tabToDisplay = 'gtm'; - } else if (!empty($templateData['cms']) && $templateData['cms'] === SitesManager::SITE_TYPE_WORDPRESS) { - $tabToDisplay = 'wordpress'; - } else if (!empty($templateData['showGAImportTab'])) { - $tabToDisplay = 'ga-import'; - } else if (!empty($templateData['cloudflare'])) { - $tabToDisplay = 'cloudflare'; - } else if (!empty($templateData['jsFramework']) && $templateData['jsFramework'] === SitesManager::JS_FRAMEWORK_VUE) { - $tabToDisplay = 'vue'; - } else if (!empty($templateData['jsFramework']) && $templateData['jsFramework'] === SitesManager::JS_FRAMEWORK_REACT && Manager::getInstance()->isPluginActivated('TagManager')) { - $tabToDisplay = 'react'; + if (!empty(in_array(GoogleTagManager::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER]))) { + $tabToDisplay = GoogleTagManager::getId(); + } else if (in_array(Wordpress::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS])) { + $tabToDisplay = Wordpress::getId(); + } else if (in_array(Cloudflare::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_CMS])) { + $tabToDisplay = Cloudflare::getId(); + } else if (in_array(VueJs::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK])) { + $tabToDisplay = VueJs::getId(); + } else if (in_array(ReactJs::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER]) && Manager::getInstance()->isPluginActivated('TagManager')) { + $tabToDisplay = ReactJs::getId(); } else if (!empty($templateData['consentManagerName'])) { $tabToDisplay = 'consentManager'; } @@ -319,60 +369,16 @@ private function getInviteUserLink() ]); } - private function getVueInitializeCode($vueVersion = '3') - { - $request = \Piwik\Request::fromRequest(); - $piwikUrl = Url::getCurrentUrlWithoutFileName(); - $siteId = $request->getIntegerParameter('idSite', 1); - $configureComment = Piwik::translate('SitesManager_SiteWithoutDataVueFollowStep2ExampleCodeCommentConfigureMatomo'); - $trackViewComment = Piwik::translate('SitesManager_SiteWithoutDataVueFollowStep2ExampleCodeCommentTrackPageView'); - if ($vueVersion == 2) { - return <<siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER]); + $ga4Used = in_array(GoogleAnalytics4::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER]); - if ($templateData['ga3Used'] || $templateData['ga4Used']) { + if ($ga3Used || $ga4Used) { $message[0] = 'Google Analytics '; $ga3GuideUrl = 'Google Analytics 3'; $ga4GuideUrl = 'Google Analytics 4'; @@ -382,8 +388,8 @@ private function mergeMultipleNotification(&$templateData) $guides[] = $ga4GuideUrl; $message[0] .= '3 & 4'; } else { - $message[0] .= ($templateData['ga3Used'] ? 3 : 4); - $guides[] = ($templateData['ga3Used'] ? $ga3GuideUrl : $ga4GuideUrl); + $message[0] .= ($ga3Used ? 3 : 4); + $guides[] = ($ga3Used ? $ga3GuideUrl : $ga4GuideUrl); } } @@ -421,21 +427,12 @@ private function getSingleNotifications(&$templateData) if (!empty($templateData['consentManagerIsConnected'])) { $info['notificationMessage'] .= '

' . Piwik::translate('SitesManager_ConsentManagerConnected', [$templateData['consentManagerName']]) . '

'; } - } else if (!empty($templateData['ga3Used'])) { + } else if (in_array(GoogleAnalytics3::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER])) { $info['notificationMessage'] = '

' . Piwik::translate('SitesManager_GADetected', ['Google Analytics 3', 'GA', '', '', '', '']) . '

'; - } else if (!empty($templateData['ga4Used'])) { + } else if (in_array(GoogleAnalytics4::getId(), $this->siteContentDetector->detectedContent[SiteContentDetectionAbstract::TYPE_TRACKER])) { $info['notificationMessage'] = '

' . Piwik::translate('SitesManager_GADetected', ['Google Analytics 4', 'GA', '', '', '', '']) . '

'; } return $info; } - - private function shouldShowGAImportTab($templateData) - { - if (Piwik::hasUserSuperUserAccess() && Manager::getInstance()->isPluginActivated('GoogleAnalyticsImporter') && (!empty($templateData['ga3Used']) || !empty($templateData['ga4Used']))) { - return true; - } - - return false; - } } diff --git a/plugins/SitesManager/GtmSiteTypeGuesser.php b/plugins/SitesManager/GtmSiteTypeGuesser.php deleted file mode 100644 index 6cb02c67f85..00000000000 --- a/plugins/SitesManager/GtmSiteTypeGuesser.php +++ /dev/null @@ -1,186 +0,0 @@ -'; - if (strpos($response['data'], $needle) !== false) { - return SitesManager::SITE_TYPE_SQUARESPACE; - } - - $needle = 'X-Wix-Published-Version'; - if (strpos($response['data'], $needle) !== false) { - return SitesManager::SITE_TYPE_WIX; - } - - // https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Application/WebApplication.php#L516 - // Joomla was the outcome of a fork of Mambo on 17 August 2005 - https://en.wikipedia.org/wiki/Joomla - if (isset($response['headers']['expires']) && $response['headers']['expires'] === 'Wed, 17 Aug 2005 00:00:00 GMT') { - return SitesManager::SITE_TYPE_JOOMLA; - } - - $needle = 'Shopify.theme'; - if (strpos($response['data'], $needle) !== false) { - return SitesManager::SITE_TYPE_SHOPIFY; - } - - $needle = 'content="Microsoft SharePoint'; - if (strpos($response['data'], $needle) !== false) { - return SitesManager::SITE_TYPE_SHAREPOINT; - } - - $needle = 'idSite = Request::fromRequest()->getIntegerParameter('idSite'); + $view->sendHeadersWhenRendering = false; + return $view->render(); + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataCloudflareDescription', + [ + '', + '' + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/Drupal.php b/plugins/SitesManager/SiteContentDetection/Drupal.php new file mode 100644 index 00000000000..64c1d82ff98 --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/Drupal.php @@ -0,0 +1,45 @@ + \Piwik\Request::fromRequest()->getIntegerParameter('idSite'), + 'piwikUrl' => $piwikUrl + ] + ); + $view = new View('@SitesManager/_gtmTabInstructions'); + $view->jsTag = $jsTag; + $view->sendHeadersWhenRendering = false; + return $view->render(); + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataGoogleTagManagerDescription', + [ + '', + '' + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/Joomla.php b/plugins/SitesManager/SiteContentDetection/Joomla.php new file mode 100644 index 00000000000..23eb9e45552 --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/Joomla.php @@ -0,0 +1,40 @@ +' . Piwik::translate('SitesManager_SiteWithoutDataMatomoTagManager') . ' +

' . Piwik::translate( 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive', ['', '']) . '

'; + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataGoogleTagManagerDescription', + [ + '', + '' + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/ReactJs.php b/plugins/SitesManager/SiteContentDetection/ReactJs.php new file mode 100644 index 00000000000..a916d7b0eba --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/ReactJs.php @@ -0,0 +1,99 @@ +

+
+ ' . Piwik::translate( + 'SitesManager_ReactDetected', + [ + '', + '', + '', + '' + ] + ) . ' +
+ +
+ +
+'; + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataReactDescription', + [ + '', + '', + '', + '', + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/Sharepoint.php b/plugins/SitesManager/SiteContentDetection/Sharepoint.php new file mode 100644 index 00000000000..f7732afd566 --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/Sharepoint.php @@ -0,0 +1,35 @@ +%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataSinglePageApplicationDescription', + [ + '', + '', + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/Squarespace.php b/plugins/SitesManager/SiteContentDetection/Squarespace.php new file mode 100644 index 00000000000..10ef92468f0 --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/Squarespace.php @@ -0,0 +1,35 @@ +'; + return (strpos($data, $needle) !== false); + } +} diff --git a/plugins/SitesManager/SiteContentDetection/VueJs.php b/plugins/SitesManager/SiteContentDetection/VueJs.php new file mode 100644 index 00000000000..f44d30b9a0f --- /dev/null +++ b/plugins/SitesManager/SiteContentDetection/VueJs.php @@ -0,0 +1,121 @@ +sendHeadersWhenRendering = false; + $view->SiteWithoutDataVueFollowStepNote2Key = StaticContainer::get('SitesManager.SiteWithoutDataVueFollowStepNote2'); + $view->vue3Code = $this->getVueInitializeCode(3); + $view->vue2Code = $this->getVueInitializeCode(2); + return $view->render(); + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataVueDescription', + [ + 'vue-matomo', + '', + '' + ] + ) + ); + } + + private function getVueInitializeCode($vueVersion = '3') + { + $request = \Piwik\Request::fromRequest(); + $piwikUrl = Url::getCurrentUrlWithoutFileName(); + $siteId = $request->getIntegerParameter('idSite', 1); + $configureComment = Piwik::translate('SitesManager_SiteWithoutDataVueFollowStep2ExampleCodeCommentConfigureMatomo'); + $trackViewComment = Piwik::translate('SitesManager_SiteWithoutDataVueFollowStep2ExampleCodeCommentTrackPageView'); + if ($vueVersion == 2) { + return <<getIntegerParameter('idSite', 0); + $period = $request->getStringParameter('period', 'day'); + $date = $request->getStringParameter('date', 'yesterday'); + $authLink = SettingsPiwik::getPiwikUrl() . 'index.php?' . + Url::getQueryStringFromParameters([ + 'idSite' => $idSite, + 'date' => $date, + 'period' => $period, + 'module' => 'UsersManager', + 'action' => 'addNewToken', + ]); + } + $view->authLink = $authLink; + $view->faqLink = $faqLink; + $view->sendHeadersWhenRendering = false; + $view->site = ['id' => $idSite, 'name' => '']; + $view->isJsTrackerInstallCheckAvailable = Manager::getInstance()->isPluginActivated('JsTrackerInstallCheck'); + return $view->render(); + } + + public function renderOthersInstruction(): string + { + return sprintf( + '

%s

', + Piwik::translate( + 'SitesManager_SiteWithoutDataWordpressDescription', + [ + '', + '', + ] + ) + ); + } +} diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index aff32dc11c6..b4e22df8110 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -20,6 +20,8 @@ use Piwik\Piwik; use Piwik\Plugin\Manager; use Piwik\Plugins\CoreHome\SystemSummary; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; +use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; use Piwik\Settings\Storage\Backend\MeasurableSettingsTable; use Piwik\SettingsPiwik; use Piwik\Tracker\Cache; @@ -46,7 +48,6 @@ class SitesManager extends \Piwik\Plugin const SITE_TYPE_SHOPIFY = 'shopify'; const SITE_TYPE_WEBFLOW = 'webflow'; const SITE_TYPE_DRUPAL = 'drupal'; - const JS_FRAMEWORK_UNKNOWN = 'unknown'; const JS_FRAMEWORK_VUE = 'vue'; const JS_FRAMEWORK_REACT = 'react'; @@ -63,8 +64,6 @@ public function registerEvents() 'SitesManager.deleteSite.end' => 'onSiteDeleted', 'System.addSystemSummaryItems' => 'addSystemSummaryItems', 'Request.dispatch' => 'redirectDashboardToWelcomePage', - 'Template.noDataPageGTMTabInstructions' => 'noDataPageGTMTabInstructions', - 'Template.noDataPageWordpressTabInstructions' => 'noDataPageWordpressTabInstructions', ]; } @@ -376,38 +375,6 @@ private function getTrackerHosts($urls) return $hosts; } - public static function getInstructionUrlBySiteType($siteType) - { - $map = [ - self::SITE_TYPE_JOOMLA => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-joomla', - self::SITE_TYPE_SHAREPOINT => 'https://matomo.org/faq/how-to-install/faq_19424', - self::SITE_TYPE_SHOPIFY => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-shopify-store', - self::SITE_TYPE_SQUARESPACE => 'https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website', - self::SITE_TYPE_WIX => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix', - self::SITE_TYPE_WORDPRESS => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/', - self::SITE_TYPE_DRUPAL => 'https://matomo.org/faq/new-to-piwik/how-to-integrate-with-drupal/', - self::SITE_TYPE_WEBFLOW => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-webflow', - ]; - - return $map[$siteType] ?? false; - } - - public static function getInstructionByCms(?string $cms): string - { - if ($cms === self::SITE_TYPE_UNKNOWN || $cms === self::SITE_TYPE_WORDPRESS) { - return ''; - } - - return Piwik::translate( - 'SitesManager_SiteWithoutDataDetectedSite', - [ - ucfirst($cms), - '', - '' - ] - ); - } - public function getClientSideTranslationKeys(&$translationKeys) { $translationKeys[] = "General_Save"; @@ -525,40 +492,4 @@ public function getClientSideTranslationKeys(&$translationKeys) $translationKeys[] = "SitesManager_SiteWithoutDataVueDescription"; $translationKeys[] = "SitesManager_SiteWithoutDataReactDescription"; } - - public function noDataPageGTMTabInstructions(&$out) - { - Piwik::checkUserHasSomeViewAccess(); - $piwikUrl = Url::getCurrentUrlWithoutFileName(); - $jsTag = Request::processRequest('SitesManager.getJavascriptTag', ['idSite' => Common::getRequestVar('idSite'), 'piwikUrl' => $piwikUrl]); - $view = new View("@SitesManager/_gtmTabInstructions"); - $view->jsTag = $jsTag; - $out = $view->render(); - } - - public function noDataPageWordpressTabInstructions(&$out) - { - Piwik::checkUserHasSomeViewAccess(); - $view = new View("@SitesManager/_wordpressTabInstructions"); - $faqLink = 'https://matomo.org/faq/general/faq_114/'; - $authLink = ''; - if (Piwik::isUserHasSomeViewAccess()) { - $request = \Piwik\Request::fromRequest(); - $idSite = $request->getIntegerParameter('idSite', 0); - $period = $request->getStringParameter('period', 'day'); - $date = $request->getStringParameter('date', 'yesterday'); - $authLink = SettingsPiwik::getPiwikUrl() . 'index.php?' . Url::getQueryStringFromParameters([ - 'idSite' => $idSite, - 'date' => $date, - 'period' => $period, - 'module' => 'UsersManager', - 'action' => 'addNewToken', - ]); - } - $view->authLink = $authLink; - $view->faqLink = $faqLink; - $view->site = ['id' => $idSite, 'name' => '']; - $view->isJsTrackerInstallCheckAvailable = Manager::getInstance()->isPluginActivated('JsTrackerInstallCheck'); - $out = $view->render(); - } } diff --git a/plugins/SitesManager/templates/_cloudflareTabInstructions.twig b/plugins/SitesManager/templates/_cloudflareTabInstructions.twig new file mode 100644 index 00000000000..ed722e5de28 --- /dev/null +++ b/plugins/SitesManager/templates/_cloudflareTabInstructions.twig @@ -0,0 +1,25 @@ +

+
+ {{ 'SitesManager_CloudflareDetected'|translate('','')|raw }} +
+ +
+ +
+

{{ 'SitesManager_SiteWithoutDataCloudflareIntro'|translate }}

+
+

{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro'|translate }}

+
    +
  1. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep01'|translate('','')|raw }}
  2. +
  3. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep02'|translate }}
  4. +
  5. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep03'|translate }}
  6. +
  7. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep04'|translate }}
  8. +
  9. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep05'|translate }}
  10. +
  11. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep06'|translate }}
  12. +
  13. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep07'|translate }}
    Matomo URL: {{ piwikUrl }}
    {{ 'SitesManager_EmailInstructionsYourSiteId'|translate('' ~ idSite ~ '')|raw }}
  14. +
  15. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep08'|translate }}
  16. +
  17. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep09'|translate }}
  18. +
  19. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep10'|translate }}
  20. +
+
+

{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepCompleted'|translate('','')|raw }}

diff --git a/plugins/SitesManager/templates/_gtmTabInstructions.twig b/plugins/SitesManager/templates/_gtmTabInstructions.twig index 3b8d225c6f7..173e7762435 100644 --- a/plugins/SitesManager/templates/_gtmTabInstructions.twig +++ b/plugins/SitesManager/templates/_gtmTabInstructions.twig @@ -1,3 +1,12 @@ +

+
+ {{ 'SitesManager_GTMDetected'|translate('', '')|raw }} +
+ +
+ +
+

{{ 'SitesManager_SiteWithoutDataGoogleTagManagerIntro'|translate('','')|raw }}


{{ 'SitesManager_SiteWithoutDataGoogleTagManagerFollowStepsIntro'|translate }}

diff --git a/plugins/SitesManager/templates/_siteWithoutDataTabs.twig b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig index 2a59c731363..53afaba0007 100644 --- a/plugins/SitesManager/templates/_siteWithoutDataTabs.twig +++ b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig @@ -16,35 +16,18 @@ }); -{% set columnClass = activeTab ? 's2' : 's3' %} +{% set columnClass = tabs|length ? 's2' : 's3' %}
@@ -53,8 +36,8 @@ {% if instruction %}

{{ instruction|raw }}

- {% if gtmUsed %} -

{{ 'SitesManager_SiteWithoutDataDetectedGtm'|translate(siteType|capitalize, '','')|raw }}

+ {% if 'GoogleTagManager' in trackers %} +

{{ 'SitesManager_SiteWithoutDataDetectedGtm'|translate('','')|raw }}

{% endif %}

{{ 'SitesManager_SiteWithoutDataOtherIntegrations'|translate }}: {{ 'CoreAdminHome_JSTrackingIntro3a'|translate('','')|raw }}

@@ -62,16 +45,9 @@

{{ 'SitesManager_InstallationGuidesIntro'|translate }}

- WordPress - | Squarespace - | Wix - | SharePoint - | Joomla - | Shopify - | Google Tag Manager - | Cloudflare - | Vue - | React + {% for instructionUrl in instructionUrls %} + {% if not loop.first %} | {% endif %}{{ instructionUrl.name }} + {% endfor %}

{{ 'CoreAdminHome_JSTrackingIntro3a'|translate('','')|raw }}

@@ -101,116 +77,11 @@ >
-
- {% if tagManagerActive %} - {{ postEvent('Template.endTrackingCodePage') }} - {% else %} -

{{ 'SitesManager_SiteWithoutDataMatomoTagManager'|translate }}

-

{{ 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive'|translate('', '')|raw }}

- {% endif %} -
- - {% if gtmUsed %} -
- -

-
- {{ 'SitesManager_GTMDetected'|translate('', '')|raw }} -
- -
- -
- {{ postEvent('Template.noDataPageGTMTabInstructions') }} - -
- {% endif %} - - {% if cms == 'wordpress' %} -
- -
- -
- {{ postEvent('Template.noDataPageWordpressTabInstructions') }} - -
- {% endif %} - - {% if cloudflare %} -
- -

-
- {{ 'SitesManager_CloudflareDetected'|translate('','')|raw }} -
- -
- -
-

{{ 'SitesManager_SiteWithoutDataCloudflareIntro'|translate }}

-
-

{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro'|translate }}

-
    -
  1. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep01'|translate('','')|raw }}
  2. -
  3. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep02'|translate }}
  4. -
  5. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep03'|translate }}
  6. -
  7. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep04'|translate }}
  8. -
  9. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep05'|translate }}
  10. -
  11. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep06'|translate }}
  12. -
  13. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep07'|translate }}
    Matomo URL: {{ piwikUrl }}
    {{ 'SitesManager_EmailInstructionsYourSiteId'|translate('' ~ idSite ~ '')|raw }}
  14. -
  15. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep08'|translate }}
  16. -
  17. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep09'|translate }}
  18. -
  19. {{ 'SitesManager_SiteWithoutDataCloudflareFollowStep10'|translate }}
  20. -
-
-

{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepCompleted'|translate('','')|raw }}

-
- {% endif %} - - {% if jsFramework == 'vue' %} -
- -

-
- {{ 'SitesManager_VueDetected'|translate('vue-matomo','','')|raw }} -
- -
- -
- {% include '@SitesManager/_vueTabInstructions.twig' %} - + {% for tab in tabs %} +
+ {{ tab.content|raw }}
- {% endif %} - - {% if jsFramework == 'react' %} -
- -

-
- {{ 'SitesManager_ReactDetected'|translate('','','','')|raw }} -
- -
- -
- {{ postEvent('Template.embedReactTagManagerTrackingCode') }} - -
- {% endif %} - - {% if tagManagerActive %} -
- {% include '@SitesManager/_spa.twig' %} -
- {% endif %} - - {% if showGAImportTab %} -
- {{ postEvent('Template.embedGAImportNoData', ga3Used) }} -
- {% endif %} + {% endfor %}

{{ 'SitesManager_OtherWaysTabDescription'|translate }}

@@ -229,30 +100,10 @@

{{ 'CoreAdminHome_HttpTrackingApi'|translate }}

{{ 'CoreAdminHome_HttpTrackingApiDescription'|translate('','')|raw }}

- {% if not gtmUsed %} -

{{ 'SitesManager_SiteWithoutDataGoogleTagManager'|translate }}

-

{{ 'SitesManager_SiteWithoutDataGoogleTagManagerDescription'|translate('','')|raw }}

- {% endif %} - - {% if cms is not same as('wordpress') %} -

WordPress

-

{{ 'SitesManager_SiteWithoutDataWordpressDescription'|translate('','')|raw }}

- {% endif %} - - {% if not cloudflare %} -

Cloudflare

-

{{ 'SitesManager_SiteWithoutDataCloudflareDescription'|translate('','')|raw }}

- {% endif %} - - {% if jsFramework is not same as('vue') %} -

Vue.js

-

{{ 'SitesManager_SiteWithoutDataVueDescription'|translate('vue-matomo', '','')|raw }}

- {% endif %} - - {% if jsFramework is not same as('react') %} -

React.js

-

{{ 'SitesManager_SiteWithoutDataReactDescription'|translate('', '', '','')|raw }}

- {% endif %} + {% for othersInstruction in othersInstructions %} +

{{ othersInstruction.name }}

+

{{ othersInstruction.othersInstruction|raw }}

+ {% endfor %} {% if googleAnalyticsImporterMessage is defined and googleAnalyticsImporterMessage is not empty %} {{ googleAnalyticsImporterMessage|raw }} diff --git a/plugins/SitesManager/templates/_spa.twig b/plugins/SitesManager/templates/_spa.twig deleted file mode 100644 index e990fc7372b..00000000000 --- a/plugins/SitesManager/templates/_spa.twig +++ /dev/null @@ -1,6 +0,0 @@ -

{{ 'SitesManager_SiteWithoutDataSPADescription'|translate('', '', '', '')|raw }}

-
-

{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro'|translate }}

-{{ postEvent('Template.embedSPATagManagerTrackingCode') }} -
-

{{ 'SitesManager_SiteWithoutDataSPAFollowStepCompleted'|translate('','')|raw }}

\ No newline at end of file diff --git a/plugins/SitesManager/templates/_trackingCodeEmail.twig b/plugins/SitesManager/templates/_trackingCodeEmail.twig index 097e066f7bb..9241a5195f5 100644 --- a/plugins/SitesManager/templates/_trackingCodeEmail.twig +++ b/plugins/SitesManager/templates/_trackingCodeEmail.twig @@ -2,33 +2,33 @@ {{ 'CoreAdminHome_JSTracking_ConsentManagerDetected'|translate(consentManagerName, consentManagerUrl) }} {% endif %} -{% if ga3Used %} +{% if 'GoogleAnalytics3' in trackers %} {{ 'SitesManager_GADetectedEmail'|translate('Google Analytics 3', 'GA', 'https://matomo.org/faq/how-to/migrate-from-google-analytics-3-to-matomo/')|raw }} {% endif %} -{% if ga4Used %} +{% if 'GoogleAnalytics3' in trackers %} {{ 'SitesManager_GADetectedEmail'|translate('Google Analytics 4', 'GA', 'https://matomo.org/faq/how-to/migrate-from-google-analytics-4-to-matomo/')|raw }} {% endif %} -{% if gtmUsed %} +{% if 'GoogleTagManager' in trackers %} {{ 'SitesManager_GTMDetectedEmail'|translate('https://matomo.org/faq/tag-manager/migrating-from-google-tag-manager/')|raw }} {% endif %} -{% if cloudflare %} +{% if 'Cloudflare' in cms %} {{ 'SitesManager_CloudflareDetectedEmail'|translate('https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/')|raw }} {% endif %} -{% if jsFramework == 'vue' %} +{% if 'VueJs' in jsFrameworks %} {{ 'SitesManager_VueDetectedEmail'|translate('vue-matomo', 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-websites-that-use-vue-js/')|raw }} {% endif %} -{% if jsFramework == 'react' %} +{% if 'ReactJs' in jsFrameworks %} {{ 'SitesManager_ReactDetectedEmail'|translate('https://matomo.org/faq/new-to-piwik/how-do-i-start-tracking-data-with-matomo-on-websites-that-use-react/')|raw }} {% endif %} -{% if consentManagerName or ga3Used or ga4Used or gtmUsed or cloudflare or jsFramework == 'vue' %} +{% if consentManagerName or 'GoogleAnalytics3' in trackers or 'GoogleAnalytics4' in trackers or 'GoogleTagManager' in trackers or 'Cloudflare' in cms or 'VueJs' in jsFrameworks %} {{ 'CoreAdminHome_JSTracking_ConsentManagerEmailNote'|translate }} {% endif %} diff --git a/plugins/SitesManager/templates/_vueTabInstructions.twig b/plugins/SitesManager/templates/_vueTabInstructions.twig index 75e45810ee1..d015ac921c6 100644 --- a/plugins/SitesManager/templates/_vueTabInstructions.twig +++ b/plugins/SitesManager/templates/_vueTabInstructions.twig @@ -1,3 +1,12 @@ +

+
+ {{ 'SitesManager_VueDetected'|translate('vue-matomo','','')|raw }} +
+ +
+ +
+

{{ 'SitesManager_SiteWithoutDataVueIntro'|translate }}


{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro'|translate }}

diff --git a/plugins/SitesManager/templates/_wordpressTabInstructions.twig b/plugins/SitesManager/templates/_wordpressTabInstructions.twig index 8dcad8326b2..e21f8663812 100644 --- a/plugins/SitesManager/templates/_wordpressTabInstructions.twig +++ b/plugins/SitesManager/templates/_wordpressTabInstructions.twig @@ -1,3 +1,7 @@ +
+ +
+ A site'; @@ -26,8 +34,8 @@ public function test_detectsConsentManager_NotConnected() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertEquals('osano', $scd->consentManagerId); - $this->assertFalse($scd->isConnected); + self::assertTrue($scd->wasDetected(Osano::getId())); + self::assertNotContains(Osano::getId(), $scd->connectedContentManagers); } public function test_detectsConsentManager_Connected() @@ -36,8 +44,8 @@ public function test_detectsConsentManager_Connected() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertEquals('osano', $scd->consentManagerId); - $this->assertTrue($scd->isConnected); + self::assertTrue($scd->wasDetected(Osano::getId())); + self::assertContains(Osano::getId(), $scd->connectedContentManagers); } public function test_detectsCMS_wordPress() @@ -46,7 +54,7 @@ public function test_detectsCMS_wordPress() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertEquals('wordpress', $scd->cms); + self::assertTrue($scd->wasDetected(Wordpress::getId())); } public function test_detectsCMS_joomla() @@ -56,7 +64,7 @@ public function test_detectsCMS_joomla() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, $headers)); - $this->assertEquals('joomla', $scd->cms); + self::assertTrue($scd->wasDetected(Joomla::getId())); } public function test_detectsCMS_wix() @@ -65,7 +73,7 @@ public function test_detectsCMS_wix() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertEquals('wix', $scd->cms); + self::assertTrue($scd->wasDetected(Wix::getId())); } private function makeSiteResponse($data, $headers = []) @@ -84,12 +92,9 @@ public function test_detectsGA3_IfPresent() ga('send', 'pageview'); A site"; $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::GA3], null, $this->makeSiteResponse($siteData)); + $scd->detectContent([GoogleAnalytics3::getId()], null, $this->makeSiteResponse($siteData)); - $this->assertEmpty($scd->consentManagerId); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->ga3); + self::assertTrue($scd->wasDetected(GoogleAnalytics3::getId())); } public function test_detectsGA4_IfPresent() @@ -104,11 +109,9 @@ function gtag(){window.dataLayer.push(arguments);} A site"; $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::GA4], null, $this->makeSiteResponse($siteData)); + $scd->detectContent([GoogleAnalytics4::getId()], null, $this->makeSiteResponse($siteData)); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->ga4); + self::assertTrue($scd->wasDetected(GoogleAnalytics4::getId())); } public function test_detectsGTM_IfPresent() @@ -123,11 +126,9 @@ public function test_detectsGTM_IfPresent() A site"; $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::GTM], null, $this->makeSiteResponse($siteData)); + $scd->detectContent([GoogleTagManager::getId()], null, $this->makeSiteResponse($siteData)); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertTrue($scd->gtm); + self::assertTrue($scd->wasDetected(GoogleTagManager::getId())); } public function test_doesNotDetectsGA_IfNotPresent() @@ -136,9 +137,9 @@ public function test_doesNotDetectsGA_IfNotPresent() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); + self::assertFalse($scd->wasDetected(GoogleAnalytics3::getId())); + self::assertFalse($scd->wasDetected(GoogleAnalytics4::getId())); + self::assertFalse($scd->wasDetected(GoogleTagManager::getId())); } public function test_detectCloudFlare_IfPresent() @@ -147,10 +148,7 @@ public function test_detectCloudFlare_IfPresent() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['server' => 'cloudflare'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_detectCloudFlare_IfPresent2() @@ -159,10 +157,7 @@ public function test_detectCloudFlare_IfPresent2() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['Server' => 'cloudflare'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_detectCloudFlare_IfPresent3() @@ -171,10 +166,7 @@ public function test_detectCloudFlare_IfPresent3() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['SERVER' => 'cloudflare'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_detectCloudFlare_IfPresent4() @@ -183,10 +175,7 @@ public function test_detectCloudFlare_IfPresent4() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['cf-ray' => 'test'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_detectCloudFlare_IfPresent5() @@ -195,10 +184,7 @@ public function test_detectCloudFlare_IfPresent5() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['Cf-Ray' => 'test'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_detectCloudFlare_IfPresent6() @@ -207,10 +193,7 @@ public function test_detectCloudFlare_IfPresent6() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['CF-RAY' => 'test'])); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertTrue($scd->cloudflare); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); } public function test_doesNotDetectsCloudflare_IfNotPresent() @@ -219,55 +202,52 @@ public function test_doesNotDetectsCloudflare_IfNotPresent() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - $this->assertFalse($scd->ga3); - $this->assertFalse($scd->ga4); - $this->assertFalse($scd->gtm); - $this->assertFalse($scd->cloudflare); + self::assertFalse($scd->wasDetected(Cloudflare::getId())); } /** * @dataProvider provideVueTestData */ - public function test_detectVue($content, $output) + public function test_detectVue($content, $result) { $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($content)); - self::assertContains(VueJs::getId(), $scd->detectedContent[VueJs::getContentType()]); + self::assertSame($result, $scd->wasDetected(VueJs::getId())); } public function provideVueTestData() { return [ - ['node_modules/vue/dist/vue-develpment.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue-min.global.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.min.js', 'vue'], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vuetmp.runtime.global.prod.min.js', 'unknown'], - ['test content', 'unknown'], - ['test content vue', 'unknown'], + ['node_modules/vue/dist/vue-develpment.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue-min.global.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.min.js', true], + ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vuetmp.runtime.global.prod.min.js', false], + ['test content', false], + ['test content vue', false], ]; } @@ -277,7 +257,7 @@ public function test_detectReact_IfPresent() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_detectReact_IfPresent2() @@ -286,7 +266,7 @@ public function test_detectReact_IfPresent2() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_detectReact_IfPresent3() @@ -295,7 +275,7 @@ public function test_detectReact_IfPresent3() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_detectReact_IfPresent4() @@ -304,7 +284,7 @@ public function test_detectReact_IfPresent4() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_detectReact_IfPresent5() @@ -313,7 +293,7 @@ public function test_detectReact_IfPresent5() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_detectReact_IfPresent6() @@ -322,7 +302,7 @@ public function test_detectReact_IfPresent6() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertTrue($scd->wasDetected(ReactJs::getId())); } public function test_doesNotDetectsReact_IfNotPresent() @@ -331,6 +311,6 @@ public function test_doesNotDetectsReact_IfNotPresent() $scd = new SiteContentDetector(); $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertNotContains(ReactJs::getId(), $scd->detectedContent[ReactJs::getContentType()]); + self::assertFalse($scd->wasDetected(ReactJs::getId())); } } From 83ee226d444e68e6ab09ecec1bbb9e7095239e86 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Sat, 15 Jul 2023 21:28:05 +0200 Subject: [PATCH 08/35] update fixtures --- .../ChallengeSetupConsentManager.php | 40 ++++++++++++++----- .../Fixtures/DisableSiteContentDetection.php | 12 ------ .../EmptySiteWithSiteContentDetection.php | 14 ++----- ...SiteWithSiteContentDetectionCloudflare.php | 16 +------- .../EmptySiteWithSiteContentDetectionGA3.php | 15 +------ .../EmptySiteWithSiteContentDetectionGA4.php | 15 +------ .../EmptySiteWithSiteContentDetectionGTM.php | 18 ++------- ...hSiteContentDetectionMergeNotification.php | 16 +++----- ...ontentDetectionMergeNotificationOnlyGA.php | 17 ++------ ...EmptySiteWithSiteContentDetectionReact.php | 17 +------- .../EmptySiteWithSiteContentDetectionVue.php | 17 +------- ...ySiteWithSiteContentDetectionWordpress.php | 16 ++------ .../Mock/FakeSiteContentDetector.php | 32 +++++++++++---- 13 files changed, 84 insertions(+), 161 deletions(-) diff --git a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php b/plugins/Tour/Engagement/ChallengeSetupConsentManager.php index d24bd1dee7d..8cf7884ed86 100644 --- a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php +++ b/plugins/Tour/Engagement/ChallengeSetupConsentManager.php @@ -9,6 +9,8 @@ namespace Piwik\Plugins\Tour\Engagement; use Piwik\Piwik; +use Piwik\Plugins\SitesManager\SiteContentDetection\ConsentManagerDetectionAbstract; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\SiteContentDetector; @@ -18,6 +20,11 @@ class ChallengeSetupConsentManager extends Challenge /** @var SiteContentDetector */ private $siteContentDetector; + /** + * @var ConsentManagerDetectionAbstract|null + */ + private $detectedContentManager; + /** * @param SiteContentDetector $siteContentDetector @@ -27,17 +34,19 @@ public function __construct(SiteContentDetector $siteContentDetector, ?array $si { parent::__construct(); $this->siteContentDetector = $siteContentDetector; - $this->siteContentDetector->detectContent([SiteContentDetector::CONSENT_MANAGER], null, $siteData); + $this->siteContentDetector->detectContent([SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER], null, $siteData); + $contentManagers = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER); + $this->detectedContentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($contentManagers)); } public function getName() { - return Piwik::translate('Tour_ConnectConsentManager', [$this->siteContentDetector->consentManagerName]); + return Piwik::translate('Tour_ConnectConsentManager', [$this->getConsentManagerName()]); } public function getDescription() { - return Piwik::translate('Tour_ConnectConsentManagerIntro', [$this->siteContentDetector->consentManagerName]); + return Piwik::translate('Tour_ConnectConsentManagerIntro', [$this->getConsentManagerName()]); } public function getId() @@ -47,30 +56,43 @@ public function getId() public function getConsentManagerId() { - return $this->siteContentDetector->consentManagerId; + if (empty($this->detectedContentManager)) { + return null; + } + + return $this->detectedContentManager::getId(); + } + + public function getConsentManagerName() + { + if (empty($this->detectedContentManager)) { + return ''; + } + + return $this->detectedContentManager::getName(); } public function isCompleted(string $login) { - if (!$this->siteContentDetector->consentManagerId) { + if (empty($this->detectedContentManager)) { return true; } - return $this->siteContentDetector->isConnected; + return in_array($this->detectedContentManager::getId(), $this->siteContentDetector->connectedContentManagers); } public function isDisabled() { - return ($this->siteContentDetector->consentManagerId === null); + return empty($this->detectedContentManager); } public function getUrl() { - if ($this->siteContentDetector->consentManagerId === null) { + if (empty($this->detectedContentManager)) { return ''; } - return $this->siteContentDetector->consentManagerUrl; + return $this->detectedContentManager::getInstructionUrl(); } } diff --git a/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php b/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php index 0a60254133e..b8a4cccdc61 100644 --- a/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php +++ b/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php @@ -23,20 +23,8 @@ class DisableSiteContentDetection extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN, - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php index 99bdf202818..bebe571f6b2 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php @@ -7,6 +7,7 @@ */ namespace Piwik\Tests\Fixtures; +use Piwik\Plugins\SitesManager\SiteContentDetection\Osano; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -21,19 +22,10 @@ class EmptySiteWithSiteContentDetection extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => 'osano', - 'consentManagerName' => 'Osano', - 'consentManagerUrl' => 'https://matomo.org/faq/how-to/using-osano-consent-manager-with-matomo', - 'isConnected' => true, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [Osano::getId()]) + ->constructorParameter('connectedContentManagers', [Osano::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionCloudflare.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionCloudflare.php index 3b6e55f93d3..4ac7daa4817 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionCloudflare.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionCloudflare.php @@ -7,7 +7,7 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,21 +22,9 @@ class EmptySiteWithSiteContentDetectionCloudflare extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN, - 'cloudflare' => true - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [Cloudflare::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA3.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA3.php index cd6f9ea98e5..565917ba508 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA3.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA3.php @@ -7,7 +7,7 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,20 +22,9 @@ class EmptySiteWithSiteContentDetectionGA3 extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => true, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [GoogleAnalytics3::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA4.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA4.php index 4fc4aa4b805..2f68e6e6d90 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA4.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGA4.php @@ -7,7 +7,7 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,20 +22,9 @@ class EmptySiteWithSiteContentDetectionGA4 extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => true, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [GoogleAnalytics4::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php index d9bc54c54fe..ad8eb2de7d8 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php @@ -7,7 +7,9 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,21 +24,9 @@ class EmptySiteWithSiteContentDetectionGTM extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => true, - 'cloudflare' => true, - 'cms' => SitesManager::SITE_TYPE_WORDPRESS, - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [GoogleTagManager::getId(), Cloudflare::getId(), Wordpress::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php index 672f96b731e..9dda1fdccad 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php @@ -7,6 +7,9 @@ */ namespace Piwik\Tests\Fixtures; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; +use Piwik\Plugins\SitesManager\SiteContentDetection\Osano; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -21,19 +24,10 @@ class EmptySiteWithSiteContentDetectionMergeNotification extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => 'osano', - 'consentManagerName' => 'Osano', - 'consentManagerUrl' => 'https://matomo.org/faq/how-to/using-osano-consent-manager-with-matomo', - 'isConnected' => true, - 'ga3' => true, - 'ga4' => true, - 'gtm' => false - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [GoogleAnalytics3::getId(), GoogleAnalytics4::getId(), Osano::getId()]) + ->constructorParameter('connectedContentManagers', [Osano::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotificationOnlyGA.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotificationOnlyGA.php index 62dd883c095..600371bdc68 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotificationOnlyGA.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotificationOnlyGA.php @@ -7,7 +7,8 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; +use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,21 +23,9 @@ class EmptySiteWithSiteContentDetectionMergeNotificationOnlyGA extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => true, - 'ga4' => true, - 'gtm' => false, - 'cloudflare' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [GoogleAnalytics3::getId(), GoogleAnalytics4::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionReact.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionReact.php index f377f59626b..2487e64ef0e 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionReact.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionReact.php @@ -7,7 +7,7 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\ReactJs; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,22 +22,9 @@ class EmptySiteWithSiteContentDetectionReact extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN, - 'cloudflare' => false, - 'jsFramework' => SitesManager::JS_FRAMEWORK_REACT, - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [ReactJs::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionVue.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionVue.php index 0cf72642f42..b4fd69ea3b7 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionVue.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionVue.php @@ -7,7 +7,7 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\VueJs; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -22,22 +22,9 @@ class EmptySiteWithSiteContentDetectionVue extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_UNKNOWN, - 'cloudflare' => false, - 'jsFramework' => SitesManager::JS_FRAMEWORK_VUE, - ]; - return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [VueJs::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php index 8c86ceef523..9d90ef156fb 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php @@ -7,6 +7,8 @@ */ namespace Piwik\Tests\Fixtures; +use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; +use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; @@ -22,21 +24,9 @@ class EmptySiteWithSiteContentDetectionWordpress extends Fixture public function provideContainerConfig() { - $mockData = [ - 'consentManagerId' => null, - 'consentManagerName' => null, - 'consentManagerUrl' => null, - 'isConnected' => false, - 'ga3' => false, - 'ga4' => false, - 'gtm' => false, - 'cms' => SitesManager::SITE_TYPE_WORDPRESS, - 'cloudflare' => true - ]; - return [ SiteContentDetector::class => \DI\autowire(FakeSiteContentDetector::class) - ->constructorParameter('mockData', $mockData) + ->constructorParameter('detectedContentDetections', [Wordpress::getId(), Cloudflare::getId()]) ]; } diff --git a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php index 30ddaa7aa15..98a439d212e 100644 --- a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php +++ b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php @@ -2,27 +2,45 @@ namespace Piwik\Tests\Framework\Mock; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\SiteContentDetector; class FakeSiteContentDetector extends SiteContentDetector { - private $mockData; + /** + * @var SiteContentDetectionAbstract[] + */ + private $detectedContentDetections; - public function __construct($mockData = []) + public function __construct($detectedContentDetections = [], $connectedConsentManagers = []) { - $this->mockData = $mockData; + $this->detectedContentDetections = $detectedContentDetections; + $this->connectedContentManagers = $connectedConsentManagers; parent::__construct(null); } public function detectContent(array $detectContent = [SiteContentDetector::ALL_CONTENT], ?int $idSite = null, ?array $siteResponse = null, int $timeOut = 60): void { - foreach ($this->mockData as $property => $value) { - if (property_exists($this, $property)) { - $this->{$property} = $value; + // skip any detections + } + + public function wasDetected(string $detectionClassId): bool + { + return in_array($detectionClassId, $this->detectedContentDetections); + } + + public function getDetectsByType(string $type): array + { + $result = []; + + foreach ($this->detectedContentDetections as $detectedContentDetection) { + if ($detectedContentDetection::getContentType() === $type) { + $result[] = $detectedContentDetection; } } - } + return $result; + } } From e1a264476929b900e79cf455e72e35fe585b9177 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Sun, 16 Jul 2023 18:38:17 +0200 Subject: [PATCH 09/35] migrate and add new tests for SiteContentDetection classes --- .../tests/Unit/GuessSiteTypeAndGtmTest.php | 148 --------- .../SiteContentDetection/CloudflareTest.php | 81 +++++ .../SiteContentDetection/ComplianzTest.php | 63 ++++ .../SiteContentDetection/CookieYesTest.php | 63 ++++ .../SiteContentDetection/CookiebotTest.php | 63 ++++ .../Unit/SiteContentDetection/DrupalTest.php | 50 +++ .../GoogleAnalytics3Test.php | 81 +++++ .../GoogleAnalytics4Test.php | 70 +++++ .../GoogleTagManagerTest.php | 70 +++++ .../Unit/SiteContentDetection/JoomlaTest.php | 50 +++ .../Unit/SiteContentDetection/KlaroTest.php | 77 +++++ .../MatomoTagManagerTest.php | 59 ++++ .../Unit/SiteContentDetection/OsanoTest.php | 61 ++++ .../Unit/SiteContentDetection/ReactJsTest.php | 80 +++++ .../SiteContentDetection/SharepointTest.php | 56 ++++ .../Unit/SiteContentDetection/ShopifyTest.php | 56 ++++ .../SiteContentDetection/SquarespaceTest.php | 56 ++++ .../TarteAuCitronTest.php | 61 ++++ .../Unit/SiteContentDetection/VueJsTest.php | 87 ++++++ .../Unit/SiteContentDetection/WebflowTest.php | 56 ++++ .../Unit/SiteContentDetection/WixTest.php | 50 +++ .../SiteContentDetection/WordpressTest.php | 50 +++ .../System/ConsentManagerDetectionTest.php | 5 +- .../Mock/FakeSiteContentDetector.php | 3 +- .../Integration/SiteContentDetectorTest.php | 292 +----------------- 25 files changed, 1354 insertions(+), 434 deletions(-) delete mode 100644 plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php create mode 100644 plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php diff --git a/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php b/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php deleted file mode 100644 index 5cc6bd0c11f..00000000000 --- a/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php +++ /dev/null @@ -1,148 +0,0 @@ -guesser = new GtmSiteTypeGuesser(); - } - - public function testSiteTypeUnknownIfResponseFalse() - { - $this->assertEquals(SitesManager::SITE_TYPE_UNKNOWN, $this->guesser->guessSiteTypeFromResponse(false)); - } - - public function testGtmIsFalseIfResponseFalse() - { - $this->assertFalse($this->guesser->guessGtmFromResponse(false)); - } - - public function testGtmIsTrue() - { - $response = [ - 'status' => 200, - 'headers' => [], - 'data' => 'it contains gtm.start somewhere' - ]; - - $this->assertTrue($this->guesser->guessGtmFromResponse($response)); - - $response['data'] = 'foo bar googletagmanager.js ffoo'; - $this->assertTrue($this->guesser->guessGtmFromResponse($response)); - } - - /** - * @dataProvider responseProvider - */ - public function testSiteTypesByResponse($expected, $response) - { - $this->assertEquals($expected, $this->guesser->guessSiteTypeFromResponse($response)); - } - - /** - * All your actual test methods should start with the name "test" - */ - public function testDetectionOfGa3() - { - $response = $this->makeSiteResponse("UA-00000-00"); - $this->assertTrue($this->guesser->detectGA3FromResponse($response)); - - $response = $this->makeSiteResponse(""); - $this->assertTrue($this->guesser->detectGA3FromResponse($response)); - - $response = $this->makeSiteResponse(""); - $this->assertTrue($this->guesser->detectGA3FromResponse($response)); - } - - public function testDetectionOfGa3_noResult() - { - $this->assertFalse($this->guesser->detectGA3FromResponse([])); - } - - public function testDetectionOfGa4() - { - $response = $this->makeSiteResponse("G-12345ABC"); - $this->assertTrue($this->guesser->detectGA4FromResponse($response)); - - $response = $this->makeSiteResponse("properties/1234"); - $this->assertTrue($this->guesser->detectGA4FromResponse($response)); - } - - public function testDetectionOfGa4_noResult() - { - $this->assertFalse($this->guesser->detectGA4FromResponse([])); - } - - private function makeSiteResponse($data, $headers = []) - { - return ['data' => $data, 'headers' => $headers, 'status' => 200]; - } - - public function responseProvider() - { - return [ - [SitesManager::SITE_TYPE_UNKNOWN, [ - 'status' => 200, - 'headers' => [], - 'data' => 'nothing special' - ]], - [SitesManager::SITE_TYPE_SHOPIFY, [ - 'status' => 200, - 'headers' => [], - 'data' => 'contains Shopify.theme text' - ]], - [SitesManager::SITE_TYPE_WORDPRESS, [ - 'status' => 200, - 'headers' => [], - 'data' => 'contains /wp-content text' - ]], - [SitesManager::SITE_TYPE_WIX, [ - 'status' => 200, - 'headers' => [], - 'data' => 'contains X-Wix-Published-Version text' - ]], - [SitesManager::SITE_TYPE_SQUARESPACE, [ - 'status' => 200, - 'headers' => [], - 'data' => 'contains text' - ]], - [SitesManager::SITE_TYPE_SHAREPOINT, [ - 'status' => 200, - 'headers' => [], - 'data' => 'contains content="Microsoft SharePoint text' - ]], - [SitesManager::SITE_TYPE_JOOMLA, [ - 'status' => 200, - 'headers' => ['expires' => 'Wed, 17 Aug 2005 00:00:00 GMT'], - 'data' => 'nothing special' - ]], - ]; - } -} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php new file mode 100644 index 00000000000..eacac719463 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php @@ -0,0 +1,81 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no cloudflare headers' => [ + false, + "A siteA site", + ['server' => 'apache'] + ]; + + yield 'cloudflare server header' => [ + true, + "\nA siteA site", + ['server' => 'cloudflare'] + ]; + + yield 'cloudflare Server header' => [ + true, + "\nA siteA site", + ['Server' => 'cloudflare'], + ]; + + yield 'cloudflare SERVER header' => [ + true, + "\nA siteA site", + ['SERVER' => 'cloudflare'], + ]; + + yield 'cloudflare cf-ray header' => [ + true, + "\nA siteA site", + ['cf-ray' => 'test'], + ]; + + yield 'cloudflare Cf-Ray header' => [ + true, + "\nA siteA site", + ['Cf-Ray' => 'test'], + ]; + + yield 'cloudflare CF-RAY header' => [ + true, + "\nA siteA site", + ['CF-RAY' => 'test'], + ]; + + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php new file mode 100644 index 00000000000..b89fb2a4e9a --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php @@ -0,0 +1,63 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no complianz content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'complianz-gdpr content found' => [ + true, + false, + "\nA siteA site", + [] + ]; + + yield 'complianz-gdpr connected' => [ + true, + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php new file mode 100644 index 00000000000..1f5b14168e8 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php @@ -0,0 +1,63 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no cookieyes content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'cookieyes content found' => [ + true, + false, + "\nA siteA site", + [] + ]; + + yield 'cookieyes connected' => [ + true, + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php new file mode 100644 index 00000000000..7f0c53239a1 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php @@ -0,0 +1,63 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no cookiebot content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'cookiebot content found' => [ + true, + false, + "\nA siteA site", + [] + ]; + + yield 'cookiebot connected' => [ + true, + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php new file mode 100644 index 00000000000..738e6d3779d --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php @@ -0,0 +1,50 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no drupal content' => [ + false, + "\nA siteA site", + [] + ]; + + yield 'Drupal found' => [ + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php new file mode 100644 index 00000000000..bf07c7e42a1 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php @@ -0,0 +1,81 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no GA3 content' => [ + false, + "\nA siteA site", + [] + ]; + + yield 'GA3 js code found' => [ + true, + "A siteA site", + [] + ]; + + yield 'UA number found' => [ + true, + "UA-00000-00", + [] + ]; + + yield 'GA3 JS file usage found' => [ + true, + "", + [] + ]; + + yield 'google-analytics found in content' => [ + true, + "", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php new file mode 100644 index 00000000000..5126e97fce8 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php @@ -0,0 +1,70 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no GA4 content' => [ + false, + "\nA siteA site", + [] + ]; + + yield 'GA4 js code found' => [ + true, + "A site + + + + A site", + [] + ]; + + yield 'G number found' => [ + true, + "G-12345ABC", + [] + ]; + + yield 'GA4 properties found' => [ + true, + "properties/1234", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php new file mode 100644 index 00000000000..69698da8147 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php @@ -0,0 +1,70 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no GTM content' => [ + false, + "\nA siteA site", + [] + ]; + + yield 'GTM js code found' => [ + true, + "A site + + + + A site", + [] + ]; + + yield 'gtm.start found' => [ + true, + 'it contains gtm.start somewhere', + [] + ]; + + yield 'googletagmanager.js found' => [ + true, + 'foo bar googletagmanager.js ffoo', + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php new file mode 100644 index 00000000000..055348147f0 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php @@ -0,0 +1,50 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no joomla content' => [ + false, + "\nA siteA site", + ['expires' => 'Wed, 17 Aug 2019 00:02:00 GMT'] + ]; + + yield 'Joomla header found' => [ + true, + "\nA siteA site", + ['expires' => 'Wed, 17 Aug 2005 00:00:00 GMT'] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php new file mode 100644 index 00000000000..1c88d2e2f94 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php @@ -0,0 +1,77 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no klaro content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'klaro.js found' => [ + true, + false, + "\nA siteA site", + [] + ]; + + yield 'kiprotect.com found' => [ + true, + false, + "\nA siteA site", + [] + ]; + + yield 'klaro connected' => [ + true, + true, + "\nA siteA site", + [] + ]; + + yield 'klaro connected 2' => [ + true, + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php new file mode 100644 index 00000000000..b7117fa00ff --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php @@ -0,0 +1,59 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no MTM content' => [ + false, + "\nA siteA site", + [] + ]; + + yield 'MTM js code found' => [ + true, + "A site + + + + A site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php new file mode 100644 index 00000000000..7e4837a3a8b --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php @@ -0,0 +1,61 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no osano content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'osano content found' => [ + true, + false, + 'A siteA site', + [] + ]; + + yield 'osano connected' => [ + true, + true, + "A siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php new file mode 100644 index 00000000000..8ea2f11ef72 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php @@ -0,0 +1,80 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no react.js content' => [ + false, + 'nothing special', + [] + ]; + + yield 'ReactDOM. is found' => [ + true, + "\nA siteA site", + [] + ]; + + yield 'react.min.js used' => [ + true, + "\nA siteA site", + [] + ]; + + yield 'react.development.min.js used' => [ + true, + "\nA siteA site", + [] + ]; + + yield 'react-dom.development.min.js used' => [ + true, + "\nA siteA site", + [] + ]; + + yield 'react.development.js used' => [ + true, + "\nA siteA site", + [] + ]; + + yield 'react-dom.development.js used' => [ + true, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php new file mode 100644 index 00000000000..3120a70424a --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php @@ -0,0 +1,56 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no sharepoint content' => [ + false, + 'nothing special', + [] + ]; + + yield 'sharepoint is found' => [ + true, + 'contains content="Microsoft SharePoint text', + [] + ]; + + yield 'sharepoint in incorrect case' => [ + false, + 'contains content="microsoft sharepoint text', + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php new file mode 100644 index 00000000000..d30207ca569 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php @@ -0,0 +1,56 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no shopify content' => [ + false, + 'nothing special', + [] + ]; + + yield 'Shopify.theme is found' => [ + true, + 'contains Shopify.theme text', + [] + ]; + + yield 'Shopify.theme in incorrect case' => [ + false, + 'contains shopify.Theme text', + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php new file mode 100644 index 00000000000..7ec30777fa0 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php @@ -0,0 +1,56 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no squarespace content' => [ + false, + "A siteA site", + [] + ]; + + yield 'squarespace comment is found' => [ + true, + "A siteA site", + [] + ]; + + yield 'squarespace comment not correctly found' => [ + false, + "A siteThis is Squarespace, or not?", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php new file mode 100644 index 00000000000..9a07f8a5a57 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php @@ -0,0 +1,61 @@ +runSiteDetectionByContent($data, $headers)); + self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + false, + '', + [] + ]; + + yield 'no TarteAuCitron content' => [ + false, + false, + "A siteA site", + [] + ]; + + yield 'TarteAuCitron content found' => [ + true, + false, + 'A siteA site', + [] + ]; + + yield 'TarteAuCitron connected' => [ + true, + true, + "A siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php new file mode 100644 index 00000000000..09ea4fcba6a --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php @@ -0,0 +1,87 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no vue.js content' => [ + false, + 'This is a blog about vue, not using it.', + [] + ]; + + $validVueJsFiles = [ + 'node_modules/vue/dist/vue-develpment.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue-min.global.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.js', + 'https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.min.js', + ]; + + foreach ($validVueJsFiles as $vueJsFile) { + yield "$vueJsFile used" => [ + true, + "\nA siteA site", + [] + ]; + } + + yield "unknown vue.js file used" => [ + false, + "\nA siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php new file mode 100644 index 00000000000..257f71a84d1 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php @@ -0,0 +1,56 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no webflow content' => [ + false, + "A siteA site", + [] + ]; + + yield 'data-wf-domain is found' => [ + true, + "A siteA site", + [] + ]; + + yield 'data-wf-page is found' => [ + true, + "A siteA site", + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php new file mode 100644 index 00000000000..5b72a22745f --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php @@ -0,0 +1,50 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no webflow content' => [ + false, + "A siteA site", + [] + ]; + + yield 'X-Wix-Published-Version is found' => [ + true, + 'A siteA site', + [] + ]; + } +} diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php new file mode 100644 index 00000000000..4e6c92bfdcf --- /dev/null +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php @@ -0,0 +1,50 @@ +runSiteDetectionByContent($data, $headers)); + } + + public function responseProvider() + { + yield 'no content at all' => [ + false, + '', + [] + ]; + + yield 'no wordpress content' => [ + false, + "A siteA site", + [] + ]; + + yield '/wp-content is found' => [ + true, + "A siteA site", + [] + ]; + } +} diff --git a/plugins/Tour/tests/System/ConsentManagerDetectionTest.php b/plugins/Tour/tests/System/ConsentManagerDetectionTest.php index 095bc5f7b24..3b67d40f4fc 100644 --- a/plugins/Tour/tests/System/ConsentManagerDetectionTest.php +++ b/plugins/Tour/tests/System/ConsentManagerDetectionTest.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\Tour\tests\System; use Piwik\Piwik; +use Piwik\Plugins\SitesManager\SiteContentDetection\Osano; use Piwik\Plugins\Tour\Engagement\ChallengeSetupConsentManager; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\TestCase\SystemTestCase; @@ -39,7 +40,7 @@ public function test_detectConsentManager_detectedButNotConnected() $challenge = new ChallengeSetupConsentManager(new SiteContentDetector(), $siteData); $this->assertFalse($challenge->isDisabled()); $this->assertFalse($challenge->isCompleted(Piwik::getCurrentUserLogin())); - $this->assertEquals('osano', $challenge->getConsentManagerId()); + $this->assertEquals(Osano::getId(), $challenge->getConsentManagerId()); } public function test_detectConsentManager_detectedAndConnected() @@ -48,7 +49,7 @@ public function test_detectConsentManager_detectedAndConnected() $challenge = new ChallengeSetupConsentManager(new SiteContentDetector(), $siteData); $this->assertFalse($challenge->isDisabled()); $this->assertTrue($challenge->isCompleted(Piwik::getCurrentUserLogin())); - $this->assertEquals('osano', $challenge->getConsentManagerId()); + $this->assertEquals(Osano::getId(), $challenge->getConsentManagerId()); } private function makeSiteResponse($data, $headers = []) diff --git a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php index 98a439d212e..701e92f6d41 100644 --- a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php +++ b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php @@ -36,7 +36,8 @@ public function getDetectsByType(string $type): array $result = []; foreach ($this->detectedContentDetections as $detectedContentDetection) { - if ($detectedContentDetection::getContentType() === $type) { + $class = $this->getSiteContentDetectionById($detectedContentDetection); + if ($class::getContentType() === $type) { $result[] = $detectedContentDetection; } } diff --git a/tests/PHPUnit/Integration/SiteContentDetectorTest.php b/tests/PHPUnit/Integration/SiteContentDetectorTest.php index d67a799a3d5..4983b741478 100644 --- a/tests/PHPUnit/Integration/SiteContentDetectorTest.php +++ b/tests/PHPUnit/Integration/SiteContentDetectorTest.php @@ -9,14 +9,8 @@ namespace Piwik\Tests\Integration; use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; -use Piwik\Plugins\SitesManager\SiteContentDetection\Joomla; use Piwik\Plugins\SitesManager\SiteContentDetection\Osano; use Piwik\Plugins\SitesManager\SiteContentDetection\ReactJs; -use Piwik\Plugins\SitesManager\SiteContentDetection\VueJs; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wix; use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -27,290 +21,22 @@ */ class SiteContentDetectorTest extends IntegrationTestCase { - public function test_detectsConsentManager_NotConnected() - { - $siteData = 'A siteA site'; - - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertTrue($scd->wasDetected(Osano::getId())); - self::assertNotContains(Osano::getId(), $scd->connectedContentManagers); - } - public function test_detectsConsentManager_Connected() + public function testSiteWithMultipleDetections() { - $siteData = "A siteA site"; $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); + $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, [ + 'data' => "A siteA site", + 'headers' => [ + 'CF-RAY' => 'test' + ], + ]); self::assertTrue($scd->wasDetected(Osano::getId())); - self::assertContains(Osano::getId(), $scd->connectedContentManagers); - } - - public function test_detectsCMS_wordPress() - { - $siteData = "A siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertTrue($scd->wasDetected(Wordpress::getId())); - } - - public function test_detectsCMS_joomla() - { - $siteData = "A site"; - $headers = ['expires' => 'Wed, 17 Aug 2005 00:00:00 GMT']; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, $headers)); - - self::assertTrue($scd->wasDetected(Joomla::getId())); - } - - public function test_detectsCMS_wix() - { - $siteData = "A siteA sit"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(Wix::getId())); - } - - private function makeSiteResponse($data, $headers = []) - { - return ['data' => $data, 'headers' => $headers, 'status' => 200]; - } - - public function test_detectsGA3_IfPresent() - { - $siteData = "A siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([GoogleAnalytics3::getId()], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(GoogleAnalytics3::getId())); - } - - public function test_detectsGA4_IfPresent() - { - $siteData = "A site - - A site"; - $scd = new SiteContentDetector(); - $scd->detectContent([GoogleAnalytics4::getId()], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(GoogleAnalytics4::getId())); - } - - public function test_detectsGTM_IfPresent() - { - $siteData = "A site - - - - A site"; - $scd = new SiteContentDetector(); - $scd->detectContent([GoogleTagManager::getId()], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(GoogleTagManager::getId())); - } - - public function test_doesNotDetectsGA_IfNotPresent() - { - $siteData = "A siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertFalse($scd->wasDetected(GoogleAnalytics3::getId())); - self::assertFalse($scd->wasDetected(GoogleAnalytics4::getId())); - self::assertFalse($scd->wasDetected(GoogleTagManager::getId())); - } - - public function test_detectCloudFlare_IfPresent() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['server' => 'cloudflare'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_detectCloudFlare_IfPresent2() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['Server' => 'cloudflare'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_detectCloudFlare_IfPresent3() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['SERVER' => 'cloudflare'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_detectCloudFlare_IfPresent4() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['cf-ray' => 'test'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_detectCloudFlare_IfPresent5() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['Cf-Ray' => 'test'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_detectCloudFlare_IfPresent6() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData, ['CF-RAY' => 'test'])); - - self::assertTrue($scd->wasDetected(Cloudflare::getId())); - } - - public function test_doesNotDetectsCloudflare_IfNotPresent() - { - $siteData = "A siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertFalse($scd->wasDetected(Cloudflare::getId())); - } - - /** - * @dataProvider provideVueTestData - */ - public function test_detectVue($content, $result) - { - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($content)); - - self::assertSame($result, $scd->wasDetected(VueJs::getId())); - } - - public function provideVueTestData() - { - return [ - ['node_modules/vue/dist/vue-develpment.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.cjs.prod.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-browser.prod.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.esm-bundler.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue-min.global.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.global.prod.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-browser.prod.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.esm-bundler.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vue.runtime.global.prod.min.js', true], - ['https://cdnjs.cloudflare.com/ajax/libs/vue/3.3.4/vuetmp.runtime.global.prod.min.js', false], - ['test content', false], - ['test content vue', false], - ]; - } - - public function test_detectReact_IfPresent() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_detectReact_IfPresent2() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_detectReact_IfPresent3() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_detectReact_IfPresent4() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_detectReact_IfPresent5() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_detectReact_IfPresent6() - { - $siteData = "\nA siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertTrue($scd->wasDetected(ReactJs::getId())); - } - - public function test_doesNotDetectsReact_IfNotPresent() - { - $siteData = "A siteA site"; - $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, $this->makeSiteResponse($siteData)); - - self::assertFalse($scd->wasDetected(ReactJs::getId())); + self::assertTrue($scd->wasDetected(Cloudflare::getId())); + self::assertContains(Osano::getId(), $scd->connectedContentManagers); } } From 7b3e20bc550ca0c516d59065a031d4a71d13b8d2 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 17 Jul 2023 16:28:18 +0200 Subject: [PATCH 10/35] remove state from detection classes again --- core/SiteContentDetector.php | 29 ++-------- plugins/PrivacyManager/Controller.php | 2 +- plugins/SitesManager/Controller.php | 2 +- .../SiteContentDetection/Cloudflare.php | 2 +- .../SiteContentDetection/Complianz.php | 2 +- .../SiteContentDetection/CookieYes.php | 2 +- .../SiteContentDetection/Cookiebot.php | 2 +- .../SiteContentDetection/Drupal.php | 2 +- .../SiteContentDetection/GoogleAnalytics3.php | 2 +- .../SiteContentDetection/GoogleAnalytics4.php | 2 +- .../SiteContentDetection/GoogleTagManager.php | 2 +- .../SiteContentDetection/Joomla.php | 2 +- .../SiteContentDetection/Klaro.php | 2 +- .../SiteContentDetection/MatomoTagManager.php | 2 +- .../SiteContentDetection/Osano.php | 2 +- .../SiteContentDetection/ReactJs.php | 2 +- .../SiteContentDetection/Sharepoint.php | 2 +- .../SiteContentDetection/Shopify.php | 2 +- .../SiteContentDetectionAbstract.php | 53 ++----------------- .../SiteContentDetection/SpaPwa.php | 2 +- .../SiteContentDetection/Squarespace.php | 2 +- .../SiteContentDetection/TarteAuCitron.php | 2 +- .../SiteContentDetection/VueJs.php | 2 +- .../SiteContentDetection/Webflow.php | 2 +- .../SitesManager/SiteContentDetection/Wix.php | 2 +- .../SiteContentDetection/Wordpress.php | 2 +- .../SiteContentDetection/CloudflareTest.php | 4 +- .../SiteContentDetection/ComplianzTest.php | 4 +- .../SiteContentDetection/CookieYesTest.php | 4 +- .../SiteContentDetection/CookiebotTest.php | 4 +- .../Unit/SiteContentDetection/DrupalTest.php | 4 +- .../GoogleAnalytics3Test.php | 4 +- .../GoogleAnalytics4Test.php | 4 +- .../GoogleTagManagerTest.php | 4 +- .../Unit/SiteContentDetection/JoomlaTest.php | 4 +- .../Unit/SiteContentDetection/KlaroTest.php | 4 +- .../MatomoTagManagerTest.php | 4 +- .../Unit/SiteContentDetection/OsanoTest.php | 4 +- .../Unit/SiteContentDetection/ReactJsTest.php | 4 +- .../SiteContentDetection/SharepointTest.php | 4 +- .../Unit/SiteContentDetection/ShopifyTest.php | 4 +- .../SiteContentDetection/SquarespaceTest.php | 4 +- .../TarteAuCitronTest.php | 4 +- .../Unit/SiteContentDetection/VueJsTest.php | 4 +- .../Unit/SiteContentDetection/WebflowTest.php | 4 +- .../Unit/SiteContentDetection/WixTest.php | 4 +- .../SiteContentDetection/WordpressTest.php | 4 +- plugins/Tour/API.php | 2 +- .../ChallengeSetupConsentManager.php | 2 +- .../EmptySiteWithSiteContentDetection.php | 2 +- ...hSiteContentDetectionMergeNotification.php | 2 +- .../Mock/FakeSiteContentDetector.php | 2 +- .../Integration/SiteContentDetectorTest.php | 2 +- 53 files changed, 81 insertions(+), 145 deletions(-) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index 7db363bac52..6051353ccc8 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -53,7 +53,7 @@ class SiteContentDetector SiteContentDetectionAbstract::TYPE_OTHER => [], ]; - public $connectedContentManagers = []; + public $connectedConsentManagers = []; private $siteResponse = [ 'data' => '', @@ -120,14 +120,14 @@ protected static function getAllSiteContentDetectionClasses(): array */ private function resetDetections(): void { - $this->detectedContent = [ + $this->detectedContent = [ SiteContentDetectionAbstract::TYPE_TRACKER => [], SiteContentDetectionAbstract::TYPE_CMS => [], SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK => [], SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER => [], SiteContentDetectionAbstract::TYPE_OTHER => [], ]; - $this->connectedContentManagers = []; + $this->connectedConsentManagers = []; } /** @@ -251,25 +251,6 @@ private function checkCacheHasRequiredProperties(array $properties, array $cache return true; } - /** - * Load object properties from the cache array - * - * @param array $properties - * @param array $cache - * - * @return void - */ - private function loadRequiredPropertiesFromCache(array $properties, array $cache): void - { - foreach ($properties as $prop) { - if (!array_key_exists($prop, $cache)) { - continue; - } - - $this->detectedContent[$prop] = $cache[$prop]; - } - } - /** * Save properties to the cache * @@ -318,10 +299,10 @@ private function detectionChecks($detectContent): void { $this->detectedContent[$type][$typeDetection::getId()] = false; - if ($typeDetection->runSiteDetectionByContent($this->siteResponse['data'], $this->siteResponse['headers'])) { + if ($typeDetection->detectByContent($this->siteResponse['data'], $this->siteResponse['headers'])) { if ($typeDetection instanceof ConsentManagerDetectionAbstract && $typeDetection->checkIsConnected($this->siteResponse['data'], $this->siteResponse['headers']) ) { - $this->connectedContentManagers[] = $typeDetection::getId(); + $this->connectedConsentManagers[] = $typeDetection::getId(); } $this->detectedContent[$type][$typeDetection::getId()] = true; } diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php index 1f363d2a862..140974b2c5f 100644 --- a/plugins/PrivacyManager/Controller.php +++ b/plugins/PrivacyManager/Controller.php @@ -183,7 +183,7 @@ public function consent() $contentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManager)); $view->consentManagerName = $contentManager::getName(); $view->consentManagerUrl = $consentManager::getInstructionUrl(); - $view->consentManagerIsConnected = in_array($contentManager::getId(), $this->siteContentDetector->connectedContentManagers); + $view->consentManagerIsConnected = in_array($contentManager::getId(), $this->siteContentDetector->connectedConsentManagers); } $consentManagers = SiteContentDetector::getKnownConsentManagers(); diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 41d27673ee9..79eb8709c86 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -249,7 +249,7 @@ public function siteWithoutDataTabs() $consentManager = $this->siteContentDetector->getSiteContentDetectionById($consentManagerId); $templateData['consentManagerName'] = $consentManager::getName(); $templateData['consentManagerUrl'] = $consentManager::getInstructionUrl(); - $templateData['consentManagerIsConnected'] = in_array($consentManagerId, $this->siteContentDetector->connectedContentManagers); + $templateData['consentManagerIsConnected'] = in_array($consentManagerId, $this->siteContentDetector->connectedConsentManagers); } $templateData['tabs'] = []; diff --git a/plugins/SitesManager/SiteContentDetection/Cloudflare.php b/plugins/SitesManager/SiteContentDetection/Cloudflare.php index f204c0d4e0e..f155610ff0a 100644 --- a/plugins/SitesManager/SiteContentDetection/Cloudflare.php +++ b/plugins/SitesManager/SiteContentDetection/Cloudflare.php @@ -36,7 +36,7 @@ public static function getPriority(): int return 40; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { return ( (!empty($headers['server']) && stripos($headers['server'], 'cloudflare') !== false) || diff --git a/plugins/SitesManager/SiteContentDetection/Complianz.php b/plugins/SitesManager/SiteContentDetection/Complianz.php index 0329b55ed6a..26e22d5c22e 100644 --- a/plugins/SitesManager/SiteContentDetection/Complianz.php +++ b/plugins/SitesManager/SiteContentDetection/Complianz.php @@ -22,7 +22,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/how-to/using-complianz-for-wordpress-consent-manager-with-matomo'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'complianz-gdpr'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/CookieYes.php b/plugins/SitesManager/SiteContentDetection/CookieYes.php index 73cdff3c9e6..58f146f8dbf 100644 --- a/plugins/SitesManager/SiteContentDetection/CookieYes.php +++ b/plugins/SitesManager/SiteContentDetection/CookieYes.php @@ -22,7 +22,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/how-to/using-cookieyes-consent-manager-with-matomo'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'cookieyes.com'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/Cookiebot.php b/plugins/SitesManager/SiteContentDetection/Cookiebot.php index 095a904e6b3..b36f90f2e72 100644 --- a/plugins/SitesManager/SiteContentDetection/Cookiebot.php +++ b/plugins/SitesManager/SiteContentDetection/Cookiebot.php @@ -22,7 +22,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/how-to/using-cookiebot-consent-manager-with-matomo'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'cookiebot.com'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/Drupal.php b/plugins/SitesManager/SiteContentDetection/Drupal.php index 04e9b51a0ba..49708b098ee 100644 --- a/plugins/SitesManager/SiteContentDetection/Drupal.php +++ b/plugins/SitesManager/SiteContentDetection/Drupal.php @@ -27,7 +27,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/new-to-piwik/how-to-integrate-with-drupal/'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'wasDetected); - } - - /** - * Unserializes the object with the detection state - * - * @param ?bool $data - * @return void - */ - public function unserialize($data) - { - $this->wasDetected = \json_decode($data); - } - public static function getId(): string { $classParts = explode('\\', static::class); @@ -93,38 +72,14 @@ public static function getPriority(): int return 1000; } - /** - * Forces the detection to return a certain state - * - * @param bool $wasDetected - * @return bool returns the provided value - */ - public function setWasDetected(bool $wasDetected): bool - { - $this->wasDetected = $wasDetected; - return $this->wasDetected; - } - - /** - * Method executed for detection - * - * @param string|null $data - * @param array|null $headers - * @return bool - */ - final public function runSiteDetectionByContent(?string $data = null, ?array $headers = null): bool - { - return $this->setWasDetected($this->detectSiteByContent($data, $headers)); - } - /** * Returns if the current detection succeeded for the provided site content or not. * * @param string|null $data - * @param array|null $headers + * @param array|null $headers * @return bool */ - abstract protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool; + abstract public function detectByContent(?string $data = null, ?array $headers = null): bool; /** * Returns whether the instruction tab should be shown. Default behavior is to show it if the detection was successful @@ -134,7 +89,7 @@ abstract protected function detectSiteByContent(?string $data = null, ?array $he */ public function shouldShowInstructionTab(SiteContentDetector $detector = null): bool { - return $this->wasDetected; + return $detector->wasDetected(static::getId()); } /** diff --git a/plugins/SitesManager/SiteContentDetection/SpaPwa.php b/plugins/SitesManager/SiteContentDetection/SpaPwa.php index 6c5940f8ccf..a845460e8f8 100644 --- a/plugins/SitesManager/SiteContentDetection/SpaPwa.php +++ b/plugins/SitesManager/SiteContentDetection/SpaPwa.php @@ -30,7 +30,7 @@ public static function getPriority(): int return 70; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { return false; } diff --git a/plugins/SitesManager/SiteContentDetection/Squarespace.php b/plugins/SitesManager/SiteContentDetection/Squarespace.php index b146f3ed680..7cd774dda83 100644 --- a/plugins/SitesManager/SiteContentDetection/Squarespace.php +++ b/plugins/SitesManager/SiteContentDetection/Squarespace.php @@ -27,7 +27,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website/'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = ''; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/TarteAuCitron.php b/plugins/SitesManager/SiteContentDetection/TarteAuCitron.php index 7c47cd61093..e2ea44a2e6a 100644 --- a/plugins/SitesManager/SiteContentDetection/TarteAuCitron.php +++ b/plugins/SitesManager/SiteContentDetection/TarteAuCitron.php @@ -25,7 +25,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/how-to/using-tarte-au-citron-consent-manager-with-matomo'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'tarteaucitron.js'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/VueJs.php b/plugins/SitesManager/SiteContentDetection/VueJs.php index bcef4d40fa9..fafb8a2ea5a 100644 --- a/plugins/SitesManager/SiteContentDetection/VueJs.php +++ b/plugins/SitesManager/SiteContentDetection/VueJs.php @@ -37,7 +37,7 @@ public static function getPriority(): int return 50; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { return preg_match("/vue\.\w.+.js|vue\-\w.+.js/i", $data) === 1; } diff --git a/plugins/SitesManager/SiteContentDetection/Webflow.php b/plugins/SitesManager/SiteContentDetection/Webflow.php index d741b7a0063..b3298ce2c05 100644 --- a/plugins/SitesManager/SiteContentDetection/Webflow.php +++ b/plugins/SitesManager/SiteContentDetection/Webflow.php @@ -27,7 +27,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-webflow'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $pattern = '/data-wf-(?:domain|page)=/i'; return (preg_match($pattern, $data) === 1); diff --git a/plugins/SitesManager/SiteContentDetection/Wix.php b/plugins/SitesManager/SiteContentDetection/Wix.php index 2749147044a..78bb01b72bd 100644 --- a/plugins/SitesManager/SiteContentDetection/Wix.php +++ b/plugins/SitesManager/SiteContentDetection/Wix.php @@ -27,7 +27,7 @@ public static function getInstructionUrl(): ?string return 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix/'; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = 'X-Wix-Published-Version'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/SiteContentDetection/Wordpress.php b/plugins/SitesManager/SiteContentDetection/Wordpress.php index 61b9f91ba23..d640996535c 100644 --- a/plugins/SitesManager/SiteContentDetection/Wordpress.php +++ b/plugins/SitesManager/SiteContentDetection/Wordpress.php @@ -38,7 +38,7 @@ public static function getPriority(): int return 30; } - protected function detectSiteByContent(?string $data = null, ?array $headers = null): bool + public function detectByContent(?string $data = null, ?array $headers = null): bool { $needle = '/wp-content'; return (strpos($data, $needle) !== false); diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php index eacac719463..26cf8d5f320 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CloudflareTest.php @@ -21,10 +21,10 @@ class CloudflareTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Cloudflare(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php index b89fb2a4e9a..cb479dbedf4 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ComplianzTest.php @@ -21,10 +21,10 @@ class ComplianzTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new Complianz(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php index 1f5b14168e8..2941865c687 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookieYesTest.php @@ -21,10 +21,10 @@ class CookieYesTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new CookieYes(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php index 7f0c53239a1..b3109b4eb51 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/CookiebotTest.php @@ -21,10 +21,10 @@ class CookiebotTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new Cookiebot(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php index 738e6d3779d..e75a32d5231 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/DrupalTest.php @@ -21,10 +21,10 @@ class DrupalTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Drupal(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php index bf07c7e42a1..3eeed9670d3 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics3Test.php @@ -21,10 +21,10 @@ class GoogleAnalytics3Test extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new GoogleAnalytics3(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php index 5126e97fce8..6cbdf0711c6 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleAnalytics4Test.php @@ -21,10 +21,10 @@ class GoogleAnalytics4Test extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new GoogleAnalytics4(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php index 69698da8147..187bf8dc7b6 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/GoogleTagManagerTest.php @@ -21,10 +21,10 @@ class GoogleTagManagerTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new GoogleTagManager(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php index 055348147f0..1090bac7ea8 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/JoomlaTest.php @@ -21,10 +21,10 @@ class JoomlaTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Joomla(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php index 1c88d2e2f94..bf2b56292ef 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/KlaroTest.php @@ -21,10 +21,10 @@ class KlaroTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new Klaro(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php index b7117fa00ff..188260216eb 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/MatomoTagManagerTest.php @@ -21,10 +21,10 @@ class MatomoTagManagerTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new MatomoTagManager(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php index 7e4837a3a8b..a37eea7564a 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/OsanoTest.php @@ -21,10 +21,10 @@ class OsanoTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new Osano(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php index 8ea2f11ef72..2d076fbc30b 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ReactJsTest.php @@ -21,10 +21,10 @@ class ReactJsTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new ReactJs(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php index 3120a70424a..7565e2efb24 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/SharepointTest.php @@ -21,10 +21,10 @@ class SharepointTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Sharepoint(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php index d30207ca569..7559aeb3e1b 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/ShopifyTest.php @@ -21,10 +21,10 @@ class ShopifyTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Shopify(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php index 7ec30777fa0..714720fff4e 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/SquarespaceTest.php @@ -21,10 +21,10 @@ class SquarespaceTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Squarespace(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php index 9a07f8a5a57..8eb6e1bdff4 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/TarteAuCitronTest.php @@ -21,10 +21,10 @@ class TarteAuCitronTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $isConnected, $data, $headers) + public function testdetectByContent($expected, $isConnected, $data, $headers) { $detection = new TarteAuCitron(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); self::assertSame($isConnected, $detection->checkIsConnected($data, $headers)); } diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php index 09ea4fcba6a..9527003814d 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/VueJsTest.php @@ -21,10 +21,10 @@ class VueJsTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new VueJs(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php index 257f71a84d1..dedf1ab36f3 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WebflowTest.php @@ -21,10 +21,10 @@ class WebflowTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Webflow(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php index 5b72a22745f..21b98b736cb 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WixTest.php @@ -21,10 +21,10 @@ class WixTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Wix(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php index 4e6c92bfdcf..6d82b5c8a42 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php @@ -21,10 +21,10 @@ class WordpressTest extends \PHPUnit\Framework\TestCase /** * @dataProvider responseProvider */ - public function testRunSiteDetectionByContent($expected, $data, $headers) + public function testdetectByContent($expected, $data, $headers) { $detection = new Wordpress(); - self::assertSame($expected, $detection->runSiteDetectionByContent($data, $headers)); + self::assertSame($expected, $detection->detectByContent($data, $headers)); } public function responseProvider() diff --git a/plugins/Tour/API.php b/plugins/Tour/API.php index d52b3e179f8..075791cb5a3 100644 --- a/plugins/Tour/API.php +++ b/plugins/Tour/API.php @@ -92,7 +92,7 @@ public function detectConsentManager($idSite, $timeOut = 60) $consentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManagers)); return ['name' => $consentManager::getName(), 'url' => $consentManager::getInstructionUrl(), - 'isConnected' => in_array($consentManager::getId(), $this->siteContentDetector->connectedContentManagers) + 'isConnected' => in_array($consentManager::getId(), $this->siteContentDetector->connectedConsentManagers) ]; } diff --git a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php b/plugins/Tour/Engagement/ChallengeSetupConsentManager.php index 8cf7884ed86..990551e5729 100644 --- a/plugins/Tour/Engagement/ChallengeSetupConsentManager.php +++ b/plugins/Tour/Engagement/ChallengeSetupConsentManager.php @@ -78,7 +78,7 @@ public function isCompleted(string $login) return true; } - return in_array($this->detectedContentManager::getId(), $this->siteContentDetector->connectedContentManagers); + return in_array($this->detectedContentManager::getId(), $this->siteContentDetector->connectedConsentManagers); } public function isDisabled() diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php index bebe571f6b2..6fc17a8866e 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetection.php @@ -25,7 +25,7 @@ public function provideContainerConfig() return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) ->constructorParameter('detectedContentDetections', [Osano::getId()]) - ->constructorParameter('connectedContentManagers', [Osano::getId()]) + ->constructorParameter('connectedConsentManagers', [Osano::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php index 9dda1fdccad..150ae1d6123 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionMergeNotification.php @@ -27,7 +27,7 @@ public function provideContainerConfig() return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) ->constructorParameter('detectedContentDetections', [GoogleAnalytics3::getId(), GoogleAnalytics4::getId(), Osano::getId()]) - ->constructorParameter('connectedContentManagers', [Osano::getId()]) + ->constructorParameter('connectedConsentManagers', [Osano::getId()]) ]; } diff --git a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php index 701e92f6d41..a406c68a02f 100644 --- a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php +++ b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php @@ -16,7 +16,7 @@ class FakeSiteContentDetector extends SiteContentDetector public function __construct($detectedContentDetections = [], $connectedConsentManagers = []) { $this->detectedContentDetections = $detectedContentDetections; - $this->connectedContentManagers = $connectedConsentManagers; + $this->connectedConsentManagers = $connectedConsentManagers; parent::__construct(null); } diff --git a/tests/PHPUnit/Integration/SiteContentDetectorTest.php b/tests/PHPUnit/Integration/SiteContentDetectorTest.php index 4983b741478..2e31db06be2 100644 --- a/tests/PHPUnit/Integration/SiteContentDetectorTest.php +++ b/tests/PHPUnit/Integration/SiteContentDetectorTest.php @@ -37,6 +37,6 @@ public function testSiteWithMultipleDetections() self::assertTrue($scd->wasDetected(Wordpress::getId())); self::assertTrue($scd->wasDetected(ReactJs::getId())); self::assertTrue($scd->wasDetected(Cloudflare::getId())); - self::assertContains(Osano::getId(), $scd->connectedContentManagers); + self::assertContains(Osano::getId(), $scd->connectedConsentManagers); } } From 039628c6344d2f22db0ec408bbf8fad6c27a2ff5 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 17 Jul 2023 17:07:44 +0200 Subject: [PATCH 11/35] fix some stuff --- core/SiteContentDetector.php | 12 +++---- .../templates/trackingCodeGenerator.twig | 4 +-- plugins/Installation/Controller.php | 34 +++++++++---------- plugins/PrivacyManager/Controller.php | 14 +++++--- ...Manager_ConsentManager_consent_default.png | 4 +-- .../PrivacyManager_consent_default.png | 4 +-- plugins/SitesManager/Controller.php | 8 ++--- .../{Wordpress.php => WordPress.php} | 4 +-- .../SiteContentDetection/WordpressTest.php | 4 +-- .../EmptySiteWithSiteContentDetectionGTM.php | 4 +-- ...ySiteWithSiteContentDetectionWordpress.php | 4 +-- .../Integration/SiteContentDetectorTest.php | 4 +-- tests/UI/specs/EmptySite_React_spec.js | 2 +- tests/UI/specs/EmptySite_spec.js | 4 +-- 14 files changed, 54 insertions(+), 52 deletions(-) rename plugins/SitesManager/SiteContentDetection/{Wordpress.php => WordPress.php} (97%) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index 6051353ccc8..a0768c94f53 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -174,7 +174,7 @@ public function detectContent(array $detectContent = [], $siteContentDetectionCache = $this->cache->fetch($cacheKey); if ($siteContentDetectionCache !== false) { - $cachedSiteContentDetection = Common::safe_unserialize($siteContentDetectionCache, self::getAllSiteContentDetectionClasses()); + $cachedSiteContentDetection = $siteContentDetectionCache; if ($this->checkCacheHasRequiredProperties($detectContent, $cachedSiteContentDetection)) { $this->detectedContent = $cachedSiteContentDetection; return; @@ -196,7 +196,7 @@ public function detectContent(array $detectContent = [], // A request was made to get this data and it isn't currently cached, so write it to the cache now $cacheLife = (60 * 60 * 24 * 7); - $this->savePropertiesToCache($cacheKey, $detectContent, $cacheLife); + $this->savePropertiesToCache($cacheKey, $this->detectedContent, $cacheLife); } /** @@ -242,11 +242,7 @@ public function getDetectsByType(string $type): array */ private function checkCacheHasRequiredProperties(array $properties, array $cache): bool { - foreach ($properties as $prop) { - if (!array_key_exists($prop, $cache) || $cache[$prop] === null) { - return false; - } - } + // todo implement return true; } @@ -361,7 +357,7 @@ public static function getKnownConsentManagers(): array foreach ($cmDetections as $detection) { $consentManagers[$detection::getId()] = [ 'name' => $detection::getName(), - 'intructionUrl' => $detection::getInstructionUrl(), + 'instructionUrl' => $detection::getInstructionUrl(), ]; } diff --git a/plugins/CoreAdminHome/templates/trackingCodeGenerator.twig b/plugins/CoreAdminHome/templates/trackingCodeGenerator.twig index 98752120a55..e7becb052d9 100644 --- a/plugins/CoreAdminHome/templates/trackingCodeGenerator.twig +++ b/plugins/CoreAdminHome/templates/trackingCodeGenerator.twig @@ -25,7 +25,7 @@ {{ 'CoreAdminHome_HttpTrackingApi'|translate }} {{ 'SitesManager_SiteWithoutDataSinglePageApplication'|translate }} {{ 'SitesManager_SiteWithoutDataGoogleTagManager'|translate }} - Wordpress + WordPress Cloudflare Vue.js React.js @@ -71,7 +71,7 @@

{{ 'CoreAdminHome_GoogleTagManagerDescription'|translate('','')|raw }}

-
+

{{ 'CoreAdminHome_WordpressDescription'|translate('','')|raw }}

diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index cb84af57137..f5d3ca11bab 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -26,6 +26,7 @@ use Piwik\Plugins\Diagnostics\DiagnosticService; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as APISitesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\Plugins\UsersManager\API as APIUsersManager; use Piwik\Plugins\UsersManager\NewsletterSignup; use Piwik\Plugins\UsersManager\UserUpdater; @@ -402,19 +403,26 @@ public function trackingCode() $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT]); - $emailBody = $this->renderTemplateAs('@SitesManager/_trackingCodeEmail', array( + $emailTemplateData = [ 'jsTag' => $rawJsTag, 'showMatomoLinks' => $showMatomoLinks, 'trackingUrl' => $trackingUrl, 'idSite' => $idSite, - 'gtmUsed' => $this->siteContentDetector->gtm, - 'ga3Used' => $this->siteContentDetector->ga3, - 'ga4Used' => $this->siteContentDetector->ga4, - 'cloudflare' => $this->siteContentDetector->cloudflare, - 'consentManagerName' => $this->siteContentDetector->consentManagerName, - 'consentManagerUrl' => $this->siteContentDetector->consentManagerUrl, - 'consentManagerIsConnected' => $this->siteContentDetector->isConnected - ), $viewType = 'basic'); + 'consentManagerName' => false, + ]; + + $detectedConsentManagers = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER); + if (!empty($detectedConsentManagers)) { + $consentManagerId = reset($detectedConsentManagers); + $consentManager = $this->siteContentDetector->getSiteContentDetectionById($consentManagerId); + $emailTemplateData['consentManagerName'] = $consentManager::getName(); + $emailTemplateData['consentManagerUrl'] = $consentManager::getInstructionUrl(); + } + $emailTemplateData['cms'] = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CMS); + $emailTemplateData['jsFrameworks'] = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_JS_FRAMEWORK); + $emailTemplateData['trackers'] = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_TRACKER); + + $emailBody = $this->renderTemplateAs('@SitesManager/_trackingCodeEmail', $emailTemplateData, $viewType = 'basic'); // Load the Tracking code and help text from the SitesManager $viewTrackingHelp = new \Piwik\View('@SitesManager/_displayJavascriptCode'); @@ -425,14 +433,6 @@ public function trackingCode() $viewTrackingHelp->piwikUrl = Url::getCurrentUrlWithoutFileName(); $viewTrackingHelp->isInstall = true; - $viewTrackingHelp->gtmUsed = $this->siteContentDetector->gtm; - $viewTrackingHelp->ga3Used = $this->siteContentDetector->ga3; - $viewTrackingHelp->ga4Used = $this->siteContentDetector->ga4; - $viewTrackingHelp->cloudflare = $this->siteContentDetector->cloudflare; - $viewTrackingHelp->consentManagerName = $this->siteContentDetector->consentManagerName; - $viewTrackingHelp->consentManagerUrl = $this->siteContentDetector->consentManagerUrl; - $viewTrackingHelp->consentManagerIsConnected = $this->siteContentDetector->isConnected; - $view->trackingHelp = $viewTrackingHelp->render(); $view->displaySiteName = $siteName; diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php index 140974b2c5f..84f8ceb073f 100644 --- a/plugins/PrivacyManager/Controller.php +++ b/plugins/PrivacyManager/Controller.php @@ -21,6 +21,7 @@ use Piwik\Plugins\CustomJsTracker\File; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\LanguagesManager\API as APILanguagesManager; +use Piwik\Plugins\SitesManager\SiteContentDetection\ConsentManagerDetectionAbstract; use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; use Piwik\SiteContentDetector; use Piwik\Scheduler\Scheduler; @@ -180,10 +181,15 @@ public function consent() $consentManager = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER); $view->consentManagerName = null; if (!empty($consentManager)) { - $contentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManager)); - $view->consentManagerName = $contentManager::getName(); - $view->consentManagerUrl = $consentManager::getInstructionUrl(); - $view->consentManagerIsConnected = in_array($contentManager::getId(), $this->siteContentDetector->connectedConsentManagers); + $consentManager = $this->siteContentDetector->getSiteContentDetectionById(reset($consentManager)); + if ($consentManager instanceof ConsentManagerDetectionAbstract) { + $view->consentManagerName = $consentManager::getName(); + $view->consentManagerUrl = $consentManager::getInstructionUrl(); + $view->consentManagerIsConnected = in_array( + $consentManager::getId(), + $this->siteContentDetector->connectedConsentManagers + ); + } } $consentManagers = SiteContentDetector::getKnownConsentManagers(); diff --git a/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_ConsentManager_consent_default.png b/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_ConsentManager_consent_default.png index d959fc586c8..f50c06fa2b2 100644 --- a/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_ConsentManager_consent_default.png +++ b/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_ConsentManager_consent_default.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8ba8275dd6a4adac8929cd16a033ae051722aaa5ba12aa43a02fd34ba0944b29 -size 133796 +oid sha256:d342763ef26cf2f670f657eb6a6b6d75bc26ed98d9c4364091d1e3c563bbb9eb +size 133806 diff --git a/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_consent_default.png b/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_consent_default.png index 390cf725590..19db295ddb0 100644 --- a/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_consent_default.png +++ b/plugins/PrivacyManager/tests/UI/expected-screenshots/PrivacyManager_consent_default.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f7a3461846c04188ef4753beffe09be161a42e098cd50c6f483ece4c4f22568d -size 113653 +oid sha256:638b13b5f9701e12ac4684a5abd36ee8ca26d475ae53d91e8a9324bf5c39f922 +size 113655 diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 79eb8709c86..c12859b34da 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -23,7 +23,7 @@ use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; +use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; use Piwik\Site; use Piwik\SiteContentDetector; use Piwik\Session; @@ -325,7 +325,7 @@ private function getCmsInstruction() $detectedCMSes = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CMS); if (empty($detectedCMSes) - || $this->siteContentDetector->wasDetected(Wordpress::getId())) { + || $this->siteContentDetector->wasDetected(WordPress::getId())) { return ''; } @@ -367,13 +367,13 @@ private function mergeMultipleNotification(&$templateData) $guides = []; $message = []; $ga3Used = $this->siteContentDetector->wasDetected(GoogleAnalytics3::getId()); - $ga4Used = $this->siteContentDetector->wasDetected(GoogleAnalytics4::getId());; + $ga4Used = $this->siteContentDetector->wasDetected(GoogleAnalytics4::getId()); if ($ga3Used || $ga4Used) { $message[0] = 'Google Analytics '; $ga3GuideUrl = 'Google Analytics 3'; $ga4GuideUrl = 'Google Analytics 4'; - if ($templateData['ga3Used'] && $templateData['ga4Used']) { + if ($ga3Used && $ga4Used) { $isNotificationsMerged = true; $guides[] = $ga3GuideUrl; $guides[] = $ga4GuideUrl; diff --git a/plugins/SitesManager/SiteContentDetection/Wordpress.php b/plugins/SitesManager/SiteContentDetection/WordPress.php similarity index 97% rename from plugins/SitesManager/SiteContentDetection/Wordpress.php rename to plugins/SitesManager/SiteContentDetection/WordPress.php index d640996535c..8566677a20a 100644 --- a/plugins/SitesManager/SiteContentDetection/Wordpress.php +++ b/plugins/SitesManager/SiteContentDetection/WordPress.php @@ -16,11 +16,11 @@ use Piwik\Url; use Piwik\View; -class Wordpress extends SiteContentDetectionAbstract +class WordPress extends SiteContentDetectionAbstract { public static function getName(): string { - return 'Wordpress'; + return 'WordPress'; } public static function getContentType(): string diff --git a/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php index 6d82b5c8a42..00ff23a0dfb 100644 --- a/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php +++ b/plugins/SitesManager/tests/Unit/SiteContentDetection/WordpressTest.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\SitesManager\tests\Unit\SiteContentDetection; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; +use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; /** * @group SitesManager @@ -23,7 +23,7 @@ class WordpressTest extends \PHPUnit\Framework\TestCase */ public function testdetectByContent($expected, $data, $headers) { - $detection = new Wordpress(); + $detection = new WordPress(); self::assertSame($expected, $detection->detectByContent($data, $headers)); } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php index ad8eb2de7d8..d058b5d816b 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionGTM.php @@ -9,7 +9,7 @@ use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; +use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; @@ -26,7 +26,7 @@ public function provideContainerConfig() { return [ SiteContentDetector::class => \Piwik\DI::autowire(FakeSiteContentDetector::class) - ->constructorParameter('detectedContentDetections', [GoogleTagManager::getId(), Cloudflare::getId(), Wordpress::getId()]) + ->constructorParameter('detectedContentDetections', [GoogleTagManager::getId(), Cloudflare::getId(), WordPress::getId()]) ]; } diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php index 9d90ef156fb..c961a1f1d31 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php @@ -8,7 +8,7 @@ namespace Piwik\Tests\Fixtures; use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; +use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; @@ -26,7 +26,7 @@ public function provideContainerConfig() { return [ SiteContentDetector::class => \DI\autowire(FakeSiteContentDetector::class) - ->constructorParameter('detectedContentDetections', [Wordpress::getId(), Cloudflare::getId()]) + ->constructorParameter('detectedContentDetections', [WordPress::getId(), Cloudflare::getId()]) ]; } diff --git a/tests/PHPUnit/Integration/SiteContentDetectorTest.php b/tests/PHPUnit/Integration/SiteContentDetectorTest.php index 2e31db06be2..51be8a6e668 100644 --- a/tests/PHPUnit/Integration/SiteContentDetectorTest.php +++ b/tests/PHPUnit/Integration/SiteContentDetectorTest.php @@ -11,7 +11,7 @@ use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; use Piwik\Plugins\SitesManager\SiteContentDetection\Osano; use Piwik\Plugins\SitesManager\SiteContentDetection\ReactJs; -use Piwik\Plugins\SitesManager\SiteContentDetection\Wordpress; +use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -34,7 +34,7 @@ public function testSiteWithMultipleDetections() ]); self::assertTrue($scd->wasDetected(Osano::getId())); - self::assertTrue($scd->wasDetected(Wordpress::getId())); + self::assertTrue($scd->wasDetected(WordPress::getId())); self::assertTrue($scd->wasDetected(ReactJs::getId())); self::assertTrue($scd->wasDetected(Cloudflare::getId())); self::assertContains(Osano::getId(), $scd->connectedConsentManagers); diff --git a/tests/UI/specs/EmptySite_React_spec.js b/tests/UI/specs/EmptySite_React_spec.js index b5c1ba9a1d4..9b34b5138ee 100644 --- a/tests/UI/specs/EmptySite_React_spec.js +++ b/tests/UI/specs/EmptySite_React_spec.js @@ -16,7 +16,7 @@ describe("EmptySite_React", function () { it('should show the tracking code if the website has no recorded data and React guide', async function () { const urlToTest = "?" + generalParams + "&module=CoreHome&action=index"; await page.goto(urlToTest); - await page.waitForSelector('#react .codeblock', { visible: true }); + await page.waitForSelector('#reactjs .codeblock', { visible: true }); await page.evaluate(function () { // since containerID will be random and keeps changing var selector = $('#react .codeblock'); diff --git a/tests/UI/specs/EmptySite_spec.js b/tests/UI/specs/EmptySite_spec.js index 7d7e1a3e705..5a083290620 100644 --- a/tests/UI/specs/EmptySite_spec.js +++ b/tests/UI/specs/EmptySite_spec.js @@ -39,12 +39,12 @@ describe("EmptySite", function () { it('should show the SPA/PWA tab when clicked', async function () { - await page.evaluate(() => $('.no-data-screen-ul-tabs a[href="#spa"]')[0].click()); + await page.evaluate(() => $('.no-data-screen-ul-tabs a[href="#spapwa"]')[0].click()); await page.waitForTimeout(500); await page.evaluate(function () { // since containerID will be random and keeps changing - var selector = $('#spa .codeblock'); + var selector = $('#spapwa .codeblock'); selector.text(selector.text().replace(/container_(.*).js/g, 'container_test123.js')); }); From 821e9d9c0fdb8d7f3ed8e10f4b22ce7f8aeefd2c Mon Sep 17 00:00:00 2001 From: sgiehl Date: Tue, 18 Jul 2023 09:47:46 +0200 Subject: [PATCH 12/35] pass detector to render method --- core/SiteContentDetector.php | 8 ++------ plugins/SitesManager/Controller.php | 4 ++-- .../SitesManager/SiteContentDetection/Cloudflare.php | 3 ++- .../SiteContentDetection/GoogleTagManager.php | 3 ++- .../SiteContentDetection/MatomoTagManager.php | 2 +- plugins/SitesManager/SiteContentDetection/ReactJs.php | 3 ++- .../SiteContentDetectionAbstract.php | 4 ++-- plugins/SitesManager/SiteContentDetection/SpaPwa.php | 2 +- plugins/SitesManager/SiteContentDetection/VueJs.php | 3 ++- .../SitesManager/SiteContentDetection/WordPress.php | 3 ++- plugins/SitesManager/SitesManager.php | 11 ----------- tests/UI/specs/EmptySite_React_spec.js | 2 +- 12 files changed, 19 insertions(+), 29 deletions(-) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index a0768c94f53..a8b708c1701 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -30,7 +30,7 @@ * Usage: * * $contentDetector = new SiteContentDetector(); - * $contentDetector->detectContent([SiteContentDetector::GA3]); + * $contentDetector->detectContent([GoogleAnalytics3::getId()]); * if ($contentDetector->ga3) { * // site is using GA3 * } @@ -156,11 +156,7 @@ public function detectContent(array $detectContent = [], // Get the site id from the request object if not explicitly passed if ($idSite === null) { - if (!isset($_REQUEST['idSite'])) { - return; - } - - $idSite = Common::getRequestVar('idSite', null, 'int'); + $idSite = Request::fromRequest()->getIntegerParameter('idSite', 0); if (!$idSite) { return; diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index c12859b34da..fe8bb0f0ddd 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -164,7 +164,7 @@ public function siteWithoutData() 'consentManagerName' => false, ]; - $this->siteContentDetector->detectContent(); + $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT], $this->idSite); $detectedConsentManagers = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER); if (!empty($detectedConsentManagers)) { $consentManagerId = reset($detectedConsentManagers); @@ -261,7 +261,7 @@ public function siteWithoutDataTabs() foreach ($this->siteContentDetector->getSiteContentDetectionsByType() as $detections) { foreach ($detections as $obj) { - $tabContent = $obj->renderInstructionsTab([]); + $tabContent = $obj->renderInstructionsTab($this->siteContentDetector); $othersInstruction = $obj->renderOthersInstruction(); $instructionUrl = $obj->getInstructionUrl(); diff --git a/plugins/SitesManager/SiteContentDetection/Cloudflare.php b/plugins/SitesManager/SiteContentDetection/Cloudflare.php index f155610ff0a..50de0b69d68 100644 --- a/plugins/SitesManager/SiteContentDetection/Cloudflare.php +++ b/plugins/SitesManager/SiteContentDetection/Cloudflare.php @@ -12,6 +12,7 @@ use Piwik\Piwik; use Piwik\Request; +use Piwik\SiteContentDetector; use Piwik\View; class Cloudflare extends SiteContentDetectionAbstract @@ -53,7 +54,7 @@ public function shouldHighlightTabIfShown(): bool return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { $view = new View("@SitesManager/_cloudflareTabInstructions"); $view->idSite = Request::fromRequest()->getIntegerParameter('idSite'); diff --git a/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php b/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php index bf0964f16cb..e1f125d6862 100644 --- a/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php @@ -12,6 +12,7 @@ use Piwik\API\Request; use Piwik\Piwik; +use Piwik\SiteContentDetector; use Piwik\Url; use Piwik\View; @@ -64,7 +65,7 @@ public function shouldHighlightTabIfShown(): bool return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { $piwikUrl = Url::getCurrentUrlWithoutFileName(); $jsTag = Request::processRequest( diff --git a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php index 2256416ffbf..611994ba2ff 100644 --- a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php @@ -47,7 +47,7 @@ public function shouldShowInstructionTab(SiteContentDetector $detector = null): return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { return '

' . Piwik::translate('SitesManager_SiteWithoutDataMatomoTagManager') . '

' . Piwik::translate( 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive', ['', '']) . '

'; diff --git a/plugins/SitesManager/SiteContentDetection/ReactJs.php b/plugins/SitesManager/SiteContentDetection/ReactJs.php index 2d2d5dd1987..0d8837e60d7 100644 --- a/plugins/SitesManager/SiteContentDetection/ReactJs.php +++ b/plugins/SitesManager/SiteContentDetection/ReactJs.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\SitesManager\SiteContentDetection; use Piwik\Piwik; +use Piwik\SiteContentDetector; class ReactJs extends SiteContentDetectionAbstract { @@ -59,7 +60,7 @@ public function shouldHighlightTabIfShown(): bool return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { return '

diff --git a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php index 379ee7edd47..d9f3dc009df 100644 --- a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php +++ b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php @@ -106,10 +106,10 @@ public function shouldHighlightTabIfShown(): bool /** * Returns the content that should be rendered into a new Tab on the no data page * - * @param array $detections + * @param SiteContentDetector|null $detector * @return string|null */ - public function renderInstructionsTab(array $detections = []): ?string + public function renderInstructionsTab(SiteContentDetector $detector = null): ?string { return null; } diff --git a/plugins/SitesManager/SiteContentDetection/SpaPwa.php b/plugins/SitesManager/SiteContentDetection/SpaPwa.php index a845460e8f8..3fa35203842 100644 --- a/plugins/SitesManager/SiteContentDetection/SpaPwa.php +++ b/plugins/SitesManager/SiteContentDetection/SpaPwa.php @@ -40,7 +40,7 @@ public function shouldShowInstructionTab(SiteContentDetector $detector = null): return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { return ''; } diff --git a/plugins/SitesManager/SiteContentDetection/VueJs.php b/plugins/SitesManager/SiteContentDetection/VueJs.php index fafb8a2ea5a..1cf869f543d 100644 --- a/plugins/SitesManager/SiteContentDetection/VueJs.php +++ b/plugins/SitesManager/SiteContentDetection/VueJs.php @@ -12,6 +12,7 @@ use Piwik\Container\StaticContainer; use Piwik\Piwik; +use Piwik\SiteContentDetector; use Piwik\Url; use Piwik\View; @@ -47,7 +48,7 @@ public function shouldHighlightTabIfShown(): bool return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { $view = new View("@SitesManager/_vueTabInstructions"); $view->sendHeadersWhenRendering = false; diff --git a/plugins/SitesManager/SiteContentDetection/WordPress.php b/plugins/SitesManager/SiteContentDetection/WordPress.php index 8566677a20a..d0c3f776fbc 100644 --- a/plugins/SitesManager/SiteContentDetection/WordPress.php +++ b/plugins/SitesManager/SiteContentDetection/WordPress.php @@ -13,6 +13,7 @@ use Piwik\Piwik; use Piwik\Plugin\Manager; use Piwik\SettingsPiwik; +use Piwik\SiteContentDetector; use Piwik\Url; use Piwik\View; @@ -49,7 +50,7 @@ public function shouldHighlightTabIfShown(): bool return true; } - public function renderInstructionsTab(array $detections = []): string + public function renderInstructionsTab(SiteContentDetector $detector = null): string { $view = new View("@SitesManager/_wordpressTabInstructions"); $faqLink = 'https://matomo.org/faq/general/faq_114/'; diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 83390a5b468..e0477524d68 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -34,17 +34,6 @@ class SitesManager extends \Piwik\Plugin const KEEP_URL_FRAGMENT_USE_DEFAULT = 0; const KEEP_URL_FRAGMENT_YES = 1; const KEEP_URL_FRAGMENT_NO = 2; - const SITE_TYPE_UNKNOWN = 'unknown'; - const SITE_TYPE_WORDPRESS = 'wordpress'; - const SITE_TYPE_SQUARESPACE = 'squarespace'; - const SITE_TYPE_WIX = 'wix'; - const SITE_TYPE_SHAREPOINT = 'sharepoint'; - const SITE_TYPE_JOOMLA = 'joomla'; - const SITE_TYPE_SHOPIFY = 'shopify'; - const SITE_TYPE_WEBFLOW = 'webflow'; - const SITE_TYPE_DRUPAL = 'drupal'; - const JS_FRAMEWORK_VUE = 'vue'; - const JS_FRAMEWORK_REACT = 'react'; /** * @see \Piwik\Plugin::registerEvents diff --git a/tests/UI/specs/EmptySite_React_spec.js b/tests/UI/specs/EmptySite_React_spec.js index 9b34b5138ee..f3bbb0ee259 100644 --- a/tests/UI/specs/EmptySite_React_spec.js +++ b/tests/UI/specs/EmptySite_React_spec.js @@ -19,7 +19,7 @@ describe("EmptySite_React", function () { await page.waitForSelector('#reactjs .codeblock', { visible: true }); await page.evaluate(function () { // since containerID will be random and keeps changing - var selector = $('#react .codeblock'); + var selector = $('#reactjs .codeblock'); selector.text(selector.text().replace(/container_(.*).js/g, 'container_test123.js')); }); From 59b26fe1c4ee1bc653f64851c1862602dcebce0b Mon Sep 17 00:00:00 2001 From: sgiehl Date: Tue, 18 Jul 2023 10:13:30 +0200 Subject: [PATCH 13/35] remove not needed constant --- core/SiteContentDetector.php | 5 +---- plugins/Installation/Controller.php | 2 +- plugins/SitesManager/Controller.php | 4 ++-- tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php | 2 +- tests/PHPUnit/Integration/SiteContentDetectorTest.php | 2 +- 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index a8b708c1701..2fdd284d7d4 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -39,9 +39,6 @@ */ class SiteContentDetector { - // Content types - const ALL_CONTENT = 1; - /** * @var array> */ @@ -287,7 +284,7 @@ private function detectionChecks($detectContent): void if (in_array($type, $detectContent) || in_array($typeDetection::getId(), $detectContent) || - in_array(SiteContentDetector::ALL_CONTENT, $detectContent)) + empty($detectContent)) { $this->detectedContent[$type][$typeDetection::getId()] = false; diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index f5d3ca11bab..b42a3a22e7d 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -401,7 +401,7 @@ public function trackingCode() $trackingUrl = trim(SettingsPiwik::getPiwikUrl(), '/') . '/' . $javascriptGenerator->getPhpTrackerEndpoint(); - $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT]); + $this->siteContentDetector->detectContent(); $emailTemplateData = [ 'jsTag' => $rawJsTag, diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index fe8bb0f0ddd..fe6565e1dfd 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -164,7 +164,7 @@ public function siteWithoutData() 'consentManagerName' => false, ]; - $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT], $this->idSite); + $this->siteContentDetector->detectContent([], $this->idSite); $detectedConsentManagers = $this->siteContentDetector->getDetectsByType(SiteContentDetectionAbstract::TYPE_CONSENT_MANAGER); if (!empty($detectedConsentManagers)) { $consentManagerId = reset($detectedConsentManagers); @@ -219,7 +219,7 @@ public function siteWithoutDataTabs() Piwik::postEvent('SitesManager.siteWithoutData.customizeImporterMessage', [&$googleAnalyticsImporterMessage]); } - $this->siteContentDetector->detectContent([SiteContentDetector::ALL_CONTENT], $this->idSite); + $this->siteContentDetector->detectContent([], $this->idSite); $dntChecker = new DoNotTrackHeaderChecker(); $templateData = [ diff --git a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php index a406c68a02f..32e9567ad70 100644 --- a/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php +++ b/tests/PHPUnit/Framework/Mock/FakeSiteContentDetector.php @@ -20,7 +20,7 @@ public function __construct($detectedContentDetections = [], $connectedConsentMa parent::__construct(null); } - public function detectContent(array $detectContent = [SiteContentDetector::ALL_CONTENT], + public function detectContent(array $detectContent = [], ?int $idSite = null, ?array $siteResponse = null, int $timeOut = 60): void { // skip any detections diff --git a/tests/PHPUnit/Integration/SiteContentDetectorTest.php b/tests/PHPUnit/Integration/SiteContentDetectorTest.php index 51be8a6e668..9a20b3deeef 100644 --- a/tests/PHPUnit/Integration/SiteContentDetectorTest.php +++ b/tests/PHPUnit/Integration/SiteContentDetectorTest.php @@ -26,7 +26,7 @@ class SiteContentDetectorTest extends IntegrationTestCase public function testSiteWithMultipleDetections() { $scd = new SiteContentDetector(); - $scd->detectContent([SiteContentDetector::ALL_CONTENT], null, [ + $scd->detectContent([], null, [ 'data' => "A siteA site", 'headers' => [ 'CF-RAY' => 'test' From 0ac14ff80aa94ca309e8f995e8fb89e1ce208d20 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Tue, 18 Jul 2023 11:03:42 +0200 Subject: [PATCH 14/35] fix caching --- core/SiteContentDetector.php | 72 ++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index 2fdd284d7d4..3c753d9acc2 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -14,17 +14,13 @@ use Piwik\Config\GeneralConfig; use Piwik\Container\StaticContainer; use Piwik\Plugins\SitesManager\SiteContentDetection\ConsentManagerDetectionAbstract; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics3; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleAnalytics4; -use Piwik\Plugins\SitesManager\SiteContentDetection\GoogleTagManager; use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract; -use Piwik\Plugins\SitesManager\SitesManager; /** * This class provides detection functions for specific content on a site. It can be used to easily detect the * presence of known third party code. * - * Note: Calling the detect() method will create a HTTP request to the site to retrieve data, only the main site URL + * Note: Calling the `detectContent()` method will create a HTTP request to the site to retrieve data, only the main site URL * will be checked * * Usage: @@ -167,9 +163,9 @@ public function detectContent(array $detectContent = [], $siteContentDetectionCache = $this->cache->fetch($cacheKey); if ($siteContentDetectionCache !== false) { - $cachedSiteContentDetection = $siteContentDetectionCache; - if ($this->checkCacheHasRequiredProperties($detectContent, $cachedSiteContentDetection)) { - $this->detectedContent = $cachedSiteContentDetection; + if ($this->checkCacheHasRequiredProperties($detectContent, $siteContentDetectionCache)) { + $this->detectedContent = $siteContentDetectionCache['detectedContent']; + $this->connectedConsentManagers = $siteContentDetectionCache['connectedConsentManagers']; return; } } @@ -189,7 +185,7 @@ public function detectContent(array $detectContent = [], // A request was made to get this data and it isn't currently cached, so write it to the cache now $cacheLife = (60 * 60 * 24 * 7); - $this->savePropertiesToCache($cacheKey, $this->detectedContent, $cacheLife); + $this->saveToCache($cacheKey, $cacheLife); } /** @@ -226,32 +222,62 @@ public function getDetectsByType(string $type): array } /** - * Checks that all required properties are in the cache array + * Checks that all required detections are in the cache array * - * @param array $properties + * @param array $detectContent * @param array $cache * * @return bool */ - private function checkCacheHasRequiredProperties(array $properties, array $cache): bool + private function checkCacheHasRequiredProperties(array $detectContent, array $cache): bool { - // todo implement + if (empty($detectContent)) { + foreach (self::getSiteContentDetectionsByType() as $type => $entries) { + foreach ($entries as $entry) { + if (!isset($cache['detectedContent'][$type][$entry::getId()])) { + return false; // random detection missing + } + } + } + + return true; + } + + foreach ($detectContent as $requestedDetection) { + if (is_string($requestedDetection)) { // specific detection + $detectionObj = $this->getSiteContentDetectionById($requestedDetection); + if (null !== $detectionObj && !isset($cache['detectedContent'][$detectionObj::getContentType()][$detectionObj::getId()])) { + return false; // specific detection was run before + } + } elseif (is_int($requestedDetection)) { // detection type requested + $detectionsByType = self::getSiteContentDetectionsByType(); + if (isset($detectionsByType[$requestedDetection])) { + foreach ($detectionsByType[$requestedDetection] as $detectionObj) { + if (!isset($cache['detectedContent'][$requestedDetection][$detectionObj::getId()])) { + return false; // random detection missing + } + } + } + } + } return true; } /** - * Save properties to the cache + * Save data to the cache * * @param string $cacheKey - * @param array $detectionTypes * @param int $cacheLife * * @return void */ - private function savePropertiesToCache(string $cacheKey, array $detectionTypes, int $cacheLife): void + private function saveToCache(string $cacheKey, int $cacheLife): void { - $cacheData = []; + $cacheData = [ + 'detectedContent' => [], + 'connectedConsentManagers' => [], + ]; // Load any existing cached values $siteContentDetectionCache = $this->cache->fetch($cacheKey); @@ -260,10 +286,18 @@ private function savePropertiesToCache(string $cacheKey, array $detectionTypes, $cacheData = $siteContentDetectionCache; } - foreach ($detectionTypes as $type) { - $cacheData[$type] = $this->detectedContent[$type]; + foreach ($this->detectedContent as $type => $detections) { + if (!isset($cacheData['detectedContent'][$type])) { + $cacheData['detectedContent'][$type] = []; + } + foreach ($detections as $detectionId => $wasDetected) + if (null !== $wasDetected) { + $cacheData['detectedContent'][$type][$detectionId] = $wasDetected; + } } + $cacheData['connectedConsentManagers'] = array_merge($cacheData['connectedConsentManagers'], $this->connectedConsentManagers); + $this->cache->save($cacheKey, $cacheData, $cacheLife); } From 0403d6003f8b9d2658bfce4d4c40389fb23fcf67 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Tue, 18 Jul 2023 15:16:57 +0200 Subject: [PATCH 15/35] code cleanup --- core/SiteContentDetector.php | 19 +++++++++++++++---- plugins/Installation/Controller.php | 2 +- plugins/SitesManager/Controller.php | 13 ++++++++++++- .../ConsentManagerDetectionAbstract.php | 3 +-- .../SiteContentDetection/GoogleAnalytics3.php | 1 - .../SiteContentDetection/GoogleAnalytics4.php | 1 - .../SiteContentDetectionAbstract.php | 14 ++++++-------- plugins/SitesManager/SitesManager.php | 2 -- .../templates/_siteWithoutDataTabs.twig | 4 ++-- .../templates/_trackingCodeEmail.twig | 2 +- .../Fixtures/DisableSiteContentDetection.php | 1 - ...ySiteWithSiteContentDetectionWordpress.php | 1 - .../Integration/SiteContentDetectorTest.php | 12 +++++++++--- 13 files changed, 47 insertions(+), 28 deletions(-) diff --git a/core/SiteContentDetector.php b/core/SiteContentDetector.php index 3c753d9acc2..adf1023e11c 100644 --- a/core/SiteContentDetector.php +++ b/core/SiteContentDetector.php @@ -36,7 +36,7 @@ class SiteContentDetector { /** - * @var array> + * @var array> */ public $detectedContent = [ SiteContentDetectionAbstract::TYPE_TRACKER => [], @@ -82,6 +82,8 @@ public static function getSiteContentDetectionsByType() } /** + * Returns the site content detection object with the provided id, or null if it can't be found + * * @param string $id * @return SiteContentDetectionAbstract|null */ @@ -128,7 +130,11 @@ private function resetDetections(): void * the details of the detected content * * @param array $detectContent Array of content type for which to check, defaults to all, limiting this list - * will speed up the detection check + * will speed up the detection check. + * Allowed values are: + * * empty array - to run all detections + * * an array containing ids of detections, e.g. Wordpress::getId() or any of the + * type constants, e.g. SiteContentDetectionAbstract::TYPE_TRACKER * @param ?int $idSite Override the site ID, will use the site from the current request if null * @param ?array $siteResponse String containing the site data to search, if blank then data will be retrieved * from the current request site via an http request @@ -207,6 +213,12 @@ public function wasDetected(string $detectionClassId): bool return false; } + /** + * Returns an array containing ids of all detected detections of the given type + * + * @param string $type One of the SiteContentDetectionAbstract::TYPE_* constants + * @return array + */ public function getDetectsByType(string $type): array { $detected = []; @@ -217,7 +229,6 @@ public function getDetectsByType(string $type): array } } - return $detected; } @@ -308,7 +319,7 @@ private function saveToCache(string $cacheKey, int $cacheLife): void * * @return void */ - private function detectionChecks($detectContent): void + private function detectionChecks(array $detectContent): void { $detections = $this->getSiteContentDetectionsByType(); diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index b42a3a22e7d..b9a60927501 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -401,7 +401,7 @@ public function trackingCode() $trackingUrl = trim(SettingsPiwik::getPiwikUrl(), '/') . '/' . $javascriptGenerator->getPhpTrackerEndpoint(); - $this->siteContentDetector->detectContent(); + $this->siteContentDetector->detectContent([], $idSite); $emailTemplateData = [ 'jsTag' => $rawJsTag, diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index fe6565e1dfd..92788241c1a 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -208,7 +208,7 @@ public function siteWithoutDataTabs() Piwik::postEvent('SitesManager.showMatomoLinksInTrackingCodeEmail', [&$showMatomoLinks]); $googleAnalyticsImporterMessage = ''; - if (Manager::getInstance()->isPluginLoaded('GoogleAnalyticsImporter')) { + if (!Manager::getInstance()->isPluginLoaded('GoogleAnalyticsImporter')) { $googleAnalyticsImporterMessage = '

' . Piwik::translate('CoreAdminHome_ImportFromGoogleAnalytics') . '

' . '

' . Piwik::translate('CoreAdminHome_ImportFromGoogleAnalyticsDescription', ['', '']) . '

' . '

'; @@ -265,7 +265,18 @@ public function siteWithoutDataTabs() $othersInstruction = $obj->renderOthersInstruction(); $instructionUrl = $obj->getInstructionUrl(); + /** + * Event that can be used to manipulate the content of a certain tab on the no data page + * + * @param string $tabContent Content of the tab + */ Piwik::postEvent('Template.siteWithoutDataTab.' . $obj::getId() . '.content', [&$tabContent]); + /** + * Event that can be used to manipulate the content of a record on the others tab on the no data page + * + * @param string $othersInstruction Content of the record + */ + Piwik::postEvent('Template.siteWithoutDataTab.' . $obj::getId() . '.others', [&$othersInstruction]); if (!empty($tabContent) && $obj->shouldShowInstructionTab($this->siteContentDetector)) { $templateData['tabs'][] = [ diff --git a/plugins/SitesManager/SiteContentDetection/ConsentManagerDetectionAbstract.php b/plugins/SitesManager/SiteContentDetection/ConsentManagerDetectionAbstract.php index b754a79f851..372217c5791 100644 --- a/plugins/SitesManager/SiteContentDetection/ConsentManagerDetectionAbstract.php +++ b/plugins/SitesManager/SiteContentDetection/ConsentManagerDetectionAbstract.php @@ -25,5 +25,4 @@ final public static function getContentType(): string * @return bool */ abstract public function checkIsConnected(?string $data = null, ?array $headers = null): bool; - -} \ No newline at end of file +} diff --git a/plugins/SitesManager/SiteContentDetection/GoogleAnalytics3.php b/plugins/SitesManager/SiteContentDetection/GoogleAnalytics3.php index f379a17c775..39afd5c99b9 100644 --- a/plugins/SitesManager/SiteContentDetection/GoogleAnalytics3.php +++ b/plugins/SitesManager/SiteContentDetection/GoogleAnalytics3.php @@ -44,5 +44,4 @@ public function detectByContent(?string $data = null, ?array $headers = null): b } return false; } - } diff --git a/plugins/SitesManager/SiteContentDetection/GoogleAnalytics4.php b/plugins/SitesManager/SiteContentDetection/GoogleAnalytics4.php index 3a4bad34c25..8cf25cd7bf0 100644 --- a/plugins/SitesManager/SiteContentDetection/GoogleAnalytics4.php +++ b/plugins/SitesManager/SiteContentDetection/GoogleAnalytics4.php @@ -41,5 +41,4 @@ public function detectByContent(?string $data = null, ?array $headers = null): b return false; } - } diff --git a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php index d9f3dc009df..2d89a745205 100644 --- a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php +++ b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php @@ -20,17 +20,15 @@ abstract class SiteContentDetectionAbstract public const TYPE_CONSENT_MANAGER = 4; public const TYPE_OTHER = 99; - /** - * Holds the detection state, once it was executed - * - * @var null|bool - */ - protected $wasDetected = null; - public function __construct() { } + /** + * Returns the ID of the current detection. Automatically built from the class name (without namespace) + * + * @return string + */ public static function getId(): string { $classParts = explode('\\', static::class); @@ -123,4 +121,4 @@ public function renderOthersInstruction(): ?string { return null; } -} \ No newline at end of file +} diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index e0477524d68..aa6687c3c60 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -447,8 +447,6 @@ public function getClientSideTranslationKeys(&$translationKeys) $translationKeys[] = "SitesManager_EmailInstructionsButton"; $translationKeys[] = "SitesManager_EmailInstructionsSubject"; $translationKeys[] = "SitesManager_JsTrackingTagHelp"; - $translationKeys[] = "SitesManager_SiteWithoutDataSinglePageApplication"; - $translationKeys[] = "SitesManager_SiteWithoutDataSinglePageApplicationDescription"; $translationKeys[] = 'SitesManager_SiteWithoutDataTitle'; $translationKeys[] = 'SitesManager_SiteWithoutDataDescription'; $translationKeys[] = 'SitesManager_SiteWithoutDataMessageDisappears'; diff --git a/plugins/SitesManager/templates/_siteWithoutDataTabs.twig b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig index 53afaba0007..1bc0acb1f76 100644 --- a/plugins/SitesManager/templates/_siteWithoutDataTabs.twig +++ b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig @@ -21,13 +21,13 @@
diff --git a/plugins/SitesManager/templates/_trackingCodeEmail.twig b/plugins/SitesManager/templates/_trackingCodeEmail.twig index 9241a5195f5..ce6b974f051 100644 --- a/plugins/SitesManager/templates/_trackingCodeEmail.twig +++ b/plugins/SitesManager/templates/_trackingCodeEmail.twig @@ -6,7 +6,7 @@ {{ 'SitesManager_GADetectedEmail'|translate('Google Analytics 3', 'GA', 'https://matomo.org/faq/how-to/migrate-from-google-analytics-3-to-matomo/')|raw }} {% endif %} -{% if 'GoogleAnalytics3' in trackers %} +{% if 'GoogleAnalytics4' in trackers %} {{ 'SitesManager_GADetectedEmail'|translate('Google Analytics 4', 'GA', 'https://matomo.org/faq/how-to/migrate-from-google-analytics-4-to-matomo/')|raw }} {% endif %} diff --git a/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php b/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php index b8a4cccdc61..79bb7e9361c 100644 --- a/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php +++ b/tests/PHPUnit/Fixtures/DisableSiteContentDetection.php @@ -7,7 +7,6 @@ */ namespace Piwik\Tests\Fixtures; -use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; diff --git a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php index c961a1f1d31..51193fb9194 100644 --- a/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php +++ b/tests/PHPUnit/Fixtures/EmptySiteWithSiteContentDetectionWordpress.php @@ -9,7 +9,6 @@ use Piwik\Plugins\SitesManager\SiteContentDetection\Cloudflare; use Piwik\Plugins\SitesManager\SiteContentDetection\WordPress; -use Piwik\Plugins\SitesManager\SitesManager; use Piwik\Tests\Framework\Fixture; use Piwik\SiteContentDetector; use Piwik\Tests\Framework\Mock\FakeSiteContentDetector; diff --git a/tests/PHPUnit/Integration/SiteContentDetectorTest.php b/tests/PHPUnit/Integration/SiteContentDetectorTest.php index 9a20b3deeef..bb957e49e74 100644 --- a/tests/PHPUnit/Integration/SiteContentDetectorTest.php +++ b/tests/PHPUnit/Integration/SiteContentDetectorTest.php @@ -21,13 +21,19 @@ */ class SiteContentDetectorTest extends IntegrationTestCase { - - public function testSiteWithMultipleDetections() { $scd = new SiteContentDetector(); $scd->detectContent([], null, [ - 'data' => "A siteA site", + 'data' => " + + A site + + + + + A site + ", 'headers' => [ 'CF-RAY' => 'test' ], From f73de93d81c40c918dcc43c1b22a5fac93b9f6d3 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 31 Jul 2023 10:49:08 +0200 Subject: [PATCH 16/35] hide listing on others tab if corresponding tab is displayed --- plugins/SitesManager/Controller.php | 4 ++-- plugins/SitesManager/SiteContentDetection/Cloudflare.php | 6 +++++- .../SitesManager/SiteContentDetection/GoogleTagManager.php | 6 +++++- .../SitesManager/SiteContentDetection/MatomoTagManager.php | 2 +- plugins/SitesManager/SiteContentDetection/ReactJs.php | 6 +++++- .../SiteContentDetection/SiteContentDetectionAbstract.php | 3 ++- plugins/SitesManager/SiteContentDetection/SpaPwa.php | 2 +- plugins/SitesManager/SiteContentDetection/VueJs.php | 6 +++++- plugins/SitesManager/SiteContentDetection/WordPress.php | 6 +++++- 9 files changed, 31 insertions(+), 10 deletions(-) diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 92788241c1a..4cabbf4a9a4 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -262,7 +262,7 @@ public function siteWithoutDataTabs() foreach ($this->siteContentDetector->getSiteContentDetectionsByType() as $detections) { foreach ($detections as $obj) { $tabContent = $obj->renderInstructionsTab($this->siteContentDetector); - $othersInstruction = $obj->renderOthersInstruction(); + $othersInstruction = $obj->renderOthersInstruction($this->siteContentDetector); $instructionUrl = $obj->getInstructionUrl(); /** @@ -298,7 +298,7 @@ public function siteWithoutDataTabs() 'id' => $obj::getId(), 'name' => $obj::getName(), 'type' => $obj::getContentType(), - 'othersInstruction' => $obj->renderOthersInstruction(), + 'othersInstruction' => $othersInstruction, ]; } diff --git a/plugins/SitesManager/SiteContentDetection/Cloudflare.php b/plugins/SitesManager/SiteContentDetection/Cloudflare.php index 50de0b69d68..5e33e82914b 100644 --- a/plugins/SitesManager/SiteContentDetection/Cloudflare.php +++ b/plugins/SitesManager/SiteContentDetection/Cloudflare.php @@ -62,8 +62,12 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return $view->render(); } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { + if ($detector->wasDetected(self::class)) { + return ''; // don't show on others page if tab is being displayed + } + return sprintf( '

%s

', Piwik::translate( diff --git a/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php b/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php index e1f125d6862..d3331b4dfee 100644 --- a/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/GoogleTagManager.php @@ -81,8 +81,12 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return $view->render(); } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { + if ($detector->wasDetected(self::class)) { + return ''; // don't show on others page if tab is being displayed + } + return sprintf( '

%s

', Piwik::translate( diff --git a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php index 611994ba2ff..f458286ca2e 100644 --- a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php @@ -53,7 +53,7 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str

' . Piwik::translate( 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive', ['', '']) . '

'; } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { return sprintf( '

%s

', diff --git a/plugins/SitesManager/SiteContentDetection/ReactJs.php b/plugins/SitesManager/SiteContentDetection/ReactJs.php index 0d8837e60d7..4f1754c8d00 100644 --- a/plugins/SitesManager/SiteContentDetection/ReactJs.php +++ b/plugins/SitesManager/SiteContentDetection/ReactJs.php @@ -82,8 +82,12 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str '; } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { + if ($detector->wasDetected(self::class)) { + return ''; // don't show on others page if tab is being displayed + } + return sprintf( '

%s

', Piwik::translate( diff --git a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php index 2d89a745205..178a2036941 100644 --- a/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php +++ b/plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php @@ -115,9 +115,10 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): ?st /** * Returns the content that should be displayed in the Others tab on the no data page * + * @param SiteContentDetector|null $detector * @return string|null */ - public function renderOthersInstruction(): ?string + public function renderOthersInstruction(SiteContentDetector $detector = null): ?string { return null; } diff --git a/plugins/SitesManager/SiteContentDetection/SpaPwa.php b/plugins/SitesManager/SiteContentDetection/SpaPwa.php index 3fa35203842..b17b0115cc0 100644 --- a/plugins/SitesManager/SiteContentDetection/SpaPwa.php +++ b/plugins/SitesManager/SiteContentDetection/SpaPwa.php @@ -45,7 +45,7 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return ''; } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { return sprintf( '

%s

', diff --git a/plugins/SitesManager/SiteContentDetection/VueJs.php b/plugins/SitesManager/SiteContentDetection/VueJs.php index 1cf869f543d..fed6787f987 100644 --- a/plugins/SitesManager/SiteContentDetection/VueJs.php +++ b/plugins/SitesManager/SiteContentDetection/VueJs.php @@ -58,8 +58,12 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return $view->render(); } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { + if ($detector->wasDetected(self::class)) { + return ''; // don't show on others page if tab is being displayed + } + return sprintf( '

%s

', Piwik::translate( diff --git a/plugins/SitesManager/SiteContentDetection/WordPress.php b/plugins/SitesManager/SiteContentDetection/WordPress.php index d0c3f776fbc..087c4c123ff 100644 --- a/plugins/SitesManager/SiteContentDetection/WordPress.php +++ b/plugins/SitesManager/SiteContentDetection/WordPress.php @@ -77,8 +77,12 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return $view->render(); } - public function renderOthersInstruction(): string + public function renderOthersInstruction(SiteContentDetector $detector = null): string { + if ($detector->wasDetected(self::class)) { + return ''; // don't show on others page if tab is being displayed + } + return sprintf( '

%s

', Piwik::translate( From 3f63003419bd00b875ec92f8fdce4c9bf6f364d1 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Thu, 3 Aug 2023 14:35:35 +0200 Subject: [PATCH 17/35] hide spa/pwa on others pages --- .../SitesManager/SiteContentDetection/SpaPwa.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/plugins/SitesManager/SiteContentDetection/SpaPwa.php b/plugins/SitesManager/SiteContentDetection/SpaPwa.php index b17b0115cc0..80401032c28 100644 --- a/plugins/SitesManager/SiteContentDetection/SpaPwa.php +++ b/plugins/SitesManager/SiteContentDetection/SpaPwa.php @@ -44,18 +44,4 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str { return ''; } - - public function renderOthersInstruction(SiteContentDetector $detector = null): string - { - return sprintf( - '

%s

', - Piwik::translate( - 'SitesManager_SiteWithoutDataSinglePageApplicationDescription', - [ - '', - '', - ] - ) - ); - } } From 430c49222f264fbde1737a0e259315b54f9b5322 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Thu, 3 Aug 2023 14:36:18 +0200 Subject: [PATCH 18/35] remove incorrectly copied code --- .../SiteContentDetection/MatomoTagManager.php | 14 -------------- .../SitesManager/SiteContentDetection/SpaPwa.php | 1 - 2 files changed, 15 deletions(-) diff --git a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php index f458286ca2e..d1279eaf735 100644 --- a/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php +++ b/plugins/SitesManager/SiteContentDetection/MatomoTagManager.php @@ -52,18 +52,4 @@ public function renderInstructionsTab(SiteContentDetector $detector = null): str return '

' . Piwik::translate('SitesManager_SiteWithoutDataMatomoTagManager') . '

' . Piwik::translate( 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive', ['', '']) . '

'; } - - public function renderOthersInstruction(SiteContentDetector $detector = null): string - { - return sprintf( - '

%s

', - Piwik::translate( - 'SitesManager_SiteWithoutDataGoogleTagManagerDescription', - [ - '', - '' - ] - ) - ); - } } diff --git a/plugins/SitesManager/SiteContentDetection/SpaPwa.php b/plugins/SitesManager/SiteContentDetection/SpaPwa.php index 80401032c28..ef561936eb9 100644 --- a/plugins/SitesManager/SiteContentDetection/SpaPwa.php +++ b/plugins/SitesManager/SiteContentDetection/SpaPwa.php @@ -10,7 +10,6 @@ namespace Piwik\Plugins\SitesManager\SiteContentDetection; -use Piwik\Piwik; use Piwik\SiteContentDetector; class SpaPwa extends SiteContentDetectionAbstract From 6ef6174f7f9b9699d96afd29fea43c074a0c6f37 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Thu, 31 Aug 2023 11:21:56 +0200 Subject: [PATCH 19/35] Move detectConsentManager from Tour to SitesManager API --- .../vue/dist/CoreAdminHome.umd.js | 58 +++++++++---------- .../vue/dist/CoreAdminHome.umd.min.js | 2 +- .../JsTrackingCodeGenerator.vue | 2 +- plugins/SitesManager/API.php | 34 ++++++++++- plugins/Tour/API.php | 32 +--------- 5 files changed, 65 insertions(+), 63 deletions(-) diff --git a/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.js b/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.js index 09aaf861def..318194f774a 100644 --- a/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.js +++ b/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.js @@ -914,58 +914,58 @@ function SmtpSettingsvue_type_template_id_14e9a186_render(_ctx, _cache, $props, SmtpSettingsvue_type_script_lang_ts.render = SmtpSettingsvue_type_template_id_14e9a186_render /* harmony default export */ var SmtpSettings = (SmtpSettingsvue_type_script_lang_ts); -// CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGenerator.vue?vue&type=template&id=7dd382c0 +// CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGenerator.vue?vue&type=template&id=0055e292 -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_1 = { +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_1 = { id: "js-code-options" }; -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_2 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_2 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_3 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_3 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_4 = ["innerHTML"]; -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_5 = ["innerHTML"]; +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_4 = ["innerHTML"]; +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_5 = ["innerHTML"]; -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_6 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_6 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_7 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_7 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_8 = ["innerHTML"]; +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_8 = ["innerHTML"]; -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_9 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_9 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_10 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_10 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_11 = ["innerHTML"]; +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_11 = ["innerHTML"]; -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_12 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_12 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_13 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_13 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("br", null, null, -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_14 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_14 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { href: "https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/", target: "_blank", rel: "noopener" }, "WordPress", -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_15 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_15 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_16 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_16 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { href: "https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website/", target: "_blank", rel: "noopener" }, "Squarespace", -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_17 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_17 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_18 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_18 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { href: "https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix/", target: "_blank", rel: "noopener" }, "Wix", -1); -var JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_19 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); +var JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_19 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" | "); var _hoisted_20 = /*#__PURE__*/Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("a", { href: "https://matomo.org/faq/how-to-install/faq_19424/", @@ -1010,7 +1010,7 @@ var _hoisted_30 = { id: "javascript-text" }; var _hoisted_31 = ["textContent"]; -function JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_render(_ctx, _cache, $props, $setup, $data, $options) { +function JsTrackingCodeGeneratorvue_type_template_id_0055e292_render(_ctx, _cache, $props, $setup, $data, $options) { var _component_Field = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveComponent"])("Field"); var _component_JsTrackingCodeAdvancedOptions = Object(external_commonjs_vue_commonjs2_vue_root_Vue_["resolveComponent"])("JsTrackingCodeAdvancedOptions"); @@ -1024,15 +1024,15 @@ function JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_render(_ctx, _cach "content-title": _ctx.translate('CoreAdminHome_JavaScriptTracking') }, { default: Object(external_commonjs_vue_commonjs2_vue_root_Vue_["withCtx"])(function () { - return [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("div", JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_1, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("p", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CoreAdminHome_JSTrackingIntro1')) + " ", 1), JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_2, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_3, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" " + Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CoreAdminHome_JSTrackingIntro2')) + " ", 1), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + return [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("div", JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_1, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("p", null, [Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CoreAdminHome_JSTrackingIntro1')) + " ", 1), JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_2, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_3, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" " + Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('CoreAdminHome_JSTrackingIntro2')) + " ", 1), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { innerHTML: _ctx.$sanitize(_ctx.jsTrackingIntro3a) - }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_4), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_4), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { innerHTML: _ctx.$sanitize(' ' + _ctx.jsTrackingIntro3b) - }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_5), JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_6, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_7, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_5), JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_6, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_7, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { innerHTML: _ctx.$sanitize(_ctx.jsTrackingIntro4a) - }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_8), JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_9, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_10, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { + }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_8), JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_9, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_10, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createElementVNode"])("span", { innerHTML: _ctx.$sanitize(_ctx.jsTrackingIntro5) - }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_11), JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_12, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_13, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" " + Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('SitesManager_InstallationGuides')) + " : ", 1), JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_14, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_15, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_16, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_17, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_18, JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_hoisted_19, _hoisted_20, _hoisted_21, _hoisted_22, _hoisted_23, _hoisted_24, _hoisted_25, _hoisted_26]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createVNode"])(_component_Field, { + }, null, 8, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_11), JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_12, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_13, Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createTextVNode"])(" " + Object(external_commonjs_vue_commonjs2_vue_root_Vue_["toDisplayString"])(_ctx.translate('SitesManager_InstallationGuides')) + " : ", 1), JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_14, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_15, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_16, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_17, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_18, JsTrackingCodeGeneratorvue_type_template_id_0055e292_hoisted_19, _hoisted_20, _hoisted_21, _hoisted_22, _hoisted_23, _hoisted_24, _hoisted_25, _hoisted_26]), Object(external_commonjs_vue_commonjs2_vue_root_Vue_["createVNode"])(_component_Field, { uicontrol: "site", name: "js-tracker-website", class: "jsTrackingCodeWebsite", @@ -1062,7 +1062,7 @@ function JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_render(_ctx, _cach _: 1 }, 8, ["content-title"]); } -// CONCATENATED MODULE: ./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGenerator.vue?vue&type=template&id=7dd382c0 +// CONCATENATED MODULE: ./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGenerator.vue?vue&type=template&id=0055e292 // CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeAdvancedOptions.vue?vue&type=template&id=cc111ec2 @@ -1681,7 +1681,7 @@ JsTrackingCodeAdvancedOptionsvue_type_script_lang_ts.render = JsTrackingCodeAdva external_CoreHome_["AjaxHelper"].fetch({ module: 'API', format: 'json', - method: 'Tour.detectConsentManager', + method: 'SitesManager.detectConsentManager', idSite: idSite, filter_limit: '-1' }).then(function (response) { @@ -1737,7 +1737,7 @@ JsTrackingCodeAdvancedOptionsvue_type_script_lang_ts.render = JsTrackingCodeAdva -JsTrackingCodeGeneratorvue_type_script_lang_ts.render = JsTrackingCodeGeneratorvue_type_template_id_7dd382c0_render +JsTrackingCodeGeneratorvue_type_script_lang_ts.render = JsTrackingCodeGeneratorvue_type_template_id_0055e292_render /* harmony default export */ var JsTrackingCodeGenerator = (JsTrackingCodeGeneratorvue_type_script_lang_ts); // CONCATENATED MODULE: ./node_modules/@vue/cli-plugin-babel/node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/@vue/cli-plugin-babel/node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/@vue/cli-service/node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/@vue/cli-service/node_modules/vue-loader-v16/dist??ref--0-1!./plugins/CoreAdminHome/vue/src/JsTrackingCodeGenerator/JsTrackingCodeGeneratorSitesWithoutData.vue?vue&type=template&id=06b9935e diff --git a/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.min.js b/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.min.js index 28429eec1c3..4a89ffc5f94 100644 --- a/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.min.js +++ b/plugins/CoreAdminHome/vue/dist/CoreAdminHome.umd.min.js @@ -1,4 +1,4 @@ -(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("CoreHome"),require("vue"),require("CorePluginsAdmin")):"function"===typeof define&&define.amd?define(["CoreHome",,"CorePluginsAdmin"],t):"object"===typeof exports?exports["CoreAdminHome"]=t(require("CoreHome"),require("vue"),require("CorePluginsAdmin")):e["CoreAdminHome"]=t(e["CoreHome"],e["Vue"],e["CorePluginsAdmin"])})("undefined"!==typeof self?self:this,(function(e,t,n){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var a=t[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(o,a,function(t){return e[t]}.bind(null,a));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="plugins/CoreAdminHome/vue/dist/",n(n.s="fae3")}({"19dc":function(t,n){t.exports=e},"8bbf":function(e,n){e.exports=t},a5a2:function(e,t){e.exports=n},fae3:function(e,t,n){"use strict";if(n.r(t),n.d(t,"ArchivingSettings",(function(){return E})),n.d(t,"BrandingSettings",(function(){return X})),n.d(t,"SmtpSettings",(function(){return ne})),n.d(t,"JsTrackingCodeGenerator",(function(){return Vt})),n.d(t,"JsTrackingCodeGeneratorSitesWithoutData",(function(){return wt})),n.d(t,"ImageTrackingCodeGenerator",(function(){return tn})),n.d(t,"TrackingFailures",(function(){return wn})),"undefined"!==typeof window){var o=window.document.currentScript,a=o&&o.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);a&&(n.p=a[1])}var r=n("8bbf"),i={class:"form-group row"},l={class:"col s12"},c={class:"col s12 m6"},s={class:"form-description",style:{"margin-left":"4px"}},d={for:"enableBrowserTriggerArchiving2"},u=["innerHTML"],m={class:"col s12 m6"},g=["innerHTML"],p={class:"form-group row"},b={class:"col s12"},h={class:"input-field col s12 m6"},j=["disabled"],v={class:"form-description"},f={class:"col s12 m6"},O={key:0,class:"form-help"},C={key:0},k=Object(r["createElementVNode"])("br",null,null,-1),V=Object(r["createElementVNode"])("br",null,null,-1),N=Object(r["createElementVNode"])("br",null,null,-1);function S(e,t,n,o,a,S){var T=Object(r["resolveComponent"])("SaveButton"),y=Object(r["resolveComponent"])("ContentBlock");return Object(r["openBlock"])(),Object(r["createBlock"])(y,{"content-title":e.translate("CoreAdminHome_ArchivingSettings"),anchor:"archivingSettings",class:"matomo-archiving-settings"},{default:Object(r["withCtx"])((function(){return[Object(r["createElementVNode"])("div",null,[Object(r["createElementVNode"])("div",i,[Object(r["createElementVNode"])("h3",l,Object(r["toDisplayString"])(e.translate("General_AllowPiwikArchivingToTriggerBrowser")),1),Object(r["createElementVNode"])("div",c,[Object(r["createElementVNode"])("p",null,[Object(r["createElementVNode"])("label",null,[Object(r["withDirectives"])(Object(r["createElementVNode"])("input",{type:"radio",id:"enableBrowserTriggerArchiving1",name:"enableBrowserTriggerArchiving",value:"1","onUpdate:modelValue":t[0]||(t[0]=function(t){return e.enableBrowserTriggerArchivingValue=t})},null,512),[[r["vModelRadio"],e.enableBrowserTriggerArchivingValue]]),Object(r["createElementVNode"])("span",null,Object(r["toDisplayString"])(e.translate("General_Yes")),1),Object(r["createElementVNode"])("span",s,Object(r["toDisplayString"])(e.translate("General_Default")),1)])]),Object(r["createElementVNode"])("p",null,[Object(r["createElementVNode"])("label",d,[Object(r["withDirectives"])(Object(r["createElementVNode"])("input",{type:"radio",id:"enableBrowserTriggerArchiving2",name:"enableBrowserTriggerArchiving",value:"0","onUpdate:modelValue":t[1]||(t[1]=function(t){return e.enableBrowserTriggerArchivingValue=t})},null,512),[[r["vModelRadio"],e.enableBrowserTriggerArchivingValue]]),Object(r["createElementVNode"])("span",null,Object(r["toDisplayString"])(e.translate("General_No")),1),Object(r["createElementVNode"])("span",{class:"form-description",innerHTML:e.$sanitize(e.archivingTriggerDesc),style:{"margin-left":"4px"}},null,8,u)])])]),Object(r["createElementVNode"])("div",m,[Object(r["createElementVNode"])("div",{class:"form-help",innerHTML:e.$sanitize(e.archivingInlineHelp)},null,8,g)])]),Object(r["createElementVNode"])("div",p,[Object(r["createElementVNode"])("h3",b,Object(r["toDisplayString"])(e.translate("General_ReportsContainingTodayWillBeProcessedAtMostEvery")),1),Object(r["createElementVNode"])("div",h,[Object(r["withDirectives"])(Object(r["createElementVNode"])("input",{type:"text","onUpdate:modelValue":t[2]||(t[2]=function(t){return e.todayArchiveTimeToLiveValue=t}),id:"todayArchiveTimeToLive",disabled:!e.isGeneralSettingsAdminEnabled},null,8,j),[[r["vModelText"],e.todayArchiveTimeToLiveValue]]),Object(r["createElementVNode"])("span",v,Object(r["toDisplayString"])(e.translate("General_RearchiveTimeIntervalOnlyForTodayReports")),1)]),Object(r["createElementVNode"])("div",f,[e.isGeneralSettingsAdminEnabled?(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",O,[e.showWarningCron?(Object(r["openBlock"])(),Object(r["createElementBlock"])("strong",C,[Object(r["createTextVNode"])(Object(r["toDisplayString"])(e.translate("General_NewReportsWillBeProcessedByCron")),1),k,Object(r["createTextVNode"])(" "+Object(r["toDisplayString"])(e.translate("General_ReportsWillBeProcessedAtMostEveryHour"))+" "+Object(r["toDisplayString"])(e.translate("General_IfArchivingIsFastYouCanSetupCronRunMoreOften")),1),V])):Object(r["createCommentVNode"])("",!0),Object(r["createTextVNode"])(" "+Object(r["toDisplayString"])(e.translate("General_SmallTrafficYouCanLeaveDefault",e.todayArchiveTimeToLiveDefault))+" ",1),N,Object(r["createTextVNode"])(" "+Object(r["toDisplayString"])(e.translate("General_MediumToHighTrafficItIsRecommendedTo",1800,3600)),1)])):Object(r["createCommentVNode"])("",!0)])]),Object(r["createElementVNode"])("div",null,[Object(r["createVNode"])(T,{saving:e.isLoading,onConfirm:t[3]||(t[3]=function(t){return e.save()})},null,8,["saving"])])])]})),_:1},8,["content-title"])}var T=n("19dc"),y=n("a5a2"),A=Object(r["defineComponent"])({props:{enableBrowserTriggerArchiving:Boolean,showSegmentArchiveTriggerInfo:Boolean,isGeneralSettingsAdminEnabled:Boolean,showWarningCron:Boolean,todayArchiveTimeToLive:Number,todayArchiveTimeToLiveDefault:Number},components:{ContentBlock:T["ContentBlock"],SaveButton:y["SaveButton"]},data:function(){return{isLoading:!1,enableBrowserTriggerArchivingValue:this.enableBrowserTriggerArchiving?1:0,todayArchiveTimeToLiveValue:this.todayArchiveTimeToLive}},watch:{enableBrowserTriggerArchiving:function(e){this.enableBrowserTriggerArchivingValue=e?1:0},todayArchiveTimeToLive:function(e){this.todayArchiveTimeToLiveValue=e}},computed:{archivingTriggerDesc:function(){var e="";return e+=Object(T["translate"])("General_ArchivingTriggerDescription",'',""),this.showSegmentArchiveTriggerInfo&&(e+=Object(T["translate"])("General_ArchivingTriggerSegment")),e},archivingInlineHelp:function(){var e=Object(T["translate"])("General_ArchivingInlineHelp");return e+="
",e+=Object(T["translate"])("General_SeeTheOfficialDocumentationForMoreInformation",'',""),e}},methods:{save:function(){var e=this;this.isLoading=!0,T["AjaxHelper"].post({module:"API",method:"CoreAdminHome.setArchiveSettings"},{enableBrowserTriggerArchiving:this.enableBrowserTriggerArchivingValue,todayArchiveTimeToLive:this.todayArchiveTimeToLiveValue}).then((function(){e.isLoading=!1;var t=T["NotificationsStore"].show({message:Object(T["translate"])("CoreAdminHome_SettingsSaveSuccess"),type:"transient",id:"generalSettings",context:"success"});T["NotificationsStore"].scrollToNotification(t)})).finally((function(){e.isLoading=!1}))}}});A.render=S;var E=A,w={id:"logoSettings"},_={id:"logoUploadForm",ref:"logoUploadForm",method:"post",enctype:"multipart/form-data",action:"index.php?module=CoreAdminHome&format=json&action=uploadCustomLogo"},H={key:0},D=["value"],x=Object(r["createElementVNode"])("input",{type:"hidden",name:"force_api_session",value:"1"},null,-1),L={key:0},B={key:0,class:"alert alert-warning uploaderror"},U={class:"row"},F={class:"col s12"},I=["src"],M={class:"row"},P={class:"col s12"},G=["src"],J={key:1},q=["innerHTML"],R={key:1},W={class:"alert alert-warning"};function K(e,t,n,o,a,i){var l=Object(r["resolveComponent"])("Field"),c=Object(r["resolveComponent"])("SaveButton"),s=Object(r["resolveComponent"])("ContentBlock"),d=Object(r["resolveDirective"])("form");return Object(r["openBlock"])(),Object(r["createBlock"])(s,{"content-title":e.translate("CoreAdminHome_BrandingSettings"),anchor:"brandingSettings"},{default:Object(r["withCtx"])((function(){return[Object(r["withDirectives"])(Object(r["createElementVNode"])("div",null,[Object(r["createElementVNode"])("p",null,Object(r["toDisplayString"])(e.translate("CoreAdminHome_CustomLogoHelpText")),1),Object(r["createVNode"])(l,{name:"useCustomLogo",uicontrol:"checkbox","model-value":e.enabled,"onUpdate:modelValue":t[0]||(t[0]=function(t){return e.onUseCustomLogoChange(t)}),title:e.translate("CoreAdminHome_UseCustomLogo"),"inline-help":e.help},null,8,["model-value","title","inline-help"]),Object(r["withDirectives"])(Object(r["createElementVNode"])("div",w,[Object(r["createElementVNode"])("form",_,[e.fileUploadEnabled?(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",H,[Object(r["createElementVNode"])("input",{type:"hidden",name:"token_auth",value:e.tokenAuth},null,8,D),x,e.logosWriteable?(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",L,[Object(r["createVNode"])(r["Transition"],{name:"fade-out"},{default:Object(r["withCtx"])((function(){return[e.showUploadError?(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",B,Object(r["toDisplayString"])(e.translate("CoreAdminHome_LogoUploadFailed")),1)):Object(r["createCommentVNode"])("",!0)]})),_:1}),Object(r["createVNode"])(l,{uicontrol:"file",name:"customLogo","model-value":e.customLogo,"onUpdate:modelValue":t[1]||(t[1]=function(t){return e.onCustomLogoChange(t)}),title:e.translate("CoreAdminHome_LogoUpload"),"inline-help":e.translate("CoreAdminHome_LogoUploadHelp","JPG / PNG / GIF","110")},null,8,["model-value","title","inline-help"]),Object(r["createElementVNode"])("div",U,[Object(r["createElementVNode"])("div",F,[Object(r["createElementVNode"])("img",{src:e.pathUserLogoWithBuster,id:"currentLogo",style:{"max-height":"150px"},ref:"currentLogo"},null,8,I)])]),Object(r["createVNode"])(l,{uicontrol:"file",name:"customFavicon","model-value":e.customFavicon,"onUpdate:modelValue":t[2]||(t[2]=function(t){return e.onFaviconChange(t)}),title:e.translate("CoreAdminHome_FaviconUpload"),"inline-help":e.translate("CoreAdminHome_LogoUploadHelp","JPG / PNG / GIF","16")},null,8,["model-value","title","inline-help"]),Object(r["createElementVNode"])("div",M,[Object(r["createElementVNode"])("div",P,[Object(r["createElementVNode"])("img",{src:e.pathUserFaviconWithBuster,id:"currentFavicon",width:"16",height:"16",ref:"currentFavicon"},null,8,G)])])])):Object(r["createCommentVNode"])("",!0),e.logosWriteable?Object(r["createCommentVNode"])("",!0):(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",J,[Object(r["createElementVNode"])("div",{class:"alert alert-warning",innerHTML:e.$sanitize(e.logosNotWriteableWarning)},null,8,q)]))])):Object(r["createCommentVNode"])("",!0),e.fileUploadEnabled?Object(r["createCommentVNode"])("",!0):(Object(r["openBlock"])(),Object(r["createElementBlock"])("div",R,[Object(r["createElementVNode"])("div",W,Object(r["toDisplayString"])(e.translate("CoreAdminHome_FileUploadDisabled","file_uploads=1")),1)]))],512)],512),[[r["vShow"],e.enabled]]),Object(r["createVNode"])(c,{onConfirm:t[3]||(t[3]=function(t){return e.save()}),saving:e.isLoading},null,8,["saving"])],512),[[d]])]})),_:1},8,["content-title"])}var z=window,Q=z.$,Y=Object(r["defineComponent"])({props:{fileUploadEnabled:{type:Boolean,required:!0},logosWriteable:{type:Boolean,required:!0},useCustomLogo:{type:Boolean,required:!0},pathUserLogoDirectory:{type:String,required:!0},pathUserLogo:{type:String,required:!0},pathUserLogoSmall:{type:String,required:!0},pathUserLogoSvg:{type:String,required:!0},hasUserLogo:{type:Boolean,required:!0},pathUserFavicon:{type:String,required:!0},hasUserFavicon:{type:Boolean,required:!0},isPluginsAdminEnabled:{type:Boolean,required:!0}},components:{Field:y["Field"],ContentBlock:T["ContentBlock"],SaveButton:y["SaveButton"]},directives:{Form:y["Form"]},data:function(){return{isLoading:!1,enabled:this.useCustomLogo,customLogo:this.pathUserLogo,customFavicon:this.pathUserFavicon,showUploadError:!1,currentLogoSrcExists:this.hasUserLogo,currentFaviconSrcExists:this.hasUserFavicon,currentLogoCacheBuster:(new Date).getTime(),currentFaviconCacheBuster:(new Date).getTime()}},computed:{tokenAuth:function(){return T["Matomo"].token_auth},logosNotWriteableWarning:function(){return Object(T["translate"])("CoreAdminHome_LogoNotWriteableInstruction","".concat(this.pathUserLogoDirectory,"
"),"".concat(this.pathUserLogo,", ").concat(this.pathUserLogoSmall,", ").concat(this.pathUserLogoSvg))},help:function(){if(this.isPluginsAdminEnabled){var e='"'.concat(Object(T["translate"])("General_GiveUsYourFeedback"),'"'),t='';return Object(T["translate"])("CoreAdminHome_CustomLogoFeedbackInfo",e,t,"")}},pathUserLogoWithBuster:function(){return this.currentLogoSrcExists&&this.pathUserLogo?"".concat(this.pathUserLogo,"?").concat(this.currentLogoCacheBuster):""},pathUserFaviconWithBuster:function(){return this.currentFaviconSrcExists&&this.pathUserFavicon?"".concat(this.pathUserFavicon,"?").concat(this.currentFaviconCacheBuster):""}},methods:{onUseCustomLogoChange:function(e){this.enabled=e},onCustomLogoChange:function(e){this.customLogo=e,this.updateLogo()},onFaviconChange:function(e){this.customFavicon=e,this.updateLogo()},save:function(){var e=this;this.isLoading=!0,T["AjaxHelper"].post({module:"API",method:"CoreAdminHome.setBrandingSettings"},{useCustomLogo:this.enabled?"1":"0"}).then((function(){var e=T["NotificationsStore"].show({message:Object(T["translate"])("CoreAdminHome_SettingsSaveSuccess"),type:"transient",id:"generalSettings",context:"success"});T["NotificationsStore"].scrollToNotification(e)})).finally((function(){e.isLoading=!1}))},updateLogo:function(){var e=this,t=!!this.customLogo,n=!!this.customFavicon;if(t||n){this.showUploadError=!1;var o="upload".concat((new Date).getTime()),a=Q('