Jump to content


Photo

Image URLs in RSS Feeds

Module Plugin

  • Please log in to reply
3 replies to this topic

#1 ClintonSkakun

ClintonSkakun

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 12

Posted 06 July 2012 - 05:13 PM

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?

#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,006 posts
  • 1081

  • LocationPorto, Portugal

Posted 06 July 2012 - 06:11 PM

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

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


#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,773 posts
  • 3122

  • LocationAtlanta, GA

Posted 08 July 2012 - 06:32 AM

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.

#4 ClintonSkakun

ClintonSkakun

    Jr. Member

  • Members
  • PipPip
  • 24 posts
  • 12

Posted 09 July 2012 - 08:54 PM

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!





Also tagged with one or more of these keywords: Module, Plugin

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users