[dev] Patches to VFS.

Chris Shepherd cshepherd at s21c.net
Mon Jan 20 15:58:14 PST 2003


Hi all,
  Pursuant to creating a Horde_VFS_Browser class, some changes to the 
listFolder function in the various VFS files were needed. These are patches to 
all the drivers, and I included a gollem patch to keep it working correctly.

  If possible, I would like someone who knows a lot more about regular 
expressions to look over the filter section I've added in each file, and let me 
know if the regexp can be done in a better way. It works as I've been able to 
test it here, but I've only got localfs available (not SQL, sql_file, et. al.), 
so please check it out and get back to me if it doesn't work. The filter code 
is done identically in all the files, simply because that was easiest at the 
time. If possible, I may create a filterRegexp function to build the regexp 
from the array that is passed.

  Over the next while I'll be working on creating a VFS browser that will allow 
you to do things like provide a VFS popup, and my intention is to also patch 
IMP to allow attaching files directly from within Gollem, rather than having to 
download then upload the files. If anyone is interested in testing pre-cvs 
versions of this, please contact me, and once I get some of this working, I'll 
send you code to test. 

Thanks,

-- 
Chris Shepherd

-------------------------------------------------
This email may contain confidential information. Use of any such information
is strictly prohibited without express written consent of the sender
-------------- next part --------------
Index: gollem/lib/Gollem.php
===================================================================
RCS file: /repository/gollem/lib/Gollem.php,v
retrieving revision 1.73
diff -u -r1.73 Gollem.php
--- gollem/lib/Gollem.php	9 Jan 2003 19:19:01 -0000	1.73
+++ gollem/lib/Gollem.php	20 Jan 2003 20:48:50 -0000
@@ -230,7 +230,7 @@
     {
         global $prefs;
 
-        $files = $GLOBALS['vfs']->listFolder($dir, $prefs->getValue('show_dotfiles'));
+        $files = $GLOBALS['vfs']->listFolder($dir, null, $prefs->getValue('show_dotfiles'));
         if (!is_a($files, 'PEAR_Error')) {
             switch ($GLOBALS['prefs']->getValue('sortby')) {
             case SORT_TYPE:
-------------- next part --------------
Index: horde/lib/VFS.php
===================================================================
RCS file: /repository/horde/lib/VFS.php,v
retrieving revision 1.32
diff -u -r1.32 VFS.php
--- horde/lib/VFS.php	6 Jan 2003 22:02:59 -0000	1.32
+++ horde/lib/VFS.php	20 Jan 2003 20:41:55 -0000
@@ -268,12 +268,14 @@
      * Returns a file list of the directory passed in.
      *
      * @param string  $path     The path of the directory.
+     * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
      * @param boolean $dotfiles (optional) Show dotfiles?
+     * @param boolean $dironly	(optional) Show only directories?
      *
      * @return mixed  File list (array) on success or a PEAR_Error
      *                object on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         return PEAR::raiseError('not supported');
     }
-------------- next part --------------
Index: horde/lib/VFS/file.php
===================================================================
RCS file: /repository/horde/lib/VFS/file.php,v
retrieving revision 1.33
diff -r1.33 file.php
266a267
> 	 * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
268c269,270
<      *
---
> 	 * @param boolean $dironly	(optional) Show only directories?
> 	 *
271c273
<     function listFolder($path, $dotfiles = true)
---
>     function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
273c275
<         $files = array();
---
> 	    $files = array();
283a286,304
> 		// build a regexp based on $filter
> 		if ($filter !== null) {
> 			$namefilter = '/';
> 			if (is_array($filter['name'])) {
> 				$once = false;
> 				foreach ($filter as $item) {
> 					if ($once !== true) {
> 						$namefilter .= '(';
> 						$once = true;
> 					} else {
> 						$namefilter .= '|(';
> 					}
> 					$namefilter .= $item . ')';	
> 				}
> 			} else {
> 				$namefilter .= '(' . $filter['name'] . ')';
> 			}
> 			$namefilter .= '/';
> 		}
328c349
<                 $file['perms'] = 'l' . $file['perms'];
---
> 				$file['perms'] = 'l' . $file['perms'];
330a352,370
>                 if (file_exists($file['link'])) {
>                     if (is_dir($file['link'])) {
>                         $file['type'] = '**dir';
>                         $file['size'] = -1;
>                     } elseif (is_link($file['link'])) {
>                         $file['type'] = '**sym';
>                     } elseif (is_file($file['link'])) {
>                         $ext = explode('.', $file['link']);
>                         if (count($ext) == 1 || (substr($file['name'], 0, 1) === '.' && count($ext) == 2)) {
>                             $file['type'] = '**none';
>                         } else {
>                             $file['type'] = Horde_VFS::strtolower($ext[count($ext)-1]);
>                         }
>                     } else {
>                         $file['type'] = '**none';
>                     }
>                 } else {
>                     $file['type'] = '**broken';
>                 }
353a394,406
> 			// filtering
> 			if ($filter !== null) {
> 				if (isset($namefilter)) {
> 					if (preg_match($namefilter, $file['name'])) {
> 						unset($file);
> 						continue;	
> 					}
> 				}
> 			}
> 			if ($dironly && $file['type'] !== '**dir') {
> 				unset($file);
> 				continue;
> 			}				
359,384d411
<         /* Figure out the real type of symlinks. */
<         foreach ($files as $key => $file) {
<             if ($file['type'] === '**sym') {
<                 if (file_exists($file['link'])) {
<                     if (is_dir($file['link'])) {
<                         $file['type'] = '**dir';
<                         $file['size'] = -1;
<                     } elseif (is_link($file['link'])) {
<                         $file['type'] = '**sym';
<                     } elseif (is_file($file['link'])) {
<                         $ext = explode('.', $file['link']);
<                         if (count($ext) == 1 || (substr($file['name'], 0, 1) === '.' && count($ext) == 2)) {
<                             $file['type'] = '**none';
<                         } else {
<                             $file['type'] = Horde_VFS::strtolower($ext[count($ext)-1]);
<                         }
<                     } else {
<                         $file['type'] = '**none';
<                     }
<                 } else {
<                     $file['type'] = '**broken';
<                 }
<                 $files[$key] = $file;
<             }
<         }
< 
387d413
< 
516d541
< 
-------------- next part --------------
Index: horde/lib/VFS/ftp.php
===================================================================
RCS file: /repository/horde/lib/VFS/ftp.php,v
retrieving revision 1.34
diff -r1.34 ftp.php
279a280
> 	 * @param mixed	  $filter	(optional) hash of items to filter based on filename.
280a282
> 	 * @param boolean $dironly  (optional) Show directories only?
284c286
<     function listFolder($path = '', $dotfiles = true)
---
>     function listFolder($path = '', $filter = null $dotfiles = true, $dironly = false)
293a296,315
> 		// build a regexp based on $filter
> 		if ($filter !== null) {
> 			$namefilter = '/';
> 			if (is_array($filter['name'])) {
> 				$once = false;
> 				foreach ($filter as $item) {
> 					if ($once !== true) {
> 						$namefilter .= '(';
> 						$once = true;
> 					} else {
> 						$namefilter .= '|(';
> 					}
> 					$namefilter .= $item . ')';	
> 				}
> 			} else {
> 				$namefilter .= '(' . $filter['name'] . ')';
> 			}
> 			$namefilter .= '/';
> 		}
> 
392a415,430
> 
> 			
> 			// filtering
> 			if ($filter !== null) {
> 				if (isset($namefilter)) {
> 					if (preg_match($namefilter, $file['name'])) {
> 						unset($file);
> 						continue;	
> 					}
> 				}
> 			}
> 			if ($dironly && $file['type'] !== '**dir') {
> 				unset($file);
> 				continue;
> 			}				
> 
393a432
>             unset($file);
396,406d434
<         /* Figure out the real type of symlinks. */
<         foreach ($files as $key => $file) {
<             if ($file['type'] === '**sym') {
<                 if (isset($files[$file['link']]) && ($file['name'] !== $file['link'])) {
<                     $file['type'] = $files[$file['link']]['type'];
<                 } else {
<                     $file['type'] = '**broken';
<                 }
<                 $files[$key] = $file;
<             }
<         }
-------------- next part --------------
Index: horde/lib/VFS/musql.php
===================================================================
RCS file: /repository/horde/lib/VFS/musql.php,v
retrieving revision 1.12
diff -r1.12 musql.php
328a329
> 	 * @param mixed   $filter	(optional) String/hash to filter file/dirname on.
329a331
> 	 * @param boolean $dironly	(optional) Show only directories?
333c335
<     function listFolder($path, $dotfiles = true)
---
>     function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
342a345,364
> 		// build a regexp based on $filter
> 		if ($filter !== null) {
> 			$namefilter = '/';
> 			if (is_array($filter['name'])) {
> 				$once = false;
> 				foreach ($filter as $item) {
> 					if ($once !== true) {
> 						$namefilter .= '(';
> 						$once = true;
> 					} else {
> 						$namefilter .= '|(';
> 					}
> 					$namefilter .= $item . ')';	
> 				}
> 			} else {
> 				$namefilter .= '(' . $filter['name'] . ')';
> 			}
> 			$namefilter .= '/';
> 		}
> 
387a410,423
> 			// filtering
> 			if ($filter !== null) {
> 				if (isset($namefilter)) {
> 					if (preg_match($namefilter, $file['name'])) {
> 						unset($file);
> 						continue;	
> 					}
> 				}
> 			}
> 			if ($dironly && $file['type'] !== '**dir') {
> 				unset($file);
> 				continue;
> 			}				
> 
388a425
>             unset($file);
-------------- next part --------------
Index: horde/lib/VFS/sql_file.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql_file.php,v
retrieving revision 1.15
diff -u -r1.15 sql_file.php
--- horde/lib/VFS/sql_file.php	13 Jan 2003 23:21:14 -0000	1.15
+++ horde/lib/VFS/sql_file.php	20 Jan 2003 20:52:19 -0000
@@ -137,7 +137,7 @@
             return $conn;
         }
 
-        $fileCheck = $this->listFolder($dest, false);
+        $fileCheck = $this->listFolder($dest, null, false);
         foreach ($fileCheck as $file) {
             if ($file['name'] == $name) {
                 return PEAR::raiseError('Unable to move VFS file.');
@@ -167,7 +167,7 @@
             return $conn;
         }
 
-        $fileCheck = $this->listFolder($dest, false);
+        $fileCheck = $this->listFolder($dest, null, false);
         foreach ($fileCheck as $file) {
             if ($file['name'] == $name) {
                 return PEAR::raiseError('Unable to copy VFS file.');
@@ -528,11 +528,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+	 * @param mixed	  $filter	(optional) hash of items to filter based on filename.
      * @param boolean $dotfiles (optional) Show dotfiles?
+	 * @param boolean $dironly  (optional) Show directories only?
      *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -542,6 +544,26 @@
         $files = array();
         $fileList = array();
 
+		// build a regexp based on $filter
+		if ($filter !== null) {
+			$namefilter = '/';
+			if (is_array($filter['name'])) {
+				$once = false;
+				foreach ($filter as $item) {
+					if ($once !== true) {
+						$namefilter .= '(';
+						$once = true;
+					} else {
+						$namefilter .= '|(';
+					}
+					$namefilter .= $item . ')';	
+				}
+			} else {
+				$namefilter .= '(' . $filter['name'] . ')';
+			}
+			$namefilter .= '/';
+		}
+
         $fileList = $this->_db->getAll(sprintf('SELECT vfs_name, vfs_type, vfs_modified, vfs_owner FROM %s
                                                WHERE vfs_path = %s',
                                                $this->_params['table'],
@@ -578,8 +600,23 @@
             $file['perms'] = '-';
             $file['group'] = '-';
 
-            $files[$file['name']] = $file;
-        }
+			// filtering
+			if ($filter !== null) {
+				if (isset($namefilter)) {
+					if (preg_match($namefilter, $file['name'])) {
+						unset($file);
+						continue;	
+					}
+				}
+			}
+			if ($dironly && $file['type'] !== '**dir') {
+				unset($file);
+				continue;
+			}				
+
+			$files[$file['name']] = $file;
+			unset($file);
+		}
 
         return $files;
     }
-------------- next part --------------
Index: horde/lib/VFS/sql.php
===================================================================
RCS file: /repository/horde/lib/VFS/sql.php,v
retrieving revision 1.39
diff -u -r1.39 sql.php
--- horde/lib/VFS/sql.php	13 Jan 2003 23:21:13 -0000	1.39
+++ horde/lib/VFS/sql.php	20 Jan 2003 20:55:17 -0000
@@ -381,11 +381,13 @@
      * Return a list of the contents of a folder.
      *
      * @param string  $path     Holds the path of the directory.
+	 * @param mixed	  $filter	(optional) hash of items to filter based on filename.
      * @param boolean $dotfiles (optional) Show dotfiles?
+	 * @param boolean $dironly  (optional) Show directories only?
      *
      * @return mixed  File list on success or false on failure.
      */
-    function listFolder($path, $dotfiles = true)
+    function listFolder($path, $filter = null, $dotfiles = true, $dironly = false)
     {
         $conn = $this->_connect();
         if (is_a($conn, 'PEAR_Error')) {
@@ -395,6 +397,26 @@
         $files = array();
         $fileList = array();
 
+		// build a regexp based on $filter
+		if ($filter !== null) {
+			$namefilter = '/';
+			if (is_array($filter['name'])) {
+				$once = false;
+				foreach ($filter as $item) {
+					if ($once !== true) {
+						$namefilter .= '(';
+						$once = true;
+					} else {
+						$namefilter .= '|(';
+					}
+					$namefilter .= $item . ')';	
+				}
+			} else {
+				$namefilter .= '(' . $filter['name'] . ')';
+			}
+			$namefilter .= '/';
+		}
+
         // Fix for an ODD Oracle quirk.
         if (empty($path) && $this->_db->dbsyntax == 'oci8') {
             $where = 'vfs_path IS NULL';
@@ -438,8 +460,24 @@
             $file['perms'] = '-';
             $file['group'] = '-';
 
+
+			// filtering
+			if ($filter !== null) {
+				if (isset($namefilter)) {
+					if (preg_match($namefilter, $file['name'])) {
+						unset($file);
+						continue;	
+					}
+				}
+			}
+			if ($dironly && $file['type'] !== '**dir') {
+				unset($file);
+				continue;
+			}				
+
             $files[$file['name']] = $file;
-        }
+            unset($file);
+	    }
 
         return $files;
     }


More information about the dev mailing list