]>
Commit | Line | Data |
---|---|---|
c309f41d AD |
1 | <?php |
2 | class Af_NatGeo extends Plugin { | |
3 | ||
4 | private $host; | |
5 | ||
6 | function about() { | |
7 | return array(1.0, | |
8 | "Fetch content of National Geographic 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"], "nationalgeographic.com") !== FALSE) { | |
22 | if (strpos($article["plugin_data"], "natgeo,$owner_uid:") === FALSE) { | |
23 | ||
24 | $doc = new DOMDocument(); | |
25 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
26 | ||
27 | $basenode = false; | |
28 | ||
29 | if ($doc) { | |
623d1308 AD |
30 | $xpath = new DOMXPath($doc); |
31 | ||
c309f41d AD |
32 | $basenode = $doc->getElementById("content_mainA"); |
33 | ||
623d1308 AD |
34 | $trash = $xpath->query("//*[@class='aside' or @id='livefyre' or @id='powered_by_livefyre' or @class='social_buttons']"); |
35 | ||
36 | foreach ($trash as $t) { | |
37 | $t->parentNode->removeChild($t); | |
38 | } | |
39 | ||
c309f41d AD |
40 | if ($basenode) { |
41 | $article["content"] = $doc->saveXML($basenode); | |
42 | $article["plugin_data"] = "natgeo,$owner_uid:" . $article["plugin_data"]; | |
43 | } | |
44 | } | |
45 | } else if (isset($article["stored"]["content"])) { | |
46 | $article["content"] = $article["stored"]["content"]; | |
47 | } | |
48 | } | |
49 | ||
50 | return $article; | |
51 | } | |
52 | ||
53 | function api_version() { | |
54 | return 2; | |
55 | } | |
56 | } | |
57 | ?> |