Задача:
Если в мультисайтинге пользователи сделаны общими, а файлы, которые загружают пользователи хранятся в разных папках, то возникает проблема с загрузкой аватар пользователей, потому что сохраняются они в разные папки, а таблица users (где хранятся пути к картинкам) - общая. Нужно показывать одинаковые аватары не всех сайтах и сделать их загрузку возможной на любом из сайтов в мультисайтинге.
В файле template.php текущей темы для каждого сайта, где нужны общие аватары для общих пользователей, вставить функцию:
Drupal 6
function phptemplate_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = $GLOBALS['base_url'] .'/'. $account->picture;
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
if (!empty($account->uid) && user_access('access user profiles')) {
$attributes = drupal_attributes($attributes);
$url = (url($picture) == $picture) ? $picture : (base_path() . $picture);
$picture = l(
'<img src="'. check_url($url) .'" alt="'. check_plain($alt) .'" title="'. check_plain($alt) .'" '. (isset($image_attributes) ? $image_attributes : '') . $attributes .' />',
'user/'. $account->uid,
array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE)
);
return '<div class="picture">'. $picture .'</div>';
}
}
}
}
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = $GLOBALS['base_url'] .'/'. $account->picture;
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
if (!empty($account->uid) && user_access('access user profiles')) {
$attributes = drupal_attributes($attributes);
$url = (url($picture) == $picture) ? $picture : (base_path() . $picture);
$picture = l(
'<img src="'. check_url($url) .'" alt="'. check_plain($alt) .'" title="'. check_plain($alt) .'" '. (isset($image_attributes) ? $image_attributes : '') . $attributes .' />',
'user/'. $account->uid,
array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE)
);
return '<div class="picture">'. $picture .'</div>';
}
}
}
}
Drupal 5
function theme_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = $GLOBALS['base_url'] .'/'. $account->picture;
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
$picture = theme('image', $picture, $alt, $alt, '', FALSE);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, 'user/$account->uid', array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
return '<div class="picture">'. $picture .'</div>';
}
}
}
}
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = $GLOBALS['base_url'] .'/'. $account->picture;
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
$picture = theme('image', $picture, $alt, $alt, '', FALSE);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, 'user/$account->uid', array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
return '<div class="picture">'. $picture .'</div>';
}
}
}
}
Права доступа
Аватары увидят те пользователи, у которых есть право доступа access users profile, остальные аватары не увидят.
Использованные материалы:
Полезные рецепты по этой теме:
Bookmark/Search this post with










