Преглед изворни кода

Chargement différé des iframe

Implémente https://github.com/marienfressinaud/FreshRSS/issues/313
(uniquement pour la vue en articles repliés)
Alexandre Alapetite пре 12 година
родитељ
комит
11b1d06b8c

+ 21 - 21
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

+ 2 - 1
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();

+ 8 - 0
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');

+ 1 - 1
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');
 		});