调用XOOPS中返回用户姓名时,通过getUnameFromId返回用户姓名时,如果希望返回用户真实姓名时,但是当用户没有填写真实姓名的时候返回的将会是空串,下面这个Hack就用于解决这个问题,当用户没有填写真实姓名时返回用户登录名。
htdocs\kernel\user.php文件,139行附近将getUnameFromId函数做如下修改即可:
原函数:
1: function getUnameFromId( $userid, $usereal = 0 )
2: {
3: $userid = intval($userid);
4: $usereal = intval($usereal);
5: if ($userid > 0) {
6: $member_handler =& xoops_gethandler('member');
7: $user =& $member_handler->getUser($userid);
8: if (is_object($user)) {
9: $ts =& MyTextSanitizer::getInstance();
10: if ( $usereal ) {
11: return $ts->htmlSpecialChars($user->getVar('name'));
12: } else {
13: return $ts->htmlSpecialChars($user->getVar('uname'));
14: }
15: }
16: }
17: return $GLOBALS['xoopsConfig']['anonymous'];
18: }
修改之后函数为:
1: function getUnameFromId( $userid, $usereal = 0 )
2: {
3: $userid = intval($userid);
4: $usereal = intval($usereal);
5: if ($userid > 0) {
6: $member_handler =& xoops_gethandler('member');
7: $user =& $member_handler->getUser($userid);
8: if (is_object($user)) {
9: $ts =& MyTextSanitizer::getInstance();
10: if ( $usereal ) {
11: if(trim($user->getVar('name')) != '') {
12: return $ts->htmlSpecialChars($user->getVar('name'));
13: } else {
14: return $ts->htmlSpecialChars($user->getVar('uname'));
15: }
16: } else {
17: return $ts->htmlSpecialChars($user->getVar('uname'));
18: }
19: }
20: }
21: return $GLOBALS['xoopsConfig']['anonymous'];
22: }