Completed
Pull Request — master (#77)
by Michael
11:21
created

XoopsCommentRenderer::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * XOOPS comment renderer
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @subpackage          comment
16
 * @since               2.0.0
17
 * @author              Kazumi Ono <[email protected]>
18
 */
19
20
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21
22
/**
23
 * Display comments
24
 *
25
 * @author Kazumi Ono <[email protected]>
26
 * @access public
27
 */
28
class XoopsCommentRenderer
29
{
30
    /**
31
     * *#@+
32
     *
33
     * @access private
34
     */
35
    public $_tpl;
36
    public $_comments;
37
    public $_useIcons    = true;
38
    public $_doIconCheck = false;
39
    public $_memberHandler;
40
    public $_statusText;
41
    /**
42
     * *#@-
43
     */
44
45
    /**
46
     * Constructor
47
     *
48
     * @param XoopsTpl $tpl
49
     * @param boolean  $use_icons
50
     * @param boolean  $do_iconcheck
51
     *
52
     */
53
    public function __construct(XoopsTpl $tpl, $use_icons = true, $do_iconcheck = false)
54
    {
55
        $this->_tpl           = $tpl;
56
        $this->_useIcons      = $use_icons;
57
        $this->_doIconCheck   = $do_iconcheck;
58
        $this->_memberHandler = xoops_getHandler('member');
59
        $this->_statusText    = array(
60
            XOOPS_COMMENT_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #00ff00;">' . _CM_PENDING . '</span>',
61
            XOOPS_COMMENT_ACTIVE  => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">' . _CM_ACTIVE . '</span>',
62
            XOOPS_COMMENT_HIDDEN  => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">' . _CM_HIDDEN . '</span>');
63
    }
64
65
    public static function instance(XoopsTpl $tpl, $use_icons = true, $do_iconcheck = false) {
66
        return self::getInstance($tpl, $use_icons, $do_iconcheck);
67
    }
68
    
69
    /**
70
     * Access the only instance of this class
71
     *
72
     * @param  XoopsTpl $tpl reference to a {@link Smarty} object
73
     * @param  boolean  $use_icons
74
     * @param  boolean  $do_iconcheck
75
     * @return \XoopsCommentRenderer
76
     */
77
    public static function getInstance(XoopsTpl $tpl, $use_icons = true, $do_iconcheck = false)
78
    {
79
        static $instance;
80
        if (!isset($instance)) {
81
            $instance = new static($tpl, $use_icons, $do_iconcheck);
82
        }
83
        return $instance;
84
    }
85
86
    /**
87
     * Accessor
88
     *
89
     * @param object $comments_arr array of {@link XoopsComment} objects
90
     */
91
    public function setComments(&$comments_arr)
92
    {
93
        if (isset($this->_comments)) {
94
            unset($this->_comments);
95
        }
96
        $this->_comments =& $comments_arr;
97
    }
98
99
    /**
100
     * Render the comments in flat view
101
     *
102
     * @param boolean $admin_view
103
     */
104
    public function renderFlatView($admin_view = false)
105
    {
106
        $count = count($this->_comments);
107
        for ($i = 0; $i < $count; ++$i) {
108
            if (false != $this->_useIcons) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
109
                $title = $this->_getTitleIcon($this->_comments[$i]->getVar('com_icon')) . '&nbsp;' . $this->_comments[$i]->getVar('com_title');
110
            } else {
111
                $title = $this->_comments[$i]->getVar('com_title');
112
            }
113
            // Start edit by voltan
114
            $poster = $this->_getPosterArray($this->_comments[$i]->getVar('com_uid'), $this->_comments[$i]->getVar('com_user'), $this->_comments[$i]->getVar('com_url'));
115
            if (false != $admin_view) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
116
                $com_email = $this->_comments[$i]->getVar('com_email');
117
                $text      = $this->_comments[$i]->getVar('com_text');
118
                $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0; margin-right: 2px;">';
119
                $text .= _CM_STATUS . ': ' . $this->_statusText[$this->_comments[$i]->getVar('com_status')] . '<br />';
120
                $text .= 'IP: <span style="font-weight: bold;">' . $this->_comments[$i]->getVar('com_ip') . '</span>';
121
                if (!empty($com_email)) {
122
                    $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
123
                }
124
                $text .= '</div>';
125
            } else {
126
                // hide comments that are not active
127
                if (XOOPS_COMMENT_ACTIVE != $this->_comments[$i]->getVar('com_status')) {
128
                    continue;
129
                } else {
130
                    $text = $this->_comments[$i]->getVar('com_text');
131
                }
132
            }
133
            // End edit by voltan
134
            $this->_tpl->append('comments', array(
135
                'id'            => $this->_comments[$i]->getVar('com_id'),
136
                'title'         => $title,
137
                'text'          => $text,
138
                'date_posted'   => formatTimestamp($this->_comments[$i]->getVar('com_created'), 'm'),
139
                'date_modified' => formatTimestamp($this->_comments[$i]->getVar('com_modified'), 'm'),
140
                'poster'        => $poster));
141
        }
142
    }
143
144
    /**
145
     * Render the comments in thread view
146
     *
147
     * This method calls itself recursively
148
     *
149
     * @param  integer $comment_id Should be "0" when called by client
150
     * @param  boolean $admin_view
151
     * @param  boolean $show_nav
152
     * @return null
153
     */
154
    public function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true)
155
    {
156
        include_once $GLOBALS['xoops']->path('class/tree.php');
157
        // construct comment tree
158
        $xot  = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
159
        $tree =& $xot->getTree();
160
161 View Code Duplication
        if (false != $this->_useIcons) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
162
            $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')) . '&nbsp;' . $tree[$comment_id]['obj']->getVar('com_title');
163
        } else {
164
            $title = $tree[$comment_id]['obj']->getVar('com_title');
165
        }
166
        if (false != $show_nav && $tree[$comment_id]['obj']->getVar('com_pid') != 0) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
167
            $this->_tpl->assign('lang_top', _CM_TOP);
168
            $this->_tpl->assign('lang_parent', _CM_PARENT);
169
            $this->_tpl->assign('show_threadnav', true);
170
        } else {
171
            $this->_tpl->assign('show_threadnav', false);
172
        }
173 View Code Duplication
        if (false != $admin_view) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
174
            // admins can see all
175
            $com_email = $tree[$comment_id]['obj']->getVar('com_email');
176
            $text      = $tree[$comment_id]['obj']->getVar('com_text');
177
            $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0; margin-right: 2px;">';
178
            $text .= _CM_STATUS . ': ' . $this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')] . '<br />';
179
            $text .= 'IP: <span style="font-weight: bold;">' . $tree[$comment_id]['obj']->getVar('com_ip') . '</span>';
180
            if (!empty($com_email)) {
181
                $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
182
            }
183
            $text .= '</div>';
184
        } else {
185
            // hide comments that are not active
186
            if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
187
                // if there are any child comments, display them as root comments
188
                if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
189
                    foreach ($tree[$comment_id]['child'] as $child_id) {
190
                        $this->renderThreadView($child_id, $admin_view, false);
191
                    }
192
                }
193
194
                return null;
195
            } else {
196
                $text = $tree[$comment_id]['obj']->getVar('com_text');
197
            }
198
        }
199
        $replies = array();
200
        $this->_renderThreadReplies($tree, $comment_id, $replies, '&nbsp;&nbsp;', $admin_view);
201
        $show_replies = (count($replies) > 0);// ? true : false;
202
        // Start edit by voltan
203
        $this->_tpl->append('comments', array(
204
            'pid'           => $tree[$comment_id]['obj']->getVar('com_pid'),
205
            'id'            => $tree[$comment_id]['obj']->getVar('com_id'),
206
            'itemid'        => $tree[$comment_id]['obj']->getVar('com_itemid'),
207
            'rootid'        => $tree[$comment_id]['obj']->getVar('com_rootid'),
208
            'title'         => $title,
209
            'text'          => $text,
210
            'date_posted'   => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'),
211
            'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'),
212
            'poster'        => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid'), $tree[$comment_id]['obj']->getVar('com_user'), $tree[$comment_id]['obj']->getVar('com_url')),
213
            'replies'       => $replies,
214
            'show_replies'  => $show_replies));
215
        // End edit by voltan
216
    }
217
218
    /**
219
     * Render replies to a thread
220
     *
221
     * @param array   $thread
222
     * @param int     $key
223
     * @param array   $replies
224
     * @param string  $prefix
225
     * @param bool    $admin_view
226
     * @param integer $depth
227
     * @param string  $current_prefix
228
     * @access   private
229
     */
230
    public function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '')
231
    {
232
        if ($depth > 0) {
233 View Code Duplication
            if (false != $this->_useIcons) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
234
                $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')) . '&nbsp;' . $thread[$key]['obj']->getVar('com_title');
235
            } else {
236
                $title = $thread[$key]['obj']->getVar('com_title');
237
            }
238
            $title = (false != $admin_view) ? $title . ' ' . $this->_statusText[$thread[$key]['obj']->getVar('com_status')] : $title;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
239
            // Start edit by voltan
240
            $replies[] = array(
241
                'id'          => $key,
242
                'prefix'      => $current_prefix,
243
                'date_posted' => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm'),
244
                'title'       => $title,
245
                'root_id'     => $thread[$key]['obj']->getVar('com_rootid'),
246
                'status'      => $this->_statusText[$thread[$key]['obj']->getVar('com_status')],
247
                'poster'      => $this->_getPosterName($thread[$key]['obj']->getVar('com_uid'), $thread[$key]['obj']->getVar('com_user'), $thread[$key]['obj']->getVar('com_url')));
248
            // End edit by voltan
249
            $current_prefix .= $prefix;
250
        }
251 View Code Duplication
        if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
252
            ++$depth;
253
            foreach ($thread[$key]['child'] as $childkey) {
254
                if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
255
                    // skip this comment if it is not active and continue on processing its child comments instead
256
                    if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
257
                        foreach ($thread[$childkey]['child'] as $childchildkey) {
258
                            $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
259
                        }
260
                    }
261
                } else {
262
                    $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix);
263
                }
264
            }
265
        }
266
    }
267
268
    /**
269
     * Render comments in nested view
270
     *
271
     * Danger: Recursive!
272
     *
273
     * @param  integer $comment_id Always "0" when called by client.
274
     * @param  boolean $admin_view
275
     * @return null
276
     */
277
    public function renderNestView($comment_id = 0, $admin_view = false)
278
    {
279
        include_once $GLOBALS['xoops']->path('class/tree.php');
280
        $xot  = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
281
        $tree =& $xot->getTree();
282 View Code Duplication
        if (false != $this->_useIcons) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
283
            $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')) . '&nbsp;' . $tree[$comment_id]['obj']->getVar('com_title');
284
        } else {
285
            $title = $tree[$comment_id]['obj']->getVar('com_title');
286
        }
287 View Code Duplication
        if (false != $admin_view) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
288
            $com_email = $tree[$comment_id]['obj']->getVar('com_email');
289
            $text      = $tree[$comment_id]['obj']->getVar('com_text');
290
            $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0; margin-right: 2px;">';
291
            $text .= _CM_STATUS . ': ' . $this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')] . '<br />';
292
            $text .= 'IP: <span style="font-weight: bold;">' . $tree[$comment_id]['obj']->getVar('com_ip') . '</span>';
293
            if (!empty($com_email)) {
294
                $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
295
            }
296
            $text .= '</div>';
297
        } else {
298
            // skip this comment if it is not active and continue on processing its child comments instead
299
            if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
300
                // if there are any child comments, display them as root comments
301
                if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
302
                    foreach ($tree[$comment_id]['child'] as $child_id) {
303
                        $this->renderNestView($child_id, $admin_view);
304
                    }
305
                }
306
307
                return null;
308
            } else {
309
                $text = $tree[$comment_id]['obj']->getVar('com_text');
310
            }
311
        }
312
        $replies = array();
313
        $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view);
314
        // Start edit by voltan
315
        $this->_tpl->append('comments', array(
316
            'pid'           => $tree[$comment_id]['obj']->getVar('com_pid'),
317
            'id'            => $tree[$comment_id]['obj']->getVar('com_id'),
318
            'itemid'        => $tree[$comment_id]['obj']->getVar('com_itemid'),
319
            'rootid'        => $tree[$comment_id]['obj']->getVar('com_rootid'),
320
            'title'         => $title,
321
            'text'          => $text,
322
            'date_posted'   => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'),
323
            'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'),
324
            'poster'        => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid'), $tree[$comment_id]['obj']->getVar('com_user'), $tree[$comment_id]['obj']->getVar('com_url')),
325
            'replies'       => $replies));
326
        // End edit by voltan
327
    }
328
329
    /**
330
     * Render replies in nested view
331
     *
332
     * @param array   $thread
333
     * @param int     $key
334
     * @param array   $replies
335
     * @param string  $prefix
336
     * @param bool    $admin_view
337
     * @param integer $depth
338
     * @access private
339
     */
340
    public function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0)
341
    {
342
        if ($depth > 0) {
343 View Code Duplication
            if (false != $this->_useIcons) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
344
                $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')) . '&nbsp;' . $thread[$key]['obj']->getVar('com_title');
345
            } else {
346
                $title = $thread[$key]['obj']->getVar('com_title');
347
            }
348
            $text = (false != $admin_view) ? $thread[$key]['obj']->getVar('com_text') . '<div style="text-align:right; margin-top: 2px; margin-right: 2px;">' . _CM_STATUS . ': ' . $this->_statusText[$thread[$key]['obj']->getVar('com_status')] . '<br />IP: <span style="font-weight: bold;">' . $thread[$key]['obj']->getVar('com_ip') . '</span><br />' . _CM_EMAIL . ' :<span style="font-weight: bold;">' . $thread[$key]['obj']->getVar('com_email') . '</span></div>' : $thread[$key]['obj']->getVar('com_text');
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
349
            // Start edit by voltan
350
            $replies[] = array(
351
                'id'            => $key,
352
                'prefix'        => $prefix,
353
                'pid'           => $thread[$key]['obj']->getVar('com_pid'),
354
                'itemid'        => $thread[$key]['obj']->getVar('com_itemid'),
355
                'rootid'        => $thread[$key]['obj']->getVar('com_rootid'),
356
                'title'         => $title,
357
                'text'          => $text,
358
                'date_posted'   => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm'),
359
                'date_modified' => formatTimestamp($thread[$key]['obj']->getVar('com_modified'), 'm'),
360
                'poster'        => $this->_getPosterArray($thread[$key]['obj']->getVar('com_uid'), $thread[$key]['obj']->getVar('com_user'), $thread[$key]['obj']->getVar('com_url')));
361
            // End edit by voltan
362
            $prefix += 25;
363
        }
364 View Code Duplication
        if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
365
            ++$depth;
366
            foreach ($thread[$key]['child'] as $childkey) {
367
                if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
368
                    // skip this comment if it is not active and continue on processing its child comments instead
369
                    if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
370
                        foreach ($thread[$childkey]['child'] as $childchildkey) {
371
                            $this->_renderNestReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
372
                        }
373
                    }
374
                } else {
375
                    $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth);
376
                }
377
            }
378
        }
379
    }
380
381
    /**
382
     * Get the name of the poster
383
     *
384
     * @param  int    $poster_id
385
     * @param         $poster_user
386
     * @param         $poster_website
387
     * @return string
388
     * @access private
389
     */
390
    // Start edit by voltan
391
    public function _getPosterName($poster_id, $poster_user, $poster_website)
392
    {
393
        $poster['id'] = (int)$poster_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$poster was never initialized. Although not strictly required by PHP, it is generally a good practice to add $poster = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
394
        if ($poster['id'] > 0) {
395
            $com_poster =& $this->_memberHandler->getUser($poster_id);
396 View Code Duplication
            if (is_object($com_poster)) {
397
                $poster['uname'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $poster['id'] . '">' . $com_poster->getVar('uname') . '</a>';
398
            }
399
        } elseif ($poster['id'] == 0 && $poster_user != '') {
400
            $poster['id'] = 0; // to cope with deleted user accounts
401 View Code Duplication
            if (!empty($poster_website)) {
402
                $poster['uname'] = '<a href="' . $poster_website . '">' . $poster_user . '</a>';
403
            } else {
404
                $poster['uname'] = $poster_user;
405
            }
406
        } else {
407
            $poster['id']    = 0; // to cope with deleted user accounts
408
            $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
409
        }
410
411
        return $poster;
412
    }
413
    // End edit by voltan
414
415
    /**
416
     * Get an array with info about the poster
417
     *
418
     * @param  int   $poster_id
419
     * @param        $poster_user
420
     * @param        $poster_website
421
     * @return array
422
     * @access private
423
     */
424
    // Start edit by voltan
425
    public function _getPosterArray($poster_id, $poster_user, $poster_website)
426
    {
427
        $poster['id'] = (int)$poster_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$poster was never initialized. Although not strictly required by PHP, it is generally a good practice to add $poster = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
428
        if ($poster['id'] > 0) {
429
            $com_poster =& $this->_memberHandler->getUser($poster['id']);
430
            if (is_object($com_poster)) {
431
                $poster['uname']      = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $poster['id'] . '">' . $com_poster->getVar('uname') . '</a>';
432
                $poster_rank          = $com_poster->rank();
433
                $poster['rank_image'] = ($poster_rank['image'] != '') ? $poster_rank['image'] : 'blank.gif';
434
                $poster['rank_title'] = $poster_rank['title'];
435
                $poster['avatar']     = $com_poster->getVar('user_avatar');
436
                $poster['regdate']    = formatTimestamp($com_poster->getVar('user_regdate'), 's');
437
                $poster['from']       = $com_poster->getVar('user_from');
438
                $poster['postnum']    = $com_poster->getVar('posts');
439
                $poster['status']     = $com_poster->isOnline() ? _CM_ONLINE : '';
440
            }
441
        } elseif ($poster['id'] == 0 && $poster_user != '') {
442 View Code Duplication
            if (!empty($poster_website)) {
443
                $poster['uname'] = '<a href="' . $poster_website . '">' . $poster_user . '</a>';
444
            } else {
445
                $poster['uname'] = $poster_user;
446
            }
447
            $poster['id']         = 0; // to cope with deleted user accounts
448
            $poster['rank_title'] = '';
449
            $poster['avatar']     = 'blank.gif';
450
            $poster['regdate']    = '';
451
            $poster['from']       = '';
452
            $poster['postnum']    = 0;
453
            $poster['status']     = '';
454
        } else {
455
            $poster['uname']      = $GLOBALS['xoopsConfig']['anonymous'];
456
            $poster['id']         = 0; // to cope with deleted user accounts
457
            $poster['rank_title'] = '';
458
            $poster['avatar']     = 'blank.gif';
459
            $poster['regdate']    = '';
460
            $poster['from']       = '';
461
            $poster['postnum']    = 0;
462
            $poster['status']     = '';
463
        }
464
465
        return $poster;
466
    }
467
    // End edit by voltan
468
469
    /**
470
     * Get the IMG tag for the title icon
471
     *
472
     * @param  string $icon_image
473
     * @return string HTML IMG tag
474
     * @access private
475
     */
476
    public function _getTitleIcon($icon_image)
477
    {
478
        $icon_image = htmlspecialchars(trim($icon_image));
479
        if ($icon_image != '') {
480
            if (false != $this->_doIconCheck) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
481
                if (!file_exists($GLOBALS['xoops']->path('images/subject/' . $icon_image))) {
482
                    return '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
483
                } else {
484
                    return '<img src="' . XOOPS_URL . '/images/subject/' . $icon_image . '" alt="" />';
485
                }
486
            } else {
487
                return '<img src="' . XOOPS_URL . '/images/subject/' . $icon_image . '" alt="" />';
488
            }
489
        }
490
491
        return '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
492
    }
493
}
494