aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2025-03-02 19:32:33 -0800
committerGravatar GitHub <noreply@github.com> 2025-03-02 19:32:33 -0800
commit8b16dd20f6544af3eedf286e23c0d34ab525736c (patch)
treeec284e22a046c4c8e9626e3fa64a000a2747bf84 /lib
parentb183aa798af48af556496c42780d6e844172cf44 (diff)
parent00a24e2f694a319a5e6cb070dddfff2dae892378 (diff)
downloadrss-bridge-master.tar.gz
rss-bridge-master.tar.zst
rss-bridge-master.zip
Merge branch 'RSS-Bridge:master' into masterHEADmaster
Diffstat (limited to 'lib')
-rw-r--r--lib/BridgeAbstract.php2
-rw-r--r--lib/BridgeCard.php4
-rw-r--r--lib/Configuration.php2
-rw-r--r--lib/FeedParser.php12
-rw-r--r--lib/bootstrap.php4
-rw-r--r--lib/contents.php19
-rw-r--r--lib/http.php2
-rw-r--r--lib/logger.php2
-rw-r--r--lib/simplehtmldom/simple_html_dom.php5
-rw-r--r--lib/url.php3
10 files changed, 32 insertions, 23 deletions
diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php
index 23e90e13..b814097a 100644
--- a/lib/BridgeAbstract.php
+++ b/lib/BridgeAbstract.php
@@ -327,7 +327,7 @@ abstract class BridgeAbstract
return $this->cache->get($this->getShortName() . '_' . $key, $default);
}
- protected function saveCacheValue(string $key, $value, int $ttl = null)
+ protected function saveCacheValue(string $key, $value, int $ttl = 86400)
{
$this->cache->set($this->getShortName() . '_' . $key, $value, $ttl);
}
diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php
index 855ddb93..2f171002 100644
--- a/lib/BridgeCard.php
+++ b/lib/BridgeCard.php
@@ -44,6 +44,10 @@ final class BridgeCard
data-short-name="$shortName"
>
+ <a style="position: absolute; top: 10px; left: 10px" href="#bridge-{$bridgeClassName}">
+ <h1>#</h1>
+ <a>
+
<h2><a href="{$uri}">{$name}</a></h2>
<p class="description">{$description}</p>
diff --git a/lib/Configuration.php b/lib/Configuration.php
index 187848fb..60bf80fb 100644
--- a/lib/Configuration.php
+++ b/lib/Configuration.php
@@ -7,7 +7,7 @@
*/
final class Configuration
{
- private const VERSION = '2024-02-02';
+ private const VERSION = '2025-01-26';
private static $config = [];
diff --git a/lib/FeedParser.php b/lib/FeedParser.php
index 0ad90965..3b133b85 100644
--- a/lib/FeedParser.php
+++ b/lib/FeedParser.php
@@ -174,7 +174,7 @@ final class FeedParser
}
foreach ($namespaces as $namespaceName => $namespaceUrl) {
- if (in_array($namespaceName, ['', 'content', 'media'])) {
+ if (in_array($namespaceName, ['', 'content'])) {
continue;
}
$item[$namespaceName] = $this->parseModule($feedItem, $namespaceName, $namespaceUrl);
@@ -250,11 +250,17 @@ final class FeedParser
private function parseModule(\SimpleXMLElement $element, string $namespaceName, string $namespaceUrl): array
{
+ // Unfortunately this parses out only node values as string
+ // TODO: parse attributes too
+
$result = [];
$module = $element->children($namespaceUrl);
foreach ($module as $name => $value) {
- // todo: add custom parsing if it's something other than a string
- $result[$name] = (string) $value;
+ if (get_class($value) === 'SimpleXMLElement' && $value->count() !== 0) {
+ $result[$name] = $this->parseModule($value, $namespaceName, $namespaceUrl);
+ } else {
+ $result[$name] = (string) $value;
+ }
}
return $result;
}
diff --git a/lib/bootstrap.php b/lib/bootstrap.php
index 36b13e19..8a7c62a1 100644
--- a/lib/bootstrap.php
+++ b/lib/bootstrap.php
@@ -7,10 +7,6 @@ if (is_file(__DIR__ . '/../vendor/autoload.php')) {
const PATH_LIB_CACHES = __DIR__ . '/../caches/';
const PATH_CACHE = __DIR__ . '/../cache/';
-// Allow larger files for simple_html_dom
-// todo: extract to config (if possible)
-const MAX_FILE_SIZE = 10000000;
-
// Files
$files = [
__DIR__ . '/../lib/html.php',
diff --git a/lib/contents.php b/lib/contents.php
index 56a3db20..b4d70817 100644
--- a/lib/contents.php
+++ b/lib/contents.php
@@ -24,6 +24,13 @@ function getContents(
// TODO: consider url validation at this point
+ $config = [
+ 'useragent' => Configuration::getConfig('http', 'useragent'),
+ 'timeout' => Configuration::getConfig('http', 'timeout'),
+ 'retries' => Configuration::getConfig('http', 'retries'),
+ 'curl_options' => $curlOptions,
+ ];
+
$httpHeadersNormalized = [];
foreach ($httpHeaders as $httpHeader) {
$parts = explode(':', $httpHeader);
@@ -69,13 +76,7 @@ function getContents(
'TE' => 'trailers',
];
- $config = [
- 'useragent' => Configuration::getConfig('http', 'useragent'),
- 'timeout' => Configuration::getConfig('http', 'timeout'),
- 'retries' => Configuration::getConfig('http', 'retries'),
- 'headers' => array_merge($defaultHttpHeaders, $httpHeadersNormalized),
- 'curl_options' => $curlOptions,
- ];
+ $config['headers'] = array_merge($defaultHttpHeaders, $httpHeadersNormalized);
$maxFileSize = Configuration::getConfig('http', 'max_filesize');
if ($maxFileSize) {
@@ -176,11 +177,9 @@ function getSimpleHTMLDOM(
}
/**
- * Gets contents from the Internet as simplhtmldom object. Contents are cached
+ * Fetch contents from the Internet as simplhtmldom object. Contents are cached
* and re-used for subsequent calls until the cache duration elapsed.
*
- * _Notice_: Cached contents are forcefully removed after 24 hours (86400 seconds).
- *
* @param string $url The URL.
* @param int $ttl Cache duration in seconds.
* @param array $header (optional) A list of cURL header.
diff --git a/lib/http.php b/lib/http.php
index d1043b33..15d6ebec 100644
--- a/lib/http.php
+++ b/lib/http.php
@@ -220,7 +220,7 @@ final class Request
return $clone;
}
- public function attribute(string $key, $default = null)
+ public function getAttribute(string $key, $default = null)
{
return $this->attributes[$key] ?? $default;
}
diff --git a/lib/logger.php b/lib/logger.php
index 74a0e713..9e5f6ce9 100644
--- a/lib/logger.php
+++ b/lib/logger.php
@@ -136,7 +136,7 @@ final class StreamHandler
$record['message'],
$context
);
- $bytes = file_put_contents($this->stream, $text, FILE_APPEND | LOCK_EX);
+ $bytes = file_put_contents($this->stream, $text, FILE_APPEND);
}
}
diff --git a/lib/simplehtmldom/simple_html_dom.php b/lib/simplehtmldom/simple_html_dom.php
index 170f6fb0..e8b3a727 100644
--- a/lib/simplehtmldom/simple_html_dom.php
+++ b/lib/simplehtmldom/simple_html_dom.php
@@ -114,8 +114,9 @@ function str_get_html(
if (empty($str)) {
throw new \Exception('Refusing to parse empty string input');
}
- if (strlen($str) > MAX_FILE_SIZE) {
- throw new \Exception('Refusing to parse too big input');
+
+ if (strlen($str) > Configuration::getConfig('system', 'max_file_size')) {
+ throw new \Exception('simple_html_dom: Refusing to parse too big input: ' . strlen($str));
}
return $dom->load($str, $lowercase, $stripRN);
diff --git a/lib/url.php b/lib/url.php
index 993fef96..9a1b59ad 100644
--- a/lib/url.php
+++ b/lib/url.php
@@ -111,6 +111,9 @@ final class Url
if (!str_starts_with($path, '/')) {
throw new UrlException(sprintf('Path must start with forward slash: %s', $path));
}
+ if (str_starts_with($path, '//')) {
+ throw new UrlException(sprintf('Illegal path (too many forward slashes): %s', $path));
+ }
$clone = clone $this;
$clone->path = $path;
return $clone;