Commit e262b5bb authored by Richard Mansfield's avatar Richard Mansfield

Use clean profile urls when data is already available

Bug #1006634, part 3

Adds a new profile_url function which respects the cleanurls
configuration, and makes use of this function in many places where the
user's url field is already available:

- Admin user account settings page
- Redirects after inviting/adding users to groups
- Redirects & notifications after accepting/denying friend requests or unfriending
- The name plate in the top right header & small view header
- Online users sideblock
- Display of threaded personal messages

Change-Id: Ia43ae0867af12f6d78c0ad389fae25c58ac69b43
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent ffb144ad
......@@ -42,7 +42,7 @@ $authobj = AuthFactory::create($user->authinstance);
if (!$USER->is_admin_for_user($user)) {
$SESSION->add_error_msg(get_string('youcannotadministerthisuser', 'admin'));
redirect('/user/view.php?id=' . $id);
redirect(profile_url($user));
}
if ($user->deleted) {
......
......@@ -83,7 +83,7 @@ $form = pieform(array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('invite', 'group'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'user/view.php?id=' . $userid,
'goto' => profile_url($user),
)
),
));
......@@ -97,5 +97,5 @@ function invitetogroup_submit(Pieform $form, $values) {
global $SESSION, $USER, $group, $user;
group_invite_user($group, $user->id, $USER, isset($values['role']) ? $values['role'] : null);
$SESSION->add_ok_msg(get_string('userinvited', 'group'));
redirect('/user/view.php?id=' . $user->id);
redirect(profile_url($user));
}
......@@ -871,7 +871,7 @@ function get_user_for_display($user=null) {
$fields = array(
'id', 'username', 'preferredname', 'firstname', 'lastname', 'admin', 'staff',
'profileicon', 'email', 'deleted',
'profileicon', 'email', 'deleted', 'urlid',
);
if (is_numeric($user) && isset($usercache[$user])) {
......@@ -1461,6 +1461,52 @@ function get_new_profile_urlid($desired) {
return $newname;
}
/**
* Get the profile url for a user
*
* @param object $user
* @param boolean $full return a full url
* @param boolean $useid Override the cleanurls setting and use a view id in the link
*
* @return string
*/
function profile_url($user, $full=true, $useid=false) {
$wantclean = !$useid && get_config('cleanurls');
if ($user instanceof User) {
$id = $user->get('id');
$urlid = $wantclean ? $user->get('urlid') : null;
}
else if (is_array($user)) {
$id = $user['id'];
$urlid = $user['urlid'];
}
else if (is_numeric($user)) {
$id = $user;
$urlid = $wantclean ? get_user_for_display($id)->urlid : null;
}
else if (isset($user->id)) {
$id = $user->id;
$urlid = isset($user->urlid) ? $user->urlid : null;
}
if ($wantclean && !is_null($urlid)) {
$url = get_config('cleanurluserdefault') . '/' . $urlid;
}
else if (!empty($id)) {
$url = 'user/view.php?id=' . (int) $id;
}
else {
throw new SystemException("profile_url called with no user id");
}
if ($full) {
$url = get_config('wwwroot') . $url;
}
return $url;
}
/**
* used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display
* @param array $userids
......@@ -1789,7 +1835,7 @@ function acceptfriend_submit(Pieform $form, $values) {
if (is_friend($USER->get('id'), $user->id)) {
$SESSION->add_info_msg(get_string('alreadyfriends', 'group', display_name($user)));
delete_records('usr_friend_request', 'owner', $USER->get('id'), 'requester', $user->id);
redirect('/user/view.php?id=' . $user->id);
redirect(profile_url($user));
}
// friend db record
......@@ -1800,7 +1846,7 @@ function acceptfriend_submit(Pieform $form, $values) {
// notification info
$n = new StdClass;
$n->url = get_config('wwwroot') . 'user/view.php?id=' . $USER->get('id');
$n->url = profile_url($USER);
$n->users = array($user->id);
$lang = get_user_language($user->id);
$displayname = display_name($USER, $user);
......@@ -1816,7 +1862,7 @@ function acceptfriend_submit(Pieform $form, $values) {
handle_event('addfriend', array('user' => $f->usr2, 'friend' => $f->usr1));
$SESSION->add_ok_msg(get_string('friendformacceptsuccess', 'group'));
redirect('/user/view.php?id=' . $values['id']);
redirect(profile_url($user));
}
// Form to add someone who has friendscontrol set to 'auto'
......@@ -1866,7 +1912,7 @@ function addfriend_submit(Pieform $form, $values) {
if (is_friend($loggedinid, $user->id)) {
$SESSION->add_info_msg(get_string('alreadyfriends', 'group', display_name($user)));
delete_records('usr_friend_request', 'owner', $loggedinid, 'requester', $user->id);
redirect('/user/view.php?id=' . $user->id);
redirect(profile_url($user));
}
// friend db record
......@@ -1875,7 +1921,7 @@ function addfriend_submit(Pieform $form, $values) {
// notification info
$n = new StdClass;
$n->url = 'user/view.php?id=' . $loggedinid;
$n->url = profile_url($USER, false);
$n->users = array($user->id);
$lang = get_user_language($user->id);
$displayname = display_name($USER, $user);
......@@ -1898,7 +1944,7 @@ function addfriend_submit(Pieform $form, $values) {
handle_event('addfriend', array('user' => $f->usr2, 'friend' => $f->usr1));
$SESSION->add_ok_msg(get_string('friendformaddsuccess', 'group', display_name($user)));
redirect('/user/view.php?id=' . $values['id']);
redirect(profile_url($user));
}
/**
......
......@@ -17,8 +17,8 @@
<table class="fullwidth" id="useraccountsettingsleft">
<tr><td class="center">
<div id="profilepict">
<a href="{$WWWROOT}user/view.php?id={$user->id}"><img src="{profile_icon_url user=$user maxheight=100 maxwidth=100}" alt=""></a>
<div id="profilename"><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name}</a></div>
<a href="{profile_url($user)}"><img src="{profile_icon_url user=$user maxheight=100 maxwidth=100}" alt=""></a>
<div id="profilename"><a href="{profile_url($user)}">{$user|display_name}</a></div>
</div>
{if $loginas}
<div id="loginas"><a class="btn" href="{$WWWROOT}admin/users/changeuser.php?id={$user->id}">{str tag=loginas section=admin}</a></div>
......
<div id="header-right">
<div id="right-nav">
<ul>{strip}
{if $LOGGEDIN} <li class="identity"><a href="{$WWWROOT}user/view.php">{$USER|display_default_name}</a> | </li>{/if}
{if $LOGGEDIN} <li class="identity"><a href="{profile_url($USER)}">{$USER|display_default_name}</a> | </li>{/if}
{if $RIGHTNAV}
{foreach from=$RIGHTNAV item=item}
<li class="{$item.path}{if $item.selected}{assign var=MAINNAVSELECTED value=$item} selected{/if}"><a href="{if $item.wwwroot}{$item.wwwroot}{else}{$WWWROOT}{/if}{$item.url}">{if $item.title}{$item.title}{/if}{if $item.icon}<img src="{$item.icon}" alt="{$item.alt}">{if isset($item.count)}<span class="navcount{if $item.countclass} {$item.countclass}{/if}">{$item.count}</span>{/if}</a> | </li>
......
......@@ -3,7 +3,7 @@
<div class="sidebar-content">
<ul class="cr">
{foreach from=$sbdata.users item=user}
<li><a href="{$WWWROOT}user/view.php?id={$user->id}"><div class="profile-icon-container"><img src="{$user->profileiconurl}" alt=""></div>{$user|display_name}</a>{if $user->loggedinfrom} ({$user->loggedinfrom}){/if}</li>
<li><a href="{profile_url($user)}"><div class="profile-icon-container"><img src="{$user->profileiconurl}" alt=""></div>{$user|display_name}</a>{if $user->loggedinfrom} ({$user->loggedinfrom}){/if}</li>
{/foreach}
</ul>
<p id="allonline"><a href="{$WWWROOT}user/online.php">{str tag="allonline"}</a></p>
......
......@@ -11,9 +11,9 @@
<td>
<h5>
{if $message->from == $user->id}
<a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name}</a>
<a href="{profile_url($user)}">{$user|display_name}</a>
{else}
<a href="{$WWWROOT}user/view.php?id={$USER->id}">{$USER|display_name}</a>
<a href="{profile_url($USER)}">{$USER|display_name}</a>
{/if}
<span class="postedon">{$message->ctime|strtotime|format_date}</span>
</h5>
......
......@@ -2,7 +2,7 @@
<div class="fl">
<img src="{profile_icon_url user=$user maxwidth=50 maxheight=50}" alt="">
</div>
<h3><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name}</a></h3>
<h3><a href="{profile_url($user)}">{$user|display_name}</a></h3>
{if $user->introduction}
<p>{$user->introduction|clean_html|safe}</p>
{else}
......
......@@ -22,7 +22,7 @@
{if $LOGGEDIN}
<div id="mainnav-container" class="nav">
<div id="mainnav">
<strong><a href="{$WWWROOT}user/view.php">{$USER|display_name:null:true}</a>:</strong>
<strong><a href="{profile_url($USER)}">{$USER|display_name:null:true}</a>:</strong>
{foreach from=$MAINNAV item=item}
{if $item.path}
<a href="{$WWWROOT}{$item.url}">{$item.title}</a> |
......
......@@ -56,7 +56,7 @@ $form = pieform(array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('denyfriendrequestlower', 'group'), get_string('cancel')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'user/find.php' : ($returnto == 'view' ? 'user/view.php?id=' . $id : 'user/myfriends.php')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'user/find.php' : ($returnto == 'view' ? profile_url($user, false) : 'user/myfriends.php')),
)
)
));
......@@ -79,7 +79,7 @@ function denyrequest_submit(Pieform $form, $values) {
// notification info
$n = new StdClass;
$n->url = 'user/view.php?id=' . $loggedinid;
$n->url = profile_url($USER, false);
$n->users = array($user->id);
$lang = get_user_language($user->id);
$displayname = display_name($USER, $user);
......@@ -104,7 +104,7 @@ function denyrequest_submit(Pieform $form, $values) {
redirect('/user/find.php');
break;
case 'view':
redirect('/user/view.php?id=' . $id);
redirect(profile_url($user));
break;
default:
redirect('/user/myfriends.php');
......
......@@ -54,7 +54,7 @@ $form = pieform(array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('removefriend', 'group'), get_string('cancel')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'user/find.php' : ($returnto == 'view' ? 'user/view.php?id=' . $id : 'user/myfriends.php')),
'goto' => get_config('wwwroot') . ($returnto == 'find' ? 'user/find.php' : ($returnto == 'view' ? profile_url($user, false) : 'user/myfriends.php')),
)
)
));
......@@ -77,7 +77,7 @@ function removefriend_submit(Pieform $form, $values) {
// notification info
$n = new StdClass;
$n->url = 'user/view.php?id=' . $loggedinid;
$n->url = profile_url($USER, false);
$n->users = array($user->id);
$lang = get_user_language($user->id);
$displayname = display_name($USER, $user);
......@@ -104,7 +104,7 @@ function removefriend_submit(Pieform $form, $values) {
redirect('/user/find.php');
break;
case 'view':
redirect('/user/view.php?id=' . $id);
redirect(profile_url($user));
break;
default:
redirect('/user/myfriends.php');
......
......@@ -325,5 +325,5 @@ function addmember_submit(Pieform $form, $values) {
catch (SQLException $e) {
$SESSION->add_error_msg(get_string('adduserfailed', 'group'));
}
redirect('/user/view.php?id=' . $userid);
redirect(profile_url($adduser));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment