From 5f42817c562741e35c2be288d883a7ed4f2569a5 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Wed, 27 Aug 2008 11:17:00 +0000 Subject: [PATCH] #add sidebox menue to filemanager, with Links to Home and root. #filemanager supports the configuration of a different startfolder (other than users home directory) #preferences for filemanager -define links to folders, that show in sidebox menu -specify the display characteristics in filelisting (default (all sorted), or forced folders first) #configuration options for filemanager -you may specify how many links to folders can be configured in filemanagers preferences YOU HAVE TO RUN Search and Register Hooks of all Applications, and you may have to login/logout. --- .../inc/class.filemanager_hooks.inc.php | 158 ++++++++++++++++++ filemanager/inc/class.filemanager_ui.inc.php | 151 +++++++++++++---- filemanager/setup/setup.inc.php | 5 + filemanager/templates/default/config.tpl | 33 ++++ 4 files changed, 311 insertions(+), 36 deletions(-) create mode 100644 filemanager/inc/class.filemanager_hooks.inc.php create mode 100644 filemanager/templates/default/config.tpl diff --git a/filemanager/inc/class.filemanager_hooks.inc.php b/filemanager/inc/class.filemanager_hooks.inc.php new file mode 100644 index 0000000000..cdb38815e6 --- /dev/null +++ b/filemanager/inc/class.filemanager_hooks.inc.php @@ -0,0 +1,158 @@ + + * @package filemanager + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id: class.filemanager_hooks.inc.php 25002 2008-03-03 12:16:11Z ralfbecker $ + */ + +/** + * Class containing admin, preferences and sidebox-menus (used as hooks) + */ +class filemanager_hooks +{ + static $appname = 'filemanager'; + static $foldercount = 1; + static function sidebox_menu($args) + { + $location = is_array($args) ? $args['location'] : $args; + $basepath = '/'; + $rootpath = '/home'; + $homepath = '/home/'.$GLOBALS['egw_info']['user']['account_lid']; + //echo "

admin_prefs_sidebox_hooks::all_hooks(".print_r($args,True).") appname='$appname', location='$location'

\n"; + $config = config::read(self::$appname); + if (!empty($config['max_folderlinks'])) self::$foldercount = (int)$config['max_folderlinks']; + $file_prefs = &$GLOBALS['egw_info']['user']['preferences'][self::$appname]; + if ($location == 'sidebox_menu') + { + $title = $GLOBALS['egw_info']['apps'][self::$appname]['title'] . ' '. lang('Menu'); + $file = Array( + 'Home' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$homepath)), + 'Root' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$rootpath)), + # not sure if we want to offer a link to the base directory for default, this way i do that as preference + #'Base' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$basepath)), + ); + if (!empty($file_prefs['showbase'])) $file['Base']= $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$basepath)); + if (!empty($file_prefs['startfolder'])) $file['Startfolder']= $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$file_prefs['startfolder'])); + for ($i=1; $i<=self::$foldercount;$i++) { + if (!empty($file_prefs['folderlink'.$i])) { + $foldername = array_pop(explode("/",$file_prefs['folderlink'.$i])); + $file['Link '.$i.($foldername?": ($foldername)":'(Base)')]= $GLOBALS['egw']->link('/index.php',array( + 'menuaction'=>self::$appname.'.filemanager_ui.index', + 'path'=>$file_prefs['folderlink'.$i])); + } + } + display_sidebox(self::$appname,$title,$file); + } + self::preferences(self::$appname); + if ($GLOBALS['egw_info']['user']['apps']['admin']) self::admin(self::$appname); + } + + /** + * Entries for filemanagers's admin menu + */ + static function admin($location = 'admin') + { + $file = Array( + 'Site Configuration' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiconfig.index&appname='.self::$appname), + ); + if ($location == 'admin') { + display_section(self::$appname,$file); + } else { + display_sidebox(self::$appname,lang('Admin'),$file); + } + } + + static function preferences($location = 'preferences') + { + $file = array( + 'Preferences' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uisettings.index&appname='.self::$appname), + ); + if ($location == 'preferences') + { + display_section(self::$appname,$file); + } else { + display_sidebox(self::$appname,lang('Preferences'),$file); + } + } + + static function settings() + { + $config = config::read(self::$appname); + if (!empty($config['max_folderlinks'])) self::$foldercount = (int)$config['max_folderlinks']; + + $upload_boxes = array( + '1' => '1', + '5' => '5', + '10' => '10', + '20' => '20', + '30' => '30' + ); + $yes_no = array( + '0' => 'No', + '1' => 'Yes' + ); + + $GLOBALS['settings'] = array( + 'showbase' => array( + 'type' => 'select', + 'name' => 'showbase', + 'values' => $yes_no, + 'label' => 'Show link to filemanagers basedirectory (/) in side box menu?', + 'help' => 'Default behavior is NO. The link will not be shown, but you are still able to navigate to this location, + or configure this paricular location as startfolder or folderlink.', + 'xmlrpc' => True, + 'amin' => False + ), + 'alwayssortfolderstotop' => array( + 'type' => 'select', + 'name' => 'alwayssortfolderstotop', + 'values' => $yes_no, + 'label' => 'Sort folders always to the top?', + 'help' => 'Default behavior is NO. If you set this to YES, folders will always appear at the top of the list, + no matter what you sort by. It will slow your mustang down as well.', + 'xmlrpc' => True, + 'amin' => False + ), + 'startfolder' => array( + 'type' => 'input', + 'name' => 'startfolder', + 'size' => 80, + 'default' => '', + 'label' => 'Enter the complete VFS path to specify your desired start folder.', + 'help' => 'If you leave this empty, the path does not exist or the user does not have permission to access the specified folder, + the users startfolder will default to the users home folder.', + 'xmlrpc' => True, + 'amin' => False + ), +# 'show_upload_boxes' => array( +# 'type' => 'select', +# 'label' => 'Default number of upload fields to show', +# 'name' => 'show_upload_boxes', +# 'values' => $upload_boxes, +# 'help' => 'How many upload slots should be available for uploading files? (The boxes are displayed at the bottom of the file listing)', +# 'xmlrpc' => True, +# 'admin' => False +# ), + ); + for ($i=1;$i<=self::$foldercount;$i++) { + $GLOBALS['settings']['folderlink'.$i] = array( + 'type' => 'input', + 'name' => 'folderlink'.$i, + 'size' => 80, + 'default' => '', + 'label' => 'Enter the complete VFS path to specify a fast access link to a folder ('.$i.').', + 'help' => 'If you leave this empty, the path does not exist or the user does not have permission to access the specified folder, + the link will lead the user to the start folder or users home folder (if the startfolder is either not configured, or + not available to the user).', + 'xmlrpc' => True, + 'amin' => False + ); + } + + return true; + } +} diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index 7802f7315e..5e650fe37b 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -60,6 +60,14 @@ class filemanager_ui if (isset($_GET['path']) && ($path = $_GET['path']) && $path[0] == '/' && egw_vfs::is_dir($path)) { $content['nm']['path'] = $path; + } + else + { + if (!empty($GLOBALS['egw_info']['user']['preferences']['filemanager']['startfolder']) + && egw_vfs::is_dir($GLOBALS['egw_info']['user']['preferences']['filemanager']['startfolder'])) + { + $content['nm']['path'] = $GLOBALS['egw_info']['user']['preferences']['filemanager']['startfolder']; + } } if (isset($_GET['msg'])) $msg = $_GET['msg']; } @@ -369,45 +377,116 @@ class filemanager_ui { $namefilter = '/'.str_replace(array('\\?','\\*'),array('.{1}','.*'),preg_quote($query['search'])).'/i'; } - foreach(egw_vfs::find($query['path'],array( - 'mindepth' => 1, - 'maxdepth' => $query['filter'] ? $query['filter'] : null, - 'order' => $query['order'], 'sort' => $query['sort'], - 'limit' => (int)$query['num_rows'].','.(int)$query['start'], - 'need_mime' => true, - 'name_preg' => $namefilter, - ),true) as $path => $row) - { - $row['icon'] = egw_vfs::mime_icon($row['mime']); - $row['perms'] = egw_vfs::int2mode($row['mode']); - // only show link if we have access to the file or dir - if (egw_vfs::check_access($path,egw_vfs::READABLE)) + // if you want to have the folders on top, we must search for them first + if ((int)$GLOBALS['egw_info']['user']['preferences']['filemanager']['alwayssortfolderstotop']==1) { + $dirs = array(); + $files = array(); + foreach(egw_vfs::find($query['path'],array( + 'type'=>'d', + 'mindepth' => 1, + 'maxdepth' => $query['filter'] ? $query['filter'] : null, + 'order' => $query['order'], 'sort' => $query['sort'], + 'limit' => (int)$query['num_rows'].','.(int)$query['start'], + 'need_mime' => true, + 'name_preg' => $namefilter, + ),true) as $path => $row) { - if ($row['mime'] == egw_vfs::DIR_MIME_TYPE) - { - $row['link'] = '/index.php?menuaction=filemanager.filemanager_ui.index&path='.$path; - } - else - { - $row['link'] = egw_vfs::download_url($path); - } + $row['icon'] = egw_vfs::mime_icon($row['mime']); + $row['perms'] = egw_vfs::int2mode($row['mode']); + // only show link if we have access to the file or dir + if (egw_vfs::check_access($path,egw_vfs::READABLE)) $row['link'] = '/index.php?menuaction=filemanager.filemanager_ui.index&path='.$path; + $row['user'] = $row['uid'] ? $GLOBALS['egw']->accounts->id2name($row['uid']) : 'root'; + $row['group'] = $row['gid'] ? $GLOBALS['egw']->accounts->id2name(-$row['gid']) : 'root'; + $row['hsize'] = egw_vfs::hsize($row['size']); + + $dirs[] = $row; + + $dir = dirname($path); + if (!isset($dir_is_writable[$dir])) $dir_is_writable[$dir] = egw_vfs::is_writable($dir); + if (!$dir_is_writable[$dir]) $readonlys["delete[$path]"] = true; // no rights to delete the file + } - $row['user'] = $row['uid'] ? $GLOBALS['egw']->accounts->id2name($row['uid']) : 'root'; - $row['group'] = $row['gid'] ? $GLOBALS['egw']->accounts->id2name(-$row['gid']) : 'root'; - $row['hsize'] = egw_vfs::hsize($row['size']); - - //echo $path; _debug_array($row); - - $rows[++$n] = $row; - - $dir = dirname($path); - if (!isset($dir_is_writable[$dir])) - { - $dir_is_writable[$dir] = egw_vfs::is_writable($dir); + $numofdirs = egw_vfs::$find_total; + $dirsretrieved = count($dirs); + #echo "Dirs found:$numofdirs
"."Rows to query:".(int)$query['num_rows']." Start at:".(int)$query['start']."
"; + $filesdontshowjet = 0; + if ($dirsretrieved >= (int)$query['num_rows']) { + $filesdontshowjet =1; } - if (!$dir_is_writable[$dir]) + // retrieve the files as well, since we need the total number of the search/listing + $numofrows = (int)$query['num_rows'] - $dirsretrieved; + $startatrow = 0; + if ($filesdontshowjet == 0 && (int)$query['start'] > $numofdirs) $startatrow = (int)$query['start']-$numofdirs; + #echo "Filessection:Dirs retrieved:$dirsretrieved
"."Rows to query:".$numofrows." Start at:".$startatrow."
"; + foreach(egw_vfs::find($query['path'],array( + 'type'=>'f', + 'mindepth' => 1, + 'maxdepth' => $query['filter'] ? $query['filter'] : null, + 'order' => $query['order'], 'sort' => $query['sort'], + 'limit' => $numofrows.','.$startatrow, + 'need_mime' => true, + 'name_preg' => $namefilter, + ),true) as $path => $row) { - $readonlys["delete[$path]"] = true; // no rights to delete the file + $row['icon'] = egw_vfs::mime_icon($row['mime']); + $row['perms'] = egw_vfs::int2mode($row['mode']); + // only show link if we have access to the file or dir + if (egw_vfs::check_access($path,egw_vfs::READABLE)) $row['link'] = egw_vfs::download_url($path); + $row['user'] = $row['uid'] ? $GLOBALS['egw']->accounts->id2name($row['uid']) : 'root'; + $row['group'] = $row['gid'] ? $GLOBALS['egw']->accounts->id2name(-$row['gid']) : 'root'; + $row['hsize'] = egw_vfs::hsize($row['size']); + + if ($filesdontshowjet == 0) $files[] = $row; + + $dir = dirname($path); + if (!isset($dir_is_writable[$dir])) $dir_is_writable[$dir] = egw_vfs::is_writable($dir); + if (!$dir_is_writable[$dir]) $readonlys["delete[$path]"] = true; // no rights to delete the file + } + $numoffiles = egw_vfs::$find_total; + $rows = array_merge($dirs,$files); + //_debug_array($readonlys); + return egw_vfs::$find_total = $numofdirs + $numoffiles; + } else { + foreach(egw_vfs::find($query['path'],array( + 'type'=>'d', + 'mindepth' => 1, + 'maxdepth' => $query['filter'] ? $query['filter'] : null, + 'order' => $query['order'], 'sort' => $query['sort'], + 'limit' => (int)$query['num_rows'].','.(int)$query['start'], + 'need_mime' => true, + 'name_preg' => $namefilter, + ),true) as $path => $row) + { + $row['icon'] = egw_vfs::mime_icon($row['mime']); + $row['perms'] = egw_vfs::int2mode($row['mode']); + // only show link if we have access to the file or dir + if (egw_vfs::check_access($path,egw_vfs::READABLE)) + { + if ($row['mime'] == egw_vfs::DIR_MIME_TYPE) + { + $row['link'] = '/index.php?menuaction=filemanager.filemanager_ui.index&path='.$path; + } + else + { + $row['link'] = egw_vfs::download_url($path); + } + } + $row['user'] = $row['uid'] ? $GLOBALS['egw']->accounts->id2name($row['uid']) : 'root'; + $row['group'] = $row['gid'] ? $GLOBALS['egw']->accounts->id2name(-$row['gid']) : 'root'; + $row['hsize'] = egw_vfs::hsize($row['size']); + + //echo $path; _debug_array($row); + $rows[++$n] = $row; + + $dir = dirname($path); + if (!isset($dir_is_writable[$dir])) + { + $dir_is_writable[$dir] = egw_vfs::is_writable($dir); + } + if (!$dir_is_writable[$dir]) + { + $readonlys["delete[$path]"] = true; // no rights to delete the file + } } } //_debug_array($readonlys); @@ -625,4 +704,4 @@ class filemanager_ui } return $mode; } -} \ No newline at end of file +} diff --git a/filemanager/setup/setup.inc.php b/filemanager/setup/setup.inc.php index f18cbf3842..c348eddeda 100755 --- a/filemanager/setup/setup.inc.php +++ b/filemanager/setup/setup.inc.php @@ -15,6 +15,11 @@ $setup_info['filemanager']['app_order'] = 6; $setup_info['filemanager']['enable'] = 1; /* The hooks this app includes, needed for hooks registration */ +$setup_info['filemanager']['hooks']['preferences'] = 'filemanager_hooks::preferences'; +$setup_info['filemanager']['hooks']['settings'] = 'filemanager_hooks::settings'; +$setup_info['filemanager']['hooks']['sidebox_menu'] = 'filemanager_hooks::sidebox_menu'; +#$setup_info['filemanager']['hooks']['verify_settings'] = 'filemanager.filemanager_hooks.verify_settings'; +$setup_info['filemanager']['hooks']['admin'] = 'filemanager_hooks::admin'; /* Dependencies for this app to work */ diff --git a/filemanager/templates/default/config.tpl b/filemanager/templates/default/config.tpl new file mode 100644 index 0000000000..3f293917fd --- /dev/null +++ b/filemanager/templates/default/config.tpl @@ -0,0 +1,33 @@ + +
+{hidden_vars} + + + + + + + + + + + + + + + + + + + + + + + + +
 {title}
 {error}
 {lang_filemanager_configuration}
 {lang_max_folderlinks}:
 {lang_allow_a_maximum_of_the_above_configured_folderlinks_to_be_configured_in_settings}
+ + +
+
+