/
Avatar.class.php
110 lines (95 loc) · 3.25 KB
/
Avatar.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Avatar class.
* @copyright Copyright 2014 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
* @package MantisBT
*/
/**
* Avatar class
*
* @package MantisBT
* @subpackage classes
*/
require_api( 'access_api.php' );
require_api( 'user_api.php' );
/**
* A class that represents information about a user's avatar.
*/
class Avatar
{
public $image = null;
public $link = null;
public $text = null;
/**
* Gets the avatar information for the user. The avatars are provided by
* plugins that can integrate with a variety of services like gravatar.com,
* LDAP, Social Identities, etc.
*
* If logged in user doesn't have access to view avatars or not avatar is found,
* then a default avatar will be used.
*
* Note that the provided user id may no longer has a corresponding user in the
* system, if the user was deleted.
*
* @param integer $p_user_id The user id.
* @param integer $p_size The desired width/height of the avatar.
*
* @return array The array with avatar information.
*/
public static function get( $p_user_id, $p_size = 80 ) {
$t_enabled = config_get( 'show_avatar' ) !== OFF &&
access_has_project_level( config_get( 'show_avatar_threshold' ) );
$t_avatar = null;
if ( $t_enabled ) {
$t_avatar = event_signal(
'EVENT_USER_AVATAR',
array( $p_user_id, $p_size ) );
if( $t_avatar === null ) {
$t_avatar = new Avatar();
}
$t_avatar->normalize( $p_user_id );
}
return $t_avatar;
}
/**
* A method that is called on the Avatar object after it is populated by
* the plugins to make sure that all fields are validated correctly,
* missing values are defaulted, and match the expectations of the MantisBT
* core.
*
* @param integer $p_user_id The user id.
*
* @return void
*/
private function normalize( $p_user_id ) {
$t_user_exists = user_exists( $p_user_id );
if( $this->image === null) {
$this->image = config_get_global( 'path' ) . 'images/avatar.png';
}
if( $this->link === null ) {
if ( $t_user_exists ) {
$this->link = config_get_global( 'path' ) .
'view_user_page.php?id=' . $p_user_id;
} else {
$this->link = '';
}
}
if( $this->text === null ) {
$this->text = $t_user_exists ? user_get_name( $p_user_id ) : '';
}
}
}