mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 19:42:15 +09:00
Move RFC5987 encoding function to UA class
This commit is contained in:
parent
8fe8c9203e
commit
c3fe8d265b
2 changed files with 63 additions and 19 deletions
|
|
@ -270,4 +270,65 @@ class UA
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method encodes a UTF-8 filename for downloading in the current visitor's browser.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $ua (optional)
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function encodeFilenameForDownload($filename, $ua = null)
|
||||||
|
{
|
||||||
|
// Get the User-Agent header if the caller did not specify $ua.
|
||||||
|
$ua = $ua ?: (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null);
|
||||||
|
|
||||||
|
// Get the browser name and version.
|
||||||
|
$browser = self::getBrowserInfo($ua);
|
||||||
|
|
||||||
|
// Find the best format that this browser supports.
|
||||||
|
if ($browser->browser === 'Chrome' && $browser->version >= 11)
|
||||||
|
{
|
||||||
|
$output_format = 'rfc5987';
|
||||||
|
}
|
||||||
|
elseif ($browser->browser === 'Firefox' && $browser->version >= 6)
|
||||||
|
{
|
||||||
|
$output_format = 'rfc5987';
|
||||||
|
}
|
||||||
|
elseif ($browser->browser === 'Safari' && $browser->version >= 6)
|
||||||
|
{
|
||||||
|
$output_format = 'rfc5987';
|
||||||
|
}
|
||||||
|
elseif ($browser->browser === 'IE' && $browser->version >= 10)
|
||||||
|
{
|
||||||
|
$output_format = 'rfc5987';
|
||||||
|
}
|
||||||
|
elseif ($browser->browser === 'IE')
|
||||||
|
{
|
||||||
|
$output_format = 'old_ie';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$output_format = 'raw';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean the filename.
|
||||||
|
$filename = Filters\FilenameFilter::clean($filename);
|
||||||
|
|
||||||
|
// Apply the format and return.
|
||||||
|
switch ($output_format)
|
||||||
|
{
|
||||||
|
case 'raw':
|
||||||
|
return 'filename="' . $filename . '"';
|
||||||
|
|
||||||
|
case 'rfc5987':
|
||||||
|
$filename = rawurlencode($filename);
|
||||||
|
return "filename*=UTF-8''" . $filename . '; filename="' . $filename . '"';
|
||||||
|
|
||||||
|
case 'old_ie':
|
||||||
|
default:
|
||||||
|
$filename = rawurlencode($filename);
|
||||||
|
return 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -342,25 +342,8 @@ class fileController extends file
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filename encoding for browsers that support RFC 5987
|
// Encode the filename.
|
||||||
if(preg_match('#(?:Chrome|Edge)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 11)
|
$filename_param = Rhymix\Framework\UA::encodeFilenameForDownload($filename);
|
||||||
{
|
|
||||||
$filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"';
|
|
||||||
}
|
|
||||||
elseif(preg_match('#(?:Firefox|Safari|Trident)/(\d+)\.#', $_SERVER['HTTP_USER_AGENT'], $matches) && $matches[1] >= 6)
|
|
||||||
{
|
|
||||||
$filename_param = "filename*=UTF-8''" . rawurlencode($filename) . '; filename="' . rawurlencode($filename) . '"';
|
|
||||||
}
|
|
||||||
// Filename encoding for browsers that do not support RFC 5987
|
|
||||||
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
|
|
||||||
{
|
|
||||||
$filename = rawurlencode($filename);
|
|
||||||
$filename_param = 'filename="' . preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1) . '"';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$filename_param = 'filename="' . $filename . '"';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close context to prevent blocking the session
|
// Close context to prevent blocking the session
|
||||||
Context::close();
|
Context::close();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue