|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
9
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
10
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
11
|
|
|
* @since 4.00 |
|
12
|
|
|
* @package module::newbb |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
\defined('NEWBB_FUNCTIONS_INI') || require $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php'); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param $RPG |
|
21
|
|
|
* @param $RPGDIFF |
|
22
|
|
|
* @return array|number |
|
23
|
|
|
*/ |
|
24
|
|
|
function newbb_calculateLevel($RPG, $RPGDIFF) |
|
25
|
|
|
{ |
|
26
|
|
|
//$RPG = $user->getVar('posts'); |
|
27
|
|
|
//$RPGDIFF = $user->getVar('user_regdate'); |
|
28
|
|
|
|
|
29
|
|
|
$today = \time(); |
|
30
|
|
|
$diff = $today - $RPGDIFF; |
|
31
|
|
|
$exp = \round($diff / 86400, 0); |
|
32
|
|
|
if ($exp <= 0) { |
|
33
|
|
|
$exp = 1; |
|
34
|
|
|
} |
|
35
|
|
|
$ppd = \round($RPG / $exp, 0); |
|
36
|
|
|
$level = \pow(\log10($RPG), 3); |
|
37
|
|
|
$ep = \floor(100 * ($level - \floor($level))); |
|
38
|
|
|
$showlevel = \floor($level + 1); |
|
39
|
|
|
$hpmulti = \round($ppd / 6, 1); |
|
40
|
|
|
if ($hpmulti > 1.5) { |
|
41
|
|
|
$hpmulti = 1.5; |
|
42
|
|
|
} |
|
43
|
|
|
if ($hpmulti < 1) { |
|
44
|
|
|
$hpmulti = 1; |
|
45
|
|
|
} |
|
46
|
|
|
$maxhp = $level * 25 * $hpmulti; |
|
47
|
|
|
$hp = $ppd / 5; |
|
48
|
|
|
if ($hp >= 1) { |
|
49
|
|
|
$hp = $maxhp; |
|
50
|
|
|
} else { |
|
51
|
|
|
$hp = \floor($hp * $maxhp); |
|
52
|
|
|
} |
|
53
|
|
|
$hp = \floor($hp); |
|
54
|
|
|
$maxhp = \floor($maxhp); |
|
55
|
|
|
$zhp = $maxhp; |
|
56
|
|
|
if ($maxhp <= 0) { |
|
57
|
|
|
$zhp = 1; |
|
58
|
|
|
} |
|
59
|
|
|
$hpf = \floor(100 * ($hp / $zhp)) - 1; |
|
60
|
|
|
$maxmp = ($exp * $level) / 5; |
|
61
|
|
|
$mp = $RPG / 3; |
|
62
|
|
|
if ($mp >= $maxmp) { |
|
63
|
|
|
$mp = $maxmp; |
|
64
|
|
|
} |
|
65
|
|
|
$maxmp = \floor($maxmp); |
|
66
|
|
|
$mp = \floor($mp); |
|
67
|
|
|
$zmp = $maxmp; |
|
68
|
|
|
if ($maxmp <= 0) { |
|
69
|
|
|
$zmp = 1; |
|
70
|
|
|
} |
|
71
|
|
|
$mpf = \floor(100 * ($mp / $zmp)) - 1; |
|
72
|
|
|
if ($hpf >= 98) { |
|
73
|
|
|
$hpf -= 2; |
|
74
|
|
|
} |
|
75
|
|
|
if ($ep >= 98) { |
|
76
|
|
|
$ep -= 2; |
|
77
|
|
|
} |
|
78
|
|
|
if ($mpf >= 98) { |
|
79
|
|
|
$mpf -= 2; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$level = []; |
|
83
|
|
|
$level['level'] = $showlevel; |
|
84
|
|
|
$level['exp'] = $ep; |
|
85
|
|
|
$level['exp_width'] = $ep . '%'; |
|
86
|
|
|
$level['hp'] = $hp; |
|
87
|
|
|
$level['hp_max'] = $maxhp; |
|
88
|
|
|
$level['hp_width'] = $hpf . '%'; |
|
89
|
|
|
$level['mp'] = $mp; |
|
90
|
|
|
$level['mp_max'] = $maxmp; |
|
91
|
|
|
$level['mp_width'] = $mpf . '%'; |
|
92
|
|
|
|
|
93
|
|
|
return $level; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Class User |
|
98
|
|
|
*/ |
|
99
|
|
|
class User |
|
100
|
|
|
{ |
|
101
|
|
|
public $user; |
|
102
|
|
|
|
|
103
|
|
|
public function __construct() |
|
104
|
|
|
{ |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return array |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getUserbar() |
|
111
|
|
|
{ |
|
112
|
|
|
global $isAdmin; |
|
113
|
|
|
|
|
114
|
|
|
$userbar = []; |
|
115
|
|
|
if (empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
116
|
|
|
return $userbar; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$user = $this->user; |
|
120
|
|
|
$userbar['profile'] = [ |
|
121
|
|
|
'link' => XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid'), |
|
122
|
|
|
'name' => _PROFILE, |
|
123
|
|
|
]; |
|
124
|
|
|
|
|
125
|
|
|
if (\is_object($GLOBALS['xoopsUser'])) { |
|
126
|
|
|
$userbar['pm'] = [ |
|
127
|
|
|
'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&to_userid=' . $user->getVar('uid') . "', 'pmlite', 450, 380);", |
|
128
|
|
|
'name' => \_MD_NEWBB_PM, |
|
129
|
|
|
]; |
|
130
|
|
|
} |
|
131
|
|
|
if ($user->getVar('user_viewemail') || $isAdmin) { |
|
132
|
|
|
$userbar['email'] = [ |
|
133
|
|
|
'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "', 'new');", |
|
134
|
|
|
'name' => \_MD_NEWBB_EMAIL, |
|
135
|
|
|
]; |
|
136
|
|
|
} |
|
137
|
|
|
$url = $user->getVar('url'); |
|
138
|
|
|
if ($url) { |
|
139
|
|
|
$userbar['url'] = [ |
|
140
|
|
|
'link' => "javascript:void window.open('" . $url . "', 'new');", |
|
141
|
|
|
'name' => \_MD_NEWBB_WWW, |
|
142
|
|
|
]; |
|
143
|
|
|
} |
|
144
|
|
|
$icq = $user->getVar('user_icq'); |
|
145
|
|
|
if ($icq) { |
|
146
|
|
|
$userbar['icq'] = [ |
|
147
|
|
|
'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=" . $icq . "', 'new');", |
|
148
|
|
|
'name' => \_MD_NEWBB_ICQ, |
|
149
|
|
|
]; |
|
150
|
|
|
} |
|
151
|
|
|
$aim = $user->getVar('user_aim'); |
|
152
|
|
|
if ($aim) { |
|
153
|
|
|
$userbar['aim'] = [ |
|
154
|
|
|
'link' => "javascript:void window.open('aim:goim?screenname=" . $aim . '&message=Hi+' . $aim . '+Are+you+there?' . "', 'new');", |
|
155
|
|
|
'name' => \_MD_NEWBB_AIM, |
|
156
|
|
|
]; |
|
157
|
|
|
} |
|
158
|
|
|
$yim = $user->getVar('user_yim'); |
|
159
|
|
|
if ($yim) { |
|
160
|
|
|
$userbar['yim'] = [ |
|
161
|
|
|
'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=" . $yim . '&.src=pg' . "', 'new');", |
|
162
|
|
|
'name' => \_MD_NEWBB_YIM, |
|
163
|
|
|
]; |
|
164
|
|
|
} |
|
165
|
|
|
$msn = $user->getVar('user_msnm'); |
|
166
|
|
|
if ($msn) { |
|
167
|
|
|
$userbar['msnm'] = [ |
|
168
|
|
|
'link' => "javascript:void window.open('http://members.msn.com?mem=" . $msn . "', 'new');", |
|
169
|
|
|
'name' => \_MD_NEWBB_MSNM, |
|
170
|
|
|
]; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
return $userbar; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @return string |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getLevel() |
|
180
|
|
|
{ |
|
181
|
|
|
global $forumUrl; |
|
182
|
|
|
|
|
183
|
|
|
$level = newbb_calculateLevel($this->user->getVar('posts'), $this->user->getVar('user_regdate')); |
|
184
|
|
|
$info = ''; |
|
185
|
|
|
if (2 == $GLOBALS['xoopsModuleConfig']['user_level']) { |
|
186
|
|
|
static $rpg_images; |
|
187
|
|
|
if (null === $rpg_images) { |
|
188
|
|
|
$iconHandler = \newbbGetIconHandler(); |
|
189
|
|
|
$rpg_path = $iconHandler->getPath('rpg'); |
|
190
|
|
|
foreach (['img_left', 'img_backing', 'img_right', 'blue', 'green', 'orange'] as $img) { |
|
191
|
|
|
// irmtfan fix: double "/" removed |
|
192
|
|
|
$rpg_images[$img] = XOOPS_URL . $rpg_path . '/' . $img . '.gif'; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
// irmtfan hardcore removed align="left" |
|
196
|
|
|
$table = "<table class='userlevel'><tr><td class='end'><img src='" |
|
197
|
|
|
. $rpg_images['img_left'] |
|
198
|
|
|
. "' alt='' ></td><td class='center' background='" |
|
199
|
|
|
. $rpg_images['img_backing'] |
|
200
|
|
|
. "'><img src='%s' width='%d' alt='' class='icon_left' ></td><td><img src='" |
|
201
|
|
|
. $rpg_images['img_right'] |
|
202
|
|
|
. "' alt='' ></td></tr></table>"; |
|
203
|
|
|
|
|
204
|
|
|
$info = \_MD_NEWBB_LEVEL . ' ' . $level['level'] . '<br><span title="' . \_MD_NEWBB_HP_DESC . '">' . \_MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>' . \sprintf($table, $rpg_images['orange'], $level['hp_width']); |
|
205
|
|
|
$info .= '<span title="' . \_MD_NEWBB_MP_DESC . '">' . \_MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span><br>' . \sprintf($table, $rpg_images['green'], $level['mp_width']); |
|
206
|
|
|
$info .= '<span title="' . \_MD_NEWBB_EXP_DESC . '">' . \_MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>' . \sprintf($table, $rpg_images['blue'], $level['exp_width']); |
|
207
|
|
|
} else { |
|
208
|
|
|
$info = \_MD_NEWBB_LEVEL . ' ' . $level['level'] . '; <span title="' . \_MD_NEWBB_EXP_DESC . '">' . \_MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>'; |
|
209
|
|
|
$info .= '<span title="' . \_MD_NEWBB_HP_DESC . '">' . \_MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>'; |
|
210
|
|
|
$info .= '<span title="' . \_MD_NEWBB_MP_DESC . '">' . \_MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span>'; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return $info; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param \XoopsUser $user |
|
218
|
|
|
* @return mixed |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getInfo($user) |
|
221
|
|
|
{ |
|
222
|
|
|
global $myts; |
|
223
|
|
|
static $name_anonymous; |
|
224
|
|
|
|
|
225
|
|
|
if (!\is_object($user) || !$user->isActive()) { |
|
226
|
|
|
if (null === $name_anonymous) { |
|
227
|
|
|
$name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
return ['name' => $name_anonymous, 'link' => $name_anonymous]; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
$this->user = $user; |
|
234
|
|
|
|
|
235
|
|
|
$userinfo['uid'] = $user->getVar('uid'); |
|
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
$name = empty($GLOBALS['xoopsModuleConfig']['show_realname']) ? $user->getVar('uname') : $user->getVar('name'); |
|
238
|
|
|
$userinfo['name'] = $name ?: $user->getVar('uname'); |
|
239
|
|
|
|
|
240
|
|
|
$userinfo['link'] = '<a href=\'' . XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid') . '\'>' . $userinfo['name'] . '</a>'; |
|
241
|
|
|
|
|
242
|
|
|
$userinfo['avatar'] = $user->getVar('user_avatar'); |
|
243
|
|
|
// START hacked by irmtfan - easier rank getting - consistency with previous version back rank.title and rank.image |
|
244
|
|
|
$userrank = $user->rank(); |
|
245
|
|
|
$userinfo['rank'] = []; |
|
246
|
|
|
if (isset($userrank['image']) && $userrank['image']) { |
|
247
|
|
|
$userinfo['rank']['image'] = $userrank['image']; |
|
248
|
|
|
$userinfo['rank']['title'] = $userrank['title']; |
|
249
|
|
|
} |
|
250
|
|
|
// END hacked by irmtfan - easier rank getting - a little correctness dot removed |
|
251
|
|
|
// START hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
252
|
|
|
//checks for user's groups |
|
253
|
|
|
$userinfo['groups'] = []; |
|
254
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
|
255
|
|
|
$memberHandler = \xoops_getHandler('member'); |
|
256
|
|
|
$usergroups = $memberHandler->getGroupsByUser($userinfo['uid'], true); |
|
257
|
|
|
foreach ($usergroups as $group) { |
|
258
|
|
|
$userinfo['groups'][] = $group->getVar('name'); |
|
259
|
|
|
} |
|
260
|
|
|
// END hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']??? |
|
261
|
|
|
$userinfo['from'] = $user->getVar('user_from'); |
|
262
|
|
|
|
|
263
|
|
|
require_once \dirname(__DIR__) . '/include/functions.time.php'; |
|
264
|
|
|
$userinfo['regdate'] = \newbbFormatTimestamp($user->getVar('user_regdate'), 'reg'); |
|
265
|
|
|
$userinfo['last_login'] = \newbbFormatTimestamp($user->getVar('last_login')); // irmtfan add last_login |
|
266
|
|
|
|
|
267
|
|
|
$userinfo['posts'] = $user->getVar('posts'); |
|
268
|
|
|
|
|
269
|
|
|
if (!empty($GLOBALS['xoopsModuleConfig']['user_level'])) { |
|
270
|
|
|
$userinfo['level'] = $this->getLevel(); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
if (!empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) { |
|
274
|
|
|
$userinfo['userbar'] = $this->getUserbar(); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
$userinfo['signature'] = $user->getVar('user_sig'); |
|
278
|
|
|
|
|
279
|
|
|
return $userinfo; |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
|