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