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 eeeb49c26f..37114f9b9c 100644 --- a/phpgwapi/inc/class.html.inc.php +++ b/phpgwapi/inc/class.html.inc.php @@ -1494,8 +1494,9 @@ egw_LAB.wait(function() { * @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') @@ -1504,18 +1505,8 @@ egw_LAB.wait(function() { } if($fn) { - // 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) @@ -1533,6 +1524,31 @@ egw_LAB.wait(function() { } } + /** + * 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 110aeca682..0d9339fa7f 100644 --- a/phpgwapi/inc/class.translation.inc.php +++ b/phpgwapi/inc/class.translation.inc.php @@ -688,6 +688,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 * @@ -1068,13 +1088,13 @@ class translation { if ($addbracesforendtag === true ) { - $_body = preg_replace('~<'.$tag.'[^>]*?>(.*)~simU','',$_body); + $_body = preg_replace('~<'.$tag.'[^>]*?>(.*?)~simU','',$_body); // remove left over tags, unfinished ones, and so on $_body = preg_replace('~<'.$tag.'[^>]*?>~si','',$_body); } if ($addbracesforendtag === false ) { - $_body = preg_replace('~<'.$tag.'[^>]*?>(.*)'.$endtag.'~simU','',$_body); + $_body = preg_replace('~<'.$tag.'[^>]*?>(.*?)'.$endtag.'~simU','',$_body); // remove left over tags, unfinished ones, and so on $_body = preg_replace('~<'.$tag.'[^>]*?>~si','',$_body); $_body = preg_replace('~'.$endtag.'~','',$_body); @@ -1227,7 +1247,7 @@ class translation self::replaceEmailAdresses($_html); //convert hrefs to description -> URL //$_html = preg_replace('~]+href=\"([^"]+)\"[^>]*>(.*)~si','[$2 -> $1]',$_html); - $_html = preg_replace_callback('~]+href=\"([^"]+)\"[^>]*>(.*)~si','self::transform_url2text',$_html); + $_html = preg_replace_callback('~]+href=\"([^"]+)\"[^>]*>(.*?)~si','self::transform_url2text',$_html); // reducing double \r\n to single ones, dont mess with pre sections if ($stripcrl === true && $isHTML) 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 +}