]>
Commit | Line | Data |
---|---|---|
c309f41d AD |
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 | ||
54af7f84 | 21 | if (strpos($article["link"], "scientificamerican.com") !== FALSE || strpos($article["link"], "rss.sciam.com") !== FALSE) { |
c309f41d AD |
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) { | |
54af7f84 AD |
30 | $xpath = new DOMXpath($doc); |
31 | ||
32 | $basenode = $xpath->query("//*[@id='singleBlogPost' or @id='articleContent']")->item(0); | |
c309f41d AD |
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 | ?> |