This commit is contained in:
logmanoriginal 2016-08-23 18:28:22 +02:00
commit c94cfce511
9 changed files with 49 additions and 78 deletions

View file

@ -2,8 +2,6 @@
/** /**
* Atom * Atom
* Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287 * Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
*
* @name Atom
*/ */
class AtomFormat extends FormatAbstract{ class AtomFormat extends FormatAbstract{

View file

@ -1,10 +1,4 @@
<?php <?php
/**
* Html
* Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
*
* @name Html
*/
class HtmlFormat extends FormatAbstract{ class HtmlFormat extends FormatAbstract{
public function stringify(){ public function stringify(){

View file

@ -2,8 +2,6 @@
/** /**
* Json * Json
* Builds a JSON string from $this->items and return it to browser. * Builds a JSON string from $this->items and return it to browser.
*
* @name Json
*/ */
class JsonFormat extends FormatAbstract{ class JsonFormat extends FormatAbstract{

View file

@ -2,8 +2,6 @@
/** /**
* Mrss * Mrss
* Documentation Source http://www.rssboard.org/media-rss * Documentation Source http://www.rssboard.org/media-rss
*
* @name Media RSS
*/ */
class MrssFormat extends FormatAbstract{ class MrssFormat extends FormatAbstract{

View file

@ -2,8 +2,6 @@
/** /**
* Plaintext * Plaintext
* Returns $this->items as raw php data. * Returns $this->items as raw php data.
*
* @name Plaintext
*/ */
class PlaintextFormat extends FormatAbstract{ class PlaintextFormat extends FormatAbstract{

View file

@ -91,15 +91,25 @@ try{
Format::setDir(__DIR__ . '/formats/'); Format::setDir(__DIR__ . '/formats/');
Cache::setDir(__DIR__ . '/caches/'); Cache::setDir(__DIR__ . '/caches/');
if( isset($_REQUEST) && isset($_REQUEST['action']) ){ $action=filter_input(INPUT_GET,'action');
switch($_REQUEST['action']){ $bridge=filter_input(INPUT_GET,'bridge');
case 'display': if($action === 'display' && !empty($bridge)){
if( isset($_REQUEST['bridge']) ){ unset($_REQUEST['action']);
unset($_REQUEST['action']); unset($_REQUEST['bridge']);
$bridge = $_REQUEST['bridge']; // DEPRECATED: 'nameBridge' scheme is replaced by 'name' in bridge parameter values
unset($_REQUEST['bridge']); // this is to keep compatibility until futher complete removal
$format = $_REQUEST['format']; if(($pos=strpos($bridge,'Bridge'))===(strlen($bridge)-strlen('Bridge'))){
unset($_REQUEST['format']); $bridge=substr($bridge,0,$pos);
}
$format = filter_input(INPUT_GET,'format');
unset($_REQUEST['format']);
// DEPRECATED: 'nameFormat' scheme is replaced by 'name' in format parameter values
// this is to keep compatibility until futher complete removal
if(($pos=strpos($format,'Format'))===(strlen($format)-strlen('Format'))){
$format=substr($format,0,$pos);
}
// whitelist control // whitelist control
if(!Bridge::isWhitelisted($whitelist_selection, $bridge)) { if(!Bridge::isWhitelisted($whitelist_selection, $bridge)) {
@ -111,13 +121,12 @@ try{
// Data retrieval // Data retrieval
$bridge = Bridge::create($bridge); $bridge = Bridge::create($bridge);
if(defined("DEBUG")) { if(!defined("DEBUG")) {
} else { $bridge->setCache($cache);
$bridge->setCache($cache); // just add disable cache to your query to disable caching
} }
if(defined('PROXY_URL') && PROXY_BYBRIDGE &&
isset($_REQUEST['_noproxy']) $noproxy=filter_input(INPUT_GET,'_noproxy',FILTER_VALIDATE_BOOLEAN);
){ if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy){
$bridge->useProxy=false; $bridge->useProxy=false;
} }
$bridge->loadMetadatas(); $bridge->loadMetadatas();
@ -138,10 +147,8 @@ try{
} }
die; die;
}
break; }
}
}
} }
catch(HttpException $e){ catch(HttpException $e){
header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode())); header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
@ -173,7 +180,7 @@ $formats = Format::searchInformation();
</header> </header>
<?php <?php
$activeFoundBridgeCount = 0; $activeFoundBridgeCount = 0;
$showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1; $showInactive = filter_input(INPUT_GET,'show_inactive',FILTER_VALIDATE_BOOLEAN);
$inactiveBridges = ''; $inactiveBridges = '';
$bridgeList = Bridge::listBridges(); $bridgeList = Bridge::listBridges();
foreach($bridgeList as $bridgeName) foreach($bridgeList as $bridgeName)

View file

@ -262,10 +262,11 @@ class Bridge{
* @return Bridge object dedicated * @return Bridge object dedicated
*/ */
static public function create($nameBridge){ static public function create($nameBridge){
if( !static::isValidNameBridge($nameBridge) ){ if( !preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameBridge)){
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) ){
@ -303,10 +304,6 @@ class Bridge{
return $dirBridge; return $dirBridge;
} }
static public function isValidNameBridge($nameBridge){
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameBridge);
}
/** /**
* Lists the available bridges. * Lists the available bridges.
* @return array List of the bridges * @return array List of the bridges
@ -317,19 +314,21 @@ class Bridge{
$listBridge = array(); $listBridge = array();
$dirFiles = scandir($pathDirBridge); $dirFiles = scandir($pathDirBridge);
if( $dirFiles !== false ){ if( $dirFiles !== false ){
foreach( $dirFiles as $fileName ) {
foreach( $dirFiles as $fileName ) { if( preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out) ){
if( preg_match('@([^.]+)\.php$@U', $fileName, $out) ){ $listBridge[] = $out[1];
$listBridge[] = $out[1]; }
} }
} }
}
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;

View file

@ -118,10 +118,11 @@ class Format{
} }
static public function create($nameFormat){ static public function create($nameFormat){
if( !static::isValidNameFormat($nameFormat) ){ if( !preg_match('@^[A-Z][a-zA-Z]*$@', $nameFormat)){
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) ){
@ -155,10 +156,6 @@ class Format{
return $dirFormat; return $dirFormat;
} }
static public function isValidNameFormat($nameFormat){
return preg_match('@^[A-Z][a-zA-Z]*$@', $nameFormat);
}
/** /**
* Read format dir and catch informations about each format depending annotation * Read format dir and catch informations about each format depending annotation
* @return array Informations about each format * @return array Informations about each format
@ -172,29 +169,13 @@ 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 ?
$infos = array(); // Information about the bridge $listFormat[] = $out[1];
$resParse = token_get_all(file_get_contents($pathDirFormat . $fileName)); // Parse PHP file
foreach($resParse as $v){
if( is_array($v) && $v[0] == T_DOC_COMMENT ){ // Lexer node is COMMENT ?
$commentary = $v[1];
foreach( $searchCommonPattern as $name){ // Catch information with common pattern
preg_match('#@' . preg_quote($name, '#') . '\s+(.+)#', $commentary, $outComment);
if( isset($outComment[1]) ){
$infos[$name] = $outComment[1];
}
}
}
}
if( isset($infos['name']) ){ // If informations containt at least a name
$listFormat[$out[1]] = $infos;
}
}
} }
}
} }
return $listFormat; return $listFormat;
} }
} }

View file

@ -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;