init.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class Af_GoComics extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Strip unnecessary stuff from gocomics 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"], "gocomics.com") !== FALSE) {
  16. if (strpos($article["plugin_data"], "gocomics,$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])'); // we might also check for img[@class='strip'] I guess...
  23. $matches = array();
  24. foreach ($entries as $entry) {
  25. if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
  26. $entry->setAttribute("src", $matches[0]);
  27. $basenode = $entry;
  28. break;
  29. }
  30. }
  31. if ($basenode) {
  32. $article["content"] = $doc->saveXML($basenode);
  33. $article["plugin_data"] = "gocomics,$owner_uid:" . $article["plugin_data"];
  34. }
  35. }
  36. } else if (isset($article["stored"]["content"])) {
  37. $article["content"] = $article["stored"]["content"];
  38. }
  39. }
  40. return $article;
  41. }
  42. }
  43. ?>