Jump to content

Image URLs in RSS Feeds


PHPSpert
 Share

Recommended Posts

I'm having this problem in my RSS Feeds. The images are pulled locally in the regular posts so often times the images do not appear correctly in the RSS Feeds.

Here's what I'm doing to fix it now:

// send the output of the RSS feed, and you are done
session_start();
ob_start();
$rss->render($items);
$contents = ob_get_contents();
$contents = str_replace("<img src=\"/site/assets/files/", "<img src=\"http://clintonskakun.com/site/assets/files/", $contents);
ob_clean();
echo $contents;
?>

I use output buffering to fix the broken URLs in the RSS Feeds. Is there a cleaner/better way to do this?

  • Like 1
Link to comment
Share on other sites

That's a good point--I hadn't actually tried images on the RSS feed before. Here's another way you could do it:

$contents = $rss->renderFeed();

$contents = str_replace("<img src=\"/site/assets/files/", "<img src=\"http://clintonskakun.com/site/assets/files/", $contents);

header($rss->header); 
echo $contents; 

This problem should resolve itself in 2.3, as I'm planning to abstract URLs to IDs in textarea fields. The IDs will be resolved to the full URL at render time.

  • Like 2
Link to comment
Share on other sites

What if you put the whole path on the post template?

echo "<img src='http://{$config->httpHost}{$page->image->url}'>";

Well the problem goes deeper than that because it's not the form template that's the problem, it's how the body content is formatted when the page is saved. I'm simply trying to quickly switch out the urls before the RSS feed parses. I could go into the HTML code when editing the page but that seems like a hassle when the search and replace does just as good a job. I was just wondering if there's a cleaner way to do it. However you do bring up a good point about using the httpHost variable. It would make the script a lot more versatile for using on multiple sites.

That's a good point--I hadn't actually tried images on the RSS feed before. Here's another way you could do it:

$contents = $rss->renderFeed();

$contents = str_replace("<img src=\"/site/assets/files/", "<img src=\"http://clintonskakun.com/site/assets/files/", $contents);

header($rss->header);
echo $contents;

This problem should resolve itself in 2.3, as I'm planning to abstract URLs to IDs in textarea fields. The IDs will be resolved to the full URL at render time.

Ok, this seems like the best fix until the release then. I didn't know you could output the buffer with the header like that. Oh well, as of now it's doing the job.

Thanks to the two of you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...