]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_redditimgur/af_redditimgur.php
2 class Af_RedditImgur
extends Plugin
{
9 "Inline image links in Reddit RSS feeds",
13 function init($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 $doc = new DOMDocument();
24 @$doc->loadHTML($article["content"]);
27 $xpath = new DOMXPath($doc);
28 $entries = $xpath->query('(//a[@href]|//img[@src])');
30 foreach ($entries as $entry) {
31 if ($entry->hasAttribute("href")) {
32 if (preg_match("/\.(jpg|jpeg|gif|png)$/i", $entry->getAttribute("href"))) {
34 $img = $doc->createElement('img');
35 $img->setAttribute("src", $entry->getAttribute("href"));
37 $entry->parentNode
->replaceChild($img, $entry);
41 // remove tiny thumbnails
42 if ($entry->hasAttribute("src")) {
43 if ($entry->parentNode
&& $entry->parentNode
->parentNode
) {
44 $entry->parentNode
->parentNode
->removeChild($entry->parentNode
);
49 $node = $doc->getElementsByTagName('body')->item(0);
52 $article["content"] = $doc->saveXML($node, LIBXML_NOEMPTYTAG
);