Skip to content

Commit

Permalink
New: Sharing articles from the article title line (FreshRSS#6395)
Browse files Browse the repository at this point in the history
* enable option

* Update entry_header.phtml

* frss.css

* fix print sharing

* Light refactoring

* fix

---------

Co-authored-by: Alexandre Alapetite <[email protected]>
  • Loading branch information
math-GH and Alkarex authored Jun 30, 2024
1 parent de477e1 commit 7aa3d9f
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 39 deletions.
1 change: 1 addition & 0 deletions app/Controllers/configureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function displayAction(): void {
FreshRSS_Context::userConf()->content_width = Minz_Request::paramString('content_width') ?: 'thin';
FreshRSS_Context::userConf()->topline_read = Minz_Request::paramBoolean('topline_read');
FreshRSS_Context::userConf()->topline_favorite = Minz_Request::paramBoolean('topline_favorite');
FreshRSS_Context::userConf()->topline_sharing = Minz_Request::paramBoolean('topline_sharing');
FreshRSS_Context::userConf()->topline_date = Minz_Request::paramBoolean('topline_date');
FreshRSS_Context::userConf()->topline_link = Minz_Request::paramBoolean('topline_link');
FreshRSS_Context::userConf()->topline_website = Minz_Request::paramString('topline_website');
Expand Down
1 change: 1 addition & 0 deletions app/Models/UserConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @property bool $topline_date
* @property bool $topline_display_authors
* @property bool $topline_favorite
* @property bool $topline_sharing
* @property bool $topline_link
* @property bool $topline_read
* @property bool $topline_summary
Expand Down
4 changes: 3 additions & 1 deletion app/views/configure/display.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
data-leave-validation="<?= FreshRSS_Context::userConf()->topline_favorite ?>" /></td>
<td><input type="checkbox" disabled="disabled" /></td>
<td><input type="checkbox" disabled="disabled" /></td>
<td><input type="checkbox" disabled="disabled" /></td>
<td><input type="checkbox" name="topline_sharing" value="1"<?=
FreshRSS_Context::userConf()->topline_sharing ? ' checked="checked"' : '' ?>
data-leave-validation="<?= FreshRSS_Context::userConf()->topline_sharing ?>" /></td>
<td><input type="checkbox" name="topline_summary" value="1"<?=
FreshRSS_Context::userConf()->topline_summary ? 'checked="checked"' : '' ?>
data-leave-validation="<?= FreshRSS_Context::userConf()->topline_summary ?>" /></td>
Expand Down
34 changes: 1 addition & 33 deletions app/views/helpers/index/normal/entry_bottom.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,7 @@
<a class="dropdown-toggle" href="#dropdown-share-<?= $this->entry->id() ?>">
<?= _i('share') ?><?= _t('index.share') ?>
</a>

<ul class="dropdown-menu">
<li class="dropdown-header"><?= _t('index.share') ?> <a href="<?= _url('configure', 'integration') ?>"><?= _i('configure') ?></a></li><?php
$id = $this->entry->id();
$link = $this->entry->link();
$title = $this->entry->title() . ' · ' . ($this->feed === null ? '' : $this->feed->name());
foreach (FreshRSS_Context::userConf()->sharing as $share_options) {
$share = FreshRSS_Share::get($share_options['type']);
if ($share === null) {
continue;
}
$cssClass = $share->isDeprecated() ? ' error' : '';
$share_options['id'] = $id;
$share_options['link'] = $link;
$share_options['title'] = $title;
$share->update($share_options);
?><li class="item share<?= $cssClass ?>">
<?php if ('GET' === $share->method()) {
if ($share->HTMLtag() !== 'button') {?>
<a target="_blank" rel="noreferrer" href="<?= $share->url() ?>" data-type="<?= $share->type() ?>"><?= $share->name() ?></a>
<?php } else { ?>
<button type="button" class="as-link" data-url="<?= $share->url() ?>" data-type="<?= $share->type() ?>" data-title="<?= htmlspecialchars($title) ?>"><?= $share->name() ?></button>
<?php
}
} else {?>
<a href="POST"><?= $share->name() ?></a>
<form method="POST" action="<?= $share->url() ?>" disabled="disabled">
<input type="hidden" value="<?= $link ?>" name="<?= $share->field() ?>"/>
</form>
<?php } ?>
</li><?php
}
?></ul>
<?php $this->renderHelper('index/normal/entry_share_menu'); ?>
<a class="dropdown-close" href="#close">❌</a>
</div>
<?php } ?>
Expand Down
13 changes: 13 additions & 0 deletions app/views/helpers/index/normal/entry_header.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** @var FreshRSS_View $this */
$topline_read = FreshRSS_Context::userConf()->topline_read;
$topline_favorite = FreshRSS_Context::userConf()->topline_favorite;
$topline_sharing = FreshRSS_Context::userConf()->topline_sharing;
$topline_website = FreshRSS_Context::userConf()->topline_website;
$topline_thumbnail = FreshRSS_Context::userConf()->topline_thumbnail;
$topline_summary = FreshRSS_Context::userConf()->topline_summary;
Expand Down Expand Up @@ -72,6 +73,18 @@
endif; ?>
<?php if ($topline_date) { ?><span class="item-element date"><time datetime="<?= $this->entry->machineReadableDate() ?>"><?= $this->entry->date() ?></time>&nbsp;</span><?php } ?>
</li>
<?php if ($topline_sharing) { ?>
<li class="item share">
<div class="item-element dropdown">
<div id="dropdown-share2-<?= $this->entry->id() ?>" class="dropdown-target"></div>
<a class="dropdown-toggle" href="#dropdown-share2-<?= $this->entry->id() ?>" title="<?= _t('index.share') ?>">
<?= _i('share') ?>
</a>
<?php $this->renderHelper('index/normal/entry_share_menu'); ?>
<a class="dropdown-close" href="#close">❌</a>
</div>
</li>
<?php } ?>
<?php if ($topline_link) { ?><li class="item link"><a target="_blank" rel="noreferrer" href="<?= $this->entry->link() ?>" class="item-element" title="<?=
_t('conf.shortcut.see_on_website') ?>"><?= _i('link') ?></a></li><?php } ?>
</ul>
37 changes: 37 additions & 0 deletions app/views/helpers/index/normal/entry_share_menu.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/** @var FreshRSS_View $this */
//TODO: To reduce output size, replace by an on-demand JavaScript menu, potentially using HTML template element
?>
<ul class="dropdown-menu">
<li class="dropdown-header"><?= _t('index.share') ?> <a href="<?= _url('configure', 'integration') ?>"><?= _i('configure') ?></a></li><?php
$id = $this->entry->id();
$link = $this->entry->link();
$title = $this->entry->title() . ' · ' . ($this->feed === null ? '' : $this->feed->name());
foreach (FreshRSS_Context::userConf()->sharing as $share_options) {
$share = FreshRSS_Share::get($share_options['type']);
if ($share === null) {
continue;
}
$cssClass = $share->isDeprecated() ? ' error' : '';
$share_options['id'] = $id;
$share_options['link'] = $link;
$share_options['title'] = $title;
$share->update($share_options);
?><li class="item share<?= $cssClass ?>">
<?php if ('GET' === $share->method()) {
if ($share->HTMLtag() !== 'button') {?>
<a target="_blank" rel="noreferrer" href="<?= $share->url() ?>" data-type="<?= $share->type() ?>"><?= $share->name() ?></a>
<?php } else { ?>
<button type="button" class="as-link" data-url="<?= $share->url() ?>" data-type="<?= $share->type() ?>" data-title="<?= htmlspecialchars($title) ?>"><?= $share->name() ?></button>
<?php
}
} else {?>
<a href="POST"><?= $share->name() ?></a>
<form method="POST" action="<?= $share->url() ?>" disabled="disabled">
<input type="hidden" value="<?= $link ?>" name="<?= $share->field() ?>"/>
</form>
<?php } ?>
</li><?php
}
?></ul>
1 change: 1 addition & 0 deletions config-user.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@

'topline_read' => true,
'topline_favorite' => true,
'topline_sharing' => false,
'topline_website' => 'full',
'topline_thumbnail' => 'none',
'topline_summary' => false,
Expand Down
23 changes: 18 additions & 5 deletions p/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,21 @@ function mark_favorite(div) {
const freshrssOpenArticleEvent = document.createEvent('Event');
freshrssOpenArticleEvent.initEvent('freshrss:openArticle', true, true);

function loadLazyImages(rootElement) {
rootElement.querySelectorAll('img[data-original], iframe[data-original]').forEach(function (el) {
el.src = el.getAttribute('data-original');
el.removeAttribute('data-original');
});
}

function toggleContent(new_active, old_active, skipping) {
// If skipping, move current without activating or marking as read
if (!new_active) {
return;
}

if (context.does_lazyload && !skipping) {
new_active.querySelectorAll('img[data-original], iframe[data-original]').forEach(function (el) {
el.src = el.getAttribute('data-original');
el.removeAttribute('data-original');
});
loadLazyImages(new_active);
}

if (old_active !== new_active) {
Expand Down Expand Up @@ -1101,7 +1105,16 @@ function init_stream(stream) {
for (let i = 0; i < document.styleSheets.length; i++) {
tmp_window.document.writeln('<link href="' + document.styleSheets[i].href + '" rel="stylesheet" type="text/css" />');
}
tmp_window.document.writeln(el.closest('.flux_content').querySelector('.content').innerHTML);
const flux_content = el.closest('.flux_content');
let content_el = null;
if (flux_content) {
content_el = el.closest('.flux_content').querySelector('.content');
}
if (content_el === null) {
content_el = el.closest('.flux').querySelector('.flux_content .content');
}
loadLazyImages(content_el);
tmp_window.document.writeln(content_el.innerHTML);
tmp_window.document.close();
tmp_window.focus();
tmp_window.print();
Expand Down
2 changes: 2 additions & 0 deletions p/themes/base-theme/frss.css
Original file line number Diff line number Diff line change
Expand Up @@ -1257,12 +1257,14 @@ input[type="search"] {

.flux .flux_header .item.manage .item-element,
.flux .flux_header .item.website .item-element,
.flux .flux_header .item.share .dropdown-toggle,
.flux .flux_header .item.link .item-element {
padding-left: var(--frss-padding-flux-items);
padding-right: var(--frss-padding-flux-items);
}

.flux .item.manage,
.flux .flux_header > .item.share,
.flux .item.link {
width: calc(1rem + 2 * var(--frss-padding-flux-items));
}
Expand Down
2 changes: 2 additions & 0 deletions p/themes/base-theme/frss.rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -1257,12 +1257,14 @@ input[type="search"] {

.flux .flux_header .item.manage .item-element,
.flux .flux_header .item.website .item-element,
.flux .flux_header .item.share .dropdown-toggle,
.flux .flux_header .item.link .item-element {
padding-right: var(--frss-padding-flux-items);
padding-left: var(--frss-padding-flux-items);
}

.flux .item.manage,
.flux .flux_header > .item.share,
.flux .item.link {
width: calc(1rem + 2 * var(--frss-padding-flux-items));
}
Expand Down

0 comments on commit 7aa3d9f

Please sign in to comment.