// Merge -> revision 9124

This commit is contained in:
rMalie
2011-10-07 09:54:43 +00:00
parent 22d560688d
commit d46fbbc039
56 changed files with 1682 additions and 1656 deletions
+44 -43
View File
@@ -73,11 +73,11 @@ class CategoryCore extends ObjectModel
/** @var string Object last modification date */
public $date_upd;
protected $langMultiShop = true;
public $groupBox;
protected static $_links = array();
protected $tables = array ('category', 'category_lang');
@@ -132,12 +132,12 @@ class CategoryCore extends ObjectModel
$fields['date_upd'] = pSQL($this->date_upd);
return $fields;
}
/**
* Allows to display the category description without HTML tags and slashes
*
* @return string
*/
*/
public static function getDescriptionClean($description)
{
return strip_tags(stripslashes($description));
@@ -176,8 +176,8 @@ class CategoryCore extends ObjectModel
/**
* update category positions in parent
*
* @param mixed $nullValues
*
* @param mixed $nullValues
* @return void
*/
public function update($nullValues = false)
@@ -332,7 +332,7 @@ class CategoryCore extends ObjectModel
self::regenerateEntireNtree();
Module::hookExec('categoryDeletion', array('category' => $this));
/* Delete Categories in GroupReduction */
foreach ($toDelete AS $category)
if (GroupReduction::getGroupReductionByCategoryId((int)$category))
@@ -420,8 +420,8 @@ class CategoryCore extends ObjectModel
{
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
UPDATE '._DB_PREFIX_.'category
SET level_depth = '.($level['level_depth'] + 1).'
WHERE id_category = '.$sub_category['id_category']);
SET level_depth = '.(int)($level['level_depth'] + 1).'
WHERE id_category = '.(int)$sub_category['id_category']);
/* Recursive call */
$this->recalculateLevelDepth($sub_category['id_category']);
}
@@ -522,7 +522,7 @@ class CategoryCore extends ObjectModel
if (!$context)
$context = Context::getContext();
if (!$checkAccess OR !$this->checkAccess($context->customer->id))
return false;
return false;
if ($p < 1) $p = 1;
@@ -531,7 +531,7 @@ class CategoryCore extends ObjectModel
else
/* Fix for all modules which are now using lowercase values for 'orderBy' parameter */
$orderBy = strtolower($orderBy);
if (empty($orderWay))
$orderWay = 'ASC';
if ($orderBy == 'id_product' OR $orderBy == 'date_add')
@@ -635,7 +635,7 @@ class CategoryCore extends ObjectModel
* @param int $id_parent
* @param int $id_lang
* @param bool $active
* @return array
* @return array
*/
public static function getChildren($id_parent, $id_lang, $active = true)
{
@@ -653,7 +653,7 @@ class CategoryCore extends ObjectModel
}
/** return an array of all children of the current category
*
*
* @return array rows of table category
* @todo return hydrateCollection
*/
@@ -667,27 +667,28 @@ class CategoryCore extends ObjectModel
/**
* This method allow to return children categories with the number of sub children selected for a product
*
*
* @param int $id_parent
* @param int $id_product
* @param int $id_lang
* @return array
* @return array
*/
public static function getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang, Shop $shop = null)
{
if (!$shop)
$shop = Context::getContext()->shop;
$selectedCat = explode(',', str_replace(' ', '', $selectedCat));
$sql = 'SELECT c.`id_category`, c.`level_depth`, cl.`name`, IF((
SELECT COUNT(*)
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'category` c2
WHERE c2.`id_parent` = c.`id_category`
) > 0, 1, 0) AS has_children, '.($selectedCat ? '(
SELECT count(c3.`id_category`)
FROM `'._DB_PREFIX_.'category` c3
WHERE c3.`nleft` > c.`nleft`
SELECT count(c3.`id_category`)
FROM `'._DB_PREFIX_.'category` c3
WHERE c3.`nleft` > c.`nleft`
AND c3.`nright` < c.`nright`
AND c3.`id_category` IN ('.pSQL($selectedCat).')
AND c3.`id_category` IN ('.implode(',', array_map('intval', $selectedCat)).')
)' : '0').' AS nbSelectedSubCat
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.$shop->sqlLang('cl').'
@@ -696,7 +697,7 @@ class CategoryCore extends ObjectModel
ORDER BY `position` ASC';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
/**
* Copy products from a category to another
*
@@ -894,7 +895,7 @@ class CategoryCore extends ObjectModel
$groups[] = $group['id_group'];
return $groups;
}
public function addGroupsIfNoExist($id_group)
{
$groups = $this->getGroups();
@@ -909,8 +910,8 @@ class CategoryCore extends ObjectModel
/**
* checkAccess return true if id_customer is in a group allowed to see this category.
*
* @param mixed $id_customer
*
* @param mixed $id_customer
* @access public
* @return boolean true if access allowed for customer $id_customer
*/
@@ -966,7 +967,7 @@ class CategoryCore extends ObjectModel
foreach ($res AS $category)
if ((int)($category['id_category']) == (int)($this->id))
$movedCategory = $category;
if (!isset($movedCategory) || !isset($position))
return false;
// < and > statements rather than BETWEEN operator
@@ -992,8 +993,8 @@ class CategoryCore extends ObjectModel
* cleanPositions keep order of category in $id_category_parent,
* but remove duplicate position. Should not be used if positions
* are clean at the beginning !
*
* @param mixed $id_category_parent
*
* @param mixed $id_category_parent
* @return boolean true if succeed
*/
public static function cleanPositions($id_category_parent)
@@ -1018,7 +1019,7 @@ class CategoryCore extends ObjectModel
}
/** this function return the number of category + 1 having $id_category_parent as parent.
*
*
* @todo rename that function to make it understandable (getNewLastPosition for example)
* @param int $id_category_parent the parent category
* @return int
@@ -1027,7 +1028,7 @@ class CategoryCore extends ObjectModel
{
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.(int)($id_category_parent)));
}
public static function getUrlRewriteInformations($id_category)
{
return Db::getInstance()->ExecuteS('
@@ -1038,10 +1039,10 @@ class CategoryCore extends ObjectModel
AND l.`active` = 1'
);
}
/**
* Return nleft and nright fields for a given category
*
*
* @since 1.5.0
* @param int $id
* @return array
@@ -1072,7 +1073,7 @@ class CategoryCore extends ObjectModel
return false;
return ($this->nleft >= $interval['nleft'] && $this->nright <= $interval['nright']);
}
public function getChildrenWs()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -1083,7 +1084,7 @@ class CategoryCore extends ObjectModel
ORDER BY `position` ASC');
return $result;
}
public function getProductsWs()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -1093,10 +1094,10 @@ class CategoryCore extends ObjectModel
ORDER BY `position` ASC');
return $result;
}
/**
* Search for another category with the same parent and the same position
*
*
* @return array first category found
*/
public function getDuplicatePosition()
@@ -1108,7 +1109,7 @@ class CategoryCore extends ObjectModel
AND `position` = '.(int)($this->position).'
AND c.`id_category` != '.(int)($this->id));
}
public function getWsNbProductsRecursive()
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
@@ -1121,12 +1122,12 @@ class CategoryCore extends ObjectModel
return -1;
return $result[0]['nb_product_recursive'];
}
/**
*
* @param Array $ids_category
* @param int $id_lang
* @return Array
* @return Array
*/
public static function getCategoryInformations($ids_category, $id_lang = null)
{
@@ -1135,19 +1136,19 @@ class CategoryCore extends ObjectModel
if (!is_array($ids_category) || !sizeof($ids_category))
return;
$categories = array();
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, cl.`id_lang`
FROM `'._DB_PREFIX_.'category` c
SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`, cl.`id_lang`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Context::getContext()->shop->sqlLang('cl').')
WHERE cl.`id_lang` = '.(int)$id_lang.'
AND c.`id_category` IN ('.implode(',', array_map('intval', $ids_category)).')
');
foreach($results as $category)
$categories[$category['id_category']] = $category;
return $categories;
}
}
+1 -1
View File
@@ -412,7 +412,7 @@ class FrontControllerCore extends Controller
protected function canonicalRedirection($canonicalURL = '')
{
if (!$canonicalURL || !Configuration::get('PS_CANONICAL_REDIRECT'))
if (!$canonicalURL || !Configuration::get('PS_CANONICAL_REDIRECT') || strtoupper($_SERVER['REQUEST_METHOD']) != 'GET')
return;
$matchUrl = (($this->ssl && Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
+1 -1
View File
@@ -339,7 +339,7 @@ class SearchCore
protected static function getProductsToIndex($nbLanguages, $limit = 50)
{
// Adjust the limit to get only "whole" products, in every languages (and at least one)
$limit = min(1, round($limit / $nbLanguages) * $nbLanguages);
$limit = max(1, round($limit / $nbLanguages) * $nbLanguages);
return Db::getInstance()->ExecuteS('
SELECT p.id_product, pl.id_lang, pl.name pname, p.reference, p.ean13, p.upc, pl.description_short, pl.description, cl.name cname, m.name mname
FROM '._DB_PREFIX_.'product p
+7
View File
@@ -120,6 +120,13 @@ class StoreCore extends ObjectModel
return $fields;
}
public function __construct($id_store = NULL, $id_lang = NULL)
{
parent::__construct($id_store, $id_lang);
$this->id_image = ($this->id AND file_exists(_PS_STORE_IMG_DIR_.(int)$this->id.'.jpg')) ? (int)$this->id : false;
$this->image_dir = _PS_STORE_IMG_DIR_;
}
public function getWsHours()
{
return implode(';', unserialize($this->hours));
+5 -9
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,20 +25,16 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceExceptionCore extends Exception
{
protected $status;
protected $wrong_value;
protected $available_values;
protected $type;
const SIMPLE = 0;
const DID_YOU_MEAN = 1;
public function __construct($message, $code)
{
$exception_code = $code;
@@ -52,12 +48,12 @@ class WebserviceExceptionCore extends Exception
}
public function getType()
{
return $this->type;
return $this->type;
}
public function setType($type)
{
$this->type = $type;
return $this;
return $this;
}
public function setStatus($status)
{
@@ -27,7 +27,6 @@
/**
* @todo : Create typed exception for more finer errors check
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceOutputBuilderCore
{
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,10 +25,6 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
interface WebserviceOutputInterface
{
public function __construct($languages = array());
+9 -13
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,29 +25,25 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceOutputXMLCore implements WebserviceOutputInterface
{
public $docUrl = '';
public $languages = array();
protected $wsUrl;
protected $schemaToDisplay;
public function setSchemaToDisplay($schema)
{
if (is_string($schema))
$this->schemaToDisplay = $schema;
return $this;
}
public function getSchemaToDisplay()
{
return $this->schemaToDisplay;
}
public function setWsUrl($url)
{
$this->wsUrl = $url;
@@ -98,10 +94,10 @@ class WebserviceOutputXMLCore implements WebserviceOutputInterface
foreach ($this->languages as $language)
{
$more_attr = '';
if (isset($field['synopsis_details']) || (isset($field['value']) AND is_array($field['value'])))
if (isset($field['synopsis_details']) || (isset($field['value']) AND is_array($field['value'])))
{
$more_attr .= ' xlink:href="'.$this->getWsUrl().'languages/'.$language.'"';
if (isset($field['synopsis_details']) && $this->schemaToDisplay != 'blank')
if (isset($field['synopsis_details']) && $this->schemaToDisplay != 'blank')
$more_attr .= ' format="isUnsignedId" ';
}
$node_content .= '<language id="'.$language.'"'.$more_attr.'>';
@@ -121,11 +117,11 @@ class WebserviceOutputXMLCore implements WebserviceOutputInterface
$ret .= ' xlink:href="'.$this->getWsUrl().$field['xlink_resource']['resourceName'].'/'.
(isset($field['xlink_resource']['subResourceName']) ? $field['xlink_resource']['subResourceName'].'/'.$field['object_id'].'/' : '').$field['value'].'"';
}
if (isset($field['getter']) && $this->schemaToDisplay != 'blank')
$ret .= ' not_filterable="true"';
if ($field['value'] != '')
if ($field['value'] != '')
$node_content .= '<![CDATA['.$field['value'].']]>';
}
if (isset($field['synopsis_details']) && !empty($field['synopsis_details']) && $this->schemaToDisplay !== 'blank')
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,21 +25,17 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManagementInterface
{
protected $objOutput;
protected $output;
protected $wsObject;
/**
* @var string The extension of the image to display
*/
protected $imgExtension = 'jpg';
/**
* @var array The type of images (general, categories, manufacturers, suppliers, stores...)
*/
@@ -56,64 +52,64 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
'suppliers' => array(),
'stores' => array()
);
/**
* @var string The image type (product, category, general,...)
*/
private $imageType = NULL;
/**
* @var int The maximum size supported when uploading images, in bytes
*/
private $imgMaxUploadSize = 3000000;
/**
* @var array The list of supported mime types
*/
protected $acceptedImgMimeTypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
/**
* @var string The product image declination id
*/
protected $productImageDeclinationId = NULL;
/**
* @var boolean If the current image management has to manage a "default" image (i.e. "No product available")
*/
protected $defaultImage = false;
/**
* @var string The file path of the image to display. If not null, the image will be displayed, even if the XML output was not empty
*/
public $imgToDisplay = null;
public $imageResource = null;
// ------------------------------------------------
// GETTERS & SETTERS
// ------------------------------------------------
public function setObjectOutput(WebserviceOutputBuilderCore $obj)
{
$this->objOutput = $obj;
return $this;
}
public function getObjectOutput()
{
return $this->objOutput;
}
public function setWsObject(WebserviceRequestCore $obj)
{
$this->wsObject = $obj;
return $this;
}
public function getWsObject()
{
return $this->wsObject;
}
/*
* This method need $this->imgToDisplay to be set if output don't needs to be XML
*/
@@ -142,23 +138,23 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
}
}
}
public function manage()
{
$this->manageImages();
return $this->wsObject->getOutputEnabled();
}
/**
* Management of images URL segment
*
*
* @return boolean
*/
private function manageImages()
{
/*
* available cases api/... :
*
*
* images ("types_list") (N-1)
* GET (xml)
* images/general ("general_list") (N-2)
@@ -166,9 +162,9 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
* images/general/[header,+] ("general") (N-3)
* GET (bin)
* PUT (bin)
*
*
* images/[categories,+] ("normal_list") (N-2) ([categories,+] = categories, manufacturers, ...)
*
*
* images/[categories,+] ("normal_list") (N-2) ([categories,+] = categories, manufacturers, ...)
* GET (xml)
* images/[categories,+]/[1,+] ("normal") (N-3)
* GET (bin)
@@ -186,7 +182,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
* DELETE
* images/[categories,+]/default/[en,+]/[small,+] ("normal_default_i18n_resized") (N-5)
* GET (bin)
*
*
* images/product ("product_list") (N-2)
* GET (xml) (list of image)
* images/product/[1,+] ("product_description") (N-3)
@@ -214,10 +210,10 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
* DELETE
* images/product/default/[en,+]/[small,+] ("product_default_i18n_resized") (N-5)
* GET (bin)
*
*
*/
/* Declinated
*ok GET (bin)
*ok images/product ("product_list") (N-2)
@@ -247,18 +243,18 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
* DELETE
*ok images/product/default/[en,+]/[small,+] ("product_default_i18n_resized") (N-5)
*ok GET (bin)
*
*
* */
// Pre configuration...
if(isset($this->wsObject->urlSegment))
for ($i = 1; $i < 6; $i++)
if (count($this->wsObject->urlSegment) == $i)
$this->wsObject->urlSegment[$i] = '';
$this->imageType = $this->wsObject->urlSegment[1];
switch ($this->wsObject->urlSegment[1])
{
// general images management : like header's logo, invoice logo, etc...
@@ -287,12 +283,12 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
}
return $this->manageDeclinatedImages($directory);
break;
// product image management : many image for one entity (product)
case 'products':
return $this->manageProductImages();
break;
// images root node management : many image for one entity (product)
case '':
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_types', array());
@@ -308,7 +304,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image_types', array());
return true;
break;
default:
$exception = new WebserviceException(sprintf('Image of type "%s" does not exists', $this->wsObject->urlSegment[1]), array(48, 400));
throw $exception->setDidYouMean($this->wsObject->urlSegment[1], array_keys($this->imageTypes));
@@ -316,7 +312,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
}
/**
* Management of general images
*
*
* @return boolean
*/
private function manageGeneralImages()
@@ -332,7 +328,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
else
throw new WebserviceException('This method is not allowed with general image resources.', array(49, 405));
break;
// Set the image path on display in relation to the mail image
case 'mail':
if (in_array($this->wsObject->method, array('GET','HEAD','PUT')))
@@ -343,7 +339,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
else
throw new WebserviceException('This method is not allowed with general image resources.', array(50, 405));
break;
// Set the image path on display in relation to the invoice image
case 'invoice':
if (in_array($this->wsObject->method, array('GET','HEAD','PUT')))
@@ -354,7 +350,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
else
throw new WebserviceException('This method is not allowed with general image resources.', array(51, 405));
break;
// Set the image path on display in relation to the icon store image
case 'store_icon':
if (in_array($this->wsObject->method, array('GET','HEAD','PUT')))
@@ -365,7 +361,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
else
throw new WebserviceException('This method is not allowed with general image resources.', array(52, 405));
break;
// List the general image types
case '':
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('general_image_types', array());
@@ -381,7 +377,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('general_image_types', array());
return true;
break;
// If the image type does not exist...
default:
$exception = new WebserviceException(sprintf('General image of type "%s" does not exists', $this->wsObject->urlSegment[2]), array(53, 400));
@@ -396,7 +392,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
return true;
break;
case 'PUT':
if ($this->writePostedImageOnDisk($path, NULL, NULL))
{
if ($this->wsObject->urlSegment[2] == 'header')
@@ -413,7 +409,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
break;
}
}
private function manageDefaultDeclinatedImages($directory, $normal_image_sizes)
{
$this->defaultImage = true;
@@ -427,7 +423,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$defaultLang = $lang['iso_code'];
$langs[] = $lang['iso_code'];
}
// Display list of languages
if($this->wsObject->urlSegment[3] == '' && $this->wsObject->method == 'GET')
{
@@ -442,7 +438,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
);
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('language', array(), $more_attr, false);
}
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('languages', array());
return true;
}
@@ -458,19 +454,19 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
return $this->manageDeclinatedImagesCRUD($filename_exists, $filename, $normal_image_sizes, $directory);// @todo : [feature] @see todo#1
}
}
private function manageListDeclinatedImages($directory, $normal_image_sizes)
{
// Check if method is allowed
if ($this->wsObject->method != 'GET')
throw new WebserviceException('This method is not allowed for listing category images.', array(55, 405));
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_types', array());
foreach ($normal_image_sizes as $image_size)
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_type', array(), array('id' => $image_size['id_image_type'], 'name' => $image_size['name'], 'xlink_resource'=>$this->wsObject->wsUrl.'image_types/'.$image_size['id_image_type']), false);
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image_types', array());
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('images', array());
if ($this->imageType == 'products')
{
$ids = array();
@@ -505,7 +501,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('images', array());
return true;
}
private function manageEntityDeclinatedImages($directory, $normal_image_sizes)
{
$normal_image_size_names = array();
@@ -515,20 +511,20 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$object_id = $this->wsObject->urlSegment[2];
if (!Validate::isUnsignedId($object_id))
throw new WebserviceException('The image id is invalid. Please set a valid id or the "default" value', array(60, 400));
// For the product case
if ($this->imageType == 'products')
{
// Get available image ids
$available_image_ids = array();
// New Behavior
$languages = Language::getLanguages();
foreach ($languages as $language)
foreach (Image::getImages($language['id_lang'], $object_id) as $image)
$available_image_ids[] = $image['id_image'];
// Old Behavior
$nodes = scandir($directory);
foreach ($nodes as $node)
@@ -539,7 +535,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
if (isset($matches[1]))
$available_image_ids[] = $matches[1];
}
// If an image id is specified
if ($this->wsObject->urlSegment[3] != '')
{
@@ -552,7 +548,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
throw new WebserviceException('This image id does not exist', array(57, 400));
else
{
// Check for new image system
$image_id = $this->wsObject->urlSegment[3];
$path = implode('/', str_split((string)$image_id));
@@ -586,7 +582,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$this->wsObject->setOutputEnabled(false);
}
}
}
// for all other cases
else
@@ -595,16 +591,16 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$image_size = $this->wsObject->urlSegment[3];
$filename = $directory.$object_id.'-'.$image_size.'.jpg';
}
// in case of declinated images list of a product is get
if ($this->output != '')
return true;
// If a size was given try to display it
elseif (isset($image_size) && $image_size != '')
{
// Check the given size
if ($this->imageType == 'products' && $image_size == 'bin')
$filename = $directory.$object_id.'-'.$image_id.'.jpg';
@@ -615,7 +611,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
}
if (!file_exists($filename))
throw new WebserviceException('This image does not exist on disk', array(59, 500));
// Display the resized specific image
$this->imgToDisplay = $filename;
return true;
@@ -634,7 +630,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
/**
* Management of normal images (as categories, suppliers, manufacturers and stores)
*
*
* @param string $directory the file path of the root of the images folder type
* @return boolean
*/
@@ -656,17 +652,17 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
return $this->manageEntityDeclinatedImages($directory, $normal_image_sizes);
break;
}
}
private function manageProductImages()
{
$this->manageDeclinatedImages(_PS_PROD_IMG_DIR_);
}
/**
* Management of normal images CRUD
*
*
* @param boolean $filename_exists if the filename exists
* @param string $filename the image path
* @param array $imageSizes The
@@ -726,14 +722,14 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
throw new WebserviceException('Unable to save this image', array(66, 500));
}
break;
default :
default :
throw new WebserviceException('This method is not allowed', array(67, 405));
}
}
/**
* Delete the image on disk
*
*
* @param string $filePath the image file path
* @param array $imageTypes The differents sizes
* @param string $parentPath The parent path
@@ -770,10 +766,10 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
return false;
}
}
/**
* Write the image on disk
*
*
* @param string $basePath
* @param string $newPath
* @param int $destWidth
@@ -802,10 +798,10 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$sourceImage = imagecreatefromjpeg($basePath);
break;
}
$widthDiff = $destWidth / $sourceWidth;
$heightDiff = $destHeight / $sourceHeight;
if ($widthDiff > 1 AND $heightDiff > 1)
{
$nextWidth = $sourceWidth;
@@ -826,10 +822,10 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$destHeight = ((int)(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destHeight : $nextHeight);
}
}
$borderWidth = (int)(($destWidth - $nextWidth) / 2);
$borderHeight = (int)(($destHeight - $nextHeight) / 2);
// Build the image
if (
!($destImage = imagecreatetruecolor($destWidth, $destHeight)) ||
@@ -839,7 +835,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
!imagecolortransparent($destImage, $white)
)
throw new WebserviceException(sprintf('Unable to build the image "%s".', str_replace(_PS_ROOT_DIR_, '[SHOP_ROOT_DIR]', $newPath)), array(69, 500));
// Write it on disk
$imaged = false;
switch ($this->imgExtension)
@@ -858,7 +854,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
imagedestroy($destImage);
if (!$imaged)
throw new WebserviceException(sprintf('Unable to write the image "%s".', str_replace(_PS_ROOT_DIR_, '[SHOP_ROOT_DIR]', $newPath)), array(70, 500));
// Write image declinations if present
if ($imageTypes)
{
@@ -881,10 +877,10 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
}
return $newPath;
}
/**
* Write the posted image on disk
*
*
* @param string $sreceptionPath
* @param int $destWidth
* @param int $destHeight
@@ -918,14 +914,14 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
$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));
// Check error while uploading
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') OR !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName))
throw new WebserviceException('Error while copying image to the temporary directory', array(75, 400));
@@ -965,19 +961,19 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
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 = checkImage($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') OR !move_uploaded_file($file['tmp_name'], $tmpName))
throw new WebserviceException('An error occurred during the image upload', array(76, 400));
elseif (!imageResize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'.'.$image->image_format))
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,22 +25,18 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
interface WebserviceSpecificManagementInterface
{
public function setObjectOutput(WebserviceOutputBuilderCore $obj);
public function getObjectOutput();
public function setWsObject(WebserviceRequestCore $obj);
public function getWsObject();
public function manage();
/**
* This must be return an array with specific values as WebserviceRequest expects.
*
*
* @return array
*/
public function getContent();
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,32 +25,28 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @author Lucas Cherifi - Nans Pellicari - Anatole Korczak - PrestaShop Team
*/
class WebserviceSpecificManagementSearchCore implements WebserviceSpecificManagementInterface
{
protected $objOutput;
protected $output;
protected $wsObject;
// ------------------------------------------------
// GETTERS & SETTERS
// ------------------------------------------------
public function setObjectOutput(WebserviceOutputBuilderCore $obj)
{
$this->objOutput = $obj;
return $this;
}
public function setWsObject(WebserviceRequestCore $obj)
{
$this->wsObject = $obj;
return $this;
}
public function getWsObject()
{
return $this->wsObject;
@@ -59,36 +55,36 @@ class WebserviceSpecificManagementSearchCore implements WebserviceSpecificManage
{
return $this->objOutput;
}
public function setUrlSegment($segments)
{
$this->urlSegment = $segments;
return $this;
}
public function getUrlSegment()
{
return $this->urlSegment;
}
/**
* Management of search
*
*
*/
public function manage()
{
if (!isset($this->wsObject->urlFragments['query']) || !isset($this->wsObject->urlFragments['language']))
throw new WebserviceException('You have to set both the \'language\' and \'query\' parameters to get a result', array(100, 400));
$objects_products = array();
$objects_categories = array();
$objects_categories = array();
$objects_products['empty'] = new Product();
$objects_categories['empty'] = new Category();
$this->_resourceConfiguration = $objects_products['empty']->getWebserviceParameters();
if (!$this->wsObject->setFieldsToDisplay())
return false;
$results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1, 1, 'position', 'desc', true, false);
$categories = array();
foreach ($results AS $result)
@@ -109,13 +105,13 @@ class WebserviceSpecificManagementSearchCore implements WebserviceSpecificManage
// $this->_resourceConfiguration = $objects_categories['empty']->getWebserviceParameters();
// if (!$this->setFieldsToDisplay())
// return false;
$this->output .= $this->objOutput->getContent($objects_categories, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
}
/**
* This must be return an array with specific values as WebserviceRequest expects.
*
*
* @return array
*/
public function getContent()