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 $items = array();
|
||||
|
||||
public $name = 'Unnamed bridge';
|
||||
public $uri = '';
|
||||
public $description = 'No description provided';
|
||||
public $maintainer = 'No maintainer';
|
||||
const NAME = 'Unnamed bridge';
|
||||
const URI = '';
|
||||
const DESCRIPTION = 'No description provided';
|
||||
const MAINTAINER = 'No maintainer';
|
||||
const PARAMETERS = array();
|
||||
public $useProxy = true;
|
||||
public $parameters = array();
|
||||
public $inputs = array();
|
||||
protected $queriedContext='';
|
||||
|
||||
|
@ -199,28 +199,28 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
if(!is_array($data))
|
||||
return false;
|
||||
|
||||
foreach($data as $name => $value){
|
||||
$registered = false;
|
||||
foreach($this->parameters as $context => $set){
|
||||
if(array_key_exists($name, $set)){
|
||||
$registered = true;
|
||||
|
||||
if(!isset($set[$name]['type'])){ // Default to 'text'
|
||||
$set[$name]['type'] = 'text';
|
||||
$validated=true;
|
||||
foreach($data as $name=>$value){
|
||||
$registered=false;
|
||||
foreach(static::PARAMETERS as $context=>$set){
|
||||
if(array_key_exists($name,$set)){
|
||||
$registered=true;
|
||||
if(!isset($set[$name]['type'])){
|
||||
$set[$name]['type']='text';
|
||||
}
|
||||
|
||||
switch($set[$name]['type']){
|
||||
case 'number':
|
||||
case 'number':
|
||||
$data[$name] = $this->isValidNumberValue($value);
|
||||
break;
|
||||
case 'checkbox':
|
||||
case 'checkbox':
|
||||
$data[$name] = $this->isValidCheckboxValue($value);
|
||||
break;
|
||||
case 'list':
|
||||
case 'list':
|
||||
$data[$name] = $this->isValidListValue($value, $set[$name]['values']);
|
||||
break;
|
||||
default:
|
||||
case 'text':
|
||||
case 'text':
|
||||
if(isset($set[$name]['pattern'])){
|
||||
$data[$name] = $this->isValidTextValue($value, $set[$name]['pattern']);
|
||||
} else {
|
||||
|
@ -245,7 +245,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
|
||||
protected function getQueriedContext(){
|
||||
$queriedContexts=array();
|
||||
foreach($this->parameters as $context=>$set){
|
||||
foreach(static::PARAMETERS as $context=>$set){
|
||||
$queriedContexts[$context]=null;
|
||||
foreach($set as $id=>$properties){
|
||||
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){
|
||||
return null;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
}
|
||||
}
|
||||
|
||||
if(empty($this->parameters)){
|
||||
if(empty(static::PARAMETERS)){
|
||||
if(!empty($inputs)){
|
||||
$this->returnClientError('Invalid parameters value(s)');
|
||||
}
|
||||
|
@ -311,8 +311,8 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
|
||||
// Populate BridgeAbstract::parameters with sanitized data
|
||||
foreach($inputs as $name=>$value){
|
||||
foreach($this->parameters as $context=>$set){
|
||||
if(isset($this->parameters[$context][$name])){
|
||||
foreach(static::PARAMETERS as $context=>$set){
|
||||
if(array_key_exists($name,static::PARAMETERS[$context])){
|
||||
$this->inputs[$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
|
||||
$contexts=array($this->queriedContext);
|
||||
if(isset($this->parameters['global'])){
|
||||
if(array_key_exists('global',static::PARAMETERS)){
|
||||
$contexts[]='global';
|
||||
}
|
||||
foreach($contexts as $context){
|
||||
foreach($this->parameters[$context] as $name=>$properties){
|
||||
foreach(static::PARAMETERS[$context] as $name=>$properties){
|
||||
if(!isset($properties['type'])){
|
||||
$this->parameters[$context][$name]['type']='text';
|
||||
$type='text';
|
||||
}else{
|
||||
$type=$properties['type'];
|
||||
}
|
||||
if(isset($properties['value'])){
|
||||
continue;
|
||||
|
@ -371,8 +373,8 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
}
|
||||
|
||||
// Copy global parameter values to the guessed context
|
||||
if(isset($this->parameters['global'])){
|
||||
foreach($this->parameters['global'] as $name=>$properties){
|
||||
if(array_key_exists('global',static::PARAMETERS)){
|
||||
foreach(static::PARAMETERS['global'] as $name=>$properties){
|
||||
if(isset($inputs[$name])){
|
||||
$value=$inputs[$name];
|
||||
}else if(isset($properties['value'])){
|
||||
|
@ -405,11 +407,11 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
return static::NAME;
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
return $this->uri;
|
||||
return static::URI;
|
||||
}
|
||||
|
||||
public function getCacheDuration(){
|
||||
|
@ -585,6 +587,10 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
|||
|
||||
abstract class RssExpander extends HttpCachingBridgeAbstract {
|
||||
|
||||
private $name;
|
||||
private $uri;
|
||||
private $description;
|
||||
|
||||
public function collectExpandableDatas($name){
|
||||
if(empty($name)){
|
||||
$this->returnServerError('There is no $name for this RSS expander');
|
||||
|
@ -632,6 +638,14 @@ abstract class RssExpander extends HttpCachingBridgeAbstract {
|
|||
*/
|
||||
abstract protected function parseRSSItem($item);
|
||||
|
||||
public function getURI(){
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getDescription(){
|
||||
return $this->description;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ class HTMLUtils {
|
|||
|
||||
public static function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
||||
$bridgeElement = Bridge::create($bridgeName);
|
||||
$bridgeClass=$bridgeName.'Bridge';
|
||||
|
||||
if($bridgeElement == false)
|
||||
return "";
|
||||
|
||||
$name = '<a href="' . $bridgeElement->uri . '">' . $bridgeElement->name . '</a>';
|
||||
$description = $bridgeElement->description;
|
||||
$name = '<a href="' . $bridgeClass::URI . '">' . $bridgeClass::NAME . '</a>';
|
||||
$description = $bridgeClass::DESCRIPTION;
|
||||
|
||||
$card = <<<CARD
|
||||
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||
|
@ -21,7 +22,7 @@ class HTMLUtils {
|
|||
CARD;
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -40,13 +41,13 @@ CARD;
|
|||
$card .= '</form>' . PHP_EOL;
|
||||
}
|
||||
|
||||
$hasGlobalParameter = array_key_exists('global', $bridgeElement->parameters);
|
||||
$hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS);
|
||||
|
||||
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')
|
||||
continue;
|
||||
|
||||
|
@ -129,7 +130,7 @@ CARD;
|
|||
}
|
||||
|
||||
$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>';
|
||||
|
||||
return $card;
|
||||
|
|
Loading…
Reference in a new issue