| 
									
										
										
										
											2013-08-18 19:02:48 +03:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | class Helper{ | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-08-28 12:02:27 +02:00
										 |  |  | 	const APP_ID = 'documents'; | 
					
						
							| 
									
										
										
										
											2013-08-18 19:02:48 +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; | 
					
						
							| 
									
										
										
										
											2013-09-20 09:57:10 +03:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		while ($view->file_exists($path)){ | 
					
						
							|  |  |  | 			$fileNum += 1; | 
					
						
							| 
									
										
										
										
											2013-09-21 00:01:11 +03:00
										 |  |  | 			$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' .$fileNum . ').odt', $path); | 
					
						
							| 
									
										
										
										
											2013-09-20 09:57:10 +03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		return $path; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-11-21 23:38:39 +03:00
										 |  |  | 	public static function isVersionsEnabled(){ | 
					
						
							|  |  |  | 		return \OCP\App::isEnabled('files_versions'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public static  function debugLog($message){ | 
					
						
							|  |  |  | 		self::log($message, \OCP\Util::DEBUG); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public static  function warnLog($message){ | 
					
						
							|  |  |  | 		self::log($message, \OCP\Util::WARN); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-07 22:13:50 +03:00
										 |  |  | 	public static  function errorLog($message){ | 
					
						
							|  |  |  | 		self::log($message, \OCP\Util::ERROR); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-08-18 19:02:48 +03:00
										 |  |  | 	public static function log($message, $level){ | 
					
						
							|  |  |  | 		\OCP\Util::writeLog(self::APP_ID, $message, $level); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |