forked from blallo/rss-bridge
[core] transform some BridgeAbstract members to class constants
This concerns $uri, $name, $maintainer, $parameters and $description Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
c642fca0d0
commit
556b8a2452
2 changed files with 51 additions and 36 deletions
|
@ -114,12 +114,12 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $items = array();
|
protected $items = array();
|
||||||
|
|
||||||
public $name = 'Unnamed bridge';
|
const NAME = 'Unnamed bridge';
|
||||||
public $uri = '';
|
const URI = '';
|
||||||
public $description = 'No description provided';
|
const DESCRIPTION = 'No description provided';
|
||||||
public $maintainer = 'No maintainer';
|
const MAINTAINER = 'No maintainer';
|
||||||
|
const PARAMETERS = array();
|
||||||
public $useProxy = true;
|
public $useProxy = true;
|
||||||
public $parameters = array();
|
|
||||||
public $inputs = array();
|
public $inputs = array();
|
||||||
protected $queriedContext='';
|
protected $queriedContext='';
|
||||||
|
|
||||||
|
@ -199,28 +199,28 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
if(!is_array($data))
|
if(!is_array($data))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
foreach($data as $name => $value){
|
$validated=true;
|
||||||
$registered = false;
|
foreach($data as $name=>$value){
|
||||||
foreach($this->parameters as $context => $set){
|
$registered=false;
|
||||||
if(array_key_exists($name, $set)){
|
foreach(static::PARAMETERS as $context=>$set){
|
||||||
$registered = true;
|
if(array_key_exists($name,$set)){
|
||||||
|
$registered=true;
|
||||||
if(!isset($set[$name]['type'])){ // Default to 'text'
|
if(!isset($set[$name]['type'])){
|
||||||
$set[$name]['type'] = 'text';
|
$set[$name]['type']='text';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($set[$name]['type']){
|
switch($set[$name]['type']){
|
||||||
case 'number':
|
case 'number':
|
||||||
$data[$name] = $this->isValidNumberValue($value);
|
$data[$name] = $this->isValidNumberValue($value);
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
$data[$name] = $this->isValidCheckboxValue($value);
|
$data[$name] = $this->isValidCheckboxValue($value);
|
||||||
break;
|
break;
|
||||||
case 'list':
|
case 'list':
|
||||||
$data[$name] = $this->isValidListValue($value, $set[$name]['values']);
|
$data[$name] = $this->isValidListValue($value, $set[$name]['values']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 'text':
|
case 'text':
|
||||||
if(isset($set[$name]['pattern'])){
|
if(isset($set[$name]['pattern'])){
|
||||||
$data[$name] = $this->isValidTextValue($value, $set[$name]['pattern']);
|
$data[$name] = $this->isValidTextValue($value, $set[$name]['pattern']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,7 +245,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
|
|
||||||
protected function getQueriedContext(){
|
protected function getQueriedContext(){
|
||||||
$queriedContexts=array();
|
$queriedContexts=array();
|
||||||
foreach($this->parameters as $context=>$set){
|
foreach(static::PARAMETERS as $context=>$set){
|
||||||
$queriedContexts[$context]=null;
|
$queriedContexts[$context]=null;
|
||||||
foreach($set as $id=>$properties){
|
foreach($set as $id=>$properties){
|
||||||
if(isset($properties['value']) &&
|
if(isset($properties['value']) &&
|
||||||
|
@ -259,7 +259,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($this->parameters['global']) &&
|
if(array_key_exists('global',static::PARAMETERS) &&
|
||||||
$queriedContexts['global']===false){
|
$queriedContexts['global']===false){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($this->parameters)){
|
if(empty(static::PARAMETERS)){
|
||||||
if(!empty($inputs)){
|
if(!empty($inputs)){
|
||||||
$this->returnClientError('Invalid parameters value(s)');
|
$this->returnClientError('Invalid parameters value(s)');
|
||||||
}
|
}
|
||||||
|
@ -311,8 +311,8 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
|
|
||||||
// Populate BridgeAbstract::parameters with sanitized data
|
// Populate BridgeAbstract::parameters with sanitized data
|
||||||
foreach($inputs as $name=>$value){
|
foreach($inputs as $name=>$value){
|
||||||
foreach($this->parameters as $context=>$set){
|
foreach(static::PARAMETERS as $context=>$set){
|
||||||
if(isset($this->parameters[$context][$name])){
|
if(array_key_exists($name,static::PARAMETERS[$context])){
|
||||||
$this->inputs[$context][$name]['value']=$value;
|
$this->inputs[$context][$name]['value']=$value;
|
||||||
$this->parameters[$context][$name]['value']=$value;
|
$this->parameters[$context][$name]['value']=$value;
|
||||||
}
|
}
|
||||||
|
@ -331,13 +331,15 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
|
|
||||||
// Apply default values to missing data
|
// Apply default values to missing data
|
||||||
$contexts=array($this->queriedContext);
|
$contexts=array($this->queriedContext);
|
||||||
if(isset($this->parameters['global'])){
|
if(array_key_exists('global',static::PARAMETERS)){
|
||||||
$contexts[]='global';
|
$contexts[]='global';
|
||||||
}
|
}
|
||||||
foreach($contexts as $context){
|
foreach($contexts as $context){
|
||||||
foreach($this->parameters[$context] as $name=>$properties){
|
foreach(static::PARAMETERS[$context] as $name=>$properties){
|
||||||
if(!isset($properties['type'])){
|
if(!isset($properties['type'])){
|
||||||
$this->parameters[$context][$name]['type']='text';
|
$type='text';
|
||||||
|
}else{
|
||||||
|
$type=$properties['type'];
|
||||||
}
|
}
|
||||||
if(isset($properties['value'])){
|
if(isset($properties['value'])){
|
||||||
continue;
|
continue;
|
||||||
|
@ -371,8 +373,8 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy global parameter values to the guessed context
|
// Copy global parameter values to the guessed context
|
||||||
if(isset($this->parameters['global'])){
|
if(array_key_exists('global',static::PARAMETERS)){
|
||||||
foreach($this->parameters['global'] as $name=>$properties){
|
foreach(static::PARAMETERS['global'] as $name=>$properties){
|
||||||
if(isset($inputs[$name])){
|
if(isset($inputs[$name])){
|
||||||
$value=$inputs[$name];
|
$value=$inputs[$name];
|
||||||
}else if(isset($properties['value'])){
|
}else if(isset($properties['value'])){
|
||||||
|
@ -405,11 +407,11 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
return $this->name;
|
return static::NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getURI(){
|
public function getURI(){
|
||||||
return $this->uri;
|
return static::URI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheDuration(){
|
public function getCacheDuration(){
|
||||||
|
@ -585,6 +587,10 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
|
|
||||||
abstract class RssExpander extends HttpCachingBridgeAbstract {
|
abstract class RssExpander extends HttpCachingBridgeAbstract {
|
||||||
|
|
||||||
|
private $name;
|
||||||
|
private $uri;
|
||||||
|
private $description;
|
||||||
|
|
||||||
public function collectExpandableDatas($name){
|
public function collectExpandableDatas($name){
|
||||||
if(empty($name)){
|
if(empty($name)){
|
||||||
$this->returnServerError('There is no $name for this RSS expander');
|
$this->returnServerError('There is no $name for this RSS expander');
|
||||||
|
@ -632,6 +638,14 @@ abstract class RssExpander extends HttpCachingBridgeAbstract {
|
||||||
*/
|
*/
|
||||||
abstract protected function parseRSSItem($item);
|
abstract protected function parseRSSItem($item);
|
||||||
|
|
||||||
|
public function getURI(){
|
||||||
|
return $this->uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(){
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
public function getDescription(){
|
public function getDescription(){
|
||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ class HTMLUtils {
|
||||||
|
|
||||||
public static function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
public static function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
||||||
$bridgeElement = Bridge::create($bridgeName);
|
$bridgeElement = Bridge::create($bridgeName);
|
||||||
|
$bridgeClass=$bridgeName.'Bridge';
|
||||||
|
|
||||||
if($bridgeElement == false)
|
if($bridgeElement == false)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
$name = '<a href="' . $bridgeElement->uri . '">' . $bridgeElement->name . '</a>';
|
$name = '<a href="' . $bridgeClass::URI . '">' . $bridgeClass::NAME . '</a>';
|
||||||
$description = $bridgeElement->description;
|
$description = $bridgeClass::DESCRIPTION;
|
||||||
|
|
||||||
$card = <<<CARD
|
$card = <<<CARD
|
||||||
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||||
|
@ -21,7 +22,7 @@ class HTMLUtils {
|
||||||
CARD;
|
CARD;
|
||||||
|
|
||||||
// If we don't have any parameter for the bridge, we print a generic form to load it.
|
// If we don't have any parameter for the bridge, we print a generic form to load it.
|
||||||
if(count($bridgeElement->parameters) == 0) {
|
if(count($bridgeClass::PARAMETERS) == 0) {
|
||||||
|
|
||||||
$card .= HTMLUtils::getFormHeader($bridgeName);
|
$card .= HTMLUtils::getFormHeader($bridgeName);
|
||||||
|
|
||||||
|
@ -40,13 +41,13 @@ CARD;
|
||||||
$card .= '</form>' . PHP_EOL;
|
$card .= '</form>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hasGlobalParameter = array_key_exists('global', $bridgeElement->parameters);
|
$hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS);
|
||||||
|
|
||||||
if($hasGlobalParameter){
|
if($hasGlobalParameter){
|
||||||
$globalParameters = $bridgeElement->parameters['global'];
|
$globalParameters = $bridgeClass::PARAMETERS['global'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($bridgeElement->parameters as $parameterName => $parameter){
|
foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){
|
||||||
if(!is_numeric($parameterName) && $parameterName == 'global')
|
if(!is_numeric($parameterName) && $parameterName == 'global')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ CARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
$card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>';
|
$card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>';
|
||||||
$card .= '<p class="maintainer">' . $bridgeElement->maintainer . '</p>';
|
$card .= '<p class="maintainer">' . $bridgeClass::MAINTAINER . '</p>';
|
||||||
$card .= '</section>';
|
$card .= '</section>';
|
||||||
|
|
||||||
return $card;
|
return $card;
|
||||||
|
|
Loading…
Reference in a new issue