forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Miscellaneous => Topic started by: Chunky C on December 07, 2006, 09:55:43 pm

Title: Add "Copy bbCode" to displayimage
Post by: Chunky C on December 07, 2006, 09:55:43 pm
Here is my take on adding bbcode to displayimage.php.  The core code I got from here (http://forum.coppermine-gallery.net/index.php?topic=3552.0)

Tested with: CPG Version 1.4.10, IE 6, IE 7 (I also had an earilier version running on 1.3.5)
Ease: Easy

My version allows the webmaster to configure how he/she would like the links displayed.  The options are 'buttons', 'text', 'textarea' and 'textbox'.  See the screen shots below for a screen shot of each option.  Just set the $bbcode_type variable to how you would like the links displayed.  Furthermore, if you want to use the textbox or textarea option, set the $bbcode_textboxsize to how wide you want the textbox.

I also added a popup window that the user can copy the bbcode from for compatability.  I'm not sure if the copy to clipboad method will work on FF, Netscape, Opera, ...

Also I used the language file so that you can translate it to any language that you wish.

I think this hack lends itself nicely to a plugin but I haven't figured out the plugins yets. ??? If / When I get it pluginized, I'll update this.

Credit needs to go to Chris, our other webmaster, for getting this code started.  I modified what he already had and cleaned it up some.

screen shots:

'buttons''text''textarea''textbox'
(http://spadfest.rcspads.com/albums/userpics/10001/thumb_cpg_bbcode_buttons.png) (http://spadfest.rcspads.com/albums/userpics/10001/cpg_bbcode_buttons.png)
(http://spadfest.rcspads.com/albums/userpics/10001/thumb_cpg_bbcode_text.png) (http://spadfest.rcspads.com/albums/userpics/10001/cpg_bbcode_text.png)
(http://spadfest.rcspads.com/albums/userpics/10001/thumb_cpg_bbcode_textarea.png) (http://spadfest.rcspads.com/albums/userpics/10001/cpg_bbcode_textarea.png)
(http://spadfest.rcspads.com/albums/userpics/10001/thumb_cpg_bbcode_textbox.png) (http://spadfest.rcspads.com/albums/userpics/10001/cpg_bbcode_textbox.png)


#
#-----[ OPEN ]------------------------------------------
#
    displayimage.php

Code: [Select]
#
#-----[ OPEN ]------------------------------------------
#
    displayimage.php

#
#-----[ FIND around line # 172]-------------------------
#
    // Create the add to fav link
$ref = $REFERER ? "&ref=$REFERER" : '';
    if (!in_array($CURRENT_PIC_DATA['pid'], $FAVPICS)) {
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . $ref . "\" >" . $lang_picinfo['addFav'] . '</a>';
    } else {
        $info[$lang_picinfo['addFavPhrase']] = "<a href=\"addfav.php?pid=" . $CURRENT_PIC_DATA['pid']  . $ref . "\" >" . $lang_picinfo['remFav'] . '</a>';
    }

#
#-----[ REPLACE WITH ]------------------------------------------
#

/*  Start bbCode display options

  // ** Configure **
  $bbcode_textboxsize = 90;

/************************************************************
   $bbcode_type = {type}
       "button"   will display button links
       "text"     will display text links
       "textarea" will display text box with the bbCode in it
       "textbox"  will display text in a single line text box
 ************************************************************/
  $bbcode_type = "button";


/* Do not change anything below this line.
   unless you know what your doing. */

  //  Create the BBcode with a link to thumbnail
  $bbcodethumb_url = get_pic_url($CURRENT_PIC_DATA, 'thumb');
  $bbcodefull_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
  $bbcodedisplay = '[url=' . $CONFIG["ecards_more_pic_target"] . $bbcodefull_url.'][img]'.$CONFIG["ecards_more_pic_target"].$bbcodethumb_url.'[/img][/url]';

  $bbcodecopy_text = "<a href='javascript:;' onclick=\"window.clipboardData.setData('Text','" . $bbcodedisplay . "');\" title='Click here to copy bbCode (IE only)'>" . $lang_picinfo['copy_bbcode'] . "</a>";
  $bbcodedisp_text = "<a href='javascript:;' onClick=\"MM_openBrWindow('yourpopupfile.php?bb=" . $bbcodedisplay . "','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=600,height=5');\" title='Click to display bbCode'>" . $lang_picinfo['disp_bbcode'] . "</a>";
  $bbcodedisp_textbox = "<small><input class='textinput' type='text' size='$bbcode_textboxsize' value='" . $bbcodedisplay . "'></small>";
  $bbcodedisp_textarea = "<small><textarea class='textinput' rows='4' cols='$bbcode_textboxsize'>" . $bbcodedisplay . "</textarea></small>";
  $favadd_text = "<a href='addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . $ref . "'>" . $lang_picinfo['addFav'] . "</a>";
  $favrem_text = "<a href='addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . $ref . "'>" . $lang_picinfo['remFav'] . "</a>";

  $bbcodecopy_button = "<button class='button' onclick=\"window.clipboardData.setData('Text','" . $bbcodedisplay . "');\">" . $lang_picinfo['copy_bbcode']; // Copy bbCode to clipboard";
  $bbcodedisp_button = "<button class='button' onClick=\"MM_openBrWindow('yourpopupfile.php?bb=" . $bbcodedisplay . "','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=600,height=5')\">" . $lang_picinfo['disp_bbcode'];
  $favadd_button = "<button class='button' onclick=\"window.open('addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . $ref . "','_self');\">" . $lang_picinfo['addFav'] ;
  $favrem_button = "<button class='button' onclick=\"window.open('addfav.php?pid=" . $CURRENT_PIC_DATA['pid'] . $ref . "','_self');\">" . $lang_picinfo['remFav'] ;


// * Show the bbCode link in the File Information section

    // Create the add to fav link
$ref = $REFERER ? "&amp;ref=$REFERER" : '';
    if (!in_array($CURRENT_PIC_DATA['pid'], $FAVPICS)) {

// ** Add to Favorites **
switch ($bbcode_type){
        case "button":
          // ** Button Method **
          $info[$lang_picinfo['copy_bbcode']] = $bbcodecopy_button;
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_button;
          $info[$lang_picinfo['addFavPhrase']] = $favadd_button;
          break;

        case "text":
          //  ** Text Method **
          $info[$lang_picinfo['copy_bbcode']] = $bbcodecopy_text;
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_text;
          $info[$lang_picinfo['addFavPhrase']] = $favadd_text;
          break;

        case "textbox":
          $info['Text Box'] = $bbcodedisp_textbox;
          $info[$lang_picinfo['addFavPhrase']] = $favadd_text;
          break;

        default:
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_textarea;
          $info[$lang_picinfo['addFavPhrase']] = $favadd_text;
          break;
}

    } else {
// ** Remove from Favorites **
switch ($bbcode_type){
        case "button":
          // ** Button Method **
          $info[$lang_picinfo['copy_bbcode']] = $bbcodecopy_button;
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_button;
          $info[$lang_picinfo['addFavPhrase']] = $favrem_button;
    break;

        case "text":
          //  ** Text Method **
          $info[$lang_picinfo['copy_bbcode']] = $bbcodecopy_text;
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_text;
          $info[$lang_picinfo['addFavPhrase']] = $favrem_text;
          break;

        case "textbox":
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_textbox;
          $info[$lang_picinfo['addFavPhrase']] = $favrem_text;
          break;

        default:
          $info[$lang_picinfo['disp_bbcode']] = $bbcodedisp_textarea;
          $info[$lang_picinfo['addFavPhrase'].'2'] = $favrem_text;
      }
    }



#
#-----[ OPEN ]------------------------------------------
#
  lang/english.php

Code: [Select]
#
#-----[ OPEN ]------------------------------------------
#
  lang/english.php

#
#-----[ FIND around line # 1450]------------------------
#
  'movie_player' => 'Play the file in your standard application',

#
#-----[ AFTER, ADD ]------------------------------------
#
  'copy_bbcode' => 'Copy bbCode to Clipboard',
  'disp_bbcode' => 'Display bbCode',

#
#-----[ CREATE ]----------------------------------------
#
  yourpopupfile.php

Code: [Select]
#
#-----[ ADD ]-------------------------------------------
#

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>popup</title>
</head>
<body>
<br>
<table style="margin-left: auto; margin-right: auto; text-align: center; width: 530px; height: 56px;" border="2" cellpadding="10" cellspacing="0">
  <tbody>
    <tr>
      <td rowspan="4" wrap="1" style="width: 75%; vertical-align: middle; height: 50%; text-align: center;">
        <?php print $_GET['bb']; ?>
      </td>
    </tr>
  </tbody>
</table>
</body>
</html>

#
#-----[ SAVE & CLOSE ALL FILES ]--------------------------
#

Title: Re: Add "Copy bbCode" to displayimage
Post by: Stramm on December 07, 2006, 10:41:03 pm
here you can find a bbcode plugin http://forum.coppermine-gallery.net/index.php?topic=36302.0
feel free to modify it to your needs
Title: Re: Add "Copy bbCode" to displayimage
Post by: rrolleston on May 26, 2008, 04:04:51 am
Is it possible to make the text area that shows a link to the picture larger?
Title: Re: Add "Copy bbCode" to displayimage
Post by: Katenkka on August 03, 2008, 04:38:57 pm
Is it possible to make the text area that shows a link to the picture larger?
yes, just replace
Code: [Select]
' . $CONFIG["ecards_more_pic_target"] . $bbcodefull_url.'on
Code: [Select]
' . $CONFIG["ecards_more_pic_target"] . (substr($CONFIG["ecards_more_pic_target"], -1) == '/' ? '' : '/') .basename($_SERVER['PHP_SELF']) . "?pos=-$CURRENT_PIC_DATA[pid]" . 'It works!