News:

Wondering if this will always be free?  See why free is better.

Main Menu

How To Use A Localized Image Folder

Started by shadav, June 23, 2020, 04:42:03 PM

Previous topic - Next topic

shadav

not sure where to ask this so I guess graphics and templates is the best place, if not feel free to move it

so, I pretty much use the same images across all themes....
how would I edit the themes to use the images from the default theme's images folder?

so instead of having multiple files of the same image in each and every theme, I could just have one file and call it into the other themes?

the only real difference would be in the themes/images/theme folder, these would be different per theme but everything else topic/post/icons/bbc/buttons/admin/ect are all the same....
so how can I get rid of these extra (duplicate) files/folders and just use one localized file/folder

I hope that made sense and you understand what I'm getting at....

thank you

[edit] for a 2.0.17

Deaks

this would require quite some work on the template and source files but really depends what exact images you were thinking
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

shadav

basically for every image it would use the images from the default theme's image folder

except for the images in the theme in use/images/theme this would be per theme

shadav

had a thought

in my admin under current theme
if I change the
This theme's images URL:
from the theme's url to the default theme's url....would this work?

Deaks

it potentially could, not something anyone has asked before, I was thinking doing similar through repair_settings then only downside would be you would need to change every call to custom files in the custom theme
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Antechinus

All themes should fall back to default theme images if the images are missing from the custom theme, so it's worth trying changing the call to the folder. Other option would be to delete the unwanted images from the custom themes (or just rename the relevant folder as a test) and see what happens.

ETA: Oh, one trick to be aware of. At the top of index.template.php there is this:

/* Use images from default theme when using templates from the default theme?
if this is 'always', images from the default theme will be used.
if this is 'defaults', images from the default theme will only be used with default templates.
if this is 'never' or isn't set at all, images from the default theme will not be used. */
$settings['use_default_images'] = 'never';

So you'd probably also want to set that appropriately.

shadav

well i tested it and changing the url in the admin does work but I don't think that's the way to go as then all images are from the default even the theme folder and the thumbnail
which isn't a big deal to me, I got rid of all the theme specific images like the main_block.png....only image specific is the header.png
and well it's funnier seeing in the user profile changing themes and the thumbnails all show the same image  :laugh:

and I tried that too Ant but nope, it doesn't fall back to the default image folder, there's just broken images everywhere  :laugh: :laugh:

I think what needs to be done is in all the theme template files need to change the links
for instance in boardindex.template.php
<img id="newsupshrink" src="', $settings['images_url'], '/collapse.gif" alt="*" title="', $txt['upshrink_description'], '" style="display: none;" />
needs to point to the default theme instead of using settings

or like this one
<img src="', $settings['images_url'], '/', $context['theme_variant_url'], 'on', $board['new'] ? '' : '2', '.png" alt="', $txt['new_posts'], '" title="', $txt['new_posts'], '" />'; change the theme variant url

so then what would be the variable for the default theme or do I just need to hardcode it in there url/Themes/default/images/

[edit] just saw you edited your reply, i'll take a look at that

shadav

Quote from: Antechinus on June 23, 2020, 05:22:58 PM
All themes should fall back to default theme images if the images are missing from the custom theme, so it's worth trying changing the call to the folder. Other option would be to delete the unwanted images from the custom themes (or just rename the relevant folder as a test) and see what happens.

ETA: Oh, one trick to be aware of. At the top of index.template.php there is this:

/* Use images from default theme when using templates from the default theme?
if this is 'always', images from the default theme will be used.
if this is 'defaults', images from the default theme will only be used with default templates.
if this is 'never' or isn't set at all, images from the default theme will not be used. */
$settings['use_default_images'] = 'never';

So you'd probably also want to set that appropriately.

eh that didn't work either

:laugh: :laugh: :laugh: do not change it to always.....that overwrote even the images in css  :laugh: :laugh:
default doesn't seem to do anything, but i'll leave it to default for now....

Antechinus

Cool. We now know more things that don't work. :D That has to narrow down the solution.

Anyway, the variable for calling from the default images folder is shown in this post:

https://www.simplemachines.org/community/index.php?topic=532532.msg3784393;topicseen#msg3784393

shadav

#9
changing
$settings['images_url']
to
$settings['default_images_url']
in the theme's template files seems to work.... a few things though
need to go through any installed mods and change it there too

for some reason though the collapse image on boards still isn't working and the gender icons, oh and stars on post profile (which might be a mod)....

it's a start :)

[edit] fixed the gender icons and stars, had to change that in load.php
do not replace all instances, only the ones for those specific images (or other images that you want to use default images for and not theme related)

still not sure why the collapse image isn't working
<img id="newsupshrink" src="', $settings['default_images_url'], '/collapse.gif" alt="*" title="', $txt['upshrink_description'], '" style="display: none;" />
the image is in the default image folder....  :-\

shadav

lol i know to most this isn't a big issue....
but my image folder is like 6mb times 4 themes.....I mean we're still only talking about 24mb but still, kind of annoying having multiple locations for the same file.....and well....my sites are using 16gb of disk space so every little bit of consolidation helps ;)

well it was a lot more but I went through today and smushed all my images to cut their file sizes almost in half and then was like why am I copying the same images to every theme  :laugh:

Antechinus

The collapse image is called in javascript in the template. You'd have to change it in the js too. :)

// Define the upper_section toggle in JavaScript.
echo '
<script type="text/javascript"><!-- // --><![CDATA[
var oMainHeaderToggle = new smc_Toggle({
bToggleEnabled: true,
bCurrentlyCollapsed: ', empty($options['collapse_header']) ? 'false' : 'true', ',
aSwappableContainers: [
\'upper_section\'
],
aSwapImages: [
{
sId: \'upshrink\',
srcExpanded: smf_images_url + \'/upshrink.png\',
altExpanded: ', JavaScriptEscape($txt['upshrink_description']), ',
srcCollapsed: smf_images_url + \'/upshrink2.png\',
altCollapsed: ', JavaScriptEscape($txt['upshrink_description']), '
}
],
oThemeOptions: {
bUseThemeSettings: ', $context['user']['is_guest'] ? 'false' : 'true', ',
sOptionName: \'collapse_header\',
sSessionVar: ', JavaScriptEscape($context['session_var']), ',
sSessionId: ', JavaScriptEscape($context['session_id']), '
},
oCookieOptions: {
bUseCookie: ', $context['user']['is_guest'] ? 'true' : 'false', ',
sCookieName: \'upshrink\'
}
});
// ]]></script>';


Same would apply to any other js toggle images (info centre, quick reply, etc).

shadav

still can't get it to work

I changed
smf_images_url
to
default_images_url

but still it's trying to pull the image from the theme and not the default theme....gotta be missing something somewhere...

thank you for your help btw :)

as far as I can tell (aside from mods) the collapse/expand image is the only thing that isn't working

Antechinus

Oh hang on, you mean the collapse image in the category header bars (ie: on boards). DId you catch this one, in Sources/Subs-BoardIndex.php?

Code (Line 99) Select
'collapse_image' => isset($row_board['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . $context['theme_variant_url'] . ($row_board['is_collapsed'] > 0 ? 'expand.gif" alt="+"' : 'collapse.gif" alt="-"') . ' />' : '',

shadav

Quote from: Antechinus on June 23, 2020, 07:22:16 PM
Oh hang on, you mean the collapse image in the category header bars (ie: on boards). DId you catch this one, in Sources/Subs-BoardIndex.php?

Code (Line 99) Select
'collapse_image' => isset($row_board['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . $context['theme_variant_url'] . ($row_board['is_collapsed'] > 0 ? 'expand.gif" alt="+"' : 'collapse.gif" alt="-"') . ' />' : '',

that did the trick  ;D

shadav

thank you, I'm going to mark this as solved as I'm pretty sure everything is working now

Antechinus

Cool. Handy to refresh my memory of where all this stuff hides. I tend to want to do unusual things every so often. :)

shadav

just as a side note
I deleted all of the files out of the theme's image folder
except for the theme folder (or custom folder that's in one of the themes) and the thumbnail.gif
this way I can keep where needed links to theme specific images and then change everything else to use the default images


shadav

ok ran into a slight snag  :laugh:
I forgot to edit the css

on one site I got rid of the theme folder as they were the same images (I just made the same theme in different colors)....so then had to edit the css to point any
../images
to
../../default/images

other than that, I think everything is sorted now  ;D

Advertisement: