XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
commentrenderer.php
Go to the documentation of this file.
1 <?php
21 defined('XOOPS_ROOT_PATH') or die('Restricted access');
22 
30 {
36  var $_tpl;
37  var $_comments = null;
38  var $_useIcons = true;
39  var $_doIconCheck = false;
53  function XoopsCommentRenderer(&$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(XOOPS_COMMENT_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #00ff00;">' . _CM_PENDING . '</span>' , XOOPS_COMMENT_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">' . _CM_ACTIVE . '</span>' , XOOPS_COMMENT_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">' . _CM_HIDDEN . '</span>');
60  }
61 
70  function &instance(&$tpl, $use_icons = true, $do_iconcheck = false)
71  {
72  static $instance;
73  if (!isset($instance)) {
74  $instance = new XoopsCommentRenderer($tpl, $use_icons, $do_iconcheck);
75  }
76  return $instance;
77  }
78 
84  function setComments(&$comments_arr)
85  {
86  if (isset($this->_comments)) {
87  unset($this->_comments);
88  }
89  $this->_comments =& $comments_arr;
90  }
91 
97  function renderFlatView($admin_view = false)
98  {
99  $count = count($this->_comments);
100  for ($i = 0; $i < $count; $i++) {
101  if (false != $this->_useIcons) {
102  $title = $this->_getTitleIcon($this->_comments[$i]->getVar('com_icon')) . '&nbsp;' . $this->_comments[$i]->getVar('com_title');
103  } else {
104  $title = $this->_comments[$i]->getVar('com_title');
105  }
106  // Start edit by voltan
107  $poster = $this->_getPosterArray($this->_comments[$i]->getVar('com_uid'), $this->_comments[$i]->getVar('com_user'), $this->_comments[$i]->getVar('com_url'));
108  if (false != $admin_view) {
109  $com_email = $this->_comments[$i]->getVar('com_email');
110  $text = $this->_comments[$i]->getVar('com_text');
111  $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">';
112  $text .= _CM_STATUS . ': ' . $this->_statusText[$this->_comments[$i]->getVar('com_status')] . '<br />';
113  $text .= 'IP: <span style="font-weight: bold;">' . $this->_comments[$i]->getVar('com_ip') . '</span>';
114  if(!empty($com_email)) {
115  $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
116  }
117  $text .= '</div>';
118  } else {
119  // hide comments that are not active
120  if (XOOPS_COMMENT_ACTIVE != $this->_comments[$i]->getVar('com_status')) {
121  continue;
122  } else {
123  $text = $this->_comments[$i]->getVar('com_text');
124  }
125  }
126  // End edit by voltan
127  $this->_tpl->append('comments', array('id' => $this->_comments[$i]->getVar('com_id') , 'title' => $title , 'text' => $text , 'date_posted' => formatTimestamp($this->_comments[$i]->getVar('com_created'), 'm') , 'date_modified' => formatTimestamp($this->_comments[$i]->getVar('com_modified'), 'm') , 'poster' => $poster));
128  }
129  }
130 
140  function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true)
141  {
142  include_once $GLOBALS['xoops']->path('class/tree.php');
143  // construct comment tree
144  $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
145  $tree =& $xot->getTree();
146 
147  if (false != $this->_useIcons) {
148  $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')) . '&nbsp;' . $tree[$comment_id]['obj']->getVar('com_title');
149  } else {
150  $title = $tree[$comment_id]['obj']->getVar('com_title');
151  }
152  if (false != $show_nav && $tree[$comment_id]['obj']->getVar('com_pid') != 0) {
153  $this->_tpl->assign('lang_top', _CM_TOP);
154  $this->_tpl->assign('lang_parent', _CM_PARENT);
155  $this->_tpl->assign('show_threadnav', true);
156  } else {
157  $this->_tpl->assign('show_threadnav', false);
158  }
159  if (false != $admin_view) {
160  // admins can see all
161  $com_email = $tree[$comment_id]['obj']->getVar('com_email');
162  $text = $tree[$comment_id]['obj']->getVar('com_text');
163  $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">';
164  $text .= _CM_STATUS . ': ' . $this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')] . '<br />';
165  $text .= 'IP: <span style="font-weight: bold;">' . $tree[$comment_id]['obj']->getVar('com_ip') . '</span>';
166  if(!empty($com_email)) {
167  $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
168  }
169  $text .= '</div>';
170  } else {
171  // hide comments that are not active
172  if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
173  // if there are any child comments, display them as root comments
174  if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
175  foreach ($tree[$comment_id]['child'] as $child_id) {
176  $this->renderThreadView($child_id, $admin_view, false);
177  }
178  }
179  return;
180  } else {
181  $text = $tree[$comment_id]['obj']->getVar('com_text');
182  }
183  }
184  $replies = array();
185  $this->_renderThreadReplies($tree, $comment_id, $replies, '&nbsp;&nbsp;', $admin_view);
186  $show_replies = (count($replies) > 0) ? true : false;
187  // Start edit by voltan
188  $this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid') , 'id' => $tree[$comment_id]['obj']->getVar('com_id') , 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid') , 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid') , 'title' => $title , 'text' => $text , 'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm') , 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm') , 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid'), $tree[$comment_id]['obj']->getVar('com_user'), $tree[$comment_id]['obj']->getVar('com_url')) , 'replies' => $replies , 'show_replies' => $show_replies));
189  // End edit by voltan
190  }
191 
204  function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '')
205  {
206  if ($depth > 0) {
207  if (false != $this->_useIcons) {
208  $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')) . '&nbsp;' . $thread[$key]['obj']->getVar('com_title');
209  } else {
210  $title = $thread[$key]['obj']->getVar('com_title');
211  }
212  $title = (false != $admin_view) ? $title . ' ' . $this->_statusText[$thread[$key]['obj']->getVar('com_status')] : $title;
213  // Start edit by voltan
214  $replies[] = array('id' => $key , 'prefix' => $current_prefix , 'date_posted' => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm') , 'title' => $title , 'root_id' => $thread[$key]['obj']->getVar('com_rootid') , 'status' => $this->_statusText[$thread[$key]['obj']->getVar('com_status')] , 'poster' => $this->_getPosterName($thread[$key]['obj']->getVar('com_uid'), $thread[$key]['obj']->getVar('com_user'), $thread[$key]['obj']->getVar('com_url')));
215  // End edit by voltan
216  $current_prefix .= $prefix;
217  }
218  if (isset($thread[$key]['child']) && ! empty($thread[$key]['child'])) {
219  $depth++;
220  foreach ($thread[$key]['child'] as $childkey) {
221  if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
222  // skip this comment if it is not active and continue on processing its child comments instead
223  if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
224  foreach ($thread[$childkey]['child'] as $childchildkey) {
225  $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
226  }
227  }
228  } else {
229  $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix);
230  }
231  }
232  }
233  }
234 
243  function renderNestView($comment_id = 0, $admin_view = false)
244  {
245  include_once $GLOBALS['xoops']->path('class/tree.php');
246  $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
247  $tree =& $xot->getTree();
248  if (false != $this->_useIcons) {
249  $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')) . '&nbsp;' . $tree[$comment_id]['obj']->getVar('com_title');
250  } else {
251  $title = $tree[$comment_id]['obj']->getVar('com_title');
252  }
253  if (false != $admin_view) {
254  $com_email = $tree[$comment_id]['obj']->getVar('com_email');
255  $text = $tree[$comment_id]['obj']->getVar('com_text');
256  $text .= '<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">';
257  $text .= _CM_STATUS . ': ' . $this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')] . '<br />';
258  $text .= 'IP: <span style="font-weight: bold;">' . $tree[$comment_id]['obj']->getVar('com_ip') . '</span>';
259  if(!empty($com_email)) {
260  $text .= '<br />' . _CM_EMAIL . ' :<span style="font-weight: bold;"><a href="mailto:' . $com_email . '" title="' . $com_email . '">' . $com_email . '</a></span>';
261  }
262  $text .= '</div>';
263  } else {
264  // skip this comment if it is not active and continue on processing its child comments instead
265  if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
266  // if there are any child comments, display them as root comments
267  if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
268  foreach ($tree[$comment_id]['child'] as $child_id) {
269  $this->renderNestView($child_id, $admin_view);
270  }
271  }
272  return;
273  } else {
274  $text = $tree[$comment_id]['obj']->getVar('com_text');
275  }
276  }
277  $replies = array();
278  $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view);
279  // Start edit by voltan
280  $this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid') , 'id' => $tree[$comment_id]['obj']->getVar('com_id') , 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid') , 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid') , 'title' => $title , 'text' => $text , 'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm') , 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm') , 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid'), $tree[$comment_id]['obj']->getVar('com_user'), $tree[$comment_id]['obj']->getVar('com_url')) , 'replies' => $replies));
281  // End edit by voltan
282  }
283 
295  function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0)
296  {
297  if ($depth > 0) {
298  if (false != $this->_useIcons) {
299  $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')) . '&nbsp;' . $thread[$key]['obj']->getVar('com_title');
300  } else {
301  $title = $thread[$key]['obj']->getVar('com_title');
302  }
303  $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;">' . $this->_comments[$i]->getVar('com_email') . '</span></div>' : $thread[$key]['obj']->getVar('com_text');
304  // Start edit by voltan
305  $replies[] = array('id' => $key , 'prefix' => $prefix , 'pid' => $thread[$key]['obj']->getVar('com_pid') , 'itemid' => $thread[$key]['obj']->getVar('com_itemid') , 'rootid' => $thread[$key]['obj']->getVar('com_rootid') , 'title' => $title , 'text' => $text , 'date_posted' => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm') , 'date_modified' => formatTimestamp($thread[$key]['obj']->getVar('com_modified'), 'm') , 'poster' => $this->_getPosterArray($thread[$key]['obj']->getVar('com_uid'), $thread[$key]['obj']->getVar('com_user'), $thread[$key]['obj']->getVar('com_url')));
306  // End edit by voltan
307  $prefix = $prefix + 25;
308  }
309  if (isset($thread[$key]['child']) && ! empty($thread[$key]['child'])) {
310  $depth++;
311  foreach ($thread[$key]['child'] as $childkey) {
312  if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
313  // skip this comment if it is not active and continue on processing its child comments instead
314  if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
315  foreach ($thread[$childkey]['child'] as $childchildkey) {
316  $this->_renderNestReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
317  }
318  }
319  } else {
320  $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth);
321  }
322  }
323  }
324  }
325 
333  // Start edit by voltan
334  function _getPosterName($poster_id, $poster_user, $poster_website)
335  {
336  $poster['id'] = intval($poster_id);
337  if ($poster['id'] > 0) {
338  $com_poster =& $this->_memberHandler->getUser($poster_id);
339  if (is_object($com_poster)) {
340  $poster['uname'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $poster['id'] . '">' . $com_poster->getVar('uname') . '</a>';
341 
342  }
343  } elseif ($poster['id'] == 0 && $poster_user != '') {
344  $poster['id'] = 0; // to cope with deleted user accounts
345  if(!empty($poster_website)) {
346  $poster['uname'] = '<a href="' . $poster_website . '">' . $poster_user . '</a>';
347  } else {
348  $poster['uname'] = $poster_user;
349  }
350  } else {
351  $poster['id'] = 0; // to cope with deleted user accounts
352  $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
353  }
354 
355  return $poster;
356  }
357  // End edit by voltan
358 
366  // Start edit by voltan
367  function _getPosterArray($poster_id, $poster_user, $poster_website)
368  {
369  $poster['id'] = intval($poster_id);
370  if ($poster['id'] > 0) {
371  $com_poster =& $this->_memberHandler->getUser($poster['id']);
372  if (is_object($com_poster)) {
373  $poster['uname'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $poster['id'] . '">' . $com_poster->getVar('uname') . '</a>';
374  $poster_rank = $com_poster->rank();
375  $poster['rank_image'] = ($poster_rank['image'] != '') ? $poster_rank['image'] : 'blank.gif';
376  $poster['rank_title'] = $poster_rank['title'];
377  $poster['avatar'] = $com_poster->getVar('user_avatar');
378  $poster['regdate'] = formatTimestamp($com_poster->getVar('user_regdate'), 's');
379  $poster['from'] = $com_poster->getVar('user_from');
380  $poster['postnum'] = $com_poster->getVar('posts');
381  $poster['status'] = $com_poster->isOnline() ? _CM_ONLINE : '';
382  }
383  } elseif ($poster['id'] == 0 && $poster_user != '') {
384  if(!empty($poster_website)) {
385  $poster['uname'] = '<a href="' . $poster_website . '">' . $poster_user . '</a>';
386  } else {
387  $poster['uname'] = $poster_user;
388  }
389  $poster['id'] = 0; // to cope with deleted user accounts
390  $poster['rank_title'] = '';
391  $poster['avatar'] = 'blank.gif';
392  $poster['regdate'] = '';
393  $poster['from'] = '';
394  $poster['postnum'] = 0;
395  $poster['status'] = '';
396  } else {
397  $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
398  $poster['id'] = 0; // to cope with deleted user accounts
399  $poster['rank_title'] = '';
400  $poster['avatar'] = 'blank.gif';
401  $poster['regdate'] = '';
402  $poster['from'] = '';
403  $poster['postnum'] = 0;
404  $poster['status'] = '';
405  }
406 
407  return $poster;
408  }
409  // End edit by voltan
410 
418  function _getTitleIcon($icon_image)
419  {
420  $icon_image = htmlspecialchars(trim($icon_image));
421  if ($icon_image != '') {
422  if (false != $this->_doIconCheck) {
423  if (!file_exists($GLOBALS['xoops']->path('images/subject/' . $icon_image))) {
424  return '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
425  } else {
426  return '<img src="' . XOOPS_URL . '/images/subject/' . $icon_image . '" alt="" />';
427  }
428  } else {
429  return '<img src="' . XOOPS_URL . '/images/subject/' . $icon_image . '" alt="" />';
430  }
431  }
432  return '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
433  }
434 }
435 
436 ?>