summaryrefslogtreecommitdiff
path: root/plugins/no_iframes/init.php
blob: a8cef74ee2764a6074181d41aa3a719e11cd9607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class No_Iframes extends Plugin {
	private $host;

	function about() {
		return array(null,
			"Remove embedded iframes (unless whitelisted)",
			"fox");
	}

	function init($host) {
		$this->host = $host;

		$host->add_hook($host::HOOK_SANITIZE, $this);
	}

	function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes) {

		$xpath = new DOMXpath($doc);
		$entries = $xpath->query('//iframe');

		foreach ($entries as $entry) {
			if (!Sanitizer::iframe_whitelisted($entry))
				$entry->parentNode->removeChild($entry);
		}

		return array($doc, $allowed_elements, $disallowed_attributes);
	}

	function api_version() {
		return 2;
	}

}