2016-01-10 00:00:16 +01:00
|
|
|
<?php
|
2016-09-03 20:10:36 +02:00
|
|
|
class MangareaderBridge extends BridgeAbstract {
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
const MAINTAINER = "logmanoriginal";
|
|
|
|
const NAME = "Mangareader Bridge";
|
|
|
|
const URI = "http://www.mangareader.net/";
|
|
|
|
const DESCRIPTION = "Returns the latest updates, popular mangas or manga updates (new chapters)";
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'Get latest updates' => array(),
|
|
|
|
'Get popular mangas' => array(
|
2016-09-03 20:10:36 +02:00
|
|
|
'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'
|
2016-08-22 01:25:56 +02:00
|
|
|
),
|
2016-09-03 20:10:36 +02:00
|
|
|
'exampleValue' => 'All',
|
|
|
|
'title' => 'Select your category'
|
2016-08-22 01:25:56 +02:00
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
),
|
|
|
|
'Get manga updates' => array(
|
2016-09-03 20:10:36 +02:00
|
|
|
'path' => array(
|
|
|
|
'name' => 'Path',
|
|
|
|
'required' => true,
|
|
|
|
'pattern' => '[a-zA-Z0-9-_]*',
|
|
|
|
'exampleValue' => 'bleach, umi-no-kishidan',
|
|
|
|
'title' => 'URL part of desired manga'
|
2016-08-22 01:25:56 +02:00
|
|
|
),
|
2016-09-03 20:10:36 +02:00
|
|
|
'limit' => array(
|
|
|
|
'name' => 'Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => 10,
|
|
|
|
'title' => 'Number of items to return [-1 returns all]'
|
2016-08-22 01:25:56 +02:00
|
|
|
)
|
2016-08-27 21:03:26 +02:00
|
|
|
)
|
|
|
|
);
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
private $request = '';
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
public function collectData(){
|
|
|
|
// We'll use the DOM parser for this as it makes navigation easier
|
|
|
|
$html = $this->getContents($this->getURI());
|
2016-01-16 16:30:29 +01:00
|
|
|
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
|
|
|
}
|
2016-08-29 13:29:17 +02:00
|
|
|
libxml_use_internal_errors(true);
|
2016-01-16 16:30:29 +01:00
|
|
|
$doc = new DomDocument;
|
2016-09-03 20:10:36 +02:00
|
|
|
@$doc->loadHTML($html);
|
2016-08-29 13:29:17 +02:00
|
|
|
libxml_clear_errors();
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
// Navigate via XPath
|
|
|
|
$xpath = new DomXPath($doc);
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-08-29 13:29:17 +02:00
|
|
|
$this->request = '';
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'Get latest updates':
|
2016-01-21 21:49:23 +01:00
|
|
|
$this->request = 'Latest updates';
|
2016-08-22 01:25:56 +02:00
|
|
|
|
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);
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
// 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){
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-09-03 20:10:36 +02:00
|
|
|
$item['uri'] = self::URI . htmlspecialchars($manga->getAttribute('href'));
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title'] = htmlspecialchars($manga->nodeValue);
|
2016-08-22 01:25:56 +02:00
|
|
|
|
|
|
|
// Add each chapter to the feed
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = "";
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
foreach ($chapters as $chapter){
|
2016-08-22 18:55:59 +02:00
|
|
|
if($item['content'] <> ""){
|
|
|
|
$item['content'] .= "<br>";
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
2016-09-03 20:23:18 +02:00
|
|
|
$item['content'] .=
|
|
|
|
"<a href='"
|
|
|
|
. self::URI
|
|
|
|
. htmlspecialchars($chapter->getAttribute('href'))
|
|
|
|
. "'>"
|
|
|
|
. htmlspecialchars($chapter->nodeValue)
|
|
|
|
. "</a>";
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-08-29 13:29:17 +02:00
|
|
|
break;
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-08-29 13:29:17 +02:00
|
|
|
case 'Get popular mangas':
|
2016-01-20 21:58:50 +01:00
|
|
|
$pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
|
2016-09-03 20:23:18 +02:00
|
|
|
|
|
|
|
// Find manga name within "Popular mangas for ..."
|
|
|
|
$this->request = substr($pagetitle, 0, strrpos($pagetitle, " -"));
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
// Query all mangas
|
|
|
|
$mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']");
|
2016-08-22 01:25:56 +02:00
|
|
|
|
|
|
|
foreach ($mangas as $manga){
|
|
|
|
|
2016-01-20 21:58:50 +01:00
|
|
|
// The thumbnail is encrypted in a css-style...
|
|
|
|
// format: "background-image:url('<the part which is actually interesting>')"
|
2016-09-03 20:23:18 +02:00
|
|
|
$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-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-09-03 20:23:18 +02:00
|
|
|
$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'] = <<<EOD
|
|
|
|
<a href="{$item['uri']}"><img src="{$thumbnail}" alt="{$item['title']}" /></a>
|
|
|
|
<p>{$item['genre']}</p>
|
|
|
|
<p>{$item['chaptercount']}</p>
|
|
|
|
EOD;
|
2016-01-20 21:58:50 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2016-08-29 13:29:17 +02:00
|
|
|
break;
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-08-29 13:29:17 +02:00
|
|
|
case 'Get manga updates':
|
|
|
|
$limit = $this->getInput('limit');
|
|
|
|
if(empty($limit)){
|
2016-09-03 20:03:06 +02:00
|
|
|
$limit = self::PARAMETERS[$this->queriedContext]['limit']['defaultValue'];
|
2016-08-29 13:29:17 +02:00
|
|
|
}
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:23:18 +02:00
|
|
|
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")
|
|
|
|
->item(0)
|
|
|
|
->nodeValue;
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
$query = "(.//*[@id='listing']//tr)[position() > 1]";
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
if($limit !== -1){
|
2016-09-03 20:23:18 +02:00
|
|
|
$query =
|
|
|
|
"(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]";
|
2016-08-22 01:25:56 +02:00
|
|
|
}
|
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
$chapters = $xpath->query($query);
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-01-16 16:30:29 +01:00
|
|
|
foreach ($chapters as $chapter){
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2016-09-03 20:23:18 +02:00
|
|
|
$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);
|
2016-01-22 19:34:19 +01:00
|
|
|
array_unshift($this->items, $item);
|
2016-08-22 01:25:56 +02:00
|
|
|
}
|
2016-08-29 13:29:17 +02:00
|
|
|
break;
|
2016-01-16 16:30:29 +01:00
|
|
|
}
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
// Return some dummy-data if no content available
|
|
|
|
if(empty($this->items)){
|
|
|
|
$item = array();
|
|
|
|
$item['content'] = "<p>No updates available</p>";
|
2016-08-22 01:25:56 +02:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-08-29 13:29:17 +02:00
|
|
|
public function getURI(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'Get latest updates':
|
|
|
|
$path = "latest";
|
|
|
|
break;
|
|
|
|
case 'Get popular mangas':
|
|
|
|
$path = "popular";
|
|
|
|
if($this->getInput('category') !== "all"){
|
|
|
|
$path .= "/" . $this->getInput('category');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Get manga updates':
|
|
|
|
$path = $this->getInput('path');
|
|
|
|
break;
|
|
|
|
}
|
2016-08-30 11:23:55 +02:00
|
|
|
return self::URI . $path;
|
2016-08-29 13:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
public function getName(){
|
|
|
|
return (!empty($this->request) ? $this->request . ' - ' : '') . 'Mangareader Bridge';
|
|
|
|
}
|
2016-01-10 00:00:16 +01:00
|
|
|
|
2016-09-03 20:10:36 +02:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 10800; // 3 hours
|
|
|
|
}
|
2016-01-10 00:00:16 +01:00
|
|
|
}
|
2016-08-22 01:25:56 +02:00
|
|
|
?>
|