Passed
Pull Request — master (#71)
by Dirk
05:28
created
class/Post.php 2 patches
Indentation   +668 added lines, -668 removed lines patch added patch discarded remove patch
@@ -43,672 +43,672 @@
 block discarded – undo
43 43
  */
44 44
 class Post extends \XoopsObject
45 45
 {
46
-    //class Post extends \XoopsObject {
47
-    private $attachmentArray = [];
48
-
49
-    /**
50
-     *
51
-     */
52
-    public function __construct()
53
-    {
54
-        parent::__construct();
55
-
56
-        $this->initVar('post_id', XOBJ_DTYPE_INT);
57
-        $this->initVar('topic_id', XOBJ_DTYPE_INT, 0, true);
58
-        $this->initVar('forum_id', XOBJ_DTYPE_INT, 0, true);
59
-        $this->initVar('post_time', XOBJ_DTYPE_INT, 0, true);
60
-        //        $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0);
61
-        $this->initVar('poster_ip', XOBJ_DTYPE_TXTBOX, '');
62
-        $this->initVar('poster_name', XOBJ_DTYPE_TXTBOX, '');
63
-        $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true);
64
-        $this->initVar('pid', XOBJ_DTYPE_INT, 0);
65
-        $this->initVar('dohtml', XOBJ_DTYPE_INT, 0);
66
-        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1);
67
-        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1);
68
-        $this->initVar('doimage', XOBJ_DTYPE_INT, 1);
69
-        $this->initVar('dobr', XOBJ_DTYPE_INT, 1);
70
-        $this->initVar('uid', XOBJ_DTYPE_INT, 1);
71
-        $this->initVar('icon', XOBJ_DTYPE_TXTBOX, '');
72
-        $this->initVar('attachsig', XOBJ_DTYPE_INT, 0);
73
-        $this->initVar('approved', XOBJ_DTYPE_INT, 1);
74
-        $this->initVar('post_karma', XOBJ_DTYPE_INT, 0);
75
-        $this->initVar('require_reply', XOBJ_DTYPE_INT, 0);
76
-        $this->initVar('attachment', XOBJ_DTYPE_TXTAREA, '');
77
-        $this->initVar('post_text', XOBJ_DTYPE_TXTAREA, '');
78
-        $this->initVar('post_edit', XOBJ_DTYPE_TXTAREA, '');
79
-    }
80
-
81
-    // ////////////////////////////////////////////////////////////////////////////////////
82
-    // attachment functions    TODO: there should be a file/attachment management class
83
-    /**
84
-     * @return array|mixed|null
85
-     */
86
-    public function getAttachment()
87
-    {
88
-        if (count($this->attachmentArray)) {
89
-            return $this->attachmentArray;
90
-        }
91
-        $attachment = $this->getVar('attachment');
92
-        if (empty($attachment)) {
93
-            $this->attachmentArray = [];
94
-        } else {
95
-            $this->attachmentArray = @unserialize(base64_decode($attachment));
96
-        }
97
-
98
-        return $this->attachmentArray;
99
-    }
100
-
101
-    /**
102
-     * @param $attachKey
103
-     * @return bool
104
-     */
105
-    public function incrementDownload($attachKey)
106
-    {
107
-        if (!$attachKey) {
108
-            return false;
109
-        }
110
-        $this->attachmentArray[(string)$attachKey]['numDownload']++;
111
-
112
-        return $this->attachmentArray[(string)$attachKey]['numDownload'];
113
-    }
114
-
115
-    /**
116
-     * @return bool
117
-     */
118
-    public function saveAttachment()
119
-    {
120
-        $attachmentSave = '';
121
-        if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) {
122
-            $attachmentSave = base64_encode(serialize($this->attachmentArray));
123
-        }
124
-        $this->setVar('attachment', $attachmentSave);
125
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id');
126
-        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
127
-            //xoops_error($GLOBALS['xoopsDB']->error());
128
-            return false;
129
-        }
130
-
131
-        return true;
132
-    }
133
-
134
-    /**
135
-     * @param  array|null $attachArray
136
-     * @return bool
137
-     */
138
-    public function deleteAttachment($attachArray = null)
139
-    {
140
-        $attachOld = $this->getAttachment();
141
-        if (!is_array($attachOld) || count($attachOld) < 1) {
142
-            return true;
143
-        }
144
-        $this->attachmentArray = [];
145
-
146
-        if (null === $attachArray) {
147
-            $attachArray = array_keys($attachOld);
148
-        } // to delete all!
149
-        if (!is_array($attachArray)) {
150
-            $attachArray = [$attachArray];
151
-        }
152
-
153
-        foreach ($attachOld as $key => $attach) {
154
-            if (in_array($key, $attachArray)) {
155
-                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']));
156
-                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails
157
-                continue;
158
-            }
159
-            $this->attachmentArray[$key] = $attach;
160
-        }
161
-        $attachmentSave = '';
162
-        if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) {
163
-            $attachmentSave = base64_encode(serialize($this->attachmentArray));
164
-        }
165
-        $this->setVar('attachment', $attachmentSave);
166
-
167
-        return true;
168
-    }
169
-
170
-    /**
171
-     * @param  string $name_saved
172
-     * @param  string $nameDisplay
173
-     * @param  string $mimetype
174
-     * @param  int    $numDownload
175
-     * @return bool
176
-     */
177
-    public function setAttachment($name_saved = '', $nameDisplay = '', $mimetype = '', $numDownload = 0)
178
-    {
179
-        static $counter = 0;
180
-        $this->attachmentArray = $this->getAttachment();
181
-        if ($name_saved) {
182
-            $key                         = (string)(time() + $counter++);
183
-            $this->attachmentArray[$key] = [
184
-                'name_saved'  => $name_saved,
185
-                'nameDisplay' => empty($nameDisplay) ? $nameDisplay : $name_saved,
186
-                'mimetype'    => $mimetype,
187
-                'numDownload' => empty($numDownload) ? (int)$numDownload : 0
188
-            ];
189
-        }
190
-        $attachmentSave = null;
191
-        if (is_array($this->attachmentArray)) {
192
-            $attachmentSave = base64_encode(serialize($this->attachmentArray));
193
-        }
194
-        $this->setVar('attachment', $attachmentSave);
195
-
196
-        return true;
197
-    }
198
-
199
-    /**
200
-     * TODO: refactor
201
-     * @param  bool $asSource
202
-     * @return string
203
-     */
204
-    public function displayAttachment($asSource = false)
205
-    {
206
-        global $xoopsModule;
207
-
208
-        $post_attachment = '';
209
-        $attachments     = $this->getAttachment();
210
-        if (is_array($attachments) && count($attachments) > 0) {
211
-            $iconHandler = newbbGetIconHandler();
212
-            $mime_path   = $iconHandler->getPath('mime');
213
-            require_once dirname(__DIR__) . '/include/functions.image.php';
214
-            $image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!!
215
-            $post_attachment  .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:';
216
-            $post_attachment  .= '<br><hr size="1" noshade="noshade" /><br>';
217
-            foreach ($attachments as $key => $att) {
218
-                $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
219
-                $filetype       = $file_extension;
220
-                if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) {
221
-                    $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif';
222
-                } else {
223
-                    $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif';
224
-                }
225
-                $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved']));
226
-                $file_size = number_format($file_size / 1024, 2) . ' KB';
227
-                if (in_array(strtolower($file_extension), $image_extensions)
228
-                    && $GLOBALS['xoopsModuleConfig']['media_allowed']) {
229
-                    $post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>';
230
-                    $post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']);
231
-                    $isDisplayed     = true;
232
-                } else {
233
-                    if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) {
234
-                        $post_attachment .= '<a href="'
235
-                                            . XOOPS_URL
236
-                                            . '/modules/'
237
-                                            . $xoopsModule->getVar('dirname', 'n')
238
-                                            . '/dl_attachment.php?attachid='
239
-                                            . $key
240
-                                            . '&amp;post_id='
241
-                                            . $this->getVar('post_id')
242
-                                            . '"> <img src="'
243
-                                            . $icon_filetype
244
-                                            . '" alt="'
245
-                                            . $filetype
246
-                                            . '" /> '
247
-                                            . $att['nameDisplay']
248
-                                            . '</a> '
249
-                                            . _MD_NEWBB_FILESIZE
250
-                                            . ': '
251
-                                            . $file_size
252
-                                            . '; '
253
-                                            . _MD_NEWBB_HITS
254
-                                            . ': '
255
-                                            . $att['numDownload'];
256
-                    } elseif ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->uid() > 0
257
-                              && $GLOBALS['xoopsUser']->isactive()) {
258
-                        $post_attachment .= '<a href="'
259
-                                            . XOOPS_URL
260
-                                            . '/modules/'
261
-                                            . $xoopsModule->getVar('dirname', 'n')
262
-                                            . '/dl_attachment.php?attachid='
263
-                                            . $key
264
-                                            . '&amp;post_id='
265
-                                            . $this->getVar('post_id')
266
-                                            . '"> <img src="'
267
-                                            . $icon_filetype
268
-                                            . '" alt="'
269
-                                            . $filetype
270
-                                            . '" /> '
271
-                                            . $att['nameDisplay']
272
-                                            . '</a> '
273
-                                            . _MD_NEWBB_FILESIZE
274
-                                            . ': '
275
-                                            . $file_size
276
-                                            . '; '
277
-                                            . _MD_NEWBB_HITS
278
-                                            . ': '
279
-                                            . $att['numDownload'];
280
-                    } else {
281
-                        $post_attachment .= _MD_NEWBB_SEENOTGUEST;
282
-                    }
283
-                }
284
-                $post_attachment .= '<br>';
285
-            }
286
-        }
287
-
288
-        return $post_attachment;
289
-    }
290
-    // attachment functions
291
-    // ////////////////////////////////////////////////////////////////////////////////////
292
-
293
-    /**
294
-     * @param  string $poster_name
295
-     * @param  string $post_editmsg
296
-     * @return bool
297
-     */
298
-    public function setPostEdit($poster_name = '', $post_editmsg = '')
299
-    {
300
-        $edit_user = '';
301
-        if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])
302
-            || (time() - $this->getVar('post_time')) < $GLOBALS['xoopsModuleConfig']['recordedit_timelimit'] * 60
303
-            || $this->getVar('approved') < 1) {
304
-            return true;
305
-        }
306
-        if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isActive()) {
307
-            if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $GLOBALS['xoopsUser']->getVar('name')) {
308
-                $edit_user = $GLOBALS['xoopsUser']->getVar('name');
309
-            } else {
310
-                $edit_user = $GLOBALS['xoopsUser']->getVar('uname');
311
-            }
312
-        }
313
-        $post_edit              = [];
314
-        $post_edit['edit_user'] = $edit_user; // (?) The proper way is to store uid instead of name.
315
-        // However, to save queries when displaying, the current way is ok.
316
-        $post_edit['edit_time'] = time();
317
-        $post_edit['edit_msg']  = $post_editmsg;
318
-
319
-        $post_edits = $this->getVar('post_edit');
320
-        if (!empty($post_edits)) {
321
-            $post_edits = unserialize(base64_decode($post_edits));
322
-        }
323
-        if (!is_array($post_edits)) {
324
-            $post_edits = [];
325
-        }
326
-        $post_edits[] = $post_edit;
327
-        $post_edit    = base64_encode(serialize($post_edits));
328
-        unset($post_edits);
329
-        $this->setVar('post_edit', $post_edit);
330
-
331
-        return true;
332
-    }
333
-
334
-    /**
335
-     * @return bool|string
336
-     */
337
-    public function displayPostEdit()
338
-    {
339
-        global $myts;
340
-
341
-        if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])) {
342
-            return false;
343
-        }
344
-
345
-        $post_edit  = '';
346
-        $post_edits = $this->getVar('post_edit');
347
-        if (!empty($post_edits)) {
348
-            $post_edits = unserialize(base64_decode($post_edits));
349
-        }
350
-        if (!isset($post_edits) || !is_array($post_edits)) {
351
-            $post_edits = [];
352
-        }
353
-        if (is_array($post_edits) && count($post_edits) > 0) {
354
-            foreach ($post_edits as $postedit) {
355
-                $edit_time = (int)$postedit['edit_time'];
356
-                $edit_user = $postedit['edit_user'];
357
-                $edit_msg  = !empty($postedit['edit_msg']) ? $postedit['edit_msg'] : '';
358
-                // Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
359
-                if (empty($GLOBALS['xoopsModuleConfig']['do_latestedit'])) {
360
-                    $post_edit = '';
361
-                }
362
-                // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
363
-                // START hacked by irmtfan
364
-                // display/save all edit records.
365
-                $post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>';
366
-                // if reason is not empty
367
-                if ('' !== $edit_msg) {
368
-                    $post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>';
369
-                }
370
-                // START hacked by irmtfan
371
-            }
372
-        }
373
-
374
-        return $post_edit;
375
-    }
376
-
377
-    /**
378
-     * @return array
379
-     */
380
-    public function &getPostBody()
381
-    {
382
-        global $viewtopic_users;
383
-        $newbbConfig = newbbLoadConfig();
384
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
385
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
386
-
387
-        $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
388
-        /** @var KarmaHandler $karmaHandler */
389
-        $karmaHandler = Newbb\Helper::getInstance()->getHandler('Karma');
390
-        $user_karma   = $karmaHandler->getUserKarma();
391
-
392
-        $post               = [];
393
-        $post['attachment'] = false;
394
-        $post_text          = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr'));
395
-        if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) {
396
-            $post['text'] = $post_text . '<br>' . $this->displayAttachment();
397
-        } elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
398
-            $post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma'));
399
-        } elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply')
400
-                  && (!$uid || !isset($viewtopic_users[$uid]))) {
401
-            $post['text'] = _MD_NEWBB_REPLY_REQUIREMENT;
402
-        } else {
403
-            $post['text'] = $post_text . '<br>' . $this->displayAttachment();
404
-        }
405
-        /** @var \XoopsMemberHandler $memberHandler */
406
-        $memberHandler = xoops_getHandler('member');
407
-        $eachposter    = $memberHandler->getUser($this->getVar('uid'));
408
-        if (is_object($eachposter) && $eachposter->isActive()) {
409
-            if ($newbbConfig['show_realname'] && $eachposter->getVar('name')) {
410
-                $post['author'] = $eachposter->getVar('name');
411
-            } else {
412
-                $post['author'] = $eachposter->getVar('uname');
413
-            }
414
-            unset($eachposter);
415
-        } else {
416
-            $post['author'] = $this->getVar('poster_name') ?: $GLOBALS['xoopsConfig']['anonymous'];
417
-        }
418
-
419
-        $post['subject'] = newbbHtmlspecialchars($this->vars['subject']['value']);
420
-
421
-        $post['date'] = $this->getVar('post_time');
422
-
423
-        return $post;
424
-    }
425
-
426
-    /**
427
-     * @return bool
428
-     */
429
-    public function isTopic()
430
-    {
431
-        return !$this->getVar('pid');
432
-    }
433
-
434
-    /**
435
-     * @param  string $action_tag
436
-     * @return bool
437
-     */
438
-    public function checkTimelimit($action_tag = 'edit_timelimit')
439
-    {
440
-        $newbbConfig = newbbLoadConfig();
441
-        if (empty($newbbConfig['edit_timelimit'])) {
442
-            return true;
443
-        }
444
-
445
-        return ($this->getVar('post_time') > time() - $newbbConfig[$action_tag] * 60);
446
-    }
447
-
448
-    /**
449
-     * @param  int $uid
450
-     * @return bool
451
-     */
452
-    public function checkIdentity($uid = -1)
453
-    {
454
-        $uid = ($uid > -1) ? $uid : (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0);
455
-        if ($this->getVar('uid') > 0) {
456
-            $user_ok = ($uid == $this->getVar('uid'));
457
-        } else {
458
-            static $user_ip;
459
-            if (!isset($user_ip)) {
460
-                $user_ip = \Xmf\IPAddress::fromRequest()->asReadable();
461
-            }
462
-            $user_ok = ($user_ip == $this->getVar('poster_ip'));
463
-        }
464
-
465
-        return $user_ok;
466
-    }
467
-
468
-    // TODO: cleaning up and merge with post hanldings in viewpost.php
469
-
470
-    /**
471
-     * @param $isAdmin
472
-     * @return array
473
-     */
474
-    public function showPost($isAdmin)
475
-    {
476
-        global $xoopsModule, $myts;
477
-        global $forumUrl, $forumImage, $forumObject, $online, $viewmode;
478
-        global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma;
479
-        global $order, $start, $total_posts, $topic_status;
480
-        static $post_NO = 0;
481
-        static $name_anonymous;
482
-        /** @var TopicHandler $topicHandler */
483
-        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
484
-        if (null === $name_anonymous) {
485
-            $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
486
-        }
487
-
488
-        require_once  dirname(__DIR__) . '/include/functions.time.php';
489
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
490
-
491
-        $post_id  = $this->getVar('post_id');
492
-        $topic_id = $this->getVar('topic_id');
493
-        $forum_id = $this->getVar('forum_id');
494
-
495
-        $query_vars              = ['status', 'order', 'start', 'mode', 'viewmode'];
496
-        $query_array             = [];
497
-        $query_array['topic_id'] = "topic_id={$topic_id}";
498
-        foreach ($query_vars as $var) {
499
-            if (Request::getString($var, '', 'GET')) {
500
-                $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
501
-            }
502
-        }
503
-        $page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5);
504
-
505
-        $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
506
-
507
-        ++$post_NO;
508
-        if ('desc' === strtolower($order)) {
509
-            $post_no = $total_posts - ($start + $post_NO) + 1;
510
-        } else {
511
-            $post_no = $start + $post_NO;
512
-        }
513
-
514
-        if ($isAdmin || $this->checkIdentity()) {
515
-            $post_text       = $this->getVar('post_text');
516
-            $post_attachment = $this->displayAttachment();
517
-        } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
518
-            $post_text       = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>';
519
-            $post_attachment = '';
520
-        } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply')
521
-                  && (!$uid || !in_array($uid, $viewtopic_posters))) {
522
-            $post_text       = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>';
523
-            $post_attachment = '';
524
-        } else {
525
-            $post_text       = $this->getVar('post_text');
526
-            $post_attachment = $this->displayAttachment();
527
-        }
528
-
529
-        // Hightlight search words
530
-        $post_title = $this->getVar('subject');
531
-        if ($keywords = Request::getString('keywords', '', 'GET')) {
532
-            //$keywords   = $myts->htmlSpecialChars(trim(urldecode(Request::getString('keywords', '', 'GET'))));
533
-            $post_text  = Highlighter::apply($keywords, $post_text, '<mark>', '</mark>');
534
-            $post_title = Highlighter::apply($keywords, $post_title, '<mark>', '</mark>');
535
-        }
536
-
537
-        if (isset($viewtopic_users[$this->getVar('uid')])) {
538
-            $poster = $viewtopic_users[$this->getVar('uid')];
539
-        } else {
540
-            $name   = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous;
541
-            $poster = [
542
-                'poster_uid' => 0,
543
-                'name'       => $name,
544
-                'link'       => $name
545
-            ];
546
-        }
547
-
548
-        if ($posticon = $this->getVar('icon')) {
549
-            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>';
550
-        } else {
551
-            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>';
552
-        }
553
-
554
-        $thread_buttons = [];
555
-        $mod_buttons    = [];
556
-
557
-        if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid'))
558
-            && $this->getVar('uid') > 0) {
559
-            $mod_buttons['bann']['image']    = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
560
-            $mod_buttons['bann']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
561
-            $mod_buttons['bann']['name']     = _MD_NEWBB_SUSPEND_MANAGEMENT;
562
-            $thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
563
-            $thread_buttons['bann']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
564
-            $thread_buttons['bann']['name']  = _MD_NEWBB_SUSPEND_MANAGEMENT;
565
-        }
566
-
567
-        if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) {
568
-            //            /** @var TopicHandler $topicHandler */
569
-            //            $topicHandler =  Newbb\Helper::getInstance()->getHandler('Topic');
570
-            $topic_status = $topicObject->getVar('topic_status');
571
-            if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) {
572
-                $edit_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit')));
573
-
574
-                if ($edit_ok) {
575
-                    $thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
576
-                    $thread_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
577
-                    $thread_buttons['edit']['name']  = _EDIT;
578
-                    $mod_buttons['edit']['image']    = newbbDisplayImage('p_edit', _EDIT);
579
-                    $mod_buttons['edit']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
580
-                    $mod_buttons['edit']['name']     = _EDIT;
581
-                }
582
-            }
583
-
584
-            if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) {
585
-                $delete_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit')));
586
-
587
-                if ($delete_ok) {
588
-                    $thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
589
-                    $thread_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
590
-                    $thread_buttons['delete']['name']  = _DELETE;
591
-                    $mod_buttons['delete']['image']    = newbbDisplayImage('p_delete', _DELETE);
592
-                    $mod_buttons['delete']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
593
-                    $mod_buttons['delete']['name']     = _DELETE;
594
-                }
595
-            }
596
-            if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) {
597
-                $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
598
-                $thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
599
-                $thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
600
-
601
-                $thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE);
602
-                $thread_buttons['quote']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&amp;quotedac=1";
603
-                $thread_buttons['quote']['name']  = _MD_NEWBB_QUOTE;
604
-            }
605
-        } else {
606
-            $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
607
-            $mod_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
608
-            $mod_buttons['edit']['name']  = _EDIT;
609
-
610
-            $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
611
-            $mod_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
612
-            $mod_buttons['delete']['name']  = _DELETE;
613
-
614
-            $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
615
-            $thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
616
-            $thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
617
-        }
618
-
619
-        if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) {
620
-            $thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT);
621
-            $thread_buttons['report']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}";
622
-            $thread_buttons['report']['name']  = _MD_NEWBB_REPORT;
623
-        }
624
-
625
-        $thread_action = [];
626
-        // irmtfan add pdf permission
627
-        if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')
628
-            && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) {
629
-            $thread_action['pdf']['image']  = newbbDisplayImage('pdf', _MD_NEWBB_PDF);
630
-            $thread_action['pdf']['link']   = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&amp;pageid=0';
631
-            $thread_action['pdf']['name']   = _MD_NEWBB_PDF;
632
-            $thread_action['pdf']['target'] = '_blank';
633
-        }
634
-        // irmtfan add print permission
635
-        if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) {
636
-            $thread_action['print']['image']  = newbbDisplayImage('printer', _MD_NEWBB_PRINT);
637
-            $thread_action['print']['link']   = XOOPS_URL . '/modules/newbb/print.php?form=2&amp;forum=' . $forum_id . '&amp;topic_id=' . $topic_id;
638
-            $thread_action['print']['name']   = _MD_NEWBB_PRINT;
639
-            $thread_action['print']['target'] = '_blank';
640
-        }
641
-
642
-        if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) {
643
-            $full_title  = $this->getVar('subject');
644
-            $clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject'));
645
-            $full_link   = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id;
646
-
647
-            $thread_action['social_twitter']['image']  = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER);
648
-            $thread_action['social_twitter']['link']   = 'http://twitter.com/share?text=' . $clean_title . '&amp;url=' . $full_link;
649
-            $thread_action['social_twitter']['name']   = _MD_NEWBB_SHARE_TWITTER;
650
-            $thread_action['social_twitter']['target'] = '_blank';
651
-
652
-            $thread_action['social_facebook']['image']  = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK);
653
-            $thread_action['social_facebook']['link']   = 'http://www.facebook.com/sharer.php?u=' . $full_link;
654
-            $thread_action['social_facebook']['name']   = _MD_NEWBB_SHARE_FACEBOOK;
655
-            $thread_action['social_facebook']['target'] = '_blank';
656
-
657
-            $thread_action['social_gplus']['image']  = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS);
658
-            $thread_action['social_gplus']['link']   = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link;
659
-            $thread_action['social_gplus']['name']   = _MD_NEWBB_SHARE_GOOGLEPLUS;
660
-            $thread_action['social_gplus']['target'] = '_blank';
661
-
662
-            $thread_action['social_linkedin']['image']  = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN);
663
-            $thread_action['social_linkedin']['link']   = 'http://www.linkedin.com/shareArticle?mini=true&amp;title=' . $full_title . '&amp;url=' . $full_link;
664
-            $thread_action['social_linkedin']['name']   = _MD_NEWBB_SHARE_LINKEDIN;
665
-            $thread_action['social_linkedin']['target'] = '_blank';
666
-
667
-            $thread_action['social_delicious']['image']  = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS);
668
-            $thread_action['social_delicious']['link']   = 'http://del.icio.us/post?title=' . $full_title . '&amp;url=' . $full_link;
669
-            $thread_action['social_delicious']['name']   = _MD_NEWBB_SHARE_DELICIOUS;
670
-            $thread_action['social_delicious']['target'] = '_blank';
671
-
672
-            $thread_action['social_digg']['image']  = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG);
673
-            $thread_action['social_digg']['link']   = 'http://digg.com/submit?phase=2&amp;title=' . $full_title . '&amp;url=' . $full_link;
674
-            $thread_action['social_digg']['name']   = _MD_NEWBB_SHARE_DIGG;
675
-            $thread_action['social_digg']['target'] = '_blank';
676
-
677
-            $thread_action['social_reddit']['image']  = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT);
678
-            $thread_action['social_reddit']['link']   = 'http://reddit.com/submit?title=' . $full_title . '&amp;url=' . $full_link;
679
-            $thread_action['social_reddit']['name']   = _MD_NEWBB_SHARE_REDDIT;
680
-            $thread_action['social_reddit']['target'] = '_blank';
681
-
682
-            $thread_action['social_wong']['image']  = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG);
683
-            $thread_action['social_wong']['link']   = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link;
684
-            $thread_action['social_wong']['name']   = _MD_NEWBB_SHARE_MRWONG;
685
-            $thread_action['social_wong']['target'] = '_blank';
686
-        }
687
-
688
-        $post = [
689
-            'post_id'         => $post_id,
690
-            'post_parent_id'  => $this->getVar('pid'),
691
-            'post_date'       => newbbFormatTimestamp($this->getVar('post_time')),
692
-            'post_image'      => $post_image,
693
-            'post_title'      => $post_title,
694
-            // irmtfan $post_title to add highlight keywords
695
-            'post_text'       => $post_text,
696
-            'post_attachment' => $post_attachment,
697
-            'post_edit'       => $this->displayPostEdit(),
698
-            'post_no'         => $post_no,
699
-            'post_signature'  => $this->getVar('attachsig') ? @$poster['signature'] : '',
700
-            //            'poster_ip'       => ($isAdmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : '',
701
-            'poster_ip'       => ($isAdmin
702
-                                  && $GLOBALS['xoopsModuleConfig']['show_ip']) ? $this->getVar('poster_ip') : '',
703
-            'thread_action'   => $thread_action,
704
-            'thread_buttons'  => $thread_buttons,
705
-            'mod_buttons'     => $mod_buttons,
706
-            'poster'          => $poster,
707
-            'post_permalink'  => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>'
708
-        ];
709
-
710
-        unset($thread_buttons, $mod_buttons, $eachposter);
711
-
712
-        return $post;
713
-    }
46
+	//class Post extends \XoopsObject {
47
+	private $attachmentArray = [];
48
+
49
+	/**
50
+	 *
51
+	 */
52
+	public function __construct()
53
+	{
54
+		parent::__construct();
55
+
56
+		$this->initVar('post_id', XOBJ_DTYPE_INT);
57
+		$this->initVar('topic_id', XOBJ_DTYPE_INT, 0, true);
58
+		$this->initVar('forum_id', XOBJ_DTYPE_INT, 0, true);
59
+		$this->initVar('post_time', XOBJ_DTYPE_INT, 0, true);
60
+		//        $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0);
61
+		$this->initVar('poster_ip', XOBJ_DTYPE_TXTBOX, '');
62
+		$this->initVar('poster_name', XOBJ_DTYPE_TXTBOX, '');
63
+		$this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true);
64
+		$this->initVar('pid', XOBJ_DTYPE_INT, 0);
65
+		$this->initVar('dohtml', XOBJ_DTYPE_INT, 0);
66
+		$this->initVar('dosmiley', XOBJ_DTYPE_INT, 1);
67
+		$this->initVar('doxcode', XOBJ_DTYPE_INT, 1);
68
+		$this->initVar('doimage', XOBJ_DTYPE_INT, 1);
69
+		$this->initVar('dobr', XOBJ_DTYPE_INT, 1);
70
+		$this->initVar('uid', XOBJ_DTYPE_INT, 1);
71
+		$this->initVar('icon', XOBJ_DTYPE_TXTBOX, '');
72
+		$this->initVar('attachsig', XOBJ_DTYPE_INT, 0);
73
+		$this->initVar('approved', XOBJ_DTYPE_INT, 1);
74
+		$this->initVar('post_karma', XOBJ_DTYPE_INT, 0);
75
+		$this->initVar('require_reply', XOBJ_DTYPE_INT, 0);
76
+		$this->initVar('attachment', XOBJ_DTYPE_TXTAREA, '');
77
+		$this->initVar('post_text', XOBJ_DTYPE_TXTAREA, '');
78
+		$this->initVar('post_edit', XOBJ_DTYPE_TXTAREA, '');
79
+	}
80
+
81
+	// ////////////////////////////////////////////////////////////////////////////////////
82
+	// attachment functions    TODO: there should be a file/attachment management class
83
+	/**
84
+	 * @return array|mixed|null
85
+	 */
86
+	public function getAttachment()
87
+	{
88
+		if (count($this->attachmentArray)) {
89
+			return $this->attachmentArray;
90
+		}
91
+		$attachment = $this->getVar('attachment');
92
+		if (empty($attachment)) {
93
+			$this->attachmentArray = [];
94
+		} else {
95
+			$this->attachmentArray = @unserialize(base64_decode($attachment));
96
+		}
97
+
98
+		return $this->attachmentArray;
99
+	}
100
+
101
+	/**
102
+	 * @param $attachKey
103
+	 * @return bool
104
+	 */
105
+	public function incrementDownload($attachKey)
106
+	{
107
+		if (!$attachKey) {
108
+			return false;
109
+		}
110
+		$this->attachmentArray[(string)$attachKey]['numDownload']++;
111
+
112
+		return $this->attachmentArray[(string)$attachKey]['numDownload'];
113
+	}
114
+
115
+	/**
116
+	 * @return bool
117
+	 */
118
+	public function saveAttachment()
119
+	{
120
+		$attachmentSave = '';
121
+		if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) {
122
+			$attachmentSave = base64_encode(serialize($this->attachmentArray));
123
+		}
124
+		$this->setVar('attachment', $attachmentSave);
125
+		$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id');
126
+		if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
127
+			//xoops_error($GLOBALS['xoopsDB']->error());
128
+			return false;
129
+		}
130
+
131
+		return true;
132
+	}
133
+
134
+	/**
135
+	 * @param  array|null $attachArray
136
+	 * @return bool
137
+	 */
138
+	public function deleteAttachment($attachArray = null)
139
+	{
140
+		$attachOld = $this->getAttachment();
141
+		if (!is_array($attachOld) || count($attachOld) < 1) {
142
+			return true;
143
+		}
144
+		$this->attachmentArray = [];
145
+
146
+		if (null === $attachArray) {
147
+			$attachArray = array_keys($attachOld);
148
+		} // to delete all!
149
+		if (!is_array($attachArray)) {
150
+			$attachArray = [$attachArray];
151
+		}
152
+
153
+		foreach ($attachOld as $key => $attach) {
154
+			if (in_array($key, $attachArray)) {
155
+				@unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']));
156
+				@unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails
157
+				continue;
158
+			}
159
+			$this->attachmentArray[$key] = $attach;
160
+		}
161
+		$attachmentSave = '';
162
+		if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) {
163
+			$attachmentSave = base64_encode(serialize($this->attachmentArray));
164
+		}
165
+		$this->setVar('attachment', $attachmentSave);
166
+
167
+		return true;
168
+	}
169
+
170
+	/**
171
+	 * @param  string $name_saved
172
+	 * @param  string $nameDisplay
173
+	 * @param  string $mimetype
174
+	 * @param  int    $numDownload
175
+	 * @return bool
176
+	 */
177
+	public function setAttachment($name_saved = '', $nameDisplay = '', $mimetype = '', $numDownload = 0)
178
+	{
179
+		static $counter = 0;
180
+		$this->attachmentArray = $this->getAttachment();
181
+		if ($name_saved) {
182
+			$key                         = (string)(time() + $counter++);
183
+			$this->attachmentArray[$key] = [
184
+				'name_saved'  => $name_saved,
185
+				'nameDisplay' => empty($nameDisplay) ? $nameDisplay : $name_saved,
186
+				'mimetype'    => $mimetype,
187
+				'numDownload' => empty($numDownload) ? (int)$numDownload : 0
188
+			];
189
+		}
190
+		$attachmentSave = null;
191
+		if (is_array($this->attachmentArray)) {
192
+			$attachmentSave = base64_encode(serialize($this->attachmentArray));
193
+		}
194
+		$this->setVar('attachment', $attachmentSave);
195
+
196
+		return true;
197
+	}
198
+
199
+	/**
200
+	 * TODO: refactor
201
+	 * @param  bool $asSource
202
+	 * @return string
203
+	 */
204
+	public function displayAttachment($asSource = false)
205
+	{
206
+		global $xoopsModule;
207
+
208
+		$post_attachment = '';
209
+		$attachments     = $this->getAttachment();
210
+		if (is_array($attachments) && count($attachments) > 0) {
211
+			$iconHandler = newbbGetIconHandler();
212
+			$mime_path   = $iconHandler->getPath('mime');
213
+			require_once dirname(__DIR__) . '/include/functions.image.php';
214
+			$image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!!
215
+			$post_attachment  .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:';
216
+			$post_attachment  .= '<br><hr size="1" noshade="noshade" /><br>';
217
+			foreach ($attachments as $key => $att) {
218
+				$file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
219
+				$filetype       = $file_extension;
220
+				if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) {
221
+					$icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif';
222
+				} else {
223
+					$icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif';
224
+				}
225
+				$file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved']));
226
+				$file_size = number_format($file_size / 1024, 2) . ' KB';
227
+				if (in_array(strtolower($file_extension), $image_extensions)
228
+					&& $GLOBALS['xoopsModuleConfig']['media_allowed']) {
229
+					$post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>';
230
+					$post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']);
231
+					$isDisplayed     = true;
232
+				} else {
233
+					if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) {
234
+						$post_attachment .= '<a href="'
235
+											. XOOPS_URL
236
+											. '/modules/'
237
+											. $xoopsModule->getVar('dirname', 'n')
238
+											. '/dl_attachment.php?attachid='
239
+											. $key
240
+											. '&amp;post_id='
241
+											. $this->getVar('post_id')
242
+											. '"> <img src="'
243
+											. $icon_filetype
244
+											. '" alt="'
245
+											. $filetype
246
+											. '" /> '
247
+											. $att['nameDisplay']
248
+											. '</a> '
249
+											. _MD_NEWBB_FILESIZE
250
+											. ': '
251
+											. $file_size
252
+											. '; '
253
+											. _MD_NEWBB_HITS
254
+											. ': '
255
+											. $att['numDownload'];
256
+					} elseif ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->uid() > 0
257
+							  && $GLOBALS['xoopsUser']->isactive()) {
258
+						$post_attachment .= '<a href="'
259
+											. XOOPS_URL
260
+											. '/modules/'
261
+											. $xoopsModule->getVar('dirname', 'n')
262
+											. '/dl_attachment.php?attachid='
263
+											. $key
264
+											. '&amp;post_id='
265
+											. $this->getVar('post_id')
266
+											. '"> <img src="'
267
+											. $icon_filetype
268
+											. '" alt="'
269
+											. $filetype
270
+											. '" /> '
271
+											. $att['nameDisplay']
272
+											. '</a> '
273
+											. _MD_NEWBB_FILESIZE
274
+											. ': '
275
+											. $file_size
276
+											. '; '
277
+											. _MD_NEWBB_HITS
278
+											. ': '
279
+											. $att['numDownload'];
280
+					} else {
281
+						$post_attachment .= _MD_NEWBB_SEENOTGUEST;
282
+					}
283
+				}
284
+				$post_attachment .= '<br>';
285
+			}
286
+		}
287
+
288
+		return $post_attachment;
289
+	}
290
+	// attachment functions
291
+	// ////////////////////////////////////////////////////////////////////////////////////
292
+
293
+	/**
294
+	 * @param  string $poster_name
295
+	 * @param  string $post_editmsg
296
+	 * @return bool
297
+	 */
298
+	public function setPostEdit($poster_name = '', $post_editmsg = '')
299
+	{
300
+		$edit_user = '';
301
+		if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])
302
+			|| (time() - $this->getVar('post_time')) < $GLOBALS['xoopsModuleConfig']['recordedit_timelimit'] * 60
303
+			|| $this->getVar('approved') < 1) {
304
+			return true;
305
+		}
306
+		if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isActive()) {
307
+			if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $GLOBALS['xoopsUser']->getVar('name')) {
308
+				$edit_user = $GLOBALS['xoopsUser']->getVar('name');
309
+			} else {
310
+				$edit_user = $GLOBALS['xoopsUser']->getVar('uname');
311
+			}
312
+		}
313
+		$post_edit              = [];
314
+		$post_edit['edit_user'] = $edit_user; // (?) The proper way is to store uid instead of name.
315
+		// However, to save queries when displaying, the current way is ok.
316
+		$post_edit['edit_time'] = time();
317
+		$post_edit['edit_msg']  = $post_editmsg;
318
+
319
+		$post_edits = $this->getVar('post_edit');
320
+		if (!empty($post_edits)) {
321
+			$post_edits = unserialize(base64_decode($post_edits));
322
+		}
323
+		if (!is_array($post_edits)) {
324
+			$post_edits = [];
325
+		}
326
+		$post_edits[] = $post_edit;
327
+		$post_edit    = base64_encode(serialize($post_edits));
328
+		unset($post_edits);
329
+		$this->setVar('post_edit', $post_edit);
330
+
331
+		return true;
332
+	}
333
+
334
+	/**
335
+	 * @return bool|string
336
+	 */
337
+	public function displayPostEdit()
338
+	{
339
+		global $myts;
340
+
341
+		if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])) {
342
+			return false;
343
+		}
344
+
345
+		$post_edit  = '';
346
+		$post_edits = $this->getVar('post_edit');
347
+		if (!empty($post_edits)) {
348
+			$post_edits = unserialize(base64_decode($post_edits));
349
+		}
350
+		if (!isset($post_edits) || !is_array($post_edits)) {
351
+			$post_edits = [];
352
+		}
353
+		if (is_array($post_edits) && count($post_edits) > 0) {
354
+			foreach ($post_edits as $postedit) {
355
+				$edit_time = (int)$postedit['edit_time'];
356
+				$edit_user = $postedit['edit_user'];
357
+				$edit_msg  = !empty($postedit['edit_msg']) ? $postedit['edit_msg'] : '';
358
+				// Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
359
+				if (empty($GLOBALS['xoopsModuleConfig']['do_latestedit'])) {
360
+					$post_edit = '';
361
+				}
362
+				// End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
363
+				// START hacked by irmtfan
364
+				// display/save all edit records.
365
+				$post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>';
366
+				// if reason is not empty
367
+				if ('' !== $edit_msg) {
368
+					$post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>';
369
+				}
370
+				// START hacked by irmtfan
371
+			}
372
+		}
373
+
374
+		return $post_edit;
375
+	}
376
+
377
+	/**
378
+	 * @return array
379
+	 */
380
+	public function &getPostBody()
381
+	{
382
+		global $viewtopic_users;
383
+		$newbbConfig = newbbLoadConfig();
384
+		require_once  dirname(__DIR__) . '/include/functions.user.php';
385
+		require_once  dirname(__DIR__) . '/include/functions.render.php';
386
+
387
+		$uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
388
+		/** @var KarmaHandler $karmaHandler */
389
+		$karmaHandler = Newbb\Helper::getInstance()->getHandler('Karma');
390
+		$user_karma   = $karmaHandler->getUserKarma();
391
+
392
+		$post               = [];
393
+		$post['attachment'] = false;
394
+		$post_text          = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr'));
395
+		if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) {
396
+			$post['text'] = $post_text . '<br>' . $this->displayAttachment();
397
+		} elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
398
+			$post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma'));
399
+		} elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply')
400
+				  && (!$uid || !isset($viewtopic_users[$uid]))) {
401
+			$post['text'] = _MD_NEWBB_REPLY_REQUIREMENT;
402
+		} else {
403
+			$post['text'] = $post_text . '<br>' . $this->displayAttachment();
404
+		}
405
+		/** @var \XoopsMemberHandler $memberHandler */
406
+		$memberHandler = xoops_getHandler('member');
407
+		$eachposter    = $memberHandler->getUser($this->getVar('uid'));
408
+		if (is_object($eachposter) && $eachposter->isActive()) {
409
+			if ($newbbConfig['show_realname'] && $eachposter->getVar('name')) {
410
+				$post['author'] = $eachposter->getVar('name');
411
+			} else {
412
+				$post['author'] = $eachposter->getVar('uname');
413
+			}
414
+			unset($eachposter);
415
+		} else {
416
+			$post['author'] = $this->getVar('poster_name') ?: $GLOBALS['xoopsConfig']['anonymous'];
417
+		}
418
+
419
+		$post['subject'] = newbbHtmlspecialchars($this->vars['subject']['value']);
420
+
421
+		$post['date'] = $this->getVar('post_time');
422
+
423
+		return $post;
424
+	}
425
+
426
+	/**
427
+	 * @return bool
428
+	 */
429
+	public function isTopic()
430
+	{
431
+		return !$this->getVar('pid');
432
+	}
433
+
434
+	/**
435
+	 * @param  string $action_tag
436
+	 * @return bool
437
+	 */
438
+	public function checkTimelimit($action_tag = 'edit_timelimit')
439
+	{
440
+		$newbbConfig = newbbLoadConfig();
441
+		if (empty($newbbConfig['edit_timelimit'])) {
442
+			return true;
443
+		}
444
+
445
+		return ($this->getVar('post_time') > time() - $newbbConfig[$action_tag] * 60);
446
+	}
447
+
448
+	/**
449
+	 * @param  int $uid
450
+	 * @return bool
451
+	 */
452
+	public function checkIdentity($uid = -1)
453
+	{
454
+		$uid = ($uid > -1) ? $uid : (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0);
455
+		if ($this->getVar('uid') > 0) {
456
+			$user_ok = ($uid == $this->getVar('uid'));
457
+		} else {
458
+			static $user_ip;
459
+			if (!isset($user_ip)) {
460
+				$user_ip = \Xmf\IPAddress::fromRequest()->asReadable();
461
+			}
462
+			$user_ok = ($user_ip == $this->getVar('poster_ip'));
463
+		}
464
+
465
+		return $user_ok;
466
+	}
467
+
468
+	// TODO: cleaning up and merge with post hanldings in viewpost.php
469
+
470
+	/**
471
+	 * @param $isAdmin
472
+	 * @return array
473
+	 */
474
+	public function showPost($isAdmin)
475
+	{
476
+		global $xoopsModule, $myts;
477
+		global $forumUrl, $forumImage, $forumObject, $online, $viewmode;
478
+		global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma;
479
+		global $order, $start, $total_posts, $topic_status;
480
+		static $post_NO = 0;
481
+		static $name_anonymous;
482
+		/** @var TopicHandler $topicHandler */
483
+		$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
484
+		if (null === $name_anonymous) {
485
+			$name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
486
+		}
487
+
488
+		require_once  dirname(__DIR__) . '/include/functions.time.php';
489
+		require_once  dirname(__DIR__) . '/include/functions.render.php';
490
+
491
+		$post_id  = $this->getVar('post_id');
492
+		$topic_id = $this->getVar('topic_id');
493
+		$forum_id = $this->getVar('forum_id');
494
+
495
+		$query_vars              = ['status', 'order', 'start', 'mode', 'viewmode'];
496
+		$query_array             = [];
497
+		$query_array['topic_id'] = "topic_id={$topic_id}";
498
+		foreach ($query_vars as $var) {
499
+			if (Request::getString($var, '', 'GET')) {
500
+				$query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
501
+			}
502
+		}
503
+		$page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5);
504
+
505
+		$uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
506
+
507
+		++$post_NO;
508
+		if ('desc' === strtolower($order)) {
509
+			$post_no = $total_posts - ($start + $post_NO) + 1;
510
+		} else {
511
+			$post_no = $start + $post_NO;
512
+		}
513
+
514
+		if ($isAdmin || $this->checkIdentity()) {
515
+			$post_text       = $this->getVar('post_text');
516
+			$post_attachment = $this->displayAttachment();
517
+		} elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
518
+			$post_text       = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>';
519
+			$post_attachment = '';
520
+		} elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply')
521
+				  && (!$uid || !in_array($uid, $viewtopic_posters))) {
522
+			$post_text       = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>';
523
+			$post_attachment = '';
524
+		} else {
525
+			$post_text       = $this->getVar('post_text');
526
+			$post_attachment = $this->displayAttachment();
527
+		}
528
+
529
+		// Hightlight search words
530
+		$post_title = $this->getVar('subject');
531
+		if ($keywords = Request::getString('keywords', '', 'GET')) {
532
+			//$keywords   = $myts->htmlSpecialChars(trim(urldecode(Request::getString('keywords', '', 'GET'))));
533
+			$post_text  = Highlighter::apply($keywords, $post_text, '<mark>', '</mark>');
534
+			$post_title = Highlighter::apply($keywords, $post_title, '<mark>', '</mark>');
535
+		}
536
+
537
+		if (isset($viewtopic_users[$this->getVar('uid')])) {
538
+			$poster = $viewtopic_users[$this->getVar('uid')];
539
+		} else {
540
+			$name   = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous;
541
+			$poster = [
542
+				'poster_uid' => 0,
543
+				'name'       => $name,
544
+				'link'       => $name
545
+			];
546
+		}
547
+
548
+		if ($posticon = $this->getVar('icon')) {
549
+			$post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>';
550
+		} else {
551
+			$post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>';
552
+		}
553
+
554
+		$thread_buttons = [];
555
+		$mod_buttons    = [];
556
+
557
+		if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid'))
558
+			&& $this->getVar('uid') > 0) {
559
+			$mod_buttons['bann']['image']    = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
560
+			$mod_buttons['bann']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
561
+			$mod_buttons['bann']['name']     = _MD_NEWBB_SUSPEND_MANAGEMENT;
562
+			$thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
563
+			$thread_buttons['bann']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
564
+			$thread_buttons['bann']['name']  = _MD_NEWBB_SUSPEND_MANAGEMENT;
565
+		}
566
+
567
+		if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) {
568
+			//            /** @var TopicHandler $topicHandler */
569
+			//            $topicHandler =  Newbb\Helper::getInstance()->getHandler('Topic');
570
+			$topic_status = $topicObject->getVar('topic_status');
571
+			if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) {
572
+				$edit_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit')));
573
+
574
+				if ($edit_ok) {
575
+					$thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
576
+					$thread_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
577
+					$thread_buttons['edit']['name']  = _EDIT;
578
+					$mod_buttons['edit']['image']    = newbbDisplayImage('p_edit', _EDIT);
579
+					$mod_buttons['edit']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
580
+					$mod_buttons['edit']['name']     = _EDIT;
581
+				}
582
+			}
583
+
584
+			if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) {
585
+				$delete_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit')));
586
+
587
+				if ($delete_ok) {
588
+					$thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
589
+					$thread_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
590
+					$thread_buttons['delete']['name']  = _DELETE;
591
+					$mod_buttons['delete']['image']    = newbbDisplayImage('p_delete', _DELETE);
592
+					$mod_buttons['delete']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
593
+					$mod_buttons['delete']['name']     = _DELETE;
594
+				}
595
+			}
596
+			if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) {
597
+				$thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
598
+				$thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
599
+				$thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
600
+
601
+				$thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE);
602
+				$thread_buttons['quote']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&amp;quotedac=1";
603
+				$thread_buttons['quote']['name']  = _MD_NEWBB_QUOTE;
604
+			}
605
+		} else {
606
+			$mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
607
+			$mod_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
608
+			$mod_buttons['edit']['name']  = _EDIT;
609
+
610
+			$mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
611
+			$mod_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
612
+			$mod_buttons['delete']['name']  = _DELETE;
613
+
614
+			$thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
615
+			$thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
616
+			$thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
617
+		}
618
+
619
+		if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) {
620
+			$thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT);
621
+			$thread_buttons['report']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}";
622
+			$thread_buttons['report']['name']  = _MD_NEWBB_REPORT;
623
+		}
624
+
625
+		$thread_action = [];
626
+		// irmtfan add pdf permission
627
+		if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')
628
+			&& $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) {
629
+			$thread_action['pdf']['image']  = newbbDisplayImage('pdf', _MD_NEWBB_PDF);
630
+			$thread_action['pdf']['link']   = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&amp;pageid=0';
631
+			$thread_action['pdf']['name']   = _MD_NEWBB_PDF;
632
+			$thread_action['pdf']['target'] = '_blank';
633
+		}
634
+		// irmtfan add print permission
635
+		if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) {
636
+			$thread_action['print']['image']  = newbbDisplayImage('printer', _MD_NEWBB_PRINT);
637
+			$thread_action['print']['link']   = XOOPS_URL . '/modules/newbb/print.php?form=2&amp;forum=' . $forum_id . '&amp;topic_id=' . $topic_id;
638
+			$thread_action['print']['name']   = _MD_NEWBB_PRINT;
639
+			$thread_action['print']['target'] = '_blank';
640
+		}
641
+
642
+		if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) {
643
+			$full_title  = $this->getVar('subject');
644
+			$clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject'));
645
+			$full_link   = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id;
646
+
647
+			$thread_action['social_twitter']['image']  = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER);
648
+			$thread_action['social_twitter']['link']   = 'http://twitter.com/share?text=' . $clean_title . '&amp;url=' . $full_link;
649
+			$thread_action['social_twitter']['name']   = _MD_NEWBB_SHARE_TWITTER;
650
+			$thread_action['social_twitter']['target'] = '_blank';
651
+
652
+			$thread_action['social_facebook']['image']  = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK);
653
+			$thread_action['social_facebook']['link']   = 'http://www.facebook.com/sharer.php?u=' . $full_link;
654
+			$thread_action['social_facebook']['name']   = _MD_NEWBB_SHARE_FACEBOOK;
655
+			$thread_action['social_facebook']['target'] = '_blank';
656
+
657
+			$thread_action['social_gplus']['image']  = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS);
658
+			$thread_action['social_gplus']['link']   = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link;
659
+			$thread_action['social_gplus']['name']   = _MD_NEWBB_SHARE_GOOGLEPLUS;
660
+			$thread_action['social_gplus']['target'] = '_blank';
661
+
662
+			$thread_action['social_linkedin']['image']  = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN);
663
+			$thread_action['social_linkedin']['link']   = 'http://www.linkedin.com/shareArticle?mini=true&amp;title=' . $full_title . '&amp;url=' . $full_link;
664
+			$thread_action['social_linkedin']['name']   = _MD_NEWBB_SHARE_LINKEDIN;
665
+			$thread_action['social_linkedin']['target'] = '_blank';
666
+
667
+			$thread_action['social_delicious']['image']  = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS);
668
+			$thread_action['social_delicious']['link']   = 'http://del.icio.us/post?title=' . $full_title . '&amp;url=' . $full_link;
669
+			$thread_action['social_delicious']['name']   = _MD_NEWBB_SHARE_DELICIOUS;
670
+			$thread_action['social_delicious']['target'] = '_blank';
671
+
672
+			$thread_action['social_digg']['image']  = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG);
673
+			$thread_action['social_digg']['link']   = 'http://digg.com/submit?phase=2&amp;title=' . $full_title . '&amp;url=' . $full_link;
674
+			$thread_action['social_digg']['name']   = _MD_NEWBB_SHARE_DIGG;
675
+			$thread_action['social_digg']['target'] = '_blank';
676
+
677
+			$thread_action['social_reddit']['image']  = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT);
678
+			$thread_action['social_reddit']['link']   = 'http://reddit.com/submit?title=' . $full_title . '&amp;url=' . $full_link;
679
+			$thread_action['social_reddit']['name']   = _MD_NEWBB_SHARE_REDDIT;
680
+			$thread_action['social_reddit']['target'] = '_blank';
681
+
682
+			$thread_action['social_wong']['image']  = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG);
683
+			$thread_action['social_wong']['link']   = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link;
684
+			$thread_action['social_wong']['name']   = _MD_NEWBB_SHARE_MRWONG;
685
+			$thread_action['social_wong']['target'] = '_blank';
686
+		}
687
+
688
+		$post = [
689
+			'post_id'         => $post_id,
690
+			'post_parent_id'  => $this->getVar('pid'),
691
+			'post_date'       => newbbFormatTimestamp($this->getVar('post_time')),
692
+			'post_image'      => $post_image,
693
+			'post_title'      => $post_title,
694
+			// irmtfan $post_title to add highlight keywords
695
+			'post_text'       => $post_text,
696
+			'post_attachment' => $post_attachment,
697
+			'post_edit'       => $this->displayPostEdit(),
698
+			'post_no'         => $post_no,
699
+			'post_signature'  => $this->getVar('attachsig') ? @$poster['signature'] : '',
700
+			//            'poster_ip'       => ($isAdmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : '',
701
+			'poster_ip'       => ($isAdmin
702
+								  && $GLOBALS['xoopsModuleConfig']['show_ip']) ? $this->getVar('poster_ip') : '',
703
+			'thread_action'   => $thread_action,
704
+			'thread_buttons'  => $thread_buttons,
705
+			'mod_buttons'     => $mod_buttons,
706
+			'poster'          => $poster,
707
+			'post_permalink'  => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>'
708
+		];
709
+
710
+		unset($thread_buttons, $mod_buttons, $eachposter);
711
+
712
+		return $post;
713
+	}
714 714
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
         if (!$attachKey) {
108 108
             return false;
109 109
         }
110
-        $this->attachmentArray[(string)$attachKey]['numDownload']++;
110
+        $this->attachmentArray[(string) $attachKey]['numDownload']++;
111 111
 
112
-        return $this->attachmentArray[(string)$attachKey]['numDownload'];
112
+        return $this->attachmentArray[(string) $attachKey]['numDownload'];
113 113
     }
114 114
 
115 115
     /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
             $attachmentSave = base64_encode(serialize($this->attachmentArray));
123 123
         }
124 124
         $this->setVar('attachment', $attachmentSave);
125
-        $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id');
125
+        $sql = 'UPDATE '.$GLOBALS['xoopsDB']->prefix('newbb_posts').' SET attachment='.$GLOBALS['xoopsDB']->quoteString($attachmentSave).' WHERE post_id = '.$this->getVar('post_id');
126 126
         if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
127 127
             //xoops_error($GLOBALS['xoopsDB']->error());
128 128
             return false;
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 
153 153
         foreach ($attachOld as $key => $attach) {
154 154
             if (in_array($key, $attachArray)) {
155
-                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']));
156
-                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails
155
+                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/'.$attach['name_saved']));
156
+                @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/thumbs/'.$attach['name_saved'])); // delete thumbnails
157 157
                 continue;
158 158
             }
159 159
             $this->attachmentArray[$key] = $attach;
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
         static $counter = 0;
180 180
         $this->attachmentArray = $this->getAttachment();
181 181
         if ($name_saved) {
182
-            $key                         = (string)(time() + $counter++);
182
+            $key                         = (string) (time() + $counter++);
183 183
             $this->attachmentArray[$key] = [
184 184
                 'name_saved'  => $name_saved,
185 185
                 'nameDisplay' => empty($nameDisplay) ? $nameDisplay : $name_saved,
186 186
                 'mimetype'    => $mimetype,
187
-                'numDownload' => empty($numDownload) ? (int)$numDownload : 0
187
+                'numDownload' => empty($numDownload) ? (int) $numDownload : 0
188 188
             ];
189 189
         }
190 190
         $attachmentSave = null;
@@ -210,25 +210,25 @@  discard block
 block discarded – undo
210 210
         if (is_array($attachments) && count($attachments) > 0) {
211 211
             $iconHandler = newbbGetIconHandler();
212 212
             $mime_path   = $iconHandler->getPath('mime');
213
-            require_once dirname(__DIR__) . '/include/functions.image.php';
213
+            require_once dirname(__DIR__).'/include/functions.image.php';
214 214
             $image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!!
215
-            $post_attachment  .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:';
215
+            $post_attachment  .= '<br><strong>'._MD_NEWBB_ATTACHMENT.'</strong>:';
216 216
             $post_attachment  .= '<br><hr size="1" noshade="noshade" /><br>';
217 217
             foreach ($attachments as $key => $att) {
218 218
                 $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
219 219
                 $filetype       = $file_extension;
220
-                if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) {
221
-                    $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif';
220
+                if (file_exists($GLOBALS['xoops']->path($mime_path.'/'.$filetype.'.gif'))) {
221
+                    $icon_filetype = XOOPS_URL.'/'.$mime_path.'/'.$filetype.'.gif';
222 222
                 } else {
223
-                    $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif';
223
+                    $icon_filetype = XOOPS_URL.'/'.$mime_path.'/unknown.gif';
224 224
                 }
225
-                $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved']));
226
-                $file_size = number_format($file_size / 1024, 2) . ' KB';
225
+                $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/'.$att['name_saved']));
226
+                $file_size = number_format($file_size / 1024, 2).' KB';
227 227
                 if (in_array(strtolower($file_extension), $image_extensions)
228 228
                     && $GLOBALS['xoopsModuleConfig']['media_allowed']) {
229
-                    $post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>';
230
-                    $post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']);
231
-                    $isDisplayed     = true;
229
+                    $post_attachment .= '<br><img src="'.$icon_filetype.'" alt="'.$filetype.'" /><strong>&nbsp; '.$att['nameDisplay'].'</strong> <small>('.$file_size.')</small>';
230
+                    $post_attachment .= '<br>'.newbbAttachmentImage($att['name_saved']);
231
+                    $isDisplayed = true;
232 232
                 } else {
233 233
                     if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) {
234 234
                         $post_attachment .= '<a href="'
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
         }
353 353
         if (is_array($post_edits) && count($post_edits) > 0) {
354 354
             foreach ($post_edits as $postedit) {
355
-                $edit_time = (int)$postedit['edit_time'];
355
+                $edit_time = (int) $postedit['edit_time'];
356 356
                 $edit_user = $postedit['edit_user'];
357 357
                 $edit_msg  = !empty($postedit['edit_msg']) ? $postedit['edit_msg'] : '';
358 358
                 // Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
@@ -362,10 +362,10 @@  discard block
 block discarded – undo
362 362
                 // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
363 363
                 // START hacked by irmtfan
364 364
                 // display/save all edit records.
365
-                $post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>';
365
+                $post_edit .= _MD_NEWBB_EDITEDBY.' '.$edit_user.' '._MD_NEWBB_ON.' '.formatTimestamp($edit_time).'<br>';
366 366
                 // if reason is not empty
367 367
                 if ('' !== $edit_msg) {
368
-                    $post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>';
368
+                    $post_edit .= _MD_NEWBB_EDITEDMSG.' '.$edit_msg.'<br>';
369 369
                 }
370 370
                 // START hacked by irmtfan
371 371
             }
@@ -381,8 +381,8 @@  discard block
 block discarded – undo
381 381
     {
382 382
         global $viewtopic_users;
383 383
         $newbbConfig = newbbLoadConfig();
384
-        require_once  dirname(__DIR__) . '/include/functions.user.php';
385
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
384
+        require_once  dirname(__DIR__).'/include/functions.user.php';
385
+        require_once  dirname(__DIR__).'/include/functions.render.php';
386 386
 
387 387
         $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
388 388
         /** @var KarmaHandler $karmaHandler */
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
         $post['attachment'] = false;
394 394
         $post_text          = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr'));
395 395
         if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) {
396
-            $post['text'] = $post_text . '<br>' . $this->displayAttachment();
396
+            $post['text'] = $post_text.'<br>'.$this->displayAttachment();
397 397
         } elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
398 398
             $post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma'));
399 399
         } elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply')
400 400
                   && (!$uid || !isset($viewtopic_users[$uid]))) {
401 401
             $post['text'] = _MD_NEWBB_REPLY_REQUIREMENT;
402 402
         } else {
403
-            $post['text'] = $post_text . '<br>' . $this->displayAttachment();
403
+            $post['text'] = $post_text.'<br>'.$this->displayAttachment();
404 404
         }
405 405
         /** @var \XoopsMemberHandler $memberHandler */
406 406
         $memberHandler = xoops_getHandler('member');
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
             $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
486 486
         }
487 487
 
488
-        require_once  dirname(__DIR__) . '/include/functions.time.php';
489
-        require_once  dirname(__DIR__) . '/include/functions.render.php';
488
+        require_once  dirname(__DIR__).'/include/functions.time.php';
489
+        require_once  dirname(__DIR__).'/include/functions.render.php';
490 490
 
491 491
         $post_id  = $this->getVar('post_id');
492 492
         $topic_id = $this->getVar('topic_id');
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         $query_array['topic_id'] = "topic_id={$topic_id}";
498 498
         foreach ($query_vars as $var) {
499 499
             if (Request::getString($var, '', 'GET')) {
500
-                $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET');
500
+                $query_array[$var] = "{$var}=".Request::getString($var, '', 'GET');
501 501
             }
502 502
         }
503 503
         $page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5);
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
             $post_text       = $this->getVar('post_text');
516 516
             $post_attachment = $this->displayAttachment();
517 517
         } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
518
-            $post_text       = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>';
518
+            $post_text       = "<div class='karma'>".sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')).'</div>';
519 519
             $post_attachment = '';
520 520
         } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply')
521 521
                   && (!$uid || !in_array($uid, $viewtopic_posters))) {
522
-            $post_text       = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>';
522
+            $post_text       = "<div class='karma'>"._MD_NEWBB_REPLY_REQUIREMENT.'</div>';
523 523
             $post_attachment = '';
524 524
         } else {
525 525
             $post_text       = $this->getVar('post_text');
@@ -546,9 +546,9 @@  discard block
 block discarded – undo
546 546
         }
547 547
 
548 548
         if ($posticon = $this->getVar('icon')) {
549
-            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>';
549
+            $post_image = '<a name="'.$post_id.'"><img src="'.XOOPS_URL.'/images/subject/'.$posticon.'" alt="" /></a>';
550 550
         } else {
551
-            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>';
551
+            $post_image = '<a name="'.$post_id.'"><img src="'.XOOPS_URL.'/images/icons/posticon.gif" alt="" /></a>';
552 552
         }
553 553
 
554 554
         $thread_buttons = [];
@@ -557,10 +557,10 @@  discard block
 block discarded – undo
557 557
         if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid'))
558 558
             && $this->getVar('uid') > 0) {
559 559
             $mod_buttons['bann']['image']    = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
560
-            $mod_buttons['bann']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
560
+            $mod_buttons['bann']['link']     = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/moderate.php?forum='.$forum_id.'&amp;uid='.$this->getVar('uid');
561 561
             $mod_buttons['bann']['name']     = _MD_NEWBB_SUSPEND_MANAGEMENT;
562 562
             $thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT);
563
-            $thread_buttons['bann']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&amp;uid=' . $this->getVar('uid');
563
+            $thread_buttons['bann']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/moderate.php?forum='.$forum_id.'&amp;uid='.$this->getVar('uid');
564 564
             $thread_buttons['bann']['name']  = _MD_NEWBB_SUSPEND_MANAGEMENT;
565 565
         }
566 566
 
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
 
574 574
                 if ($edit_ok) {
575 575
                     $thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
576
-                    $thread_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
576
+                    $thread_buttons['edit']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}";
577 577
                     $thread_buttons['edit']['name']  = _EDIT;
578 578
                     $mod_buttons['edit']['image']    = newbbDisplayImage('p_edit', _EDIT);
579
-                    $mod_buttons['edit']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
579
+                    $mod_buttons['edit']['link']     = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}";
580 580
                     $mod_buttons['edit']['name']     = _EDIT;
581 581
                 }
582 582
             }
@@ -586,55 +586,55 @@  discard block
 block discarded – undo
586 586
 
587 587
                 if ($delete_ok) {
588 588
                     $thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
589
-                    $thread_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
589
+                    $thread_buttons['delete']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}";
590 590
                     $thread_buttons['delete']['name']  = _DELETE;
591 591
                     $mod_buttons['delete']['image']    = newbbDisplayImage('p_delete', _DELETE);
592
-                    $mod_buttons['delete']['link']     = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
592
+                    $mod_buttons['delete']['link']     = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}";
593 593
                     $mod_buttons['delete']['name']     = _DELETE;
594 594
                 }
595 595
             }
596 596
             if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) {
597 597
                 $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
598
-                $thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
598
+                $thread_buttons['reply']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}";
599 599
                 $thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
600 600
 
601 601
                 $thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE);
602
-                $thread_buttons['quote']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&amp;quotedac=1";
602
+                $thread_buttons['quote']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}&amp;quotedac=1";
603 603
                 $thread_buttons['quote']['name']  = _MD_NEWBB_QUOTE;
604 604
             }
605 605
         } else {
606 606
             $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT);
607
-            $mod_buttons['edit']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}";
607
+            $mod_buttons['edit']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}";
608 608
             $mod_buttons['edit']['name']  = _EDIT;
609 609
 
610 610
             $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE);
611
-            $mod_buttons['delete']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}";
611
+            $mod_buttons['delete']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}";
612 612
             $mod_buttons['delete']['name']  = _DELETE;
613 613
 
614 614
             $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY);
615
-            $thread_buttons['reply']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}";
615
+            $thread_buttons['reply']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}";
616 616
             $thread_buttons['reply']['name']  = _MD_NEWBB_REPLY;
617 617
         }
618 618
 
619 619
         if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) {
620 620
             $thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT);
621
-            $thread_buttons['report']['link']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}";
621
+            $thread_buttons['report']['link']  = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/report.php?{$page_query}";
622 622
             $thread_buttons['report']['name']  = _MD_NEWBB_REPORT;
623 623
         }
624 624
 
625 625
         $thread_action = [];
626 626
         // irmtfan add pdf permission
627
-        if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')
627
+        if (file_exists(XOOPS_ROOT_PATH.'/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')
628 628
             && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) {
629 629
             $thread_action['pdf']['image']  = newbbDisplayImage('pdf', _MD_NEWBB_PDF);
630
-            $thread_action['pdf']['link']   = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&amp;pageid=0';
630
+            $thread_action['pdf']['link']   = XOOPS_URL.'/modules/newbb/makepdf.php?type=post&amp;pageid=0';
631 631
             $thread_action['pdf']['name']   = _MD_NEWBB_PDF;
632 632
             $thread_action['pdf']['target'] = '_blank';
633 633
         }
634 634
         // irmtfan add print permission
635 635
         if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) {
636 636
             $thread_action['print']['image']  = newbbDisplayImage('printer', _MD_NEWBB_PRINT);
637
-            $thread_action['print']['link']   = XOOPS_URL . '/modules/newbb/print.php?form=2&amp;forum=' . $forum_id . '&amp;topic_id=' . $topic_id;
637
+            $thread_action['print']['link']   = XOOPS_URL.'/modules/newbb/print.php?form=2&amp;forum='.$forum_id.'&amp;topic_id='.$topic_id;
638 638
             $thread_action['print']['name']   = _MD_NEWBB_PRINT;
639 639
             $thread_action['print']['target'] = '_blank';
640 640
         }
@@ -642,45 +642,45 @@  discard block
 block discarded – undo
642 642
         if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) {
643 643
             $full_title  = $this->getVar('subject');
644 644
             $clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject'));
645
-            $full_link   = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id;
645
+            $full_link   = XOOPS_URL.'/modules/newbb/viewtopic.php?post_id='.$post_id;
646 646
 
647 647
             $thread_action['social_twitter']['image']  = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER);
648
-            $thread_action['social_twitter']['link']   = 'http://twitter.com/share?text=' . $clean_title . '&amp;url=' . $full_link;
648
+            $thread_action['social_twitter']['link']   = 'http://twitter.com/share?text='.$clean_title.'&amp;url='.$full_link;
649 649
             $thread_action['social_twitter']['name']   = _MD_NEWBB_SHARE_TWITTER;
650 650
             $thread_action['social_twitter']['target'] = '_blank';
651 651
 
652 652
             $thread_action['social_facebook']['image']  = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK);
653
-            $thread_action['social_facebook']['link']   = 'http://www.facebook.com/sharer.php?u=' . $full_link;
653
+            $thread_action['social_facebook']['link']   = 'http://www.facebook.com/sharer.php?u='.$full_link;
654 654
             $thread_action['social_facebook']['name']   = _MD_NEWBB_SHARE_FACEBOOK;
655 655
             $thread_action['social_facebook']['target'] = '_blank';
656 656
 
657 657
             $thread_action['social_gplus']['image']  = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS);
658
-            $thread_action['social_gplus']['link']   = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link;
658
+            $thread_action['social_gplus']['link']   = 'https://plusone.google.com/_/+1/confirm?hl=en&url='.$full_link;
659 659
             $thread_action['social_gplus']['name']   = _MD_NEWBB_SHARE_GOOGLEPLUS;
660 660
             $thread_action['social_gplus']['target'] = '_blank';
661 661
 
662 662
             $thread_action['social_linkedin']['image']  = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN);
663
-            $thread_action['social_linkedin']['link']   = 'http://www.linkedin.com/shareArticle?mini=true&amp;title=' . $full_title . '&amp;url=' . $full_link;
663
+            $thread_action['social_linkedin']['link']   = 'http://www.linkedin.com/shareArticle?mini=true&amp;title='.$full_title.'&amp;url='.$full_link;
664 664
             $thread_action['social_linkedin']['name']   = _MD_NEWBB_SHARE_LINKEDIN;
665 665
             $thread_action['social_linkedin']['target'] = '_blank';
666 666
 
667 667
             $thread_action['social_delicious']['image']  = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS);
668
-            $thread_action['social_delicious']['link']   = 'http://del.icio.us/post?title=' . $full_title . '&amp;url=' . $full_link;
668
+            $thread_action['social_delicious']['link']   = 'http://del.icio.us/post?title='.$full_title.'&amp;url='.$full_link;
669 669
             $thread_action['social_delicious']['name']   = _MD_NEWBB_SHARE_DELICIOUS;
670 670
             $thread_action['social_delicious']['target'] = '_blank';
671 671
 
672 672
             $thread_action['social_digg']['image']  = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG);
673
-            $thread_action['social_digg']['link']   = 'http://digg.com/submit?phase=2&amp;title=' . $full_title . '&amp;url=' . $full_link;
673
+            $thread_action['social_digg']['link']   = 'http://digg.com/submit?phase=2&amp;title='.$full_title.'&amp;url='.$full_link;
674 674
             $thread_action['social_digg']['name']   = _MD_NEWBB_SHARE_DIGG;
675 675
             $thread_action['social_digg']['target'] = '_blank';
676 676
 
677 677
             $thread_action['social_reddit']['image']  = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT);
678
-            $thread_action['social_reddit']['link']   = 'http://reddit.com/submit?title=' . $full_title . '&amp;url=' . $full_link;
678
+            $thread_action['social_reddit']['link']   = 'http://reddit.com/submit?title='.$full_title.'&amp;url='.$full_link;
679 679
             $thread_action['social_reddit']['name']   = _MD_NEWBB_SHARE_REDDIT;
680 680
             $thread_action['social_reddit']['target'] = '_blank';
681 681
 
682 682
             $thread_action['social_wong']['image']  = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG);
683
-            $thread_action['social_wong']['link']   = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link;
683
+            $thread_action['social_wong']['link']   = 'http://www.mister-wong.de/index.php?action=addurl&bm_url='.$full_link;
684 684
             $thread_action['social_wong']['name']   = _MD_NEWBB_SHARE_MRWONG;
685 685
             $thread_action['social_wong']['target'] = '_blank';
686 686
         }
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             'thread_buttons'  => $thread_buttons,
705 705
             'mod_buttons'     => $mod_buttons,
706 706
             'poster'          => $poster,
707
-            'post_permalink'  => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>'
707
+            'post_permalink'  => '<a href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/viewtopic.php?post_id='.$post_id.'"></a>'
708 708
         ];
709 709
 
710 710
         unset($thread_buttons, $mod_buttons, $eachposter);
Please login to merge, or discard this patch.
class/PermissionCategoryHandler.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -23,82 +23,82 @@
 block discarded – undo
23 23
  */
24 24
 class PermissionCategoryHandler extends Newbb\PermissionHandler
25 25
 {
26
-    /**
27
-     * @param \XoopsDatabase $db
28
-     */
29
-    public function __construct(\XoopsDatabase $db = null)
30
-    {
31
-        //        $this->PermissionHandler($db);
32
-        parent::__construct($db);
33
-    }
26
+	/**
27
+	 * @param \XoopsDatabase $db
28
+	 */
29
+	public function __construct(\XoopsDatabase $db = null)
30
+	{
31
+		//        $this->PermissionHandler($db);
32
+		parent::__construct($db);
33
+	}
34 34
 
35
-    /**
36
-     * @param        $mid
37
-     * @param  int   $id
38
-     * @return array
39
-     */
40
-    public function getValidItems($mid, $id = 0)
41
-    {
42
-        $full_items = [];
43
-        if (empty($mid)) {
44
-            return $full_items;
45
-        }
35
+	/**
36
+	 * @param        $mid
37
+	 * @param  int   $id
38
+	 * @return array
39
+	 */
40
+	public function getValidItems($mid, $id = 0)
41
+	{
42
+		$full_items = [];
43
+		if (empty($mid)) {
44
+			return $full_items;
45
+		}
46 46
 
47
-        $full_items[] = "'category_access'";
47
+		$full_items[] = "'category_access'";
48 48
 
49
-        return $full_items;
50
-    }
49
+		return $full_items;
50
+	}
51 51
 
52
-    /**
53
-     * @param $cat_id
54
-     * @return bool
55
-     */
56
-    public function deleteByCategory($cat_id)
57
-    {
58
-        $cat_id = (int)$cat_id;
59
-        if (empty($cat_id)) {
60
-            return false;
61
-        }
62
-        /** @var \XoopsGroupPermHandler $grouppermHandler */
63
-        $grouppermHandler = xoops_getHandler('groupperm');
64
-        $criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid')));
65
-        $criteria->add(new \Criteria('gperm_name', 'category_access'));
66
-        $criteria->add(new \Criteria('gperm_itemid', $cat_id));
52
+	/**
53
+	 * @param $cat_id
54
+	 * @return bool
55
+	 */
56
+	public function deleteByCategory($cat_id)
57
+	{
58
+		$cat_id = (int)$cat_id;
59
+		if (empty($cat_id)) {
60
+			return false;
61
+		}
62
+		/** @var \XoopsGroupPermHandler $grouppermHandler */
63
+		$grouppermHandler = xoops_getHandler('groupperm');
64
+		$criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid')));
65
+		$criteria->add(new \Criteria('gperm_name', 'category_access'));
66
+		$criteria->add(new \Criteria('gperm_itemid', $cat_id));
67 67
 
68
-        return $grouppermHandler->deleteAll($criteria);
69
-    }
68
+		return $grouppermHandler->deleteAll($criteria);
69
+	}
70 70
 
71
-    /**
72
-     * @param        $category
73
-     * @param  array $groups
74
-     * @return bool
75
-     */
76
-    public function setCategoryPermission($category, array $groups = [])
77
-    {
78
-        if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
79
-            $mid = $GLOBALS['xoopsModule']->getVar('mid');
80
-        } else {
81
-            /** @var \XoopsModuleHandler $moduleHandler */
82
-            $moduleHandler = xoops_getHandler('module');
83
-            $newbb         = $moduleHandler->getByDirname('newbb');
84
-            $mid           = $newbb->getVar('mid');
85
-        }
86
-        if (empty($groups)) {
87
-            /** @var \XoopsMemberHandler $memberHandler */
88
-            $memberHandler = xoops_getHandler('member');
89
-            $glist         = $memberHandler->getGroupList();
90
-            $groups        = array_keys($glist);
91
-        }
92
-        $ids     = $this->getGroupIds('category_access', $category, $mid);
93
-        $ids_add = array_diff($groups, $ids);
94
-        $ids_rmv = array_diff($ids, $groups);
95
-        foreach ($ids_add as $group) {
96
-            $this->addRight('category_access', $category, $group, $mid);
97
-        }
98
-        foreach ($ids_rmv as $group) {
99
-            $this->deleteRight('category_access', $category, $group, $mid);
100
-        }
71
+	/**
72
+	 * @param        $category
73
+	 * @param  array $groups
74
+	 * @return bool
75
+	 */
76
+	public function setCategoryPermission($category, array $groups = [])
77
+	{
78
+		if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
79
+			$mid = $GLOBALS['xoopsModule']->getVar('mid');
80
+		} else {
81
+			/** @var \XoopsModuleHandler $moduleHandler */
82
+			$moduleHandler = xoops_getHandler('module');
83
+			$newbb         = $moduleHandler->getByDirname('newbb');
84
+			$mid           = $newbb->getVar('mid');
85
+		}
86
+		if (empty($groups)) {
87
+			/** @var \XoopsMemberHandler $memberHandler */
88
+			$memberHandler = xoops_getHandler('member');
89
+			$glist         = $memberHandler->getGroupList();
90
+			$groups        = array_keys($glist);
91
+		}
92
+		$ids     = $this->getGroupIds('category_access', $category, $mid);
93
+		$ids_add = array_diff($groups, $ids);
94
+		$ids_rmv = array_diff($ids, $groups);
95
+		foreach ($ids_add as $group) {
96
+			$this->addRight('category_access', $category, $group, $mid);
97
+		}
98
+		foreach ($ids_rmv as $group) {
99
+			$this->deleteRight('category_access', $category, $group, $mid);
100
+		}
101 101
 
102
-        return true;
103
-    }
102
+		return true;
103
+	}
104 104
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,13 +55,13 @@
 block discarded – undo
55 55
      */
56 56
     public function deleteByCategory($cat_id)
57 57
     {
58
-        $cat_id = (int)$cat_id;
58
+        $cat_id = (int) $cat_id;
59 59
         if (empty($cat_id)) {
60 60
             return false;
61 61
         }
62 62
         /** @var \XoopsGroupPermHandler $grouppermHandler */
63 63
         $grouppermHandler = xoops_getHandler('groupperm');
64
-        $criteria     = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid')));
64
+        $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid')));
65 65
         $criteria->add(new \Criteria('gperm_name', 'category_access'));
66 66
         $criteria->add(new \Criteria('gperm_itemid', $cat_id));
67 67
 
Please login to merge, or discard this patch.
class/RateHandler.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -39,32 +39,32 @@
 block discarded – undo
39 39
  */
40 40
 class RateHandler extends \XoopsPersistableObjectHandler
41 41
 {
42
-    /**
43
-     * @param \XoopsDatabase $db
44
-     */
45
-    public function __construct(\XoopsDatabase $db = null)
46
-    {
47
-        parent::__construct($db, 'newbb_votedata', Rate::class, 'ratingid', '');
48
-    }
42
+	/**
43
+	 * @param \XoopsDatabase $db
44
+	 */
45
+	public function __construct(\XoopsDatabase $db = null)
46
+	{
47
+		parent::__construct($db, 'newbb_votedata', Rate::class, 'ratingid', '');
48
+	}
49 49
 
50
-    /**
51
-     *
52
-     */
53
-    public function synchronization()
54
-    {
55
-        //        return;
56
-    }
50
+	/**
51
+	 *
52
+	 */
53
+	public function synchronization()
54
+	{
55
+		//        return;
56
+	}
57 57
 
58
-    /**
59
-     * clean orphan items from database
60
-     *
61
-     * @param  string $table_link
62
-     * @param  string $field_link
63
-     * @param  string $field_object
64
-     * @return bool   true on success
65
-     */
66
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
67
-    {
68
-        return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id');
69
-    }
58
+	/**
59
+	 * clean orphan items from database
60
+	 *
61
+	 * @param  string $table_link
62
+	 * @param  string $field_link
63
+	 * @param  string $field_object
64
+	 * @return bool   true on success
65
+	 */
66
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
67
+	{
68
+		return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id');
69
+	}
70 70
 }
Please login to merge, or discard this patch.
class/UserstatsHandler.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -20,47 +20,47 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class UserstatsHandler extends \XoopsPersistableObjectHandler
22 22
 {
23
-    /**
24
-     * @param \XoopsDatabase $db
25
-     */
26
-    public function __construct(\XoopsDatabase $db = null)
27
-    {
28
-        parent::__construct($db, 'newbb_user_stats', Userstats::class, 'uid', '');
29
-    }
30
-
31
-    /**
32
-     * @param  null $db
33
-     * @return UserstatsHandler
34
-     */
35
-    public static function getInstance($db = null)
36
-    {
37
-        static $instance;
38
-        if (null === $instance) {
39
-            $instance = new static($db);
40
-        }
41
-
42
-        return $instance;
43
-    }
44
-
45
-    /**
46
-     * @param  mixed $id
47
-     * @param  null  $fields
48
-     * @return null|\XoopsObject
49
-     */
50
-    public function get($id = null, $fields = null) //get($id)
51
-    {
52
-        $object = null;
53
-        if (!$id = (int)$id) {
54
-            return $object;
55
-        }
56
-        $object = $this->create(false);
57
-        $object->setVar($this->keyName, $id);
58
-        if (!$row = $this->getStats($id)) {
59
-            return $object;
60
-        }
61
-        $object->assignVars($row);
62
-
63
-        /*
23
+	/**
24
+	 * @param \XoopsDatabase $db
25
+	 */
26
+	public function __construct(\XoopsDatabase $db = null)
27
+	{
28
+		parent::__construct($db, 'newbb_user_stats', Userstats::class, 'uid', '');
29
+	}
30
+
31
+	/**
32
+	 * @param  null $db
33
+	 * @return UserstatsHandler
34
+	 */
35
+	public static function getInstance($db = null)
36
+	{
37
+		static $instance;
38
+		if (null === $instance) {
39
+			$instance = new static($db);
40
+		}
41
+
42
+		return $instance;
43
+	}
44
+
45
+	/**
46
+	 * @param  mixed $id
47
+	 * @param  null  $fields
48
+	 * @return null|\XoopsObject
49
+	 */
50
+	public function get($id = null, $fields = null) //get($id)
51
+	{
52
+		$object = null;
53
+		if (!$id = (int)$id) {
54
+			return $object;
55
+		}
56
+		$object = $this->create(false);
57
+		$object->setVar($this->keyName, $id);
58
+		if (!$row = $this->getStats($id)) {
59
+			return $object;
60
+		}
61
+		$object->assignVars($row);
62
+
63
+		/*
64 64
         $sql = "SELECT * FROM " . $this->table . " WHERE ".$this->keyName." = " . $id;
65 65
         if (!$result = $this->db->query($sql)) {
66 66
             return $object;
@@ -70,27 +70,27 @@  discard block
 block discarded – undo
70 70
         }
71 71
         */
72 72
 
73
-        return $object;
74
-    }
75
-
76
-    /**
77
-     * @param $id
78
-     * @return null|array
79
-     */
80
-    public function getStats($id)
81
-    {
82
-        if (empty($id)) {
83
-            return null;
84
-        }
85
-        $sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id;
86
-        if (!$result = $this->db->query($sql)) {
87
-            return null;
88
-        }
89
-        $row = $this->db->fetchArray($result);
90
-
91
-        return $row;
92
-    }
93
-    /*
73
+		return $object;
74
+	}
75
+
76
+	/**
77
+	 * @param $id
78
+	 * @return null|array
79
+	 */
80
+	public function getStats($id)
81
+	{
82
+		if (empty($id)) {
83
+			return null;
84
+		}
85
+		$sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id;
86
+		if (!$result = $this->db->query($sql)) {
87
+			return null;
88
+		}
89
+		$row = $this->db->fetchArray($result);
90
+
91
+		return $row;
92
+	}
93
+	/*
94 94
         function insert(\XoopsObject $object, $force = true)
95 95
         {
96 96
             if (!$object->isDirty()) {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     public function get($id = null, $fields = null) //get($id)
51 51
     {
52 52
         $object = null;
53
-        if (!$id = (int)$id) {
53
+        if (!$id = (int) $id) {
54 54
             return $object;
55 55
         }
56 56
         $object = $this->create(false);
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         if (empty($id)) {
83 83
             return null;
84 84
         }
85
-        $sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id;
85
+        $sql = 'SELECT * FROM '.$this->table.' WHERE '.$this->keyName.' = '.(int) $id;
86 86
         if (!$result = $this->db->query($sql)) {
87 87
             return null;
88 88
         }
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 \XoopsDatabase $db
38
-     */
39
-    public function __construct(\XoopsDatabase $db = null)
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 \XoopsDatabase $db
38
+	 */
39
+	public function __construct(\XoopsDatabase $db = null)
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   +4 added lines, -4 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
             }
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 
261 261
             foreach ($permissions as $gperm) {
262 262
                 $item_id                                         = $gperm->getVar('gperm_itemid');
263
-                $group_id                                        = (int)$gperm->getVar('gperm_groupid');
263
+                $group_id                                        = (int) $gperm->getVar('gperm_groupid');
264 264
                 $perms[$gperm->getVar('gperm_name')][$item_id][] = $group_id;
265 265
             }
266 266
         }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
         $ret      = false;
332 332
         $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $gperm_modid));
333 333
         $criteria->add(new \Criteria('gperm_name', $gperm_name));
334
-        $gperm_itemid = (int)$gperm_itemid;
334
+        $gperm_itemid = (int) $gperm_itemid;
335 335
         if ($gperm_itemid > 0) {
336 336
             $criteria->add(new \Criteria('gperm_itemid', $gperm_itemid));
337 337
         }
Please login to merge, or discard this patch.
class/ReportHandler.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -19,114 +19,114 @@
 block discarded – undo
19 19
  */
20 20
 class ReportHandler extends \XoopsPersistableObjectHandler
21 21
 {
22
-    /**
23
-     * @param \XoopsDatabase $db
24
-     */
25
-    public function __construct(\XoopsDatabase $db = null)
26
-    {
27
-        parent::__construct($db, 'newbb_report', Report::class, 'report_id', '');
28
-    }
22
+	/**
23
+	 * @param \XoopsDatabase $db
24
+	 */
25
+	public function __construct(\XoopsDatabase $db = null)
26
+	{
27
+		parent::__construct($db, 'newbb_report', Report::class, 'report_id', '');
28
+	}
29 29
 
30
-    /**
31
-     * @param $posts
32
-     * @return array
33
-     */
34
-    public function getByPost($posts)
35
-    {
36
-        $ret = [];
37
-        if (!$posts) {
38
-            return $ret;
39
-        }
40
-        if (!is_array($posts)) {
41
-            $posts = [$posts];
42
-        }
43
-        $post_criteria = new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN');
44
-        $ret           = $this->getAll($post_criteria);
30
+	/**
31
+	 * @param $posts
32
+	 * @return array
33
+	 */
34
+	public function getByPost($posts)
35
+	{
36
+		$ret = [];
37
+		if (!$posts) {
38
+			return $ret;
39
+		}
40
+		if (!is_array($posts)) {
41
+			$posts = [$posts];
42
+		}
43
+		$post_criteria = new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN');
44
+		$ret           = $this->getAll($post_criteria);
45 45
 
46
-        return $ret;
47
-    }
46
+		return $ret;
47
+	}
48 48
 
49
-    /**
50
-     * @param  int|array    $forums
51
-     * @param  string $order
52
-     * @param  int    $perpage
53
-     * @param         $start
54
-     * @param  int    $report_result
55
-     * @param  int    $report_id
56
-     * @return array
57
-     */
58
-    public function getAllReports(
59
-        $forums = 0,
60
-        $order = 'ASC',
61
-        $perpage = 0,
62
-        &$start,
63
-        $report_result = 0,
64
-        $report_id = 0
65
-    ) {
66
-        $forumCriteria = '';
67
-        $row           = [];
68
-        if ('DESC' === $order) {
69
-            $operator_for_position = '>';
70
-        } else {
71
-            $order                 = 'ASC';
72
-            $operator_for_position = '<';
73
-        }
74
-        $order_criteria = " ORDER BY r.report_id $order";
49
+	/**
50
+	 * @param  int|array    $forums
51
+	 * @param  string $order
52
+	 * @param  int    $perpage
53
+	 * @param         $start
54
+	 * @param  int    $report_result
55
+	 * @param  int    $report_id
56
+	 * @return array
57
+	 */
58
+	public function getAllReports(
59
+		$forums = 0,
60
+		$order = 'ASC',
61
+		$perpage = 0,
62
+		&$start,
63
+		$report_result = 0,
64
+		$report_id = 0
65
+	) {
66
+		$forumCriteria = '';
67
+		$row           = [];
68
+		if ('DESC' === $order) {
69
+			$operator_for_position = '>';
70
+		} else {
71
+			$order                 = 'ASC';
72
+			$operator_for_position = '<';
73
+		}
74
+		$order_criteria = " ORDER BY r.report_id $order";
75 75
 
76
-        if ($perpage <= 0) {
77
-            $perpage = 10;
78
-        }
79
-        if (empty($start)) {
80
-            $start = 0;
81
-        }
82
-        $result_criteria = ' AND r.report_result = ' . $report_result;
76
+		if ($perpage <= 0) {
77
+			$perpage = 10;
78
+		}
79
+		if (empty($start)) {
80
+			$start = 0;
81
+		}
82
+		$result_criteria = ' AND r.report_result = ' . $report_result;
83 83
 
84
-        if ($forums) {
85
-            $forumCriteria = '';
86
-        } elseif (!is_array($forums)) {
87
-            $forums        = [$forums];
88
-            $forumCriteria = ' AND p.forum_id IN (' . implode(',', $forums) . ')';
89
-        }
90
-        $tables_criteria = ' FROM ' . $this->db->prefix('newbb_report') . ' r, ' . $this->db->prefix('newbb_posts') . ' p WHERE r.post_id= p.post_id';
84
+		if ($forums) {
85
+			$forumCriteria = '';
86
+		} elseif (!is_array($forums)) {
87
+			$forums        = [$forums];
88
+			$forumCriteria = ' AND p.forum_id IN (' . implode(',', $forums) . ')';
89
+		}
90
+		$tables_criteria = ' FROM ' . $this->db->prefix('newbb_report') . ' r, ' . $this->db->prefix('newbb_posts') . ' p WHERE r.post_id= p.post_id';
91 91
 
92
-        if ($report_id) {
93
-            $result = $this->db->query('SELECT COUNT(*) as report_count' . $tables_criteria . $forumCriteria . $result_criteria . " AND report_id $operator_for_position $report_id" . $order_criteria);
94
-            if ($result) {
95
-                $row = $this->db->fetchArray($result);
96
-            }
97
-            $position = $row['report_count'];
98
-            $start    = (int)($position / $perpage) * $perpage;
99
-        }
92
+		if ($report_id) {
93
+			$result = $this->db->query('SELECT COUNT(*) as report_count' . $tables_criteria . $forumCriteria . $result_criteria . " AND report_id $operator_for_position $report_id" . $order_criteria);
94
+			if ($result) {
95
+				$row = $this->db->fetchArray($result);
96
+			}
97
+			$position = $row['report_count'];
98
+			$start    = (int)($position / $perpage) * $perpage;
99
+		}
100 100
 
101
-        $sql    = 'SELECT r.*, p.subject, p.topic_id, p.forum_id' . $tables_criteria . $forumCriteria . $result_criteria . $order_criteria;
102
-        $result = $this->db->query($sql, $perpage, $start);
103
-        $ret    = [];
104
-        //$reportHandler =  Newbb\Helper::getInstance()->getHandler('Report');
105
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
106
-            $ret[] = $myrow; // return as array
107
-        }
101
+		$sql    = 'SELECT r.*, p.subject, p.topic_id, p.forum_id' . $tables_criteria . $forumCriteria . $result_criteria . $order_criteria;
102
+		$result = $this->db->query($sql, $perpage, $start);
103
+		$ret    = [];
104
+		//$reportHandler =  Newbb\Helper::getInstance()->getHandler('Report');
105
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
106
+			$ret[] = $myrow; // return as array
107
+		}
108 108
 
109
-        return $ret;
110
-    }
109
+		return $ret;
110
+	}
111 111
 
112
-    /**
113
-     *
114
-     */
115
-    public function synchronization()
116
-    {
117
-        //        return;
118
-    }
112
+	/**
113
+	 *
114
+	 */
115
+	public function synchronization()
116
+	{
117
+		//        return;
118
+	}
119 119
 
120
-    /**
121
-     * clean orphan items from database
122
-     *
123
-     * @param  string $table_link
124
-     * @param  string $field_link
125
-     * @param  string $field_object
126
-     * @return bool   true on success
127
-     */
128
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
129
-    {
130
-        return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id');
131
-    }
120
+	/**
121
+	 * clean orphan items from database
122
+	 *
123
+	 * @param  string $table_link
124
+	 * @param  string $field_link
125
+	 * @param  string $field_object
126
+	 * @return bool   true on success
127
+	 */
128
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
129
+	{
130
+		return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id');
131
+	}
132 132
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
         if (!is_array($posts)) {
41 41
             $posts = [$posts];
42 42
         }
43
-        $post_criteria = new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN');
43
+        $post_criteria = new \Criteria('post_id', '('.implode(', ', $posts).')', 'IN');
44 44
         $ret           = $this->getAll($post_criteria);
45 45
 
46 46
         return $ret;
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
         if (empty($start)) {
80 80
             $start = 0;
81 81
         }
82
-        $result_criteria = ' AND r.report_result = ' . $report_result;
82
+        $result_criteria = ' AND r.report_result = '.$report_result;
83 83
 
84 84
         if ($forums) {
85 85
             $forumCriteria = '';
86 86
         } elseif (!is_array($forums)) {
87 87
             $forums        = [$forums];
88
-            $forumCriteria = ' AND p.forum_id IN (' . implode(',', $forums) . ')';
88
+            $forumCriteria = ' AND p.forum_id IN ('.implode(',', $forums).')';
89 89
         }
90
-        $tables_criteria = ' FROM ' . $this->db->prefix('newbb_report') . ' r, ' . $this->db->prefix('newbb_posts') . ' p WHERE r.post_id= p.post_id';
90
+        $tables_criteria = ' FROM '.$this->db->prefix('newbb_report').' r, '.$this->db->prefix('newbb_posts').' p WHERE r.post_id= p.post_id';
91 91
 
92 92
         if ($report_id) {
93
-            $result = $this->db->query('SELECT COUNT(*) as report_count' . $tables_criteria . $forumCriteria . $result_criteria . " AND report_id $operator_for_position $report_id" . $order_criteria);
93
+            $result = $this->db->query('SELECT COUNT(*) as report_count'.$tables_criteria.$forumCriteria.$result_criteria." AND report_id $operator_for_position $report_id".$order_criteria);
94 94
             if ($result) {
95 95
                 $row = $this->db->fetchArray($result);
96 96
             }
97 97
             $position = $row['report_count'];
98
-            $start    = (int)($position / $perpage) * $perpage;
98
+            $start    = (int) ($position / $perpage) * $perpage;
99 99
         }
100 100
 
101
-        $sql    = 'SELECT r.*, p.subject, p.topic_id, p.forum_id' . $tables_criteria . $forumCriteria . $result_criteria . $order_criteria;
101
+        $sql    = 'SELECT r.*, p.subject, p.topic_id, p.forum_id'.$tables_criteria.$forumCriteria.$result_criteria.$order_criteria;
102 102
         $result = $this->db->query($sql, $perpage, $start);
103 103
         $ret    = [];
104 104
         //$reportHandler =  Newbb\Helper::getInstance()->getHandler('Report');
Please login to merge, or discard this patch.
class/PostHandler.php 2 patches
Indentation   +545 added lines, -545 removed lines patch added patch discarded remove patch
@@ -41,555 +41,555 @@
 block discarded – undo
41 41
  */
42 42
 class PostHandler extends \XoopsPersistableObjectHandler
43 43
 {
44
-    /**
45
-     * @param \XoopsDatabase $db
46
-     */
47
-    public function __construct(\XoopsDatabase $db = null)
48
-    {
49
-        parent::__construct($db, 'newbb_posts', Post::class, 'post_id', 'subject');
50
-    }
51
-
52
-    /**
53
-     * @param  mixed $id
54
-     * @param  null  $var
55
-     * @return null|\XoopsObject
56
-     */
57
-    public function get($id = null, $var = null) //get($id)
58
-    {
59
-        $id   = (int)$id;
60
-        $post = null;
61
-        $sql  = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id;
62
-        if ($array = $this->db->fetchArray($this->db->query($sql))) {
63
-            $post = $this->create(false);
64
-            $post->assignVars($array);
65
-        }
66
-
67
-        return $post;
68
-    }
69
-
70
-    /**
71
-     * @param  int             $limit
72
-     * @param  int             $start
73
-     * @param  \CriteriaElement $criteria
74
-     * @param  null            $fields
75
-     * @param  bool            $asObject
76
-     * @param  int             $topic_id
77
-     * @param  int             $approved
78
-     * @return array
79
-     */
80
-    //    public function getByLimit($topic_id, $limit, $approved = 1)
81
-    public function &getByLimit(
82
-        $limit = 0,
83
-        $start = 0,
84
-        \CriteriaElement $criteria = null,
85
-        $fields = null,
86
-        $asObject = true,
87
-        $topic_id = 0,
88
-        $approved = 1
89
-    ) {
90
-        $sql    = 'SELECT p.*, t.*, tp.topic_status FROM '
91
-                  . $this->db->prefix('newbb_posts')
92
-                  . ' p LEFT JOIN '
93
-                  . $this->db->prefix('newbb_posts_text')
94
-                  . ' t ON p.post_id=t.post_id LEFT JOIN '
95
-                  . $this->db->prefix('newbb_topics')
96
-                  . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id='
97
-                  . $topic_id
98
-                  . ' AND p.approved ='
99
-                  . $approved
100
-                  . ' ORDER BY p.post_time DESC';
101
-        $result = $this->db->query($sql, $limit, 0);
102
-        $ret    = [];
103
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
104
-            $post = $this->create(false);
105
-            $post->assignVars($myrow);
106
-
107
-            $ret[$myrow['post_id']] = $post;
108
-            unset($post);
109
-        }
110
-
111
-        return $ret;
112
-    }
113
-
114
-    /**
115
-     * @param Post $post
116
-     * @return mixed
117
-     */
118
-    public function getPostForPDF(&$post)
119
-    {
120
-        return $post->getPostBody(true);
121
-    }
122
-
123
-    /**
124
-     * @param Post $post
125
-     * @return mixed
126
-     */
127
-    public function getPostForPrint(&$post)
128
-    {
129
-        return $post->getPostBody();
130
-    }
131
-
132
-    /**
133
-     * @param  int|Post|\XoopsObject $post
134
-     * @param  bool $force
135
-     * @return bool
136
-     */
137
-    public function approve(&$post, $force = false)
138
-    {
139
-        if (empty($post)) {
140
-            return false;
141
-        }
142
-        if (is_numeric($post)) {
143
-            $post = $this->get($post);
144
-        }
145
-
146
-        $wasApproved = $post->getVar('approved');
147
-        // irmtfan approve post if the approved = 0 (pending) or -1 (deleted)
148
-        if (empty($force) && $wasApproved > 0) {
149
-            return true;
150
-        }
151
-        $post->setVar('approved', 1);
152
-        $this->insert($post, true);
153
-
154
-        /** @var Newbb\TopicHandler $topicHandler */
155
-        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
156
-        $topicObject  = $topicHandler->get($post->getVar('topic_id'));
157
-        if ($topicObject->getVar('topic_last_post_id') < $post->getVar('post_id')) {
158
-            $topicObject->setVar('topic_last_post_id', $post->getVar('post_id'));
159
-        }
160
-        if ($post->isTopic()) {
161
-            $topicObject->setVar('approved', 1);
162
-        } else {
163
-            $topicObject->setVar('topic_replies', $topicObject->getVar('topic_replies') + 1);
164
-        }
165
-        $topicHandler->insert($topicObject, true);
166
-
167
-        /** @var Newbb\ForumHandler $forumHandler */
168
-        $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
169
-        $forumObject  = $forumHandler->get($post->getVar('forum_id'));
170
-        if ($forumObject->getVar('forum_last_post_id') < $post->getVar('post_id')) {
171
-            $forumObject->setVar('forum_last_post_id', $post->getVar('post_id'));
172
-        }
173
-        $forumObject->setVar('forum_posts', $forumObject->getVar('forum_posts') + 1);
174
-        if ($post->isTopic()) {
175
-            $forumObject->setVar('forum_topics', $forumObject->getVar('forum_topics') + 1);
176
-        }
177
-        $forumHandler->insert($forumObject, true);
178
-
179
-        // Update user stats
180
-        if ($post->getVar('uid') > 0) {
181
-            /** @var \XoopsMemberHandler $memberHandler */
182
-            $memberHandler = xoops_getHandler('member');
183
-            $poster        = $memberHandler->getUser($post->getVar('uid'));
184
-            if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) {
185
-                $poster->setVar('posts', $poster->getVar('posts') + 1);
186
-                $res = $memberHandler->insertUser($poster, true);
187
-                unset($poster);
188
-            }
189
-        }
190
-
191
-        // Update forum stats
192
-        /** @var StatsHandler $statsHandler */
193
-        $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats');
194
-        $statsHandler->update($post->getVar('forum_id'), 'post');
195
-        if ($post->isTopic()) {
196
-            $statsHandler->update($post->getVar('forum_id'), 'topic');
197
-        }
198
-
199
-        return true;
200
-    }
201
-
202
-    /**
203
-     * @param \XoopsObject $post
204
-     * @param  bool        $force
205
-     * @return bool
206
-     */
207
-    public function insert(\XoopsObject $post, $force = true) //insert(&$post, $force = true)
208
-    {
209
-        $topicObject = null;
210
-        // Set the post time
211
-        // The time should be "publish" time. To be adjusted later
212
-        if (!$post->getVar('post_time')) {
213
-            $post->setVar('post_time', time());
214
-        }
215
-
216
-        /** @var Newbb\TopicHandler $topicHandler */
217
-        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
218
-        // Verify the topic ID
219
-        if ($topic_id = $post->getVar('topic_id')) {
220
-            $topicObject = $topicHandler->get($topic_id);
221
-            // Invalid topic OR the topic is no approved and the post is not top post
222
-            if (!$topicObject//    || (!$post->isTopic() && $topicObject->getVar("approved") < 1)
223
-            ) {
224
-                return false;
225
-            }
226
-        }
227
-        if (empty($topic_id)) {
228
-            $post->setVar('topic_id', 0);
229
-            $post->setVar('pid', 0);
230
-            $post->setNew();
231
-            $topicObject = $topicHandler->create();
232
-        }
233
-        $textHandler    = Newbb\Helper::getInstance()->getHandler('Text');
234
-        $post_text_vars = ['post_text', 'post_edit', 'dohtml', 'doxcode', 'dosmiley', 'doimage', 'dobr'];
235
-        if ($post->isNew()) {
236
-            if (!$topic_id = $post->getVar('topic_id')) {
237
-                $topicObject->setVar('topic_title', $post->getVar('subject', 'n'));
238
-                $topicObject->setVar('topic_poster', $post->getVar('uid'));
239
-                $topicObject->setVar('forum_id', $post->getVar('forum_id'));
240
-                $topicObject->setVar('topic_time', $post->getVar('post_time'));
241
-                $topicObject->setVar('poster_name', $post->getVar('poster_name'));
242
-                $topicObject->setVar('approved', $post->getVar('approved'));
243
-
244
-                if (!$topic_id = $topicHandler->insert($topicObject, $force)) {
245
-                    $post->deleteAttachment();
246
-                    $post->setErrors('insert topic error');
247
-
248
-                    //xoops_error($topicObject->getErrors());
249
-                    return false;
250
-                }
251
-                $post->setVar('topic_id', $topic_id);
252
-
253
-                $pid = 0;
254
-                $post->setVar('pid', 0);
255
-            } elseif (!$post->getVar('pid')) {
256
-                $pid = $topicHandler->getTopPostId($topic_id);
257
-                $post->setVar('pid', $pid);
258
-            }
259
-
260
-            $textObject = $textHandler->create();
261
-            foreach ($post_text_vars as $key) {
262
-                $textObject->vars[$key] = $post->vars[$key];
263
-            }
264
-            $post->destroyVars($post_text_vars);
265
-
266
-            //            if (!$post_id = parent::insert($post, $force)) {
267
-            //                return false;
268
-            //            }
269
-
270
-            if (!$post_id = parent::insert($post, $force)) {
271
-                return false;
272
-            } else {
273
-                $post->unsetNew();
274
-            }
275
-
276
-            $textObject->setVar('post_id', $post_id);
277
-            if (!$textHandler->insert($textObject, $force)) {
278
-                $this->delete($post);
279
-                $post->setErrors('post text insert error');
280
-
281
-                //xoops_error($textObject->getErrors());
282
-                return false;
283
-            }
284
-            if ($post->getVar('approved') > 0) {
285
-                $this->approve($post, true);
286
-            }
287
-            $post->setVar('post_id', $post_id);
288
-        } else {
289
-            if ($post->isTopic()) {
290
-                if ($post->getVar('subject') !== $topicObject->getVar('topic_title')) {
291
-                    $topicObject->setVar('topic_title', $post->getVar('subject', 'n'));
292
-                }
293
-                if ($post->getVar('approved') !== $topicObject->getVar('approved')) {
294
-                    $topicObject->setVar('approved', $post->getVar('approved'));
295
-                }
296
-                $topicObject->setDirty();
297
-                if (!$result = $topicHandler->insert($topicObject, $force)) {
298
-                    $post->setErrors('update topic error');
299
-
300
-                    //xoops_error($topicObject->getErrors());
301
-                    return false;
302
-                }
303
-            }
304
-            $textObject = $textHandler->get($post->getVar('post_id'));
305
-            $textObject->setDirty();
306
-            foreach ($post_text_vars as $key) {
307
-                $textObject->vars[$key] = $post->vars[$key];
308
-            }
309
-            $post->destroyVars($post_text_vars);
310
-            if (!$post_id = parent::insert($post, $force)) {
311
-                //xoops_error($post->getErrors());
312
-                return false;
313
-            } else {
314
-                $post->unsetNew();
315
-            }
316
-            if (!$textHandler->insert($textObject, $force)) {
317
-                $post->setErrors('update post text error');
318
-
319
-                //xoops_error($textObject->getErrors());
320
-                return false;
321
-            }
322
-        }
323
-
324
-        return $post->getVar('post_id');
325
-    }
326
-
327
-    /**
328
-     * @param \XoopsObject|Post $post
329
-     * @param  bool        $isDeleteOne
330
-     * @param  bool        $force
331
-     * @return bool
332
-     */
333
-    public function delete(\XoopsObject $post, $isDeleteOne = true, $force = false)
334
-    {
335
-        if (!is_object($post) || 0 == $post->getVar('post_id')) {
336
-            return false;
337
-        }
338
-
339
-        if ($isDeleteOne) {
340
-            if ($post->isTopic()) {
341
-                $criteria = new \CriteriaCompo(new \Criteria('topic_id', $post->getVar('topic_id')));
342
-                $criteria->add(new \Criteria('approved', 1));
343
-                $criteria->add(new \Criteria('pid', 0, '>'));
344
-                if ($this->getPostCount($criteria) > 0) {
345
-                    return false;
346
-                }
347
-            }
348
-
349
-            return $this->myDelete($post, $force);
350
-        } else {
351
-            require_once $GLOBALS['xoops']->path('class/xoopstree.php');
352
-            $mytree = new \XoopsTree($this->db->prefix('newbb_posts'), 'post_id', 'pid');
353
-            $arr    = $mytree->getAllChild($post->getVar('post_id'));
354
-            // irmtfan - delete childs in a reverse order
355
-            for ($i = count($arr) - 1; $i >= 0; $i--) {
356
-                $childpost = $this->create(false);
357
-                $childpost->assignVars($arr[$i]);
358
-                $this->myDelete($childpost, $force);
359
-                unset($childpost);
360
-            }
361
-            $this->myDelete($post, $force);
362
-        }
363
-
364
-        return true;
365
-    }
366
-
367
-    /**
368
-     * @param  Post|\XoopsObject $post
369
-     * @param  bool $force
370
-     * @return bool
371
-     */
372
-    public function myDelete(Post $post, $force = false)
373
-    {
374
-        global $xoopsModule;
375
-
376
-        if (!is_object($post) || 0 == $post->getVar('post_id')) {
377
-            return false;
378
-        }
379
-
380
-        /* Set active post as deleted */
381
-        if ($post->getVar('approved') > 0 && empty($force)) {
382
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id');
383
-            if (!$result = $this->db->queryF($sql)) {
384
-            }
385
-            /* delete pending post directly */
386
-        } else {
387
-            $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id'));
388
-            if (!$result = $this->db->queryF($sql)) {
389
-                $post->setErrors('delete post error: ' . $sql);
390
-
391
-                return false;
392
-            }
393
-            $post->deleteAttachment();
394
-
395
-            $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id'));
396
-            if (!$result = $this->db->queryF($sql)) {
397
-                $post->setErrors('Could not remove post text: ' . $sql);
398
-
399
-                return false;
400
-            }
401
-        }
402
-
403
-        if ($post->isTopic()) {
404
-            $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
405
-            /** @var Topic $topicObject */
406
-            $topicObject = $topicHandler->get($post->getVar('topic_id'));
407
-            if (is_object($topicObject) && $topicObject->getVar('approved') > 0 && empty($force)) {
408
-                $topiccount_toupdate = 1;
409
-                $topicObject->setVar('approved', -1);
410
-                $topicHandler->insert($topicObject);
411
-                xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id'));
412
-            } else {
413
-                if (is_object($topicObject)) {
414
-                    if ($topicObject->getVar('approved') > 0) {
415
-                        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id'));
416
-                    }
417
-
418
-                    $poll_id = $topicObject->getVar('poll_id');
419
-                    // START irmtfan poll_module
420
-                    $topicObject->deletePoll($poll_id);
421
-                    // END irmtfan poll_module
422
-                }
423
-
424
-                $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_topics'), $post->getVar('topic_id'));
425
-                if (!$result = $this->db->queryF($sql)) {
426
-                    //xoops_error($this->db->error());
427
-                }
428
-                $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_votedata'), $post->getVar('topic_id'));
429
-                if (!$result = $this->db->queryF($sql)) {
430
-                    //xoops_error($this->db->error());
431
-                }
432
-            }
433
-        } else {
434
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t
44
+	/**
45
+	 * @param \XoopsDatabase $db
46
+	 */
47
+	public function __construct(\XoopsDatabase $db = null)
48
+	{
49
+		parent::__construct($db, 'newbb_posts', Post::class, 'post_id', 'subject');
50
+	}
51
+
52
+	/**
53
+	 * @param  mixed $id
54
+	 * @param  null  $var
55
+	 * @return null|\XoopsObject
56
+	 */
57
+	public function get($id = null, $var = null) //get($id)
58
+	{
59
+		$id   = (int)$id;
60
+		$post = null;
61
+		$sql  = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id;
62
+		if ($array = $this->db->fetchArray($this->db->query($sql))) {
63
+			$post = $this->create(false);
64
+			$post->assignVars($array);
65
+		}
66
+
67
+		return $post;
68
+	}
69
+
70
+	/**
71
+	 * @param  int             $limit
72
+	 * @param  int             $start
73
+	 * @param  \CriteriaElement $criteria
74
+	 * @param  null            $fields
75
+	 * @param  bool            $asObject
76
+	 * @param  int             $topic_id
77
+	 * @param  int             $approved
78
+	 * @return array
79
+	 */
80
+	//    public function getByLimit($topic_id, $limit, $approved = 1)
81
+	public function &getByLimit(
82
+		$limit = 0,
83
+		$start = 0,
84
+		\CriteriaElement $criteria = null,
85
+		$fields = null,
86
+		$asObject = true,
87
+		$topic_id = 0,
88
+		$approved = 1
89
+	) {
90
+		$sql    = 'SELECT p.*, t.*, tp.topic_status FROM '
91
+				  . $this->db->prefix('newbb_posts')
92
+				  . ' p LEFT JOIN '
93
+				  . $this->db->prefix('newbb_posts_text')
94
+				  . ' t ON p.post_id=t.post_id LEFT JOIN '
95
+				  . $this->db->prefix('newbb_topics')
96
+				  . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id='
97
+				  . $topic_id
98
+				  . ' AND p.approved ='
99
+				  . $approved
100
+				  . ' ORDER BY p.post_time DESC';
101
+		$result = $this->db->query($sql, $limit, 0);
102
+		$ret    = [];
103
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
104
+			$post = $this->create(false);
105
+			$post->assignVars($myrow);
106
+
107
+			$ret[$myrow['post_id']] = $post;
108
+			unset($post);
109
+		}
110
+
111
+		return $ret;
112
+	}
113
+
114
+	/**
115
+	 * @param Post $post
116
+	 * @return mixed
117
+	 */
118
+	public function getPostForPDF(&$post)
119
+	{
120
+		return $post->getPostBody(true);
121
+	}
122
+
123
+	/**
124
+	 * @param Post $post
125
+	 * @return mixed
126
+	 */
127
+	public function getPostForPrint(&$post)
128
+	{
129
+		return $post->getPostBody();
130
+	}
131
+
132
+	/**
133
+	 * @param  int|Post|\XoopsObject $post
134
+	 * @param  bool $force
135
+	 * @return bool
136
+	 */
137
+	public function approve(&$post, $force = false)
138
+	{
139
+		if (empty($post)) {
140
+			return false;
141
+		}
142
+		if (is_numeric($post)) {
143
+			$post = $this->get($post);
144
+		}
145
+
146
+		$wasApproved = $post->getVar('approved');
147
+		// irmtfan approve post if the approved = 0 (pending) or -1 (deleted)
148
+		if (empty($force) && $wasApproved > 0) {
149
+			return true;
150
+		}
151
+		$post->setVar('approved', 1);
152
+		$this->insert($post, true);
153
+
154
+		/** @var Newbb\TopicHandler $topicHandler */
155
+		$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
156
+		$topicObject  = $topicHandler->get($post->getVar('topic_id'));
157
+		if ($topicObject->getVar('topic_last_post_id') < $post->getVar('post_id')) {
158
+			$topicObject->setVar('topic_last_post_id', $post->getVar('post_id'));
159
+		}
160
+		if ($post->isTopic()) {
161
+			$topicObject->setVar('approved', 1);
162
+		} else {
163
+			$topicObject->setVar('topic_replies', $topicObject->getVar('topic_replies') + 1);
164
+		}
165
+		$topicHandler->insert($topicObject, true);
166
+
167
+		/** @var Newbb\ForumHandler $forumHandler */
168
+		$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
169
+		$forumObject  = $forumHandler->get($post->getVar('forum_id'));
170
+		if ($forumObject->getVar('forum_last_post_id') < $post->getVar('post_id')) {
171
+			$forumObject->setVar('forum_last_post_id', $post->getVar('post_id'));
172
+		}
173
+		$forumObject->setVar('forum_posts', $forumObject->getVar('forum_posts') + 1);
174
+		if ($post->isTopic()) {
175
+			$forumObject->setVar('forum_topics', $forumObject->getVar('forum_topics') + 1);
176
+		}
177
+		$forumHandler->insert($forumObject, true);
178
+
179
+		// Update user stats
180
+		if ($post->getVar('uid') > 0) {
181
+			/** @var \XoopsMemberHandler $memberHandler */
182
+			$memberHandler = xoops_getHandler('member');
183
+			$poster        = $memberHandler->getUser($post->getVar('uid'));
184
+			if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) {
185
+				$poster->setVar('posts', $poster->getVar('posts') + 1);
186
+				$res = $memberHandler->insertUser($poster, true);
187
+				unset($poster);
188
+			}
189
+		}
190
+
191
+		// Update forum stats
192
+		/** @var StatsHandler $statsHandler */
193
+		$statsHandler = Newbb\Helper::getInstance()->getHandler('Stats');
194
+		$statsHandler->update($post->getVar('forum_id'), 'post');
195
+		if ($post->isTopic()) {
196
+			$statsHandler->update($post->getVar('forum_id'), 'topic');
197
+		}
198
+
199
+		return true;
200
+	}
201
+
202
+	/**
203
+	 * @param \XoopsObject $post
204
+	 * @param  bool        $force
205
+	 * @return bool
206
+	 */
207
+	public function insert(\XoopsObject $post, $force = true) //insert(&$post, $force = true)
208
+	{
209
+		$topicObject = null;
210
+		// Set the post time
211
+		// The time should be "publish" time. To be adjusted later
212
+		if (!$post->getVar('post_time')) {
213
+			$post->setVar('post_time', time());
214
+		}
215
+
216
+		/** @var Newbb\TopicHandler $topicHandler */
217
+		$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
218
+		// Verify the topic ID
219
+		if ($topic_id = $post->getVar('topic_id')) {
220
+			$topicObject = $topicHandler->get($topic_id);
221
+			// Invalid topic OR the topic is no approved and the post is not top post
222
+			if (!$topicObject//    || (!$post->isTopic() && $topicObject->getVar("approved") < 1)
223
+			) {
224
+				return false;
225
+			}
226
+		}
227
+		if (empty($topic_id)) {
228
+			$post->setVar('topic_id', 0);
229
+			$post->setVar('pid', 0);
230
+			$post->setNew();
231
+			$topicObject = $topicHandler->create();
232
+		}
233
+		$textHandler    = Newbb\Helper::getInstance()->getHandler('Text');
234
+		$post_text_vars = ['post_text', 'post_edit', 'dohtml', 'doxcode', 'dosmiley', 'doimage', 'dobr'];
235
+		if ($post->isNew()) {
236
+			if (!$topic_id = $post->getVar('topic_id')) {
237
+				$topicObject->setVar('topic_title', $post->getVar('subject', 'n'));
238
+				$topicObject->setVar('topic_poster', $post->getVar('uid'));
239
+				$topicObject->setVar('forum_id', $post->getVar('forum_id'));
240
+				$topicObject->setVar('topic_time', $post->getVar('post_time'));
241
+				$topicObject->setVar('poster_name', $post->getVar('poster_name'));
242
+				$topicObject->setVar('approved', $post->getVar('approved'));
243
+
244
+				if (!$topic_id = $topicHandler->insert($topicObject, $force)) {
245
+					$post->deleteAttachment();
246
+					$post->setErrors('insert topic error');
247
+
248
+					//xoops_error($topicObject->getErrors());
249
+					return false;
250
+				}
251
+				$post->setVar('topic_id', $topic_id);
252
+
253
+				$pid = 0;
254
+				$post->setVar('pid', 0);
255
+			} elseif (!$post->getVar('pid')) {
256
+				$pid = $topicHandler->getTopPostId($topic_id);
257
+				$post->setVar('pid', $pid);
258
+			}
259
+
260
+			$textObject = $textHandler->create();
261
+			foreach ($post_text_vars as $key) {
262
+				$textObject->vars[$key] = $post->vars[$key];
263
+			}
264
+			$post->destroyVars($post_text_vars);
265
+
266
+			//            if (!$post_id = parent::insert($post, $force)) {
267
+			//                return false;
268
+			//            }
269
+
270
+			if (!$post_id = parent::insert($post, $force)) {
271
+				return false;
272
+			} else {
273
+				$post->unsetNew();
274
+			}
275
+
276
+			$textObject->setVar('post_id', $post_id);
277
+			if (!$textHandler->insert($textObject, $force)) {
278
+				$this->delete($post);
279
+				$post->setErrors('post text insert error');
280
+
281
+				//xoops_error($textObject->getErrors());
282
+				return false;
283
+			}
284
+			if ($post->getVar('approved') > 0) {
285
+				$this->approve($post, true);
286
+			}
287
+			$post->setVar('post_id', $post_id);
288
+		} else {
289
+			if ($post->isTopic()) {
290
+				if ($post->getVar('subject') !== $topicObject->getVar('topic_title')) {
291
+					$topicObject->setVar('topic_title', $post->getVar('subject', 'n'));
292
+				}
293
+				if ($post->getVar('approved') !== $topicObject->getVar('approved')) {
294
+					$topicObject->setVar('approved', $post->getVar('approved'));
295
+				}
296
+				$topicObject->setDirty();
297
+				if (!$result = $topicHandler->insert($topicObject, $force)) {
298
+					$post->setErrors('update topic error');
299
+
300
+					//xoops_error($topicObject->getErrors());
301
+					return false;
302
+				}
303
+			}
304
+			$textObject = $textHandler->get($post->getVar('post_id'));
305
+			$textObject->setDirty();
306
+			foreach ($post_text_vars as $key) {
307
+				$textObject->vars[$key] = $post->vars[$key];
308
+			}
309
+			$post->destroyVars($post_text_vars);
310
+			if (!$post_id = parent::insert($post, $force)) {
311
+				//xoops_error($post->getErrors());
312
+				return false;
313
+			} else {
314
+				$post->unsetNew();
315
+			}
316
+			if (!$textHandler->insert($textObject, $force)) {
317
+				$post->setErrors('update post text error');
318
+
319
+				//xoops_error($textObject->getErrors());
320
+				return false;
321
+			}
322
+		}
323
+
324
+		return $post->getVar('post_id');
325
+	}
326
+
327
+	/**
328
+	 * @param \XoopsObject|Post $post
329
+	 * @param  bool        $isDeleteOne
330
+	 * @param  bool        $force
331
+	 * @return bool
332
+	 */
333
+	public function delete(\XoopsObject $post, $isDeleteOne = true, $force = false)
334
+	{
335
+		if (!is_object($post) || 0 == $post->getVar('post_id')) {
336
+			return false;
337
+		}
338
+
339
+		if ($isDeleteOne) {
340
+			if ($post->isTopic()) {
341
+				$criteria = new \CriteriaCompo(new \Criteria('topic_id', $post->getVar('topic_id')));
342
+				$criteria->add(new \Criteria('approved', 1));
343
+				$criteria->add(new \Criteria('pid', 0, '>'));
344
+				if ($this->getPostCount($criteria) > 0) {
345
+					return false;
346
+				}
347
+			}
348
+
349
+			return $this->myDelete($post, $force);
350
+		} else {
351
+			require_once $GLOBALS['xoops']->path('class/xoopstree.php');
352
+			$mytree = new \XoopsTree($this->db->prefix('newbb_posts'), 'post_id', 'pid');
353
+			$arr    = $mytree->getAllChild($post->getVar('post_id'));
354
+			// irmtfan - delete childs in a reverse order
355
+			for ($i = count($arr) - 1; $i >= 0; $i--) {
356
+				$childpost = $this->create(false);
357
+				$childpost->assignVars($arr[$i]);
358
+				$this->myDelete($childpost, $force);
359
+				unset($childpost);
360
+			}
361
+			$this->myDelete($post, $force);
362
+		}
363
+
364
+		return true;
365
+	}
366
+
367
+	/**
368
+	 * @param  Post|\XoopsObject $post
369
+	 * @param  bool $force
370
+	 * @return bool
371
+	 */
372
+	public function myDelete(Post $post, $force = false)
373
+	{
374
+		global $xoopsModule;
375
+
376
+		if (!is_object($post) || 0 == $post->getVar('post_id')) {
377
+			return false;
378
+		}
379
+
380
+		/* Set active post as deleted */
381
+		if ($post->getVar('approved') > 0 && empty($force)) {
382
+			$sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id');
383
+			if (!$result = $this->db->queryF($sql)) {
384
+			}
385
+			/* delete pending post directly */
386
+		} else {
387
+			$sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id'));
388
+			if (!$result = $this->db->queryF($sql)) {
389
+				$post->setErrors('delete post error: ' . $sql);
390
+
391
+				return false;
392
+			}
393
+			$post->deleteAttachment();
394
+
395
+			$sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id'));
396
+			if (!$result = $this->db->queryF($sql)) {
397
+				$post->setErrors('Could not remove post text: ' . $sql);
398
+
399
+				return false;
400
+			}
401
+		}
402
+
403
+		if ($post->isTopic()) {
404
+			$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
405
+			/** @var Topic $topicObject */
406
+			$topicObject = $topicHandler->get($post->getVar('topic_id'));
407
+			if (is_object($topicObject) && $topicObject->getVar('approved') > 0 && empty($force)) {
408
+				$topiccount_toupdate = 1;
409
+				$topicObject->setVar('approved', -1);
410
+				$topicHandler->insert($topicObject);
411
+				xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id'));
412
+			} else {
413
+				if (is_object($topicObject)) {
414
+					if ($topicObject->getVar('approved') > 0) {
415
+						xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id'));
416
+					}
417
+
418
+					$poll_id = $topicObject->getVar('poll_id');
419
+					// START irmtfan poll_module
420
+					$topicObject->deletePoll($poll_id);
421
+					// END irmtfan poll_module
422
+				}
423
+
424
+				$sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_topics'), $post->getVar('topic_id'));
425
+				if (!$result = $this->db->queryF($sql)) {
426
+					//xoops_error($this->db->error());
427
+				}
428
+				$sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_votedata'), $post->getVar('topic_id'));
429
+				if (!$result = $this->db->queryF($sql)) {
430
+					//xoops_error($this->db->error());
431
+				}
432
+			}
433
+		} else {
434
+			$sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t
435 435
                             LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.topic_id = t.topic_id
436 436
                             SET t.topic_last_post_id = p.post_id
437 437
                             WHERE t.topic_last_post_id = ' . $post->getVar('post_id') . '
438 438
                                     AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=t.topic_id)';
439
-            if (!$result = $this->db->queryF($sql)) {
440
-            }
441
-        }
442
-
443
-        $postcount_toupdate = $post->getVar('approved');
444
-
445
-        if ($postcount_toupdate > 0) {
446
-
447
-            // Update user stats
448
-            if ($post->getVar('uid') > 0) {
449
-                /** @var \XoopsMemberHandler $memberHandler */
450
-                $memberHandler = xoops_getHandler('member');
451
-                $poster        = $memberHandler->getUser($post->getVar('uid'));
452
-                if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) {
453
-                    $poster->setVar('posts', $poster->getVar('posts') - 1);
454
-                    $res = $memberHandler->insertUser($poster, true);
455
-                    unset($poster);
456
-                }
457
-            }
458
-            // irmtfan - just update the pid for approved posts when the post is not topic (pid=0)
459
-            if (!$post->isTopic()) {
460
-                $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id');
461
-                if (!$result = $this->db->queryF($sql)) {
462
-                    //xoops_error($this->db->error());
463
-                }
464
-            }
465
-        }
466
-
467
-        return true;
468
-    }
469
-
470
-    // START irmtfan enhance getPostCount when there is join (read_mode = 2)
471
-
472
-    /**
473
-     * @param  null $criteria
474
-     * @param  null $join
475
-     * @return int|null
476
-     */
477
-    public function getPostCount($criteria = null, $join = null)
478
-    {
479
-        // if not join get the count from XOOPS/class/model/stats as before
480
-        if (empty($join)) {
481
-            return parent::getCount($criteria);
482
-        }
483
-
484
-        $sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
485
-        // LEFT JOIN
486
-        $sql .= $join;
487
-        // WHERE
488
-        if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
489
-            $sql .= ' ' . $criteria->renderWhere();
490
-        }
491
-        if (!$result = $this->db->query($sql)) {
492
-            //xoops_error($this->db->error().'<br>'.$sql);
493
-            return null;
494
-        }
495
-        $myrow = $this->db->fetchArray($result);
496
-        $count = $myrow['count'];
497
-
498
-        return $count;
499
-    }
500
-    // END irmtfan enhance getPostCount when there is join (read_mode = 2)
501
-    /*
439
+			if (!$result = $this->db->queryF($sql)) {
440
+			}
441
+		}
442
+
443
+		$postcount_toupdate = $post->getVar('approved');
444
+
445
+		if ($postcount_toupdate > 0) {
446
+
447
+			// Update user stats
448
+			if ($post->getVar('uid') > 0) {
449
+				/** @var \XoopsMemberHandler $memberHandler */
450
+				$memberHandler = xoops_getHandler('member');
451
+				$poster        = $memberHandler->getUser($post->getVar('uid'));
452
+				if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) {
453
+					$poster->setVar('posts', $poster->getVar('posts') - 1);
454
+					$res = $memberHandler->insertUser($poster, true);
455
+					unset($poster);
456
+				}
457
+			}
458
+			// irmtfan - just update the pid for approved posts when the post is not topic (pid=0)
459
+			if (!$post->isTopic()) {
460
+				$sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id');
461
+				if (!$result = $this->db->queryF($sql)) {
462
+					//xoops_error($this->db->error());
463
+				}
464
+			}
465
+		}
466
+
467
+		return true;
468
+	}
469
+
470
+	// START irmtfan enhance getPostCount when there is join (read_mode = 2)
471
+
472
+	/**
473
+	 * @param  null $criteria
474
+	 * @param  null $join
475
+	 * @return int|null
476
+	 */
477
+	public function getPostCount($criteria = null, $join = null)
478
+	{
479
+		// if not join get the count from XOOPS/class/model/stats as before
480
+		if (empty($join)) {
481
+			return parent::getCount($criteria);
482
+		}
483
+
484
+		$sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
485
+		// LEFT JOIN
486
+		$sql .= $join;
487
+		// WHERE
488
+		if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
489
+			$sql .= ' ' . $criteria->renderWhere();
490
+		}
491
+		if (!$result = $this->db->query($sql)) {
492
+			//xoops_error($this->db->error().'<br>'.$sql);
493
+			return null;
494
+		}
495
+		$myrow = $this->db->fetchArray($result);
496
+		$count = $myrow['count'];
497
+
498
+		return $count;
499
+	}
500
+	// END irmtfan enhance getPostCount when there is join (read_mode = 2)
501
+	/*
502 502
      * TODO: combining viewtopic.php
503 503
      */
504
-    /**
505
-     * @param  null $criteria
506
-     * @param  int  $limit
507
-     * @param  int  $start
508
-     * @param  null $join
509
-     * @return array
510
-     */
511
-    public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null)
512
-    {
513
-        $ret = [];
514
-        $sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
515
-        if (!empty($join)) {
516
-            $sql .= $join;
517
-        }
518
-        if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
519
-            $sql .= ' ' . $criteria->renderWhere();
520
-            if ('' !== $criteria->getSort()) {
521
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
522
-            }
523
-        }
524
-        $result = $this->db->query($sql, (int)$limit, (int)$start);
525
-        if (!$result) {
526
-            //xoops_error($this->db->error());
527
-            return $ret;
528
-        }
529
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
530
-            $post = $this->create(false);
531
-            $post->assignVars($myrow);
532
-            $ret[$myrow['post_id']] = $post;
533
-            unset($post);
534
-        }
535
-
536
-        return $ret;
537
-    }
538
-
539
-    /**
540
-     * @return bool
541
-     */
542
-    public function synchronization()
543
-    {
544
-        //$this->cleanOrphan();
545
-        return true;
546
-    }
547
-
548
-    /**
549
-     * clean orphan items from database
550
-     *
551
-     * @param  string $table_link
552
-     * @param  string $field_link
553
-     * @param  string $field_object
554
-     * @return bool   true on success
555
-     */
556
-    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
557
-    {
558
-        $this->deleteAll(new \Criteria('post_time', 0), true, true);
559
-        parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id');
560
-        parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id');
561
-
562
-        $sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )';
563
-        if (!$result = $this->db->queryF($sql)) {
564
-            //xoops_error($this->db->error());
565
-            return false;
566
-        }
567
-
568
-        return true;
569
-    }
570
-
571
-    /**
572
-     * clean expired objects from database
573
-     *
574
-     * @param  int $expire time limit for expiration
575
-     * @return bool true on success
576
-     */
577
-    public function cleanExpires($expire = 0)
578
-    {
579
-        // irmtfan if 0 no cleanup look include/plugin.php
580
-        if (!func_num_args()) {
581
-            $newbbConfig = newbbLoadConfig();
582
-            $expire      = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7;
583
-            $expire      = $expire * 24 * 3600; // days to seconds
584
-        }
585
-        if (empty($expire)) {
586
-            return false;
587
-        }
588
-        $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<='));
589
-        //if (!empty($expire)) {
590
-        $crit_expire->add(new \Criteria('post_time', time() - (int)$expire, '<'));
591
-
592
-        //}
593
-        return $this->deleteAll($crit_expire, true/*, true*/);
594
-    }
504
+	/**
505
+	 * @param  null $criteria
506
+	 * @param  int  $limit
507
+	 * @param  int  $start
508
+	 * @param  null $join
509
+	 * @return array
510
+	 */
511
+	public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null)
512
+	{
513
+		$ret = [];
514
+		$sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
515
+		if (!empty($join)) {
516
+			$sql .= $join;
517
+		}
518
+		if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
519
+			$sql .= ' ' . $criteria->renderWhere();
520
+			if ('' !== $criteria->getSort()) {
521
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
522
+			}
523
+		}
524
+		$result = $this->db->query($sql, (int)$limit, (int)$start);
525
+		if (!$result) {
526
+			//xoops_error($this->db->error());
527
+			return $ret;
528
+		}
529
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
530
+			$post = $this->create(false);
531
+			$post->assignVars($myrow);
532
+			$ret[$myrow['post_id']] = $post;
533
+			unset($post);
534
+		}
535
+
536
+		return $ret;
537
+	}
538
+
539
+	/**
540
+	 * @return bool
541
+	 */
542
+	public function synchronization()
543
+	{
544
+		//$this->cleanOrphan();
545
+		return true;
546
+	}
547
+
548
+	/**
549
+	 * clean orphan items from database
550
+	 *
551
+	 * @param  string $table_link
552
+	 * @param  string $field_link
553
+	 * @param  string $field_object
554
+	 * @return bool   true on success
555
+	 */
556
+	public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
557
+	{
558
+		$this->deleteAll(new \Criteria('post_time', 0), true, true);
559
+		parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id');
560
+		parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id');
561
+
562
+		$sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )';
563
+		if (!$result = $this->db->queryF($sql)) {
564
+			//xoops_error($this->db->error());
565
+			return false;
566
+		}
567
+
568
+		return true;
569
+	}
570
+
571
+	/**
572
+	 * clean expired objects from database
573
+	 *
574
+	 * @param  int $expire time limit for expiration
575
+	 * @return bool true on success
576
+	 */
577
+	public function cleanExpires($expire = 0)
578
+	{
579
+		// irmtfan if 0 no cleanup look include/plugin.php
580
+		if (!func_num_args()) {
581
+			$newbbConfig = newbbLoadConfig();
582
+			$expire      = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7;
583
+			$expire      = $expire * 24 * 3600; // days to seconds
584
+		}
585
+		if (empty($expire)) {
586
+			return false;
587
+		}
588
+		$crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<='));
589
+		//if (!empty($expire)) {
590
+		$crit_expire->add(new \Criteria('post_time', time() - (int)$expire, '<'));
591
+
592
+		//}
593
+		return $this->deleteAll($crit_expire, true/*, true*/);
594
+	}
595 595
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function get($id = null, $var = null) //get($id)
58 58
     {
59
-        $id   = (int)$id;
59
+        $id   = (int) $id;
60 60
         $post = null;
61
-        $sql  = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id;
61
+        $sql  = 'SELECT p.*, t.* FROM '.$this->db->prefix('newbb_posts').' p LEFT JOIN '.$this->db->prefix('newbb_posts_text').' t ON p.post_id=t.post_id WHERE p.post_id='.$id;
62 62
         if ($array = $this->db->fetchArray($this->db->query($sql))) {
63 63
             $post = $this->create(false);
64 64
             $post->assignVars($array);
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $topic_id = 0,
88 88
         $approved = 1
89 89
     ) {
90
-        $sql    = 'SELECT p.*, t.*, tp.topic_status FROM '
90
+        $sql = 'SELECT p.*, t.*, tp.topic_status FROM '
91 91
                   . $this->db->prefix('newbb_posts')
92 92
                   . ' p LEFT JOIN '
93 93
                   . $this->db->prefix('newbb_posts_text')
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 
380 380
         /* Set active post as deleted */
381 381
         if ($post->getVar('approved') > 0 && empty($force)) {
382
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id');
382
+            $sql = 'UPDATE '.$this->db->prefix('newbb_posts').' SET approved = -1 WHERE post_id = '.$post->getVar('post_id');
383 383
             if (!$result = $this->db->queryF($sql)) {
384 384
             }
385 385
             /* delete pending post directly */
386 386
         } else {
387 387
             $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id'));
388 388
             if (!$result = $this->db->queryF($sql)) {
389
-                $post->setErrors('delete post error: ' . $sql);
389
+                $post->setErrors('delete post error: '.$sql);
390 390
 
391 391
                 return false;
392 392
             }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 
395 395
             $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id'));
396 396
             if (!$result = $this->db->queryF($sql)) {
397
-                $post->setErrors('Could not remove post text: ' . $sql);
397
+                $post->setErrors('Could not remove post text: '.$sql);
398 398
 
399 399
                 return false;
400 400
             }
@@ -431,11 +431,11 @@  discard block
 block discarded – undo
431 431
                 }
432 432
             }
433 433
         } else {
434
-            $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t
435
-                            LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.topic_id = t.topic_id
434
+            $sql = 'UPDATE '.$this->db->prefix('newbb_topics').' t
435
+                            LEFT JOIN ' . $this->db->prefix('newbb_posts').' p ON p.topic_id = t.topic_id
436 436
                             SET t.topic_last_post_id = p.post_id
437
-                            WHERE t.topic_last_post_id = ' . $post->getVar('post_id') . '
438
-                                    AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=t.topic_id)';
437
+                            WHERE t.topic_last_post_id = ' . $post->getVar('post_id').'
438
+                                    AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts').' WHERE topic_id=t.topic_id)';
439 439
             if (!$result = $this->db->queryF($sql)) {
440 440
             }
441 441
         }
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
             }
458 458
             // irmtfan - just update the pid for approved posts when the post is not topic (pid=0)
459 459
             if (!$post->isTopic()) {
460
-                $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id');
460
+                $sql = 'UPDATE '.$this->db->prefix('newbb_posts').' SET pid = '.$post->getVar('pid').' WHERE approved=1 AND pid='.$post->getVar('post_id');
461 461
                 if (!$result = $this->db->queryF($sql)) {
462 462
                     //xoops_error($this->db->error());
463 463
                 }
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
             return parent::getCount($criteria);
482 482
         }
483 483
 
484
-        $sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
484
+        $sql = 'SELECT COUNT(*) as count'.' FROM '.$this->db->prefix('newbb_posts').' AS p'.' LEFT JOIN '.$this->db->prefix('newbb_posts_text').' AS t ON t.post_id = p.post_id';
485 485
         // LEFT JOIN
486 486
         $sql .= $join;
487 487
         // WHERE
488 488
         if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
489
-            $sql .= ' ' . $criteria->renderWhere();
489
+            $sql .= ' '.$criteria->renderWhere();
490 490
         }
491 491
         if (!$result = $this->db->query($sql)) {
492 492
             //xoops_error($this->db->error().'<br>'.$sql);
@@ -511,17 +511,17 @@  discard block
 block discarded – undo
511 511
     public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null)
512 512
     {
513 513
         $ret = [];
514
-        $sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id';
514
+        $sql = 'SELECT p.*, t.* '.' FROM '.$this->db->prefix('newbb_posts').' AS p'.' LEFT JOIN '.$this->db->prefix('newbb_posts_text').' AS t ON t.post_id = p.post_id';
515 515
         if (!empty($join)) {
516 516
             $sql .= $join;
517 517
         }
518 518
         if (null !== $criteria && is_subclass_of($criteria, 'CriteriaElement')) {
519
-            $sql .= ' ' . $criteria->renderWhere();
519
+            $sql .= ' '.$criteria->renderWhere();
520 520
             if ('' !== $criteria->getSort()) {
521
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
521
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
522 522
             }
523 523
         }
524
-        $result = $this->db->query($sql, (int)$limit, (int)$start);
524
+        $result = $this->db->query($sql, (int) $limit, (int) $start);
525 525
         if (!$result) {
526 526
             //xoops_error($this->db->error());
527 527
             return $ret;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
         parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id');
560 560
         parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id');
561 561
 
562
-        $sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )';
562
+        $sql = 'DELETE FROM '.$this->db->prefix('newbb_posts_text').' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM '.$this->table.') )';
563 563
         if (!$result = $this->db->queryF($sql)) {
564 564
             //xoops_error($this->db->error());
565 565
             return false;
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
         // irmtfan if 0 no cleanup look include/plugin.php
580 580
         if (!func_num_args()) {
581 581
             $newbbConfig = newbbLoadConfig();
582
-            $expire      = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7;
582
+            $expire      = isset($newbbConfig['pending_expire']) ? (int) $newbbConfig['pending_expire'] : 7;
583 583
             $expire      = $expire * 24 * 3600; // days to seconds
584 584
         }
585 585
         if (empty($expire)) {
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
         }
588 588
         $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<='));
589 589
         //if (!empty($expire)) {
590
-        $crit_expire->add(new \Criteria('post_time', time() - (int)$expire, '<'));
590
+        $crit_expire->add(new \Criteria('post_time', time() - (int) $expire, '<'));
591 591
 
592 592
         //}
593 593
         return $this->deleteAll($crit_expire, true/*, true*/);
Please login to merge, or discard this patch.
class/CategoryHandler.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -19,136 +19,136 @@
 block discarded – undo
19 19
  */
20 20
 class CategoryHandler extends \XoopsPersistableObjectHandler
21 21
 {
22
-    /**
23
-     * @param null|\XoopsDatabase $db
24
-     */
25
-    public function __construct(\XoopsDatabase $db = null)
26
-    {
27
-        parent::__construct($db, 'newbb_categories', Category::class, 'cat_id', 'cat_title');
28
-    }
29
-
30
-    /**
31
-     * @param  string $perm
32
-     * @return mixed
33
-     */
34
-    public function getIdsByPermission($perm = 'access')
35
-    {
36
-        /** var Newbb\PermissionHandler $permHandler */
37
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
38
-        return $permHandler->getCategories($perm);
39
-    }
40
-
41
-    /**
42
-     * @param  string $permission
43
-     * @param  null   $tags
44
-     * @param  bool   $asObject
45
-     * @return array
46
-     */
47
-    public function &getByPermission($permission = 'access', $tags = null, $asObject = true)
48
-    {
49
-        $categories = [];
50
-        if (!$valid_ids = $this->getIdsByPermission($permission)) {
51
-            return $categories;
52
-        }
53
-        $criteria = new \Criteria('cat_id', '(' . implode(', ', $valid_ids) . ')', 'IN');
54
-        $criteria->setSort('cat_order');
55
-        $categories = $this->getAll($criteria, $tags, $asObject);
56
-
57
-        return $categories;
58
-    }
59
-
60
-    /**
61
-     * @param \XoopsObject $category
62
-     * @param  bool        $force
63
-     * @return mixed
64
-     */
65
-    public function insert(\XoopsObject $category, $force = true)
66
-    {
67
-        $className = Category::class;
68
-        if (!($category instanceof $className)) {
69
-            return false;
70
-        }
71
-        parent::insert($category, $force);
72
-        if ($category->isNew()) {
73
-            $this->applyPermissionTemplate($category);
74
-        }
75
-
76
-        return $category->getVar('cat_id');
77
-    }
78
-
79
-    /**
80
-     * @param \XoopsObject $category
81
-     * @param  bool        $force
82
-     * @return bool|mixed
83
-     * @internal param Category $category
84
-     */
85
-    public function delete(\XoopsObject $category, $force = false)//delete(Category $category)
86
-    {
87
-        $className = Category::class;
88
-        if (!($category instanceof $className)) {
89
-            return false;
90
-        }
91
-        /** @var Newbb\ForumHandler $forumHandler */
92
-        $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
93
-        $forumHandler->deleteAll(new \Criteria('cat_id', $category->getVar('cat_id')), true, true);
94
-        if ($result = parent::delete($category)) {
95
-            // Delete group permissions
96
-            return $this->deletePermission($category);
97
-        } else {
98
-            $category->setErrors('delete category error');
99
-
100
-            return false;
101
-        }
102
-    }
103
-
104
-    /**
105
-     * Check permission for a category
106
-     *
107
-     * @param  Category|int $category object or id
108
-     * @param  string       $perm     permission name
109
-     *
110
-     * @return bool
111
-     */
112
-    public function getPermission($category, $perm = 'access')
113
-    {
114
-        if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
115
-            return true;
116
-        }
117
-
118
-        $cat_id = is_object($category) ? $category->getVar('cat_id') : (int)$category;
119
-        /** @var PermissionHandler $permHandler */
120
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
121
-        return $permHandler->getPermission('category', $perm, $cat_id);
122
-    }
123
-
124
-    /**
125
-     * @param Category $category
126
-     * @return mixed
127
-     */
128
-    public function deletePermission(Category $category)
129
-    {
130
-        /** @var PermissionHandler $permHandler */
131
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
132
-        return $permHandler->deleteByCategory($category->getVar('cat_id'));
133
-    }
134
-
135
-    /**
136
-     * @param Category $category
137
-     * @return mixed
138
-     */
139
-    public function applyPermissionTemplate(Category $category)
140
-    {
141
-        /** @var PermissionHandler $permHandler */
142
-        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
143
-        return $permHandler->setCategoryPermission($category->getVar('cat_id'));
144
-    }
145
-
146
-    /**
147
-     * @param  mixed $object
148
-     * @return bool
149
-     */
150
-    public function synchronization($object = null)
151
-    {
152
-        return true;
153
-    }
22
+	/**
23
+	 * @param null|\XoopsDatabase $db
24
+	 */
25
+	public function __construct(\XoopsDatabase $db = null)
26
+	{
27
+		parent::__construct($db, 'newbb_categories', Category::class, 'cat_id', 'cat_title');
28
+	}
29
+
30
+	/**
31
+	 * @param  string $perm
32
+	 * @return mixed
33
+	 */
34
+	public function getIdsByPermission($perm = 'access')
35
+	{
36
+		/** var Newbb\PermissionHandler $permHandler */
37
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
38
+		return $permHandler->getCategories($perm);
39
+	}
40
+
41
+	/**
42
+	 * @param  string $permission
43
+	 * @param  null   $tags
44
+	 * @param  bool   $asObject
45
+	 * @return array
46
+	 */
47
+	public function &getByPermission($permission = 'access', $tags = null, $asObject = true)
48
+	{
49
+		$categories = [];
50
+		if (!$valid_ids = $this->getIdsByPermission($permission)) {
51
+			return $categories;
52
+		}
53
+		$criteria = new \Criteria('cat_id', '(' . implode(', ', $valid_ids) . ')', 'IN');
54
+		$criteria->setSort('cat_order');
55
+		$categories = $this->getAll($criteria, $tags, $asObject);
56
+
57
+		return $categories;
58
+	}
59
+
60
+	/**
61
+	 * @param \XoopsObject $category
62
+	 * @param  bool        $force
63
+	 * @return mixed
64
+	 */
65
+	public function insert(\XoopsObject $category, $force = true)
66
+	{
67
+		$className = Category::class;
68
+		if (!($category instanceof $className)) {
69
+			return false;
70
+		}
71
+		parent::insert($category, $force);
72
+		if ($category->isNew()) {
73
+			$this->applyPermissionTemplate($category);
74
+		}
75
+
76
+		return $category->getVar('cat_id');
77
+	}
78
+
79
+	/**
80
+	 * @param \XoopsObject $category
81
+	 * @param  bool        $force
82
+	 * @return bool|mixed
83
+	 * @internal param Category $category
84
+	 */
85
+	public function delete(\XoopsObject $category, $force = false)//delete(Category $category)
86
+	{
87
+		$className = Category::class;
88
+		if (!($category instanceof $className)) {
89
+			return false;
90
+		}
91
+		/** @var Newbb\ForumHandler $forumHandler */
92
+		$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
93
+		$forumHandler->deleteAll(new \Criteria('cat_id', $category->getVar('cat_id')), true, true);
94
+		if ($result = parent::delete($category)) {
95
+			// Delete group permissions
96
+			return $this->deletePermission($category);
97
+		} else {
98
+			$category->setErrors('delete category error');
99
+
100
+			return false;
101
+		}
102
+	}
103
+
104
+	/**
105
+	 * Check permission for a category
106
+	 *
107
+	 * @param  Category|int $category object or id
108
+	 * @param  string       $perm     permission name
109
+	 *
110
+	 * @return bool
111
+	 */
112
+	public function getPermission($category, $perm = 'access')
113
+	{
114
+		if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) {
115
+			return true;
116
+		}
117
+
118
+		$cat_id = is_object($category) ? $category->getVar('cat_id') : (int)$category;
119
+		/** @var PermissionHandler $permHandler */
120
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
121
+		return $permHandler->getPermission('category', $perm, $cat_id);
122
+	}
123
+
124
+	/**
125
+	 * @param Category $category
126
+	 * @return mixed
127
+	 */
128
+	public function deletePermission(Category $category)
129
+	{
130
+		/** @var PermissionHandler $permHandler */
131
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
132
+		return $permHandler->deleteByCategory($category->getVar('cat_id'));
133
+	}
134
+
135
+	/**
136
+	 * @param Category $category
137
+	 * @return mixed
138
+	 */
139
+	public function applyPermissionTemplate(Category $category)
140
+	{
141
+		/** @var PermissionHandler $permHandler */
142
+		$permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
143
+		return $permHandler->setCategoryPermission($category->getVar('cat_id'));
144
+	}
145
+
146
+	/**
147
+	 * @param  mixed $object
148
+	 * @return bool
149
+	 */
150
+	public function synchronization($object = null)
151
+	{
152
+		return true;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         if (!$valid_ids = $this->getIdsByPermission($permission)) {
51 51
             return $categories;
52 52
         }
53
-        $criteria = new \Criteria('cat_id', '(' . implode(', ', $valid_ids) . ')', 'IN');
53
+        $criteria = new \Criteria('cat_id', '('.implode(', ', $valid_ids).')', 'IN');
54 54
         $criteria->setSort('cat_order');
55 55
         $categories = $this->getAll($criteria, $tags, $asObject);
56 56
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             return true;
116 116
         }
117 117
 
118
-        $cat_id = is_object($category) ? $category->getVar('cat_id') : (int)$category;
118
+        $cat_id = is_object($category) ? $category->getVar('cat_id') : (int) $category;
119 119
         /** @var PermissionHandler $permHandler */
120 120
         $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
121 121
         return $permHandler->getPermission('category', $perm, $cat_id);
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 = null)
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 = null)
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   +22 added lines, -22 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
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             $this->forum_id    = $forum->getVar('forum_id');
48 48
             $this->forumObject = $forum;
49 49
         } else {
50
-            $this->forum_id    = (int)$forum;
50
+            $this->forum_id    = (int) $forum;
51 51
             $this->forumObject = $forum;
52 52
         }
53 53
         if (is_object($forumtopic)) {
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                 $this->forum_id = $forumtopic->getVar('forum_id');
57 57
             }
58 58
         } else {
59
-            $this->topic_id = (int)$forumtopic;
59
+            $this->topic_id = (int) $forumtopic;
60 60
         }
61 61
 
62 62
         $this->update();
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     {
67 67
         global $xoopsModule;
68 68
 
69
-        mt_srand((double)microtime() * 1000000);
69
+        mt_srand((double) microtime() * 1000000);
70 70
         // set gc probabillity to 10% for now..
71 71
         if (mt_rand(1, 100) < 60) {
72 72
             $this->gc(150);
@@ -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;
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
     {
228 228
         global $xoopsModule, $xoopsDB;
229 229
 
230
-        $uid = (int)$uid;
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.