From 581bff166ca50c52ded7bf2b1a21ed109a20edb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Tue, 23 Aug 2016 14:34:07 +0200 Subject: [PATCH] [core] makes 'bridge' and 'format' parameters value less verbose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove the requirement for 'Format' and 'Bridge' suffixes: https://example.com/?action=display&bridge=Twitter&format=Atom&u=user Signed-off-by: Pierre Mazière --- lib/Bridge.php | 21 ++++++++++++--------- lib/Format.php | 3 ++- lib/HTMLUtils.php | 6 ++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 688c502..05fe77e 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -266,6 +266,7 @@ class Bridge{ throw new \InvalidArgumentException('Name bridge must be at least one uppercase follow or not by alphanumeric or dash characters.'); } + $nameBridge=$nameBridge.'Bridge'; $pathBridge = self::getDir() . $nameBridge . '.php'; if( !file_exists($pathBridge) ){ @@ -313,19 +314,21 @@ class Bridge{ $listBridge = array(); $dirFiles = scandir($pathDirBridge); - if( $dirFiles !== false ){ - - foreach( $dirFiles as $fileName ) { - if( preg_match('@([^.]+)\.php$@U', $fileName, $out) ){ - $listBridge[] = $out[1]; - } - } - } + if( $dirFiles !== false ){ + foreach( $dirFiles as $fileName ) { + if( preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out) ){ + $listBridge[] = $out[1]; + } + } + } return $listBridge; } static function isWhitelisted( $whitelist, $name ) { - if(in_array("$name", $whitelist) or in_array("$name.php", $whitelist) or count($whitelist) === 1 and trim($whitelist[0]) === '*') + if(in_array($name, $whitelist) or in_array($name.'.php', $whitelist) or + // DEPRECATED: the nameBridge notation will be removed in future releases + in_array($name.'Bridge', $whitelist) or in_array($name.'Bridge.php', $whitelist) or + count($whitelist) === 1 and trim($whitelist[0]) === '*') return TRUE; else return FALSE; diff --git a/lib/Format.php b/lib/Format.php index f3b053b..486ae84 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -122,6 +122,7 @@ class Format{ throw new \InvalidArgumentException('Name format must be at least one uppercase follow or not by alphabetic characters.'); } + $nameFormat=$nameFormat.'Format'; $pathFormat = self::getDir() . $nameFormat . '.php'; if( !file_exists($pathFormat) ){ @@ -169,7 +170,7 @@ class Format{ $dirFiles = scandir($pathDirFormat); if( $dirFiles !== false ){ foreach( $dirFiles as $fileName ){ - if( preg_match('@^([^.]+)\.php$@U', $fileName, $out) ){ // Is PHP file ? + if( preg_match('@^([^.]+)Format\.php$@U', $fileName, $out) ){ // Is PHP file ? $listFormat[] = $out[1]; } } diff --git a/lib/HTMLUtils.php b/lib/HTMLUtils.php index 330ce6f..9384753 100644 --- a/lib/HTMLUtils.php +++ b/lib/HTMLUtils.php @@ -139,10 +139,8 @@ CARD; private static function getHelperButtonsFormat($formats){ $buttons = ''; - - foreach( $formats as $name => $infos ){ - if ( isset($infos['name']) ) - $buttons .= '' . PHP_EOL; + foreach( $formats as $name){ + $buttons .= '' . PHP_EOL; } return $buttons;