| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * ownCloud - Documents App | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author Victor Dubiniuk | 
					
						
							|  |  |  |  * @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
					
						
							|  |  |  |  * later. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace OCA\Documents; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Config { | 
					
						
							|  |  |  | 	const APP_NAME = 'documents'; | 
					
						
							| 
									
										
										
										
											2014-11-05 17:25:43 +03:00
										 |  |  | 	const TEST_DOC_PATH = '/assets/test.doc'; | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:47:56 +03:00
										 |  |  | 	public static function testConversion(){ | 
					
						
							|  |  |  | 		$targetFilter = 'odt:writer8'; | 
					
						
							|  |  |  | 		$targetExtension = 'odt'; | 
					
						
							| 
									
										
										
										
											2014-11-05 17:25:43 +03:00
										 |  |  | 		$input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH); | 
					
						
							| 
									
										
										
										
											2014-10-26 15:47:56 +03:00
										 |  |  | 		$infile = \OCP\Files::tmpFile(); | 
					
						
							|  |  |  | 		$outdir = \OCP\Files::tmpFolder(); | 
					
						
							|  |  |  | 		$outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension; | 
					
						
							|  |  |  | 		$cmd = Helper::findOpenOffice(); | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | 		$params = ' --headless --convert-to ' . escapeshellarg($targetFilter) . ' --outdir '  | 
					
						
							|  |  |  | 			. escapeshellarg($outdir)  | 
					
						
							|  |  |  | 			. ' --writer '. escapeshellarg($infile)  | 
					
						
							| 
									
										
										
										
											2015-04-28 11:42:33 +02:00
										 |  |  | 			. ' -env:UserInstallation=file://' | 
					
						
							|  |  |  | 			. escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId().'/') . ' 2>&1' | 
					
						
							| 
									
										
										
										
											2014-10-26 15:47:56 +03:00
										 |  |  | 		; | 
					
						
							|  |  |  | 		file_put_contents($infile, $input); | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | 		$result = shell_exec($cmd . $params); | 
					
						
							|  |  |  |  		$exists = file_exists($outfile); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (!$exists){ | 
					
						
							| 
									
										
										
										
											2014-10-28 22:38:08 +03:00
										 |  |  | 			Helper::warnLog('Conversion test failed. Raw output:' . $result); | 
					
						
							| 
									
										
										
										
											2014-10-26 15:47:56 +03:00
										 |  |  | 			return false; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			unlink($outfile); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-04-09 17:48:48 +03:00
										 |  |  | 	public static function getL10n(){ | 
					
						
							|  |  |  | 		return \OCP\Util::getL10N(self::APP_NAME); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	public static function getConverter(){ | 
					
						
							| 
									
										
										
										
											2014-11-06 19:31:25 +03:00
										 |  |  | 		return self::getAppValue('converter', 'off'); | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public static function setConverter($value){ | 
					
						
							|  |  |  | 		return self::setAppValue('converter', $value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public static function getConverterUrl(){ | 
					
						
							|  |  |  | 		return self::getAppValue('converter_url', 'http://localhost:16080'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public static function setConverterUrl($value){ | 
					
						
							|  |  |  | 		return self::setAppValue('converter_url', $value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	protected static function getAppValue($key, $default){ | 
					
						
							|  |  |  | 		return \OCP\Config::getAppValue(self::APP_NAME, $key, $default); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	protected static function setAppValue($key, $value){ | 
					
						
							|  |  |  | 		return \OCP\Config::setAppValue(self::APP_NAME, $key, $value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2015-04-28 11:42:33 +02:00
										 |  |  | } |