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
* Documentation Source http://en.wikipedia.org/wiki/Atom_%28standard%29 and http://tools.ietf.org/html/rfc4287
*
* @name Atom
*/
class AtomFormat extends FormatAbstract{

View file

@ -1,10 +1,4 @@
<?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{
public function stringify(){

View file

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

View file

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

View file

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

View file

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

View file

@ -262,10 +262,11 @@ class Bridge{
* @return Bridge object dedicated
*/
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.');
}
$nameBridge=$nameBridge.'Bridge';
$pathBridge = self::getDir() . $nameBridge . '.php';
if( !file_exists($pathBridge) ){
@ -303,10 +304,6 @@ class Bridge{
return $dirBridge;
}
static public function isValidNameBridge($nameBridge){
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameBridge);
}
/**
* Lists the available bridges.
* @return array List of the bridges
@ -317,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;

View file

@ -118,10 +118,11 @@ class Format{
}
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.');
}
$nameFormat=$nameFormat.'Format';
$pathFormat = self::getDir() . $nameFormat . '.php';
if( !file_exists($pathFormat) ){
@ -155,10 +156,6 @@ class Format{
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
* @return array Informations about each format
@ -172,27 +169,11 @@ class Format{
$dirFiles = scandir($pathDirFormat);
if( $dirFiles !== false ){
foreach( $dirFiles as $fileName ){
if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ // Is PHP file ?
$infos = array(); // Information about the bridge
$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;
}
}
foreach( $dirFiles as $fileName ){
if( preg_match('@^([^.]+)Format\.php$@U', $fileName, $out) ){ // Is PHP file ?
$listFormat[] = $out[1];
}
}
}
return $listFormat;

View file

@ -139,10 +139,8 @@ CARD;
private static function getHelperButtonsFormat($formats){
$buttons = '';
foreach( $formats as $name => $infos ){
if ( isset($infos['name']) )
$buttons .= '<button type="submit" name="format" value="' . $name . '">' . $infos['name'] . '</button>' . PHP_EOL;
foreach( $formats as $name){
$buttons .= '<button type="submit" name="format" value="' . $name . '">' . $name . '</button>' . PHP_EOL;
}
return $buttons;