Coppermine 1.3.2 Shop hack instructions

Instructions for adding shop hack to an already modifiedCoppermine Photo Gallery v1.3.2
Shop hack by Casper.
For Coppermine credits and copyrights, see Coppermine documentation

The shop hack is available as a simple drop in, replacing all the neccessary files. If you are running an un-modified version of Coppermine, or are unable to follow the instructions below, you are advised to use the prepared hack.

Support for this hack should be asked only on the associated thread in the modifications board of the Coppermine forums.

This hack is not designed for use with Nuke or CMS versions of Coppermine, although a decent coder with knowledge of these versions should be able to make any required changes.
Please do not ask for help with this on the standalone version boards.




Backing up your existing files.

Make copies of all the existing files you are about, and keep them so you can return to these if the modifications we are making cause problems with your existing modifications.



Changes to the language files.

Open your language.php file, found in the 'lang' folder. You will need to do the following changes to all languages you use on your site.

Find;

array('Character encoding', 'charset', 4),

Add below, in a new line, and with at least 1 line space;
'Paypal shop account email',
  array('Paypal email account', 'paypal_email', 0),
  
  
  'Shop sizes and prices',
  array('Size 1', 'size1', 0),
  array('Price size 1', 'size1_price', 0),
  array('Size 2', 'size2', 0),
  array('Price size 2', 'size2_price', 0),
  array('Size 3', 'size3', 0),
  array('Price size 3', 'size3_price', 0),
  array('Size 4', 'size4', 0),
  array('Price size 4', 'size4_price', 0),
  array('Size 5', 'size5', 0),
  array('Price size 5', 'size5_price', 0),
  array('Size 6', 'size6', 0),
  array('Price size 6', 'size6_price', 0),
  array('Size 7', 'size7', 0),
  array('Price size 7', 'size7_price', 0),
  array('Size 8', 'size8', 0),
  array('Price size 8', 'size8_price', 0),
  array('Size 9', 'size9', 0),
  array('Price size 9', 'size9_price', 0),
  array('Size 10', 'size10', 0),
  array('Price size 10', 'size10_price', 0),
  array('Size 11', 'size11', 0),
  array('Price size 11', 'size11_price', 0),
  array('Size 12', 'size12', 0),
  array('Price size 12', 'size12_price', 0),
  array('Size 13', 'size13', 0),
  array('Price size 13', 'size13_price', 0),
  array('Size 14', 'size14', 0),
  array('Price size 14', 'size14_price', 0),
  array('Size 15', 'size15', 0),
  array('Price size 15', 'size15_price', 0),
  array('Size 16', 'size16', 0),
  array('Price size 16', 'size16_price', 0),
  array('Size 17', 'size17', 0),
  array('Price size 17', 'size17_price', 0),
  array('Size 18', 'size18', 0),
  array('Price size 18', 'size18_price', 0),
  array('Size 19', 'size19', 0),
  array('Price size 19', 'size19_price', 0),
  array('Size 20', 'size20', 0),
  array('Price size 20', 'size20_price', 0),
  array('Currency symbol US$ - Can$ - £ - € - ¥', 'currency_symbol', 0),
  array('Currency USD-CAD-GBP-EUR-JPY', 'currency', 0),
  
Save and close your language files.




Changing the sql files.

open your sql/update.php, and add the following at the bottom of the page.

#
#add shop fields for shop hack
#
INSERT INTO CPG_config VALUES ('size1', '0');
INSERT INTO CPG_config VALUES ('size2', '0');
INSERT INTO CPG_config VALUES ('size3', '0');
INSERT INTO CPG_config VALUES ('size4', '0');
INSERT INTO CPG_config VALUES ('size5', '0');
INSERT INTO CPG_config VALUES ('size6', '0');
INSERT INTO CPG_config VALUES ('size7', '0');
INSERT INTO CPG_config VALUES ('size8', '0');
INSERT INTO CPG_config VALUES ('size9', '0');
INSERT INTO CPG_config VALUES ('size10', '0');
INSERT INTO CPG_config VALUES ('size11', '0');
INSERT INTO CPG_config VALUES ('size12', '0');
INSERT INTO CPG_config VALUES ('size13', '0');
INSERT INTO CPG_config VALUES ('size14', '0');
INSERT INTO CPG_config VALUES ('size15', '0');
INSERT INTO CPG_config VALUES ('size16', '0');
INSERT INTO CPG_config VALUES ('size17', '0');
INSERT INTO CPG_config VALUES ('size18', '0');
INSERT INTO CPG_config VALUES ('size19', '0');
INSERT INTO CPG_config VALUES ('size20', '0');
INSERT INTO CPG_config VALUES ('size1_price', '0');
INSERT INTO CPG_config VALUES ('size2_price', '0');
INSERT INTO CPG_config VALUES ('size3_price', '0');
INSERT INTO CPG_config VALUES ('size4_price', '0');
INSERT INTO CPG_config VALUES ('size5_price', '0');
INSERT INTO CPG_config VALUES ('size6_price', '0');
INSERT INTO CPG_config VALUES ('size7_price', '0');
INSERT INTO CPG_config VALUES ('size8_price', '0');
INSERT INTO CPG_config VALUES ('size9_price', '0');
INSERT INTO CPG_config VALUES ('size10_price', '0');
INSERT INTO CPG_config VALUES ('size11_price', '0');
INSERT INTO CPG_config VALUES ('size12_price', '0');
INSERT INTO CPG_config VALUES ('size13_price', '0');
INSERT INTO CPG_config VALUES ('size14_price', '0');
INSERT INTO CPG_config VALUES ('size15_price', '0');
INSERT INTO CPG_config VALUES ('size16_price', '0');
INSERT INTO CPG_config VALUES ('size17_price', '0');
INSERT INTO CPG_config VALUES ('size18_price', '0');
INSERT INTO CPG_config VALUES ('size19_price', '0');
INSERT INTO CPG_config VALUES ('size20_price', '0');
INSERT INTO CPG_config VALUES ('currency_symbol', '£');
INSERT INTO CPG_config VALUES ('currency', 'GBP');
INSERT INTO CPG_config VALUES ('paypal_email', '');


Save and close your update.php.



Changes to your theme files.

The following changes will need to be made to all themes you will be using. If you are going to use.

Open themes/your_theme/template.html, and find;

<script type="text/javascript" src="scripts.js"></script>


Add, after the above;
<script type="text/javascript">

<!-- Hide JS source from HTML validators
function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) { // process un-named selects
var i,amt,des,obj,pos,val;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description
  for (i=0; i= 0) amt = val.substring (pos + 1)*1.0;
      pos  = val.indexOf ("+");       // price increment?
      if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
      pos  = val.indexOf ("%");       // percent change?
      if (pos >= 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
      if (des.length == 0) des = val;
      else des = des + ", " + val;    // accumulate value
    }
  }
  obj1.item_name.value = des;
  obj1.amount.value = Dollar (amt);
  if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
}
//-->
</script>

Save and close your template.html.

Open themes/your_theme/theme.php.

The first thing is to add the 'View Basket' button. The positioning of this code will depend on which theme you use, and in some themes may even be better in the template.html.
If not sure, look at the code in the pre-prepared themes to see where I added it for the theme you want.
This is where a bit of 'suck it and see' may be needed.
The following is for adding it to the classic theme, or any custom theme based on that.
Open theme.php, and find;
$template_main_menu = <<<EOT
                <span class="topmenu">
Now add, immediately after that;
<!--  view basket button  -->
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value='{$CONFIG['paypal_email']}'>
<input type="image" src="https://www.paypal.com/en_GB/i/btn/view_cart_02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form>


Now we will replace the album sort selection with instructions for customers to click on pics to buy.

Find;
// HTML template for title row of the thumbnail view (album title + sort options)
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="0" cellspacing="0"&rt;
                        <tr&rt;
                                <td width="100%" class="statlink"&rt;<h2&rt;{ALBUM_NAME}</h2&rt;</td&rt;
                                <td&rt;<img src="images/spacer.gif" width="1"&rt;</td&rt;
                                <td class="sortorder_cell"&rt;
                                        <table height="100%" cellpadding="0" cellspacing="0"&rt;
                                        <tr&rt;
                                <td class="sortorder_options"&rt;{TITLE}</td&rt;
                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=ta" title="{SORT_TA}"&rt; + </a&rt;</span&rt;</td&rt;
                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=td" title="{SORT_TD}"&rt; - </a&rt;</span&rt;</td&rt;
                                        </tr&rt;
                                        <tr&rt;
                                                <td class="sortorder_options"&rt;{NAME}</td&rt;
                                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=na" title="{SORT_NA}"&rt; + </a&rt;</span&rt;</td&rt;
                                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=nd" title="{SORT_ND}"&rt; - </a&rt;</span&rt;</td&rt;
                                        </tr&rt;
                                        <tr&rt;
                                                <td class="sortorder_options"&rt;{DATE}</td&rt;
                                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=da" title="{SORT_DA}"&rt; + </a&rt;</span&rt;</td&rt;
                                                <td class="sortorder_options"&rt;<span class="statlink"&rt;<a href="thumbnails.php?album={AID}&page={PAGE}&sort=dd" title="{SORT_DD}"&rt; - </a&rt;</span&rt;</td&rt;
                                        </tr&rt;
                                        </table&rt;
                                </td&rt;
                        </tr&rt;
                        </table&rt;


And replace it with the code below, changing the 'Click to buy to your language as required;
// HTML template for title row of the thumbnail view (album title + sort options)
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                                <td width="50%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
                                <td><img src="images/spacer.gif" width="1"></td>
                                <td class="statlink">
                 <h3>Click on pic to see large version and to buy.</h3>                      
                                </td>
                        </tr>
                        </table>


Now we will add the selection and purchase buttons.

Find;
<!-- BEGIN title -->
                                <tr>
                                        <th>
                                                {TITLE}
                                        </th>
                                </tr>
<!-- END title -->
<!-- BEGIN caption -->
                                <tr>
                                        <td>
                                                {CAPTION}
                                        </td>
                                </tr>
<!-- END caption -->


And replace it with;
<!-- BEGIN title -->
                                <tr>
                                        <th>
                                               Picture; {TITLE}
                                        </th>
                                </tr>
<!-- END title -->
<!-- BEGIN caption -->
<tr>
                                        <th><center>
                                                {CAPTION}
                                        </th>
                                </tr>

                                <tr>
                                        <td font size="-1"><center>
                                                
	<table>		<tr><td valign="top"><form action="https://www.paypal.com/cgi-bin/webscr" method="post" 
onsubmit="this.target = 'paypal';
          ReadForm (this);">
<p>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="{$CONFIG['paypal_email']}" />
<input type="hidden" name="item_name" value="Photo Name : {TITLE}" />
<input type="hidden" name="amount" value="" />
<input type="hidden" name="currency_code" value="{$CONFIG[currency]}" />


<input type="hidden" name="baseamt" value="{$CONFIG['size1_price']}" />
<input type="hidden" name="basedes" value="Photo Name, '{TITLE}', Filename, '{FILENAME}'" />

 
Select size and frame here   
<select onchange = "ReadForm (this.form);">
<option value="{$CONFIG['size1']} @{$CONFIG['size1_price']} ">{$CONFIG['size1']};    {$CONFIG[currency_symbol]}{$CONFIG['size1_price']}   </option>
<option value="{$CONFIG['size2']} @{$CONFIG['size2_price']}">{$CONFIG['size2']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size2_price']}   </option>
<option value="{$CONFIG['size3']} @{$CONFIG['size3_price']}">{$CONFIG['size3']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size3_price']}</option>
<option value="{$CONFIG['size4']} @{$CONFIG['size4_price']}">{$CONFIG['size4']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size4_price']}</option>
<option value="{$CONFIG['size5']} @{$CONFIG['size5_price']}">{$CONFIG['size5']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size5_price']}</option>
<option value="{$CONFIG['size6']} @{$CONFIG['size6_price']}">{$CONFIG['size6']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size6_price']}</option>
<option value="{$CONFIG['size7']} @{$CONFIG['size7_price']}">{$CONFIG['size7']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size7_price']}</option>
<option value="{$CONFIG['size8']} @{$CONFIG['size8_price']}">{$CONFIG['size8']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size8_price']}</option>
<option value="{$CONFIG['size9']} @{$CONFIG['size9_price']}">{$CONFIG['size9']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size9_price']}</option>
<option value="{$CONFIG['size10']} @{$CONFIG['size10_price']}">{$CONFIG['size10']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size10_price']}</option>
<option value="{$CONFIG['size11']} @{$CONFIG['size11_price']} ">{$CONFIG['size11']};    {$CONFIG[currency_symbol]}{$CONFIG['size11_price']}</option>
<option value="{$CONFIG['size12']} @{$CONFIG['size12_price']}">{$CONFIG['size12']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size12_price']}</option>
<option value="{$CONFIG['size13']} @{$CONFIG['size13_price']}">{$CONFIG['size13']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size13_price']}</option>
<option value="{$CONFIG['size14']} @{$CONFIG['size14_price']}">{$CONFIG['size14']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size14_price']}</option>
<option value="{$CONFIG['size15']} @{$CONFIG['size15_price']}">{$CONFIG['size15']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size15_price']}</option>
<option value="{$CONFIG['size16']} @{$CONFIG['size16_price']}">{$CONFIG['size16']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size16_price']}</option>
<option value="{$CONFIG['size17']} @{$CONFIG['size17_price']}">{$CONFIG['size17']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size17_price']}</option>
<option value="{$CONFIG['size18']} @{$CONFIG['size18_price']}">{$CONFIG['size18']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size18_price']}</option>
<option value="{$CONFIG['size19']} @{$CONFIG['size19_price']}">{$CONFIG['size19']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size19_price']}</option>
<option value="{$CONFIG['size20']} @{$CONFIG['size20_price']}">{$CONFIG['size20']} ;    {$CONFIG[currency_symbol]}{$CONFIG['size20_price']}</option>
</select>
   
Paper   
<input type="hidden" name="on0" value="Paper"><select name="os0"><option value="Glossy">Glossy<option value="Matt">Matt<option value="Satin">Satin</select>
    


<input type="image" src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" name="submit" alt="cart add" />

</p>
</form></td></tr>


		</table>	
		
		
                                        </td>
                                </tr>

<!-- END caption -->

The above code assumes you are going to provide your customers with a choice of 20 sizes/frames etc. If you are offering less than that, edit the above code to remove the lines you are not using, i.e., if offering 6 choices, remove the lines for size7 to size20.

You can edit the line for paper selection, to say what you want, for instance, change 'Satin' to 'Lustre'. You can also remove this line if not offering a choice of paper type.

Save and close your theme files.



Changes to displayimage.php

Open displayimage.php, and find;

'{IMAGE}' => $pic_html,
        '{ADMIN_MENU}' => $picture_menu,
        '{TITLE}' => $CURRENT_PIC_DATA['title'],
        '{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),


Add after;
'{FILENAME}' => $CURRENT_PIC_DATA['filename'],


Save and close displayimage.php.


Changes to index.php.

These changes are not absolutely required, but remove the album info (number of files, last added etc.) from the album index page, which you may want to keep.

Open index.php, and find, and comment out, the following lines, which are in the file 4 times;

$alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");


Save and close index.php




Applying the hack to your install.

  • Upload the changed files to your server.
  • Browse to www.your_site.com/your_gallery/update.php, and click 'continue, at the bottom of the page.
  • Log in, and go to the config page. Fill in your paypal registered email address, and the sizes/prices you have available.