Esempio n. 1
0
 public static function openOOdocument($filepath)
 {
     $myConverter = new Converter();
     $pdfFilter = self::getPDFFilterString($filepath);
     if ($pdfFilter == 'PDF') {
         //None Convert anything
         $PDFPath = $myConverter->Convert($filepath);
     } else {
         //Convert to PDF
         $PDFPath = $myConverter->Convert($filepath, $pdfFilter);
     }
     $PDFDir = dirname($PDFPath);
     if (!$PDFPath || !file_exists($PDFPath)) {
         throw new Exception('Cannot convert document');
     }
     //Generate Images from PDF
     $imageRadixName = 'results';
     $smallImageRadixName = 'preview';
     $cmd = 'convert -interlace line -quality 75 -density 100 ' . escapeshellarg($PDFPath) . ' ' . escapeshellarg($PDFDir . '/' . $imageRadixName . '.jpg');
     shell_exec('LANG=en_US.utf-8;' . $cmd);
     $cmd = 'convert  -interlace line -quality 30 -density 70 ' . escapeshellarg($PDFPath) . ' ' . escapeshellarg($PDFDir . '/' . $smallImageRadixName . '.jpg');
     shell_exec('LANG=en_US.utf-8;' . $cmd);
     $iterator = new DirectoryIterator($PDFDir);
     $imagesList = array();
     $smallImageList = array();
     foreach ($iterator as $fileInfo) {
         if (strpos($fileInfo->getFilename(), $smallImageRadixName) !== false) {
             $smallImageList[] = $fileInfo->getFileName();
         }
         if (strpos($fileInfo->getFilename(), $imageRadixName) !== false) {
             $imageList[] = $fileInfo->getFileName();
         }
     }
     natsort($imageList);
     natsort($smallImageList);
     return array('hash' => basename($PDFDir), 'images' => array_values($imageList), 'previews' => array_values($smallImageList));
 }
Esempio n. 2
0
 public static function fileExport(array $params)
 {
     $destinationFile = $params[0];
     $originalFile = $params[1];
     $format = $params[2];
     if ($format == 'PDF') {
         $extension = 'pdf';
         $format = 'writer_pdf_Export';
     } elseif ($format == 'Doc') {
         $extension = 'doc';
         $format = 'MS Word 97';
     } elseif ($format == 'Open Office') {
         $extension = 'odt';
         $format = 'writer8';
     } elseif ($format == 'HTML') {
         $extension = 'html';
         $format = 'HTML (StarWriter)';
     } elseif ($format == 'RTF') {
         $extension = 'rtf';
         $format = 'Rich Text Format';
     } elseif ($format == 'TXT') {
         $extension = 'txt';
         $format = 'Text (encoded)';
     }
     $destinationFile .= '.' . $extension;
     $file = FSI::getFile($originalFile);
     $memory = MemoryManager::getInstance();
     $file->checkReadPermission();
     $to = 'home:///';
     //then, check the destination file
     $myFileDest = FSI::getFile($to);
     $myFileDest->checkWritePermission();
     $myRealFile = $myFileDest->getRealFile();
     $partName = '.office/' . uniqid(time()) . '_conversion/';
     $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/' . $partName;
     mkdir($fileNameDestination);
     $myRealFile = $file->getRealFile();
     $originalFile = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath());
     $cmd = 'unzip  -d ' . escapeshellarg($fileNameDestination) . ' ' . escapeshellarg($originalFile);
     shell_exec($cmd);
     $myConverter = new Converter();
     $fileName = $myConverter->Convert($to . $partName . '/document.html', $format);
     shell_exec('rm -rf ' . escapeshellarg($fileNameDestination));
     if (!file_exists($fileName)) {
         return false;
     }
     $content = file_get_contents($fileName);
     $newFile = FSI::getFile($destinationFile);
     $newFile->createNewFile(true);
     $newFile->putContents($content);
     return $destinationFile;
 }
Esempio n. 3
0
 public static function getDocument($params)
 {
     $instance = MemoryManager::getInstance();
     $plist = $instance->get('playList');
     $filepath = $plist[$params];
     $info = utf8_pathinfo($filepath);
     //TODO: maybe fsi has better things than pathinfo
     if (strtolower($info['extension']) == 'odt' || strtolower($info['extension']) == 'doc' || strtolower($info['extension']) == 'xls' || strtolower($info['extension']) == 'ods') {
         $myConverter = new Converter();
         $path = $myConverter->Convert($filepath, 'HTML (StarWriter)');
         $md5 = utf8_basename($path);
         if (!$path || !file_exists($path)) {
             return array($filepath, 'Unable to convert office file, maybe this system does not have office support installed?');
         }
         //TODO: we are having problems with FSI and hidden folders
         $data = file_get_contents($path);
         $data = str_replace('<IMG SRC="', '<IMG SRC="index.php/externMsg/' . ProcManager::getInstance()->getCurrentProcess()->getChecknum() . '/viewTempImg/', $data);
         return array($filepath, $data);
     }
     $myFile = FSI::getFile($filepath);
     $data = $myFile->getContents();
     return array($filepath, $data);
 }
Esempio n. 4
0
 private function openOOdocument($filepath)
 {
     $myConverter = new Converter();
     $pdfFilter = self::getPDFFilterString($filepath);
     if ($pdfFilter == 'PDF') {
         //None Convert anything
         $PDFPath = $myConverter->Convert($filepath);
     } else {
         //Convert to PDF
         $PDFPath = $myConverter->Convert($filepath, $pdfFilter);
     }
     if (!$PDFPath || !file_exists($PDFPath)) {
         throw new Exception('Cannot convert document');
     }
     return $PDFPath;
 }