1: | <?php |
2: | /* |
3: | * You may not change or alter any portion of this comment or credits |
4: | * of supporting developers from this source code or any supporting source code |
5: | * which is considered copyrighted (c) material of the original comment or credit authors. |
6: | * |
7: | * This program is distributed in the hope that it will be useful, |
8: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10: | */ |
11: | |
12: | /** |
13: | * @copyright 2000-2020 XOOPS Project https://xoops.org/ |
14: | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
15: | * @author XOOPS Development Team |
16: | */ |
17: | |
18: | /* |
19: | * Smarty plugin |
20: | * ------------------------------------------------------------- |
21: | * Type: function |
22: | * Name: xoUserInfo |
23: | * Version: 1.0 |
24: | * Author: DuGris |
25: | * Purpose: Get data for a specified user id and assign it to a template variable. |
26: | * For the input uid, return an array of related information, specifically |
27: | * these fields from the users table: |
28: | * uname,name,email,user_avatar,url,posts,user_from,user_occ,user_intrest,bio,user_sig |
29: | * Input: uid = uid of user for which information is requested |
30: | * assign = smarty variable to be initialized for the template. default 'userInfo' |
31: | * |
32: | * Example: |
33: | * Get user data |
34: | * <{xoUserInfo uid=42 assign=memberInfo}> |
35: | * ------------------------------------------------------------- |
36: | */ |
37: | |
38: | /** |
39: | * @param $params |
40: | * @param $smarty |
41: | */ |
42: | function smarty_function_xoUserInfo($params, &$smarty) |
43: | { |
44: | global $xoopsUser, $xoopsConfig; |
45: | |
46: | /** @var array $usersInfo uid indexed cache of user data */ |
47: | static $usersInfo = array(); |
48: | |
49: | $uid = 0; |
50: | if (!empty($params['uid'])) { |
51: | $uid = (int)$params['uid']; |
52: | } elseif (isset($xoopsUser) && is_object($xoopsUser)) { |
53: | $uid = $xoopsUser->getVar('uid'); |
54: | } |
55: | |
56: | $assign = empty($params['assign']) ? 'userInfo' : $params['assign']; |
57: | |
58: | $infoFields = array( |
59: | 'uname', 'name', 'email', 'user_avatar', 'url', 'posts', |
60: | 'user_from', 'user_occ', 'user_intrest', 'bio', 'user_sig' |
61: | ); |
62: | |
63: | if (!isset($usersInfo[0])) { |
64: | $usersInfo[0] = array('uname' => $xoopsConfig['anonymous']); |
65: | } |
66: | |
67: | $userHandler = xoops_getHandler('user'); |
68: | if (isset($usersInfo[$uid])) { |
69: | $userData = $usersInfo[$uid]; |
70: | } elseif ($userObject = $userHandler->get($uid)) { |
71: | $userData = array(); |
72: | foreach ($infoFields as $field) { |
73: | $userData[$field] = $userObject->getVar($field, 'E'); |
74: | } |
75: | $usersInfo[$uid] = $userData; |
76: | } else { |
77: | $userData = $usersInfo[0]; |
78: | } |
79: | $smarty->assign($assign, $userData); |
80: | } |
81: |