diff options
author | 2023-06-08 23:04:16 +0200 | |
---|---|---|
committer | 2023-06-08 23:04:16 +0200 | |
commit | fbaf26e8bf3d61449833e12885778814e82eb168 (patch) | |
tree | 48d686dcedfd9c3e5b14fe03643584a1d003590d | |
parent | 95071d0134528ccec51328e26d5c5f14e0db5126 (diff) | |
download | rss-bridge-fbaf26e8bf3d61449833e12885778814e82eb168.tar.gz rss-bridge-fbaf26e8bf3d61449833e12885778814e82eb168.tar.zst rss-bridge-fbaf26e8bf3d61449833e12885778814e82eb168.zip |
fix(html_format): add spacing below date if author is missing (#3425)
* small ui tweak
* remove unused <div>
* refactor: rename method
* refactor: inline const
* refactor
-rw-r--r-- | actions/DisplayAction.php | 3 | ||||
-rw-r--r-- | actions/SetBridgeCacheAction.php | 2 | ||||
-rw-r--r-- | docs/08_Format_API/03_FormatAbstract.md | 13 | ||||
-rw-r--r-- | formats/AtomFormat.php | 2 | ||||
-rw-r--r-- | formats/JsonFormat.php | 2 | ||||
-rw-r--r-- | formats/MrssFormat.php | 2 | ||||
-rw-r--r-- | lib/BridgeFactory.php | 9 | ||||
-rw-r--r-- | lib/bootstrap.php | 1 | ||||
-rw-r--r-- | lib/html.php | 2 | ||||
-rw-r--r-- | templates/html-format.html.php | 7 | ||||
-rw-r--r-- | tests/Bridges/BridgeImplementationTest.php | 2 |
11 files changed, 14 insertions, 31 deletions
diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index c71be5dd..0a3d6dcd 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -41,8 +41,7 @@ class DisplayAction implements ActionInterface $bridge = $bridgeFactory->create($bridgeClassName); $bridge->loadConfiguration(); - $noproxy = array_key_exists('_noproxy', $request) - && filter_var($request['_noproxy'], FILTER_VALIDATE_BOOLEAN); + $noproxy = array_key_exists('_noproxy', $request) && filter_var($request['_noproxy'], FILTER_VALIDATE_BOOLEAN); if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge') && $noproxy) { define('NOPROXY', true); diff --git a/actions/SetBridgeCacheAction.php b/actions/SetBridgeCacheAction.php index 8bd4b545..ac56f7ea 100644 --- a/actions/SetBridgeCacheAction.php +++ b/actions/SetBridgeCacheAction.php @@ -21,7 +21,7 @@ class SetBridgeCacheAction implements ActionInterface $key = $request['key'] or returnClientError('You must specify key!'); - $bridgeFactory = new \BridgeFactory(); + $bridgeFactory = new BridgeFactory(); $bridgeClassName = null; if (isset($request['bridge'])) { diff --git a/docs/08_Format_API/03_FormatAbstract.md b/docs/08_Format_API/03_FormatAbstract.md deleted file mode 100644 index cb206b85..00000000 --- a/docs/08_Format_API/03_FormatAbstract.md +++ /dev/null @@ -1,13 +0,0 @@ -The `FormatAbstract` class implements the [`FormatInterface`](../08_Format_API/02_FormatInterface.md) interface with basic functional behavior and adds common helper functions for new formats: - -* [sanitizeHtml](#the-sanitizehtml-function) - -# Functions - -## The `sanitizeHtml` function - -The `sanitizeHtml` function receives an HTML formatted string and returns the string with disabled `<script>`, `<iframe>` and `<link>` tags. - -```PHP -sanitize_html(string $html): string -``` diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index e67e8ade..1b9053fa 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -158,7 +158,7 @@ class AtomFormat extends FormatAbstract $content = $document->createElement('content'); $content->setAttribute('type', 'html'); - $content->appendChild($document->createTextNode(sanitize_html($entryContent))); + $content->appendChild($document->createTextNode(break_annoying_html_tags($entryContent))); $entry->appendChild($content); foreach ($item->getEnclosures() as $enclosure) { diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php index cb47f12d..5bb1a525 100644 --- a/formats/JsonFormat.php +++ b/formats/JsonFormat.php @@ -47,7 +47,7 @@ class JsonFormat extends FormatAbstract $entryTitle = $item->getTitle(); $entryUri = $item->getURI(); $entryTimestamp = $item->getTimestamp(); - $entryContent = $item->getContent() ? sanitize_html($item->getContent()) : ''; + $entryContent = $item->getContent() ? break_annoying_html_tags($item->getContent()) : ''; $entryEnclosures = $item->getEnclosures(); $entryCategories = $item->getCategories(); diff --git a/formats/MrssFormat.php b/formats/MrssFormat.php index 3f0ed312..3c3dce5a 100644 --- a/formats/MrssFormat.php +++ b/formats/MrssFormat.php @@ -103,7 +103,7 @@ class MrssFormat extends FormatAbstract $itemTimestamp = $item->getTimestamp(); $itemTitle = $item->getTitle(); $itemUri = $item->getURI(); - $itemContent = $item->getContent() ? sanitize_html($item->getContent()) : ''; + $itemContent = $item->getContent() ? break_annoying_html_tags($item->getContent()) : ''; $entryID = $item->getUid(); $isPermaLink = 'false'; diff --git a/lib/BridgeFactory.php b/lib/BridgeFactory.php index e525452b..6bd832bf 100644 --- a/lib/BridgeFactory.php +++ b/lib/BridgeFactory.php @@ -2,18 +2,16 @@ final class BridgeFactory { - private $folder; /** @var array<class-string<BridgeInterface>> */ private $bridgeClassNames = []; + /** @var array<class-string<BridgeInterface>> */ private $whitelist = []; - public function __construct(string $folder = PATH_LIB_BRIDGES) + public function __construct() { - $this->folder = $folder; - // create names - foreach (scandir($this->folder) as $file) { + foreach (scandir(__DIR__ . '/../bridges/') as $file) { if (preg_match('/^([^.]+Bridge)\.php$/U', $file, $m)) { $this->bridgeClassNames[] = $m[1]; } @@ -27,6 +25,7 @@ final class BridgeFactory } else { $contents = ''; } + if ($contents === '*') { // Whitelist all bridges $this->whitelist = $this->getBridgeClassNames(); diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 98c7b54d..86182801 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -16,7 +16,6 @@ const PATH_ROOT = __DIR__ . '/../'; /** Path to the bridges library */ -const PATH_LIB_BRIDGES = __DIR__ . '/../bridges/'; /** Path to the formats library */ const PATH_LIB_FORMATS = __DIR__ . '/../formats/'; diff --git a/lib/html.php b/lib/html.php index ca0a411c..489fb5b4 100644 --- a/lib/html.php +++ b/lib/html.php @@ -124,7 +124,7 @@ function sanitize( return $htmlContent; } -function sanitize_html(string $html): string +function break_annoying_html_tags(string $html): string { $html = str_replace('<script', '<‌script', $html); // Disable scripts, but leave them visible. $html = str_replace('<iframe', '<‌iframe', $html); diff --git a/templates/html-format.html.php b/templates/html-format.html.php index 3a384deb..3b0fe6fe 100644 --- a/templates/html-format.html.php +++ b/templates/html-format.html.php @@ -53,16 +53,15 @@ <time datetime="<?= date('Y-m-d H:i:s', $item['timestamp']) ?>"> <?= date('Y-m-d H:i:s', $item['timestamp']) ?> </time> + <p></p> <?php endif; ?> <?php if ($item['author']): ?> - <br/> <p class="author">by: <?= e($item['author']) ?></p> <?php endif; ?> - <div class="content"> - <?= sanitize_html($item['content']) ?> - </div> + <!-- Intentionally not escaping for html context --> + <?= break_annoying_html_tags($item['content']) ?> <?php if ($item['enclosures']): ?> <div class="attachments"> diff --git a/tests/Bridges/BridgeImplementationTest.php b/tests/Bridges/BridgeImplementationTest.php index 60f94d4a..ab66d0a8 100644 --- a/tests/Bridges/BridgeImplementationTest.php +++ b/tests/Bridges/BridgeImplementationTest.php @@ -222,7 +222,7 @@ class BridgeImplementationTest extends TestCase public function dataBridgesProvider() { $bridges = []; - foreach (glob(PATH_LIB_BRIDGES . '*Bridge.php') as $path) { + foreach (glob(__DIR__ . '/../bridges/*Bridge.php') as $path) { $bridges[basename($path, '.php')] = [$path]; } return $bridges; |