init.php 2.3 KB

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