init.php 824 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. $doc = new DOMDocument();
  16. @$doc->loadHTML(fetch_file_contents($article["link"]));
  17. $basenode = false;
  18. if ($doc) {
  19. $xpath = new DOMXPath($doc);
  20. $basenode = $xpath->query("//div[contains(@class,'content') and contains(@class, 'html_format')]")->item(0);
  21. if ($basenode) {
  22. $article["content"] = $doc->saveXML($basenode);
  23. }
  24. }
  25. }
  26. return $article;
  27. }
  28. function api_version() {
  29. return 2;
  30. }
  31. }
  32. ?>