protected function postProcess() { $errors = ''; if (Tools::isSubmit('deleteImage')) { if (!file_exists(dirname(__FILE__) . '/img/' . $this->_getUserImg())) { $errors .= $this->displayError($this->l('This action cannot be taken.')); } else { unlink(dirname(__FILE__) . '/img/' . $this->_getUserImg()); Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id)); } } if (Tools::isSubmit('submitUpdateScrolltop')) { if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { if ($error = ImageManager::validateUpload($_FILES['image'])) { $errors .= $this->displayError($error); } elseif (!ImageManager::resize($_FILES['image']['tmp_name'], dirname(__FILE__) . '/img/' . $this->_getUserImg())) { $errors .= $this->displayError($this->l('An error occurred during the image upload.')); } } foreach ($this->_scrollParams as $param => $value) { if ($val = (int) Tools::getValue($param)) { $this->_setScrollParam($param, $val); } else { $errors .= $this->displayError($this->l('"' . $param . '" is not valid.')); } } if (!$errors) { Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id)); } } $this->_html .= $errors; }
public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { if (!($languages = Language::getLanguages(true))) { return false; } $text = array(); foreach ($languages as $lang) { $text[$lang['id_lang']] = Tools::getValue('BLOCKSTORE_TEXT_' . $lang['id_lang']); } Configuration::updateValue('BLOCKSTORE_TEXT', $text); if (isset($_FILES['BLOCKSTORE_IMG']) && isset($_FILES['BLOCKSTORE_IMG']['tmp_name']) && !empty($_FILES['BLOCKSTORE_IMG']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['BLOCKSTORE_IMG'], 4000000)) { return $this->displayError($this->l('Invalid image.')); } else { $ext = substr($_FILES['BLOCKSTORE_IMG']['name'], strrpos($_FILES['BLOCKSTORE_IMG']['name'], '.') + 1); $file_name = md5($_FILES['BLOCKSTORE_IMG']['name']) . '.' . $ext; if (!move_uploaded_file($_FILES['BLOCKSTORE_IMG']['tmp_name'], dirname(__FILE__) . '/' . $file_name)) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $file_name) { @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG')); } Configuration::updateValue('BLOCKSTORE_IMG', $file_name); $this->_clearCache('blockstore.tpl'); return $this->displayConfirmation($this->l('The settings have been updated.')); } } } $this->_clearCache('blockstore.tpl'); } return ''; }
protected function validate(&$file) { $file['error'] = $this->checkUploadError($file['error']); if ($file['error']) { return false; } $post_max_size = Tools::convertBytes(ini_get('post_max_size')); $upload_max_filesize = Tools::convertBytes(ini_get('upload_max_filesize')); if ($post_max_size && $this->_getServerVars('CONTENT_LENGTH') > $post_max_size) { $file['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini'); return false; } if ($upload_max_filesize && $this->_getServerVars('CONTENT_LENGTH') > $upload_max_filesize) { $file['error'] = Tools::displayError('The uploaded file exceeds the upload_max_filesize directive in php.ini'); return false; } if ($error = ImageManager::validateUpload($file, Tools::getMaxUploadSize($this->getMaxSize()), $this->getAcceptTypes())) { $file['error'] = $error; return false; } if ($file['size'] > $this->getMaxSize()) { $file['error'] = sprintf(Tools::displayError('File (size : %1s) is too big (max : %2s)'), $file['size'], $this->getMaxSize()); return false; } return true; }
public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { Configuration::updateValue('PRODUCTPAYMENTLOGOS_LINK', Tools::getValue('PRODUCTPAYMENTLOGOS_LINK')); Configuration::updateValue('PRODUCTPAYMENTLOGOS_TITLE', Tools::getValue('PRODUCTPAYMENTLOGOS_TITLE')); if (isset($_FILES['PRODUCTPAYMENTLOGOS_IMG']) && isset($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name']) && !empty($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name'])) { if (ImageManager::validateUpload($_FILES['PRODUCTPAYMENTLOGOS_IMG'], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { $ext = Tools::substr($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name'], Tools::strrpos($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name'], '.') + 1); $file_name = md5($_FILES['PRODUCTPAYMENTLOGOS_IMG']['name']) . '.' . $ext; if (!move_uploaded_file($_FILES['PRODUCTPAYMENTLOGOS_IMG']['tmp_name'], dirname(__FILE__) . '/img/' . $file_name)) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { $file_path = dirname(__FILE__) . '/img/' . Configuration::get('PRODUCTPAYMENTLOGOS_IMG'); if (Configuration::hasContext('PRODUCTPAYMENTLOGOS_IMG', null, Shop::getContext()) && Configuration::get('PRODUCTPAYMENTLOGOS_IMG') != $file_name && file_exists($file_path)) { unlink($file_path); } Configuration::updateValue('PRODUCTPAYMENTLOGOS_IMG', $file_name); $this->_clearCache('productpaymentlogos.tpl'); Tools::redirectAdmin('index.php?tab=AdminModules&conf=6&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')); } } } $this->_clearCache('productpaymentlogos.tpl'); } return ''; }
protected function validate(&$file) { $post_max_size = $this->getPostMaxSizeBytes(); if ($post_max_size && $this->_getServerVars('CONTENT_LENGTH') > $post_max_size) { $file['error'] = Tools::displayError('The uploaded file exceeds the post_max_size directive in php.ini'); return false; } if ($error = ImageManager::validateUpload($file, Tools::getMaxUploadSize($this->getMaxSize()), $this->getAcceptTypes())) { $file['error'] = $error; return false; } if ($file['size'] > $this->getMaxSize()) { $file['error'] = Tools::displayError('File is too big'); return false; } return true; }
public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000)) { return $this->displayError($this->l('invalid image')); } else { if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__) . '/' . $_FILES['store_img']['name'])) { return $this->displayError($this->l('an error occurred on uploading file')); } else { if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name']) { @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG')); } Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']); return $this->displayConfirmation($this->l('Settings are updated')); } } } } return ''; }
protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null) { if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) { // Delete old image if (Validate::isLoadedObject($object = $this->loadObject())) { $object->deleteImage(); } else { return false; } // Check image validity $max_size = isset($this->max_image_size) ? $this->max_image_size : 0; if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size))) { $this->errors[] = $error; } $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if (!$tmp_name) { return false; } if (!move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name)) { return false; } // Evaluate the memory required to resize the image: if it's too much, you can't resize it. if (!ImageManager::checkImageMemoryLimit($tmp_name)) { $this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. '); } // Copy new image if (empty($this->errors) && !ImageManager::resize($tmp_name, _PS_MODULE_DIR_ . 'possequence' . DS . 'images' . DS . $name . '_' . $id . '.' . $this->imageType, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) { $this->errors[] = Tools::displayError('An error occurred while uploading the image.'); } if (count($this->errors)) { return false; } if ($this->afterImageUpload()) { unlink($tmp_name); return true; } return false; } return true; }
public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__) . '/' . $_FILES['store_img']['name'])) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $_FILES['store_img']['name']) { @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKSTORE_IMG')); } Configuration::updateValue('BLOCKSTORE_IMG', $_FILES['store_img']['name']); $this->_clearCache('blockstore.tpl'); return $this->displayConfirmation($this->l('The settings have been updated.')); } } } } return ''; }
/** * Generic function which allows logo upload * * @param $field_name * @param $logo_prefix * * @return bool */ protected function updateLogo($field_name, $logo_prefix) { $id_shop = Context::getContext()->shop->id; if (isset($_FILES[$field_name]['tmp_name']) && $_FILES[$field_name]['tmp_name']) { if ($error = ImageManager::validateUpload($_FILES[$field_name], Tools::getMaxUploadSize())) { $this->errors[] = $error; return false; } $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if (!$tmp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $tmp_name)) { return false; } $ext = $field_name == 'PS_STORES_ICON' ? '.gif' : '.jpg'; $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . '-' . (int) $id_shop . $ext; if (Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL || $id_shop == 0 || Shop::isFeatureActive() == false) { $logo_name = Tools::link_rewrite(Context::getContext()->shop->name) . '-' . Configuration::get('PS_IMG_UPDATE_TIME') . $ext; } if ($field_name == 'PS_STORES_ICON') { if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name, null, null, 'gif', true)) { $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.'); } } else { if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name)) { $this->errors[] = Tools::displayError('An error occurred while attempting to copy your logo.'); } } if (!count($this->errors) && @filemtime(_PS_IMG_DIR_ . Configuration::get($field_name))) { @unlink(_PS_IMG_DIR_ . Configuration::get($field_name)); } Configuration::updateValue($field_name, $logo_name); @unlink($tmp_name); } }
public function ajaxProcessUpdateCustomizationFields() { $errors = array(); if ($this->tabAccess['edit'] === '1') { $errors = array(); if (Tools::getValue('only_display') != 1) { if (!$this->context->cart->id || !($id_product = (int) Tools::getValue('id_product'))) { return; } $product = new Product((int) $id_product); if (!($customization_fields = $product->getCustomizationFieldIds())) { return; } foreach ($customization_fields as $customization_field) { $field_id = 'customization_' . $id_product . '_' . $customization_field['id_customization_field']; if ($customization_field['type'] == Product::CUSTOMIZE_TEXTFIELD) { if (!Tools::getValue($field_id)) { if ($customization_field['required']) { $errors[] = Tools::displayError('Please fill in all the required fields.'); } continue; } if (!Validate::isMessage(Tools::getValue($field_id))) { $errors[] = Tools::displayError('Invalid message'); } $this->context->cart->addTextFieldToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_TEXTFIELD, Tools::getValue($field_id)); } elseif ($customization_field['type'] == Product::CUSTOMIZE_FILE) { if (!isset($_FILES[$field_id]) || !isset($_FILES[$field_id]['tmp_name']) || empty($_FILES[$field_id]['tmp_name'])) { if ($customization_field['required']) { $errors[] = Tools::displayError('Please fill in all the required fields.'); } continue; } if ($error = ImageManager::validateUpload($_FILES[$field_id], (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) { $errors[] = $error; } if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$field_id]['tmp_name'], $tmp_name)) { $errors[] = Tools::displayError('An error occurred during the image upload process.'); } $file_name = md5(uniqid(rand(), true)); if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name)) { continue; } elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name . '_small', (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH'), (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'))) { $errors[] = Tools::displayError('An error occurred during the image upload process.'); } elseif (!chmod(_PS_UPLOAD_DIR_ . $file_name, 0777) || !chmod(_PS_UPLOAD_DIR_ . $file_name . '_small', 0777)) { $errors[] = Tools::displayError('An error occurred during the image upload process.'); } else { $this->context->cart->addPictureToProduct((int) $product->id, (int) $customization_field['id_customization_field'], Product::CUSTOMIZE_FILE, $file_name); } unlink($tmp_name); } } } $this->setMedia(); $this->initFooter(); $this->context->smarty->assign(array('customization_errors' => implode('<br />', $errors), 'css_files' => $this->css_files)); return $this->smartyOutputContent('controllers/orders/form_customization_feedback.tpl'); } }
/** * Process the upload of new logo */ public function processUploadLogo() { $error = ''; if (isset($_FILES['fileToUpload']['tmp_name']) && $_FILES['fileToUpload']['tmp_name']) { $file = $_FILES['fileToUpload']; $error = ImageManager::validateUpload($file, 300000); if (!strlen($error)) { $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name)) { return false; } list($width, $height, $type) = getimagesize($tmp_name); $newheight = $height > 500 ? 500 : $height; $percent = $newheight / $height; $newwidth = $width * $percent; $newheight = $height * $percent; if (!is_writable(_PS_ROOT_DIR_ . '/img/')) { $error = $this->l('Image folder %s is not writable', _PS_ROOT_DIR_ . '/img/'); } if (!$error) { list($src_width, $src_height, $type) = getimagesize($tmp_name); $src_image = ImageManager::create($type, $tmp_name); $dest_image = imagecreatetruecolor($src_width, $src_height); $white = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $src_width, $src_height, $white); imagecopyresampled($dest_image, $src_image, 0, 0, 0, 0, $src_width, $src_height, $src_width, $src_height); if (!imagejpeg($dest_image, _PS_ROOT_DIR_ . '/img/logo.jpg', 95)) { $error = $this->l('An error occurred during logo copy.'); } else { imagedestroy($dest_image); @chmod($filename, 0664); } } } else { $error = $this->l('An error occurred during logo upload.'); } } $this->ajaxJsonAnswer($error ? false : true, $error); }
public function getContent() { $html = ''; $id_reinsurance = (int) Tools::getValue('id_reinsurance'); if (Tools::isSubmit('saveblockreinsurance')) { if ($id_reinsurance = Tools::getValue('id_reinsurance')) { $reinsurance = new reinsuranceClass((int) $id_reinsurance); } else { $reinsurance = new reinsuranceClass(); } $reinsurance->copyFromPost(); $reinsurance->id_shop = $this->context->shop->id; if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) { $reinsurance->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['image'])) { return false; } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) { return false; } elseif (!ImageManager::resize($tmpName, dirname(__FILE__) . '/img/reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg')) { return false; } unlink($tmpName); $reinsurance->file_name = 'reinsurance-' . (int) $reinsurance->id . '-' . (int) $reinsurance->id_shop . '.jpg'; $reinsurance->save(); } $this->_clearCache('blockreinsurance.tpl'); } else { $html .= '<div class="conf error">' . $this->l('An error occurred while attempting to save.') . '</div>'; } } if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) { $helper = $this->initForm(); foreach (Language::getLanguages(false) as $lang) { if ($id_reinsurance) { $reinsurance = new reinsuranceClass((int) $id_reinsurance); $helper->fields_value['text'][(int) $lang['id_lang']] = $reinsurance->text[(int) $lang['id_lang']]; } else { $helper->fields_value['text'][(int) $lang['id_lang']] = Tools::getValue('text_' . (int) $lang['id_lang'], ''); } } if ($id_reinsurance = Tools::getValue('id_reinsurance')) { $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance'); $helper->fields_value['id_reinsurance'] = (int) $id_reinsurance; } return $html . $helper->generateForm($this->fields_form); } else { if (Tools::isSubmit('deleteblockreinsurance')) { $reinsurance = new reinsuranceClass((int) $id_reinsurance); if (file_exists(dirname(__FILE__) . '/img/' . $reinsurance->file_name)) { unlink(dirname(__FILE__) . '/img/' . $reinsurance->file_name); } $reinsurance->delete(); $this->_clearCache('blockreinsurance.tpl'); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')); } else { $helper = $this->initList(); return $html . $helper->generateList($this->getListContent((int) Configuration::get('PS_LANG_DEFAULT')), $this->fields_list); } } if (isset($_POST['submitModule'])) { Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', isset($_POST['nbblocks']) && $_POST['nbblocks'] != '' ? (int) $_POST['nbblocks'] : ''); if ($this->removeFromDB() && $this->addToDB()) { $this->_clearCache('blockreinsurance.tpl'); $output = '<div class="conf confirm">' . $this->l('The block configuration has been updated.') . '</div>'; } else { $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>' . $this->l('An error occurred while attempting to save.') . '</div>'; } } }
private function _postProcess() { $errors = array(); /* Process Slide status */ if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) { $slide = new leftBanner((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $res = $slide->update(); $this->clearCache(); $this->html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')); } elseif (Tools::isSubmit('submitSlide')) { /* Sets ID if needed */ if (Tools::getValue('id_slide')) { $slide = new leftBanner((int) Tools::getValue('id_slide')); if (!Validate::isLoadedObject($slide)) { $this->html .= $this->displayError($this->l('Invalid id_slide')); return false; } } else { $slide = new leftBanner(); } /* Sets position */ $slide->position = (int) Tools::getValue('position'); /* Sets active */ $slide->active = (int) Tools::getValue('active_slide'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']); $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']); /* Uploads image and sets slide */ $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1)); $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']); if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = sha1(microtime()); if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) { $errors[] = $error; } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/img/' . Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type, null, null, $type)) { $errors[] = $this->displayError($this->l('An error occurred during the image upload process.')); } if (isset($temp_name)) { @unlink($temp_name); } $slide->image[$language['id_lang']] = Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type; } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') { $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']); } } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_slide')) { if (!$slide->add()) { $errors[] = $this->displayError($this->l('The slide could not be added.')); } } elseif (!$slide->update()) { $errors[] = $this->displayError($this->l('The slide could not be updated.')); } $this->clearCache(); } } elseif (Tools::isSubmit('delete_id_slide')) { $slide = new leftBanner((int) Tools::getValue('delete_id_slide')); $res = $slide->delete(); $this->clearCache(); if (!$res) { $this->html .= $this->displayError('Could not delete.'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } } /* Display errors if needed */ if (count($errors)) { $this->html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } elseif (Tools::isSubmit('submitSlide')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } }
public function processImageUpload($FILES) { if (isset($FILES['avatar']) && isset($FILES['avatar']['tmp_name']) && !empty($FILES['avatar']['tmp_name'])) { if (ImageManager::validateUpload($FILES['avatar'], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { $ext = Tools::substr($FILES['avatar']['name'], strrpos($FILES['avatar']['name'], '.') + 1); $file_name = 'avatar.' . $ext; $path = _PS_MODULE_DIR_ . 'smartblog/images/avatar/' . $file_name; if (!move_uploaded_file($FILES['avatar']['tmp_name'], $path)) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { $author_types = BlogImageType::GetImageAllType('author'); foreach ($author_types as $image_type) { $dir = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg'; if (file_exists($dir)) { unlink($dir); } } $images_types = BlogImageType::GetImageAllType('author'); foreach ($images_types as $image_type) { ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . Tools::stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']); } } } } }
/** * render content info */ public function getContent() { // $resultCheck = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_btmegamenu` as id FROM `' . _DB_PREFIX_ . 'btmegamenu_shop` WHERE `id_btmegamenu` = 1 AND `id_shop`=' . (int) ($this->context->shop->id)); // if ($resultCheck["id"] != 1){ // Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'btmegamenu_shop`(`id_btmegamenu`,`id_shop`) VALUES( 1, '.(int)$this->context->shop->id.' )'); // } $output = ''; $this->_html .= $this->headerHTML(); $this->_html .= '<h2>' . $this->displayName . '.</h2>'; /* update tree megamenu positions */ if (Tools::getValue('doupdatepos') && Tools::isSubmit('updatePosition')) { $list = Tools::getValue('list'); $root = 1; $child = array(); foreach ($list as $id => $parent_id) { if ($parent_id <= 0) { # validate module $parent_id = $root; } $child[$parent_id][] = $id; } $res = true; foreach ($child as $id_parent => $menus) { $i = 0; foreach ($menus as $id_btmegamenu) { $res &= Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'btmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' WHERE `id_btmegamenu` = ' . (int) $id_btmegamenu); $i++; } } $this->clearCache(); die($this->l('Update Positions Done')); } if (Tools::getValue('show_cavas') && Tools::isSubmit('updatecavas')) { $show = Tools::getValue('show') ? Tools::getValue('show') : 0; if (Configuration::updateValue('LEO_MEGAMENU_CAVAS', $show)) { $this->clearCache(); die($this->l('Update Done')); } else { die($this->l('Can not Update')); } } /* delete megamenu item */ if (Tools::getValue('dodel')) { $obj = new Btmegamenu((int) Tools::getValue('id_btmegamenu')); $res = $obj->delete(); $this->clearCache(); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')); } if (Tools::isSubmit('save' . $this->name) && Tools::isSubmit('active')) { // if( Tools::getValue('type') == 'url' && !Tools::getValue('url')){ // $errors[] = $this->l('Account details are required.'); // } // if (!isset($errors) AND !sizeof($errors)){ if ($id_btmegamenu = Tools::getValue('id_btmegamenu')) { # validate module $megamenu = new Btmegamenu((int) $id_btmegamenu); } else { # validate module $megamenu = new Btmegamenu(); } $keys = LeoBtmegamenuHelper::getConfigKey(false); $post = LeoBtmegamenuHelper::getPost($keys, false); $keys = LeoBtmegamenuHelper::getConfigKey(true); $post += LeoBtmegamenuHelper::getPost($keys, true); $megamenu->copyFromPost($post); $megamenu->id_shop = $this->context->shop->id; if ($megamenu->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) { # validate module $megamenu->item = Tools::getValue($megamenu->type . '_type'); } $url_default = ''; foreach ($megamenu->url as $menu_url) { if ($menu_url) { $url_default = $menu_url; break; } } if ($url_default) { foreach ($megamenu->url as &$menu_url) { if (!$menu_url) { $menu_url = $url_default; } } } if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) { $megamenu->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { $this->checkFolderIcon(); if (ImageManager::validateUpload($_FILES['image'])) { return false; } elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) { return false; } elseif (!ImageManager::resize($tmp_name, $this->img_path . $_FILES['image']['name'])) { return false; } unlink($tmp_name); $megamenu->image = $_FILES['image']['name']; $megamenu->save(); } else { if (Tools::getIsset('delete_icon')) { if ($megamenu->image) { unlink($this->img_path . $megamenu->image); $megamenu->image = ''; $megamenu->save(); } } } Tools::redirectAdmin(AdminController::$currentIndex . '&configure=leobootstrapmenu&save' . $this->name . '&token=' . Tools::getValue('token') . '&id_btmegamenu=' . $megamenu->id); } else { # validate module $errors = array(); $errors[] = $this->l('An error occurred while attempting to save.'); } // } if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } else { $this->clearCache(); $output .= $this->displayConfirmation($this->l('Settings updated.')); } } return $output . $this->displayForm(); }
/** * Copy a no-product image * * @param string $language Language iso_code for no_picture image filename * * @return void|false */ public function copyNoPictureImage($language) { if (isset($_FILES['no_picture']) && $_FILES['no_picture']['error'] === 0) { if ($error = ImageManager::validateUpload($_FILES['no_picture'], Tools::getMaxUploadSize())) { $this->errors[] = $error; } else { if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['no_picture']['tmp_name'], $tmp_name)) { return false; } if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'p/' . $language . '.jpg')) { $this->errors[] = Tools::displayError('An error occurred while copying "No Picture" image to your product folder.'); } if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'c/' . $language . '.jpg')) { $this->errors[] = Tools::displayError('An error occurred while copying "No picture" image to your category folder.'); } if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'm/' . $language . '.jpg')) { $this->errors[] = Tools::displayError('An error occurred while copying "No picture" image to your manufacturer folder.'); } else { $images_types = ImageType::getImagesTypes('products'); foreach ($images_types as $k => $image_type) { if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'p/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) { $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your product directory.'); } if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'c/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) { $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your category directory.'); } if (!ImageManager::resize($tmp_name, _PS_IMG_DIR_ . 'm/' . $language . '-default-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'])) { $this->errors[] = Tools::displayError('An error occurred while resizing "No picture" image to your manufacturer directory.'); } } } unlink($tmp_name); } } }
/** * Copy a product image * * @param integer $id_product Product Id for product image filename * @param integer $id_image Image Id for product image filename */ public function copyImage($id_product, $id_image, $method = 'auto') { if (!isset($_FILES['image_product']['tmp_name'])) { return false; } if ($error = ImageManager::validateUpload($_FILES['image_product'])) { $this->errors[] = $error; } else { $image = new Image($id_image); if (!($new_path = $image->getPathForCreation())) { $this->errors[] = Tools::displayError('An error occurred while attempting to create a new folder.'); } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image_product']['tmp_name'], $tmpName)) { $this->errors[] = Tools::displayError('An error occurred during the image upload process.'); } elseif (!ImageManager::resize($tmpName, $new_path . '.' . $image->image_format)) { $this->errors[] = Tools::displayError('An error occurred while copying the image.'); } elseif ($method == 'auto') { $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $k => $image_type) { if (!ImageManager::resize($tmpName, $new_path . '-' . stripslashes($image_type['name']) . '.' . $image->image_format, $image_type['width'], $image_type['height'], $image->image_format)) { $this->errors[] = Tools::displayError('An error occurred while copying this image:') . ' ' . stripslashes($image_type['name']); } } } @unlink($tmpName); Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_product)); } }
/** * @deprecated 1.5.0 */ function checkImage($file, $maxFileSize = 0) { Tools::displayAsDeprecated(); return ImageManager::validateUpload($file, $maxFileSize); }
/** * @param Employee $object * * @return bool */ protected function postImage($id) { $ret = parent::postImage($id); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['image'], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { $path = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '.' . $this->imageType; $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if (!$tmp_name) { return false; } if (!move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) { return false; } // Evaluate the memory required to resize the image: if it's too much, you can't resize it. if (!ImageManager::checkImageMemoryLimit($tmp_name)) { $this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. '); } // Copy new image if (empty($this->errors) && !ImageManager::resize($tmp_name, $path, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) { $this->errors[] = Tools::displayError('An error occurred while uploading the image.'); } if (count($this->errors)) { return false; } if ($this->afterImageUpload()) { unlink($tmp_name); // return true; } $posts_types = BlogImageType::GetImageAllType('post'); foreach ($posts_types as $image_type) { $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg'; if (file_exists($dir)) { unlink($dir); } } foreach ($posts_types as $image_type) { ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']); } } } return $ret; }
public function postProcess() { if (Tools::isSubmit('submitStoreConf')) { $languages = Language::getLanguages(false); $values = array(); $update_images_values = false; foreach ($languages as $lang) { if (isset($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]) && isset($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['tmp_name']) && !empty($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { $ext = substr($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['name'], strrpos($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['name'], '.') + 1); $file_name = md5($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['name']) . '.' . $ext; if (!move_uploaded_file($_FILES['BLOCKBANNER_IMG_' . $lang['id_lang']]['tmp_name'], dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $file_name)) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { if (Configuration::hasContext('BLOCKBANNER_IMG', $lang['id_lang'], Shop::getContext()) && Configuration::get('BLOCKBANNER_IMG', $lang['id_lang']) != $file_name) { @unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . Configuration::get('BLOCKBANNER_IMG', $lang['id_lang'])); } $values['BLOCKBANNER_IMG'][$lang['id_lang']] = $file_name; } } $update_images_values = true; } $values['BLOCKBANNER_LINK'][$lang['id_lang']] = Tools::getValue('BLOCKBANNER_LINK_' . $lang['id_lang']); $values['BLOCKBANNER_DESC'][$lang['id_lang']] = Tools::getValue('BLOCKBANNER_DESC_' . $lang['id_lang']); } if ($update_images_values) { Configuration::updateValue('BLOCKBANNER_IMG', $values['BLOCKBANNER_IMG']); } Configuration::updateValue('BLOCKBANNER_LINK', $values['BLOCKBANNER_LINK']); Configuration::updateValue('BLOCKBANNER_DESC', $values['BLOCKBANNER_DESC']); $this->_clearCache('blockbanner.tpl'); return $this->displayConfirmation($this->l('The settings have been updated.')); } return ''; }
protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null) { if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) { // Delete old image if (Validate::isLoadedObject($object = $this->loadObject())) { $object->deleteImage(); } else { return false; } // Check image validity $max_size = isset($this->maxImageSize) ? $this->maxImageSize : 0; if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size))) { $this->_errors[] = $error; } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$name]['tmp_name'], $tmpName)) { return false; } else { $_FILES[$name]['tmp_name'] = $tmpName; // Copy new image if (!ImageManager::resize($tmpName, _PS_IMG_DIR_ . $dir . $id . '.' . $this->imageType, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) { $this->_errors[] = Tools::displayError('An error occurred while uploading image.'); } if (count($this->_errors)) { return false; } if ($this->afterImageUpload()) { unlink($tmpName); return true; } return false; } } return true; }
public function processImageCategory($FILES, $id) { if (isset($FILES['category_image']) && isset($FILES['category_image']['tmp_name']) && !empty($FILES['category_image']['tmp_name'])) { if ($error = ImageManager::validateUpload($FILES['category_image'], 4000000)) { return $this->displayError($this->l('Invalid image')); } else { $ext = substr($FILES['category_image']['name'], strrpos($FILES['category_image']['name'], '.') + 1); $file_name = $id . '.' . $ext; $path = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $file_name; if (!move_uploaded_file($FILES['category_image']['tmp_name'], $path)) { return $this->displayError($this->l('An error occurred while attempting to upload the file.')); } else { if (Configuration::hasContext('category_image', null, Shop::getContext()) && Configuration::get('BLOCKBANNER_IMG') != $file_name) { @unlink(dirname(__FILE__) . '/' . Configuration::get('BLOCKBANNER_IMG')); } $images_types = BlogImageType::GetImageAllType('category'); foreach ($images_types as $image_type) { $dir = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg'; if (file_exists($dir)) { unlink($dir); } } foreach ($images_types as $image_type) { ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/category/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']); } } } } }
/** * Write the posted image on disk * * @param string $sreceptionPath * @param int $destWidth * @param int $destHeight * @param array $imageTypes * @param string $parentPath * @return boolean */ protected function writePostedImageOnDisk($receptionPath, $destWidth = null, $destHeight = null, $imageTypes = null, $parentPath = null) { if ($this->wsObject->method == 'PUT') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $this->imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400)); } // Get mime content type $mime_type = false; if (Tools::isCallable('finfo_open')) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; $finfo = finfo_open($const); $mime_type = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); } elseif (Tools::isCallable('mime_content_type')) { $mime_type = mime_content_type($file['tmp_name']); } elseif (Tools::isCallable('exec')) { $mime_type = trim(exec('file -b --mime-type ' . escapeshellarg($file['tmp_name']))); } if (empty($mime_type) || $mime_type == 'regular file') { $mime_type = $file['type']; } if (($pos = strpos($mime_type, ';')) !== false) { $mime_type = substr($mime_type, 0, $pos); } // Check mime content type if (!$mime_type || !in_array($mime_type, $this->acceptedImgMimeTypes)) { throw new WebserviceException('This type of image format not recognized, allowed formats are: ' . implode('", "', $this->acceptedImgMimeTypes), array(73, 400)); } elseif ($file['error']) { throw new WebserviceException('Error while uploading image. Please change your server\'s settings', array(74, 400)); } // Try to copy image file to a temporary file if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) { throw new WebserviceException('Error while copying image to the temporary directory', array(75, 400)); } else { $result = $this->writeImageOnDisk($tmpName, $receptionPath, $destWidth, $destHeight, $imageTypes, $parentPath); } @unlink($tmpName); return $result; } else { throw new WebserviceException('Please set an "image" parameter with image data for value', array(76, 400)); } } elseif ($this->wsObject->method == 'POST') { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $file = $_FILES['image']; if ($file['size'] > $this->imgMaxUploadSize) { throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', $this->imgMaxUploadSize / 1000), array(72, 400)); } require_once _PS_ROOT_DIR_ . '/images.inc.php'; if ($error = ImageManager::validateUpload($file)) { throw new WebserviceException('Image upload error : ' . $error, array(76, 400)); } if (isset($file['tmp_name']) && $file['tmp_name'] != null) { if ($this->imageType == 'products') { $product = new Product((int) $this->wsObject->urlSegment[2]); if (!Validate::isLoadedObject($product)) { throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400)); } $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; if (!Image::getCover((int) $product->id)) { $image->cover = 1; } else { $image->cover = 0; } if (!$image->add()) { throw new WebserviceException('Error while creating image', array(76, 400)); } if (!Validate::isLoadedObject($product)) { throw new WebserviceException('Product ' . (int) $this->wsObject->urlSegment[2] . ' doesn\'t exists', array(76, 400)); } } // copy image if (!isset($file['tmp_name'])) { return false; } if ($error = ImageManager::validateUpload($file, $this->imgMaxUploadSize)) { throw new WebserviceException('Bad image : ' . $error, array(76, 400)); } if ($this->imageType == 'products') { $image = new Image($image->id); if (!(Configuration::get('PS_OLD_FILESYSTEM') && file_exists(_PS_PROD_IMG_DIR_ . $product->id . '-' . $image->id . '.jpg'))) { $image->createImgFolder(); } if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) { throw new WebserviceException('An error occurred during the image upload', array(76, 400)); } elseif (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format)) { throw new WebserviceException('An error occurred while copying image', array(76, 400)); } else { $imagesTypes = ImageType::getImagesTypes('products'); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($tmpName, _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) { $this->_errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']); } } } @unlink($tmpName); $this->imgToDisplay = _PS_PROD_IMG_DIR_ . $image->getExistingImgPath() . '.' . $image->image_format; $this->objOutput->setFieldsToDisplay('full'); $this->output = $this->objOutput->renderEntity($image, 1); $image_content = array('sqlId' => 'content', 'value' => base64_encode(file_get_contents($this->imgToDisplay)), 'encode' => 'base64'); $this->output .= $this->objOutput->objectRender->renderField($image_content); } elseif (in_array($this->imageType, array('categories', 'manufacturers', 'suppliers', 'stores'))) { if (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($file['tmp_name'], $tmpName)) { throw new WebserviceException('An error occurred during the image upload', array(76, 400)); } elseif (!ImageManager::resize($tmpName, $receptionPath)) { throw new WebserviceException('An error occurred while copying image', array(76, 400)); } $imagesTypes = ImageType::getImagesTypes($this->imageType); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($tmpName, $parentPath . $this->wsObject->urlSegment[2] . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height'])) { $this->_errors[] = Tools::displayError('An error occurred while copying image:') . ' ' . stripslashes($imageType['name']); } } @unlink(_PS_TMP_IMG_DIR_ . $tmpName); $this->imgToDisplay = $receptionPath; } return true; } } } else { throw new WebserviceException('Method ' . $this->wsObject->method . ' is not allowed for an image resource', array(77, 405)); } }
public function postProcess() { $errors = ''; $id_shop = (int) $this->context->shop->id; // Delete logo image if (Tools::isSubmit('deleteImage')) { if (!file_exists(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg')) { $errors .= $this->displayError($this->l('This action cannot be made.')); } else { unlink(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 1); $this->_clearCache('editorial.tpl'); Tools::redirectAdmin('index.php?tab=AdminModules&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id)); } $this->_html .= $errors; } if (Tools::isSubmit('submitUpdateEditorial')) { $id_shop = (int) $this->context->shop->id; $editorial = EditorialClass::getByIdShop($id_shop); $editorial->copyFromPost(); $editorial->update(); /* upload the image */ if (isset($_FILES['body_homepage_logo']) && isset($_FILES['body_homepage_logo']['tmp_name']) && !empty($_FILES['body_homepage_logo']['tmp_name'])) { Configuration::set('PS_IMAGE_GENERATION_METHOD', 1); if (file_exists(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg')) { unlink(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg'); } if ($error = ImageManager::validateUpload($_FILES['body_homepage_logo'])) { $errors .= $error; } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmpName)) { return false; } elseif (!ImageManager::resize($tmpName, dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg')) { $errors .= $this->displayError($this->l('An error occurred while attempting to upload the image.')); } if (isset($tmpName)) { unlink($tmpName); } } $this->_html .= $errors == '' ? $this->displayConfirmation($this->l('Settings updated successfully.')) : $errors; if (file_exists(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg')) { list($width, $height, $type, $attr) = getimagesize(dirname(__FILE__) . '/homepage_logo_' . (int) $id_shop . '.jpg'); Configuration::updateValue('EDITORIAL_IMAGE_WIDTH', (int) round($width)); Configuration::updateValue('EDITORIAL_IMAGE_HEIGHT', (int) round($height)); Configuration::updateValue('EDITORIAL_IMAGE_DISABLE', 0); } $this->_clearCache('editorial.tpl'); } }
protected function uploadImage($image, $image_w = '', $image_h = '') { $res = false; if (is_array($image) && ImageManager::validateUpload($image, $this->max_image_size) === false && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name)) { $salt = sha1(microtime()); $pathinfo = pathinfo($image['name']); $img_name = $salt . '_' . Tools::str2url($pathinfo['filename']) . '.' . $pathinfo['extension']; if (ImageManager::resize($tmp_name, dirname(__FILE__) . '/img/' . $img_name, $image_w, $image_h)) { $res = true; } } if (!$res) { $this->context->smarty->assign('error', $this->l('An error occurred during the image upload.')); return false; } return $img_name; }
/** * Generic function which allows logo upload * * @param $field_name * @param $logo_prefix * @return bool */ protected function updateLogo($field_name, $logo_prefix) { $id_shop = Context::getContext()->shop->id; if (isset($_FILES[$field_name]['tmp_name']) && $_FILES[$field_name]['tmp_name']) { if ($error = ImageManager::validateUpload($_FILES[$field_name], 300000)) { $this->errors[] = $error; } $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if (!$tmp_name || !move_uploaded_file($_FILES[$field_name]['tmp_name'], $tmp_name)) { return false; } $ext = $field_name == 'PS_STORES_ICON' ? '.gif' : '.jpg'; $logo_name = $logo_prefix . '-' . (int) $id_shop . $ext; if (Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL || $id_shop == 0) { $logo_name = $logo_prefix . $ext; } if ($field_name == 'PS_STORES_ICON') { if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name, null, null, 'gif', true)) { $this->errors[] = Tools::displayError('An error occurred during logo copy.'); } } else { if (!@ImageManager::resize($tmp_name, _PS_IMG_DIR_ . $logo_name)) { $this->errors[] = Tools::displayError('An error occurred during logo copy.'); } } Configuration::updateValue($field_name, $logo_name); $this->fields_options['appearance']['fields'][$field_name]['thumb'] = _PS_IMG_ . $logo_name . '?date=' . time(); unlink($tmp_name); } }
protected function pictureUpload() { if (!($field_ids = $this->product->getCustomizationFieldIds())) { return false; } $authorized_file_fields = array(); foreach ($field_ids as $field_id) { if ($field_id['type'] == Product::CUSTOMIZE_FILE) { $authorized_file_fields[(int) $field_id['id_customization_field']] = 'file' . (int) $field_id['id_customization_field']; } } $indexes = array_flip($authorized_file_fields); foreach ($_FILES as $field_name => $file) { if (in_array($field_name, $authorized_file_fields) && isset($file['tmp_name']) && !empty($file['tmp_name'])) { $file_name = md5(uniqid(rand(), true)); if ($error = ImageManager::validateUpload($file, (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) { $this->errors[] = $error; } $product_picture_width = (int) Configuration::get('PS_PRODUCT_PICTURE_WIDTH'); $product_picture_height = (int) Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'); $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); if ($error || (!$tmp_name || !move_uploaded_file($file['tmp_name'], $tmp_name))) { return false; } /* Original file */ if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name)) { $this->errors[] = Tools::displayError('An error occurred during the image upload.'); } elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_ . $file_name . '_small', $product_picture_width, $product_picture_height)) { $this->errors[] = Tools::displayError('An error occurred during the image upload.'); } elseif (!chmod(_PS_UPLOAD_DIR_ . $file_name, 0777) || !chmod(_PS_UPLOAD_DIR_ . $file_name . '_small', 0777)) { $this->errors[] = Tools::displayError('An error occurred during the image upload.'); } else { $this->context->cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name); } unlink($tmp_name); } } return true; }
protected function _postProcess() { $errors = array(); $shop_context = Shop::getContext(); /* Processes Slider */ if (Tools::isSubmit('submitSlider')) { $shop_groups_list = array(); $shops = Shop::getContextListShopID(); foreach ($shops as $shop_id) { $shop_group_id = (int) Shop::getGroupFromShop($shop_id, true); if (!in_array($shop_group_id, $shop_groups_list)) { $shop_groups_list[] = $shop_group_id; } $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id, $shop_id); $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id, $shop_id); } /* Update global shop context if needed*/ switch ($shop_context) { case Shop::CONTEXT_ALL: $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH')); $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED')); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE')); $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP')); if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id); } } break; case Shop::CONTEXT_GROUP: if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id); $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id); } } break; } $this->clearCache(); if (!$res) { $errors[] = $this->displayError($this->l('The configuration could not be updated.')); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) { $slide = new HomeSlide((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $res = $slide->update(); $this->clearCache(); $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')); } elseif (Tools::isSubmit('submitSlide')) { /* Sets ID if needed */ if (Tools::getValue('id_slide')) { $slide = new HomeSlide((int) Tools::getValue('id_slide')); if (!Validate::isLoadedObject($slide)) { $this->_html .= $this->displayError($this->l('Invalid slide ID')); return false; } } else { $slide = new HomeSlide(); } /* Sets position */ $slide->position = (int) Tools::getValue('position'); /* Sets active */ $slide->active = (int) Tools::getValue('active_slide'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']); $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']); $slide->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']); $slide->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']); /* Uploads image and sets slide */ $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1)); $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']); if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = sha1(microtime()); if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) { $errors[] = $error; } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/images/' . $salt . '_' . $_FILES['image_' . $language['id_lang']]['name'], null, null, $type)) { $errors[] = $this->displayError($this->l('An error occurred during the image upload process.')); } if (isset($temp_name)) { @unlink($temp_name); } $slide->image[$language['id_lang']] = $salt . '_' . $_FILES['image_' . $language['id_lang']]['name']; } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') { $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']); } } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_slide')) { if (!$slide->add()) { $errors[] = $this->displayError($this->l('The slide could not be added.')); } } elseif (!$slide->update()) { $errors[] = $this->displayError($this->l('The slide could not be updated.')); } $this->clearCache(); } } elseif (Tools::isSubmit('delete_id_slide')) { $slide = new HomeSlide((int) Tools::getValue('delete_id_slide')); $res = $slide->delete(); $this->clearCache(); if (!$res) { $this->_html .= $this->displayError('Could not delete.'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } elseif (Tools::isSubmit('submitSlide')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } }
private function _postProcess() { $errors = array(); /* Processes Slider */ if (Tools::isSubmit('submitSlider')) { $res = Configuration::updateValue('CATESLIDER_WIDTH', (int) Tools::getValue('slide_width')); $res &= Configuration::updateValue('CATESLIDER_HEIGHT', (int) Tools::getValue('slide_height')); $res &= Configuration::updateValue('CATESLIDER_SPEED', (int) Tools::getValue('slide_speed')); $res &= Configuration::updateValue('CATESLIDER_PAUSE', (int) Tools::getValue('slide_pause')); $res &= Configuration::updateValue('CATESLIDER_LOOP', (int) Tools::getValue('slide_loop')); $this->clearCache(); if (!$res) { $errors[] = $this->displayError($this->l('The configuration could not be updated.')); } $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) { $slide = new CategorySlide((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $res = $slide->update(); $this->clearCache(); $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')); } elseif (Tools::isSubmit('submitSlide')) { /* Sets ID if needed */ if (Tools::getValue('id_slide')) { $slide = new CategorySlide((int) Tools::getValue('id_slide')); if (!Validate::isLoadedObject($slide)) { $this->_html .= $this->displayError($this->l('Invalid id_slide')); return; } } else { $slide = new CategorySlide(); } /* Sets position */ $slide->position = (int) Tools::getValue('position'); /* Sets active */ $slide->active = (int) Tools::getValue('active_slide'); $slide->id_category = (int) Tools::getValue('id_category'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']); $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']); $slide->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']); $slide->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']); /* Uploads image and sets slide */ $type = strtolower(substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1)); $imagesize = array(); $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']); if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = sha1(microtime()); if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) { $errors[] = $error; } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/images/' . Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type, null, null, $type)) { $errors[] = $this->displayError($this->l('An error occurred during the image upload process.')); } if (isset($temp_name)) { @unlink($temp_name); } $slide->image[$language['id_lang']] = Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type; } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') { $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']); } } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_slide')) { if (!$slide->add()) { $errors[] = $this->displayError($this->l('The slide could not be added.')); } } elseif (!$slide->update()) { $errors[] = $this->displayError($this->l('The slide could not be updated.')); } $this->clearCache(); } } elseif (Tools::isSubmit('delete_id_slide')) { $slide = new CategorySlide((int) Tools::getValue('delete_id_slide')); $res = $slide->delete(); $this->clearCache(); if (!$res) { $this->_html .= $this->displayError('Could not delete'); } else { $this->_html .= $this->displayConfirmation($this->l('Slide deleted')); } } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) { $this->_html .= $this->displayConfirmation($this->l('Slide updated')); } elseif (Tools::isSubmit('submitSlide')) { $this->_html .= $this->displayConfirmation($this->l('Slide added')); } }
public function postProcess() { if (Tools::isSubmit('submitDeleteImgConf')) { $this->_deleteCurrentImg(); } $errors = ''; if (Tools::isSubmit('submitAdvConf')) { if (isset($_FILES['adv_img']) && isset($_FILES['adv_img']['tmp_name']) && !empty($_FILES['adv_img']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['adv_img'], Tools::convertBytes(ini_get('upload_max_filesize')))) { $errors .= $error; } else { Configuration::updateValue('BLOCKADVERT_IMG_EXT', substr($_FILES['adv_img']['name'], strrpos($_FILES['adv_img']['name'], '.') + 1)); // Set the image name with a name contextual to the shop context $this->adv_imgname = 'advertising'; if (Shop::getContext() == Shop::CONTEXT_GROUP) { $this->adv_imgname = 'advertising-g' . (int) $this->context->shop->getContextShopGroupID(); } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) { $this->adv_imgname = 'advertising-s' . (int) $this->context->shop->getContextShopID(); } // Copy the image in the module directory with its new name if (!move_uploaded_file($_FILES['adv_img']['tmp_name'], _PS_MODULE_DIR_ . $this->name . '/img/' . $this->adv_imgname . '.' . Configuration::get('BLOCKADVERT_IMG_EXT'))) { $errors .= $this->l('File upload error.'); } } } // If the link is not set, then delete it in order to use the next default value (either the global value or the group value) if ($link = Tools::getValue('adv_link')) { Configuration::updateValue('BLOCKADVERT_LINK', $link); } elseif (Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP) { Configuration::deleteFromContext('BLOCKADVERT_LINK'); } // If the title is not set, then delete it in order to use the next default value (either the global value or the group value) if ($title = Tools::getValue('adv_title')) { Configuration::updateValue('BLOCKADVERT_TITLE', $title); } elseif (Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP) { Configuration::deleteFromContext('BLOCKADVERT_TITLE'); } // Reset the module properties $this->initialize(); $this->_clearCache('blockadvertising.tpl'); if (!$errors) { Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&conf=6'); } echo $this->displayError($errors); } }