From f01729c86f29b61d4a50ea8f76c639cd1fc19f5a Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 13 Dec 2023 21:40:13 +0100 Subject: [PATCH] fix(arstechnica): plus a few unrelated tweaks (#3829) --- actions/FrontpageAction.php | 1 + bridges/ArsTechnicaBridge.php | 9 ++++++++- bridges/VkBridge.php | 2 +- caches/FileCache.php | 2 +- index.php | 6 +++++- lib/Configuration.php | 15 ++------------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/actions/FrontpageAction.php b/actions/FrontpageAction.php index 64281b1e9e2..ad48927d731 100644 --- a/actions/FrontpageAction.php +++ b/actions/FrontpageAction.php @@ -31,6 +31,7 @@ public function execute(array $request) } } + // todo: cache this renderered template return render(__DIR__ . '/../templates/frontpage.html.php', [ 'messages' => $messages, 'admin_email' => Configuration::getConfig('admin', 'email'), diff --git a/bridges/ArsTechnicaBridge.php b/bridges/ArsTechnicaBridge.php index 5b3283b519b..613c1c58ca4 100644 --- a/bridges/ArsTechnicaBridge.php +++ b/bridges/ArsTechnicaBridge.php @@ -37,7 +37,14 @@ protected function parseItem(array $item) { $item_html = getSimpleHTMLDOMCached($item['uri'] . '&'); $item_html = defaultLinkTo($item_html, self::URI); - $item['content'] = $item_html->find('.amp-wp-article-content', 0); + + $item_content = $item_html->find('.article-content.post-page', 0); + if (!$item_content) { + // The dom selector probably broke. Let's just return the item as-is + return $item; + } + + $item['content'] = $item_content; // remove various ars advertising $item['content']->find('#social-left', 0)->remove(); diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 503bc4d0ed1..980b4154877 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -523,7 +523,7 @@ private function getContents() } if (!preg_match('#^https?://vk.com/#', $uri)) { - returnServerError('Unexpected redirect location'); + returnServerError('Unexpected redirect location: ' . $uri); } $redirects++; diff --git a/caches/FileCache.php b/caches/FileCache.php index 2f4b3ad5ec6..09d127910ac 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -49,8 +49,8 @@ public function set($key, $value, int $ttl = null): void { $item = [ 'key' => $key, - 'value' => $value, 'expiration' => $ttl === null ? 0 : time() + $ttl, + 'value' => $value, ]; $cacheFile = $this->createCacheFile($key); $bytes = file_put_contents($cacheFile, serialize($item), LOCK_EX); diff --git a/index.php b/index.php index 123f6ecdb88..14713e06f75 100644 --- a/index.php +++ b/index.php @@ -6,7 +6,11 @@ require_once __DIR__ . '/lib/bootstrap.php'; -Configuration::verifyInstallation(); +$errors = Configuration::checkInstallation(); +if ($errors) { + die('
' . implode("\n", $errors) . '
'); +} + $customConfig = []; if (file_exists(__DIR__ . '/config.ini.php')) { $customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED); diff --git a/lib/Configuration.php b/lib/Configuration.php index d699178fac0..ac7d29bfbdc 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -15,15 +15,7 @@ private function __construct() { } - /** - * Verifies the current installation of RSS-Bridge and PHP. - * - * Returns an error message and aborts execution if the installation does - * not satisfy the requirements of RSS-Bridge. - * - * @return void - */ - public static function verifyInstallation() + public static function checkInstallation(): array { $errors = []; @@ -57,10 +49,7 @@ public static function verifyInstallation() if (!extension_loaded('json')) { $errors[] = 'json extension not loaded'; } - - if ($errors) { - throw new \Exception(sprintf('Configuration error: %s', implode(', ', $errors))); - } + return $errors; } public static function loadConfiguration(array $customConfig = [], array $env = [])