]> git.wh0rd.org - tt-rss.git/blob - plugins/af_sciam/init.php
658265e507dfeca3c22fd6532ed2ee07cf3c9856
[tt-rss.git] / plugins / af_sciam / init.php
1 <?php
2 class Af_SciAm extends Plugin {
3
4 private $host;
5
6 function about() {
7 return array(1.0,
8 "Fetch content of Scientific American feeds",
9 "fox");
10 }
11
12 function init($host) {
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
16 }
17
18 function hook_article_filter($article) {
19 $owner_uid = $article["owner_uid"];
20
21 if (strpos($article["link"], "scientificamerican.com") !== FALSE || strpos($article["link"], "rss.sciam.com") !== FALSE) {
22 if (strpos($article["plugin_data"], "sciam,$owner_uid:") === FALSE) {
23
24 $doc = new DOMDocument();
25 @$doc->loadHTML(fetch_file_contents($article["link"]));
26
27 $basenode = false;
28
29 if ($doc) {
30 $xpath = new DOMXpath($doc);
31
32 $basenode = $xpath->query("//*[@id='singleBlogPost' or @id='articleContent']")->item(0);
33
34 if ($basenode) {
35 $article["content"] = $doc->saveXML($basenode);
36 $article["plugin_data"] = "sciam,$owner_uid:" . $article["plugin_data"];
37 }
38 }
39 } else if (isset($article["stored"]["content"])) {
40 $article["content"] = $article["stored"]["content"];
41 }
42 }
43
44 return $article;
45 }
46
47 function api_version() {
48 return 2;
49 }
50 }
51 ?>