* @copyright Copyright 2005-2006 breakmyzencart.com * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0 * @version $Id: image_handler.php,v 1.5 2006/05/01 12:16:43 tim Exp $ */ require('includes/application_top.php'); require(DIR_WS_CLASSES . 'currencies.php'); require_once(DIR_FS_CATALOG . DIR_WS_CLASSES . 'bmz_image_handler.class.php'); define('HEADING_TITLE', IH_HEADING_TITLE); define('HEADING_TITLE_PRODUCT_SELECT', IH_HEADING_TITLE_PRODUCT_SELECT); global $messageStack; $page = isset($_GET['page']) ? $_GET['page'] : ((!defined('IH_VERSION') || (IH_VERSION == 'REMOVED')) ? 'admin' : 'manager'); $action = (isset($_GET['action']) ? $_GET['action'] : ''); $products_filter = (isset($_GET['products_filter']) ? $_GET['products_filter'] : $products_filter); $current_category_id = (isset($_GET['current_category_id']) ? $_GET['current_category_id'] : $current_category_id); $currencies = new currencies(); $import_info = null; function get_image_details_string( $filename ) { if (!file_exists( $filename )) { return "no info"; } $str = ""; // find out some details about the file $image_size = @getimagesize($filename); $image_fs_size = filesize($filename); $str .= $image_size[0]."x".$image_size[1]; $str .= "
". round($image_fs_size/1024, 2) . "Kb"; return $str; } // // Search the base directory and find additional images // function find_additional_images(&$array, $directory, $extension, $base ) { $image = $base . $extension; // Check for additional matching images if ($dir = @dir($directory)) { while ($file = $dir->read()) { if (!is_dir($directory . $file)) { if(preg_match("/^" . $base . "/i", $file) == '1') { // echo "BASE: ".$base.' FILE: '.$file.'
'; if (substr($file, 0, strrpos($file, '.')) != substr($image, 0, strrpos($image, '.'))) { if ($base . preg_replace("/^$base/", '', $file) == $file) { $array[] = $file; // echo 'I AM A MATCH ' . $products_image_directory . '/'.$file . $products_image_extension .'
'; } else { // echo 'I AM NOT A MATCH ' . $file . '
'; } } } } } if (sizeof($array) > 1) { sort($array); } $dir->close(); return 1; } return 0; } function find_original_image($src) { global $ihConf; // try to find file by using different file extensions if initial // source doesn't succeed $imageroot = $ihConf['dir']['docroot'] . $ihConf['dir']['images'] . 'original/'; if (is_file($imageroot . $src)) { return 'original/' . $src; } else { // do a quick search for files with common extensions $extensions = array('.png', '.PNG', '.jpg', '.JPG', '.jpeg', '.JPEG', '.gif', '.GIF'); $base = substr($src, 0, strrpos($src, '.')); for ($i=0; $iread()) { if (!is_dir($directory . $file)) { if(preg_match("/^" . $imageroot . $base . "/i", $file) == '1') { $file_ext = substr($file, strrpos($file, '.')); if (is_file($imageroot . $base . $file_ext)) { return 'original/' . $base . $file_ext; } } } } } } // still here? no file found... return false; } function get_import_info() { global $db; $products = $db->Execute("select products_id, products_image from " . TABLE_PRODUCTS . " where products_image != '' order by products_image asc"); $previous_image = ''; $info = array(); $index = 0; $previous_image = ''; while (!$products->EOF){ $image = $products->fields['products_image']; if ($image != $previous_image) { $previous_image = $image; $original_image = find_original_image($image); if ($original_image) { $info[$index]['source'] = $image; $info[$index]['original'] = $original_image; $info[$index]['target'] = preg_replace('/^original\//', '', $original_image); $index++; } } $products->MoveNext(); } return $info; } if ($action == 'set_products_filter') { $_GET['products_filter'] = $_POST['products_filter']; zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=manager&products_filter=' . $_GET['products_filter'])); } if ($page == 'manager') { // manager actions are handled in a seperate file require('includes/ih_manager.php'); } if ($action == 'ih_remove') { $error = remove_image_handler(); if ($error) { $messageStack->add($error, 'error'); } else { zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=admin&action=ih_remove_success')); } } if ($action == 'ih_remove_success') { $messageStack->add(IH_REMOVED, 'success'); } if ($action == 'ih_install') { $error = install_image_handler(); if ($error) { $messageStack->add($error, 'error'); } else { zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=admin&action=ih_install_success')); } } if ($action == 'ih_install_success') { $messageStack->add(IH_INSTALLED, 'success'); } if ($action == 'ih_update') { $error = update_image_handler(); if ($error) { $messageStack->add($error, 'error'); } else { zen_redirect(zen_href_link(FILENAME_IMAGE_HANDLER, 'page=admin&action=ih_update_success')); } } if ($action == 'ih_update_success') { $messageStack->add(IH_UPDATED, 'success'); } if ($action == 'ih_import_images') { $files = get_import_info(); $previous_image = ''; $imageroot = $ihConf['dir']['docroot'] . $ihConf['dir']['images']; if (count($files) > 0) { for ($i = 0; $i < count($files); $i++) { // Remove destination file if it's there @unlink($imageroot . $files[$i]['target']); if (rename($imageroot . $files[$i]['original'], $imageroot . $files[$i]['target'])) { // Update database if ($files[$i]['target'] != $files[$i]['source']) { $db->Execute("update " . TABLE_PRODUCTS . " set products_image='" . $files[$i]['target'] . "' where products_image='" . $files[$i]['source'] . "'"); } @unlink($imageroot . $files[$i]['source']); $messageStack->add(TEXT_MSG_IMPORT_SUCCESS . $files[$i]['original'] . ' => ' . $files[$i]['target'], 'success'); } else { $messageStack->add(TEXT_MSG_IMPORT_FAILURE . $files[$i]['original'] . ' => ' . $files[$i]['target'], 'error'); } } $messageStack->add(IH_IMAGES_IMPORTED, 'success'); } } if ($action == 'ih_scan_originals') { $import_info = get_import_info(); if (count($import_info) <= 0) { $messageStack->add(IH_NO_ORIGINALS, 'caution'); } } if ($action == 'ih_clear_cache') { $error = bmz_clear_cache(); if (!$error) { $messageStack->add(IH_CACHE_CLEARED, 'success'); } } ?> > <?php echo TITLE; ?>

'; } else { echo IH_VERSION_NOT_FOUND . '
'; } ?>
'; echo zen_draw_form('search', FILENAME_CATEGORIES, '', 'get'); // show reset search if (isset($_GET['search']) && zen_not_null($_GET['search'])) { echo '' . zen_image_button('button_reset.gif', IMAGE_RESET) . '  '; } echo HEADING_TITLE_SEARCH_DETAIL . ' ' . zen_draw_input_field('search'); if (isset($_GET['search']) && zen_not_null($_GET['search'])) { $keywords = zen_db_input(zen_db_prepare_input($_GET['search'])); echo '
' . TEXT_INFO_SEARCH_DETAIL_FILTER . $keywords; } echo ''; echo '
'; } ?>
?>

Please donate. Why?


Donors’ list



Visa, MasterCard, Discover, American Express, eCheck

'; } if ($action == 'ih_scan_originals') { if (count($import_info) > 0) { echo zen_draw_form('import_form', FILENAME_IMAGE_HANDLER, '', 'get'); echo zen_draw_hidden_field('action', 'ih_import_images'); echo IH_CONFIRM_IMPORT . '
'; echo zen_image_submit('button_confirm.gif', IMAGE_CONFIRM) . '

'; for ($i = 0; $i < count($import_info); $i++) { echo "#$i: " . $import_info[$i]['original'] . ' => ' . $import_info[$i]['target'] . '

'; } echo '

' . IH_CONFIRM_IMPORT . '
'; echo zen_image_submit('button_confirm.gif', IMAGE_CONFIRM) . '
'; echo ''; } } if (count($ih_admin_actions) > 0) { echo '
    '; foreach ($ih_admin_actions as $action_name => $link_name) { echo '
  • ' . $link_name . '
  • '; } echo '
'; } /** * MANAGER TABPAGE */ if ($page == 'manager') { $curr_page = FILENAME_IMAGE_HANDLER; require(DIR_WS_MODULES . FILENAME_PREV_NEXT_DISPLAY); ?>
method="post">
 
' . TEXT_PRICED_BY_ATTRIBUTES . '' . '
' : ''); echo zen_get_products_display_price($_GET['products_filter']) . '

'; echo zen_get_products_quantity_min_units_display($_GET['products_filter'], $include_break = true); $not_for_cart = $db->Execute("select p.products_id from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCT_TYPES . " pt on p.products_type= pt.type_id where pt.allow_add_to_cart = 'N'"); } else { echo ''; $not_for_cart = ''; } ?>
fields, true, $_GET['products_filter'], true, true); ?>
' . zen_image_button('button_edit_product.gif', IMAGE_EDIT_PRODUCT) . '
' . TEXT_PRODUCT_EDIT . ''; echo '
'; echo '' . zen_image_button('button_edit_attribs.gif', IMAGE_EDIT_ATTRIBUTES) . '
' . TEXT_ATTRIBUTE_EDIT . '
' . '   '; } ?>

Execute("select p.products_id, p.products_model, p.products_image, p.product_is_free, p.product_is_call, p.products_quantity_mixed, p.products_priced_by_attribute, p.products_status, p.products_discount_type, p.products_discount_type_from, p.products_price_sorter, pd.products_name, p.master_categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $_GET['products_filter'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"); if ($product->RecordCount() > 0) { $pInfo = new objectInfo($product->fields); } // Determine if there are any images and work out the file names // (based on code from modules/pages/product_info/main_template_vars_images(& _additional) (copying is evil!)) if ($pInfo->products_image != '') { $products_image = $pInfo->products_image; $products_image_match_array = array(); // get file extension and base $products_image_extension = substr($products_image, strrpos($products_image, '.')); $products_image_base = preg_replace("/".$products_image_extension."$/", '', $products_image); // if in a subdirectory if (strrpos($products_image_base, '/')) { $products_image_base = substr($products_image_base, strrpos($products_image_base, '/')+1); } // sort out directory $products_image_directory = substr($products_image, 0, strrpos($products_image, '/')); // add slash to base dir if (($products_image_directory != '') && (!ereg("\/$", $products_image_directory))) { $products_image_directory .= '/'; } $products_image_directory_full = DIR_FS_CATALOG . DIR_WS_IMAGES . $products_image_directory; // Check that the image exists! (out of date Database) if (file_exists( $products_image_directory_full . $products_image_base . $products_image_extension )) { // Add base image to array $products_image_match_array[] = $products_image_base . $products_image_extension; // $products_image_base .= "_"; // Check for additional matching images find_additional_images($products_image_match_array, $products_image_directory_full, $products_image_extension, $products_image_base ); } } // if products_image ?> products_id != '') { ?>

products_id . '  ' . $pInfo->products_name; ?>    products_model != '') { echo TEXT_PRODUCTS_MODEL . ': ' . $pInfo->products_model; } ?>     products_image != '') { if (preg_match("/^([^\/]+)\//", $pInfo->products_image, $matches)) { echo TEXT_IMAGE_BASE_DIR .': '; echo $matches[1]; } } ?>

'' . TEXT_INFO_IMAGE_INFO . ''); $contents = array('align' => 'center', 'form' => zen_draw_form('image_define', FILENAME_IMAGE_HANDLER, 'page=' . $_GET['page'] . '&products_filter=' . $_GET['products_filter'] . '&action=save', 'post', 'enctype="multipart/form-data"')); $contents[] = array('text' => ''.TEXT_INFO_NAME.': ' . $selected_image_name .'
'); $contents[] = array('text' => ''.TEXT_INFO_FILE_TYPE.': ' . $selected_image_extension .'
'); $contents[] = array('text' => '' ); // show new, delete, and edit buttons $contents[] = array('align' => 'center', 'text' => '
' . ' ' . zen_image_button('button_edit.gif', IMAGE_EDIT) . '   ' .' ' . zen_image_button('button_delete.gif', IMAGE_DELETE) . '  ' .' ' . zen_image_button('button_new_file.gif', IMAGE_NEW) . ''); break; case 'layout_edit': // Edit specific details $imgNameStr = '&imgEdit=1' .'&imgBase=' . $products_image_base . "&imgSuffix=" . $selected_image_suffix . "&imgBaseDir=" . $products_image_directory . "&imgExtension=" . $selected_image_extension; $heading[] = array('text' => '' . TEXT_INFO_EDIT_PHOTO . ''); case 'layout_new': if ( $action != 'layout_edit' ) { $imgNameStr .= ( $no_images == 1 ) ? "&newImg=1" : '&imgBase='.$products_image_base . "&imgBaseDir=" . $products_image_directory . "&imgExtension=" . $products_image_extension; $heading[] = array('text' => '' . TEXT_INFO_NEW_PHOTO . ''); } $contents = array('form' => zen_draw_form('image_define', FILENAME_IMAGE_HANDLER, '&products_filter=' . $_GET['products_filter'] . $imgNameStr .'&action=save', 'post', 'enctype="multipart/form-data"')); // check if this is a master image or if no images exist if ($no_images == 1) { $contents[] = array('text' => ''.TEXT_INFO_IMAGE_BASE_NAME.'
' ); $contents[] = array('text' => zen_draw_input_field('imgBase', '', 30)); $dir = @dir(DIR_FS_CATALOG_IMAGES); $dir_info[] = array('id' => '', 'text' => TEXT_INFO_MAIN_DIR); while ($file = $dir->read()) { if (is_dir(DIR_FS_CATALOG_IMAGES . $file) && strtoupper($file) != 'CVS' && $file != "." && $file != ".." && $file != 'original' && $file != 'medium' && $file != 'large') { $dir_info[] = array('id' => $file . '/', 'text' => $file); } } $contents[] = array('text' => '
'.TEXT_INFO_BASE_DIR.'
'.TEXT_INFO_NEW_DIR); $contents[] = array('text' => TEXT_INFO_IMAGE_DIR . zen_draw_pull_down_menu('imgBaseDir', $dir_info, "")); $contents[] = array('text' => TEXT_INFO_OR.' ' . zen_draw_input_field('imgNewBaseDir', '', 20) ); } else if ($action != 'layout_edit') { $contents[] = array('text' => ''.TEXT_INFO_IMAGE_SUFFIX.'
'.TEXT_INFO_USE_AUTO_SUFFIX.'
' ); $contents[] = array('text' => zen_draw_input_field('imgSuffix', $selected_image_suffix, 10) ); } // Image fields $contents[] = array('text' => '
' . TEXT_INFO_DEFAULT_IMAGE . '
' . TEXT_INFO_DEFAULT_IMAGE_HELP . '
' . zen_draw_input_field('default_image', '', ' size="20" ', false, 'file') . '
' . $ptInfo->default_image); if ( $action == 'layout_edit' ) { if ( $selected_image_name == $products_image_match_array[0]) { $contents[] = array('text' => zen_draw_radio_field('imgNaming', 'new_discard', true) . IH_NEW_NAME_DISCARD_IMAGES . '
' // new_copy functionality scheduled for future release // . zen_draw_radio_field('imgNaming', 'new_copy', false) // . IH_NEW_NAME_COPY_IMAGES . '
' . zen_draw_radio_field('imgNaming', 'keep_name', false) . IH_KEEP_NAME); } } $contents[] = array('text' => '
' . 'Medium image file (optional)' . '
' . zen_draw_input_field('medium_image', '', ' size="20" ', false, 'file') . '
' . $ptInfo->medium_image); $contents[] = array('text' => '
' . 'Large image file (optional)' . '
' . zen_draw_input_field('large_image', '', ' size="20" ', false, 'file') . '
' . $ptInfo->large_image); $contents[] = array('align' => 'center', 'text' => '
' . zen_image_submit('button_save.gif', IMAGE_SAVE) ); break; case 'layout_delete': $imgStr = "&imgBase=" . $products_image_base . "&imgSuffix=" . $selected_image_suffix . "&imgBaseDir=" . $products_image_directory . "&imgExtension=" . $selected_image_extension; // show new button $heading[] = array('text' => '' . TEXT_INFO_CONFIRM_DELETE . ''); $contents[] = array('text' => '
' . $products_image_directory.$products_image_base.$selected_image_suffix.$selected_image_extension); $contents[] = array('text' => '
' . TEXT_INFO_CONFIRM_DELETE_SURE); if ($selected_image_suffix == '') { $contents[] = array('text' => zen_draw_checkbox_field('delete_from_database_only', 'Y', false) . IH_DELETE_FROM_DB_ONLY); } $contents[] = array('align' => 'center', 'text' => '
' .' ' . zen_image_button( 'button_delete.gif', IMAGE_DELETE ) . ''); break; default: // show new button $heading[] = array('text' => '' . TEXT_INFO_SELECT_ACTION . ''); $contents = array('form' => zen_draw_form('image_define', FILENAME_PRODUCT_TYPES, 'page=' . $_GET['page'] . '&ptID=' . $ptInfo->type_id . '&action=new', 'post', 'enctype="multipart/form-data"')); $contents[] = array('text' => '
' . TEXT_INFO_CLICK_TO_ADD); $contents[] = array('align' => 'center', 'text' => '
' .' ' . zen_image_button('button_new_file.gif', IMAGE_NEW) . ''); break; } if ( (zen_not_null($heading)) && (zen_not_null($contents)) ) { echo ' ' . "\n"; } ?>
get_local(); $tmp_image_file_full = DIR_FS_CATALOG . $tmp_image_file; $tmp_image_preview = new ih_image($tmp_image_file, IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT); $tmp_image_medium = new ih_image($image_file_medium, $ihConf['medium']['width'], $ihConf['medium']['height']); $tmp_image_file_medium = $tmp_image_medium->get_local(); $tmp_image_file_medium_full = DIR_FS_CATALOG . $tmp_image_file_medium; $tmp_image_medium_preview = new ih_image($tmp_image_file_medium, IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT); $tmp_image_large = new ih_image($image_file_large, $ihConf['large']['width'], $ihConf['large']['height']); $tmp_image_file_large = $tmp_image_large->get_local(); $tmp_image_file_large_full = DIR_FS_CATALOG . $tmp_image_file_large; $tmp_image_large_preview = new ih_image($tmp_image_file_large, IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT); // Get file details $text_default_size = get_image_details_string( $tmp_image_file_full ); $text_medium_size = get_image_details_string( $tmp_image_file_medium_full ); $text_large_size = get_image_details_string( $tmp_image_file_large_full ); if ($first == 1) { $tmp_image_link = zen_catalog_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $pInfo->products_id); $first = 0; } else { $tmp_image_link = zen_catalog_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $pInfo->products_id . '&pic='.($i).'&products_image_large_additional='.$tmp_image_file_large); } if ( $_GET['imgName'] == $tmp_image_name ) { // an image is selected, highlight it echo '' . "\n"; // set some details for later usage $selected_image_file = DIR_WS_CATALOG . $tmp_image_file_medium; $selected_image_file_large = DIR_WS_CATALOG . $tmp_image_file_large; $selected_image_link = $tmp_image_link; $selected_image_name = $tmp_image_name; $selected_image_suffix = preg_replace("/^".$products_image_base."/", '', $tmp_image_name); $selected_image_extension = $products_image_extension; } else { echo '' . "\n"; } ?>
 
get_resized_image(IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT, 'generic'); list($width, $height) = @getimagesize(DIR_FS_CATALOG . $preview_image); $width = min($width, intval(IMAGE_SHOPPING_CART_WIDTH)); $height = min ($height, intval(IMAGE_SHOPPING_CART_HEIGHT)); echo zen_image(DIR_WS_CATALOG . $preview_image, addslashes($products_name), $width, $height) . '
'; ?>
get_resized_image(IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT, 'generic'); list($width, $height) = @getimagesize(DIR_FS_CATALOG . $preview_image); $width = min($width, intval(IMAGE_SHOPPING_CART_WIDTH)); $height = min ($height, intval(IMAGE_SHOPPING_CART_HEIGHT)); echo zen_image(DIR_WS_CATALOG . $preview_image, addslashes($products_name), $width, $height) . '
'; echo $text_medium_size . '
'; if (is_file($image_file_medium_full)) { echo ' ' . zen_image_button('button_delete.gif', IMAGE_DELETE) . ''; } ?>
get_resized_image(IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT, 'generic'); list($width, $height) = @getimagesize(DIR_FS_CATALOG . $preview_image); $width = min($width, intval(IMAGE_SHOPPING_CART_WIDTH)); $height = min ($height, intval(IMAGE_SHOPPING_CART_HEIGHT)); echo zen_image(DIR_WS_CATALOG . $preview_image, addslashes($products_name), $width, $height) . '
'; echo $text_large_size . '
'; if (is_file($image_file_large_full)) { echo ' ' . zen_image_button('button_delete.gif', IMAGE_DELETE) . ''; } ?>
' . zen_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . ''; } ?> 
' . "\n"; $box = new box; echo $box->infoBox($heading, $contents); echo '
get_resized_image(intval($ihConf['small']['width']), intval($ihConf['small']['height']), 'orig'); $images['pngsmall'] = $pngimage->get_resized_image($ihConf['small']['width'], $ihConf['small']['height'], 'small'); $images['pngmedium'] = $pngimage->get_resized_image($ihConf['medium']['width'], $ihConf['medium']['height'], 'medium'); $images['pnglarge'] = $pngimage->get_resized_image($ihConf['large']['width'], $ihConf['large']['height'], 'large'); $jpgimage = new ih_image($ihConf['dir']['admin'] . 'images/ih-test.jpg', intval($ihConf['small']['width']), intval($ihConf['small']['height'])); $images['jpgsource'] = $jpgimage->get_resized_image(intval($ihConf['small']['width']), intval($ihConf['small']['height']), 'orig'); $images['jpgsmall'] = $jpgimage->get_resized_image($ihConf['small']['width'], $ihConf['small']['height'], 'small'); $images['jpgmedium'] = $jpgimage->get_resized_image($ihConf['medium']['width'], $ihConf['medium']['height'], 'medium'); $images['jpglarge'] = $jpgimage->get_resized_image($ihConf['large']['width'], $ihConf['large']['height'], 'large'); $gifimage = new ih_image($ihConf['dir']['admin'] . 'images/ih-test.gif', intval($ihConf['small']['width']), intval($ihConf['small']['height'])); $images['gifsource'] = $gifimage->get_resized_image(intval($ihConf['small']['width']), intval($ihConf['small']['height']), 'orig'); $images['gifsmall'] = $gifimage->get_resized_image($ihConf['small']['width'], $ihConf['small']['height'], 'small'); $images['gifmedium'] = $gifimage->get_resized_image($ihConf['medium']['width'], $ihConf['medium']['height'], 'medium'); $images['giflarge'] = $gifimage->get_resized_image($ihConf['large']['width'], $ihConf['large']['height'], 'large'); ?>
png
jpg
gif

Image Handler2

by
breakmyzencart.com
(tim@breakmyzencart.com)

Donations help me divert more time from other projects to breakmyzencart, which means you get the great new Zen-Cart contributions, maintenance of current releases for your ease of use and this informational website stays up-to-date.

And don’t forget my university studies! You help with that, too!

Any amount is very much appreciated, so don’t hesitate to send whatever you can. Every little bit helps!
Thank you!