mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:15 +01:00
move groupdav to_ascii to translation class; unify content_header and content_disposition_header to be used by all downloads; adapt vfs_webdav_server thereof; try to improve replaceTagsCompletley
This commit is contained in:
parent
384f1b4d45
commit
a46398da52
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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.'[^>]*?>(.*)</'.$endtag.'[\s]*>~simU','',$_body);
|
||||
$_body = preg_replace('~<'.$tag.'[^>]*?>(.*?)</'.$endtag.'[\s]*>~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('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*)</a>~si','[$2 -> $1]',$_html);
|
||||
$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*)</a>~si','self::transform_url2text',$_html);
|
||||
$_html = preg_replace_callback('~<a[^>]+href=\"([^"]+)\"[^>]*>(.*?)</a>~si','self::transform_url2text',$_html);
|
||||
|
||||
// reducing double \r\n to single ones, dont mess with pre sections
|
||||
if ($stripcrl === true && $isHTML)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user