core: Add context hinting for new feeds
RSS-Bridge currently has to guess the queried context from the data provided by the user. This, however, can cause issues for bridges that have multiple contexts with conflicting parameters (i.e. none). This commit adds context hinting to queries via '&context=<context>' which can be omitted in which case the context is determined as before.
This commit is contained in:
parent
e2bca5bb05
commit
1591e18027
3 changed files with 19 additions and 4 deletions
|
@ -194,6 +194,11 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
*/
|
*/
|
||||||
public function setDatas(array $inputs){
|
public function setDatas(array $inputs){
|
||||||
|
|
||||||
|
if(isset($inputs['context'])) { // Context hinting (optional)
|
||||||
|
$this->queriedContext = $inputs['context'];
|
||||||
|
unset($inputs['context']);
|
||||||
|
}
|
||||||
|
|
||||||
if(empty(static::PARAMETERS)) {
|
if(empty(static::PARAMETERS)) {
|
||||||
|
|
||||||
if(!empty($inputs)) {
|
if(!empty($inputs)) {
|
||||||
|
@ -218,8 +223,11 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guess the paramter context from input data
|
// Guess the context from input data
|
||||||
$this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
|
if(empty($this->queriedContext)) {
|
||||||
|
$this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
|
||||||
|
}
|
||||||
|
|
||||||
if(is_null($this->queriedContext)) {
|
if(is_null($this->queriedContext)) {
|
||||||
returnClientError('Required parameter(s) missing');
|
returnClientError('Required parameter(s) missing');
|
||||||
} elseif($this->queriedContext === false) {
|
} elseif($this->queriedContext === false) {
|
||||||
|
|
|
@ -48,13 +48,19 @@ final class BridgeCard {
|
||||||
* @param bool $isHttps If disabled, adds a warning to the form
|
* @param bool $isHttps If disabled, adds a warning to the form
|
||||||
* @return string The form header
|
* @return string The form header
|
||||||
*/
|
*/
|
||||||
private static function getFormHeader($bridgeName, $isHttps = false) {
|
private static function getFormHeader($bridgeName, $isHttps = false, $parameterName = '') {
|
||||||
$form = <<<EOD
|
$form = <<<EOD
|
||||||
<form method="GET" action="?">
|
<form method="GET" action="?">
|
||||||
<input type="hidden" name="action" value="display" />
|
<input type="hidden" name="action" value="display" />
|
||||||
<input type="hidden" name="bridge" value="{$bridgeName}" />
|
<input type="hidden" name="bridge" value="{$bridgeName}" />
|
||||||
EOD;
|
EOD;
|
||||||
|
|
||||||
|
if(!empty($parameterName)) {
|
||||||
|
$form .= <<<EOD
|
||||||
|
<input type="hidden" name="context" value="{$parameterName}" />
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
|
||||||
if(!$isHttps) {
|
if(!$isHttps) {
|
||||||
$form .= '<div class="secure-warning">Warning :
|
$form .= '<div class="secure-warning">Warning :
|
||||||
This bridge is not fetching its content through a secure connection</div>';
|
This bridge is not fetching its content through a secure connection</div>';
|
||||||
|
@ -80,7 +86,7 @@ This bridge is not fetching its content through a secure connection</div>';
|
||||||
$isHttps = false,
|
$isHttps = false,
|
||||||
$parameterName = '',
|
$parameterName = '',
|
||||||
$parameters = array()) {
|
$parameters = array()) {
|
||||||
$form = self::getFormHeader($bridgeName, $isHttps);
|
$form = self::getFormHeader($bridgeName, $isHttps, $parameterName);
|
||||||
|
|
||||||
if(count($parameters) > 0) {
|
if(count($parameters) > 0) {
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,7 @@ class ParameterValidator {
|
||||||
|
|
||||||
switch(array_sum($queriedContexts)) {
|
switch(array_sum($queriedContexts)) {
|
||||||
case 0: // Found no match, is there a context without parameters?
|
case 0: // Found no match, is there a context without parameters?
|
||||||
|
if(isset($data['context'])) return $data['context'];
|
||||||
foreach($queriedContexts as $context => $queried) {
|
foreach($queriedContexts as $context => $queried) {
|
||||||
if(is_null($queried)) {
|
if(is_null($queried)) {
|
||||||
return $context;
|
return $context;
|
||||||
|
|
Loading…
Reference in a new issue