init.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class Af_Fsckportal extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Remove feedsportal spamlinks from article content",
  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. $doc = new DOMDocument();
  15. $charset_hack = '<head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  17. </head>';
  18. @$doc->loadHTML($charset_hack . $article["content"]);
  19. if ($doc) {
  20. $xpath = new DOMXPath($doc);
  21. $entries = $xpath->query('(//img[@src]|//a[@href])');
  22. foreach ($entries as $entry) {
  23. if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
  24. $entry->parentNode->removeChild($entry);
  25. } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
  26. $entry->parentNode->removeChild($entry);
  27. }
  28. }
  29. $article["content"] = $doc->saveHTML();
  30. }
  31. return $article;
  32. }
  33. function api_version() {
  34. return 2;
  35. }
  36. }