From 3a1410d315679b9ca169d946e6d07ff9ed9c830b Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 12 Jan 2021 19:00:30 +0000 Subject: [PATCH 1/2] [FirefoxAddonsBridge] Add bridge --- bridges/FirefoxAddonsBridge.php | 83 +++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 bridges/FirefoxAddonsBridge.php diff --git a/bridges/FirefoxAddonsBridge.php b/bridges/FirefoxAddonsBridge.php new file mode 100644 index 00000000000..8b616a4cd3e --- /dev/null +++ b/bridges/FirefoxAddonsBridge.php @@ -0,0 +1,83 @@ + array( + 'name' => 'Add-on ID', + 'type' => 'text', + 'required' => true, + 'exampleValue' => 'save-to-the-wayback-machine', + ) + ) + ); + + const CACHE_TIMEOUT = 3600; + + private $feedName = ''; + private $releaseDateRegex = '/Released ([\w, ]+) - ([\w. ]+)/'; + private $outgoingRegex = '/https:\/\/outgoing.prod.mozaws.net\/v1\/(?:[A-z0-9]+)\//'; + + public function collectData() { + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request: ' . $this->getURI()); + + $this->feedName = $html->find('h1[class="AddonTitle"] > a', 0)->innertext; + $author = $html->find('span.AddonTitle-author > a', 0)->plaintext; + + foreach ($html->find('div.AddonVersionCard-content') as $div) { + $item = array(); + + $item['title'] = $div->find('h2.AddonVersionCard-version', 0)->plaintext; + $item['uri'] = $this->getURI(); + $item['author'] = $author; + + if (preg_match($this->releaseDateRegex, $div->find('div.AddonVersionCard-fileInfo', 0)->plaintext, $match)) { + $item['timestamp'] = $match[1]; + $size = $match[2]; + } + + $downloadlink = $div->find('a.InstallButtonWrapper-download-link', 0)->href; + $releaseNotes = $this->removeOutgoinglink($div->find('div.AddonVersionCard-releaseNotes', 0)); + + $item['content'] = <<Release Notes +

{$releaseNotes}

+Compatibility +

{$div->find('div.AddonVersionCard-compatibility', 0)->plaintext}

+License +

{$div->find('p.AddonVersionCard-license', 0)->innertext}

+Download +

{$downloadlink} ($size)

+EOD; + + $this->items[] = $item; + } + } + + public function getURI() { + if (!is_null($this->getInput('id'))) { + return self::URI . 'en-US/firefox/addon/' . $this->getInput('id') . '/versions/'; + } + + return parent::getURI(); + } + + public function getName() { + if (!empty($this->feedName)) { + return $this->feedName . ' - Firefox Add-on'; + } + + return parent::getName(); + } + + private function removeOutgoinglink($html) { + foreach ($html->find('a') as $a) { + $a->href = urldecode(preg_replace($this->outgoingRegex, '', $a->href)); + } + + return $html->innertext; + } +} From 61c02aff8aad36adfa2884fd132ae1039acf8f58 Mon Sep 17 00:00:00 2001 From: Joseph Date: Sun, 24 Jan 2021 16:25:05 +0000 Subject: [PATCH 2/2] [FirefoxAddonsBridge] Update --- bridges/FirefoxAddonsBridge.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bridges/FirefoxAddonsBridge.php b/bridges/FirefoxAddonsBridge.php index 8b616a4cd3e..d9803b74367 100644 --- a/bridges/FirefoxAddonsBridge.php +++ b/bridges/FirefoxAddonsBridge.php @@ -18,6 +18,7 @@ class FirefoxAddonsBridge extends BridgeAbstract { private $feedName = ''; private $releaseDateRegex = '/Released ([\w, ]+) - ([\w. ]+)/'; + private $xpiFileRegex = '/([A-Za-z0-9_.-]+)\.xpi$/'; private $outgoingRegex = '/https:\/\/outgoing.prod.mozaws.net\/v1\/(?:[A-z0-9]+)\//'; public function collectData() { @@ -39,18 +40,24 @@ public function collectData() { $size = $match[2]; } + $compatibility = $div->find('div.AddonVersionCard-compatibility', 0)->plaintext; + $license = $div->find('p.AddonVersionCard-license', 0)->innertext; $downloadlink = $div->find('a.InstallButtonWrapper-download-link', 0)->href; $releaseNotes = $this->removeOutgoinglink($div->find('div.AddonVersionCard-releaseNotes', 0)); + if (preg_match($this->xpiFileRegex, $downloadlink, $match)) { + $xpiFilename = $match[0]; + } + $item['content'] = <<Release Notes

{$releaseNotes}

Compatibility -

{$div->find('div.AddonVersionCard-compatibility', 0)->plaintext}

+

{$compatibility}

License -

{$div->find('p.AddonVersionCard-license', 0)->innertext}

+

{$license}

Download -

{$downloadlink} ($size)

+

{$xpiFilename} ($size)

EOD; $this->items[] = $item;