的Gravatar有PHP執行以下網頁上的說明:
https://en.gravatar.com/site/implement/images/php/
我想使用此代碼在Drupal的用戶配置文件和用戶圖片中實現它。
我創建了一個預處理功能,能夠在用戶profile.tpl.php打印電子郵件地址
function THEMENAME_preprocess_user_profile(&$variables) {
$account = $variables['elements']['#account'];
foreach (element_children($variables['elements']) as $key) {
$variables['user_profile'][$key] = $variables['elements'][$key];
}
$variables['user_profile']['mail'] = $account->mail;
field_attach_preprocess('user', $account, $variables['elements'], $variables);
}
添加的代碼到用戶profile.tpl.php
print render($user_profile['mail']);
這段代碼的工作原理是它在用戶配置文件中顯示郵件地址。現在我需要使用該地址在以後的配置文件和用戶圖片中創建gravatars。
我不知何故嘗試連接Gravatar的網站和此代碼的教程,但沒有成功。這裏是代碼(我已經試過至少20個不同的組合):
$email = "['user_profile']['mail']";
$default = "http://www.somewhere.com/homestar.jpg";
$size = 40;
function get_gravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array()) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($email)));
$url .= "?s=$s&d=$d&r=$r";
if ($img) {
$url = '<img src="' . $url . '"';
foreach ($atts as $key => $val)
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
據我瞭解,問題是此行中:
$email = "['user_profile']['mail']";
我在做什麼錯的,什麼是在這一行中引號之間的正確表達式?
是什麼有這個問題呢?我已經接受了每一個答案,我設法實現,即這解決了我的問題。 – take2