Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
bb9ece16
Commit
bb9ece16
authored
Mar 11, 2010
by
Richard Mansfield
Browse files
Prefetch profileicon ids on user search page & avoid redirect to gravatar
Signed-off-by:
Richard Mansfield
<
richardm@catalyst.net.nz
>
parent
e9e1969e
Changes
6
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/dwoo/mahara/plugins/function.profile_icon_url.php
0 → 100644
View file @
bb9ece16
<?php
/**
* Dwoo {profile_icon_url} function plugin
*
* Type: function<br>
* Date: June 22, 2006<br>
* Purpose: Display a user's profile icon according to mahara rules
* @author Catalyst IT Ltd
* @version 1.0
*/
function
Dwoo_Plugin_profile_icon_url
(
Dwoo
$dwoo
,
$user
,
$maxwidth
,
$maxheight
)
{
return
profile_icon_url
(
$user
,
$maxwidth
,
$maxheight
);
}
?>
htdocs/lib/searchlib.php
View file @
bb9ece16
...
...
@@ -291,7 +291,7 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
$cols
=
array
(
'icon'
=>
array
(
'name'
=>
''
,
'template'
=>
'<img src="
'
.
get_config
(
'wwwroot'
)
.
'thumb.php?type=
profileicon
&
maxwidth=40
&
maxheight=40
&id={$r.id
}" alt="'
.
get_string
(
'profileimage'
)
.
'" />'
,
'template'
=>
'<img src="
{
profile
_
icon
_url user=$r
maxwidth=40
maxheight=40}" alt="'
.
get_string
(
'profileimage'
)
.
'" />'
,
'class'
=>
'center'
),
'firstname'
=>
array
(
'name'
=>
get_string
(
'firstname'
)),
'lastname'
=>
array
(
'name'
=>
get_string
(
'lastname'
)),
...
...
htdocs/lib/user.php
View file @
bb9ece16
...
...
@@ -1238,6 +1238,7 @@ function get_new_username($desired) {
function
get_users_data
(
$userlist
,
$getviews
=
true
)
{
global
$USER
;
$sql
=
'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
u.profileicon, u.email,
0 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,
COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol,
...
...
@@ -1250,6 +1251,7 @@ function get_users_data($userlist, $getviews=true) {
WHERE u.id IN ('
.
$userlist
.
')
UNION
SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
u.profileicon, u.email,
1 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,
NULL AS friendscontrol,
...
...
@@ -1669,4 +1671,52 @@ function install_system_profile_view() {
}
/**
* Return profile icon url for a user
*/
function
profile_icon_url
(
$user
,
$maxwidth
=
40
,
$maxheight
=
40
)
{
if
(
is_array
(
$user
))
{
$user
=
(
object
)
$user
;
}
if
(
!
property_exists
(
$user
,
'profileicon'
)
||
!
property_exists
(
$user
,
'email'
))
{
throw
new
SystemException
(
'profile_icon_url requires a user with profileicon & email properties'
);
}
$thumb
=
get_config
(
'wwwroot'
)
.
'thumb.php'
;
$sizeparams
=
'maxwidth='
.
$maxwidth
.
'&maxheight='
.
$maxheight
;
$notfound
=
$thumb
.
'?type=profileiconbyid&'
.
$sizeparams
.
'&id=0'
;
if
(
!
empty
(
$user
->
profileicon
))
{
return
$thumb
.
'?type=profileiconbyid&'
.
$sizeparams
.
'&id='
.
$user
->
profileicon
;
}
else
if
(
get_config
(
'remoteavatars'
))
{
return
gravatar_icon
(
$user
->
email
,
array
(
'maxw'
=>
$maxwidth
,
'maxh'
=>
$maxheight
),
$notfound
);
}
return
$notfound
;
}
/**
* Return a Gravatar URL if one exists for the given user.
*
* @param string $email Email address of the user
* @param object $size Maximum size of the image
* @param boolean $notfound
*
* @returns string The URL of the image or FALSE if none was found
*/
function
gravatar_icon
(
$email
,
$size
,
$notfound
)
{
if
(
!
get_config
(
'remoteavatars'
))
{
return
false
;
}
require_once
(
'file.php'
);
$md5sum
=
md5
(
strtolower
(
$email
));
$s
=
100
;
$newsize
=
image_get_new_dimensions
(
$s
,
$s
,
$size
);
if
(
$newsize
)
{
$s
=
min
(
$newsize
[
'w'
],
$newsize
[
'h'
]);
}
return
"http://www.gravatar.com/avatar/
{
$md5sum
}
.jpg?r=g&s=
$s
&d="
.
urlencode
(
$notfound
);
}
?>
htdocs/search/internal/lib.php
View file @
bb9ece16
...
...
@@ -285,7 +285,7 @@ class PluginSearchInternal extends PluginSearch {
if
(
$count
>
0
)
{
$data
=
get_records_sql_assoc
(
'
SELECT
u.id, u.firstname, u.lastname, u.username, u.email, u.staff,
u.id, u.firstname, u.lastname, u.username, u.email, u.staff,
u.profileicon,
u.active, NOT u.suspendedcusr IS NULL as suspended
FROM
{usr} u '
.
$institutionsearch
.
$where
.
'
...
...
htdocs/theme/raw/templates/user/user.tpl
View file @
bb9ece16
...
...
@@ -17,7 +17,7 @@
{/
if
}
</ul>
<div
class=
"leftdiv"
id=
"friendinfo_
{
$user
->
id
}
"
>
<img
src=
"
{
$WWWROOT
}
thumb.php?type=
profileicon
&
maxwidth=40
&
maxheight=40
&id=
{
$user
->
id
}
"
alt=
""
>
<img
src=
"
{
profile
_
icon
_url
user
=
$user
maxwidth
=
40
maxheight
=
40
}
"
alt=
""
>
</div>
<div
class=
"rightdiv"
>
<h3>
...
...
@@ -55,7 +55,7 @@
</li>
</ul>
<div
class=
"leftdiv"
id=
"friendinfo_
{
$user
->
id
}
"
>
<img
src=
"
{
$WWWROOT
}
thumb.php?type=
profileicon
&
maxwidth=40
&
maxheight=40
&id=
{
$user
->
id
}
"
alt=
""
>
<img
src=
"
{
profile
_
icon
_url
user
=
$user
maxwidth
=
40
maxheight
=
40
}
"
alt=
""
>
</div>
<div
class=
"rightdiv"
>
<h3>
...
...
@@ -105,7 +105,7 @@
</li>
</ul>
<div
class=
"leftdiv"
id=
"friendinfo_
{
$user
->
id
}
"
>
<img
src=
"
{
$WWWROOT
}
thumb.php?type=
profileicon
&
maxwidth=40
&
maxheight=40
&id=
{
$user
->
id
}
"
alt=
""
>
<img
src=
"
{
profile
_
icon
_url
user
=
$user
maxwidth
=
40
maxheight
=
40
}
"
alt=
""
>
</div>
<div
class=
"rightdiv"
>
<h3>
...
...
@@ -142,7 +142,7 @@
</li>
</ul>
<div
class=
"leftdiv"
id=
"friendinfo_
{
$user
->
id
}
"
>
<img
src=
"
{
$WWWROOT
}
thumb.php?type=
profileicon
&
maxwidth=40
&
maxheight=40
&id=
{
$user
->
id
}
"
alt=
""
>
<img
src=
"
{
profile
_
icon
_url
user
=
$user
maxwidth
=
40
maxheight
=
40
}
"
alt=
""
>
</div>
<div
class=
"rightdiv"
>
<h3>
...
...
htdocs/thumb.php
View file @
bb9ece16
...
...
@@ -30,6 +30,7 @@ define('PUBLIC', 1);
define
(
'NOCHECKPASSWORDCHANGE'
,
1
);
require
(
'init.php'
);
require_once
(
'file.php'
);
require_once
(
'user.php'
);
$type
=
param_alpha
(
'type'
);
...
...
@@ -178,27 +179,3 @@ switch ($type) {
break
;
}
/**
* Return a Gravatar URL if one exists for the given user.
*
* @param string $email Email address of the user
* @param object $size Maximum size of the image
* @param boolean $notfound
*
* @returns string The URL of the image or FALSE if none was found
*/
function
gravatar_icon
(
$email
,
$size
,
$notfound
)
{
if
(
!
get_config
(
'remoteavatars'
))
{
return
false
;
}
$md5sum
=
md5
(
strtolower
(
$email
));
$s
=
100
;
$newsize
=
image_get_new_dimensions
(
$s
,
$s
,
$size
);
if
(
$newsize
)
{
$s
=
min
(
$newsize
[
'w'
],
$newsize
[
'h'
]);
}
return
"http://www.gravatar.com/avatar/
{
$md5sum
}
.jpg?r=g&s=
$s
&d="
.
urlencode
(
$notfound
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment