]> git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/init.php
e8b5a00ccbd4ae0e921a4c94a72ac6844e6c11d5
[tt-rss.git] / plugins / af_comics / init.php
1 <?php
2 class Af_Comics extends Plugin {
3
4 private $host;
5
6 function about() {
7 return array(1.0,
8 "Fixes RSS feeds of assorted comic strips",
9 "fox");
10 }
11
12 function init($host) {
13 $this->host = $host;
14
15 $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
16 $host->add_hook($host::HOOK_PREFS_TAB, $this);
17 }
18
19 function hook_prefs_tab($args) {
20 if ($args != "prefPrefs") return;
21
22 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds supported by af_comics')."\">";
23
24 print_notice("This plugin supports the following comics:");
25
26 print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
27 print "<li>Buni</li>
28 <li>Buttersafe</li>
29 <li>CSection</li>
30 <li>Dilbert</li>
31 <li>Explosm</li>
32 <li>GoComics</li>
33 <li>Penny Arcade</li>
34 <li>Three word phrase</li>
35 <li>Whomp</li>";
36 print "</ul>";
37
38 print "</div>";
39 }
40
41 function hook_article_filter($article) {
42 $owner_uid = $article["owner_uid"];
43
44 $found = false;
45
46 # div#comic - comicpress?
47
48 if (strpos($article["guid"], "bunicomic.com") !== FALSE ||
49 strpos($article["guid"], "buttersafe.com") !== FALSE ||
50 strpos($article["guid"], "whompcomic.com") !== FALSE ||
51 strpos($article["guid"], "csectioncomics.com") !== FALSE) {
52
53 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
54
55 $doc = new DOMDocument();
56 @$doc->loadHTML(fetch_file_contents($article["link"]));
57
58 $basenode = false;
59
60 if ($doc) {
61 $xpath = new DOMXPath($doc);
62 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
63
64 if ($basenode) {
65 $article["content"] = $doc->saveXML($basenode);
66 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
67 }
68 }
69 } else if (isset($article["stored"]["content"])) {
70 $article["content"] = $article["stored"]["content"];
71 }
72 }
73
74 if (strpos($article["guid"], "dilbert.com") !== FALSE) {
75 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
76 $doc = new DOMDocument();
77 @$doc->loadHTML(fetch_file_contents($article["link"]));
78
79 $basenode = false;
80
81 if ($doc) {
82 $xpath = new DOMXPath($doc);
83 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
84
85 $matches = array();
86
87 foreach ($entries as $entry) {
88
89 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
90
91 $entry->setAttribute("src",
92 rewrite_relative_url("http://dilbert.com/",
93 $matches[0]));
94
95 $basenode = $entry;
96 break;
97 }
98 }
99
100 if ($basenode) {
101 $article["content"] = $doc->saveXML($basenode);
102 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
103 }
104 }
105 } else if (isset($article["stored"]["content"])) {
106 $article["content"] = $article["stored"]["content"];
107 }
108 }
109
110 if (strpos($article["link"], "explosm.net/comics") !== FALSE) {
111 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
112
113 $doc = new DOMDocument();
114 @$doc->loadHTML(fetch_file_contents($article["link"]));
115
116 $basenode = false;
117
118 if ($doc) {
119 $xpath = new DOMXPath($doc);
120 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
121
122 $matches = array();
123
124 foreach ($entries as $entry) {
125
126 if (preg_match("/(http:\/\/.*\/db\/files\/Comics\/.*)/i", $entry->getAttribute("src"), $matches)) {
127
128 $basenode = $entry;
129 break;
130 }
131 }
132
133 if ($basenode) {
134 $article["content"] = $doc->saveXML($basenode);
135 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
136 }
137 }
138 } else if (isset($article["stored"]["content"])) {
139 $article["content"] = $article["stored"]["content"];
140 }
141 }
142
143 if (strpos($article["guid"], "gocomics.com") !== FALSE) {
144 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
145 $doc = new DOMDocument();
146 @$doc->loadHTML(fetch_file_contents($article["link"]));
147
148 $basenode = false;
149
150 if ($doc) {
151 $xpath = new DOMXPath($doc);
152 $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
153
154 $matches = array();
155
156 foreach ($entries as $entry) {
157
158 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*width.*)/i", $entry->getAttribute("src"), $matches)) {
159
160 $entry->setAttribute("src", $matches[0]);
161 $basenode = $entry;
162 break;
163 }
164 }
165
166 if (!$basenode) {
167 // fallback on the smaller version
168 foreach ($entries as $entry) {
169
170 if (preg_match("/(http:\/\/assets.amuniversal.com\/.*)/i", $entry->getAttribute("src"), $matches)) {
171
172 $entry->setAttribute("src", $matches[0]);
173 $basenode = $entry;
174 break;
175 }
176 }
177 }
178
179 if ($basenode) {
180 $article["content"] = $doc->saveXML($basenode);
181 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
182 }
183 }
184 } else if (isset($article["stored"]["content"])) {
185 $article["content"] = $article["stored"]["content"];
186 }
187 }
188
189 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
190 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
191
192 if ($debug_enabled) {
193 _debug("af_pennyarcade: Processing comic");
194 }
195
196 $doc = new DOMDocument();
197 $doc->loadHTML(fetch_file_contents($article["link"]));
198
199 $basenode = false;
200
201 if ($doc) {
202 $xpath = new DOMXPath($doc);
203 $entries = $xpath->query('(//div[@class="post comic"])');
204
205 foreach ($entries as $entry) {
206 $basenode = $entry;
207 }
208
209 if ($basenode) {
210 $article["content"] = $doc->saveXML($basenode);
211 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
212 }
213 }
214 } else if (isset($article["stored"]["content"])) {
215 $article["content"] = $article["stored"]["content"];
216 }
217 }
218
219 if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
220 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
221 if ($debug_enabled) {
222 _debug("af_pennyarcade: Processing news post");
223 }
224 $doc = new DOMDocument();
225 $doc->loadHTML(fetch_file_contents($article["link"]));
226
227 if ($doc) {
228 $xpath = new DOMXPath($doc);
229 $entries = $xpath->query('(//div[@class="post"])');
230
231 $basenode = false;
232
233 foreach ($entries as $entry) {
234 $basenode = $entry;
235 }
236
237 $uninteresting = $xpath->query('(//div[@class="heading"])');
238 foreach ($uninteresting as $i) {
239 $i->parentNode->removeChild($i);
240 }
241
242 if ($basenode){
243 $article["content"] = $doc->saveXML($basenode);
244 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
245 }
246 }
247 } else if (isset($article["stored"]["content"])) {
248 $article["content"] = $article["stored"]["content"];
249 }
250 }
251
252 if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
253 if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
254
255 $doc = new DOMDocument();
256 @$doc->loadHTML(fetch_file_contents($article["link"]));
257
258 $basenode = false;
259
260 if ($doc) {
261 $xpath = new DOMXpath($doc);
262
263 $basenode = $xpath->query("//td/center/img")->item(0);
264
265 if ($basenode) {
266 $article["content"] = $doc->saveXML($basenode);
267 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
268 }
269 }
270 } else if (isset($article["stored"]["content"])) {
271 $article["content"] = $article["stored"]["content"];
272 }
273 }
274
275 return $article;
276 }
277
278 function api_version() {
279 return 2;
280 }
281
282 }
283 ?>