]> git.wh0rd.org Git - tt-rss.git/blob - plugins/af_comics/filters/af_comics_dilbert.php
af_comics: split filters to separate files to ease maintenance
[tt-rss.git] / plugins / af_comics / filters / af_comics_dilbert.php
1 <?php
2 class Af_Comics_Dilbert extends Af_ComicFilter {
3
4         function supported() {
5                 return array("Dilbert");
6         }
7
8         function process(&$article) {
9                 $owner_uid = $article["owner_uid"];
10
11                 if (strpos($article["guid"], "dilbert.com") !== FALSE) {
12                         if (strpos($article["plugin_data"], "af_comics,$owner_uid:") === FALSE) {
13                                 $doc = new DOMDocument();
14                                 @$doc->loadHTML(fetch_file_contents($article["link"]));
15
16                                 $basenode = false;
17
18                                 if ($doc) {
19                                         $xpath = new DOMXPath($doc);
20                                         $entries = $xpath->query('(//img[@src])'); // we might also check for img[@class='strip'] I guess...
21
22                                         $matches = array();
23
24                                         foreach ($entries as $entry) {
25
26                                                 if (preg_match("/dyn\/str_strip\/.*zoom\.gif$/", $entry->getAttribute("src"), $matches)) {
27
28                                                         $entry->setAttribute("src",
29                                                                 rewrite_relative_url("http://dilbert.com/",
30                                                                 $matches[0]));
31
32                                                         $basenode = $entry;
33                                                         break;
34                                                 }
35                                         }
36
37                                         if ($basenode) {
38                                                 $article["content"] = $doc->saveXML($basenode);
39                                                 $article["plugin_data"] = "af_comics,$owner_uid:" . $article["plugin_data"];
40                                         }
41                                 }
42                         } else if (isset($article["stored"]["content"])) {
43                                 $article["content"] = $article["stored"]["content"];
44                         }
45
46                         return true;
47                 }
48
49                 return false;
50         }
51 }
52 ?>