21 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
37 var $_comments = null;
38 var $_useIcons =
true;
39 var $_doIconCheck =
false;
53 function XoopsCommentRenderer(&
$tpl, $use_icons =
true, $do_iconcheck =
false)
56 $this->_useIcons = $use_icons;
57 $this->_doIconCheck = $do_iconcheck;
70 function &instance(&
$tpl, $use_icons =
true, $do_iconcheck =
false)
73 if (!isset($instance)) {
74 $instance =
new XoopsCommentRenderer(
$tpl, $use_icons, $do_iconcheck);
84 function setComments(&$comments_arr)
86 if (isset($this->_comments)) {
87 unset($this->_comments);
89 $this->_comments =& $comments_arr;
97 function renderFlatView($admin_view =
false)
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')) .
' ' . $this->_comments[
$i]->getVar(
'com_title');
104 $title = $this->_comments[
$i]->getVar(
'com_title');
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) {
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>';
123 $text = $this->_comments[
$i]->getVar(
'com_text');
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));
140 function renderThreadView($comment_id = 0, $admin_view =
false, $show_nav =
true)
142 include_once
$GLOBALS[
'xoops']->path(
'class/tree.php');
144 $xot =
new XoopsObjectTree($this->_comments,
'com_id',
'com_pid',
'com_rootid');
145 $tree =& $xot->getTree();
147 if (
false != $this->_useIcons) {
148 $title = $this->_getTitleIcon($tree[$comment_id][
'obj']->getVar(
'com_icon')) .
' ' . $tree[$comment_id][
'obj']->getVar(
'com_title');
150 $title = $tree[$comment_id][
'obj']->getVar(
'com_title');
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);
157 $this->_tpl->assign(
'show_threadnav',
false);
159 if (
false != $admin_view) {
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>';
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);
181 $text = $tree[$comment_id][
'obj']->getVar(
'com_text');
185 $this->_renderThreadReplies($tree, $comment_id, $replies,
' ', $admin_view);
186 $show_replies = (count($replies) > 0) ?
true :
false;
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));
204 function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix =
'')
207 if (
false != $this->_useIcons) {
208 $title = $this->_getTitleIcon($thread[$key][
'obj']->getVar(
'com_icon')) .
' ' . $thread[$key][
'obj']->getVar(
'com_title');
210 $title = $thread[$key][
'obj']->getVar(
'com_title');
212 $title = (
false != $admin_view) ?
$title .
' ' . $this->_statusText[$thread[$key][
'obj']->getVar(
'com_status')] :
$title;
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')));
216 $current_prefix .= $prefix;
218 if (isset($thread[$key][
'child']) && ! empty($thread[$key][
'child'])) {
220 foreach ($thread[$key][
'child'] as $childkey) {
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);
229 $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix);
243 function renderNestView($comment_id = 0, $admin_view =
false)
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')) .
' ' . $tree[$comment_id][
'obj']->getVar(
'com_title');
251 $title = $tree[$comment_id][
'obj']->getVar(
'com_title');
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>';
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);
274 $text = $tree[$comment_id][
'obj']->getVar(
'com_text');
278 $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view);
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));
295 function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0)
298 if (
false != $this->_useIcons) {
299 $title = $this->_getTitleIcon($thread[$key][
'obj']->getVar(
'com_icon')) .
' ' . $thread[$key][
'obj']->getVar(
'com_title');
301 $title = $thread[$key][
'obj']->getVar(
'com_title');
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');
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')));
307 $prefix = $prefix + 25;
309 if (isset($thread[$key][
'child']) && ! empty($thread[$key][
'child'])) {
311 foreach ($thread[$key][
'child'] as $childkey) {
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);
320 $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth);
334 function _getPosterName($poster_id, $poster_user, $poster_website)
336 $poster[
'id'] = intval($poster_id);
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>';
343 } elseif (
$poster[
'id'] == 0 && $poster_user !=
'') {
345 if(!empty($poster_website)) {
346 $poster[
'uname'] =
'<a href="' . $poster_website .
'">' . $poster_user .
'</a>';
348 $poster[
'uname'] = $poster_user;
367 function _getPosterArray($poster_id, $poster_user, $poster_website)
369 $poster[
'id'] = intval($poster_id);
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');
379 $poster[
'from'] = $com_poster->getVar(
'user_from');
380 $poster[
'postnum'] = $com_poster->getVar(
'posts');
381 $poster[
'status'] = $com_poster->isOnline() ?
_CM_ONLINE :
'';
383 } elseif (
$poster[
'id'] == 0 && $poster_user !=
'') {
384 if(!empty($poster_website)) {
385 $poster[
'uname'] =
'<a href="' . $poster_website .
'">' . $poster_user .
'</a>';
387 $poster[
'uname'] = $poster_user;
391 $poster[
'avatar'] =
'blank.gif';
400 $poster[
'avatar'] =
'blank.gif';
418 function _getTitleIcon($icon_image)
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="" />';
426 return '<img src="' . XOOPS_URL .
'/images/subject/' . $icon_image .
'" alt="" />';
429 return '<img src="' . XOOPS_URL .
'/images/subject/' . $icon_image .
'" alt="" />';
432 return '<img src="' . XOOPS_URL .
'/images/icons/no_posticon.gif" alt="" />';