rss-bridge/index.php
Dag ecb486794b
refactor: use static values for cache scope
This fixes a future problem when code is placed under a namespace because `get_class($bridge)` will then return e.g. `RssBridge\Bridge\TwitterBridge` instead of the the current value `TwitterBridge`.

Also a bit refactoring of `Configuration.php`.
2022-08-02 15:03:54 +02:00

58 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/lib/rssbridge.php';
Configuration::verifyInstallation();
Configuration::loadConfiguration();
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
define('CUSTOM_CACHE_TIMEOUT', Configuration::getConfig('cache', 'custom_timeout'));
Authentication::showPromptIfNeeded();
try {
if (isset($argv)) {
parse_str(implode('&', array_slice($argv, 1)), $cliArgs);
$request = $cliArgs;
} else {
$request = $_GET;
}
foreach ($request as $key => $value) {
if (! is_string($value)) {
http_response_code(400);
print render('error.html.php', [
'title' => '400 Bad Request',
'message' => "Query parameter \"$key\" is not a string.",
]);
exit(1);
}
}
$actionFactory = new ActionFactory();
if (array_key_exists('action', $request)) {
$action = $actionFactory->create($request['action']);
$action->execute($request);
} else {
$showInactive = filter_input(INPUT_GET, 'show_inactive', FILTER_VALIDATE_BOOLEAN);
echo BridgeList::create($showInactive);
}
} catch (\Throwable $e) {
error_log($e);
$message = sprintf(
'Uncaught Exception %s: %s at %s line %s',
get_class($e),
$e->getMessage(),
trim_path_prefix($e->getFile()),
$e->getLine()
);
http_response_code(500);
print render('error.html.php', [
'message' => $message,
'stacktrace' => create_sane_stacktrace($e),
]);
}