2016-01-10 00:00:16 +01:00
|
|
|
<?php
|
2016-01-16 16:30:29 +01:00
|
|
|
define('MANGAREADER_LIMIT', 10); // The default limit
|
2016-01-10 00:00:16 +01:00
|
|
|
class MangareaderBridge extends BridgeAbstract{
|
|
|
|
|
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "logmanoriginal";
|
|
|
|
$this->name = "Mangareader Bridge";
|
|
|
|
$this->uri = "http://www.mangareader.net";
|
2016-01-21 21:49:23 +01:00
|
|
|
$this->description = "Returns the latest updates, popular mangas or manga updates (new chapters)";
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-01-21 21:49:23 +01:00
|
|
|
$this->parameters["Get latest updates"] = '[]';
|
|
|
|
$this->parameters["Get popular mangas"] =
|
2016-01-20 21:58:50 +01:00
|
|
|
'[
|
|
|
|
{
|
|
|
|
"name" : "Category",
|
|
|
|
"identifier" : "category",
|
|
|
|
"type" : "list",
|
2016-08-15 01:19:16 +02:00
|
|
|
"required" : true,
|
2016-01-20 21:58:50 +01:00
|
|
|
"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"
|
|
|
|
}
|
|
|
|
],
|
2016-01-21 21:49:23 +01:00
|
|
|
"exampleValue" : "All",
|
|
|
|
"title" : "Select your category"
|
2016-01-20 21:58:50 +01:00
|
|
|
}
|
|
|
|
]';
|
|
|
|
$this->parameters["Get manga updates"] =
|
|
|
|
'[
|
2016-01-16 16:30:29 +01:00
|
|
|
{
|
2016-01-20 20:56:09 +01:00
|
|
|
"name" : "Path",
|
2016-01-16 16:30:29 +01:00
|
|
|
"identifier" : "path",
|
|
|
|
"type" : "text",
|
2016-08-15 01:19:16 +02:00
|
|
|
"required" : true,
|
2016-01-16 16:30:29 +01:00
|
|
|
"pattern" : "[a-zA-Z0-9-_]*",
|
2016-01-21 21:49:23 +01:00
|
|
|
"exampleValue" : "bleach, umi-no-kishidan",
|
|
|
|
"title" : "URL part of desired manga"
|
2016-01-16 16:30:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "Limit",
|
|
|
|
"identifier" : "limit",
|
|
|
|
"type" : "number",
|
2016-01-21 21:49:23 +01:00
|
|
|
"exampleValue" : "10",
|
|
|
|
"title" : "Number of items to return.\n-1 returns all"
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
|
|
|
]';
|
2016-01-10 00:00:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(array $param){
|
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
$this->request = '';
|
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
$type = "latest"; // can be "latest", "popular" or "path". Default is "latest"!
|
2016-01-16 16:30:29 +01:00
|
|
|
$path = "latest";
|
|
|
|
$limit = MANGAREADER_LIMIT;
|
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
if(isset($param['category'])){ // Get popular updates
|
|
|
|
$type = "popular";
|
|
|
|
$path = "popular";
|
|
|
|
if($param['category'] !== "all"){
|
|
|
|
$path .= "/" . $param['category'];
|
|
|
|
}
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
if(isset($param['path'])){ // Get manga updates
|
|
|
|
$type = "path";
|
|
|
|
$path = $param['path'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($param['limit']) && $param['limit'] !== ""){ // Get manga updates (optional parameter)
|
2016-01-16 16:30:29 +01:00
|
|
|
$limit = $param['limit'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll use the DOM parser for this as it makes navigation easier
|
|
|
|
$html = file_get_contents("http://www.mangareader.net/" . $path);
|
|
|
|
if(!$html){
|
2016-08-17 14:45:08 +02:00
|
|
|
$this->returnClientError('Could not receive data for ' . $path . '!');
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
|
|
|
$doc = new DomDocument;
|
2016-01-10 00:00:16 +01:00
|
|
|
@$doc->loadHTML($html);
|
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
// Navigate via XPath
|
2016-01-10 00:00:16 +01:00
|
|
|
$xpath = new DomXPath($doc);
|
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
// Build feed based on the context (site updates or manga updates)
|
2016-01-20 21:58:50 +01:00
|
|
|
if($type === "latest"){
|
2016-01-16 16:30:29 +01:00
|
|
|
|
2016-01-21 21:49:23 +01:00
|
|
|
$this->request = 'Latest updates';
|
2016-01-16 16:30:29 +01:00
|
|
|
|
|
|
|
// Query each item (consists of Manga + chapters)
|
|
|
|
$nodes = $xpath->query("//*[@id='latestchapters']/table//td");
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
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);
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
if (isset($manga) && $chapters->length >= 1){
|
|
|
|
$item = new \Item();
|
|
|
|
$item->uri = 'http://www.mangareader.net' . 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 .= "<br>";
|
|
|
|
}
|
|
|
|
$item->content .= "<a href='http://www.mangareader.net" . htmlspecialchars($chapter->getAttribute('href')) . "'>" . htmlspecialchars($chapter->nodeValue) . "</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 21:58:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2016-08-09 15:50:25 +02:00
|
|
|
$thumbnail = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24);
|
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
$item = new \Item();
|
2016-01-22 19:30:45 +01:00
|
|
|
$item->title = htmlspecialchars($xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->nodeValue);
|
2016-01-20 21:58:50 +01:00
|
|
|
$item->uri = 'http://www.mangareader.net' . $xpath->query(".//*[@class='manga_name']//a", $manga)->item(0)->getAttribute('href');
|
2016-01-22 19:30:45 +01:00
|
|
|
$item->author = htmlspecialchars($xpath->query("//*[@class='author_name']", $manga)->item(0)->nodeValue);
|
2016-01-20 21:58:50 +01:00
|
|
|
$item->chaptercount = $xpath->query(".//*[@class='chapter_count']", $manga)->item(0)->nodeValue;
|
2016-01-22 19:30:45 +01:00
|
|
|
$item->genre = htmlspecialchars($xpath->query(".//*[@class='manga_genre']", $manga)->item(0)->nodeValue);
|
2016-08-09 15:50:25 +02:00
|
|
|
$item->content = '<a href="' . $item->uri . '"><img src="' . $thumbnail . '" alt="' . $item->title . '" /></a><p>' . $item->genre . '</p><p>' . $item->chaptercount . '</p>';
|
2016-01-20 21:58:50 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($type === "path") {
|
2016-01-16 16:30:29 +01:00
|
|
|
|
|
|
|
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;
|
|
|
|
|
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1]";
|
|
|
|
|
|
|
|
if($limit !== -1){
|
2016-01-19 21:41:14 +01:00
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - " . $limit . "]";
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$chapters = $xpath->query($query);
|
|
|
|
|
|
|
|
foreach ($chapters as $chapter){
|
|
|
|
$item = new \Item();
|
2016-01-22 19:30:45 +01:00
|
|
|
$item->title = htmlspecialchars($xpath->query("td[1]", $chapter)->item(0)->nodeValue);
|
2016-01-20 20:52:57 +01:00
|
|
|
$item->uri = 'http://www.mangareader.net' . $xpath->query("td[1]/a", $chapter)->item(0)->getAttribute('href');
|
2016-01-22 19:56:07 +01:00
|
|
|
$item->timestamp = strtotime($xpath->query("td[2]", $chapter)->item(0)->nodeValue);
|
2016-01-22 19:34:19 +01:00
|
|
|
array_unshift($this->items, $item);
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return some dummy-data if no content available
|
2016-01-10 00:00:16 +01:00
|
|
|
if(count($this->items) == 0){
|
|
|
|
$item = new \Item();
|
|
|
|
$item->content = "<p>No updates available</p>";
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2016-01-16 16:30:29 +01:00
|
|
|
return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge';
|
2016-01-10 00:00:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 10800; // 3 hours
|
|
|
|
}
|
|
|
|
}
|
2016-01-16 16:30:29 +01:00
|
|
|
?>
|