bridges: Fix default return values and function scopes

getURI and getName should fall back to parent::getURI or
parent::getName respectively if it cannot build propper
return values.

Functions defined by bridges should be made private to
prevent confusion with inherited functions
This commit is contained in:
logmanoriginal 2016-12-17 16:39:18 +01:00
parent 271c71d0ac
commit 95b99d42a4
6 changed files with 34 additions and 19 deletions

View file

@ -23,6 +23,8 @@ class AllocineFRBridge extends BridgeAbstract{
)); ));
public function getURI(){ public function getURI(){
if(!is_null($this->getInput('category'))){
switch($this->getInput('category')){ switch($this->getInput('category')){
case 'faux-raccord': case 'faux-raccord':
$uri = static::URI.'video/programme-12284/saison-27129/'; $uri = static::URI.'video/programme-12284/saison-27129/';
@ -38,7 +40,11 @@ class AllocineFRBridge extends BridgeAbstract{
return $uri; return $uri;
} }
return parent::getURI();
}
public function getName(){ public function getName(){
if(!is_null($this->getInput('category'))){
return self::NAME.' : ' return self::NAME.' : '
.array_search( .array_search(
$this->getInput('category'), $this->getInput('category'),
@ -46,6 +52,9 @@ class AllocineFRBridge extends BridgeAbstract{
); );
} }
return parent::getName();
}
public function collectData(){ public function collectData(){
$html = getSimpleHTMLDOM($this->getURI()) $html = getSimpleHTMLDOM($this->getURI())

View file

@ -34,7 +34,7 @@ class DailymotionBridge extends BridgeAbstract{
) )
); );
function getMetadata($id) { protected function getMetadata($id) {
$metadata=array(); $metadata=array();
$html2 = getSimpleHTMLDOM(self::URI.'video/'.$id); $html2 = getSimpleHTMLDOM(self::URI.'video/'.$id);
if(!$html2){ if(!$html2){

View file

@ -93,7 +93,7 @@ class FuturaSciencesBridge extends FeedExpander {
return $item; return $item;
} }
function StripWithDelimiters($string, $start, $end) { private function StripWithDelimiters($string, $start, $end) {
while (strpos($string, $start) !== false) { while (strpos($string, $start) !== false) {
$section_to_remove = substr($string, strpos($string, $start)); $section_to_remove = substr($string, strpos($string, $start));
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end)); $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
@ -101,7 +101,7 @@ class FuturaSciencesBridge extends FeedExpander {
} return $string; } return $string;
} }
function StripRecursiveHTMLSection($string, $tag_name, $tag_start) { private function StripRecursiveHTMLSection($string, $tag_name, $tag_start) {
$open_tag = '<'.$tag_name; $open_tag = '<'.$tag_name;
$close_tag = '</'.$tag_name.'>'; $close_tag = '</'.$tag_name.'>';
$close_tag_length = strlen($close_tag); $close_tag_length = strlen($close_tag);
@ -125,7 +125,7 @@ class FuturaSciencesBridge extends FeedExpander {
return $string; return $string;
} }
function ExtractArticleContent($article){ private function ExtractArticleContent($article){
$contents = $article->find('section[class=module article-text article-text-classic bg-white]', 0)->innertext; $contents = $article->find('section[class=module article-text article-text-classic bg-white]', 0)->innertext;
foreach (array( foreach (array(
@ -156,7 +156,7 @@ class FuturaSciencesBridge extends FeedExpander {
} }
// Extracts the author from an article or element // Extracts the author from an article or element
function ExtractAuthor($article){ private function ExtractAuthor($article){
$article_author = $article->find('span.author', 0); $article_author = $article->find('span.author', 0);
if($article_author){ if($article_author){
return trim(str_replace(', Futura-Sciences', '', $article_author->plaintext)); return trim(str_replace(', Futura-Sciences', '', $article_author->plaintext));

View file

@ -122,6 +122,8 @@ class IsoHuntBridge extends BridgeAbstract{
if($category!=='movies') if($category!=='movies')
$uri .= '&ihq=' . urlencode($this->getInput('search_name')); $uri .= '&ihq=' . urlencode($this->getInput('search_name'));
break; break;
default: parent::getURI();
} }
return $uri; return $uri;
@ -155,6 +157,8 @@ class IsoHuntBridge extends BridgeAbstract{
); );
$name = 'Search: "' . $this->getInput('search_name') . '" in category: ' . $categoryName . ' - ' . self::NAME; $name = 'Search: "' . $this->getInput('search_name') . '" in category: ' . $categoryName . ' - ' . self::NAME;
break; break;
default: return parent::getName();
} }
return $name; return $name;

View file

@ -20,13 +20,13 @@ class LeMondeInformatiqueBridge extends FeedExpander {
return $item; return $item;
} }
function StripCDATA($string) { private function StripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string); $string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string); $string = str_replace(']]>', '', $string);
return $string; return $string;
} }
function StripWithDelimiters($string, $start, $end) { private function StripWithDelimiters($string, $start, $end) {
while (strpos($string, $start) !== false) { while (strpos($string, $start) !== false) {
$section_to_remove = substr($string, strpos($string, $start)); $section_to_remove = substr($string, strpos($string, $start));
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end)); $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
@ -34,7 +34,7 @@ class LeMondeInformatiqueBridge extends FeedExpander {
} return $string; } return $string;
} }
function CleanArticle($article_html) { private function CleanArticle($article_html) {
$article_html = $this->StripWithDelimiters($article_html, '<script', '</script>'); $article_html = $this->StripWithDelimiters($article_html, '<script', '</script>');
$article_html = $this->StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>'); $article_html = $this->StripWithDelimiters($article_html, '<h1 class="cleanprint-title"', '</h1>');
return $article_html; return $article_html;

View file

@ -103,6 +103,7 @@ EOD;
case 'From search': case 'From search':
$uri = self::URI . 'search/?q=' . urlencode($this->getInput('q')); $uri = self::URI . 'search/?q=' . urlencode($this->getInput('q'));
break; break;
default: return parent::getURI();
} }
return $uri; return $uri;
} }
@ -115,6 +116,7 @@ EOD;
case 'From search': case 'From search':
$specific = $this->getInput('q'); $specific = $this->getInput('q');
break; break;
default: return parent::getName();
} }
return $specific . ' - ' . self::NAME; return $specific . ' - ' . self::NAME;
} }