]>
Commit | Line | Data |
---|---|---|
eb1921ef AD |
1 | <?php |
2 | class Af_Habr extends Plugin { | |
3 | ||
4 | function about() { | |
5 | return array(1.0, | |
6 | "Fetch content of Habrahabr feeds", | |
7 | "fox"); | |
8 | } | |
9 | ||
10 | function init($host) { | |
11 | $this->host = $host; | |
12 | ||
13 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | |
14 | } | |
15 | ||
16 | function hook_article_filter($article) { | |
17 | $owner_uid = $article["owner_uid"]; | |
18 | ||
19 | if (strpos($article["link"], "habrahabr.ru") !== FALSE) { | |
20 | if (strpos($article["plugin_data"], "af_habr,$owner_uid:") === FALSE) { | |
21 | ||
22 | $doc = new DOMDocument(); | |
23 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
24 | ||
25 | $basenode = false; | |
26 | ||
27 | if ($doc) { | |
28 | $xpath = new DOMXPath($doc); | |
29 | ||
463bcb77 | 30 | $basenode = $xpath->query("//div[contains(@class,'content') and contains(@class, 'html_format')]")->item(0); |
eb1921ef AD |
31 | |
32 | if ($basenode) { | |
33 | $article["content"] = $doc->saveXML($basenode); | |
34 | $article["plugin_data"] = "af_habr,$owner_uid:" . $article["plugin_data"]; | |
35 | } | |
36 | } | |
37 | } else if (isset($article["stored"]["content"])) { | |
38 | $article["content"] = $article["stored"]["content"]; | |
39 | } | |
40 | } | |
41 | ||
42 | return $article; | |
43 | } | |
44 | ||
45 | function api_version() { | |
46 | return 2; | |
47 | } | |
48 | } | |
49 | ?> |