} $file = MEDIA_PATH . ($old_cat_id != 0 ? "/" . $old_cat_id : "") . "/" . $image_media_file; $big_dir = MEDIA_PATH . "/" . $old_cat_id . "/" . $big_folder; $big_file = ""; $log[] = str_replace("{file}", str_replace(ROOT_PATH, "", $file), $lang['cni_working']); if (file_exists($file)) { $image_media_file_backup = $image_media_file; if ($cat_id != $old_cat_id) { $image_media_file = copy_media($image_media_file, $old_cat_id, $cat_id); if ($image_media_file && file_exists(MEDIA_PATH . "/" . $cat_id . "/" . $image_media_file)) { $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id, $lang['cni_copy_success']); } else { $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id, $lang['cni_copy_error']); $error_major = 1; } if ($image_thumb_file = copy_thumbnail($image_media_file_backup, $image_thumb_file, $old_cat_id, $cat_id)) { if (file_exists(THUMB_PATH . "/" . $cat_id . "/" . $image_thumb_file)) { $log[] = str_replace("{name}", THUMB_DIR . "/" . $cat_id, $lang['cni_copy_success']); } else { $log[] = str_replace("{name}", THUMB_DIR . "/" . $cat_id, $lang['cni_copy_error']); } } if (!$error_major && $big) { if (file_exists($big_dir . "/" . $image_media_file_backup)) { if ($big_file = copy_file($big_dir, MEDIA_PATH . "/" . $cat_id . "/" . $big_folder, $image_media_file_backup, $image_media_file, 1)) { $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id . "/" . $big_folder, $lang['cni_copy_success']); } else { $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id . "/" . $big_folder, $lang['cni_copy_error']); } } }
foreach ($image_list as $key => $val) { flush(); $image_name = addslashes($image_cache[$key]['image_name']); $cat_id = $image_cache[$key]['cat_id']; $user_id = $image_cache[$key]['user_id']; $image_description = addslashes($image_cache[$key]['image_description']); $image_keywords = addslashes($image_cache[$key]['image_keywords']); $image_date = $image_cache[$key]['image_date']; $image_media_file = addslashes($image_cache[$key]['image_media_file']); $image_thumb_file = addslashes($image_cache[$key]['image_thumb_file']); $image_download_url = addslashes($image_cache[$key]['image_download_url']); $old_media_path = MEDIA_TEMP_PATH . "/" . $image_media_file; $old_thumb_path = THUMB_TEMP_PATH . "/" . $image_thumb_file; if ($val == 1) { $new_name = copy_media($image_media_file, "-1", $cat_id); $new_thumb_name = copy_thumbnail($new_name, $image_thumb_file, "-1", $cat_id); if ($new_name) { $additional_field_sql = ""; $additional_value_sql = ""; if (!empty($additional_image_fields)) { $table_fields = $site_db->get_table_fields(IMAGES_TABLE); foreach ($additional_image_fields as $key2 => $val2) { if (isset($image_cache[$key][$key2]) && isset($image_cache[$key][$key2])) { $additional_field_sql .= ", {$key2}"; $additional_value_sql .= ", '" . addslashes($image_cache[$key][$key2]) . "'"; } } } $current_time = time(); $sql = "INSERT INTO " . IMAGES_TABLE . "\n (cat_id, user_id, image_name, image_description, image_keywords, image_date, image_media_file, image_thumb_file, image_download_url" . $additional_field_sql . ")\n VALUES\n ({$cat_id}, {$user_id}, '{$image_name}', '{$image_description}', '{$image_keywords}', {$current_time}, '{$new_name}', '{$new_thumb_name}', '{$image_download_url}'" . $additional_value_sql . ")"; $result = $site_db->query($sql);
if (!$new_thumb_name) { $error_msg .= $lang['thumb_upload_error'] . ": <b>" . $HTTP_POST_FILES['thumb_file']['name'] . "</b><br />" . $site_upload->get_upload_errors(); @rename(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name . ".bak", THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name); @unlink(MEDIA_PATH . "/" . $old_cat_id . "/" . $new_name); $error = 1; } else { $log[] = $lang['thumb_upload_success'] . ": <b>{$new_thumb_name}</b>"; } } elseif ((empty($HTTP_POST_FILES['thumb_file']['tmp_name']) || $HTTP_POST_FILES['thumb_file']['tmp_name'] == "none") && $remote_thumb_file != "" && (check_remote_thumb($remote_thumb_file) || check_local_thumb($remote_thumb_file))) { $new_thumb_name = $remote_thumb_file; if (file_exists(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name) && is_file(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name)) { unlink(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name); } } else { if ($cat_id != $old_cat_id && !empty($old_thumb_file_name)) { $new_thumb_name = copy_thumbnail($new_name, $old_thumb_file_name, $old_cat_id, $cat_id); } else { $new_thumb_name = $old_thumb_file_name; } } if (empty($error)) { $additional_sql = ""; if (!empty($additional_image_fields)) { $table_fields = $site_db->get_table_fields(IMAGES_TABLE); foreach ($additional_image_fields as $key => $val) { if (isset($HTTP_POST_VARS[$key]) && isset($table_fields[$key])) { $additional_sql .= ", {$key} = '" . un_htmlspecialchars(trim($HTTP_POST_VARS[$key])) . "'"; } } } $sql = "UPDATE " . IMAGES_TABLE . "\n SET cat_id = {$cat_id}, user_id = {$user_id}, image_name = '{$image_name}', image_description = '{$image_description}', image_keywords = '{$image_keywords}', image_date = {$image_date}, image_active = {$image_active}, image_media_file = '{$new_name}', image_thumb_file = '{$new_thumb_name}', image_download_url = '{$image_download_url}', image_allow_comments = {$image_allow_comments}, image_downloads = {$image_downloads}, image_votes = {$image_votes}, image_rating = '{$image_rating}', image_hits = {$image_hits}" . $additional_sql . "\n WHERE image_id = {$image_id}";
/** * Create thumbnail */ function create_thumbnail($source, $new_file, $mimetype) { global $config, $imagick; $source = amod_realpath($source); $min_filesize = (int) $config['img_min_thumb_filesize']; $img_filesize = @file_exists($source) ? @filesize($source) : false; if (!$img_filesize || $img_filesize <= $min_filesize) { $result = false; if ($img_filesize <= $min_filesize) { $result = copy_thumbnail($source, $new_file, $mimetype); } return $result; } list($width, $height, $type, ) = getimagesize($source); if (!$width || !$height) { return false; } if ($width <= $config['img_link_width'] && $height <= $config['img_link_height']) { $result = copy_thumbnail($source, $new_file, $mimetype); return $result; } list($new_width, $new_height) = get_img_size_format($width, $height); // If new w and h are larger than current image, just copy the image... if ($width <= $new_width && $height <= $new_height) { $result = copy_thumbnail($source, $new_file, $mimetype); return $result; } $tmp_path = $old_file = ''; if (intval($config['allow_ftp_upload'])) { $old_file = $new_file; $tmp_path = explode('/', $source); $tmp_path[sizeof($tmp_path) - 1] = ''; $tmp_path = implode('/', $tmp_path); if ($tmp_path == '') { $tmp_path = '/tmp'; } $value = trim($tmp_path); if ($value[strlen($value) - 1] == '/') { $value[strlen($value) - 1] = ' '; } // $new_file = tempnam(trim($value), 't00000'); // We remove it now because it gets created again later @unlink($new_file); } $used_imagick = false; if (is_imagick()) { passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"'); if (@file_exists($new_file)) { $used_imagick = true; } } if (!$used_imagick) { $type = get_supported_image_types($type); if ($type['gd']) { switch ($type['format']) { case IMG_GIF: $image = imagecreatefromgif($source); break; case IMG_JPG: $image = imagecreatefromjpeg($source); break; case IMG_PNG: $image = imagecreatefrompng($source); break; case IMG_WBMP: $image = imagecreatefromwbmp($source); break; } if ($type['version'] == 1 || !$config['use_gd2']) { $new_image = imagecreate($new_width, $new_height); imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); } else { $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); } switch ($type['format']) { case IMG_GIF: imagegif($new_image, $new_file); break; case IMG_JPG: imagejpeg($new_image, $new_file, 90); break; case IMG_PNG: imagepng($new_image, $new_file); break; case IMG_WBMP: imagewbmp($new_image, $new_file); break; } imagedestroy($new_image); } } if (!@file_exists($new_file)) { return false; } if (intval($config['allow_ftp_upload'])) { $result = ftp_file($new_file, $old_file, $mimetype, true); // True for disable error-mode @unlink($new_file); if (!$result) { return false; } } else { @chmod($new_file, 0664); } return true; }