// revert from r11699
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11702 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+18
-21
@@ -95,29 +95,29 @@ class FileUploaderCore
|
||||
/**
|
||||
* Handle file uploads via XMLHttpRequest
|
||||
*/
|
||||
class qqUploadedFileXhr
|
||||
class qqUploadedFileXhr
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
function upload($path)
|
||||
{
|
||||
function upload($path)
|
||||
{
|
||||
$input = fopen("php://input", "r");
|
||||
$temp = tmpfile();
|
||||
$realSize = stream_copy_to_stream($input, $temp);
|
||||
fclose($input);
|
||||
if ($realSize != $this->getSize())
|
||||
if ($realSize != $this->getSize())
|
||||
return false;
|
||||
$target = fopen($path, "w");
|
||||
$target = fopen($path, "w");
|
||||
fseek($temp, 0, SEEK_SET);
|
||||
stream_copy_to_stream($temp, $target);
|
||||
fclose($target);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function save()
|
||||
|
||||
function save()
|
||||
{
|
||||
$product = new Product($_GET['id_product']);
|
||||
if (!Validate::isLoadedObject($product))
|
||||
@@ -134,12 +134,12 @@ class qqUploadedFileXhr
|
||||
if (!$image->add())
|
||||
return array('error' => Tools::displayError('Error while creating additional image'));
|
||||
else
|
||||
{
|
||||
{
|
||||
return $this->copyImage($product->id, $image->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function copyImage($id_product, $id_image, $method = 'auto')
|
||||
{
|
||||
$image = new Image($id_image);
|
||||
@@ -154,11 +154,8 @@ class qqUploadedFileXhr
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
foreach ($imagesTypes AS $k => $imageType)
|
||||
{
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$imageType['id_theme'] : '');
|
||||
if (!imageResize($tmpName, $new_path.'-'.stripslashes($imageType['name']).$theme.'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
if (!imageResize($tmpName, $new_path.'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
return array('error' => Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']));
|
||||
}
|
||||
}
|
||||
unlink($tmpName);
|
||||
Hook::exec('watermark', array('id_image' => $id_image, 'id_product' => $id_product));
|
||||
@@ -169,17 +166,17 @@ class qqUploadedFileXhr
|
||||
$img = array('id_image' => $image->id, 'position' => $image->position, 'cover' => $image->cover);
|
||||
return array("success" => $img);
|
||||
}
|
||||
|
||||
function getName()
|
||||
|
||||
function getName()
|
||||
{
|
||||
return $_GET['qqfile'];
|
||||
}
|
||||
|
||||
function getSize()
|
||||
function getSize()
|
||||
{
|
||||
if (isset($_SERVER["CONTENT_LENGTH"]))
|
||||
return (int)$_SERVER["CONTENT_LENGTH"];
|
||||
else
|
||||
throw new Exception('Getting content length is not supported.');
|
||||
}
|
||||
return (int)$_SERVER["CONTENT_LENGTH"];
|
||||
else
|
||||
throw new Exception('Getting content length is not supported.');
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -238,13 +238,12 @@ class ImageCore extends ObjectModel
|
||||
$new_path = $image_new->getPathForCreation();
|
||||
foreach ($images_types as $image_type)
|
||||
{
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].$theme.'.jpg'))
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].'.jpg'))
|
||||
{
|
||||
if (!Configuration::get('PS_LEGACY_IMAGES'))
|
||||
$image_new->createImgFolder();
|
||||
copy(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].$theme.'.jpg',
|
||||
$new_path.'-'.$image_type['name'].$theme.'.jpg');
|
||||
copy(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].'.jpg',
|
||||
$new_path.'-'.$image_type['name'].'.jpg');
|
||||
}
|
||||
}
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'.jpg'))
|
||||
@@ -402,10 +401,8 @@ class ImageCore extends ObjectModel
|
||||
// Delete auto-generated images
|
||||
$image_types = ImageType::getImagesTypes();
|
||||
foreach ($image_types as $image_type)
|
||||
{
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-'.$image_type['name'].$theme.'.'.$this->image_format;
|
||||
}
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-'.$image_type['name'].'.'.$this->image_format;
|
||||
|
||||
// Delete watermark image
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-watermark.'.$this->image_format;
|
||||
// delete index.php
|
||||
|
||||
+9
-14
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -29,9 +29,6 @@ class ImageTypeCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
/** @var string id_theme */
|
||||
public $id_theme;
|
||||
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
|
||||
@@ -55,7 +52,7 @@ class ImageTypeCore extends ObjectModel
|
||||
|
||||
/** @var integer Apply to scenes */
|
||||
public $scenes;
|
||||
|
||||
|
||||
/** @var integer Apply to store */
|
||||
public $stores;
|
||||
|
||||
@@ -66,7 +63,6 @@ class ImageTypeCore extends ObjectModel
|
||||
'table' => 'image_type',
|
||||
'primary' => 'id_image_type',
|
||||
'fields' => array(
|
||||
'id_theme' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isImageTypeName', 'required' => true, 'size' => 16),
|
||||
'width' => array('type' => self::TYPE_INT, 'validate' => 'isImageSize', 'required' => true),
|
||||
'height' => array('type' => self::TYPE_INT, 'validate' => 'isImageSize', 'required' => true),
|
||||
@@ -83,7 +79,7 @@ class ImageTypeCore extends ObjectModel
|
||||
* @var array Image types cache
|
||||
*/
|
||||
protected static $images_types_cache = array();
|
||||
|
||||
|
||||
protected $webserviceParameters = array();
|
||||
|
||||
/**
|
||||
@@ -92,17 +88,16 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string|null Image type
|
||||
* @return array Image type definitions
|
||||
*/
|
||||
public static function getImagesTypes($type = NULL, $id_theme = false)
|
||||
public static function getImagesTypes($type = NULL)
|
||||
{
|
||||
if (!isset(self::$images_types_cache[$type.($id_theme ? '-'.$id_theme : '')]))
|
||||
if (!isset(self::$images_types_cache[$type]))
|
||||
{
|
||||
$where = 'WHERE 1';
|
||||
if ($id_theme)
|
||||
$where .= ' AND id_theme='.(int)$id_theme;
|
||||
if (!empty($type))
|
||||
$where .= ' AND ' . pSQL($type) . ' = 1 ';
|
||||
$where = 'WHERE ' . pSQL($type) . ' = 1 ';
|
||||
else
|
||||
$where = '';
|
||||
|
||||
$query = 'SELECT * FROM `'._DB_PREFIX_.'image_type`'.$where.' ORDER BY `name` ASC';
|
||||
$query = 'SELECT * FROM `'._DB_PREFIX_.'image_type`'.$where.'ORDER BY `name` ASC';
|
||||
self::$images_types_cache[$type] = Db::getInstance()->executeS($query);
|
||||
}
|
||||
|
||||
|
||||
+8
-10
@@ -306,26 +306,24 @@ class LinkCore
|
||||
public function getImageLink($name, $ids, $type = null)
|
||||
{
|
||||
// legacy mode or default image
|
||||
$theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
|
||||
if ((Configuration::get('PS_LEGACY_IMAGES')
|
||||
&& (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg')))
|
||||
&& (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'.jpg')))
|
||||
|| strpos($ids, 'default') !== false)
|
||||
{
|
||||
if ($this->allow == 1)
|
||||
$uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
|
||||
else
|
||||
$uri_path = _THEME_PROD_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg';
|
||||
}
|
||||
if ($this->allow == 1)
|
||||
$uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg';
|
||||
else
|
||||
$uri_path = _THEME_PROD_DIR_.$ids.($type ? '-'.$type : '').'.jpg';
|
||||
}else
|
||||
{
|
||||
// if ids if of the form id_product-id_image, we want to extract the id_image part
|
||||
$split_ids = explode('-', $ids);
|
||||
$id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
|
||||
$theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
|
||||
|
||||
if ($this->allow == 1)
|
||||
$uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
|
||||
$uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').'/'.$name.'.jpg';
|
||||
else
|
||||
$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg';
|
||||
$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg';
|
||||
}
|
||||
|
||||
return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
|
||||
|
||||
+17
-17
@@ -42,7 +42,7 @@ class ToolsCore
|
||||
{
|
||||
switch ($flag)
|
||||
{
|
||||
case 'NUMERIC':
|
||||
case 'NUMERIC':
|
||||
$str = '0123456789';
|
||||
break;
|
||||
case 'NO_NUMERIC':
|
||||
@@ -52,7 +52,7 @@ class ToolsCore
|
||||
$str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0, $passwd = ''; $i < $length; $i++)
|
||||
$passwd .= self::substr($str, mt_rand(0, self::strlen($str) - 1), 1);
|
||||
return $passwd;
|
||||
@@ -367,7 +367,7 @@ class ToolsCore
|
||||
$context = Context::getContext();
|
||||
if ($id_lang = (int)(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang))
|
||||
$context->cookie->id_lang = $id_lang;
|
||||
|
||||
|
||||
$language = new Language($id_lang);
|
||||
if (Validate::isLoadedObject($language))
|
||||
$context->language = $language;
|
||||
@@ -558,10 +558,10 @@ class ToolsCore
|
||||
{
|
||||
if (!$date || !($time = strtotime($date)))
|
||||
return $date;
|
||||
|
||||
|
||||
if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00')
|
||||
return '';
|
||||
|
||||
|
||||
if (!Validate::isDate($date) || !Validate::isBool($full))
|
||||
throw new PrestashopException('Invalid date');
|
||||
|
||||
@@ -636,7 +636,7 @@ class ToolsCore
|
||||
|
||||
if (is_null($context))
|
||||
$context = Context::getContext();
|
||||
|
||||
|
||||
@include_once(_PS_TRANSLATIONS_DIR_.$context->language->iso_code.'/errors.php');
|
||||
|
||||
if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $string == 'Fatal error')
|
||||
@@ -1566,8 +1566,8 @@ class ToolsCore
|
||||
fwrite($write_fd, "# Images\n");
|
||||
if (Configuration::get('PS_LEGACY_IMAGES'))
|
||||
{
|
||||
fwrite($write_fd, 'RewriteRule (*UTF8)^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)(-[0-9]+)?/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.'$1-$2$3$4.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule (*UTF8)^([0-9]+)\-([0-9]+)(-[0-9]+)?/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.'$1-$2$3.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.'$1-$2$3.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule ^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.'$1-$2.jpg [L]'."\n");
|
||||
}
|
||||
|
||||
// Rewrite product images < 100 millions
|
||||
@@ -1580,10 +1580,10 @@ class ToolsCore
|
||||
$img_name .= '$'.$j;
|
||||
}
|
||||
$img_name .= '$'.$j;
|
||||
fwrite($write_fd, 'RewriteRule (*UTF8)^'.str_repeat('([0-9])', $i).'(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.$img_path.$img_name.'$'.($j+1).".jpg [L]\n");
|
||||
fwrite($write_fd, 'RewriteRule ^'.str_repeat('([0-9])', $i).'(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-\pL]*\.jpg$ '._PS_PROD_IMG_.$img_path.$img_name.".jpg [L]\n");
|
||||
}
|
||||
fwrite($write_fd, 'RewriteRule (*UTF8)^c/([0-9]+)(\-[_a-zA-Z0-9-\pL]*)(-[0-9]+)?/[_a-zA-Z0-9-]*\.jpg$ img/c/$1$2$3.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule (*UTF8)^c/([a-zA-Z-]+)(-[0-9]+)?/[a-zA-Z0-9-\pL]+\.jpg$ img/c/$1$2.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule ^c/([0-9]+)(\-[_a-zA-Z0-9-\pL]*)/[_a-zA-Z0-9-]*\.jpg$ img/c/$1$2.jpg [L]'."\n");
|
||||
fwrite($write_fd, 'RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-\pL]+\.jpg$ img/c/$1.jpg [L]'."\n");
|
||||
}
|
||||
|
||||
// Redirections to dispatcher
|
||||
@@ -1702,7 +1702,7 @@ FileETag INode MTime Size
|
||||
$error = 'Parameter <b>'.$parameter.'</b> in function <b>'.$callee['function'].'()</b> is deprecated in <b>'.$callee['file'].'</b> on line <b>'.$callee['Line'].'</b><br />';
|
||||
$message = 'The parameter '.$parameter.' in function '.$callee['function'].' (Line '.$callee['Line'].') is deprecated and will be removed in the next major version.';
|
||||
|
||||
trigger_error($message, E_WARNING);
|
||||
trigger_error($message, E_WARNING);
|
||||
$class = isset($callee['class']) ? $callee['class'] : null;
|
||||
self::throwDeprecated($error, $message, $class);
|
||||
}
|
||||
@@ -2092,7 +2092,7 @@ FileETag INode MTime Size
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @params string $path Path to scan
|
||||
@@ -2108,15 +2108,15 @@ FileETag INode MTime Size
|
||||
$files = scandir($real_path);
|
||||
if (!$files)
|
||||
return array();
|
||||
|
||||
|
||||
$filtered_files = array();
|
||||
|
||||
|
||||
$real_ext = '';
|
||||
if (!empty($ext))
|
||||
$real_ext = '.' . $ext;
|
||||
|
||||
|
||||
$real_ext_length = strlen($real_ext);
|
||||
|
||||
|
||||
foreach ($files as $file)
|
||||
if (strpos($file, $real_ext) && strpos($file, $real_ext) == (strlen($file) - $real_ext_length))
|
||||
$filtered_files[] = $dir . '/' . $file;
|
||||
|
||||
@@ -982,11 +982,8 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
foreach ($imagesTypes AS $imageType)
|
||||
{
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
|
||||
if (!imageResize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).$theme.'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
if (!imageResize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']);
|
||||
}
|
||||
}
|
||||
@unlink($tmpName);
|
||||
$this->imgToDisplay = _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.'.$image->image_format;
|
||||
@@ -1007,4 +1004,4 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
else
|
||||
throw new WebserviceException('Method '.$this->wsObject->method.' is not allowed for an image resource', array(77, 405));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user