/** * Import image pair * * @param string $prefix path prefix * @param string $image_file thumbanil path or filename * @param string $detailed_path detailed image path or filename * @param string $position image position * @param string $type pair type * @param int $object_id ID of object to attach images to * @param string $object name of object to attach images to * @return array|bool True if images were imported */ function fn_import_images($prefix, $image_file, $detailed_file, $position, $type, $object_id, $object) { static $updated_products = array(); if (!empty($object_id)) { // Process multilang requests if (!is_array($object_id)) { $object_id = array($object_id); } foreach ($object_id as $_id) { if (empty($updated_products[$_id]) && !empty($_REQUEST['import_options']['remove_images']) && $_REQUEST['import_options']['remove_images'] == 'Y') { $updated_products[$_id] = true; fn_delete_image_pairs($_id, $object, 'A'); } $_REQUEST["server_import_image_icon"] = ''; $_REQUEST["type_import_image_icon"] = ''; // Get image alternative text if exists if (!empty($image_file) && strpos($image_file, '#') !== false) { list($image_file, $image_alt) = explode('#', $image_file); } if (!empty($detailed_file) && strpos($detailed_file, '#') !== false) { list($detailed_file, $detailed_alt) = explode('#', $detailed_file); } if (!empty($image_alt)) { preg_match_all('/\\[([A-Za-z]+?)\\]:(.*?);/', $image_alt, $matches); if (!empty($matches[1]) && !empty($matches[2])) { $image_alt = array_combine(array_values($matches[1]), array_values($matches[2])); } } if (!empty($detailed_alt)) { preg_match_all('/\\[([A-Za-z]+?)\\]:(.*?);/', $detailed_alt, $matches); if (!empty($matches[1]) && !empty($matches[2])) { $detailed_alt = array_combine(array_values($matches[1]), array_values($matches[2])); } } $type_image_detailed = strpos($detailed_file, '://') === false ? 'server' : 'url'; $type_image_icon = strpos($image_file, '://') === false ? 'server' : 'url'; $_REQUEST["type_import_image_icon"] = array($type_image_icon); $_REQUEST["type_import_image_detailed"] = array($type_image_detailed); $image_file = fn_find_file($prefix, $image_file); if ($image_file !== false) { if ($type_image_icon == 'url') { $_REQUEST["file_import_image_icon"] = array($image_file); } elseif (strpos($image_file, Registry::get('config.dir.root')) === 0) { $_REQUEST["file_import_image_icon"] = array(str_ireplace(fn_get_files_dir_path(), '', $image_file)); } else { fn_set_notification('E', __('error'), __('error_images_need_located_root_dir')); $_REQUEST["file_import_image_detailed"] = array(); } } else { $_REQUEST["file_import_image_icon"] = array(); } $detailed_file = fn_find_file($prefix, $detailed_file); if ($detailed_file !== false) { if ($type_image_detailed == 'url') { $_REQUEST["file_import_image_detailed"] = array($detailed_file); } elseif (strpos($detailed_file, Registry::get('config.dir.root')) === 0) { $_REQUEST["file_import_image_detailed"] = array(str_ireplace(fn_get_files_dir_path(), '', $detailed_file)); } else { fn_set_notification('E', __('error'), __('error_images_need_located_root_dir')); $_REQUEST["file_import_image_detailed"] = array(); } } else { $_REQUEST["file_import_image_detailed"] = array(); } $_REQUEST['import_image_data'] = array(array('type' => $type, 'image_alt' => empty($image_alt) ? '' : $image_alt, 'detailed_alt' => empty($detailed_alt) ? '' : $detailed_alt, 'position' => empty($position) ? 0 : $position)); $result = fn_attach_image_pairs('import', $object, $_id); } return $result; } return false; }
function fn_exim_import_file($product_id, $filename, $path, $delete_files = 'N') { $path = fn_get_files_dir_path() . fn_normalize_path($path); // Clean up the directory above if flag is set if ($delete_files == 'Y') { fn_delete_product_file_folders(0, $product_id); fn_delete_product_files(0, $product_id); } // Check if we have several files $files = fn_explode(',', $filename); $folders = array(); // Create folders foreach ($files as $file) { if (strpos($file, '/') !== false) { list($folder) = fn_explode('/', $file); if (!isset($folders[$folder])) { $folder_data = array('product_id' => $product_id, 'folder_name' => $folder); $folders[$folder] = fn_update_product_file_folder($folder_data, 0); } } } // Copy files foreach ($files as $file) { if (strpos($file, '/') !== false) { list($folder_name, $file) = fn_explode('/', $file); } else { $folder_name = ''; } if (strpos($file, '#') !== false) { list($f, $pr) = fn_explode('#', $file); } else { $f = $file; $pr = ''; } $file = fn_find_file($path, $f); if (!empty($file)) { $uploads = array('file_base_file' => array($file), 'type_base_file' => array('server')); if (!empty($pr)) { $preview = fn_find_file($path, $pr); if (!empty($preview)) { $uploads['file_file_preview'] = array($preview); $uploads['type_file_preview'] = array('server'); } } else { $uploads['file_file_preview'] = ""; $uploads['type_file_preview'] = ""; } $_REQUEST = fn_array_merge($_REQUEST, $uploads); // not good to add data to $_REQUEST $file_data = array('product_id' => $product_id); if (!empty($folder_name)) { $file_data['folder_id'] = $folders[$folder_name]; } if (fn_update_product_file($file_data, 0) == false) { return false; } } } return true; }
/** * Import image pair * * @param string $prefix path prefix * @param string $image_file thumbanil path or filename * @param string $detailed_path detailed image path or filename * @param string $type pair type * @param int $object_id ID of object to attach images to * @param string $object name of object to attach images to * @return boolean true if images were imported */ function fn_import_images($prefix, $image_file, $detailed_file, $type, $object_id, $object) { if (!empty($object_id)) { $_REQUEST["server_import_image_icon"] = ''; $_REQUEST["type_import_image_icon"] = ''; // Get image alternative text if exists if (!empty($image_file) && strpos($image_file, '#') !== false) { list($image_file, $image_alt) = explode('#', $image_file); } if (!empty($detailed_file) && strpos($detailed_file, '#') !== false) { list($detailed_file, $detailed_alt) = explode('#', $detailed_file); } $_REQUEST["type_import_image_icon"] = array('server'); $_REQUEST["type_import_image_detailed"] = array('server'); if (($image_file = fn_find_file($prefix, $image_file)) !== false) { $_REQUEST["file_import_image_icon"] = array(str_ireplace(DIR_ROOT, '', $image_file)); } else { $_REQUEST["file_import_image_icon"] = array(); } if (($detailed_file = fn_find_file($prefix, $detailed_file)) !== false) { $_REQUEST["file_import_image_detailed"] = array(str_ireplace(DIR_ROOT, '', $detailed_file)); } else { $_REQUEST["file_import_image_detailed"] = array(); } $_REQUEST['import_image_data'] = array(array('type' => $type, 'image_alt' => !empty($image_alt) ? unserialize($image_alt) : '', 'detailed_alt' => !empty($detailed_alt) ? unserialize($detailed_alt) : '')); return fn_attach_image_pairs('import', $object, $object_id); } }
function fn_exim_import_file($product_id, $filename, $path, $delete_files = 'N') { // Check if directory for storing files is exist if (!@is_dir(DIR_DOWNLOADS . $product_id) && fn_mkdir(DIR_DOWNLOADS . $product_id) == false) { $msg = str_replace('[directory]', DIR_DOWNLOADS . $product_id, fn_get_lang_var('text_cannot_create_directory')); fn_set_notification('E', fn_get_lang_var('error'), $msg); return false; } // Clean up the directory above if flag is set if ($delete_files == 'Y') { $file_ids = db_get_fields("SELECT file_id FROM ?:product_files WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_files WHERE product_id = ?i", $product_id); db_query("DELETE FROM ?:product_file_descriptions WHERE file_id IN (?n)", $file_ids); fn_rm(DIR_DOWNLOADS . $product_id, false); } // Check if we have several files $files = fn_explode(',', $filename); // Copy files foreach ($files as $file) { if (strpos($file, '#') !== false) { list($f, $pr) = fn_explode('#', $file); } else { $f = $file; $pr = ''; } $file = fn_find_file($path, $f); if (!empty($file)) { $pr_res = false; list($_path, $_filename) = fn_generate_file_name(DIR_DOWNLOADS . $product_id . '/', basename($f)); copy($file, $_path); if (!empty($pr)) { $file = fn_find_file($path, $pr); if (!empty($file)) { list($_prpath, $_prfilename) = fn_generate_file_name(DIR_DOWNLOADS . $product_id . '/', basename($pr)); $pr_res = copy($file, $_prpath); } } $_data = array('file_path' => basename($_filename), 'file_size' => filesize(DIR_DOWNLOADS . $product_id . '/' . basename($_filename)), 'preview_path' => !empty($pr_res) ? basename($_prfilename) : '', 'preview_size' => !empty($pr_res) ? filesize(DIR_DOWNLOADS . $product_id . '/' . basename($_prfilename)) : 0, 'product_id' => $product_id); $file_id = db_get_field("SELECT file_id FROM ?:product_files WHERE product_id = ?i AND file_path = ?s", $product_id, $_data['file_path']); if (!empty($file_id)) { db_query("UPDATE ?:product_files SET ?u WHERE file_id = ?i", $_data, $file_id); } else { $file_id = db_query("INSERT INTO ?:product_files ?e", $_data, $file_id); $_data = array('file_id' => $file_id, 'file_name' => basename($_filename)); foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:product_file_descriptions ?e", $_data); } } } } }