From fa359e2c728135c81f69579f2634824220c00443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Badet=20Aur=C3=A9lien?= Date: Fri, 18 Nov 2016 23:52:16 +0100 Subject: [PATCH 1/3] Check for Bridge's const FORMATS restrictions before adding helperbuttons --- lib/html.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/html.php b/lib/html.php index e329102d..c58228cb 100644 --- a/lib/html.php +++ b/lib/html.php @@ -1,15 +1,29 @@ 0)){ + $bridgeFormats = $bridgeClass::FORMATS;} + else {$bridgeFormats = $formats}; + $getHelperButtonsFormat = function($formats){ $buttons = ''; foreach($formats as $name){ + if(in_array($name , $bridgeFormats){ $buttons .= '' . PHP_EOL; + } } return $buttons; @@ -23,12 +37,6 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){ EOD; }; - $bridgeElement = Bridge::create($bridgeName); - $bridgeClass = $bridgeName . 'Bridge'; - - if($bridgeElement == false) - return ""; - $name = '' . $bridgeClass::NAME . ''; $description = $bridgeClass::DESCRIPTION; From 35c9ff85a32a231d6c47d74bcc3c3581a4797319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Badet=20Aur=C3=A9lien?= Date: Sat, 19 Nov 2016 00:02:37 +0100 Subject: [PATCH 2/3] add const FORMATS = array() Add a constant FORMATS as a list of compatibles formats. If the list is set null, all formats are compatibles. --- lib/BridgeAbstract.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 9629ee3d..cf8b962a 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -8,6 +8,7 @@ abstract class BridgeAbstract implements BridgeInterface { const MAINTAINER = 'No maintainer'; const CACHE_TIMEOUT = 3600; const PARAMETERS = array(); + const FORMATS = array(); // array of compatibles formats or null protected $cache; protected $items = array(); From 056f2e220ddbddb9279df0f42738e6d12f347f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Badet=20Aur=C3=A9lien?= Date: Sat, 19 Nov 2016 00:35:37 +0100 Subject: [PATCH 3/3] additional check on Bridge's compatibles FORMATS list before showing helperbuttons If there is errors in compatibles formats list, the malformed formats are skipped. If there is no compatible format, we use le list of available formats instead. --- lib/html.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/html.php b/lib/html.php index c58228cb..55591259 100644 --- a/lib/html.php +++ b/lib/html.php @@ -9,23 +9,29 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){ // If we have a defined array of compatibles formats : show only helperbuttons for thoses formats. // If we dont have any defined array of compatibles formats : show helperbuttons for every availables formats. + $compatiblesFormats = array(); if (defined($bridgeClass::FORMATS)&&(count($bridgeClass::FORMATS) > 0)){ - $bridgeFormats = $bridgeClass::FORMATS;} - else {$bridgeFormats = $formats}; + $bridgeFormats = $bridgeClass::FORMATS; + //check if format exists + foreach($bridgeFormats as $name){ + if(in_array($name , $formats){ + $compatiblesFormats[] = $name ; + } + } + } + // if no compatible format, nevermind + if (count($compatibles)==0){$compatiblesFormats = $formats}; - $getHelperButtonsFormat = function($formats){ + $getHelperButtonsFormat = function($compatiblesFormats){ $buttons = ''; - foreach($formats as $name){ - if(in_array($name , $bridgeFormats){ + foreach($compatiblesFormats as $name){ $buttons .= '' - . PHP_EOL; - } + . PHP_EOL; } - return $buttons; };