2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/**  
						 
					
						
							
								
									
										
										
										
											2013-08-28 12:02:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  ownCloud  -  Documents  App 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ author  Victor  Dubiniuk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ copyright  2013  Victor  Dubiniuk  victor . dubiniuk @ gmail . com 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  This  file  is  licensed  under  the  Affero  General  Public  License  version  3  or 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  later . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-28 12:02:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								namespace  OCA\Documents ;  
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  Helper  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-28 12:02:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  APP_ID  =  'documents' ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-21 00:01:11 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									public  static  function  getNewFileName ( $view ,  $path ,  $prepend  =  ' ' ){ 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 16:27:09 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										$fileNum  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-20 09:57:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										while  ( $view -> file_exists ( $path )){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$fileNum  +=  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											$path  =  preg_replace ( '/(\.odt|'  .  $prepend  .  '\(\d+\)\.odt)$/' ,  $prepend  .  '('  .  $fileNum  .  ').odt' ,  $path ); 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-20 09:57:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-20 09:57:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  $path ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-21 23:38:39 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									public  static  function  isVersionsEnabled (){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  \OCP\App :: isEnabled ( 'files_versions' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									public  static  function  getRandomColor (){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$str  =  dechex ( floor ( rand ( 0 ,  16777215 ))); 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-20 09:57:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  '#'  .  str_pad ( $str ,  6 ,  " 0 " ,  STR_PAD_LEFT ); 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  static  function  getMemberColor ( $name ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$hash  =  md5 ( $name ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$maxRange  =  hexdec ( 'ffffffffffffffffffffffffffffffff' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$hue  =  hexdec ( $hash )  /  $maxRange  *  256 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  '#'  .  self :: convertHSLToRGB ( $hue ,  90 ,  60 ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  static  function  debugLog ( $message ){ 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										self :: log ( $message ,  \OCP\Util :: DEBUG ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									public  static  function  warnLog ( $message ){ 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										self :: log ( $message ,  \OCP\Util :: WARN ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									public  static  function  errorLog ( $message ){ 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-07 22:13:50 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										self :: log ( $message ,  \OCP\Util :: ERROR ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-08-18 19:02:48 +03:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									public  static  function  log ( $message ,  $level ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										\OCP\Util :: writeLog ( self :: APP_ID ,  $message ,  $level ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									protected  static  function  convertHSLToRGB ( $iH ,  $iS ,  $iV ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iH  <  0 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iH  =  0 ;    // Hue:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iH  >  360 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iH  =  360 ;  //   0-360
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iS  <  0 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iS  =  0 ;    // Saturation:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iS  >  100 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iS  =  100 ;  //   0-100
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iV  <  0 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iV  =  0 ;    // Lightness:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $iV  >  100 ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$iV  =  100 ;  //   0-100
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dS  =  $iS  /  100.0 ;  // Saturation: 0.0-1.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dV  =  $iV  /  100.0 ;  // Lightness:  0.0-1.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dC  =  $dV  *  $dS ;    // Chroma:     0.0-1.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dH  =  $iH  /  60.0 ;   // H-Prime:    0.0-6.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dT  =  $dH ; 	   // Temp variable
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										while  ( $dT  >=  2.0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$dT  -=  2.0 ;  // php modulus does not work with float
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dX  =  $dC  *  ( 1  -  abs ( $dT  -  1 )); 	 // as used in the Wikipedia link
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										switch  ( $dH ){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  0.0  &&  $dH  <  1.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  1.0  &&  $dH  <  2.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  2.0  &&  $dH  <  3.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  3.0  &&  $dH  <  4.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  4.0  &&  $dH  <  5.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											case ( $dH  >=  5.0  &&  $dH  <  6.0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  $dX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dR  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dG  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												$dB  =  0.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dM  =  $dV  -  $dC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dR  +=  $dM ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dG  +=  $dM ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dB  +=  $dM ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dR  *=  255 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dG  *=  255 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dB  *=  255 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dR  =  str_pad ( dechex ( round ( $dR )),  2 ,  " 0 " ,  STR_PAD_LEFT ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dG  =  str_pad ( dechex ( round ( $dG )),  2 ,  " 0 " ,  STR_PAD_LEFT ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dB  =  str_pad ( dechex ( round ( $dB )),  2 ,  " 0 " ,  STR_PAD_LEFT ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  $dR . $dG . $dB ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-28 22:14:51 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									public  static  function  findOpenOffice (){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$cmd  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( is_string ( \OC_Config :: getValue ( 'preview_libreoffice_path' ,  null ))){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$cmd  =  \OC_Config :: getValue ( 'preview_libreoffice_path' ,  null ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$whichLibreOffice  =  shell_exec ( 'which libreoffice' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $cmd  ===  ''  &&  ! empty ( $whichLibreOffice )){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$cmd  =  'libreoffice' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$whichOpenOffice  =  shell_exec ( 'which openoffice' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( $cmd  ===  ''  &&  ! empty ( $whichOpenOffice )){ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											$cmd  =  'openoffice' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( empty ( $cmd )){ 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-28 22:29:46 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Helper :: warnLog ( 'Pure configuration issue. Missing open office binary that is mandatory for conversion.' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Helper :: debugLog ( 'If openoffice or libreoffice is already installed please specify the path to it using preview_libreoffice_path config. Refer to admin manual for details.' ); 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-28 22:14:51 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											throw  new  \RuntimeException ( 'Missing open office binary that is mandatory for conversion.' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  $cmd ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 15:46:53 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}