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
This commit is contained in:
Dag 2023-06-08 23:04:16 +02:00 committed by GitHub
parent 95071d0134
commit fbaf26e8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 31 deletions

View File

@ -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);

View File

@ -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'])) {

View File

@ -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
```

View File

@ -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) {

View File

@ -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();

View File

@ -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';

View File

@ -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();

View File

@ -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/';

View File

@ -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', '<&zwnj;script', $html); // Disable scripts, but leave them visible.
$html = str_replace('<iframe', '<&zwnj;iframe', $html);

View File

@ -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">

View File

@ -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;