Skip to content

Commit

Permalink
Merge pull request #164 from eurich/gravatars
Browse files Browse the repository at this point in the history
feature: Gravatars
  • Loading branch information
norv committed Feb 25, 2013
2 parents e5cffb1 + a38abd7 commit eeb047f
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 20 deletions.
3 changes: 3 additions & 0 deletions install/install_1-0_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ VALUES (-1, 'search_posts'),
(0, 'profile_server_avatar'),
(0, 'profile_upload_avatar'),
(0, 'profile_remote_avatar'),
(0, 'profile_gravatar'),
(0, 'send_email_to_members'),
(0, 'karma_edit'),
(2, 'view_mlist'),
Expand All @@ -1510,6 +1511,7 @@ VALUES (-1, 'search_posts'),
(2, 'profile_server_avatar'),
(2, 'profile_upload_avatar'),
(2, 'profile_remote_avatar'),
(2, 'profile_gravatar'),
(2, 'send_email_to_members'),
(2, 'profile_title_own'),
(2, 'calendar_post'),
Expand Down Expand Up @@ -1761,6 +1763,7 @@ VALUES ('ourVersion', '{$current_version}'),
('avatar_max_width_upload', '65'),
('avatar_resize_upload', '1'),
('avatar_download_png', '1'),
('gravatar_rating', 'g'),
('failed_login_threshold', '3'),
('oldTopicDays', '120'),
('edit_wait_time', '90'),
Expand Down
3 changes: 3 additions & 0 deletions install/install_1-0_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_r
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_server_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_upload_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_remote_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_gravatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'send_email_to_members');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'karma_edit');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'view_mlist');
Expand All @@ -1960,6 +1961,7 @@ INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_r
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_server_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_upload_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_remote_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_gravatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'send_email_to_members');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_title_own');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'calendar_post');
Expand Down Expand Up @@ -2250,6 +2252,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_max_height_up
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_max_width_upload', '65');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_resize_upload', '1');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_download_png', '1');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('gravatar_rating', 'g');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('failed_login_threshold', '3');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('oldTopicDays', '120');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('edit_wait_time', '90');
Expand Down
3 changes: 3 additions & 0 deletions install/install_1-0_sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_r
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_server_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_upload_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_remote_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'profile_gravatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'send_email_to_members');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (0, 'karma_edit');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'view_mlist');
Expand All @@ -1636,6 +1637,7 @@ INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_r
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_server_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_upload_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_remote_avatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_gravatar');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'send_email_to_members');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'profile_title_own');
INSERT INTO {$db_prefix}permissions (id_group, permission) VALUES (2, 'calendar_post');
Expand Down Expand Up @@ -1903,6 +1905,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_max_height_up
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_max_width_upload', '65');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_resize_upload', '1');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('avatar_download_png', '1');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('gravatar_rating', 'g');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('failed_login_threshold', '3');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('oldTopicDays', '120');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('edit_wait_time', '90');
Expand Down
30 changes: 29 additions & 1 deletion install/upgrade_dia_1-0_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['pac
INSERT IGNORE INTO {$db_prefix}settings
(variable, value)
VALUES
('avatar_default', '0');
('avatar_default', '0'),
('gravatar_rating', 'g');
---#

/******************************************************************************/
Expand Down Expand Up @@ -344,4 +345,31 @@ ALTER TABLE `{$db_prefix}members`
DROP `aim`,
DROP `yim`,
DROP `msn`;
---#
---# Adding gravatar permissions...
---{
// Don't do this twice!
if (@$modSettings['ourVersion'] < '1.0')
{
// Try find people who probably can use remote avatars.
$request = upgrade_query("
SELECT id_group, add_deny, permission
FROM {$db_prefix}permissions
WHERE permission = 'profile_remote_avatar'");
$inserts = array();
while ($row = mysql_fetch_assoc($request))
{
$inserts[] = "($row[id_group], 'profile_gravatar', $row[add_deny])";
}
mysql_free_result($request);

if (!empty($inserts))
upgrade_query("
INSERT IGNORE INTO {$db_prefix}permissions
(id_group, permission, add_deny)
VALUES
" . implode(',', $inserts));
}
---}
---#
30 changes: 29 additions & 1 deletion install/upgrade_dia_1-0_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['pac
INSERT IGNORE INTO {$db_prefix}settings
(variable, value)
VALUES
('avatar_default', '0');
('avatar_default', '0'),
('gravatar_rating', 'g');
---#

/******************************************************************************/
Expand Down Expand Up @@ -397,4 +398,31 @@ ALTER TABLE `{$db_prefix}members`
DROP `aim`,
DROP `yim`,
DROP `msn`;
---#

---# Adding gravatar permissions...
---{
// Don't do this twice!
if (@$modSettings['ourVersion'] < '1.0')
{
// Try find people who probably can use remote avatars.
$request = upgrade_query("
SELECT id_group, add_deny, permission
FROM {$db_prefix}permissions
WHERE permission = 'profile_remote_avatar'");
$inserts = array();
while ($row = mysql_fetch_assoc($request))
{
$inserts[] = "($row[id_group], 'profile_gravatar', $row[add_deny])";
}
mysql_free_result($request);
if (!empty($inserts))
upgrade_query("
INSERT IGNORE INTO {$db_prefix}permissions
(id_group, permission, add_deny)
VALUES
" . implode(',', $inserts));
}
---}
---#
30 changes: 29 additions & 1 deletion install/upgrade_dia_1-0_sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['pac
INSERT IGNORE INTO {$db_prefix}settings
(variable, value)
VALUES
('avatar_default', '0');
('avatar_default', '0'),
('gravatar_rating', 'g');
---#

/******************************************************************************/
Expand Down Expand Up @@ -381,3 +382,30 @@ ALTER TABLE `{$db_prefix}members`
DROP `yim`,
DROP `msn`;
---#

---# Adding gravatar permissions...
---{
// Don't do this twice!
if (@$modSettings['ourVersion'] < '1.0')
{
// Try find people who probably can use remote avatars.
$request = upgrade_query("
SELECT id_group, add_deny, permission
FROM {$db_prefix}permissions
WHERE permission = 'profile_remote_avatar'");
$inserts = array();
while ($row = mysql_fetch_assoc($request))
{
$inserts[] = "($row[id_group], 'profile_gravatar', $row[add_deny])";
}
mysql_free_result($request);
if (!empty($inserts))
upgrade_query("
INSERT IGNORE INTO {$db_prefix}permissions
(id_group, permission, add_deny)
VALUES
" . implode(',', $inserts));
}
---}
---#
98 changes: 81 additions & 17 deletions sources/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,7 @@ function loadMemberContext($user, $display_custom_fields = false)
'location' => $profile['location'],
'real_posts' => $profile['posts'],
'posts' => comma_format($profile['posts']),
'avatar' => array(
'name' => $profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
),
'avatar' => determineAvatar($profile, $avatar_width, $avatar_height),
'last_login' => empty($profile['last_login']) ? $txt['never'] : timeformat($profile['last_login']),
'last_login_timestamp' => empty($profile['last_login']) ? 0 : forum_time(0, $profile['last_login']),
'karma' => array(
Expand Down Expand Up @@ -1153,17 +1148,6 @@ function loadMemberContext($user, $display_custom_fields = false)
'local_time' => timeformat(time() + ($profile['time_offset'] - $user_info['time_offset']) * 3600, false),
);

if(!empty($modSettings['avatar_default']) && empty($profile['avatar']) && empty($profile['filename']))
{
// Change the avatar's URL
$memberContext[$user]['avatar'] = array(
'name' => '',
'image' => '<img src="' . $settings['images_url'] . '/default_avatar.png' . '" alt="" class="avatar" border="0" />',
'href' => $settings['images_url'] . '/default_avatar.png',
'url' => 'http://'
);
}

// Are we also loading the members custom fields into context?
if ($display_custom_fields && !empty($modSettings['displayFields']))
{
Expand Down Expand Up @@ -2554,3 +2538,83 @@ function loadDatabase()
if (ELKARTE == 'SSI')
db_fix_prefix($db_prefix, $db_name);
}
/**
* Determine the user's avatar type and return the information as an array
*
* @param array $profile
* @param type $max_avatar_width
* @param type $max_avatar_height
* @return array $avatar
*/
function determineAvatar($profile, $max_avatar_width, $max_avatar_height)
{
global $modSettings, $scripturl, $settings;

// uploaded avatar?
if ($profile['id_attach'] > 0 && empty($profile['avatar']))
{
$avatar = array(
'name' => $profile['avatar'],
'image' => '<img class="avatar" src="' . $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar" alt="" />',
'href' => $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar',
'url' => '',
);
}

// remote avatar?
elseif (stristr($profile['avatar'], 'http://'))
{
$avatar = array(
'name' => $profile['avatar'],
'image' => '<img class="avatar" src="' . $profile['avatar'] . '" ' . $max_avatar_width . $max_avatar_height . ' alt="" border="0" />',
'href' => $profile['avatar'],
'url' => $profile['avatar'],
);
}

// Gravatar instead?
elseif (!empty($profile['avatar']) && $profile['avatar'] === 'gravatar')
{
// Gravatars URL.
$gravatar_url = 'http://www.gravatar.com/avatar/' . md5(strtolower($profile['email_address'])) . 'd=' . $modSettings['avatar_max_height_external'] . (!empty($modSettings['gravatar_rating']) ? ('&r=' . $modSettings['gravatar_rating']) : '');

$avatar = array(
'name' => $profile['avatar'],
'image' => '<img src="' . $gravatar_url . '" alt="" class="avatar" border="0" />',
'href' => $gravatar_url,
'url' => $gravatar_url,
);
}

// an avatar from the gallery?
elseif (!empty($profile['avatar']) && !stristr($profile['avatar'], 'http://'))
{
$avatar = array(
'name' => $profile['avatar'],
'image' => '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . $profile['avatar'] . '" alt="" />',
'href' => $modSettings['avatar_url'] . '/' . $profile['avatar'],
'url' => $modSettings['avatar_url'] . '/' . $profile['avatar'],
);
}

// no custon avatar found yet, maybe a default avatar?
elseif (($modSettings['avatar_default']) && empty($profile['avatar']) && empty($profile['filename']))
{
$avatar = array(
'name' => '',
'image' => '<img src="' . $settings['images_url'] . '/default_avatar.png' . '" alt="" class="avatar" border="0" />',
'href' => $settings['images_url'] . '/default_avatar.png',
'url' => 'http://',
);
}
//finally ...
else
$avatar = array(
'name' => '',
'image' => '',
'href' => '',
'url' => ''
);

return $avatar;
}
10 changes: 10 additions & 0 deletions sources/admin/ManageAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ function action_avatars($return_config = false)
'option_download_and_resize' => $txt['option_download_and_resize'],
),
),
array('title','gravatar'),
array('permissions', 'profile_gvatar', 0, $txt['gravatar_groups']),
array('select', 'gravatar_rating',
array(
'g' => 'g',
'pg' => 'pg',
'r' => 'r',
'x' => 'x',
),
),
// Uploadable avatars?
array('title', 'avatar_upload'),
array('permissions', 'profile_upload_avatar', 0, $txt['avatar_upload_groups']),
Expand Down
11 changes: 11 additions & 0 deletions sources/subs/Profile.subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ function profileLoadAvatarData()
'allow_server_stored' => allowedTo('profile_server_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
'allow_upload' => allowedTo('profile_upload_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
'allow_external' => allowedTo('profile_remote_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
'allow_gravatar' => allowedTo('profile_gravatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
);

if ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
Expand All @@ -1571,6 +1572,12 @@ function profileLoadAvatarData()
'server_pic' => 'blank.png',
'external' => $cur_profile['avatar']
);
elseif ($cur_profile['avatar'] == 'gravatar' && $context['member']['avatar']['allow_gravatar'])
$context['member']['avatar'] += array(
'choice' => 'gravatar',
'server_pic' => 'blank.png',
'external' => 'http://'
);
elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
$context['member']['avatar'] += array(
'choice' => 'server_stored',
Expand Down Expand Up @@ -1946,6 +1953,10 @@ function profileSaveAvatarData(&$value)
// Get rid of their old avatar. (if uploaded.)
removeAttachments(array('id_member' => $memID));
}
elseif ($value == 'gravatar' && allowedTo('profile_gavatar'))
{
$profile_vars['avatar'] = 'gravatar';
}
elseif ($value == 'external' && allowedTo('profile_remote_avatar') && stripos($_POST['userpicpersonal'], 'http://') === 0 && empty($modSettings['avatar_download_external']))
{
// We need these clean...
Expand Down
Loading

0 comments on commit eeb047f

Please sign in to comment.