Skip to content

Commit

Permalink
fix(arstechnica): plus a few unrelated tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan committed Dec 13, 2023
1 parent 0b67544 commit 9a86141
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions actions/FrontpageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
9 changes: 8 additions & 1 deletion bridges/ArsTechnicaBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ protected function parseItem(array $item)
{
$item_html = getSimpleHTMLDOMCached($item['uri'] . '&amp');
$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();
Expand Down
2 changes: 1 addition & 1 deletion bridges/VkBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ private function getContents()
}

if (!preg_match('#^https?://vk.com/#', $uri)) {
returnServerError('Unexpected redirect location');
returnServerError('Unexpected redirect location: ' . $uri);
}

$redirects++;
Expand Down
2 changes: 1 addition & 1 deletion caches/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

require_once __DIR__ . '/lib/bootstrap.php';

Configuration::verifyInstallation();
$errors = Configuration::checkInstallation();
if ($errors) {
die('<pre>' . implode("\n", $errors) . '</pre>');
}

$customConfig = [];
if (file_exists(__DIR__ . '/config.ini.php')) {
$customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED);
Expand Down
15 changes: 2 additions & 13 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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 = [])
Expand Down

0 comments on commit 9a86141

Please sign in to comment.