Commit 2e778acb6158e627e2c95d71f0cd49f6b04c4672

Authored by jjordaan
2 parents efeb8295 183860ec

Merge branch 'master' of git@github.com:ktgit/knowledgetree

bin/luceneserver/ktlucene.jar
No preview for this file type
bin/luceneserver/lib/jodconverter-2.2.2.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/jodconverter.jar deleted
No preview for this file type
bin/luceneserver/lib/juh-3.0.1.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/juh.jar deleted
No preview for this file type
bin/luceneserver/lib/jurt-3.0.1.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/jurt.jar deleted
No preview for this file type
bin/luceneserver/lib/ridl-3.0.1.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/ridl.jar deleted
No preview for this file type
bin/luceneserver/lib/slf4j-api-1.5.6.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar 0 → 100644
No preview for this file type
bin/luceneserver/lib/unoil.jar renamed to bin/luceneserver/lib/unoil-3.0.1.jar
No preview for this file type
bin/luceneserver/lib/xstream-1.3.1.jar 0 → 100644
No preview for this file type
plugins/ktstandard/PDFGeneratorAction.php
... ... @@ -257,7 +257,7 @@ class PDFGeneratorAction extends KTDocumentAction {
257 257  
258 258 if(!$res){
259 259 $default->log->error('PDF Generator: PDF file could not be generated');
260   - $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type.'));
  260 + $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type or the PDF Generator could not connect.'));
261 261 exit();
262 262 }
263 263  
... ...
plugins/pdfConverter/pdfConverter.php
... ... @@ -32,19 +32,34 @@ class pdfConverter extends BaseProcessor
32 32 {
33 33 public $order = 2;
34 34 protected $namespace = 'pdf.converter.processor';
  35 + private $ooHost = '127.0.0.1';
  36 + private $ooPort = 8100;
35 37  
  38 + /**
  39 + * Constructor gets the connection to the java server
  40 + *
  41 + * @return pdfConverter
  42 + */
36 43 public function pdfConverter()
37 44 {
38 45 $config =& KTConfig::getSingleton();
39 46 $javaServerUrl = $config->get('indexer/javaLuceneURL');
  47 + $this->ooHost = $config->get('openoffice/host','127.0.0.1');
  48 + $this->ooPort = $config->get('openoffice/port','8100');
40 49  
41 50 $this->xmlrpc = XmlRpcLucene::get($javaServerUrl);
42 51 }
43 52  
  53 + /**
  54 + * Gets the document path and calls the conversion function
  55 + *
  56 + * @return boolean
  57 + */
44 58 public function processDocument()
45 59 {
46 60 $oStorage = KTStorageManagerUtil::getSingleton();
47 61 $path = $oStorage->temporaryFile($this->document);
  62 + $ext = KTMime::getFileType($this->document->getMimeTypeID());
48 63  
49 64 if(!file_exists($path)){
50 65 global $default;
... ... @@ -53,7 +68,7 @@ class pdfConverter extends BaseProcessor
53 68 }
54 69  
55 70 // do pdf conversion
56   - $res = $this->convertFile($path);
  71 + $res = $this->convertFile($path, $ext);
57 72  
58 73 if($res === false){
59 74 global $default;
... ... @@ -80,14 +95,17 @@ class pdfConverter extends BaseProcessor
80 95  
81 96 // taken from the original list of accepted types in the pdf generator action
82 97 $mime_types = array();
83   - //$mime_types[] = 'text/plain';
84   - //$mime_types[] = 'text/xml';
85   - //$mime_types[] = 'chemical/x-pdb';
86   - //$mime_types[] = 'text/csv';
  98 + $mime_types[] = 'text/plain';
  99 + $mime_types[] = 'text/html';
  100 + $mime_types[] = 'text/csv';
87 101 $mime_types[] = 'text/rtf';
  102 +
  103 + // Office OLE2 - 2003, XP, etc
88 104 $mime_types[] = 'application/msword';
89 105 $mime_types[] = 'application/vnd.ms-powerpoint';
90 106 $mime_types[] = 'application/vnd.ms-excel';
  107 +
  108 + // Star Office
91 109 $mime_types[] = 'application/vnd.sun.xml.writer';
92 110 $mime_types[] = 'application/vnd.sun.xml.writer.template';
93 111 $mime_types[] = 'application/vnd.sun.xml.calc';
... ... @@ -96,6 +114,8 @@ class pdfConverter extends BaseProcessor
96 114 $mime_types[] = 'application/vnd.sun.xml.draw.template';
97 115 $mime_types[] = 'application/vnd.sun.xml.impress';
98 116 $mime_types[] = 'application/vnd.sun.xml.impress.template';
  117 +
  118 + // Open Office
99 119 $mime_types[] = 'application/vnd.oasis.opendocument.text';
100 120 $mime_types[] = 'application/vnd.oasis.opendocument.text-template';
101 121 $mime_types[] = 'application/vnd.oasis.opendocument.graphics';
... ... @@ -105,39 +125,65 @@ class pdfConverter extends BaseProcessor
105 125 $mime_types[] = 'application/vnd.oasis.opendocument.spreadsheet';
106 126 $mime_types[] = 'application/vnd.oasis.opendocument.spreadsheet-template';
107 127  
  128 + // Office 2007
  129 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
  130 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
  131 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.template';
  132 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
  133 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
  134 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  135 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
  136 +
108 137 return $mime_types;
109 138 }
110 139  
111   - function convertFile($filename)
  140 + /**
  141 + * Converts the given file to a pdf
  142 + *
  143 + * @param string $filename The full path to the file
  144 + * @param string $ext The extension of the file
  145 + * @return boolean
  146 + */
  147 + function convertFile($filename, $ext)
112 148 {
113 149 global $default;
  150 + $tempDir = $default->tmpDirectory;
  151 +
  152 + // Create temporary copy of document
  153 + $sourceFile = tempnam($tempDir, 'pdfconverter') . '.' .$ext;
  154 + $res = @copy($filename, $sourceFile);
  155 +
  156 + // Create a temporary file to store the converted document
  157 + $targetFile = tempnam($tempDir, 'pdfconverter') . '.pdf';
114 158  
115 159 // Get contents and send to converter
116   - $buffer = file_get_contents($filename);
117   - $buffer = $this->xmlrpc->convertDocument($buffer, 'pdf');
  160 + $result = $this->xmlrpc->convertDocument($sourceFile, $targetFile, $this->ooHost, $this->ooPort);
118 161  
119   - if($buffer === false){
  162 + if($result === false){
120 163 $default->log->error('PDF Converter Plugin: Conversion to PDF Failed');
  164 + @unlink($sourceFile);
  165 + @unlink($targetFile);
121 166 return false;
122 167 }
123 168  
124   - $dir = $default->pdfDirectory;
  169 + $pdfDir = $default->pdfDirectory;
125 170  
126 171 // Ensure the PDF directory exists
127   - if(!file_exists($dir)){
128   - mkdir($dir, 0755);
  172 + if(!file_exists($pdfDir)){
  173 + mkdir($pdfDir, 0755);
129 174 }
130 175  
131   - $pdfFile = $dir .'/'. $this->document->iId.'.pdf';
  176 + $pdfFile = $pdfDir .'/'. $this->document->iId.'.pdf';
132 177  
133 178 // if a previous version of the pdf exists - delete it
134 179 if(file_exists($pdfFile)){
135 180 @unlink($pdfFile);
136 181 }
137 182  
138   - file_put_contents($pdfFile, $buffer);
139   - unset($buffer);
140   -
  183 + // Copy the generated pdf into the pdf directory
  184 + $res = @copy($targetFile, $pdfFile);
  185 + @unlink($sourceFile);
  186 + @unlink($targetFile);
141 187 return $pdfFile;
142 188  
143 189 }
... ...
search2/indexing/lib/XmlRpcLucene.inc.php
... ... @@ -400,15 +400,44 @@ class XmlRpcLucene
400 400 return $obj['metadata'];
401 401 }
402 402  
  403 + /**
  404 + * Converts a document to the format of the given target file based on the extension of both files.
  405 + *
  406 + * @param string $sourceFile The full path of the document to be converted, with extension.
  407 + * @param string $targetFile The full path of the file to save the converted document with the desired extension.
  408 + * @param string $ooHost The host domain or IP address on which OpenOffice is running
  409 + * @param string $ooPort The port on which OpenOffice is listening.
  410 + * @return boolean
  411 + */
  412 + function convertDocument($sourceFile, $targetFile, $ooHost, $ooPort)
  413 + {
  414 + $function = new xmlrpcmsg('openoffice.convertDocument',
  415 + array(
  416 + php_xmlrpc_encode((string) $sourceFile),
  417 + php_xmlrpc_encode((string) $targetFile),
  418 + php_xmlrpc_encode((string) $ooHost),
  419 + php_xmlrpc_encode((int) $ooPort)
  420 + )
  421 + );
  422 +
  423 + $result=&$this->client->send($function, 120);
  424 +
  425 + if($result->faultCode()) {
  426 + $this->error($result, 'convertDocument');
  427 + return false;
  428 + }
  429 + return php_xmlrpc_decode($result->value()) == 0;
  430 + }
403 431  
404 432 /**
405 433 * Convert document to given format. Defaults to pdf
406 434 *
  435 + * @deprecated
407 436 * @param $content
408 437 * @param $toExtension
409 438 * @return unknown_type
410 439 */
411   - function convertDocument($content, $toExtension = 'pdf')
  440 + function convertDocumentStreamed($content, $toExtension = 'pdf')
412 441 {
413 442 $function = new xmlrpcmsg('openoffice.convertDocument',
414 443 array(
... ...