Advertisement:

Author Topic: Easily and transparently use default images for missing images...  (Read 27040 times)

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Sources/Subs.php:
Code: [Select]
// Start up the session URL fixer.
ob_start('ob_sessrewrite');

Add below:
Code: [Select]

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]
« Last Edit: December 30, 2004, 07:28:22 PM by [Unknown] »

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Easily and transparently use the default theme for default images...
« Reply #1 on: December 28, 2004, 08:56:07 PM »
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]. :)
Cristián Lávaque http://cristianlavaque.com

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Easily and transparently use the default theme for default images...
« Reply #2 on: December 28, 2004, 09:00:16 PM »
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.
« Last Edit: December 28, 2004, 09:02:42 PM by Anguz »
Cristián Lávaque http://cristianlavaque.com

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Easily and transparently use the default theme for default images...
« Reply #3 on: December 29, 2004, 11:11:20 AM »
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]

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Easily and transparently use the default theme for default images...
« Reply #4 on: December 29, 2004, 02:12:53 PM »
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.
« Last Edit: December 29, 2004, 02:14:51 PM by Anguz »
Cristián Lávaque http://cristianlavaque.com

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: Easily and transparently use the default theme for default images...
« Reply #5 on: December 30, 2004, 07:15:27 PM »
What does this modification do exactly?

Offline mytreo

  • Jr. Member
  • **
  • Posts: 284
    • treo
Re: Easily and transparently use the default theme for default images...
« Reply #6 on: December 30, 2004, 07:19:08 PM »
Elijah I was wondering the very same.

Chris
Treo forum - Powered by SMF, of course
Treo news - powered by MovableType and integrated with SMF
Treo downloads - hacked from phpNuke and integrated with SMF
Treo knowledge base - powered by Wikka and integrated with SMF
Treo 650 | Treo 700w | Treo 700p

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Easily and transparently use the default theme for default images...
« Reply #7 on: December 30, 2004, 07:25:39 PM »
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.
Cristián Lávaque http://cristianlavaque.com

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Easily and transparently use default images for missing images...
« Reply #8 on: December 30, 2004, 07:28:51 PM »
Sorry, I screwed up the subject.  Does it make more sense now?

-[Unknown]

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: Easily and transparently use default images for missing images...
« Reply #9 on: December 30, 2004, 07:32:40 PM »
Sorry, I screwed up the subject.  Does it make more sense now?

-[Unknown]

Now it makes sense. Cool mod.

Offline Gregor

  • Semi-Newbie
  • *
  • Posts: 19
    • Natal24
Re: Easily and transparently use default images for missing images...
« Reply #10 on: May 01, 2005, 09:20:58 PM »
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?


Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Easily and transparently use default images for missing images...
« Reply #11 on: May 01, 2005, 09:27:09 PM »
What do you mean?  This doesn't affect how the browser caches things.

-[Unknown]

Offline Gregor

  • Semi-Newbie
  • *
  • Posts: 19
    • Natal24
Re: Easily and transparently use default images for missing images...
« Reply #12 on: May 01, 2005, 09:58:40 PM »
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!

Offline edi67

  • SMF Hero
  • ******
  • Posts: 1,532
  • Gender: Male
  • Italian Supporter
    • CrazyZone
Re: Easily and transparently use default images for missing images...
« Reply #13 on: November 08, 2007, 10:15:19 AM »
how make it work with smf 1.1.1 ?
CrazyZone - My SMF Forum


From the difficult the hardening of the man you can see

Offline Rumbaar

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,805
  • Gender: Male
  • Inherent Omniscience
    • Rumbaar.net
Re: Easily and transparently use default images for missing images...
« Reply #14 on: December 09, 2007, 04:47:27 AM »
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.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]