init.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class Af_Habr extends Plugin {
  3. function about() {
  4. return array(1.0,
  5. "Fetch content of Habrahabr feeds",
  6. "fox");
  7. }
  8. function init($host) {
  9. $this->host = $host;
  10. $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
  11. }
  12. function hook_article_filter($article) {
  13. $owner_uid = $article["owner_uid"];
  14. if (strpos($article["link"], "habrahabr.ru") !== FALSE) {
  15. if (strpos($article["plugin_data"], "af_habr,$owner_uid:") === FALSE) {
  16. $doc = new DOMDocument();
  17. @$doc->loadHTML(fetch_file_contents($article["link"]));
  18. $basenode = false;
  19. if ($doc) {
  20. $xpath = new DOMXPath($doc);
  21. $basenode = $xpath->query("//div[contains(@class,'content') and contains(@class, 'html_format')]")->item(0);
  22. if ($basenode) {
  23. $article["content"] = $doc->saveXML($basenode);
  24. $article["plugin_data"] = "af_habr,$owner_uid:" . $article["plugin_data"];
  25. }
  26. }
  27. } else if (isset($article["stored"]["content"])) {
  28. $article["content"] = $article["stored"]["content"];
  29. }
  30. }
  31. return $article;
  32. }
  33. function api_version() {
  34. return 2;
  35. }
  36. }
  37. ?>