Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: ameo on May 09, 2015, 03:07:53 PM

Title: I need PNG icons support in BBC
Post by: ameo on May 09, 2015, 03:07:53 PM
How do I make changes so forum would support PNG images in BBC?


I'm pretty sure I have to add png extension here:



$icons = array();
foreach ($icon_data as $icon)
{
$icons[$icon['filename']] = array(
'value' => $icon['filename'],
'name' => $icon['title'],
'url' => $settings[file_exists($settings['theme_dir'] . '/images/post/' . $icon['filename'] . '.gif') ? 'images_url' : 'default_images_url'] . '/post/' . $icon['filename'] . '.gif',
'is_last' => false,
);
}



but how exactly, so I don't encounter syntax errors?
Title: Re: I need PNG icons support in BBC
Post by: NanoSector on May 09, 2015, 03:26:23 PM
Try

$icons = array();
foreach ($icon_data as $icon)
{
if (file_exists($settings['theme_dir'] . '/images/post/' . $icon['filename'] . '.gif'))
$url = $settings['images_url'] . '/post/' . $icon['filename'] . '.gif';
elseif (file_exists($settings['theme_dir'] . '/images/post/' . $icon['filename'] . '.png'))
$url = $settings['images_url'] . '/post/' . $icon['filename'] . '.png';
else
$url = $settings['default_images_url'] . '/post/' . $icon['filename'] . '.gif';

$icons[$icon['filename']] = array(
'value' => $icon['filename'],
'name' => $icon['title'],
'url' => $url,
'is_last' => false,
);
}
Title: Re: I need PNG icons support in BBC
Post by: ameo on May 09, 2015, 03:55:36 PM
so, i deleted glow.gif and uploaded glow.png

but glow.png doesn't show, even though i made your changes in the code. :(
Title: Re: I need PNG icons support in BBC
Post by: NanoSector on May 10, 2015, 12:28:48 PM
Did you upload it to all themes?
Title: Re: I need PNG icons support in BBC
Post by: ameo on May 10, 2015, 03:07:07 PM
this is PASTIE of how my code looks like now (http://pastie.org/10181497)


also, i've put glow.png  in 1. current theme i'm using 2. in default theme.


doesn't display image, that is, browser displays image as broken.
Title: Re: I need PNG icons support in BBC
Post by: ameo on May 14, 2015, 05:34:00 PM
Anyone care to help? I still need this.
Title: Re: I need PNG icons support in BBC
Post by: ameo on May 18, 2015, 09:54:14 AM
*bump*!
Title: Re: I need PNG icons support in BBC
Post by: margarett on May 22, 2015, 06:22:16 AM
The code above relates to the POST icons, the ones that show in each message. Eg:
(http://media.simplemachinesweb.com/smf/default/images/post/xx.gif)
(http://media.simplemachinesweb.com/smf/default/images/post/clip.gif)

The BBC icons are in images/bbc and the code that handles them is
// Here loop through the array, printing the images/rows/separators!
foreach ($context['bbc_tags'] as $i => $buttonRow)
{
echo '
[';
foreach ($buttonRow as $tag)
{
// Is there a "before" part for this bbc button? If not, it can't be a button!!
if (isset($tag['before']))
echo '
{
sType: \'button\',
bEnabled: ', empty($context['disabled_tags'][$tag['code']]) ? 'true' : 'false', ',
sImage: ', JavaScriptEscape($settings['images_url'] . '/bbc/' . $tag['image'] . '.gif'), ',
sCode: ', JavaScriptEscape($tag['code']), ',
sBefore: ', JavaScriptEscape($tag['before']), ',
sAfter: ', isset($tag['after']) ? JavaScriptEscape($tag['after']) : 'null', ',
sDescription: ', JavaScriptEscape($tag['description']), '
}', empty($tag['isLast']) ? ',' : '';

// Must be a divider then.
else
echo '
{
sType: \'divider\'
}', empty($tag['isLast']) ? ',' : '';
}


This works:
// Here loop through the array, printing the images/rows/separators!
foreach ($context['bbc_tags'] as $i => $buttonRow)
{
echo '
[';
foreach ($buttonRow as $tag)
{
// Is there a "before" part for this bbc button? If not, it can't be a button!!
if (isset($tag['before']))
{
if (file_exists($settings['actual_theme_dir'] . '/images/bbc/' . $tag['image'] . '.gif'))
$url = $settings['actual_images_url'] . '/bbc/' . $tag['image'] . '.gif';
elseif (file_exists($settings['actual_theme_dir'] . '/images/bbc/' . $tag['image'] . '.png'))
$url = $settings['actual_images_url'] . '/bbc/' . $tag['image'] . '.png';
elseif (file_exists($settings['default_theme_dir'] . '/images/bbc/' . $tag['image'] . '.png'))
$url = $settings['default_images_url'] . '/bbc/' . $tag['image'] . '.png';
else
$url = $settings['default_images_url'] . '/bbc/' . $tag['image'] . '.gif';


echo '
{
sType: \'button\',
bEnabled: ', empty($context['disabled_tags'][$tag['code']]) ? 'true' : 'false', ',
sImage: ', JavaScriptEscape($url), ',
sCode: ', JavaScriptEscape($tag['code']), ',
sBefore: ', JavaScriptEscape($tag['before']), ',
sAfter: ', isset($tag['after']) ? JavaScriptEscape($tag['after']) : 'null', ',
sDescription: ', JavaScriptEscape($tag['description']), '
}', empty($tag['isLast']) ? ',' : '';
}

// Must be a divider then.
else
echo '
{
sType: \'divider\'
}', empty($tag['isLast']) ? ',' : '';
}

Title: Re: I need PNG icons support in BBC
Post by: Illori on May 22, 2015, 06:38:57 AM
i have PM'ed margarett, his code does not work. i somewhat fixed it but i still get an error.
Title: Re: I need PNG icons support in BBC
Post by: margarett on May 22, 2015, 07:28:02 AM
Should work now, thanks for testing ;)
Title: Re: I need PNG icons support in BBC
Post by: ameo on May 23, 2015, 06:05:55 AM
Works like a charm.  :)
Thank you very much, both of you.
I'm thankful and glad you helped me.

Cheers!

I'd just say, for any future reference that this code above is in file:
Themes/Default/GenericControls.template.php

I've barely found it, haha :D