Enabling simple BB codes in photo description Enabling simple BB codes in photo description
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Enabling simple BB codes in photo description

Started by cgc0202, August 30, 2006, 10:24:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cgc0202

Hi,

The caption for a photo is generally centered, and is the default format in the presentation of the title and addtional short captions (photographer name, address, etc.) of the photo in CPG. 

The default center alignment, is also the default alignment for long descriptions that may be included.  This is not always aesthetically good to look at.  Is it possible to specify, left align and right align and other combinations, also? 

Example 01:

"... That if all vicious men are bound together and constitute a force, then all honorable men ought to do the same ..."
-- Leo Tolstoy (War and Peace)

The description is "left aligned" while the attribution is "right aligned"

Example 02:

"...Oh Wind.
If Winter comes, can Spring be far behind?"

-- Ode to the West Wind
Percy Bysshe Shelley

In the second example given above, the first line, second line and attribution were "right aligned", "left aligned"  and "right aligned", respectively; before the entire text was boxed in a table and the table itself, centered -- to get the desired appearance of the quote from the poem.

Basically, I used the allowed simple BB tags in this forum, to enable the above formatting. I may have missed reading it in the Manual, but it would be nice if such basic simple BB tags are allowed in the photo description. 

Without the alignments, the default in the photo description would appear like these:

Example 1:

"... That if all vicious men are bound together and constitute a force, then all honorable men ought to do the same ..."
-- Leo Tolstoy (War and Peace)

Here, if the above quoted description is very long, and consists of multiple paragraphs, the appearance is not very nice.

Example 2:

"... Oh Wind.
If Winter comes, can Spring be far behind?"

-- Ode to the West Wind
Percy Bysshe Shelley

Again, the centered alignment is not the best presentation for poems. 


In the FAQ, there is an example to enable BB codes to allow clickable links:

******************
Edit displayimage.php and change
$info[$CONFIG['user_field'.$i.'_name']] = make_clickable($CURRENT_PIC_DATA['user'.$i]);
into
$info[$CONFIG['user_field'.$i.'_name']] = bb_decode($CURRENT_PIC_DATA['user'.$i]);
******************

How can all the other simple BB codes be allowed in the caption of the photo?

Thanks.

CGC


Joachim Müller

The bbcode tags you can use in Coppermine differ from the bbcode tags in SMF. Coppermine only supports [ b ], [ i ], [ u r l ], [ e m a i l ], [ i m g ]. Adding in more bbcode tags is not that easy. I suggest looking up how phpBB (that's where Coppermine "borrowed" the bbcode processing from) handles additional bbcode tags.

Nibbler

#2
You can add alignment tags fairly easily, just add this code into bb_decode() function in inlcude/functions.inc.php


         // [left] and [/left] for left align.
        $text = str_replace("[left]", '<div align="left">', $text);
        $text = str_replace("[/left]", '</div>', $text);
       
        // [center] and [/center] for centered.
        $text = str_replace("[center]", '<div align="center">', $text);
        $text = str_replace("[/center]", '</div>', $text);
       
        // [right] and [/right] for right align.
        $text = str_replace("[right]", '<div align="right">', $text);
        $text = str_replace("[/right]", '</div>', $text);


You may need code to balance the tags though.

[edit: typo]

cgc0202

#3
Thanks Gau, Nibbler,

The added info is good to know.  Just to clarify:  Based from what you stated, provided it is a BB code, and I add it in the include/functions.inc.php, it will work?  Also, I will need them mostly in the "display"  presentation. In the FAQ, it had this note:

******************
Edit displayimage.php and change
$info[$CONFIG['user_field'.$i.'_name']] = make_clickable($CURRENT_PIC_DATA['user'.$i]);
into
$info[$CONFIG['user_field'.$i.'_name']] = bb_decode($CURRENT_PIC_DATA['user'.$i]);
******************

Is there a need to modify the displayimage.php, further?  Or, does the above edit enable the BB codes in the "display" page -- provided they have been included, as you stated, in the "include/functions.inc.php"?

I really do not expect to add more than alignments (not even img) and other formatting.  Aside from those you indicated in your responses, the only other one I need would be the "table" code.  I will look that up in the BB codes.  Thanks again.

CGC

Nibbler

Once you change the bb_decode function they will work everywhere bbcode is allowed. Tables are difficult since you need to verify what the user is creating is a valid table. If it is not then it can break the layout of your page. If it's only you that will use the code then you should be ok.


        // [table] and [/table] for a table.
        $text = str_replace("[table]", '<table style="font: inherit; color: inherit;">', $text);
        $text = str_replace("[/table]", '</table>', $text);

        // [tr] and [/tr] for a table row.
        $text = str_replace("[tr]", '<tr>', $text);
        $text = str_replace("[/tr]", '</tr>', $text);
       
        // [td] and [/td] for a table cell.
        $text = str_replace("[td]", '<td valign="top" style="font: inherit; color: inherit;">', $text);
        $text = str_replace("[/td]", '</td>', $text);

cgc0202

#5
Thanks Nibbler,

Yes, I hesitate to add the table tags.  Very risky.

Copying your examples as templates, I was able to add this and they work:


   // [sup] and [/sup] for superscript.
        $text = str_replace("[sup]", '<sup>', $text);
        $text = str_replace("[/sup]", '</sup>', $text);

   // [sub] and [/sub] for subscript.
        $text = str_replace("[sub]", '<sub>', $text);
        $text = str_replace("[/sub]", '</sub>', $text);


[Edit: Added code tags - Nibbler]

cgc0202

      Hi Nibbler,

      However, I had mixed success with these:

               //
[list=1] and [/ol] for ordered numerical listing.
        $text = str_replace("[list=1]", '<ol>', $text);
        $text = str_replace("[/list]", '</ol>', $text);


         // [list=a] and [/ol] for ordered alphabetical listing.
        $text = str_replace("[list=a]", '<ol>', $text);
        $text = str_replace("[/list]", '</ol>', $text);


         // [ul] and [/ul] for unordered enumeration.
        $text = str_replace("[ul]", '<ul>', $text);
        $text = str_replace("[/ul]", '</ul>', $text);

I tried to combine the above with either :

         //
  • and
for enumeration.
        $text = str_replace("
  • ", '<li>', $text);
            $text = str_replace("
", '</li>', $text);

or

         //
  • and [/*] for enumeration.
            $text = str_replace("
  • ", '<li>', $text);
            $text = str_replace("[/*]", '</li>', $text);


    but they do not get the desired equivalent in the usual "html" pages.  I sometimes get "indention" and a "bullet" but not the numbered or alphabetized listing.

    How are these  done properly?

    Thanks.

    Cornelio