/** * renderForm contains all necessary initialization needed for all tabs * * @return void */ public function renderList() { //this code for select or upload IMG $tpl = $this->createTemplate('imagemanager.tpl'); $sortBy = Tools::getValue('sortBy'); $reloadBack = Tools::getValue('reloadBack'); if ($reloadBack) { $images = $this->getImageList($sortBy); $tpl->assign(array('images' => $images, 'reloadBack' => $reloadBack)); die(Tools::jsonEncode($tpl->fetch())); } $reloadSliderImage = Tools::getValue('reloadSliderImage'); if ($reloadSliderImage) { $images = $this->getImageList($sortBy); $tpl->assign(array('images' => $images, 'reloadSliderImage' => $reloadSliderImage)); die(Tools::jsonEncode($tpl->fetch())); } $images = $this->getImageList($sortBy); $image_uploader = new HelperImageUploader('file'); $image_uploader->setSavePath($this->img_path); $url = Context::getContext()->link->getAdminLink('AdminLeomanagewidgetsImages') . '&ajax=1&action=addSliderImage' . $this->paramLink; $image_uploader->setMultiple(true)->setUseAjax(true)->setUrl($url); $tpl->assign(array('countImages' => count($images), 'images' => $images, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'image_uploader' => $image_uploader->render(), 'imgManUrl' => Context::getContext()->link->getAdminLink('AdminLeomanagewidgetsImages') . $this->paramLink, 'token' => $this->token)); return $tpl->fetch(); }
public function ajaxProcessuploadThumbnailImages() { $category = new Category((int) Tools::getValue('id_category')); if (isset($_FILES['thumbnail'])) { //Get total of image already present in directory $files = scandir(_PS_CAT_IMG_DIR_); $assigned_keys = array(); $allowed_keys = array(0, 1, 2); foreach ($files as $file) { $matches = array(); if (preg_match('/^' . $category->id . '-([0-9])?_thumb.jpg/i', $file, $matches) === 1) { $assigned_keys[] = (int) $matches[1]; } } $available_keys = array_diff($allowed_keys, $assigned_keys); $helper = new HelperImageUploader('thumbnail'); $files = $helper->process(); $total_errors = array(); if (count($available_keys) < count($files)) { $total_errors['name'] = sprintf(Tools::displayError('An error occurred while uploading the image :')); $total_errors['error'] = sprintf(Tools::displayError('You cannot upload more files')); die(Tools::jsonEncode(array('thumbnail' => array($total_errors)))); } foreach ($files as $key => &$file) { $id = array_shift($available_keys); $errors = array(); // Evaluate the memory required to resize the image: if it's too much, you can't resize it. if (isset($file['save_path']) && !ImageManager::checkImageMemoryLimit($file['save_path'])) { $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 (!isset($file['save_path']) || empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ . (int) Tools::getValue('id_category') . '-' . $id . '_thumb.jpg')) { $errors[] = Tools::displayError('An error occurred while uploading the image.'); } if (count($errors)) { $total_errors = array_merge($total_errors, $errors); } if (isset($file['save_path']) && is_file($file['save_path'])) { unlink($file['save_path']); } //Necesary to prevent hacking if (isset($file['save_path'])) { unset($file['save_path']); } if (isset($file['tmp_name'])) { unset($file['tmp_name']); } //Add image preview and delete url $file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $id . '_thumb.jpg', $this->context->controller->table . '_' . (int) $category->id . '-' . $id . '_thumb.jpg', 100, 'jpg', true, true); $file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&deleteThumb=' . $id . '&id_category=' . (int) $category->id . '&updatecategory'; } if (count($total_errors)) { $this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors); } else { Tools::clearSmartyCache(); } die(Tools::jsonEncode(array('thumbnail' => $files))); } }
/** * renderForm contains all necessary initialization needed for all tabs * * @return void */ public function renderList() { $tpl = $this->createTemplate('imagesmanagement.tpl'); $sort_by = Tools::getValue('sortBy'); $reload_slider_image = Tools::getValue('reloadSliderImage'); $images = $this->getImageList($sort_by); $tpl->assign(array('images' => $images, 'reloadSliderImage' => $reload_slider_image)); if ($reload_slider_image) { die(Tools::jsonEncode($tpl->fetch())); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setSavePath($this->img_path); $image_uploader->setMultiple(true)->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminPspagebuilderImage') . '&ajax=1&action=addSliderImage'); $tpl->assign(array('countImages' => count($images), 'images' => $images, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'image_uploader' => $image_uploader->render(), 'imgManUrl' => Context::getContext()->link->getAdminLink('AdminPspagebuilderImage'), 'token' => $this->token, 'imgUploadDir' => $this->img_path, 'add_cls' => Tools::getValue('modal') ? 'modalshowed' : '')); return $tpl->fetch(); }
/** * renderForm contains all necessary initialization needed for all tabs * * @return void */ public function renderList() { //this code for typo $typo = Tools::getValue('typo'); if ($typo) { //check css file in theme if (file_exists(_PS_THEME_DIR_ . 'css/modules/leosliderlayer/css/typo.css')) { $typoDir = _THEME_DIR_ . 'css/' . str_replace('//', '/', 'modules/leosliderlayer') . '/css/typo.css'; } else { $typoDir = __PS_BASE_URI__ . str_replace('//', '/', 'modules/leosliderlayer') . '/css/typo.css'; } $this->addCss($typoDir, 'all'); $this->addJS(__PS_BASE_URI__ . 'modules/leosliderlayer/assets/admin/jquery-ui-1.10.3.custom.min.js'); $content = Tools::file_get_contents($this->context->link->getMediaLink($typoDir)); preg_match_all('#\\.tp-caption\\.(\\w+)\\s*{\\s*#', $content, $matches); if (isset($matches[1])) { $captions = $matches[1]; } $tpl = $this->createTemplate('typo.tpl'); $tpl->assign(array('typoDir' => $typoDir, 'captions' => $captions, 'field' => Tools::getValue('field'))); return $tpl->fetch(); } //this code for select or upload IMG $tpl = $this->createTemplate('imagemanager.tpl'); $sortBy = Tools::getValue('sortBy'); $reloadSliderImage = Tools::getValue('reloadSliderImage'); $images = $this->getImageList($sortBy); $tpl->assign(array('images' => $images, 'reloadSliderImage' => $reloadSliderImage)); if ($reloadSliderImage) { die(Tools::jsonEncode($tpl->fetch())); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setSavePath($this->img_path); $url = Context::getContext()->link->getAdminLink('AdminLeoSliderLayer') . '&ajax=1&action=addSliderImage'; $image_uploader->setMultiple(true)->setUseAjax(true)->setUrl($url); $tpl->assign(array('countImages' => count($images), 'images' => $images, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'image_uploader' => $image_uploader->render(), 'imgManUrl' => Context::getContext()->link->getAdminLink('AdminLeoSliderLayer'), 'token' => $this->token, 'imgUploadDir' => $this->img_path)); return $tpl->fetch(); }
public function hookDisplayBackOfficeCategory($params) { $category = new Category((int) Tools::getValue('id_category')); $files = array(); if ($category->level_depth < 1) { return; } for ($i = 0; $i < 3; $i++) { if (file_exists(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $i . '_thumb.jpg')) { $files[$i]['type'] = HelperImageUploader::TYPE_IMAGE; $files[$i]['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $i . '_thumb.jpg', $this->context->controller->table . '_' . (int) $category->id . '-' . $i . '_thumb.jpg', 100, 'jpg', true, true); $files[$i]['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&deleteThumb=' . $i . '&id_category=' . (int) $category->id; } } $helper = new HelperImageUploader(); $helper->setMultiple(true)->setUseAjax(true)->setName('thumbnail')->setFiles($files)->setMaxFiles(3)->setUrl(Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&ajax=1&id_category=' . $category->id . '&action=uploadThumbnailImages'); $this->smarty->assign('helper', $helper->render()); return $this->display(__FILE__, 'views/blockcategories_admin.tpl'); }
public function ajaxProcessaddGallaryImage() { self::$currentIndex = 'index.php?tab=AdminSmartBlog&token=' . Tools::getAdminTokenLite('AdminSmartBlog'); $smart_blog_post = new SmartBlogPost((int) Tools::getValue('id_smart_blog_post')); $legends = Tools::getValue('legend'); if (!is_array($legends)) { $legends = (array) $legends; } if (!Validate::isLoadedObject($smart_blog_post)) { $files = array(); $files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.'); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size); $files = $image_uploader->process(); foreach ($files as &$file) { $image = new SmartBlogGallaryImage(); $image->id_smart_blog_post = (int) $smart_blog_post->id; $image->position = SmartBlogGallaryImage::getHighestPosition($smart_blog_post->id) + 1; foreach ($legends as $key => $legend) { if (!empty($legend)) { $image->legend[(int) $key] = $legend; } } if (($validate = $image->validateFieldsLang(false, true)) !== true) { $file['error'] = Tools::displayError($validate); } if (isset($file['error']) && (!is_numeric($file['error']) || $file['error'] != 0)) { continue; } if (!$image->add()) { $file['error'] = Tools::displayError('Error while creating additional image'); } else { if (!($new_path = $image->getPathForCreation())) { $file['error'] = Tools::displayError('An error occurred during new folder creation'); continue; } $error = 0; if (!ImageManager::resize($file['save_path'], $new_path . '.' . $image->image_format, null, null, 'jpg', false, $error)) { switch ($error) { case ImageManager::ERROR_FILE_NOT_EXIST: $file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.'); break; case ImageManager::ERROR_FILE_WIDTH: $file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.'); break; case ImageManager::ERROR_MEMORY_LIMIT: $file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.'); break; default: $file['error'] = Tools::displayError('An error occurred while copying image.'); break; } continue; } else { $imagesTypes = BlogImageType::GetImageAllType('post'); foreach ($imagesTypes as $imageType) { if (!ImageManager::resize($file['save_path'], $new_path . '-' . Tools::stripslashes($imageType['type_name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) { $file['error'] = Tools::displayError('An error occurred while copying image:') . ' ' . Tools::stripslashes($imageType['name']); continue; } } } unlink($file['save_path']); //Necesary to prevent hacking unset($file['save_path']); Hook::exec('actionWatermark', array('id_smart_blog_post_mage' => $image->id, 'id_smart_blog_post' => $smart_blog_post->id)); if (!$image->update()) { $file['error'] = Tools::displayError('Error while updating status'); continue; } $file['status'] = 'ok'; $file['id'] = $image->id; $file['position'] = $image->position; $file['cover'] = $image->cover; $file['legend'] = $image->legend; $file['path'] = $image->getExistingImgPath(); $file['shops'] = array("{$this->context->shop->id}" => true); @unlink(_PS_TMP_IMG_DIR_ . 'smart_blog_post_' . (int) $smart_blog_post->id . '.jpg'); @unlink(_PS_TMP_IMG_DIR_ . 'smart_blog_post__mini_' . (int) $smart_blog_post->id . '_' . $this->context->shop->id . '.jpg'); } } die(Tools::jsonEncode(array($image_uploader->getName() => $files))); }
public function initFormImages($obj) { $data = $this->createTemplate($this->tpl_form); if ((bool) $obj->id) { if ($this->product_exists_in_shop) { $data->assign('product', $this->loadObject()); $shops = false; if (Shop::isFeatureActive()) { $shops = Shop::getShops(); } if ($shops) { foreach ($shops as $key => $shop) { if (!$obj->isAssociatedToShop($shop['id_shop'])) { unset($shops[$key]); } } } $data->assign('shops', $shops); $count_images = Db::getInstance()->getValue(' SELECT COUNT(id_product) FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $obj->id); $images = Image::getImages($this->context->language->id, $obj->id); foreach ($images as $k => $image) { $images[$k] = new Image($image['id_image']); } if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) { $current_shop_id = (int) $this->context->shop->id; } else { $current_shop_id = 0; } $languages = Language::getLanguages(true); $image_uploader = new HelperImageUploader('file'); $image_uploader->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminProducts') . '&ajax=1&id_product=' . (int) $obj->id . '&action=addProductImage'); $data->assign(array('countImages' => $count_images, 'id_product' => (int) Tools::getValue('id_product'), 'id_category_default' => (int) $this->_category->id, 'images' => $images, 'iso_lang' => $languages[0]['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'up_filename' => (string) Tools::getValue('virtual_product_filename_attribute'), 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'image_uploader' => $image_uploader->render())); $type = ImageType::getByNameNType('%', 'products', 'height'); if (isset($type['name'])) { $data->assign('imageType', $type['name']); } else { $data->assign('imageType', 'small_default'); } } else { $this->displayWarning($this->l('You must save the product in this shop before adding images.')); } } else { $this->displayWarning($this->l('You must save this product before adding images.')); } $this->tpl_form_vars['custom_form'] = $data->fetch(); }
public function renderForm() { $this->post_format_fields = smartblog::$post_meta_fields; if (!($obj = $this->loadObject(true))) { return; } $shops = false; if (Shop::isFeatureActive()) { $shops = Shop::getShops(); } if ($shops) { foreach ($shops as $key => $shop) { if (!$obj->isAssociatedToShop($shop['id_shop'])) { unset($shops[$key]); } } } $languages = Language::getLanguages(false); //Added From Old /* * ************* featured image ****************** */ $featured_image = _MODULE_SMARTBLOG_DIR_ . $obj->id . '.jpg'; $image_url = ImageManager::thumbnail($featured_image, $this->table . '_' . pSQL(Tools::getvalue('id_smart_blog_post')) . '.jpg', 200, 'jpg', true, true); $image_size = file_exists($featured_image) ? filesize($featured_image) / 1000 : false; /* * ************* featured image ****************** */ // image gallary $id_smart_blog_post = (int) Tools::getValue('id_smart_blog_post'); $images = SmartBlogGallaryImage::getImages($this->context->language->id, $id_smart_blog_post); foreach ($images as $k => $image) { $images[$k] = new SmartBlogGallaryImage($image['id_smart_blog_gallary_images']); } //start sdsimage type $image_uploader = new HelperImageUploader('file'); $image_uploader->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminSmartBlogAjax') . '&ajax=1&id_smart_blog_post=' . (int) Tools::getvalue('id_smart_blog_post') . '&action=addGallaryImage'); // test code $root = BlogCategory::getRootCategory(); $default_category = $root['id_smart_blog_category']; if (!Tools::isSubmit('id_smart_blog_post')) { $selected_cat = BlogCategory::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { if (Tools::isSubmit('categoryBox')) { $selected_cat = BlogCategory::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language); } else { $selected_cat = BlogCategory::getPostCategoriesFull((int) Tools::getValue('id_smart_blog_post'), $this->default_form_language); } } $categories = array(); foreach ($selected_cat as $key => $category) { $categories[] = $key; } $tree = new SmartBlogHelperTreeCategories('smartblog-associated-categories-tree', 'Associated categories'); $tree->setTemplate('tree_associated_categories.tpl')->setHeaderTemplate('tree_associated_header.tpl')->setRootCategory((int) $root['id_category'])->setUseCheckBox(true)->setUseSearch(false)->setSelectedCategories($categories); // end test code $temp_employees = Employee::getEmployees(); $employees = array(); foreach ($temp_employees as $employee) { $employee['fullname'] = $employee['firstname'] . ' ' . $employee['lastname']; $employee['id_select'] = $employee['id_employee']; $employees[] = $employee; } $this->fields_form = array('legend' => array('title' => $this->l('Blog Post')), 'input' => array(array('type' => 'text', 'label' => $this->l('Blog Title'), 'name' => 'meta_title', 'id' => 'name', 'class' => 'copyMeta2friendlyURL', 'size' => 60, 'required' => true, 'desc' => $this->l('Enter Your Blog Post Title'), 'lang' => true), array('type' => 'select', 'label' => $this->l('Author'), 'name' => 'id_author', 'options' => array('query' => $employees, 'id' => 'id_select', 'name' => 'fullname')), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'content', 'lang' => true, 'rows' => 10, 'cols' => 62, 'class' => 'rte', 'autoload_rte' => true, 'desc' => $this->l('Enter Your Post Description')), array('type' => 'file', 'label' => $this->l('Featured Image:'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . pSQL(Tools::getvalue('id_smart_blog_post')) . '&token=' . $this->token . '&deleteImage=1', 'hint' => $this->l('Upload a feature image from your computer.')), array('type' => 'html', 'label' => $this->l('Blog Categories'), 'name' => 'id_category_big', 'required' => true, 'html_content' => $tree->render(), 'desc' => $this->l('Select Your Parent Category')), array('type' => 'text', 'label' => $this->l('Meta Keyword'), 'name' => 'meta_keyword', 'lang' => true, 'size' => 60, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Keyword. Separated by comma(,)')), array('type' => 'textarea', 'label' => $this->l('Short Description'), 'name' => 'short_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => true, 'desc' => $this->l('Enter Your Post Short Description')), array('type' => 'textarea', 'label' => $this->l('Meta Description'), 'name' => 'meta_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Description')), array('type' => 'text', 'label' => $this->l('Link Rewrite'), 'name' => 'link_rewrite', 'size' => 60, 'lang' => true, 'required' => false, 'desc' => $this->l('Enetr Your Post Slug. Use In SEO Friendly URL')), array('type' => 'tags', 'label' => $this->l('Tag'), 'name' => 'tags', 'size' => 60, 'lang' => true, 'required' => false, 'hint' => array($this->l('To add "tags" click in the field, write something, and then press "Enter."'), $this->l('Invalid characters:') . ' <>;=#{}')), array('type' => 'switch', 'label' => $this->l('Comment Status'), 'name' => 'comment_status', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('You Can Enable or Disable Your Comments')), array('label' => $this->l('Published Date'), 'name' => 'created', 'title' => $this->l('Published date'), 'type' => 'datetime'), array('type' => 'associations', 'label' => $this->l('Related Product(s)'), 'name' => 'associations', 'size' => 60, 'lang' => true, 'required' => false), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'label' => $this->l('Is Featured?'), 'name' => 'is_featured', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'gallary' => array('images' => array('count' => count($images), 'max_image_size' => $this->max_image_size / 1024 / 1024, 'table' => $this->table, 'images' => $images, 'id_smart_blog_post' => (int) Tools::getValue('id_smart_blog_post'), 'object' => $this->object, 'image_uploader' => $image_uploader->render()))); $this->fields_form['input'][] = array('type' => 'radio', 'label' => $this->l('Post Format'), 'name' => 'post_type', 'required' => true, 'values' => array(array('id' => 'post_type_default', 'value' => '', 'label' => '<i class="icon-home"></i> ' . $this->l('None')), array('id' => 'post_type_gallery', 'value' => 'gallery', 'label' => '<i class="icon-picture"></i> ' . $this->l('Gallery')), array('id' => 'post_type_audio', 'value' => 'audio', 'label' => '<i class="icon-music"></i> ' . $this->l('Audio')), array('id' => 'post_type_video', 'value' => 'video', 'label' => '<i class="icon-film"></i> ' . $this->l('Video')), array('id' => 'post_type_quote', 'value' => 'quote', 'label' => '<i class="icon-quote-left"></i> ' . $this->l('Quote')), array('id' => 'post_type_link', 'value' => 'link', 'label' => '<i class="icon-link"></i> ' . $this->l('Link')))); $this->fields_form['input'][] = array('type' => 'html', 'label' => $this->l('Post Format Fields'), 'name' => 'post_format_fields', 'html_content' => $this->AdminMetaFields(), 'desc' => $this->l('Set exclusive fields for the post format')); if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso'); } if (!($SmartBlogPost = $this->loadObject(true))) { return; } $this->fields_form['submit'] = array('title' => $this->l('Save')); $image = ImageManager::thumbnail(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg', $this->table . '_' . (int) $SmartBlogPost->id_smart_blog_post . '.' . $this->imageType, 350, $this->imageType, true); $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg') / 1000 : false); if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) { foreach (Language::getLanguages(false) as $lang) { $this->fields_value['tags'][(int) $lang['id_lang']] = SmartBlogPost::getProductTagsBylang((int) Tools::getvalue('id_smart_blog_post'), (int) $lang['id_lang']); } } $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); // related product using Accessories block $accessories = SmartBlogPost::getAccessoriesLight($this->context->language->id, $SmartBlogPost->id_smart_blog_post); if ($post_accessories = Tools::getValue('inputAccessories')) { $post_accessories_tab = explode('-', $post_accessories); foreach ($post_accessories_tab as $accessory_id) { if (!$this->haveThisAccessory($accessory_id, $accessories) && ($accessory = Product::getAccessoryById($accessory_id))) { $accessories[] = $accessory; } } } $this->tpl_form_vars['accessories'] = $accessories; /* image gallary */ $this->tpl_form_vars['images'] = $images; $this->tpl_form_vars['image_uploader'] = $image_uploader->render(); $this->tpl_form_vars['max_image_size'] = $this->max_image_size / 1024 / 1024; $this->tpl_form_vars['languages'] = $languages; $this->tpl_form_vars['iso_lang'] = $languages[0]['iso_code']; $this->tpl_form_vars['imageType'] = 'home-small'; $this->tpl_form_vars['id_smart_blog_post'] = (int) Tools::getValue('id_smart_blog_post'); $this->tpl_form_vars['default_language'] = (int) Configuration::get('PS_LANG_DEFAULT'); $this->tpl_form_vars['table'] = $this->table; $this->tpl_form_vars['token'] = Tools::getAdminTokenLite('AdminBlogPost'); $this->tpl_form_vars['gallary_path'] = _MODULE_DIR_ . 'smartblog/gallary/'; // $this->tpl_form_vars['token_book'] = Tools::getAdminTokenLite('AdminBook'); return parent::renderForm(); }
/** * @param Offer $obj * @throws Exception * @throws SmartyException */ public function initFormImages($obj) { $data = $this->createTemplate($this->tpl_form); if ((bool) $obj->id) { // if ($this->offer_exists_in_shop) { $data->assign('offer', $this->loadObject()); $count_images = Db::getInstance()->getValue(' SELECT COUNT(id_offer) FROM ' . _DB_PREFIX_ . 'offer_image WHERE id_offer = ' . (int) $obj->id); $images = AphOfferImage::getImages($this->context->language->id, $obj->id); foreach ($images as $k => $image) { $images[$k] = new AphOfferImage($image['id_image']); } if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) { $current_shop_id = (int) $this->context->shop->id; } else { $current_shop_id = 0; } $language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $image_uploader = new HelperImageUploader('file'); $image_uploader->setTemplateDirectory($this->tpl_dir . 'helpers/uploader/')->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminAphOffers') . '&ajax=1&id_offer=' . (int) $obj->id . '&action=addOfferImage')->setTemplate('ajax.tpl'); $data->assign(array('countImages' => $count_images, 'id_offer' => (int) Tools::getValue('id_offer'), 'images' => $images, 'iso_lang' => $language['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'image_uploader' => $image_uploader->render())); $type = ImageType::getByNameNType('%', 'products', 'height'); if (isset($type['name'])) { $data->assign('imageType', $type['name']); } else { $data->assign('imageType', ImageType::getFormatedName('small')); } // } else { // $this->displayWarning($this->l('You must save the offer in this shop before adding images.')); // } } else { $this->displayWarning($this->l('You must save this offer before adding images.')); } $this->tpl_form_vars['custom_form'] = $data->fetch(); }
/** POST TYPE - GALLERY */ public function ajaxProcessAddPostImages() { $image_dir = _SIMPLEBLOG_GALLERY_DIR_; $image_uploader = new HelperImageUploader('file'); $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg')); $files = $image_uploader->process(); foreach ($files as &$file) { $SimpleBlogPostImage = new SimpleBlogPostImage(); $SimpleBlogPostImage->id_simpleblog_post = (int) Tools::getValue('id_simpleblog_post'); $SimpleBlogPostImage->position = SimpleBlogPostImage::getNewLastPosition((int) Tools::getValue('id_simpleblog_post')); $SimpleBlogPostImage->add(); $filenameParts = explode('.', $file['name']); $destFiles = array('original' => $image_dir . $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]) . '.jpg', 'thumbnail' => $image_dir . $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]) . '-thumb.jpg', 'square' => $image_dir . $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]) . '-square.jpg', 'wide' => $image_dir . $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]) . '-wide.jpg'); if (!ImageManager::resize($file['save_path'], $destFiles['original'], null, null, 'jpg', false, $error)) { switch ($error) { case ImageManager::ERROR_FILE_NOT_EXIST: $file['error'] = Tools::displayError('An error occurred while copying image, the file does not exist anymore.'); $SimpleBlogPostImage->delete(); break; case ImageManager::ERROR_FILE_WIDTH: $file['error'] = Tools::displayError('An error occurred while copying image, the file width is 0px.'); $SimpleBlogPostImage->delete(); break; case ImageManager::ERROR_MEMORY_LIMIT: $file['error'] = Tools::displayError('An error occurred while copying image, check your memory limit.'); $SimpleBlogPostImage->delete(); break; default: $file['error'] = Tools::displayError('An error occurred while copying image.'); $SimpleBlogPostImage->delete(); break; } continue; } else { $SimpleBlogPostImage->image = $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]); $SimpleBlogPostImage->update(); $thumbX = Configuration::get('PH_BLOG_THUMB_X'); $thumbY = Configuration::get('PH_BLOG_THUMB_Y'); $thumb_wide_X = Configuration::get('PH_BLOG_THUMB_X_WIDE'); $thumb_wide_Y = Configuration::get('PH_BLOG_THUMB_Y_WIDE'); $thumbMethod = Configuration::get('PH_BLOG_THUMB_METHOD'); try { $orig = PhpThumbFactory::create($destFiles['original']); $thumb = PhpThumbFactory::create($destFiles['original']); $square = PhpThumbFactory::create($destFiles['original']); $wide = PhpThumbFactory::create($destFiles['original']); } catch (Exception $e) { echo $e; } if ($thumbMethod == '1') { $thumb->adaptiveResize($thumbX, $thumbY); $square->adaptiveResize(800, 800); $wide->adaptiveResize($thumb_wide_X, $thumb_wide_Y); } elseif ($thumbMethod == '2') { $thumb->cropFromCenter($thumbX, $thumbY); $square->cropFromCenter(800, 800); $wide->cropFromCenter($thumb_wide_X, $thumb_wide_Y); } $orig->save($destFiles['original']); $thumb->save($destFiles['thumbnail']); $square->save($destFiles['square']); $wide->save($destFiles['wide']); unlink($file['save_path']); unset($file['save_path']); $file['status'] = 'ok'; $file['name'] = $SimpleBlogPostImage->id . '-' . $SimpleBlogPostImage->id_simpleblog_post . '-' . Tools::link_rewrite($filenameParts[0]); $file['id'] = $SimpleBlogPostImage->id; $file['position'] = $SimpleBlogPostImage->position; $file['path'] = $image_dir; } } die(Tools::jsonEncode(array($image_uploader->getName() => $files))); }
/** * @param Store $obj * @throws Exception * @throws SmartyException */ public function initFormImages($obj) { if ((bool) $obj->id) { $count_images = Db::getInstance()->getValue(' SELECT COUNT(id_shop) FROM ' . _DB_PREFIX_ . 'store_image WHERE id_shop = ' . (int) $obj->id_shop); $images = AphStoreImage::getImages($this->context->language->id, $obj->id_shop); foreach ($images as $k => $image) { $images[$k] = new AphStoreImage($image['id_image']); } $language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $image_uploader = new HelperImageUploader('file'); $image_uploader->setTemplateDirectory($this->tpl_dir . 'helpers/uploader/')->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminAphStores') . '&ajax=1&id_store=' . (int) $obj->id . '&action=addStoreImage')->setTemplate('ajax.tpl'); $this->context->smarty->assign(array('iso_lang' => $language['iso_code'], 'token' => $this->token, 'table' => $this->table, 'countImages' => $count_images, 'images' => $images, 'max_image_size' => $this->max_image_size / 1024 / 1024, "image_uploader" => $image_uploader->render(), 'table' => $this->table, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'current_shop_id' => (int) $obj->id_shop, 'id_shop' => (int) $obj->id_shop, 'id_store' => (int) $obj->id)); $type = ImageType::getByNameNType('%', 'stores', 'height'); if (isset($type['name'])) { $this->context->smarty->assign('imageType', $type['name']); } else { $this->context->smarty->assign('imageType', ImageType::getFormatedName('medium')); } } }