From 4c96aab8321b79e5d41200e7c2e51854d394a18b Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 3 Sep 2016 20:03:06 +0200 Subject: [PATCH 1/4] [Mangareader] Replace global constant with 'defaultValue' --- bridges/MangareaderBridge.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index ce93ed37..23a8dea5 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -1,5 +1,4 @@ array( 'name'=>'Limit', 'type'=>'number', - 'exampleValue'=>10, + 'defaultValue'=>10, 'title'=>'Number of items to return [-1 returns all]' ) ) @@ -154,7 +153,7 @@ class MangareaderBridge extends BridgeAbstract{ case 'Get manga updates': $limit = $this->getInput('limit'); if(empty($limit)){ - $limit = MANGAREADER_LIMIT; + $limit = self::PARAMETERS[$this->queriedContext]['limit']['defaultValue']; } $this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue; From 6c51eaa4d775079de273e16d3e137e680b915c9e Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 3 Sep 2016 20:10:36 +0200 Subject: [PATCH 2/4] [Mangareader] Fix coding styles --- bridges/MangareaderBridge.php | 166 +++++++++++++++++----------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index 23a8dea5..551c2ab1 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -1,94 +1,94 @@ array(), 'Get popular mangas' => array( - 'category'=>array( - 'name'=>'Category', - 'type'=>'list', - 'required'=>true, - 'values'=>array( - 'All'=>'all', - 'Action'=>'action', - 'Adventure'=>'adventure', - 'Comedy'=>'comedy', - 'Demons'=>'demons', - 'Drama'=>'drama', - 'Ecchi'=>'ecchi', - 'Fantasy'=>'fantasy', - 'Gender Bender'=>'gender-bender', - 'Harem'=>'harem', - 'Historical'=>'historical', - 'Horror'=>'horror', - 'Josei'=>'josei', - 'Magic'=>'magic', - 'Martial Arts'=>'martial-arts', - 'Mature'=>'mature', - 'Mecha'=>'mecha', - 'Military'=>'military', - 'Mystery'=>'mystery', - 'One Shot'=>'one-shot', - 'Psychological'=>'psychological', - 'Romance'=>'romance', - 'School Life'=>'school-life', - 'Sci-Fi'=>'sci-fi', - 'Seinen'=>'seinen', - 'Shoujo'=>'shoujo', - 'Shoujoai'=>'shoujoai', - 'Shounen'=>'shounen', - 'Shounenai'=>'shounenai', - 'Slice of Life'=>'slice-of-life', - 'Smut'=>'smut', - 'Sports'=>'sports', - 'Super Power'=>'super-power', - 'Supernatural'=>'supernatural', - 'Tragedy'=>'tragedy', - 'Vampire'=>'vampire', - 'Yaoi'=>'yaoi', - 'Yuri'=>'yuri' + 'category' => array( + 'name' => 'Category', + 'type' => 'list', + 'required' => true, + 'values' => array( + 'All' => 'all', + 'Action' => 'action', + 'Adventure' => 'adventure', + 'Comedy' => 'comedy', + 'Demons' => 'demons', + 'Drama' => 'drama', + 'Ecchi' => 'ecchi', + 'Fantasy' => 'fantasy', + 'Gender Bender' => 'gender-bender', + 'Harem' => 'harem', + 'Historical' => 'historical', + 'Horror' => 'horror', + 'Josei' => 'josei', + 'Magic' => 'magic', + 'Martial Arts' => 'martial-arts', + 'Mature' => 'mature', + 'Mecha' => 'mecha', + 'Military' => 'military', + 'Mystery' => 'mystery', + 'One Shot' => 'one-shot', + 'Psychological' => 'psychological', + 'Romance' => 'romance', + 'School Life' => 'school-life', + 'Sci-Fi' => 'sci-fi', + 'Seinen' => 'seinen', + 'Shoujo' => 'shoujo', + 'Shoujoai' => 'shoujoai', + 'Shounen' => 'shounen', + 'Shounenai' => 'shounenai', + 'Slice of Life' => 'slice-of-life', + 'Smut' => 'smut', + 'Sports' => 'sports', + 'Super Power' => 'super-power', + 'Supernatural' => 'supernatural', + 'Tragedy' => 'tragedy', + 'Vampire' => 'vampire', + 'Yaoi' => 'yaoi', + 'Yuri' => 'yuri' ), - 'exampleValue'=>'All', - 'title'=>'Select your category' + 'exampleValue' => 'All', + 'title' => 'Select your category' ) ), 'Get manga updates' => array( - 'path'=>array( - 'name'=>'Path', - 'required'=>true, - 'pattern'=>'[a-zA-Z0-9-_]*', - 'exampleValue'=>'bleach, umi-no-kishidan', - 'title'=>'URL part of desired manga' + 'path' => array( + 'name' => 'Path', + 'required' => true, + 'pattern' => '[a-zA-Z0-9-_]*', + 'exampleValue' => 'bleach, umi-no-kishidan', + 'title' => 'URL part of desired manga' ), - 'limit'=>array( - 'name'=>'Limit', - 'type'=>'number', - 'defaultValue'=>10, - 'title'=>'Number of items to return [-1 returns all]' + 'limit' => array( + 'name' => 'Limit', + 'type' => 'number', + 'defaultValue' => 10, + 'title' => 'Number of items to return [-1 returns all]' ) ) ); - private $request=''; + private $request = ''; - public function collectData(){ - // We'll use the DOM parser for this as it makes navigation easier - $html = $this->getContents($this->getURI()); + public function collectData(){ + // We'll use the DOM parser for this as it makes navigation easier + $html = $this->getContents($this->getURI()); if(!$html){ $this->returnClientError('Could not receive data for ' . $path . '!'); } libxml_use_internal_errors(true); $doc = new DomDocument; - @$doc->loadHTML($html); + @$doc->loadHTML($html); libxml_clear_errors(); - // Navigate via XPath - $xpath = new DomXPath($doc); + // Navigate via XPath + $xpath = new DomXPath($doc); $this->request = ''; switch($this->queriedContext){ @@ -107,7 +107,7 @@ class MangareaderBridge extends BridgeAbstract{ if (isset($manga) && $chapters->length >= 1){ $item = array(); - $item['uri'] = self::URI. htmlspecialchars($manga->getAttribute('href')); + $item['uri'] = self::URI . htmlspecialchars($manga->getAttribute('href')); $item['title'] = htmlspecialchars($manga->nodeValue); // Add each chapter to the feed @@ -117,7 +117,7 @@ class MangareaderBridge extends BridgeAbstract{ if($item['content'] <> ""){ $item['content'] .= "
"; } - $item['content'] .= "" . htmlspecialchars($chapter->nodeValue) . ""; + $item['content'] .= "" . htmlspecialchars($chapter->nodeValue) . ""; } $this->items[] = $item; @@ -176,14 +176,14 @@ class MangareaderBridge extends BridgeAbstract{ break; } - // Return some dummy-data if no content available - if(empty($this->items)){ - $item = array(); - $item['content'] = "

No updates available

"; + // Return some dummy-data if no content available + if(empty($this->items)){ + $item = array(); + $item['content'] = "

No updates available

"; - $this->items[] = $item; - } - } + $this->items[] = $item; + } + } public function getURI(){ switch($this->queriedContext){ @@ -204,12 +204,12 @@ class MangareaderBridge extends BridgeAbstract{ } - public function getName(){ - return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge'; - } + public function getName(){ + return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge'; + } - public function getCacheDuration(){ - return 10800; // 3 hours - } + public function getCacheDuration(){ + return 10800; // 3 hours + } } ?> From f9a8f166858e7127a50841610e1748e92b4e91de Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 3 Sep 2016 20:23:18 +0200 Subject: [PATCH 3/4] [Mangareader] Reduce line lengths --- bridges/MangareaderBridge.php | 61 +++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index 551c2ab1..e4ad472b 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -117,7 +117,13 @@ class MangareaderBridge extends BridgeAbstract { if($item['content'] <> ""){ $item['content'] .= "
"; } - $item['content'] .= "" . htmlspecialchars($chapter->nodeValue) . ""; + $item['content'] .= + "" + . htmlspecialchars($chapter->nodeValue) + . ""; } $this->items[] = $item; @@ -127,7 +133,9 @@ class MangareaderBridge extends BridgeAbstract { case 'Get popular mangas': $pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue; - $this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); // "Popular mangas for ..." + + // Find manga name within "Popular mangas for ..." + $this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); // Query all mangas $mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']"); @@ -136,16 +144,32 @@ class MangareaderBridge extends BridgeAbstract { // The thumbnail is encrypted in a css-style... // format: "background-image:url('')" - $mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga)->item(0)->getAttribute('style'); + $mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga) + ->item(0) + ->getAttribute('style'); $thumbnail = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24); $item = array(); - $item['title'] = htmlspecialchars($xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->nodeValue); - $item['uri'] = self::URI . $xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->getAttribute('href'); - $item['author'] = htmlspecialchars($xpath->query("//*[@class='author_name']", $manga)->item(0)->nodeValue); - $item['chaptercount'] = $xpath->query(".//*[@class='chapter_count']", $manga)->item(0)->nodeValue; - $item['genre'] = htmlspecialchars($xpath->query(".//*[@class='manga_genre']", $manga)->item(0)->nodeValue); - $item['content'] = '' . $item['title'] . '

' . $item['genre'] . '

' . $item['chaptercount'] . '

'; + $item['title'] = htmlspecialchars($xpath->query(".//*[@class='manga_name']//a", $manga) + ->item(0) + ->nodeValue); + $item['uri'] = self::URI . $xpath->query(".//*[@class='manga_name']//a", $manga) + ->item(0) + ->getAttribute('href'); + $item['author'] = htmlspecialchars($xpath->query("//*[@class='author_name']", $manga) + ->item(0) + ->nodeValue); + $item['chaptercount'] = $xpath->query(".//*[@class='chapter_count']", $manga) + ->item(0) + ->nodeValue; + $item['genre'] = htmlspecialchars($xpath->query(".//*[@class='manga_genre']", $manga) + ->item(0) + ->nodeValue); + $item['content'] = <<{$item['title']} +

{$item['genre']}

+

{$item['chaptercount']}

+EOD; $this->items[] = $item; } break; @@ -156,21 +180,30 @@ class MangareaderBridge extends BridgeAbstract { $limit = self::PARAMETERS[$this->queriedContext]['limit']['defaultValue']; } - $this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue; + $this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']") + ->item(0) + ->nodeValue; $query = "(.//*[@id='listing']//tr)[position() > 1]"; if($limit !== -1){ - $query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - " . $limit . "]"; + $query = + "(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]"; } $chapters = $xpath->query($query); foreach ($chapters as $chapter){ $item = array(); - $item['title'] = htmlspecialchars($xpath->query("td[1]", $chapter)->item(0)->nodeValue); - $item['uri'] = self::URI . $xpath->query("td[1]/a", $chapter)->item(0)->getAttribute('href'); - $item['timestamp'] = strtotime($xpath->query("td[2]", $chapter)->item(0)->nodeValue); + $item['title'] = htmlspecialchars($xpath->query("td[1]", $chapter) + ->item(0) + ->nodeValue); + $item['uri'] = self::URI . $xpath->query("td[1]/a", $chapter) + ->item(0) + ->getAttribute('href'); + $item['timestamp'] = strtotime($xpath->query("td[2]", $chapter) + ->item(0) + ->nodeValue); array_unshift($this->items, $item); } break; From 99f00e57b5c837b070547236edbddde784d46171 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 3 Sep 2016 20:35:49 +0200 Subject: [PATCH 4/4] [Mangareader] Add functions to collect data --- bridges/MangareaderBridge.php | 200 +++++++++++++++++----------------- 1 file changed, 103 insertions(+), 97 deletions(-) diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index e4ad472b..60b15f00 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -94,86 +94,14 @@ class MangareaderBridge extends BridgeAbstract { switch($this->queriedContext){ case 'Get latest updates': $this->request = 'Latest updates'; - - // Query each item (consists of Manga + chapters) - $nodes = $xpath->query("//*[@id='latestchapters']/table//td"); - - foreach ($nodes as $node){ - // Query the manga - $manga = $xpath->query("a[@class='chapter']", $node)->item(0); - - // Collect the chapters for each Manga - $chapters = $xpath->query("a[@class='chaptersrec']", $node); - - if (isset($manga) && $chapters->length >= 1){ - $item = array(); - $item['uri'] = self::URI . htmlspecialchars($manga->getAttribute('href')); - $item['title'] = htmlspecialchars($manga->nodeValue); - - // Add each chapter to the feed - $item['content'] = ""; - - foreach ($chapters as $chapter){ - if($item['content'] <> ""){ - $item['content'] .= "
"; - } - $item['content'] .= - "" - . htmlspecialchars($chapter->nodeValue) - . ""; - } - - $this->items[] = $item; - } - } + $this->get_latest_updates($xpath); break; - case 'Get popular mangas': - $pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue; - // Find manga name within "Popular mangas for ..." + $pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue; $this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); - - // 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('')" - $mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga) - ->item(0) - ->getAttribute('style'); - $thumbnail = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24); - - $item = array(); - $item['title'] = htmlspecialchars($xpath->query(".//*[@class='manga_name']//a", $manga) - ->item(0) - ->nodeValue); - $item['uri'] = self::URI . $xpath->query(".//*[@class='manga_name']//a", $manga) - ->item(0) - ->getAttribute('href'); - $item['author'] = htmlspecialchars($xpath->query("//*[@class='author_name']", $manga) - ->item(0) - ->nodeValue); - $item['chaptercount'] = $xpath->query(".//*[@class='chapter_count']", $manga) - ->item(0) - ->nodeValue; - $item['genre'] = htmlspecialchars($xpath->query(".//*[@class='manga_genre']", $manga) - ->item(0) - ->nodeValue); - $item['content'] = <<{$item['title']} -

{$item['genre']}

-

{$item['chaptercount']}

-EOD; - $this->items[] = $item; - } + $this->get_popular_mangas($xpath); break; - case 'Get manga updates': $limit = $this->getInput('limit'); if(empty($limit)){ @@ -184,28 +112,7 @@ EOD; ->item(0) ->nodeValue; - $query = "(.//*[@id='listing']//tr)[position() > 1]"; - - if($limit !== -1){ - $query = - "(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]"; - } - - $chapters = $xpath->query($query); - - foreach ($chapters as $chapter){ - $item = array(); - $item['title'] = htmlspecialchars($xpath->query("td[1]", $chapter) - ->item(0) - ->nodeValue); - $item['uri'] = self::URI . $xpath->query("td[1]/a", $chapter) - ->item(0) - ->getAttribute('href'); - $item['timestamp'] = strtotime($xpath->query("td[2]", $chapter) - ->item(0) - ->nodeValue); - array_unshift($this->items, $item); - } + $this->get_manga_updates($xpath, $limit); break; } @@ -218,6 +125,105 @@ EOD; } } + private function get_latest_updates($xpath){ + // Query each item (consists of Manga + chapters) + $nodes = $xpath->query("//*[@id='latestchapters']/table//td"); + + foreach ($nodes as $node){ + // Query the manga + $manga = $xpath->query("a[@class='chapter']", $node)->item(0); + + // Collect the chapters for each Manga + $chapters = $xpath->query("a[@class='chaptersrec']", $node); + + if (isset($manga) && $chapters->length >= 1){ + $item = array(); + $item['uri'] = self::URI . htmlspecialchars($manga->getAttribute('href')); + $item['title'] = htmlspecialchars($manga->nodeValue); + + // Add each chapter to the feed + $item['content'] = ""; + + foreach ($chapters as $chapter){ + if($item['content'] <> ""){ + $item['content'] .= "
"; + } + $item['content'] .= + "" + . htmlspecialchars($chapter->nodeValue) + . ""; + } + + $this->items[] = $item; + } + } + } + + private function get_popular_mangas($xpath){ + // 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('')" + $mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga) + ->item(0) + ->getAttribute('style'); + $thumbnail = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24); + + $item = array(); + $item['title'] = htmlspecialchars($xpath->query(".//*[@class='manga_name']//a", $manga) + ->item(0) + ->nodeValue); + $item['uri'] = self::URI . $xpath->query(".//*[@class='manga_name']//a", $manga) + ->item(0) + ->getAttribute('href'); + $item['author'] = htmlspecialchars($xpath->query("//*[@class='author_name']", $manga) + ->item(0) + ->nodeValue); + $item['chaptercount'] = $xpath->query(".//*[@class='chapter_count']", $manga) + ->item(0) + ->nodeValue; + $item['genre'] = htmlspecialchars($xpath->query(".//*[@class='manga_genre']", $manga) + ->item(0) + ->nodeValue); + $item['content'] = <<{$item['title']} +

{$item['genre']}

+

{$item['chaptercount']}

+EOD; + $this->items[] = $item; + } + } + + private function get_manga_updates($xpath, $limit){ + $query = "(.//*[@id='listing']//tr)[position() > 1]"; + + if($limit !== -1){ + $query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]"; + } + + $chapters = $xpath->query($query); + + foreach ($chapters as $chapter){ + $item = array(); + $item['title'] = htmlspecialchars($xpath->query("td[1]", $chapter) + ->item(0) + ->nodeValue); + $item['uri'] = self::URI . $xpath->query("td[1]/a", $chapter) + ->item(0) + ->getAttribute('href'); + $item['timestamp'] = strtotime($xpath->query("td[2]", $chapter) + ->item(0) + ->nodeValue); + array_unshift($this->items, $item); + } + } + public function getURI(){ switch($this->queriedContext){ case 'Get latest updates':