mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-04 17:18:52 +00:00
[feature/avatars] UCP Avatar Interface
This stubs out the avatar form fields and how form processing will occur. Form processing is not yet implemented, but shouldn't be too hard. After this I will refactor/duplicate some of the logic for the ACP. PHPBB3-10018
This commit is contained in:
parent
24379f1297
commit
7abded081d
11 changed files with 265 additions and 94 deletions
|
@ -86,4 +86,12 @@ abstract class phpbb_avatar_driver
|
|||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function handle_form($template, &$error = array(), $submitted = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,4 +47,77 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function handle_form($template, &$error = array(), $submitted = false)
|
||||
{
|
||||
if ($submitted) {
|
||||
$error[] = 'TODO';
|
||||
return '';
|
||||
}
|
||||
|
||||
$avatar_list = array();
|
||||
$path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
|
||||
|
||||
$dh = @opendir($path);
|
||||
|
||||
if (!$dh)
|
||||
{
|
||||
return $avatar_list;
|
||||
}
|
||||
|
||||
while (($cat = readdir($dh)) !== false) {
|
||||
if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
|
||||
{
|
||||
if ($ch = @opendir("$path/$cat"))
|
||||
{
|
||||
while (($image = readdir($ch)) !== false)
|
||||
{
|
||||
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image))
|
||||
{
|
||||
$avatar_list[$cat][] = array(
|
||||
'file' => rawurlencode($cat) . '/' . rawurlencode($image),
|
||||
'filename' => rawurlencode($image),
|
||||
'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
|
||||
);
|
||||
}
|
||||
}
|
||||
@closedir($ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@closedir($dh);
|
||||
|
||||
@ksort($avatar_list);
|
||||
|
||||
$category = request_var('av_local_cat', '');
|
||||
$categories = array_keys($avatar_list);
|
||||
|
||||
foreach ($categories as $cat)
|
||||
{
|
||||
if (!empty($avatar_list[$cat]))
|
||||
{
|
||||
$template->assign_block_vars('av_local_cats', array(
|
||||
'NAME' => $cat,
|
||||
'SELECTED' => ($cat == $category),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($avatar_list[$category]))
|
||||
{
|
||||
foreach ($avatar_list[$category] as $img => $data)
|
||||
{
|
||||
$template->assign_block_vars('av_local_imgs', array(
|
||||
'AVATAR_IMAGE' => $path . '/' . $data['file'],
|
||||
'AVATAR_NAME' => $data['name'],
|
||||
'AVATAR_FILE' => $data['filename'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,4 +47,19 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function handle_form($template, &$error = array(), $submitted = false)
|
||||
{
|
||||
if ($submitted) {
|
||||
$error[] = 'TODO';
|
||||
return '';
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,4 +47,31 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function handle_form($template, &$error = array(), $submitted = false)
|
||||
{
|
||||
if ($submitted) {
|
||||
$error[] = 'TODO';
|
||||
return '';
|
||||
}
|
||||
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;
|
||||
if ($can_upload)
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ class phpbb_avatar_manager
|
|||
private $cache;
|
||||
private static $valid_drivers = false;
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_config $config, phpbb_cache_driver_interface $cache = null)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
|
@ -34,6 +37,9 @@ class phpbb_avatar_manager
|
|||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function get_singleton($avatar_type)
|
||||
{
|
||||
if (self::$valid_drivers === false)
|
||||
|
@ -57,6 +63,9 @@ class phpbb_avatar_manager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
private function load_valid_drivers()
|
||||
{
|
||||
require_once($this->phpbb_root_path . 'includes/avatar/driver.' . $this->php_ext);
|
||||
|
@ -88,4 +97,16 @@ class phpbb_avatar_manager
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function get_valid_drivers() {
|
||||
if (self::$valid_drivers === false)
|
||||
{
|
||||
$this->load_valid_drivers();
|
||||
}
|
||||
|
||||
return array_keys(self::$valid_drivers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ 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;
|
||||
|
||||
$user->add_lang('posting');
|
||||
|
@ -544,23 +544,50 @@ class ucp_profile
|
|||
break;
|
||||
|
||||
case 'avatar':
|
||||
|
||||
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
|
||||
|
||||
$display_gallery = request_var('display_gallery', '0');
|
||||
$avatar_select = basename(request_var('avatar_select', ''));
|
||||
$category = basename(request_var('category', ''));
|
||||
|
||||
$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;
|
||||
|
||||
add_form_key('ucp_avatar');
|
||||
|
||||
if ($submit)
|
||||
$avatars_enabled = false;
|
||||
|
||||
if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar'))
|
||||
{
|
||||
$avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $cache->getDriver());
|
||||
$avatar_drivers = $avatar_manager->get_valid_drivers();
|
||||
sort($avatar_drivers);
|
||||
|
||||
foreach ($avatar_drivers as $driver) {
|
||||
if ($config["allow_avatar_$driver"]) {
|
||||
$avatars_enabled = true;
|
||||
$template->set_filenames(array(
|
||||
'avatar' => "ucp_avatar_options_$driver.html",
|
||||
));
|
||||
|
||||
$avatar = $avatar_manager->get_singleton($driver);
|
||||
if (isset($_POST["submit_av_$driver"]))
|
||||
{
|
||||
if (check_form_key('ucp_avatar'))
|
||||
{
|
||||
if (avatar_process_user($error, false, $can_upload))
|
||||
$result = $avatar->handle_form($template, $error, true);
|
||||
|
||||
if (empty($error))
|
||||
{
|
||||
// Success! Lets save the result in the database
|
||||
$sql_ary = array(
|
||||
'user_avatar_type' => $driver,
|
||||
'user_avatar' => (string) $result,
|
||||
);
|
||||
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
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);
|
||||
|
@ -570,29 +597,36 @@ class ucp_profile
|
|||
{
|
||||
$error[] = 'FORM_INVALID';
|
||||
}
|
||||
// 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'];
|
||||
if ($avatar->handle_form($template, $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,
|
||||
'OUTPUT' => $template->assign_display('avatar'),
|
||||
));
|
||||
}
|
||||
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']))
|
||||
{
|
||||
$error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replace "error" strings with their real, localised form
|
||||
$error = array_map(array($user, 'lang'), $error);
|
||||
|
||||
$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', true),
|
||||
'AVATAR' => $avatar,
|
||||
'AVATAR_SIZE' => $config['avatar_filesize'],
|
||||
|
||||
'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=profile&mode=avatar&display_gallery=1'),
|
||||
|
||||
'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(),
|
||||
));
|
||||
|
@ -603,16 +637,11 @@ class ucp_profile
|
|||
}
|
||||
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']),
|
||||
'AVATAR_WIDTH' => request_var('width', empty($avatar) ? 0 : $user->data['user_avatar_width']),
|
||||
'AVATAR_HEIGHT' => request_var('height', empty($avatar) ? 0 : $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)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,28 +10,9 @@
|
|||
<dl>
|
||||
<dt><label>{L_CURRENT_IMAGE}:</label><br /><span>{L_AVATAR_EXPLAIN}</span></dt>
|
||||
<dd><!-- IF AVATAR -->{AVATAR}<!-- ELSE --><img src="{T_THEME_PATH}/images/no_avatar.gif" alt="" /><!-- ENDIF --></dd>
|
||||
<dd><label for="delete"><input type="checkbox" name="delete" id="delete" /> {L_DELETE_AVATAR}</label></dd>
|
||||
</dl>
|
||||
|
||||
<!-- IF S_UPLOAD_AVATAR_FILE -->
|
||||
<dl>
|
||||
<dt><label for="uploadfile">{L_UPLOAD_AVATAR_FILE}:</label></dt>
|
||||
<dd><input type="hidden" name="MAX_FILE_SIZE" value="{AVATAR_SIZE}" /><input type="file" name="uploadfile" id="uploadfile" class="inputbox autowidth" /></dd>
|
||||
</dl>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF S_UPLOAD_AVATAR_URL -->
|
||||
<dl>
|
||||
<dt><label for="uploadurl">{L_UPLOAD_AVATAR_URL}:</label><br /><span>{L_UPLOAD_AVATAR_URL_EXPLAIN}</span></dt>
|
||||
<dd><input type="text" name="uploadurl" id="uploadurl" value="{AVATAR_URL}" class="inputbox" /></dd>
|
||||
</dl>
|
||||
<!-- ENDIF -->
|
||||
|
||||
<!-- IF S_LINK_AVATAR -->
|
||||
<dl>
|
||||
<dt><label for="remotelink">{L_LINK_REMOTE_AVATAR}:</label><br /><span>{L_LINK_REMOTE_AVATAR_EXPLAIN}</span></dt>
|
||||
<dd><input type="text" name="remotelink" id="remotelink" value="{AVATAR_REMOTE}" class="inputbox" /></dd>
|
||||
<!-- IF AVATAR && S_AVATARS_ENABLED --><dd><input type="submit" name="submit" id="delete" value="{LA_DELETE_AVATAR}" /></dd><!-- ENDIF -->
|
||||
</dl>
|
||||
<!-- IF S_AVATARS_ENABLED -->
|
||||
<dl>
|
||||
<dt><label for="width">{L_LINK_REMOTE_SIZE}:</label><br /><span>{L_LINK_REMOTE_SIZE_EXPLAIN}</span></dt>
|
||||
<dd>
|
||||
|
@ -42,29 +23,23 @@
|
|||
<!-- ENDIF -->
|
||||
</fieldset>
|
||||
|
||||
<!-- IF S_IN_AVATAR_GALLERY -->
|
||||
<span class="corners-bottom"><span></span></span></div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="inner"><span class="corners-top"><span></span></span>
|
||||
|
||||
<h3>{L_AVATAR_GALLERY}</h3>
|
||||
<!-- BEGIN avatar_drivers -->
|
||||
<h3>{avatar_drivers.L_TITLE}</h3>
|
||||
<p>{avatar_drivers.L_EXPLAIN}</p>
|
||||
|
||||
<fieldset>
|
||||
<label for="category">{L_AVATAR_CATEGORY}: <select name="category" id="category">{S_CAT_OPTIONS}</select></label>
|
||||
<input type="submit" value="{L_GO}" name="display_gallery" class="button2" />
|
||||
<input type="submit" name="cancel" value="{L_CANCEL}" class="button2" />
|
||||
{avatar_drivers.OUTPUT}
|
||||
</fieldset>
|
||||
<fieldset class="submit-buttons">
|
||||
<input type="reset" value="{L_RESET}" name="reset" class="button2" />
|
||||
<input type="submit" name="submit_av_{avatar_drivers.DRIVER}" value="{L_SUBMIT}" class="button1" />
|
||||
</fieldset>
|
||||
<!-- END avatar_drivers -->
|
||||
|
||||
<div id="gallery">
|
||||
<!-- BEGIN avatar_row --><!-- BEGIN avatar_column -->
|
||||
<label for="av-{avatar_row.S_ROW_COUNT}-{avatar_row.avatar_column.S_ROW_COUNT}"><img src="{avatar_row.avatar_column.AVATAR_IMAGE}" alt="" /><br />
|
||||
<input type="radio" name="avatar_select" id="av-{avatar_row.S_ROW_COUNT}-{avatar_row.avatar_column.S_ROW_COUNT}" value="{avatar_row.avatar_column.AVATAR_FILE}" /></label>
|
||||
<!-- END avatar_column --><!-- END avatar_row -->
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<!-- IF S_LINK_AVATAR -->
|
||||
<!-- ENDIF -->
|
||||
</fieldset>
|
||||
|
||||
<span class="corners-bottom"><span></span></span></div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<label for="category">{L_AVATAR_CATEGORY}: <select name="av_local_cat" id="category">
|
||||
<option value="">{L_NO_AVATAR_CATEGORY}</option>
|
||||
<!-- BEGIN av_local_cats -->
|
||||
<option value="{av_local_cats.NAME}"<!-- IF av_local_cats.SELECTED --> selected="selected"<!-- ENDIF -->>{av_local_cats.NAME}</option>
|
||||
<!-- END av_local_cats -->
|
||||
</select></label>
|
||||
<input type="submit" value="{L_GO}" name="av_local_go" class="button2" />
|
||||
|
||||
<div id="gallery">
|
||||
<!-- BEGIN av_local_imgs -->
|
||||
<label for="av-{av_local_imgs.S_ROW_COUNT}"><img src="{av_local_imgs.AVATAR_IMAGE}" alt="" /><br />
|
||||
<input type="radio" name="avatar_select" id="av-{av_local_imgs.S_ROW_COUNT}" value="{av_local_imgs.AVATAR_FILE}" /></label>
|
||||
<!-- END av_local_imgs -->
|
||||
</div>
|
|
@ -0,0 +1,4 @@
|
|||
<dl>
|
||||
<dt><label for="remotelink">{L_LINK_REMOTE_AVATAR}:</label><br /><span>{L_LINK_REMOTE_AVATAR_EXPLAIN}</span></dt>
|
||||
<dd><input type="text" name="remotelink" id="remotelink" value="" class="inputbox" /></dd>
|
||||
</dl>
|
|
@ -0,0 +1,11 @@
|
|||
<dl>
|
||||
<dt><label for="uploadfile">{L_UPLOAD_AVATAR_FILE}:</label></dt>
|
||||
<dd><input type="hidden" name="MAX_FILE_SIZE" value="{AVATAR_SIZE}" /><input type="file" name="uploadfile" id="uploadfile" class="inputbox autowidth" /></dd>
|
||||
</dl>
|
||||
|
||||
<!-- IF S_UPLOAD_AVATAR_URL -->
|
||||
<dl>
|
||||
<dt><label for="uploadurl">{L_UPLOAD_AVATAR_URL}:</label><br /><span>{L_UPLOAD_AVATAR_URL_EXPLAIN}</span></dt>
|
||||
<dd><input type="text" name="uploadurl" id="uploadurl" value="{AVATAR_URL}" class="inputbox" /></dd>
|
||||
</dl>
|
||||
<!-- ENDIF -->
|
|
@ -6,14 +6,8 @@
|
|||
|
||||
<!-- INCLUDE ucp_avatar_options.html -->
|
||||
|
||||
<fieldset class="submit-buttons">
|
||||
{S_HIDDEN_FIELDS}
|
||||
<!-- IF S_DISPLAY_GALLERY --><input type="submit" name="display_gallery" value="{L_DISPLAY_GALLERY}" class="button2" /> <!-- ENDIF -->
|
||||
<!-- IF S_IN_AVATAR_GALLERY --><input type="submit" name="cancel" value="{L_CANCEL}" class="button2" /> <!-- ELSE -->
|
||||
<input type="reset" value="{L_RESET}" name="reset" class="button2" /> <!-- ENDIF -->
|
||||
<input type="submit" name="submit" value="{L_SUBMIT}" class="button1" />
|
||||
{S_FORM_TOKEN}
|
||||
</fieldset>
|
||||
{S_HIDDEN_FIELDS}
|
||||
{S_FORM_TOKEN}
|
||||
</form>
|
||||
|
||||
<!-- INCLUDE ucp_footer.html -->
|
||||
|
|
Loading…
Add table
Reference in a new issue