Example #1
0
 function convert($manager, $sourceMimeData, &$destinationMimeData, $filters = false)
 {
     $argumentList = array();
     $executable = $this->Executable;
     if (eZSys::osType() == 'win32' and $this->ExecutableWin32) {
         $executable = $this->ExecutableWin32;
     } else {
         if (eZSys::osType() == 'mac' and $this->ExecutableMac) {
             $executable = $this->ExecutableMac;
         } else {
             if (eZSys::osType() == 'unix' and $this->ExecutableUnix) {
                 $executable = $this->ExecutableUnix;
             }
         }
     }
     if ($this->Path) {
         $executable = $this->Path . eZSys::fileSeparator() . $executable;
     }
     if (eZSys::osType() == 'win32') {
         $executable = "\"{$executable}\"";
     }
     $argumentList[] = $executable;
     if ($this->PreParameters) {
         $argumentList[] = $this->PreParameters;
     }
     $frameRangeParameters = $this->FrameRangeParameters;
     if ($frameRangeParameters && isset($frameRangeParameters[$sourceMimeData['name']])) {
         $sourceMimeData['url'] .= $frameRangeParameters[$sourceMimeData['name']];
     }
     $argumentList[] = eZSys::escapeShellArgument($sourceMimeData['url']);
     $qualityParameters = $this->QualityParameters;
     if ($qualityParameters and isset($qualityParameters[$destinationMimeData['name']])) {
         $qualityParameter = $qualityParameters[$destinationMimeData['name']];
         $outputQuality = $manager->qualityValue($destinationMimeData['name']);
         if ($outputQuality) {
             $qualityArgument = eZSys::createShellArgument($qualityParameter, array('%1' => $outputQuality));
             $argumentList[] = $qualityArgument;
         }
     }
     if ($filters !== false) {
         foreach ($filters as $filterData) {
             $argumentList[] = $this->textForFilter($filterData);
         }
     }
     $destinationURL = $destinationMimeData['url'];
     if ($this->UseTypeTag) {
         $destinationURL = $this->tagForMIMEType($destinationMimeData) . $this->UseTypeTag . $destinationURL;
     }
     $argumentList[] = eZSys::escapeShellArgument($destinationURL);
     if ($this->PostParameters) {
         $argumentList[] = $this->PostParameters;
     }
     $systemString = implode(' ', $argumentList);
     system($systemString, $returnCode);
     if ($returnCode == 0) {
         if (!file_exists($destinationMimeData['url'])) {
             eZDebug::writeError('Unknown destination file: ' . $destinationMimeData['url'] . " when executing '{$systemString}'", 'eZImageShellHandler(' . $this->HandlerName . ')');
             return false;
         }
         $this->changeFilePermissions($destinationMimeData['url']);
         return true;
     } else {
         eZDebug::writeWarning("Failed executing: {$systemString}, Error code: {$returnCode}", __METHOD__);
         return false;
     }
 }
 static function convertFilterToText($filterDefinition, $filterData)
 {
     $replaceList = array();
     if ($filterData['data']) {
         $counter = 1;
         foreach ($filterData['data'] as $data) {
             $replaceList['%' . $counter] = $data;
             ++$counter;
         }
     }
     $argumentText = $filterDefinition['text'];
     $text = eZSys::createShellArgument($argumentText, $replaceList);
     return $text;
 }
 function convert($manager, $sourceMimeData, &$destinationMimeData, $filters = false)
 {
     $argumentList = array();
     $executable = $this->Executable;
     if (eZSys::osType() == 'win32' and $this->ExecutableWin32) {
         $executable = $this->ExecutableWin32;
     } else {
         if (eZSys::osType() == 'mac' and $this->ExecutableMac) {
             $executable = $this->ExecutableMac;
         } else {
             if (eZSys::osType() == 'unix' and $this->ExecutableUnix) {
                 $executable = $this->ExecutableUnix;
             }
         }
     }
     if ($this->Path) {
         $executable = $this->Path . eZSys::fileSeparator() . $executable;
     }
     if (eZSys::osType() == 'win32') {
         $executable = "\"{$executable}\"";
     }
     $argumentList[] = $executable;
     if ($this->PreParameters) {
         $argumentList[] = $this->PreParameters;
     }
     $frameRangeParameters = $this->FrameRangeParameters;
     if ($frameRangeParameters && isset($frameRangeParameters[$sourceMimeData['name']])) {
         $sourceMimeData['url'] .= $frameRangeParameters[$sourceMimeData['name']];
     }
     // Issue EZP-21357:
     // ImageMagick has it's own meta-characters support, hence:
     //     $ convert 'File*.jpg'' ...
     // Still expand File*.jpg as the shell would do, however, this is only true for the file's basename part and not
     // for the whole path.
     $argumentList[] = eZSys::escapeShellArgument($sourceMimeData['dirpath'] . DIRECTORY_SEPARATOR . addcslashes($sourceMimeData['filename'], '~*?[]{}<>'));
     $qualityParameters = $this->QualityParameters;
     if ($qualityParameters and isset($qualityParameters[$destinationMimeData['name']])) {
         $qualityParameter = $qualityParameters[$destinationMimeData['name']];
         $outputQuality = $manager->qualityValue($destinationMimeData['name']);
         if ($outputQuality) {
             $qualityArgument = eZSys::createShellArgument($qualityParameter, array('%1' => $outputQuality));
             $argumentList[] = $qualityArgument;
         }
     }
     if ($filters !== false) {
         foreach ($filters as $filterData) {
             $argumentList[] = $this->textForFilter($filterData);
         }
     }
     $destinationURL = $destinationMimeData['url'];
     if ($this->UseTypeTag) {
         $destinationURL = $this->tagForMIMEType($destinationMimeData) . $this->UseTypeTag . $destinationURL;
     }
     $argumentList[] = eZSys::escapeShellArgument($destinationURL);
     if ($this->PostParameters) {
         $argumentList[] = $this->PostParameters;
     }
     $systemString = implode(' ', $argumentList);
     system($systemString, $returnCode);
     if ($returnCode == 0) {
         if (!file_exists($destinationMimeData['url'])) {
             eZDebug::writeError('Unknown destination file: ' . $destinationMimeData['url'] . " when executing '{$systemString}'", 'eZImageShellHandler(' . $this->HandlerName . ')');
             return false;
         }
         $this->changeFilePermissions($destinationMimeData['url']);
         return true;
     } else {
         eZDebug::writeWarning("Failed executing: {$systemString}, Error code: {$returnCode}", __METHOD__);
         return false;
     }
 }