relative image path in RSS feed (Bugs)

by Auge ⌂ @, Monday, May 20, 2019, 12:17 (250 days ago) @ Mardor


The RSS feeds produced by rss.inc.php (at least up to version 2.4.11) includes image URLs as relative paths. They should become prefixed by the forum_address setting instead.

Yes, that's true. At the time pawnindia brought this up, I thought about a solution for this issue. Either we could remove the images from the feed or we could add the necessary informations to genererate an absolute URL for the images. But at that time I was not a member of the team and with the time the issue disappeared from my sight.

I added the following line 54 in rss.inc.php:

$rss_items[$i]['text'] = str_replace('src="images', 'src="'.$settings['forum_address'].'images', $rss_items[$i]['text']);

It's a bad hack …

No, it isn't. Adding $settings['forum_address'] to the string for the src-attribute is correct but the way you does it, looks a bit hacky. But that is only the look of the code.

The relevant code of version 2.4.11 beginning with line #44:

while ($row = mysqli_fetch_array($result)) {
  if ($row['pid'] != 0) $rss_items[$i]['reply'] = true;
  if ($row['cache_text'] == '') {
    $rss_items[$i]['text'] = html_format($row['text']);
    @mysqli_query($connid, "DELETE FROM ".$db_settings['entry_cache_table']." WHERE cache_id = ". intval($row['id']));
    @mysqli_query($connid, "INSERT INTO ".$db_settings['entry_cache_table']." (cache_id, cache_text) VALUES (". intval($row['id']) .",'". mysqli_real_escape_string($connid, $rss_items[$i]['text']) ."')");
  } else {
    $rss_items[$i]['text'] = $row['cache_text'];
  $rss_items[$i]['title'] = htmlspecialchars(filter_control_characters($row['subject'])); // this is line #54
  /* ... */

If you inserted your line of code in front of the last shown line (#54), you will hit the posting text in every case. Is that the case?

… and there should be a more adequate way to do this, so I would appreciate to receive a comment about a better solution.

The entry is taken from the posting cache or from the posting table and in the latter case it is instantaneously formatted as HTML with $rss_items[$i]['text'] = html_format($row['text']);. The main purpose of the if-else-block beginning with if ($row['cache_text'] == '') is to unify the text resulting in the text in HTML-elements.

The alternatve to your solution would be to handle both cases separately inside the if-else-block but that would doubling the code and the case of the else-part (posting text from cache) is the same as in your solution. So it is IMHO better to replace the URL-string afterwards as you did.

If noone presents a better solution I will add your code to the repository. It will be part of the first open preview for My Little Forum 2.5 which will land in the public within the next days.

Tschö, Auge

Trenne niemals Müll, denn er hat nur eine Silbe!

Complete thread:

 RSS Feed of thread

powered by my little forum