} $orig_type = $type; if (zerolen($image_path) && isset($available_images[$type]) && !empty($tables[$type]) && !empty($id)) { $hash_types = array(); $i = 0; $max_attempts = 1; while ($i++ < $max_attempts) { # counting attempts to prevent infinite loop $_table = $tables[$type]; $_field = $available_images[$type]['type'] == "U" ? "id" : "image_id"; $result = db_query("SELECT image_path, image_type, md5, image_size, filename FROM {$_table} WHERE {$_field}='{$id}' LIMIT 1"); if ($result && db_num_rows($result) > 0) { list($image_path, $image_type, $md5, $image_size, $_filename) = db_fetch_row($result); if (zerolen($image_path) && !zerolen($_filename)) { cw_load("image"); $image_path = cw_image_dir($type) . "/" . $_filename; } db_free_result($result); break; } if ($is_substitute) { if (!empty($config['substitute_images'][$type]) && isset($config['available_images'][$config['substitute_images'][$type]]) && !isset($hash_types[$config['substitute_images'][$type]])) { $type = $config['substitute_images'][$type]; $hash_types[$type] = true; continue; } # kornev, TOFIX if ($type == "W") { $tmp_id = cw_query_first_cell("SELECT product_id FROM {$tables['product_variants']} WHERE variant_id = '{$id}'"); if ($tmp_id) { $id = $tmp_id;
function cw_image_delete_all($type = '', $where = '') { global $available_images, $tables, $app_dir; if (!isset($available_images[$type])) { return false; } if (!empty($where)) { $where = " where " . $where; } $_table = $tables[$type]; if (cw_query_first_cell("select count(*) from " . $_table . $where) == 0) { return false; } $res = db_query("SELECT image_id, image_path, filename FROM " . $_table . $where); if ($res) { cw_load('image'); $img_dir = cw_image_dir($type) . "/"; while ($v = db_fetch_array($res)) { if (!zerolen($v['image_path']) && is_url($v['image_path'])) { continue; } $image_path = $v['image_path']; if (zerolen($image_path)) { $image_path = cw_relative_path($img_dir . $v['filename']); } $is_found = false; # check other types foreach ($available_images as $k => $i) { $is_found = cw_query_first_cell("select count(*) from " . $tables[$k] . " where image_path='" . addslashes($image_path) . "'" . ($k == $type ? " AND image_id != '{$v['image_id']}'" : "")) > 0; if ($is_found) { break; } } if (!$is_found && file_exists($image_path)) { @unlink($image_path); if ($type == 'products_images_thumb') { cw_rm_dir($img_dir . '/' . $v['image_id']); } } } db_free_result($res); } db_query("delete from " . $_table . $where); return true; }
<?php cw_load("image"); if (!$addons['magnifier']) { return; } $zoomer_images_old = cw_query("SELECT * from {$tables['magnifier_images']} WHERE id='" . $product_id . "'"); if (empty($zoomer_images_old)) { return; } foreach ($zoomer_images_old as $image_old) { $folder_with_images = cw_image_dir("Z") . DIRECTORY_SEPARATOR . $product_id . DIRECTORY_SEPARATOR . $image_old['imageid'] . DIRECTORY_SEPARATOR; cw_unset($image_old, "imageid"); $image_old['id'] = $new_product_id; $new_imageid = cw_array2insert("magnifier_images", $image_old); $new_folder_with_images = cw_image_dir("Z") . DIRECTORY_SEPARATOR . $new_product_id . DIRECTORY_SEPARATOR . $new_imageid . DIRECTORY_SEPARATOR; if (!file_exists($new_folder_with_images)) { cw_mkdir($new_folder_with_images); } cw_magnifier_dircpy($folder_with_images, $new_folder_with_images); }
* Shell tool to check images in DB and filesystem * * @use To check integrity * > php index.php <cron_code> images * @use To delete discrepancy on both sides or only in DB or FS * > php index.php <cron_code> images --delete * > php index.php <cron_code> images --delete-fs * > php index.php <cron_code> images --delete-db * */ cw_load('image'); //$available_images = cw_query_column("SELECT name FROM $tables[available_images]"); unset($available_images['magnifier_images']); foreach ($available_images as $image_type => $image_params) { $images_fs = array(); $image_path = cw_image_dir($image_type); $_images_fs = scandir($image_path); foreach ($_images_fs as $image) { if (is_file($image_path . '/' . $image)) { $images_fs[] = $image; } } $images_db = cw_query_column("SELECT filename FROM {$tables[$image_type]}"); $common = array_intersect($images_fs, $images_db); $in_db_only = array_diff($images_db, $images_fs); $in_fs_only = array_diff($images_fs, $images_db); $delete_fs = in_array($argv[3], array('--delete', '--delete-fs'), true); $delete_db = in_array($argv[3], array('--delete', '--delete-db'), true); if ($delete_fs) { foreach ($in_fs_only as $image) { if (is_file($image_path . '/' . $image)) {