[21188] Improvement: use mime magic for vfs 4746:5203

Sigurd Nes <[email protected]> Wed, 14 Apr 2010 19:09:53 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 21188
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=21188
Author:   sigurdne
Date:     2010-04-14 19:09:53 +0000 (Wed, 14 Apr 2010)
Log Message:
-----------
Improvement: use mime magic for vfs 4746:5203

Modified Paths:
--------------
    people/sigurdne/modules/phpgwapi/trunk/inc/class.vfs_shared.inc.php

Modified: people/sigurdne/modules/phpgwapi/trunk/inc/class.vfs_shared.inc.php
===================================================================
--- people/sigurdne/modules/phpgwapi/trunk/inc/class.vfs_shared.inc.php	2010-04-14 19:08:46 UTC (rev 21187)
+++ people/sigurdne/modules/phpgwapi/trunk/inc/class.vfs_shared.inc.php	2010-04-14 19:09:53 UTC (rev 21188)
@@ -227,6 +227,7 @@
 
 			//Load the override_locks
 			$this->locks_restore_session();
+			$this->mime_magic = createObject('phpgwapi.mime_magic');
 		}
 
 		/*
@@ -1226,14 +1227,24 @@
 		 *  * string	Real path to file, with or without leading paths
 		 *  * @return String.  MIME type based on file extension.
 		  */
-		function get_ext_mime_type ($data)
+		function get_ext_mime_type($data)
 		{
 			if (!is_array ($data))
 			{
-				$data = array ();
+				return '';
 			}
 
-			$file=basename($data['string']);
+			$path_parts = pathinfo($data['string']);
+
+			if(!isset($path_parts['extension']) || !$path_parts['extension'])
+			{
+				return '';
+			}
+			$file = $path_parts['basename'];
+
+			return $this->mime_magic->filename2mime($file);
+/*
+			$file = basename($data['string']);
 			$mimefile=PHPGW_API_INC.'/phpgw_mime.types';
 			$fp=fopen($mimefile,'r');
 			$contents = explode("\n",fread($fp,filesize($mimefile)));
@@ -1261,6 +1272,7 @@
 			}
 
 			return '';
+*/
  		}
 
 		/* PUBLIC functions (mandatory) they don't need to be implemented