当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::getHighestPosition方法代码示例

本文整理汇总了PHP中Image::getHighestPosition方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getHighestPosition方法的具体用法?PHP Image::getHighestPosition怎么用?PHP Image::getHighestPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::getHighestPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertImageInPrestashop

 /**
  * Inserts product's image in Prestashop.
  * 
  * @param integer $id_product
  * @param string $url
  * @param string $name_photo
  * @return integer 
  * @see $this->copyImg
  *
  */
 public function insertImageInPrestashop($id_product, $url, $name_photo)
 {
     $shops = Shop::getShops(true, null, true);
     $image = new ImageCore();
     $image->id_product = $id_product;
     $image->position = Image::getHighestPosition($id_product) + 1;
     $image->cover = true;
     // or false;
     $tmp = explode(".", $name_photo);
     $name_photo_product = "";
     $name_for_legend = "";
     if (count($tmp) == 1) {
         $name_photo_product = trim($url) . $name_photo . ".jpg";
         $name_for_legend = $name_photo . ".jpg";
     } else {
         $name_photo_product = trim($url) . $name_photo;
         $name_for_legend = $name_photo;
     }
     $image->legend = array('1' => trim($name_for_legend));
     if ($image->validateFields(false, true) === true && $image->validateFieldsLang(false, true) === true && $image->add()) {
         $image->associateTo($shops);
         if (!$this->copyImg($id_product, $image->id, $name_photo_product, 'products')) {
             $image->delete();
         }
     }
     return $image->id;
 }
开发者ID:valucifer,项目名称:S-SoldP-Pal,代码行数:37,代码来源:PrestashopProducts.php

示例2: add

 /**
  * @see ObjectModel::add()
  */
 public function add($autodate = true, $null_values = false)
 {
     if ($this->position <= 0) {
         $this->position = Image::getHighestPosition($this->id_customer) + 1;
     }
     if ($this->cover) {
         $this->cover = 1;
     } else {
         $this->cover = null;
     }
     return parent::add($autodate, $null_values);
 }
开发者ID:jpodracky,项目名称:dogs,代码行数:15,代码来源:SocialUserHeaderModel.php

示例3: loadImage

 public function loadImage($id_product, $images)
 {
     $images_array = $this->imagesToArray($images);
     $images_id = array();
     $product = new Product($id_product);
     $image_types = ImageType::getImagesTypes('product');
     if ($images_array) {
         foreach ($images_array as $img) {
             if (file_exists(_TM_ROOT_DIR_ . $img['url'])) {
                 //ajout de l'image au produit
                 $image = new Image();
                 $image->id_product = intval($product->id);
                 $image->position = Image::getHighestPosition($product->id) + 1;
                 if (!intval($product->id_image_default)) {
                     $image->cover = 1;
                 } else {
                     $image->cover = 0;
                 }
                 $image->legend = 0;
                 $image->add();
                 if ($image->cover) {
                     $product->id_image_default = (int) $image->id;
                 }
                 $id_image = $image->id;
                 $images_id[] = $id_image;
                 $path = $image->getPathForCreation();
                 //echo $imgDir.$img['url'];
                 @copy(_TM_ROOT_DIR_ . $img['url'], $path . '.jpg');
                 foreach ($image_types as $k => $image_type) {
                     ImageManager::resize(_TM_ROOT_DIR_ . $img['url'], $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
                 }
                 //@unlink($tmpName);
             } else {
                 $this->_output .= '<div class="alert error">Image not exists!</div>';
             }
             $product->update();
         }
     }
     return $images_id;
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:40,代码来源:Import.php

示例4: copyImg

 private function copyImg($item, $className)
 {
     require_once '../../images.inc.php';
     $identifier = $this->supportedImports[strtolower($className)]['identifier'];
     $matchId = $this->getMatchId(strtolower($className));
     $matchIdLang = $this->getMatchIdLang();
     switch ($className) {
         default:
         case 'Product':
             $path = _PS_PROD_IMG_DIR_;
             $type = 'products';
             break;
         case 'Category':
             $path = _PS_CAT_IMG_DIR_;
             $type = 'categories';
             break;
         case 'Manufacturer':
             $path = _PS_MANU_IMG_DIR_;
             $type = 'manufacturers';
             break;
         case 'Supplier':
             $path = _PS_SUPP_IMG_DIR_;
             $type = 'suppliers';
             break;
     }
     $cover = 1;
     if (array_key_exists($item[$identifier], $matchId)) {
         if (array_key_exists('images', $item) && !is_null($item['images'])) {
             foreach ($item['images'] as $key => $image) {
                 $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import');
                 if (@copy(str_replace(' ', '%20', $image), $tmpfile)) {
                     $imagesTypes = ImageType::getImagesTypes($type);
                     ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '.jpg');
                     if ($className == 'Product') {
                         $image = new Image();
                         $image->id_product = (int) $matchId[$item[$identifier]];
                         $image->cover = $cover;
                         $image->position = Image::getHighestPosition((int) $matchId[$item[$identifier]]) + 1;
                         $legend = array();
                         foreach ($item['name'] as $key => $val) {
                             if (array_key_exists($key, $matchIdLang)) {
                                 $legend[$matchIdLang[$key]] = Tools::link_rewrite($val);
                             } else {
                                 $legend[Configuration::get('PS_LANG_DEFAULT')] = Tools::link_rewrite($val);
                             }
                         }
                         $image->legend = $legend;
                         $image->add();
                         ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . (int) $image->id . '.jpg');
                         foreach ($imagesTypes as $k => $imageType) {
                             ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . (int) $image->id . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height']);
                         }
                     } else {
                         foreach ($imagesTypes as $imageType) {
                             ImageManager::resize($tmpfile, $path . (int) $matchId[$item[$identifier]] . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height']);
                         }
                     }
                 } else {
                     @unlink($tmpfile);
                 }
                 @unlink($tmpfile);
                 $cover = 0;
             }
         }
     }
 }
开发者ID:FAVHYAN,项目名称:a3workout,代码行数:66,代码来源:shopimporter.php

示例5: writePostedImageOnDisk

 /**
  * 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));
//.........这里部分代码省略.........
开发者ID:toufikadfab,项目名称:PrestaShop-1.5,代码行数:101,代码来源:WebserviceSpecificManagementImages.php

示例6: attributeImport

 public function attributeImport()
 {
     global $cookie;
     $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
     $groups = array();
     foreach (AttributeGroup::getAttributesGroups($defaultLanguage) as $group) {
         $groups[$group['name']] = (int) $group['id_attribute_group'];
     }
     $attributes = array();
     foreach (Attribute::getAttributes($defaultLanguage) as $attribute) {
         $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
     }
     $this->receiveTab();
     $handle = $this->openCsvFile();
     $fsep = (is_null(Tools::getValue('multiple_value_separator')) or trim(Tools::getValue('multiple_value_separator')) == '') ? ',' : Tools::getValue('multiple_value_separator');
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         $info = array_map('trim', $info);
         self::setDefaultValues($info);
         $product = new Product((int) $info['id_product'], false, $defaultLanguage);
         $id_image = null;
         if (isset($info['image_url']) && $info['image_url']) {
             $productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id);
             $url = $info['image_url'];
             $image = new Image();
             $image->id_product = (int) $product->id;
             $image->position = Image::getHighestPosition($product->id) + 1;
             $image->cover = !$productHasImages ? true : false;
             $image->legend = self::createMultiLangField($product->name);
             if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) {
                 if (!self::copyImg($product->id, $image->id, $url)) {
                     $this->_warnings[] = Tools::displayError('Error copying image: ') . $url;
                 } else {
                     $id_image = array($image->id);
                 }
             } else {
                 $this->_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
         } elseif (isset($info['image_position']) && $info['image_position']) {
             $images = $product->getImages($defaultLanguage);
             if ($images) {
                 foreach ($images as $row) {
                     if ($row['position'] == (int) $info['image_position']) {
                         $id_image = array($row['id_image']);
                         break;
                     }
                 }
             }
             if (!$id_image) {
                 $this->_warnings[] = sprintf(Tools::displayError('No image found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']);
             }
         }
         $id_product_attribute = $product->addProductAttribute((double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], $id_image, strval($info['reference']), strval($info['supplier_reference']), strval($info['ean13']), (int) $info['default_on'], strval($info['upc']));
         foreach (explode($fsep, $info['options']) as $option) {
             list($group, $attribute) = array_map('trim', explode(':', $option));
             if (!isset($groups[$group])) {
                 $obj = new AttributeGroup();
                 $obj->is_color_group = false;
                 $obj->name[$defaultLanguage] = $group;
                 $obj->public_name[$defaultLanguage] = $group;
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $groups[$group] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             if (!isset($attributes[$group . '_' . $attribute])) {
                 $obj = new Attribute();
                 $obj->id_attribute_group = $groups[$group];
                 $obj->name[$defaultLanguage] = str_replace('\\n', '', str_replace('\\r', '', $attribute));
                 if (($fieldError = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
                     $obj->add();
                     $attributes[$group . '_' . $attribute] = $obj->id;
                 } else {
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '');
                 }
             }
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attributes[$group . '_' . $attribute] . ',' . (int) $id_product_attribute . ')');
         }
     }
     $this->closeCsvFile($handle);
 }
开发者ID:greench,项目名称:prestashop,代码行数:88,代码来源:AdminImport.php

示例7: attributeImportOne

    protected function attributeImportOne($info, $default_language, &$groups, &$attributes, $regenerate, $shop_is_feature_active, $validateOnly = false)
    {
        AdminImportController::setDefaultValues($info);
        if (!$shop_is_feature_active) {
            $info['shop'] = 1;
        } elseif (!isset($info['shop']) || empty($info['shop'])) {
            $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
        }
        // Get shops for each attributes
        $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
        $id_shop_list = array();
        if (is_array($info['shop']) && count($info['shop'])) {
            foreach ($info['shop'] as $shop) {
                if (!empty($shop) && !is_numeric($shop)) {
                    $id_shop_list[] = Shop::getIdByName($shop);
                } elseif (!empty($shop)) {
                    $id_shop_list[] = $shop;
                }
            }
        }
        if (isset($info['id_product']) && $info['id_product']) {
            $product = new Product((int) $info['id_product'], false, $default_language);
        } elseif (Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) {
            $datas = Db::getInstance()->getRow('
				SELECT p.`id_product`
				FROM `' . _DB_PREFIX_ . 'product` p
				' . Shop::addSqlAssociation('product', 'p') . '
				WHERE p.`reference` = "' . pSQL($info['product_reference']) . '"
			', false);
            if (isset($datas['id_product']) && $datas['id_product']) {
                $product = new Product((int) $datas['id_product'], false, $default_language);
            }
        } else {
            return;
        }
        $id_image = array();
        if (isset($info['image_url']) && $info['image_url']) {
            $info['image_url'] = explode($this->multiple_value_separator, $info['image_url']);
            if (is_array($info['image_url']) && count($info['image_url'])) {
                foreach ($info['image_url'] as $key => $url) {
                    $url = trim($url);
                    $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
                    $image = new Image();
                    $image->id_product = (int) $product->id;
                    $image->position = Image::getHighestPosition($product->id) + 1;
                    $image->cover = !$product_has_images ? true : false;
                    if (isset($info['image_alt'])) {
                        $alt = self::split($info['image_alt']);
                        if (isset($alt[$key]) && strlen($alt[$key]) > 0) {
                            $alt = self::createMultiLangField($alt[$key]);
                            $image->legend = $alt;
                        }
                    }
                    $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
                    $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
                    if ($field_error === true && $lang_field_error === true && !$validateOnly && $image->add()) {
                        $image->associateTo($id_shop_list);
                        // FIXME: 2s/image !
                        if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) {
                            $this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url);
                            $image->delete();
                        } else {
                            $id_image[] = (int) $image->id;
                        }
                        // until here
                    } else {
                        if (!$validateOnly) {
                            $this->warnings[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
                        }
                        if ($field_error !== true || $lang_field_error !== true) {
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
                        }
                    }
                }
            }
        } elseif (isset($info['image_position']) && $info['image_position']) {
            $info['image_position'] = explode($this->multiple_value_separator, $info['image_position']);
            if (is_array($info['image_position']) && count($info['image_position'])) {
                foreach ($info['image_position'] as $position) {
                    // choose images from product by position
                    $images = $product->getImages($default_language);
                    if ($images) {
                        foreach ($images as $row) {
                            if ($row['position'] == (int) $position) {
                                $id_image[] = (int) $row['id_image'];
                                break;
                            }
                        }
                    }
                    if (empty($id_image)) {
                        $this->warnings[] = sprintf($this->trans('No image was found for combination with id_product = %s and image position = %s.', array(), 'Admin.Parameters.Notification'), $product->id, (int) $position);
                    }
                }
            }
        }
        $id_attribute_group = 0;
        // groups
        $groups_attributes = array();
        if (isset($info['group'])) {
            foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) {
//.........这里部分代码省略.........
开发者ID:M03G,项目名称:PrestaShop,代码行数:101,代码来源:AdminImportController.php

示例8: uploadImageZip

 public function uploadImageZip($product)
 {
     // Move the ZIP file to the img/tmp directory
     if (!($zipfile = tempnam(_PS_TMP_IMG_DIR_, 'PS')) or !move_uploaded_file($_FILES['image_product']['tmp_name'], $zipfile)) {
         $this->_errors[] = Tools::displayError('An error occurred during the ZIP file upload.');
         return false;
     }
     // Unzip the file to a subdirectory
     $subdir = _PS_TMP_IMG_DIR_ . uniqid() . '/';
     try {
         if (!Tools::ZipExtract($zipfile, $subdir)) {
             throw new Exception(Tools::displayError('An error occurred while unzipping your file.'));
         }
         $types = array('.gif' => 'image/gif', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpg', '.png' => 'image/png');
         $_POST['id_product'] = (int) $product->id;
         $imagesTypes = ImageType::getImagesTypes('products');
         $highestPosition = Image::getHighestPosition($product->id);
         foreach (scandir($subdir) as $file) {
             if ($file[0] == '.') {
                 continue;
             }
             // Create image object
             $image = new Image();
             $image->id_product = (int) $product->id;
             $image->position = ++$highestPosition;
             $image->cover = $highestPosition == 1 ? true : false;
             // Call automated copy function
             $this->validateRules('Image', 'image');
             $this->copyFromPost($image, 'image');
             if (sizeof($this->_errors)) {
                 throw new Exception('');
             }
             if (!$image->add()) {
                 throw new Exception(Tools::displayError('Error while creating additional image'));
             }
             if (filesize($subdir . $file) > $this->maxImageSize) {
                 $image->delete();
                 throw new Exception(Tools::displayError('Image is too large') . ' (' . filesize($subdir . $file) / 1000 . Tools::displayError('kB') . '). ' . Tools::displayError('Maximum allowed:') . ' ' . $this->maxImageSize / 1000 . Tools::displayError('kB'));
             }
             $ext = substr($file, -4) == 'jpeg' ? '.jpeg' : substr($file, -4);
             $type = isset($types[$ext]) ? $types[$ext] : '';
             if (!isPicture(array('tmp_name' => $subdir . $file, 'type' => $type))) {
                 $image->delete();
                 throw new Exception(Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png'));
             }
             if (!($new_path = $image->getPathForCreation())) {
                 throw new Exception(Tools::displayError('An error occurred during new folder creation'));
             }
             if (!imageResize($subdir . $file, $new_path . '.' . $image->image_format)) {
                 $image->delete();
                 throw new Exception(Tools::displayError('An error occurred while resizing image.'));
             }
             foreach ($imagesTypes as $k => $imageType) {
                 if (!imageResize($image->getPathForCreation() . '.jpg', $image->getPathForCreation() . '-' . stripslashes($imageType['name']) . '.jpg', $imageType['width'], $imageType['height'])) {
                     $image->delete();
                     throw new Exception(Tools::displayError('An error occurred while copying image.') . ' ' . stripslashes($imageType['name']));
                 }
             }
             Module::hookExec('watermark', array('id_image' => $image->id, 'id_product' => $image->id_product));
         }
     } catch (Exception $e) {
         if ($error = $e->getMessage()) {
         }
         $this->_errors[] = $error;
         Tools::deleteDirectory($subdir);
         return false;
     }
     Tools::deleteDirectory($subdir);
     return true;
 }
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:70,代码来源:AdminProducts.php

示例9: addProductImage

 public static function addProductImage($id_product, $url)
 {
     $rhueeqpyqid = "url";
     $hrqreqrws = "product_has_images";
     $gdvfsxvvwqw = "id_product";
     $muucuokjnr = "url";
     ${$muucuokjnr} = trim(${$rhueeqpyqid});
     ${"GLOBALS"}["spvdeam"] = "url";
     if (empty(${${"GLOBALS"}["csdyhfby"]})) {
         return false;
     }
     ${${"GLOBALS"}["csdyhfby"]} = str_replace(" ", "%20", ${${"GLOBALS"}["spvdeam"]});
     ${"GLOBALS"}["mmicugw"] = "image";
     ${$hrqreqrws} = (bool) Image::getImages(Context::getContext()->language->id, (int) ${$gdvfsxvvwqw});
     ${${"GLOBALS"}["mmicugw"]} = new Image();
     $image->id_product = (int) ${${"GLOBALS"}["ktxxdlcenjrd"]};
     $image->position = Image::getHighestPosition(${${"GLOBALS"}["ktxxdlcenjrd"]}) + 1;
     ${"GLOBALS"}["mincqrvbtcit"] = "product_has_images";
     $image->cover = ${${"GLOBALS"}["mincqrvbtcit"]} ? false : true;
     if ($image->validateFields(false, true) === true && $image->validateFieldsLang(false, true) === true && $image->add()) {
         $image->associateTo(array(1));
         ${"GLOBALS"}["vgrilvvuoi"] = "id_product";
         ${"GLOBALS"}["flxzymmafk"] = "url";
         return AgileHelper::copyImg(${${"GLOBALS"}["vgrilvvuoi"]}, $image->id, ${${"GLOBALS"}["flxzymmafk"]}, "products", !Tools::getValue("regenerate"));
     }
     return false;
 }
开发者ID:evilscripts,项目名称:gy,代码行数:27,代码来源:AgileHelper.php

示例10: productImport


//.........这里部分代码省略.........
                                break;
                            }
                        }
                    } else {
                        foreach ($product->tags as $key => $tags) {
                            $str = '';
                            foreach ($tags as $one_tag) {
                                $str .= $one_tag . $this->multiple_value_separator;
                            }
                            $str = rtrim($str, $this->multiple_value_separator);
                            $is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator);
                            if (!$is_tag_added) {
                                $this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')');
                                break;
                            }
                        }
                    }
                }
                //delete existing images if "delete_existing_images" is set to 1
                if (isset($product->delete_existing_images)) {
                    if ((bool) $product->delete_existing_images) {
                        $product->deleteImages();
                    }
                }
                if (isset($product->image) && is_array($product->image) && count($product->image)) {
                    $product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id);
                    foreach ($product->image as $key => $url) {
                        $url = trim($url);
                        $error = false;
                        if (!empty($url)) {
                            $url = str_replace(' ', '%20', $url);
                            $image = new Image();
                            $image->id_product = (int) $product->id;
                            $image->position = Image::getHighestPosition($product->id) + 1;
                            $image->cover = !$key && !$product_has_images ? true : false;
                            // file_exists doesn't work with HTTP protocol
                            if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add()) {
                                // associate image to selected shops
                                $image->associateTo($shops);
                                if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !Tools::getValue('regenerate'))) {
                                    $image->delete();
                                    $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
                                }
                            } else {
                                $error = true;
                            }
                        } else {
                            $error = true;
                        }
                        if ($error) {
                            $this->warnings[] = sprintf(Tools::displayError('Product #%1$d: the picture (%2$s) cannot be saved.'), $image->id_product, $url);
                        }
                    }
                }
                if (isset($product->id_category) && is_array($product->id_category)) {
                    $product->updateCategories(array_map('intval', $product->id_category));
                }
                $product->checkDefaultAttributes();
                if (!$product->cache_default_attribute) {
                    Product::updateDefaultAttribute($product->id);
                }
                // Features import
                $features = get_object_vars($product);
                if (isset($features['features']) && !empty($features['features'])) {
                    foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) {
                        if (empty($single_feature)) {
开发者ID:julienlerch,项目名称:xburning,代码行数:67,代码来源:AdminImportController.php

示例11: addProductImage

 /**
  * Add or update a product image
  *
  * @param object $product Product object to add image
  */
 public function addProductImage($product, $method = 'auto')
 {
     /**HANDLING GALLERY IMAGES*/
     if (isset($_POST['imageurl']) && strlen(trim($_POST['imageurl'])) != 0) {
         $url = $_POST['imageurl'];
         $urlimage = file_get_contents($url);
         $filename = time() . substr($url, strtolower(strrpos($url, '.')));
         $filename = strtolower($filename);
         $filepath = '/tmp/' . $filename;
         file_put_contents($filepath, $urlimage);
         $mimetype = mime_content_type($filepath);
         $filesize = filesize($filepath);
         $galleryfile = array('name' => $filename, 'type' => $mimetype, 'tmp_name' => $filepath, 'error' => 0, 'size' => $filesize);
         $_FILES['image_product'] = $galleryfile;
     }
     /* Updating an existing product image */
     if ($id_image = intval(Tools::getValue('id_image'))) {
         $image = new Image($id_image);
         if (!Validate::isLoadedObject($image)) {
             $this->_errors[] = Tools::displayError('an error occurred while loading object image');
         } else {
             if (($cover = Tools::getValue('cover')) == 1) {
                 Image::deleteCover($product->id);
             }
             $image->cover = $cover;
             $this->validateRules('Image');
             $this->copyFromPost($image, 'image');
             if (sizeof($this->_errors) or !$image->update()) {
                 $this->_errors[] = Tools::displayError('an error occurred while updating image');
             } elseif (isset($_FILES['image_product']['tmp_name']) and $_FILES['image_product']['tmp_name'] != NULL) {
                 $this->copyImage($product->id, $image->id, $method);
             }
         }
     } elseif (isset($_FILES['image_product']['tmp_name']) and $_FILES['image_product']['tmp_name'] != NULL) {
         if (!Validate::isLoadedObject($product)) {
             $this->_errors[] = Tools::displayError('cannot add image because product add failed');
         } else {
             $image = new Image();
             $image->id_product = intval($product->id);
             $_POST['id_product'] = $image->id_product;
             $image->position = Image::getHighestPosition($product->id) + 1;
             if (($cover = Tools::getValue('cover')) == 1) {
                 Image::deleteCover($product->id);
             }
             $image->cover = !$cover ? !sizeof($product->getImages(Configuration::get('PS_LANG_DEFAULT'))) : true;
             $this->validateRules('Image', 'image');
             $this->copyFromPost($image, 'image');
             if (!sizeof($this->_errors)) {
                 if (!$image->add()) {
                     $this->_errors[] = Tools::displayError('error while creating additional image');
                 } else {
                     $this->copyImage($product->id, $image->id, $method);
                 }
             }
         }
         $id_image = $image->id;
     }
     if (isset($image) and Validate::isLoadedObject($image) and !file_exists(_PS_IMG_DIR_ . 'p/' . $image->id_product . '-' . $image->id . '.jpg')) {
         $image->delete();
     }
     if (sizeof($this->_errors)) {
         return false;
     }
     @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $product->id . '.jpg');
     @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $product->id . '.jpg');
     return (isset($id_image) and is_int($id_image) and $id_image) ? $id_image : true;
 }
开发者ID:redb,项目名称:prestashop,代码行数:72,代码来源:AdminProducts.php

示例12: execImages

 public static function execImages($pdt, $product)
 {
     $images = array();
     if (isset($pdt->images)) {
         $images = (array) $pdt->images->url;
     } else {
         return;
     }
     foreach ($images as &$img) {
         if (preg_match('/:\\/\\//', $img)) {
             continue;
         }
         $img = _PS_ROOT_DIR_ . $img;
         if (!file_exists($img)) {
             Log::notice($pdt->supplier_reference, 'File $img not found.');
         }
     }
     $product->deleteImages();
     $productHasImages = (bool) Image::getImages(self::getInfoEco('ID_LANG'), (int) $product->id);
     foreach ($images as $key => $url) {
         $url = str_replace(' ', '%20', $url);
         $image = new Image();
         $image->id_product = $product->id;
         $image->position = Image::getHighestPosition($product->id) + 1;
         $image->cover = !$key && !$productHasImages ? true : false;
         if ($image->add()) {
             if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                 $image->associateTo($pdt->id_shop_default);
             }
             if (!self::copyImg($product->id, $image->id, $url)) {
                 Log::notice($pdt->supplier_reference, 'Error copying image: $url');
             }
         } else {
             Log::notice($pdt->supplier_reference, 'Cannot save image $url');
         }
     }
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:37,代码来源:importProduct.class.php

示例13: attributeImport

    public function attributeImport()
    {
        $default_language = Configuration::get('PS_LANG_DEFAULT');
        $groups = array();
        foreach (AttributeGroup::getAttributesGroups($default_language) as $group) {
            $groups[$group['name']] = (int) $group['id_attribute_group'];
        }
        $attributes = array();
        foreach (Attribute::getAttributes($default_language) as $attribute) {
            $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute'];
        }
        $this->receiveTab();
        $handle = $this->openCsvFile();
        AdminImportController::setLocale();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
            if (count($line) == 1 && empty($line[0])) {
                continue;
            }
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }
            $info = AdminImportController::getMaskedRow($line);
            $info = array_map('trim', $info);
            if (self::ignoreRow($info)) {
                continue;
            }
            AdminImportController::setDefaultValues($info);
            if (!Shop::isFeatureActive()) {
                $info['shop'] = 1;
            } elseif (!isset($info['shop']) || empty($info['shop'])) {
                $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID());
            }
            $info['shop'] = explode($this->multiple_value_separator, $info['shop']);
            $id_shop_list = array();
            if (is_array($info['shop']) && count($info['shop'])) {
                foreach ($info['shop'] as $shop) {
                    if (!empty($shop) && !is_numeric($shop)) {
                        $id_shop_list[] = Shop::getIdByName($shop);
                    } elseif (!empty($shop)) {
                        $id_shop_list[] = $shop;
                    }
                }
            }
            if (isset($info['id_product']) && is_string($info['id_product'])) {
                $prod = self::findProductByName($default_language, $info['id_product']);
                if ($prod['id_product']) {
                    $info['id_product'] = $prod['id_product'];
                } else {
                    unset($info['id_product']);
                }
            }
            if (!isset($info['id_product']) && Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) {
                $datas = Db::getInstance()->getRow('
					SELECT p.`id_product`
					FROM `' . _DB_PREFIX_ . 'product` p
					' . Shop::addSqlAssociation('product', 'p') . '
					WHERE p.`reference` = "' . pSQL($info['product_reference']) . '"
				');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $info['id_product'] = $datas['id_product'];
                }
            }
            if (isset($info['id_product'])) {
                $product = new Product((int) $info['id_product'], false, $default_language);
            } else {
                continue;
            }
            $id_image = array();
            if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) {
                $product->deleteImages();
                $this->cache_image_deleted[(int) $product->id] = true;
            }
            if (isset($info['image_url']) && $info['image_url']) {
                $info['image_url'] = explode(',', $info['image_url']);
                if (is_array($info['image_url']) && count($info['image_url'])) {
                    foreach ($info['image_url'] as $url) {
                        $url = trim($url);
                        $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id);
                        $image = new Image();
                        $image->id_product = (int) $product->id;
                        $image->position = Image::getHighestPosition($product->id) + 1;
                        $image->cover = !$product_has_images ? true : false;
                        $field_error = $image->validateFields(UNFRIENDLY_ERROR, true);
                        $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true);
                        if ($field_error === true && $lang_field_error === true && $image->add()) {
                            $image->associateTo($id_shop_list);
                            if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !Tools::getValue('regenerate'))) {
                                $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url);
                                $image->delete();
                            } else {
                                $id_image[] = (int) $image->id;
                            }
                        } else {
                            $this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : '');
                            $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error();
                        }
                    }
                }
            } elseif (isset($info['image_position']) && $info['image_position']) {
                $info['image_position'] = explode(',', $info['image_position']);
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:AdminImportController.php

示例14: addProductImage

 public static function addProductImage($id_product, $url)
 {
     ${"GLOBALS"}["fvripywkibk"] = "url";
     $ebptnhakfo = "url";
     ${"GLOBALS"}["sipzolomo"] = "url";
     ${${"GLOBALS"}["fvripywkibk"]} = trim(${${"GLOBALS"}["sipzolomo"]});
     $irpunjy = "id_product";
     if (empty(${$ebptnhakfo})) {
         return false;
     }
     ${"GLOBALS"}["dbttbk"] = "product_has_images";
     ${"GLOBALS"}["ngbttfrcas"] = "url";
     ${${"GLOBALS"}["ngbttfrcas"]} = str_replace(" ", "%20", ${${"GLOBALS"}["qqvbhasckjhp"]});
     ${${"GLOBALS"}["dbttbk"]} = (bool) Image::getImages(Context::getContext()->language->id, (int) ${${"GLOBALS"}["fhxsdwr"]});
     ${${"GLOBALS"}["jbswpeulv"]} = new Image();
     $image->id_product = (int) ${$irpunjy};
     $image->position = Image::getHighestPosition(${${"GLOBALS"}["fhxsdwr"]}) + 1;
     $image->cover = ${${"GLOBALS"}["ntduigxet"]} ? false : true;
     if ($image->validateFields(false, true) === true && $image->validateFieldsLang(false, true) === true && $image->add()) {
         $otsljdt = "url";
         $jpwhwuiglhb = "id_product";
         $image->associateTo(array(1));
         return AgileHelper::copyImg(${$jpwhwuiglhb}, $image->id, ${$otsljdt}, "products", !Tools::getValue("regenerate"));
     }
     return false;
 }
开发者ID:sho5kubota,项目名称:guidingyou2,代码行数:26,代码来源:AgileHelper.php

示例15: productImport


//.........这里部分代码省略.........
                 $product->quantity = 0;
             }
             // If id product AND id product already in base, trying to update
             if ($product->id and Product::existsInDatabase((int) $product->id)) {
                 $datas = Db::getInstance()->getRow('SELECT `date_add` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product->id);
                 $product->date_add = pSQL($datas['date_add']);
                 $res = $product->update();
             }
             // If no id_product or update failed
             if (!$res) {
                 $res = $product->add();
             }
         }
         // If both failed, mysql error
         if (!$res) {
             $this->_errors[] = $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
             $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
         } else {
             // SpecificPrice (only the basic reduction feature is supported by the import)
             if (isset($info['reduction_price']) or isset($info['reduction_percent'])) {
                 $specificPrice = new SpecificPrice();
                 $specificPrice->id_product = (int) $product->id;
                 $specificPrice->id_shop = (int) Shop::getCurrentShop();
                 $specificPrice->id_currency = 0;
                 $specificPrice->id_country = 0;
                 $specificPrice->id_group = 0;
                 $specificPrice->price = 0.0;
                 $specificPrice->from_quantity = 1;
                 $specificPrice->reduction = (isset($info['reduction_price']) and $info['reduction_price']) ? $info['reduction_price'] : $info['reduction_percent'] / 100;
                 $specificPrice->reduction_type = (isset($info['reduction_price']) and $info['reduction_price']) ? 'amount' : 'percentage';
                 $specificPrice->from = (isset($info['reduction_from']) and Validate::isDate($info['reduction_from'])) ? $info['reduction_from'] : '0000-00-00 00:00:00';
                 $specificPrice->to = (isset($info['reduction_to']) and Validate::isDate($info['reduction_to'])) ? $info['reduction_to'] : '0000-00-00 00:00:00';
                 if (!$specificPrice->add()) {
                     $this->_addProductWarning($info['name'], $product->id, $this->l('Discount is invalid'));
                 }
             }
             if (isset($product->tags) and !empty($product->tags)) {
                 // Delete tags for this id product, for no duplicating error
                 Tag::deleteTagsForProduct($product->id);
                 $tag = new Tag();
                 if (!is_array($product->tags)) {
                     $product->tags = self::createMultiLangField($product->tags);
                     foreach ($product->tags as $key => $tags) {
                         $isTagAdded = $tag->addTags($key, $product->id, $tags);
                         if (!$isTagAdded) {
                             $this->_addProductWarning($info['name'], $product->id, $this->l('Tags list') . ' ' . $this->l('is invalid'));
                             break;
                         }
                     }
                 } else {
                     foreach ($product->tags as $key => $tags) {
                         $str = '';
                         foreach ($tags as $one_tag) {
                             $str .= $one_tag . ',';
                         }
                         $str = rtrim($str, ',');
                         $isTagAdded = $tag->addTags($key, $product->id, $str);
                         if (!$isTagAdded) {
                             $this->_addProductWarning($info['name'], $product->id, 'Invalid tag(s) (' . $str . ')');
                             break;
                         }
                     }
                 }
             }
             if (isset($product->image) and is_array($product->image) and sizeof($product->image)) {
                 $productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id);
                 foreach ($product->image as $key => $url) {
                     if (!empty($url)) {
                         $image = new Image();
                         $image->id_product = (int) $product->id;
                         $image->position = Image::getHighestPosition($product->id) + 1;
                         $image->cover = (!$key and !$productHasImages) ? true : false;
                         $image->legend = self::createMultiLangField($product->name[$defaultLanguageId]);
                         if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) {
                             if (!self::copyImg($product->id, $image->id, $url)) {
                                 $this->_warnings[] = Tools::displayError('Error copying image: ') . $url;
                             }
                         } else {
                             $this->_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                             $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                         }
                     }
                 }
             }
             if (isset($product->id_category)) {
                 $product->updateCategories(array_map('intval', $product->id_category));
             }
             $features = get_object_vars($product);
             foreach ($features as $feature => $value) {
                 if (!strncmp($feature, '#F_', 3) and Tools::strlen($product->{$feature})) {
                     $feature_name = str_replace('#F_', '', $feature);
                     $id_feature = Feature::addFeatureImport($feature_name);
                     $id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature});
                     Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
                 }
             }
         }
     }
     $this->closeCsvFile($handle);
 }
开发者ID:hecbuma,项目名称:quali-fisioterapia,代码行数:101,代码来源:AdminImport.php


注:本文中的Image::getHighestPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。