$tmp_filename = explode('.', $original_file); $count_filename = count($tmp_filename); $ext = $tmp_filename[$count_filename - 1]; unset($tmp_filename[$count_filename - 1]); $new_filename = implode('', $tmp_filename) . '-CL' . $image_tstamp . '.' . $ext; // copy original product image $original_path = $this->DOCUMENT_ROOT . mslib_befe::getImagePath($original_file, 'products', 'original'); // $folder = mslib_befe::getImagePrefixFolder($new_filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $new_filename; if (copy($original_path, $target)) { mslib_befe::resizeProductImage($target, $new_filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey), 1); } // $updateArray[$arr_key] = $new_filename; } } if ($update_product_images) { foreach ($update_product_images as $key => $value) { if ($original_images[$key] != $value) { $updateArray[$key] = $value; } } } //} if ($updateArray['products_image']) { $updateArray['contains_image'] = 1;
public function duplicateProduct($id_product, $target_categories_id) { if (!is_numeric($id_product)) { return false; } if (!is_numeric($target_categories_id)) { return false; } $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) == 0) { return false; } else { //insert into tx_multishop_products $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); $product_arr_new = array(); if (is_array($row) && count($row)) { foreach ($row as $key_p => $val_p) { if ($key_p != 'products_id') { if ($key_p == 'products_image' or $key_p == 'products_image1' or $key_p == 'products_image2' or $key_p == 'products_image3' or $key_p == 'products_image4') { if (!empty($val_p)) { $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_description', 'products_id=\'' . $id_product . '\' and language_id=\'' . $this->sys_language_uid . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); $row_desc = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); $file = mslib_befe::getImagePath($val_p, 'products', 'original'); //echo $file; $imgtype = mslib_befe::exif_imagetype($file); if ($imgtype) { // valid image $ext = image_type_to_extension($imgtype, false); if ($ext) { $i = 0; $filename = mslib_fe::rewritenamein($row_desc['products_name']) . '.' . $ext; //echo $filename; $folder = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $filename; //echo $target; if (file_exists($target)) { do { $filename = mslib_fe::rewritenamein($row_desc['products_name']) . ($i > 0 ? '-' . $i : '') . '.' . $ext; $folder_name = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); $folder = $folder_name; if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $filename; $i++; //echo $target . "<br/>"; } while (file_exists($target)); } if (copy($file, $target)) { $target_origineel = $target; $update_product_images = mslib_befe::resizeProductImage($target_origineel, $filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey)); } } } $product_arr_new[$key_p] = $update_product_images; } else { $product_arr_new[$key_p] = $val_p; } } else { $product_arr_new[$key_p] = $val_p; } } } } $product_arr_new['sort_order'] = time(); $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); $id_product_new = $GLOBALS['TYPO3_DB']->sql_insert_id(); unset($product_arr_new); if ($id_product_new) { // insert tx_multishop_products_description $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_description', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; if (strpos($product_arr_new['products_name'], '(copy') === false) { $product_arr_new['products_name'] .= ' (copy ' . $id_product_new . ')'; } else { if (strpos($product_arr_new['products_name'], '(copy ' . $id_product . ')') !== false) { $product_arr_new['products_name'] = str_replace('(copy ' . $id_product . ')', ' (copy ' . $id_product_new . ')', $product_arr_new['products_name']); } else { $product_arr_new['products_name'] = str_replace('(copy)', ' (copy ' . $id_product_new . ')', $product_arr_new['products_name']); } } $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_description', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } // insert tx_multishop_products_attributes $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_attributes', 'products_id=\'' . $id_product . '\' and page_uid=\'' . $this->showCatalogFromPage . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; $product_arr_new['page_uid'] = $this->showCatalogFromPage; unset($product_arr_new['products_attributes_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_attributes', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert tx_multishop_specials $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_specials', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; unset($product_arr_new['specials_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_specials', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert tx_multishop_products_to_relative_products $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_to_relative_products', 'products_id=\'' . $id_product . '\' or relative_product_id = \'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; if ($product_arr_new['products_id'] == $id_product) { $product_arr_new['products_id'] = $id_product_new; } else { $product_arr_new['relative_product_id'] = $id_product_new; } unset($product_arr_new['products_to_relative_product_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_relative_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert into tx_multishop_products_to_categories $insertArray = array('products_id' => $id_product_new, 'categories_id' => $target_categories_id, 'sort_order' => time(), 'page_uid' => $this->showCatalogFromPage); //$query=$GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_categories', $insertArray); //$res=$GLOBALS['TYPO3_DB']->sql_query($query); // create categories tree linking $res = tx_mslib_catalog::linkCategoriesTreeToProduct($id_product_new, $target_categories_id, $insertArray); if ($res) { if ($this->ms['MODULES']['FLAT_DATABASE']) { mslib_befe::convertProductToFlat($id_product); } } else { return false; } } } }
$filename = mslib_fe::rewritenamein($row_desc['products_name']) . ($i > 0 ? '-' . $i : '') . '.' . $ext; $folder_name = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); $folder = $folder_name; if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $filename; $i++; //echo $target . "<br/>"; } while (file_exists($target)); } if (copy($file, $target)) { $target_origineel = $target; $update_product_images = mslib_befe::resizeProductImage($target_origineel, $filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey)); } } } $product_arr_new[$key_p] = $update_product_images; } else { $product_arr_new[$key_p] = $val_p; } } else { $product_arr_new[$key_p] = $val_p; } } } $product_arr_new['sort_order'] = time(); $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query);
function customAjaxPage(&$params, &$ref) { error_log("customAjaxPage hook"); error_log("products path: " . $ref->ms['image_paths']['products']['original']); $ref->ms['image_paths']['variants']['original'] = 'uploads/tx_msvariants/images/original'; error_log("variants path: " . $ref->ms['image_paths']['variants']['original']); if ($ref->ADMIN_USER) { if (isset($_SERVER["CONTENT_LENGTH"])) { // switch ($ref->get['file_type']) { // case 'variants_image': // for ($x=0; $x<$ref->ms['MODULES']['NUMBER_OF_PRODUCT_IMAGES']; $x++) { // // hidden filename that is retrieved from the ajax upload // $i=$x; // if ($i==0) { // $i=''; // } // $field='products_image'.$i; // if ($ref->get['file_type']==$field) { $temp_file = $ref->DOCUMENT_ROOT . 'uploads/tx_multishop/tmp/' . uniqid(); if (isset($_FILES['qqfile'])) { move_uploaded_file($_FILES['qqfile']['tmp_name'], $temp_file); } else { $input = fopen("php://input", "r"); $debug_file = fopen("/Applications/XAMPP/xamppfiles/htdocs/typo3/typo3temp/debug.txt", "w"); fwrite($debug_file, sys_get_temp_dir()); fclose($debug_file); $temp = tmpfile(); $realSize = stream_copy_to_stream($input, $temp); fclose($input); $target = fopen($temp_file, "w"); fseek($temp, 0, SEEK_SET); stream_copy_to_stream($temp, $target); fclose($target); } error_log("temp file created"); $size = getimagesize($temp_file); if ($size[0] > 5 and $size[1] > 5) { error_log("size ok"); $imgtype = mslib_befe::exif_imagetype($temp_file); if ($imgtype) { error_log("type ok"); // valid image $ext = image_type_to_extension($imgtype, false); if ($ext) { error_log("ext ok"); $i = 0; $filename = mslib_fe::rewritenamein($ref->get['products_name']) . '.' . $ext; $folder = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); if (!is_dir($ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder)) { t3lib_div::mkdir($ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder); } error_log("mkdir ok"); $folder .= '/'; $target = $ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder . $filename; if (file_exists($target)) { error_log("file exists ok"); do { $filename = mslib_fe::rewritenamein($ref->get['products_name']) . ($i > 0 ? '-' . $i : '') . '.' . $ext; $folder_name = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); $folder = $folder_name; if (!is_dir($ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder)) { t3lib_div::mkdir($ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder); } $folder .= '/'; $target = $ref->DOCUMENT_ROOT . $ref->ms['image_paths']['variants']['original'] . '/' . $folder . $filename; $i++; } while (file_exists($target)); } error_log("before copy file ok"); if (copy($temp_file, $target)) { $filename = mslib_befe::resizeProductImage($target, $filename, $ref->DOCUMENT_ROOT . t3lib_extMgm::siteRelPath($ref->extKey), 1); $result = array(); $result['success'] = true; $result['error'] = false; $result['filename'] = $filename; echo htmlspecialchars(json_encode($result), ENT_NOQUOTES); exit; } } } } } // } // break; // } // } } // exit(); // break; }
$this->ms['product_image_formats'][300]['width'] = $format[0]; $this->ms['product_image_formats'][300]['height'] = $format[1]; $format = explode("x", $this->ms['MODULES']['PRODUCT_IMAGE_SIZE_ENLARGED']); $this->ms['product_image_formats']['enlarged']['width'] = $format[0]; $this->ms['product_image_formats']['enlarged']['height'] = $format[1]; if (count($restore_files['products']) > 0) { foreach ($restore_files['products'] as $filename => $path) { // backup original $folder = mslib_befe::getImagePrefixFolder($filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . '/' . $filename; if (copy($path, $target)) { if ($this->post['resize_images']) { $tmp = mslib_befe::resizeProductImage($target, $filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('multishop')); } } } } if (count($restore_files['categories']) > 0) { foreach ($restore_files['categories'] as $filename => $path) { // backup original $folder = mslib_befe::getImagePrefixFolder($filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['categories']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['categories']['original'] . '/' . $folder); } $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['categories']['original'] . '/' . $folder . '/' . $filename; if (copy($path, $target)) { if ($this->post['resize_images']) { $tmp = mslib_befe::resizeCategoryImage($target, $filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('multishop'));