]>
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) { | |
c309f41d AD |
22 | |
23 | $doc = new DOMDocument(); | |
24 | @$doc->loadHTML(fetch_file_contents($article["link"])); | |
25 | ||
26 | $basenode = false; | |
27 | ||
28 | if ($doc) { | |
623d1308 AD |
29 | $xpath = new DOMXPath($doc); |
30 | ||
c309f41d AD |
31 | $basenode = $doc->getElementById("content_mainA"); |
32 | ||
623d1308 AD |
33 | $trash = $xpath->query("//*[@class='aside' or @id='livefyre' or @id='powered_by_livefyre' or @class='social_buttons']"); |
34 | ||
35 | foreach ($trash as $t) { | |
36 | $t->parentNode->removeChild($t); | |
37 | } | |
38 | ||
c309f41d AD |
39 | if ($basenode) { |
40 | $article["content"] = $doc->saveXML($basenode); | |
c309f41d AD |
41 | } |
42 | } | |
c309f41d AD |
43 | } |
44 | ||
45 | return $article; | |
46 | } | |
47 | ||
48 | function api_version() { | |
49 | return 2; | |
50 | } | |
51 | } | |
52 | ?> |