]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | class Af_Buttersafe extends Plugin { | |
3 | ||
4 | private $host; | |
5 | ||
6 | function about() { | |
7 | return array(1.0, | |
8 | "Strip unnecessary stuff from Buttersafe 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["guid"], "buttersafe.com") !== FALSE) { | |
22 | if (strpos($article["plugin_data"], "buttersafe,$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 | $entries = $xpath->query('(//img[@src])'); | |
32 | ||
33 | $matches = array(); | |
34 | ||
35 | foreach ($entries as $entry) { | |
36 | ||
37 | if (preg_match("/(http:\/\/buttersafe.com\/comics\/\d{4}.*)/i", $entry->getAttribute("src"), $matches)) { | |
38 | ||
39 | $basenode = $entry; | |
40 | break; | |
41 | } | |
42 | } | |
43 | ||
44 | if ($basenode) { | |
45 | $article["content"] = $doc->saveXML($basenode); | |
46 | $article["plugin_data"] = "buttersafe,$owner_uid:" . $article["plugin_data"]; | |
47 | } | |
48 | } | |
49 | } else if (isset($article["stored"]["content"])) { | |
50 | $article["content"] = $article["stored"]["content"]; | |
51 | } | |
52 | } | |
53 | ||
54 | return $article; | |
55 | } | |
56 | ||
57 | function api_version() { | |
58 | return 2; | |
59 | } | |
60 | ||
61 | } | |
62 | ?> |