-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.php
59 lines (51 loc) · 1.29 KB
/
helper.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
<?php
/**
* @package PlgUserCMAvatar
* @copyright Copyright (C) 2015 CMExtension Team http://www.cmext.vn/
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
/**
* Helper for plg_user_cmavatar plugin.
*
* @package PlgUserCMAvatar
* @since 1.0.0
*/
class PlgUserCMAvatarHelper
{
/**
* Get user's avatar.
*
* @param integer $userId The ID of the user.
*
* @return string The path to the avatar's file.
*
* @since 1.0.0
*/
public static function getAvatar($userId)
{
$profileKey = 'cmavatar';
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('profile_value'))
->from($db->qn('#__user_profiles'))
->where($db->qn('user_id') . ' = ' . $db->q((int) $userId))
->where($db->qn('profile_key') . ' = ' . $db->quote($profileKey));
$avatar = $db->setQuery($query)->loadResult();
// Check for a database error.
if ($error = $db->getErrorMsg())
{
throw new RuntimeException($error);
return false;
}
if (!empty($avatar))
{
$extension = 'jpg';
$plugin = JPluginHelper::getPlugin('user', 'cmavatar');
$params = new JRegistry($plugin->params);
$folder = $params->get('folder', '');
$avatar = JPath::clean($folder . '/' . $avatar . '.' . $extension);
}
return $avatar;
}
}