[LWNprevBridge] code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 12:28:27 +02:00
parent 453cacf490
commit 953faabb1a

View file

@ -2,9 +2,13 @@
class LWNprevBridge extends BridgeAbstract{ class LWNprevBridge extends BridgeAbstract{
public $maintainer = 'Pierre Mazière'; public $maintainer = 'Pierre Mazière';
public $name = 'LWN Free Weekly Edition'; public $name = 'LWN Free Weekly Edition';
public $uri = 'https://lwn.net/free/bigpage'; public $uri = 'https://lwn.net/';
public $description = 'LWN Free Weekly Edition available one week late'; public $description = 'LWN Free Weekly Edition available one week late';
function getURI(){
return $this->uri.'free/bigpage';
}
private function jumpToNextTag(&$node){ private function jumpToNextTag(&$node){
while($node && $node->nodeType===XML_TEXT_NODE){ while($node && $node->nodeType===XML_TEXT_NODE){
$nextNode=$node->nextSibling; $nextNode=$node->nextSibling;
@ -28,20 +32,7 @@ class LWNprevBridge extends BridgeAbstract{
public function collectData(){ public function collectData(){
// Because the LWN page is written in loose HTML and not XHTML, // Because the LWN page is written in loose HTML and not XHTML,
// Simple HTML Dom is not accurate enough for the job // Simple HTML Dom is not accurate enough for the job
$content=$this->getContents($this->getURI())
$uri='https://lwn.net/free/bigpage';
$context=null;
if(defined('PROXY_URL')) {
$context = array(
'http' => array(
'proxy' => PROXY_URL,
'request_fulluri' => true,
),
);
$context = stream_context_create($context);
}
$content=file_get_contents($uri, false, $context)
or $this->returnServerError('No results for LWNprev'); or $this->returnServerError('No results for LWNprev');
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
@ -52,13 +43,12 @@ class LWNprevBridge extends BridgeAbstract{
$cat1=''; $cat1='';
$cat2=''; $cat2='';
$realURI='https://lwn.net';
foreach($html->getElementsByTagName('a') as $a){ foreach($html->getElementsByTagName('a') as $a){
if($a->textContent==='Multi-page format'){ if($a->textContent==='Multi-page format'){
break; break;
} }
} }
$realURI.=$a->getAttribute('href'); $realURI=$this->uri.$a->getAttribute('href');
$URICounter=0; $URICounter=0;
$edition=$html->getElementsByTagName('h1')->item(0)->textContent; $edition=$html->getElementsByTagName('h1')->item(0)->textContent;
@ -92,7 +82,7 @@ class LWNprevBridge extends BridgeAbstract{
$h2FirstChild=$h2->firstChild; $h2FirstChild=$h2->firstChild;
$this->jumpToNextTag($h2FirstChild); $this->jumpToNextTag($h2FirstChild);
if($h2FirstChild->nodeName==='a'){ if($h2FirstChild->nodeName==='a'){
$item['uri']='https://lwn.net'.$h2FirstChild->getAttribute('href'); $item['uri']=$this->uri.$h2FirstChild->getAttribute('href');
}else{ }else{
$item['uri']=$realURI.'#'.$URICounter; $item['uri']=$realURI.'#'.$URICounter;
} }