// ImageType is now applied to a them
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11700 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -154,8 +154,11 @@ class qqUploadedFileXhr
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
foreach ($imagesTypes AS $k => $imageType)
|
||||
if (!imageResize($tmpName, $new_path.'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
{
|
||||
$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))
|
||||
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));
|
||||
|
||||
+8
-5
@@ -238,12 +238,13 @@ class ImageCore extends ObjectModel
|
||||
$new_path = $image_new->getPathForCreation();
|
||||
foreach ($images_types as $image_type)
|
||||
{
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].'.jpg'))
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].$theme.'.jpg'))
|
||||
{
|
||||
if (!Configuration::get('PS_LEGACY_IMAGES'))
|
||||
$image_new->createImgFolder();
|
||||
copy(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].'.jpg',
|
||||
$new_path.'-'.$image_type['name'].'.jpg');
|
||||
copy(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'-'.$image_type['name'].$theme.'.jpg',
|
||||
$new_path.'-'.$image_type['name'].$theme.'.jpg');
|
||||
}
|
||||
}
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$image_old->getExistingImgPath().'.jpg'))
|
||||
@@ -401,8 +402,10 @@ class ImageCore extends ObjectModel
|
||||
// Delete auto-generated images
|
||||
$image_types = ImageType::getImagesTypes();
|
||||
foreach ($image_types as $image_type)
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-'.$image_type['name'].'.'.$this->image_format;
|
||||
|
||||
{
|
||||
$theme = (Shop::isFeatureActive() ? '-'.$image_type['id_theme'] : '');
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-'.$image_type['name'].$theme.'.'.$this->image_format;
|
||||
}
|
||||
// Delete watermark image
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-watermark.'.$this->image_format;
|
||||
// delete index.php
|
||||
|
||||
+12
-7
@@ -29,6 +29,9 @@ class ImageTypeCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
/** @var string id_theme */
|
||||
public $id_theme;
|
||||
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
|
||||
@@ -63,6 +66,7 @@ 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),
|
||||
@@ -88,16 +92,17 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string|null Image type
|
||||
* @return array Image type definitions
|
||||
*/
|
||||
public static function getImagesTypes($type = NULL)
|
||||
public static function getImagesTypes($type = NULL, $id_theme = false)
|
||||
{
|
||||
if (!isset(self::$images_types_cache[$type]))
|
||||
if (!isset(self::$images_types_cache[$type.($id_theme ? '-'.$id_theme : '')]))
|
||||
{
|
||||
$where = 'WHERE 1';
|
||||
if ($id_theme)
|
||||
$where .= ' AND id_theme='.(int)$id_theme;
|
||||
if (!empty($type))
|
||||
$where = 'WHERE ' . pSQL($type) . ' = 1 ';
|
||||
else
|
||||
$where = '';
|
||||
$where .= ' AND ' . pSQL($type) . ' = 1 ';
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -114,7 +119,7 @@ class ImageTypeCore extends ObjectModel
|
||||
{
|
||||
if (!Validate::isImageTypeName($typeName))
|
||||
die(Tools::displayError());
|
||||
|
||||
|
||||
Db::getInstance()->executeS('
|
||||
SELECT `id_image_type`
|
||||
FROM `'._DB_PREFIX_.'image_type`
|
||||
|
||||
+10
-8
@@ -306,24 +306,26 @@ 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 : '').'.jpg')))
|
||||
&& (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').$theme.'.jpg')))
|
||||
|| strpos($ids, 'default') !== false)
|
||||
{
|
||||
if ($this->allow == 1)
|
||||
$uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg';
|
||||
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';
|
||||
}
|
||||
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 : '').'/'.$name.'.jpg';
|
||||
$uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').$theme.'/'.$name.'.jpg';
|
||||
else
|
||||
$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg';
|
||||
$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg';
|
||||
}
|
||||
|
||||
return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
|
||||
|
||||
+5
-5
@@ -1566,8 +1566,8 @@ class ToolsCore
|
||||
fwrite($write_fd, "# Images\n");
|
||||
if (Configuration::get('PS_LEGACY_IMAGES'))
|
||||
{
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
// Rewrite product images < 100 millions
|
||||
@@ -1580,10 +1580,10 @@ class ToolsCore
|
||||
$img_name .= '$'.$j;
|
||||
}
|
||||
$img_name .= '$'.$j;
|
||||
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)^'.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 ^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");
|
||||
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");
|
||||
}
|
||||
|
||||
// Redirections to dispatcher
|
||||
|
||||
@@ -982,8 +982,11 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
foreach ($imagesTypes AS $imageType)
|
||||
if (!imageResize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
{
|
||||
$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))
|
||||
$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;
|
||||
@@ -1004,4 +1007,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