/** * Method processAddAttachments() : Change name of file which are uploaded for this product * Rules: * - For the first upload the filename has been : name-of-product.extention * - For the second upload : name-of-product-1.extention * - ... * * @module now_seo_links * @return void * * @see AdminProductsControllerCore::processAddAttachments() */ public function processAddAttachments() { $languages = Language::getLanguages(false); $is_attachment_name_valid = false; foreach ($languages as $language) { $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']); if (Tools::strlen($attachment_name_lang) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) { $this->errors[] = Tools::displayError('Invalid Name'); } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) { $this->errors[] = sprintf(Tools::displayError('The name is too long (%d chars max).'), 32); } if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) { $this->errors[] = Tools::displayError('Invalid description'); } } if (!$is_attachment_name_valid) { $this->errors[] = Tools::displayError('An attachment name is required.'); } if (empty($this->errors)) { if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $this->errors[] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '')); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $this->errors[] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } elseif ((int) $_FILES['attachment_file']['error'] === 1) { $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $this->errors[] = sprintf($this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>'); } else { $this->errors[] = Tools::displayError('The file is missing.'); } if (empty($this->errors) && isset($uniqid)) { $attachment = new Attachment(); foreach ($languages as $language) { if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) { $attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']); } if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) { $attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']); } } if (Tools::getIsset('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))) { $sFilename = $_FILES['attachment_file']['name']; $sExtention = substr($sFilename, strrpos($sFilename, '.') + 1); $attachment->file_name = Tools::link_rewrite(trim(Tools::getValue('name_' . (int) Configuration::get('PS_LANG_DEFAULT')))); // On regarde si c'est le premier document joint au produit ou pas $aAttachmentOfProduct = $attachment->getAttachments(Context::getContext()->language->id, (int) Tools::getValue('id_product')); $iNb = count($aAttachmentOfProduct); if ($iNb > 0) { $attachment->file_name .= '-' . $iNb; } $attachment->file_name .= '.' . $sExtention; } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) { $this->errors[] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $this->errors[] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $this->errors[] = Tools::displayError('The file name is too long.'); } if (empty($this->errors)) { $res = $attachment->add(); if (!$res) { $this->errors[] = Tools::displayError('This attachment was unable to be loaded into the database.'); } else { $id_product = (int) Tools::getValue($this->identifier); $res = $attachment->attachProduct($id_product); if (!$res) { $this->errors[] = Tools::displayError('We were unable to associate this attachment to a product.'); } } } else { $this->errors[] = Tools::displayError('Invalid file'); } } } }
public function ajaxProcessAddAttachment() { if (isset($_FILES['attachment_file'])) { if ((int) $_FILES['attachment_file']['error'] === 1) { $_FILES['attachment_file']['error'] = array(); $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $_FILES['attachment_file']['error'][] = sprintf($this->l('File %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>'); } $_FILES['attachment_file']['error'] = array(); $is_attachment_name_valid = false; $attachment_names = Tools::getValue('attachment_name'); $attachment_descriptions = Tools::getValue('attachment_description'); if (!isset($attachment_names) || !$attachment_names) { $attachment_names = array(); } if (!isset($attachment_descriptions) || !$attachment_descriptions) { $attachment_descriptions = array(); } foreach ($attachment_names as $lang => $name) { $language = Language::getLanguage((int) $lang); if (Tools::strlen($name) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName($name)) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid name for %s language'), $language['name']); } elseif (Tools::strlen($name) > 32) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('The name for %1s language is too long (%2d chars max).'), $language['name'], 32); } } foreach ($attachment_descriptions as $lang => $description) { $language = Language::getLanguage((int) $lang); if (!Validate::isCleanHtml($description)) { $_FILES['attachment_file']['error'][] = sprintf(Tools::displayError('Invalid description for %s language'), $language['name']); } } if (!$is_attachment_name_valid) { $_FILES['attachment_file']['error'][] = Tools::displayError('An attachment name is required.'); } if (empty($_FILES['attachment_file']['error'])) { if (is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $_FILES['attachment_file']['error'][] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '')); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $_FILES['attachment_file']['error'][] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } else { $_FILES['attachment_file']['error'][] = Tools::displayError('The file is missing.'); } if (empty($_FILES['attachment_file']['error']) && isset($uniqid)) { $attachment = new Attachment(); foreach ($attachment_names as $lang => $name) { $attachment->name[(int) $lang] = $name; } foreach ($attachment_descriptions as $lang => $description) { $attachment->description[(int) $lang] = $description; } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; $attachment->file_name = $_FILES['attachment_file']['name']; if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $_FILES['attachment_file']['error'][] = Tools::displayError('The file name is too long.'); } if (empty($this->errors)) { $res = $attachment->add(); if (!$res) { $_FILES['attachment_file']['error'][] = Tools::displayError('This attachment was unable to be loaded into the database.'); } else { $_FILES['attachment_file']['id_attachment'] = $attachment->id; $_FILES['attachment_file']['filename'] = $attachment->name[$this->context->employee->id_lang]; $id_product = (int) Tools::getValue($this->identifier); $res = $attachment->attachProduct($id_product); if (!$res) { $_FILES['attachment_file']['error'][] = Tools::displayError('We were unable to associate this attachment to a product.'); } } } else { $_FILES['attachment_file']['error'][] = Tools::displayError('Invalid file'); } } } die(Tools::jsonEncode($_FILES)); } }
/** * postProcess handle every checks before saving products information * * @param mixed $token * @return void */ public function postProcess($token = null) { global $cookie, $currentIndex; // Add a new product if (Tools::isSubmit('submitAddproduct') || Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddProductAndPreview')) { if (Tools::getValue('id_product') && $this->tabAccess['edit'] === '1' || $this->tabAccess['add'] === '1' && !Tools::isSubmit('id_product')) { $this->submitAddproduct($token); } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } /* Delete a product in the download folder */ if (Tools::getValue('deleteVirtualProduct')) { if ($this->tabAccess['delete'] === '1') { $this->deleteVirtualProduct(); } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitAddAttachments')) { if ($this->tabAccess['add'] === '1') { $languages = Language::getLanguages(false); $is_attachment_name_valid = false; foreach ($languages as $language) { $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']); if (strlen($attachment_name_lang) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) { $this->_errors[] = Tools::displayError('Invalid Name'); } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) { $this->_errors[] = Tools::displayError('Name is too long'); } if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) { $this->_errors[] = Tools::displayError('Invalid description'); } } if (!$is_attachment_name_valid) { $this->_errors[] = Tools::displayError('Attachment Name Required'); } if (empty($this->_errors)) { if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $this->_errors[] = $this->l('File too large, maximum size allowed:') . ' ' . Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 . ' ' . $this->l('kb') . '. ' . $this->l('File size you\'re trying to upload is:') . number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '') . $this->l('kb'); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $this->_errors[] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } elseif ((int) $_FILES['attachment_file']['error'] === 1) { $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $this->_errors[] = $this->l('the File') . ' <b>' . $_FILES['attachment_file']['name'] . '</b> ' . $this->l('exceeds the size allowed by the server, this limit is set to') . ' <b>' . $upload_mb . $this->l('Mb') . '</b>'; } if (empty($this->_errors) && isset($uniqid)) { $attachment = new Attachment(); foreach ($languages as $language) { if (isset($_POST['attachment_name_' . (int) $language['id_lang']])) { $attachment->name[(int) $language['id_lang']] = pSQL($_POST['attachment_name_' . (int) $language['id_lang']]); } if (isset($_POST['attachment_description_' . (int) $language['id_lang']])) { $attachment->description[(int) $language['id_lang']] = pSQL($_POST['attachment_description_' . (int) $language['id_lang']]); } } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; $attachment->file_name = pSQL($_FILES['attachment_file']['name']); if (empty($attachment->mime) or Tools::strlen($attachment->mime) > 128) { $this->_errors[] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $this->_errors[] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $this->_errors[] = Tools::displayError('File name too long'); } if (!sizeof($this->_errors)) { $attachment->add(); Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Invalid file'); } } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('submitAttachments')) { if ($this->tabAccess['edit'] === '1') { if ($id = (int) Tools::getValue($this->identifier)) { if (Attachment::attachToProduct($id, $_POST['attachments'])) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $id . (isset($_POST['id_category']) ? '&id_category=' . (int) $_POST['id_category'] : '') . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token)); } } } } elseif (isset($_GET['duplicate' . $this->table])) { if ($this->tabAccess['add'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { $id_product_old = $product->id; unset($product->id); unset($product->id_product); $product->indexed = 0; $product->active = 0; if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and GroupReduction::duplicateReduction($id_product_old, $product->id) and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateSpecificPrices($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id) and Product::duplicateDownload($id_product_old, $product->id)) { if ($product->hasAttributes()) { Product::updateDefaultAttribute($product->id); } if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) { $this->_errors[] = Tools::displayError('An error occurred while copying images.'); } else { Hook::addProduct($product); Search::indexation(false, $product->id); Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=19&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('An error occurred while creating object.'); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (isset($_GET['status']) and Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) { Tools::redirectAdmin($currentIndex . '&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1' and Tools::getValue('id_product')) ? '&id_category=' . $id_category : '') . '&token=' . $token); } else { $this->_errors[] = Tools::displayError('An error occurred while updating status.'); } } else { $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (isset($_GET['delete' . $this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject()) and isset($this->fieldImageSettings)) { // check if request at least one object with noZeroObject if (isset($object->noZeroObject) and sizeof($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1) { $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.'); } else { $id_category = Tools::getValue('id_category'); $category_url = empty($id_category) ? '' : '&id_category=' . $id_category; if ($this->deleted) { $object->deleteImages(); $object->deleted = 1; if ($object->update()) { Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url); } } elseif ($object->delete()) { Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url); } $this->_errors[] = Tools::displayError('An error occurred during deletion.'); } } else { $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::getValue('submitDel' . $this->table)) { if ($this->tabAccess['delete'] === '1') { if (isset($_POST[$this->table . 'Box'])) { $object = new $this->className(); if (isset($object->noZeroObject) and (sizeof(call_user_func(array($this->className, $object->noZeroObject))) <= 1 or sizeof($_POST[$this->table . 'Box']) == sizeof(call_user_func(array($this->className, $object->noZeroObject))))) { $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.'); } else { $result = true; if ($this->deleted) { foreach (Tools::getValue($this->table . 'Box') as $id) { $toDelete = new $this->className($id); $toDelete->deleted = 1; $result = $result and $toDelete->update(); } } else { $result = $object->deleteSelection(Tools::getValue($this->table . 'Box')); } if ($result) { $id_category = Tools::getValue('id_category'); $category_url = empty($id_category) ? '' : '&id_category=' . $id_category; Tools::redirectAdmin($currentIndex . '&conf=2&token=' . $token . $category_url); } $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); } } else { $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif ($id_image = (int) Tools::getValue('id_image') and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_) { $this->_errors[] = Tools::displayError('This functionnality has been disabled.'); return; } /* PrestaShop demo mode*/ if ($this->tabAccess['edit'] === '1') { /* Delete product image */ if (isset($_GET['deleteImage'])) { $image->delete(); if (!Image::getCover($image->id_product)) { $first_img = Db::getInstance()->getRow(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . (int) $image->id_product); Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'image` SET `cover` = 1 WHERE `id_image` = ' . (int) $first_img['id_image']); } @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $image->id_product . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $image->id_product . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token)); } elseif (isset($_GET['editImage'])) { if ($image->cover) { $_POST['cover'] = 1; } $languages = Language::getLanguages(false); foreach ($languages as $language) { if (isset($image->legend[$language['id_lang']])) { $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']]; } } $_POST['id_image'] = $image->id; $this->displayForm(); } elseif (isset($_GET['coverImage'])) { Image::deleteCover($image->id_product); $image->cover = 1; if (!$image->update()) { $this->_errors[] = Tools::displayError('Cannot change the product cover'); } else { $productId = (int) Tools::getValue('id_product'); @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $productId . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $productId . '.jpg'); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token)); } } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) { $image->positionImage((int) Tools::getValue('imgPosition'), (int) Tools::getValue('imgDirection')); Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (Tools::isSubmit('submitProductAttribute')) { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) { $this->_errors[] = Tools::displayError('Attribute price required.'); } if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('You must add at least one attribute.'); } if (!sizeof($this->_errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if ($id_product_attribute = (int) Tools::getValue('id_product_attribute')) { if ($this->tabAccess['edit'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) { $this->_errors[] = Tools::displayError('This attribute already exists.'); } else { $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), false, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity')); if ($id_reason = (int) Tools::getValue('id_mvt_reason') and (int) Tools::getValue('attribute_mvt_quantity') > 0 and $id_reason > 0) { $reason = new StockMvtReason((int) $id_reason); $qty = Tools::getValue('attribute_mvt_quantity') * $reason->sign; if (!$product->addStockMvt($qty, $id_reason, (int) $id_product_attribute, NULL, $cookie->id_employee)) { $this->_errors[] = Tools::displayError('An error occurred while updating qty.'); } } Hook::updateProductAttribute((int) $id_product_attribute); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) { $this->_errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity')); } } else { $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.'); } } if (!sizeof($this->_errors)) { $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list')); $product->checkDefaultAttributes(); } if (!sizeof($this->_errors)) { if (!$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token)); } } } } elseif (Tools::isSubmit('deleteProductAttribute')) { if ($this->tabAccess['delete'] === '1') { if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteAttributeCombinaison((int) Tools::getValue('id_product_attribute')); $product->checkDefaultAttributes(); $product->updateQuantityProductWithAttributeQuantity(); if (!$product->hasAttributes()) { $product->cache_default_attribute = 0; $product->update(); } else { Product::updateDefaultAttribute($id_product); } Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot delete attribute'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('deleteAllProductAttributes')) { if ($this->tabAccess['delete'] === '1') { if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) { $product->deleteProductAttributes(); $product->updateQuantityProductWithAttributeQuantity(); if ($product->cache_default_attribute) { $product->cache_default_attribute = 0; $product->update(); } Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot delete attributes'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('defaultProductAttribute')) { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { $product->deleteDefaultAttributes(); $product->setDefaultAttribute((int) Tools::getValue('id_product_attribute')); Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token)); } else { $this->_errors[] = Tools::displayError('Cannot make default attribute'); } } elseif (Tools::isSubmit('submitProductFeature')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { // delete all objects $product->deleteFeatures(); // add new objects $languages = Language::getLanguages(false); foreach ($_POST as $key => $val) { if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) { if ($val) { $product->addFeaturesToDB($match[1], $val); } else { if ($default_value = $this->checkFeatures($languages, $match[1])) { $id_value = $product->addFeaturesToDB($match[1], 0, 1, (int) $language['id_lang']); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_' . $match[1] . '_' . (int) $language['id_lang'])) { $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $cust); } else { $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $default_value); } } } } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=4&conf=4&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding features.'); } } $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } elseif (Tools::isSubmit('submitPricesModification')) { $_POST['tabs'] = 5; if ($this->tabAccess['edit'] === '1') { $id_specific_prices = Tools::getValue('spm_id_specific_price'); $id_shops = Tools::getValue('spm_id_shop'); $id_currencies = Tools::getValue('spm_id_currency'); $id_countries = Tools::getValue('spm_id_country'); $id_groups = Tools::getValue('spm_id_group'); $prices = Tools::getValue('spm_price'); $from_quantities = Tools::getValue('spm_from_quantity'); $reductions = Tools::getValue('spm_reduction'); $reduction_types = Tools::getValue('spm_reduction_type'); $froms = Tools::getValue('spm_from'); $tos = Tools::getValue('spm_to'); foreach ($id_specific_prices as $key => $id_specific_price) { if ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key])) { $specificPrice = new SpecificPrice((int) $id_specific_price); $specificPrice->id_shop = (int) $id_shops[$key]; $specificPrice->id_currency = (int) $id_currencies[$key]; $specificPrice->id_country = (int) $id_countries[$key]; $specificPrice->id_group = (int) $id_groups[$key]; $specificPrice->price = (double) $prices[$key]; $specificPrice->from_quantity = (int) $from_quantities[$key]; $specificPrice->reduction = (double) ($reduction_types[$key] == 'percentage' ? $reductions[$key] / 100 : $reductions[$key]); $specificPrice->reduction_type = !$reductions[$key] ? 'amount' : $reduction_types[$key]; $specificPrice->from = !$froms[$key] ? '0000-00-00 00:00:00' : $froms[$key]; $specificPrice->to = !$tos[$key] ? '0000-00-00 00:00:00' : $tos[$key]; if (!$specificPrice->update()) { $this->_errors = Tools::displayError('An error occurred while updating the specific price.'); } } } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&update' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('submitPriceAddition')) { if ($this->tabAccess['add'] === '1') { $id_product = (int) Tools::getValue('id_product'); $id_shop = Tools::getValue('sp_id_shop'); $id_currency = Tools::getValue('sp_id_currency'); $id_country = Tools::getValue('sp_id_country'); $id_group = Tools::getValue('sp_id_group'); $price = Tools::getValue('sp_price'); $from_quantity = Tools::getValue('sp_from_quantity'); $reduction = (double) Tools::getValue('sp_reduction'); $reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type'); $from = Tools::getValue('sp_from'); $to = Tools::getValue('sp_to'); if ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to)) { $specificPrice = new SpecificPrice(); $specificPrice->id_product = $id_product; $specificPrice->id_shop = (int) $id_shop; $specificPrice->id_currency = (int) $id_currency; $specificPrice->id_country = (int) $id_country; $specificPrice->id_group = (int) $id_group; $specificPrice->price = (double) $price; $specificPrice->from_quantity = (int) $from_quantity; $specificPrice->reduction = (double) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction); $specificPrice->reduction_type = $reduction_type; $specificPrice->from = !$from ? '0000-00-00 00:00:00' : $from; $specificPrice->to = !$to ? '0000-00-00 00:00:00' : $to; if (!$specificPrice->add()) { $this->_errors = Tools::displayError('An error occurred while updating the specific price.'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $id_product . '&add' . $this->table . '&tabs=2&conf=3&token=' . ($token ? $token : $this->token)); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (Tools::isSubmit('deleteSpecificPrice')) { if ($this->tabAccess['delete'] === '1') { if (!($obj = $this->loadObject())) { return; } if (!($id_specific_price = Tools::getValue('id_specific_price')) or !Validate::isUnsignedId($id_specific_price)) { $this->_errors[] = Tools::displayError('Invalid specific price ID'); } else { $specificPrice = new SpecificPrice((int) $id_specific_price); if (!$specificPrice->delete()) { $this->_errors[] = Tools::displayError('An error occurred while deleting the specific price'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=1&token=' . ($token ? $token : $this->token)); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } elseif (Tools::isSubmit('submitSpecificPricePriorities')) { if (!($obj = $this->loadObject())) { return; } if (!($priorities = Tools::getValue('specificPricePriority'))) { $this->_errors[] = Tools::displayError('Please specify priorities'); } elseif (Tools::isSubmit('specificPricePriorityToAll')) { if (!SpecificPrice::setPriorities($priorities)) { $this->_errors[] = Tools::displayError('An error occurred while updating priorities.'); } else { Tools::redirectAdmin($currentIndex . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token)); } } elseif (!SpecificPrice::setSpecificPriority((int) $obj->id, $priorities)) { $this->_errors[] = Tools::displayError('An error occurred while setting priorities.'); } else { Tools::redirectAdmin($currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token)); } } elseif (Tools::isSubmit('submitCustomizationConfiguration')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { if (!$product->createLabels((int) $_POST['uploadable_files'] - (int) $product->uploadable_files, (int) $_POST['text_fields'] - (int) $product->text_fields)) { $this->_errors[] = Tools::displayError('An error occurred while creating customization fields.'); } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization.'); } $product->uploadable_files = (int) $_POST['uploadable_files']; $product->text_fields = (int) $_POST['text_fields']; $product->customizable = ((int) $_POST['uploadable_files'] > 0 or (int) $_POST['text_fields'] > 0) ? 1 : 0; if (!sizeof($this->_errors) and !$product->update()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization configuration.'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (Tools::isSubmit('submitProductCustomization')) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) { foreach ($_POST as $field => $value) { if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) { $this->_errors[] = Tools::displayError('Label fields are invalid'); } } if (!sizeof($this->_errors) and !$product->updateLabels()) { $this->_errors[] = Tools::displayError('An error occurred while updating customization.'); } if (!sizeof($this->_errors)) { Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token)); } } else { $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } elseif (isset($_GET['position'])) { if ($this->tabAccess['edit'] !== '1') { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } elseif (!Validate::isLoadedObject($object = $this->loadObject())) { $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } if (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) { $this->_errors[] = Tools::displayError('Failed to update the position.'); } else { Tools::redirectAdmin($currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') ? '&id_category=' . $id_category : '') . '&token=' . Tools::getAdminTokenLite('AdminCatalog')); } } else { parent::postProcess(true); } }
/** * 图片裁切 * * @return boolean */ public function crop_upload() { if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) { $pic = $GLOBALS["HTTP_RAW_POST_DATA"]; if (isset($_GET['width']) && !empty($_GET['width'])) { $width = intval($_GET['width']); } if (isset($_GET['height']) && !empty($_GET['height'])) { $height = intval($_GET['height']); } if (isset($_GET['file']) && !empty($_GET['file'])) { if (is_image($_GET['file']) == false) { exit; } if (strpos($_GET['file'], C('attachment', 'upload_url')) !== false) { $file = $_GET['file']; $basename = basename($file); $filepath = str_replace(SITE_URL, '', dirname($file)) . '/'; if (strpos($basename, 'thumb_') !== false) { $file_arr = explode('_', $basename); $basename = array_pop($file_arr); } $new_file = 'thumb_' . $width . '_' . $height . '_' . $basename; } else { $application = trim($_GET['application']); $catid = intval($_GET['catid']); $attachment = new Attachment($application, $catid); $uploadedfile['filename'] = basename($_GET['file']); $uploadedfile['fileext'] = File::get_suffix($_GET['file']); if (in_array($uploadedfile['fileext'], array('jpg', 'gif', 'jpeg', 'png', 'bmp'))) { $uploadedfile['isimage'] = 1; } $file_path = C('attachment', 'upload_path') . date('Y/md/'); Folder::mk($file_path); $new_file = date('Ymdhis') . rand(100, 999) . '.' . $uploadedfile['fileext']; $uploadedfile['filepath'] = date('Y/md/') . $new_file; $aid = $attachment->add($uploadedfile); $filepath = str_replace(SITE_URL, '', C('attachment', 'upload_url')) . date('Y/md/'); } file_put_contents(BASE_PATH . $filepath . $new_file, $pic); } else { return false; } echo SITE_URL . $filepath . $new_file; exit; } }
function importer($path, $node, $line) { global $blogid, $migrational, $items, $item; switch ($path) { case '/blog/setting': setProgress($item++ / $items * 100, _t('블로그 설정을 복원하고 있습니다.')); $setting = new BlogSetting(); if (isset($node['title'][0]['.value'])) { $setting->title = $node['title'][0]['.value']; } if (isset($node['description'][0]['.value'])) { $setting->description = $node['description'][0]['.value']; } if (isset($node['banner'][0]['name'][0]['.value'])) { $setting->banner = $node['banner'][0]['name'][0]['.value']; } if (isset($node['useSloganOnPost'][0]['.value'])) { $setting->useSloganOnPost = $node['useSloganOnPost'][0]['.value']; } if (isset($node['postsOnPage'][0]['.value'])) { $setting->postsOnPage = $node['postsOnPage'][0]['.value']; } if (isset($node['postsOnList'][0]['.value'])) { $setting->postsOnList = $node['postsOnList'][0]['.value']; } if (isset($node['postsOnFeed'][0]['.value'])) { $setting->postsOnFeed = $node['postsOnFeed'][0]['.value']; } if (isset($node['publishWholeOnFeed'][0]['.value'])) { $setting->publishWholeOnFeed = $node['publishWholeOnFeed'][0]['.value']; } if (isset($node['acceptGuestComment'][0]['.value'])) { $setting->acceptGuestComment = $node['acceptGuestComment'][0]['.value']; } if (isset($node['acceptcommentOnGuestComment'][0]['.value'])) { $setting->acceptcommentOnGuestComment = $node['acceptcommentOnGuestComment'][0]['.value']; } if (isset($node['language'][0]['.value'])) { $setting->language = $node['language'][0]['.value']; } if (isset($node['timezone'][0]['.value'])) { $setting->timezone = $node['timezone'][0]['.value']; } if (!$setting->save()) { user_error(__LINE__ . $setting->error); } if (!empty($setting->banner) && !empty($node['banner'][0]['content'][0]['.stream'])) { Attachment::confirmFolder(); Utils_Base64Stream::decode($node['banner'][0]['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $setting->banner)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $setting->banner)); fclose($node['banner'][0]['content'][0]['.stream']); unset($node['banner'][0]['content'][0]['.stream']); } return true; case '/blog/category': setProgress($item++ / $items * 100, _t('분류를 복원하고 있습니다.')); $category = new Category(); $category->name = $node['name'][0]['.value']; $category->priority = $node['priority'][0]['.value']; if (isset($node['root'][0]['.value'])) { $category->id = 0; } if (!$category->add()) { user_error(__LINE__ . $category->error); } if (isset($node['category'])) { for ($i = 0; $i < count($node['category']); $i++) { $childCategory = new Category(); $childCategory->parent = $category->id; $cursor =& $node['category'][$i]; $childCategory->name = $cursor['name'][0]['.value']; $childCategory->priority = $cursor['priority'][0]['.value']; if (!$childCategory->add()) { user_error(__LINE__ . $childCategory->error); } } } return true; case '/blog/post': setProgress($item++ / $items * 100, _t('글을 복원하고 있습니다.')); $post = new Post(); $post->id = $node['id'][0]['.value']; $post->slogan = @$node['.attributes']['slogan']; $post->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $post->starred = $node['starred'][0]['.value']; } else { $post->starred = 0; } $post->title = $node['title'][0]['.value']; $post->content = $node['content'][0]['.value']; $post->contentformatter = isset($node['content'][0]['.attributes']['formatter']) ? $node['content'][0]['.attributes']['formatter'] : 'ttml'; $post->contenteditor = isset($node['content'][0]['.attributes']['editor']) ? $node['content'][0]['.attributes']['editor'] : 'modern'; $post->location = $node['location'][0]['.value']; $post->password = isset($node['password'][0]['.value']) ? $node['password'][0]['.value'] : null; $post->acceptcomment = $node['acceptComment'][0]['.value']; $post->accepttrackback = $node['acceptTrackback'][0]['.value']; $post->published = $node['published'][0]['.value']; if (isset($node['longitude'][0]['.value'])) { $post->longitude = $node['longitude'][0]['.value']; } if (isset($node['latitude'][0]['.value'])) { $post->latitude = $node['latitude'][0]['.value']; } $post->created = @$node['created'][0]['.value']; $post->modified = @$node['modified'][0]['.value']; if ($post->visibility == 'private' && intval($post->published) > $_SERVER['REQUEST_TIME'] || !empty($node['appointed'][0]['.value']) && $node['appointed'][0]['.value'] == 'true') { // for compatibility of appointed entries $post->visibility = 'appointed'; } if ($post->slogan == '') { $post->slogan = 'Untitled' . $post->id; } if (!empty($node['category'][0]['.value'])) { $post->category = Category::getId($node['category'][0]['.value']); } if (isset($node['tag'])) { $post->tags = array(); for ($i = 0; $i < count($node['tag']); $i++) { if (!empty($node['tag'][$i]['.value'])) { array_push($post->tags, $node['tag'][$i]['.value']); } } } if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $post->content = nl2brWithHTML($post->content); } if (!$post->add()) { user_error(__LINE__ . $post->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $post->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } else { if ($cursor['name'][0]['.value'] != $attachment->name) { $post2 = new Post(); if ($post2->open($post->id, 'id, content')) { $post2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $post2->content); $post2->loadTags(); $post2->update(); $post2->close(); } unset($post2); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } if (isset($node['comment'])) { for ($i = 0; $i < count($node['comment']); $i++) { $comment = new Comment(); $comment->entry = $post->id; $cursor =& $node['comment'][$i]; $comment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['id'][0]['.value'])) { $comment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $comment->commenter = $cursor['commenter'][0]['.attributes']['id']; } if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $comment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $comment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $comment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $comment->password = $cursor['password'][0]['.value']; $comment->secret = $cursor['secret'][0]['.value']; $comment->written = $cursor['written'][0]['.value']; if (isset($cursor['longitude'][0]['.value'])) { $comment->longitude = $cursor['longitude'][0]['.value']; } if (isset($cursor['latitude'][0]['.value'])) { $comment->latitude = $cursor['latitude'][0]['.value']; } $comment->content = $cursor['content'][0]['.value']; if (!empty($cursor['isFiltered'][0]['.value'])) { $comment->isfiltered = $cursor['isFiltered'][0]['.value']; } if (!$comment->add()) { user_error(__LINE__ . $comment->error); } if (isset($node['comment'][$i]['comment'])) { for ($j = 0; $j < count($node['comment'][$i]['comment']); $j++) { $childComment = new Comment(); $childComment->entry = $post->id; $childComment->parent = $comment->id; $cursor =& $node['comment'][$i]['comment'][$j]; if (!empty($cursor['id'][0]['.value'])) { $childComment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $childComment->commenter = $cursor['commenter'][0]['.attributes']['id']; } $childComment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $childComment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $childComment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $childComment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $childComment->password = $cursor['password'][0]['.value']; $childComment->secret = $cursor['secret'][0]['.value']; $childComment->written = $cursor['written'][0]['.value']; if (isset($cursor['longitude'][0]['.value'])) { $comment->longitude = $cursor['longitude'][0]['.value']; } if (isset($cursor['latitude'][0]['.value'])) { $comment->latitude = $cursor['latitude'][0]['.value']; } $childComment->content = $cursor['content'][0]['.value']; if (!empty($cursor['isFiltered'][0]['.value'])) { $childComment->isfiltered = $cursor['isFiltered'][0]['.value']; } if (!$childComment->add()) { user_error(__LINE__ . $childComment->error); } } } } } if (isset($node['trackback'])) { for ($i = 0; $i < count($node['trackback']); $i++) { $trackback = new Trackback(); $trackback->entry = $post->id; $cursor =& $node['trackback'][$i]; $trackback->url = $cursor['url'][0]['.value']; $trackback->site = $cursor['site'][0]['.value']; $trackback->title = $cursor['title'][0]['.value']; $trackback->excerpt = @$cursor['excerpt'][0]['.value']; if (!empty($cursor['ip'][0]['.value'])) { $trackback->ip = $cursor['ip'][0]['.value']; } if (!empty($cursor['received'][0]['.value'])) { $trackback->received = $cursor['received'][0]['.value']; } if (!empty($cursor['isFiltered'][0]['.value'])) { $trackback->isFiltered = $cursor['isFiltered'][0]['.value']; } if (!$trackback->add()) { user_error(__LINE__ . $trackback->error); } } } if (isset($node['logs'][0]['trackback'])) { for ($i = 0; $i < count($node['logs'][0]['trackback']); $i++) { $log = new TrackbackLog(); $log->entry = $post->id; $cursor =& $node['logs'][0]['trackback'][$i]; $log->url = $cursor['url'][0]['.value']; if (!empty($cursor['sent'][0]['.value'])) { $log->sent = $cursor['sent'][0]['.value']; } if (!$log->add()) { user_error(__LINE__ . $log->error); } } } return true; case '/blog/page': setProgress($item++ / $items * 100, _t('페이지를 복원하고 있습니다.')); $page = new Page(); $page->id = $node['id'][0]['.value']; $page->slogan = @$node['.attributes']['slogan']; $page->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $page->starred = $node['starred'][0]['.value']; } else { $page->starred = 0; } $page->title = $node['title'][0]['.value']; $page->content = $node['content'][0]['.value']; $page->contentformatter = isset($node['content']['.attributes']['formatter']) ? $node['content']['.attributes']['formatter'] : getDefaultFormatter(); $page->contenteditor = isset($node['content']['.attributes']['editor']) ? $node['content']['.attributes']['editor'] : getDefaultEditor(); $page->published = $node['published'][0]['.value']; $page->created = @$node['created'][0]['.value']; $page->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $page->content = nl2brWithHTML($page->content); } if (!$page->add()) { user_error(__LINE__ . $page->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $page->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $page2 = new Page(); if ($page2->open($page->id, 'id, content')) { $page2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $page2->content); $page2->update(); $page2->close(); } unset($page2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/notice': setProgress($item++ / $items * 100, _t('공지를 복원하고 있습니다.')); $notice = new Notice(); $notice->id = $node['id'][0]['.value']; $notice->slogan = @$node['.attributes']['slogan']; $notice->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $notice->starred = $node['starred'][0]['.value']; } else { $notice->starred = 0; } $notice->title = $node['title'][0]['.value']; $notice->content = $node['content'][0]['.value']; $notice->contentformatter = isset($node['content'][0]['.attributes']['formatter']) ? $node['content'][0]['.attributes']['formatter'] : getDefaultFormatter(); $notice->contenteditor = isset($node['content'][0]['.attributes']['editor']) ? $node['content'][0]['.attributes']['editor'] : getDefaultEditor(); $notice->published = intval($node['published'][0]['.value']); $notice->created = @$node['created'][0]['.value']; $notice->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $notice->content = nl2brWithHTML($notice->content); } if (!$notice->add()) { user_error(__LINE__ . $notice->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $notice->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $notice2 = new Notice(); if ($notice2->open($notice->id, 'id, content')) { $notice2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $notice2->content); $notice2->update(); $notice2->close(); } unset($notice2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/keyword': setProgress($item++ / $items * 100, _t('키워드를 복원하고 있습니다.')); $keyword = new Keyword(); $keyword->id = $node['id'][0]['.value']; $keyword->visibility = $node['visibility'][0]['.value']; if (isset($node['starred'][0]['.value'])) { $keyword->starred = $node['starred'][0]['.value']; } else { $keyword->starred = 0; } $keyword->name = $node['name'][0]['.value']; $keyword->description = $node['description'][0]['.value']; $keyword->descriptionEditor = isset($node['description'][0]['.attributes']['editor']) ? $node['description'][0]['.attributes']['editor'] : getDefaultEditor(); $keyword->descriptionFormatter = isset($node['description'][0]['.attributes']['formatter']) ? $node['description'][0]['.attributes']['formatter'] : getDefaultFormatter(); $keyword->published = intval($node['published'][0]['.value']); $keyword->created = @$node['created'][0]['.value']; $keyword->modified = @$node['modified'][0]['.value']; if (floatval(Setting::getServiceSettingGlobal('newlineStyle')) >= 1.1 && floatval(@$node['.attributes']['format']) < 1.1) { $keyword->description = nl2brWithHTML($keyword->description); } if (!$keyword->add()) { user_error(__LINE__ . $keyword->error); } if (isset($node['attachment'])) { for ($i = 0; $i < count($node['attachment']); $i++) { $attachment = new Attachment(); $attachment->parent = $keyword->id; $cursor =& $node['attachment'][$i]; $attachment->name = $cursor['name'][0]['.value']; $attachment->label = $cursor['label'][0]['.value']; $attachment->mime = @$cursor['.attributes']['mime']; $attachment->size = $cursor['.attributes']['size']; $attachment->width = $cursor['.attributes']['width']; $attachment->height = $cursor['.attributes']['height']; $attachment->enclosure = @$cursor['enclosure'][0]['.value']; $attachment->attached = $cursor['attached'][0]['.value']; $attachment->downloads = @$cursor['downloads'][0]['.value']; if (Attachment::doesExist($attachment->name)) { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } $keyword2 = new Keyword(); if ($keyword2->open($keyword->id, 'id, content')) { $keyword2->content = str_replace($cursor['name'][0]['.value'], $attachment->name, $keyword2->content); $keyword2->update(); $keyword2->close(); } unset($keyword2); } else { if (!$attachment->add()) { user_error(__LINE__ . $attachment->error); } } if (!empty($cursor['content'][0]['.stream'])) { Utils_Base64Stream::decode($cursor['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $attachment->name)); Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $attachment->name)); fclose($cursor['content'][0]['.stream']); unset($cursor['content'][0]['.stream']); } } } return true; case '/blog/linkCategories': setProgress($item++ / $items * 100, _t('링크 카테고리를 복원하고 있습니다.')); $linkCategory = new LinkCategories(); $linkCategory->name = $node['name'][0]['.value']; $linkCategory->priority = $node['priority'][0]['.value']; $linkCategory->visibility = !isset($node['visibility'][0]['.value']) || empty($node['visibility'][0]['.value']) ? 2 : $node['visibility'][0]['.value']; $linkCategory->id = LinkCategories::getId($linkCategory->name); if ($linkCategory->id) { if (!$linkCategory->update()) { user_error(__LINE__ . $linkCategory->error); } } else { if (!$linkCategory->add()) { user_error(__LINE__ . $linkCategory->error); } } return true; case '/blog/link': setProgress($item++ / $items * 100, _t('링크를 복원하고 있습니다.')); $link = new Link(); $link->category = empty($node['category'][0]['.value']) ? 0 : $node['category'][0]['.value']; $link->url = $node['url'][0]['.value']; $link->title = $node['title'][0]['.value']; if (!empty($node['feed'][0]['.value'])) { $link->feed = $node['feed'][0]['.value']; } if (!empty($node['registered'][0]['.value'])) { $link->registered = $node['registered'][0]['.value']; } if (!empty($node['xfn'][0]['.value'])) { $link->xfn = $node['xfn'][0]['.value']; } $link->id = Link::getId($link->url); if ($link->id) { if (!$link->update()) { user_error(__LINE__ . $link->error); } } else { if (!$link->add()) { user_error(__LINE__ . $link->error); } } return true; case '/blog/logs/referer': setProgress($item++ / $items * 100, _t('리퍼러 로그를 복원하고 있습니다.')); $log = new RefererLog(); if (isset($node['path'][0]['.value'])) { $log->url = $node['path'][0]['.value']; } else { $log->url = $node['url'][0]['.value']; } $log->referred = $node['referred'][0]['.value']; if (!$log->add(false)) { user_error(__LINE__ . $log->error); } return true; case '/blog/commentsNotified/comment': setProgress($item++ / $items * 100, _t('댓글 알리미 내용을 복원하고 있습니다.')); $cmtNotified = new CommentNotified(); $cmtNotified->id = $node['id'][0]['.value']; $cursor =& $node['commenter'][0]; $cmtNotified->name = $cursor['name'][0]['.value']; $cmtNotified->homepage = $cursor['homepage'][0]['.value']; $cmtNotified->ip = $cursor['ip'][0]['.value']; $cmtNotified->entry = $node['entry'][0]['.value']; $cmtNotified->password = $node['password'][0]['.value']; $cmtNotified->content = $node['content'][0]['.value']; $cmtNotified->parent = $node['parent'][0]['.value']; $cmtNotified->secret = $node['secret'][0]['.value']; $cmtNotified->written = $node['written'][0]['.value']; $cmtNotified->modified = $node['modified'][0]['.value']; $cmtNotified->url = $node['url'][0]['.value']; $cmtNotified->isnew = $node['isNew'][0]['.value']; $site = new CommentNotifiedSiteInfo(); if (!$site->open("url = '{$node['site'][0]['.value']}'")) { $site->title = ''; $site->name = ''; $site->modified = 31536000; $site->url = $node['site'][0]['.value']; $site->add(); } $cmtNotified->siteid = $site->id; $site->close(); $cmtNotified->remoteid = $node['remoteId'][0]['.value']; $cmtNotified->entrytitle = !isset($node['entryTitle'][0]['.value']) || empty($node['entryTitle'][0]['.value']) ? 'No title' : $node['entryTitle'][0]['.value']; $cmtNotified->entryurl = $node['entryUrl'][0]['.value']; if (!$cmtNotified->add()) { user_error(__LINE__ . $cmtNotified->error); } return true; case '/blog/commentsNotifiedSiteInfo/site': setProgress($item++ / $items * 100, _t('댓글 알리미 내용을 복원하고 있습니다.')); $cmtNotifiedSite = new CommentNotifiedSiteInfo(); if ($cmtNotifiedSite->open("url = '{$node['url'][0]['.value']}'")) { if (intval($node['modified'][0]['.value']) > intval($cmtNotifiedSite->modified)) { $cmtNotifiedSite->title = $node['title'][0]['.value']; $cmtNotifiedSite->name = $node['name'][0]['.value']; $cmtNotifiedSite->modified = $node['modified'][0]['.value']; } if (!$cmtNotifiedSite->update()) { user_error(__LINE__ . $cmtNotifiedSite->error); } } else { $cmtNotifiedSite->url = $node['url'][0]['.value']; $cmtNotifiedSite->title = $node['title'][0]['.value']; $cmtNotifiedSite->name = $node['name'][0]['.value']; $cmtNotifiedSite->modified = $node['modified'][0]['.value']; if (!$cmtNotifiedSite->add()) { user_error(__LINE__ . $cmtNotifiedSite->error); } } return true; case '/blog/statistics/referer': setProgress($item++ / $items * 100, _t('리퍼러 통계를 복원하고 있습니다.')); $statistics = new RefererStatistics(); $statistics->host = $node['host'][0]['.value']; $statistics->count = $node['count'][0]['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/statistics/visits': setProgress($item++ / $items * 100, _t('블로그 통계 정보를 복원하고 있습니다.')); $statistics = new BlogStatistics(); $statistics->visits = $node['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/statistics/daily': setProgress($item++ / $items * 100, _t('일별 통계 정보를 복원하고 있습니다.')); $statistics = new DailyStatistics(); $statistics->date = $node['date'][0]['.value']; $statistics->visits = $node['visits'][0]['.value']; if (!$statistics->add()) { user_error(__LINE__ . $statistics->error); } return true; case '/blog/skin': setProgress($item++ / $items * 100, _t('스킨 설정을 복원하고 있습니다.')); $setting = new SkinSetting(); if (false) { $setting->skin = $node['name'][0]['.value']; if (!$setting->save()) { user_error(__LINE__ . $setting->error); } $setting->skin = null; } $setting->entriesOnRecent = $node['entriesOnRecent'][0]['.value']; $setting->commentsOnRecent = $node['commentsOnRecent'][0]['.value']; $setting->trackbacksOnRecent = $node['trackbacksOnRecent'][0]['.value']; $setting->commentsOnGuestbook = $node['commentsOnGuestbook'][0]['.value']; $setting->tagsOnTagbox = $node['tagsOnTagbox'][0]['.value']; $setting->alignOnTagbox = $node['alignOnTagbox'][0]['.value']; $setting->expandComment = $node['expandComment'][0]['.value']; $setting->expandTrackback = $node['expandTrackback'][0]['.value']; if (!empty($node['recentNoticeLength'][0]['.value'])) { $setting->recentNoticeLength = $node['recentNoticeLength'][0]['.value']; } $setting->recentEntryLength = $node['recentEntryLength'][0]['.value']; $setting->recentTrackbackLength = $node['recentTrackbackLength'][0]['.value']; $setting->linkLength = $node['linkLength'][0]['.value']; $setting->showListOnCategory = $node['showListOnCategory'][0]['.value']; $setting->showListOnArchive = $node['showListOnArchive'][0]['.value']; if (isset($node['tree'])) { $cursor =& $node['tree'][0]; $setting->tree = $cursor['name'][0]['.value']; $setting->colorOnTree = $cursor['color'][0]['.value']; $setting->bgcolorOnTree = $cursor['bgColor'][0]['.value']; $setting->activecolorOnTree = $cursor['activeColor'][0]['.value']; $setting->activebgcolorOnTree = $cursor['activeBgColor'][0]['.value']; $setting->labelLengthOnTree = $cursor['labelLength'][0]['.value']; $setting->showValueOnTree = $cursor['showValue'][0]['.value']; } if (!$setting->save()) { user_error(__LINE__ . $setting->error); } return true; case '/blog/plugin': // setProgress($item++ / $items * 100, _t('플러그인 설정을 복원하고 있습니다.')); // $setting = new PluginSetting(); // $setting->name = $node['name'][0]['.value']; // $setting->setting = $node['setting'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/personalization': // setProgress($item++ / $items * 100, _t('사용자 편의 설정을 복원하고 있습니다.')); // $setting = new UserSetting(); // $setting->name = 'rowsPerPage'; // $setting->value = $node['rowsPerPage'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'readerPannelVisibility'; // $setting->value = $node['readerPannelVisibility'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'readerPannelHeight'; // $setting->value = $node['readerPannelHeight'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); // $setting->name = 'lastVisitNotifiedPage'; // $setting->value = $node['lastVisitNotifiedPage'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/userSetting': // setProgress($item++ / $items * 100, _t('사용자 편의 설정을 복원하고 있습니다')); // $setting = new UserSetting(); // $setting->name = $node['name'][0]['.value']; // $setting->value = $node['value'][0]['.value']; // if (!$setting->add()) // user_error(__LINE__ . $setting->error); return true; case '/blog/guestbook/comment': setProgress($item++ / $items * 100, _t('방명록을 복원하고 있습니다.')); $comment = new GuestComment(); $comment->name = $node['commenter'][0]['name'][0]['.value']; if (!empty($node['id'][0]['.value'])) { $comment->id = $node['id'][0]['.value']; } if (!empty($node['commenter'][0]['.attributes']['id'])) { $comment->commenter = $node['commenter'][0]['.attributes']['id']; } if (!empty($node['commenter'][0]['homepage'][0]['.value'])) { $comment->homepage = $node['commenter'][0]['homepage'][0]['.value']; } if (!empty($node['commenter'][0]['ip'][0]['.value'])) { $comment->ip = $node['commenter'][0]['ip'][0]['.value']; } if (!empty($node['commenter'][0]['openid'][0]['.value'])) { $comment->openid = $node['commenter'][0]['openid'][0]['.value']; } $comment->password = $node['password'][0]['.value']; $comment->secret = @$node['secret'][0]['.value']; $comment->written = $node['written'][0]['.value']; $comment->content = $node['content'][0]['.value']; if (!$comment->add()) { user_error(__LINE__ . $comment->error); } if (isset($node['comment'])) { for ($j = 0; $j < count($node['comment']); $j++) { $childComment = new GuestComment(); $childComment->parent = $comment->id; $cursor =& $node['comment'][$j]; $childComment->name = $cursor['commenter'][0]['name'][0]['.value']; if (!empty($cursor['id'][0]['.value'])) { $comment->id = $cursor['id'][0]['.value']; } if (!empty($cursor['commenter'][0]['.attributes']['id'])) { $childComment->commenter = $cursor['commenter'][0]['.attributes']['id']; } if (!empty($cursor['commenter'][0]['homepage'][0]['.value'])) { $childComment->homepage = $cursor['commenter'][0]['homepage'][0]['.value']; } if (!empty($cursor['commenter'][0]['ip'][0]['.value'])) { $childComment->ip = $cursor['commenter'][0]['ip'][0]['.value']; } if (!empty($cursor['commenter'][0]['openid'][0]['.value'])) { $childComment->openid = $cursor['commenter'][0]['openid'][0]['.value']; } $childComment->password = $cursor['password'][0]['.value']; $childComment->secret = @$cursor['secret'][0]['.value']; $childComment->written = $cursor['written'][0]['.value']; $childComment->content = $cursor['content'][0]['.value']; if (!$childComment->add()) { user_error(__LINE__ . $childComment->error); } } } return true; case '/blog/filter': setProgress($item++ / $items * 100, _t('필터 설정을 복원하고 있습니다.')); $filter = new Filter(); $filter->type = $node['.attributes']['type']; $filter->pattern = $node['pattern'][0]['.value']; if (!$filter->add()) { user_error(__LINE__ . $filter->error); } return true; case '/blog/feed': setProgress($item++ / $items * 100, _t('리더 데이터를 복원하고 있습니다.')); $feed = new Feed(); if (!empty($node['group'][0]['.value'])) { $feed->group = FeedGroup::getId($node['group'][0]['.value'], true); } $feed->url = $node['url'][0]['.value']; if (!$feed->add()) { user_error(__LINE__ . $feed->error); } return true; case '/blog/line': setProgress($item++ / $items * 100, _t('라인을 복원하고 있습니다.')); $line = Model_Line::getInstance(); $line->reset(); if (!empty($node['author'][0]['.value'])) { $line->author = $node['author'][0]['.value']; } if (!empty($node['category'][0]['.value'])) { $line->category = $node['category'][0]['.value']; } if (!empty($node['root'][0]['.value'])) { $line->root = $node['root'][0]['.value']; } if (!empty($node['permalink'][0]['.value'])) { $line->permalink = $node['permalink'][0]['.value']; } if (!empty($node['content'][0]['.value'])) { $line->content = $node['content'][0]['.value']; } if (!empty($node['created'][0]['.value'])) { $line->created = intval($node['created'][0]['.value']); } if ($line->add()) { return true; } else { user_error(__LINE__ . $line->_error); } } }
/** * Upload new attachment * * @return void */ public function processAddAttachments() { $languages = Language::getLanguages(false); $is_attachment_name_valid = false; foreach ($languages as $language) { $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']); if (Tools::strlen($attachment_name_lang) > 0) { $is_attachment_name_valid = true; } if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) { $this->errors[] = Tools::displayError('Invalid Name'); } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) { $this->errors[] = sprintf(Tools::displayError('Name is too long (%d chars max).'), 32); } if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) { $this->errors[] = Tools::displayError('Invalid description'); } } if (!$is_attachment_name_valid) { $this->errors[] = Tools::displayError('Attachment name required'); } if (empty($this->errors)) { if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) { if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) { $this->errors[] = sprintf($this->l('File too large, maximum size allowed: %1$d kB. File size you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '')); } else { do { $uniqid = sha1(microtime()); } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)); if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) { $this->errors[] = $this->l('File copy failed'); } @unlink($_FILES['attachment_file']['tmp_name']); } } elseif ((int) $_FILES['attachment_file']['error'] === 1) { $max_upload = (int) ini_get('upload_max_filesize'); $max_post = (int) ini_get('post_max_size'); $upload_mb = min($max_upload, $max_post); $this->errors[] = sprintf($this->l('The File %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>'); } else { $this->errors[] = Tools::displayError('File is missing'); } if (empty($this->errors) && isset($uniqid)) { $attachment = new Attachment(); foreach ($languages as $language) { if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) { $attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']); } if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) { $attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']); } } $attachment->file = $uniqid; $attachment->mime = $_FILES['attachment_file']['type']; $attachment->file_name = $_FILES['attachment_file']['name']; if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) { $this->errors[] = Tools::displayError('Invalid file extension'); } if (!Validate::isGenericName($attachment->file_name)) { $this->errors[] = Tools::displayError('Invalid file name'); } if (Tools::strlen($attachment->file_name) > 128) { $this->errors[] = Tools::displayError('File name too long'); } if (empty($this->errors)) { $res = $attachment->add(); if (!$res) { $this->errors[] = Tools::displayError('Unable to add this attachment in the database'); } else { $id_product = (int) Tools::getValue($this->identifier); $res = $attachment->attachProduct($id_product); if (!$res) { $this->errors[] = Tools::displayError('Unable to associate this attachment to product'); } } } else { $this->errors[] = Tools::displayError('Invalid file'); } } } }
/** * Method used to extract and associate attachments in an email * to the given issue. * * @access public * @param integer $issue_id The issue ID * @param string $full_email The full contents of the email * @param boolean $internal_only Whether these files are supposed to be internal only or not * @param integer $associated_note_id The note ID that these attachments should be associated with * @return void */ function extractAttachments($issue_id, $full_email, $internal_only = false, $associated_note_id = false) { // figure out who should be the 'owner' of this attachment $structure = Mime_Helper::decode($full_email, false, false); $sender_email = strtolower(Mail_API::getEmailAddress($structure->headers['from'])); $usr_id = User::getUserIDByEmail($sender_email); $unknown_user = false; if (empty($usr_id)) { $prj_id = Issue::getProjectID($issue_id); if (Customer::hasCustomerIntegration($prj_id)) { // try checking if a customer technical contact has this email associated with it list(, $contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email)); if (!empty($contact_id)) { $usr_id = User::getUserIDByContactID($contact_id); } } if (empty($usr_id)) { // if we couldn't find a real customer by that email, set the usr_id to be the system user id, // and store the actual email address in the unknown_user field. $usr_id = APP_SYSTEM_USER_ID; $unknown_user = $structure->headers['from']; } } // now for the real thing $attachments = Mime_Helper::getAttachments($full_email); if (count($attachments) > 0) { if (empty($associated_note_id)) { $history_log = 'Attachment originated from an email'; } else { $history_log = 'Attachment originated from a note'; } $attachment_id = Attachment::add($issue_id, $usr_id, $history_log, $internal_only, $unknown_user, $associated_note_id); for ($i = 0; $i < count($attachments); $i++) { Attachment::addFile($attachment_id, $issue_id, $attachments[$i]['filename'], $attachments[$i]['filetype'], $attachments[$i]['blob']); } // mark the note as having attachments (poor man's caching system) if ($associated_note_id != false) { Note::setAttachmentFlag($associated_note_id); } } }
public function update_ticket() { if (!isset($_POST['ticket_id'])) { error(__("Error"), __("No ticket ID specified.", "progress")); } $ticket = new Ticket($_POST['ticket_id']); if ($ticket->no_results) { error(__("Error"), __("Invalid ticket ID specified.", "progress")); } if (!$ticket->editable()) { show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this ticket.", "progress")); } $files = array(); if (!empty($_FILES['attachment'])) { foreach ($_FILES['attachment'] as $key => $val) { foreach ($val as $file => $attr) { $files[$file][$key] = $attr; } } } foreach ($files as $attachment) { if ($attachment['error'] != 4) { $path = upload($attachment, null, "attachments"); Attachment::add(basename($path), $path, "ticket", $ticket->id); } } $ticket->update($_POST['title'], $_POST['description']); Flash::notice(__("Ticket updated.", "progress"), $ticket->url()); }
public function update_version() { if (!isset($_POST['version_id'])) { error(__("Error"), __("No version ID specified.", "extend")); } $version = new Version($_POST['version_id'], array("filter" => false)); if ($version->no_results) { error(__("Error"), __("Invalid version ID specified.", "extend")); } if (!$version->editable()) { show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this version.", "extend")); } $files = array(); if (!empty($_FILES['attachment'])) { foreach ($_FILES['attachment'] as $key => $val) { foreach ($val as $file => $attr) { $files[$file][$key] = $attr; } } } foreach ($files as $attachment) { if ($attachment['error'] != 4) { $path = upload($attachment, null, "attachments"); Attachment::add(basename($path), $path, "version", $version->id); } } $version->extension->update($_POST['name']); if ($_FILES['extension']['error'] == 0) { @unlink(uploaded($version->filename, true)); # Add the MIT license if no license is specified $zip = new ZipArchive(); if ($zip->open($_FILES['extension']['tmp_name']) === true and $zip->locateName("LICENSE") === false) { $header = "Copyright (c) " . date("Y") . " " . oneof($visitor->full_name, $visitor->login); $mit = <<<EOF Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization. EOF; $zip->addFromString("LICENSE", $header . "\n\n" . $mit . "\n"); $zip->close(); } $filename = upload($_FILES['extension'], "zip", "extension/" . pluralize($version->extension->type->url)); } else { $filename = $version->filename; } if ($_FILES['image']['error'] == 0) { @unlink(uploaded($version->image, true)); $image = upload($_FILES['image'], null, "previews/" . pluralize($version->extension->type->url)); } else { $image = $version->image; } $version->update($_POST['number'], $_POST['description'], comma_sep($_POST['compatible']), comma_sep($_POST['tags']), $filename, $image); Flash::notice(__("Version updated.", "extend"), $version->url()); }
/** * Method used to add a new issue using the normal report form. * * @access public * @return integer The new issue ID */ function insert() { global $HTTP_POST_VARS, $HTTP_POST_FILES, $insert_errors; $usr_id = Auth::getUserID(); $prj_id = Auth::getCurrentProject(); $initial_status = Project::getInitialStatus($prj_id); $insert_errors = array(); $missing_fields = array(); if ($HTTP_POST_VARS["category"] == '-1') { $missing_fields[] = "Category"; } if ($HTTP_POST_VARS["priority"] == '-1') { $missing_fields[] = "Priority"; } if ($HTTP_POST_VARS["estimated_dev_time"] == '') { $HTTP_POST_VARS["estimated_dev_time"] = 0; } // add new issue $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n (\n iss_prj_id,\n"; if (!empty($HTTP_POST_VARS["group"])) { $stmt .= "iss_grp_id,\n"; } if (!empty($HTTP_POST_VARS["category"])) { $stmt .= "iss_prc_id,\n"; } if (!empty($HTTP_POST_VARS["release"])) { $stmt .= "iss_pre_id,\n"; } if (!empty($HTTP_POST_VARS["priority"])) { $stmt .= "iss_pri_id,\n"; } $stmt .= "iss_usr_id,"; if (!empty($initial_status)) { $stmt .= "iss_sta_id,"; } if (Customer::hasCustomerIntegration($prj_id)) { $stmt .= "\n iss_customer_id,\n iss_customer_contact_id,\n iss_contact_person_lname,\n iss_contact_person_fname,\n iss_contact_email,\n iss_contact_phone,\n iss_contact_timezone,"; } $stmt .= "\n iss_created_date,\n iss_last_public_action_date,\n iss_last_public_action_type,\n iss_summary,\n iss_description,\n iss_dev_time,\n iss_private,\n iss_root_message_id\n ) VALUES (\n " . $prj_id . ",\n"; if (!empty($HTTP_POST_VARS["group"])) { $stmt .= Misc::escapeInteger($HTTP_POST_VARS["group"]) . ",\n"; } if (!empty($HTTP_POST_VARS["category"])) { $stmt .= Misc::escapeInteger($HTTP_POST_VARS["category"]) . ",\n"; } if (!empty($HTTP_POST_VARS["release"])) { $stmt .= Misc::escapeInteger($HTTP_POST_VARS["release"]) . ",\n"; } if (!empty($HTTP_POST_VARS["priority"])) { $stmt .= Misc::escapeInteger($HTTP_POST_VARS["priority"]) . ","; } // if we are creating an issue for a customer, put the // main customer contact as the reporter for it if (Customer::hasCustomerIntegration($prj_id)) { $contact_usr_id = User::getUserIDByContactID($HTTP_POST_VARS['contact']); if (empty($contact_usr_id)) { $contact_usr_id = $usr_id; } $stmt .= Misc::escapeInteger($contact_usr_id) . ","; } else { $stmt .= $usr_id . ","; } if (!empty($initial_status)) { $stmt .= Misc::escapeInteger($initial_status) . ","; } if (Customer::hasCustomerIntegration($prj_id)) { $stmt .= "\n " . Misc::escapeInteger($HTTP_POST_VARS['customer']) . ",\n " . Misc::escapeInteger($HTTP_POST_VARS['contact']) . ",\n '" . Misc::escapeString($HTTP_POST_VARS["contact_person_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_person_fname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_email"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_phone"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_timezone"]) . "',"; } $stmt .= "\n '" . Date_API::getCurrentDateGMT() . "',\n '" . Date_API::getCurrentDateGMT() . "',\n 'created',\n '" . Misc::escapeString($HTTP_POST_VARS["summary"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n " . Misc::escapeString($HTTP_POST_VARS["estimated_dev_time"]) . ",\n " . Misc::escapeInteger($HTTP_POST_VARS["private"]) . " ,\n '" . Misc::escapeString(Mail_API::generateMessageID()) . "'\n )"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { $new_issue_id = $GLOBALS["db_api"]->get_last_insert_id(); $has_TAM = false; $has_RR = false; $info = User::getNameEmail($usr_id); // log the creation of the issue History::add($new_issue_id, Auth::getUserID(), History::getTypeID('issue_opened'), 'Issue opened by ' . User::getFullName(Auth::getUserID())); $emails = array(); if (Customer::hasCustomerIntegration($prj_id)) { if (@count($HTTP_POST_VARS['contact_extra_emails']) > 0) { $emails = $HTTP_POST_VARS['contact_extra_emails']; } // add the primary contact to the notification list if ($HTTP_POST_VARS['add_primary_contact'] == 'yes') { $contact_email = User::getEmailByContactID($HTTP_POST_VARS['contact']); if (!empty($contact_email)) { $emails[] = $contact_email; } } // if there are any technical account managers associated with this customer, add these users to the notification list $managers = Customer::getAccountManagers($prj_id, $HTTP_POST_VARS['customer']); $manager_usr_ids = array_keys($managers); $manager_emails = array_values($managers); $emails = array_merge($emails, $manager_emails); } // add the reporter to the notification list $emails[] = $info['usr_email']; $emails = array_unique($emails); // COMPAT: version >= 4.0.1 $actions = Notification::getDefaultActions(); foreach ($emails as $address) { Notification::subscribeEmail($usr_id, $new_issue_id, $address, $actions); } // only assign the issue to an user if the associated customer has any technical account managers $users = array(); $has_TAM = false; if (Customer::hasCustomerIntegration($prj_id) && count($manager_usr_ids) > 0) { foreach ($manager_usr_ids as $manager_usr_id) { $users[] = $manager_usr_id; Issue::addUserAssociation($usr_id, $new_issue_id, $manager_usr_id, false); History::add($new_issue_id, $usr_id, History::getTypeID('issue_auto_assigned'), 'Issue auto-assigned to ' . User::getFullName($manager_usr_id) . ' (TAM)'); } $has_TAM = true; } // now add the user/issue association (aka assignments) if (@count($HTTP_POST_VARS["users"]) > 0) { for ($i = 0; $i < count($HTTP_POST_VARS["users"]); $i++) { Notification::subscribeUser($usr_id, $new_issue_id, $HTTP_POST_VARS["users"][$i], $actions); Issue::addUserAssociation($usr_id, $new_issue_id, $HTTP_POST_VARS["users"][$i]); if ($HTTP_POST_VARS["users"][$i] != $usr_id) { $users[] = $HTTP_POST_VARS["users"][$i]; } } } else { // only use the round-robin feature if this new issue was not // already assigned to a customer account manager if (@count($manager_usr_ids) < 1) { $assignee = Round_Robin::getNextAssignee($prj_id); // assign the issue to the round robin person if (!empty($assignee)) { $users[] = $assignee; Issue::addUserAssociation($usr_id, $new_issue_id, $assignee, false); History::add($new_issue_id, APP_SYSTEM_USER_ID, History::getTypeID('rr_issue_assigned'), 'Issue auto-assigned to ' . User::getFullName($assignee) . ' (RR)'); $has_RR = true; } } } // now process any files being uploaded $found = 0; for ($i = 0; $i < count(@$HTTP_POST_FILES["file"]["name"]); $i++) { if (!@empty($HTTP_POST_FILES["file"]["name"][$i])) { $found = 1; break; } } if ($found) { $files = array(); for ($i = 0; $i < count($HTTP_POST_FILES["file"]["name"]); $i++) { $filename = @$HTTP_POST_FILES["file"]["name"][$i]; if (empty($filename)) { continue; } $blob = Misc::getFileContents($HTTP_POST_FILES["file"]["tmp_name"][$i]); if (empty($blob)) { // error reading a file $insert_errors["file[{$i}]"] = "There was an error uploading the file '{$filename}'."; continue; } $files[] = array("filename" => $filename, "type" => $HTTP_POST_FILES['file']['type'][$i], "blob" => $blob); } if (count($files) > 0) { $attachment_id = Attachment::add($new_issue_id, $usr_id, 'Files uploaded at issue creation time'); foreach ($files as $file) { Attachment::addFile($attachment_id, $new_issue_id, $file["filename"], $file["type"], $file["blob"]); } } } // need to associate any emails ? if (!empty($HTTP_POST_VARS["attached_emails"])) { $items = explode(",", $HTTP_POST_VARS["attached_emails"]); Support::associate($usr_id, $new_issue_id, $items, true); } // need to notify any emails being converted into issues ? if (@count($HTTP_POST_VARS["notify_senders"]) > 0) { $recipients = Notification::notifyEmailConvertedIntoIssue($prj_id, $new_issue_id, $HTTP_POST_VARS["notify_senders"], $customer_id); } else { $recipients = array(); } // need to process any custom fields ? if (@count($HTTP_POST_VARS["custom_fields"]) > 0) { foreach ($HTTP_POST_VARS["custom_fields"] as $fld_id => $value) { Custom_Field::associateIssue($new_issue_id, $fld_id, $value); } } // also send a special confirmation email to the customer contact if (@$HTTP_POST_VARS['notify_customer'] == 'yes' && !empty($HTTP_POST_VARS['contact'])) { // also need to pass the list of sender emails already notified, // so we can avoid notifying the same person again $contact_email = User::getEmailByContactID($HTTP_POST_VARS['contact']); if (@(!in_array($contact_email, $recipients))) { Customer::notifyCustomerIssue($prj_id, $new_issue_id, $HTTP_POST_VARS['contact']); } } Workflow::handleNewIssue($prj_id, $new_issue_id, $has_TAM, $has_RR); // also notify any users that want to receive emails anytime a new issue is created Notification::notifyNewIssue($prj_id, $new_issue_id); return $new_issue_id; } }
protected function importAttachments() { $this->truncateTables(array('attachment', 'attachment_lang')); $handle = $this->openCsvFile('attachments.csv'); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) { $res = false; $fields = $this->filterFields('Attachment', $this->attachments_fields, $line); if (!isset($fields['id'])) { $attacment = new Attachment((int) $line[0]); $attacment->id = $line[0]; } else { $attacment = new Attachment((int) $fields['id']); } foreach ($fields as $key => $field) { if ($key == 'name' || $key == 'description') { $attacment->{$key} = $this->multilFild($field); } else { $attacment->{$key} = $field; } } $attacment->force_id = true; if (!$res) { $attacment->add(); } } $this->closeCsvFile($handle); return true; }