Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative image links not being rewritten #57

Open
GoogleCodeExporter opened this issue Mar 15, 2015 · 2 comments
Open

Relative image links not being rewritten #57

GoogleCodeExporter opened this issue Mar 15, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

Some comics' RSS feeds (such as Dumm Comics) use relative paths to their
images' SRC and links' HREF attributes. While this is technically an error
in the RSS feed (since feeds are supposed to be portable), other readers
(notably Google Reader) rewrite the relative paths, which helps prevent the
problem.

For whatever it's worth, for my own RSS feeds I have written a function
"rewriteRelative" which fixes relative paths; perhaps it would be useful to
integrate it into FonF:

// Rewrite all relative links in a chunk of HTML/XML/etc. to point to the
appropriate place
function rewriteRelative($html, $base) {
        // generate server-only replacement for root-relative URLs
        $server = preg_replace('@^([^\:]*)://([^/*]*)(/|$).*@', '\1://\2/',
$base);

        // replace root-relative URLs
        $html = preg_replace('@\<([^>]*) (href|src)="/([^"]*)"@i',
                '<\1 \2="' . $server . '\3"', $html);

        // replace base-relative URLs (kludgy, but I couldn't get ! to work)
        $html = preg_replace('@\<([^>]*)
(href|src)="(([^\:"])*|([^"]*:[^/"].*))"@i',
                '<\1 \2="' . $base . '\3"', $html);

        return $html;
}


It's a little kludgy but it does the job.

Original issue reported on code.google.com by fluffy%[email protected] on 6 May 2009 at 3:53

@GoogleCodeExporter
Copy link
Author

After looking into it a bit more, it appears that SimplePie IS already rewriting
content links, but for some reason the images aren't displaying, even though 
they're
getting rewritten to something that's technically valid.

I wonder if this is more a case of the site in question (dummcomics.com) being 
a bit
overzealous with hotlink prevention, since if I manually load one of the image 
URLs,
it shows up, and then promptly disappears from FonF - and stays disappeared 
when I go
to the site itself (until I reload).

Original comment by fluffy%[email protected] on 7 May 2009 at 6:16

@GoogleCodeExporter
Copy link
Author

Yeah, that's definitely the case. Feel free to close this ticket. Sorry for the
inconvenience.

Original comment by fluffy%[email protected] on 7 May 2009 at 6:29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant