Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $request = new Request();
     try {
         $event = new ImageEvent($request);
         $subdir = $input->getArgument('subdir');
         if (!is_null($subdir)) {
             $event->setCacheSubdirectory($subdir);
         }
         $this->getDispatcher()->dispatch(TheliaEvents::IMAGE_CLEAR_CACHE, $event);
         $output->writeln(sprintf('%s image cache successfully cleared.', is_null($subdir) ? 'Entire' : ucfirst($subdir)));
     } catch (\Exception $ex) {
         $output->writeln(sprintf("Failed to clear image cache: %s", $ex->getMessage()));
     }
 }
 /**
  * @param ProductImage $image
  * @return ImageEvent
  */
 public function createProductImageEvent(ProductImage $image)
 {
     $imageEvent = new ImageEvent($this->request);
     $baseSourceFilePath = ConfigQuery::read('images_library_path');
     if ($baseSourceFilePath === null) {
         $baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'images';
     } else {
         $baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
     }
     // Put source image file path
     $sourceFilePath = sprintf('%s/%s/%s', $baseSourceFilePath, 'product', $image->getFile());
     $imageEvent->setSourceFilepath($sourceFilePath);
     $imageEvent->setCacheSubdirectory('product');
     return $imageEvent;
 }
Exemplo n.º 3
0
 public function parseResults(LoopResult $loopResult)
 {
     // Create image processing event
     $event = new ImageEvent($this->request);
     // Prepare tranformations
     $width = $this->getWidth();
     $height = $this->getHeight();
     $rotation = $this->getRotation();
     $background_color = $this->getBackgroundColor();
     $quality = $this->getQuality();
     $effects = $this->getEffects();
     if (!is_null($effects)) {
         $effects = explode(',', $effects);
     }
     switch ($this->getResizeMode()) {
         case 'crop':
             $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
             break;
         case 'borders':
             $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
             break;
         case 'none':
         default:
             $resize_mode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
     }
     foreach ($loopResult->getResultDataCollection() as $result) {
         // Setup required transformations
         if (!is_null($width)) {
             $event->setWidth($width);
         }
         if (!is_null($height)) {
             $event->setHeight($height);
         }
         $event->setResizeMode($resize_mode);
         if (!is_null($rotation)) {
             $event->setRotation($rotation);
         }
         if (!is_null($background_color)) {
             $event->setBackgroundColor($background_color);
         }
         if (!is_null($quality)) {
             $event->setQuality($quality);
         }
         if (!is_null($effects)) {
             $event->setEffects($effects);
         }
         // Put source image file path
         $source_filepath = sprintf("%s%s/%s/%s", THELIA_ROOT, ConfigQuery::read('images_library_path', 'local' . DS . 'media' . DS . 'images'), $this->objectType, $result->getFile());
         $event->setSourceFilepath($source_filepath);
         $event->setCacheSubdirectory($this->objectType);
         $loopResultRow = new LoopResultRow($result);
         $loopResultRow->set("ID", $result->getId())->set("LOCALE", $this->locale)->set("ORIGINAL_IMAGE_PATH", $source_filepath)->set("TITLE", $result->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $result->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $result->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $result->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("VISIBLE", $result->getVisible())->set("POSITION", $result->getPosition())->set("OBJECT_TYPE", $this->objectType)->set("OBJECT_ID", $this->objectId);
         $addRow = true;
         $returnErroredImages = $this->getBackendContext() || !$this->getIgnoreProcessingErrors();
         try {
             // Dispatch image processing event
             $this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
             $loopResultRow->set("IMAGE_URL", $event->getFileUrl())->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())->set("IMAGE_PATH", $event->getCacheFilepath())->set("PROCESSING_ERROR", false);
         } catch (\Exception $ex) {
             // Ignore the result and log an error
             Tlog::getInstance()->addError(sprintf("Failed to process image in image loop: %s", $ex->getMessage()));
             if ($returnErroredImages) {
                 $loopResultRow->set("IMAGE_URL", '')->set("ORIGINAL_IMAGE_URL", '')->set("IMAGE_PATH", '')->set("PROCESSING_ERROR", true);
             } else {
                 $addRow = false;
             }
         }
         if ($addRow) {
             $this->addOutputFields($loopResultRow, $result);
             $loopResult->addRow($loopResultRow);
         }
     }
     return $loopResult;
 }
Exemplo n.º 4
0
 /**
  * Try to clear directory ouside of the cache
  *
  * @expectedException \InvalidArgumentException
  */
 public function testClearUnallowedPathCache()
 {
     $event = new ImageEvent($this->request);
     $event->setDispatcher($this->getDispatcher());
     $event->setCacheSubdirectory('../../../..');
     $image = new Image($this->getFileManager());
     $image->clearCache($event);
 }
Exemplo n.º 5
0
 /**
  * @param $type
  * @param RewritingUrl $result
  * @param $configValues
  * @param $sitemap
  */
 protected function generateSitemapImage($type, $result, $configValues, &$sitemap)
 {
     $event = new ImageEvent();
     $event->setWidth($configValues['width'])->setHeight($configValues['height'])->setQuality($configValues['quality'])->setRotation($configValues['rotation'])->setResizeMode($configValues['resizeMode'])->setBackgroundColor($configValues['bgColor'])->setAllowZoom($configValues['allowZoom']);
     // Put source image file path
     $source_filepath = sprintf("%s%s/%s/%s", THELIA_ROOT, ConfigQuery::read('images_library_path', 'local/media/images'), $type, $result->getVirtualColumn('PRODUCT_FILE'));
     $event->setSourceFilepath($source_filepath);
     $event->setCacheSubdirectory($type);
     try {
         // Dispatch image processing event
         $this->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
         // New sitemap image entry
         $sitemap[] = '
         <url>
             <loc>' . URL::getInstance()->absoluteUrl($result->getUrl()) . '</loc>
             <image:image>
                 <image:loc>' . $event->getFileUrl() . '</image:loc>
                 <image:title>' . htmlspecialchars($result->getVirtualColumn('PRODUCT_TITLE')) . '</image:title>
             </image:image>
         </url>';
     } catch (\Exception $ex) {
     }
 }