From 2301a12cc62f187f5891c5c82685ac7122be61a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sat, 27 Aug 2016 20:42:05 +0200 Subject: [PATCH] [WordpPessBridge] implement getURI() and simplify code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/WordPressBridge.php | 47 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/bridges/WordPressBridge.php b/bridges/WordPressBridge.php index 370b772..db2f4a7 100644 --- a/bridges/WordPressBridge.php +++ b/bridges/WordPressBridge.php @@ -3,7 +3,6 @@ define('WORDPRESS_TYPE_ATOM', 1); // Content is of type ATOM define('WORDPRESS_TYPE_RSS', 2); // Content is of type RSS class WordPressBridge extends BridgeAbstract { - private $url; public $sitename; // Name of the site public function loadMetadatas() { @@ -21,15 +20,6 @@ class WordPressBridge extends BridgeAbstract { ); } - // Returns the content type for a given html dom - private function DetectContentType($html){ - if($html->find('entry')) - return WORDPRESS_TYPE_ATOM; - if($html->find('item')) - return WORDPRESS_TYPE_RSS; - return WORDPRESS_TYPE_ATOM; // Make ATOM default - } - // Replaces all 'link' tags with 'url' for simplehtmldom to actually find 'links' ('url') private function ReplaceLinkTagsWithUrlTags($element){ // We need to fix the 'link' tag as simplehtmldom cannot parse it (just rename it and load back as dom) @@ -54,18 +44,19 @@ class WordPressBridge extends BridgeAbstract { } public function collectData(){ - $param=$this->parameters[$this->queriedContext]; - $this->processParams($param); + $param=$this->parameters[$this->queriedContext]; - if (!$this->hasUrl()) { - $this->returnClientError('You must specify a URL'); - } - - $this->url = $this->url.'/feed/atom'; - $html = $this->getSimpleHTMLDOM($this->url) or $this->returnServerError("Could not request {$this->url}."); + $html = $this->getSimpleHTMLDOM($this->getURI().'/feed/atom') + or $this->returnServerError("Could not request ".$this->getURI().'/feed/atom'); // Notice: We requested an ATOM feed, however some sites return RSS feeds instead! - $type = $this->DetectContentType($html); + if($html->find('entry')){ + $type=WORDPRESS_TYPE_ATOM; + }else if($html->find('item')){ + $type=WORDPRESS_TYPE_RSS; + }else{ + $type=WORDPRESS_TYPE_ATOM; // Make ATOM default + } if($type === WORDPRESS_TYPE_RSS) $posts = $html->find('item'); @@ -126,10 +117,15 @@ class WordPressBridge extends BridgeAbstract { } } } else { - $this->returnServerError("Sorry, {$this->url} doesn't seem to be a Wordpress blog."); + $this->returnServerError("Sorry, ".$this->getURI()." doesn't seem to be a Wordpress blog."); } } + public function getURI(){ + $param=$this->parameters[$this->queriedContext]; + return $param['url']['value']; + } + public function getName() { return "{$this->sitename} - Wordpress Bridge"; } @@ -137,15 +133,4 @@ class WordPressBridge extends BridgeAbstract { public function getCacheDuration() { return 3600*3; // 3 hours } - - private function hasUrl() { - if (empty($this->url)) { - return false; - } - return true; - } - - private function processParams($param) { - $this->url = $param['url']['value']; - } }