]>
git.wh0rd.org - tt-rss.git/blob - plugins/redditimgur/redditimgur.php
2 class RedditImgur
extends Plugin
{
9 "Inline image links in Reddit RSS feeds",
13 function __construct($host) {
14 $this->link
= $host->get_link();
17 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
20 function hook_article_filter($article) {
22 if (strpos($article["link"], "reddit.com/r/") !== FALSE) {
23 if (strpos($article["content"], "i.imgur.com") !== FALSE) {
25 $doc = new DOMDocument();
26 @$doc->loadHTML($article["content"]);
29 $xpath = new DOMXPath($doc);
30 $entries = $xpath->query('(//a[@href]|//img[@src])');
32 foreach ($entries as $entry) {
33 if ($entry->hasAttribute("href")) {
34 if (preg_match("/\.(jpg|jpeg|gif|png)$/i", $entry->getAttribute("href"))) {
36 $img = $doc->createElement('img');
37 $img->setAttribute("src", $entry->getAttribute("href"));
39 $entry->parentNode
->replaceChild($img, $entry);
43 // remove tiny thumbnails
44 if ($entry->hasAttribute("src")) {
45 if ($entry->parentNode
&& $entry->parentNode
->parentNode
) {
46 $entry->parentNode
->parentNode
->removeChild($entry->parentNode
);
51 $node = $doc->getElementsByTagName('body')->item(0);
54 $article["content"] = $doc->saveXML($node, LIBXML_NOEMPTYTAG
);