• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Registered Feeds Broken Images

#1
When I point to a Google News feed, it picks up the content, but all of the images are broken. I copied the image URL and followed it on another machine and the image was good, even when not logged into my Google account. I then tried to pass the feed through feedcat and they picked up the images correctly. When I pointed to their URL of the feed, Xenforo still displays broken images. Another thread suggested Feedburner, but Feedburner doesn't like the feed.

Is there a way to fix this, or can I tell Xenforo to ignore the images somehow in the template?

Please help! Thanks!
 

Chris D

XenForo developer
Staff member
#5
Ok, so the problem is the feed's URLs. They are formed like:

//nt1.ggpht.com/news/tbn/1coC5hUOAt_AfM/6.jpg

The double slash prefix is so that the browser will use http or https depending on the protocol you're currently browsing on. It avoids various security errors if, for example, you're browsing on HTTPS and it tries to load HTTP content and vice versa.

What is actually happening, is XenForo is assuming the URL is relative, and therefore prepending the feed's base URL to the images. This means the resulting images are like this:

https://news.google.com//nt1.ggpht.com/news/tbn/1coC5hUOAt_AfM/6.jpg

Clearly not going to work.

So, this is a XenForo bug.

I don't have time to look into a fix right now, and obviously it should be resolved by the devs properly anyway... so I have reported your post to request it be moved to the Bug Reports forum.

In the mean time, what you might want to do is to unselect the option on the Registered Feed to "Post immediately".

This will force all posts to go into the Moderation Queue.

At that point, you can just edit the posts manually before they are published and change replace https://news.google.com// with simply https://
 

Jake Bunce

XenForo moderator
Staff member
#6
Confirmed in 1.1.3

Code fix:

library/XenForo/Html/Renderer/BbCode.php

Add the red code:

Code:
	public function convertUrlToAbsolute($url)
	{
		if (preg_match('#^(https?|ftp)://#i', $url))
		{
			return $url;
		}

		if (!$this->_options['baseUrl'])
		{
			return $url;
		}

		if ($url === '')
		{
			return $this->_options['baseUrl'];
		}

		preg_match('#^(?P<protocolHost>(?P<protocol>https?|ftp)://[^/]+)(?P<path>.*)$#i',
			$this->_options['baseUrl'], $baseParts
		);
		if (!$baseParts)
		{
			return $url;
		}

		if (substr($url, 0, 2) == '//')
		{
			return $baseParts['protocol'] . ':' . $url;
		}

		if ($url[0] == '/')
		{
			return $baseParts['protocolHost'] . $url;
		}

		if (preg_match('#^((\.\./)+)#', $url, $upMatch))
		{
			$count = strlen($upMatch[1]) / strlen($upMatch[2]);

			for ($i = 1; $i <= $count; $i++)
			{
				$baseParts['path'] = dirname($baseParts['path']);
			}

			$url = substr($url, strlen($upMatch[0]));
		}

		$baseParts['path'] = str_replace('\\', '/', $baseParts['path']);

		if (substr($baseParts['path'], -1) != '/')
		{
			$baseParts['path'] .= '/';
		}
		if ($url[0] == '/')
		{
			// path has trailing slash
			$url = substr($url, 1);
		}

		return $baseParts['protocolHost'] . $baseParts['path'] . $url;
	}