Jump to content
babyewok

Trouble with images in rss feed block...they work, but sometimes one doesn't load

Recommended Posts

OK So I am using the rss feed block to show the three latest items from a wordpress blog that is on the same domain as the prestashop store (I have to use feedburner to do this as by default the blog can't be on the same domain for some weird reason).  Anyway, after much faffing I was able to show the featured image for each post on the feed. 

However, randomly the 3rd image doesn't load.  For that image, the source code on the page reads: <img src(unknown) .....  Even though this image was working fine when it was the 1st or 2nd post, sometimes when it gets demoted to 3rd place, the image just isn't showing, even though it is present in the rss feed! 

The feed is structured like this: 

<TITLE>Post title</TITLE>
		<LINK>http://website.com/blog/2018/02/post/</LINK>
		<PUBDATE>Mon, 15 Feb 2018 08:39:00 +0000</PUBDATE>
		<DC:CREATOR><![CDATA[Kitty &#38; Dulcie]]></DC:CREATOR>
		<CATEGORY><![CDATA[Uncategorised]]></CATEGORY>
		<CATEGORY><![CDATA[sale]]></CATEGORY>

		<GUID isPermaLink="false"></GUID>
		<DESCRIPTION><![CDATA[<div><img width="283" height="185" src="http://website.com/blog/wp-content/uploads/2018/03/image-283x185.jpeg" class="attachment-my-rss-thumb size-my-rss-thumb wp-post-image" alt="Blah blah" srcset="http://website.com/blog/wp-content/uploads/2018/03/image-283x185.jpeg 283w, http://website.com/blog/wp-content/uploads/2018/03/image-665x435.jpeg 665w" sizes="(max-width: 283px) 100vw, 283px" /></div> Blah Blah blah [&#8230;]]]></DESCRIPTION>
		</ITEM>

and blockrss.php reads at line 150:

								// First image
								if (isset($xmlValues['content']) && $xmlValues['content'])
								{
									preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/', $xmlValues['content'], $image);
									if (array_key_exists(1, $image) && $image[1])
									{
										if ($image[1][0] == '/')
											$image[1] = 'http:'.$image[1];
										// Try if distant image exist : timeout 0.3s
										$context = stream_context_create(array('http' => array('timeout' => 0.3)));
										if (file_get_contents($image[1], false, $context, -1, 1) !== false)
											$xmlValues['image'] = $image[1];
										
									}
									$text = $xmlValues['content']; 
									$xmlValues['text'] =  preg_replace("/<img[^>]+\>/i", "", $text); 
									
								}

You can see I added 'text' to strip out the image from the content.  I tried all sorts and the only way I could pull the image was to put it in the content!

The template looks like this:

<div id="rss_block">
	<h2>{$title}</h2>
	<div class="block_content">
		{if $rss_links}
	
			<ul>{foreach from=$rss_links item='rss_link'}
				<li><div class="blog-img"><a href="{$rss_link.url}"><img src="{$rss_link.image}" alt="{$rss_link.title}" /></a></div>
					<h3><a href="{$rss_link.url}">{$rss_link.title}</a></h3>
					<p>{$rss_link.text|truncate:195}</p>
					<a href="{$rss_link.url}" class="more-blog">Continue Reading ></a></li>
				{/foreach}
			</ul>
		{else}
			<p>{l s='No RSS feed added' mod='blockrss'}</p>
		{/if}
	</div>
</div>

 

Sometimes, that 3rd image loads, other times it doesn't, even after clearing the cache and refreshing the page.  I really don't get what is going on!  Does anyone have any suggestions?

Share this post


Link to post
Share on other sites

Did you ever get this sorted  - I have a similar issue!

thanks

Baz

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More