mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 18:26:32 +02:00
Merge pull request #4894 from rubencm/ticket/15276
[ticket/15276] Use storage in avatars * github.com:phpbb/phpbb: (34 commits) [ticket/15276] Changed annotation [ticket/15276] Remove unused code [ticket/15276] Revert some changes [ticket/15276] Use IniGetWrapper [ticket/15276] Add missing dependency [ticket/15276] Remove unused dependency [ticket/15276] Add missing properties [ticket/15276] Use InitGetWrapper [ticket/15276] Fix comments [ticket/15276] Fix code and add phpdoc [ticket/15276] Use stream_copy_to_stream [ticket/15276] Fix typo [ticket/15276] Use mimetype guesser [ticket/15276] Update file_info to get size of images [ticket/15276] Update [ticket/15276] Remove avatar_path [ticket/15276] Remove avatar_path from acp [ticket/15276] Use finfo to get mimetype [ticket/15276] Update file_info [ticket/15276] Fix code style ...
This commit is contained in:
@@ -502,26 +502,8 @@ class acp_main
|
||||
|
||||
$upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
|
||||
|
||||
$avatar_dir_size = 0;
|
||||
|
||||
if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
|
||||
{
|
||||
while (($file = readdir($avatar_dir)) !== false)
|
||||
{
|
||||
if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
|
||||
{
|
||||
$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
|
||||
}
|
||||
}
|
||||
closedir($avatar_dir);
|
||||
|
||||
$avatar_dir_size = get_formatted_filesize($avatar_dir_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Couldn't open Avatar dir.
|
||||
$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
|
||||
}
|
||||
// Couldn't open Avatar dir.
|
||||
$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
|
||||
|
||||
if ($posts_per_day > $total_posts)
|
||||
{
|
||||
|
@@ -4434,7 +4434,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
'T_SUPER_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/template',
|
||||
'T_IMAGES_PATH' => "{$web_path}images/",
|
||||
'T_SMILIES_PATH' => "{$web_path}{$config['smilies_path']}/",
|
||||
'T_AVATAR_PATH' => "{$web_path}{$config['avatar_path']}/",
|
||||
'T_AVATAR_GALLERY_PATH' => "{$web_path}{$config['avatar_gallery_path']}/",
|
||||
'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/",
|
||||
'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/",
|
||||
@@ -4452,7 +4451,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
'T_SUPER_TEMPLATE_NAME' => rawurlencode((isset($user->style['style_parent_tree']) && $user->style['style_parent_tree']) ? $user->style['style_parent_tree'] : $user->style['style_path']),
|
||||
'T_IMAGES' => 'images',
|
||||
'T_SMILIES' => $config['smilies_path'],
|
||||
'T_AVATAR' => $config['avatar_path'],
|
||||
'T_AVATAR_GALLERY' => $config['avatar_gallery_path'],
|
||||
'T_ICONS' => $config['icons_path'],
|
||||
'T_RANKS' => $config['ranks_path'],
|
||||
|
@@ -88,7 +88,6 @@ function adm_page_header($page_title)
|
||||
|
||||
'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
|
||||
'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",
|
||||
'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/",
|
||||
'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
|
||||
'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
|
||||
'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
|
||||
|
@@ -25,30 +25,27 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
function send_avatar_to_browser($file, $browser)
|
||||
{
|
||||
global $config, $phpbb_root_path;
|
||||
global $config, $phpbb_container;
|
||||
|
||||
$storage = $phpbb_container->get('storage.avatar');
|
||||
|
||||
$prefix = $config['avatar_salt'] . '_';
|
||||
$image_dir = $config['avatar_path'];
|
||||
$file_path = $prefix . $file;
|
||||
|
||||
// Adjust image_dir path (no trailing slash)
|
||||
if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\')
|
||||
if ($storage->exists($file_path) && !headers_sent())
|
||||
{
|
||||
$image_dir = substr($image_dir, 0, -1) . '/';
|
||||
}
|
||||
$image_dir = str_replace(array('../', '..\\', './', '.\\'), '', $image_dir);
|
||||
$file_info = $storage->file_info($file_path);
|
||||
|
||||
if ($image_dir && ($image_dir[0] == '/' || $image_dir[0] == '\\'))
|
||||
{
|
||||
$image_dir = '';
|
||||
}
|
||||
$file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file;
|
||||
|
||||
if ((@file_exists($file_path) && @is_readable($file_path)) && !headers_sent())
|
||||
{
|
||||
header('Cache-Control: public');
|
||||
|
||||
$image_data = @getimagesize($file_path);
|
||||
header('Content-Type: ' . image_type_to_mime_type($image_data[2]));
|
||||
try
|
||||
{
|
||||
header('Content-Type: ' . $file_info->mimetype);
|
||||
}
|
||||
catch (\phpbb\storage\exception\exception $e)
|
||||
{
|
||||
// Just don't send this header
|
||||
}
|
||||
|
||||
if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7))
|
||||
{
|
||||
@@ -69,24 +66,26 @@ function send_avatar_to_browser($file, $browser)
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
|
||||
}
|
||||
|
||||
$size = @filesize($file_path);
|
||||
if ($size)
|
||||
try
|
||||
{
|
||||
header("Content-Length: $size");
|
||||
header('Content-Length: ' . $file_info->size);
|
||||
}
|
||||
catch (\phpbb\storage\exception\exception $e)
|
||||
{
|
||||
// Just don't send this header
|
||||
}
|
||||
|
||||
if (@readfile($file_path) == false)
|
||||
try
|
||||
{
|
||||
$fp = @fopen($file_path, 'rb');
|
||||
|
||||
if ($fp !== false)
|
||||
{
|
||||
while (!feof($fp))
|
||||
{
|
||||
echo fread($fp, 8192);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
$fp = $storage->read_stream($file_path);
|
||||
$output = fopen('php://output', 'w+b');
|
||||
stream_copy_to_stream($fp, $output);
|
||||
fclose($fp);
|
||||
fclose($output);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Send nothing
|
||||
}
|
||||
|
||||
flush();
|
||||
|
@@ -2166,7 +2166,9 @@ function phpbb_style_is_active($style_id)
|
||||
*/
|
||||
function avatar_delete($mode, $row, $clean_db = false)
|
||||
{
|
||||
global $phpbb_root_path, $config;
|
||||
global $config, $phpbb_container;
|
||||
|
||||
$storage = $phpbb_container->get('storage.avatar');
|
||||
|
||||
// Check if the users avatar is actually *not* a group avatar
|
||||
if ($mode == 'user')
|
||||
@@ -2183,11 +2185,16 @@ function avatar_delete($mode, $row, $clean_db = false)
|
||||
}
|
||||
$filename = get_avatar_filename($row[$mode . '_avatar']);
|
||||
|
||||
if (file_exists($phpbb_root_path . $config['avatar_path'] . '/' . $filename))
|
||||
try
|
||||
{
|
||||
@unlink($phpbb_root_path . $config['avatar_path'] . '/' . $filename);
|
||||
$storage->delete($filename);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (\phpbb\storage\exception\exception $e)
|
||||
{
|
||||
// Fail is covered by return statement below
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -2507,7 +2514,9 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
|
||||
*/
|
||||
function group_correct_avatar($group_id, $old_entry)
|
||||
{
|
||||
global $config, $db, $phpbb_root_path;
|
||||
global $config, $db, $phpbb_container;
|
||||
|
||||
$storage = $phpbb_container->get('storage.avatar');
|
||||
|
||||
$group_id = (int) $group_id;
|
||||
$ext = substr(strrchr($old_entry, '.'), 1);
|
||||
@@ -2515,14 +2524,19 @@ function group_correct_avatar($group_id, $old_entry)
|
||||
$new_filename = $config['avatar_salt'] . "_g$group_id.$ext";
|
||||
$new_entry = 'g' . $group_id . '_' . substr(time(), -5) . ".$ext";
|
||||
|
||||
$avatar_path = $phpbb_root_path . $config['avatar_path'];
|
||||
if (@rename($avatar_path . '/'. $old_filename, $avatar_path . '/' . $new_filename))
|
||||
try
|
||||
{
|
||||
$this->storage->rename($old_filename, $new_filename);
|
||||
|
||||
$sql = 'UPDATE ' . GROUPS_TABLE . '
|
||||
SET group_avatar = \'' . $db->sql_escape($new_entry) . "'
|
||||
WHERE group_id = $group_id";
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
catch (\phpbb\storage\exception\exception $e)
|
||||
{
|
||||
// If rename fail, dont execute the query
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user