From 064ba456e83dcd58b86fb7498aa07ca0497c1dd5 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Tue, 29 May 2018 12:32:18 +0200 Subject: [PATCH] [InstagramBridge] Fix broken compatibility for media_type parameter The media_type parameter was recently replaced by media_type_u (for user mode) and media_type_h (for hashtag mode). This was necessary in order to add the media type 'story' only for the user mode. "The reason for that is that RSS-Bridge supports multiple parameters with the same name if and only if they contain the exact same value. Here, hashtags don't have stories, so it would not be possible to pass "story" as a parameter. This is a design mistake that I made when I added support for hashtags." -- https://github.com/RSS-Bridge/rss-bridge/commit/8770c87389ffde62551e4a1a8923ded1c95b077a?diff=split#r28871502 However as pointed out this change breaks existing feeds as the parameter name is no longer compatible to previous implementations. This commit changes the implementation to provide the old media_type parameter globally and check for invalid options on each request. If a user uses the 'story' option in history mode the bridge returns a client error. references 8770c87 references #694 fixes #696 fixes #699 fixes #701 --- bridges/InstagramBridge.php | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index b0b1d17..c763128 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -11,8 +11,16 @@ class InstagramBridge extends BridgeAbstract { 'u' => array( 'name' => 'username', 'required' => true - ), - 'media_type_u' => array( + ) + ), + array( + 'h' => array( + 'name' => 'hashtag', + 'required' => true + ) + ), + 'global' => array( + 'media_type' => array( 'name' => 'Media type', 'type' => 'list', 'required' => false, @@ -24,28 +32,16 @@ class InstagramBridge extends BridgeAbstract { ), 'defaultValue' => 'all' ) - ), - array( - 'h' => array( - 'name' => 'hashtag', - 'required' => true - ), - 'media_type_h' => array( - 'name' => 'Media type', - 'type' => 'list', - 'required' => false, - 'values' => array( - 'Both' => 'all', - 'Video' => 'video', - 'Picture' => 'picture' - ), - 'defaultValue' => 'all' - ) ) + ); public function collectData(){ + if(!is_null($this->getInput('h')) && $this->getInput('media_type') == 'story') { + returnClientError('Stories are not supported for hashtags!'); + } + $data = $this->getInstagramJSON($this->getURI()); if(!is_null($this->getInput('u'))) { @@ -58,7 +54,7 @@ class InstagramBridge extends BridgeAbstract { $media = $media->node; if(!is_null($this->getInput('u'))) { - switch($this->getInput('media_type_u')) { + switch($this->getInput('media_type')) { case 'all': break; case 'video': if($media->__typename != 'GraphVideo') continue 2; @@ -72,7 +68,7 @@ class InstagramBridge extends BridgeAbstract { default: break; } } else { - if($this->getInput('media_type_h') == 'video' && !$media->is_video) continue; + if($this->getInput('media_type') == 'video' && !$media->is_video) continue; } $item = array();