mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 04:41:41 +02:00
allow to extend filemanager via plugins with more views
This commit is contained in:
parent
a6c1f34be7
commit
15c8775a80
@ -35,21 +35,34 @@ class filemanager_hooks
|
|||||||
if ($location == 'sidebox_menu')
|
if ($location == 'sidebox_menu')
|
||||||
{
|
{
|
||||||
$title = $GLOBALS['egw_info']['apps'][self::$appname]['title'] . ' '. lang('Menu');
|
$title = $GLOBALS['egw_info']['apps'][self::$appname]['title'] . ' '. lang('Menu');
|
||||||
$file = array(
|
$file = array();
|
||||||
'Your home directory' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$homepath)),
|
// add selection for available views, if we have more then one
|
||||||
'Users and groups' => $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$basepath)),
|
if (count(filemanager_ui::init_views()) > 1)
|
||||||
|
{
|
||||||
|
$index_url = egw::link('/index.php',array('menuaction' => 'filemanager.filemanager_ui.index'),false);
|
||||||
|
$file[] = array(
|
||||||
|
'text' => html::select('filemanager_view',filemanager_ui::get_view(),filemanager_ui::$views,false,
|
||||||
|
' onchange="'."egw_appWindow('filemanager').location='$index_url&view='+this.value;".
|
||||||
|
'" style="width: 100%;"'),
|
||||||
|
'no_lang' => True,
|
||||||
|
'link' => False
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$file += array(
|
||||||
|
'Your home directory' => egw::link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$homepath)),
|
||||||
|
'Users and groups' => egw::link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$basepath)),
|
||||||
);
|
);
|
||||||
if (!empty($file_prefs['showbase']) && $file_prefs['showbase']=='yes')
|
if (!empty($file_prefs['showbase']) && $file_prefs['showbase']=='yes')
|
||||||
{
|
{
|
||||||
$file['Basedirectory'] = $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$rootpath));
|
$file['Basedirectory'] = egw::link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$rootpath));
|
||||||
}
|
}
|
||||||
if (!empty($file_prefs['startfolder'])) $file['Startfolder']= $GLOBALS['egw']->link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$file_prefs['startfolder']));
|
if (!empty($file_prefs['startfolder'])) $file['Startfolder']= egw::link('/index.php',array('menuaction'=>self::$appname.'.filemanager_ui.index','path'=>$file_prefs['startfolder']));
|
||||||
for ($i=1; $i<=self::$foldercount; $i++)
|
for ($i=1; $i<=self::$foldercount; $i++)
|
||||||
{
|
{
|
||||||
if (!empty($file_prefs['folderlink'.$i]))
|
if (!empty($file_prefs['folderlink'.$i]))
|
||||||
{
|
{
|
||||||
$foldername = array_pop(explode('/',$file_prefs['folderlink'.$i]));
|
$foldername = array_pop(explode('/',$file_prefs['folderlink'.$i]));
|
||||||
$file[lang('Link %1: %2',$i,$foldername)]= $GLOBALS['egw']->link('/index.php',array(
|
$file[lang('Link %1: %2',$i,$foldername)]= egw::link('/index.php',array(
|
||||||
'menuaction' => self::$appname.'.filemanager_ui.index',
|
'menuaction' => self::$appname.'.filemanager_ui.index',
|
||||||
'path' => $file_prefs['folderlink'.$i],
|
'path' => $file_prefs['folderlink'.$i],
|
||||||
'nolang' => true,
|
'nolang' => true,
|
||||||
@ -72,8 +85,8 @@ class filemanager_hooks
|
|||||||
if (is_array($location)) $location = $location['location'];
|
if (is_array($location)) $location = $location['location'];
|
||||||
|
|
||||||
$file = Array(
|
$file = Array(
|
||||||
'Site Configuration' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiconfig.index&appname='.self::$appname),
|
'Site Configuration' => egw::link('/index.php','menuaction=admin.uiconfig.index&appname='.self::$appname),
|
||||||
'Custom fields' => $GLOBALS['egw']->link('/index.php','menuaction=admin.customfields.edit&appname='.self::$appname),
|
'Custom fields' => egw::link('/index.php','menuaction=admin.customfields.edit&appname='.self::$appname),
|
||||||
);
|
);
|
||||||
// add other administration links, eg. of filesystem backends like versioning
|
// add other administration links, eg. of filesystem backends like versioning
|
||||||
if (($other = $GLOBALS['egw']->hooks->process('filemanager_admin',array(),true)))
|
if (($other = $GLOBALS['egw']->hooks->process('filemanager_admin',array(),true)))
|
||||||
@ -103,7 +116,7 @@ class filemanager_hooks
|
|||||||
if (is_array($location)) $location = $location['location'];
|
if (is_array($location)) $location = $location['location'];
|
||||||
|
|
||||||
$file = array(
|
$file = array(
|
||||||
'Preferences' => $GLOBALS['egw']->link('/index.php','menuaction=preferences.uisettings.index&appname='.self::$appname),
|
'Preferences' => egw::link('/index.php','menuaction=preferences.uisettings.index&appname='.self::$appname),
|
||||||
);
|
);
|
||||||
if ($location == 'preferences')
|
if ($location == 'preferences')
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,16 @@ class filemanager_ui
|
|||||||
'file' => true,
|
'file' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Views available from plugins
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $views = array(
|
||||||
|
'filemanager_ui::listview' => 'Listview',
|
||||||
|
);
|
||||||
|
public static $views_init = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -41,36 +51,51 @@ class filemanager_ui
|
|||||||
{
|
{
|
||||||
egw_vfs::$is_root = true;
|
egw_vfs::$is_root = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self::init_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the current user (vfs) root
|
* Initialise and return available views
|
||||||
*
|
*
|
||||||
* The user/pw is either the setup config user or a specially configured vfs_root user
|
* @return array with method => label pairs
|
||||||
*
|
|
||||||
* @param string $user='' setup config user to become root or '' to log off as root
|
|
||||||
* @param string $password=null setup config password to become root
|
|
||||||
* @param boolean &$is_setup=null on return true if authenticated user is setup config user, false otherwise
|
|
||||||
* @return boolean true is root user given, false otherwise (including logout / empty $user)
|
|
||||||
*/
|
*/
|
||||||
protected function sudo($user='',$password=null,&$is_setup=null)
|
public static function init_views()
|
||||||
{
|
{
|
||||||
if (!$user)
|
if (!self::$views_init)
|
||||||
{
|
{
|
||||||
$is_root = $is_setup = false;
|
// translate our labels
|
||||||
|
foreach(self::$views as $method => &$label)
|
||||||
|
{
|
||||||
|
$label = lang($label);
|
||||||
}
|
}
|
||||||
else
|
// search for plugins with additional filemanager views
|
||||||
|
foreach($GLOBALS['egw']->hooks->process('filemanager_views') as $app => $views)
|
||||||
{
|
{
|
||||||
// config user & password
|
if ($views) self::$views += $views;
|
||||||
$is_setup = egw_session::user_pw_hash($user,$password) === $GLOBALS['egw_info']['server']['config_hash'];
|
|
||||||
// or vfs root user from setup >> configuration
|
|
||||||
$is_root = $is_setup || $GLOBALS['egw_info']['server']['vfs_root_user'] &&
|
|
||||||
in_array($user,preg_split('/, */',$GLOBALS['egw_info']['server']['vfs_root_user'])) &&
|
|
||||||
$GLOBALS['egw']->auth->authenticate($user, $password, 'text');
|
|
||||||
}
|
}
|
||||||
//echo "<p>".__METHOD__."('$user','$password',$is_setup) user_pw_hash(...)='".egw_session::user_pw_hash($user,$password)."', config_hash='{$GLOBALS['egw_info']['server']['config_hash']}' --> returning ".array2string($is_root)."</p>\n";
|
self::$views_init = true;
|
||||||
egw_session::appsession('is_setup','filemanager',$is_setup);
|
}
|
||||||
return egw_session::appsession('is_root','filemanager',egw_vfs::$is_root = $is_root);
|
return self::$views;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get active view
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function get_view()
|
||||||
|
{
|
||||||
|
$view =& egw_cache::getSession('filemanager', 'view');
|
||||||
|
if (isset($_GET['view']))
|
||||||
|
{
|
||||||
|
$view = $_GET['view'];
|
||||||
|
}
|
||||||
|
if (!isset(self::$views[$view]))
|
||||||
|
{
|
||||||
|
$view = key(self::$views);
|
||||||
|
}
|
||||||
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,10 +106,6 @@ class filemanager_ui
|
|||||||
*/
|
*/
|
||||||
function index(array $content=null,$msg=null)
|
function index(array $content=null,$msg=null)
|
||||||
{
|
{
|
||||||
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
|
||||||
|
|
||||||
$tpl = new etemplate('filemanager.index');
|
|
||||||
|
|
||||||
if (!is_array($content))
|
if (!is_array($content))
|
||||||
{
|
{
|
||||||
$content = array(
|
$content = array(
|
||||||
@ -140,6 +161,53 @@ class filemanager_ui
|
|||||||
if (!$content['nm']['filter']) $content['nm']['filter'] = '1';
|
if (!$content['nm']['filter']) $content['nm']['filter'] = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$view = self::get_view();
|
||||||
|
|
||||||
|
call_user_func($view,$content,$msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make the current user (vfs) root
|
||||||
|
*
|
||||||
|
* The user/pw is either the setup config user or a specially configured vfs_root user
|
||||||
|
*
|
||||||
|
* @param string $user='' setup config user to become root or '' to log off as root
|
||||||
|
* @param string $password=null setup config password to become root
|
||||||
|
* @param boolean &$is_setup=null on return true if authenticated user is setup config user, false otherwise
|
||||||
|
* @return boolean true is root user given, false otherwise (including logout / empty $user)
|
||||||
|
*/
|
||||||
|
protected function sudo($user='',$password=null,&$is_setup=null)
|
||||||
|
{
|
||||||
|
if (!$user)
|
||||||
|
{
|
||||||
|
$is_root = $is_setup = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// config user & password
|
||||||
|
$is_setup = egw_session::user_pw_hash($user,$password) === $GLOBALS['egw_info']['server']['config_hash'];
|
||||||
|
// or vfs root user from setup >> configuration
|
||||||
|
$is_root = $is_setup || $GLOBALS['egw_info']['server']['vfs_root_user'] &&
|
||||||
|
in_array($user,preg_split('/, */',$GLOBALS['egw_info']['server']['vfs_root_user'])) &&
|
||||||
|
$GLOBALS['egw']->auth->authenticate($user, $password, 'text');
|
||||||
|
}
|
||||||
|
//echo "<p>".__METHOD__."('$user','$password',$is_setup) user_pw_hash(...)='".egw_session::user_pw_hash($user,$password)."', config_hash='{$GLOBALS['egw_info']['server']['config_hash']}' --> returning ".array2string($is_root)."</p>\n";
|
||||||
|
egw_session::appsession('is_setup','filemanager',$is_setup);
|
||||||
|
return egw_session::appsession('is_root','filemanager',egw_vfs::$is_root = $is_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filemanager listview
|
||||||
|
*
|
||||||
|
* @param array $content=null
|
||||||
|
* @param string $msg=null
|
||||||
|
*/
|
||||||
|
function listview(array $content=null,$msg=null)
|
||||||
|
{
|
||||||
|
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
||||||
|
|
||||||
|
$tpl = new etemplate('filemanager.index');
|
||||||
|
|
||||||
$content['nm']['msg'] = $msg;
|
$content['nm']['msg'] = $msg;
|
||||||
|
|
||||||
if ($content['action'] || $content['nm']['rows'])
|
if ($content['action'] || $content['nm']['rows'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user