]> git.wh0rd.org - tt-rss.git/commitdiff
af_redditimgur: support albums
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 12 Mar 2013 07:26:44 +0000 (11:26 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Tue, 12 Mar 2013 07:26:44 +0000 (11:26 +0400)
plugins/af_redditimgur/init.php

index 53cb875c82c2cc7edf6290664a063b7d53869ef5..5e863108db7ec9d5e019d8e8f28eb51148440c71 100644 (file)
@@ -45,7 +45,7 @@ class Af_RedditImgur extends Plugin {
 
                                                        // links to imgur pages
                                                        $matches = array();
-                                                       if (preg_match("/^http:\/\/imgur.com\/([^\.]+$)/", $entry->getAttribute("href"), $matches)) {
+                                                       if (preg_match("/^http:\/\/imgur.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
 
                                                                $token = $matches[1];
 
@@ -66,11 +66,37 @@ class Af_RedditImgur extends Plugin {
                                                                                                $img->setAttribute("src", $aentry->getAttribute("src"));
                                                                                                $entry->parentNode->insertBefore($img, $entry);
                                                                                                $found = true;
+
+                                                                                               break;
                                                                                        }
                                                                                }
                                                                        }
                                                                }
                                                        }
+
+                                                       // linked albums, ffs
+                                                       if (preg_match("/^http:\/\/imgur.com\/a\/[^\.]+$/", $entry->getAttribute("href"), $matches)) {
+
+                                                               $album_content = fetch_file_contents($entry->getAttribute("href"),
+                                                                       false, false, false, false, 10);
+
+                                                               if ($album_content) {
+                                                                       $adoc = new DOMDocument();
+                                                                       @$adoc->loadHTML($album_content);
+
+                                                                       if ($adoc) {
+                                                                               $axpath = new DOMXPath($adoc);
+                                                                               $aentries = $axpath->query("//div[@class='image']//a[@href and @class='zoom']");
+
+                                                                               foreach ($aentries as $aentry) {
+                                                                                       $img = $doc->createElement('img');
+                                                                                       $img->setAttribute("src", $aentry->getAttribute("href"));
+                                                                                       $entry->parentNode->insertBefore($img, $entry);
+                                                                                       $found = true;
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
                                                }
 
                                                // remove tiny thumbnails