diff options
author | Marc Alexander <admin@m-a-styles.de> | 2012-11-12 14:57:28 +0100 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2012-11-12 14:57:28 +0100 |
commit | 2265811cd16f6473807f647cba4693c5366324c6 (patch) | |
tree | ff27efb016da2f8adff55e2d343c1163d26219d8 /phpBB/includes/ucp/ucp_profile.php | |
parent | 5a5e507a14084b08e41c4d2f86f2fb6700e68eb5 (diff) | |
parent | 0e2a30a27b92a851221be489370217b9c7bf8e07 (diff) | |
download | forums-2265811cd16f6473807f647cba4693c5366324c6.tar forums-2265811cd16f6473807f647cba4693c5366324c6.tar.gz forums-2265811cd16f6473807f647cba4693c5366324c6.tar.bz2 forums-2265811cd16f6473807f647cba4693c5366324c6.tar.xz forums-2265811cd16f6473807f647cba4693c5366324c6.zip |
Merge branch 'feature/avatars' of https://github.com/igorw/phpbb3 into feature/avatars
Conflicts:
phpBB/adm/style/acp_groups.html
phpBB/adm/style/acp_users_avatar.html
phpBB/includes/acp/acp_groups.php
phpBB/includes/acp/acp_users.php
phpBB/includes/functions_display.php
phpBB/install/database_update.php
phpBB/install/schemas/mssql_schema.sql
phpBB/styles/prosilver/template/ucp_avatar_options.html
Diffstat (limited to 'phpBB/includes/ucp/ucp_profile.php')
-rw-r--r-- | phpBB/includes/ucp/ucp_profile.php | 166 |
1 files changed, 115 insertions, 51 deletions
diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 89bf20a30f..4b0e59b9e8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -28,8 +28,9 @@ class ucp_profile function main($id, $mode) { - global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; + global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; global $request; + global $phpbb_avatar_manager; $user->add_lang('posting'); @@ -544,79 +545,142 @@ class ucp_profile break; case 'avatar': + include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + add_form_key('ucp_avatar'); - $display_gallery = request_var('display_gallery', '0'); - $avatar_select = basename(request_var('avatar_select', '')); - $category = basename(request_var('category', '')); + $avatars_enabled = false; - $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; + if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) + { + $avatar_drivers = $phpbb_avatar_manager->get_valid_drivers(); + sort($avatar_drivers); - add_form_key('ucp_avatar'); + // This is normalised data, without the user_ prefix + $avatar_data = phpbb_avatar_manager::clean_row($user->data); - if ($submit) - { - if (check_form_key('ucp_avatar')) + if ($submit) { - if (avatar_process_user($error, false, $can_upload)) + if (check_form_key('ucp_avatar')) { - meta_refresh(3, $this->u_action); - $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); - trigger_error($message); + $driver = request_var('avatar_driver', ''); + if (in_array($driver, $avatar_drivers) && $config["allow_avatar_$driver"]) + { + $avatar = $phpbb_avatar_manager->get_driver($driver); + $result = $avatar->process_form($template, $avatar_data, $error); + + if ($result && empty($error)) + { + // Success! Lets save the result in the database + $result = array( + 'user_avatar_type' => $driver, + 'user_avatar' => $result['avatar'], + 'user_avatar_width' => $result['avatar_width'], + 'user_avatar_height' => $result['avatar_height'], + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); + trigger_error($message); + } + } + else + { + // They are removing their avatar or are trying to play games with us + if ($avatar = $phpbb_avatar_manager->get_driver($user->data['user_avatar_type'])) + { + $avatar->delete($avatar_data); + } + + $result = array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => 0, + 'user_avatar_height' => 0, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_id = ' . $user->data['user_id']; + + $db->sql_query($sql); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); + trigger_error($message); + } + } + else + { + $error[] = 'FORM_INVALID'; } } - else + + $focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']); + + foreach ($avatar_drivers as $driver) { - $error[] = 'FORM_INVALID'; + $avatar = $phpbb_avatar_manager->get_driver($driver); + + if ($avatar->is_enabled()) + { + $avatars_enabled = true; + $template->set_filenames(array( + 'avatar' => $avatar->get_template_name(), + )); + + if ($avatar->prepare_form($template, $avatar_data, $error)) + { + $driver_u = strtoupper($driver); + + $template->assign_block_vars('avatar_drivers', array( + 'L_TITLE' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_TITLE'), // @TODO add lang values + 'L_EXPLAIN' => $user->lang('AVATAR_DRIVER_' . $driver_u . '_EXPLAIN'), + + 'DRIVER' => $driver, + 'SELECTED' => ($driver == $focused_driver), + 'OUTPUT' => $template->assign_display('avatar'), + )); + } + } } - // Replace "error" strings with their real, localised form - $error = array_map(array($user, 'lang'), $error); } - if (!$config['allow_avatar'] && $user->data['user_avatar_type']) - { - $error[] = $user->lang['AVATAR_NOT_ALLOWED']; - } - else if ((($user->data['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) || - (($user->data['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) || - (($user->data['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local'])) + // Replace "error" strings with their real, localised form + $err = $error; + $error = array(); + foreach ($err as $e) { - $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED']; + if (is_array($e)) + { + $key = array_shift($e); + $error[] = vsprintf($user->lang($key), $e); + } + else + { + $error[] = $user->lang((string) $e); + } } + + $avatar = get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', - 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true), - 'AVATAR_SIZE' => $config['avatar_filesize'], - - 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=avatar&display_gallery=1'), + 'AVATAR' => $avatar, - 'S_FORM_ENCTYPE' => ($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) ? ' enctype="multipart/form-data"' : '', + 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), + + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), )); - if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) - { - avatar_gallery($category, $avatar_select, 4); - } - else if ($config['allow_avatar']) - { - $avatars_enabled = (($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload'])) || ($auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']))) ? true : false; - - $template->assign_vars(array( - 'AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']), - 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']), - - 'S_AVATARS_ENABLED' => $avatars_enabled, - 'S_UPLOAD_AVATAR_FILE' => ($can_upload && $config['allow_avatar_upload']) ? true : false, - 'S_UPLOAD_AVATAR_URL' => ($can_upload && $config['allow_avatar_remote_upload']) ? true : false, - 'S_LINK_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) ? true : false, - 'S_DISPLAY_GALLERY' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false) - ); - } - break; case 'autologin_keys': |