init.php 714 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class No_Iframes extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Remove embedded iframes (unless whitelisted)",
  7. "fox");
  8. }
  9. function init($host) {
  10. $this->host = $host;
  11. $host->add_hook($host::HOOK_SANITIZE, $this);
  12. }
  13. /**
  14. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  15. */
  16. function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) {
  17. $xpath = new DOMXpath($doc);
  18. $entries = $xpath->query('//iframe');
  19. foreach ($entries as $entry) {
  20. if (!iframe_whitelisted($entry))
  21. $entry->parentNode->removeChild($entry);
  22. }
  23. return array($doc, $allowed_elements, $disallowed_attributes);
  24. }
  25. function api_version() {
  26. return 2;
  27. }
  28. }