1
0
Fork 0
forked from blallo/rss-bridge

[Mangareader] Add functions to collect data

This commit is contained in:
logmanoriginal 2016-09-03 20:35:49 +02:00
parent f9a8f16685
commit 99f00e57b5

View file

@ -94,7 +94,38 @@ class MangareaderBridge extends BridgeAbstract {
switch($this->queriedContext){ switch($this->queriedContext){
case 'Get latest updates': case 'Get latest updates':
$this->request = '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) // Query each item (consists of Manga + chapters)
$nodes = $xpath->query("//*[@id='latestchapters']/table//td"); $nodes = $xpath->query("//*[@id='latestchapters']/table//td");
@ -129,14 +160,9 @@ class MangareaderBridge extends BridgeAbstract {
$this->items[] = $item; $this->items[] = $item;
} }
} }
break; }
case 'Get popular mangas':
$pagetitle = $xpath->query(".//*[@id='bodyalt']/h1")->item(0)->nodeValue;
// Find manga name within "Popular mangas for ..."
$this->request = substr($pagetitle, 0, strrpos($pagetitle, " -"));
private function get_popular_mangas($xpath){
// Query all mangas // Query all mangas
$mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']"); $mangas = $xpath->query("//*[@id='mangaresults']/*[@class='mangaresultitem']");
@ -172,23 +198,13 @@ class MangareaderBridge extends BridgeAbstract {
EOD; EOD;
$this->items[] = $item; $this->items[] = $item;
} }
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']") private function get_manga_updates($xpath, $limit){
->item(0)
->nodeValue;
$query = "(.//*[@id='listing']//tr)[position() > 1]"; $query = "(.//*[@id='listing']//tr)[position() > 1]";
if($limit !== -1){ if($limit !== -1){
$query = $query = "(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]";
"(.//*[@id='listing']//tr)[position() > 1][position() > last() - {$limit}]";
} }
$chapters = $xpath->query($query); $chapters = $xpath->query($query);
@ -206,16 +222,6 @@ EOD;
->nodeValue); ->nodeValue);
array_unshift($this->items, $item); 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(){ public function getURI(){