Nothing we can do about IE 6, but this should reduce the bandwidth need significantly.

git-svn-id: file:///svn/phpbb/trunk@8238 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Henry Sudhof 2007-11-16 14:21:05 +00:00
parent bec8f7b22c
commit 053730e477
2 changed files with 27 additions and 9 deletions

View file

@ -101,6 +101,8 @@
<li>[Fix] Use correct RFC 2822 date format in emails (Bug #15042)</li> <li>[Fix] Use correct RFC 2822 date format in emails (Bug #15042)</li>
<li>[Fix] Require founder status for some actions on founder-only groups (Bug #15119)</li> <li>[Fix] Require founder status for some actions on founder-only groups (Bug #15119)</li>
<li>[Fix] Allow changing the "now" option of date CPFs (Bug #15111)</li> <li>[Fix] Allow changing the "now" option of date CPFs (Bug #15111)</li>
<li>[Change] Some improvements to the caching of avatars</li>
</ul> </ul>
<a name="v30rc6"></a><h3>1.ii. Changes since 3.0.RC6</h3> <a name="v30rc6"></a><h3>1.ii. Changes since 3.0.RC6</h3>

View file

@ -32,6 +32,9 @@ if (isset($_GET['avatar']))
exit; exit;
} }
unset($dbpasswd); unset($dbpasswd);
// worst-case default
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
$config = $cache->obtain_config(); $config = $cache->obtain_config();
$filename = $_GET['avatar']; $filename = $_GET['avatar'];
@ -53,9 +56,25 @@ if (isset($_GET['avatar']))
$db->sql_close(); $db->sql_close();
exit; exit;
} }
$ext = substr(strrchr($filename, '.'), 1); $ext = substr(strrchr($filename, '.'), 1);
$filename = intval($filename); $stamp = (int) substr(stristr($filename, '_'), 1);
$filename = (int) $filename;
// let's see if we have to send the file at all
$last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false;
if (strpos(strtolower($browser), 'msie 6.0') === false)
{
if ($last_load !== false && $last_load <= $stamp)
{
header('Not Modified', true, 304);
exit();
}
else
{
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $stamp) . ' GMT');
}
}
if (!in_array($ext, array('png', 'gif', 'jpg', 'jpeg'))) if (!in_array($ext, array('png', 'gif', 'jpg', 'jpeg')))
{ {
@ -68,7 +87,7 @@ if (isset($_GET['avatar']))
$db->sql_close(); $db->sql_close();
exit; exit;
} }
if (!$filename) if (!$filename)
{ {
// no way such an avatar could exist. They are not following the rules, stop the show. // no way such an avatar could exist. They are not following the rules, stop the show.
@ -81,7 +100,7 @@ if (isset($_GET['avatar']))
exit; exit;
} }
send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext); send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext, $browser);
if (!empty($cache)) if (!empty($cache))
{ {
@ -267,16 +286,13 @@ else
* A simplified function to deliver avatars * A simplified function to deliver avatars
* The argument needs to be checked before calling this function. * The argument needs to be checked before calling this function.
*/ */
function send_avatar_to_browser($file) function send_avatar_to_browser($file, $browser)
{ {
global $config, $phpbb_root_path; global $config, $phpbb_root_path;
$prefix = $config['avatar_salt'] . '_'; $prefix = $config['avatar_salt'] . '_';
$image_dir = $config['avatar_path']; $image_dir = $config['avatar_path'];
// worst-case default
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
// Adjust image_dir path (no trailing slash) // Adjust image_dir path (no trailing slash)
if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\') if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\')
{ {
@ -290,7 +306,7 @@ function send_avatar_to_browser($file)
} }
$file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file; $file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file;
if ((@file_exists($file_path) && @is_readable($file_path)) || headers_sent()) if ((@file_exists($file_path) && @is_readable($file_path)) && !headers_sent())
{ {
header('Pragma: public'); header('Pragma: public');