Display favorites as folders in file select dialog

This commit is contained in:
Nathan Gray 2014-02-20 17:47:38 +00:00
parent a9b6c6e9b4
commit a70e12f3d3

View File

@ -238,20 +238,44 @@ class filemanager_select
{ {
$content['path'] = '/apps/'.(isset($content['apps'][$app]) ? $content['apps'][$app] : $app); $content['path'] = '/apps/'.(isset($content['apps'][$app]) ? $content['apps'][$app] : $app);
} }
if ((substr($content['path'],0,strlen('/apps/favorites/')) == '/apps/favorites/' /*|| // favorites the imediatly resolved
egw_vfs::is_link($content['path'])*/) && // we could replace all symlinks with the link, to save space in the URL // Set a flag for easy detection as we go
$link = egw_vfs::readlink($content['path'])) $favorites_flag = substr($content['path'],0,strlen('/apps/favorites')) == '/apps/favorites';
{
$content['path'] = $link[0] == '/' ? $link : egw_vfs::concat($content['path'],'../'.$link); if (!$favorites_flag && (!$content['path'] || !egw_vfs::is_dir($content['path'])))
}
if (!$content['path'] || !egw_vfs::is_dir($content['path']))
{ {
$content['path'] = filemanager_ui::get_home_dir(); $content['path'] = filemanager_ui::get_home_dir();
} }
$tpl = new etemplate_new('filemanager.select'); $tpl = new etemplate_new('filemanager.select');
$et2 = class_exists('etemplate_widget', false) && is_a($tpl, 'etemplate_widget'); $et2 = class_exists('etemplate_widget', false) && is_a($tpl, 'etemplate_widget');
if (!($files = egw_vfs::find($content['path'],array( if ($favorites_flag)
{
// Display favorites as if they were folders
$files = array();
$favorites = egw_favorites::get_favorites('filemanager');
$n = 0;
foreach($favorites as $f_id => $favorite)
{
$path = $favorite['state']['path'];
// Just directories
if(!$path) continue;
if ($path == $content['path']) continue; // remove directory itself
$mime = egw_vfs::mime_content_type($path);
$content['dir'][$n] = array(
'name' => $favorite['name'],
'path' => $path,
'mime' => $mime,
);
if ($content['mode'] == 'open-multiple')
{
$readonlys['selected['.$favorite['name'].']'] = true;
}
++$n;
}
}
else if (!($files = egw_vfs::find($content['path'],array(
'dirsontop' => true, 'dirsontop' => true,
'order' => 'name', 'order' => 'name',
'sort' => 'ASC', 'sort' => 'ASC',