Install Instructions (also available in the zip download):
###############################################
## MOD Title: Tiff Image Display
## MOD Author: Garibaldi (Garibaldi@wiscollectorcar.com)
http://www.wiscollectorcar.com## MOD Description: Allows users to upload tiff images which are then converted to jpgs for display while the orininal tiff is still available for download
## MOD Version: 1.1.0
## Installation Level: Easy
## Installation Time: 10 minutes
## Requirements: Imagemagick
## Files To Edit:2
## delete.php
## upload.php
## Included Files:
## albums/tiff_downloads/
## License:
http://opensource.org/licenses/gpl-license.php GNU General Public License v3
##############################################################
## Author Notes:
## This modification requires that you use imagemagick for processing images
##
## Once this modification is applied, the user2 custom field cannot be used
## for something else except this mod. Please uninstall this mod if you
## want to use user2 again and cannot use user1, user3, or user4 instead.
##############################################################
## MOD History:
## 2009-08-03- version 1.1.0 now deletes the uploaded tiff when deleting a picture
## 2009-07-29- version 1.0.1 - bugfixes with multiple uploads
## 2009-07-29- version 1.0.0
##############################################################
## Before Adding This MOD To Your Coppermine install, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ IN COPPERMINE ]---------------------------------
#
Log in as an administrator and go to Config. Expand the section
"Custom fields for image description (leave blank if unused)" and
enter a name in "Field 2 name" like "Download Tiff". Now, expand the
section "Files and thumbnails advanced settings" and for
"Method for resizing images", select "Image Magick". Fill in the
"Path to ImageMagick 'convert' utility", e.g. "/usr/bin/" . Save the new
configuration.
#
#-----[ UPLOAD ]----------------------------------------
#
Upload the tiff_downloads/ folder into the albums/ folderand chmod it
to 777. It must have group read/write permissions for the tiff images
to be uploaded
#
#-----[ OPEN ]------------------------------------------
#
delete.php
#
#-----[ FIND ]------------------------------------------
#
if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], htmlspecialchars($dir)), __FILE__, __LINE__);
#
#-----[ BEFORE, ADD ]-----------------------------------
#
// start garibaldi
$g_query = "SELECT user2 FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'";
$g_result = cpg_db_query($g_query);
$g_user2 = mysql_fetch_array($g_result);
foreach($g_user2 as $key => $value) {
if (strpos($value, "http") === false) {
} else {
// if its the url, grab it and cut off the part we don't want and put on the server path
$path = str_replace($CONFIG['ecards_more_pic_target'], "", $value);
}
}
if (is_file($path)) {
unlink($path);
}
// end garibaldi
#
#-----[ OPEN ]------------------------------------------
#
upload.php
#
#-----[ FIND ]------------------------------------------
#
$allowed_URI_boxes = NUM_URI_BOXES;
$allowed_file_boxes = NUM_FILE_BOXES;
#
#-----[ After, ADD ]------------------------------------
#
// garibaldi start
$g_debug = false; // set this to true to see debug during upload
$mod_name = "Tiff Image Display"; // the name of the modification by garibaldi
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
$form_array[] = array($CONFIG['user_field2_name'], 'user2', 0, 255, 1);
#
#-----[ REPLACE WITH ]----------------------------------
#
// garibaldi start
$num_left = $_POST['numuploads'] - 1;
$tiffpath = "";
if (!empty($_POST['tiffpath'])) {
$paths = explode(";", $_POST['tiffpath']);
$_POST['tiffpath'] = "";
$length = count($paths);
$tiffpath = $paths[$num_left];
if ($tiffpath == "not") {
$tiffpath = "";
}
$i = 0;
foreach ($paths as $key => $value) {
if ($i < $num_left) {
$_POST['tiffpath'] .= $value . ";";
}
$i++;
}
}
$form_array[] = array('numuploads', $num_left, 4); // create a hidden field to show the number image we're on
$form_array[] = array('tiffpath', $_POST['tiffpath'], 4); // create a hidden field to show the number image we're on
$form_array[] = array('user2', $tiffpath, 4); // use user2 as a hidden field containing the tiff url
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
// Assemble the file path.
$path_to_image = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;
} while (file_exists($path_to_image));
// Create a holder called $tempname.
$tempname = $prefix . $seed . '.' . $suffix;
#
#-----[ REPLACE WITH ]----------------------------------
#
// garibaldi start
$g_debug_messages = ""; // the debug messages
$g_debug_messages .= "Initial Suffix: " . $suffix . "<br>";
$tiff_storage = './'.$CONFIG['fullpath'].'tiff_downloads/'; // the location of the tiff files on the server
$pos = strpos($suffix,"tif"); // determine if this is a tiff image
$isTiff = false;
if($pos === false) { // if its not a tiff, proceed as normal
// Assemble the file path.
$path_to_jpg = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;
$g_debug_messages .= "Its not a tiff image<br>";
}
else { // it is a tiff, lets create a jpg version
// Convert the image, then assemble the file path
$g_debug_messages .= "Its a tiff image<br>";
$path_to_jpg = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.jpg';
$isTiff = true;
}
$path_to_image = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;
//
} while (file_exists($path_to_image));//
//
// Create a holder called $tempname.//
// $tempname = $prefix . $seed . '.' . $suffix; // garibaldi
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
//Now we upload the file.
if (!(move_uploaded_file($_FILES['file_upload_array']['tmp_name'][$counter], $path_to_image))) {
// The file upload has failed.
$file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['impossible']);
// There is no need for further tests or action, so skip the remainder of the iteration.
continue;
}
#
#-----[ AFTER, ADD ]------------------------------------
#
// garibaldi start
// Change file permission
@chmod($path_to_image, octdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled
$convert_output_arr = ""; // the output from the imagemagick call as an array
$convert_output = ""; // the output from the imagemagick call as a string (for display)
if ($isTiff) {
exec("convert " . $path_to_image . " " . $path_to_jpg, $convert_output_arr); // do the conversion to create a jpg
$path_to_tiff = $path_to_image; // set the tiff path
$path_to_image = $path_to_jpg; // update the image path to point to the jpg version
foreach ($convert_output_arr as $key => $value) { // create the string output of the conversion call
$convert_output .= $value . "<br>";
}
}
$g_debug_messages .= "picture_name: " . $picture_name . "<br>";
$tiff_final_location = $tiff_storage . $seed . "." . $suffix; // set the final location of the tiff
// now its okay for the suffixes to be adjusted
if ($isTiff) { // its a tiff, set the variables
$suffix = "tif";
$matches[2] = $suffix;
if (strpos($picture_name, "tiff") == false) {
// the extension is tif, change it to jpg
$g_debug_messages .= "The extension is 'tif', changing it<br>";
$picture_name = str_replace("tif", "jpg", $picture_name);
} else {
// the extension is tiff, change it to jpg
$g_debug_messages .= "The extension is 'tiff', changing it<br>";
$picture_name = str_replace("tiff", "jpg", $picture_name);
}
$suffix = "jpg";
$matches[2] = "jpg";
$matches[0] = $matches[1] . "." . $matches[2];
}
// Create a holder called $tempname.
$tempname = $prefix . $seed . '.' . $suffix;
$g_debug_messages .= "The new picture name: " . $picture_name . "<br>";
if (copy($path_to_tiff, $tiff_final_location)) { // if we can successfully move the tif, then proceed
unlink($path_to_tiff);
$g_tiff_names = $tiff_final_location;
} else {
$tiff_final_location = $path_to_tiff;
$g_tiff_names = "";
}
// format the url correctly (only if its a tiff)
if ($g_tiff_names != "") {
if (substr($g_tiff_names,0,1) == ".") {
$g_tiff_names = substr($g_tiff_names, 1);
}
if ((substr($CONFIG['site_url'], strlen($CONFIG['site_url'])-1) == "/") && (substr($g_tiff_names, 0, 1) == "/")) {
$g_tiff_names = substr($g_tiff_names, 1);
}
$g_tiff_names = $CONFIG['site_url'] . $g_tiff_names; // set the tiff url
}
if ($isTiff) {
$_POST['tiffpath'] .= $g_tiff_names . ";"; // update the POST info with the tiff url
} else {
$_POST['tiffpath'] .= "not;"; // update the POST info with the tiff url
}
// compile all the debug
$g_debug_messages .= "convert output: " . $convert_output . "<br>tiff path: " . $tiff_final_location . "<br>jpg path: ";
$g_debug_messages .= $path_to_image . "<br>picture_name: " . $picture_name . "<br>matches[0]: " . $matches[0];
$g_debug_messages .= "<br>matches[1]: " . $matches[1] . "<br>matches[2]: " . $matches[2] . "<br>tempname: " . $tempname;
$g_debug_messages .= "<br>Tiff POST: " . $_POST['tiffpath'];
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
// Prepare success data for user.
open_form($_SERVER['PHP_SELF']); // Set the form action to this script.
starttable("100%", $lang_upload_php['succ'], 2);
echo "<tr><td colspan=\"2\">";
printf ($lang_upload_php['success'], $escrow_array_count);
echo "<br /><br />";
echo $lang_upload_php['add'];
echo "</td></tr>";
#
#-----[ AFTER, ADD ]------------------------------------
#
// garibaldi start
// send the tiff path information
hidden_input("tiffpath", $_POST['tiffpath']);
hidden_input("numuploads", $escrow_array_count);
if ($g_debug) {
echo "<tr><td><u><b>$mod_name Debug:</b></u><br>" . $g_debug_messages . "<br></td></tr>";
}
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
if ($file_placement == 'no') {
$final_message = ''.$lang_upload_php['no_place'].'<br /><br />'.$lang_upload_php['process_complete'];
} else {
$final_message = ''.$lang_upload_php['yes_place'].'<br /><br />'.$lang_upload_php['process_complete'];
}
#
#-----[ REPLACE WITH ]----------------------------------
#
// garibaldi start
if ($file_placement == 'no') {//
// set up some debug output
$final_message = ''.$lang_upload_php['no_place'].'<br />';
if ($g_debug) {
$final_message .= "<br /><b><u>$mod_name Debug:</u></b>";
$final_message .= "<br />filename: $file_set[1]<br />";
$final_message .= "tiff location: $user2<br />$g_debug_output<br />";
}
//
$final_message .= '<br />'.$lang_upload_php['process_complete'];
//
} else { //
//
$final_message = ''.$lang_upload_php['yes_place'].'<br /><br />'.$lang_upload_php['process_complete'];//
if ($g_debug) {
$final_message .= "<br /><b><u>$mod_name Debug:</u></b>";
$final_message .= "<br />filename: $file_set[1]<br />";
$final_message .= "tiff location: $user2<br />$g_debug_output<br />";
}
}//
// garibaldi end
#
#-----[ FIND ]------------------------------------------
#
$form_array[] = array($CONFIG['user_field2_name'], 'user2', 0, 255, 1);
#
#-----[ REPLACE WITH ]----------------------------------
#
// garibaldi start
$num_left = $_POST['numuploads'] - 1;
$tiffpath = "";
if (!empty($_POST['tiffpath'])) {
$paths = explode(";", $_POST['tiffpath']);
$_POST['tiffpath'] = "";
$length = count($paths);
$tiffpath = $paths[$num_left];
if ($tiffpath == "not") {
$tiffpath = "";
}
$i = 0;
foreach ($paths as $key => $value) {
if ($i < $num_left) {
$_POST['tiffpath'] .= $value . ";";
}
$i++;
}
}
$form_array[] = array('numuploads', $num_left, 4); // create a hidden field to show the number image we're on
$form_array[] = array('tiffpath', $_POST['tiffpath'], 4); // create a hidden field to show the number image we're on
$form_array[] = array('user2', $tiffpath, 4); // use user2 as a hidden field containing the tiff url // garibaldi end
#
#-----[ NOTE ]------------------------------------------
#
Once this modification is applied, the user2 custom field cannot be used
for something else except this mod. Please uninstall this mod if you
want to use user2 again and cannot use user1, user3, or user4 instead.
#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------
#
# EoM