summaryrefslogtreecommitdiff
path: root/init.php
blob: 560faccad78fef839d3743159eb485241f9c66d8 (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
<?php

class Af_Fontanka extends Plugin {

	function about() {
		return array(1.0,
			"Gets full text content from fontanka.ru RSS feed",
			"fox");
	}

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

	function hook_article_filter($article) {
		if (strpos($article["link"], ".fontanka.ru") !== FALSE) {
			$tmp = fetch_file_contents(["url" => $article["link"]]);

			if ($tmp) {
				$doc = new DOMDocument("1.0", "UTF-8");

				if (!@$doc->loadHTML($tmp))
					return false;

				$xpath = new DOMXPath($doc);
				$base_node = $xpath->query("//article")->item(0);

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

		return $article;
	}

	function api_version() {
		return 2;
	}

}