public function convert($bin, Plugin\InterfaceCommand $command = null)
 {
     $source = tempnam($this->tempPath, "ooconverter_");
     chmod($source, 0664);
     $destination = $source . '.' . $this->targetContentType->standardExtension();
     file_put_contents($source, $bin);
     $out = exec('python ' . __DIR__ . '/../../../../externals/pyodconverter/DocumentConverter.py ' . "{$source} {$destination}");
     unlink($source);
     if (!is_file($destination)) {
         throw new OpenOfficeException($out);
     }
     $bin = file_get_contents($destination);
     unlink($destination);
     return $bin;
 }
 public function convert($bin, Plugin\InterfaceCommand $command = null)
 {
     $shellCommand = new ShellCommand($command);
     $source = tempnam($this->tempPath, "imagemagick_");
     chmod($source, 0664);
     $destination = $source . '.' . $this->targetContentType->standardExtension();
     file_put_contents($source, $bin);
     exec('convert ' . $source . ' ' . strval($shellCommand) . ' ' . $destination);
     if (is_file($destination)) {
         $bin = file_get_contents($destination);
         unlink($destination);
     }
     unlink($source);
     return $bin;
 }
    private static function classCode($className, $newConverterPhp, ContentType $destinationContentType, $tempDirectory, $newCommandPhp = null)
    {
        $commandInitialization = null;
        if (!is_null($newCommandPhp)) {
            $newCommandPhp = rtrim($newCommandPhp, ';') . ';';
            $commandInitialization = <<<PHP
\$this->command = {$newCommandPhp}
        \$this->command->configure(\$commandString);
        if (!\$this->command->conforms(\$commandString)) {
            throw new Exception\\AmbiguousPluginCommand(\$commandString);
        }
PHP;
        }
        $converterInitialization = rtrim($newConverterPhp, ';');
        $contentTypeConstructor = "ContentType::byExtention('{$destinationContentType->standardExtension()}')";
        return <<<PHP
<?php
namespace Barberry\\Direction;
use Barberry;
use Barberry\\Exception;
use Barberry\\Plugin;
use Barberry\\ContentType;

class Direction{$className} extends DirectionAbstract {
    protected function init(\$commandString = null) {
        \$this->converter = {$converterInitialization};
        \$this->converter->configure({$contentTypeConstructor}, '{$tempDirectory}');
        {$commandInitialization}
    }
}
PHP;
    }
Exemple #4
0
 /**
  * @param ContentType $sourceContentType
  * @param ContentType $destinationContentType
  * @param null|string $commandPart
  * @throws \Barberry\Plugin\NotAvailableException
  * @return \Barberry\Plugin\InterfaceConverter
  */
 public function direction(ContentType $sourceContentType, ContentType $destinationContentType, $commandPart = null)
 {
     $directionClassName = 'Barberry\\Direction\\' . 'Direction' . ucfirst($sourceContentType->standardExtension()) . 'To' . ucfirst($destinationContentType->standardExtension());
     if ($destinationContentType == $sourceContentType && !$commandPart) {
         return new Plugin\Null();
     }
     if (class_exists($directionClassName, true)) {
         return new $directionClassName($commandPart);
     }
     throw new Plugin\NotAvailableException($sourceContentType . ' to ' . $destinationContentType);
 }