]> git.wh0rd.org Git - tt-rss.git/blob - plugins/af_threewordphrase/init.php
7b178313b1f64174f059284ec6a5a9e95a3d70b0
[tt-rss.git] / plugins / af_threewordphrase / init.php
1 <?php
2 class Af_ThreeWordPhrase extends Plugin {
3
4         private $host;
5
6         function about() {
7                 return array(1.0,
8                         "Fetch content of Three Word Phrase comics",
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"], "threewordphrase.com") !== FALSE) {
22                         if (strpos($article["plugin_data"], "threewordphrase,$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("//td/center/img")->item(0);
33
34                                         if ($basenode) {
35                                                 $article["content"] = $doc->saveXML($basenode);
36                                                 $article["plugin_data"] = "threewordphrase,$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 ?>