summaryrefslogtreecommitdiff
path: root/init.php
blob: e62e353e42115987d409eedbb9a05397e840bb3e (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class Af_GoodShowSir extends Plugin {
	private $host;

	function about() {
		return array(1.0,
			"Fix image url in goodshowsir.co.uk RSS feed",
			"fox");
	}

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

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

	function hook_article_filter($article) {

		$doc = new DOMDocument();

		$found = false;

		if (@$doc->loadHTML($article["content"])) {

			$xpath = new DOMXpath($doc);
			$images = $xpath->query('(//img[contains(@src, \'goodshowsir.co.uk\')])');

			foreach ($images as $img) {
				$src = $img->getAttribute("src");

				if (strpos($src, " ") !== FALSE) {
					$img->setAttribute("src", trim($src));

					$found = true;

				}
			}
		}

		if ($found) {
			$article["content"] = $doc->saveXML();
		}

		return $article;

	}


	function api_version() {
		return 2;
	}

}
?>