Procházet zdrojové kódy

Rework UI authors (#7054)

Add separators, and mutualise code
fix https://github.com/FreshRSS/FreshRSS/issues/7032
Alexandre Alapetite před 1 rokem
rodič
revize
8464203735

+ 10 - 26
app/views/helpers/index/article.phtml

@@ -77,18 +77,13 @@
 								<img class="favicon" src="<?= $feed->favicon() ?>" alt="✇" loading="lazy" /><?php
 							endif; ?><span><?= $feed->name() ?></span></a></span>
 					<?php }
-					$authors = $entry->authors();
-					if (!empty($authors) && is_array($authors)) { ?>
-						<div class="author">
-						<?= _t('gen.short.by_author') ?>
-						<?php
-						foreach ($authors as $author) {
-							$href = Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:"' . htmlspecialchars_decode($author, ENT_QUOTES) . '"']));
-							?>
-							<a href="<?= $href ?>" title="<?= _t('gen.action.filter') ?>"><?= $author ?></a>
-						<?php } ?>
-						</div>
-					<?php } ?>
+						if (!empty($entry->authors())) {
+							$this->renderHelper('index/authors');
+							if ($this->feed === null || $this->entry === null) {
+								throw new Exception('Unexpected side effect!');	// Should never occur. Only for PHPStan
+							}
+						}
+					?>
 				</div>
 				<div class="item date">
 					<time datetime="<?= $entry->machineReadableDate() ?>"><?= $entry->date() ?></time>
@@ -120,20 +115,9 @@
 							<?php if (FreshRSS_Context::userConf()->show_favicons): ?>
 								<img class="favicon" src="<?= $feed->favicon() ?>" alt="✇" loading="lazy" /><?php
 							endif; ?><span><?= $feed->name() ?></span></a></div>
-					<?php } ?>
-					<div class="author"><?php
-						$authors = $entry->authors();
-						if (is_array($authors)) {
-							foreach ($authors as $author) {
-								?>
-								<a href="<?= Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:' . str_replace(' ', '+', htmlspecialchars_decode($author, ENT_QUOTES))])) ?>">
-									<?= $author ?>
-								</a>
-								<?php
-							}
-						}
-						?>
-					</div>
+					<?php }
+						$this->renderHelper('index/authors');
+					?>
 					<div class="date">
 						<time datetime="<?= $entry->machineReadableDate() ?>"><?= $entry->date() ?></time>
 					</div>

+ 17 - 0
app/views/helpers/index/authors.phtml

@@ -0,0 +1,17 @@
+<?php
+	declare(strict_types=1);
+	/** @var FreshRSS_View $this */
+	if ($this->entry === null) {
+		return;
+	}
+?>
+<div class="author"><?= _t('gen.short.by_author') ?>
+<?php
+	$first = true;
+	foreach ($this->entry->authors() as $author) {
+		$href = Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:"' . htmlspecialchars_decode($author, ENT_QUOTES) . '"']));
+		?><?= $first ? '' : ' · ' ?><a href="<?= $href ?>" title="<?= _t('gen.action.filter') ?>"><?= $author ?></a><?php
+		$first = false;
+	}
+?>
+</div>

+ 2 - 11
app/views/helpers/index/normal/entry_header.phtml

@@ -15,7 +15,7 @@
 	if ($this->feed === null || $this->entry === null) {
 		return;
 	}
-?><ul class="horizontal-list flux_header website<?= $topline_website ?>" data-website-name="<?= $this->feed->name() ?>" data-article-authors="<?= implode(', ', $this->entry->authors()) ?>"><?php
+?><ul class="horizontal-list flux_header website<?= $topline_website ?>" data-website-name="<?= $this->feed->name() ?>" data-article-authors="<?= implode(' · ', $this->entry->authors()) ?>"><?php
 	if (FreshRSS_Auth::hasAccess()) {
 		if ($topline_read) {
 			?><li class="item manage"><?php
@@ -59,16 +59,7 @@
 	<li class="item titleAuthorSummaryDate">
 		<a target="_blank" rel="noreferrer" href="<?= $this->entry->link() ?>" class="item-element title<?= (($topline_thumbnail !== 'none') || $topline_summary) ? ' multiline' : '' ?>" dir="auto"><?= $this->entry->title() ?><?php
 		if ($topline_display_authors):
-			?><span class="author"><?php
-			$authors = $this->entry->authors();
-			if (is_array($authors)) {
-				$first = true;
-				foreach ($authors as $author) {
-					echo $first ? $author : ', ' . $author;
-					$first = false;
-				}
-			}
-			?></span><?php
+			?> <span class="author"><?= implode(' · ', $this->entry->authors()) ?></span><?php
 		endif;
 		?></a>
 	<?php

+ 13 - 28
app/views/index/normal.phtml

@@ -119,22 +119,14 @@ $today = @strtotime('today');
 									<img class="favicon" src="<?= $this->feed->favicon() ?>" alt="✇" loading="lazy" /><?php
 								endif; ?><span><?= $this->feed->name() ?></span></a>
 							</div>
-							<?php
+						<?php }
+						if (!empty($this->entry->authors())) {
+							$this->renderHelper('index/authors');
+							if ($this->feed === null || $this->entry === null) {
+								throw new Exception('Unexpected side effect!');	// Should never occur. Only for PHPStan
+							}
 						}
-
-						$authors = $this->entry->authors();
-						if (!empty($authors) && is_array($authors)) {
 						?>
-						<div class="author">
-							<?= _t('gen.short.by_author') ?>
-							<?php
-							foreach ($authors as $author) {
-								$href = Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:"' . htmlspecialchars_decode($author, ENT_QUOTES) . '"']));
-							?>
-							<a href="<?= $href ?>" title="<?= _t('gen.action.filter') ?>"><?= $author ?></a>
-							<?php } ?>
-						</div>
-						<?php } ?>
 						<div class="date"><?= $this->entry->date() ?></div>
 					</div>
 					<?php } ?>
@@ -158,21 +150,14 @@ $today = @strtotime('today');
 											<img class="favicon" src="<?= $this->feed->favicon() ?>" alt="✇" loading="lazy" /><?php
 										endif; ?><span><?= $this->feed->name() ?></span></a>
 									</div>
-									<?php
-								}
-								$authors = $this->entry->authors();
-								if (!empty($authors) && is_array($authors)) {
+								<?php }
+									if (!empty($this->entry->authors())) {
+										$this->renderHelper('index/authors');
+										if ($this->feed === null || $this->entry === null) {
+											throw new Exception('Unexpected side effect!');	// Should never occur. Only for PHPStan
+										}
+									}
 								?>
-								<div class="author">
-									<?= _t('gen.short.by_author') ?>
-									<?php
-									foreach ($authors as $author) {
-										$href = Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:"' . htmlspecialchars_decode($author, ENT_QUOTES) . '"']));
-									?>
-									<a href="<?= $href ?>" title="<?= _t('gen.action.filter') ?>"><?= $author ?></a>
-									<?php } ?>
-								</div>
-								<?php } ?>
 								<div class="date"><?= $this->entry->date() ?></div>
 							</div>
 						<?php