| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-04 21:13:45 +03:00
										 |  |  | namespace OCA\Documents\Filter; | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-04 21:13:45 +03:00
										 |  |  | class Office { | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	const NATIVE_MIMETYPE = 'application/vnd.oasis.opendocument.text'; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-04-10 20:34:29 +03:00
										 |  |  | 	private $readSpec; | 
					
						
							|  |  |  | 	private $writeSpec; | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* sample mimespec 	 | 
					
						
							|  |  |  | 			array ( | 
					
						
							|  |  |  | 				'read' =>  | 
					
						
							|  |  |  | 					array ( | 
					
						
							|  |  |  | 						'target' => 'application/vnd.oasis.opendocument.text', | 
					
						
							|  |  |  | 						'format' => 'odt:writer8', | 
					
						
							|  |  |  | 						'extension' => 'odt' | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 				'write' =>  | 
					
						
							|  |  |  | 					array ( | 
					
						
							|  |  |  | 						'target' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | 
					
						
							|  |  |  | 						'format' => 'docx', | 
					
						
							|  |  |  | 						'extension' => 'docx' | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			array( | 
					
						
							|  |  |  | 				'read' =>  | 
					
						
							|  |  |  | 					array ( | 
					
						
							|  |  |  | 						'target' => 'application/vnd.oasis.opendocument.text', | 
					
						
							|  |  |  | 						'format' => 'odt:writer8', | 
					
						
							|  |  |  | 						'extension' => 'odt' | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 				'write' =>  | 
					
						
							|  |  |  | 					array ( | 
					
						
							|  |  |  | 						'target' => 'application/msword', | 
					
						
							|  |  |  | 						'format' => 'doc', | 
					
						
							|  |  |  | 						'extension' => 'doc' | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public function __construct($mimeSpec){ | 
					
						
							|  |  |  | 		$this->readSpec = $mimeSpec['read']; | 
					
						
							|  |  |  | 		$this->writeSpec = $mimeSpec['write']; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2014-08-04 21:13:45 +03:00
										 |  |  | 		\OCA\Documents\Filter::add($mimeSpec['write']['target'], $this); | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function read($data){ | 
					
						
							|  |  |  | 		return array( | 
					
						
							|  |  |  | 			'mimetype' => $this->readSpec['target'], | 
					
						
							|  |  |  | 			'content' =>  | 
					
						
							| 
									
										
										
										
											2014-08-04 21:13:45 +03:00
										 |  |  | 				\OCA\Documents\Converter::convert( | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 						$data['content'],  | 
					
						
							|  |  |  | 						$this->readSpec['format'], | 
					
						
							|  |  |  | 						$this->readSpec['extension'] | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	public function write($data){ | 
					
						
							|  |  |  | 		return array( | 
					
						
							|  |  |  | 			'mimetype' => $this->writeSpec['target'], | 
					
						
							|  |  |  | 			'content' =>  | 
					
						
							| 
									
										
										
										
											2014-08-04 21:13:45 +03:00
										 |  |  | 				\OCA\Documents\Converter::convert( | 
					
						
							| 
									
										
										
										
											2014-03-28 22:14:51 +03:00
										 |  |  | 						$data['content'],  | 
					
						
							|  |  |  | 						$this->writeSpec['format'], | 
					
						
							|  |  |  | 						$this->writeSpec['extension'] | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |