Esempio n. 1
0
 /**
  * Produce a diff (using the "diff" application) between two strings
  * The function will write the two input strings to temporary files, then execute the diff program, delete the temp files and return the result.
  *
  * @param string $str1 String 1
  * @param string $str2 String 2
  * @return array The result from the exec() function call.
  * @access private
  */
 public function getDiff($str1, $str2)
 {
     // Create file 1 and write string
     $file1 = GeneralUtility::tempnam('diff1_');
     GeneralUtility::writeFile($file1, $str1);
     // Create file 2 and write string
     $file2 = GeneralUtility::tempnam('diff2_');
     GeneralUtility::writeFile($file2, $str2);
     // Perform diff.
     $cmd = $GLOBALS['TYPO3_CONF_VARS']['BE']['diff_path'] . ' ' . $this->diffOptions . ' ' . $file1 . ' ' . $file2;
     $res = array();
     CommandUtility::exec($cmd, $res);
     unlink($file1);
     unlink($file2);
     return $res;
 }
Esempio n. 2
0
 /**
  * @param string|null $imageSource
  * @throws Exception
  */
 public function preprocessImage($imageSource = null)
 {
     $src = null === $imageSource ? $this->arguments['src'] : $imageSource;
     $width = $this->arguments['width'];
     $height = $this->arguments['height'];
     $minW = $this->arguments['minW'];
     $minH = $this->arguments['minH'];
     $maxW = $this->arguments['maxW'];
     $maxH = $this->arguments['maxH'];
     $format = $this->arguments['format'];
     $quality = $this->arguments['quality'];
     $treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
     $crop = $this->arguments['crop'];
     if (is_object($src) && $src instanceof FileReference) {
         $src = $src->getUid();
         $treatIdAsReference = true;
     }
     if ($crop === null) {
         $crop = is_object($src) && $src instanceof FileReference ? $src->getProperty('crop') : null;
     }
     if ('BE' === TYPO3_MODE) {
         $this->simulateFrontendEnvironment();
     }
     $setup = ['width' => $width, 'height' => $height, 'minW' => $minW, 'minH' => $minH, 'maxW' => $maxW, 'maxH' => $maxH, 'treatIdAsReference' => $treatIdAsReference, 'crop' => $crop];
     if (false === empty($format)) {
         $setup['ext'] = $format;
     }
     if (0 < (int) $quality) {
         $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
         $setup['params'] = '-quality ' . $quality;
     }
     if (TYPO3_MODE === 'BE' && strpos($src, '../') === 0) {
         $src = substr($src, 3);
     }
     $this->imageInfo = $this->contentObject->getImgResource($src, $setup);
     $GLOBALS['TSFE']->lastImageInfo = $this->imageInfo;
     if (false === is_array($this->imageInfo)) {
         throw new Exception('Could not get image resource for "' . htmlspecialchars($src) . '".', 1253191060);
     }
     if ($this->hasArgument('canvasWidth') && $this->hasArgument('canvasHeight')) {
         $canvasWidth = (int) $this->arguments['canvasWidth'];
         $canvasHeight = (int) $this->arguments['canvasHeight'];
         $canvasColor = str_replace('#', '', $this->arguments['canvasColor']);
         $originalFilename = $this->imageInfo[3];
         $originalExtension = substr($originalFilename, -3);
         $destinationFilename = 'typo3temp/vhs-canvas-' . md5($originalFilename . $canvasColor . $canvasWidth . $canvasHeight) . '.' . $originalExtension;
         $destinationFilepath = GeneralUtility::getFileAbsFileName($destinationFilename);
         if (!file_exists($destinationFilepath)) {
             $arguments = sprintf('%s -background \'#%s\' -gravity center -extent %dx%d %s', $originalFilename, $canvasColor, $canvasWidth, $canvasHeight, $destinationFilepath);
             $command = CommandUtility::imageMagickCommand('convert', $arguments);
             CommandUtility::exec($command);
         }
         $this->imageInfo[3] = $destinationFilename;
     }
     $GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
     $GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
     $publicUrl = rawurldecode($this->imageInfo[3]);
     $this->mediaSource = GeneralUtility::rawUrlEncodeFP($publicUrl);
     if (TYPO3_MODE === 'BE') {
         $this->resetFrontendEnvironment();
     }
 }