/** * Converts the given document. * * @param Transformist_Document $Document Document to convert. */ public function convert(Transformist_Document $Document) { $Input =& $Document->input(); $input = Transformist_Registry::extension($Input->type()); if (!empty($input)) { $input .= ':'; } $input .= $Input->path(); $Output =& $Document->output(); $output = Transformist_Registry::extension($Output->type()); if (!empty($output)) { $output .= ':'; } $output .= $Output->path(); $Convert = new Transformist_Command('convert'); $Convert->execute(array($input, $output)); }
/** * Converts the given document. * * @param Transformist_Document $Document Document to convert. */ public function convert(Transformist_Document $Document) { $Input =& $Document->input(); $Output =& $Document->output(); // The office command doesn't allow us to specify an output file name. // So here's the trick: we're creating a link to the input file, named // as the desired output file name, with a unique extension to ensure // that the link file name doesn't exists. // The we will pass the symlink to the office command, which will use // the link name as output file name. $inputPath = $Input->path(); $workaround = $Input->baseName() !== $Output->baseName(); if ($workaround) { $linkPath = $Output->dirPath() . DIRECTORY_SEPARATOR . $Output->baseName() . uniqid('.workaround-'); if (symlink($inputPath, $linkPath)) { $inputPath = $linkPath; } else { return; } } // $arguments = array(); if ($Output->type() == 'application/pdfa') { $arguments['-e'] = 'SelectPdfVersion=1'; } $format = Transformist_Registry::extension($Output->type()); if ($format) { $arguments['-f'] = $format; } $arguments += array('--output' => $Output->dirPath(), $inputPath); $Unoconv = new Transformist_Command('unoconv'); $R = $Unoconv->execute($arguments); // We don't need the symlink anymore. if ($workaround) { unlink($inputPath); } }
/** * Lists documents based on the settings defined in setup( ). */ protected function _listDocuments() { if (empty($this->_pending)) { return; } foreach ($this->_pending['conversions'] as $in => $out) { if (!$this->_isMimeType($out)) { continue; } $mime = $this->_isMimeType($in); $pattern = $mime ? '*' : $in; $path = $this->_pending['input'] . DS . $pattern; $files = $this->_isGlobPattern($pattern) ? glob($path, GLOB_NOSORT) : array($path); if ($files) { foreach ($files as $file) { if ($mime) { $FileInfo = new Transformist_FileInfo($file); $type = false; try { $type = $FileInfo->type(); } catch (Transformist_Exception $exception) { //var_dump( $exception->getMessage( )); } if ($type !== $in) { continue; } } $Input = new Transformist_FileInfo($file, $mime ? $in : ''); $Output = new Transformist_FileInfo($this->_pending['output'] . DS . basename($file), $out); $Output->setExtension(Transformist_Registry::extension($out)); $this->addDocument(new Transformist_Document($Input, $Output)); } } } }
/** * */ public function testRegisterMulti() { Transformist_Registry::register(array('foo' => 'mime/foo', 'bar' => 'mime/bar')); $this->assertEquals('foo', Transformist_Registry::extension('mime/foo')); $this->assertEquals('bar', Transformist_Registry::extension('mime/bar')); }
<?php /** * Core constants */ if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!defined('TRANSFORMIST_ROOT')) { define('TRANSFORMIST_ROOT', dirname(__FILE__) . DS); } if (!defined('TRANSFORMIST_BOOTSTRAPPED')) { define('TRANSFORMIST_BOOTSTRAPPED', true); } /** * Autoload */ require_once TRANSFORMIST_ROOT . 'Transformist' . DS . 'ClassLoader.php'; $ClassLoader = new Transformist_ClassLoader(TRANSFORMIST_ROOT); $ClassLoader->register(); /** * Types */ Transformist_Registry::register(array('avi' => 'video/x-msvideo', 'css' => 'text/css', 'csv' => 'text/csv', 'doc' => 'application/msword', 'flv' => 'video/x-flv', 'gif' => 'image/gif', 'html' => 'text/html', 'ico' => 'image/vnd.microsoft.icon', 'jpg' => 'image/jpeg', 'js' => 'application/javascript', 'js' => 'text/javascript', 'json' => 'application/json', 'mov' => 'video/quicktime', 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 'odg' => 'application/vnd.oasis.opendocument.graphics', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'ogg' => 'application/ogg', 'pdf' => 'application/pdf', 'pdf' => 'application/pdfa', 'png' => 'image/png', 'svg' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', 'tiff' => 'image/tiff', 'txt' => 'text/plain', 'wav' => 'audio/x-wav', 'wma' => 'audio/x-ms-wma', 'wmv' => 'video/x-ms-wmv', 'xhtml' => 'application/xhtml+xml', 'xml' => 'application/xml', 'xml' => 'text/xml', 'xul' => 'application/vnd.mozilla.xul+xml', 'zip' => 'application/zip'));