init.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class Af_NatGeo extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Fetch content of National Geographic 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"], "nationalgeographic.com") !== FALSE) {
  16. if (strpos($article["plugin_data"], "natgeo,$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. $basenode = $doc->getElementById("content_mainA");
  23. $trash = $xpath->query("//*[@class='aside' or @id='livefyre' or @id='powered_by_livefyre' or @class='social_buttons']");
  24. foreach ($trash as $t) {
  25. $t->parentNode->removeChild($t);
  26. }
  27. if ($basenode) {
  28. $article["content"] = $doc->saveXML($basenode);
  29. $article["plugin_data"] = "natgeo,$owner_uid:" . $article["plugin_data"];
  30. }
  31. }
  32. } else if (isset($article["stored"]["content"])) {
  33. $article["content"] = $article["stored"]["content"];
  34. }
  35. }
  36. return $article;
  37. }
  38. function api_version() {
  39. return 2;
  40. }
  41. }
  42. ?>