Merge branch 'MangareaderBridge' of https://github.com/logmanoriginal/rss-bridge
This commit is contained in:
commit
c365f35e47
1 changed files with 189 additions and 151 deletions
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
define('MANGAREADER_LIMIT', 10); // The default limit
|
||||
class MangareaderBridge extends BridgeAbstract {
|
||||
|
||||
const MAINTAINER = "logmanoriginal";
|
||||
|
@ -69,7 +68,7 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
'limit' => array(
|
||||
'name' => 'Limit',
|
||||
'type' => 'number',
|
||||
'exampleValue'=>10,
|
||||
'defaultValue' => 10,
|
||||
'title' => 'Number of items to return [-1 returns all]'
|
||||
)
|
||||
)
|
||||
|
@ -95,7 +94,38 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
switch($this->queriedContext){
|
||||
case 'Get latest updates':
|
||||
$this->request = 'Latest updates';
|
||||
$this->get_latest_updates($xpath);
|
||||
break;
|
||||
case 'Get popular mangas':
|
||||
// Find manga name within "Popular mangas for ..."
|
||||
$pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
|
||||
$this->request = substr($pagetitle, 0, strrpos($pagetitle, " -"));
|
||||
$this->get_popular_mangas($xpath);
|
||||
break;
|
||||
case 'Get manga updates':
|
||||
$limit = $this->getInput('limit');
|
||||
if(empty($limit)){
|
||||
$limit = self::PARAMETERS[$this->queriedContext]['limit']['defaultValue'];
|
||||
}
|
||||
|
||||
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")
|
||||
->item(0)
|
||||
->nodeValue;
|
||||
|
||||
$this->get_manga_updates($xpath, $limit);
|
||||
break;
|
||||
}
|
||||
|
||||
// Return some dummy-data if no content available
|
||||
if(empty($this->items)){
|
||||
$item = array();
|
||||
$item['content'] = "<p>No updates available</p>";
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_latest_updates($xpath){
|
||||
// Query each item (consists of Manga + chapters)
|
||||
$nodes = $xpath->query("//*[@id='latestchapters']/table//td");
|
||||
|
||||
|
@ -118,18 +148,21 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
if($item['content'] <> ""){
|
||||
$item['content'] .= "<br>";
|
||||
}
|
||||
$item['content'] .= "<a href='" .self::URI. htmlspecialchars($chapter->getAttribute('href')) . "'>" . htmlspecialchars($chapter->nodeValue) . "</a>";
|
||||
$item['content'] .=
|
||||
"<a href='"
|
||||
. self::URI
|
||||
. htmlspecialchars($chapter->getAttribute('href'))
|
||||
. "'>"
|
||||
. htmlspecialchars($chapter->nodeValue)
|
||||
. "</a>";
|
||||
}
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Get popular mangas':
|
||||
$pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
|
||||
$this->request = substr($pagetitle, 0, strrpos($pagetitle, " -")); // "Popular mangas for ..."
|
||||
}
|
||||
|
||||
private function get_popular_mangas($xpath){
|
||||
// Query all mangas
|
||||
$mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']");
|
||||
|
||||
|
@ -137,53 +170,58 @@ class MangareaderBridge extends BridgeAbstract{
|
|||
|
||||
// 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');
|
||||
$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'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnail . '" alt="' . $item['title'] . '" /></a><p>' . $item['genre'] . '</p><p>' . $item['chaptercount'] . '</p>';
|
||||
$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;
|
||||
$this->items[] = $item;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Get manga updates':
|
||||
$limit = $this->getInput('limit');
|
||||
if(empty($limit)){
|
||||
$limit = MANGAREADER_LIMIT;
|
||||
}
|
||||
|
||||
$this->request = $xpath->query(".//*[@id='mangaproperties']//*[@class='aname']")->item(0)->nodeValue;
|
||||
|
||||
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 . "]";
|
||||
$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;
|
||||
}
|
||||
|
||||
// Return some dummy-data if no content available
|
||||
if(empty($this->items)){
|
||||
$item = array();
|
||||
$item['content'] = "<p>No updates available</p>";
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
|
|
Loading…
Reference in a new issue