* Filemanager: "Save as" option for files to force download and not open in browser

This commit is contained in:
Ralf Becker 2011-08-29 08:40:22 +00:00
parent ae5cde8259
commit 4a1f4fff8c
3 changed files with 66 additions and 5 deletions

View File

@ -109,12 +109,20 @@ class filemanager_ui
$actions = array(
'open' => array(
'caption' => lang('Open'),
'icon' => 'filemanager/folder',
'icon' => '',
'group' => $group=1,
'allowOnMultiple' => false,
'onExecute' => 'javaScript:nm_activate_link',
'default' => true
),
'saveas' => array(
'caption' => lang('Save as'),
'group' => $group,
'allowOnMultiple' => false,
'icon' => 'filesave',
'onExecute' => 'javaScript:force_download',
'disableClass' => 'isDir',
),
'edit' => array(
'caption' => lang('Edit settings'),
'group' => $group,
@ -482,6 +490,13 @@ function do_clipboard(_action, _elems)
}
xajax_doXMLHTTP("filemanager_ui::ajax_clipboard", _action.id, ids);
}
function force_download(_action, _senders)
{
var a_href = $j(_senders[0].iface.getDOMNode()).find("a:first").attr("href");
window.location = a_href+"?download";
}
</script>'."\n";
$tpl->exec('filemanager.filemanager_ui.index',$content,$sel_options,$readonlys,array('nm' => $content['nm']));
}
@ -822,8 +837,6 @@ function do_clipboard(_action, _elems)
),true) as $path => $row)
{
//echo $path; _debug_array($row);
$rows[++$n] = $row;
$path2n[$path] = $n;
$dir = dirname($path);
if (!isset($dir_is_writable[$dir]))
@ -835,11 +848,18 @@ function do_clipboard(_action, _elems)
{
$readonlys["delete[$path_quoted]"] = true; // no rights to delete the file
}
if (egw_vfs::is_dir($path) || !egw_vfs::is_readable($path) ||
if (egw_vfs::is_dir($path))
{
$readonlys["mail[$path_quoted]"] = true;
$row['class'] = 'isDir';
}
elseif (!egw_vfs::is_readable($path) ||
!$GLOBALS['egw_info']['user']['apps']['felamimail'])
{
$readonlys["mail[$path_quoted]"] = true;
}
$rows[++$n] = $row;
$path2n[$path] = $n;
}
// query comments and cf's for the displayed rows
$cols_to_show = explode(',',$GLOBALS['egw_info']['user']['preferences']['filemanager']['nextmatch-filemanager.index.rows']);

View File

@ -1272,7 +1272,7 @@ class egw_vfs extends vfs_stream_wrapper
}
// we do NOT need to encode % itself, as our path are already url encoded, with the exception of ' ' and '+'
// we urlencode double quotes '"', as that fixes many problems in html markup
return '/webdav.php'.strtr($path,array('+' => '%2B',' ' => '%20','"' => '%22'));
return '/webdav.php'.strtr($path,array('+' => '%2B',' ' => '%20','"' => '%22')).($force_download ? '?download' : '');
}
/**

View File

@ -522,4 +522,45 @@ class vfs_webdav_server extends HTTP_WebDAV_Server_Filesystem
parent::GetDir($fspath, $options);
}
private $force_download = false;
/**
* Constructor
*
* Reimplement to add a Content-Disposition header, if ?download is appended to the REQUEST_URI
*/
function __construct()
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' && ($this->force_download = substr($_SERVER['REQUEST_URI'],-9) == '?download'))
{
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],0,-9);
}
parent::HTTP_WebDAV_Server();
}
/**
* GET method handler
*
* Reimplement to add a Content-Disposition header, if ?download is appended to the REQUEST_URI
*
* @param array parameter passing array
* @return bool true on success
*/
function GET(&$options)
{
if (($ok = parent::GET($options)) && $this->force_download)
{
if(html::$user_agent == 'msie') // && self::$ua_version == '5.5')
{
$attachment = '';
}
else
{
$attachment = ' attachment;';
}
header('Content-disposition:'.$attachment.' filename="'.egw_vfs::basename($options['path']).'"');
}
return $ok;
}
}