实现思路:利用评论表单接收
email
的值并记录邮箱到MySQL,再通过MySQL记录的邮箱地址来获取与该邮箱相关联的头像。第一步:利用评论表单email
,写入邮箱信息到MySQL
在 engine/modules/addcomments.php 查找:
$weburl = $_POST['weburl'];
if( $is_logged ) $db->query( "INSERT INTO " . PREFIX . "_comments (post_id, user_id, date, autor, email, text, ip, is_register, approve, parent,weburl) values ('{$post_id}', '{$member_id['user_id']}', '{$time}', '{$name}', '{$mail}', '{$comments}', '{$_IP}', '1', '{$where_approve}', '{$parent}', '{$weburl}')" );
else $db->query( "INSERT INTO " . PREFIX . "_comments (post_id, date, autor, email, text, ip, is_register, approve, parent,weburl) values ('{$post_id}', '{$time}', '{$name}', '{$mail}', '{$comments}', '{$_IP}', '0', '{$where_approve}', '{$parent}', '{$weburl}')" );
上面这段代码是记录评论URL而修改的,如果你没有用 guest_url v1.0 插件,则应该查找:
if( $row['gast_email'] != "" ) {
$tpl->set( '{author}', "<a href=\"mailto:".htmlspecialchars($row['gast_email'], ENT_QUOTES, $config['charset'])."\">" . $row['gast_name'] . "</a>" );
你必须登录查看隐藏内容.请 注册 或 登录
上面这段代码是游客URL而修改的,如果你没用 guest_url v1.0 插件(替换为上面的代码),否则应替换为(这里将weburl
和mail
合并,不然会冲突):你必须登录查看隐藏内容.请 注册 或 登录
第二步:guestfoto
(写入到数据库的邮箱,详见第一步)替换foto
(默认头像)以获取邮箱相关联的头像。
请注意:这里需要用到 Gravatar.cn 插件,因为源代码是以 www.gravatar.com 访问。Gravatar.cn 插件可以将 www.gravatar.com 切换到cravatar.cn,速度会快很多。
Gravatar官方
const md5 = require( 'md5' );
function getGravatarURL( email ) {
// Trim leading and trailing whitespace from
// an email address and force all characters
// to lower case
const address = String( email ).trim().toLowerCase();
// Create an MD5 hash of the final string
const hash = md5( address );
// Grab the actual image URL
return `https://www.gravatar.cn/avatar/${ hash }`;
}
function get_gravatar_url( $email ) {
// Trim leading and trailing whitespace from
// an email address and force all characters
// to lower case
$address = strtolower( trim( $email ) );
// Create an MD5 hash of the final string
$hash = md5( $address );
// Grab the actual image URL
return 'https://www.gravatar.cn/avatar/' . $hash;
}
你必须登录查看隐藏内容.请 注册 或 登录
if ( count(explode("@", $row['foto'])) == 2 ) {
$tpl->set( '{foto}', 'https://cravatar.cn/avatar/' . md5(trim($row['foto'])) . '?s=' . intval($user_group[$row['user_group']]['max_foto']) );
} else {
if( $row['foto'] ) {
if (strpos($row['foto'], "//") === 0) $avatar = "http:".$row['foto']; else $avatar = $row['foto'];
$avatar = @parse_url ( $avatar );
if($avatar['host']) {
$tpl->set( '{foto}', $row['foto'] );
} else $tpl->set( '{foto}', $config['http_home_url'] . "uploads/fotos/" . $row['foto'] );
} else $tpl->set( '{foto}', "{THEME}/dleimages/noavatar.png" );
}
你必须登录查看隐藏内容.请 注册 或 登录
Gravatar-v1.3 XML
Dabenshi-Blog-gravatar-v1_3.zip
size: 1.68 Kb
time: 2023-08-24 11:07:53
md5:caf16973cc2780cd3a89ad998a17e14e
time: 2023-08-24 11:07:53
md5:caf16973cc2780cd3a89ad998a17e14e
请注册一个帐户或登录下载。
Guest_url v1.0 双生 XML
Dabenshi-Blog-guest_url-v1_0gravatar-v1_3.zip
size: 2.24 Kb
time: 2023-08-24 11:11:01
md5:5a88a7b40773747a5068835e8226f21c
time: 2023-08-24 11:11:01
md5:5a88a7b40773747a5068835e8226f21c
请注册一个帐户或登录下载。
Gravatar.cn XML
Dabenshi-Blog-gravatar_cn.zip
size: 691 b
time: 2023-08-24 11:40:04
md5:a1b02b7055e6bfbc089db2cff0f33894
time: 2023-08-24 11:40:04
md5:a1b02b7055e6bfbc089db2cff0f33894
请注册一个帐户或登录下载。