1
0

Support linking to user profiles (if viewable).

This commit is contained in:
rWatcher 2012-06-11 14:05:12 -04:00
parent 5f5d8b986f
commit 40c9303d63
2 changed files with 74 additions and 5 deletions

View File

@ -116,11 +116,19 @@ class rwinfo_block_Core {
if ($theme->item->owner && module::get_var("rwinfo", "show_owner")) {
$display_name = $theme->item->owner->display_name();
if ($theme->item->owner->url) {
// rWatcher Edit: Display profile instead of web site, if viewable.
$str_owner_url = $theme->item->owner->url;
if (rwinfo_block_Core::_can_view_profile_pages(identity::lookup_user($theme->item->owner->id))) {
$str_owner_url = user_profile::url($theme->item->owner->id);
}
// rWatcher End Edit
if ($str_owner_url) { //rW Edit $str_owner_url.
$info["owner"] = array(
"label" => t("Owner:"),
"value" => "<a href=\"{$theme->item->owner->url}\">" .
html::clean($display_name) . "</a>"
"value" => "<a href=\"{$str_owner_url}\">" .
html::clean($display_name) . "</a>" //rW Edit $str_owner_url.
);
} else {
$info["owner"] = array(
@ -137,4 +145,31 @@ class rwinfo_block_Core {
}
return $block;
}
// This came from modules/gallery/controllers/user_profile.php.
private function _can_view_profile_pages($user) {
if (!$user->loaded()) {
return false;
}
if ($user->id == identity::active_user()->id) {
// You can always view your own profile
return true;
}
switch (module::get_var("gallery", "show_user_profiles_to")) {
case "admin_users":
return identity::active_user()->admin;
case "registered_users":
return !identity::active_user()->guest;
case "everybody":
return true;
default:
// Fail in private mode on an invalid setting
return false;
}
}
}

View File

@ -44,12 +44,19 @@ class rwinfo_theme_Core {
}
// rWatcher End Edit
// rWatcher Edit: Display profile instead of web site, if viewable.
$str_owner_url = $item->owner->url;
if (rwinfo_theme_Core::_can_view_profile_pages(identity::lookup_user($item->owner->id))) {
$str_owner_url = user_profile::url($item->owner->id);
}
// rWatcher End Edit
if ($item->owner) {
$results .= "<li>";
if ($item->owner->url) {
if ($str_owner_url) { //rW Edit str_owner_url
$results .= t("By: <a href=\"%owner_url\">%owner_name</a>",
array("owner_name" => $item->owner->display_name(),
"owner_url" => $item->owner->url));
"owner_url" => $str_owner_url)); // rW Edit str_owner_url
} else {
$results .= t("By: %owner_name", array("owner_name" => $item->owner->display_name()));
}
@ -57,4 +64,31 @@ class rwinfo_theme_Core {
}
return $results;
}
// This came from modules/gallery/controllers/user_profile.php.
private function _can_view_profile_pages($user) {
if (!$user->loaded()) {
return false;
}
if ($user->id == identity::active_user()->id) {
// You can always view your own profile
return true;
}
switch (module::get_var("gallery", "show_user_profiles_to")) {
case "admin_users":
return identity::active_user()->admin;
case "registered_users":
return !identity::active_user()->guest;
case "everybody":
return true;
default:
// Fail in private mode on an invalid setting
return false;
}
}
}