| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * ownCloud - Documents App | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace OCA\Documents; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  class Filter { | 
					
						
							| 
									
										
										
										
											2013-12-26 18:14:11 +00:00
										 |  |  | 	 protected static $filters = array(); | 
					
						
							|  |  |  | 	  | 
					
						
							|  |  |  | 	 public static function add($mimetype, $class){ | 
					
						
							|  |  |  | 		 self::$filters[$mimetype] = $class; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-26 18:14:11 +00:00
										 |  |  | 	public static function read($content, $mimetype){ | 
					
						
							| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  | 		$data = array( | 
					
						
							|  |  |  | 			'mimetype' => $mimetype, | 
					
						
							|  |  |  | 			'content' => $content | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2013-12-26 18:14:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (isset(self::$filters[$mimetype])){ | 
					
						
							|  |  |  | 			$data = call_user_func( | 
					
						
							|  |  |  | 					array( | 
					
						
							|  |  |  | 						self::$filters[$mimetype], | 
					
						
							|  |  |  | 						'read' | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					$data | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		return $data; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	  | 
					
						
							|  |  |  | 	 public static function write($content, $mimetype){ | 
					
						
							|  |  |  | 		$data = array( | 
					
						
							|  |  |  | 			'mimetype' => $mimetype, | 
					
						
							|  |  |  | 			'content' => $content | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2013-12-26 18:14:11 +00:00
										 |  |  | 		if (isset(self::$filters[$mimetype])){ | 
					
						
							|  |  |  | 			$data = call_user_func( | 
					
						
							|  |  |  | 					array( | 
					
						
							|  |  |  | 						self::$filters[$mimetype], | 
					
						
							|  |  |  | 						'write' | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					$data | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  | 		return $data; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	  | 
					
						
							| 
									
										
										
										
											2013-12-26 18:14:11 +00:00
										 |  |  | 	 public static function getAll(){ | 
					
						
							|  |  |  | 		 return array_keys(self::$filters); | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	  | 
					
						
							| 
									
										
										
										
											2013-12-26 15:42:28 +00:00
										 |  |  |  } | 
					
						
							|  |  |  |   |