init.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. $owner_uid = $article["owner_uid"];
  15. if (strpos($article["plugin_data"], "fsckportal,$owner_uid:") === FALSE) {
  16. $doc = new DOMDocument();
  17. $charset_hack = '<head>
  18. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  19. </head>';
  20. @$doc->loadHTML($charset_hack . $article["content"]);
  21. if ($doc) {
  22. $xpath = new DOMXPath($doc);
  23. $entries = $xpath->query('(//img[@src]|//a[@href])');
  24. $matches = array();
  25. foreach ($entries as $entry) {
  26. if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
  27. $entry->parentNode->removeChild($entry);
  28. } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
  29. $entry->parentNode->removeChild($entry);
  30. }
  31. }
  32. $article["content"] = $doc->saveXML($basenode);
  33. $article["plugin_data"] = "fsckportal,$owner_uid:" . $article["plugin_data"];
  34. }
  35. } else if (isset($article["stored"]["content"])) {
  36. $article["content"] = $article["stored"]["content"];
  37. }
  38. return $article;
  39. }
  40. function api_version() {
  41. return 2;
  42. }
  43. }
  44. ?>