[Various] getKey replacements and docu (#3283)

* [Various] getKey replacements and docu

* more bridges and fix to the abstract

* linting

* revert bandcampdaily. doing more than i thought
This commit is contained in:
Bocki 2023-03-06 20:01:51 +01:00 committed by GitHub
parent b40714079f
commit f0e5ef0fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 57 additions and 100 deletions

View File

@ -75,11 +75,7 @@ class AllocineFRBridge extends BridgeAbstract
public function getName()
{
if (!is_null($this->getInput('category'))) {
return self::NAME . ' : '
. array_search(
$this->getInput('category'),
self::PARAMETERS[$this->queriedContext]['category']['values']
);
return self::NAME . ' : ' . $this->getKey('category');
}
return parent::getName();
@ -89,10 +85,6 @@ class AllocineFRBridge extends BridgeAbstract
{
$html = getSimpleHTMLDOM($this->getURI());
$category = array_search(
$this->getInput('category'),
self::PARAMETERS[$this->queriedContext]['category']['values']
);
foreach ($html->find('div[class=gd-col-left]', 0)->find('div[class*=video-card]') as $element) {
$item = [];

View File

@ -25,10 +25,7 @@ class AnimeUltimeBridge extends BridgeAbstract
public function collectData()
{
//Add type filter if provided
$typeFilter = array_search(
$this->getInput('type'),
self::PARAMETERS[$this->queriedContext]['type']['values']
);
$typeFilter = $this->getKey('type');
//Build date and filters for making requests
$thismonth = date('mY') . $typeFilter;
@ -128,12 +125,7 @@ class AnimeUltimeBridge extends BridgeAbstract
public function getName()
{
if (!is_null($this->getInput('type'))) {
$typeFilter = array_search(
$this->getInput('type'),
self::PARAMETERS[$this->queriedContext]['type']['values']
);
return 'Latest ' . $typeFilter . ' - Anime-Ultime Bridge';
return 'Latest ' . $this->getKey('type') . ' - Anime-Ultime Bridge';
}
return parent::getName();

View File

@ -97,13 +97,8 @@ EOD;
public function getName()
{
if (!is_null($this->getInput('edition')) && !is_null($this->getInput('category'))) {
$parameters = $this->getParameters();
$editionValues = array_flip($parameters[0]['edition']['values']);
$categoryValues = array_flip($parameters[0]['category']['values']);
return $categoryValues[$this->getInput('category')] . ' - ' .
$editionValues[$this->getInput('edition')] . ' - Brut.';
return $this->getKey('category') . ' - ' .
$this->getKey('edition') . ' - Brut.';
}
return parent::getName();

View File

@ -146,11 +146,7 @@ class GBAtempBridge extends BridgeAbstract
public function getName()
{
if (!is_null($this->getInput('type'))) {
$type = array_search(
$this->getInput('type'),
self::PARAMETERS[$this->queriedContext]['type']['values']
);
return 'GBAtemp ' . $type . ' Bridge';
return 'GBAtemp ' . $this->getKey('type') . ' Bridge';
}
return parent::getName();

View File

@ -625,8 +625,7 @@ class GithubTrendingBridge extends BridgeAbstract
public function getName()
{
if (!is_null($this->getInput('language'))) {
$language = array_search($this->getInput('language'), self::PARAMETERS['By language']['language']['values']);
return self::NAME . ': ' . $language;
return self::NAME . ': ' . $this->getKey('language');
}
return parent::getName();

View File

@ -138,9 +138,7 @@ class InternetArchiveBridge extends BridgeAbstract
public function getName()
{
if (!is_null($this->getInput('username')) && !is_null($this->getInput('content'))) {
$contentValues = array_flip(self::PARAMETERS['Account']['content']['values']);
return $contentValues[$this->getInput('content')] . ' - '
return $this->getKey('content') . ' - '
. $this->processUsername() . ' - Internet Archive';
}

View File

@ -181,11 +181,11 @@ class NineGagBridge extends BridgeAbstract
public function getName()
{
if ($this->getInput('d')) {
$name = sprintf('%s - %s', '9GAG', $this->getParameterKey('d'));
$name = sprintf('%s - %s', '9GAG', $this->getKey('d'));
} elseif ($this->getInput('g')) {
$name = sprintf('%s - %s', '9GAG', $this->getParameterKey('g'));
$name = sprintf('%s - %s', '9GAG', $this->getKey('g'));
if ($this->getInput('t')) {
$name = sprintf('%s [%s]', $name, $this->getParameterKey('t'));
$name = sprintf('%s [%s]', $name, $this->getKey('t'));
}
}
if (!empty($name)) {
@ -236,23 +236,6 @@ class NineGagBridge extends BridgeAbstract
return $this->p;
}
protected function getParameterKey($input = '')
{
$params = $this->getParameters();
$tab = 'Sections';
if ($input === 'd') {
$tab = 'Popular';
}
if (!isset($params[$tab][$input])) {
return '';
}
return array_search(
$this->getInput($input),
$params[$tab][$input]['values']
);
}
protected static function getContent($post)
{
if ($post['type'] === 'Animated') {

View File

@ -47,13 +47,9 @@ class NpciBridge extends BridgeAbstract
public function getName()
{
$product = $this->getInput('product');
if ($product) {
$productNameMap = array_flip(self::PARAMETERS[0]['product']['values']);
$productName = $productNameMap[$product];
return "NPCI Circulars: $productName";
if ($this->getInput('product')) {
return 'NPCI Circulars: ' . $this->getKey('product');
}
return 'NPCI Circulars';
}

View File

@ -592,9 +592,7 @@ HEREDOC;
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-keyword') . ' : ' . $this->getInput('q');
break;
case $this->i8n('context-group'):
$values = $this->getParameters()[$this->i8n('context-group')]['group']['values'];
$group = array_search($this->getInput('group'), $values);
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-group') . ' : ' . $group;
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-group') . ' : ' . $this->getKey('group');
break;
case $this->i8n('context-talk'):
return $this->i8n('bridge-name') . ' - ' . $this->i8n('title-talk') . ' : ' . $this->getTalkTitle();

View File

@ -76,11 +76,7 @@ class PixivBridge extends BridgeAbstract
default:
return parent::getName();
}
$mode = array_search(
$this->getInput('mode'),
self::PARAMETERS['global']['mode']['values']
);
return "Pixiv ${mode} from ${context} ${query}";
return 'Pixiv ' . $this->getKey('mode') . " from ${context} ${query}";
}
public function getURI()
@ -149,7 +145,6 @@ class PixivBridge extends BridgeAbstract
public function collectData()
{
$content = $this->collectWorksArray();
$content = array_filter($content, function ($v, $k) {
return !array_key_exists('isAdContainer', $v);
}, ARRAY_FILTER_USE_BOTH);

View File

@ -54,11 +54,7 @@ class SplCenterBridge extends FeedExpander
public function getName()
{
if (!is_null($this->getInput('content'))) {
$parameters = $this->getParameters();
$contentValues = array_flip($parameters[0]['content']['values']);
return $contentValues[$this->getInput('content')] . ' - Southern Poverty Law Center';
return $this->getKey('content') . ' - Southern Poverty Law Center';
}
return parent::getName();

View File

@ -147,10 +147,7 @@ EOD;
public function getName()
{
if (!is_null($this->getInput('country'))) {
$parameters = $this->getParameters();
$values = array_flip($parameters[0]['country']['values']);
return $values[$this->getInput('country')] . ' - TwitScoop';
return $this->getKey('country') . ' - TwitScoop';
}
return parent::getName();

View File

@ -76,7 +76,7 @@ class UnogsBridge extends BridgeAbstract
if ($this->queriedContext == 'Global') {
$feedName .= 'Netflix Global - ';
} elseif ($this->queriedContext == 'Country') {
$feedName .= 'Netflix ' . $this->getParametersKey('country_code') . ' - ';
$feedName .= 'Netflix ' . $this->getKey('country_code') . ' - ';
}
if ($this->getInput('feed') == 'expiring') {
$feedName .= 'Expiring title';
@ -88,20 +88,6 @@ class UnogsBridge extends BridgeAbstract
return $feedName;
}
private function getParametersKey($input = '')
{
$params = $this->getParameters();
$tab = 'Country';
if (!isset($params[$tab][$input])) {
return '';
}
return array_search(
$this->getInput($input),
$params[$tab][$input]['values']
);
}
private function getJSON($url)
{
$header = [

View File

@ -48,10 +48,7 @@ class WebfailBridge extends BridgeAbstract
{
$html = getSimpleHTMLDOM($this->getURI() . $this->getInput('type'));
$type = array_search(
$this->getInput('type'),
self::PARAMETERS[$this->queriedContext]['type']['values']
);
$type = $this->getKey('type');
switch (strtolower($type)) {
case 'facebook':

View File

@ -7,6 +7,35 @@ $this->getInput('your input name here');
`getInput` will either return the value for your parameter or `null` if the parameter is unknown or not specified.
# getKey
The `getKey` function is used to receive the key name to a selected list value given the name of the list, specified in `const PARAMETERS`
Is able to work with multidimensional list arrays.
```PHP
// Given a multidimensional array like this
const PARAMETERS = [[
'country' => [
'name' => 'Country',
'type' => 'list',
'values' => [
'North America' => [
'Mexico' => 'mx',
'United States' => 'us'
],
'South America' => [
'Uruguay' => 'uy',
'Venezuela' => 've'
],
]
]
]],
// Provide the list name to the function
$this->getKey('country');
// if the selected value was "ve", this function will return "Venezuela"
```
`getKey` will either return the key name for your parameter or `null` if the parameter is unknown or not specified.
# getContents
The `getContents` function uses [cURL](https://secure.php.net/manual/en/book.curl.php) to acquire data from the specified URI while respecting the various settings defined at a global level by RSS-Bridge (i.e., proxy host, user agent, etc.). This function accepts a few parameters:

View File

@ -306,8 +306,16 @@ abstract class BridgeAbstract implements BridgeInterface
if (!isset($this->inputs[$this->queriedContext][$input]['value'])) {
return null;
}
if (array_key_exists('global', static::PARAMETERS)) {
if (array_key_exists($input, static::PARAMETERS['global'])) {
$context = 'global';
}
}
if (!isset($context)) {
$context = $this->queriedContext;
}
$needle = $this->inputs[$this->queriedContext][$input]['value'];
foreach (static::PARAMETERS[$this->queriedContext][$input]['values'] as $first_level_key => $first_level_value) {
foreach (static::PARAMETERS[$context][$input]['values'] as $first_level_key => $first_level_value) {
if ($needle === (string)$first_level_value) {
return $first_level_key;
} elseif (is_array($first_level_value)) {