init.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class Af_Buttersafe extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Strip unnecessary stuff from Buttersafe feeds",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
  12. }
  13. function hook_article_filter($article) {
  14. $owner_uid = $article["owner_uid"];
  15. if (strpos($article["guid"], "buttersafe.com") !== FALSE) {
  16. if (strpos($article["plugin_data"], "buttersafe,$owner_uid:") === FALSE) {
  17. $doc = new DOMDocument();
  18. @$doc->loadHTML(fetch_file_contents($article["link"]));
  19. $basenode = false;
  20. if ($doc) {
  21. $xpath = new DOMXPath($doc);
  22. $entries = $xpath->query('(//img[@src])');
  23. $matches = array();
  24. foreach ($entries as $entry) {
  25. if (preg_match("/(http:\/\/buttersafe.com\/comics\/\d{4}.*)/i", $entry->getAttribute("src"), $matches)) {
  26. $basenode = $entry;
  27. break;
  28. }
  29. }
  30. if ($basenode) {
  31. $article["content"] = $doc->saveXML($basenode);
  32. $article["plugin_data"] = "buttersafe,$owner_uid:" . $article["plugin_data"];
  33. }
  34. }
  35. } else if (isset($article["stored"]["content"])) {
  36. $article["content"] = $article["stored"]["content"];
  37. }
  38. }
  39. return $article;
  40. }
  41. }
  42. ?>