[feature/avatars] Implement avatar uploads for ucp

As above, implement avatar uploads from local and remote sources in
the UCP.

PHPBB3-10018
This commit is contained in:
Cullen Walsh 2011-04-19 11:19:47 -07:00 committed by Cullen Walsh
parent f02f621686
commit 019b9bc073
3 changed files with 82 additions and 41 deletions

View file

@ -58,11 +58,8 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
$dh = @opendir($path); $dh = @opendir($path);
if (!$dh) if ($dh)
{ {
return $avatar_list;
}
while (($cat = readdir($dh)) !== false) { while (($cat = readdir($dh)) !== false) {
if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
{ {
@ -95,6 +92,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
} }
} }
@closedir($dh); @closedir($dh);
}
@ksort($avatar_list); @ksort($avatar_list);

View file

@ -49,15 +49,64 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
*/ */
public function handle_form($template, $user_row, &$error, $submitted = false) public function handle_form($template, $user_row, &$error, $submitted = false)
{ {
if ($submitted) { $can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
$error[] = 'TODO';
return ''; if ($can_upload == false)
{
return false;
}
if ($submitted)
{
include_once($this->phpbb_root_path . 'includes/functions_upload.' . $this->phpEx);
$upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));
$url = request_var('av_upload_url', '');
if (!empty($_FILES['av_upload_file']['name']))
{
$file = $upload->form_upload('av_upload_file');
} }
else else
{ {
$can_upload = (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; $file = $upload->remote_upload($url);
if ($can_upload) }
$prefix = $this->config['avatar_salt'] . '_';
$file->clean_filename('avatar', $prefix, $user_row['user_id']);
$destination = $this->config['avatar_path'];
// Adjust destination path (no trailing slash)
if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
{ {
$destination = substr($destination, 0, -1);
}
$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
{
$destination = '';
}
// Move file and overwrite any existing image
$file->move_file($destination, true);
if (sizeof($file->error))
{
$file->remove();
$error = array_merge($error, $file->error);
return false;
}
return array(
'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'),
'user_avatar_width' => $file->get('width'),
'user_avatar_height' => $file->get('height'),
);
}
$template->assign_vars(array( $template->assign_vars(array(
'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'],
@ -65,10 +114,4 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
return true; return true;
} }
else
{
return false;
}
}
}
} }

View file

@ -570,7 +570,7 @@ class ucp_profile
{ {
$result = $avatar->handle_form($template, $user->data, $error, true); $result = $avatar->handle_form($template, $user->data, $error, true);
if (empty($error)) if ($result && empty($error))
{ {
// Success! Lets save the result in the database // Success! Lets save the result in the database
$result['user_avatar_type'] = $driver; $result['user_avatar_type'] = $driver;