2016-09-05 19:05:19 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
|
|
|
|
* Atom feeds for websites that don't have one.
|
|
|
|
*
|
|
|
|
* For the full license information, please view the UNLICENSE file distributed
|
|
|
|
* with this source code.
|
|
|
|
*
|
|
|
|
* @package Core
|
|
|
|
* @license http://unlicense.org/ UNLICENSE
|
|
|
|
* @link https://github.com/rss-bridge/rss-bridge
|
|
|
|
*/
|
2018-11-06 21:23:32 +03:00
|
|
|
|
2016-09-05 19:05:19 +03:00
|
|
|
abstract class BridgeAbstract implements BridgeInterface
|
|
|
|
{
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* Name of the bridge
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getName()} to read this parameter
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
const NAME = 'Unnamed bridge';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* URI to the site the bridge is intended to be used for.
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getURI()} to read this parameter
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
const URI = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-06-25 22:45:25 +03:00
|
|
|
/**
|
|
|
|
* Donation URI to the site the bridge is intended to be used for.
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getDonationURI()} to read this parameter
|
|
|
|
*/
|
|
|
|
const DONATION_URI = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* A brief description of what the bridge can do
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getDescription()} to read this parameter
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
const DESCRIPTION = 'No description provided';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* The name of the maintainer. Multiple maintainers can be separated by comma
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getMaintainer()} to read this parameter
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
const MAINTAINER = 'No maintainer';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* The default cache timeout for the bridge
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getCacheTimeout()} to read this parameter
|
|
|
|
*/
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 3600;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-12-12 19:05:22 +03:00
|
|
|
/**
|
|
|
|
* Configuration for the bridge
|
|
|
|
*/
|
|
|
|
const CONFIGURATION = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* Parameters for the bridge
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getParameters()} to read this parameter
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
const PARAMETERS = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-06-05 07:19:07 +03:00
|
|
|
/**
|
|
|
|
* Test cases for detectParameters for the bridge
|
|
|
|
*/
|
|
|
|
const TEST_DETECT_PARAMETERS = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-10 19:56:24 +03:00
|
|
|
/**
|
|
|
|
* This is a convenient const for the limit option in bridge contexts.
|
|
|
|
* Can be inlined and modified if necessary.
|
|
|
|
*/
|
|
|
|
protected const LIMIT = [
|
|
|
|
'name' => 'Limit',
|
|
|
|
'type' => 'number',
|
|
|
|
'title' => 'Maximum number of items to return',
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* Holds the list of items collected by the bridge
|
|
|
|
*
|
|
|
|
* Items must be collected by {@see BridgeInterface::collectData()}
|
|
|
|
*
|
|
|
|
* Use {@see BridgeAbstract::getItems()} to access items.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2022-08-06 23:46:28 +03:00
|
|
|
protected array $items = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/**
|
|
|
|
* Holds the list of input parameters used by the bridge
|
|
|
|
*
|
|
|
|
* Do not access this parameter directly!
|
|
|
|
* Use {@see BridgeAbstract::setInputs()} and {@see BridgeAbstract::getInput()} instead!
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2022-08-06 23:46:28 +03:00
|
|
|
protected array $inputs = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
/**
|
2018-11-16 23:48:59 +03:00
|
|
|
* Holds the name of the queried context
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $queriedContext = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2023-08-01 20:35:06 +03:00
|
|
|
/**
|
|
|
|
* Holds the list of bridge-specific configurations from config.ini.php, used by the bridge.
|
|
|
|
*/
|
|
|
|
private array $configuration = [];
|
|
|
|
|
2023-09-10 22:50:15 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2016-09-10 21:41:11 +03:00
|
|
|
public function getItems()
|
|
|
|
{
|
|
|
|
return $this->items;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-02-13 21:26:39 +03:00
|
|
|
/**
|
2018-11-16 23:48:59 +03:00
|
|
|
* Sets the input values for a given context.
|
2017-02-13 21:26:39 +03:00
|
|
|
*
|
|
|
|
* @param array $inputs Associative array of inputs
|
2018-11-16 23:48:59 +03:00
|
|
|
* @param string $queriedContext The context name
|
|
|
|
* @return void
|
2017-02-13 21:26:39 +03:00
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
protected function setInputs(array $inputs, $queriedContext)
|
|
|
|
{
|
|
|
|
// Import and assign all inputs to their context
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($inputs as $name => $value) {
|
|
|
|
foreach (static::PARAMETERS as $context => $set) {
|
|
|
|
if (array_key_exists($name, static::PARAMETERS[$context])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$this->inputs[$context][$name]['value'] = $value;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
// Apply default values to missing data
|
|
|
|
$contexts = [$queriedContext];
|
2017-07-29 20:28:00 +03:00
|
|
|
if (array_key_exists('global', static::PARAMETERS)) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$contexts[] = 'global';
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach ($contexts as $context) {
|
2023-07-31 21:43:18 +03:00
|
|
|
if (!isset(static::PARAMETERS[$context])) {
|
|
|
|
// unknown context provided by client, throw exception here? or continue?
|
|
|
|
}
|
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach (static::PARAMETERS[$context] as $name => $properties) {
|
|
|
|
if (isset($this->inputs[$context][$name]['value'])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$type = $properties['type'] ?? 'text';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
switch ($type) {
|
2016-09-10 21:41:11 +03:00
|
|
|
case 'checkbox':
|
2023-09-10 05:15:05 +03:00
|
|
|
$this->inputs[$context][$name]['value'] = $inputs[$context][$name]['value'] ?? false;
|
2016-09-10 21:41:11 +03:00
|
|
|
break;
|
|
|
|
case 'list':
|
2017-07-29 20:28:00 +03:00
|
|
|
if (!isset($properties['defaultValue'])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$firstItem = reset($properties['values']);
|
2017-07-29 20:28:00 +03:00
|
|
|
if (is_array($firstItem)) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$firstItem = reset($firstItem);
|
|
|
|
}
|
|
|
|
$this->inputs[$context][$name]['value'] = $firstItem;
|
|
|
|
} else {
|
|
|
|
$this->inputs[$context][$name]['value'] = $properties['defaultValue'];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-07-29 20:28:00 +03:00
|
|
|
if (isset($properties['defaultValue'])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$this->inputs[$context][$name]['value'] = $properties['defaultValue'];
|
|
|
|
}
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
// Copy global parameter values to the guessed context
|
2017-07-29 20:28:00 +03:00
|
|
|
if (array_key_exists('global', static::PARAMETERS)) {
|
|
|
|
foreach (static::PARAMETERS['global'] as $name => $properties) {
|
|
|
|
if (isset($inputs[$name])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$value = $inputs[$name];
|
|
|
|
} else {
|
2023-09-11 14:18:00 +03:00
|
|
|
if ($properties['type'] ?? null === 'checkbox') {
|
2023-09-10 05:15:05 +03:00
|
|
|
$value = false;
|
|
|
|
} elseif (isset($properties['defaultValue'])) {
|
|
|
|
$value = $properties['defaultValue'];
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
|
|
|
$this->inputs[$queriedContext][$name]['value'] = $value;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
// Only keep guessed context parameters values
|
2017-07-29 20:28:00 +03:00
|
|
|
if (isset($this->inputs[$queriedContext])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$this->inputs = [$queriedContext => $this->inputs[$queriedContext]];
|
|
|
|
} else {
|
|
|
|
$this->inputs = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
/**
|
2018-11-16 23:48:59 +03:00
|
|
|
* Set inputs for the bridge
|
|
|
|
*
|
|
|
|
* Returns errors and aborts execution if the provided input parameters are
|
|
|
|
* invalid.
|
|
|
|
*
|
|
|
|
* @param array List of input parameters. Each element in this list must
|
|
|
|
* relate to an item in {@see BridgeAbstract::PARAMETERS}
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
public function setDatas(array $inputs)
|
|
|
|
{
|
2019-06-21 20:08:59 +03:00
|
|
|
if (isset($inputs['context'])) { // Context hinting (optional)
|
|
|
|
$this->queriedContext = $inputs['context'];
|
|
|
|
unset($inputs['context']);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if (empty(static::PARAMETERS)) {
|
|
|
|
if (!empty($inputs)) {
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception('Invalid parameters value(s)');
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-09-22 17:42:04 +03:00
|
|
|
$validator = new ParameterValidator();
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-09-22 17:42:04 +03:00
|
|
|
if (!$validator->validateData($inputs, static::PARAMETERS)) {
|
|
|
|
$parameters = array_map(
|
|
|
|
function ($i) {
|
|
|
|
return $i['name'];
|
|
|
|
}, // Just display parameter names
|
|
|
|
$validator->getInvalidParameters()
|
|
|
|
);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception(sprintf('Invalid parameters value(s): %s', implode(', ', $parameters)));
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-06-21 20:08:59 +03:00
|
|
|
// Guess the context from input data
|
|
|
|
if (empty($this->queriedContext)) {
|
|
|
|
$this->queriedContext = $validator->getQueriedContext($inputs, static::PARAMETERS);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if (is_null($this->queriedContext)) {
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception('Required parameter(s) missing');
|
2017-07-29 20:28:00 +03:00
|
|
|
} elseif ($this->queriedContext === false) {
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception('Mixed context parameters');
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$this->setInputs($inputs, $this->queriedContext);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-12-12 19:05:22 +03:00
|
|
|
/**
|
|
|
|
* Loads configuration for the bridge
|
|
|
|
*
|
|
|
|
* Returns errors and aborts execution if the provided configuration is
|
|
|
|
* invalid.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function loadConfiguration()
|
|
|
|
{
|
|
|
|
foreach (static::CONFIGURATION as $optionName => $optionValue) {
|
2022-08-07 00:12:30 +03:00
|
|
|
$section = $this->getShortName();
|
2022-08-02 16:03:54 +03:00
|
|
|
$configurationOption = Configuration::getConfig($section, $optionName);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-12-12 19:05:22 +03:00
|
|
|
if ($configurationOption !== null) {
|
|
|
|
$this->configuration[$optionName] = $configurationOption;
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-12-12 19:05:22 +03:00
|
|
|
if (isset($optionValue['required']) && $optionValue['required'] === true) {
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception(sprintf('Missing configuration option: %s', $optionName));
|
2020-12-12 19:05:22 +03:00
|
|
|
} elseif (isset($optionValue['defaultValue'])) {
|
|
|
|
$this->configuration[$optionName] = $optionValue['defaultValue'];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-12-12 19:05:22 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
|
|
/**
|
2020-12-12 19:05:22 +03:00
|
|
|
* Returns the value for the provided input
|
2022-07-01 16:10:30 +03:00
|
|
|
*
|
2017-02-13 21:26:39 +03:00
|
|
|
* @param string $input The input name
|
|
|
|
* @return mixed|null The input value or null if the input is not defined
|
2022-07-01 16:10:30 +03:00
|
|
|
*/
|
2017-02-13 21:26:39 +03:00
|
|
|
protected function getInput($input)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2017-02-13 21:26:39 +03:00
|
|
|
if (!isset($this->inputs[$this->queriedContext][$input]['value'])) {
|
2016-09-10 21:41:11 +03:00
|
|
|
return null;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2016-09-10 21:41:11 +03:00
|
|
|
return $this->inputs[$this->queriedContext][$input]['value'];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2023-03-02 15:25:57 +03:00
|
|
|
/**
|
|
|
|
* Get the key name of a given input
|
|
|
|
* Can process multilevel arrays with two levels, the max level a list can have
|
|
|
|
*
|
|
|
|
* @param string $input The input name
|
|
|
|
* @return string|null The accompaning key to a given input or null if the input is not defined
|
|
|
|
*/
|
|
|
|
public function getKey($input)
|
|
|
|
{
|
|
|
|
if (!isset($this->inputs[$this->queriedContext][$input]['value'])) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-03-06 22:01:51 +03:00
|
|
|
if (array_key_exists('global', static::PARAMETERS)) {
|
|
|
|
if (array_key_exists($input, static::PARAMETERS['global'])) {
|
|
|
|
$context = 'global';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isset($context)) {
|
|
|
|
$context = $this->queriedContext;
|
|
|
|
}
|
2023-07-11 17:54:59 +03:00
|
|
|
|
2023-03-02 15:25:57 +03:00
|
|
|
$needle = $this->inputs[$this->queriedContext][$input]['value'];
|
2023-03-06 22:01:51 +03:00
|
|
|
foreach (static::PARAMETERS[$context][$input]['values'] as $first_level_key => $first_level_value) {
|
2023-07-11 17:54:59 +03:00
|
|
|
if (!is_array($first_level_value) && $needle === (string)$first_level_value) {
|
2023-03-02 15:25:57 +03:00
|
|
|
return $first_level_key;
|
|
|
|
} elseif (is_array($first_level_value)) {
|
|
|
|
foreach ($first_level_value as $second_level_key => $second_level_value) {
|
|
|
|
if ($needle === (string)$second_level_value) {
|
|
|
|
return $second_level_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
/**
|
2022-08-06 23:46:28 +03:00
|
|
|
* Get bridge configuration value
|
2017-02-13 21:26:39 +03:00
|
|
|
*/
|
|
|
|
public function getOption($name)
|
2017-07-29 20:28:00 +03:00
|
|
|
{
|
2022-08-06 23:46:28 +03:00
|
|
|
return $this->configuration[$name] ?? null;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2020-12-12 19:05:22 +03:00
|
|
|
/** {@inheritdoc} */
|
2018-11-16 23:48:59 +03:00
|
|
|
public function getDescription()
|
|
|
|
{
|
2017-02-13 22:56:19 +03:00
|
|
|
return static::DESCRIPTION;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2017-02-13 22:56:19 +03:00
|
|
|
public function getMaintainer()
|
|
|
|
{
|
|
|
|
return static::MAINTAINER;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2016-09-10 21:41:11 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return static::NAME;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2018-08-21 18:46:47 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
2020-12-07 20:08:58 +03:00
|
|
|
return static::URI . '/favicon.ico';
|
2018-08-21 18:46:47 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2017-02-13 22:56:19 +03:00
|
|
|
public function getParameters()
|
|
|
|
{
|
|
|
|
return static::PARAMETERS;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2016-09-10 21:41:11 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
return static::URI;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-06-25 22:45:25 +03:00
|
|
|
/** {@inheritdoc} */
|
|
|
|
public function getDonationURI()
|
|
|
|
{
|
|
|
|
return static::DONATION_URI;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-16 23:48:59 +03:00
|
|
|
/** {@inheritdoc} */
|
2018-03-14 20:06:36 +03:00
|
|
|
public function getCacheTimeout()
|
|
|
|
{
|
2018-10-15 18:21:43 +03:00
|
|
|
return static::CACHE_TIMEOUT;
|
2018-03-14 20:06:36 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2018-11-26 20:05:41 +03:00
|
|
|
/** {@inheritdoc} */
|
|
|
|
public function detectParameters($url)
|
|
|
|
{
|
|
|
|
$regex = '/^(https?:\/\/)?(www\.)?(.+?)(\/)?$/';
|
|
|
|
if (
|
|
|
|
empty(static::PARAMETERS)
|
|
|
|
&& preg_match($regex, $url, $urlMatches) > 0
|
|
|
|
&& preg_match($regex, static::URI, $bridgeUriMatches) > 0
|
|
|
|
&& $urlMatches[3] === $bridgeUriMatches[3]
|
|
|
|
) {
|
|
|
|
return [];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2022-08-06 23:46:28 +03:00
|
|
|
return null;
|
2018-11-26 20:05:41 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-02 09:15:28 +03:00
|
|
|
/**
|
|
|
|
* Loads a cached value for the specified key
|
|
|
|
*
|
|
|
|
* @return mixed Cached value or null if the key doesn't exist or has expired
|
|
|
|
*/
|
2023-09-10 22:50:15 +03:00
|
|
|
protected function loadCacheValue(string $key)
|
2022-04-02 09:15:28 +03:00
|
|
|
{
|
2023-07-08 18:03:12 +03:00
|
|
|
$cache = RssBridge::getCache();
|
2023-09-10 22:50:15 +03:00
|
|
|
$cacheKey = $this->getShortName() . '_' . $key;
|
|
|
|
return $cache->get($cacheKey);
|
2022-04-02 09:15:28 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-02 09:15:28 +03:00
|
|
|
/**
|
|
|
|
* Stores a value to cache with the specified key
|
|
|
|
*
|
|
|
|
* @param mixed $value Value to cache
|
|
|
|
*/
|
2023-09-10 22:50:15 +03:00
|
|
|
protected function saveCacheValue(string $key, $value, $ttl = 86400)
|
2022-04-02 09:15:28 +03:00
|
|
|
{
|
2023-07-08 18:03:12 +03:00
|
|
|
$cache = RssBridge::getCache();
|
2023-09-10 22:50:15 +03:00
|
|
|
$cacheKey = $this->getShortName() . '_' . $key;
|
|
|
|
$cache->set($cacheKey, $value, $ttl);
|
2022-04-02 09:15:28 +03:00
|
|
|
}
|
2022-08-07 00:12:30 +03:00
|
|
|
|
|
|
|
public function getShortName(): string
|
|
|
|
{
|
|
|
|
return (new \ReflectionClass($this))->getShortName();
|
|
|
|
}
|
2016-09-05 19:05:19 +03:00
|
|
|
}
|