Skip to content

Commit 9bda9e2

Browse files
authored
refactor: FeedExpander (RSS-Bridge#3740)
* refactor: FeedExpander
1 parent 6634291 commit 9bda9e2

9 files changed

+312
-501
lines changed

bridges/CssSelectorFeedExpanderBridge.php

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function collectData()
6161
$discard_thumbnail = $this->getInput('discard_thumbnail');
6262
$limit = $this->getInput('limit');
6363

64+
//$xmlString = getContents($url);
65+
//$feed = (new FeedParser())->parseFeed($xmlString);
66+
//$items = $feed['items'];
67+
6468
$feed_expander = new CssSelectorFeedExpanderBridgeInternal();
6569
$items = $feed_expander->collectExpandableDatas($url)->getItems();
6670

bridges/FeedExpanderExampleBridge.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ public function collectData()
4646

4747
protected function parseItem($newsItem)
4848
{
49-
switch ($this->getInput('version')) {
50-
case 'rss_0_9_1':
51-
return $this->parseRss091Item($newsItem);
52-
break;
53-
case 'rss_1_0':
54-
return $this->parseRss1Item($newsItem);
55-
break;
56-
case 'rss_2_0':
57-
return $this->parseRss2Item($newsItem);
58-
break;
59-
case 'atom_1_0':
60-
return $this->parseATOMItem($newsItem);
61-
break;
62-
default:
63-
returnClientError('Unknown version ' . $this->getInput('version') . '!');
64-
}
49+
return (array) $newsItem;
6550
}
6651
}

bridges/MastodonBridge.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public function collectData()
8282
}
8383
$items = $content['orderedItems'] ?? $content['items'];
8484
foreach ($items as $status) {
85-
$item = $this->parseItem($status);
85+
$item = $this->parseStatus($status);
8686
if ($item) {
8787
$this->items[] = $item;
8888
}
8989
}
9090
}
9191

92-
protected function parseItem($content)
92+
protected function parseStatus($content)
9393
{
9494
$item = [];
9595
switch ($content['type']) {

bridges/NyaaTorrentsBridge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function collectData()
6767

6868
protected function parseItem($newItem)
6969
{
70-
$item = parent::parseRss2Item($newItem);
70+
$item = parent::parseItem($newItem);
7171
$item['id'] = str_replace(['https://nyaa.si/download/', '.torrent'], '', $item['uri']);
7272

7373
$nyaaFields = (array)($newItem->children('nyaa', true));

bridges/RaceDepartmentBridge.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function collectData()
1414

1515
protected function parseItem($feedItem)
1616
{
17-
$item = parent::parseRss2Item($feedItem);
17+
$item = parent::parseItem($feedItem);
1818

1919
//fetch page
2020
$articlePage = getSimpleHTMLDOMCached($feedItem->link);

index.php

+50
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,56 @@
66

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

9+
Configuration::verifyInstallation();
10+
$customConfig = [];
11+
if (file_exists(__DIR__ . '/config.ini.php')) {
12+
$customConfig = parse_ini_file(__DIR__ . '/config.ini.php', true, INI_SCANNER_TYPED);
13+
}
14+
Configuration::loadConfiguration($customConfig, getenv());
15+
16+
// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
17+
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
18+
919
$rssBridge = new RssBridge();
1020

21+
set_exception_handler(function (\Throwable $e) {
22+
http_response_code(500);
23+
print render(__DIR__ . '/templates/exception.html.php', ['e' => $e]);
24+
RssBridge::getLogger()->error('Uncaught Exception', ['e' => $e]);
25+
exit(1);
26+
});
27+
28+
set_error_handler(function ($code, $message, $file, $line) {
29+
if ((error_reporting() & $code) === 0) {
30+
return false;
31+
}
32+
// In the future, uncomment this:
33+
//throw new \ErrorException($message, 0, $code, $file, $line);
34+
$text = sprintf(
35+
'%s at %s line %s',
36+
sanitize_root($message),
37+
sanitize_root($file),
38+
$line
39+
);
40+
RssBridge::getLogger()->warning($text);
41+
});
42+
43+
// There might be some fatal errors which are not caught by set_error_handler() or \Throwable.
44+
register_shutdown_function(function () {
45+
$error = error_get_last();
46+
if ($error) {
47+
$message = sprintf(
48+
'(shutdown) %s: %s in %s line %s',
49+
$error['type'],
50+
sanitize_root($error['message']),
51+
sanitize_root($error['file']),
52+
$error['line']
53+
);
54+
RssBridge::getLogger()->error($message);
55+
if (Debug::isEnabled()) {
56+
print sprintf("<pre>%s</pre>\n", e($message));
57+
}
58+
}
59+
});
60+
1161
$rssBridge->main($argv ?? []);

0 commit comments

Comments
 (0)