diff options
| author | 2024-02-26 09:01:03 +0100 | |
|---|---|---|
| committer | 2024-02-26 09:01:03 +0100 | |
| commit | 39cc1c11ec596176e842cc98e6a54337e3c04d7e (patch) | |
| tree | dab89beb80268acb5e4bd58dfc55297bd30a8486 /app/views/helpers | |
| parent | 25166c218be4e1ce1cb098de274a231b623d527e (diff) | |
New feature: shareable user query (#6052)
* New feature: shareable user query
Share the output of a user query by RSS / HTML / OPML with other people through unique URLs.
Replaces the global admin token, which was the only option (but unsafe) to share RSS outputs with other people.
Also add a new HTML output for people without an RSS reader.
fix https://github.com/FreshRSS/FreshRSS/issues/3066#issuecomment-648977890
fix https://github.com/FreshRSS/FreshRSS/issues/3178#issuecomment-769435504
* Remove unused method
* Fix token saving
* Implement HTML view
* Update i18n for master token
* Revert i18n get_favorite
* Fix missing i18n for user queries from before this PR
* Remove irrelevant tests
* Add link to RSS version
* Fix getGet
* Fix getState
* Fix getSearch
* Alternative getSearch
* Default getOrder
* Explicit default state
* Fix test
* Add OPML sharing
* Remove many redundant SQL queries from original implementation of user queries
* Fix article tags
* Use default user settings
* Prepare public search
* Fixes
* Allow user search on article tags
* Implement user search
* Revert filter bug
* Revert wrong SQL left outer join change
* Implement checkboxes
* Safe check of OPML
* Fix label
* Remove RSS button to favour new sharing method
That sharing button was using a global admin token
* First version of HTTP 304
* Disallow some recusrivity
fix https://github.com/FreshRSS/FreshRSS/issues/6086
* Draft of nav
* Minor httpConditional
* Add support for offset for pagination
* Fix offset pagination
* Fix explicit order ASC
* Add documentation
* Help links i18n
* Note about deprecated master token
* Typo
* Doc about format
Diffstat (limited to 'app/views/helpers')
| -rw-r--r-- | app/views/helpers/configure/query.phtml | 67 | ||||
| -rw-r--r-- | app/views/helpers/export/articles.phtml | 2 | ||||
| -rw-r--r-- | app/views/helpers/feed/update.phtml | 3 | ||||
| -rw-r--r-- | app/views/helpers/htmlPagination.phtml | 21 | ||||
| -rw-r--r-- | app/views/helpers/index/article.phtml | 117 | ||||
| -rw-r--r-- | app/views/helpers/index/normal/entry_header.phtml | 3 | ||||
| -rw-r--r-- | app/views/helpers/index/tags.phtml | 42 |
7 files changed, 234 insertions, 21 deletions
diff --git a/app/views/helpers/configure/query.phtml b/app/views/helpers/configure/query.phtml index 145425271..49ffbad87 100644 --- a/app/views/helpers/configure/query.phtml +++ b/app/views/helpers/configure/query.phtml @@ -7,7 +7,6 @@ ?> <div class="post"> <h2><?= $this->query->getName() ?></h2> - <div> <a href="<?= $this->query->getUrl() ?>"><?= _i('link') ?> <?= _t('gen.action.filter') ?></a> </div> @@ -18,15 +17,53 @@ <div class="form-group"> <label class="group-name" for="name"><?= _t('conf.query.name') ?></label> <div class="group-controls"> - <input type="text" name="name" id="name" value="<?= $this->query->getName() ?>" /> + <input type="text" name="name" id="name" value="<?= $this->query->getName() ?>" /> + <input type="hidden" name="query[token]" id="query_token" value="<?= $this->query->getToken() ?>" /> </div> </div> - <legend><?= _t('conf.query.filter') ?></legend> + <legend><?= _t('conf.query.share') ?></legend> + <div class="form-group"> + <div class="group-controls"> + <label class="checkbox" for="shareRss"> + <input type="checkbox" name="query[shareRss]" id="shareRss" value="1" <?= $this->query->shareRss() ? 'checked="checked"' : ''?> /> + <?= _t('conf.query.filter.shareRss') ?> + </label> + <?php if ($this->query->sharedUrlRss() !== ''): ?> + <ul> + <li><a href="<?= $this->query->sharedUrlHtml() ?>"><?= _i('link') ?> <?= _t('conf.query.share.html') ?></a></li> + <li><a href="<?= $this->query->sharedUrlRss() ?>"><?= _i('link') ?> <?= _t('conf.query.share.rss') ?></a></li> + </ul> + <?php endif; ?> + </div> + <div class="group-controls"> + <label class="checkbox" for="shareOpml"> + <input type="checkbox" name="query[shareOpml]" id="shareOpml" value="1" <?= $this->query->shareOpml() && $this->query->safeForOpml() ? 'checked="checked"' : '' ?> + <?= $this->query->safeForOpml() ? '' : 'disabled="disabled"' ?> /> + <?= _t('conf.query.filter.shareOpml') ?> + </label> + <?php if ($this->query->sharedUrlOpml() !== ''): ?> + <ul> + <li><a href="<?= $this->query->sharedUrlOpml() ?>"><?= _i('link') ?> <?= _t('conf.query.share.opml') ?></a></li> + </ul> + <?php endif; ?> + </div> + <p class="help"><?= _i('help') ?> <?= _t('conf.query.share.help') ?></a></p> + <p class="help"><?= _i('help') ?> <?= _t('conf.query.help') ?></a></p> + </div> + + <div class="form-group form-actions"> + <div class="group-controls"> + <button type="submit" class="btn btn-important"><?= _t('gen.action.submit') ?></button> + </div> + </div> + + <legend><?= _t('conf.query.filter') ?></legend> <div class="form-group"> <label class="group-name" for=""><?= _t('conf.query.filter.search') ?></label> <div class="group-controls"> <input type="text" id="query_search" name="query[search]" value="<?= htmlspecialchars($this->query->getSearch()->getRawInput(), ENT_COMPAT, 'UTF-8') ?>"/> + <p class="help"><?= _i('help') ?> <?= _t('gen.menu.search_help') ?></a></p> </div> </div> <div class="form-group"> @@ -58,22 +95,24 @@ <label class="group-name" for="query_get"><?= _t('conf.query.filter.type') ?></label> <div class="group-controls"> <select name="query[get]" id="query_get" size="10"> - <option value=""></option> - <option value="s" <?= 's' === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= _t('conf.query.get_favorite') ?></option> + <option value="a" <?= in_array($this->query->getGet(), ['', 'a'], true) ? 'selected="selected"' : '' ?>><?= _t('index.feed.title') ?></option> + <option value="i" <?= 'i' === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= _t('index.menu.important') ?></option> + <option value="s" <?= 's' === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= _t('index.feed.title_fav') ?></option> + <option value="T" <?= 'T' === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= _t('index.menu.tags') ?></option> + <optgroup label="<?= _t('conf.query.filter.tags') ?>"> + <?php foreach ($this->tags as $tag): ?> + <option value="t_<?= $tag->id() ?>" <?= "t_{$tag->id()}" === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= $tag->name() ?></option> + <?php endforeach?> + </optgroup> <optgroup label="<?= _t('conf.query.filter.categories') ?>"> <?php foreach ($this->categories as $category): ?> <option value="c_<?= $category->id() ?>" <?= "c_{$category->id()}" === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= $category->name() ?></option> <?php endforeach?> </optgroup> <optgroup label="<?= _t('conf.query.filter.feeds') ?>"> - <?php foreach ($this->feeds as $feed): ?> - <option value="f_<?= $feed->id() ?>" <?= "f_{$feed->id()}" === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= $feed->name() ?></option> - <?php endforeach?> - </optgroup> - <optgroup label="<?= _t('conf.query.filter.tags') ?>"> - <?php foreach ($this->tags as $tag): ?> - <option value="t_<?= $tag->id() ?>" <?= "t_{$tag->id()}" === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= $tag->name() ?></option> - <?php endforeach?> + <?php foreach ($this->feeds as $feed): ?> + <option value="f_<?= $feed->id() ?>" <?= "f_{$feed->id()}" === $this->query->getGet() ? 'selected="selected"' : '' ?>><?= $feed->name() ?></option> + <?php endforeach?> </optgroup> </select> </div> @@ -83,8 +122,8 @@ <div class="group-controls"> <select name="query[order]" id="query_order"> <option value=""></option> - <option value="ASC" <?= 'ASC' === $this->query->getOrder() ? 'selected="selected"' : '' ?>><?= _t('conf.query.order_asc') ?></option> <option value="DESC" <?= 'DESC' === $this->query->getOrder() ? 'selected="selected"' : '' ?>><?= _t('conf.query.order_desc') ?></option> + <option value="ASC" <?= 'ASC' === $this->query->getOrder() ? 'selected="selected"' : '' ?>><?= _t('conf.query.order_asc') ?></option> </select> </div> </div> diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml index 6903c3c69..40390d832 100644 --- a/app/views/helpers/export/articles.phtml +++ b/app/views/helpers/export/articles.phtml @@ -24,7 +24,7 @@ foreach ($this->entries as $entry) { continue; } - $feed = $this->feed ?? FreshRSS_CategoryDAO::findFeed($this->categories, $entry->feedId()); + $feed = $this->feed ?? FreshRSS_Category::findFeed($this->categories, $entry->feedId()); $entry->_feed($feed); $article = $entry->toGReader('freshrss', $this->entryIdsTagNames['e_' . $entry->id()] ?? []); diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index 13a751c09..9d3aa59fa 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -1,9 +1,6 @@ <?php declare(strict_types=1); /** @var FreshRSS_View $this */ - if ($this->feed === null) { - throw new FreshRSS_Context_Exception('Feed not initialised!'); - } ?> <div class="post" id="feed_update"> <h1><?= $this->feed->name() ?></h1> diff --git a/app/views/helpers/htmlPagination.phtml b/app/views/helpers/htmlPagination.phtml new file mode 100644 index 000000000..d1f895425 --- /dev/null +++ b/app/views/helpers/htmlPagination.phtml @@ -0,0 +1,21 @@ +<?php + declare(strict_types=1); + /** @var FreshRSS_View $this */ +?> +<nav class="nav-pagination nav-list"> + <ul class="pagination"> + <?php if (FreshRSS_Context::$offset > 0): ?> + <li class="item pager-first"> + <a href="<?= $this->userQuery->sharedUrlHtml() . '&nb=' . FreshRSS_Context::$number ?>">« <?= _t('conf.logs.pagination.first') ?></a> + </li> + <li class="item pager-previous"> + <a href="<?= $this->userQuery->sharedUrlHtml() . '&nb=' . FreshRSS_Context::$number . + '&offset=' . max(0, FreshRSS_Context::$offset - FreshRSS_Context::$number) ?>">‹ <?= _t('conf.logs.pagination.previous') ?></a> + </li> + <?php endif; ?> + <li class="item pager-next"> + <a href="<?= $this->userQuery->sharedUrlHtml() . '&nb=' . FreshRSS_Context::$number . + '&offset=' . (FreshRSS_Context::$offset + FreshRSS_Context::$number) ?>"><?= _t('conf.logs.pagination.next') ?> ›</a> + </li> + </ul> +</nav> diff --git a/app/views/helpers/index/article.phtml b/app/views/helpers/index/article.phtml new file mode 100644 index 000000000..caf06359d --- /dev/null +++ b/app/views/helpers/index/article.phtml @@ -0,0 +1,117 @@ +<?php + declare(strict_types=1); + /** @var FreshRSS_View $this */ + $entry = $this->entry; + $feed = $this->feed; +?> +<article class="flux_content" dir="auto"> +<div class="content <?= FreshRSS_Context::userConf()->content_width ?>"> + <header> + <?php + $favoriteUrl = ['c' => 'entry', 'a' => 'bookmark', 'params' => ['id' => $entry->id()]]; + if ($entry->isFavorite()) { + $favoriteUrl['params']['is_favorite'] = 0; + } + $readUrl = ['c' => 'entry', 'a' => 'read', 'params' => ['id' => $entry->id()]]; + if ($entry->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($entry->isRead() ? 'read' : 'unread') ?></a> + <a class="bookmark" href="<?= Minz_Url::display($favoriteUrl) ?>" title="<?= _t('conf.shortcut.mark_favorite') ?>"><?= _i($entry->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 (in_array(FreshRSS_Context::userConf()->show_tags, ['b', 'h'], true)) { + $this->renderHelper('index/tags'); + } + ?> + + <h1 class="title"><a target="_blank" rel="noreferrer" class="go_website" href="<?= $entry->link() ?>"><?= $entry->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="<?= $this->internal_rendering ? $feed->website() : _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 = $entry->authors(); + if (is_array($authors)) { + if ($this->internal_rendering): + foreach ($authors as $author): ?> + <?= $author ?> + <?php endforeach; + else: + foreach ($authors as $author): ?> + <a href="<?= Minz_Url::display(Minz_Request::modifiedCurrentRequest(['search' => 'author:' . str_replace(' ', '+', htmlspecialchars_decode($author, ENT_QUOTES))])) ?>"> + <?= $author ?> + </a> + <?php endforeach; + endif; + } ?> + </div> + <div class="date"> + <time datetime="<?= $entry->machineReadableDate() ?>"><?= $entry->date() ?></time> + </div> + </div> + <?php } ?> + </header> + + <div class="text"> + <?= $entry->content(true) ?> + </div> + <?php + $display_authors_date = in_array(FreshRSS_Context::userConf()->show_author_date, ['b', 'f'], true); + $display_tags = in_array(FreshRSS_Context::userConf()->show_tags, ['b', 'f'], true); + + 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 = $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> + <div class="date"> + <time datetime="<?= $entry->machineReadableDate() ?>"><?= $entry->date() ?></time> + </div> + </div> + <?php + } + + if ($display_tags) { + $this->renderHelper('index/tags'); + } + ?> + </footer> + <?php + } ?> +</div> +</article> diff --git a/app/views/helpers/index/normal/entry_header.phtml b/app/views/helpers/index/normal/entry_header.phtml index b324a5949..f550dfa21 100644 --- a/app/views/helpers/index/normal/entry_header.phtml +++ b/app/views/helpers/index/normal/entry_header.phtml @@ -1,9 +1,6 @@ <?php declare(strict_types=1); /** @var FreshRSS_View $this */ - if ($this->feed === null) { - throw new FreshRSS_Context_Exception('Feed not initialised!'); - } $topline_read = FreshRSS_Context::userConf()->topline_read; $topline_favorite = FreshRSS_Context::userConf()->topline_favorite; $topline_website = FreshRSS_Context::userConf()->topline_website; diff --git a/app/views/helpers/index/tags.phtml b/app/views/helpers/index/tags.phtml new file mode 100644 index 000000000..8f67784dd --- /dev/null +++ b/app/views/helpers/index/tags.phtml @@ -0,0 +1,42 @@ +<?php + declare(strict_types=1); + /** @var FreshRSS_View $this */ + [$firstTags,$remainingTags] = $this->entry->tagsFormattingHelper(); +?> +<div class="tags"> +<?php if (!empty($firstTags)): ?> + <?= _i('tag') ?><ul class="list-tags"> + <?php if (Minz_Request::controllerName() === 'index'): ?> + <?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 endforeach; ?> + <?php else: // API public access ?> + <?php foreach ($firstTags as $tag): ?> + <li class="item tag"><a class="link-tag" href="<?= $this->html_url . '&search=%23' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES)) ?>" title="<?= _t('gen.action.filter') ?>">#<?= $tag ?></a></li> + <?php endforeach; ?> + <?php endif; ?> + + <?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 if (Minz_Request::controllerName() === 'index'): ?> + <?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 endforeach; ?> + <?php else: ?> + <?php foreach ($remainingTags as $tag): ?> + <li class="item tag"><a class="link-tag" href="<?= $this->html_url . '&search=%23' . str_replace(' ', '+', htmlspecialchars_decode($tag, ENT_QUOTES)) ?>" title="<?= _t('gen.action.filter') ?>">#<?= $tag ?></a></li> + <?php endforeach; ?> + <?php endif; ?> + </ul> + <a class="dropdown-close" href="#close">❌</a> + </div> + </li> + <?php endif; ?> + </ul> +<?php endif; ?> +</div> |
