init.php 1.4 KB

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