1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31: 32: 33: 34: 35: 36: 37: 38: 39:
40: class XoopsCommentRenderer {
41:
42: 43: 44:
45: var $_tpl;
46: var $_comments = null;
47: var $_useIcons = true;
48: var $_doIconCheck = false;
49: var $_memberHandler;
50: var $_statusText;
51:
52:
53: 54: 55: 56: 57: 58: 59:
60: function XoopsCommentRenderer(&$tpl, $use_icons = true, $do_iconcheck = false)
61: {
62: $this->_tpl =& $tpl;
63: $this->_useIcons = $use_icons;
64: $this->_doIconCheck = $do_iconcheck;
65: $this->_memberHandler =& xoops_gethandler('member');
66: $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>');
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76:
77: function &instance(&$tpl, $use_icons = true, $do_iconcheck = false)
78: {
79: static $instance;
80: if (!isset($instance)) {
81: $instance = new XoopsCommentRenderer($tpl, $use_icons, $do_iconcheck);
82: }
83: return $instance;
84: }
85:
86: 87: 88: 89: 90:
91: function setComments(&$comments_arr)
92: {
93: if (isset($this->_comments)) {
94: unset($this->_comments);
95: }
96: $this->_comments =& $comments_arr;
97: }
98:
99: 100: 101: 102: 103:
104: function renderFlatView($admin_view = false)
105: {
106: $count = count($this->_comments);
107: for ($i = 0; $i < $count; $i++) {
108: if (false != $this->_useIcons) {
109: $title = $this->_getTitleIcon($this->_comments[$i]->getVar('com_icon')).' '.$this->_comments[$i]->getVar('com_title');
110: } else {
111: $title = $this->_comments[$i]->getVar('com_title');
112: }
113: $poster = $this->_getPosterArray($this->_comments[$i]->getVar('com_uid'));
114: if (false != $admin_view) {
115: $text = $this->_comments[$i]->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$this->_comments[$i]->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$this->_comments[$i]->getVar('com_ip').'</span></div>';
116: } else {
117:
118: if (XOOPS_COMMENT_ACTIVE != $this->_comments[$i]->getVar('com_status')) {
119: continue;
120: } else {
121: $text = $this->_comments[$i]->getVar('com_text');
122: }
123: }
124: $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));
125: }
126: }
127:
128: 129: 130: 131: 132: 133: 134: 135: 136:
137: function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true)
138: {
139: include_once XOOPS_ROOT_PATH.'/class/tree.php';
140:
141: $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
142: $tree =& $xot->getTree();
143:
144: if (false != $this->_useIcons) {
145: $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).' '.$tree[$comment_id]['obj']->getVar('com_title');
146: } else {
147: $title = $tree[$comment_id]['obj']->getVar('com_title');
148: }
149: if (false != $show_nav && $tree[$comment_id]['obj']->getVar('com_pid') != 0) {
150: $this->_tpl->assign('lang_top', _CM_TOP);
151: $this->_tpl->assign('lang_parent', _CM_PARENT);
152: $this->_tpl->assign('show_threadnav', true);
153: } else {
154: $this->_tpl->assign('show_threadnav', false);
155: }
156: if (false != $admin_view) {
157:
158: $text = $tree[$comment_id]['obj']->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$tree[$comment_id]['obj']->getVar('com_ip').'</span></div>';
159: } else {
160:
161: if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
162:
163: if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
164: foreach ($tree[$comment_id]['child'] as $child_id) {
165: $this->renderThreadView($child_id, $admin_view, false);
166: }
167: }
168: return;
169: } else {
170: $text = $tree[$comment_id]['obj']->getVar('com_text');
171: }
172: }
173: $replies = array();
174: $this->_renderThreadReplies($tree, $comment_id, $replies, ' ', $admin_view);
175: $show_replies = (count($replies) > 0) ? true : false;
176: $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')), 'replies' => $replies, 'show_replies' => $show_replies));
177: }
178:
179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191:
192: function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '')
193: {
194: if ($depth > 0) {
195: if (false != $this->_useIcons) {
196: $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).' '.$thread[$key]['obj']->getVar('com_title');
197: } else {
198: $title = $thread[$key]['obj']->getVar('com_title');
199: }
200: $title = (false != $admin_view) ? $title.' '.$this->_statusText[$thread[$key]['obj']->getVar('com_status')] : $title;
201: $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')));
202: $current_prefix .= $prefix;
203: }
204: if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
205: $depth++;
206: foreach ($thread[$key]['child'] as $childkey) {
207: if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
208:
209: if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
210: foreach ($thread[$childkey]['child'] as $childchildkey) {
211: $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
212: }
213: }
214: } else {
215: $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix);
216: }
217: }
218: }
219: }
220:
221: 222: 223: 224: 225: 226: 227: 228:
229: function renderNestView($comment_id = 0, $admin_view = false)
230: {
231: include_once XOOPS_ROOT_PATH.'/class/tree.php';
232: $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
233: $tree =& $xot->getTree();
234: if (false != $this->_useIcons) {
235: $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).' '.$tree[$comment_id]['obj']->getVar('com_title');
236: } else {
237: $title = $tree[$comment_id]['obj']->getVar('com_title');
238: }
239: if (false != $admin_view) {
240: $text = $tree[$comment_id]['obj']->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$tree[$comment_id]['obj']->getVar('com_ip').'</span></div>';
241: } else {
242:
243: if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
244:
245: if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
246: foreach ($tree[$comment_id]['child'] as $child_id) {
247: $this->renderNestView($child_id, $admin_view);
248: }
249: }
250: return;
251: } else {
252: $text = $tree[$comment_id]['obj']->getVar('com_text');
253: }
254: }
255: $replies = array();
256: $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view);
257: $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')), 'replies' => $replies));
258: }
259:
260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271:
272: function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0)
273: {
274: if ($depth > 0) {
275: if (false != $this->_useIcons) {
276: $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).' '.$thread[$key]['obj']->getVar('com_title');
277: } else {
278: $title = $thread[$key]['obj']->getVar('com_title');
279: }
280: $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></div>' : $thread[$key]['obj']->getVar('com_text');
281: $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')));
282:
283: $prefix = $prefix + 25;
284: }
285: if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
286: $depth++;
287: foreach ($thread[$key]['child'] as $childkey) {
288: if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
289:
290: if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
291: foreach ($thread[$childkey]['child'] as $childchildkey) {
292: $this->_renderNestReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
293: }
294: }
295: } else {
296: $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth);
297: }
298: }
299: }
300: }
301:
302:
303: 304: 305: 306: 307: 308: 309: 310:
311: function _getPosterName($poster_id)
312: {
313: $poster['id'] = intval($poster_id);
314: if ($poster['id'] > 0) {
315: $com_poster =& $this->_memberHandler->getUser($poster_id);
316: if (is_object($com_poster)) {
317: $poster['uname'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster['id'].'">'.$com_poster->getVar('uname').'</a>';
318: return $poster;
319: }
320: }
321: $poster['id'] = 0;
322: $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
323: return $poster;
324: }
325:
326: 327: 328: 329: 330: 331: 332: 333:
334: function _getPosterArray($poster_id)
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: $poster_rank = $com_poster->rank();
342: $poster['rank_image'] = ($poster_rank['image'] != '') ? $poster_rank['image'] : 'blank.gif';
343: $poster['rank_title'] = $poster_rank['title'];
344: $poster['avatar'] = $com_poster->getVar('user_avatar');
345: $poster['regdate'] = formatTimestamp($com_poster->getVar('user_regdate'), 's');
346: $poster['from'] = $com_poster->getVar('user_from');
347: $poster['postnum'] = $com_poster->getVar('posts');
348: $poster['status'] = $com_poster->isOnline() ? _CM_ONLINE : '';
349: return $poster;
350: }
351: }
352: $poster['id'] = 0;
353: $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
354: $poster['rank_title'] = '';
355: $poster['avatar'] = 'blank.gif';
356: $poster['regdate'] = '';
357: $poster['from'] = '';
358: $poster['postnum'] = 0;
359: $poster['status'] = '';
360: return $poster;
361: }
362:
363: 364: 365: 366: 367: 368: 369: 370:
371: function _getTitleIcon($icon_image)
372: {
373: $icon_image = trim($icon_image);
374: if ($icon_image != '') {
375: $icon_image = htmlspecialchars($icon_image);
376: if (false != $this->_doIconCheck) {
377: if (!file_exists(XOOPS_URL.'/images/subject/'.$icon_image)) {
378: return '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
379: } else {
380: return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />';
381: }
382: } else {
383: return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />';
384: }
385: }
386: return '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
387: }
388: }
389: ?>