forked from blallo/rss-bridge
[core] makes 'bridge' and 'format' parameters value less verbose
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 <pierre.maziere@gmx.com>
This commit is contained in:
parent
eb3392db82
commit
581bff166c
3 changed files with 16 additions and 14 deletions
|
@ -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.');
|
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';
|
$pathBridge = self::getDir() . $nameBridge . '.php';
|
||||||
|
|
||||||
if( !file_exists($pathBridge) ){
|
if( !file_exists($pathBridge) ){
|
||||||
|
@ -314,9 +315,8 @@ class Bridge{
|
||||||
$dirFiles = scandir($pathDirBridge);
|
$dirFiles = scandir($pathDirBridge);
|
||||||
|
|
||||||
if( $dirFiles !== false ){
|
if( $dirFiles !== false ){
|
||||||
|
|
||||||
foreach( $dirFiles as $fileName ) {
|
foreach( $dirFiles as $fileName ) {
|
||||||
if( preg_match('@([^.]+)\.php$@U', $fileName, $out) ){
|
if( preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out) ){
|
||||||
$listBridge[] = $out[1];
|
$listBridge[] = $out[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,10 @@ class Bridge{
|
||||||
return $listBridge;
|
return $listBridge;
|
||||||
}
|
}
|
||||||
static function isWhitelisted( $whitelist, $name ) {
|
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;
|
return TRUE;
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -122,6 +122,7 @@ class Format{
|
||||||
throw new \InvalidArgumentException('Name format must be at least one uppercase follow or not by alphabetic characters.');
|
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';
|
$pathFormat = self::getDir() . $nameFormat . '.php';
|
||||||
|
|
||||||
if( !file_exists($pathFormat) ){
|
if( !file_exists($pathFormat) ){
|
||||||
|
@ -169,7 +170,7 @@ class Format{
|
||||||
$dirFiles = scandir($pathDirFormat);
|
$dirFiles = scandir($pathDirFormat);
|
||||||
if( $dirFiles !== false ){
|
if( $dirFiles !== false ){
|
||||||
foreach( $dirFiles as $fileName ){
|
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];
|
$listFormat[] = $out[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,10 +139,8 @@ CARD;
|
||||||
|
|
||||||
private static function getHelperButtonsFormat($formats){
|
private static function getHelperButtonsFormat($formats){
|
||||||
$buttons = '';
|
$buttons = '';
|
||||||
|
foreach( $formats as $name){
|
||||||
foreach( $formats as $name => $infos ){
|
$buttons .= '<button type="submit" name="format" value="' . $name . '">' . $name . '</button>' . PHP_EOL;
|
||||||
if ( isset($infos['name']) )
|
|
||||||
$buttons .= '<button type="submit" name="format" value="' . $name . '">' . $infos['name'] . '</button>' . PHP_EOL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $buttons;
|
return $buttons;
|
||||||
|
|
Loading…
Reference in a new issue