From 1610cdce82ce6755b85e08a8d99bf3239ee1a11c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Jan 2013 14:54:03 +0400 Subject: [PATCH] add af_buttersafe --- plugins/af_buttersafe/init.php | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 plugins/af_buttersafe/init.php diff --git a/plugins/af_buttersafe/init.php b/plugins/af_buttersafe/init.php new file mode 100644 index 000000000..2b4279501 --- /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; + } +} +?>