forked from blallo/rss-bridge
core: Use methods to access bridge information
Bridge information were exposed and accessed via public constants which doesn't work if you want to generate bridges dynamically as discussed in #402
This commit is contained in:
parent
c44fb25845
commit
d93d491d8e
3 changed files with 47 additions and 17 deletions
|
@ -228,10 +228,22 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||
return $this->inputs[$this->queriedContext][$input]['value'];
|
||||
}
|
||||
|
||||
public function getDescription(){
|
||||
return static::DESCRIPTION;
|
||||
}
|
||||
|
||||
public function getMaintainer(){
|
||||
return static::MAINTAINER;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return static::NAME;
|
||||
}
|
||||
|
||||
public function getParameters(){
|
||||
return static::PARAMETERS;
|
||||
}
|
||||
|
||||
public function getURI(){
|
||||
return static::URI;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,13 @@ interface BridgeInterface {
|
|||
*/
|
||||
public function getCachable();
|
||||
|
||||
/**
|
||||
* Returns the description
|
||||
*
|
||||
* @return string Description
|
||||
*/
|
||||
public function getDescription();
|
||||
|
||||
/**
|
||||
* Return an array of extra information
|
||||
*
|
||||
|
@ -27,6 +34,13 @@ interface BridgeInterface {
|
|||
*/
|
||||
public function getItems();
|
||||
|
||||
/**
|
||||
* Returns the bridge maintainer
|
||||
*
|
||||
* @return string Bridge maintainer
|
||||
*/
|
||||
public function getMaintainer();
|
||||
|
||||
/**
|
||||
* Returns the bridge name
|
||||
*
|
||||
|
@ -34,6 +48,13 @@ interface BridgeInterface {
|
|||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Returns the bridge parameters
|
||||
*
|
||||
* @return array Bridge parameters
|
||||
*/
|
||||
public function getParameters();
|
||||
|
||||
/**
|
||||
* Returns the bridge URI
|
||||
*
|
||||
|
|
25
lib/html.php
25
lib/html.php
|
@ -15,22 +15,21 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
|||
return $buttons;
|
||||
};
|
||||
|
||||
$getFormHeader = function($bridge){
|
||||
$getFormHeader = function($bridgeName){
|
||||
return <<<EOD
|
||||
<form method="GET" action="?">
|
||||
<input type="hidden" name="action" value="display" />
|
||||
<input type="hidden" name="bridge" value="{$bridge}" />
|
||||
<input type="hidden" name="bridge" value="{$bridgeName}" />
|
||||
EOD;
|
||||
};
|
||||
|
||||
$bridgeElement = Bridge::create($bridgeName);
|
||||
$bridgeClass = $bridgeName . 'Bridge';
|
||||
$bridge = Bridge::create($bridgeName);
|
||||
|
||||
if($bridgeElement == false)
|
||||
if($bridge == false)
|
||||
return "";
|
||||
|
||||
$name = '<a href="' . $bridgeClass::URI . '">' . $bridgeClass::NAME . '</a>';
|
||||
$description = $bridgeClass::DESCRIPTION;
|
||||
$name = '<a href="' . $bridge->getURI() . '">' . $bridge->getName() . '</a>';
|
||||
$description = $bridge->getDescription();
|
||||
|
||||
$card = <<<CARD
|
||||
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||
|
@ -43,7 +42,7 @@ EOD;
|
|||
CARD;
|
||||
|
||||
// If we don't have any parameter for the bridge, we print a generic form to load it.
|
||||
if(count($bridgeClass::PARAMETERS) == 0){
|
||||
if(count($bridge->getParameters()) == 0){
|
||||
|
||||
$card .= $getFormHeader($bridgeName);
|
||||
|
||||
|
@ -77,13 +76,13 @@ CARD;
|
|||
$card .= '</form>' . PHP_EOL;
|
||||
}
|
||||
|
||||
$hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS);
|
||||
$hasGlobalParameter = array_key_exists('global', $bridge->getParameters());
|
||||
|
||||
if($hasGlobalParameter){
|
||||
$globalParameters = $bridgeClass::PARAMETERS['global'];
|
||||
$globalParameters = $bridge->getParameters()['global'];
|
||||
}
|
||||
|
||||
foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){
|
||||
foreach($bridge->getParameters() as $parameterName => $parameter){
|
||||
if(!is_numeric($parameterName) && $parameterName == 'global')
|
||||
continue;
|
||||
|
||||
|
@ -251,7 +250,7 @@ CARD;
|
|||
}
|
||||
|
||||
$card .= '<label class="showless" for="showmore-' . $bridgeName . '">Show less</label>';
|
||||
$card .= '<p class="maintainer">' . $bridgeClass::MAINTAINER . '</p>';
|
||||
$card .= '<p class="maintainer">' . $bridge->getMaintainer() . '</p>';
|
||||
$card .= '</section>';
|
||||
|
||||
return $card;
|
||||
|
@ -288,5 +287,3 @@ function defaultImageSrcTo($content, $server){
|
|||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue