2016-01-10 02:00:16 +03:00
|
|
|
<?php
|
2016-01-16 18:30:29 +03:00
|
|
|
define('MANGAREADER_LIMIT', 10); // The default limit
|
2016-01-10 02:00:16 +03:00
|
|
|
class MangareaderBridge extends BridgeAbstract{
|
|
|
|
|
|
|
|
public function loadMetadatas() {
|
|
|
|
|
|
|
|
$this->maintainer = "logmanoriginal";
|
|
|
|
$this->name = "Mangareader Bridge";
|
|
|
|
$this->uri = "http://www.mangareader.net";
|
2016-01-21 23:49:23 +03:00
|
|
|
$this->description = "Returns the latest updates, popular mangas or manga updates (new chapters)";
|
2016-01-10 02:00:16 +03:00
|
|
|
|
2016-08-22 02:25:56 +03:00
|
|
|
$this->parameters["Get latest updates"] = array();
|
|
|
|
$this->parameters["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'
|
|
|
|
),
|
|
|
|
'exampleValue'=>'All',
|
|
|
|
'title'=>'Select your category'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->parameters["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'
|
|
|
|
),
|
|
|
|
'limit'=>array(
|
|
|
|
'name'=>'Limit',
|
|
|
|
'type'=>'number',
|
|
|
|
'exampleValue'=>10,
|
|
|
|
'title'=>'Number of items to return [-1 returns all]'
|
|
|
|
)
|
|
|
|
);
|
2016-01-10 02:00:16 +03:00
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-10 02:00:16 +03:00
|
|
|
public function collectData(array $param){
|
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->request = '';
|
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
$type = "latest"; // can be "latest", "popular" or "path". Default is "latest"!
|
2016-01-16 18:30:29 +03:00
|
|
|
$path = "latest";
|
|
|
|
$limit = MANGAREADER_LIMIT;
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
if(isset($param['category'])){ // Get popular updates
|
|
|
|
$type = "popular";
|
|
|
|
$path = "popular";
|
|
|
|
if($param['category'] !== "all"){
|
|
|
|
$path .= "/" . $param['category'];
|
|
|
|
}
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
if(isset($param['path'])){ // Get manga updates
|
|
|
|
$type = "path";
|
|
|
|
$path = $param['path'];
|
2016-08-22 02:25:56 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
if(isset($param['limit']) && $param['limit'] !== ""){ // Get manga updates (optional parameter)
|
2016-01-16 18:30:29 +03:00
|
|
|
$limit = $param['limit'];
|
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// We'll use the DOM parser for this as it makes navigation easier
|
2016-08-23 00:39:40 +03:00
|
|
|
$html = $this->getContents("http://www.mangareader.net/" . $path);
|
2016-01-16 18:30:29 +03:00
|
|
|
if(!$html){
|
2016-08-17 15:45:08 +03:00
|
|
|
$this->returnClientError('Could not receive data for ' . $path . '!');
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
|
|
|
$doc = new DomDocument;
|
2016-01-10 02:00:16 +03:00
|
|
|
@$doc->loadHTML($html);
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// Navigate via XPath
|
2016-01-10 02:00:16 +03:00
|
|
|
$xpath = new DomXPath($doc);
|
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// Build feed based on the context (site updates or manga updates)
|
2016-01-20 23:58:50 +03:00
|
|
|
if($type === "latest"){
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-21 23:49:23 +03:00
|
|
|
$this->request = 'Latest updates';
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// Query each item (consists of Manga + chapters)
|
|
|
|
$nodes = $xpath->query("//*[@id='latestchapters']/table//td");
|
2016-01-10 02:00:16 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
foreach ($nodes as $node){
|
|
|
|
// Query the manga
|
|
|
|
$manga = $xpath->query("a[@class='chapter']", $node)->item(0);
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// Collect the chapters for each Manga
|
|
|
|
$chapters = $xpath->query("a[@class='chaptersrec']", $node);
|
2016-01-10 02:00:16 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
if (isset($manga) && $chapters->length >= 1){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = 'http://www.mangareader.net' . htmlspecialchars($manga->getAttribute('href'));
|
|
|
|
$item['title'] = htmlspecialchars($manga->nodeValue);
|
2016-08-22 02:25:56 +03:00
|
|
|
|
|
|
|
// Add each chapter to the feed
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content'] = "";
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
foreach ($chapters as $chapter){
|
2016-08-22 19:55:59 +03:00
|
|
|
if($item['content'] <> ""){
|
|
|
|
$item['content'] .= "<br>";
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content'] .= "<a href='http://www.mangareader.net" . htmlspecialchars($chapter->getAttribute('href')) . "'>" . htmlspecialchars($chapter->nodeValue) . "</a>";
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
if($type === "popular"){
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
$pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
|
|
|
|
$this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); // "Popular mangas for ..."
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
// Query all mangas
|
|
|
|
$mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']");
|
2016-08-22 02:25:56 +03:00
|
|
|
|
|
|
|
foreach ($mangas as $manga){
|
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
// The thumbnail is encrypted in a css-style...
|
|
|
|
// format: "background-image:url('<the part which is actually interesting>')"
|
2016-08-22 02:25:56 +03:00
|
|
|
$mangaimgelement = $xpath->query(".//*[@class='imgsearchresults']", $manga)->item(0)->getAttribute('style');
|
2016-08-09 16:50:25 +03:00
|
|
|
$thumbnail = substr($mangaimgelement, 22, strlen($mangaimgelement) - 24);
|
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['title'] = htmlspecialchars($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'] = 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'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnail . '" alt="' . $item['title'] . '" /></a><p>' . $item['genre'] . '</p><p>' . $item['chaptercount'] . '</p>';
|
2016-01-20 23:58:50 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-20 23:58:50 +03:00
|
|
|
if($type === "path") {
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1]";
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
if($limit !== -1){
|
2016-01-19 23:41:14 +03:00
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - " . $limit . "]";
|
2016-08-22 02:25:56 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$chapters = $xpath->query($query);
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
foreach ($chapters as $chapter){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['title'] = htmlspecialchars($xpath->query("td[1]", $chapter)->item(0)->nodeValue);
|
|
|
|
$item['uri'] = 'http://www.mangareader.net' . $xpath->query("td[1]/a", $chapter)->item(0)->getAttribute('href');
|
|
|
|
$item['timestamp'] = strtotime($xpath->query("td[2]", $chapter)->item(0)->nodeValue);
|
2016-01-22 21:34:19 +03:00
|
|
|
array_unshift($this->items, $item);
|
2016-08-22 02:25:56 +03:00
|
|
|
}
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
// Return some dummy-data if no content available
|
2016-01-10 02:00:16 +03:00
|
|
|
if(count($this->items) == 0){
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['content'] = "<p>No updates available</p>";
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2016-01-10 02:00:16 +03:00
|
|
|
$this->items[] = $item;
|
2016-08-22 02:25:56 +03:00
|
|
|
}
|
2016-01-10 02:00:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2016-01-16 18:30:29 +03:00
|
|
|
return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge';
|
2016-01-10 02:00:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 10800; // 3 hours
|
|
|
|
}
|
|
|
|
}
|
2016-08-22 02:25:56 +03:00
|
|
|
?>
|