Index: filebrowser.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filebrowser/filebrowser.module,v retrieving revision 1.7 diff -u -r1.7 filebrowser.module --- filebrowser.module 28 Jun 2006 12:29:58 -0000 1.7 +++ filebrowser.module 6 Jul 2006 15:47:45 -0000 @@ -85,17 +85,24 @@ */ function filebrowser_page() { // Build breadcrumb list for uplevel folders - $subfolder = preg_replace("!^filebrowser/*!", "", $_GET['q']); - $parts = explode("/", $subfolder); + $parts = func_get_args(); + $subfolder = join('/',$parts); + + // set context for later filebrowser links + $filebrowser_base = $subfolder ? substr($_GET['q'],0,strpos($_GET['q'],$subfolder)) : $_GET['q']; + filebrowser_proper_path('', $filebrowser_base); + $breadcrumb = array(); $dirname = t('root'); if ($subfolder) { - $dirname = array_pop($parts); + $breadcrumb[] = $dirname = array_pop($parts); while (count($parts)) { $breadcrumb[] = l($parts[count($parts) -1], filebrowser_proper_path(join("/", $parts))); array_pop($parts); } $breadcrumb[] = l(t('Filebrowser root'), 'filebrowser'); + } else { + $breadcrumb[] = t('Filebrowser'); } $breadcrumb[] = l(t('Home'), NULL); drupal_set_breadcrumb(array_reverse($breadcrumb)); @@ -115,7 +122,8 @@ array('data' => t("Name"), 'field' => 1), array('data' => t("Size"), 'field' => 2), array('data' => t("Last modified"), 'field' => 3), - ), filebrowser_get_fileinfo() + ), filebrowser_get_fileinfo() + , filebrowser_get_more_columns() ); // Set sorting criteria eg. array(the 'field' key's associated value, asc/desc) filebrowser_sort_table(array(tablesort_get_order($headers), tablesort_get_sort($headers))); @@ -245,7 +253,8 @@ array('data' => $link, 'class' => 'filename', 'sv' => $file), array('data' => $size, 'sv' => ($size ? $stat['size'] : 0)), array('data' => format_interval($age), 'sv' => $age) - ), $extrainfo); + ), $extrainfo, filebrowser_get_more_columns($completepath,$stat) + ); } } // The special one-up folder not in the root folder @@ -316,6 +325,46 @@ } /** + * Impliment callbacks from any other modules that wish to extend filebrowser + * with additional columns, like data or actions. + * A callback takes the filepath as an argument, and returns an array of table + * cells. The table cells get inserted as part of the current row. + * When given NULL as the argument, it returns the table column header. + * + */ +function filebrowser_get_more_columns($fullpath = NULL,$stat = array() ){ + return module_invoke_all('filebrowser_column', $fullpath, $stat); +} + +/** + * A sample filebrowser column callback. + * If a module implimented this, a new column would become available to + * filebrowser with the contents of the new cell in each row. + * It should return an ARRAY of table cells - any callback can add any number of + * columns. + * This function would be called filebrowser_filebrowser_column() - a module + * would declare a function modulename_filebrowser_column() + */ +function hook_filebrowser_column($fullpath = NULL, $stat = array()){ + // return the column header + if(!$fullpath){ + return array( + array('data' => t("Type"), 'field' => 2) + ); + } + // Return a cell displaying the suffix. Sortable. + $suffix = substr($fullpath,strrpos($fullpath,".")+1); + if(strrpos($fullpath,".") && $suffix ){ + return array( + array( 'data' => $suffix, 'sv' => $suffix ) + ); + } else { + return array(array('sv' => '')); + // Need to keep up the right number of table cells. + } +} + +/** * Returns the appropriate HTML code for an icon representing * a file, based on the extension of the file. A specific icon * can also be requested with the second parameter. @@ -360,10 +409,17 @@ } /** - * Allows easy path generation even if $path has a leading slash. + * Prepend the filebrowser location to the path. + * Allows easy path generation even if $path has a leading slash. Setting the + * second parameter allows filebrowser to run from different contexts. + * @param $path + * @param $filebrowser_base + * Define where filebrowser is run from. */ -function filebrowser_proper_path($path) { - return str_replace("//", "/", "filebrowser/$path"); +function filebrowser_proper_path($path, $filebrowser_base=NULL) { + static $base; if(!$base){$base='filebrowser/';} + if($filebrowser_base){$base=$filebrowser_base;} + return str_replace("//", "/", $base.$path); } /**