# HG changeset patch
# User Dan
# Date 1215657641 14400
# Node ID 68f8a9cc0a18f8ac3c0e85eb8ec282f704d7cc6b
# Parent 58852672ff12728c6037fefb9e552a6a93d3da27
Added Gravatar support! And it's really configurable too.
diff -r 58852672ff12 -r 68f8a9cc0a18 includes/comment.php
--- a/includes/comment.php Wed Jul 09 21:04:51 2008 -0400
+++ b/includes/comment.php Wed Jul 09 22:40:41 2008 -0400
@@ -98,7 +98,7 @@
{
$ret['template'] = file_get_contents(ENANO_ROOT . '/themes/' . $template->theme . '/comment.tpl');
}
- $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c
+ $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c
LEFT JOIN '.table_prefix.'users AS u
ON (u.user_id=c.user_id)
LEFT JOIN '.table_prefix.'buddies AS b
@@ -107,7 +107,7 @@
ON ( ( u.user_rank = r.rank_id ) )
WHERE page_id=\'' . $this->page_id . '\'
AND namespace=\'' . $this->namespace . '\'
- GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend
+ GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend
ORDER BY c.time ASC;');
$count_appr = 0;
$count_total = 0;
@@ -157,7 +157,7 @@
$row['have_ip'] = ( $row['have_ip'] == 1 );
// Avatar URL
- $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
+ $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type'], $row['email']);
// Add the comment to the list
$ret['comments'][] = $row;
@@ -308,7 +308,7 @@
$db->die_json();
// Re-fetch
- $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type FROM '.table_prefix.'comments AS c
+ $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type FROM '.table_prefix.'comments AS c
LEFT JOIN '.table_prefix.'users AS u
ON (u.user_id=c.user_id)
WHERE page_id=\'' . $this->page_id . '\'
@@ -341,7 +341,7 @@
$ret['user_level_list']['member'] = USER_LEVEL_MEMBER;
$ret['user_level_list']['mod'] = USER_LEVEL_MOD;
$ret['user_level_list']['admin'] = USER_LEVEL_ADMIN;
- $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
+ $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type'], $row['email']);
}
break;
diff -r 58852672ff12 -r 68f8a9cc0a18 includes/constants.php
--- a/includes/constants.php Wed Jul 09 21:04:51 2008 -0400
+++ b/includes/constants.php Wed Jul 09 22:40:41 2008 -0400
@@ -75,6 +75,7 @@
define('IMAGE_TYPE_PNG', 1);
define('IMAGE_TYPE_GIF', 2);
define('IMAGE_TYPE_JPG', 3);
+define('IMAGE_TYPE_GRV', 4);
// token types
define('TOKEN_VARIABLE', 1);
diff -r 58852672ff12 -r 68f8a9cc0a18 includes/functions.php
--- a/includes/functions.php Wed Jul 09 21:04:51 2008 -0400
+++ b/includes/functions.php Wed Jul 09 22:40:41 2008 -0400
@@ -4152,25 +4152,38 @@
* Generates a URL for the avatar for the given user ID and avatar type.
* @param int User ID
* @param string Image type - must be one of jpg, png, or gif.
+ * @param string User's e-mail address, makes Special:Avatar redirect if not specified
* @return string
*/
-function make_avatar_url($user_id, $avi_type)
+function make_avatar_url($user_id, $avi_type, $user_email = false)
{
static $img_types = array(
'png' => IMAGE_TYPE_PNG,
'gif' => IMAGE_TYPE_GIF,
- 'jpg' => IMAGE_TYPE_JPG
+ 'jpg' => IMAGE_TYPE_JPG,
+ 'grv' => IMAGE_TYPE_GRV
);
if ( !is_int($user_id) )
return false;
if ( !isset($img_types[$avi_type]) )
return false;
- $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
- if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
+
+ if ( $avi_type == 'grv' )
{
- return '';
+ if ( $user_email )
+ {
+ return make_gravatar_url($user_email);
+ }
+ }
+ else
+ {
+ $avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
+ if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
+ {
+ return '';
+ }
}
$img_type = $img_types[$avi_type];
@@ -4184,6 +4197,39 @@
}
/**
+ * Generates a URL to the Gravatar for a user based on his/her e-mail address.
+ * @param string E-mail address
+ * @param int Size - defaults to site-wide limits
+ * @return string URL
+ */
+
+function make_gravatar_url($email, $size = false)
+{
+ $email = md5($email);
+
+ // gravatar parameters
+ if ( $size )
+ {
+ $max_size = intval($size);
+ }
+ else
+ {
+ $max_x = intval(getConfig('avatar_max_width', '150'));
+ $max_y = intval(getConfig('avatar_max_height', '150'));
+ // ?s=
+ $max_size = ( $max_x > $max_y ) ? $max_y : $max_x;
+ }
+
+ // ?r=
+ $rating = getConfig('gravatar_rating', 'g');
+
+ // final URL
+ $url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size";
+
+ return $url;
+}
+
+/**
* Determines an image's filetype based on its signature.
* @param string Path to image file
* @return string One of gif, png, or jpg, or false if none of these.
diff -r 58852672ff12 -r 68f8a9cc0a18 includes/pageprocess.php
--- a/includes/pageprocess.php Wed Jul 09 21:04:51 2008 -0400
+++ b/includes/pageprocess.php Wed Jul 09 22:40:41 2008 -0400
@@ -1398,7 +1398,7 @@
echo '
';
if ( $userdata['user_has_avatar'] == '1' )
{
- echo ' ';
+ echo ' ';
}
// username
echo '' . htmlspecialchars($target_username) . ' ';
diff -r 58852672ff12 -r 68f8a9cc0a18 includes/pageutils.php
--- a/includes/pageutils.php Wed Jul 09 21:04:51 2008 -0400
+++ b/includes/pageutils.php Wed Jul 09 22:40:41 2008 -0400
@@ -641,7 +641,7 @@
if(!$e) $db->_die('The comment text data could not be selected.');
$num_app = $db->numrows();
$db->free_result();
- $lq = $db->sql_query('SELECT c.comment_id,c.subject,c.name,c.comment_data,c.approved,c.time,c.user_id,c.ip_address,u.user_level,u.signature,u.user_has_avatar,u.avatar_type
+ $lq = $db->sql_query('SELECT c.comment_id,c.subject,c.name,c.comment_data,c.approved,c.time,c.user_id,c.ip_address,u.user_level,u.email,u.signature,u.user_has_avatar,u.avatar_type
FROM ' . table_prefix.'comments AS c
LEFT JOIN ' . table_prefix.'users AS u
ON c.user_id=u.user_id
@@ -765,7 +765,7 @@
{
$bool['user_has_avatar'] = true;
$strings['AVATAR_ALT'] = $lang->get('usercp_avatar_image_alt', array('username' => $row['name']));
- $strings['AVATAR_URL'] = make_avatar_url(intval($row['user_id']), $row['avatar_type']);
+ $strings['AVATAR_URL'] = make_avatar_url(intval($row['user_id']), $row['avatar_type'], $row['email']);
$strings['USERPAGE_LINK'] = makeUrlNS('User', $row['name']);
}
diff -r 58852672ff12 -r 68f8a9cc0a18 install/schemas/mysql_stage2.sql
--- a/install/schemas/mysql_stage2.sql Wed Jul 09 21:04:51 2008 -0400
+++ b/install/schemas/mysql_stage2.sql Wed Jul 09 22:40:41 2008 -0400
@@ -108,7 +108,7 @@
user_coppa tinyint(1) NOT NULL DEFAULT 0,
user_lang smallint(5) NOT NULL DEFAULT 1,
user_has_avatar tinyint(1) NOT NULL DEFAULT 0,
- avatar_type ENUM('jpg', 'png', 'gif') NOT NULL DEFAULT 'png',
+ avatar_type ENUM('jpg', 'png', 'gif', 'grv') NOT NULL DEFAULT 'png',
user_registration_ip varchar(39),
user_rank int(12) UNSIGNED DEFAULT NULL,
user_timezone int(12) UNSIGNED NOT NULL DEFAULT 0,
diff -r 58852672ff12 -r 68f8a9cc0a18 install/schemas/postgresql_stage2.sql
--- a/install/schemas/postgresql_stage2.sql Wed Jul 09 21:04:51 2008 -0400
+++ b/install/schemas/postgresql_stage2.sql Wed Jul 09 22:40:41 2008 -0400
@@ -114,7 +114,7 @@
user_timezone int NOT NULL DEFAULT 0,
user_title varchar(64) DEFAULT NULL,
user_group int NOT NULL DEFAULT 1,
- CHECK (avatar_type IN ('jpg', 'png', 'gif')),
+ CHECK (avatar_type IN ('jpg', 'png', 'gif', 'grv')),
PRIMARY KEY (user_id)
);
diff -r 58852672ff12 -r 68f8a9cc0a18 install/schemas/upgrade/1.1.3-1.1.4-mysql.sql
--- a/install/schemas/upgrade/1.1.3-1.1.4-mysql.sql Wed Jul 09 21:04:51 2008 -0400
+++ b/install/schemas/upgrade/1.1.3-1.1.4-mysql.sql Wed Jul 09 22:40:41 2008 -0400
@@ -27,3 +27,6 @@
-- Disable JS effects column
ALTER TABLE {{TABLE_PREFIX}}users_extra ADD COLUMN disable_js_fx tinyint(1) NOT NULL DEFAULT 0;
+
+-- Add "grv" avatar type
+ALTER TABLE {{TABLE_PREFIX}}users MODIFY COLUMN avatar_type ENUM('png', 'gif', 'jpg', 'grv');
diff -r 58852672ff12 -r 68f8a9cc0a18 install/schemas/upgrade/1.1.3-1.1.4-postgresql.sql
--- a/install/schemas/upgrade/1.1.3-1.1.4-postgresql.sql Wed Jul 09 21:04:51 2008 -0400
+++ b/install/schemas/upgrade/1.1.3-1.1.4-postgresql.sql Wed Jul 09 22:40:41 2008 -0400
@@ -40,3 +40,6 @@
-- Disable JS effects column
ALTER TABLE {{TABLE_PREFIX}}users_extra ADD COLUMN disable_js_fx smallint NOT NULL DEFAULT 0;
+-- Add "grv" avatar type
+ALTER TABLE {{TABLE_PREFIX}}users DROP CONSTRAINT {{TABLE_PREFIX}}users_avatar_type_check;
+ALTER TABLE {{TABLE_PREFIX}}users ADD CONSTRAINT {{TABLE_PREFIX}}users_avatar_type_check CHECK ( avatar_type IN ( 'png', 'gif', 'jpg', 'grv' ) );
diff -r 58852672ff12 -r 68f8a9cc0a18 language/english/admin.json
--- a/language/english/admin.json Wed Jul 09 21:04:51 2008 -0400
+++ b/language/english/admin.json Wed Jul 09 22:40:41 2008 -0400
@@ -327,6 +327,12 @@
field_avatar_upload_methods: 'Allowed upload methods:',
field_avatar_upload_file: 'Allow users to upload image files from their computers',
field_avatar_upload_http: 'Allow users to enter a URL to their desired avatar',
+ field_avatar_upload_gravatar: 'Allow users to use their Gravatar',
+ field_avatar_gravatar_rating: 'Highest allowed rating for Gravatar images:',
+ field_avatar_gravatar_rating_g: 'G (no objectionable content)',
+ field_avatar_gravatar_rating_pg: 'PG (rude gestures, immodest dress, mild swearing/violence)',
+ field_avatar_gravatar_rating_r: 'R (profanity, violence, nudity, hard drug use)',
+ field_avatar_gravatar_rating_x: 'X (hardcore sexual images, extremely disturbing violence)',
field_avatar_directory: 'Avatar storage directory:',
field_avatar_directory_hint: 'This should be relative to your Enano root and should contain only alphanumeric characters and forward slashes, even if your server runs Windows.',
diff -r 58852672ff12 -r 68f8a9cc0a18 language/english/user.json
--- a/language/english/user.json Wed Jul 09 21:04:51 2008 -0400
+++ b/language/english/user.json Wed Jul 09 22:40:41 2008 -0400
@@ -331,6 +331,7 @@
avatar_lbl_remove: 'Delete my avatar',
avatar_lbl_set_http: 'Upload a new avatar from the Web',
avatar_lbl_set_file: 'Upload a new avatar from my computer',
+ avatar_lbl_set_gravatar: 'Use my Gravatar',
avatar_lbl_url: 'URL to image:',
avatar_lbl_url_desc: 'This must start with the http:// prefix and must be a valid URL. The image will be copied from the existing URL to this server - dynamic avatars are not supported.',
avatar_lbl_file: 'Upload file:',
@@ -345,6 +346,12 @@
avatar_move_failed: 'Your image was accepted, but there was a problem moving the image file to the correct location.',
avatar_upload_success: 'Your avatar has been updated.',
avatar_file_too_large: 'The image you uploaded exceeds the maximum file size allowed for avatars on this site.',
+ avatar_gravatar_success: 'Your Gravatar will now be used as your avatar on this site.',
+ avatar_gravatar_rating_g: 'The highest allowed rating for your Gravatar image is G. Images must be suitable for display on all websites with any audience type.',
+ avatar_gravatar_rating_pg: 'The highest allowed rating for your Gravatar image is PG. Rude gestures, lesser swear words, mild violence, and mildly provocatively dressed individuals are permitted.',
+ avatar_gravatar_rating_r: 'The highest allowed rating for your Gravatar image is R. Nudity and violence must be tasteful.',
+ avatar_gravatar_rating_x: 'The highest allowed rating for your Gravatar image is X.',
+ avatar_link_gravatar_info: 'Learn about Gravatar',
// Password strength widget
pwstrength_score_verystrong: 'Very strong (score: %score%)',
diff -r 58852672ff12 -r 68f8a9cc0a18 plugins/SpecialAdmin.php
--- a/plugins/SpecialAdmin.php Wed Jul 09 21:04:51 2008 -0400
+++ b/plugins/SpecialAdmin.php Wed Jul 09 22:40:41 2008 -0400
@@ -341,6 +341,11 @@
setConfig('avatar_enable_anim', ( isset($_POST['avatar_enable_anim']) ? '1' : '0' ));
setConfig('avatar_upload_file', ( isset($_POST['avatar_upload_file']) ? '1' : '0' ));
setConfig('avatar_upload_http', ( isset($_POST['avatar_upload_http']) ? '1' : '0' ));
+ setConfig('avatar_upload_gravatar', ( isset($_POST['avatar_upload_gravatar']) ? '1' : '0' ));
+ if ( in_array($_POST['gravatar_rating'], array('g', 'pg', 'r', 'x')) )
+ {
+ setConfig('gravatar_rating', $_POST['gravatar_rating']);
+ }
if ( is_dir(ENANO_ROOT . '/' . $_POST['avatar_directory']) )
{
@@ -497,22 +502,6 @@
|
-
-
-
-
get('acpgc_heading_disablesite'); ?> |
@@ -811,6 +800,40 @@
/>
get('acpgc_field_avatar_upload_http'); ?>
+
+
+
+
+
+
+
+
diff -r 58852672ff12 -r 68f8a9cc0a18 plugins/SpecialUserFuncs.php
--- a/plugins/SpecialUserFuncs.php Wed Jul 09 21:04:51 2008 -0400
+++ b/plugins/SpecialUserFuncs.php Wed Jul 09 22:40:41 2008 -0400
@@ -2079,7 +2079,8 @@
$img_types = array(
IMAGE_TYPE_PNG => 'png',
IMAGE_TYPE_GIF => 'gif',
- IMAGE_TYPE_JPG => 'jpg'
+ IMAGE_TYPE_JPG => 'jpg',
+ IMAGE_TYPE_GRV => 'grv'
);
$avi_id = $paths->getParam(0);
@@ -2106,6 +2107,31 @@
// build file path
$avi_type = $img_types[$avi_id_dec['img_type']];
+
+ // is this a gravatar?
+ if ( $avi_type == 'grv' )
+ {
+ // yes, we'll have to redirect
+ // sanitize UID
+ $uid = intval($avi_id_dec['uid']);
+
+ // fetch email
+ $q = $db->sql_query('SELECT email FROM ' . table_prefix . "users WHERE user_id = $uid;");
+ if ( !$q )
+ $db->_die();
+ if ( $db->numrows() < 1 )
+ return false;
+
+ list($email) = $db->fetchrow_num();
+ $db->free_result();
+
+ $url = make_gravatar_url($url);
+
+ // ship out the redirect
+ header('HTTP/1.1 302 Permanent Redirect');
+ header("Location: $url");
+ }
+
$avi_path = ENANO_ROOT . '/' . getConfig('avatar_directory') . '/' . $avi_id_dec['uid'] . '.' . $avi_type;
if ( file_exists($avi_path) )
{
diff -r 58852672ff12 -r 68f8a9cc0a18 plugins/SpecialUserPrefs.php
--- a/plugins/SpecialUserPrefs.php Wed Jul 09 21:04:51 2008 -0400
+++ b/plugins/SpecialUserPrefs.php Wed Jul 09 22:40:41 2008 -0400
@@ -896,6 +896,32 @@
echo '' . $lang->get('usercp_avatar_move_failed') . '
';
}
break;
+ case 'set_gravatar':
+ // set avatar to use Gravatar
+ // make sure we're allowed to do this
+ if ( getConfig('avatar_upload_gravatar') != '1' )
+ {
+ // access denied
+ break;
+ }
+ // first, remove old image
+ if ( $has_avi )
+ {
+ // First switch the avatar off
+ $q = $db->sql_query('UPDATE ' . table_prefix . 'users SET user_has_avatar = 0 WHERE user_id = ' . $session->user_id . ';');
+ if ( !$q )
+ $db->_die('Avatar CP switching user avatar off');
+
+ @unlink($avi_path);
+ }
+ // set to gravatar mode
+ $q = $db->sql_query('UPDATE ' . table_prefix . 'users SET user_has_avatar = 1, avatar_type = \'grv\' WHERE user_id = ' . $session->user_id . ';');
+ if ( !$q )
+ $db->_die('Avatar CP switching user avatar off');
+
+ $has_avi = 1;
+ echo '' . $lang->get('usercp_avatar_gravatar_success') . '
';
+ break;
}
}
@@ -910,14 +936,22 @@
case 'remove':
$('avatar_upload_http').object.style.display = 'none';
$('avatar_upload_file').object.style.display = 'none';
+ $('avatar_upload_gravatar').object.style.display = 'none';
break;
case 'set_http':
$('avatar_upload_http').object.style.display = 'block';
$('avatar_upload_file').object.style.display = 'none';
+ $('avatar_upload_gravatar').object.style.display = 'none';
break;
case 'set_file':
$('avatar_upload_http').object.style.display = 'none';
$('avatar_upload_file').object.style.display = 'block';
+ $('avatar_upload_gravatar').object.style.display = 'none';
+ break;
+ case 'set_gravatar':
+ $('avatar_upload_gravatar').object.style.display = 'block';
+ $('avatar_upload_http').object.style.display = 'none';
+ $('avatar_upload_file').object.style.display = 'none';
break;
}
}
@@ -942,7 +976,7 @@
if ( $has_avi == 1 )
{
- echo '';
+ echo '';
}
else
{
@@ -973,7 +1007,7 @@
}
if ( getConfig('avatar_upload_file') == '1' )
{
- echo '
+ echo '
' . $lang->get('usercp_avatar_lbl_file') . '
' . $lang->get('usercp_avatar_lbl_file_desc') . ' ' . $lang->get('usercp_avatar_limits') . '
@@ -983,6 +1017,24 @@
{
echo '
';
}
+ if ( getConfig('avatar_upload_gravatar') == '1' )
+ {
+ $rating_images = array('g' => '0', 'pg' => '1', 'r' => '2', 'x' => '3');
+ $rating_id = $rating_images[ getConfig('gravatar_rating', 'g') ];
+ $rating_image = "http://s.gravatar.com/images/gravatars/ratings/$rating_id.gif";
+ $max_rating = getConfig('gravatar_rating', 'g');
+ echo '
(
' . $lang->get('usercp_avatar_link_gravatar_info') . ')
+
+
+
+
+ ' . $lang->get("usercp_avatar_gravatar_rating_$max_rating") . '
+
';
+ }
+ else
+ {
+ echo '
';
+ }
echo '
';
diff -r 58852672ff12 -r 68f8a9cc0a18 plugins/admin/UserManager.php
--- a/plugins/admin/UserManager.php Wed Jul 09 21:04:51 2008 -0400
+++ b/plugins/admin/UserManager.php Wed Jul 09 22:40:41 2008 -0400
@@ -1226,7 +1226,7 @@
{
$parser->assign_vars(array(
'AVATAR_SRC' => make_avatar_url($this->user_id, $this->avi_type),
- 'AVATAR_ALT' => $lang->get('usercp_avatar_image_alt', array('username' => $this->username))
+ 'AVATAR_ALT' => $lang->get('usercp_avatar_image_alt', array('username' => $this->username), $this->email)
));
}