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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Ă–zdemir <ozdemirburak@users.noreply.github.com>2018-12-04 08:22:18 +0300
committerdiosmosis <diosmosis@users.noreply.github.com>2018-12-04 08:22:18 +0300
commit12b522d23fa4fba633686792319a7aa02ed266e6 (patch)
tree984775911f4086acd685f28deb3958141f6e9f32 /plugins/SEO
parent28c41eb93b42672076fc9cc8f4ff39d244eb31a4 (diff)
Added Fallback Method for Alexa in SEO Plugin (#13552)
* added fallback method for Alexa, fixes issue #13427 * do not use short array syntax for consistency with other methods * use mini link for Alexa, use DomXPath to filter out the global ranking instead of regex
Diffstat (limited to 'plugins/SEO')
-rw-r--r--plugins/SEO/Metric/Alexa.php21
1 files changed, 19 insertions, 2 deletions
diff --git a/plugins/SEO/Metric/Alexa.php b/plugins/SEO/Metric/Alexa.php
index bf0b999659..e1a9a0cc1c 100644
--- a/plugins/SEO/Metric/Alexa.php
+++ b/plugins/SEO/Metric/Alexa.php
@@ -18,6 +18,7 @@ use Psr\Log\LoggerInterface;
class Alexa implements MetricsProvider
{
const URL = 'https://data.alexa.com/data?cli=10&url=';
+ const URL_FALLBACK = 'https://www.alexa.com/minisiteinfo/';
const LINK = 'https://www.alexa.com/siteinfo/';
/**
@@ -34,12 +35,11 @@ class Alexa implements MetricsProvider
{
try {
$response = Http::sendHttpRequest(self::URL . urlencode($domain), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']);
-
$xml = @simplexml_load_string($response);
$value = $xml ? NumberFormatter::getInstance()->formatNumber((int)$xml->SD->POPULARITY['TEXT']) : null;
} catch (\Exception $e) {
$this->logger->warning('Error while getting Alexa SEO stats: {message}', array('message' => $e->getMessage()));
- $value = null;
+ $value = $this->tryFallbackMethod($domain);
}
$logo = "plugins/Morpheus/icons/dist/SEO/alexa.com.png";
@@ -49,4 +49,21 @@ class Alexa implements MetricsProvider
new Metric('alexa', 'SEO_AlexaRank', $value, $logo, $link)
);
}
+
+ private function tryFallbackMethod($domain)
+ {
+ try {
+ $response = Http::sendHttpRequest(self::URL_FALLBACK . urlencode($domain), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']);
+ $dom = new \DomDocument();
+ $dom->loadHTML($response);
+ $nodes = (new \DomXPath($dom))->query("//div[contains(@class, 'data')]");
+ if (isset($nodes[0]->nodeValue)) {
+ $globalRanking = (int) str_replace(array(',', '.'), '', $nodes[0]->nodeValue);
+ return NumberFormatter::getInstance()->formatNumber($globalRanking);
+ }
+ } catch (\Exception $e) {
+ $this->logger->warning('Error while getting Alexa SEO stats via fallback method: {message}', array('message' => $e->getMessage()));
+ }
+ return null;
+ }
}