init.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class Af_PennyArcade extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.1,
  6. "Strip unnecessary stuff from PA 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["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
  16. if (strpos($article["plugin_data"], "pennyarcade,$owner_uid:") === FALSE) {
  17. if ($debug_enabled) {
  18. _debug("af_pennyarcade: Processing comic");
  19. }
  20. $doc = new DOMDocument();
  21. $doc->loadHTML(fetch_file_contents($article["link"]));
  22. $basenode = false;
  23. if ($doc) {
  24. $xpath = new DOMXPath($doc);
  25. $entries = $xpath->query('(//div[@class="post comic"])');
  26. foreach ($entries as $entry) {
  27. $basenode = $entry;
  28. }
  29. if ($basenode) {
  30. $article["content"] = $doc->saveXML($basenode);
  31. $article["plugin_data"] = "pennyarcade,$owner_uid:" . $article["plugin_data"];
  32. }
  33. }
  34. } else if (isset($article["stored"]["content"])) {
  35. $article["content"] = $article["stored"]["content"];
  36. }
  37. }
  38. if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
  39. if (strpos($article["plugin_data"], "pennyarcade,$owner_uid:") === FALSE) {
  40. if ($debug_enabled) {
  41. _debug("af_pennyarcade: Processing news post");
  42. }
  43. $doc = new DOMDocument();
  44. $doc->loadHTML(fetch_file_contents($article["link"]));
  45. if ($doc) {
  46. $xpath = new DOMXPath($doc);
  47. $entries = $xpath->query('(//div[@class="post"])');
  48. $basenode = false;
  49. foreach ($entries as $entry) {
  50. $basenode = $entry;
  51. }
  52. $uninteresting = $xpath->query('(//div[@class="heading"])');
  53. foreach ($uninteresting as $i) {
  54. $i->parentNode->removeChild($i);
  55. }
  56. if ($basenode){
  57. $article["content"] = $doc->saveXML($basenode);
  58. $article["plugin_data"] = "pennyarcade,$owner_uid:" . $article["plugin_data"];
  59. }
  60. }
  61. } else if (isset($article["stored"]["content"])) {
  62. $article["content"] = $article["stored"]["content"];
  63. }
  64. }
  65. return $article;
  66. }
  67. }
  68. ?>