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;
     }
 }
Example #2
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;
     }
 }
Example #3
0
 function publish($contentObjectID, $contentObjectVersion)
 {
     // fetch object
     $object = eZContentObject::fetch($contentObjectID);
     // get content class object
     $contentClass = $object->attribute('content_class');
     if ($contentClass->attribute('identifier') == 'file' || $contentClass->attribute('identifier') == 'nettopp') {
         $contentObjectAttributes = $object->contentObjectAttributes();
         $loopLenght = count($contentObjectAttributes);
         // Find image and file attribute
         for ($i = 0; $i < $loopLenght; $i++) {
             switch ($contentObjectAttributes[$i]->attribute('contentclass_attribute_identifier')) {
                 case 'image':
                     $image = $contentObjectAttributes[$i];
                     break;
                 case 'file':
                     $file = $contentObjectAttributes[$i];
                     break;
             }
         }
         if (!$file->hasContent()) {
             return;
         }
         if (!is_object($image)) {
             eZDebug::writeNotice("Image field was not found", "pdf2image");
             return;
         }
         // Get previous version and check that file has changed
         if ((int) $file->Version > 0 && $image->hasContent()) {
             $previousFile = eZContentObjectAttribute::fetch($file->ID, $file->Version - 1, true);
             if (is_object($previousFile) && $previousFile->hasContent()) {
                 if ($previousFile->content()->Filename == $file->content()->Filename) {
                     eZDebug::writeNotice("File hasn't changed", "pdf2image");
                     return;
                 }
             }
         }
         // Check that file is PDF
         if ($file->content()->MimeType != "application/pdf") {
             eZDebug::writeNotice("File not application/pdf", "pdf2image");
             return;
         }
         $source = $file->content()->filePath();
         if (!file_exists($source) or !is_readable($source)) {
             eZDebug::writeError("File not readable or doesn't exist", "pdf2image");
             return;
         }
         $page = 0;
         $width = 1000;
         $height = 1000;
         $target = eZSys::cacheDirectory() . "/" . md5(time() . 'pdf2image') . ".jpg";
         // Run conversion and redirect error to stdin
         $cmd = "convert " . "-density 200 " . eZSys::escapeShellArgument($source . "[" . $page . "]") . " " . "-colorspace rgb " . "-resize " . eZSys::escapeShellArgument($width . "x" . $height) . " " . eZSys::escapeShellArgument($target) . " 2>&1";
         eZDebug::writeNotice("Converting '" . $cmd . "'", "pdf2image");
         $out = shell_exec($cmd);
         // If we got a message somthing went wrong
         if ($out) {
             eZDebug::writeError("Conversion return error message '" . $out . "'", "pdf2image");
             // but it doesn't necessarily mean that it failed
             if (!is_readable($target)) {
                 return;
             }
         }
         // Add imagefile to image handler and save
         $imageContent = $image->content();
         $imageContent->initializeFromFile($target, $object->Name);
         if ($imageContent->isStorageRequired()) {
             $imageContent->store($image);
         }
         unlink($target);
     }
 }