aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-23 00:01:00 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-23 00:01:00 +0100
commit11b1d06b8c4672f7dab98f8de5a7f7f95eeeec12 (patch)
treeec96ddcb423771fd001c47b7822f9f6c66170767
parent2919b9a0b6c7a9e1c8b5ad7f3b6207bd86de2dbc (diff)
Chargement différé des iframe
Implémente https://github.com/marienfressinaud/FreshRSS/issues/313 (uniquement pour la vue en articles repliés)
-rw-r--r--app/views/helpers/view/normal_view.phtml42
-rw-r--r--app/views/helpers/view/reader_view.phtml3
-rw-r--r--lib/lib_rss.php8
-rw-r--r--public/scripts/main.js2
4 files changed, 32 insertions, 23 deletions
diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml
index f21a2bdd9..4307c2113 100644
--- a/app/views/helpers/view/normal_view.phtml
+++ b/app/views/helpers/view/normal_view.phtml
@@ -4,25 +4,25 @@ $this->partial ('aside_flux');
$this->partial ('nav_menu');
if (!empty($this->entries)) {
-?>
+ $display_today = true;
+ $display_yesterday = true;
+ $display_others = true;
-<div id="stream" class="normal<?php echo $this->conf->displayPosts () === 'no' ? ' hide_posts' : ''; ?>">
- <?php
- $display_today = true;
- $display_yesterday = true;
- $display_others = true;
+ $logged = !login_is_conf ($this->conf) || is_logged ();
+ $shaarli = $this->conf->sharing ('shaarli');
+ $poche = $this->conf->sharing ('poche');
+ $diaspora = $this->conf->sharing ('diaspora');
+ $twitter = $this->conf->sharing ('twitter');
+ $google_plus = $this->conf->sharing ('g+');
+ $facebook = $this->conf->sharing ('facebook');
+ $email = $this->conf->sharing ('email');
+ $print = $this->conf->sharing ('print');
+ $today = $this->today;
+ $hidePosts = $this->conf->displayPosts() === 'no';
+ $lazyload = $this->conf->lazyload() === 'yes';
+?>
- $logged = !login_is_conf ($this->conf) || is_logged ();
- $shaarli = $this->conf->sharing ('shaarli');
- $poche = $this->conf->sharing ('poche');
- $diaspora = $this->conf->sharing ('diaspora');
- $twitter = $this->conf->sharing ('twitter');
- $google_plus = $this->conf->sharing ('g+');
- $facebook = $this->conf->sharing ('facebook');
- $email = $this->conf->sharing ('email');
- $print = $this->conf->sharing ('print');
- $today = $this->today;
- ?>
+<div id="stream" class="normal<?php echo $hidePosts ? ' hide_posts' : ''; ?>">
<?php foreach ($this->entries as $item) { ?>
<?php if ($display_today && $item->isDay (FreshRSS_Days::TODAY, $today)) { ?>
@@ -48,7 +48,7 @@ if (!empty($this->entries)) {
<div class="flux<?php echo !$item->isRead () ? ' not_read' : ''; ?><?php echo $item->isFavorite () ? ' favorite' : ''; ?>" id="flux_<?php echo $item->id (); ?>">
<ul class="horizontal-list flux_header"><?php
- if (!login_is_conf ($this->conf) || is_logged ()) {
+ if ($logged) {
if ($this->conf->toplineRead ()) {
?><li class="item manage"><?php
?><a class="read" href="<?php echo _url ('entry', 'read', 'id', $item->id (), 'is_read', $item->isRead () ? 0 : 1); ?>"><?php
@@ -77,15 +77,15 @@ if (!empty($this->entries)) {
<?php
$author = $item->author ();
echo $author != '' ? '<div class="author">' . Minz_Translate::t ('by_author', $author) . '</div>' : '';
- if($this->conf->lazyload() == 'yes') {
- echo lazyimg($item->content ());
+ if ($lazyload) {
+ echo $hidePosts ? lazyIframe(lazyimg($item->content())) : lazyimg($item->content());
} else {
echo $item->content();
}
?>
</div>
<ul class="horizontal-list bottom"><?php
- if (!login_is_conf ($this->conf) || is_logged ()) {
+ if ($logged) {
if ($this->conf->bottomlineRead ()) {
?><li class="item manage"><?php
?><a class="read" href="<?php echo _url ('entry', 'read', 'id', $item->id (), 'is_read', $item->isRead () ? 0 : 1); ?>"><?php
diff --git a/app/views/helpers/view/reader_view.phtml b/app/views/helpers/view/reader_view.phtml
index e28af6ade..47254f74e 100644
--- a/app/views/helpers/view/reader_view.phtml
+++ b/app/views/helpers/view/reader_view.phtml
@@ -2,6 +2,7 @@
$this->partial ('nav_menu');
if (!empty($this->entries)) {
+ $lazyload = $this->conf->lazyload() === 'yes';
?>
<div id="stream" class="reader">
@@ -26,7 +27,7 @@ if (!empty($this->entries)) {
</div>
<?php
- if($this->conf->lazyload() == 'yes') {
+ if ($lazyload) {
echo lazyimg($item->content ());
} else {
echo $item->content();
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 4ef06ddbc..a1fadcb24 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -288,6 +288,14 @@ function lazyimg($content) {
);
}
+function lazyIframe($content) {
+ return preg_replace(
+ '/<iframe([^>]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i',
+ '<iframe$1src="about:blank" data-original="$2"$3>',
+ $content
+ );
+}
+
function uTimeString() {
$t = @gettimeofday();
return $t['sec'] . str_pad($t['usec'], 6, '0');
diff --git a/public/scripts/main.js b/public/scripts/main.js
index 3bd23a669..ef05eb2fb 100644
--- a/public/scripts/main.js
+++ b/public/scripts/main.js
@@ -136,7 +136,7 @@ function mark_favorite(active) {
function toggleContent(new_active, old_active) {
if (does_lazyload) {
- new_active.find('img[data-original]').each(function () {
+ new_active.find('img[data-original], iframe[data-original]').each(function () {
this.setAttribute('src', this.getAttribute('data-original'));
this.removeAttribute('data-original');
});