diff --git a/phpgwapi/inc/class.groupdav_principals.inc.php b/phpgwapi/inc/class.groupdav_principals.inc.php index 4f9c334e1c..a28fde9f1b 100644 --- a/phpgwapi/inc/class.groupdav_principals.inc.php +++ b/phpgwapi/inc/class.groupdav_principals.inc.php @@ -1161,30 +1161,9 @@ class groupdav_principals extends groupdav_handler $displayname = translation::convert($resource['name'], translation::charset(), 'utf-8'); return ($is_location ? 'locations/' : 'resources/').$resource['res_id'].'-'. - preg_replace('/[^a-z0-9]+/i','-', self::to_ascii($resource['name'])); + preg_replace('/[^a-z0-9]+/i','-', translation::to_ascii($resource['name'])); } - /** - * Transliterate utf-8 filename to ascii, eg. 'Äpfel' --> 'Aepfel' - * - * @param string $str - * @return string - */ - protected static function to_ascii($str) - { - static $extra = array( - 'ß' => 'ss', - ); - $str = htmlentities($str,ENT_QUOTES,translation::charset()); - $str = str_replace(array_keys($extra),array_values($extra),$str); - $str = preg_replace('/&([aAuUoO])uml;/','\\1e',$str); // replace german umlauts with the letter plus one 'e' - $str = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1',$str); // remove all types of accents - $str = preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','',$str); // remove all other entities - - return $str; - } - - /** * Check if resource is a location * diff --git a/phpgwapi/inc/class.html.inc.php b/phpgwapi/inc/class.html.inc.php index 507eff95a6..33eb4d3918 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -1055,7 +1055,7 @@ class html { if (!is_array($options)) $options = explode(',',$options); if (!is_array($names)) $names = explode(',',$names); - + //if (empty($options)) return "";//this should not be needed foreach($options as $n => $val) { if ($val != '' && $names[$n] != '') @@ -1368,8 +1368,9 @@ class html * @param string $mime='' mimetype or '' (default) to detect it from filename, using mime_magic::filename2mime() * @param int $length=0 content length, default 0 = skip that header * @param boolean $nocache=true send headers to disallow browser/proxies to cache the download + * @param boolean $forceDownload=true send headers to handle as attachment/download */ - public static function content_header($fn,$mime='',$length=0,$nocache=True) + public static function content_header($fn,$mime='',$length=0,$nocache=True,$forceDownload=true) { // if no mime-type is given or it's the default binary-type, guess it from the extension if(empty($mime) || $mime == 'application/octet-stream') @@ -1378,18 +1379,22 @@ class html } if($fn) { + if ($forceDownload===true) + { + $attachment = ' attachment;'; + } + else + { + $attachment = ' inline;'; + } // limit IE hack (no attachment in Content-disposition header) to IE < 9 if(self::$user_agent == 'msie' && self::$ua_version < 9) { $attachment = ''; } - else - { - $attachment = ' attachment;'; - } // Show this for all - header('Content-disposition:'.$attachment.' filename="'.$fn.'"'); + self::content_disposition_header($fn,$forceDownload); header('Content-type: '.$mime); if($length) @@ -1407,6 +1412,31 @@ class html } } + /** + * Output content-disposition header for file downloads + * + * @param string $fn filename + * @param boolean $forceDownload=true send headers to handle as attachment/download + */ + public static function content_disposition_header($fn,$forceDownload=true) + { + if ($forceDownload===true) + { + $attachment = ' attachment;'; + } + else + { + $attachment = ' inline;'; + } + // limit IE hack (no attachment in Content-disposition header) to IE < 9 + if(self::$user_agent == 'msie' && self::$ua_version < 9) + { + $attachment = ''; + } + + header('Content-disposition:'.$attachment.' filename="'.translation::to_ascii($fn).'"; filename*=utf-8\'\''.rawurlencode($fn)); + } + /** * split html by PRE tag, return array with all content pre-sections isolated in array elements * @author Leithoff, Klaus diff --git a/phpgwapi/inc/class.translation.inc.php b/phpgwapi/inc/class.translation.inc.php index 3f43fcc1f7..a834e08fae 100644 --- a/phpgwapi/inc/class.translation.inc.php +++ b/phpgwapi/inc/class.translation.inc.php @@ -624,6 +624,26 @@ class translation return $charsets; } + /** + * Transliterate utf-8 filename to ascii, eg. 'Äpfel' --> 'Aepfel' + * + * @param string $str + * @return string + */ + static function to_ascii($str) + { + static $extra = array( + 'ß' => 'ss', + ); + $str = htmlentities($str,ENT_QUOTES,self::charset()); + $str = str_replace(array_keys($extra),array_values($extra),$str); + $str = preg_replace('/&([aAuUoO])uml;/','\\1e',$str); // replace german umlauts with the letter plus one 'e' + $str = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1',$str); // remove all types of accents + $str = preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','',$str); // remove all other entities + + return $str; + } + /** * converts a string $data from charset $from to charset $to * diff --git a/phpgwapi/inc/class.vfs_webdav_server.inc.php b/phpgwapi/inc/class.vfs_webdav_server.inc.php index db8bf5d925..307cdfd376 100644 --- a/phpgwapi/inc/class.vfs_webdav_server.inc.php +++ b/phpgwapi/inc/class.vfs_webdav_server.inc.php @@ -692,7 +692,7 @@ class vfs_webdav_server extends HTTP_WebDAV_Server_Filesystem } if ($this->force_download) { - header('Content-disposition: attachment; filename="'.egw_vfs::basename($options['path']).'"'); + html::content_disposition_header(egw_vfs::basename($options['path']),true); } } return $ok; @@ -923,4 +923,4 @@ class vfs_webdav_server extends HTTP_WebDAV_Server_Filesystem } return parent::PUT($options); } -} \ No newline at end of file +}