From 0e41d7e28ae063ca6117cb00d73f1c6a2b1a8436 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Thu, 5 May 2022 03:59:00 +0200 Subject: Remove Alexa page rank from SEO plugin (#19171) * Remove Alexa page rank from SEO plugin * updates expected UI files --- plugins/SEO/API.php | 9 +- plugins/SEO/Metric/Aggregator.php | 10 +- plugins/SEO/Metric/Alexa.php | 65 ----- plugins/SEO/config/config.php | 3 +- plugins/SEO/config/tracker.php | 5 +- plugins/SEO/config/ui-test.php | 18 +- plugins/SEO/lang/en.json | 3 +- plugins/SEO/tests/Integration/SEOTest.php | 12 +- plugins/SEO/tests/UI/SeoWidget_spec.js | 3 +- .../SeoWidgetTest_widget.png | Bin 29157 -> 25383 bytes plugins/SEO/tests/resources/alexa_response.html | 306 --------------------- 11 files changed, 30 insertions(+), 404 deletions(-) delete mode 100644 plugins/SEO/Metric/Alexa.php delete mode 100644 plugins/SEO/tests/resources/alexa_response.html (limited to 'plugins') diff --git a/plugins/SEO/API.php b/plugins/SEO/API.php index 73ddc960fc..ce207969e8 100644 --- a/plugins/SEO/API.php +++ b/plugins/SEO/API.php @@ -1,4 +1,5 @@ getName()); - $translated[$label] = array( + $translated[$label] = [ 'id' => $metric->getId(), 'rank' => $metric->getValue(), 'logo' => $metric->getLogo(), 'logo_link' => $metric->getLogoLink(), 'logo_tooltip' => Piwik::translate($metric->getLogoTooltip()), 'rank_suffix' => Piwik::translate($metric->getValueSuffix()), - ); + ]; } return DataTable::makeFromIndexedArray($translated); diff --git a/plugins/SEO/Metric/Aggregator.php b/plugins/SEO/Metric/Aggregator.php index 2059464af6..cf73f247e7 100644 --- a/plugins/SEO/Metric/Aggregator.php +++ b/plugins/SEO/Metric/Aggregator.php @@ -1,4 +1,5 @@ providers as $provider) { $metrics = array_merge($metrics, $provider->getMetrics($domain)); @@ -44,19 +45,18 @@ class Aggregator implements MetricsProvider { $container = StaticContainer::getContainer(); - $providers = array( + $providers = [ $container->get('Piwik\Plugins\SEO\Metric\Google'), $container->get('Piwik\Plugins\SEO\Metric\Bing'), - $container->get('Piwik\Plugins\SEO\Metric\Alexa'), $container->get('Piwik\Plugins\SEO\Metric\DomainAge'), - ); + ]; /** * Use this event to register new SEO metrics providers. * * @param array $providers Contains an array of Piwik\Plugins\SEO\Metric\MetricsProvider instances. */ - Piwik::postEvent('SEO.getMetricsProviders', array(&$providers)); + Piwik::postEvent('SEO.getMetricsProviders', [&$providers]); return $providers; } diff --git a/plugins/SEO/Metric/Alexa.php b/plugins/SEO/Metric/Alexa.php deleted file mode 100644 index c0ae41854a..0000000000 --- a/plugins/SEO/Metric/Alexa.php +++ /dev/null @@ -1,65 +0,0 @@ -logger = $logger; - } - - public function getMetrics($domain) - { - $value = null; - $suffix = 'General_Pages'; - try { - $response = Http::sendHttpRequest(self::URL . urlencode($domain ?? ''), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']); - libxml_use_internal_errors(true); // suppress errors - $dom = new \DomDocument(); - $dom->loadHTML($response); - libxml_clear_errors(); - $nodes = (new \DomXPath($dom))->query("//div[contains(@class, 'ACard')]//section//a"); - if (isset($nodes[0]->nodeValue)) { - foreach( $nodes[0]->childNodes as $node) { - $nodes[0]->removeChild($node); // remove the span tags with additional info - } - $globalRanking = (int) str_replace(array(',', '.'), '', $nodes[0]->nodeValue); - $value = NumberFormatter::getInstance()->formatNumber($globalRanking); - } - } catch (\Exception $e) { - $this->logger->info('Error while getting Alexa SEO stats: {message}', array('message' => $e->getMessage())); - $value = Piwik::translate('General_ErrorTryAgain'); - $suffix = ''; - } - - $logo = "plugins/Morpheus/icons/dist/SEO/alexa.com.png"; - $link = self::LINK . urlencode($domain ?? ''); - - return array( - new Metric('alexa', 'SEO_AlexaRank', $value, $logo, $link, null, $suffix) - ); - } -} diff --git a/plugins/SEO/config/config.php b/plugins/SEO/config/config.php index d266508bcd..0b67a5fe47 100644 --- a/plugins/SEO/config/config.php +++ b/plugins/SEO/config/config.php @@ -1,2 +1,3 @@ \DI\add([ ['Http.sendHttpRequest',\DI\value(function ($aUrl, $httpEventParams, &$response, &$status, &$headers) { // fake responses for SEO metric requests - if (strpos($aUrl, 'www.alexa.com') ) { - $response = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/alexa_response.html'); - } elseif (strpos($aUrl, 'www.bing.com') ) { + if (strpos($aUrl, 'www.bing.com')) { $response = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/bing_response.html'); - } elseif (strpos($aUrl, 'archive.org') ) { + } elseif (strpos($aUrl, 'archive.org')) { $response = '{"timestamp": "19900101", "url": "matomo.org", "archived_snapshots": {"closest": {"timestamp": "20180109155124", "available": true, "status": "200", "url": "http://web.archive.org/web/20180109155124/https://matomo.org"}}}'; - } elseif (strpos($aUrl, 'www.who.is') ) { + } elseif (strpos($aUrl, 'www.who.is')) { $response = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/whois_response.html'); - } elseif (strpos($aUrl, 'www.whois.com') ) { + } elseif (strpos($aUrl, 'www.whois.com')) { $response = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/whoiscom_response.html'); - } elseif (strpos($aUrl, 'www.google.com') ) { + } elseif (strpos($aUrl, 'www.google.com')) { $response = file_get_contents(PIWIK_INCLUDE_PATH . '/plugins/SEO/tests/resources/google_response.html'); } })] ]), - -); +]; diff --git a/plugins/SEO/lang/en.json b/plugins/SEO/lang/en.json index eb6ff829c1..7a16436e33 100644 --- a/plugins/SEO/lang/en.json +++ b/plugins/SEO/lang/en.json @@ -1,7 +1,6 @@ { "SEO": { - "PluginDescription": "This Plugin extracts and displays SEO metrics: Alexa web ranking, Google Pagerank, number of Indexed pages and backlinks of the currently selected website.", - "AlexaRank": "Alexa Rank", + "PluginDescription": "This Plugin extracts and displays SEO metrics: Google Pagerank, number of Indexed pages and backlinks of the currently selected website.", "Bing_IndexedPages": "Bing indexed pages", "DomainAge": "Domain Age", "Google_IndexedPages": "Google indexed pages", diff --git a/plugins/SEO/tests/Integration/SEOTest.php b/plugins/SEO/tests/Integration/SEOTest.php index 75de0b7490..80111140ab 100644 --- a/plugins/SEO/tests/Integration/SEOTest.php +++ b/plugins/SEO/tests/Integration/SEOTest.php @@ -1,4 +1,5 @@ getRank('http://matomo.org/'); $renderer = Renderer::factory('json'); @@ -55,9 +56,8 @@ class SEOTest extends IntegrationTestCase public function provideContainerConfig() { - return array( + return [ 'Piwik\Access' => new FakeAccess() - ); + ]; } - } diff --git a/plugins/SEO/tests/UI/SeoWidget_spec.js b/plugins/SEO/tests/UI/SeoWidget_spec.js index b65927b182..71387ec123 100644 --- a/plugins/SEO/tests/UI/SeoWidget_spec.js +++ b/plugins/SEO/tests/UI/SeoWidget_spec.js @@ -1,6 +1,6 @@ /*! * Matomo - free/libre analytics platform - * + * * Seo widget screenshot tests. * * @link https://matomo.org @@ -23,7 +23,6 @@ describe("SeoWidgetTest", function () { await page.goto(url); await page.evaluate(function () { $('td:last div').text('3 years 78 days'); - $('td:contains(Alexa)').next().children('div').text('25,558'); }); expect(await page.screenshotSelector('.widget')).to.matchImage('widget'); }); diff --git a/plugins/SEO/tests/UI/expected-ui-screenshots/SeoWidgetTest_widget.png b/plugins/SEO/tests/UI/expected-ui-screenshots/SeoWidgetTest_widget.png index 8d218d7c5c..b074741b39 100644 Binary files a/plugins/SEO/tests/UI/expected-ui-screenshots/SeoWidgetTest_widget.png and b/plugins/SEO/tests/UI/expected-ui-screenshots/SeoWidgetTest_widget.png differ diff --git a/plugins/SEO/tests/resources/alexa_response.html b/plugins/SEO/tests/resources/alexa_response.html deleted file mode 100644 index d60cc3df00..0000000000 --- a/plugins/SEO/tests/resources/alexa_response.html +++ /dev/null @@ -1,306 +0,0 @@ - - - - - - - matomo.org Site Overview from Alexa - - - - - -
- -
-

Traffic stats for matomo.org

- - - - - - -
- -
Alexa Traffic Rank
-
- -
Traffic Rank in US
-
-
- 152 -
-
Sites Linking In
-
-
-
- - -- cgit v1.2.3