mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
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:
parent
95071d0134
commit
fbaf26e8bf
11 changed files with 14 additions and 31 deletions
|
@ -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);
|
||||
|
|
|
@ -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'])) {
|
||||
|
|
|
@ -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
|
||||
```
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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/';
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue