Passed
Branch master (565d4a)
by Michael
15:11 queued 01:11
created
class/XmlrssHandler.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -22,42 +22,42 @@
 block discarded – undo
22 22
  */
23 23
 class XmlrssHandler
24 24
 {
25
-    /**
26
-     * @return Xmlrss
27
-     */
28
-    public function create()
29
-    {
30
-        $xmlrss = new Newbb\Xmlrss();
31
-
32
-        return $xmlrss;
33
-    }
34
-
35
-    /**
36
-     * @param $rss
37
-     * @return array
38
-     */
39
-    public function get(Xmlrss $rss)
40
-    {
41
-        $rss_array                      = [];
42
-        $rss_array['xml_version']       = $rss->xml_version;
43
-        $rss_array['xml_encoding']      = $rss->xml_encoding;
44
-        $rss_array['rss_version']       = $rss->rss_version;
45
-        $rss_array['channel_title']     = $rss->channel_title;
46
-        $rss_array['channel_link']      = $rss->channel_link;
47
-        $rss_array['channel_desc']      = $rss->channel_desc;
48
-        $rss_array['channel_lastbuild'] = $rss->channel_lastbuild;
49
-        $rss_array['channel_webmaster'] = $rss->channel_webmaster;
50
-        $rss_array['channel_editor']    = $rss->channel_editor;
51
-        $rss_array['channel_category']  = $rss->channel_category;
52
-        $rss_array['channel_generator'] = $rss->channel_generator;
53
-        $rss_array['channel_language']  = $rss->channel_language;
54
-        $rss_array['image_title']       = $rss->channel_title;
55
-        $rss_array['image_url']         = $rss->image_url;
56
-        $rss_array['image_link']        = $rss->channel_link;
57
-        $rss_array['image_width']       = $rss->image_width;
58
-        $rss_array['image_height']      = $rss->image_height;
59
-        $rss_array['items']             = $rss->items;
60
-
61
-        return $rss_array;
62
-    }
25
+	/**
26
+	 * @return Xmlrss
27
+	 */
28
+	public function create()
29
+	{
30
+		$xmlrss = new Newbb\Xmlrss();
31
+
32
+		return $xmlrss;
33
+	}
34
+
35
+	/**
36
+	 * @param $rss
37
+	 * @return array
38
+	 */
39
+	public function get(Xmlrss $rss)
40
+	{
41
+		$rss_array                      = [];
42
+		$rss_array['xml_version']       = $rss->xml_version;
43
+		$rss_array['xml_encoding']      = $rss->xml_encoding;
44
+		$rss_array['rss_version']       = $rss->rss_version;
45
+		$rss_array['channel_title']     = $rss->channel_title;
46
+		$rss_array['channel_link']      = $rss->channel_link;
47
+		$rss_array['channel_desc']      = $rss->channel_desc;
48
+		$rss_array['channel_lastbuild'] = $rss->channel_lastbuild;
49
+		$rss_array['channel_webmaster'] = $rss->channel_webmaster;
50
+		$rss_array['channel_editor']    = $rss->channel_editor;
51
+		$rss_array['channel_category']  = $rss->channel_category;
52
+		$rss_array['channel_generator'] = $rss->channel_generator;
53
+		$rss_array['channel_language']  = $rss->channel_language;
54
+		$rss_array['image_title']       = $rss->channel_title;
55
+		$rss_array['image_url']         = $rss->image_url;
56
+		$rss_array['image_link']        = $rss->channel_link;
57
+		$rss_array['image_width']       = $rss->image_width;
58
+		$rss_array['image_height']      = $rss->image_height;
59
+		$rss_array['items']             = $rss->items;
60
+
61
+		return $rss_array;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
class/User.php 2 patches
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -22,74 +22,74 @@  discard block
 block discarded – undo
22 22
 function newbb_calculateLevel($RPG, $RPGDIFF)
23 23
 {
24 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     = 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;
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     = 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 93
 }
94 94
 
95 95
 /**
@@ -97,179 +97,179 @@  discard block
 block discarded – undo
97 97
  */
98 98
 class User
99 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&amp;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 . '&amp;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
-        require_once  dirname(__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
-    }
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&amp;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 . '&amp;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
+		require_once  dirname(__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 275
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
     $level              = [];
82 82
     $level['level']     = $showlevel;
83 83
     $level['exp']       = $ep;
84
-    $level['exp_width'] = $ep . '%';
84
+    $level['exp_width'] = $ep.'%';
85 85
     $level['hp']        = $hp;
86 86
     $level['hp_max']    = $maxhp;
87
-    $level['hp_width']  = $hpf . '%';
87
+    $level['hp_width']  = $hpf.'%';
88 88
     $level['mp']        = $mp;
89 89
     $level['mp_max']    = $maxmp;
90
-    $level['mp_width']  = $mpf . '%';
90
+    $level['mp_width']  = $mpf.'%';
91 91
 
92 92
     return $level;
93 93
 }
@@ -117,49 +117,49 @@  discard block
 block discarded – undo
117 117
 
118 118
         $user               = $this->user;
119 119
         $userbar['profile'] = [
120
-            'link' => XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid'),
120
+            'link' => XOOPS_URL.'/userinfo.php?uid='.$user->getVar('uid'),
121 121
             'name' => _PROFILE
122 122
         ];
123 123
 
124 124
         if (is_object($GLOBALS['xoopsUser'])) {
125 125
             $userbar['pm'] = [
126
-                'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $user->getVar('uid') . "', 'pmlite', 450, 380);",
126
+                'link' => "javascript:void openWithSelfMain('".XOOPS_URL.'/pmlite.php?send2=1&amp;to_userid='.$user->getVar('uid')."', 'pmlite', 450, 380);",
127 127
                 'name' => _MD_NEWBB_PM
128 128
             ];
129 129
         }
130 130
         if ($user->getVar('user_viewemail') || $isAdmin) {
131 131
             $userbar['email'] = [
132
-                'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "', 'new');",
132
+                'link' => "javascript:void window.open('mailto:".$user->getVar('email')."', 'new');",
133 133
                 'name' => _MD_NEWBB_EMAIL
134 134
             ];
135 135
         }
136 136
         if ($url = $user->getVar('url')) {
137 137
             $userbar['url'] = [
138
-                'link' => "javascript:void window.open('" . $url . "', 'new');",
138
+                'link' => "javascript:void window.open('".$url."', 'new');",
139 139
                 'name' => _MD_NEWBB_WWW
140 140
             ];
141 141
         }
142 142
         if ($icq = $user->getVar('user_icq')) {
143 143
             $userbar['icq'] = [
144
-                'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=" . $icq . "', 'new');",
144
+                'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=".$icq."', 'new');",
145 145
                 'name' => _MD_NEWBB_ICQ
146 146
             ];
147 147
         }
148 148
         if ($aim = $user->getVar('user_aim')) {
149 149
             $userbar['aim'] = [
150
-                'link' => "javascript:void window.open('aim:goim?screenname=" . $aim . '&amp;message=Hi+' . $aim . '+Are+you+there?' . "', 'new');",
150
+                'link' => "javascript:void window.open('aim:goim?screenname=".$aim.'&amp;message=Hi+'.$aim.'+Are+you+there?'."', 'new');",
151 151
                 'name' => _MD_NEWBB_AIM
152 152
             ];
153 153
         }
154 154
         if ($yim = $user->getVar('user_yim')) {
155 155
             $userbar['yim'] = [
156
-                'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=" . $yim . '&.src=pg' . "', 'new');",
156
+                'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=".$yim.'&.src=pg'."', 'new');",
157 157
                 'name' => _MD_NEWBB_YIM
158 158
             ];
159 159
         }
160 160
         if ($msn = $user->getVar('user_msnm')) {
161 161
             $userbar['msnm'] = [
162
-                'link' => "javascript:void window.open('http://members.msn.com?mem=" . $msn . "', 'new');",
162
+                'link' => "javascript:void window.open('http://members.msn.com?mem=".$msn."', 'new');",
163 163
                 'name' => _MD_NEWBB_MSNM
164 164
             ];
165 165
         }
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
                 $rpg_path    = $iconHandler->getPath('rpg');
184 184
                 foreach (['img_left', 'img_backing', 'img_right', 'blue', 'green', 'orange'] as $img) {
185 185
                     // irmtfan fix: double "/" removed
186
-                    $rpg_images[$img] = XOOPS_URL . $rpg_path . '/' . $img . '.gif';
186
+                    $rpg_images[$img] = XOOPS_URL.$rpg_path.'/'.$img.'.gif';
187 187
                 }
188 188
             }
189 189
             // irmtfan hardcore removed align="left"
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
                      . $rpg_images['img_right']
196 196
                      . "' alt='' /></td></tr></table>";
197 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']);
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 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>';
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 205
         }
206 206
 
207 207
         return $info;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         $name             = empty($GLOBALS['xoopsModuleConfig']['show_realname']) ? $user->getVar('uname') : $user->getVar('name');
232 232
         $userinfo['name'] = $name ?: $user->getVar('uname');
233 233
 
234
-        $userinfo['link'] = '<a href=\'' . XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid') . '\'>' . $userinfo['name'] . '</a>';
234
+        $userinfo['link'] = '<a href=\''.XOOPS_URL.'/userinfo.php?uid='.$user->getVar('uid').'\'>'.$userinfo['name'].'</a>';
235 235
 
236 236
         $userinfo['avatar'] = $user->getVar('user_avatar');
237 237
         // START hacked by irmtfan - easier rank getting - consistency with previous version back rank.title and rank.image
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         // END hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']???
255 255
         $userinfo['from'] = $user->getVar('user_from');
256 256
 
257
-        require_once  dirname(__DIR__) . '/include/functions.time.php';
257
+        require_once  dirname(__DIR__).'/include/functions.time.php';
258 258
         $userinfo['regdate']    = newbbFormatTimestamp($user->getVar('user_regdate'), 'reg');
259 259
         $userinfo['last_login'] = newbbFormatTimestamp($user->getVar('last_login')); // irmtfan add last_login
260 260
 
Please login to merge, or discard this patch.
class/PermissionHandler.php 2 patches
Indentation   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Initializing XoopsGroupPermHandler if not loaded yet
21 21
 if (!class_exists('XoopsGroupPermHandler')) {
22
-    require_once $GLOBALS['xoops']->path('kernel/groupperm.php');
22
+	require_once $GLOBALS['xoops']->path('kernel/groupperm.php');
23 23
 }
24 24
 
25 25
 /**
@@ -27,402 +27,402 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class PermissionHandler extends \XoopsGroupPermHandler
29 29
 {
30
-    /** @var \Xmf\Module\Helper\Cache */
31
-    protected $cacheHelper;
32
-
33
-    /** @var array */
34
-    private $_handler;
35
-
36
-    /**
37
-     * @param $db
38
-     */
39
-    public function __construct(\XoopsDatabase $db)
40
-    {
41
-        $this->cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
42
-
43
-        $this->db = $db;
44
-        parent::__construct($db);
45
-    }
46
-
47
-    /**
48
-     * @param $name
49
-     * @return mixed
50
-     */
51
-    public function loadHandler($name)
52
-    {
53
-        if (!isset($this->_handler[$name])) {
30
+	/** @var \Xmf\Module\Helper\Cache */
31
+	protected $cacheHelper;
32
+
33
+	/** @var array */
34
+	private $_handler;
35
+
36
+	/**
37
+	 * @param $db
38
+	 */
39
+	public function __construct(\XoopsDatabase $db)
40
+	{
41
+		$this->cacheHelper = new \Xmf\Module\Helper\Cache('newbb');
42
+
43
+		$this->db = $db;
44
+		parent::__construct($db);
45
+	}
46
+
47
+	/**
48
+	 * @param $name
49
+	 * @return mixed
50
+	 */
51
+	public function loadHandler($name)
52
+	{
53
+		if (!isset($this->_handler[$name])) {
54 54
 //            require_once __DIR__ . "/permission.{$name}.php";
55
-            $className             = '\\XoopsModules\\Newbb\\Permission' . ucfirst($name) . 'Handler';
56
-            $this->_handler[$name] = new $className($this->db);
57
-        }
58
-
59
-        return $this->_handler[$name];
60
-    }
61
-
62
-    /**
63
-     * @param  bool $fullname
64
-     * @return mixed
65
-     */
66
-    public function getValidForumPerms($fullname = false)
67
-    {
68
-        $handler = $this->loadHandler('forum');
69
-
70
-        return $handler->getValidPerms($fullname);
71
-    }
72
-
73
-    /**
74
-     * @param  int  $forum
75
-     * @param  bool $topic_locked
76
-     * @param  bool $isAdmin
77
-     * @return mixed
78
-     */
79
-    public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false)
80
-    {
81
-        $handler = $this->loadHandler('forum');
82
-        $perm    = $handler->getPermissionTable($forum, $topic_locked, $isAdmin);
83
-
84
-        return $perm;
85
-    }
86
-
87
-    /**
88
-     * @param $forum_id
89
-     * @return mixed
90
-     */
91
-    public function deleteByForum($forum_id)
92
-    {
93
-        $this->cacheHelper->delete('permission_forum');
94
-        $handler = $this->loadHandler('forum');
95
-
96
-        return $handler->deleteByForum($forum_id);
97
-    }
98
-
99
-    /**
100
-     * @param $cat_id
101
-     * @return mixed
102
-     */
103
-    public function deleteByCategory($cat_id)
104
-    {
105
-        $this->cacheHelper->delete('permission_category');
106
-        $handler = $this->loadHandler('category');
107
-
108
-        return $handler->deleteByCategory($cat_id);
109
-    }
110
-
111
-    /**
112
-     * @param        $category
113
-     * @param  array $groups
114
-     * @return mixed
115
-     */
116
-    public function setCategoryPermission($category, array $groups = [])
117
-    {
118
-        $this->cacheHelper->delete('permission_category');
119
-        $handler = $this->loadHandler('category');
120
-
121
-        return $handler->setCategoryPermission($category, $groups);
122
-    }
123
-
124
-    /**
125
-     * @param         $type
126
-     * @param  string $gperm_name
127
-     * @param  int    $id
128
-     * @return bool
129
-     */
130
-    public function getPermission($type, $gperm_name = 'access', $id = 0)
131
-    {
132
-        global $xoopsModule;
133
-        $ret = false;
134
-        if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $xoopsModule->getVar('dirname')) {
135
-            $ret = true;
136
-        }
137
-
138
-        $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS];
139
-        if (!$groups) {
140
-            $ret = false;
141
-        }
142
-        if (!$allowed_groups = $this->getGroups("{$type}_{$gperm_name}", $id)) {
143
-            $ret = false;
144
-        }
145
-
146
-        if (count(array_intersect($allowed_groups, $groups)) > 0) {
147
-            $ret = true;
148
-        }
149
-
150
-        return $ret;
151
-    }
152
-
153
-    /**
154
-     * @param  string $perm_name
155
-     * @return array
156
-     */
157
-    public function &getCategories($perm_name = 'access')
158
-    {
159
-        $ret = $this->getAllowedItems('category', "category_{$perm_name}");
160
-
161
-        return $ret;
162
-    }
163
-
164
-    /**
165
-     * @param  string $perm_name
166
-     * @return array
167
-     */
168
-    public function getForums($perm_name = 'access')
169
-    {
170
-        $ret = $this->getAllowedItems('forum', "forum_{$perm_name}");
171
-
172
-        return $ret;
173
-    }
174
-
175
-    /**
176
-     * @param $type
177
-     * @param $perm_name
178
-     * @return array
179
-     */
180
-    public function getAllowedItems($type, $perm_name)
181
-    {
182
-        $ret = [];
183
-
184
-        $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS];
185
-        if (count($groups) < 1) {
186
-            return $ret;
187
-        }
188
-
189
-        if (!$_cachedPerms = $this->loadPermData($perm_name, $type)) {
190
-            return $ret;
191
-        }
192
-
193
-        $allowed_items = [];
194
-        foreach ($_cachedPerms as $id => $allowed_groups) {
195
-            if (0 == $id || empty($allowed_groups)) {
196
-                continue;
197
-            }
198
-
199
-            if (array_intersect($groups, $allowed_groups)) {
200
-                $allowed_items[$id] = 1;
201
-            }
202
-        }
203
-        unset($_cachedPerms);
204
-        $ret = array_keys($allowed_items);
205
-
206
-        return $ret;
207
-    }
208
-
209
-    /**
210
-     * @param        $gperm_name
211
-     * @param  int   $id
212
-     * @return array
213
-     */
214
-    public function getGroups($gperm_name, $id = 0)
215
-    {
216
-        $_cachedPerms = $this->loadPermData($gperm_name);
217
-        $groups       = empty($_cachedPerms[$id]) ? [] : array_unique($_cachedPerms[$id]);
218
-        unset($_cachedPerms);
219
-
220
-        return $groups;
221
-    }
222
-
223
-    /**
224
-     * @param  string $perm_name
225
-     * @return array
226
-     */
227
-    public function createPermData($perm_name = 'forum_all')
228
-    {
229
-        global $xoopsModule;
230
-        /** @var \XoopsModuleHandler $moduleHandler */
231
-        $perms = [];
232
-
233
-        if (is_object($xoopsModule) && 'newbb' === $xoopsModule->getVar('dirname')) {
234
-            $modid = $xoopsModule->getVar('mid');
235
-        } else {
236
-            $moduleHandler = xoops_getHandler('module');
237
-            $module        = $moduleHandler->getByDirname('newbb');
238
-            $modid         = $module->getVar('mid');
239
-            unset($module);
240
-        }
241
-
242
-        if (in_array($perm_name, ['forum_all', 'category_all'], true)) {
243
-            /** @var \XoopsMemberHandler $memberHandler */
244
-            $memberHandler = xoops_getHandler('member');
245
-            $groups        = array_keys($memberHandler->getGroupList());
246
-
247
-            $type          = ('category_all' === $perm_name) ? 'category' : 'forum';
248
-            $objectHandler = Newbb\Helper::getInstance()->getHandler($type);
249
-            $object_ids    = $objectHandler->getIds();
250
-            foreach ($object_ids as $item_id) {
251
-                $perms[$perm_name][$item_id] = $groups;
252
-            }
253
-        } else {
254
-            $grouppermHandler = xoops_getHandler('groupperm');
255
-            $criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $modid));
256
-            if (!empty($perm_name) && 'forum_all' !== $perm_name && 'category_all' !== $perm_name) {
257
-                $criteria->add(new \Criteria('gperm_name', $perm_name));
258
-            }
259
-            $permissions = $this->getObjects($criteria);
260
-
261
-            foreach ($permissions as $gperm) {
262
-                $item_id                                         = $gperm->getVar('gperm_itemid');
263
-                $group_id                                        = (int)$gperm->getVar('gperm_groupid');
264
-                $perms[$gperm->getVar('gperm_name')][$item_id][] = $group_id;
265
-            }
266
-        }
267
-        if (count($perms) > 0) {
268
-            foreach (array_keys($perms) as $perm) {
269
-                $this->cacheHelper->write("permission_{$perm}", $perms[$perm]);
270
-            }
271
-        }
272
-        $ret = !empty($perm_name) ? @$perms[$perm_name] : $perms;
273
-
274
-        return $ret;
275
-    }
276
-
277
-    /**
278
-     * @param  string $perm_name
279
-     * @return array|mixed|null
280
-     */
281
-    public function &loadPermData($perm_name = 'forum_access')
282
-    {
283
-        if (!$perms = $this->cacheHelper->read("permission_{$perm_name}")) {
284
-            $perms = $this->createPermData($perm_name);
285
-        }
286
-
287
-        return $perms;
288
-    }
289
-
290
-    /**
291
-     * @param       $perm
292
-     * @param       $itemid
293
-     * @param       $groupid
294
-     * @param  null $mid
295
-     * @return bool
296
-     */
297
-    public function validateRight($perm, $itemid, $groupid, $mid = null)
298
-    {
299
-        if (empty($mid)) {
300
-            if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
301
-                $mid = $GLOBALS['xoopsModule']->getVar('mid');
302
-            } else {
303
-                /** @var \XoopsModuleHandler $moduleHandler */
304
-                $moduleHandler = xoops_getHandler('module');
305
-                $mod           = $moduleHandler->getByDirname('newbb');
306
-                $mid           = $mod->getVar('mid');
307
-                unset($mod);
308
-            }
309
-        }
310
-        if ($this->myCheckRight($perm, $itemid, $groupid, $mid)) {
311
-            return true;
312
-        }
313
-        $this->cacheHelper->delete('permission');
314
-        $this->addRight($perm, $itemid, $groupid, $mid);
315
-
316
-        return true;
317
-    }
318
-
319
-    /**
320
-     * Check permission (directly)
321
-     *
322
-     * @param string $gperm_name   Name of permission
323
-     * @param int    $gperm_itemid ID of an item
324
-     * @param        int           /array $gperm_groupid A group ID or an array of group IDs
325
-     * @param int    $gperm_modid  ID of a module
326
-     *
327
-     * @return bool TRUE if permission is enabled
328
-     */
329
-    public function myCheckRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid = 1)
330
-    {
331
-        $ret      = false;
332
-        $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $gperm_modid));
333
-        $criteria->add(new \Criteria('gperm_name', $gperm_name));
334
-        $gperm_itemid = (int)$gperm_itemid;
335
-        if ($gperm_itemid > 0) {
336
-            $criteria->add(new \Criteria('gperm_itemid', $gperm_itemid));
337
-        }
338
-        if (is_array($gperm_groupid)) {
339
-            $criteria2 = new \CriteriaCompo();
340
-            foreach ($gperm_groupid as $gid) {
341
-                $criteria2->add(new \Criteria('gperm_groupid', $gid), 'OR');
342
-            }
343
-            $criteria->add($criteria2);
344
-        } else {
345
-            $criteria->add(new \Criteria('gperm_groupid', $gperm_groupid));
346
-        }
347
-        if ($this->getCount($criteria) > 0) {
348
-            $ret = true;
349
-        }
350
-
351
-        return $ret;
352
-    }
353
-
354
-    /**
355
-     * @param       $perm
356
-     * @param       $itemid
357
-     * @param       $groupid
358
-     * @param  null $mid
359
-     * @return bool
360
-     */
361
-    public function deleteRight($perm, $itemid, $groupid, $mid = null)
362
-    {
363
-        $this->cacheHelper->delete('permission');
364
-        if (null === $mid) {
365
-            if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
366
-                $mid = $GLOBALS['xoopsModule']->getVar('mid');
367
-            } else {
368
-                /** @var \XoopsModuleHandler $moduleHandler */
369
-                $moduleHandler = xoops_getHandler('module');
370
-                $mod           = $moduleHandler->getByDirname('newbb');
371
-                $mid           = $mod->getVar('mid');
372
-                unset($mod);
373
-            }
374
-        }
375
-        if (is_callable('parent::deleteRight')) {
376
-            return parent::deleteRight($perm, $itemid, $groupid, $mid);
377
-        } else {
378
-            $criteria = new \CriteriaCompo(new \Criteria('gperm_name', $perm));
379
-            $criteria->add(new \Criteria('gperm_groupid', $groupid));
380
-            $criteria->add(new \Criteria('gperm_itemid', $itemid));
381
-            $criteria->add(new \Criteria('gperm_modid', $mid));
382
-            $permsObject = $this->getObjects($criteria);
383
-            if (!empty($permsObject)) {
384
-                foreach ($permsObject as $permObject) {
385
-                    $this->delete($permObject);
386
-                }
387
-            }
388
-            unset($criteria, $permsObject);
389
-        }
390
-
391
-        return true;
392
-    }
393
-
394
-    /**
395
-     * @param        $forum
396
-     * @param  int   $mid
397
-     * @return mixed
398
-     */
399
-    public function applyTemplate($forum, $mid = 0)
400
-    {
401
-        $this->cacheHelper->delete('permission_forum');
402
-        $handler = $this->loadHandler('forum');
403
-
404
-        return $handler->applyTemplate($forum, $mid);
405
-    }
406
-
407
-    /**
408
-     * @return mixed
409
-     */
410
-    public function getTemplate()
411
-    {
412
-        $handler  = $this->loadHandler('forum');
413
-        $template = $handler->getTemplate();
414
-
415
-        return $template;
416
-    }
417
-
418
-    /**
419
-     * @param $perms
420
-     * @return mixed
421
-     */
422
-    public function setTemplate($perms)
423
-    {
424
-        $handler = $this->loadHandler('forum');
425
-
426
-        return $handler->setTemplate($perms);
427
-    }
55
+			$className             = '\\XoopsModules\\Newbb\\Permission' . ucfirst($name) . 'Handler';
56
+			$this->_handler[$name] = new $className($this->db);
57
+		}
58
+
59
+		return $this->_handler[$name];
60
+	}
61
+
62
+	/**
63
+	 * @param  bool $fullname
64
+	 * @return mixed
65
+	 */
66
+	public function getValidForumPerms($fullname = false)
67
+	{
68
+		$handler = $this->loadHandler('forum');
69
+
70
+		return $handler->getValidPerms($fullname);
71
+	}
72
+
73
+	/**
74
+	 * @param  int  $forum
75
+	 * @param  bool $topic_locked
76
+	 * @param  bool $isAdmin
77
+	 * @return mixed
78
+	 */
79
+	public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false)
80
+	{
81
+		$handler = $this->loadHandler('forum');
82
+		$perm    = $handler->getPermissionTable($forum, $topic_locked, $isAdmin);
83
+
84
+		return $perm;
85
+	}
86
+
87
+	/**
88
+	 * @param $forum_id
89
+	 * @return mixed
90
+	 */
91
+	public function deleteByForum($forum_id)
92
+	{
93
+		$this->cacheHelper->delete('permission_forum');
94
+		$handler = $this->loadHandler('forum');
95
+
96
+		return $handler->deleteByForum($forum_id);
97
+	}
98
+
99
+	/**
100
+	 * @param $cat_id
101
+	 * @return mixed
102
+	 */
103
+	public function deleteByCategory($cat_id)
104
+	{
105
+		$this->cacheHelper->delete('permission_category');
106
+		$handler = $this->loadHandler('category');
107
+
108
+		return $handler->deleteByCategory($cat_id);
109
+	}
110
+
111
+	/**
112
+	 * @param        $category
113
+	 * @param  array $groups
114
+	 * @return mixed
115
+	 */
116
+	public function setCategoryPermission($category, array $groups = [])
117
+	{
118
+		$this->cacheHelper->delete('permission_category');
119
+		$handler = $this->loadHandler('category');
120
+
121
+		return $handler->setCategoryPermission($category, $groups);
122
+	}
123
+
124
+	/**
125
+	 * @param         $type
126
+	 * @param  string $gperm_name
127
+	 * @param  int    $id
128
+	 * @return bool
129
+	 */
130
+	public function getPermission($type, $gperm_name = 'access', $id = 0)
131
+	{
132
+		global $xoopsModule;
133
+		$ret = false;
134
+		if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $xoopsModule->getVar('dirname')) {
135
+			$ret = true;
136
+		}
137
+
138
+		$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS];
139
+		if (!$groups) {
140
+			$ret = false;
141
+		}
142
+		if (!$allowed_groups = $this->getGroups("{$type}_{$gperm_name}", $id)) {
143
+			$ret = false;
144
+		}
145
+
146
+		if (count(array_intersect($allowed_groups, $groups)) > 0) {
147
+			$ret = true;
148
+		}
149
+
150
+		return $ret;
151
+	}
152
+
153
+	/**
154
+	 * @param  string $perm_name
155
+	 * @return array
156
+	 */
157
+	public function &getCategories($perm_name = 'access')
158
+	{
159
+		$ret = $this->getAllowedItems('category', "category_{$perm_name}");
160
+
161
+		return $ret;
162
+	}
163
+
164
+	/**
165
+	 * @param  string $perm_name
166
+	 * @return array
167
+	 */
168
+	public function getForums($perm_name = 'access')
169
+	{
170
+		$ret = $this->getAllowedItems('forum', "forum_{$perm_name}");
171
+
172
+		return $ret;
173
+	}
174
+
175
+	/**
176
+	 * @param $type
177
+	 * @param $perm_name
178
+	 * @return array
179
+	 */
180
+	public function getAllowedItems($type, $perm_name)
181
+	{
182
+		$ret = [];
183
+
184
+		$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS];
185
+		if (count($groups) < 1) {
186
+			return $ret;
187
+		}
188
+
189
+		if (!$_cachedPerms = $this->loadPermData($perm_name, $type)) {
190
+			return $ret;
191
+		}
192
+
193
+		$allowed_items = [];
194
+		foreach ($_cachedPerms as $id => $allowed_groups) {
195
+			if (0 == $id || empty($allowed_groups)) {
196
+				continue;
197
+			}
198
+
199
+			if (array_intersect($groups, $allowed_groups)) {
200
+				$allowed_items[$id] = 1;
201
+			}
202
+		}
203
+		unset($_cachedPerms);
204
+		$ret = array_keys($allowed_items);
205
+
206
+		return $ret;
207
+	}
208
+
209
+	/**
210
+	 * @param        $gperm_name
211
+	 * @param  int   $id
212
+	 * @return array
213
+	 */
214
+	public function getGroups($gperm_name, $id = 0)
215
+	{
216
+		$_cachedPerms = $this->loadPermData($gperm_name);
217
+		$groups       = empty($_cachedPerms[$id]) ? [] : array_unique($_cachedPerms[$id]);
218
+		unset($_cachedPerms);
219
+
220
+		return $groups;
221
+	}
222
+
223
+	/**
224
+	 * @param  string $perm_name
225
+	 * @return array
226
+	 */
227
+	public function createPermData($perm_name = 'forum_all')
228
+	{
229
+		global $xoopsModule;
230
+		/** @var \XoopsModuleHandler $moduleHandler */
231
+		$perms = [];
232
+
233
+		if (is_object($xoopsModule) && 'newbb' === $xoopsModule->getVar('dirname')) {
234
+			$modid = $xoopsModule->getVar('mid');
235
+		} else {
236
+			$moduleHandler = xoops_getHandler('module');
237
+			$module        = $moduleHandler->getByDirname('newbb');
238
+			$modid         = $module->getVar('mid');
239
+			unset($module);
240
+		}
241
+
242
+		if (in_array($perm_name, ['forum_all', 'category_all'], true)) {
243
+			/** @var \XoopsMemberHandler $memberHandler */
244
+			$memberHandler = xoops_getHandler('member');
245
+			$groups        = array_keys($memberHandler->getGroupList());
246
+
247
+			$type          = ('category_all' === $perm_name) ? 'category' : 'forum';
248
+			$objectHandler = Newbb\Helper::getInstance()->getHandler($type);
249
+			$object_ids    = $objectHandler->getIds();
250
+			foreach ($object_ids as $item_id) {
251
+				$perms[$perm_name][$item_id] = $groups;
252
+			}
253
+		} else {
254
+			$grouppermHandler = xoops_getHandler('groupperm');
255
+			$criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $modid));
256
+			if (!empty($perm_name) && 'forum_all' !== $perm_name && 'category_all' !== $perm_name) {
257
+				$criteria->add(new \Criteria('gperm_name', $perm_name));
258
+			}
259
+			$permissions = $this->getObjects($criteria);
260
+
261
+			foreach ($permissions as $gperm) {
262
+				$item_id                                         = $gperm->getVar('gperm_itemid');
263
+				$group_id                                        = (int)$gperm->getVar('gperm_groupid');
264
+				$perms[$gperm->getVar('gperm_name')][$item_id][] = $group_id;
265
+			}
266
+		}
267
+		if (count($perms) > 0) {
268
+			foreach (array_keys($perms) as $perm) {
269
+				$this->cacheHelper->write("permission_{$perm}", $perms[$perm]);
270
+			}
271
+		}
272
+		$ret = !empty($perm_name) ? @$perms[$perm_name] : $perms;
273
+
274
+		return $ret;
275
+	}
276
+
277
+	/**
278
+	 * @param  string $perm_name
279
+	 * @return array|mixed|null
280
+	 */
281
+	public function &loadPermData($perm_name = 'forum_access')
282
+	{
283
+		if (!$perms = $this->cacheHelper->read("permission_{$perm_name}")) {
284
+			$perms = $this->createPermData($perm_name);
285
+		}
286
+
287
+		return $perms;
288
+	}
289
+
290
+	/**
291
+	 * @param       $perm
292
+	 * @param       $itemid
293
+	 * @param       $groupid
294
+	 * @param  null $mid
295
+	 * @return bool
296
+	 */
297
+	public function validateRight($perm, $itemid, $groupid, $mid = null)
298
+	{
299
+		if (empty($mid)) {
300
+			if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
301
+				$mid = $GLOBALS['xoopsModule']->getVar('mid');
302
+			} else {
303
+				/** @var \XoopsModuleHandler $moduleHandler */
304
+				$moduleHandler = xoops_getHandler('module');
305
+				$mod           = $moduleHandler->getByDirname('newbb');
306
+				$mid           = $mod->getVar('mid');
307
+				unset($mod);
308
+			}
309
+		}
310
+		if ($this->myCheckRight($perm, $itemid, $groupid, $mid)) {
311
+			return true;
312
+		}
313
+		$this->cacheHelper->delete('permission');
314
+		$this->addRight($perm, $itemid, $groupid, $mid);
315
+
316
+		return true;
317
+	}
318
+
319
+	/**
320
+	 * Check permission (directly)
321
+	 *
322
+	 * @param string $gperm_name   Name of permission
323
+	 * @param int    $gperm_itemid ID of an item
324
+	 * @param        int           /array $gperm_groupid A group ID or an array of group IDs
325
+	 * @param int    $gperm_modid  ID of a module
326
+	 *
327
+	 * @return bool TRUE if permission is enabled
328
+	 */
329
+	public function myCheckRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid = 1)
330
+	{
331
+		$ret      = false;
332
+		$criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $gperm_modid));
333
+		$criteria->add(new \Criteria('gperm_name', $gperm_name));
334
+		$gperm_itemid = (int)$gperm_itemid;
335
+		if ($gperm_itemid > 0) {
336
+			$criteria->add(new \Criteria('gperm_itemid', $gperm_itemid));
337
+		}
338
+		if (is_array($gperm_groupid)) {
339
+			$criteria2 = new \CriteriaCompo();
340
+			foreach ($gperm_groupid as $gid) {
341
+				$criteria2->add(new \Criteria('gperm_groupid', $gid), 'OR');
342
+			}
343
+			$criteria->add($criteria2);
344
+		} else {
345
+			$criteria->add(new \Criteria('gperm_groupid', $gperm_groupid));
346
+		}
347
+		if ($this->getCount($criteria) > 0) {
348
+			$ret = true;
349
+		}
350
+
351
+		return $ret;
352
+	}
353
+
354
+	/**
355
+	 * @param       $perm
356
+	 * @param       $itemid
357
+	 * @param       $groupid
358
+	 * @param  null $mid
359
+	 * @return bool
360
+	 */
361
+	public function deleteRight($perm, $itemid, $groupid, $mid = null)
362
+	{
363
+		$this->cacheHelper->delete('permission');
364
+		if (null === $mid) {
365
+			if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
366
+				$mid = $GLOBALS['xoopsModule']->getVar('mid');
367
+			} else {
368
+				/** @var \XoopsModuleHandler $moduleHandler */
369
+				$moduleHandler = xoops_getHandler('module');
370
+				$mod           = $moduleHandler->getByDirname('newbb');
371
+				$mid           = $mod->getVar('mid');
372
+				unset($mod);
373
+			}
374
+		}
375
+		if (is_callable('parent::deleteRight')) {
376
+			return parent::deleteRight($perm, $itemid, $groupid, $mid);
377
+		} else {
378
+			$criteria = new \CriteriaCompo(new \Criteria('gperm_name', $perm));
379
+			$criteria->add(new \Criteria('gperm_groupid', $groupid));
380
+			$criteria->add(new \Criteria('gperm_itemid', $itemid));
381
+			$criteria->add(new \Criteria('gperm_modid', $mid));
382
+			$permsObject = $this->getObjects($criteria);
383
+			if (!empty($permsObject)) {
384
+				foreach ($permsObject as $permObject) {
385
+					$this->delete($permObject);
386
+				}
387
+			}
388
+			unset($criteria, $permsObject);
389
+		}
390
+
391
+		return true;
392
+	}
393
+
394
+	/**
395
+	 * @param        $forum
396
+	 * @param  int   $mid
397
+	 * @return mixed
398
+	 */
399
+	public function applyTemplate($forum, $mid = 0)
400
+	{
401
+		$this->cacheHelper->delete('permission_forum');
402
+		$handler = $this->loadHandler('forum');
403
+
404
+		return $handler->applyTemplate($forum, $mid);
405
+	}
406
+
407
+	/**
408
+	 * @return mixed
409
+	 */
410
+	public function getTemplate()
411
+	{
412
+		$handler  = $this->loadHandler('forum');
413
+		$template = $handler->getTemplate();
414
+
415
+		return $template;
416
+	}
417
+
418
+	/**
419
+	 * @param $perms
420
+	 * @return mixed
421
+	 */
422
+	public function setTemplate($perms)
423
+	{
424
+		$handler = $this->loadHandler('forum');
425
+
426
+		return $handler->setTemplate($perms);
427
+	}
428 428
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     {
53 53
         if (!isset($this->_handler[$name])) {
54 54
 //            require_once __DIR__ . "/permission.{$name}.php";
55
-            $className             = '\\XoopsModules\\Newbb\\Permission' . ucfirst($name) . 'Handler';
55
+            $className             = '\\XoopsModules\\Newbb\\Permission'.ucfirst($name).'Handler';
56 56
             $this->_handler[$name] = new $className($this->db);
57 57
         }
58 58
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             }
253 253
         } else {
254 254
             $grouppermHandler = xoops_getHandler('groupperm');
255
-            $criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $modid));
255
+            $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid));
256 256
             if (!empty($perm_name) && 'forum_all' !== $perm_name && 'category_all' !== $perm_name) {
257 257
                 $criteria->add(new \Criteria('gperm_name', $perm_name));
258 258
             }
Please login to merge, or discard this patch.
class/Text.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@
 block discarded – undo
19 19
  */
20 20
 class Text extends \XoopsObject
21 21
 {
22
-    /**
23
-     *
24
-     */
25
-    public function __construct()
26
-    {
27
-        parent::__construct();
28
-        $this->initVar('post_id', XOBJ_DTYPE_INT);
29
-        $this->initVar('post_text', XOBJ_DTYPE_TXTAREA);
30
-        $this->initVar('post_edit', XOBJ_DTYPE_SOURCE);
31
-    }
22
+	/**
23
+	 *
24
+	 */
25
+	public function __construct()
26
+	{
27
+		parent::__construct();
28
+		$this->initVar('post_id', XOBJ_DTYPE_INT);
29
+		$this->initVar('post_text', XOBJ_DTYPE_TXTAREA);
30
+		$this->initVar('post_edit', XOBJ_DTYPE_SOURCE);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
class/TypeHandler.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -21,175 +21,175 @@
 block discarded – undo
21 21
  */
22 22
 class TypeHandler extends \XoopsPersistableObjectHandler
23 23
 {
24
-    /**
25
-     * @param null|\XoopsDatabase $db
26
-     */
27
-    public function __construct(\XoopsDatabase $db)
28
-    {
29
-        parent::__construct($db, 'newbb_type', Type::class, 'type_id', 'type_name');
30
-    }
31
-
32
-    /**
33
-     * Get types linked to a forum
34
-     *
35
-     * @param  mixed $forums single forum ID or an array of forum IDs
36
-     * @return array associative array of types (name, color, order)
37
-     */
38
-    public function getByForum($forums = null)
39
-    {
40
-        $ret = [];
41
-
42
-        $forums = (is_array($forums) ? array_filter(array_map('intval', array_map('trim', $forums))) : (empty($forums) ? 0 : [(int)$forums]));
43
-
44
-        $sql = '    SELECT o.type_id, o.type_name, o.type_color, l.type_order'
45
-               . '     FROM '
46
-               . $this->db->prefix('newbb_type_forum')
47
-               . ' AS l '
48
-               . "         LEFT JOIN {$this->table} AS o ON o.{$this->keyName} = l.{$this->keyName} "
49
-               . '     WHERE '
50
-               . '        l.forum_id '
51
-               . (empty($forums) ? 'IS NOT NULL' : 'IN (' . implode(', ', $forums) . ')')
52
-               . '         ORDER BY l.type_order ASC';
53
-        if (false === ($result = $this->db->query($sql))) {
54
-            //xoops_error($this->db->error());
55
-            return $ret;
56
-        }
57
-
58
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
59
-            $ret[$myrow[$this->keyName]] = [
60
-                'type_id'    => $myrow[$this->keyName],
61
-                'type_order' => $myrow['type_order'],
62
-                'type_name'  => htmlspecialchars($myrow['type_name'], ENT_QUOTES | ENT_HTML5),
63
-                'type_color' => htmlspecialchars($myrow['type_color'], ENT_QUOTES | ENT_HTML5)
64
-            ];
65
-        }
66
-
67
-        return $ret;
68
-    }
69
-
70
-    /**
71
-     * Update types linked to a forum
72
-     *
73
-     * @param  integer $forum_id
74
-     * @param  array   $types
75
-     * @return boolean
76
-     */
77
-    public function updateByForum($forum_id, $types)
78
-    {
79
-        $forum_id = (int)$forum_id;
80
-        if (empty($forum_id)) {
81
-            return false;
82
-        }
83
-
84
-        $types_existing = $this->getByForum($forum_id);
85
-        $types_valid    = [];
86
-        $types_add      = [];
87
-        $types_update   = [];
88
-        foreach (array_keys($types_existing) as $key) {
89
-            if (empty($types[$key])) {
90
-                continue;
91
-            }
92
-            $types_valid[] = $key;
93
-            if ($types[$key] !== $types_existing[$key]['type_order']) {
94
-                $types_update[] = $key;
95
-            }
96
-        }
97
-        foreach (array_keys($types) as $key) {
98
-            if (!empty($types[$key]) && !isset($types_existing[$key])) {
99
-                $types_add[] = $key;
100
-            }
101
-        }
102
-        $types_valid  = array_filter($types_valid);
103
-        $types_add    = array_filter($types_add);
104
-        $types_update = array_filter($types_update);
105
-
106
-        if (!empty($types_valid)) {
107
-            $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . ' forum_id = ' . $forum_id . ' AND ' . // irmtfan bug fix: delete other forums types when update the type for a specific forum
108
-                   "     {$this->keyName} NOT IN (" . implode(', ', $types_valid) . ')';
109
-            if (false === ($result = $this->db->queryF($sql))) {
110
-            }
111
-        }
112
-
113
-        if (!empty($types_update)) {
114
-            $type_query = [];
115
-            foreach ($types_update as $key) {
116
-                $order = $types[$key];
117
-                if ($types_existing[$key]['type_order'] == $order) {
118
-                    continue;
119
-                }
120
-                $sql = 'UPDATE ' . $this->db->prefix('newbb_type_forum') . " SET type_order = {$order}" . " WHERE  {$this->keyName} = {$key} AND forum_id = {$forum_id}";
121
-                if (false === ($result = $this->db->queryF($sql))) {
122
-                }
123
-            }
124
-        }
125
-
126
-        if (!empty($types_add)) {
127
-            $type_query = [];
128
-            foreach ($types_add as $key) {
129
-                $order = $types[$key];
130
-                //if (!in_array($key, $types_add)) continue;
131
-                $type_query[] = "({$key}, {$forum_id}, {$order})";
132
-            }
133
-            $sql = 'INSERT INTO ' . $this->db->prefix('newbb_type_forum') . ' (type_id, forum_id, type_order) ' . ' VALUES ' . implode(', ', $type_query);
134
-            if (false === ($result = $this->db->queryF($sql))) {
135
-                //xoops_error($this->db->error());
136
-            }
137
-        }
138
-
139
-        return true;
140
-    }
141
-
142
-    /**
143
-     * delete an object as well as links relying on it
144
-     *
145
-     * @param Type|\XoopsObject $object {@link Type}
146
-     * @param  bool        $force  flag to force the query execution despite security settings
147
-     * @return bool
148
-     */
149
-    public function delete(\XoopsObject $object, $force = true)
150
-    {
151
-        if (!is_object($object) || !$object->getVar($this->keyName)) {
152
-            return false;
153
-        }
154
-        $queryFunc = empty($force) ? 'query' : 'queryF';
155
-
156
-        /*
24
+	/**
25
+	 * @param null|\XoopsDatabase $db
26
+	 */
27
+	public function __construct(\XoopsDatabase $db)
28
+	{
29
+		parent::__construct($db, 'newbb_type', Type::class, 'type_id', 'type_name');
30
+	}
31
+
32
+	/**
33
+	 * Get types linked to a forum
34
+	 *
35
+	 * @param  mixed $forums single forum ID or an array of forum IDs
36
+	 * @return array associative array of types (name, color, order)
37
+	 */
38
+	public function getByForum($forums = null)
39
+	{
40
+		$ret = [];
41
+
42
+		$forums = (is_array($forums) ? array_filter(array_map('intval', array_map('trim', $forums))) : (empty($forums) ? 0 : [(int)$forums]));
43
+
44
+		$sql = '    SELECT o.type_id, o.type_name, o.type_color, l.type_order'
45
+			   . '     FROM '
46
+			   . $this->db->prefix('newbb_type_forum')
47
+			   . ' AS l '
48
+			   . "         LEFT JOIN {$this->table} AS o ON o.{$this->keyName} = l.{$this->keyName} "
49
+			   . '     WHERE '
50
+			   . '        l.forum_id '
51
+			   . (empty($forums) ? 'IS NOT NULL' : 'IN (' . implode(', ', $forums) . ')')
52
+			   . '         ORDER BY l.type_order ASC';
53
+		if (false === ($result = $this->db->query($sql))) {
54
+			//xoops_error($this->db->error());
55
+			return $ret;
56
+		}
57
+
58
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
59
+			$ret[$myrow[$this->keyName]] = [
60
+				'type_id'    => $myrow[$this->keyName],
61
+				'type_order' => $myrow['type_order'],
62
+				'type_name'  => htmlspecialchars($myrow['type_name'], ENT_QUOTES | ENT_HTML5),
63
+				'type_color' => htmlspecialchars($myrow['type_color'], ENT_QUOTES | ENT_HTML5)
64
+			];
65
+		}
66
+
67
+		return $ret;
68
+	}
69
+
70
+	/**
71
+	 * Update types linked to a forum
72
+	 *
73
+	 * @param  integer $forum_id
74
+	 * @param  array   $types
75
+	 * @return boolean
76
+	 */
77
+	public function updateByForum($forum_id, $types)
78
+	{
79
+		$forum_id = (int)$forum_id;
80
+		if (empty($forum_id)) {
81
+			return false;
82
+		}
83
+
84
+		$types_existing = $this->getByForum($forum_id);
85
+		$types_valid    = [];
86
+		$types_add      = [];
87
+		$types_update   = [];
88
+		foreach (array_keys($types_existing) as $key) {
89
+			if (empty($types[$key])) {
90
+				continue;
91
+			}
92
+			$types_valid[] = $key;
93
+			if ($types[$key] !== $types_existing[$key]['type_order']) {
94
+				$types_update[] = $key;
95
+			}
96
+		}
97
+		foreach (array_keys($types) as $key) {
98
+			if (!empty($types[$key]) && !isset($types_existing[$key])) {
99
+				$types_add[] = $key;
100
+			}
101
+		}
102
+		$types_valid  = array_filter($types_valid);
103
+		$types_add    = array_filter($types_add);
104
+		$types_update = array_filter($types_update);
105
+
106
+		if (!empty($types_valid)) {
107
+			$sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE ' . ' forum_id = ' . $forum_id . ' AND ' . // irmtfan bug fix: delete other forums types when update the type for a specific forum
108
+				   "     {$this->keyName} NOT IN (" . implode(', ', $types_valid) . ')';
109
+			if (false === ($result = $this->db->queryF($sql))) {
110
+			}
111
+		}
112
+
113
+		if (!empty($types_update)) {
114
+			$type_query = [];
115
+			foreach ($types_update as $key) {
116
+				$order = $types[$key];
117
+				if ($types_existing[$key]['type_order'] == $order) {
118
+					continue;
119
+				}
120
+				$sql = 'UPDATE ' . $this->db->prefix('newbb_type_forum') . " SET type_order = {$order}" . " WHERE  {$this->keyName} = {$key} AND forum_id = {$forum_id}";
121
+				if (false === ($result = $this->db->queryF($sql))) {
122
+				}
123
+			}
124
+		}
125
+
126
+		if (!empty($types_add)) {
127
+			$type_query = [];
128
+			foreach ($types_add as $key) {
129
+				$order = $types[$key];
130
+				//if (!in_array($key, $types_add)) continue;
131
+				$type_query[] = "({$key}, {$forum_id}, {$order})";
132
+			}
133
+			$sql = 'INSERT INTO ' . $this->db->prefix('newbb_type_forum') . ' (type_id, forum_id, type_order) ' . ' VALUES ' . implode(', ', $type_query);
134
+			if (false === ($result = $this->db->queryF($sql))) {
135
+				//xoops_error($this->db->error());
136
+			}
137
+		}
138
+
139
+		return true;
140
+	}
141
+
142
+	/**
143
+	 * delete an object as well as links relying on it
144
+	 *
145
+	 * @param Type|\XoopsObject $object {@link Type}
146
+	 * @param  bool        $force  flag to force the query execution despite security settings
147
+	 * @return bool
148
+	 */
149
+	public function delete(\XoopsObject $object, $force = true)
150
+	{
151
+		if (!is_object($object) || !$object->getVar($this->keyName)) {
152
+			return false;
153
+		}
154
+		$queryFunc = empty($force) ? 'query' : 'queryF';
155
+
156
+		/*
157 157
          * Remove forum-type links
158 158
          */
159
-        $sql = 'DELETE' . ' FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE  ' . $this->keyName . ' = ' . $object->getVar($this->keyName);
160
-        if (false === ($result = $this->db->{$queryFunc}($sql))) {
161
-            // xoops_error($this->db->error());
162
-        }
159
+		$sql = 'DELETE' . ' FROM ' . $this->db->prefix('newbb_type_forum') . ' WHERE  ' . $this->keyName . ' = ' . $object->getVar($this->keyName);
160
+		if (false === ($result = $this->db->{$queryFunc}($sql))) {
161
+			// xoops_error($this->db->error());
162
+		}
163 163
 
164
-        /*
164
+		/*
165 165
          * Reset topic type linked to this type
166 166
          */
167
-        $sql = 'UPATE' . ' ' . $this->db->prefix('newbb_topics') . ' SET ' . $this->keyName . '=0' . ' WHERE  ' . $this->keyName . ' = ' . $object->getVar($this->keyName);
168
-        if (false === ($result = $this->db->{$queryFunc}($sql))) {
169
-            //xoops_error($this->db->error());
170
-        }
171
-
172
-        return parent::delete($object, $force);
173
-    }
174
-
175
-    /**
176
-     * clean orphan links from database
177
-     *
178
-     * @param  string $table_link
179
-     * @param  string $field_link
180
-     * @param  string $field_object
181
-     * @return bool   true on success
182
-     */
183
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
184
-    {
185
-        /* clear forum-type links */
186
-        $sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )";
187
-        $this->db->queryF($sql);
188
-
189
-        /* reconcile topic-type link */
190
-        $sql = 'UPATE ' . $this->db->prefix('newbb_topics') . " SET {$this->keyName} = 0" . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )";
191
-        $this->db->queryF($sql);
192
-
193
-        return true;
194
-    }
167
+		$sql = 'UPATE' . ' ' . $this->db->prefix('newbb_topics') . ' SET ' . $this->keyName . '=0' . ' WHERE  ' . $this->keyName . ' = ' . $object->getVar($this->keyName);
168
+		if (false === ($result = $this->db->{$queryFunc}($sql))) {
169
+			//xoops_error($this->db->error());
170
+		}
171
+
172
+		return parent::delete($object, $force);
173
+	}
174
+
175
+	/**
176
+	 * clean orphan links from database
177
+	 *
178
+	 * @param  string $table_link
179
+	 * @param  string $field_link
180
+	 * @param  string $field_object
181
+	 * @return bool   true on success
182
+	 */
183
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
184
+	{
185
+		/* clear forum-type links */
186
+		$sql = 'DELETE FROM ' . $this->db->prefix('newbb_type_forum') . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )";
187
+		$this->db->queryF($sql);
188
+
189
+		/* reconcile topic-type link */
190
+		$sql = 'UPATE ' . $this->db->prefix('newbb_topics') . " SET {$this->keyName} = 0" . " WHERE ({$this->keyName} NOT IN ( SELECT DISTINCT {$this->keyName} FROM {$this->table}) )";
191
+		$this->db->queryF($sql);
192
+
193
+		return true;
194
+	}
195 195
 }
Please login to merge, or discard this patch.
class/TextHandler.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,24 +19,24 @@
 block discarded – undo
19 19
  */
20 20
 class TextHandler extends \XoopsPersistableObjectHandler
21 21
 {
22
-    /**
23
-     * @param \XoopsDatabase $db
24
-     */
25
-    public function __construct(\XoopsDatabase $db)
26
-    {
27
-        parent::__construct($db, 'newbb_posts_text', Text::class, 'post_id', '');
28
-    }
22
+	/**
23
+	 * @param \XoopsDatabase $db
24
+	 */
25
+	public function __construct(\XoopsDatabase $db)
26
+	{
27
+		parent::__construct($db, 'newbb_posts_text', Text::class, 'post_id', '');
28
+	}
29 29
 
30
-    /**
31
-     * clean orphan items from database
32
-     *
33
-     * @param  string $table_link
34
-     * @param  string $field_link
35
-     * @param  string $field_object
36
-     * @return bool   true on success
37
-     */
38
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
39
-    {
40
-        return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id');
41
-    }
30
+	/**
31
+	 * clean orphan items from database
32
+	 *
33
+	 * @param  string $table_link
34
+	 * @param  string $field_link
35
+	 * @param  string $field_object
36
+	 * @return bool   true on success
37
+	 */
38
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
39
+	{
40
+		return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id');
41
+	}
42 42
 }
Please login to merge, or discard this patch.
class/ForumHandler.php 2 patches
Indentation   +1020 added lines, -1020 removed lines patch added patch discarded remove patch
@@ -26,613 +26,613 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class ForumHandler extends \XoopsPersistableObjectHandler
28 28
 {
29
-    /**
30
-     * @param null|\XoopsDatabase $db
31
-     */
32
-    public function __construct(\XoopsDatabase $db)
33
-    {
34
-        parent::__construct($db, 'newbb_forums', Forum::class, 'forum_id', 'forum_name');
35
-    }
36
-
37
-    /**
38
-     * @param \XoopsObject $object
39
-     * @param  bool        $force
40
-     * @return bool
41
-     * @internal param \XoopsObject $forum
42
-     */
43
-
44
-    public function insert(\XoopsObject $object, $force = true) //insert($forum)
45
-    {
46
-        $forum = $object;
47
-        if (!parent::insert($forum, true)) {
48
-            return false;
49
-        }
50
-
51
-        if ($forum->isNew()) {
52
-            $this->applyPermissionTemplate($forum);
53
-        }
54
-
55
-        return $forum->getVar('forum_id');
56
-    }
57
-
58
-    /**
59
-     * @param \XoopsObject $forum
60
-     * @param  bool        $force
61
-     * @return bool
62
-     */
63
-    public function delete(\XoopsObject $forum, $force = false) //delete(&$forum)
64
-    {
65
-        global $xoopsModule;
66
-        // RMV-NOTIFY
67
-        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id'));
68
-        // Get list of all topics in forum, to delete them too
69
-        /** @var Newbb\TopicHandler $topicHandler */
70
-        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
71
-        $topicHandler->deleteAll(new \Criteria('forum_id', $forum->getVar('forum_id')), true, true);
72
-        $this->updateAll('parent_forum', $forum->getVar('parent_forum'), new \Criteria('parent_forum', $forum->getVar('forum_id')));
73
-        $this->deletePermission($forum);
74
-
75
-        return parent::delete($forum);
76
-    }
77
-
78
-    /**
79
-     * @param  string $perm
80
-     * @return mixed
81
-     */
82
-    public function getIdsByPermission($perm = 'access')
83
-    {
84
-        /** var Newbb\PermissionHandler $permHandler */
85
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
86
-        return $permHandler->getForums($perm);
87
-    }
88
-
89
-    /**
90
-     * @param  int|array    $cat
91
-     * @param  string $permission
92
-     * @param  null   $tags
93
-     * @param  bool   $asObject
94
-     * @return array
95
-     */
96
-    public function &getByPermission($cat = 0, $permission = 'access', $tags = null, $asObject = true)
97
-    {
98
-        $_cachedForums = [];
99
-        if (!$valid_ids = $this->getIdsByPermission($permission)) {
100
-            return $_cachedForums;
101
-        }
102
-
103
-        $criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN'));
104
-        if (is_numeric($cat) && $cat > 0) {
105
-            $criteria->add(new \Criteria('cat_id', (int)$cat));
106
-        } elseif (is_array($cat) && count($cat) > 0) {
107
-            $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN'));
108
-        }
109
-        $criteria->setSort('forum_order');
110
-        $criteria->setOrder('ASC');
111
-        $_cachedForums = $this->getAll($criteria, $tags, $asObject);
112
-
113
-        return $_cachedForums;
114
-    }
115
-
116
-    /**
117
-     * @param  int    $categoryid
118
-     * @param  string $permission
119
-     * @param  bool   $asObject
120
-     * @param  null   $tags
121
-     * @return array
122
-     */
123
-    public function &getForumsByCategory($categoryid = 0, $permission = '', $asObject = true, $tags = null)
124
-    {
125
-        $forums = $this->getByPermission($categoryid, $permission, $tags);
126
-        if ($asObject) {
127
-            return $forums;
128
-        }
129
-
130
-        $forums_array = [];
131
-        $array_cat    = [];
132
-        $array_forum  = [];
133
-        if (!is_array($forums)) {
134
-            return [];
135
-        }
136
-        foreach (array_keys($forums) as $forumid) {
137
-            $forum                                                  = $forums[$forumid];
138
-            $forums_array[$forum->getVar('parent_forum')][$forumid] = [
139
-                'cid'   => $forum->getVar('cat_id'),
140
-                'title' => $forum->getVar('forum_name')
141
-            ];
142
-        }
143
-        if (!isset($forums_array[0])) {
144
-            $ret = [];
145
-
146
-            return $ret;
147
-        }
148
-        foreach ($forums_array[0] as $key => $forum) {
149
-            if (isset($forums_array[$key])) {
150
-                $forum['sub'] = $forums_array[$key];
151
-            }
152
-            $array_forum[$forum['cid']][$key] = $forum;
153
-        }
154
-        ksort($array_forum);
155
-        unset($forums, $forums_array);
156
-
157
-        return $array_forum;
158
-    }
159
-
160
-    /**
161
-     * @param        $forum
162
-     * @param  null  $criteria
163
-     * @return array
164
-     */
165
-    public function getAllTopics(&$forum, $criteria = null)
166
-    {
167
-        global $myts, $viewAllForums;
168
-        $startdate = '';
169
-
170
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
171
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
172
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
173
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
174
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.topic.php');
175
-
176
-        $criteria_vars = ['startdate', 'start', 'sort', 'order', 'type', 'status', 'excerpt'];
177
-        foreach ($criteria_vars as $var) {
178
-            ${$var} = $criteria[$var];
179
-        }
180
-
181
-        $topic_lastread = newbbGetCookie('LT', true);
182
-        $criteria_forum = '';
183
-        if (is_object($forum)) {
184
-            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
185
-            $hot_threshold  = $forum->getVar('hot_threshold');
186
-        } else {
187
-            $hot_threshold = 10;
188
-            if (is_array($forum) && count($forum) > 0) {
189
-                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
190
-            } elseif (!empty($forum)) {
191
-                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
192
-            }
193
-        }
194
-
195
-        $criteria_post    = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 ';
196
-        $criteria_topic   = empty($type) ? '' : " AND t.type_id={$type}";
197
-        $criteria_extra   = '';
198
-        $criteria_approve = ' AND t.approved = 1';
199
-        $post_on          = ' p.post_id = t.topic_last_post_id';
200
-        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
201
-        $sort_array       = [];
202
-        switch ($status) {
203
-            case 'digest':
204
-                $criteria_extra = ' AND t.topic_digest = 1';
205
-                break;
206
-
207
-            case 'unreplied':
208
-                $criteria_extra = ' AND t.topic_replies < 1';
209
-                break;
210
-
211
-            case 'unread':
212
-                if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
213
-                } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
214
-                    // START irmtfan use read_uid to find the unread posts when the user is logged in
215
-                    $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
216
-                    if (!empty($read_uid)) {
217
-                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
218
-                        $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
219
-                    } else {
220
-                    }
221
-                    // END irmtfan use read_uid to find the unread posts when the user is logged in
222
-                } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
223
-                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
224
-                    if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
225
-                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
226
-                        $topics         = [];
227
-                        $topic_lastread = newbbGetCookie('LT', true);
228
-                        if (count($topic_lastread) > 0) {
229
-                            foreach ($topic_lastread as $id => $time) {
230
-                                if ($time > $time_criterion) {
231
-                                    $topics[] = $id;
232
-                                }
233
-                            }
234
-                        }
235
-                        if (count($topics) > 0) {
236
-                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
237
-                        }
238
-                    }
239
-                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
240
-                }
241
-                break;
242
-            case 'pending':
243
-                $post_on          = ' p.topic_id = t.topic_id';
244
-                $criteria_post    .= ' AND p.pid = 0';
245
-                $criteria_approve = ' AND t.approved = 0';
246
-                break;
247
-
248
-            case 'deleted':
249
-                $criteria_approve = ' AND t.approved = -1';
250
-                break;
251
-
252
-            case 'all': // For viewall.php; do not display sticky topics at first
253
-            case 'active': // same as "all"
254
-                break;
255
-
256
-            default:
257
-                if ($startdate > 0) {
258
-                    $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
259
-                }
260
-                $sort_array[] = 't.topic_sticky DESC';
261
-                break;
262
-        }
263
-
264
-        $select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
265
-        $from   = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
266
-        $where  = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve;
267
-
268
-        if ($excerpt) {
269
-            $select .= ', p.post_karma, p.require_reply, pt.post_text';
270
-            $from   .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id';
271
-        }
272
-        if ('u.uname' === $sort) {
273
-            $sort = 't.topic_poster';
274
-        }
275
-
276
-        $sort_array[] = trim($sort . ' ' . $order);
277
-        $sortby       = implode(', ', array_filter($sort_array));
278
-        if (empty($sortby)) {
279
-            $sortby = 't.topic_last_post_id DESC';
280
-        }
281
-
282
-        $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby;
283
-
284
-        if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) {
285
-            redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED);
286
-        }
287
-
288
-        $sticky  = 0;
289
-        $topics  = [];
290
-        $posters = [];
291
-        $reads   = [];
292
-        $types   = [];
293
-
294
-        /** @var Newbb\TypeHandler $typeHandler */
295
-        $typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
296
-        $typen       = $typeHandler->getByForum($forum->getVar('forum_id'));
297
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
298
-            if ($myrow['topic_sticky']) {
299
-                ++$sticky;
300
-            }
301
-
302
-            // ------------------------------------------------------
303
-            // topic_icon: priority: sticky -> digest -> regular
304
-
305
-            if ($myrow['topic_haspoll']) {
306
-                if ($myrow['topic_sticky']) {
307
-                    $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
308
-                } else {
309
-                    $topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
310
-                }
311
-            } elseif ($myrow['topic_sticky']) {
312
-                $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY);
313
-            } elseif (!empty($myrow['icon'])) {
314
-                $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />';
315
-            } else {
316
-                $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
317
-            }
318
-
319
-            // ------------------------------------------------------
320
-            // rating_img
321
-            $rating = number_format($myrow['rating'] / 2, 0);
322
-            // irmtfan - add alt key for rating
323
-            if ($rating < 1) {
324
-                $rating_img = newbbDisplayImage('blank');
325
-            } else {
326
-                $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating));
327
-            }
328
-            // ------------------------------------------------------
329
-            // topic_page_jump
330
-            $topic_page_jump      = '';
331
-            $topic_page_jump_icon = '';
332
-            $totalpages           = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']);
333
-            if ($totalpages > 1) {
334
-                $topic_page_jump .= '&nbsp;&nbsp;';
335
-                $append          = false;
336
-                for ($i = 1; $i <= $totalpages; ++$i) {
337
-                    if ($i > 3 && $i < $totalpages) {
338
-                        if (!$append) {
339
-                            $topic_page_jump .= '...';
340
-                            $append          = true;
341
-                        }
342
-                    } else {
343
-                        $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]';
344
-                        // irmtfan remove here and move
345
-                        //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&amp;start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>';
346
-                    }
347
-                }
348
-            }
349
-            // irmtfan - move here for both topics with and without pages
350
-            $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>';
351
-
352
-            // ------------------------------------------------------
353
-            // => topic array
354
-            $forum_link = '';
355
-            if (!empty($viewAllForums[$myrow['forum_id']])) {
356
-                $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>';
357
-            }
358
-
359
-            $topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
360
-            // irmtfan remove here and move to for loop
361
-            //if ($myrow['type_id'] > 0) {
362
-            //$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.'';
363
-            //}
364
-            if ($myrow['topic_digest']) {
365
-                $topic_title = "<span class='digest'>" . $topic_title . '</span>';
366
-            }
367
-
368
-            if (0 == $excerpt) {
369
-                $topic_excerpt = '';
370
-            } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($forum)) {
371
-                $topic_excerpt = '';
372
-            } else {
373
-                $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt);
374
-                $topic_excerpt = str_replace('[', '&#91;', $myts->htmlSpecialChars($topic_excerpt));
375
-            }
376
-            // START irmtfan move here
377
-            $topics[$myrow['topic_id']] = [
378
-                'topic_id'             => $myrow['topic_id'],
379
-                'topic_icon'           => $topic_icon,
380
-                'type_id'              => $myrow['type_id'],
381
-                //'type_text'                 => $topic_prefix,/*irmtfan remove here and move to for loop*/
382
-                'topic_title'          => $topic_title,
383
-                //'topic_link'                => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'],
384
-                'topic_link'           => 'viewtopic.php?topic_id=' . $myrow['topic_id'],
385
-                'rating_img'           => $rating_img,
386
-                'topic_page_jump'      => $topic_page_jump,
387
-                'topic_page_jump_icon' => $topic_page_jump_icon,
388
-                'topic_replies'        => $myrow['topic_replies'],
389
-
390
-                'topic_digest' => $myrow['topic_digest'],
391
-                //mb
392
-
393
-                'topic_poster_uid'       => $myrow['topic_poster'],
394
-                'topic_poster_name'      => $myts->htmlSpecialChars($myrow['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
395
-                'topic_views'            => $myrow['topic_views'],
396
-                'topic_time'             => newbbFormatTimestamp($myrow['topic_time']),
397
-                'topic_last_posttime'    => newbbFormatTimestamp($myrow['last_post_time']),
398
-                'topic_last_poster_uid'  => $myrow['uid'],
399
-                'topic_last_poster_name' => $myts->htmlSpecialChars($myrow['last_poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
400
-                'topic_forum_link'       => $forum_link,
401
-                'topic_excerpt'          => $topic_excerpt,
402
-                'stick'                  => empty($myrow['topic_sticky']),
403
-                'stats'                  => [
404
-                    $myrow['topic_status'],
405
-                    $myrow['topic_digest'],
406
-                    $myrow['topic_replies']
407
-                ],
408
-                /* irmtfan uncomment use ib the for loop*/
409
-                //"topic_poster"              => $topic_poster,/*irmtfan remove here and move to for loop*/
410
-                //"topic_last_poster"         => $topic_last_poster,/*irmtfan remove here and move to for loop*/
411
-                //"topic_folder"              => newbbDisplayImage($topic_folder,$topic_folder_text),/*irmtfan remove here and move to for loop*/
412
-            ];
413
-            // END irmtfan move here
414
-            /* users */
415
-            $posters[$myrow['topic_poster']] = 1;
416
-            $posters[$myrow['uid']]          = 1;
417
-            // reads
418
-            if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
419
-                $reads[$myrow['topic_id']] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id'];
420
-            }
421
-        }// irmtfan while end
422
-        // START irmtfan move to a for loop
423
-        $posters_name = newbbGetUnameFromIds(array_keys($posters), $GLOBALS['xoopsModuleConfig']['show_realname'], true);
424
-        //$topic_poster = newbbGetUnameFromId($myrow['topic_poster'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
425
-        //$topic_last_poster = newbbGetUnameFromId($myrow['uid'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
426
-        $topic_isRead = newbbIsRead('topic', $reads);
427
-        foreach (array_keys($topics) as $id) {
428
-            $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable
429
-            if (!empty($topics[$id]['type_id']) && isset($typen[$topics[$id]['type_id']])) {
430
-                $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title'], $typen[$topics[$id]['type_id']]['type_name'], $typen[$topics[$id]['type_id']]['type_color']);
431
-            }
432
-            //$topic_prefix =  (!empty($typen[$myrow['type_id']])) ? getTopicTitle("", $typen[$myrow['type_id']]["type_name"], $typen[$myrow['type_id']]["type_color"]) : "";
433
-            $topics[$id]['topic_poster']      = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name'];
434
-            $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name'];
435
-
436
-            // ------------------------------------------------------
437
-            // topic_folder: priority: newhot -> hot/new -> regular
438
-            list($topic_status, $topic_digest, $topic_replies) = $topics[$id]['stats'];
439
-            if (1 == $topic_status) {
440
-                $topic_folder      = 'topic_locked';
441
-                $topic_folder_text = _MD_NEWBB_TOPICLOCKED;
442
-            } else {
443
-                if ($topic_digest) {
444
-                    $topic_folder      = 'topic_digest';
445
-                    $topic_folder_text = _MD_NEWBB_TOPICDIGEST;
446
-                } elseif ($topic_replies >= $hot_threshold) {
447
-                    $topic_folder      = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot';
448
-                    $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2;
449
-                } else {
450
-                    $topic_folder      = empty($topic_isRead[$id]) ? 'topic_new' : 'topic';
451
-                    $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS;
452
-                }
453
-            }
454
-            $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text);
455
-            unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name'], $topics[$id]['stats']);
456
-        } // irmtfan end for loop
457
-        // END irmtfan move to a for loop
458
-        if (count($topics) > 0) {
459
-            $sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')';
460
-            if ($result = $this->db->query($sql)) {
461
-                while (false !== (list($topic_id) = $this->db->fetchRow($result))) {
462
-                    $topics[$topic_id]['attachment'] = '&nbsp;' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT);
463
-                }
464
-            }
465
-        }
466
-
467
-        return [$topics, $sticky];
468
-    }
469
-
470
-    /**
471
-     * @param $forum
472
-     * @param $startdate
473
-     * @param $type
474
-     * @return null|int
475
-     */
476
-    public function getTopicCount(&$forum, $startdate, $type)
477
-    {
478
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
479
-
480
-        $criteria_extra   = '';
481
-        $criteria_approve = ' AND t.approved = 1'; // any others?
482
-        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
483
-        $criteria_post    = ' p.post_time > ' . $startdate;
484
-        switch ($type) {
485
-            case 'digest':
486
-                $criteria_extra = ' AND topic_digest = 1';
487
-                break;
488
-            case 'unreplied':
489
-                $criteria_extra = ' AND topic_replies < 1';
490
-                break;
491
-            case 'unread':
492
-                if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
493
-                } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
494
-                    // START irmtfan use read_uid to find the unread posts when the user is logged in
495
-
496
-                    $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
497
-                    if (!empty($read_uid)) {
498
-                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
499
-                        $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
500
-                    } else {
501
-                    }
502
-                    // END irmtfan use read_uid to find the unread posts when the user is logged in
503
-                } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
504
-                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
505
-                    if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
506
-                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
507
-                        $topics         = [];
508
-                        $topic_lastread = newbbGetCookie('LT', true);
509
-                        if (count($topic_lastread) > 0) {
510
-                            foreach ($topic_lastread as $id => $time) {
511
-                                if ($time > $time_criterion) {
512
-                                    $topics[] = $id;
513
-                                }
514
-                            }
515
-                        }
516
-                        if (count($topics) > 0) {
517
-                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
518
-                        }
519
-                    }
520
-                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
521
-                }
522
-                break;
523
-            case 'pending':
524
-                $criteria_approve = ' AND t.approved = 0';
525
-                break;
526
-            case 'deleted':
527
-                $criteria_approve = ' AND t.approved = -1';
528
-                break;
529
-            case 'all':
530
-                break;
531
-            default:
532
-                $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
533
-                break;
534
-        }
535
-        $criteria_forum = '';
536
-        if (is_object($forum)) {
537
-            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
538
-        } else {
539
-            if (is_array($forum) && count($forum) > 0) {
540
-                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
541
-            } elseif (!empty($forum)) {
542
-                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
543
-            }
544
-        }
545
-
546
-        $sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
547
-        $sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve;
548
-        if (!$result = $this->db->query($sql)) {
549
-            //xoops_error($this->db->error().'<br>'.$sql);
550
-            return null;
551
-        }
552
-        $myrow = $this->db->fetchArray($result);
553
-        $count = $myrow['count'];
554
-
555
-        return $count;
556
-    }
557
-
558
-    // get permission
559
-
560
-    /**
561
-     * @param         $forum
562
-     * @param  string $type
563
-     * @param  bool   $checkCategory
564
-     * @return bool
565
-     */
566
-    public function getPermission($forum, $type = 'access', $checkCategory = true)
567
-    {
568
-        global $xoopsModule;
569
-        static $_cachedPerms;
570
-
571
-        if ('all' === $type) {
572
-            return true;
573
-        }
574
-
575
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
576
-        if (newbbIsAdmin($forum)) {
577
-            return true;
578
-        }
579
-        //if ($GLOBALS["xoopsUserIsAdmin"] && $xoopsModule->getVar("dirname") === "newbb") {
580
-        //return true;
581
-        //}
582
-
583
-        if (!is_object($forum)) {
584
-            $forum = $this->get($forum);
585
-        }
586
-
587
-        if (!empty($checkCategory)) {
588
-            /** @var Newbb\CategoryHandler $categoryHandler */
589
-            $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
590
-            $categoryPerm    = $categoryHandler->getPermission($forum->getVar('cat_id'));
591
-            if (!$categoryPerm) {
592
-                return false;
593
-            }
594
-        }
595
-
596
-        $type = strtolower($type);
597
-        // START irmtfan commented and removed
598
-        //if ('moderate' === $type) {
599
-        //require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
600
-        //$permission = newbbIsModerator($forum);
601
-        //} else {
602
-        $forum_id = $forum->getVar('forum_id');
603
-        /** var Newbb\PermissionHandler $permHandler */
604
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
605
-        $permission  = $permHandler->getPermission('forum', $type, $forum_id);
606
-        //}
607
-        // END irmtfan commented and removed
608
-        return $permission;
609
-    }
610
-
611
-    /**
612
-     * @param $forum
613
-     * @return mixed
614
-     */
615
-    public function deletePermission(&$forum)
616
-    {
617
-        /** var Newbb\PermissionHandler $permHandler */
618
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
619
-
620
-        return $permHandler->deleteByForum($forum->getVar('forum_id'));
621
-    }
622
-
623
-    /**
624
-     * @param $forum
625
-     * @return mixed
626
-     */
627
-    public function applyPermissionTemplate(&$forum)
628
-    {
629
-        /** var Newbb\PermissionHandler $permHandler */
630
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
631
-
632
-        return $permHandler->applyTemplate($forum->getVar('forum_id'));
633
-    }
634
-
635
-    /*
29
+	/**
30
+	 * @param null|\XoopsDatabase $db
31
+	 */
32
+	public function __construct(\XoopsDatabase $db)
33
+	{
34
+		parent::__construct($db, 'newbb_forums', Forum::class, 'forum_id', 'forum_name');
35
+	}
36
+
37
+	/**
38
+	 * @param \XoopsObject $object
39
+	 * @param  bool        $force
40
+	 * @return bool
41
+	 * @internal param \XoopsObject $forum
42
+	 */
43
+
44
+	public function insert(\XoopsObject $object, $force = true) //insert($forum)
45
+	{
46
+		$forum = $object;
47
+		if (!parent::insert($forum, true)) {
48
+			return false;
49
+		}
50
+
51
+		if ($forum->isNew()) {
52
+			$this->applyPermissionTemplate($forum);
53
+		}
54
+
55
+		return $forum->getVar('forum_id');
56
+	}
57
+
58
+	/**
59
+	 * @param \XoopsObject $forum
60
+	 * @param  bool        $force
61
+	 * @return bool
62
+	 */
63
+	public function delete(\XoopsObject $forum, $force = false) //delete(&$forum)
64
+	{
65
+		global $xoopsModule;
66
+		// RMV-NOTIFY
67
+		xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id'));
68
+		// Get list of all topics in forum, to delete them too
69
+		/** @var Newbb\TopicHandler $topicHandler */
70
+		$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
71
+		$topicHandler->deleteAll(new \Criteria('forum_id', $forum->getVar('forum_id')), true, true);
72
+		$this->updateAll('parent_forum', $forum->getVar('parent_forum'), new \Criteria('parent_forum', $forum->getVar('forum_id')));
73
+		$this->deletePermission($forum);
74
+
75
+		return parent::delete($forum);
76
+	}
77
+
78
+	/**
79
+	 * @param  string $perm
80
+	 * @return mixed
81
+	 */
82
+	public function getIdsByPermission($perm = 'access')
83
+	{
84
+		/** var Newbb\PermissionHandler $permHandler */
85
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
86
+		return $permHandler->getForums($perm);
87
+	}
88
+
89
+	/**
90
+	 * @param  int|array    $cat
91
+	 * @param  string $permission
92
+	 * @param  null   $tags
93
+	 * @param  bool   $asObject
94
+	 * @return array
95
+	 */
96
+	public function &getByPermission($cat = 0, $permission = 'access', $tags = null, $asObject = true)
97
+	{
98
+		$_cachedForums = [];
99
+		if (!$valid_ids = $this->getIdsByPermission($permission)) {
100
+			return $_cachedForums;
101
+		}
102
+
103
+		$criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN'));
104
+		if (is_numeric($cat) && $cat > 0) {
105
+			$criteria->add(new \Criteria('cat_id', (int)$cat));
106
+		} elseif (is_array($cat) && count($cat) > 0) {
107
+			$criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN'));
108
+		}
109
+		$criteria->setSort('forum_order');
110
+		$criteria->setOrder('ASC');
111
+		$_cachedForums = $this->getAll($criteria, $tags, $asObject);
112
+
113
+		return $_cachedForums;
114
+	}
115
+
116
+	/**
117
+	 * @param  int    $categoryid
118
+	 * @param  string $permission
119
+	 * @param  bool   $asObject
120
+	 * @param  null   $tags
121
+	 * @return array
122
+	 */
123
+	public function &getForumsByCategory($categoryid = 0, $permission = '', $asObject = true, $tags = null)
124
+	{
125
+		$forums = $this->getByPermission($categoryid, $permission, $tags);
126
+		if ($asObject) {
127
+			return $forums;
128
+		}
129
+
130
+		$forums_array = [];
131
+		$array_cat    = [];
132
+		$array_forum  = [];
133
+		if (!is_array($forums)) {
134
+			return [];
135
+		}
136
+		foreach (array_keys($forums) as $forumid) {
137
+			$forum                                                  = $forums[$forumid];
138
+			$forums_array[$forum->getVar('parent_forum')][$forumid] = [
139
+				'cid'   => $forum->getVar('cat_id'),
140
+				'title' => $forum->getVar('forum_name')
141
+			];
142
+		}
143
+		if (!isset($forums_array[0])) {
144
+			$ret = [];
145
+
146
+			return $ret;
147
+		}
148
+		foreach ($forums_array[0] as $key => $forum) {
149
+			if (isset($forums_array[$key])) {
150
+				$forum['sub'] = $forums_array[$key];
151
+			}
152
+			$array_forum[$forum['cid']][$key] = $forum;
153
+		}
154
+		ksort($array_forum);
155
+		unset($forums, $forums_array);
156
+
157
+		return $array_forum;
158
+	}
159
+
160
+	/**
161
+	 * @param        $forum
162
+	 * @param  null  $criteria
163
+	 * @return array
164
+	 */
165
+	public function getAllTopics(&$forum, $criteria = null)
166
+	{
167
+		global $myts, $viewAllForums;
168
+		$startdate = '';
169
+
170
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
171
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
172
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
173
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
174
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.topic.php');
175
+
176
+		$criteria_vars = ['startdate', 'start', 'sort', 'order', 'type', 'status', 'excerpt'];
177
+		foreach ($criteria_vars as $var) {
178
+			${$var} = $criteria[$var];
179
+		}
180
+
181
+		$topic_lastread = newbbGetCookie('LT', true);
182
+		$criteria_forum = '';
183
+		if (is_object($forum)) {
184
+			$criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
185
+			$hot_threshold  = $forum->getVar('hot_threshold');
186
+		} else {
187
+			$hot_threshold = 10;
188
+			if (is_array($forum) && count($forum) > 0) {
189
+				$criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
190
+			} elseif (!empty($forum)) {
191
+				$criteria_forum = ' AND t.forum_id =' . (int)$forum;
192
+			}
193
+		}
194
+
195
+		$criteria_post    = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 ';
196
+		$criteria_topic   = empty($type) ? '' : " AND t.type_id={$type}";
197
+		$criteria_extra   = '';
198
+		$criteria_approve = ' AND t.approved = 1';
199
+		$post_on          = ' p.post_id = t.topic_last_post_id';
200
+		$leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
201
+		$sort_array       = [];
202
+		switch ($status) {
203
+			case 'digest':
204
+				$criteria_extra = ' AND t.topic_digest = 1';
205
+				break;
206
+
207
+			case 'unreplied':
208
+				$criteria_extra = ' AND t.topic_replies < 1';
209
+				break;
210
+
211
+			case 'unread':
212
+				if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
213
+				} elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
214
+					// START irmtfan use read_uid to find the unread posts when the user is logged in
215
+					$read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
216
+					if (!empty($read_uid)) {
217
+						$leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
218
+						$criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
219
+					} else {
220
+					}
221
+					// END irmtfan use read_uid to find the unread posts when the user is logged in
222
+				} elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
223
+					// START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
224
+					if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
225
+						$criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
226
+						$topics         = [];
227
+						$topic_lastread = newbbGetCookie('LT', true);
228
+						if (count($topic_lastread) > 0) {
229
+							foreach ($topic_lastread as $id => $time) {
230
+								if ($time > $time_criterion) {
231
+									$topics[] = $id;
232
+								}
233
+							}
234
+						}
235
+						if (count($topics) > 0) {
236
+							$criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
237
+						}
238
+					}
239
+					// END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
240
+				}
241
+				break;
242
+			case 'pending':
243
+				$post_on          = ' p.topic_id = t.topic_id';
244
+				$criteria_post    .= ' AND p.pid = 0';
245
+				$criteria_approve = ' AND t.approved = 0';
246
+				break;
247
+
248
+			case 'deleted':
249
+				$criteria_approve = ' AND t.approved = -1';
250
+				break;
251
+
252
+			case 'all': // For viewall.php; do not display sticky topics at first
253
+			case 'active': // same as "all"
254
+				break;
255
+
256
+			default:
257
+				if ($startdate > 0) {
258
+					$criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
259
+				}
260
+				$sort_array[] = 't.topic_sticky DESC';
261
+				break;
262
+		}
263
+
264
+		$select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
265
+		$from   = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
266
+		$where  = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve;
267
+
268
+		if ($excerpt) {
269
+			$select .= ', p.post_karma, p.require_reply, pt.post_text';
270
+			$from   .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id';
271
+		}
272
+		if ('u.uname' === $sort) {
273
+			$sort = 't.topic_poster';
274
+		}
275
+
276
+		$sort_array[] = trim($sort . ' ' . $order);
277
+		$sortby       = implode(', ', array_filter($sort_array));
278
+		if (empty($sortby)) {
279
+			$sortby = 't.topic_last_post_id DESC';
280
+		}
281
+
282
+		$sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby;
283
+
284
+		if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) {
285
+			redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED);
286
+		}
287
+
288
+		$sticky  = 0;
289
+		$topics  = [];
290
+		$posters = [];
291
+		$reads   = [];
292
+		$types   = [];
293
+
294
+		/** @var Newbb\TypeHandler $typeHandler */
295
+		$typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
296
+		$typen       = $typeHandler->getByForum($forum->getVar('forum_id'));
297
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
298
+			if ($myrow['topic_sticky']) {
299
+				++$sticky;
300
+			}
301
+
302
+			// ------------------------------------------------------
303
+			// topic_icon: priority: sticky -> digest -> regular
304
+
305
+			if ($myrow['topic_haspoll']) {
306
+				if ($myrow['topic_sticky']) {
307
+					$topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
308
+				} else {
309
+					$topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
310
+				}
311
+			} elseif ($myrow['topic_sticky']) {
312
+				$topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY);
313
+			} elseif (!empty($myrow['icon'])) {
314
+				$topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />';
315
+			} else {
316
+				$topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
317
+			}
318
+
319
+			// ------------------------------------------------------
320
+			// rating_img
321
+			$rating = number_format($myrow['rating'] / 2, 0);
322
+			// irmtfan - add alt key for rating
323
+			if ($rating < 1) {
324
+				$rating_img = newbbDisplayImage('blank');
325
+			} else {
326
+				$rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating));
327
+			}
328
+			// ------------------------------------------------------
329
+			// topic_page_jump
330
+			$topic_page_jump      = '';
331
+			$topic_page_jump_icon = '';
332
+			$totalpages           = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']);
333
+			if ($totalpages > 1) {
334
+				$topic_page_jump .= '&nbsp;&nbsp;';
335
+				$append          = false;
336
+				for ($i = 1; $i <= $totalpages; ++$i) {
337
+					if ($i > 3 && $i < $totalpages) {
338
+						if (!$append) {
339
+							$topic_page_jump .= '...';
340
+							$append          = true;
341
+						}
342
+					} else {
343
+						$topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]';
344
+						// irmtfan remove here and move
345
+						//$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&amp;start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>';
346
+					}
347
+				}
348
+			}
349
+			// irmtfan - move here for both topics with and without pages
350
+			$topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>';
351
+
352
+			// ------------------------------------------------------
353
+			// => topic array
354
+			$forum_link = '';
355
+			if (!empty($viewAllForums[$myrow['forum_id']])) {
356
+				$forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>';
357
+			}
358
+
359
+			$topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
360
+			// irmtfan remove here and move to for loop
361
+			//if ($myrow['type_id'] > 0) {
362
+			//$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.'';
363
+			//}
364
+			if ($myrow['topic_digest']) {
365
+				$topic_title = "<span class='digest'>" . $topic_title . '</span>';
366
+			}
367
+
368
+			if (0 == $excerpt) {
369
+				$topic_excerpt = '';
370
+			} elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($forum)) {
371
+				$topic_excerpt = '';
372
+			} else {
373
+				$topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt);
374
+				$topic_excerpt = str_replace('[', '&#91;', $myts->htmlSpecialChars($topic_excerpt));
375
+			}
376
+			// START irmtfan move here
377
+			$topics[$myrow['topic_id']] = [
378
+				'topic_id'             => $myrow['topic_id'],
379
+				'topic_icon'           => $topic_icon,
380
+				'type_id'              => $myrow['type_id'],
381
+				//'type_text'                 => $topic_prefix,/*irmtfan remove here and move to for loop*/
382
+				'topic_title'          => $topic_title,
383
+				//'topic_link'                => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'],
384
+				'topic_link'           => 'viewtopic.php?topic_id=' . $myrow['topic_id'],
385
+				'rating_img'           => $rating_img,
386
+				'topic_page_jump'      => $topic_page_jump,
387
+				'topic_page_jump_icon' => $topic_page_jump_icon,
388
+				'topic_replies'        => $myrow['topic_replies'],
389
+
390
+				'topic_digest' => $myrow['topic_digest'],
391
+				//mb
392
+
393
+				'topic_poster_uid'       => $myrow['topic_poster'],
394
+				'topic_poster_name'      => $myts->htmlSpecialChars($myrow['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
395
+				'topic_views'            => $myrow['topic_views'],
396
+				'topic_time'             => newbbFormatTimestamp($myrow['topic_time']),
397
+				'topic_last_posttime'    => newbbFormatTimestamp($myrow['last_post_time']),
398
+				'topic_last_poster_uid'  => $myrow['uid'],
399
+				'topic_last_poster_name' => $myts->htmlSpecialChars($myrow['last_poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
400
+				'topic_forum_link'       => $forum_link,
401
+				'topic_excerpt'          => $topic_excerpt,
402
+				'stick'                  => empty($myrow['topic_sticky']),
403
+				'stats'                  => [
404
+					$myrow['topic_status'],
405
+					$myrow['topic_digest'],
406
+					$myrow['topic_replies']
407
+				],
408
+				/* irmtfan uncomment use ib the for loop*/
409
+				//"topic_poster"              => $topic_poster,/*irmtfan remove here and move to for loop*/
410
+				//"topic_last_poster"         => $topic_last_poster,/*irmtfan remove here and move to for loop*/
411
+				//"topic_folder"              => newbbDisplayImage($topic_folder,$topic_folder_text),/*irmtfan remove here and move to for loop*/
412
+			];
413
+			// END irmtfan move here
414
+			/* users */
415
+			$posters[$myrow['topic_poster']] = 1;
416
+			$posters[$myrow['uid']]          = 1;
417
+			// reads
418
+			if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
419
+				$reads[$myrow['topic_id']] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id'];
420
+			}
421
+		}// irmtfan while end
422
+		// START irmtfan move to a for loop
423
+		$posters_name = newbbGetUnameFromIds(array_keys($posters), $GLOBALS['xoopsModuleConfig']['show_realname'], true);
424
+		//$topic_poster = newbbGetUnameFromId($myrow['topic_poster'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
425
+		//$topic_last_poster = newbbGetUnameFromId($myrow['uid'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
426
+		$topic_isRead = newbbIsRead('topic', $reads);
427
+		foreach (array_keys($topics) as $id) {
428
+			$topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable
429
+			if (!empty($topics[$id]['type_id']) && isset($typen[$topics[$id]['type_id']])) {
430
+				$topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title'], $typen[$topics[$id]['type_id']]['type_name'], $typen[$topics[$id]['type_id']]['type_color']);
431
+			}
432
+			//$topic_prefix =  (!empty($typen[$myrow['type_id']])) ? getTopicTitle("", $typen[$myrow['type_id']]["type_name"], $typen[$myrow['type_id']]["type_color"]) : "";
433
+			$topics[$id]['topic_poster']      = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name'];
434
+			$topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name'];
435
+
436
+			// ------------------------------------------------------
437
+			// topic_folder: priority: newhot -> hot/new -> regular
438
+			list($topic_status, $topic_digest, $topic_replies) = $topics[$id]['stats'];
439
+			if (1 == $topic_status) {
440
+				$topic_folder      = 'topic_locked';
441
+				$topic_folder_text = _MD_NEWBB_TOPICLOCKED;
442
+			} else {
443
+				if ($topic_digest) {
444
+					$topic_folder      = 'topic_digest';
445
+					$topic_folder_text = _MD_NEWBB_TOPICDIGEST;
446
+				} elseif ($topic_replies >= $hot_threshold) {
447
+					$topic_folder      = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot';
448
+					$topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2;
449
+				} else {
450
+					$topic_folder      = empty($topic_isRead[$id]) ? 'topic_new' : 'topic';
451
+					$topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS;
452
+				}
453
+			}
454
+			$topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text);
455
+			unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name'], $topics[$id]['stats']);
456
+		} // irmtfan end for loop
457
+		// END irmtfan move to a for loop
458
+		if (count($topics) > 0) {
459
+			$sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')';
460
+			if ($result = $this->db->query($sql)) {
461
+				while (false !== (list($topic_id) = $this->db->fetchRow($result))) {
462
+					$topics[$topic_id]['attachment'] = '&nbsp;' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT);
463
+				}
464
+			}
465
+		}
466
+
467
+		return [$topics, $sticky];
468
+	}
469
+
470
+	/**
471
+	 * @param $forum
472
+	 * @param $startdate
473
+	 * @param $type
474
+	 * @return null|int
475
+	 */
476
+	public function getTopicCount(&$forum, $startdate, $type)
477
+	{
478
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
479
+
480
+		$criteria_extra   = '';
481
+		$criteria_approve = ' AND t.approved = 1'; // any others?
482
+		$leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
483
+		$criteria_post    = ' p.post_time > ' . $startdate;
484
+		switch ($type) {
485
+			case 'digest':
486
+				$criteria_extra = ' AND topic_digest = 1';
487
+				break;
488
+			case 'unreplied':
489
+				$criteria_extra = ' AND topic_replies < 1';
490
+				break;
491
+			case 'unread':
492
+				if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
493
+				} elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
494
+					// START irmtfan use read_uid to find the unread posts when the user is logged in
495
+
496
+					$read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
497
+					if (!empty($read_uid)) {
498
+						$leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
499
+						$criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
500
+					} else {
501
+					}
502
+					// END irmtfan use read_uid to find the unread posts when the user is logged in
503
+				} elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
504
+					// START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
505
+					if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
506
+						$criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
507
+						$topics         = [];
508
+						$topic_lastread = newbbGetCookie('LT', true);
509
+						if (count($topic_lastread) > 0) {
510
+							foreach ($topic_lastread as $id => $time) {
511
+								if ($time > $time_criterion) {
512
+									$topics[] = $id;
513
+								}
514
+							}
515
+						}
516
+						if (count($topics) > 0) {
517
+							$criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
518
+						}
519
+					}
520
+					// END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
521
+				}
522
+				break;
523
+			case 'pending':
524
+				$criteria_approve = ' AND t.approved = 0';
525
+				break;
526
+			case 'deleted':
527
+				$criteria_approve = ' AND t.approved = -1';
528
+				break;
529
+			case 'all':
530
+				break;
531
+			default:
532
+				$criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
533
+				break;
534
+		}
535
+		$criteria_forum = '';
536
+		if (is_object($forum)) {
537
+			$criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
538
+		} else {
539
+			if (is_array($forum) && count($forum) > 0) {
540
+				$criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
541
+			} elseif (!empty($forum)) {
542
+				$criteria_forum = ' AND t.forum_id =' . (int)$forum;
543
+			}
544
+		}
545
+
546
+		$sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
547
+		$sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve;
548
+		if (!$result = $this->db->query($sql)) {
549
+			//xoops_error($this->db->error().'<br>'.$sql);
550
+			return null;
551
+		}
552
+		$myrow = $this->db->fetchArray($result);
553
+		$count = $myrow['count'];
554
+
555
+		return $count;
556
+	}
557
+
558
+	// get permission
559
+
560
+	/**
561
+	 * @param         $forum
562
+	 * @param  string $type
563
+	 * @param  bool   $checkCategory
564
+	 * @return bool
565
+	 */
566
+	public function getPermission($forum, $type = 'access', $checkCategory = true)
567
+	{
568
+		global $xoopsModule;
569
+		static $_cachedPerms;
570
+
571
+		if ('all' === $type) {
572
+			return true;
573
+		}
574
+
575
+		require_once  dirname(__DIR__) . '/include/functions.user.php';
576
+		if (newbbIsAdmin($forum)) {
577
+			return true;
578
+		}
579
+		//if ($GLOBALS["xoopsUserIsAdmin"] && $xoopsModule->getVar("dirname") === "newbb") {
580
+		//return true;
581
+		//}
582
+
583
+		if (!is_object($forum)) {
584
+			$forum = $this->get($forum);
585
+		}
586
+
587
+		if (!empty($checkCategory)) {
588
+			/** @var Newbb\CategoryHandler $categoryHandler */
589
+			$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
590
+			$categoryPerm    = $categoryHandler->getPermission($forum->getVar('cat_id'));
591
+			if (!$categoryPerm) {
592
+				return false;
593
+			}
594
+		}
595
+
596
+		$type = strtolower($type);
597
+		// START irmtfan commented and removed
598
+		//if ('moderate' === $type) {
599
+		//require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
600
+		//$permission = newbbIsModerator($forum);
601
+		//} else {
602
+		$forum_id = $forum->getVar('forum_id');
603
+		/** var Newbb\PermissionHandler $permHandler */
604
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
605
+		$permission  = $permHandler->getPermission('forum', $type, $forum_id);
606
+		//}
607
+		// END irmtfan commented and removed
608
+		return $permission;
609
+	}
610
+
611
+	/**
612
+	 * @param $forum
613
+	 * @return mixed
614
+	 */
615
+	public function deletePermission(&$forum)
616
+	{
617
+		/** var Newbb\PermissionHandler $permHandler */
618
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
619
+
620
+		return $permHandler->deleteByForum($forum->getVar('forum_id'));
621
+	}
622
+
623
+	/**
624
+	 * @param $forum
625
+	 * @return mixed
626
+	 */
627
+	public function applyPermissionTemplate(&$forum)
628
+	{
629
+		/** var Newbb\PermissionHandler $permHandler */
630
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
631
+
632
+		return $permHandler->applyTemplate($forum->getVar('forum_id'));
633
+	}
634
+
635
+	/*
636 636
     function isForum($forum)
637 637
     {
638 638
         $count = false;
@@ -647,422 +647,422 @@  discard block
 block discarded – undo
647 647
     }
648 648
     */
649 649
 
650
-    /**
651
-     * clean orphan forums from database
652
-     * @param  string $table_link
653
-     * @param  string $field_link
654
-     * @param  string $field_object
655
-     * @param  array  $forum_ids forum IDs
656
-     * @return bool   true on success
657
-     */
658
-    // START irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
659
-    //    public function cleanOrphan(array $forum_ids = array())
660
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '', $forum_ids = [])
661
-    {
662
-        // check parent_forum orphan forums
663
-        if (empty($forum_ids)) {
664
-            $forum_ids = $this->getIds();
665
-        }
666
-        if (empty($forum_ids)) {
667
-            return false;
668
-        }
669
-        /*
650
+	/**
651
+	 * clean orphan forums from database
652
+	 * @param  string $table_link
653
+	 * @param  string $field_link
654
+	 * @param  string $field_object
655
+	 * @param  array  $forum_ids forum IDs
656
+	 * @return bool   true on success
657
+	 */
658
+	// START irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
659
+	//    public function cleanOrphan(array $forum_ids = array())
660
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '', $forum_ids = [])
661
+	{
662
+		// check parent_forum orphan forums
663
+		if (empty($forum_ids)) {
664
+			$forum_ids = $this->getIds();
665
+		}
666
+		if (empty($forum_ids)) {
667
+			return false;
668
+		}
669
+		/*
670 670
             $sql =    "    UPDATE ".$GLOBALS['xoopsDB']->prefix("newbb_forums").
671 671
                     "    SET parent_forum = 0".
672 672
                     "    WHERE (parent_forum NOT IN ( ".$forum_ids."))".
673 673
                     "        OR parent_forum = forum_id";
674 674
         */
675
-        $criteria = new \CriteriaCompo();
676
-        $criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND');
677
-        $criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR');
678
-        $b1 = $this->updateAll('parent_forum', 0, $criteria, true);
679
-        // check cat_id orphan forums
680
-        $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
681
-        $cat_ids         = $categoryHandler->getIds();
682
-        if (empty($cat_ids)) {
683
-            return false;
684
-        }
685
-        $criteria = new \CriteriaCompo();
686
-        $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND');
687
-        $b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true);
688
-
689
-        return ($b1 && $b2);
690
-    }
691
-    // END irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
692
-
693
-    /**
694
-     * forum data synchronization
695
-     *
696
-     * @param  mixed $object null for all forums; integer for forum_id; object for forum object
697
-     * @return bool
698
-     * @internal param int $mode 1 for stats only; 2 for forum index data only; 0 for both
699
-     *
700
-     */
701
-    public function synchronization($object = null)
702
-    {
703
-        if (empty($object)) {
704
-            $forums = $this->getIds();
705
-            $this->cleanOrphan('', '', '', $forums); // irmtfan - move cleanOrphan to synchronization function
706
-            foreach ($forums as $id) {
707
-                $this->synchronization($id);
708
-            }
709
-
710
-            return true;
711
-        }
712
-
713
-        if (!is_object($object)) {
714
-            $object = $this->get((int)$object);
715
-        }
716
-
717
-        if (!$object->getVar('forum_id')) {
718
-            return false;
719
-        }
720
-        $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN  ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id');
721
-
722
-        if ($result = $this->db->query($sql)) {
723
-            $last_post = 0;
724
-            $posts     = 0;
725
-            if ($row = $this->db->fetchArray($result)) {
726
-                $last_post = (int)$row['last_post'];
727
-                $posts     = (int)$row['total'];
728
-            }
729
-            if ($object->getVar('forum_last_post_id') !== $last_post) {
730
-                $object->setVar('forum_last_post_id', $last_post);
731
-            }
732
-            if ($object->getVar('forum_posts') !== $posts) {
733
-                $object->setVar('forum_posts', $posts);
734
-            }
735
-        }
736
-
737
-        $sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id');
738
-        if ($result = $this->db->query($sql)) {
739
-            if ($row = $this->db->fetchArray($result)) {
740
-                if ($object->getVar('forum_topics') !== $row['total']) {
741
-                    $object->setVar('forum_topics', $row['total']);
742
-                }
743
-            }
744
-        }
745
-        $object->setDirty();
746
-
747
-        return $this->insert($object, true);
748
-    }
749
-
750
-    /**
751
-     * @param  null $passedSubForums
752
-     * @return array
753
-     */
754
-    public function getSubforumStats($passedSubForums = null)
755
-    {
756
-        $stats = [];
757
-
758
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
759
-
760
-        $subForumTree = newbbGetSubForum();
761
-        if (empty($passedSubForums)) {
762
-            $sub_forums = $subForumTree;
763
-        } else {
764
-            foreach ($passedSubForums as $id) {
765
-                $sub_forums[$id] = isset($subForumTree[$id]) ? $subForumTree[$id] : null;
766
-            }
767
-        }
768
-
769
-        $forums_id = [];
770
-        foreach (array_keys($sub_forums) as $id) {
771
-            if (empty($sub_forums[$id])) {
772
-                continue;
773
-            }
774
-            $forums_id = array_merge($forums_id, $sub_forums[$id]);
775
-        }
776
-        if (!$forums_id) {
777
-            return $stats;
778
-        }
779
-        $sql = '    SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . '    FROM ' . $this->table . '    WHERE forum_id IN (' . implode(', ', $forums_id) . ')';
780
-        if (!$result = $this->db->query($sql)) {
781
-            return $stats;
782
-        }
783
-
784
-        $forum_stats = [];
785
-        while (false !== ($row = $this->db->fetchArray($result))) {
786
-            $forum_stats[$row['id']] = ['topics' => $row['topics'], 'posts' => $row['posts']];
787
-        }
788
-
789
-        foreach (array_keys($sub_forums) as $id) {
790
-            if (empty($sub_forums[$id])) {
791
-                continue;
792
-            }
793
-            $stats[$id] = ['topics' => 0, 'posts' => 0];
794
-            foreach ($sub_forums[$id] as $fid) {
795
-                $stats[$id]['topics'] += $forum_stats[$fid]['topics'];
796
-                $stats[$id]['posts']  += $forum_stats[$fid]['posts'];
797
-            }
798
-        }
799
-
800
-        return $stats;
801
-    }
802
-
803
-    /**
804
-     * @param        $forums
805
-     * @param  int   $length_title_index
806
-     * @param  int   $count_subforum
807
-     * @return array
808
-     */
809
-    public function &display($forums, $length_title_index = 30, $count_subforum = 1)
810
-    {
811
-        global $myts;
812
-
813
-        $posts       = [];
814
-        $postsObject = [];
815
-        foreach (array_keys($forums) as $id) {
816
-            $posts[] = $forums[$id]['forum_last_post_id'];
817
-        }
818
-        if (!empty($posts)) {
819
-            $postHandler = Newbb\Helper::getInstance()->getHandler('Post');
820
-            $tags_post   = ['uid', 'topic_id', 'post_time', 'poster_name', 'icon'];
821
-            if (!empty($length_title_index)) {
822
-                $tags_post[] = 'subject';
823
-            }
824
-            $posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false);
825
-        }
826
-
827
-        // Get topic/post stats per forum
828
-        $stats_forum = [];
829
-
830
-        if (!empty($count_subforum)) {
831
-            $stats_forum = $this->getSubforumStats(array_keys($forums)); // irmtfan uncomment to count sub forum posts/topics
832
-        }
833
-
834
-        $users  = [];
835
-        $reads  = [];
836
-        $topics = [];
837
-
838
-        foreach (array_keys($forums) as $id) {
839
-            $forum =& $forums[$id];
840
-
841
-            if (!$forum['forum_last_post_id']) {
842
-                continue;
843
-            }
844
-            if (!$post = @$posts[$forum['forum_last_post_id']]) {
845
-                $forum['forum_last_post_id'] = 0;
846
-                continue;
847
-            }
848
-
849
-            $users[] = $post['uid'];
850
-            if ($moderators[$id] = $forum['forum_moderator']) {
851
-                $users = array_merge($users, $moderators[$id]);
852
-            }
853
-
854
-            // reads
855
-            if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
856
-                $reads[$id] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $post['post_time'] : $post['post_id'];
857
-            }
858
-        }
859
-
860
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
861
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
862
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
863
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
864
-        $forum_isread = newbbIsRead('forum', $reads);
865
-        $users_linked = newbbGetUnameFromIds(array_unique($users), !empty($GLOBALS['xoopsModuleConfig']['show_realname']), true);
866
-
867
-        $forums_array   = [];
868
-        $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
869
-
870
-        foreach (array_keys($forums) as $id) {
871
-            $forum =& $forums[$id];
872
-
873
-            $_forum_data                 = [];
874
-            $_forum_data['forum_order']  = $forum['forum_order'];
875
-            $_forum_data['forum_id']     = $id;
876
-            $_forum_data['forum_cid']    = $forum['cat_id'];
877
-            $_forum_data['forum_name']   = $forum['forum_name'];
878
-            $forumDescLength             = $GLOBALS['xoopsModuleConfig']['forum_desc_length'];
879
-            $_forum_data['forum_desc']   = mb_strimwidth($forum['forum_desc'], 0, $forumDescLength, '...');
880
-            $_forum_data['forum_topics'] = $forum['forum_topics'] + @$stats_forum[$id]['topics'];
881
-            $_forum_data['forum_posts']  = $forum['forum_posts'] + @$stats_forum[$id]['posts'];
882
-            //$_forum_data["forum_type"]= $forum['forum_type'];
883
-
884
-            $forum_moderators = [];
885
-            if (!empty($moderators[$id])) {
886
-                foreach (@$moderators[$id] as $moderator) {
887
-                    $forum_moderators[] = @$users_linked[$moderator];
888
-                }
889
-            }
890
-            $_forum_data['forum_moderators'] = implode(', ', $forum_moderators);
891
-
892
-            // irmtfan change if/endif to if{} method
893
-            if ($post_id = $forum['forum_last_post_id']) {
894
-                $post                               =& $posts[$post_id];
895
-                $_forum_data['forum_lastpost_id']   = $post_id;
896
-                $_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']);
897
-                if (!empty($users_linked[$post['uid']])) {
898
-                    $_forum_data['forum_lastpost_user'] = $users_linked[$post['uid']];
899
-                } elseif ($poster_name = $post['poster_name']) {
900
-                    $_forum_data['forum_lastpost_user'] = $poster_name;
901
-                } else {
902
-                    $_forum_data['forum_lastpost_user'] = $name_anonymous;
903
-                }
904
-                if (!empty($length_title_index)) {
905
-                    $subject = $post['subject'];
906
-                    if ($length_title_index < 255) {
907
-                        $subject = xoops_substr($subject, 0, $length_title_index);
908
-                    }
909
-                    $_forum_data['forum_lastpost_subject'] = $subject;
910
-                }
911
-                // irmtfan - remove icon_path and use newbbDisplayImage
912
-                $_forum_data['forum_lastpost_icon'] = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST);
913
-                // START irmtfan change the method to add read smarty
914
-                if (empty($forum_isread[$id])) {
915
-                    $_forum_data['forum_folder'] = newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS);
916
-                    $_forum_data['forum_read']   = 0; // irmtfan add forum-read/forum-new smarty variable
917
-                } else {
918
-                    $_forum_data['forum_folder'] = newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS);
919
-                    $_forum_data['forum_read']   = 1; // irmtfan add forum-read/forum-new smarty variable
920
-                }
921
-                // END irmtfan change the method to add read smarty
922
-            }
923
-            $forums_array[$forum['parent_forum']][] = $_forum_data;
924
-        }
925
-
926
-        return $forums_array;
927
-    }
928
-
929
-    /**
930
-     * get a hierarchical tree of forums
931
-     *
932
-     * {@link newbbTree}
933
-     *
934
-     * @param  int    $cat_id     category ID
935
-     * @param  int    $pid        Top forum ID
936
-     * @param  string $permission permission type
937
-     * @param  string $prefix     prefix for display
938
-     * @param  string|array|null $tags       variables to fetch
939
-     * @return array  associative array of category IDs and sanitized titles
940
-     */
941
-    public function &getTree($cat_id = 0, $pid = 0, $permission = 'access', $prefix = '--', $tags = null)
942
-    {
943
-        $pid         = (int)$pid;
944
-        $perm_string = $permission;
945
-        if (!is_array($tags) || 0 === count($tags)) {
946
-            $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
947
-        }
948
-        $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
949
-
950
-        require_once __DIR__ . '/Tree.php';
951
-        $forums_structured = [];
952
-        foreach (array_keys($forumsObject) as $key) {
953
-            $forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key];
954
-        }
955
-
956
-        foreach (array_keys($forums_structured) as $cid) {
957
-            $tree              = new ObjectTree($forums_structured[$cid]);
958
-            $forum_array[$cid] = $tree->makeTree($prefix, $pid, $tags);
959
-            unset($tree);
960
-        }
961
-
962
-        return $forum_array;
963
-    }
964
-
965
-    /**
966
-     * get a hierarchical array tree of forums
967
-     *
968
-     * {@link newbbTree}
969
-     *
970
-     * @param  int     $cat_id     category ID
971
-     * @param  int     $pid        Top forum ID
972
-     * @param  string  $permission permission type
973
-     * @param  string|array|null  $tags       variables to fetch
974
-     * @param  integer $depth      level of subcategories
975
-     * @return array   associative array of category IDs and sanitized titles
976
-     */
977
-    public function &getArrayTree($cat_id = 0, $pid = 0, $permission = 'access', $tags = null, $depth = 0)
978
-    {
979
-        $pid         = (int)$pid;
980
-        $perm_string = $permission;
981
-        if (!is_array($tags) || 0 === count($tags)) {
982
-            $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
983
-        }
984
-        $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
985
-
986
-        require_once __DIR__ . '/Tree.php';
987
-        $forums_structured = [];
988
-        foreach (array_keys($forumsObject) as $key) {
989
-            $forumObject                                             =& $forumsObject[$key];
990
-            $forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key];
991
-        }
992
-        foreach (array_keys($forums_structured) as $cid) {
993
-            $tree              = new ObjectTree($forums_structured[$cid]);
994
-            $forum_array[$cid] = $tree->makeArrayTree($pid, $tags, $depth);
995
-            unset($tree);
996
-        }
997
-
998
-        return $forum_array;
999
-    }
1000
-
1001
-    /**
1002
-     * @param $object
1003
-     * @return array|null
1004
-     */
1005
-    public function &getParents($object)
1006
-    {
1007
-        $ret = null;
1008
-        if (!$object->getVar('forum_id')) {
1009
-            return $ret;
1010
-        }
1011
-
1012
-        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
1013
-        if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) {
1014
-            return $ret;
1015
-        }
1016
-        $parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN'));
1017
-        foreach ($parents as $key => $id) {
1018
-            $ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]];
1019
-        }
1020
-        unset($parents, $parents_list);
1021
-
1022
-        return $ret;
1023
-    }
1024
-
1025
-    // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
1026
-
1027
-    /**
1028
-     * function for get forum Ids by positive and negative values
1029
-     *
1030
-     * @param  int|text|array $values : positive values = forums | negative values = cats | $values=0 = all valid forums, $permission , true/false $parse_cats
1031
-     * @param  string   $permission
1032
-     * @param  bool     $parse_cats
1033
-     * @return array|mixed $validForums
1034
-     */
1035
-    public function getIdsByValues($values = 0, $permission = 'access', $parse_cats = true)
1036
-    {
1037
-        // Get all valid forums with this permission
1038
-        $validForums = $this->getIdsByPermission($permission);
1039
-        // if no value or value=0 return all valid forums
1040
-        if (empty($values)) {
1041
-            return $validForums;
1042
-        }
1043
-        $values = is_numeric($values) ? [$values] : $values;
1044
-        //parse negative values to category IDs
1045
-        $forums = [];
1046
-        $cats   = [];
1047
-        foreach ($values as $val) {
1048
-            if (0 == $val) {
1049
-                // value=0 => all valid forums
1050
-                return $validForums;
1051
-            } elseif ($val > 0) {
1052
-                $forums[] = $val;
1053
-            } else {
1054
-                $cats[] = abs($val);
1055
-            }
1056
-        }
1057
-        // if dont want to parse categories OR no cats return all forums
1058
-        if (empty($parse_cats) || empty($cats)) {
1059
-            return array_intersect($validForums, $forums);
1060
-        }
1061
-        // Get all forums by category IDs
1062
-        $forumObjs = $this->getForumsByCategory($cats, $permission, true);
1063
-        $forums    = array_merge($forums, array_keys($forumObjs));
1064
-
1065
-        return array_intersect($validForums, $forums);
1066
-    }
1067
-    // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
675
+		$criteria = new \CriteriaCompo();
676
+		$criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND');
677
+		$criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR');
678
+		$b1 = $this->updateAll('parent_forum', 0, $criteria, true);
679
+		// check cat_id orphan forums
680
+		$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
681
+		$cat_ids         = $categoryHandler->getIds();
682
+		if (empty($cat_ids)) {
683
+			return false;
684
+		}
685
+		$criteria = new \CriteriaCompo();
686
+		$criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND');
687
+		$b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true);
688
+
689
+		return ($b1 && $b2);
690
+	}
691
+	// END irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
692
+
693
+	/**
694
+	 * forum data synchronization
695
+	 *
696
+	 * @param  mixed $object null for all forums; integer for forum_id; object for forum object
697
+	 * @return bool
698
+	 * @internal param int $mode 1 for stats only; 2 for forum index data only; 0 for both
699
+	 *
700
+	 */
701
+	public function synchronization($object = null)
702
+	{
703
+		if (empty($object)) {
704
+			$forums = $this->getIds();
705
+			$this->cleanOrphan('', '', '', $forums); // irmtfan - move cleanOrphan to synchronization function
706
+			foreach ($forums as $id) {
707
+				$this->synchronization($id);
708
+			}
709
+
710
+			return true;
711
+		}
712
+
713
+		if (!is_object($object)) {
714
+			$object = $this->get((int)$object);
715
+		}
716
+
717
+		if (!$object->getVar('forum_id')) {
718
+			return false;
719
+		}
720
+		$sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN  ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id');
721
+
722
+		if ($result = $this->db->query($sql)) {
723
+			$last_post = 0;
724
+			$posts     = 0;
725
+			if ($row = $this->db->fetchArray($result)) {
726
+				$last_post = (int)$row['last_post'];
727
+				$posts     = (int)$row['total'];
728
+			}
729
+			if ($object->getVar('forum_last_post_id') !== $last_post) {
730
+				$object->setVar('forum_last_post_id', $last_post);
731
+			}
732
+			if ($object->getVar('forum_posts') !== $posts) {
733
+				$object->setVar('forum_posts', $posts);
734
+			}
735
+		}
736
+
737
+		$sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id');
738
+		if ($result = $this->db->query($sql)) {
739
+			if ($row = $this->db->fetchArray($result)) {
740
+				if ($object->getVar('forum_topics') !== $row['total']) {
741
+					$object->setVar('forum_topics', $row['total']);
742
+				}
743
+			}
744
+		}
745
+		$object->setDirty();
746
+
747
+		return $this->insert($object, true);
748
+	}
749
+
750
+	/**
751
+	 * @param  null $passedSubForums
752
+	 * @return array
753
+	 */
754
+	public function getSubforumStats($passedSubForums = null)
755
+	{
756
+		$stats = [];
757
+
758
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
759
+
760
+		$subForumTree = newbbGetSubForum();
761
+		if (empty($passedSubForums)) {
762
+			$sub_forums = $subForumTree;
763
+		} else {
764
+			foreach ($passedSubForums as $id) {
765
+				$sub_forums[$id] = isset($subForumTree[$id]) ? $subForumTree[$id] : null;
766
+			}
767
+		}
768
+
769
+		$forums_id = [];
770
+		foreach (array_keys($sub_forums) as $id) {
771
+			if (empty($sub_forums[$id])) {
772
+				continue;
773
+			}
774
+			$forums_id = array_merge($forums_id, $sub_forums[$id]);
775
+		}
776
+		if (!$forums_id) {
777
+			return $stats;
778
+		}
779
+		$sql = '    SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . '    FROM ' . $this->table . '    WHERE forum_id IN (' . implode(', ', $forums_id) . ')';
780
+		if (!$result = $this->db->query($sql)) {
781
+			return $stats;
782
+		}
783
+
784
+		$forum_stats = [];
785
+		while (false !== ($row = $this->db->fetchArray($result))) {
786
+			$forum_stats[$row['id']] = ['topics' => $row['topics'], 'posts' => $row['posts']];
787
+		}
788
+
789
+		foreach (array_keys($sub_forums) as $id) {
790
+			if (empty($sub_forums[$id])) {
791
+				continue;
792
+			}
793
+			$stats[$id] = ['topics' => 0, 'posts' => 0];
794
+			foreach ($sub_forums[$id] as $fid) {
795
+				$stats[$id]['topics'] += $forum_stats[$fid]['topics'];
796
+				$stats[$id]['posts']  += $forum_stats[$fid]['posts'];
797
+			}
798
+		}
799
+
800
+		return $stats;
801
+	}
802
+
803
+	/**
804
+	 * @param        $forums
805
+	 * @param  int   $length_title_index
806
+	 * @param  int   $count_subforum
807
+	 * @return array
808
+	 */
809
+	public function &display($forums, $length_title_index = 30, $count_subforum = 1)
810
+	{
811
+		global $myts;
812
+
813
+		$posts       = [];
814
+		$postsObject = [];
815
+		foreach (array_keys($forums) as $id) {
816
+			$posts[] = $forums[$id]['forum_last_post_id'];
817
+		}
818
+		if (!empty($posts)) {
819
+			$postHandler = Newbb\Helper::getInstance()->getHandler('Post');
820
+			$tags_post   = ['uid', 'topic_id', 'post_time', 'poster_name', 'icon'];
821
+			if (!empty($length_title_index)) {
822
+				$tags_post[] = 'subject';
823
+			}
824
+			$posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false);
825
+		}
826
+
827
+		// Get topic/post stats per forum
828
+		$stats_forum = [];
829
+
830
+		if (!empty($count_subforum)) {
831
+			$stats_forum = $this->getSubforumStats(array_keys($forums)); // irmtfan uncomment to count sub forum posts/topics
832
+		}
833
+
834
+		$users  = [];
835
+		$reads  = [];
836
+		$topics = [];
837
+
838
+		foreach (array_keys($forums) as $id) {
839
+			$forum =& $forums[$id];
840
+
841
+			if (!$forum['forum_last_post_id']) {
842
+				continue;
843
+			}
844
+			if (!$post = @$posts[$forum['forum_last_post_id']]) {
845
+				$forum['forum_last_post_id'] = 0;
846
+				continue;
847
+			}
848
+
849
+			$users[] = $post['uid'];
850
+			if ($moderators[$id] = $forum['forum_moderator']) {
851
+				$users = array_merge($users, $moderators[$id]);
852
+			}
853
+
854
+			// reads
855
+			if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
856
+				$reads[$id] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $post['post_time'] : $post['post_id'];
857
+			}
858
+		}
859
+
860
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
861
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
862
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
863
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
864
+		$forum_isread = newbbIsRead('forum', $reads);
865
+		$users_linked = newbbGetUnameFromIds(array_unique($users), !empty($GLOBALS['xoopsModuleConfig']['show_realname']), true);
866
+
867
+		$forums_array   = [];
868
+		$name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
869
+
870
+		foreach (array_keys($forums) as $id) {
871
+			$forum =& $forums[$id];
872
+
873
+			$_forum_data                 = [];
874
+			$_forum_data['forum_order']  = $forum['forum_order'];
875
+			$_forum_data['forum_id']     = $id;
876
+			$_forum_data['forum_cid']    = $forum['cat_id'];
877
+			$_forum_data['forum_name']   = $forum['forum_name'];
878
+			$forumDescLength             = $GLOBALS['xoopsModuleConfig']['forum_desc_length'];
879
+			$_forum_data['forum_desc']   = mb_strimwidth($forum['forum_desc'], 0, $forumDescLength, '...');
880
+			$_forum_data['forum_topics'] = $forum['forum_topics'] + @$stats_forum[$id]['topics'];
881
+			$_forum_data['forum_posts']  = $forum['forum_posts'] + @$stats_forum[$id]['posts'];
882
+			//$_forum_data["forum_type"]= $forum['forum_type'];
883
+
884
+			$forum_moderators = [];
885
+			if (!empty($moderators[$id])) {
886
+				foreach (@$moderators[$id] as $moderator) {
887
+					$forum_moderators[] = @$users_linked[$moderator];
888
+				}
889
+			}
890
+			$_forum_data['forum_moderators'] = implode(', ', $forum_moderators);
891
+
892
+			// irmtfan change if/endif to if{} method
893
+			if ($post_id = $forum['forum_last_post_id']) {
894
+				$post                               =& $posts[$post_id];
895
+				$_forum_data['forum_lastpost_id']   = $post_id;
896
+				$_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']);
897
+				if (!empty($users_linked[$post['uid']])) {
898
+					$_forum_data['forum_lastpost_user'] = $users_linked[$post['uid']];
899
+				} elseif ($poster_name = $post['poster_name']) {
900
+					$_forum_data['forum_lastpost_user'] = $poster_name;
901
+				} else {
902
+					$_forum_data['forum_lastpost_user'] = $name_anonymous;
903
+				}
904
+				if (!empty($length_title_index)) {
905
+					$subject = $post['subject'];
906
+					if ($length_title_index < 255) {
907
+						$subject = xoops_substr($subject, 0, $length_title_index);
908
+					}
909
+					$_forum_data['forum_lastpost_subject'] = $subject;
910
+				}
911
+				// irmtfan - remove icon_path and use newbbDisplayImage
912
+				$_forum_data['forum_lastpost_icon'] = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST);
913
+				// START irmtfan change the method to add read smarty
914
+				if (empty($forum_isread[$id])) {
915
+					$_forum_data['forum_folder'] = newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS);
916
+					$_forum_data['forum_read']   = 0; // irmtfan add forum-read/forum-new smarty variable
917
+				} else {
918
+					$_forum_data['forum_folder'] = newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS);
919
+					$_forum_data['forum_read']   = 1; // irmtfan add forum-read/forum-new smarty variable
920
+				}
921
+				// END irmtfan change the method to add read smarty
922
+			}
923
+			$forums_array[$forum['parent_forum']][] = $_forum_data;
924
+		}
925
+
926
+		return $forums_array;
927
+	}
928
+
929
+	/**
930
+	 * get a hierarchical tree of forums
931
+	 *
932
+	 * {@link newbbTree}
933
+	 *
934
+	 * @param  int    $cat_id     category ID
935
+	 * @param  int    $pid        Top forum ID
936
+	 * @param  string $permission permission type
937
+	 * @param  string $prefix     prefix for display
938
+	 * @param  string|array|null $tags       variables to fetch
939
+	 * @return array  associative array of category IDs and sanitized titles
940
+	 */
941
+	public function &getTree($cat_id = 0, $pid = 0, $permission = 'access', $prefix = '--', $tags = null)
942
+	{
943
+		$pid         = (int)$pid;
944
+		$perm_string = $permission;
945
+		if (!is_array($tags) || 0 === count($tags)) {
946
+			$tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
947
+		}
948
+		$forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
949
+
950
+		require_once __DIR__ . '/Tree.php';
951
+		$forums_structured = [];
952
+		foreach (array_keys($forumsObject) as $key) {
953
+			$forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key];
954
+		}
955
+
956
+		foreach (array_keys($forums_structured) as $cid) {
957
+			$tree              = new ObjectTree($forums_structured[$cid]);
958
+			$forum_array[$cid] = $tree->makeTree($prefix, $pid, $tags);
959
+			unset($tree);
960
+		}
961
+
962
+		return $forum_array;
963
+	}
964
+
965
+	/**
966
+	 * get a hierarchical array tree of forums
967
+	 *
968
+	 * {@link newbbTree}
969
+	 *
970
+	 * @param  int     $cat_id     category ID
971
+	 * @param  int     $pid        Top forum ID
972
+	 * @param  string  $permission permission type
973
+	 * @param  string|array|null  $tags       variables to fetch
974
+	 * @param  integer $depth      level of subcategories
975
+	 * @return array   associative array of category IDs and sanitized titles
976
+	 */
977
+	public function &getArrayTree($cat_id = 0, $pid = 0, $permission = 'access', $tags = null, $depth = 0)
978
+	{
979
+		$pid         = (int)$pid;
980
+		$perm_string = $permission;
981
+		if (!is_array($tags) || 0 === count($tags)) {
982
+			$tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
983
+		}
984
+		$forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
985
+
986
+		require_once __DIR__ . '/Tree.php';
987
+		$forums_structured = [];
988
+		foreach (array_keys($forumsObject) as $key) {
989
+			$forumObject                                             =& $forumsObject[$key];
990
+			$forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key];
991
+		}
992
+		foreach (array_keys($forums_structured) as $cid) {
993
+			$tree              = new ObjectTree($forums_structured[$cid]);
994
+			$forum_array[$cid] = $tree->makeArrayTree($pid, $tags, $depth);
995
+			unset($tree);
996
+		}
997
+
998
+		return $forum_array;
999
+	}
1000
+
1001
+	/**
1002
+	 * @param $object
1003
+	 * @return array|null
1004
+	 */
1005
+	public function &getParents($object)
1006
+	{
1007
+		$ret = null;
1008
+		if (!$object->getVar('forum_id')) {
1009
+			return $ret;
1010
+		}
1011
+
1012
+		require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
1013
+		if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) {
1014
+			return $ret;
1015
+		}
1016
+		$parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN'));
1017
+		foreach ($parents as $key => $id) {
1018
+			$ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]];
1019
+		}
1020
+		unset($parents, $parents_list);
1021
+
1022
+		return $ret;
1023
+	}
1024
+
1025
+	// START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
1026
+
1027
+	/**
1028
+	 * function for get forum Ids by positive and negative values
1029
+	 *
1030
+	 * @param  int|text|array $values : positive values = forums | negative values = cats | $values=0 = all valid forums, $permission , true/false $parse_cats
1031
+	 * @param  string   $permission
1032
+	 * @param  bool     $parse_cats
1033
+	 * @return array|mixed $validForums
1034
+	 */
1035
+	public function getIdsByValues($values = 0, $permission = 'access', $parse_cats = true)
1036
+	{
1037
+		// Get all valid forums with this permission
1038
+		$validForums = $this->getIdsByPermission($permission);
1039
+		// if no value or value=0 return all valid forums
1040
+		if (empty($values)) {
1041
+			return $validForums;
1042
+		}
1043
+		$values = is_numeric($values) ? [$values] : $values;
1044
+		//parse negative values to category IDs
1045
+		$forums = [];
1046
+		$cats   = [];
1047
+		foreach ($values as $val) {
1048
+			if (0 == $val) {
1049
+				// value=0 => all valid forums
1050
+				return $validForums;
1051
+			} elseif ($val > 0) {
1052
+				$forums[] = $val;
1053
+			} else {
1054
+				$cats[] = abs($val);
1055
+			}
1056
+		}
1057
+		// if dont want to parse categories OR no cats return all forums
1058
+		if (empty($parse_cats) || empty($cats)) {
1059
+			return array_intersect($validForums, $forums);
1060
+		}
1061
+		// Get all forums by category IDs
1062
+		$forumObjs = $this->getForumsByCategory($cats, $permission, true);
1063
+		$forums    = array_merge($forums, array_keys($forumObjs));
1064
+
1065
+		return array_intersect($validForums, $forums);
1066
+	}
1067
+	// END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
1068 1068
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
             return $_cachedForums;
101 101
         }
102 102
 
103
-        $criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN'));
103
+        $criteria = new \CriteriaCompo(new \Criteria('forum_id', '('.implode(', ', $valid_ids).')', 'IN'));
104 104
         if (is_numeric($cat) && $cat > 0) {
105 105
             $criteria->add(new \Criteria('cat_id', (int)$cat));
106 106
         } elseif (is_array($cat) && count($cat) > 0) {
107
-            $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN'));
107
+            $criteria->add(new \Criteria('cat_id', '('.implode(', ', $cat).')', 'IN'));
108 108
         }
109 109
         $criteria->setSort('forum_order');
110 110
         $criteria->setOrder('ASC');
@@ -181,23 +181,23 @@  discard block
 block discarded – undo
181 181
         $topic_lastread = newbbGetCookie('LT', true);
182 182
         $criteria_forum = '';
183 183
         if (is_object($forum)) {
184
-            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
184
+            $criteria_forum = ' AND t.forum_id = '.$forum->getVar('forum_id');
185 185
             $hot_threshold  = $forum->getVar('hot_threshold');
186 186
         } else {
187 187
             $hot_threshold = 10;
188 188
             if (is_array($forum) && count($forum) > 0) {
189
-                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
189
+                $criteria_forum = ' AND t.forum_id IN ('.implode(',', array_keys($forum)).')';
190 190
             } elseif (!empty($forum)) {
191
-                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
191
+                $criteria_forum = ' AND t.forum_id ='.(int)$forum;
192 192
             }
193 193
         }
194 194
 
195
-        $criteria_post    = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 ';
195
+        $criteria_post    = $startdate ? ' p.post_time > '.$startdate : ' 1 = 1 ';
196 196
         $criteria_topic   = empty($type) ? '' : " AND t.type_id={$type}";
197 197
         $criteria_extra   = '';
198 198
         $criteria_approve = ' AND t.approved = 1';
199 199
         $post_on          = ' p.post_id = t.topic_last_post_id';
200
-        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
200
+        $leftjoin         = ' LEFT JOIN '.$this->db->prefix('newbb_posts').' p ON p.post_id = t.topic_last_post_id';
201 201
         $sort_array       = [];
202 202
         switch ($status) {
203 203
             case 'digest':
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
                     // START irmtfan use read_uid to find the unread posts when the user is logged in
215 215
                     $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
216 216
                     if (!empty($read_uid)) {
217
-                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
217
+                        $leftjoin      .= ' LEFT JOIN '.$this->db->prefix('newbb_reads_topic').' r ON r.read_item = t.topic_id AND r.uid = '.$read_uid.' ';
218 218
                         $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
219 219
                     } else {
220 220
                     }
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                 } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
223 223
                     // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
224 224
                     if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
225
-                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
225
+                        $criteria_post  = ' p.post_time > '.$time_criterion; // for all users
226 226
                         $topics         = [];
227 227
                         $topic_lastread = newbbGetCookie('LT', true);
228 228
                         if (count($topic_lastread) > 0) {
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                             }
234 234
                         }
235 235
                         if (count($topics) > 0) {
236
-                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
236
+                            $criteria_extra = ' AND t.topic_id NOT IN ('.implode(',', $topics).')';
237 237
                         }
238 238
                     }
239 239
                     // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                 break;
242 242
             case 'pending':
243 243
                 $post_on          = ' p.topic_id = t.topic_id';
244
-                $criteria_post    .= ' AND p.pid = 0';
244
+                $criteria_post .= ' AND p.pid = 0';
245 245
                 $criteria_approve = ' AND t.approved = 0';
246 246
                 break;
247 247
 
@@ -255,31 +255,31 @@  discard block
 block discarded – undo
255 255
 
256 256
             default:
257 257
                 if ($startdate > 0) {
258
-                    $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
258
+                    $criteria_post = ' (p.post_time > '.$startdate.' OR t.topic_sticky=1)';
259 259
                 }
260 260
                 $sort_array[] = 't.topic_sticky DESC';
261 261
                 break;
262 262
         }
263 263
 
264
-        $select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
265
-        $from   = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
266
-        $where  = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve;
264
+        $select = 't.*, '.' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
265
+        $from   = $this->db->prefix('newbb_topics').' t '.$leftjoin;
266
+        $where  = $criteria_post.$criteria_topic.$criteria_forum.$criteria_extra.$criteria_approve;
267 267
 
268 268
         if ($excerpt) {
269 269
             $select .= ', p.post_karma, p.require_reply, pt.post_text';
270
-            $from   .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id';
270
+            $from   .= ' LEFT JOIN '.$this->db->prefix('newbb_posts_text').' pt ON pt.post_id = t.topic_last_post_id';
271 271
         }
272 272
         if ('u.uname' === $sort) {
273 273
             $sort = 't.topic_poster';
274 274
         }
275 275
 
276
-        $sort_array[] = trim($sort . ' ' . $order);
276
+        $sort_array[] = trim($sort.' '.$order);
277 277
         $sortby       = implode(', ', array_filter($sort_array));
278 278
         if (empty($sortby)) {
279 279
             $sortby = 't.topic_last_post_id DESC';
280 280
         }
281 281
 
282
-        $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby;
282
+        $sql = 'SELECT '.$select.' FROM '.$from.' WHERE '.$where.' ORDER BY '.$sortby;
283 283
 
284 284
         if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) {
285 285
             redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED);
@@ -304,16 +304,16 @@  discard block
 block discarded – undo
304 304
 
305 305
             if ($myrow['topic_haspoll']) {
306 306
                 if ($myrow['topic_sticky']) {
307
-                    $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
307
+                    $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY).'<br>'.newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
308 308
                 } else {
309 309
                     $topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
310 310
                 }
311 311
             } elseif ($myrow['topic_sticky']) {
312 312
                 $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY);
313 313
             } elseif (!empty($myrow['icon'])) {
314
-                $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />';
314
+                $topic_icon = '<img src="'.XOOPS_URL.'/images/subject/'.htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5).'" alt="" />';
315 315
             } else {
316
-                $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
316
+                $topic_icon = '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
317 317
             }
318 318
 
319 319
             // ------------------------------------------------------
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
             if ($rating < 1) {
324 324
                 $rating_img = newbbDisplayImage('blank');
325 325
             } else {
326
-                $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating));
326
+                $rating_img = newbbDisplayImage('rate'.$rating, constant('_MD_NEWBB_RATE'.$rating));
327 327
             }
328 328
             // ------------------------------------------------------
329 329
             // topic_page_jump
@@ -332,28 +332,28 @@  discard block
 block discarded – undo
332 332
             $totalpages           = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']);
333 333
             if ($totalpages > 1) {
334 334
                 $topic_page_jump .= '&nbsp;&nbsp;';
335
-                $append          = false;
335
+                $append = false;
336 336
                 for ($i = 1; $i <= $totalpages; ++$i) {
337 337
                     if ($i > 3 && $i < $totalpages) {
338 338
                         if (!$append) {
339 339
                             $topic_page_jump .= '...';
340
-                            $append          = true;
340
+                            $append = true;
341 341
                         }
342 342
                     } else {
343
-                        $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]';
343
+                        $topic_page_jump .= '[<a href="'.XOOPS_URL.'/modules/newbb/viewtopic.php?topic_id='.$myrow['topic_id'].'&amp;start='.(($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']).'">'.$i.'</a>]';
344 344
                         // irmtfan remove here and move
345 345
                         //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&amp;start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>';
346 346
                     }
347 347
                 }
348 348
             }
349 349
             // irmtfan - move here for both topics with and without pages
350
-            $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>';
350
+            $topic_page_jump_icon = "<a href='".XOOPS_URL.'/modules/newbb/viewtopic.php?post_id='.$myrow['post_id']."'>".newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST).'</a>';
351 351
 
352 352
             // ------------------------------------------------------
353 353
             // => topic array
354 354
             $forum_link = '';
355 355
             if (!empty($viewAllForums[$myrow['forum_id']])) {
356
-                $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>';
356
+                $forum_link = '<a href="'.XOOPS_URL.'/modules/newbb/viewforum.php?forum='.$myrow['forum_id'].'">'.$viewAllForums[$myrow['forum_id']]['forum_name'].'</a>';
357 357
             }
358 358
 
359 359
             $topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
             //$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.'';
363 363
             //}
364 364
             if ($myrow['topic_digest']) {
365
-                $topic_title = "<span class='digest'>" . $topic_title . '</span>';
365
+                $topic_title = "<span class='digest'>".$topic_title.'</span>';
366 366
             }
367 367
 
368 368
             if (0 == $excerpt) {
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
                 //'type_text'                 => $topic_prefix,/*irmtfan remove here and move to for loop*/
382 382
                 'topic_title'          => $topic_title,
383 383
                 //'topic_link'                => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'],
384
-                'topic_link'           => 'viewtopic.php?topic_id=' . $myrow['topic_id'],
384
+                'topic_link'           => 'viewtopic.php?topic_id='.$myrow['topic_id'],
385 385
                 'rating_img'           => $rating_img,
386 386
                 'topic_page_jump'      => $topic_page_jump,
387 387
                 'topic_page_jump_icon' => $topic_page_jump_icon,
@@ -456,10 +456,10 @@  discard block
 block discarded – undo
456 456
         } // irmtfan end for loop
457 457
         // END irmtfan move to a for loop
458 458
         if (count($topics) > 0) {
459
-            $sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')';
459
+            $sql = ' SELECT DISTINCT topic_id FROM '.$this->db->prefix('newbb_posts')." WHERE attachment != ''".' AND topic_id IN ('.implode(',', array_keys($topics)).')';
460 460
             if ($result = $this->db->query($sql)) {
461 461
                 while (false !== (list($topic_id) = $this->db->fetchRow($result))) {
462
-                    $topics[$topic_id]['attachment'] = '&nbsp;' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT);
462
+                    $topics[$topic_id]['attachment'] = '&nbsp;'.newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT);
463 463
                 }
464 464
             }
465 465
         }
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 
480 480
         $criteria_extra   = '';
481 481
         $criteria_approve = ' AND t.approved = 1'; // any others?
482
-        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
483
-        $criteria_post    = ' p.post_time > ' . $startdate;
482
+        $leftjoin         = ' LEFT JOIN '.$this->db->prefix('newbb_posts').' p ON p.post_id = t.topic_last_post_id';
483
+        $criteria_post    = ' p.post_time > '.$startdate;
484 484
         switch ($type) {
485 485
             case 'digest':
486 486
                 $criteria_extra = ' AND topic_digest = 1';
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 
496 496
                     $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
497 497
                     if (!empty($read_uid)) {
498
-                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
498
+                        $leftjoin      .= ' LEFT JOIN '.$this->db->prefix('newbb_reads_topic').' r ON r.read_item = t.topic_id AND r.uid = '.$read_uid.' ';
499 499
                         $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
500 500
                     } else {
501 501
                     }
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
                 } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
504 504
                     // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
505 505
                     if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
506
-                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
506
+                        $criteria_post  = ' p.post_time > '.$time_criterion; // for all users
507 507
                         $topics         = [];
508 508
                         $topic_lastread = newbbGetCookie('LT', true);
509 509
                         if (count($topic_lastread) > 0) {
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
                             }
515 515
                         }
516 516
                         if (count($topics) > 0) {
517
-                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
517
+                            $criteria_extra = ' AND t.topic_id NOT IN ('.implode(',', $topics).')';
518 518
                         }
519 519
                     }
520 520
                     // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
@@ -529,22 +529,22 @@  discard block
 block discarded – undo
529 529
             case 'all':
530 530
                 break;
531 531
             default:
532
-                $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
532
+                $criteria_post = ' (p.post_time > '.$startdate.' OR t.topic_sticky=1)';
533 533
                 break;
534 534
         }
535 535
         $criteria_forum = '';
536 536
         if (is_object($forum)) {
537
-            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
537
+            $criteria_forum = ' AND t.forum_id = '.$forum->getVar('forum_id');
538 538
         } else {
539 539
             if (is_array($forum) && count($forum) > 0) {
540
-                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
540
+                $criteria_forum = ' AND t.forum_id IN ('.implode(',', array_keys($forum)).')';
541 541
             } elseif (!empty($forum)) {
542
-                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
542
+                $criteria_forum = ' AND t.forum_id ='.(int)$forum;
543 543
             }
544 544
         }
545 545
 
546
-        $sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
547
-        $sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve;
546
+        $sql = 'SELECT COUNT(*) AS count FROM '.$this->db->prefix('newbb_topics').' t '.$leftjoin;
547
+        $sql .= ' WHERE '.$criteria_post.$criteria_forum.$criteria_extra.$criteria_approve;
548 548
         if (!$result = $this->db->query($sql)) {
549 549
             //xoops_error($this->db->error().'<br>'.$sql);
550 550
             return null;
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
             return true;
573 573
         }
574 574
 
575
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
575
+        require_once  dirname(__DIR__).'/include/functions.user.php';
576 576
         if (newbbIsAdmin($forum)) {
577 577
             return true;
578 578
         }
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
                     "        OR parent_forum = forum_id";
674 674
         */
675 675
         $criteria = new \CriteriaCompo();
676
-        $criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND');
676
+        $criteria->add(new \Criteria('parent_forum', '('.implode(', ', $forum_ids).')', 'NOT IN'), 'AND');
677 677
         $criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR');
678 678
         $b1 = $this->updateAll('parent_forum', 0, $criteria, true);
679 679
         // check cat_id orphan forums
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
             return false;
684 684
         }
685 685
         $criteria = new \CriteriaCompo();
686
-        $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND');
686
+        $criteria->add(new \Criteria('cat_id', '('.implode(', ', $cat_ids).')', 'NOT IN'), 'AND');
687 687
         $b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true);
688 688
 
689 689
         return ($b1 && $b2);
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         if (!$object->getVar('forum_id')) {
718 718
             return false;
719 719
         }
720
-        $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN  ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id');
720
+        $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM '.$this->db->prefix('newbb_posts').' AS p LEFT JOIN  '.$this->db->prefix('newbb_topics').' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = '.$object->getVar('forum_id');
721 721
 
722 722
         if ($result = $this->db->query($sql)) {
723 723
             $last_post = 0;
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             }
735 735
         }
736 736
 
737
-        $sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id');
737
+        $sql = 'SELECT COUNT(*) AS total FROM '.$this->db->prefix('newbb_topics').' WHERE approved=1 AND forum_id = '.$object->getVar('forum_id');
738 738
         if ($result = $this->db->query($sql)) {
739 739
             if ($row = $this->db->fetchArray($result)) {
740 740
                 if ($object->getVar('forum_topics') !== $row['total']) {
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
         if (!$forums_id) {
777 777
             return $stats;
778 778
         }
779
-        $sql = '    SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . '    FROM ' . $this->table . '    WHERE forum_id IN (' . implode(', ', $forums_id) . ')';
779
+        $sql = '    SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id'.'    FROM '.$this->table.'    WHERE forum_id IN ('.implode(', ', $forums_id).')';
780 780
         if (!$result = $this->db->query($sql)) {
781 781
             return $stats;
782 782
         }
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
             if (!empty($length_title_index)) {
822 822
                 $tags_post[] = 'subject';
823 823
             }
824
-            $posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false);
824
+            $posts = $postHandler->getAll(new \Criteria('post_id', '('.implode(', ', $posts).')', 'IN'), $tags_post, false);
825 825
         }
826 826
 
827 827
         // Get topic/post stats per forum
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
         $topics = [];
837 837
 
838 838
         foreach (array_keys($forums) as $id) {
839
-            $forum =& $forums[$id];
839
+            $forum = & $forums[$id];
840 840
 
841 841
             if (!$forum['forum_last_post_id']) {
842 842
                 continue;
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
         $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
869 869
 
870 870
         foreach (array_keys($forums) as $id) {
871
-            $forum =& $forums[$id];
871
+            $forum = & $forums[$id];
872 872
 
873 873
             $_forum_data                 = [];
874 874
             $_forum_data['forum_order']  = $forum['forum_order'];
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 
892 892
             // irmtfan change if/endif to if{} method
893 893
             if ($post_id = $forum['forum_last_post_id']) {
894
-                $post                               =& $posts[$post_id];
894
+                $post                               = & $posts[$post_id];
895 895
                 $_forum_data['forum_lastpost_id']   = $post_id;
896 896
                 $_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']);
897 897
                 if (!empty($users_linked[$post['uid']])) {
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
         }
948 948
         $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
949 949
 
950
-        require_once __DIR__ . '/Tree.php';
950
+        require_once __DIR__.'/Tree.php';
951 951
         $forums_structured = [];
952 952
         foreach (array_keys($forumsObject) as $key) {
953 953
             $forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key];
@@ -983,10 +983,10 @@  discard block
 block discarded – undo
983 983
         }
984 984
         $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
985 985
 
986
-        require_once __DIR__ . '/Tree.php';
986
+        require_once __DIR__.'/Tree.php';
987 987
         $forums_structured = [];
988 988
         foreach (array_keys($forumsObject) as $key) {
989
-            $forumObject                                             =& $forumsObject[$key];
989
+            $forumObject                                             = & $forumsObject[$key];
990 990
             $forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key];
991 991
         }
992 992
         foreach (array_keys($forums_structured) as $cid) {
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
         if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) {
1014 1014
             return $ret;
1015 1015
         }
1016
-        $parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN'));
1016
+        $parents_list = $this->getList(new \Criteria('forum_id', '('.implode(', ', $parents).')', 'IN'));
1017 1017
         foreach ($parents as $key => $id) {
1018 1018
             $ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]];
1019 1019
         }
Please login to merge, or discard this patch.
class/Readtopic.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,12 +44,12 @@
 block discarded – undo
44 44
  */
45 45
 class Readtopic extends Newbb\Read
46 46
 {
47
-    /**
48
-     *
49
-     */
50
-    public function __construct()
51
-    {
52
-        parent::__construct();
53
-        //$this->initVar('forum_id', XOBJ_DTYPE_INT);
54
-    }
47
+	/**
48
+	 *
49
+	 */
50
+	public function __construct()
51
+	{
52
+		parent::__construct();
53
+		//$this->initVar('forum_id', XOBJ_DTYPE_INT);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 
33 33
 use XoopsModules\Newbb;
34 34
 
35
-require_once __DIR__ . '/Read.php';
35
+require_once __DIR__.'/Read.php';
36 36
 
37 37
 /**
38 38
  * A handler for read/unread handling
Please login to merge, or discard this patch.
class/OnlineHandler.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -22,356 +22,356 @@
 block discarded – undo
22 22
  */
23 23
 class OnlineHandler
24 24
 {
25
-    public $db;
26
-    public $forum_id;
27
-    public $forumObject;
28
-    public $topic_id;
29
-    public $user_ids = [];
30
-
31
-    /**
32
-     * OnlineHandler constructor.
33
-     * @param \XoopsDatabase $db
34
-     */
35
-    public function __construct(\XoopsDatabase $db)
36
-    {
37
-        $this->db = $db;
38
-    }
39
-
40
-    /**
41
-     * @param null|Newbb\Forum $forum
42
-     * @param null|Topic  $forumtopic
43
-     */
44
-    public function init($forum = null, $forumtopic = null)
45
-    {
46
-        if (is_object($forum)) {
47
-            $this->forum_id    = $forum->getVar('forum_id');
48
-            $this->forumObject = $forum;
49
-        } else {
50
-            $this->forum_id    = (int)$forum;
51
-            $this->forumObject = $forum;
52
-        }
53
-        if (is_object($forumtopic)) {
54
-            $this->topic_id = $forumtopic->getVar('topic_id');
55
-            if (empty($this->forum_id)) {
56
-                $this->forum_id = $forumtopic->getVar('forum_id');
57
-            }
58
-        } else {
59
-            $this->topic_id = (int)$forumtopic;
60
-        }
61
-
62
-        $this->update();
63
-    }
64
-
65
-    public function update()
66
-    {
67
-        global $xoopsModule;
68
-
69
-        mt_srand((double)microtime() * 1000000);
70
-        // set gc probabillity to 10% for now..
71
-        if (mt_rand(1, 100) < 60) {
72
-            $this->gc(150);
73
-        }
74
-        if (is_object($GLOBALS['xoopsUser'])) {
75
-            $uid   = $GLOBALS['xoopsUser']->getVar('uid');
76
-            $uname = $GLOBALS['xoopsUser']->getVar('uname');
77
-            $name  = $GLOBALS['xoopsUser']->getVar('name');
78
-        } else {
79
-            $uid   = 0;
80
-            $uname = '';
81
-            $name  = '';
82
-        }
83
-
84
-        $xoops_onlineHandler = xoops_getHandler('online');
85
-        $xoopsupdate         = $xoops_onlineHandler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), \Xmf\IPAddress::fromRequest()->asReadable());
86
-        if (!$xoopsupdate) {
87
-            //xoops_error("newbb online upate error");
88
-        }
89
-
90
-        $uname = (empty($GLOBALS['xoopsModuleConfig']['show_realname']) || empty($name)) ? $uname : $name;
91
-        $this->write($uid, $uname, time(), $this->forum_id, IPAddress::fromRequest()->asReadable(), $this->topic_id);
92
-    }
93
-
94
-    /**
95
-     * @param $xoopsTpl
96
-     */
97
-    public function render(\Smarty $xoopsTpl)
98
-    {
99
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
100
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
101
-        $criteria = null;
102
-        if ($this->topic_id) {
103
-            $criteria = new \Criteria('online_topic', $this->topic_id);
104
-        } elseif ($this->forum_id) {
105
-            $criteria = new \Criteria('online_forum', $this->forum_id);
106
-        }
107
-        $users     = $this->getAll($criteria);
108
-        $num_total = count($users);
109
-
110
-        $num_user     = 0;
111
-        $users_id     = [];
112
-        $users_online = [];
113
-        for ($i = 0; $i < $num_total; ++$i) {
114
-            if (empty($users[$i]['online_uid'])) {
115
-                continue;
116
-            }
117
-            $users_id[]                             = $users[$i]['online_uid'];
118
-            $users_online[$users[$i]['online_uid']] = [
119
-                'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
120
-                'uname' => $users[$i]['online_uname']
121
-            ];
122
-            ++$num_user;
123
-        }
124
-        $num_anonymous           = $num_total - $num_user;
125
-        $online                  = [];
126
-        $online['image']         = newbbDisplayImage('whosonline');
127
-        $online['num_total']     = $num_total;
128
-        $online['num_user']      = $num_user;
129
-        $online['num_anonymous'] = $num_anonymous;
130
-        $administrator_list      = newbbIsModuleAdministrators($users_id);
131
-        $moderator_list          = [];
132
-        if ($member_list = array_diff(array_keys($administrator_list), $users_id)) {
133
-            if (is_object($this->forumObject)) {
134
-                $moderator_list = $this->forumObject->getVar('forum_moderator');
135
-            } else {
136
-                $moderator_list = newbbIsForumModerators($member_list);
137
-            }
138
-        }
139
-        foreach ($users_online as $uid => $user) {
140
-            if (!empty($administrator_list[$uid])) {
141
-                $user['level'] = 2;
142
-            } elseif (!empty($moderator_list[$uid])) {
143
-                $user['level'] = 1;
144
-            } else {
145
-                $user['level'] = 0;
146
-            }
147
-            $online['users'][] = $user;
148
-        }
149
-
150
-        $xoopsTpl->assign_by_ref('online', $online);
151
-    }
152
-
153
-    /**
154
-     * Deprecated
155
-     */
156
-    public function showOnline()
157
-    {
158
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
159
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
160
-        $criteria = null;
161
-        if ($this->topic_id) {
162
-            $criteria = new \Criteria('online_topic', $this->topic_id);
163
-        } elseif ($this->forum_id) {
164
-            $criteria = new \Criteria('online_forum', $this->forum_id);
165
-        }
166
-        $users     = $this->getAll($criteria);
167
-        $num_total = count($users);
168
-
169
-        $num_user     = 0;
170
-        $users_id     = [];
171
-        $users_online = [];
172
-        for ($i = 0; $i < $num_total; ++$i) {
173
-            if (empty($users[$i]['online_uid'])) {
174
-                continue;
175
-            }
176
-            $users_id[]                             = $users[$i]['online_uid'];
177
-            $users_online[$users[$i]['online_uid']] = [
178
-                'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
179
-                'uname' => $users[$i]['online_uname']
180
-            ];
181
-            ++$num_user;
182
-        }
183
-        $num_anonymous           = $num_total - $num_user;
184
-        $online                  = [];
185
-        $online['image']         = newbbDisplayImage('whosonline');
186
-        $online['statistik']     = newbbDisplayImage('statistik');
187
-        $online['num_total']     = $num_total;
188
-        $online['num_user']      = $num_user;
189
-        $online['num_anonymous'] = $num_anonymous;
190
-        $administrator_list      = newbbIsModuleAdministrators($users_id);
191
-        $moderator_list          = [];
192
-        if ($member_list = array_diff($users_id, array_keys($administrator_list))) {
193
-            if (is_object($this->forumObject)) {
194
-                $moderator_list = $this->forumObject->getVar('forum_moderator');
195
-            } else {
196
-                $moderator_list = newbbIsForumModerators($member_list);
197
-            }
198
-        }
199
-
200
-        foreach ($users_online as $uid => $user) {
201
-            if (in_array($uid, $administrator_list)) {
202
-                $user['level'] = 2;
203
-            } elseif (in_array($uid, $moderator_list)) {
204
-                $user['level'] = 1;
205
-            } else {
206
-                $user['level'] = 0;
207
-            }
208
-            $online['users'][] = $user;
209
-        }
210
-
211
-        return $online;
212
-    }
213
-
214
-    /**
215
-     * Write online information to the database
216
-     *
217
-     * @param  int    $uid      UID of the active user
218
-     * @param  string $uname    Username
219
-     * @param         $time
220
-     * @param  string $forum_id Current forum_id
221
-     * @param  string $ip       User's IP adress
222
-     * @param         $topic_id
223
-     * @return bool   TRUE on success
224
-     * @internal param string $timestamp
225
-     */
226
-    public function write($uid, $uname, $time, $forum_id, $ip, $topic_id)
227
-    {
228
-        global $xoopsModule, $xoopsDB;
229
-
230
-        $uid = (int)$uid;
231
-        if ($uid > 0) {
232
-            $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid;
233
-        } else {
234
-            $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid . " AND online_ip='" . $ip . "'";
235
-        }
236
-        list($count) = $this->db->fetchRow($this->db->queryF($sql));
237
-        if ($count > 0) {
238
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_online') . " SET online_updated= '" . $time . "', online_forum = '" . $forum_id . "', online_topic = '" . $topic_id . "' WHERE online_uid = " . $uid;
239
-            if (0 == $uid) {
240
-                $sql .= " AND online_ip='" . $ip . "'";
241
-            }
242
-        } else {
243
-            $sql = sprintf('INSERT INTO `%s` (online_uid, online_uname, online_updated, online_ip, online_forum, online_topic) VALUES (%u, %s, %u, %s, %u, %u)', $this->db->prefix('newbb_online'), $uid, $this->db->quote($uname), $time, $this->db->quote($ip), $forum_id, $topic_id);
244
-        }
245
-        if (!$this->db->queryF($sql)) {
246
-            //xoops_error($this->db->error());
247
-            return false;
248
-        }
249
-
250
-        /** @var \XoopsOnlineHandler $xoops_onlineHandler */
251
-        $xoops_onlineHandler = xoops_getHandler('online');
252
-        $xoopsOnlineTable    = $xoops_onlineHandler->table;
253
-
254
-        $sql = 'DELETE FROM '
255
-               . $this->db->prefix('newbb_online')
256
-               . ' WHERE'
257
-               . ' ( online_uid > 0 AND online_uid NOT IN ( SELECT online_uid FROM '
258
-               . $xoopsOnlineTable
259
-               . ' WHERE online_module ='
260
-               . $xoopsModule->getVar('mid')
261
-               . ' ) )'
262
-               . ' OR ( online_uid = 0 AND online_ip NOT IN ( SELECT online_ip FROM '
263
-               . $xoopsOnlineTable
264
-               . ' WHERE online_module ='
265
-               . $xoopsModule->getVar('mid')
266
-               . ' AND online_uid = 0 ) )';
267
-
268
-        if ($result = $this->db->queryF($sql)) {
269
-            return true;
270
-        } else {
271
-            //xoops_error($this->db->error());
272
-            return false;
273
-        }
274
-    }
275
-
276
-    /**
277
-     * Garbage Collection
278
-     *
279
-     * Delete all online information that has not been updated for a certain time
280
-     *
281
-     * @param int $expire Expiration time in seconds
282
-     */
283
-    public function gc($expire)
284
-    {
285
-        global $xoopsModule;
286
-        $sql = 'DELETE FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_updated < ' . (time() - (int)$expire);
287
-        $this->db->queryF($sql);
288
-
289
-        $xoops_onlineHandler = xoops_getHandler('online');
290
-        $xoops_onlineHandler->gc($expire);
291
-    }
292
-
293
-    /**
294
-     * Get an array of online information
295
-     *
296
-     * @param  \CriteriaElement $criteria {@link \CriteriaElement}
297
-     * @return array           Array of associative arrays of online information
298
-     */
299
-    public function getAll(\CriteriaElement $criteria = null)
300
-    {
301
-        $ret   = [];
302
-        $limit = $start = 0;
303
-        $sql   = 'SELECT * FROM ' . $this->db->prefix('newbb_online');
304
-        if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
305
-            $sql   .= ' ' . $criteria->renderWhere();
306
-            $limit = $criteria->getLimit();
307
-            $start = $criteria->getStart();
308
-        }
309
-        $result = $this->db->query($sql, $limit, $start);
310
-        if (!$result) {
311
-            return $ret;
312
-        }
313
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
314
-            $ret[] = $myrow;
315
-            if ($myrow['online_uid'] > 0) {
316
-                $this->user_ids[] = $myrow['online_uid'];
317
-            }
318
-            unset($myrow);
319
-        }
320
-        $this->user_ids = array_unique($this->user_ids);
321
-
322
-        return $ret;
323
-    }
324
-
325
-    /**
326
-     * @param $uids
327
-     * @return array
328
-     */
329
-    public function checkStatus($uids)
330
-    {
331
-        $online_users = [];
332
-        $ret          = [];
333
-        if (!empty($this->user_ids)) {
334
-            $online_users = $this->user_ids;
335
-        } else {
336
-            $sql = 'SELECT online_uid FROM ' . $this->db->prefix('newbb_online');
337
-            if (!empty($uids)) {
338
-                $sql .= ' WHERE online_uid IN (' . implode(', ', array_map('intval', $uids)) . ')';
339
-            }
340
-
341
-            $result = $this->db->query($sql);
342
-            if (!$result) {
343
-                return $ret;
344
-            }
345
-            while (false !== (list($uid) = $this->db->fetchRow($result))) {
346
-                $online_users[] = $uid;
347
-            }
348
-        }
349
-        foreach ($uids as $uid) {
350
-            if (in_array($uid, $online_users)) {
351
-                $ret[$uid] = 1;
352
-            }
353
-        }
354
-
355
-        return $ret;
356
-    }
357
-
358
-    /**
359
-     * Count the number of online users
360
-     *
361
-     * @param  \CriteriaElement $criteria {@link CriteriaElement}
362
-     * @return bool
363
-     */
364
-    public function getCount(\CriteriaElement $criteria = null)
365
-    {
366
-        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online');
367
-        if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
368
-            $sql .= ' ' . $criteria->renderWhere();
369
-        }
370
-        if (!$result = $this->db->query($sql)) {
371
-            return false;
372
-        }
373
-        list($ret) = $this->db->fetchRow($result);
374
-
375
-        return $ret;
376
-    }
25
+	public $db;
26
+	public $forum_id;
27
+	public $forumObject;
28
+	public $topic_id;
29
+	public $user_ids = [];
30
+
31
+	/**
32
+	 * OnlineHandler constructor.
33
+	 * @param \XoopsDatabase $db
34
+	 */
35
+	public function __construct(\XoopsDatabase $db)
36
+	{
37
+		$this->db = $db;
38
+	}
39
+
40
+	/**
41
+	 * @param null|Newbb\Forum $forum
42
+	 * @param null|Topic  $forumtopic
43
+	 */
44
+	public function init($forum = null, $forumtopic = null)
45
+	{
46
+		if (is_object($forum)) {
47
+			$this->forum_id    = $forum->getVar('forum_id');
48
+			$this->forumObject = $forum;
49
+		} else {
50
+			$this->forum_id    = (int)$forum;
51
+			$this->forumObject = $forum;
52
+		}
53
+		if (is_object($forumtopic)) {
54
+			$this->topic_id = $forumtopic->getVar('topic_id');
55
+			if (empty($this->forum_id)) {
56
+				$this->forum_id = $forumtopic->getVar('forum_id');
57
+			}
58
+		} else {
59
+			$this->topic_id = (int)$forumtopic;
60
+		}
61
+
62
+		$this->update();
63
+	}
64
+
65
+	public function update()
66
+	{
67
+		global $xoopsModule;
68
+
69
+		mt_srand((double)microtime() * 1000000);
70
+		// set gc probabillity to 10% for now..
71
+		if (mt_rand(1, 100) < 60) {
72
+			$this->gc(150);
73
+		}
74
+		if (is_object($GLOBALS['xoopsUser'])) {
75
+			$uid   = $GLOBALS['xoopsUser']->getVar('uid');
76
+			$uname = $GLOBALS['xoopsUser']->getVar('uname');
77
+			$name  = $GLOBALS['xoopsUser']->getVar('name');
78
+		} else {
79
+			$uid   = 0;
80
+			$uname = '';
81
+			$name  = '';
82
+		}
83
+
84
+		$xoops_onlineHandler = xoops_getHandler('online');
85
+		$xoopsupdate         = $xoops_onlineHandler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), \Xmf\IPAddress::fromRequest()->asReadable());
86
+		if (!$xoopsupdate) {
87
+			//xoops_error("newbb online upate error");
88
+		}
89
+
90
+		$uname = (empty($GLOBALS['xoopsModuleConfig']['show_realname']) || empty($name)) ? $uname : $name;
91
+		$this->write($uid, $uname, time(), $this->forum_id, IPAddress::fromRequest()->asReadable(), $this->topic_id);
92
+	}
93
+
94
+	/**
95
+	 * @param $xoopsTpl
96
+	 */
97
+	public function render(\Smarty $xoopsTpl)
98
+	{
99
+		require_once  dirname(__DIR__) . '/include/functions.render.php';
100
+		require_once  dirname(__DIR__) . '/include/functions.user.php';
101
+		$criteria = null;
102
+		if ($this->topic_id) {
103
+			$criteria = new \Criteria('online_topic', $this->topic_id);
104
+		} elseif ($this->forum_id) {
105
+			$criteria = new \Criteria('online_forum', $this->forum_id);
106
+		}
107
+		$users     = $this->getAll($criteria);
108
+		$num_total = count($users);
109
+
110
+		$num_user     = 0;
111
+		$users_id     = [];
112
+		$users_online = [];
113
+		for ($i = 0; $i < $num_total; ++$i) {
114
+			if (empty($users[$i]['online_uid'])) {
115
+				continue;
116
+			}
117
+			$users_id[]                             = $users[$i]['online_uid'];
118
+			$users_online[$users[$i]['online_uid']] = [
119
+				'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
120
+				'uname' => $users[$i]['online_uname']
121
+			];
122
+			++$num_user;
123
+		}
124
+		$num_anonymous           = $num_total - $num_user;
125
+		$online                  = [];
126
+		$online['image']         = newbbDisplayImage('whosonline');
127
+		$online['num_total']     = $num_total;
128
+		$online['num_user']      = $num_user;
129
+		$online['num_anonymous'] = $num_anonymous;
130
+		$administrator_list      = newbbIsModuleAdministrators($users_id);
131
+		$moderator_list          = [];
132
+		if ($member_list = array_diff(array_keys($administrator_list), $users_id)) {
133
+			if (is_object($this->forumObject)) {
134
+				$moderator_list = $this->forumObject->getVar('forum_moderator');
135
+			} else {
136
+				$moderator_list = newbbIsForumModerators($member_list);
137
+			}
138
+		}
139
+		foreach ($users_online as $uid => $user) {
140
+			if (!empty($administrator_list[$uid])) {
141
+				$user['level'] = 2;
142
+			} elseif (!empty($moderator_list[$uid])) {
143
+				$user['level'] = 1;
144
+			} else {
145
+				$user['level'] = 0;
146
+			}
147
+			$online['users'][] = $user;
148
+		}
149
+
150
+		$xoopsTpl->assign_by_ref('online', $online);
151
+	}
152
+
153
+	/**
154
+	 * Deprecated
155
+	 */
156
+	public function showOnline()
157
+	{
158
+		require_once  dirname(__DIR__) . '/include/functions.render.php';
159
+		require_once  dirname(__DIR__) . '/include/functions.user.php';
160
+		$criteria = null;
161
+		if ($this->topic_id) {
162
+			$criteria = new \Criteria('online_topic', $this->topic_id);
163
+		} elseif ($this->forum_id) {
164
+			$criteria = new \Criteria('online_forum', $this->forum_id);
165
+		}
166
+		$users     = $this->getAll($criteria);
167
+		$num_total = count($users);
168
+
169
+		$num_user     = 0;
170
+		$users_id     = [];
171
+		$users_online = [];
172
+		for ($i = 0; $i < $num_total; ++$i) {
173
+			if (empty($users[$i]['online_uid'])) {
174
+				continue;
175
+			}
176
+			$users_id[]                             = $users[$i]['online_uid'];
177
+			$users_online[$users[$i]['online_uid']] = [
178
+				'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
179
+				'uname' => $users[$i]['online_uname']
180
+			];
181
+			++$num_user;
182
+		}
183
+		$num_anonymous           = $num_total - $num_user;
184
+		$online                  = [];
185
+		$online['image']         = newbbDisplayImage('whosonline');
186
+		$online['statistik']     = newbbDisplayImage('statistik');
187
+		$online['num_total']     = $num_total;
188
+		$online['num_user']      = $num_user;
189
+		$online['num_anonymous'] = $num_anonymous;
190
+		$administrator_list      = newbbIsModuleAdministrators($users_id);
191
+		$moderator_list          = [];
192
+		if ($member_list = array_diff($users_id, array_keys($administrator_list))) {
193
+			if (is_object($this->forumObject)) {
194
+				$moderator_list = $this->forumObject->getVar('forum_moderator');
195
+			} else {
196
+				$moderator_list = newbbIsForumModerators($member_list);
197
+			}
198
+		}
199
+
200
+		foreach ($users_online as $uid => $user) {
201
+			if (in_array($uid, $administrator_list)) {
202
+				$user['level'] = 2;
203
+			} elseif (in_array($uid, $moderator_list)) {
204
+				$user['level'] = 1;
205
+			} else {
206
+				$user['level'] = 0;
207
+			}
208
+			$online['users'][] = $user;
209
+		}
210
+
211
+		return $online;
212
+	}
213
+
214
+	/**
215
+	 * Write online information to the database
216
+	 *
217
+	 * @param  int    $uid      UID of the active user
218
+	 * @param  string $uname    Username
219
+	 * @param         $time
220
+	 * @param  string $forum_id Current forum_id
221
+	 * @param  string $ip       User's IP adress
222
+	 * @param         $topic_id
223
+	 * @return bool   TRUE on success
224
+	 * @internal param string $timestamp
225
+	 */
226
+	public function write($uid, $uname, $time, $forum_id, $ip, $topic_id)
227
+	{
228
+		global $xoopsModule, $xoopsDB;
229
+
230
+		$uid = (int)$uid;
231
+		if ($uid > 0) {
232
+			$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid;
233
+		} else {
234
+			$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid . " AND online_ip='" . $ip . "'";
235
+		}
236
+		list($count) = $this->db->fetchRow($this->db->queryF($sql));
237
+		if ($count > 0) {
238
+			$sql = 'UPDATE ' . $this->db->prefix('newbb_online') . " SET online_updated= '" . $time . "', online_forum = '" . $forum_id . "', online_topic = '" . $topic_id . "' WHERE online_uid = " . $uid;
239
+			if (0 == $uid) {
240
+				$sql .= " AND online_ip='" . $ip . "'";
241
+			}
242
+		} else {
243
+			$sql = sprintf('INSERT INTO `%s` (online_uid, online_uname, online_updated, online_ip, online_forum, online_topic) VALUES (%u, %s, %u, %s, %u, %u)', $this->db->prefix('newbb_online'), $uid, $this->db->quote($uname), $time, $this->db->quote($ip), $forum_id, $topic_id);
244
+		}
245
+		if (!$this->db->queryF($sql)) {
246
+			//xoops_error($this->db->error());
247
+			return false;
248
+		}
249
+
250
+		/** @var \XoopsOnlineHandler $xoops_onlineHandler */
251
+		$xoops_onlineHandler = xoops_getHandler('online');
252
+		$xoopsOnlineTable    = $xoops_onlineHandler->table;
253
+
254
+		$sql = 'DELETE FROM '
255
+			   . $this->db->prefix('newbb_online')
256
+			   . ' WHERE'
257
+			   . ' ( online_uid > 0 AND online_uid NOT IN ( SELECT online_uid FROM '
258
+			   . $xoopsOnlineTable
259
+			   . ' WHERE online_module ='
260
+			   . $xoopsModule->getVar('mid')
261
+			   . ' ) )'
262
+			   . ' OR ( online_uid = 0 AND online_ip NOT IN ( SELECT online_ip FROM '
263
+			   . $xoopsOnlineTable
264
+			   . ' WHERE online_module ='
265
+			   . $xoopsModule->getVar('mid')
266
+			   . ' AND online_uid = 0 ) )';
267
+
268
+		if ($result = $this->db->queryF($sql)) {
269
+			return true;
270
+		} else {
271
+			//xoops_error($this->db->error());
272
+			return false;
273
+		}
274
+	}
275
+
276
+	/**
277
+	 * Garbage Collection
278
+	 *
279
+	 * Delete all online information that has not been updated for a certain time
280
+	 *
281
+	 * @param int $expire Expiration time in seconds
282
+	 */
283
+	public function gc($expire)
284
+	{
285
+		global $xoopsModule;
286
+		$sql = 'DELETE FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_updated < ' . (time() - (int)$expire);
287
+		$this->db->queryF($sql);
288
+
289
+		$xoops_onlineHandler = xoops_getHandler('online');
290
+		$xoops_onlineHandler->gc($expire);
291
+	}
292
+
293
+	/**
294
+	 * Get an array of online information
295
+	 *
296
+	 * @param  \CriteriaElement $criteria {@link \CriteriaElement}
297
+	 * @return array           Array of associative arrays of online information
298
+	 */
299
+	public function getAll(\CriteriaElement $criteria = null)
300
+	{
301
+		$ret   = [];
302
+		$limit = $start = 0;
303
+		$sql   = 'SELECT * FROM ' . $this->db->prefix('newbb_online');
304
+		if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
305
+			$sql   .= ' ' . $criteria->renderWhere();
306
+			$limit = $criteria->getLimit();
307
+			$start = $criteria->getStart();
308
+		}
309
+		$result = $this->db->query($sql, $limit, $start);
310
+		if (!$result) {
311
+			return $ret;
312
+		}
313
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
314
+			$ret[] = $myrow;
315
+			if ($myrow['online_uid'] > 0) {
316
+				$this->user_ids[] = $myrow['online_uid'];
317
+			}
318
+			unset($myrow);
319
+		}
320
+		$this->user_ids = array_unique($this->user_ids);
321
+
322
+		return $ret;
323
+	}
324
+
325
+	/**
326
+	 * @param $uids
327
+	 * @return array
328
+	 */
329
+	public function checkStatus($uids)
330
+	{
331
+		$online_users = [];
332
+		$ret          = [];
333
+		if (!empty($this->user_ids)) {
334
+			$online_users = $this->user_ids;
335
+		} else {
336
+			$sql = 'SELECT online_uid FROM ' . $this->db->prefix('newbb_online');
337
+			if (!empty($uids)) {
338
+				$sql .= ' WHERE online_uid IN (' . implode(', ', array_map('intval', $uids)) . ')';
339
+			}
340
+
341
+			$result = $this->db->query($sql);
342
+			if (!$result) {
343
+				return $ret;
344
+			}
345
+			while (false !== (list($uid) = $this->db->fetchRow($result))) {
346
+				$online_users[] = $uid;
347
+			}
348
+		}
349
+		foreach ($uids as $uid) {
350
+			if (in_array($uid, $online_users)) {
351
+				$ret[$uid] = 1;
352
+			}
353
+		}
354
+
355
+		return $ret;
356
+	}
357
+
358
+	/**
359
+	 * Count the number of online users
360
+	 *
361
+	 * @param  \CriteriaElement $criteria {@link CriteriaElement}
362
+	 * @return bool
363
+	 */
364
+	public function getCount(\CriteriaElement $criteria = null)
365
+	{
366
+		$sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online');
367
+		if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
368
+			$sql .= ' ' . $criteria->renderWhere();
369
+		}
370
+		if (!$result = $this->db->query($sql)) {
371
+			return false;
372
+		}
373
+		list($ret) = $this->db->fetchRow($result);
374
+
375
+		return $ret;
376
+	}
377 377
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
17 17
 
18
-require_once  dirname(__DIR__) . '/include/functions.config.php';
18
+require_once  dirname(__DIR__).'/include/functions.config.php';
19 19
 
20 20
 /**
21 21
  * Class OnlineHandler
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public function render(\Smarty $xoopsTpl)
98 98
     {
99
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
100
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
99
+        require_once  dirname(__DIR__).'/include/functions.render.php';
100
+        require_once  dirname(__DIR__).'/include/functions.user.php';
101 101
         $criteria = null;
102 102
         if ($this->topic_id) {
103 103
             $criteria = new \Criteria('online_topic', $this->topic_id);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             }
117 117
             $users_id[]                             = $users[$i]['online_uid'];
118 118
             $users_online[$users[$i]['online_uid']] = [
119
-                'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
119
+                'link'  => XOOPS_URL.'/userinfo.php?uid='.$users[$i]['online_uid'],
120 120
                 'uname' => $users[$i]['online_uname']
121 121
             ];
122 122
             ++$num_user;
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function showOnline()
157 157
     {
158
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
159
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
158
+        require_once  dirname(__DIR__).'/include/functions.render.php';
159
+        require_once  dirname(__DIR__).'/include/functions.user.php';
160 160
         $criteria = null;
161 161
         if ($this->topic_id) {
162 162
             $criteria = new \Criteria('online_topic', $this->topic_id);
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             }
176 176
             $users_id[]                             = $users[$i]['online_uid'];
177 177
             $users_online[$users[$i]['online_uid']] = [
178
-                'link'  => XOOPS_URL . '/userinfo.php?uid=' . $users[$i]['online_uid'],
178
+                'link'  => XOOPS_URL.'/userinfo.php?uid='.$users[$i]['online_uid'],
179 179
                 'uname' => $users[$i]['online_uname']
180 180
             ];
181 181
             ++$num_user;
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 
230 230
         $uid = (int)$uid;
231 231
         if ($uid > 0) {
232
-            $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid;
232
+            $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('newbb_online').' WHERE online_uid='.$uid;
233 233
         } else {
234
-            $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_uid=' . $uid . " AND online_ip='" . $ip . "'";
234
+            $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('newbb_online').' WHERE online_uid='.$uid." AND online_ip='".$ip."'";
235 235
         }
236 236
         list($count) = $this->db->fetchRow($this->db->queryF($sql));
237 237
         if ($count > 0) {
238
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_online') . " SET online_updated= '" . $time . "', online_forum = '" . $forum_id . "', online_topic = '" . $topic_id . "' WHERE online_uid = " . $uid;
238
+            $sql = 'UPDATE '.$this->db->prefix('newbb_online')." SET online_updated= '".$time."', online_forum = '".$forum_id."', online_topic = '".$topic_id."' WHERE online_uid = ".$uid;
239 239
             if (0 == $uid) {
240
-                $sql .= " AND online_ip='" . $ip . "'";
240
+                $sql .= " AND online_ip='".$ip."'";
241 241
             }
242 242
         } else {
243 243
             $sql = sprintf('INSERT INTO `%s` (online_uid, online_uname, online_updated, online_ip, online_forum, online_topic) VALUES (%u, %s, %u, %s, %u, %u)', $this->db->prefix('newbb_online'), $uid, $this->db->quote($uname), $time, $this->db->quote($ip), $forum_id, $topic_id);
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     public function gc($expire)
284 284
     {
285 285
         global $xoopsModule;
286
-        $sql = 'DELETE FROM ' . $this->db->prefix('newbb_online') . ' WHERE online_updated < ' . (time() - (int)$expire);
286
+        $sql = 'DELETE FROM '.$this->db->prefix('newbb_online').' WHERE online_updated < '.(time() - (int)$expire);
287 287
         $this->db->queryF($sql);
288 288
 
289 289
         $xoops_onlineHandler = xoops_getHandler('online');
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
     {
301 301
         $ret   = [];
302 302
         $limit = $start = 0;
303
-        $sql   = 'SELECT * FROM ' . $this->db->prefix('newbb_online');
303
+        $sql   = 'SELECT * FROM '.$this->db->prefix('newbb_online');
304 304
         if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
305
-            $sql   .= ' ' . $criteria->renderWhere();
305
+            $sql .= ' '.$criteria->renderWhere();
306 306
             $limit = $criteria->getLimit();
307 307
             $start = $criteria->getStart();
308 308
         }
@@ -333,9 +333,9 @@  discard block
 block discarded – undo
333 333
         if (!empty($this->user_ids)) {
334 334
             $online_users = $this->user_ids;
335 335
         } else {
336
-            $sql = 'SELECT online_uid FROM ' . $this->db->prefix('newbb_online');
336
+            $sql = 'SELECT online_uid FROM '.$this->db->prefix('newbb_online');
337 337
             if (!empty($uids)) {
338
-                $sql .= ' WHERE online_uid IN (' . implode(', ', array_map('intval', $uids)) . ')';
338
+                $sql .= ' WHERE online_uid IN ('.implode(', ', array_map('intval', $uids)).')';
339 339
             }
340 340
 
341 341
             $result = $this->db->query($sql);
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
      */
364 364
     public function getCount(\CriteriaElement $criteria = null)
365 365
     {
366
-        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_online');
366
+        $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('newbb_online');
367 367
         if (is_object($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
368
-            $sql .= ' ' . $criteria->renderWhere();
368
+            $sql .= ' '.$criteria->renderWhere();
369 369
         }
370 370
         if (!$result = $this->db->query($sql)) {
371 371
             return false;
Please login to merge, or discard this patch.