protected function manageEntityDeclinatedImages($directory, $normal_image_sizes) { $normal_image_size_names = array(); foreach ($normal_image_sizes as $normal_image_size) { $normal_image_size_names[] = $normal_image_size['name']; } // If id is detected $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']; } } // If an image id is specified if ($this->wsObject->urlSegment[3] != '') { if ($this->wsObject->urlSegment[3] == 'bin') { $currentProduct = new Product($object_id); $this->wsObject->urlSegment[3] = $currentProduct->getCoverWs(); } if (!Validate::isUnsignedId($object_id) || !in_array($this->wsObject->urlSegment[3], $available_image_ids)) { 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)); $image_size = $this->wsObject->urlSegment[4]; if (file_exists($directory . $path . '/' . $image_id . (strlen($this->wsObject->urlSegment[4]) > 0 ? '-' . $this->wsObject->urlSegment[4] : '') . '.jpg')) { $filename = $directory . $path . '/' . $image_id . (strlen($this->wsObject->urlSegment[4]) > 0 ? '-' . $this->wsObject->urlSegment[4] : '') . '.jpg'; $orig_filename = $directory . $path . '/' . $image_id . '.jpg'; } else { $orig_filename = $directory . $object_id . '-' . $image_id . '.jpg'; $filename = $directory . $object_id . '-' . $image_id . '-' . $image_size . '.jpg'; } } } else { if ($this->wsObject->method == 'GET' || $this->wsObject->method == 'HEAD') { if ($available_image_ids) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $object_id)); foreach ($available_image_ids as $available_image_id) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('declination', array(), array('id' => $available_image_id, 'xlink_resource' => $this->wsObject->wsUrl . 'images/' . $this->imageType . '/' . $object_id . '/' . $available_image_id), false); } $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image', array()); } else { $this->objOutput->setStatus(404); $this->wsObject->setOutputEnabled(false); } } } } else { $orig_filename = $directory . $object_id . '.jpg'; $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; } elseif (isset($image_size) && $image_size != '') { // Check the given size if ($this->imageType == 'products' && $image_size == 'bin') { $filename = $directory . $object_id . '-' . $image_id . '.jpg'; } elseif (!in_array($image_size, $normal_image_size_names)) { $exception = new WebserviceException('This image size does not exist', array(58, 400)); throw $exception->setDidYouMean($image_size, $normal_image_size_names); } 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; } elseif (isset($orig_filename)) { $orig_filename_exists = file_exists($orig_filename); return $this->manageDeclinatedImagesCRUD($orig_filename_exists, $orig_filename, $normal_image_sizes, $directory); } else { return $this->manageDeclinatedImagesCRUD(false, '', $normal_image_sizes, $directory); } }
/** * AuthenticationFailedException constructor. * * @param string $message * @param \Exception|null $previous */ public function __construct($message, \Exception $previous = null) { $statusCode = 403; parent::__construct($message, $statusCode, $previous); }
private function manageEntityDeclinatedImages($directory, $normal_image_sizes) { $normal_image_size_names = array(); foreach ($normal_image_sizes as $normal_image_size) { $normal_image_size_names[] = $normal_image_size['name']; } // If id is detected $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(); $images = Db::getInstance()->ExecuteS(' SELECT `id_image`, `id_product` FROM `' . _DB_PREFIX_ . 'image` WHERE id_product = ' . (int) $object_id . ' ORDER BY `position` ASC'); if ($images) { foreach ($images as $image) { $available_image_ids[] = $image['id_image']; } } // Old Behavior $nodes = scandir($directory); foreach ($nodes as $node) { // avoid too much preg_match... if ($node != '.' && $node != '..' && $node != '.svn') { preg_match('/^' . intval($object_id) . '-(\\d+)\\.jpg*$/Ui', $node, $matches); if (isset($matches[1])) { $available_image_ids[] = $matches[1]; } } } $available_image_ids = array_unique($available_image_ids); // If an image id is specified if ($this->wsObject->urlSegment[3] != '') { if ($this->wsObject->urlSegment[3] == 'bin') { $currentProduct = new Product($object_id); $this->wsObject->urlSegment[3] = $currentProduct->getCoverWs(); } if (!Validate::isUnsignedId($object_id) || !in_array($this->wsObject->urlSegment[3], $available_image_ids)) { 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)); $image_size = $this->wsObject->urlSegment[4]; if (file_exists($directory . $path . '/' . $image_id . (strlen($this->wsObject->urlSegment[4]) > 0 ? '-' . $this->wsObject->urlSegment[4] : '') . '.jpg')) { $filename = $directory . $path . '/' . $image_id . (strlen($this->wsObject->urlSegment[4]) > 0 ? '-' . $this->wsObject->urlSegment[4] : '') . '.jpg'; $orig_filename = $directory . $path . '/' . $image_id . '.jpg'; } else { $orig_filename = $directory . $object_id . '-' . $image_id . '.jpg'; $filename = $directory . $object_id . '-' . $image_id . '-' . $image_size . '.jpg'; } } } elseif ($this->wsObject->method == 'GET' || $this->wsObject->method == 'HEAD') { if ($available_image_ids) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $object_id)); foreach ($available_image_ids as $available_image_id) { $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('declination', array(), array('id' => $available_image_id, 'xlink_resource' => $this->wsObject->wsUrl . 'images/' . $this->imageType . '/' . $object_id . '/' . $available_image_id), false); } $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('image', array()); } else { $this->objOutput->setStatus(404); $this->wsObject->setOutputEnabled(false); } } } else { $orig_filename = $directory . $object_id . '.jpg'; $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; } elseif (isset($image_size) && $image_size != '') { // Check the given size if ($this->imageType == 'products' && $image_size == 'bin') { $filename = $directory . $object_id . '-' . $image_id . '.jpg'; } elseif (!in_array($image_size, $normal_image_size_names)) { $exception = new WebserviceException('This image size does not exist', array(58, 400)); throw $exception->setDidYouMean($image_size, $normal_image_size_names); } 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; } elseif (isset($orig_filename)) { $orig_filename_exists = file_exists($orig_filename); return $this->manageDeclinatedImagesCRUD($orig_filename_exists, $orig_filename, $normal_image_sizes, $directory); } else { return $this->manageDeclinatedImagesCRUD(false, '', $normal_image_sizes, $directory); } }
/** * ConnectionFailedException constructor. * * @param string $message * @param \Exception|null $previous */ public function __construct($message = "Failed connecting the client to the server", \Exception $previous = null) { parent::__construct($message, 500, $previous); }