Пример #1
0
 function resize()
 {
     $mainframe =& JFactory::getApplication();
     $jshopConfig =& JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher =& JDispatcher::getInstance();
     $filelist = glob($jshopConfig->image_product_path . '/' . 'full_*');
     foreach ($filelist as $key => $value) {
         $url = $value;
         $url_parts = pathinfo($url);
         //filenames
         $name_full = $url_parts['basename'];
         $name_image = substr($url_parts['basename'], 5);
         $name_thumb = "thumb_" . $name_image;
         //file path
         $path_image = $jshopConfig->image_product_path . '/' . $name_image;
         $path_thumb = $jshopConfig->image_product_path . '/' . $name_thumb;
         $path_full = $jshopConfig->image_product_path . '/' . $name_full;
         //resize thumb
         $product_width_image = $jshopConfig->image_product_width;
         $product_height_image = $jshopConfig->image_product_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_thumb);
             saveToLog("error.log", "Resize Product Image - Error create thumbail " . $name_thumb);
             $error = 1;
         }
         //resize image
         $product_full_width_image = $jshopConfig->image_product_full_width;
         $product_full_height_image = $jshopConfig->image_product_full_height;
         if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
             JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL . " " . $name_image);
             saveToLog("error.log", "Resize Product Image - Error create image " . $name_image);
             $error = 1;
         }
         $dispatcher->trigger('onAfterSaveProductImage', array($product_id, $name_image));
     }
     if (!JRequest::getInt("noredirect")) {
         $mainframe->redirect("index.php?option=com_jshopping&controller=resize&task=view", _JSHOP_COMPLETED);
     }
 }
Пример #2
0
 function uploadImage($post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if ($category_width_image || $category_height_image) {
                 if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveCategory - Error create thumbail");
                 }
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         }
         $category_image = $name;
         $dispatcher->trigger('onAfterSaveCategoryImage', array(&$post, &$category_image, &$path_full, &$path_thumb));
     } else {
         $category_image = '';
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     return $category_image;
 }
Пример #3
0
 function uploadImages($product, $product_id, $post)
 {
     $jshopConfig = JSFactory::getConfig();
     $dispatcher = JDispatcher::getInstance();
     for ($i = 0; $i < $jshopConfig->product_image_upload_count; $i++) {
         $upload = new UploadFile($_FILES['product_image_' . $i]);
         $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
         $upload->setDir($jshopConfig->image_product_path);
         $upload->setFileNameMd5(0);
         $upload->setFilterName(1);
         if ($upload->upload()) {
             $name_image = $upload->getName();
             $name_thumb = 'thumb_' . $name_image;
             $name_full = 'full_' . $name_image;
             @chmod($jshopConfig->image_product_path . "/" . $name_image, 0777);
             $path_image = $jshopConfig->image_product_path . "/" . $name_image;
             $path_thumb = $jshopConfig->image_product_path . "/" . $name_thumb;
             $path_full = $jshopConfig->image_product_path . "/" . $name_full;
             rename($path_image, $path_full);
             if ($jshopConfig->image_product_original_width || $jshopConfig->image_product_original_height) {
                 if (!ImageLib::resizeImageMagic($path_full, $jshopConfig->image_product_original_width, $jshopConfig->image_product_original_height, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_full, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveProduct - Error create thumbail");
                     $error = 1;
                 }
             }
             $error = 0;
             if ($post['size_im_product'] == 3) {
                 copy($path_full, $path_thumb);
                 @chmod($path_thumb, 0777);
             } else {
                 if ($post['size_im_product'] == 1) {
                     $product_width_image = $jshopConfig->image_product_width;
                     $product_height_image = $jshopConfig->image_product_height;
                 } else {
                     $product_width_image = JRequest::getInt('product_width_image');
                     $product_height_image = JRequest::getInt('product_height_image');
                 }
                 if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     saveToLog("error.log", "SaveProduct - Error create thumbail");
                     $error = 1;
                 }
                 @chmod($path_thumb, 0777);
                 unset($img);
             }
             if ($post['size_full_product'] == 3) {
                 copy($path_full, $path_image);
                 @chmod($path_image, 0777);
             } else {
                 if ($post['size_full_product'] == 1) {
                     $product_full_width_image = $jshopConfig->image_product_full_width;
                     $product_full_height_image = $jshopConfig->image_product_full_height;
                 } else {
                     $product_full_width_image = JRequest::getInt('product_full_width_image');
                     $product_full_height_image = JRequest::getInt('product_full_height_image');
                 }
                 if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                     JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                     $error = 1;
                 }
                 @chmod($path_image, 0777);
                 unset($img);
             }
             if (!$error) {
                 $this->addToProductImage($product_id, $name_image, $post["product_image_descr_" . $i]);
                 $dispatcher->trigger('onAfterSaveProductImage', array($product_id, $name_image));
             }
         } else {
             if ($upload->getError() != 4) {
                 JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
                 saveToLog("error.log", "SaveProduct - Error upload image. code: " . $upload->getError());
             }
         }
         unset($upload);
     }
     for ($i = 0; $i < $jshopConfig->product_image_upload_count; $i++) {
         if ($post['product_folder_image_' . $i] != '') {
             if (file_exists($jshopConfig->image_product_path . '/' . $post['product_folder_image_' . $i])) {
                 $name_image = $post['product_folder_image_' . $i];
                 $name_thumb = 'thumb_' . $name_image;
                 $name_full = 'full_' . $name_image;
                 $this->addToProductImage($product_id, $name_image, $post["product_image_descr_" . $i]);
                 $dispatcher->trigger('onAfterSaveProductFolerImage', array($product_id, $name_full, $name_image, $name_thumb));
             }
         }
     }
     if (!$product->image) {
         $list_images = $product->getImages();
         if (count($list_images)) {
             $product = JTable::getInstance('product', 'jshop');
             $product->load($product_id);
             $product->image = $list_images[0]->image_name;
             $product->store();
         }
     }
     if (isset($post['old_image_descr'])) {
         $this->renameProductImageOld($post['old_image_descr'], $post['old_image_ordering']);
     }
 }
Пример #4
0
 function save()
 {
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     $dispatcher = JDispatcher::getInstance();
     $apply = JRequest::getVar("apply");
     $_alias = JSFactory::getModel("alias");
     $db = JFactory::getDBO();
     $man = JSFactory::getTable('manufacturer', 'jshop');
     $man_id = JRequest::getInt("manufacturer_id");
     $post = JRequest::get("post");
     $_lang = JSFactory::getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, 0, $man_id)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$post['manufacturer_publish']) {
         $post['manufacturer_publish'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveManufacturer', array(&$post));
     if (!$man->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     if (!$man_id) {
         $man->ordering = null;
         $man->ordering = $man->getNextOrder();
     }
     $upload = new UploadFile($_FILES['manufacturer_logo']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_manufs_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         if ($post['old_image']) {
             @unlink($jshopConfig->image_manufs_path . "/" . $post['old_image']);
         }
         $name = $upload->getName();
         @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_manufs_path . "/" . $name;
             $path_thumb = $jshopConfig->image_manufs_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color, $jshopConfig->image_interlace)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveManufacturer - Error create thumbail");
             }
             @chmod($jshopConfig->image_manufs_path . "/" . $name, 0777);
             unset($img);
         }
         $man->manufacturer_logo = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveManufacturer - Error upload image. code: " . $upload->getError());
         }
     }
     if (!$man->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveManufacturer', array(&$man));
     if ($this->getTask() == 'apply') {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers&task=edit&man_id=" . $man->manufacturer_id);
     } else {
         $this->setRedirect("index.php?option=com_jshopping&controller=manufacturers");
     }
 }
Пример #5
0
 function save()
 {
     $mainframe = JFactory::getApplication();
     $jshopConfig = JSFactory::getConfig();
     require_once $jshopConfig->path . 'lib/image.lib.php';
     require_once $jshopConfig->path . 'lib/uploadfile.class.php';
     JPluginHelper::importPlugin('jshoppingadmin');
     $dispatcher = JDispatcher::getInstance();
     $_alias = $this->getModel("alias");
     $db = JFactory::getDBO();
     $category = JTable::getInstance("category", "jshop");
     if (!$_POST["category_id"]) {
         $_POST['category_add_date'] = getJsDate();
     }
     if (!isset($_POST['category_publish'])) {
         $_POST['category_publish'] = 0;
     }
     $post = JRequest::get('post');
     $_lang = $this->getModel("languages");
     $languages = $_lang->getAllLanguages(1);
     if ($post['category_parent_id'] == $post['category_id']) {
         $post['category_parent_id'] = 0;
     }
     $dispatcher->trigger('onBeforeSaveCategory', array(&$post));
     foreach ($languages as $lang) {
         $post['name_' . $lang->language] = trim($post['name_' . $lang->language]);
         if ($jshopConfig->create_alias_product_category_auto && $post['alias_' . $lang->language] == "") {
             $post['alias_' . $lang->language] = $post['name_' . $lang->language];
         }
         $post['alias_' . $lang->language] = JApplication::stringURLSafe($post['alias_' . $lang->language]);
         if ($post['alias_' . $lang->language] != "" && !$_alias->checkExistAlias1Group($post['alias_' . $lang->language], $lang->language, $post['category_id'], 0)) {
             $post['alias_' . $lang->language] = "";
             JError::raiseWarning("", _JSHOP_ERROR_ALIAS_ALREADY_EXIST);
         }
         $post['description_' . $lang->language] = JRequest::getVar('description' . $lang->id, '', 'post', "string", 2);
         $post['short_description_' . $lang->language] = JRequest::getVar('short_description_' . $lang->language, '', 'post', "string", 2);
     }
     if (!$category->bind($post)) {
         JError::raiseWarning("", _JSHOP_ERROR_BIND);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $edit = $category->category_id;
     $upload = new UploadFile($_FILES['category_image']);
     $upload->setAllowFile(array('jpeg', 'jpg', 'gif', 'png'));
     $upload->setDir($jshopConfig->image_category_path);
     $upload->setFileNameMd5(0);
     $upload->setFilterName(1);
     if ($upload->upload()) {
         $name = $upload->getName();
         if ($post['old_image'] && $name != $post['old_image']) {
             @unlink($jshopConfig->image_category_path . "/" . $post['old_image']);
         }
         @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
         if ($post['size_im_category'] < 3) {
             if ($post['size_im_category'] == 1) {
                 $category_width_image = $jshopConfig->image_category_width;
                 $category_height_image = $jshopConfig->image_category_height;
             } else {
                 $category_width_image = JRequest::getInt('category_width_image');
                 $category_height_image = JRequest::getInt('category_height_image');
             }
             $path_full = $jshopConfig->image_category_path . "/" . $name;
             $path_thumb = $jshopConfig->image_category_path . "/" . $name;
             if (!ImageLib::resizeImageMagic($path_full, $category_width_image, $category_height_image, $jshopConfig->image_cut, $jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality, $jshopConfig->image_fill_color)) {
                 JError::raiseWarning("", _JSHOP_ERROR_CREATE_THUMBAIL);
                 saveToLog("error.log", "SaveCategory - Error create thumbail");
             }
             @chmod($jshopConfig->image_category_path . "/" . $name, 0777);
             unset($img);
         }
         $category->category_image = $name;
     } else {
         if ($upload->getError() != 4) {
             JError::raiseWarning("", _JSHOP_ERROR_UPLOADING_IMAGE);
             saveToLog("error.log", "SaveCategory - Error upload image. code: " . $upload->getError());
         }
     }
     $this->_reorderCategory($category);
     if (!$category->store()) {
         JError::raiseWarning("", _JSHOP_ERROR_SAVE_DATABASE);
         $this->setRedirect("index.php?option=com_jshopping&controller=categories");
         return 0;
     }
     $dispatcher->trigger('onAfterSaveCategory', array(&$category));
     $success = $edit ? _JSHOP_CATEGORY_SUCC_UPDATE : _JSHOP_CATEGORY_SUCC_ADDED;
     if ($this->getTask() == 'apply') {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories&task=edit&category_id=' . $category->category_id, $success);
     } else {
         $this->setRedirect('index.php?option=com_jshopping&controller=categories', $success);
     }
 }