From 4a1f4fff8cc96e2fa0dbcf852d8efbcb6d9823b1 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 29 Aug 2011 08:40:22 +0000 Subject: [PATCH] * Filemanager: "Save as" option for files to force download and not open in browser --- filemanager/inc/class.filemanager_ui.inc.php | 28 +++++++++++-- phpgwapi/inc/class.egw_vfs.inc.php | 2 +- phpgwapi/inc/class.vfs_webdav_server.inc.php | 41 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index badc8946d7..96ef1b252b 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -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"; +} '."\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']); diff --git a/phpgwapi/inc/class.egw_vfs.inc.php b/phpgwapi/inc/class.egw_vfs.inc.php index 2992c433b1..d6db71b8b8 100644 --- a/phpgwapi/inc/class.egw_vfs.inc.php +++ b/phpgwapi/inc/class.egw_vfs.inc.php @@ -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' : ''); } /** diff --git a/phpgwapi/inc/class.vfs_webdav_server.inc.php b/phpgwapi/inc/class.vfs_webdav_server.inc.php index 0a2db2e5ff..4a2b7a7384 100644 --- a/phpgwapi/inc/class.vfs_webdav_server.inc.php +++ b/phpgwapi/inc/class.vfs_webdav_server.inc.php @@ -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; + } } \ No newline at end of file