1
0
Quellcode durchsuchen

Add new option to get popular updates

logmanoriginal vor 8 Jahren
Ursprung
Commit
4422024cfd
1 geänderte Dateien mit 209 neuen und 7 gelöschten Zeilen
  1. 209 7
      bridges/MangareaderBridge.php

+ 209 - 7
bridges/MangareaderBridge.php

@@ -11,8 +11,172 @@ class MangareaderBridge extends BridgeAbstract{
 		$this->update = "2016-01-20";
 
 		$this->parameters["Get site updates"] = '[]';
-        $this->parameters["Get manga updates"] = '
-        [
+        $this->parameters["Get popular updates"] = 
+        '[
+            {
+                "name" : "Category",
+                "identifier" : "category",
+                "type" : "list",
+                "required" : "true",
+                "values" : [
+                    { 
+                        "name" : "All", 
+                        "value" : "all" 
+                    },
+                    {
+                        "name" : "Action",
+                        "value" : "action"
+                    },
+                    {
+                        "name" : "Adventure",
+                        "value" : "adventure"
+                    },
+                    {
+                        "name" : "Comedy",
+                        "value" : "comedy"
+                    },
+                    {
+                        "name" : "Demons",
+                        "value" : "demons"
+                    },
+                    {
+                        "name" : "Drama",
+                        "value" : "drama"
+                    },
+                    {
+                        "name" : "Ecchi",
+                        "value" : "ecchi"
+                    },
+                    {
+                        "name" : "Fantasy",
+                        "value" : "fantasy"
+                    },
+                    {
+                        "name" : "Gender Bender",
+                        "value" : "gender-bender"
+                    },
+                    {
+                        "name" : "Harem",
+                        "value" : "harem"
+                    },
+                    {
+                        "name" : "Historical",
+                        "value" : "historical"
+                    },
+                    {
+                        "name" : "Horror",
+                        "value" : "horror"
+                    },
+                    {
+                        "name" : "Josei",
+                        "value" : "josei"
+                    },
+                    {
+                        "name" : "Magic",
+                        "value" : "magic"
+                    },
+                    {
+                        "name" : "Martial Arts",
+                        "value" : "martial-arts"
+                    },
+                    {
+                        "name" : "Mature",
+                        "value" : "mature"
+                    },
+                    {
+                        "name" : "Mecha",
+                        "value" : "mecha"
+                    },
+                    {
+                        "name" : "Military",
+                        "value" : "military"
+                    },
+                    {
+                        "name" : "Mystery",
+                        "value" : "mystery"
+                    },
+                    {
+                        "name" : "One Shot",
+                        "value" : "one-shot"
+                    },
+                    {
+                        "name" : "Psychological",
+                        "value" : "psychological"
+                    },
+                    {
+                        "name" : "Romance",
+                        "value" : "romance"
+                    },
+                    {
+                        "name" : "School Life",
+                        "value" : "school-life"
+                    },
+                    {
+                        "name" : "Sci-Fi",
+                        "value" : "sci-fi"
+                    },
+                    {
+                        "name" : "Seinen",
+                        "value" : "seinen"
+                    },
+                    {
+                        "name" : "Shoujo",
+                        "value" : "shoujo"
+                    },
+                    {
+                        "name" : "Shoujoai",
+                        "value" : "shoujoai"
+                    },
+                    {
+                        "name" : "Shounen",
+                        "value" : "shounen"
+                    },
+                    {
+                        "name" : "Shounenai",
+                        "value" : "shounenai"
+                    },
+                    {
+                        "name" : "Slice of Life",
+                        "value" : "slice-of-life"
+                    },
+                    {
+                        "name" : "Smut",
+                        "value" : "smut"
+                    },
+                    {
+                        "name" : "Sports",
+                        "value" : "sports"
+                    },
+                    {
+                        "name" : "Super Power",
+                        "value" : "super-power"
+                    },
+                    {
+                        "name" : "Supernatural",
+                        "value" : "supernatural"
+                    },
+                    {
+                        "name" : "Tragedy",
+                        "value" : "tragedy"
+                    },
+                    {
+                        "name" : "Vampire",
+                        "value" : "vampire"
+                    },
+                    {
+                        "name" : "Yaoi",
+                        "value" : "yaoi"
+                    },
+                    {
+                        "name" : "Yuri",
+                        "value" : "yuri"
+                    }
+                ],
+                "exampleValue" : "All"
+            }
+        ]';
+        $this->parameters["Get manga updates"] = 
+        '[
            {
                "name" : "Path",
                "identifier" : "path",
@@ -34,14 +198,24 @@ class MangareaderBridge extends BridgeAbstract{
 
         $this->request = '';
 
+        $type = "latest"; // can be "latest", "popular" or "path". Default is "latest"!
         $path = "latest";
         $limit = MANGAREADER_LIMIT;
         
-        if(isset($param['path'])){
-            $path = $param['path'];
+        if(isset($param['category'])){ // Get popular updates
+            $type = "popular";
+            $path = "popular";
+            if($param['category'] !== "all"){
+                $path .= "/" . $param['category'];
+            }
         }
         
-        if(isset($param['limit']) && $param['limit'] !== ""){
+        if(isset($param['path'])){ // Get manga updates
+            $type = "path";
+            $path = $param['path'];
+        } 
+        
+        if(isset($param['limit']) && $param['limit'] !== ""){ // Get manga updates (optional parameter)
             $limit = $param['limit'];
         }
         
@@ -57,7 +231,7 @@ class MangareaderBridge extends BridgeAbstract{
 		$xpath = new DomXPath($doc);
 
         // Build feed based on the context (site updates or manga updates)
-        if($path === "latest"){
+        if($type === "latest"){
             
             $this->request = 'Latest';
             
@@ -89,7 +263,35 @@ class MangareaderBridge extends BridgeAbstract{
                     $this->items[] = $item;
                 }
             }
-        } else {
+        } 
+        
+        if($type === "popular"){
+            
+            $pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
+            $this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); // "Popular mangas for ..."
+            
+            // Query all mangas
+            $mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']");
+            
+            foreach ($mangas as $manga){ 
+                
+                // The thumbnail is encrypted in a css-style...
+                // format: "background-image:url('<the part which is actually interesting>')"
+                $mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga)->item(0)->getAttribute('style'); 
+                
+                $item = new \Item();
+                $item->title = $xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->nodeValue;
+                $item->uri = 'http://www.mangareader.net' . $xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->getAttribute('href');
+                $item->author = $xpath->query("//*[@class='author_name']", $manga)->item(0)->nodeValue;
+                $item->chaptercount = $xpath->query(".//*[@class='chapter_count']", $manga)->item(0)->nodeValue;
+                $item->genre = $xpath->query(".//*[@class='manga_genre']", $manga)->item(0)->nodeValue;
+                $item->thumbnailUri = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24);
+                $item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" alt="' . $item->title . '" /></a><p>' . $item->genre . '</p><p>' . $item->chaptercount . '</p>';
+                $this->items[] = $item;
+            }
+        }
+        
+        if($type === "path") {
             
             $this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;