From f694023f7da19e4d4555733e8738111be2068fab Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 17 Dec 2016 17:03:09 +0100 Subject: [PATCH 1/4] bridges: Return default values for getName and getURI --- bridges/AnimeUltimeBridge.php | 14 +++++++++----- bridges/DailymotionBridge.php | 1 + bridges/GBAtempBridge.php | 14 +++++++++----- bridges/MangareaderBridge.php | 1 + 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/bridges/AnimeUltimeBridge.php b/bridges/AnimeUltimeBridge.php index ef87499f..aea376bd 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -108,12 +108,16 @@ class AnimeUltimeBridge extends BridgeAbstract { } public function getName() { - $typeFilter = array_search( - $this->getInput('type'), - self::PARAMETERS[$this->queriedContext]['type']['values'] - ); + if(!is_null($this->getInput('type'))){ + $typeFilter = array_search( + $this->getInput('type'), + self::PARAMETERS[$this->queriedContext]['type']['values'] + ); - return 'Latest '.$typeFilter.' - Anime-Ultime Bridge'; + return 'Latest '.$typeFilter.' - Anime-Ultime Bridge'; + } + + return parent::getName(); } } diff --git a/bridges/DailymotionBridge.php b/bridges/DailymotionBridge.php index 9547babb..3cb882fd 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -85,6 +85,7 @@ class DailymotionBridge extends BridgeAbstract{ case 'From search results': $specific=$this->getInput('s'); break; + default: return parent::getName(); } return $specific.' : Dailymotion Bridge'; diff --git a/bridges/GBAtempBridge.php b/bridges/GBAtempBridge.php index a171affc..cf0c8e0c 100644 --- a/bridges/GBAtempBridge.php +++ b/bridges/GBAtempBridge.php @@ -115,10 +115,14 @@ class GBAtempBridge extends BridgeAbstract { } public function getName() { - $type=array_search( - $this->getInput('type'), - self::PARAMETERS[$this->queriedContext]['type']['values'] - ); - return 'GBAtemp '.$type.' Bridge'; + if(!is_null($this->getInput('type'))){ + $type=array_search( + $this->getInput('type'), + self::PARAMETERS[$this->queriedContext]['type']['values'] + ); + return 'GBAtemp '.$type.' Bridge'; + } + + return parent::getName(); } } diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index 949e7a48..1a408e30 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -239,6 +239,7 @@ EOD; case 'Get manga updates': $path = $this->getInput('path'); break; + default: return parent::getURI(); } return self::URI . $path; } From 83b5bbcc3794cb2a9323f8ba58be113b363ca28d Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 17 Dec 2016 17:11:58 +0100 Subject: [PATCH 2/4] [Kununu] Use tabs for indentation --- bridges/KununuBridge.php | 106 +++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/bridges/KununuBridge.php b/bridges/KununuBridge.php index 11ebd32c..dec567b8 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -6,66 +6,66 @@ class KununuBridge extends BridgeAbstract { const CACHE_TIMEOUT = 86400; // 24h const DESCRIPTION = "Returns the latest reviews for a company and site of your choice."; - const PARAMETERS = array( - 'global' => array( - 'site'=>array( - 'name'=>'Site', - 'type'=>'list', - 'required'=>true, - 'title'=>'Select your site', - 'values'=>array( - 'Austria'=>'at', - 'Germany'=>'de', - 'Switzerland'=>'ch', - 'United States'=>'us' - ) - ), - 'full'=>array( - 'name'=>'Load full article', - 'type'=>'checkbox', - 'required'=>false, - 'exampleValue'=>'checked', - 'title'=>'Activate to load full article' - ) - ), + const PARAMETERS = array( + 'global' => array( + 'site'=>array( + 'name'=>'Site', + 'type'=>'list', + 'required'=>true, + 'title'=>'Select your site', + 'values'=>array( + 'Austria'=>'at', + 'Germany'=>'de', + 'Switzerland'=>'ch', + 'United States'=>'us' + ) + ), + 'full'=>array( + 'name'=>'Load full article', + 'type'=>'checkbox', + 'required'=>false, + 'exampleValue'=>'checked', + 'title'=>'Activate to load full article' + ) + ), - array( - 'company'=>array( - 'name'=>'Company', - 'required'=>true, - 'exampleValue'=>'kununu-us', - 'title'=>'Insert company name (i.e. Kununu US) or URI path (i.e. kununu-us)' - ) - ) - ); + array( + 'company'=>array( + 'name'=>'Company', + 'required'=>true, + 'exampleValue'=>'kununu-us', + 'title'=>'Insert company name (i.e. Kununu US) or URI path (i.e. kununu-us)' + ) + ) + ); - private $companyName=''; + private $companyName=''; - public function getURI(){ - $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); - $site=$this->getInput('site'); - $section = ''; - switch($site){ - case 'at': - case 'de': - case 'ch': - $section = 'kommentare'; - break; - case 'us': - $section = 'reviews'; - break; - } + public function getURI(){ + $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); + $site=$this->getInput('site'); + $section = ''; + switch($site){ + case 'at': + case 'de': + case 'ch': + $section = 'kommentare'; + break; + case 'us': + $section = 'reviews'; + break; + } - return self::URI.$site.'/'.$company.'/'.$section; - } + return self::URI.$site.'/'.$company.'/'.$section; + } - function getName(){ - $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); - return ($this->companyName?:$company).' - '.self::NAME; - } + function getName(){ + $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); + return ($this->companyName?:$company).' - '.self::NAME; + } public function collectData(){ - $full = $this->getInput('full'); + $full = $this->getInput('full'); // Load page $html = getSimpleHTMLDOM($this->getURI()); From 5ad3198d71dc4923d8637c19570da08a57a65e02 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 17 Dec 2016 17:21:29 +0100 Subject: [PATCH 3/4] [Kununu] Fix content check condition Check if null instead of false according to: http://simplehtmldom.sourceforge.net/manual.htm#section_find --- bridges/KununuBridge.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bridges/KununuBridge.php b/bridges/KununuBridge.php index dec567b8..4384fadf 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -124,11 +124,11 @@ class KununuBridge extends BridgeAbstract { */ private function extract_company_name($html){ $panel = $html->find('div.panel', 0); - if($panel === false) + if(is_null($panel)) returnServerError('Cannot find panel for company name!'); $company_name = $panel->find('h1', 0); - if($company_name === false) + if(is_null($company_name)) returnServerError('Cannot find company name!'); return $company_name->plaintext; @@ -140,7 +140,7 @@ class KununuBridge extends BridgeAbstract { private function extract_article_date($article){ // They conviniently provide a time attribute for us :) $date = $article->find('time[itemprop=dtreviewed]', 0); - if($date === false) + if(is_null($date)) returnServerError('Cannot find article date!'); return strtotime($date->datetime); @@ -151,7 +151,7 @@ class KununuBridge extends BridgeAbstract { */ private function extract_article_rating($article){ $rating = $article->find('span.rating', 0); - if($rating === false) + if(is_null($rating)) returnServerError('Cannot find article rating!'); return $rating->getAttribute('aria-label'); @@ -162,7 +162,7 @@ class KununuBridge extends BridgeAbstract { */ private function extract_article_summary($article){ $summary = $article->find('[itemprop=summary]', 0); - if($summary === false) + if(is_null($summary)) returnServerError('Cannot find article summary!'); return strip_tags($summary->innertext); @@ -174,11 +174,11 @@ class KununuBridge extends BridgeAbstract { private function extract_article_uri($article){ // Notice: This first part is the same as in extract_article_summary! $summary = $article->find('[itemprop=summary]', 0); - if($summary === false) + if(is_null($summary)) returnServerError('Cannot find article summary!'); $anchor = $summary->find('a', 0); - if($anchor === false) + if(is_null($anchor)) returnServerError('Cannot find article URI!'); return self::URI . $anchor->href; @@ -190,7 +190,7 @@ class KununuBridge extends BridgeAbstract { private function extract_article_author_position($article){ // We need to parse the aside manually $aside = $article->find('aside', 0); - if($aside === false) + if(is_null($aside)) returnServerError('Cannot find article author information!'); // Go through all h2 elements to find index of required span (I know... it's stupid) @@ -210,7 +210,7 @@ class KununuBridge extends BridgeAbstract { */ private function extract_article_description($article){ $description = $article->find('div[itemprop=description]', 0); - if($description === false) + if(is_null($description)) returnServerError('Cannot find article description!'); return $this->fix_url($description->innertext); @@ -227,7 +227,7 @@ class KununuBridge extends BridgeAbstract { // Find the article $article = $html->find('article', 0); - if($article === false) + if(is_null($article)) returnServerError('Cannot find article!'); // Luckily they use the same layout for the review overview and full article pages :) From d0c9397613d0830c28d0914de3bba92db2bee760 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 17 Dec 2016 18:04:21 +0100 Subject: [PATCH 4/4] [Kununu] Fix source layout changed --- bridges/KununuBridge.php | 91 ++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/bridges/KununuBridge.php b/bridges/KununuBridge.php index 4384fadf..9e00148e 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -39,36 +39,46 @@ class KununuBridge extends BridgeAbstract { ) ); - private $companyName=''; + private $companyName = ''; public function getURI(){ - $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); - $site=$this->getInput('site'); - $section = ''; - switch($site){ - case 'at': - case 'de': - case 'ch': - $section = 'kommentare'; - break; - case 'us': - $section = 'reviews'; - break; + if(!is_null($this->getInput('company')) && !is_null($this->getInput('site'))){ + + $company = $this->fix_company_name($this->getInput('company')); + $site = $this->getInput('site'); + $section = ''; + + switch($site){ + case 'at': + case 'de': + case 'ch': + $section = 'kommentare'; + break; + case 'us': + $section = 'reviews'; + break; + } + + return self::URI . $site . '/' . $company . '/' . $section; } - return self::URI.$site.'/'.$company.'/'.$section; + return parent::getURI(); } function getName(){ - $company = $this->encode_umlauts(strtolower(str_replace(' ', '-', trim($this->getInput('company'))))); - return ($this->companyName?:$company).' - '.self::NAME; + if(!is_null($this->getInput('company'))){ + $company = $this->fix_company_name($this->getInput('company')); + return ($this->companyName?:$company).' - '.self::NAME; + } + + return paren::getName(); } public function collectData(){ $full = $this->getInput('full'); // Load page - $html = getSimpleHTMLDOM($this->getURI()); + $html = getSimpleHTMLDOMCached($this->getURI()); if(!$html) returnServerError('Unable to receive data from ' . $this->getURI() . '!'); // Update name for this request @@ -109,6 +119,16 @@ class KununuBridge extends BridgeAbstract { return preg_replace('/href=(\'|\")\//i', 'href="'.self::URI, $text); } + /* + * Returns a fixed version of the provided company name + */ + private function fix_company_name($company){ + $company = trim($company); + $company = str_replace(' ', '-', $company); + $company = strtolower($company); + return $this->encode_umlauts($company); + } + /** * Encodes unmlauts in the given text */ @@ -123,11 +143,7 @@ class KununuBridge extends BridgeAbstract { * Returns the company name from the review html */ private function extract_company_name($html){ - $panel = $html->find('div.panel', 0); - if(is_null($panel)) - returnServerError('Cannot find panel for company name!'); - - $company_name = $panel->find('h1', 0); + $company_name = $html->find('h1[itemprop=name]', 0); if(is_null($company_name)) returnServerError('Cannot find company name!'); @@ -139,11 +155,11 @@ class KununuBridge extends BridgeAbstract { */ private function extract_article_date($article){ // They conviniently provide a time attribute for us :) - $date = $article->find('time[itemprop=dtreviewed]', 0); + $date = $article->find('meta[itemprop=dateCreated]', 0); if(is_null($date)) returnServerError('Cannot find article date!'); - return strtotime($date->datetime); + return strtotime($date->content); } /** @@ -161,7 +177,7 @@ class KununuBridge extends BridgeAbstract { * Returns the summary from a given article */ private function extract_article_summary($article){ - $summary = $article->find('[itemprop=summary]', 0); + $summary = $article->find('[itemprop=name]', 0); if(is_null($summary)) returnServerError('Cannot find article summary!'); @@ -172,32 +188,27 @@ class KununuBridge extends BridgeAbstract { * Returns the URI from a given article */ private function extract_article_uri($article){ - // Notice: This first part is the same as in extract_article_summary! - $summary = $article->find('[itemprop=summary]', 0); - if(is_null($summary)) - returnServerError('Cannot find article summary!'); - - $anchor = $summary->find('a', 0); + $anchor = $article->find('ku-company-review-more', 0); if(is_null($anchor)) returnServerError('Cannot find article URI!'); - return self::URI . $anchor->href; + return self::URI . $anchor->{'review-url'}; } /** * Returns the position of the author from a given article */ private function extract_article_author_position($article){ - // We need to parse the aside manually - $aside = $article->find('aside', 0); - if(is_null($aside)) - returnServerError('Cannot find article author information!'); + // We need to parse the user-content manually + $user_content = $article->find('div.user-content', 0); + if(is_null($user_content)) + returnServerError('Cannot find user content!'); // Go through all h2 elements to find index of required span (I know... it's stupid) $author_position = 'Unknown'; - foreach($aside->find('h2') as $subject){ - if(stristr(strtolower($subject->plaintext), 'position')){ /* This works for at, ch, de, us */ - $author_position = $subject->next_sibling()->plaintext; + foreach($user_content->find('div') as $content){ + if(stristr(strtolower($content->plaintext), 'position')){ /* This works for at, ch, de, us */ + $author_position = $content->next_sibling()->plaintext; break; } } @@ -209,7 +220,7 @@ class KununuBridge extends BridgeAbstract { * Returns the description from a given article */ private function extract_article_description($article){ - $description = $article->find('div[itemprop=description]', 0); + $description = $article->find('[itemprop=reviewBody]', 0); if(is_null($description)) returnServerError('Cannot find article description!');