2008-03-02 22:44:15 +01:00
< ? php
/**
2016-05-05 09:20:07 +02:00
* EGroupware - Filemanager - user interface
2008-03-02 22:44:15 +01:00
*
* @ link http :// www . egroupware . org
2008-03-03 08:53:43 +01:00
* @ package filemanager
2008-03-02 22:44:15 +01:00
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
2016-01-21 12:49:50 +01:00
* @ copyright ( c ) 2008 - 16 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2008-03-02 22:44:15 +01:00
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ version $Id $
*/
2008-03-18 10:07:06 +01:00
2016-03-21 11:06:54 +01:00
use EGroupware\Api ;
2016-05-05 09:20:07 +02:00
use EGroupware\Api\Link ;
use EGroupware\Api\Framework ;
use EGroupware\Api\Egw ;
use EGroupware\Api\Etemplate ;
2016-03-21 11:06:54 +01:00
use EGroupware\Api\Vfs ;
2016-08-17 17:23:22 +02:00
2009-12-01 15:51:13 +01:00
/**
* Filemanage user interface class
*/
2008-03-02 22:44:15 +01:00
class filemanager_ui
{
/**
* Methods callable via menuaction
*
* @ var array
*/
var $public_functions = array (
'index' => true ,
2008-03-03 23:15:44 +01:00
'file' => true ,
2016-07-19 18:20:08 +02:00
'editor' => true
2008-03-02 22:44:15 +01:00
);
2010-12-28 04:12:57 +01:00
2010-10-15 21:42:38 +02:00
/**
* Views available from plugins
2010-12-28 04:12:57 +01:00
*
2010-10-15 21:42:38 +02:00
* @ var array
*/
public static $views = array (
'filemanager_ui::listview' => 'Listview' ,
);
public static $views_init = false ;
2013-04-09 18:20:06 +02:00
2012-10-27 13:38:47 +02:00
/**
* vfs namespace for document merge properties
*
*/
public static $merge_prop_namespace = '' ;
2008-04-16 09:07:31 +02:00
2008-10-05 19:07:36 +02:00
/**
* Constructor
*
*/
function __construct ()
{
// strip slashes from _GET parameters, if someone still has magic_quotes_gpc on
if ( get_magic_quotes_gpc () && $_GET )
{
2016-05-05 09:20:07 +02:00
$_GET = array_stripslashes ( $_GET );
2008-10-05 19:07:36 +02:00
}
2008-11-09 17:33:09 +01:00
// do we have root rights
2016-03-21 11:06:54 +01:00
if ( Api\Cache :: getSession ( 'filemanager' , 'is_root' ))
2008-11-09 17:33:09 +01:00
{
2016-03-21 11:06:54 +01:00
Vfs :: $is_root = true ;
2008-11-09 17:33:09 +01:00
}
2010-12-28 04:12:57 +01:00
2014-11-18 13:55:32 +01:00
static :: init_views ();
2016-03-21 11:06:54 +01:00
static :: $merge_prop_namespace = Vfs :: DEFAULT_PROP_NAMESPACE . $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ];
2010-10-15 21:42:38 +02:00
}
2010-12-28 04:12:57 +01:00
2010-10-15 21:42:38 +02:00
/**
* Initialise and return available views
2010-12-28 04:12:57 +01:00
*
2010-10-15 21:42:38 +02:00
* @ return array with method => label pairs
*/
public static function init_views ()
{
2014-11-18 13:55:32 +01:00
if ( ! static :: $views_init )
2010-10-15 21:42:38 +02:00
{
// translate our labels
2014-11-18 13:55:32 +01:00
foreach ( static :: $views as & $label )
2010-10-15 21:42:38 +02:00
{
$label = lang ( $label );
}
// search for plugins with additional filemanager views
2016-05-05 09:20:07 +02:00
foreach ( Api\Hooks :: process ( 'filemanager_views' ) as $views )
2010-10-15 21:42:38 +02:00
{
2014-11-18 13:55:32 +01:00
if ( is_array ( $views )) static :: $views += $views ;
2010-10-15 21:42:38 +02:00
}
2014-11-18 13:55:32 +01:00
static :: $views_init = true ;
2010-10-15 21:42:38 +02:00
}
2014-11-18 13:55:32 +01:00
return static :: $views ;
2008-11-09 17:33:09 +01:00
}
/**
2010-10-15 21:42:38 +02:00
* Get active view
2008-11-09 17:33:09 +01:00
*
2010-10-15 21:42:38 +02:00
* @ return string
2008-11-09 17:33:09 +01:00
*/
2012-03-04 14:33:10 +01:00
public static function get_view ()
2008-11-09 17:33:09 +01:00
{
2016-03-21 11:06:54 +01:00
$view =& Api\Cache :: getSession ( 'filemanager' , 'view' );
2010-10-15 21:42:38 +02:00
if ( isset ( $_GET [ 'view' ]))
2008-11-09 17:33:09 +01:00
{
2010-10-15 21:42:38 +02:00
$view = $_GET [ 'view' ];
2008-11-09 17:33:09 +01:00
}
2014-11-18 13:55:32 +01:00
if ( ! isset ( static :: $views [ $view ]))
2008-11-09 17:33:09 +01:00
{
2014-11-18 13:55:32 +01:00
reset ( static :: $views );
$view = key ( static :: $views );
2008-11-09 17:33:09 +01:00
}
2010-10-15 21:42:38 +02:00
return $view ;
2008-10-05 19:07:36 +02:00
}
2011-06-30 15:07:55 +02:00
/**
* Context menu
*
* @ return array
*/
2014-12-05 20:34:12 +01:00
public static function get_actions ()
2011-06-30 15:07:55 +02:00
{
2011-07-01 09:49:58 +02:00
$actions = array (
2011-06-30 15:07:55 +02:00
'open' => array (
'caption' => lang ( 'Open' ),
2011-08-29 10:40:22 +02:00
'icon' => '' ,
2011-06-30 15:07:55 +02:00
'group' => $group = 1 ,
'allowOnMultiple' => false ,
2013-04-10 19:11:32 +02:00
'onExecute' => 'javaScript:app.filemanager.open' ,
2011-06-30 15:07:55 +02:00
'default' => true
),
2016-07-20 10:34:52 +02:00
'modify' => array (
'caption' => lang ( 'Edit' ),
'group' => $group ,
'icon' => 'edit' ,
'onExecute' => 'javaScript:app.filemanager.open' ,
'enabled' => 'javaScript:app.filemanager.isEditable' ,
),
2016-07-20 16:44:37 +02:00
'new' => array (
'caption' => 'New' ,
'group' => $group ,
'children' => array (
'document' => array (
'caption' => 'Document' ,
'icon' => 'new' ,
'onExecute' => 'javaScript:app.filemanager.editor_new' ,
)
)
),
2011-08-29 10:40:22 +02:00
'saveas' => array (
'caption' => lang ( 'Save as' ),
'group' => $group ,
2014-06-24 00:41:34 +02:00
'allowOnMultiple' => true ,
2011-08-29 10:40:22 +02:00
'icon' => 'filesave' ,
2013-04-09 18:20:06 +02:00
'onExecute' => 'javaScript:app.filemanager.force_download' ,
2011-08-29 10:40:22 +02:00
'disableClass' => 'isDir' ,
2014-06-24 00:41:34 +02:00
'enabled' => 'javaScript:app.filemanager.is_multiple_allowed'
2011-08-29 10:40:22 +02:00
),
2014-06-24 21:29:05 +02:00
'saveaszip' => array (
'caption' => lang ( 'Save as ZIP' ),
'group' => $group ,
'allowOnMultiple' => true ,
2014-07-17 12:10:43 +02:00
'icon' => 'save_zip' ,
2014-06-24 21:29:05 +02:00
'postSubmit' => true
),
2011-06-30 15:07:55 +02:00
'edit' => array (
'caption' => lang ( 'Edit settings' ),
'group' => $group ,
'allowOnMultiple' => false ,
2016-03-21 11:06:54 +01:00
'onExecute' => Api\Header\UserAgent :: mobile () ? 'javaScript:app.filemanager.viewEntry' : 'javaScript:app.filemanager.editprefs' ,
2016-05-25 16:44:23 +02:00
'mobileViewTemplate' => 'file?' . filemtime ( Api\Etemplate\Widget\Template :: rel2path ( '/filemanager/templates/mobile/file.xet' ))
2011-06-30 15:07:55 +02:00
),
2014-11-19 18:58:02 +01:00
'mkdir' => array (
'caption' => lang ( 'Create directory' ),
2014-11-24 17:25:05 +01:00
'icon' => 'filemanager/button_createdir' ,
2014-11-19 18:58:02 +01:00
'group' => $group ,
'allowOnMultiple' => false ,
'onExecute' => 'javaScript:app.filemanager.createdir'
),
2011-06-30 15:07:55 +02:00
'mail' => array (
'caption' => lang ( 'Mail files' ),
'icon' => 'filemanager/mail_post_to' ,
'group' => $group ,
2014-12-03 17:25:10 +01:00
'children' => array (),
2011-06-30 15:07:55 +02:00
),
2016-08-24 22:28:34 +02:00
'egw_paste' => array (
'enabled' => false ,
'group' => $group + 0.5 ,
'hideOnDisabled' => true
),
'paste' => array (
'caption' => lang ( 'Paste' ),
'acceptedTypes' => 'file' ,
'group' => $group + 0.5 ,
'order' => 10 ,
'children' => array ()
),
2012-05-03 19:58:16 +02:00
'documents' => filemanager_merge :: document_action (
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'document_dir' ],
++ $group , 'Insert in document' , 'document_' ,
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'default_document' ]
),
2011-06-30 15:07:55 +02:00
'delete' => array (
'caption' => lang ( 'Delete' ),
'group' => ++ $group ,
'confirm' => 'Delete these files or directories?' ,
2013-04-11 12:46:39 +02:00
'onExecute' => 'javaScript:app.filemanager.action' ,
2011-06-30 15:07:55 +02:00
),
2013-04-11 12:46:39 +02:00
// DRAG and DROP events
'file_drag' => array (
2014-09-23 23:25:46 +02:00
'dragType' => array ( 'file' , 'link' ),
2013-04-11 12:46:39 +02:00
'type' => 'drag' ,
2013-04-11 15:16:40 +02:00
'onExecute' => 'javaScript:app.filemanager.drag'
2013-04-11 12:46:39 +02:00
),
2014-10-17 00:41:39 +02:00
'file_drop_mail' => array (
'type' => 'drop' ,
'acceptedTypes' => 'mail' ,
2014-11-19 18:58:02 +01:00
'onExecute' => 'javaScript:app.filemanager.drop' ,
'hideOnDisabled' => true
2014-10-17 00:41:39 +02:00
),
2013-04-11 12:46:39 +02:00
'file_drop_move' => array (
'icon' => 'stylite/move' ,
'acceptedTypes' => 'file' ,
'caption' => lang ( 'Move into folder' ),
'type' => 'drop' ,
'onExecute' => 'javaScript:app.filemanager.drop' ,
'default' => true
),
'file_drop_copy' => array (
'icon' => 'stylite/edit_copy' ,
'acceptedTypes' => 'file' ,
'caption' => lang ( 'Copy into folder' ),
'type' => 'drop' ,
'onExecute' => 'javaScript:app.filemanager.drop'
2014-11-18 01:09:38 +01:00
),
'file_drop_symlink' => array (
'icon' => 'linkpaste' ,
'acceptedTypes' => 'file' ,
'caption' => lang ( 'Link into folder' ),
'type' => 'drop' ,
'onExecute' => 'javaScript:app.filemanager.drop'
2013-04-11 12:46:39 +02:00
)
2011-06-30 15:07:55 +02:00
);
2014-05-27 09:30:33 +02:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'mail' ]))
2011-07-01 09:49:58 +02:00
{
unset ( $actions [ 'mail' ]);
}
2014-12-03 17:25:10 +01:00
else
{
2016-03-21 11:06:54 +01:00
foreach ( Vfs\Sharing :: $modes as $mode => $data )
2014-12-03 17:25:10 +01:00
{
$actions [ 'mail' ][ 'children' ][ 'mail_' . $mode ] = array (
'caption' => $data [ 'label' ],
2014-12-04 10:19:03 +01:00
'hint' => $data [ 'title' ],
2014-12-03 17:25:10 +01:00
'onExecute' => 'javaScript:app.filemanager.mail' ,
);
}
}
2016-08-24 22:28:34 +02:00
// This would be done automatically, but we're overriding
foreach ( $actions as $action_id => $action )
{
if ( $action [ 'type' ] == 'drop' && $action [ 'caption' ])
{
$action [ 'type' ] = 'popup' ;
if ( $action [ 'acceptedTypes' ] == 'file' )
{
$action [ 'enabled' ] = 'javaScript:app.filemanager.drop_enabled' ;
}
$actions [ 'paste' ][ 'children' ][ " { $action_id } _paste " ] = $action ;
}
}
2011-07-01 09:49:58 +02:00
return $actions ;
2011-06-30 15:07:55 +02:00
}
2013-04-09 18:20:06 +02:00
2012-10-27 13:38:47 +02:00
/**
* Get mergeapp property for given path
*
* @ param string $path
2014-05-27 09:30:33 +02:00
* @ param string $scope ( default ) or 'parents'
2012-10-27 13:38:47 +02:00
* $scope == 'self' query only the given path
* $scope == 'parents' query only path parents for property ( first parent in hierarchy upwards wins )
*
* @ return string merge application or NULL if no property found
*/
private static function get_mergeapp ( $path , $scope = 'self' )
{
$app = null ;
switch ( $scope )
{
case 'self' :
2016-03-21 11:06:54 +01:00
$props = Vfs :: propfind ( $path , static :: $merge_prop_namespace );
2012-10-27 13:38:47 +02:00
$app = empty ( $props ) ? null : $props [ 0 ][ 'val' ];
break ;
case 'parents' :
// search for props in parent directories
$currentpath = $path ;
2016-03-21 11:06:54 +01:00
while ( $dir = Vfs :: dirname ( $currentpath ))
2012-10-27 13:38:47 +02:00
{
2016-03-21 11:06:54 +01:00
$props = Vfs :: propfind ( $dir , static :: $merge_prop_namespace );
2012-10-27 13:38:47 +02:00
if ( ! empty ( $props ))
{
// found prop in parent directory
return $app = $props [ 0 ][ 'val' ];
}
$currentpath = $dir ;
}
break ;
}
2013-04-09 18:20:06 +02:00
2012-10-27 13:38:47 +02:00
return $app ;
}
2011-06-30 15:07:55 +02:00
2008-03-02 22:44:15 +01:00
/**
* Main filemanager page
*
2014-05-27 09:30:33 +02:00
* @ param array $content
* @ param string $msg
2008-03-02 22:44:15 +01:00
*/
2008-03-03 23:15:44 +01:00
function index ( array $content = null , $msg = null )
2008-03-02 22:44:15 +01:00
{
if ( ! is_array ( $content ))
{
$content = array (
2016-03-21 11:06:54 +01:00
'nm' => Api\Cache :: getSession ( 'filemanager' , 'index' ),
2008-03-02 22:44:15 +01:00
);
2013-04-11 12:46:39 +02:00
if ( ! is_array ( $content [ 'nm' ]))
2008-03-02 22:44:15 +01:00
{
$content [ 'nm' ] = array (
'get_rows' => 'filemanager.filemanager_ui.get_rows' , // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
2014-04-08 00:46:00 +02:00
'filter' => '' , // current dir only
2008-03-02 22:44:15 +01:00
'no_filter2' => True , // I disable the 2. filter (params are the same as for filter)
'no_cat' => True , // I disable the cat-selectbox
2008-03-03 13:16:11 +01:00
'lettersearch' => True , // I show a lettersearch
2008-03-02 22:44:15 +01:00
'searchletter' => false , // I0 active letter of the lettersearch or false for [all]
2008-09-04 08:44:48 +02:00
'start' => 0 , // IO position in list
2008-03-02 22:44:15 +01:00
'order' => 'name' , // IO name of the column to sort after (optional for the sortheaders)
'sort' => 'ASC' , // IO direction of the sort: 'ASC' or 'DESC'
2008-03-03 08:53:43 +01:00
'default_cols' => '!comment,ctime' , // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns
2008-04-16 09:07:31 +02:00
'csv_fields' => false , // I false=disable csv export, true or unset=enable it with auto-detected fieldnames,
2008-03-02 22:44:15 +01:00
//or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type)
2014-11-18 13:55:32 +01:00
'actions' => static :: get_actions (),
2011-06-30 15:07:55 +02:00
'row_id' => 'path' ,
2013-04-13 21:02:09 +02:00
'row_modified' => 'mtime' ,
'parent_id' => 'dir' ,
'is_parent' => 'mime' ,
2016-03-21 11:06:54 +01:00
'is_parent_value' => Vfs :: DIR_MIME_TYPE ,
2014-11-18 01:25:37 +01:00
'favorites' => true ,
2014-11-19 18:58:02 +01:00
'placeholder_actions' => array ( 'mkdir' , 'file_drop_mail' , 'file_drop_move' , 'file_drop_copy' , 'file_drop_symlink' )
2008-03-02 22:44:15 +01:00
);
2014-11-18 13:55:32 +01:00
$content [ 'nm' ][ 'path' ] = static :: get_home_dir ();
2008-03-02 22:44:15 +01:00
}
2014-11-18 13:55:32 +01:00
$content [ 'nm' ][ 'home_dir' ] = static :: get_home_dir ();
2015-01-16 18:07:18 +01:00
$content [ 'nm' ][ 'view' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'nm_view' ];
2013-04-10 19:11:32 +02:00
2008-08-28 13:09:09 +02:00
if ( isset ( $_GET [ 'msg' ])) $msg = $_GET [ 'msg' ];
2009-05-06 17:15:39 +02:00
2015-02-02 18:50:45 +01:00
// Blank favorite set via GET needs special handling for path
if ( isset ( $_GET [ 'favorite' ]) && $_GET [ 'favorite' ] == 'blank' )
{
$content [ 'nm' ][ 'path' ] = static :: get_home_dir ();
}
2009-05-06 17:15:39 +02:00
// switch to projectmanager folders
if ( isset ( $_GET [ 'pm_id' ]))
{
$_GET [ 'path' ] = '/apps/projectmanager' . (( int ) $_GET [ 'pm_id' ] ? '/' . ( int ) $_GET [ 'pm_id' ] : '' );
}
2008-09-04 08:44:48 +02:00
if ( isset ( $_GET [ 'path' ]) && ( $path = $_GET [ 'path' ]))
2008-08-27 13:17:00 +02:00
{
2009-04-30 10:09:50 +02:00
switch ( $path )
{
case '..' :
2016-03-21 11:06:54 +01:00
$path = Vfs :: dirname ( $content [ 'nm' ][ 'path' ]);
2009-04-30 10:09:50 +02:00
break ;
case '~' :
2014-11-18 13:55:32 +01:00
$path = static :: get_home_dir ();
2009-04-30 10:09:50 +02:00
break ;
}
2016-07-02 12:39:28 +02:00
if ( $path && $path [ 0 ] == '/' && Vfs :: stat ( $path , true ) && Vfs :: is_dir ( $path ) && Vfs :: check_access ( $path , Vfs :: READABLE ))
2008-09-04 08:44:48 +02:00
{
$content [ 'nm' ][ 'path' ] = $path ;
2008-10-05 19:07:36 +02:00
}
2008-09-04 08:44:48 +02:00
else
2008-08-27 13:17:00 +02:00
{
2016-07-02 14:02:13 +02:00
$msg .= lang ( 'The requested path %1 is not available.' , $path ? Vfs :: decodePath ( $path ) : " false " );
2008-08-27 13:17:00 +02:00
}
2009-04-23 08:05:48 +02:00
// reset lettersearch as it confuses users (they think the dir is empty)
$content [ 'nm' ][ 'searchletter' ] = false ;
// switch recusive display off
2014-04-08 00:46:00 +02:00
if ( ! $content [ 'nm' ][ 'filter' ]) $content [ 'nm' ][ 'filter' ] = '' ;
2008-03-02 22:44:15 +01:00
}
}
2014-11-18 13:55:32 +01:00
$view = static :: get_view ();
2010-10-15 21:42:38 +02:00
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
*
2014-05-27 09:30:33 +02:00
* @ param string $user setup config user to become root or '' to log off as root
* @ param string $password setup config password to become root
2010-10-15 21:42:38 +02:00
* @ 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
2016-03-21 11:06:54 +01:00
$is_setup = Api\Session :: user_pw_hash ( $user , $password ) === $GLOBALS [ 'egw_info' ][ 'server' ][ 'config_hash' ];
2010-10-15 21:42:38 +02:00
// 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' );
}
2016-05-30 18:02:57 +02:00
//error_log(__METHOD__."('$user','$password',$is_setup) user_pw_hash(...)='".Api\Session::user_pw_hash($user,$password)."', config_hash='{$GLOBALS['egw_info']['server']['config_hash']}' --> returning ".array2string($is_root));
2016-03-21 11:06:54 +01:00
Api\Cache :: setSession ( 'filemanager' , 'is_setup' , $is_setup );
2016-05-30 18:02:57 +02:00
Api\Cache :: setSession ( 'filemanager' , 'is_root' , Vfs :: $is_root = $is_root );
return Vfs :: $is_root ;
2010-10-15 21:42:38 +02:00
}
/**
* Filemanager listview
*
2014-05-27 09:30:33 +02:00
* @ param array $content
* @ param string $msg
2010-10-15 21:42:38 +02:00
*/
function listview ( array $content = null , $msg = null )
{
2016-05-05 09:20:07 +02:00
$tpl = new Etemplate ( 'filemanager.index' );
2010-10-15 21:42:38 +02:00
2016-05-05 09:20:07 +02:00
if ( $msg ) Framework :: message ( $msg );
2008-03-02 22:44:15 +01:00
2011-12-27 12:08:41 +01:00
if (( $content [ 'nm' ][ 'action' ] || $content [ 'nm' ][ 'rows' ]) && ( empty ( $content [ 'button' ]) || ! isset ( $content [ 'button' ])))
2008-03-02 22:44:15 +01:00
{
2011-06-30 15:07:55 +02:00
if ( $content [ 'nm' ][ 'action' ])
2008-03-02 22:44:15 +01:00
{
2014-11-18 13:55:32 +01:00
$msg = static :: action ( $content [ 'nm' ][ 'action' ], $content [ 'nm' ][ 'selected' ], $content [ 'nm' ][ 'path' ]);
2016-05-05 09:20:07 +02:00
if ( $msg ) Framework :: message ( $msg );
2014-02-06 00:36:01 +01:00
2011-12-27 12:08:41 +01:00
// clean up after action
unset ( $content [ 'nm' ][ 'selected' ]);
// reset any occasion where action may be stored, as it may be ressurected out of the helpers by etemplate, which is quite unconvenient in case of action delete
if ( isset ( $content [ 'nm' ][ 'action' ])) unset ( $content [ 'nm' ][ 'action' ]);
if ( isset ( $content [ 'nm' ][ 'nm_action' ])) unset ( $content [ 'nm' ][ 'nm_action' ]);
if ( isset ( $content [ 'nm_action' ])) unset ( $content [ 'nm_action' ]);
// we dont use ['nm']['rows']['delete'], so unset it, if it is present
if ( isset ( $content [ 'nm' ][ 'rows' ][ 'delete' ])) unset ( $content [ 'nm' ][ 'rows' ][ 'delete' ]);
2008-03-02 22:44:15 +01:00
}
elseif ( $content [ 'nm' ][ 'rows' ][ 'delete' ])
{
2014-11-18 13:55:32 +01:00
$msg = static :: action ( 'delete' , array_keys ( $content [ 'nm' ][ 'rows' ][ 'delete' ]), $content [ 'nm' ][ 'path' ]);
2016-05-05 09:20:07 +02:00
if ( $msg ) Framework :: message ( $msg );
2014-02-06 00:36:01 +01:00
2011-12-27 12:08:41 +01:00
// clean up after action
unset ( $content [ 'nm' ][ 'rows' ][ 'delete' ]);
// reset any occasion where action may be stored, as we use ['nm']['rows']['delete'] anyhow
// we clean this up, as it may be ressurected out of the helpers by etemplate, which is quite unconvenient in case of action delete
if ( isset ( $content [ 'nm' ][ 'action' ])) unset ( $content [ 'nm' ][ 'action' ]);
if ( isset ( $content [ 'nm' ][ 'nm_action' ])) unset ( $content [ 'nm' ][ 'nm_action' ]);
if ( isset ( $content [ 'nm_action' ])) unset ( $content [ 'nm_action' ]);
if ( isset ( $content [ 'nm' ][ 'selected' ])) unset ( $content [ 'nm' ][ 'selected' ]);
2008-03-02 22:44:15 +01:00
}
unset ( $content [ 'nm' ][ 'rows' ]);
2016-03-21 11:06:54 +01:00
Api\Cache :: setSession ( 'filemanager' , 'index' , $content [ 'nm' ]);
2008-03-02 22:44:15 +01:00
}
2010-05-11 17:02:30 +02:00
// be tolerant with (in previous versions) not correct urlencoded pathes
2016-03-21 11:06:54 +01:00
if ( $content [ 'nm' ][ 'path' ][ 0 ] == '/' && ! Vfs :: stat ( $content [ 'nm' ][ 'path' ], true ) && Vfs :: stat ( urldecode ( $content [ 'nm' ][ 'path' ])))
2010-05-11 17:02:30 +02:00
{
$content [ 'nm' ][ 'path' ] = urldecode ( $content [ 'nm' ][ 'path' ]);
}
2008-03-02 22:44:15 +01:00
if ( $content [ 'button' ])
{
if ( $content [ 'button' ])
{
list ( $button ) = each ( $content [ 'button' ]);
unset ( $content [ 'button' ]);
}
switch ( $button )
{
case 'upload' :
2009-02-26 15:48:53 +01:00
if ( ! $content [ 'upload' ])
{
2016-05-05 09:20:07 +02:00
Framework :: message ( lang ( 'You need to select some files first!' ), 'error' );
2009-02-26 15:48:53 +01:00
break ;
}
$upload_success = $upload_failure = array ();
foreach ( isset ( $content [ 'upload' ][ 0 ]) ? $content [ 'upload' ] : array ( $content [ 'upload' ]) as $upload )
2008-03-02 22:44:15 +01:00
{
2010-05-11 17:02:30 +02:00
// encode chars which special meaning in url/vfs (some like / get removed!)
2016-03-21 11:06:54 +01:00
$to = Vfs :: concat ( $content [ 'nm' ][ 'path' ], Vfs :: encodePathComponent ( $upload [ 'name' ]));
2013-02-05 10:27:41 +01:00
if ( $upload &&
2016-03-21 11:06:54 +01:00
( Vfs :: is_writable ( $content [ 'nm' ][ 'path' ]) || Vfs :: is_writable ( $to )) &&
copy ( $upload [ 'tmp_name' ], Vfs :: PREFIX . $to ))
2009-02-26 15:48:53 +01:00
{
$upload_success [] = $upload [ 'name' ];
}
else
{
$upload_failure [] = $upload [ 'name' ];
}
2008-03-02 22:44:15 +01:00
}
2009-02-26 15:48:53 +01:00
$content [ 'nm' ][ 'msg' ] = '' ;
if ( $upload_success )
2008-03-02 22:44:15 +01:00
{
2016-05-05 09:20:07 +02:00
Framework :: message ( count ( $upload_success ) == 1 && ! $upload_failure ? lang ( 'File successful uploaded.' ) :
2014-02-06 00:36:01 +01:00
lang ( '%1 successful uploaded.' , implode ( ', ' , $upload_success )));
2009-02-26 15:48:53 +01:00
}
if ( $upload_failure )
{
2016-05-05 09:20:07 +02:00
Framework :: message ( lang ( 'Error uploading file!' ) . " \n " . etemplate :: max_upload_size_message (), 'error' );
2008-03-02 22:44:15 +01:00
}
break ;
}
}
2014-05-27 09:30:33 +02:00
$readonlys [ 'button[mailpaste]' ] = ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'mail' ]);
2008-04-16 09:07:31 +02:00
2008-03-03 13:16:11 +01:00
$sel_options [ 'filter' ] = array (
2014-04-08 00:46:00 +02:00
'' => 'Current directory' ,
2008-10-06 19:43:42 +02:00
'2' => 'Directories sorted in' ,
2009-05-16 13:29:47 +02:00
'3' => 'Show hidden files' ,
2014-09-23 19:46:06 +02:00
'4' => 'All subdirectories' ,
2014-10-20 20:17:31 +02:00
'5' => 'Files from links' ,
2014-04-08 00:46:00 +02:00
'0' => 'Files from subdirectories' ,
2008-03-03 13:16:11 +01:00
);
2014-12-09 13:08:00 +01:00
// sharing has no divAppbox, we need to set popupMainDiv instead, to be able to drop files everywhere
if ( substr ( $_SERVER [ 'SCRIPT_FILENAME' ], - 10 ) == '/share.php' )
{
$tpl -> setElementAttribute ( 'nm[buttons][upload]' , 'drop_target' , 'popupMainDiv' );
}
2015-01-13 22:56:54 +01:00
// Set view button to match current settings
if ( $content [ 'nm' ][ 'view' ] == 'tile' )
{
2016-03-08 14:55:26 +01:00
$tpl -> setElementAttribute ( 'nm[button][change_view]' , 'statustext' , lang ( 'List view' ));
$tpl -> setElementAttribute ( 'nm[button][change_view]' , 'image' , 'list_row' );
2015-01-13 22:56:54 +01:00
}
2014-12-10 11:32:47 +01:00
// if initial load is done via GET request (idots template or share.php)
// get_rows cant call app.filemanager.set_readonly, so we need to do that here
2016-03-21 11:06:54 +01:00
$content [ 'initial_path_readonly' ] = ! Vfs :: is_writable ( $content [ 'nm' ][ 'path' ]);
2014-12-10 11:32:47 +01:00
2008-03-02 22:44:15 +01:00
$tpl -> exec ( 'filemanager.filemanager_ui.index' , $content , $sel_options , $readonlys , array ( 'nm' => $content [ 'nm' ]));
}
2008-03-04 17:53:14 +01:00
2008-10-14 15:20:31 +02:00
/**
* Get the configured start directory for the current user
*
* @ return string
*/
static function get_home_dir ()
{
$start = '/home/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lid' ];
// check if user specified a valid startpath in his prefs --> use it
if (( $path = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'startfolder' ]) &&
2016-03-21 11:06:54 +01:00
$path [ 0 ] == '/' && Vfs :: is_dir ( $path ) && Vfs :: check_access ( $path , Vfs :: READABLE ))
2008-10-14 15:20:31 +02:00
{
$start = $path ;
}
2016-03-21 11:06:54 +01:00
elseif ( ! Vfs :: is_dir ( $start ) && Vfs :: check_access ( $start , Vfs :: READABLE ))
2014-11-18 13:55:32 +01:00
{
$start = '/' ;
}
2008-10-14 15:20:31 +02:00
return $start ;
}
2008-03-02 22:44:15 +01:00
/**
* Run a certain action with the selected file
*
* @ param string $action
* @ param array $selected selected pathes
2014-05-27 09:30:33 +02:00
* @ param mixed $dir current directory
2010-12-28 04:12:57 +01:00
* @ param int & $errs = null on return number of errors
* @ param int & $dirs = null on return number of dirs deleted
* @ param int & $files = null on return number of files deleted
2008-03-02 22:44:15 +01:00
* @ return string success or failure message displayed to the user
*/
2014-12-05 20:34:12 +01:00
static public function action ( $action , $selected , $dir = null , & $errs = null , & $files = null , & $dirs = null )
2008-03-02 22:44:15 +01:00
{
if ( ! count ( $selected ))
{
return lang ( 'You need to select some files first!' );
}
$errs = $dirs = $files = 0 ;
2012-05-03 19:58:16 +02:00
2008-03-02 22:44:15 +01:00
switch ( $action )
{
2010-05-06 08:53:52 +02:00
2008-03-02 22:44:15 +01:00
case 'delete' :
2014-11-18 13:55:32 +01:00
return static :: do_delete ( $selected , $errs , $files , $dirs );
2010-05-06 08:53:52 +02:00
2014-12-09 17:29:00 +01:00
case 'mail' :
2008-03-02 22:44:15 +01:00
case 'copy' :
foreach ( $selected as $path )
{
2014-10-17 00:41:39 +02:00
if ( strpos ( $path , 'mail::' ) === 0 && $path = substr ( $path , 6 ))
{
// Support for dropping mail in filemanager - Pass mail back to mail app
if ( ExecMethod2 ( 'mail.mail_ui.vfsSaveMessage' , $path , $dir , false ))
{
++ $files ;
}
else
{
++ $errs ;
}
}
2016-03-21 11:06:54 +01:00
elseif ( ! Vfs :: is_dir ( $path ))
2008-03-02 22:44:15 +01:00
{
2016-03-21 11:06:54 +01:00
$to = Vfs :: concat ( $dir , Vfs :: basename ( $path ));
if ( $path != $to && Vfs :: copy ( $path , $to ))
2008-03-02 22:44:15 +01:00
{
++ $files ;
}
else
{
++ $errs ;
}
}
else
{
$len = strlen ( dirname ( $path ));
2016-03-21 11:06:54 +01:00
foreach ( Vfs :: find ( $path ) as $p )
2008-03-02 22:44:15 +01:00
{
$to = $dir . substr ( $p , $len );
2008-03-04 08:35:05 +01:00
if ( $to == $p ) // cant copy into itself!
{
++ $errs ;
continue ;
}
2016-03-21 11:06:54 +01:00
if (( $is_dir = Vfs :: is_dir ( $p )) && Vfs :: mkdir ( $to , null , STREAM_MKDIR_RECURSIVE ))
2008-03-02 22:44:15 +01:00
{
++ $dirs ;
}
2016-03-21 11:06:54 +01:00
elseif ( ! $is_dir && Vfs :: copy ( $p , $to ))
2008-03-02 22:44:15 +01:00
{
++ $files ;
}
else
{
++ $errs ;
}
}
}
}
if ( $errs )
{
return lang ( '%1 errors copying (%2 diretories and %3 files copied)!' , $errs , $dirs , $files );
}
return $dirs ? lang ( '%1 directories and %2 files copied.' , $dirs , $files ) : lang ( '%1 files copied.' , $files );
2008-04-16 09:07:31 +02:00
2010-12-28 04:12:57 +01:00
case 'move' :
2008-03-02 22:44:15 +01:00
foreach ( $selected as $path )
{
2016-03-21 11:06:54 +01:00
$to = Vfs :: is_dir ( $dir ) || count ( $selected ) > 1 ? Vfs :: concat ( $dir , Vfs :: basename ( $path )) : $dir ;
if ( $path != $to && Vfs :: rename ( $path , $to ))
2008-03-02 22:44:15 +01:00
{
++ $files ;
}
else
{
++ $errs ;
}
}
if ( $errs )
{
return lang ( '%1 errors moving (%2 files moved)!' , $errs , $files );
}
return lang ( '%1 files moved.' , $files );
2009-04-09 16:05:14 +02:00
2013-04-12 10:56:28 +02:00
case 'symlink' : // symlink given files to $dir
foreach (( array ) $selected as $target )
2009-04-09 16:05:14 +02:00
{
2016-03-21 11:06:54 +01:00
$link = Vfs :: concat ( $dir , Vfs :: basename ( $target ));
if ( ! Vfs :: stat ( $dir ) || ( $ok = Vfs :: mkdir ( $dir , 0 , true )))
2014-09-01 23:23:04 +02:00
{
if ( ! $ok )
{
$errs ++ ;
continue ;
}
}
2016-03-21 11:06:54 +01:00
if ( $target [ 0 ] != '/' ) $target = Vfs :: concat ( $dir , $target );
if ( ! Vfs :: stat ( $target ))
2013-04-12 10:56:28 +02:00
{
2016-03-21 11:06:54 +01:00
return lang ( 'Link target %1 not found!' , Vfs :: decodePath ( $target ));
2013-04-12 10:56:28 +02:00
}
2016-03-21 11:06:54 +01:00
if ( $target != $link && Vfs :: symlink ( $target , $link ))
2009-04-09 16:05:14 +02:00
{
++ $files ;
}
else
{
++ $errs ;
}
}
2013-04-12 10:56:28 +02:00
if ( count (( array ) $selected ) == 1 )
{
2016-03-21 11:06:54 +01:00
return $files ? lang ( 'Symlink to %1 created.' , Vfs :: decodePath ( $target )) :
lang ( 'Error creating symlink to target %1!' , Vfs :: decodePath ( $target ));
2013-04-12 10:56:28 +02:00
}
$ret = lang ( '%1 elements linked.' , $files );
2009-04-09 16:05:14 +02:00
if ( $errs )
{
2013-04-12 10:56:28 +02:00
$ret = lang ( '%1 errors linking (%2)!' , $errs , $ret );
2009-04-09 16:05:14 +02:00
}
2016-03-21 11:06:54 +01:00
return $ret ; //." Vfs::symlink('$target', '$link')";
2013-04-11 15:16:40 +02:00
case 'createdir' :
2016-03-21 11:06:54 +01:00
$dst = Vfs :: concat ( $dir , is_array ( $selected ) ? $selected [ 0 ] : $selected );
if ( Vfs :: mkdir ( $dst , null , STREAM_MKDIR_RECURSIVE ))
2013-04-11 15:16:40 +02:00
{
2013-04-12 10:07:26 +02:00
return lang ( " Directory successfully created. " );
2013-04-11 15:16:40 +02:00
}
2013-04-12 10:07:26 +02:00
return lang ( " Error while creating directory. " );
2013-04-11 15:16:40 +02:00
2014-06-24 21:29:05 +02:00
case 'saveaszip' :
2016-03-21 11:06:54 +01:00
Vfs :: download_zip ( $selected );
exit ;
2014-10-13 19:23:33 +02:00
2012-05-11 12:30:52 +02:00
default :
list ( $action , $settings ) = explode ( '_' , $action , 2 );
switch ( $action )
{
case 'document' :
if ( ! $settings ) $settings = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'default_document' ];
2016-03-21 11:06:54 +01:00
$document_merge = new filemanager_merge ( Vfs :: decodePath ( $dir ));
2012-05-11 12:30:52 +02:00
$msg = $document_merge -> download ( $settings , $selected , '' , $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'document_dir' ]);
2012-05-16 19:33:37 +02:00
if ( $msg ) return $msg ;
2014-11-18 13:55:32 +01:00
$errs = count ( $selected );
2012-05-11 12:30:52 +02:00
return false ;
}
2008-03-02 22:44:15 +01:00
}
return " Unknown action ' $action '! " ;
}
2010-12-28 04:12:57 +01:00
2010-09-24 20:55:36 +02:00
/**
* Delete selected files and return success or error message
2010-12-28 04:12:57 +01:00
*
2010-09-24 20:55:36 +02:00
* @ param array $selected
2010-12-28 04:12:57 +01:00
* @ param int & $errs = null on return number of errors
* @ param int & $dirs = null on return number of dirs deleted
* @ param int & $files = null on return number of files deleted
2010-09-24 20:55:36 +02:00
* @ return string
*/
2010-12-28 04:12:57 +01:00
public static function do_delete ( array $selected , & $errs = null , & $dirs = null , & $files = null )
2010-09-24 20:55:36 +02:00
{
$dirs = $files = $errs = 0 ;
// we first delete all selected links (and files)
2016-03-21 11:06:54 +01:00
// feeding the links to dirs to Vfs::find() deletes the content of the dirs, not just the link!
2010-09-24 20:55:36 +02:00
foreach ( $selected as $key => $path )
{
2016-03-21 11:06:54 +01:00
if ( ! Vfs :: is_dir ( $path ) || Vfs :: is_link ( $path ))
2010-09-24 20:55:36 +02:00
{
2016-03-21 11:06:54 +01:00
if ( Vfs :: unlink ( $path ))
2010-09-24 20:55:36 +02:00
{
++ $files ;
}
else
{
++ $errs ;
}
unset ( $selected [ $key ]);
}
}
if ( $selected ) // somethings left to delete
{
// some precaution to never allow to (recursivly) remove /, /apps or /home
foreach (( array ) $selected as $path )
{
2016-08-18 10:03:53 +02:00
if ( Vfs :: isProtectedDir ( $path ))
2010-09-24 20:55:36 +02:00
{
2010-12-28 04:12:57 +01:00
$errs ++ ;
2016-03-21 11:06:54 +01:00
return lang ( " Cautiously rejecting to remove folder '%1'! " , Vfs :: decodePath ( $path ));
2010-09-24 20:55:36 +02:00
}
}
// now we use find to loop through all files and dirs: (selected only contains dirs now)
// - depth=true to get first the files and then the dir containing it
// - hidden=true to also return hidden files (eg. Thumbs.db), as we cant delete non-empty dirs
2016-01-21 12:49:50 +01:00
// - show-deleted=false to not (finally) deleted versioned files
2016-03-21 11:06:54 +01:00
foreach ( Vfs :: find ( $selected , array ( 'depth' => true , 'hidden' => true , 'show-deleted' => false )) as $path )
2010-09-24 20:55:36 +02:00
{
2016-03-21 11:06:54 +01:00
if (( $is_dir = Vfs :: is_dir ( $path ) && ! Vfs :: is_link ( $path )) && Vfs :: rmdir ( $path , 0 ))
2010-09-24 20:55:36 +02:00
{
++ $dirs ;
}
2016-03-21 11:06:54 +01:00
elseif ( ! $is_dir && Vfs :: unlink ( $path ))
2010-09-24 20:55:36 +02:00
{
++ $files ;
}
else
{
++ $errs ;
}
}
}
if ( $errs )
{
return lang ( '%1 errors deleteting (%2 directories and %3 files deleted)!' , $errs , $dirs , $files );
}
if ( $dirs )
{
return lang ( '%1 directories and %2 files deleted.' , $dirs , $files );
}
return $files == 1 ? lang ( 'File deleted.' ) : lang ( '%1 files deleted.' , $files );
}
2008-03-02 22:44:15 +01:00
/**
* Callback to fetch the rows for the nextmatch widget
*
* @ param array $query
* @ param array & $rows
*/
2015-01-13 22:56:54 +01:00
function get_rows ( & $query , & $rows )
2008-03-02 22:44:15 +01:00
{
2013-04-20 14:24:45 +02:00
// do NOT store query, if hierarchical data / children are requested
2013-10-10 13:29:31 +02:00
if ( ! $query [ 'csv_export' ])
2013-04-20 14:24:45 +02:00
{
2016-03-21 11:06:54 +01:00
Api\Cache :: setSession ( 'filemanager' , 'index' , $query );
2013-04-20 14:24:45 +02:00
}
2014-11-18 13:55:32 +01:00
if ( ! $query [ 'path' ]) $query [ 'path' ] = static :: get_home_dir ();
2014-06-04 14:08:57 +02:00
2015-01-13 22:56:54 +01:00
// Change template to match selected view
if ( $query [ 'view' ])
{
$query [ 'template' ] = ( $query [ 'view' ] == 'row' ? 'filemanager.index.rows' : 'filemanager.tile' );
2015-01-16 18:07:18 +01:00
// Store as preference but only for index, not home
if ( $query [ 'get_rows' ] == 'filemanager.filemanager_ui.get_rows' )
{
$GLOBALS [ 'egw' ] -> preferences -> add ( 'filemanager' , 'nm_view' , $query [ 'view' ]);
$GLOBALS [ 'egw' ] -> preferences -> save_repository ();
}
2015-01-13 22:56:54 +01:00
}
2010-05-11 17:02:30 +02:00
// be tolerant with (in previous versions) not correct urlencoded pathes
2016-03-21 11:06:54 +01:00
if ( ! Vfs :: stat ( $query [ 'path' ], true ) && Vfs :: stat ( urldecode ( $query [ 'path' ])))
2010-05-11 17:02:30 +02:00
{
$query [ 'path' ] = urldecode ( $query [ 'path' ]);
}
2016-03-21 11:06:54 +01:00
if ( ! Vfs :: stat ( $query [ 'path' ], true ) || ! Vfs :: is_dir ( $query [ 'path' ]) || ! Vfs :: check_access ( $query [ 'path' ], Vfs :: READABLE ))
2008-03-02 22:44:15 +01:00
{
2014-11-18 13:55:32 +01:00
// only redirect, if it would be to some other location, gives redirect-loop otherwise
if ( $query [ 'path' ] != ( $path = static :: get_home_dir ()))
{
// we will leave here, since we are not allowed, or the location does not exist. Index must handle that, and give
// an appropriate message
2016-05-05 09:20:07 +02:00
Egw :: redirect_link ( '/index.php' , array ( 'menuaction' => 'filemanager.filemanager_ui.index' ,
2014-11-18 13:55:32 +01:00
'path' => $path ,
2016-03-21 11:06:54 +01:00
'msg' => lang ( 'The requested path %1 is not available.' , Vfs :: decodePath ( $query [ 'path' ])),
2014-11-18 13:55:32 +01:00
'ajax' => 'true'
));
}
$rows = array ();
return 0 ;
2008-03-02 22:44:15 +01:00
}
2008-03-03 13:16:11 +01:00
$rows = $dir_is_writable = array ();
if ( $query [ 'searchletter' ] && ! empty ( $query [ 'search' ]))
{
$namefilter = '/^' . $query [ 'searchletter' ] . '.*' . str_replace ( array ( '\\?' , '\\*' ), array ( '.{1}' , '.*' ), preg_quote ( $query [ 'search' ])) . '/i' ;
if ( $query [ 'searchletter' ] == strtolower ( $query [ 'search' ][ 0 ]))
{
$namefilter = '/^(' . $query [ 'searchletter' ] . '.*' . str_replace ( array ( '\\?' , '\\*' ), array ( '.{1}' , '.*' ), preg_quote ( $query [ 'search' ])) . '|' .
str_replace ( array ( '\\?' , '\\*' ), array ( '.{1}' , '.*' ), preg_quote ( $query [ 'search' ])) . ')/i' ;
}
}
elseif ( $query [ 'searchletter' ])
{
$namefilter = '/^' . $query [ 'searchletter' ] . '/i' ;
}
elseif ( ! empty ( $query [ 'search' ]))
{
$namefilter = '/' . str_replace ( array ( '\\?' , '\\*' ), array ( '.{1}' , '.*' ), preg_quote ( $query [ 'search' ])) . '/i' ;
}
2014-06-04 14:08:57 +02:00
2014-04-08 00:46:00 +02:00
// Re-map so 'No filters' favorite ('') is depth 1
$filter = $query [ 'filter' ] === '' ? 1 : $query [ 'filter' ];
2014-09-23 19:46:06 +02:00
$maxdepth = $filter && $filter != 4 ? ( int )( boolean ) $filter : null ;
if ( $filter == 5 ) $maxdepth = 2 ;
2014-11-18 13:55:32 +01:00
$n = 0 ;
2015-01-21 00:58:38 +01:00
$vfs_options = array (
2008-10-06 19:43:42 +02:00
'mindepth' => 1 ,
2014-09-23 19:46:06 +02:00
'maxdepth' => $maxdepth ,
2014-04-08 00:46:00 +02:00
'dirsontop' => $filter <= 1 ,
2014-10-20 20:17:31 +02:00
'type' => $filter && $filter != 5 ? ( $filter == 4 ? 'd' : null ) : ( $filter == 5 ? 'F' : 'f' ),
2008-10-06 19:43:42 +02:00
'order' => $query [ 'order' ], 'sort' => $query [ 'sort' ],
'limit' => ( int ) $query [ 'num_rows' ] . ',' . ( int ) $query [ 'start' ],
'need_mime' => true ,
'name_preg' => $namefilter ,
2014-04-08 00:46:00 +02:00
'hidden' => $filter == 3 ,
2014-10-20 20:17:31 +02:00
'follow' => $filter == 5 ,
2015-01-21 00:58:38 +01:00
);
if ( $query [ 'col_filter' ][ 'mime' ])
{
$vfs_options [ 'mime' ] = $query [ 'col_filter' ][ 'mime' ];
}
2016-03-21 11:06:54 +01:00
foreach ( Vfs :: find ( ! empty ( $query [ 'col_filter' ][ 'dir' ]) ? $query [ 'col_filter' ][ 'dir' ] : $query [ 'path' ], $vfs_options , true ) as $path => $row )
2008-10-06 19:43:42 +02:00
{
//echo $path; _debug_array($row);
2008-10-05 19:07:36 +02:00
2008-10-06 19:43:42 +02:00
$dir = dirname ( $path );
if ( ! isset ( $dir_is_writable [ $dir ]))
2008-03-03 13:16:11 +01:00
{
2016-03-21 11:06:54 +01:00
$dir_is_writable [ $dir ] = Vfs :: is_writable ( $dir );
2008-03-03 13:16:11 +01:00
}
2016-03-21 11:06:54 +01:00
if ( Vfs :: is_dir ( $path ))
2011-08-29 10:40:22 +02:00
{
$row [ 'class' ] = 'isDir' ;
}
2016-03-21 11:06:54 +01:00
$row [ 'download_url' ] = Vfs :: download_url ( $path );
2015-03-27 10:28:46 +01:00
$row [ 'gid' ] = - abs ( $row [ 'gid' ]); // gid are positive, but we use negagive account_id for groups internal
2013-04-09 18:20:06 +02:00
2011-08-29 10:40:22 +02:00
$rows [ ++ $n ] = $row ;
$path2n [ $path ] = $n ;
2008-03-02 22:44:15 +01:00
}
2008-10-05 19:07:36 +02:00
// query comments and cf's for the displayed rows
$cols_to_show = explode ( ',' , $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'filemanager' ][ 'nextmatch-filemanager.index.rows' ]);
2015-03-27 10:28:46 +01:00
2015-01-16 17:50:52 +01:00
// Always include comment in tiles
if ( $query [ 'view' ] == 'tile' )
{
$cols_to_show [] = 'comment' ;
}
2008-10-05 19:07:36 +02:00
$all_cfs = in_array ( 'customfields' , $cols_to_show ) && $cols_to_show [ count ( $cols_to_show ) - 1 ][ 0 ] != '#' ;
if ( $path2n && ( in_array ( 'comment' , $cols_to_show ) || in_array ( 'customfields' , $cols_to_show )) &&
2016-03-21 11:06:54 +01:00
( $path2props = Vfs :: propfind ( array_keys ( $path2n ))))
2008-10-05 19:07:36 +02:00
{
foreach ( $path2props as $path => $props )
{
2008-10-21 11:08:37 +02:00
unset ( $row ); // fixes a weird problem with php5.1, does NOT happen with php5.2
2008-10-05 19:07:36 +02:00
$row =& $rows [ $path2n [ $path ]];
2009-02-27 11:22:28 +01:00
if ( ! is_array ( $props ) ) continue ;
2008-10-05 19:07:36 +02:00
foreach ( $props as $prop )
{
if ( ! $all_cfs && $prop [ 'name' ][ 0 ] == '#' && ! in_array ( $prop [ 'name' ], $cols_to_show )) continue ;
2008-10-05 21:01:49 +02:00
$row [ $prop [ 'name' ]] = strlen ( $prop [ 'val' ]) < 64 ? $prop [ 'val' ] : substr ( $prop [ 'val' ], 0 , 64 ) . ' ...' ;
2008-10-05 19:07:36 +02:00
}
}
}
2013-04-12 19:57:12 +02:00
// tell client-side if directory is writeable or not
2016-03-21 11:06:54 +01:00
$response = Api\Json\Response :: get ();
$response -> call ( 'app.filemanager.set_readonly' , $query [ 'path' ], ! Vfs :: is_writable ( $query [ 'path' ]));
2013-04-12 11:33:37 +02:00
2008-03-02 22:44:15 +01:00
//_debug_array($readonlys);
2009-05-06 17:15:39 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'projectmanager' )
{
// we need our app.css file
if ( ! file_exists ( EGW_SERVER_ROOT . ( $css_file = '/filemanager/templates/' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] . '/app.css' )))
{
$css_file = '/filemanager/templates/default/app.css' ;
}
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'css' ] .= " \n \t \t </style> \n \t \t " . '<link href="' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] .
$css_file . '?' . filemtime ( EGW_SERVER_ROOT . $css_file ) . '" type="text/css" rel="StyleSheet" />' . " \n \t \t <style> \n \t \t \t " ;
}
2016-03-21 11:06:54 +01:00
return Vfs :: $find_total ;
2008-03-02 22:44:15 +01:00
}
2008-04-16 09:07:31 +02:00
2008-03-03 23:15:44 +01:00
/**
* Preferences of a file / directory
*
2014-05-27 09:30:33 +02:00
* @ param array $content
* @ param string $msg
2008-03-03 23:15:44 +01:00
*/
2008-04-14 07:54:10 +02:00
function file ( array $content = null , $msg = '' )
2008-03-03 23:15:44 +01:00
{
2016-05-05 09:20:07 +02:00
$tpl = new Etemplate ( 'filemanager.file' );
2008-04-16 09:07:31 +02:00
2008-03-03 23:15:44 +01:00
if ( ! is_array ( $content ))
{
2010-04-22 19:38:01 +02:00
if ( isset ( $_GET [ 'msg' ]))
{
$msg .= $_GET [ 'msg' ];
}
2011-09-05 12:25:28 +02:00
if ( ! ( $path = str_replace ( array ( '#' , '?' ), array ( '%23' , '%3F' ), $_GET [ 'path' ])) || // ?, # need to stay encoded!
// actions enclose pathes containing comma with "
( $path [ 0 ] == '"' && substr ( $path , - 1 ) == '"' && ! ( $path = substr ( str_replace ( '""' , '"' , $path ), 1 , - 1 ))) ||
2016-03-21 11:06:54 +01:00
! ( $stat = Vfs :: lstat ( $path )))
2008-03-03 23:15:44 +01:00
{
2011-09-05 12:25:28 +02:00
$msg .= lang ( 'File or directory not found!' ) . " path=' $path ', stat= " . array2string ( $stat );
2008-03-03 23:15:44 +01:00
}
else
{
$content = $stat ;
2016-03-21 11:06:54 +01:00
$content [ 'name' ] = $content [ 'itempicker_merge' ][ 'name' ] = Vfs :: basename ( $path );
2016-07-02 12:39:28 +02:00
$content [ 'dir' ] = $content [ 'itempicker_merge' ][ 'dir' ] = ( $dir = Vfs :: dirname ( $path )) ? Vfs :: decodePath ( $dir ) : '' ;
2008-03-03 23:15:44 +01:00
$content [ 'path' ] = $path ;
2016-03-21 11:06:54 +01:00
$content [ 'hsize' ] = Vfs :: hsize ( $stat [ 'size' ]);
$content [ 'mime' ] = Vfs :: mime_content_type ( $path );
2008-03-03 23:15:44 +01:00
$content [ 'gid' ] *= - 1 ; // our widgets use negative gid's
2016-03-21 11:06:54 +01:00
if (( $props = Vfs :: propfind ( $path )))
2008-10-05 19:07:36 +02:00
{
2014-05-27 09:30:33 +02:00
foreach ( $props as $prop )
{
$content [ $prop [ 'name' ]] = $prop [ 'val' ];
}
2008-10-05 19:07:36 +02:00
}
2016-03-21 11:06:54 +01:00
if (( $content [ 'is_link' ] = Vfs :: is_link ( $path )))
2009-03-19 21:12:35 +01:00
{
2016-03-21 11:06:54 +01:00
$content [ 'symlink' ] = Vfs :: readlink ( $path );
2009-03-19 21:12:35 +01:00
}
2008-03-03 23:15:44 +01:00
}
2009-03-19 21:12:35 +01:00
$content [ 'tabs' ] = $_GET [ 'tabs' ];
2016-03-21 11:06:54 +01:00
if ( ! ( $content [ 'is_dir' ] = Vfs :: is_dir ( $path ) && ! Vfs :: is_link ( $path )))
2008-03-03 23:15:44 +01:00
{
$content [ 'perms' ][ 'executable' ] = ( int ) !! ( $content [ 'mode' ] & 0111 );
$mask = 6 ;
if ( preg_match ( '/^text/' , $content [ 'mime' ]) && $content [ 'size' ] < 100000 )
{
2016-03-21 11:06:54 +01:00
$content [ 'text_content' ] = file_get_contents ( Vfs :: PREFIX . $path );
2008-03-03 23:15:44 +01:00
}
}
else
{
2008-04-14 07:54:10 +02:00
//currently not implemented in backend $content['perms']['sticky'] = (int)!!($content['mode'] & 0x201);
2008-03-03 23:15:44 +01:00
$mask = 7 ;
}
foreach ( array ( 'owner' => 6 , 'group' => 3 , 'other' => 0 ) as $name => $shift )
{
$content [ 'perms' ][ $name ] = ( $content [ 'mode' ] >> $shift ) & $mask ;
}
2016-03-21 11:06:54 +01:00
$content [ 'is_owner' ] = Vfs :: has_owner_rights ( $path , $content );
2008-03-03 23:15:44 +01:00
}
else
{
2008-04-14 07:54:10 +02:00
//_debug_array($content);
2008-07-27 20:58:41 +02:00
$path =& $content [ 'path' ];
2008-04-16 09:07:31 +02:00
2008-04-14 07:54:10 +02:00
list ( $button ) = @ each ( $content [ 'button' ]); unset ( $content [ 'button' ]);
2013-12-16 19:46:48 +01:00
if ( ! $button && $content [ 'sudo' ])
{
// Button to stop sudo is not in button namespace
$button = 'sudo' ;
unset ( $content [ 'sudo' ]);
}
2010-05-11 17:02:30 +02:00
// need to check 'setup' button (submit button in sudo popup), as some browsers (eg. chrome) also fill the hidden field
2016-03-21 11:06:54 +01:00
if ( $button == 'sudo' && Vfs :: $is_root || $button == 'setup' && $content [ 'sudo' ][ 'user' ])
2008-11-09 17:33:09 +01:00
{
2010-05-11 17:02:30 +02:00
$msg = $this -> sudo ( $button == 'setup' ? $content [ 'sudo' ][ 'user' ] : '' , $content [ 'sudo' ][ 'passwd' ]) ?
lang ( 'Root access granted.' ) : ( $button == 'setup' && $content [ 'sudo' ][ 'user' ] ?
lang ( 'Wrong username or password!' ) : lang ( 'Root access stopped.' ));
2008-11-09 17:33:09 +01:00
unset ( $content [ 'sudo' ]);
2016-03-21 11:06:54 +01:00
$content [ 'is_owner' ] = Vfs :: has_owner_rights ( $path );
2008-11-09 17:33:09 +01:00
}
2008-04-14 07:54:10 +02:00
if ( in_array ( $button , array ( 'save' , 'apply' )))
2008-03-03 23:15:44 +01:00
{
2008-10-05 19:07:36 +02:00
$props = array ();
2014-11-18 13:55:32 +01:00
$perm_changed = $perm_failed = 0 ;
2008-04-14 07:54:10 +02:00
foreach ( $content [ 'old' ] as $name => $old_value )
2008-03-03 23:15:44 +01:00
{
2009-06-14 15:26:07 +02:00
if ( isset ( $content [ $name ]) && ( $old_value != $content [ $name ] ||
// do not check for modification, if modify_subs is checked!
2009-12-01 10:07:18 +01:00
$content [ 'modify_subs' ] && in_array ( $name , array ( 'uid' , 'gid' , 'perms' ))) &&
2016-03-21 11:06:54 +01:00
( $name != 'uid' || Vfs :: $is_root ))
2008-03-03 23:15:44 +01:00
{
2008-10-05 19:07:36 +02:00
if ( $name == 'name' )
{
2016-07-02 12:39:28 +02:00
if ( ! ( $dir = Vfs :: dirname ( $path )))
{
$msg .= lang ( 'File or directory not found!' ) . " Vfs::dirname(' $path ')===false " ;
if ( $button == 'save' ) $button = 'apply' ;
continue ;
}
$to = Vfs :: concat ( $dir , $content [ 'name' ]);
2016-03-21 11:06:54 +01:00
if ( file_exists ( Vfs :: PREFIX . $to ) && $content [ 'confirm_overwrite' ] !== $to )
2008-11-16 11:18:19 +01:00
{
$tpl -> set_validation_error ( 'name' , lang ( " There's already a file with that name! " ) . '<br />' .
lang ( 'To overwrite the existing file store again.' , lang ( $button )));
$content [ 'confirm_overwrite' ] = $to ;
if ( $button == 'save' ) $button = 'apply' ;
continue ;
}
2016-03-21 11:06:54 +01:00
if ( Vfs :: rename ( $path , $to ))
2008-10-05 19:07:36 +02:00
{
2016-03-21 11:06:54 +01:00
$msg .= lang ( 'Renamed %1 to %2.' , Vfs :: decodePath ( basename ( $path )), Vfs :: decodePath ( basename ( $to ))) . ' ' ;
2008-10-05 19:07:36 +02:00
$content [ 'old' ][ 'name' ] = $content [ $name ];
$path = $to ;
2016-05-05 09:20:07 +02:00
$content [ 'mime' ] = Api\MimeMagic :: filename2mime ( $path ); // recheck mime type
2016-03-21 11:06:54 +01:00
$refresh_path = Vfs :: dirname ( $path ); // for renames, we have to refresh the parent
2008-10-05 19:07:36 +02:00
}
else
{
2016-03-21 11:06:54 +01:00
$msg .= lang ( 'Rename of %1 to %2 failed!' , Vfs :: decodePath ( basename ( $path )), Vfs :: decodePath ( basename ( $to ))) . ' ' ;
if ( Vfs :: deny_script ( $to ))
2009-03-31 13:30:12 +02:00
{
$msg .= lang ( 'You are NOT allowed to upload a script!' ) . ' ' ;
}
2008-10-05 19:07:36 +02:00
}
}
elseif ( $name [ 0 ] == '#' || $name == 'comment' )
2008-04-14 07:54:10 +02:00
{
2008-10-05 21:01:49 +02:00
$props [] = array ( 'name' => $name , 'val' => $content [ $name ] ? $content [ $name ] : null );
2008-04-14 07:54:10 +02:00
}
2012-10-27 13:38:47 +02:00
elseif ( $name == 'mergeapp' )
{
$mergeprop = array (
array (
2014-11-18 13:55:32 +01:00
'ns' => static :: $merge_prop_namespace ,
2012-10-27 13:38:47 +02:00
'name' => 'mergeapp' ,
'val' => ( ! empty ( $content [ $name ]) ? $content [ $name ] : null ),
),
);
2016-03-21 11:06:54 +01:00
if ( Vfs :: proppatch ( $path , $mergeprop ))
2012-10-27 13:38:47 +02:00
{
$content [ 'old' ][ $name ] = $content [ $name ];
$msg .= lang ( 'Setting for document merge saved.' );
}
else
{
$msg .= lang ( 'Saving setting for document merge failed!' );
}
}
2008-10-05 19:07:36 +02:00
else
{
static $name2cmd = array ( 'uid' => 'chown' , 'gid' => 'chgrp' , 'perms' => 'chmod' );
$cmd = array ( 'egw_vfs' , $name2cmd [ $name ]);
2014-11-18 13:55:32 +01:00
$value = $name == 'perms' ? static :: perms2mode ( $content [ 'perms' ]) : $content [ $name ];
2008-11-09 17:33:09 +01:00
if ( $content [ 'modify_subs' ])
2008-10-05 19:07:36 +02:00
{
2008-11-09 17:33:09 +01:00
if ( $name == 'perms' )
{
2016-03-21 11:06:54 +01:00
$changed = Vfs :: find ( $path , array ( 'type' => 'd' ), $cmd , array ( $value ));
$changed += Vfs :: find ( $path , array ( 'type' => 'f' ), $cmd , array ( $value & 0666 )); // no execute for files
2008-11-09 17:33:09 +01:00
}
else
{
2016-03-21 11:06:54 +01:00
$changed = Vfs :: find ( $path , null , $cmd , array ( $value ));
2008-11-09 17:33:09 +01:00
}
$ok = $failed = 0 ;
2014-05-27 09:30:33 +02:00
foreach ( $changed as & $r )
2008-11-09 17:33:09 +01:00
{
if ( $r )
{
++ $ok ;
}
else
{
++ $failed ;
}
}
if ( $ok && ! $failed )
{
2009-06-14 15:26:07 +02:00
if ( ! $perm_changed ++ ) $msg .= lang ( 'Permissions of %1 changed.' , $path . ' ' . lang ( 'and all it\'s childeren' ));
2008-11-12 18:04:38 +01:00
$content [ 'old' ][ $name ] = $content [ $name ];
2008-11-09 17:33:09 +01:00
}
elseif ( $failed )
{
2009-06-14 15:26:07 +02:00
if ( ! $perm_failed ++ ) $msg .= lang ( 'Failed to change permissions of %1!' , $path . lang ( 'and all it\'s childeren' ) .
2008-11-09 17:33:09 +01:00
( $ok ? ' (' . lang ( '%1 failed, %2 succeded' , $failed , $ok ) . ')' : '' ));
}
2008-10-05 19:07:36 +02:00
}
2008-11-09 17:33:09 +01:00
elseif ( call_user_func_array ( $cmd , array ( $path , $value )))
2008-10-05 19:07:36 +02:00
{
2008-11-09 17:33:09 +01:00
$msg .= lang ( 'Permissions of %1 changed.' , $path );
2008-11-12 18:04:38 +01:00
$content [ 'old' ][ $name ] = $content [ $name ];
2008-10-05 19:07:36 +02:00
}
else
{
2008-11-09 17:33:09 +01:00
$msg .= lang ( 'Failed to change permissions of %1!' , $path );
2008-10-05 19:07:36 +02:00
}
}
}
}
if ( $props )
{
2016-03-21 11:06:54 +01:00
if ( Vfs :: proppatch ( $path , $props ))
2008-10-05 19:07:36 +02:00
{
foreach ( $props as $prop )
{
2008-10-05 21:01:49 +02:00
$content [ 'old' ][ $prop [ 'name' ]] = $prop [ 'val' ];
2008-10-05 19:07:36 +02:00
}
$msg .= lang ( 'Properties saved.' );
}
else
{
$msg .= lang ( 'Saving properties failed!' );
2008-04-14 07:54:10 +02:00
}
}
}
elseif ( $content [ 'eacl' ] && $content [ 'is_owner' ])
{
if ( $content [ 'eacl' ][ 'delete' ])
{
list ( $ino_owner ) = each ( $content [ 'eacl' ][ 'delete' ]);
2014-11-18 13:55:32 +01:00
list (, $owner ) = explode ( '-' , $ino_owner , 2 ); // $owner is a group and starts with a minus!
2016-03-21 11:06:54 +01:00
$msg .= Vfs :: eacl ( $path , null , $owner ) ? lang ( 'ACL deleted.' ) : lang ( 'Error deleting the ACL entry!' );
2008-04-14 07:54:10 +02:00
}
elseif ( $button == 'eacl' )
{
2014-04-23 21:49:17 +02:00
if ( ! $content [ 'eacl_owner' ])
2008-04-14 07:54:10 +02:00
{
$msg .= lang ( 'You need to select an owner!' );
}
else
{
2016-03-21 11:06:54 +01:00
$msg .= Vfs :: eacl ( $path , $content [ 'eacl' ][ 'rights' ], $content [ 'eacl_owner' ]) ?
2008-04-14 07:54:10 +02:00
lang ( 'ACL added.' ) : lang ( 'Error adding the ACL!' );
2008-03-03 23:15:44 +01:00
}
}
}
2016-05-05 09:20:07 +02:00
Framework :: refresh_opener ( $msg , 'filemanager' , $refresh_path ? $refresh_path : $path , 'edit' , null , '&path=[^&]*' );
if ( $button == 'save' ) Framework :: window_close ();
2008-03-03 23:15:44 +01:00
}
2016-03-21 11:06:54 +01:00
if ( $content [ 'is_link' ] && ! Vfs :: stat ( $path ))
2009-03-19 21:12:35 +01:00
{
$msg .= ( $msg ? " \n " : '' ) . lang ( 'Link target %1 not found!' , $content [ 'symlink' ]);
}
2016-05-05 09:20:07 +02:00
$content [ 'link' ] = Egw :: link ( Vfs :: download_url ( $path ));
2016-03-21 11:06:54 +01:00
$content [ 'icon' ] = Vfs :: mime_icon ( $content [ 'mime' ]);
2008-04-14 07:54:10 +02:00
$content [ 'msg' ] = $msg ;
2016-03-21 11:06:54 +01:00
if (( $readonlys [ 'uid' ] = ! Vfs :: $is_root ) && ! $content [ 'uid' ]) $content [ 'ro_uid_root' ] = 'root' ;
2008-03-03 23:15:44 +01:00
// only owner can change group & perms
2008-04-14 07:54:10 +02:00
if (( $readonlys [ 'gid' ] = ! $content [ 'is_owner' ] ||
2016-03-21 11:06:54 +01:00
Vfs :: parse_url ( Vfs :: resolve_url ( $content [ 'path' ]), PHP_URL_SCHEME ) == 'oldvfs' )) // no uid, gid or perms in oldvfs
2008-03-03 23:15:44 +01:00
{
if ( ! $content [ 'gid' ]) $content [ 'ro_gid_root' ] = 'root' ;
foreach ( $content [ 'perms' ] as $name => $value )
{
$readonlys [ 'perms[' . $name . ']' ] = true ;
}
}
2016-07-02 12:39:28 +02:00
$readonlys [ 'name' ] = $path == '/' || ! ( $dir = Vfs :: dirname ( $path )) || ! Vfs :: is_writable ( $dir );
2016-03-21 11:06:54 +01:00
$readonlys [ 'comment' ] = ! Vfs :: is_writable ( $path );
2014-04-23 21:49:17 +02:00
$readonlys [ 'tabs' ][ 'filemanager.file.preview' ] = $readonlys [ 'tabs' ][ 'filemanager.file.perms' ] = $content [ 'is_link' ];
2008-04-16 09:07:31 +02:00
2008-11-09 17:33:09 +01:00
// if neither owner nor is writable --> disable save&apply
2016-03-21 11:06:54 +01:00
$readonlys [ 'button[save]' ] = $readonlys [ 'button[apply]' ] = ! $content [ 'is_owner' ] && ! Vfs :: is_writable ( $path );
2008-11-09 17:33:09 +01:00
2016-03-21 11:06:54 +01:00
if ( ! ( $cfs = Api\Storage\Customfields :: get ( 'filemanager' )))
2008-10-05 19:07:36 +02:00
{
2009-03-19 21:12:35 +01:00
$readonlys [ 'tabs' ][ 'custom' ] = true ;
2008-10-05 19:07:36 +02:00
}
2016-03-21 11:06:54 +01:00
elseif ( ! Vfs :: is_writable ( $path ))
2008-10-05 19:07:36 +02:00
{
foreach ( $cfs as $name => $data )
{
$readonlys [ '#' . $name ] = true ;
}
}
2014-04-23 21:49:17 +02:00
$readonlys [ 'tabs' ][ 'filemanager.file.eacl' ] = true ; // eacl off by default
2008-03-03 23:15:44 +01:00
if ( $content [ 'is_dir' ])
{
2014-04-23 21:49:17 +02:00
$readonlys [ 'tabs' ][ 'filemanager.file.preview' ] = true ; // no preview tab for dirs
2008-04-14 07:54:10 +02:00
$sel_options [ 'rights' ] = $sel_options [ 'owner' ] = $sel_options [ 'group' ] = $sel_options [ 'other' ] = array (
2008-03-03 23:15:44 +01:00
7 => lang ( 'Display and modification of content' ),
5 => lang ( 'Display of content' ),
0 => lang ( 'No access' ),
);
2016-03-21 11:06:54 +01:00
if (( $content [ 'eacl' ] = Vfs :: get_eacl ( $content [ 'path' ])) !== false ) // backend supports eacl
2008-04-14 07:54:10 +02:00
{
2014-04-23 21:49:17 +02:00
unset ( $readonlys [ 'tabs' ][ 'filemanager.file.eacl' ]); // --> switch the tab on again
2008-04-14 07:54:10 +02:00
foreach ( $content [ 'eacl' ] as & $eacl )
{
2016-03-21 11:06:54 +01:00
$eacl [ 'path' ] = rtrim ( Vfs :: parse_url ( $eacl [ 'path' ], PHP_URL_PATH ), '/' );
2008-04-16 09:07:31 +02:00
$readonlys [ 'delete[' . $eacl [ 'ino' ] . '-' . $eacl [ 'owner' ] . ']' ] = $eacl [ 'ino' ] != $content [ 'ino' ] ||
2008-04-14 07:54:10 +02:00
$eacl [ 'path' ] != $content [ 'path' ] || ! $content [ 'is_owner' ];
}
array_unshift ( $content [ 'eacl' ], false ); // make the keys start with 1, not 0
2009-08-26 12:04:21 +02:00
$content [ 'eacl' ][ 'owner' ] = 0 ;
$content [ 'eacl' ][ 'rights' ] = 5 ;
2008-04-14 07:54:10 +02:00
}
2008-03-03 23:15:44 +01:00
}
else
{
$sel_options [ 'owner' ] = $sel_options [ 'group' ] = $sel_options [ 'other' ] = array (
6 => lang ( 'Read & write access' ),
4 => lang ( 'Read access only' ),
0 => lang ( 'No access' ),
2008-04-14 07:54:10 +02:00
);
2008-03-03 23:15:44 +01:00
}
2013-04-09 18:20:06 +02:00
2012-10-27 13:38:47 +02:00
// mergeapp
2014-11-18 13:55:32 +01:00
$content [ 'mergeapp' ] = static :: get_mergeapp ( $path , 'self' );
$content [ 'mergeapp_parent' ] = static :: get_mergeapp ( $path , 'parents' );
2012-10-27 13:38:47 +02:00
if ( ! empty ( $content [ 'mergeapp' ]))
{
$content [ 'mergeapp_effective' ] = $content [ 'mergeapp' ];
}
elseif ( ! empty ( $content [ 'mergeapp_parent' ]))
{
$content [ 'mergeapp_effective' ] = $content [ 'mergeapp_parent' ];
}
else
{
$content [ 'mergeapp_effective' ] = null ;
}
// mergeapp select options
2016-05-05 09:20:07 +02:00
$mergeapp_list = Link :: app_list ( 'merge' );
2013-01-04 01:23:57 +01:00
unset ( $mergeapp_list [ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ]]); // exclude filemanager from list
2012-10-27 13:38:47 +02:00
$mergeapp_empty = ! empty ( $content [ 'mergeapp_parent' ])
? $mergeapp_list [ $content [ 'mergeapp_parent' ]] . ' (parent setting)' : '' ;
$sel_options [ 'mergeapp' ] = array ( '' => $mergeapp_empty );
$sel_options [ 'mergeapp' ] = $sel_options [ 'mergeapp' ] + $mergeapp_list ;
// mergeapp other gui options
$content [ 'mergeapp_itempicker_disabled' ] = $content [ 'is_dir' ] || empty ( $content [ 'mergeapp_effective' ]);
2013-04-09 18:20:06 +02:00
2008-03-03 23:15:44 +01:00
$preserve = $content ;
if ( ! isset ( $preserve [ 'old' ]))
{
$preserve [ 'old' ] = array (
'perms' => $content [ 'perms' ],
'name' => $content [ 'name' ],
'uid' => $content [ 'uid' ],
'gid' => $content [ 'gid' ],
2008-10-05 19:07:36 +02:00
'comment' => ( string ) $content [ 'comment' ],
2012-10-27 13:38:47 +02:00
'mergeapp' => $content [ 'mergeapp' ]
2008-03-03 23:15:44 +01:00
);
2008-10-05 19:07:36 +02:00
if ( $cfs ) foreach ( $cfs as $name => $data )
{
$preserve [ 'old' ][ '#' . $name ] = ( string ) $content [ '#' . $name ];
}
2008-03-03 23:15:44 +01:00
}
2016-03-21 11:06:54 +01:00
if ( Vfs :: $is_root )
2008-11-09 17:33:09 +01:00
{
2014-07-31 19:45:57 +02:00
$tpl -> setElementAttribute ( 'sudouser' , 'label' , 'Logout' );
$tpl -> setElementAttribute ( 'sudouser' , 'help' , 'Log out as superuser' );
2013-12-16 19:46:48 +01:00
// Need a more complex submit because button type is buttononly, which doesn't submit
2014-07-31 19:45:57 +02:00
$tpl -> setElementAttribute ( 'sudouser' , 'onclick' , 'app.filemanager.set_sudoButton(widget,"login")' );
2013-12-16 19:46:48 +01:00
2008-11-09 17:33:09 +01:00
}
2014-07-31 19:45:57 +02:00
elseif ( $button == 'sudo' )
{
$tpl -> setElementAttribute ( 'sudouser' , 'label' , 'Superuser' );
$tpl -> setElementAttribute ( 'sudouser' , 'help' , 'Enter setup user and password to get root rights' );
$tpl -> setElementAttribute ( 'sudouser' , 'onclick' , 'app.filemanager.set_sudoButton(widget,"logout")' );
}
2016-03-21 11:06:54 +01:00
if (( $extra_tabs = Vfs :: getExtraInfo ( $path , $content )))
2010-03-23 21:44:17 +01:00
{
2013-12-16 19:46:48 +01:00
// add to existing tabs in template
$tpl -> setElementAttribute ( 'tabs' , 'add_tabs' , true );
2013-08-20 18:41:31 +02:00
2013-12-16 19:46:48 +01:00
$tabs =& $tpl -> getElementAttribute ( 'tabs' , 'tabs' );
2014-11-18 13:55:32 +01:00
if ( true ) $tabs = array ();
2012-07-09 23:23:21 +02:00
2011-06-23 20:34:47 +02:00
foreach ( isset ( $extra_tabs [ 0 ]) ? $extra_tabs : array ( $extra_tabs ) as $extra_tab )
2010-03-23 21:44:17 +01:00
{
2013-12-16 19:46:48 +01:00
$tabs [] = array (
'label' => $extra_tab [ 'label' ],
'template' => $extra_tab [ 'name' ]
);
2011-06-23 20:34:47 +02:00
if ( $extra_tab [ 'data' ] && is_array ( $extra_tab [ 'data' ]))
{
$content = array_merge ( $content , $extra_tab [ 'data' ]);
}
if ( $extra_tab [ 'preserve' ] && is_array ( $extra_tab [ 'preserve' ]))
{
$preserve = array_merge ( $preserve , $extra_tab [ 'preserve' ]);
}
if ( $extra_tab [ 'readonlys' ] && is_array ( $extra_tab [ 'readonlys' ]))
{
2011-06-24 18:45:11 +02:00
$readonlys = array_merge ( $readonlys , $extra_tab [ 'readonlys' ]);
2011-06-23 20:34:47 +02:00
}
2010-05-13 13:59:16 +02:00
}
2010-03-23 21:44:17 +01:00
}
2016-05-05 09:20:07 +02:00
Framework :: window_focus ();
2016-03-21 11:06:54 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Preferences' ) . ' ' . Vfs :: decodePath ( $path );
2008-03-03 23:15:44 +01:00
$tpl -> exec ( 'filemanager.filemanager_ui.file' , $content , $sel_options , $readonlys , $preserve , 2 );
}
2008-04-16 09:07:31 +02:00
2010-12-28 04:12:57 +01:00
/**
* Run given action on given path ( es ) and return array / object with values for keys 'msg' , 'errs' , 'dirs' , 'files'
*
* @ param string $action eg . 'delete' , ...
2013-04-11 15:16:40 +02:00
* @ param array $selected selected path ( s )
* @ param string $dir = null current directory
2014-11-18 13:55:32 +01:00
* @ see static :: action ()
2010-12-28 04:12:57 +01:00
*/
2013-11-08 00:30:50 +01:00
public static function ajax_action ( $action , $selected , $dir = null , $props = null )
2010-12-28 04:12:57 +01:00
{
2014-10-13 19:23:33 +02:00
// do we have root rights, need to run here too, as method is static and therefore does NOT run __construct
2016-03-21 11:06:54 +01:00
if ( Api\Cache :: getSession ( 'filemanager' , 'is_root' ))
2014-10-13 19:23:33 +02:00
{
2016-03-21 11:06:54 +01:00
Vfs :: $is_root = true ;
2014-10-13 19:23:33 +02:00
}
2016-03-21 11:06:54 +01:00
$response = Api\Json\Response :: get ();
2011-03-21 17:14:43 +01:00
2010-12-28 04:12:57 +01:00
$arr = array (
'msg' => '' ,
2013-11-14 22:38:45 +01:00
'action' => $action ,
2010-12-28 04:12:57 +01:00
'errs' => 0 ,
'dirs' => 0 ,
'files' => 0 ,
);
2011-03-21 17:14:43 +01:00
2013-04-11 15:16:40 +02:00
if ( ! isset ( $dir )) $dir = array_pop ( $selected );
2011-03-21 17:14:43 +01:00
2013-04-20 21:23:36 +02:00
switch ( $action )
{
case 'upload' :
$script_error = 0 ;
foreach ( $selected as $tmp_name => & $data )
{
2016-03-21 11:06:54 +01:00
$path = Vfs :: concat ( $dir , Vfs :: encodePathComponent ( $data [ 'name' ]));
2011-03-21 17:14:43 +01:00
2016-03-21 11:06:54 +01:00
if ( Vfs :: deny_script ( $path ))
2013-04-20 21:23:36 +02:00
{
if ( ! isset ( $script_error ))
{
$arr [ 'msg' ] .= ( $arr [ 'msg' ] ? " \n " : '' ) . lang ( 'You are NOT allowed to upload a script!' );
}
++ $script_error ;
++ $arr [ 'errs' ];
unset ( $selected [ $tmp_name ]);
}
2016-03-21 11:06:54 +01:00
elseif ( Vfs :: is_dir ( $path ))
2013-04-23 18:52:39 +02:00
{
$data [ 'confirm' ] = 'is_dir' ;
}
2016-03-21 11:06:54 +01:00
elseif ( ! $data [ 'confirmed' ] && Vfs :: stat ( $path ))
2013-04-20 21:23:36 +02:00
{
$data [ 'confirm' ] = true ;
}
else
{
if ( is_dir ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ]) && is_writable ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ]))
{
$tmp_path = $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ] . '/' . basename ( $tmp_name );
}
else
{
$tmp_path = ini_get ( 'upload_tmp_dir' ) . '/' . basename ( $tmp_name );
}
2016-03-21 11:06:54 +01:00
if ( Vfs :: copy_uploaded ( $tmp_path , $path , $props , false ))
2013-04-20 21:23:36 +02:00
{
++ $arr [ 'files' ];
$uploaded [] = $data [ 'name' ];
}
else
{
++ $arr [ 'errs' ];
}
}
}
if ( $arr [ 'errs' ] > $script_error )
{
$arr [ 'msg' ] .= ( $arr [ 'msg' ] ? " \n " : '' ) . lang ( 'Error uploading file!' );
}
if ( $arr [ 'files' ])
{
$arr [ 'msg' ] .= ( $arr [ 'msg' ] ? " \n " : '' ) . lang ( '%1 successful uploaded.' , implode ( ', ' , $uploaded ));
}
$arr [ 'uploaded' ] = $selected ;
$arr [ 'path' ] = $dir ;
2013-11-08 00:30:50 +01:00
$arr [ 'props' ] = $props ;
2013-04-20 21:23:36 +02:00
break ;
2013-11-14 22:38:45 +01:00
// Upload, then link
case 'link' :
// First upload
2014-11-18 13:55:32 +01:00
$arr = static :: ajax_action ( 'upload' , $selected , $dir , $props );
2016-05-05 09:20:07 +02:00
$app_dir = Link :: vfs_path ( $props [ 'entry' ][ 'app' ], $props [ 'entry' ][ 'id' ], '' , true );
2013-11-14 22:38:45 +01:00
foreach ( $arr [ 'uploaded' ] as $file )
{
2016-03-21 11:06:54 +01:00
$target = Vfs :: concat ( $dir , Vfs :: encodePathComponent ( $file [ 'name' ]));
if ( Vfs :: file_exists ( $target ) && $app_dir )
2013-11-14 22:38:45 +01:00
{
2016-03-21 11:06:54 +01:00
if ( ! Vfs :: file_exists ( $app_dir )) Vfs :: mkdir ( $app_dir );
2013-11-14 22:38:45 +01:00
error_log ( " Symlinking $target to $app_dir " );
2016-03-21 11:06:54 +01:00
Vfs :: symlink ( $target , Vfs :: concat ( $app_dir , Vfs :: encodePathComponent ( $file [ 'name' ])));
2013-11-14 22:38:45 +01:00
}
}
// Must return to avoid adding to $response again
return ;
2013-04-20 21:23:36 +02:00
default :
2014-11-18 13:55:32 +01:00
$arr [ 'msg' ] = static :: action ( $action , $selected , $dir , $arr [ 'errs' ], $arr [ 'dirs' ], $arr [ 'files' ]);
2013-04-20 21:23:36 +02:00
}
2010-12-28 04:12:57 +01:00
$response -> data ( $arr );
2011-06-30 15:07:55 +02:00
//error_log(__METHOD__."('$action',".array2string($selected).') returning '.array2string($arr));
2013-11-14 22:38:45 +01:00
return $arr ;
2010-12-28 04:12:57 +01:00
}
2008-03-03 23:15:44 +01:00
/**
* Convert perms array back to integer mode
*
* @ param array $perms with keys owner , group , other , executable , sticky
* @ return int
*/
private function perms2mode ( array $perms )
{
2008-11-09 17:33:09 +01:00
$mode = $perms [ 'owner' ] << 6 | $perms [ 'group' ] << 3 | $perms [ 'other' ];
2008-03-03 23:15:44 +01:00
if ( $mode [ 'executable' ])
{
$mode |= 0111 ;
}
if ( $mode [ 'sticky' ])
{
$mode |= 0x201 ;
}
return $mode ;
}
2016-07-19 18:20:08 +02:00
/**
* Editor for odf files
*
* @ param array $content
*/
2016-08-19 17:59:44 +02:00
function editor ( $content = null )
2016-07-19 18:20:08 +02:00
{
$tmpl = new Etemplate ( 'filemanager.editor' );
$file_path = $_GET [ 'path' ];
2016-08-17 17:23:22 +02:00
$paths = explode ( '/webdav.php' , $file_path );
2016-08-03 18:15:09 +02:00
// Include css files used by wodocollabeditor
Api\Framework :: includeCSS ( '/api/js/webodf/collab/app/resources/app.css' );
Api\Framework :: includeCSS ( '/api/js/webodf/collab/wodocollabpane.css' );
Api\Framework :: includeCSS ( '/api/js/webodf/collab/wodotexteditor.css' );
2016-08-16 12:47:00 +02:00
Api\Framework :: includeJS ( '/filemanager/js/collab.js' , null , 'filemanager' );
2016-07-19 18:20:08 +02:00
2016-08-19 16:38:44 +02:00
if ( ! $content )
{
if ( $file_path )
{
$content [ 'es_id' ] = md5 ( $file_path );
2016-08-23 15:26:59 +02:00
$content [ 'file_path' ] = $paths [ 1 ];
2016-08-19 16:38:44 +02:00
}
2016-08-23 17:57:03 +02:00
else
{
$content = array ();
}
2016-08-19 16:38:44 +02:00
}
2016-08-19 17:59:44 +02:00
2016-08-17 17:23:22 +02:00
$actions = self :: getActions_edit ();
if ( ! Api\Vfs :: check_access ( $paths [ 1 ], Api\Vfs :: WRITABLE ))
{
unset ( $actions [ 'save' ]);
2016-08-22 17:46:48 +02:00
unset ( $actions [ 'discard' ]);
2016-08-17 17:23:22 +02:00
unset ( $actions [ 'delete' ]);
}
$tmpl -> setElementAttribute ( 'tools' , 'actions' , $actions );
2016-08-19 16:38:44 +02:00
$preserve = $content ;
2016-07-19 18:20:08 +02:00
$tmpl -> exec ( 'filemanager.filemanager_ui.editor' , $content , array (), array (), $preserve , 2 );
}
/**
* Editor dialog ' s toolbar actions
*
* @ return array return array of actions
*/
static function getActions_edit () {
$actions = array (
'save' => array (
'caption' => 'Save' ,
2016-07-20 15:55:47 +02:00
'icon' => 'apply' ,
2016-07-19 18:20:08 +02:00
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_save' ,
'allowOnMultiple' => false ,
'toolbarDefault' => true
),
'new' => array (
'caption' => 'New' ,
'icon' => 'add' ,
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_new' ,
'allowOnMultiple' => false ,
'toolbarDefault' => true
),
'close' => array (
'caption' => 'Close' ,
'icon' => 'close' ,
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_close' ,
'allowOnMultiple' => false ,
'toolbarDefault' => true
),
2016-07-20 15:55:47 +02:00
'saveas' => array (
'caption' => 'Save As' ,
'icon' => 'save_all' ,
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_save' ,
'allowOnMultiple' => false ,
'toolbarDefault' => true
),
2016-07-19 18:20:08 +02:00
'delete' => array (
'caption' => 'Delete' ,
'icon' => 'delete' ,
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_delete' ,
'allowOnMultiple' => false ,
'toolbarDefault' => false
2016-08-22 17:46:48 +02:00
),
'discard' => array (
'caption' => 'Discard' ,
'icon' => 'delete' ,
'group' => ++ $group ,
'onExecute' => 'javaScript:app.filemanager.editor_discard' ,
'allowOnMultiple' => false ,
'toolbarDefault' => false
2016-07-19 18:20:08 +02:00
)
);
return $actions ;
}
2008-08-27 13:17:00 +02:00
}