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-16 18:30:29 +03:00
|
|
|
$this->description = "Returns the latest updates. Set limits to -1 to disable the limit.";
|
2016-01-20 22:52:57 +03:00
|
|
|
$this->update = "2016-01-20";
|
2016-01-10 02:00:16 +03:00
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->parameters["Get site updates"] = '[]';
|
|
|
|
$this->parameters["Get manga updates"] = '
|
|
|
|
[
|
|
|
|
{
|
2016-01-20 22:56:09 +03:00
|
|
|
"name" : "Path",
|
2016-01-16 18:30:29 +03:00
|
|
|
"identifier" : "path",
|
|
|
|
"type" : "text",
|
|
|
|
"required" : "true",
|
|
|
|
"pattern" : "[a-zA-Z0-9-_]*",
|
|
|
|
"exampleValue" : "bleach, umi-no-kishidan"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" : "Limit",
|
|
|
|
"identifier" : "limit",
|
|
|
|
"type" : "number",
|
|
|
|
"exampleValue" : "10"
|
|
|
|
}
|
|
|
|
]';
|
2016-01-10 02:00:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(array $param){
|
|
|
|
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->request = '';
|
|
|
|
|
|
|
|
$path = "latest";
|
|
|
|
$limit = MANGAREADER_LIMIT;
|
|
|
|
|
|
|
|
if(isset($param['path'])){
|
|
|
|
$path = $param['path'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($param['limit']) && $param['limit'] !== ""){
|
|
|
|
$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){
|
|
|
|
$this->returnError('Could not receive data for ' . $path . '!', 400);
|
|
|
|
}
|
|
|
|
$doc = new DomDocument;
|
2016-01-10 02:00:16 +03:00
|
|
|
@$doc->loadHTML($html);
|
|
|
|
|
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)
|
|
|
|
if($path === "latest"){
|
|
|
|
|
|
|
|
$this->request = 'Latest';
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// 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){
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;
|
|
|
|
|
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1]";
|
|
|
|
|
|
|
|
if($limit !== -1){
|
2016-01-19 23:41:14 +03:00
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - " . $limit . "]";
|
2016-01-16 18:30:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$chapters = $xpath->query($query);
|
|
|
|
|
|
|
|
foreach ($chapters as $chapter){
|
|
|
|
$item = new \Item();
|
2016-01-20 22:52:57 +03:00
|
|
|
$item->title = $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->description = substr($xpath->query("td[1]", $chapter)->item(0)->nodeValue, strrpos($item->title, ": ") + 2);
|
|
|
|
$item->date = $xpath->query("td[2]", $chapter)->item(0)->nodeValue;
|
2016-01-19 23:36:41 +03:00
|
|
|
$item->content = $item->description . "<br/><time datetime=\"" . $item->date . "\">" . $item->date . "</time>";
|
2016-01-16 18:30:29 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return some dummy-data if no content available
|
2016-01-10 02:00:16 +03: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 18:30:29 +03:00
|
|
|
return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge';
|
2016-01-10 02:00:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
return 'http://www.mangareader.net';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 10800; // 3 hours
|
|
|
|
}
|
|
|
|
}
|
2016-01-16 18:30:29 +03:00
|
|
|
?>
|