From: Andrew Dolgov Date: Wed, 23 Jan 2013 10:54:03 +0000 (+0400) Subject: add af_buttersafe X-Git-Tag: 1.7.0~27 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=1610cdce82ce6755b85e08a8d99bf3239ee1a11c;p=tt-rss.git add af_buttersafe --- diff --git a/plugins/af_buttersafe/init.php b/plugins/af_buttersafe/init.php new file mode 100644 index 00000000..2b427950 --- /dev/null +++ b/plugins/af_buttersafe/init.php @@ -0,0 +1,57 @@ +link = $host->get_link(); + $this->host = $host; + + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); + } + + function hook_article_filter($article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["guid"], "buttersafe.com") !== FALSE && + strpos($article["guid"], "buttersafe,$owner_uid:") === FALSE) { + + $doc = new DOMDocument(); + @$doc->loadHTML(fetch_file_contents($article["link"])); + + $basenode = false; + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query('(//img[@src])'); + + $matches = array(); + + foreach ($entries as $entry) { + + if (preg_match("/(http:\/\/buttersafe.com\/comics\/\d{4}.*)/i", $entry->getAttribute("src"), $matches)) { + + $basenode = $entry; + break; + } + } + + if ($basenode) { + $article["content"] = $doc->saveXML($basenode, LIBXML_NOEMPTYTAG); + } + } + + $article["guid"] = "buttersafe,$owner_uid:" . $article["guid"]; + } + + return $article; + } +} +?>