]>
git.wh0rd.org - tt-rss.git/blob - plugins/redditimgur/redditimgur.php
7 function __construct($host) {
8 $this->link
= $host->get_link();
11 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
14 function hook_article_filter($article) {
16 if (strpos($article["link"], "reddit.com/r/") !== FALSE) {
17 if (strpos($article["content"], "i.imgur.com") !== FALSE) {
19 $doc = new DOMDocument();
20 @$doc->loadHTML($article["content"]);
23 $xpath = new DOMXPath($doc);
24 $entries = $xpath->query('(//a[@href]|//img[@src])');
26 foreach ($entries as $entry) {
27 if ($entry->hasAttribute("href")) {
28 if (preg_match("/\.(jpg|jpeg|gif|png)$/i", $entry->getAttribute("href"))) {
30 $img = $doc->createElement('img');
31 $img->setAttribute("src", $entry->getAttribute("href"));
33 $entry->parentNode
->replaceChild($img, $entry);
37 // remove tiny thumbnails
38 if ($entry->hasAttribute("src")) {
39 if ($entry->parentNode
&& $entry->parentNode
->parentNode
) {
40 $entry->parentNode
->parentNode
->removeChild($entry->parentNode
);
45 $node = $doc->getElementsByTagName('body')->item(0);
48 $article["content"] = $doc->saveXML($node, LIBXML_NOEMPTYTAG
);