Skip to content

Commit

Permalink
core: Add context hinting for new feeds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
logmanoriginal committed Jun 21, 2019
1 parent e2bca5b commit 1591e18
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/BridgeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ protected function setInputs(array $inputs, $queriedContext){
*/
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($inputs)) {
Expand All @@ -218,8 +223,11 @@ function($i){ return $i['name']; }, // Just display parameter names
);
}

// Guess the paramter context from input data
$this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
// Guess the context from input data
if(empty($this->queriedContext)) {
$this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
}

if(is_null($this->queriedContext)) {
returnClientError('Required parameter(s) missing');
} elseif($this->queriedContext === false) {
Expand Down
10 changes: 8 additions & 2 deletions lib/BridgeCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ private static function buildFormatButtons($formats) {
* @param bool $isHttps If disabled, adds a warning to the form
* @return string The form header
*/
private static function getFormHeader($bridgeName, $isHttps = false) {
private static function getFormHeader($bridgeName, $isHttps = false, $parameterName = '') {
$form = <<<EOD
<form method="GET" action="?">
<input type="hidden" name="action" value="display" />
<input type="hidden" name="bridge" value="{$bridgeName}" />
EOD;

if(!empty($parameterName)) {
$form .= <<<EOD
<input type="hidden" name="context" value="{$parameterName}" />
EOD;
}

if(!$isHttps) {
$form .= '<div class="secure-warning">Warning :
This bridge is not fetching its content through a secure connection</div>';
Expand All @@ -80,7 +86,7 @@ private static function getForm($bridgeName,
$isHttps = false,
$parameterName = '',
$parameters = array()) {
$form = self::getFormHeader($bridgeName, $isHttps);
$form = self::getFormHeader($bridgeName, $isHttps, $parameterName);

if(count($parameters) > 0) {

Expand Down
1 change: 1 addition & 0 deletions lib/ParameterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function getQueriedContext($data, $parameters){

switch(array_sum($queriedContexts)) {
case 0: // Found no match, is there a context without parameters?
if(isset($data['context'])) return $data['context'];
foreach($queriedContexts as $context => $queried) {
if(is_null($queried)) {
return $context;
Expand Down

0 comments on commit 1591e18

Please sign in to comment.