Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: General_Naga on August 02, 2008, 03:48:11 AM

Title: Changing IMG output
Post by: General_Naga on August 02, 2008, 03:48:11 AM
OK I've been trying to integrate with Lightbox (http://www.huddletogether.com/projects/lightbox/) so I can use it in conjunction with SSI for my frontpage.

Well I've got it working using the following edit:
Quote
            array(
                'tag' => 'img',
                'type' => 'unparsed_content',
                'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
                'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
                'disabled_content' => '($1)',
            ),

but I now want to go a stage further and have it so if I type in
[img=group1]X.jpg[/img]
it produces
<a href="X.jpg" rel="lightbox[group1]" title="mytitle">image #1</a>

I think the answer could be found by looking at the quotes code in Subs.php, but its far to complicated for me to make any sense of. Has anyone got any ideas or even better the correct changes to the code?

Thanks to anyone who can help.
Title: Re: Changing IMG output
Post by: General_Naga on August 03, 2008, 09:12:08 AM
I'm still stuck on this, if anyone has any thoughts they would be much appreciated.
Title: Re: Changing IMG output
Post by: Rumbaar on August 07, 2008, 05:03:11 AM
Well you've already got an array that can take optional variables, why not work with that one?
array(
'tag' => 'img',
'type' => 'unparsed_content',
'parameters' => array(
'alt' => array('optional' => true),
'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
),
'content' => '<img src="$1" alt="{alt}"{width}{height} class="bbc_img" />',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
'disabled_content' => '($1)',
),


So try:
array(
'tag' => 'img',
'type' => 'unparsed_content',
'parameters' => array(
'alt' => array('optional' => true),
'group' => array('optional' => true),
'width' => array('optional' => true, 'value' => ' width="$1"', 'match' => '(\d+)'),
'height' => array('optional' => true, 'value' => ' height="$1"', 'match' => '(\d+)'),
),
'content' => '<a href="$1" target="_blank" rel="lightbox[{group}]"><img src="$1" alt="{alt}"{width}{height} class="bbc_img" /></a>',
'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
'disabled_content' => '($1)',
),


Then you want use it as [img group=group1]Image URL[/img] with the output HTML:
<a href="Image URL" target="_blank" rel="lightbox[group1]"><img src="Image URL" alt="" class="bbc_img" /></a>With this code you can still even use the width, height and alt BBC code to define their values.
Title: Re: Changing IMG output
Post by: General_Naga on August 08, 2008, 05:23:39 AM
Thanks Rumbaar your a god!

I was hoping to integrate this into the Thumbnail Mod (http://custom.simplemachines.org/mods/index.php?mod=1067)

This is the code for the Thumbnail BBcode.
            array(
                'tag' => 'imgt',
                'type' => 'unparsed_content',
                'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
                'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
                'disabled_content' => '($1)',
            ),
        );


which using your code I've adjusted to this;

            array(
                'tag' => 'imgt',
                'type' => 'unparsed_content',
                 'parameters' => array(
                    'group' => array('optional' => true),
                ),
                'content' => '<a href="$1" target="_blank" rel="lightbox[{group}]"><img src="$1" width="256px" height="192px" border="0" /></a>',
                'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
                'disabled_content' => '($1)',
            ),


But that just causes the IMGT BBcode to stop working.

Thanks for getting me this far!
Title: Re: Changing IMG output
Post by: Rumbaar on August 08, 2008, 06:52:25 AM
You're welcome.  Yes I was thinking later on, it would be best to use an alternate bbcode as this global change would affect any 'normal' use of the IMG tags.

So I'm not 100% sure, have you gotten a solution or still having issues?
Title: Re: Changing IMG output
Post by: General_Naga on August 08, 2008, 11:01:38 AM
I'm still having problems I'm afraid, I think its because I've added an parameters array.

I tried making my own thumbnail BBcode by using your code, removing the variable heights and putting in fixed ones. That just resulted in the forum loading as a blank page though.

This is what I think *should* work:


         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'parameters' => array(
               'group' => array('optional' => true,)
               'title' => array('optional' => true, 'value' => ' {"$1"}', ')
               ),
            'content' => '<a href="$1" target="_blank" {title} rel="lightbox[{group}]"><img src="$1" width="128px" height="96px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
            'disabled_content' => '($1)',
         ),


Should that be working? or have I made a miss-take somewhere?

Thanks
Title: Re: Changing IMG output
Post by: Rumbaar on August 08, 2008, 07:49:34 PM
What are you trying to do with:
'title' => array('optional' => true, 'value' => ' {"$1"}', ')

But if I think right, try:
array(
                'tag' => 'imgt',
                'type' => 'unparsed_content',
                 'parameters' => array(
                    'group' => array('optional' => true),
'title' => array('optional' => true),
                ),
                'content' => '<a href="$1" target="_blank" title="{title}" rel="lightbox[{group}]"><img src="$1" width="256px" height="192px" class="bbc_img" /></a>',
                'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
                'disabled_content' => '($1)',
            ),
Title: Re: Changing IMG output
Post by: General_Naga on August 08, 2008, 08:59:31 PM
That code also results in the forum opening as a blank white page. As does any page with SSI on it.

It's probably easier if you have the time to just glace at the Lighbox 2.0 page (http://www.huddletogether.com/projects/lightbox2/) (skip down to Part 2: Activate). It explains how to use it in the first few paragraphs. What I'm trying to do is get all the options working and customizable.

He explains it far better than I can.

Thanks for all your help so far.
Title: Re: Changing IMG output
Post by: Rumbaar on August 08, 2008, 09:04:23 PM
Well I added that bbcode to my SMF 2.x Subs.php array and was able to post an image with no issues on my 2.x test site.  There must be alternate code in that page or I'm not sure of the issue with SSI.php pulling contents from the main forum in regards to this alter code.
Title: Re: Changing IMG output
Post by: General_Naga on August 09, 2008, 05:19:39 AM
It all works perfectly!

I must have done something wrong the first time. I don't get a blank page anymore and I solve the problem with the BBcode being shown instead of the output by putting the new modified IMGT code underneath the old one.

         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
         ),
          array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
                'parameters' => array(
                    'group' => array('optional' => true),
            'title' => array('optional' => true),
            ),
            'content' => '<a href="$1" target="_blank" title="{title}" rel="lightbox[{group}]"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
            ),


Thanks so much Rumbaar, There's no way I could have done that alone.
Title: Re: Changing IMG output
Post by: Rumbaar on August 09, 2008, 10:23:17 AM
You're welcome.  Though I'd still look to use a unique bbcode from any current ones you use.  So the current one can be used separately to any new one you've created.
Title: Re: Changing IMG output
Post by: General_Naga on August 18, 2008, 10:25:56 AM
Thanks for the tip, but I only use that BBcode for that sort of thing anyway. I'll bare it in mind if I mess around with any other BBcode though :)
Title: Re: Changing IMG output
Post by: General_Naga on September 10, 2008, 10:27:41 AM
After upgrading to Beta 4 I had to reinstall this mod. I now can't get it to work however. The first bit of code:

         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
         ),

works fine. However if I put in the second half my forum loads a blank white page. Has there been a change in beta 4 which has thrown this code off? Or is there a syntax error I've missed?

The complete code which was working is:
         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
         ),
          array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
                'parameters' => array(
                    'group' => array('optional' => true),
            'title' => array('optional' => true),
            ),
            'content' => '<a href="$1" target="_blank" title="{title}" rel="lightbox[{group}]"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
            ),


Thanks to anyone who can help, however small the contribution :)
Title: Re: Changing IMG output
Post by: General_Naga on September 12, 2008, 06:56:56 PM
Anyone got any ideas? It was such a great bit of code and I want to avoid having to roll back our whole site to pre-lightbox integration. Which I will have to do if I can't find a solution in the next week or so.

I've gone over it again and again but I just can't spot the problem. Is it just me who can't spot it or am I missing a blindingly obvious syntax error?
Title: Re: Changing IMG output
Post by: Oldiesmann on October 19, 2008, 12:59:54 AM
Quote from: General_Naga on September 10, 2008, 10:27:41 AM
After upgrading to Beta 4 I had to reinstall this mod. I now can't get it to work however. The first bit of code:

         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
         ),

works fine. However if I put in the second half my forum loads a blank white page. Has there been a change in beta 4 which has thrown this code off? Or is there a syntax error I've missed?

The complete code which was working is:
         array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
            'content' => '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
         ),
          array(
            'tag' => 'imgt',
            'type' => 'unparsed_content',
                'parameters' => array(
                    'group' => array('optional' => true),
            'title' => array('optional' => true),
            ),
            'content' => '<a href="$1" target="_blank" title="{title}" rel="lightbox[{group}]"><img src="$1" width="256px" height="192px" border="0" /></a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array('<br />' => ''));'),
            'disabled_content' => '($1)',
            ),


Thanks to anyone who can help, however small the contribution :)

Do you still need help with this?

I don't see anything in there that would cause an error.
Title: Re: Changing IMG output
Post by: General_Naga on October 19, 2008, 04:49:45 AM
Thanks I did manage to solve it with the help of another site. If anyone interested the solution is here (http://www.smfhelper.info/forum/index.php/topic,3034.msg30432.html#msg30432)