aboutsummaryrefslogtreecommitdiff
path: root/app/views/index/reader.phtml
blob: af51933cf014fd08abd593e79a6a4f2233a18998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
declare(strict_types=1);
/** @var FreshRSS_View $this */
if (!Minz_Request::paramBoolean('ajax')) {
	$this->partial('aside_feed');
	$this->partial('nav_menu');
}

call_user_func($this->callbackBeforeEntries, $this);

$lazyload = FreshRSS_Context::userConf()->lazyload;
$content_width = FreshRSS_Context::userConf()->content_width;
$MAX_TAGS_DISPLAYED = (int)FreshRSS_Context::userConf()->show_tags_max;
?>
<main id="stream" class="reader">
	<h1 class="title_hidden"><?= _t('conf.reading.view.reader') ?></h1>
	<div id="new-article">
		<a href="<?= Minz_Url::display(Minz_Request::currentRequest()) ?>"><?= _t('gen.js.new_article'); /* TODO: move string in JS*/ ?></a>
	</div><?php
	$lastEntry = null;
	$nbEntries = 0;
	/** @var FreshRSS_Entry */
	foreach ($this->entries as $item):
		$lastEntry = $item;
		$nbEntries++;
		ob_flush();
		/** @var FreshRSS_Entry */
		$item = Minz_ExtensionManager::callHook('entry_before_display', $item);
		if ($item == null) {
			continue;
		}
		$this->entry = $item;

		$tags = null;
		$firstTags = array();
		$remainingTags = array();

		if (FreshRSS_Context::userConf()->show_tags == 'h' || FreshRSS_Context::userConf()->show_tags == 'f' || FreshRSS_Context::userConf()->show_tags == 'b') {
			$tags = $this->entry->tags();
			if (!empty($tags)) {
				if ($MAX_TAGS_DISPLAYED > 0) {
					$firstTags = array_slice($tags, 0, $MAX_TAGS_DISPLAYED);
					$remainingTags = array_slice($tags, $MAX_TAGS_DISPLAYED);
				} else {
					$firstTags = $tags;
				}
			}
		}

		//We most likely already have the feed object in cache, otherwise make a request
		$feed = FreshRSS_CategoryDAO::findFeed($this->categories, $item->feedId()) ?? $item->feed() ?? FreshRSS_Feed::example();
	?><div class="flux<?= !$item->isRead() ? ' not_read' : '' ?><?= $item->isFavorite() ? ' favorite' : '' ?>" id="flux_<?= $item->id() ?>" data-priority="<?= $feed->priority() ?>">
		<article class="flux_content" dir="auto">

			<div class="content <?= $content_width ?>">
				<header>
					<?php
						$favoriteUrl = array('c' => 'entry', 'a' => 'bookmark', 'params' => array('id' => $item->id()));
						if ($item->isFavorite()) {
							$favoriteUrl['params']['is_favorite'] = 0;
						}
						$readUrl = array('c' => 'entry', 'a' => 'read', 'params' => array('id' => $item->id()));
						if ($item->isRead()) {
							$readUrl['params']['is_read'] = 0;
						}
					?>
					<div class="article-header-topline">
						<?php if (FreshRSS_Auth::hasAccess()) { ?>
							<a class="read" href="<?= Minz_Url::display($readUrl) ?>" title="<?= _t('conf.shortcut.mark_read') ?>"><?= _i($item->isRead() ? 'read' : 'unread') ?></a>
							<a class="bookmark" href="<?= Minz_Url::display($favoriteUrl) ?>" title="<?= _t('conf.shortcut.mark_favorite') ?>"><?= _i($item->isFavorite() ? 'starred' : 'non-starred') ?></a>
						<?php } ?>
						<?php if (FreshRSS_Context::userConf()->show_feed_name === 't') { ?>
							<a class="website" href="<?= _url('index', 'reader', 'get', 'f_' . $feed->id()) ?>" title="<?= _t('gen.action.filter') ?>">
								<?php if (FreshRSS_Context::userConf()->show_favicons): ?>
									<img class="favicon" src="<?= $feed->favicon() ?>" alt="✇" loading="lazy" /><?php
								endif; ?><span><?= $feed->name() ?></span></a>
						<?php } ?>
					</div>

					<?php if (FreshRSS_Context::userConf()->show_tags === 'h' || FreshRSS_Context::userConf()->show_tags === 'b') { ?>
						<div class="tags">
							<?php
							if (!empty($tags)) {
								?><?= _i('tag') ?><ul class="list-tags"><?php
								foreach ($firstTags as $tag) {
									?><li class="item tag"><a class="link-tag" href="<?= _url('index', 'index', 'search', '#' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES))) ?>" title="<?= _t('gen.action.filter') ?>">#<?= $tag ?></a></li><?php
								}

								if (!empty($remainingTags)) { // more than 7 tags: show dropdown menu ?>
									<li class="item tag">
										<div class="dropdown">
											<div id="dropdown-tags-<?= $this->entry->id() ?>" class="dropdown-target"></div>
											<a class="dropdown-toggle" href="#dropdown-tags-<?= $this->entry->id() ?>"><?= _i('down') ?></a>
											<ul class="dropdown-menu">
												<li class="dropdown-header"><?= _t('index.tag.related') ?></li>
												<?php
												foreach ($remainingTags as $tag) {
													?><li class="item"><a href="<?= _url('index', 'index', 'search', '#' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES))) ?>" title="<?= _t('gen.action.filter') ?>"><?= $tag ?></a></li><?php
												} ?>
											</ul>
											<a class="dropdown-close" href="#close">❌</a>
										</div>
									</li>
									<?php
								} ?>
								</ul><?php
							} ?>
						</div>
					<?php } ?>

					<h1 class="title"><a target="_blank" rel="noreferrer" class="go_website" href="<?= $item->link() ?>"><?= $item->title() ?></a></h1>
					<?php if (FreshRSS_Context::userConf()->show_author_date === 'h' || FreshRSS_Context::userConf()->show_author_date === 'b') { ?>
						<div class="subtitle">
							<?php if (FreshRSS_Context::userConf()->show_feed_name === 'a') { ?>
								<div class="website"><a href="<?= _url('index', 'reader', 'get', 'f_' . $feed->id()) ?>" title="<?= _t('gen.action.filter') ?>">
									<?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 = $item->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>
							<div class="date">
								<time datetime="<?= $item->machineReadableDate() ?>"><?= $item->date() ?></time>
							</div>
						</div>
					<?php } ?>
				</header>

				<div class="text">
					<?= $item->content(true) ?>
				</div>
				<?php
				$display_authors_date = FreshRSS_Context::userConf()->show_author_date === 'f' || FreshRSS_Context::userConf()->show_author_date === 'b';
				$display_tags = FreshRSS_Context::userConf()->show_tags === 'f' || FreshRSS_Context::userConf()->show_tags === 'b';

				if ($display_authors_date || $display_tags) {
					?>
					<footer>
						<?php if ($display_authors_date) { ?>
							<div class="subtitle">
								<?php if (FreshRSS_Context::userConf()->show_feed_name === 'a') { ?>
									<div class="website"><a href="<?= _url('index', 'reader', 'get', 'f_' . $feed->id()) ?>" title="<?= _t('gen.action.filter') ?>">
										<?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 = $item->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>
								<div class="date">
									<time datetime="<?= $item->machineReadableDate() ?>"><?= $item->date() ?></time>
								</div>
							</div>
							<?php
						}

						if ($display_tags) { ?>
							<div class="tags">
								<?php
								if (!empty($tags)) {
									?><?= _i('tag') ?><ul class="list-tags"><?php
									foreach ($firstTags as $tag) {
										?><li class="item tag"><a class="link-tag" href="<?= _url('index', 'index', 'search', '#' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES))) ?>" title="<?= _t('gen.action.filter') ?>">#<?= $tag ?></a></li><?php
									}

									if (!empty($remainingTags)) { // more than 7 tags: show dropdown menu ?>
										<li class="item tag">
											<div class="dropdown">
												<div id="dropdown-tags2-<?= $this->entry->id() ?>" class="dropdown-target"></div>
												<a class="dropdown-toggle" href="#dropdown-tags2-<?= $this->entry->id() ?>"><?= _i('down') ?></a>
												<ul class="dropdown-menu">
													<li class="dropdown-header"><?= _t('index.tag.related') ?></li>
													<?php
													foreach ($remainingTags as $tag) {
														?><li class="item"><a href="<?= _url('index', 'index', 'search', '#' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES))) ?>" title="<?= _t('gen.action.filter') ?>"><?= $tag ?></a></li><?php
													} ?>
												</ul>
												<a class="dropdown-close" href="#close">❌</a>
											</div>
										</li>
										<?php
									} ?>
									</ul><?php
								} ?>
							</div>
						<?php } ?>
					</footer>
					<?php
				} ?>
			</div>
		</article>
	</div><?php
	endforeach;

	if ($nbEntries > 0):
		call_user_func($this->callbackBeforePagination, $this, $nbEntries, $lastEntry);
		$this->renderHelper('stream-footer');
?></main><?php
	else:
		ob_end_clean();	//Discard the articles headers, as we have no articles
?>
<main id="stream" class="reader">
	<div id="new-article">
		<a href="<?= Minz_Url::display(Minz_Request::currentRequest()) ?>"><?= _t('gen.js.new_article'); /* TODO: move string in JS*/ ?></a>
	</div>
	<div class="prompt alert alert-warn">
		<h2 class="alert-head"><?= _t('index.feed.empty') ?></h2>
	</div>
</main>
<?php endif; ?>