Commit 0d28fabc authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use profile_url when data is easy or inexpensive to fetch



Bug #1006634, part 3

In many places user urlids are not currently available when the
profile url is generated, but it is trivial to get it, and then change
the user/view.php url to a profile_url call:

- Admin page access report
- Profile links in feedback lists
- My friends block
- Wall posts
- Group members block
- Group members tab
- Recent forum posts block
- Group admin lists on forums page
- Group admin lists on my groups, find groups
- Group admin lists in group info block
- Profile sideblock
- My friends & find friends pages
- Institution landing page
- Online users page

Change-Id: I33e122896982037a887aad8e3362db450e123e3f
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 021d755b
......@@ -70,7 +70,7 @@ if (!$USER->get('admin') && !$USER->get('staff')) {
$users = get_records_sql_assoc('
SELECT
u.id, u.username, u.email, u.firstname, u.lastname, u.studentid, u.preferredname,
u.id, u.username, u.email, u.firstname, u.lastname, u.studentid, u.preferredname, u.urlid,
aru.remoteusername AS remoteuser
FROM {usr} u
LEFT JOIN {auth_remote_user} aru ON u.id = aru.localusr AND u.authinstance = aru.authinstance
......
......@@ -341,7 +341,7 @@ class ArtefactTypeComment extends ArtefactType {
a.id, a.author, a.authorname, a.ctime, a.mtime, a.description,
c.private, c.deletedby, c.requestpublic, c.rating,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon
u.deleted, u.profileicon, u.urlid
FROM {artefact} a
INNER JOIN {artefact_comment_comment} c ON a.id = c.artefact
LEFT JOIN {usr} u ON a.author = u.id
......@@ -494,6 +494,7 @@ class ArtefactTypeComment extends ArtefactType {
'admin' => $item->admin,
'deleted' => $item->deleted,
'profileicon' => $item->profileicon,
'profileurl' => profile_url($item),
);
}
}
......
......@@ -13,10 +13,10 @@
</div>
<div class="details commentleft">
{if $item->author}
<div class="icon"><a href="{$WWWROOT}user/view.php?id={$item->author->id}">
<div class="icon"><a href="{$item->author->profileurl}">
<img src="{profile_icon_url user=$item->author maxheight=40 maxwidth=40}" valign="middle" alt="{$item->author|display_name}">
</a><br />
<a href="{$WWWROOT}user/view.php?id={$item->author->id}" class="username">{$item->author|display_name}</a></div>
<a href="{$item->author->profileurl}" class="username">{$item->author|display_name}</a></div>
{else}
{$item->authorname}
{/if}
......
{foreach from=$groupmembers item=groupmember}
<div class="{cycle values='d0,d1'} friendcell center">
<a href="{$WWWROOT}user/view.php?id={$groupmember['id']}">
<a href="{profile_url($groupmember)}">
<img src="{profile_icon_url user=$groupmember maxwidth=60 maxheight=60}" alt="" title="{$groupmember|display_default_name|escape}">
</a>
<div class="membername"><a href="{$WWWROOT}user/view.php?id={$groupmember['id']}">{$groupmember|display_default_name|escape}</a></div>
<div class="membername"><a href="{profile_url($groupmember)}">{$groupmember|display_default_name|escape}</a></div>
</div>
{/foreach}
{foreach from=$friends item=row}
{foreach from=$row item=friend}
<div class="{cycle values='d0,d1'} friendcell">
<a href="{$WWWROOT}user/view.php?id={$friend->id}">
<a href="{profile_url($friend)}">
<img src="{profile_icon_url user=$friend maxwidth=60 maxheight=60}" alt="">
</a>
<div><a href="{$WWWROOT}user/view.php?id={$friend->id}">{$friend|display_default_name|escape}</a></div>
<div><a href="{profile_url($friend)}">{$friend|display_default_name|escape}</a></div>
</div>
{/foreach}
{/foreach}
......
......@@ -84,7 +84,7 @@ class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
$foruminfo = get_records_sql_array('
SELECT
p.id, p.subject, p.body, p.poster, p.topic, t.forum, pt.subject AS topicname,
u.firstname, u.lastname, u.username, u.preferredname, u.email, u.profileicon, u.admin, u.staff, u.deleted
u.firstname, u.lastname, u.username, u.preferredname, u.email, u.profileicon, u.admin, u.staff, u.deleted, u.urlid
FROM
{interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic)
......@@ -104,7 +104,7 @@ class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
if ($foruminfo) {
$userfields = array(
'firstname', 'lastname', 'username', 'preferredname', 'email', 'profileicon',
'admin', 'staff', 'deleted'
'admin', 'staff', 'deleted', 'urlid',
);
foreach ($foruminfo as $f) {
$f->author = (object) array('id' => $f->poster);
......
......@@ -3,7 +3,7 @@
{foreach from=$foruminfo item=postinfo}
<tr class="{cycle values='r0,r1'}">
<td><h4><a href="{$WWWROOT}interaction/forum/topic.php?id={$postinfo->topic|escape}#post{$postinfo->id}">{$postinfo->topicname}</a></h4><div class="s">{$postinfo->body|str_shorten_html:100:true|safe}</div></td>
<td class="valign s right"><a href="{$WWWROOT}user/view.php?id={$postinfo->poster}"><img src="{profile_icon_url user=$postinfo->author maxheight=16 maxwidth=16}" alt=""> {$postinfo->author|display_name}</a>
<td class="valign s right"><a href="{profile_url($postinfo->author)}"><img src="{profile_icon_url user=$postinfo->author maxheight=16 maxwidth=16}" alt=""> {$postinfo->author|display_name}</a>
</td>
</tr>
{/foreach}
......
......@@ -5,7 +5,7 @@
<tr class="{cycle values='r0,r1'}">
<td><strong><a href="{$WWWROOT}interaction/forum/topic.php?id={$postinfo->topic}#post{$postinfo->id}">{$postinfo->topicname}</a></strong><br />
<div class="s">{$postinfo->body|str_shorten_html:100:true|safe}</div></td>
<td class="valign s center"><a href="{$WWWROOT}user/view.php?id={$postinfo->poster}"><img src="{profile_icon_url user=$postinfo->author maxheight=20 maxwidth=20}" alt=""><br />{$postinfo->author|display_name}</a></td>
<td class="valign s center"><a href="{profile_url($postinfo->author)}"><img src="{profile_icon_url user=$postinfo->author maxheight=20 maxwidth=20}" alt=""><br />{$postinfo->author|display_name}</a></td>
</tr>
{/foreach}
</table>
......
......@@ -48,7 +48,7 @@ if (!PluginBlocktypeWall::can_delete_wallpost($wallpost->from, $owner)) {
$goto = get_config('wwwroot');
$goto .= ($return == 'wall')
? '/blocktype/wall/wall.php?id=' . $instance->get('id')
: '/user/view.php?id=' . $owner;
: profile_url($owner);
$form = pieform(array(
'name' => 'deletepost',
......
......@@ -233,7 +233,7 @@ EOF;
'message' => get_string('addpostsuccess', 'blocktype.wall'),
'posts' => $renderedposts,
'block' => $values['instance'],
'goto' => '/user/view.php?id=' . $owner,
'goto' => profile_url($owner),
));
}
......@@ -248,7 +248,7 @@ EOF;
// avoid confusion in the templates
$sql = '
SELECT bwp.id AS postid, bwp.instance, bwp.from, bwp.replyto, bwp.private, bwp.postdate, bwp.text,' . db_format_tsfield('postdate') . ',
u.id, u.id AS userid, u.username, u.firstname, u.lastname, u.preferredname, u.staff, u.admin, u.email, u.profileicon
u.id, u.id AS userid, u.username, u.firstname, u.lastname, u.preferredname, u.staff, u.admin, u.email, u.profileicon, u.urlid
FROM {blocktype_wall_post} bwp
JOIN {usr} u ON bwp.from = u.id
WHERE bwp.instance = ? AND u.deleted = 0
......@@ -263,6 +263,7 @@ EOF;
create_function(
'$item',
'$item->displayname = display_name($item);
$item->profileurl = profile_url($item);
$item->deletable = PluginBlocktypeWall::can_delete_wallpost($item->from, ' . intval($owner) .');
return $item;'),
$records
......
......@@ -8,7 +8,7 @@
{if $wallpost->deletable}
<a href="{$WWWROOT}blocktype/wall/deletepost.php?postid={$wallpost->postid}&return={if $wholewall}wall{else}profile{/if}" class="wallpostdelete">{str tag='delete' section='blocktype.wall'}</a>
{/if}
<div class="userinfo"><img src="{profile_icon_url user=$wallpost maxheight=25 maxwidth=25}" alt="Profile Picture"><a href="{$WWWROOT}user/view.php?id={$wallpost->userid}">{$wallpost->displayname}</a><span class="postedon"> - {$wallpost->postdate|format_date}</span></div>
<div class="userinfo"><img src="{profile_icon_url user=$wallpost maxheight=25 maxwidth=25}" alt="Profile Picture"><a href="{$wallpost->profileurl}">{$wallpost->displayname}</a><span class="postedon"> - {$wallpost->postdate|format_date}</span></div>
<div class="text">{$wallpost->text|parse_bbcode|safe}</div>
<div class="controls">
{* {if $ownwall}
......
{include file="header.tpl"}
<h2>{$owner->displayname}: {str tag='wall' section='blocktype.wall'}</h2>
<div class="rbuttons"><a href="{$WWWROOT}/user/view.php?id={$owner->id}" class="btn">{str tag='backtoprofile' section='blocktype.wall'}</a></div>
<div class="rbuttons"><a href="{profile_url($owner)}" class="btn">{str tag='backtoprofile' section='blocktype.wall'}</a></div>
{include file="blocktype:wall:inlineposts.tpl"}
......
......@@ -51,7 +51,7 @@
<label>{str tag="groupadminlist" section="interaction.forum"}</label>
{foreach from=$groupadmins item=groupadmin}
<span class="inlinelist">
<a href="{$WWWROOT}user/view.php?id={$groupadmin->id}" class="groupadmin"><img src="{profile_icon_url user=$groupadmin maxheight=20 maxwidth=20}" alt=""> {$groupadmin|display_name}</a>
<a href="{profile_url($groupadmin)}" class="groupadmin"><img src="{profile_icon_url user=$groupadmin maxheight=20 maxwidth=20}" alt=""> {$groupadmin|display_name}</a>
</span>
{/foreach}
</div>
......
......@@ -525,7 +525,7 @@ class ActivityTypeContactus extends ActivityTypeAdmin {
function __construct($data, $cron=false) {
parent::__construct($data, $cron);
if (!empty($this->fromuser)) {
$this->url = 'user/view.php?id=' . $this->fromuser;
$this->url = profile_url($this->fromuser, false);
}
else {
$this->customheaders = array(
......@@ -611,7 +611,7 @@ class ActivityTypeObjectionable extends ActivityTypeAdmin {
}
public function get_emailmessage($user) {
$reporterurl = get_config('wwwroot') . 'user/view.php?id=' . $this->reporter;
$reporterurl = profile_url($this->reporter);
$ctime = strftime(get_string_from_language($user->lang, 'strftimedaydatetime'), $this->ctime);
if (empty($this->artefact)) {
return get_string_from_language(
......@@ -632,7 +632,7 @@ class ActivityTypeObjectionable extends ActivityTypeAdmin {
public function get_htmlmessage($user) {
$viewtitle = hsc($this->view->get('title'));
$reportername = hsc(display_default_name($this->reporter));
$reporterurl = get_config('wwwroot') . 'user/view.php?id=' . $this->reporter;
$reporterurl = profile_url($this->reporter);
$ctime = strftime(get_string_from_language($user->lang, 'strftimedaydatetime'), $this->ctime);
$message = hsc($this->message);
if (empty($this->artefact)) {
......
......@@ -1306,7 +1306,7 @@ function group_get_admins($groupids) {
}
$groupadmins = get_records_sql_array('
SELECT m.group, m.member, u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.profileicon
SELECT m.group, m.member, u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.profileicon, u.urlid
FROM {group_member} m JOIN {usr} u ON u.id = m.member
WHERE m.group IN (' . implode(',', db_array_to_ph($groupids)) . ")
AND m.role = 'admin'",
......
......@@ -2416,6 +2416,7 @@ function profile_sideblock() {
'id' => $USER->get('id'),
'myname' => display_name($USER, null, true),
'username' => $USER->get('username'),
'url' => profile_url($USER),
);
$authinstance = $SESSION->get('mnetuser') ? $SESSION->get('authinstance') : $USER->get('authinstance');
......
......@@ -1518,7 +1518,7 @@ function get_users_data($userids, $getviews=true) {
$userids = array_map('intval', $userids);
$sql = 'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
u.profileicon, u.email,
u.profileicon, u.email, u.urlid,
fp.requester AS pending,
ap.value AS hidenamepref,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
......@@ -2375,11 +2375,11 @@ function get_friends($userid, $limit=10, $offset=0) {
$result = array('count' => 0, 'limit' => $limit, 'offset' => $offset, 'data' => false);
$from = 'FROM (
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff, u.profileicon
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff, u.profileicon, u.urlid
FROM {usr} u JOIN {usr_friend} f ON u.id = f.usr1
WHERE f.usr2 = ? AND u.deleted = 0
UNION
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff, u.profileicon
SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff, u.profileicon, u.urlid
FROM {usr} u JOIN {usr_friend} f ON u.id = f.usr2
WHERE f.usr1 = ? AND u.deleted = 0
) f';
......
......@@ -2943,7 +2943,7 @@ function display_cleaned_html($html, $filename, $params) {
$smarty = smarty_core();
$smarty->assign('params', $params);
if ($params['owner']) {
$smarty->assign('htmlremovedmessage', get_string('htmlremovedmessage', 'artefact.file', hsc($filename), get_config('wwwroot') . 'user/view.php?id=' . (int) $params['owner'], hsc(display_name($params['owner']))));
$smarty->assign('htmlremovedmessage', get_string('htmlremovedmessage', 'artefact.file', hsc($filename), profile_url((int) $params['owner']), hsc(display_name($params['owner']))));
} else {
$smarty->assign('htmlremovedmessage', get_string('htmlremovedmessagenoowner', 'artefact.file', hsc($filename)));
}
......
......@@ -471,7 +471,7 @@ class PluginSearchInternal extends PluginSearch {
if ($membershiptype == 'nonmember') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon, u.staff';
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon, u.staff, u.urlid';
$from = '
FROM {usr} u
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = \'hiderealname\')
......@@ -482,7 +482,7 @@ class PluginSearchInternal extends PluginSearch {
}
else if ($membershiptype == 'notinvited') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon, u.staff';
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon, u.staff, u.urlid';
$from = '
FROM {usr} u
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = \'hiderealname\')
......@@ -496,7 +496,7 @@ class PluginSearchInternal extends PluginSearch {
else if ($membershiptype == 'request') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon,
u.staff, ' . db_format_tsfield('gm.ctime', 'jointime');
u.staff, u.urlid, ' . db_format_tsfield('gm.ctime', 'jointime');
$from = '
FROM {usr} u
INNER JOIN {group_member_request} gm ON (gm.member = u.id)
......@@ -512,7 +512,7 @@ class PluginSearchInternal extends PluginSearch {
else if ($membershiptype == 'invite') {
$select = '
u.id, u.firstname, u.lastname, u.username, u.email, u.profileicon,
u.staff, ' . db_format_tsfield('gm.ctime', 'jointime');
u.staff, u.urlid, ' . db_format_tsfield('gm.ctime', 'jointime');
$from = '
FROM {usr} u
INNER JOIN {group_member_invite} gm ON (gm.member = u.id)
......@@ -525,7 +525,7 @@ class PluginSearchInternal extends PluginSearch {
else { // All group members
$select = '
u.id, u.firstname, u.lastname, u.username, u.preferredname, u.email, u.profileicon,
u.staff, ' . db_format_tsfield('gm.ctime', 'jointime') . ', gm.role';
u.staff, u.urlid, ' . db_format_tsfield('gm.ctime', 'jointime') . ', gm.role';
$from = '
FROM {usr} u
INNER JOIN {group_member} gm ON (gm.member = u.id)
......
......@@ -10,20 +10,20 @@
{foreach from=$users item=user}
{if !$user->views && !$user->collections}
<tr class="{cycle values='r0,r1'}">
<td><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name:null:true:true}</a></td>
<td><a href="{profile_url($user)}">{$user|display_name:null:true:true}</a></td>
<td colspan=3>{str tag=noviews section=view}</td>
</tr>
{else}
{foreach from=$user->views item=item}
<tr class="{cycle values='r0,r1'}">
<td><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name:null:true:true}</a></td>
<td><a href="{profile_url($user)}">{$user|display_name:null:true:true}</a></td>
<td><a href="{$item.url}">{$item.name|str_shorten_text:50:true}</a></td>
<td>{include file="admin/users/accesslistitem.tpl" item=$item}</td>
</tr>
{/foreach}
{foreach from=$user->collections item=item}
<tr class="{cycle values='r0,r1'}">
<td><a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name:null:true:true}</a></td>
<td><a href="{profile_url($user)}">{$user|display_name:null:true:true}</a></td>
<td><a href="{$item.views[$item.viewid].url}">{$item.name|str_shorten_text:40:true}</a> ({str tag=nviews section=view arg1=count($item.views)})</td>
<td>{include file="admin/users/accesslistitem.tpl" item=$item}</td>
</tr>
......
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