init.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class Af_Explosm extends Plugin {
  3. private $link;
  4. private $host;
  5. function about() {
  6. return array(1.0,
  7. "Strip unnecessary stuff from Cyanide and Happiness 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["link"], "explosm.net/comics") !== FALSE) {
  18. if (strpos($article["plugin_data"], "explosm,$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:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
  28. $basenode = $entry;
  29. break;
  30. }
  31. }
  32. if ($basenode) {
  33. $article["content"] = $doc->saveXML($basenode);
  34. $article["plugin_data"] = "explosm,$owner_uid:" . $article["plugin_data"];
  35. }
  36. }
  37. } else if (isset($article["stored"]["content"])) {
  38. $article["content"] = $article["stored"]["content"];
  39. }
  40. }
  41. return $article;
  42. }
  43. }
  44. ?>