Sources/Subs.php:
// Start up the session URL fixer.
ob_start('ob_sessrewrite');
Add below:
function ob_check_images($buffer)
{
global $settings;
if (@version_compare(PHP_VERSION, '4.2.3') == -1)
return $buffer;
preg_match_all('~<img[^>]+?src="' . preg_quote($settings['actual_theme_url'] . '/images', '~') . '(/[^"]+?)"~', $buffer, $matches, PREG_SET_ORDER);
$replace = array();
foreach ($matches as $match)
{
if (!file_exists($settings['actual_theme_dir'] . '/images' . $match[1]))
$replace[$match[0]] = strtr($match[0], array($settings['actual_theme_url'] . '/images' . $match[1] => $settings['default_theme_url'] . '/images' . $match[1]));
}
return strtr($buffer, array_unique($replace));
}
ob_start('ob_check_images');
Make sure your theme's images URL is not set to the default's images directory.
-[Unknown]
Maybe an array_unique would be good on $matches before doing all the file_exists.
It'll add some time to the page generation, but it's a nice safety net for those missing images in themes.
Thanks [Unknown]. :)
Thinking about it, to avoid the preg functions on the whole buffer, why not do something like get all the image file names from the custom theme's dir, compare the list to the default theme's, then eliminating matches you'll be left with the missing images to do the strtr.
Zitat von: Anguz in Dezember 28, 2004, 09:00:16 NACHMITTAGS
Thinking about it, to avoid the preg functions on the whole buffer, why not do something like get all the image file names from the custom theme's dir, compare the list to the default theme's, then eliminating matches you'll be left with the missing images to do the strtr.
Regular expressions may not be fast, but they still mop file access up and down.
-[Unknown]
True, but I didn't mean to check the directory every time. It could probably be stored in the themes table or something, a CSV of the images in a theme. Then it's a quick thing, you could strpos the CSV in that function instead of file_exists, or something like that.
What does this modification do exactly?
Elijah I was wondering the very same.
Chris
Zitat von: Elijah Bliss in Dezember 30, 2004, 07:15:27 NACHMITTAGS
What does this modification do exactly?
If you have a missing image file in your custom theme, it'll fix the img tag to use the one in the default theme, so that you don't get the broken image in your page.
Sorry, I screwed up the subject. Does it make more sense now?
-[Unknown]
Zitat von: [Unknown] in Dezember 30, 2004, 07:28:51 NACHMITTAGS
Sorry, I screwed up the subject. Does it make more sense now?
-[Unknown]
Now it makes sense. Cool mod.
Works very nice, but can it be that now on every page laod all images are loaded again, and not fetched from the browser catch? Even the images that are not missing?
What do you mean? This doesn't affect how the browser caches things.
-[Unknown]
Zitat von: [Unknown] in Mai 01, 2005, 09:27:09 NACHMITTAGS
What do you mean? This doesn't affect how the browser caches things.
-[Unknown]
Yes, sorry, I made some tests, and it is obviously the same with or without the mod. I had the impression that even when a page is in the browser cache the images are reloaded. ::)
So, it is only left to say that it works fine!
how make it work with smf 1.1.1 ?
What did you get when you tried to add the code to your current post.php file edi67?
I would suggest you upgrade to 1.1.4 first, there have been a number of security fixes between your version and the current one.