Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gravatar #8

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion phpBB/includes/acp/acp_board.php
Expand Up @@ -119,12 +119,22 @@ function main($id, $mode)
'allow_avatar_local' => array('lang' => 'ALLOW_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'allow_avatar_remote' => array('lang' => 'ALLOW_REMOTE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'allow_avatar_upload' => array('lang' => 'ALLOW_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'allow_avatar_gravatar' => array('lang' => 'ALLOW_GRAVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'text:4:10', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
'avatar_min' => array('lang' => 'MIN_AVATAR_SIZE', 'validate' => 'int:0', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
'avatar_max' => array('lang' => 'MAX_AVATAR_SIZE', 'validate' => 'int:0', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rwpath', 'type' => 'text:20:255', 'explain' => true),
'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true)
'avatar_gallery_path' => array('lang' => 'AVATAR_GALLERY_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true),

'legend2' => 'GRAVATAR_SETTINGS',

'gravatar_force_all' => array('lang' => 'GRAVATAR_FORCE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'gravatar_default' => array('lang' => 'GRAVATAR_DEFAULT', 'validate' => 'string', 'type' => 'text::255', 'explain' => true),
'gravatar_rating' => array('lang' => 'GRAVATAR_RATING', 'validate' => 'string', 'type' => 'select', 'method' => 'select_gravatar_rating', 'explain' => true),
'gravatar_default_size' => array('lang' => 'GRAVATAR_DEFAULT_SIZE', 'validate' => 'int::512', 'type' => 'text:4:3', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),

'legend3' => 'ACP_SUBMIT_CHANGES',
)
);
break;
Expand Down Expand Up @@ -984,6 +994,19 @@ function store_feed_forums($option, $key)
$cache->destroy('sql', FORUMS_TABLE);
}

function select_gravatar_rating($selected, $key)
{
// http://en.gravatar.com/site/implement/images/#rating
$gravatar_ratings = array('g', 'pg', 'r', 'x');

$options = '';
foreach($gravatar_ratings as $value)
{
$options .= '<option value="' . $value . '"' . (($value == $selected) ? ' selected="selected"' : '') . '>' . strtoupper($value) . '</option>';
}

return $options;
}
}

?>
5 changes: 5 additions & 0 deletions phpBB/includes/acp/acp_users.php
Expand Up @@ -884,6 +884,11 @@ function main($id, $mode)
'user_email_hash' => phpbb_email_hash($update_email),
);

if ($user_row['user_avatar_type'] == AVATAR_GRAVATAR)
{
$sql_ary['user_avatar'] = md5($update_email);
}

add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
}

Expand Down
1 change: 1 addition & 0 deletions phpBB/includes/constants.php
Expand Up @@ -41,6 +41,7 @@
define('AVATAR_UPLOAD', 1);
define('AVATAR_REMOTE', 2);
define('AVATAR_GALLERY', 3);
define('AVATAR_GRAVATAR', 4);

define('USER_NORMAL', 0);
define('USER_INACTIVE', 1);
Expand Down
54 changes: 54 additions & 0 deletions phpBB/includes/functions_display.php
Expand Up @@ -1245,6 +1245,16 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
{
global $user, $config, $phpbb_root_path, $phpEx;

// if gravatar_force_all is on, we _ignore_ everything about avatars and
// simply set their gravatar as the avatar.
if ($config['gravatar_force_all'])
{
$size = ($user->data['user_avatar_width']) ? $user->data['user_avatar_width'] : $config['gravatar_default_size'];
$avatar_img = get_gravatar(md5($user->data['user_email']), $size);

return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $config['gravatar_default_size'] . '" height="' . $config['gravatar_default_size'] . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}

if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
{
return '';
Expand Down Expand Up @@ -1276,10 +1286,54 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
return '';
}
break;

case AVATAR_GRAVATAR:
if (!$config['allow_avatar_gravatar'] && !$ignore_config)
{
return '';
}

// We are going to clear out $avatar because get_gravatar returns
// the full URI directly
$avatar_img = get_gravatar($avatar, $avatar_width);
$avatar = '';
break;
}

$avatar_img .= $avatar;
return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}

/**
* Get Gravatar
*
* @param string $hash User's gravatar hash (md5 of email)
* @param int $size Size in px of one side of the gravatar (they are square)
*
* @return string Gravatar url
*/
function get_gravatar($hash, $size = 80)
{
global $config;

// Get the ssl or not figured out first
$url = ($_SERVER['HTTPS'] === 'on') ? 'https://secure' : 'http://www';
$url .= '.gravatar.com/avatar/';

// here comes the $hash and $size portion
$url .= $hash . '?s=' . $size;

if ($config['gravatar_rating'])
{
$url .= '&r=' . urlencode(strtolower($config['gravatar_rating']));
}

if ($config['gravatar_default'])
{
$url .= '&d=' . urlencode($config['gravatar_default']);
}

return $url;
}

?>
51 changes: 51 additions & 0 deletions phpBB/includes/functions_user.php
Expand Up @@ -2071,6 +2071,44 @@ function avatar_remote($data, &$error)
return array(AVATAR_REMOTE, $data['remotelink'], $width, $height);
}

/**
* Gravatar avatar linking
*/
function avatar_gravatar($data, &$error)
{
global $user, $config;

// Hieght and width, Gravatars are /always/ square, and we are using 80 is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hieght -> Height

you also might not want to capitalise it

// the Gravatar default.
$size = ($data['width'] > 0) ? $data['width'] : 80;

if ($config['avatar_max_width'] || $config['avatar_max_height'])
{
if ($size > $config['avatar_max_width'] || $size > $config['avatar_max_height'])
{
$error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $size, $size);
return false;
}
}

if ($config['avatar_min_width'] || $config['avatar_min_height'])
{
if ($size < $config['avatar_min_width'] || $size < $config['avatar_min_height'])
{
$error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $size, $size);
return false;
}
}

/*
* According to the specifications at http://gravatar.com/site/implement/url,
* md5() of an strtolower()'d and trim()'d email address. This allows the
* storage only the 'slug' portion, the URL portion is applied when displaying
* the gravatar.
*/
return array(AVATAR_GRAVATAR, md5($user->data['user_email']), $size, $size);
}

/**
* Avatar upload using the upload class
*/
Expand Down Expand Up @@ -2259,6 +2297,13 @@ function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $
case AVATAR_REMOTE :
break;

case AVATAR_GRAVATAR :
// Note: we actually return in this case. We accecpt whatever
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accecpt -> accept

// current_x is and fall back on 80 (Gravatar standard default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of hard to understand.

maybe: "use current_x if the size has been set and fall back on 80 (Gravatar default) if not

$size = ($current_x > 0 && $current_y > 0) ? $current_x : 80;
return array($size, $size);
break;

case AVATAR_UPLOAD :
$avatar = $phpbb_root_path . $config['avatar_path'] . '/' . get_avatar_filename($avatar);
break;
Expand Down Expand Up @@ -2312,13 +2357,15 @@ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = nu
'remotelink' => request_var('remotelink', ''),
'width' => request_var('width', 0),
'height' => request_var('height', 0),
'use_gravatar' => request_var('gravatar', 0),
);

$error = validate_data($data, array(
'uploadurl' => array('string', true, 5, 255),
'remotelink' => array('string', true, 5, 255),
'width' => array('string', true, 1, 3),
'height' => array('string', true, 1, 3),
'use_gravatar' => array('num', true, 0, 1),
));

if (sizeof($error))
Expand Down Expand Up @@ -2355,6 +2402,10 @@ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = nu
{
list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_remote($data, $error);
}
else if ($data['use_gravatar'] && $change_avatar && $config['allow_avatar_gravatar'])
{
list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_gravatar($data, $error);
}
else if ($avatar_select && $change_avatar && $config['allow_avatar_local'])
{
$category = basename(request_var('category', ''));
Expand Down
11 changes: 9 additions & 2 deletions phpBB/includes/ucp/ucp_profile.php
Expand Up @@ -116,6 +116,12 @@ function main($id, $mode)
'user_passchg' => ($auth->acl_get('u_chgpasswd') && $data['new_password']) ? time() : 0,
);

// update gravatar if necessary
if($user->data['user_avatar_type'] == AVATAR_GRAVATAR)
{
$sql_ary['user_avatar'] = md5($sql_ary['user_email']);
}

if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username'])
{
add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $data['username']);
Expand Down Expand Up @@ -614,7 +620,7 @@ function main($id, $mode)
}
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;
$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'] || $config['allow_avatar_gravatar']))) ? true : false;

$template->assign_vars(array(
'AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']),
Expand All @@ -624,7 +630,8 @@ function main($id, $mode)
'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)
'S_DISPLAY_GALLERY' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false,
'S_GRAVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_gravatar']) ? true : false)
);
}

Expand Down
5 changes: 5 additions & 0 deletions phpBB/install/schemas/schema_data.sql
Expand Up @@ -12,6 +12,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar', '0'
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_local', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_remote', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_upload', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_gravatar', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_remote_upload', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_bbcode', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_birthdays', '1');
Expand Down Expand Up @@ -123,6 +124,10 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_native_co
INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_native_load_upd', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_native_max_chars', '14');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_native_min_chars', '3');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('gravatar_force_all', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('gravatar_default', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('gravatar_rating', 'g');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('gravatar_default_size', '80');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('gzip_compress', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('hot_threshold', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('icons_path', 'images/icons');
Expand Down
11 changes: 11 additions & 0 deletions phpBB/language/en/acp/board.php
Expand Up @@ -101,10 +101,21 @@
'ALLOW_REMOTE_UPLOAD' => 'Enable remote avatar uploading',
'ALLOW_REMOTE_UPLOAD_EXPLAIN' => 'Allow uploading of avatars from another website.',
'ALLOW_UPLOAD' => 'Enable avatar uploading',
'ALLOW_GRAVATAR' => 'Enable Gravatar avatars',
'ALLOW_GRAVATAR_EXPLAIN' => 'Allow users to use the Gravatar attached to their email address.',
'AVATAR_GALLERY_PATH' => 'Avatar gallery path',
'AVATAR_GALLERY_PATH_EXPLAIN' => 'Path under your phpBB root directory for pre-loaded images, e.g. <samp>images/avatars/gallery</samp>.',
'AVATAR_STORAGE_PATH' => 'Avatar storage path',
'AVATAR_STORAGE_PATH_EXPLAIN' => 'Path under your phpBB root directory, e.g. <samp>images/avatars/upload</samp>.',
'GRAVATAR_SETTINGS' => 'Gravatar Ssettings',
'GRAVATAR_FORCE' => 'Force Gravatar avatars',
'GRAVATAR_FORCE_EXPLAIN' => 'Force all newly registered users to use Gravatar avatars. This will work regardless of if avatars are on or not.',
'GRAVATAR_DEFAULT' => 'Default Gravatar image',
'GRAVATAR_DEFAULT_EXPLAIN' => 'If the user\'s email address does not have a Gravatar associated with it, default to this picture. See all possible values <a href="http://en.gravatar.com/site/implement/images/#default-image">here</a> or specify the full URI of a default avatar.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be using a backslash to escape it

'GRAVATAR_RATING' => 'Maximum rating',
'GRAVATAR_RATING_EXPLAIN' => 'Allow the following <a href="http://en.gravatar.com/site/implement/images/#rating">Gravatar rating</a> in Gravatars on the board',
'GRAVATAR_DEFAULT_SIZE' => 'Default Gravatar dimensions',
'GRAVATAR_DEFAULT_SIZE_EXPLAIN' => 'Size of a side in pixels (Gravatars are square)',
'MAX_AVATAR_SIZE' => 'Maximum avatar dimensions',
'MAX_AVATAR_SIZE_EXPLAIN' => 'Width x Height in pixels.',
'MAX_FILESIZE' => 'Maximum avatar file size',
Expand Down
2 changes: 2 additions & 0 deletions phpBB/language/en/ucp.php
Expand Up @@ -474,6 +474,8 @@
'USERNAME_CHARS_ANY_EXPLAIN' => 'Length must be between %1$d and %2$d characters.',
'USERNAME_TAKEN_USERNAME' => 'The username you entered is already in use, please select an alternative.',
'USERNAME_DISALLOWED_USERNAME' => 'The username you entered has been disallowed or contains a disallowed word. Please choose a different name.',
'USE_GRAVATAR' => 'Use Gravatar',
'USE_GRAVATAR_EXPLAIN' => 'Use the Gravatar linked with the email to this forum account. Visit <a href="http://gravatar.com/">Gravatar.com</a> to get one today.',
'USER_NOT_FOUND_OR_INACTIVE' => 'The usernames you specified could either not be found or are not activated users.',

'VIEW_AVATARS' => 'Display avatars',
Expand Down
9 changes: 8 additions & 1 deletion phpBB/styles/prosilver/template/ucp_avatar_options.html
Expand Up @@ -27,7 +27,14 @@
</dl>
<!-- ENDIF -->

<!-- IF S_LINK_AVATAR -->
<!-- IF S_GRAVATAR -->
<dl>
<dt><label for="gravatar">{L_USE_GRAVATAR}:</label><br /><span>{L_USE_GRAVATAR_EXPLAIN}</span></dt>
<dd><input type="checkbox" name="gravatar" id="gravatar" value="1" /></dd>
</dl>
<!-- ENDIF -->

<!-- IF S_LINK_AVATAR or S_GRAVATAR -->
<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>
Expand Down