XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
comment_view.php
Go to the documentation of this file.
1 <?php
20 if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
21  die('Restricted access');
22 }
23 
24 include_once $GLOBALS['xoops']->path('include/comment_constants.php');
25 
27  include_once $GLOBALS['xoops']->path('modules/system/constants.php');
28  $gperm_handler =& xoops_gethandler('groupperm');
29  $groups = ($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
30  $xoopsTpl->assign('xoops_iscommentadmin', $gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_COMMENT, $groups));
31 
32  xoops_loadLanguage('comment');
33 
34  $comment_config = $xoopsModule->getInfo('comments');
35  $com_itemid = (trim($comment_config['itemName']) != '' && isset($_GET[$comment_config['itemName']])) ? intval($_GET[$comment_config['itemName']]) : 0;
36  if ($com_itemid > 0) {
37  $com_mode = isset($_GET['com_mode']) ? htmlspecialchars(trim($_GET['com_mode']), ENT_QUOTES) : '';
38  if ($com_mode == '') {
39  if (is_object($xoopsUser)) {
40  $com_mode = $xoopsUser->getVar('umode');
41  }
42  $com_mode = empty($com_mode) ? $xoopsConfig['com_mode'] : $com_mode;
43  }
44  $xoopsTpl->assign('comment_mode', $com_mode);
45  if (!isset($_GET['com_order'])) {
46  if (is_object($xoopsUser)) {
47  $com_order = $xoopsUser->getVar('uorder');
48  } else {
49  $com_order = $xoopsConfig['com_order'];
50  }
51  } else {
52  $com_order = intval($_GET['com_order']);
53  }
55  $xoopsTpl->assign(array(
56  'comment_order' => XOOPS_COMMENT_NEW1ST ,
57  'order_other' => XOOPS_COMMENT_OLD1ST));
58  $com_dborder = 'DESC';
59  } else {
60  $xoopsTpl->assign(array(
61  'comment_order' => XOOPS_COMMENT_OLD1ST ,
62  'order_other' => XOOPS_COMMENT_NEW1ST));
63  $com_dborder = 'ASC';
64  }
65  // admins can view all comments and IPs, others can only view approved(active) comments
66  if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
67  $admin_view = true;
68  } else {
69  $admin_view = false;
70  }
71 
72  $com_id = isset($_GET['com_id']) ? intval($_GET['com_id']) : 0;
73  $com_rootid = isset($_GET['com_rootid']) ? intval($_GET['com_rootid']) : 0;
74  $comment_handler = & xoops_gethandler('comment');
75  if ($com_mode == 'flat') {
76  $comments = $comment_handler->getByItemId($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
77  include_once $GLOBALS['xoops']->path('class/commentrenderer.php');
79  $renderer->setComments($comments);
80  $renderer->renderFlatView($admin_view);
81  } elseif ($com_mode == 'thread') {
82  // RMV-FIX... added extraParam stuff here
83  $comment_url = $comment_config['pageName'] . '?';
84  if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
85  $extra_params = '';
86  foreach ($comment_config['extraParams'] as $extra_param) {
87  // This page is included in the module hosting page -- param could be from anywhere
88  if (isset(${$extra_param})) {
89  $extra_params .= $extra_param . '=' . ${$extra_param} . '&amp;';
90  } else if (isset($_POST[$extra_param])) {
91  $extra_params .= $extra_param . '=' . $_POST[$extra_param] . '&amp;';
92  } else if (isset($_GET[$extra_param])) {
93  $extra_params .= $extra_param . '=' . $_GET[$extra_param] . '&amp;';
94  } else {
95  $extra_params .= $extra_param . '=&amp;';
96  }
97  //$extra_params .= isset(${$extra_param}) ? $extra_param .'='.${$extra_param}.'&amp;' : $extra_param .'=&amp;';
98  }
99  $comment_url .= $extra_params;
100  }
101  $xoopsTpl->assign('comment_url', $comment_url . $comment_config['itemName'] . '=' . $com_itemid . '&amp;com_mode=thread&amp;com_order=' . $com_order);
102  if (!empty($com_id) && !empty($com_rootid) && ($com_id != $com_rootid)) {
103  // Show specific thread tree
105  if (false != $comments) {
106  include_once $GLOBALS['xoops']->path('class/commentrenderer.php');
108  $renderer->setComments($comments);
109  $renderer->renderThreadView($com_id, $admin_view);
110  }
111  } else {
112  // Show all threads
113  $top_comments = $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
114  $c_count = count($top_comments);
115  if ($c_count > 0) {
116  for($i = 0; $i < $c_count; $i ++) {
117  $comments = $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id'));
118  if (false != $comments) {
119  include_once $GLOBALS['xoops']->path('class/commentrenderer.php');
121  $renderer->setComments($comments);
122  $renderer->renderThreadView($top_comments[$i]->getVar('com_id'), $admin_view);
123  }
124  unset($comments);
125  }
126  }
127  }
128  } else {
129  // Show all threads
130  $top_comments = $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
131  $c_count = count($top_comments);
132  if ($c_count > 0) {
133  for($i = 0; $i < $c_count; $i ++) {
134  $comments = $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id'));
135  include_once $GLOBALS['xoops']->path('class/commentrenderer.php');
137  $renderer->setComments($comments);
138  $renderer->renderNestView($top_comments[$i]->getVar('com_id'), $admin_view);
139  }
140  }
141  }
142 
143  // assign comment nav bar
144  $navbar = '
145 <form method="get" action="' . $comment_config['pageName'] . '">
146 <table width="95%" class="outer" cellspacing="1">
147  <tr>
148  <td class="even" align="center"><select name="com_mode"><option value="flat"';
149  if ($com_mode == 'flat') {
150  $navbar .= ' selected="selected"';
151  }
152  $navbar .= '>' . _FLAT . '</option><option value="thread"';
153  if ($com_mode == 'thread' || $com_mode == '') {
154  $navbar .= ' selected="selected"';
155  }
156  $navbar .= '>' . _THREADED . '</option><option value="nest"';
157  if ($com_mode == 'nest') {
158  $navbar .= ' selected="selected"';
159  }
160  $navbar .= '>' . _NESTED . '</option></select> <select name="com_order"><option value="' . XOOPS_COMMENT_OLD1ST . '"';
161  if ($com_order == XOOPS_COMMENT_OLD1ST) {
162  $navbar .= ' selected="selected"';
163  }
164  $navbar .= '>' . _OLDESTFIRST . '</option><option value="' . XOOPS_COMMENT_NEW1ST . '"';
165  if ($com_order == XOOPS_COMMENT_NEW1ST) {
166  $navbar .= ' selected="selected"';
167  }
168  unset($postcomment_link);
169  $navbar .= '>' . _NEWESTFIRST . '</option></select><input type="hidden" name="' . $comment_config['itemName'] . '" value="' . $com_itemid . '" /> <input type="submit" value="' . _CM_REFRESH . '" class="formButton" />';
170  if (! empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser)) {
171  $postcomment_link = 'comment_new.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode;
172 
173  $xoopsTpl->assign('anon_canpost', true);
174  }
175  $link_extra = '';
176  if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
177  foreach ($comment_config['extraParams'] as $extra_param) {
178  if (isset(${$extra_param})) {
179  $link_extra .= '&amp;' . $extra_param . '=' . ${$extra_param};
180  $hidden_value = htmlspecialchars(${$extra_param}, ENT_QUOTES);
181  $extra_param_val = ${$extra_param};
182  } else if (isset($_POST[$extra_param])) {
183  $extra_param_val = $_POST[$extra_param];
184  } else if (isset($_GET[$extra_param])) {
185  $extra_param_val = $_GET[$extra_param];
186  }
187  if (isset($extra_param_val)) {
188  $link_extra .= '&amp;' . $extra_param . '=' . $extra_param_val;
189  $hidden_value = htmlspecialchars($extra_param_val, ENT_QUOTES);
190  $navbar .= '<input type="hidden" name="' . $extra_param . '" value="' . $hidden_value . '" />';
191  }
192  }
193  }
194  if (isset($postcomment_link)) {
195  $navbar .= '&nbsp;<input type="button" onclick="self.location.href=\'' . $postcomment_link . '' . $link_extra . '\'" class="formButton" value="' . _CM_POSTCOMMENT . '" />';
196  }
197  $navbar .= '
198  </td>
199  </tr>
200 </table>
201 </form>';
202 
203  // Start add by voltan
204  if (! empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser)) {
205 
206  xoops_load('XoopsLists');
207  xoops_load('XoopsFormLoader');
208 
209  if(file_exists($GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname') . '/comment_fast.php'))) {
210  include_once $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname') . '/comment_fast.php');
211  }
212  if (isset($com_replytitle)) {
213  $myts =& MyTextSanitizer::getInstance();
214  $com_title = $myts->htmlSpecialChars($com_replytitle);
215  if (!preg_match("/^" . _RE . "/i", $com_title)) {
216  $com_title = _RE . " " . xoops_substr($com_title, 0, 56);
217  }
218  } else {
219  $com_title = '';
220  }
221 
222  // set form
223  $cform = new XoopsThemeForm(_CM_POSTCOMMENT, "commentfastform", 'comment_post.php', 'post', true);
224  $cform->addElement(new XoopsFormElementTray(''));
225  if (isset($xoopsModuleConfig['com_rule'])) {
226  include_once $GLOBALS['xoops']->path('include/comment_constants.php');
227  switch ($xoopsModuleConfig['com_rule']) {
228  case XOOPS_COMMENT_APPROVEALL:
229  $rule_text = _CM_COMAPPROVEALL;
230  break;
231  case XOOPS_COMMENT_APPROVEUSER:
232  $rule_text = _CM_COMAPPROVEUSER;
233  break;
234  case XOOPS_COMMENT_APPROVEADMIN:
235  default:
236  $rule_text = _CM_COMAPPROVEADMIN;
237  break;
238  }
239  $cform->addElement(new XoopsFormLabel(_CM_COMRULES, $rule_text));
240  }
241  $cform->addElement(new XoopsFormText(_CM_TITLE, 'com_title', 50, 255, $com_title), true);
242  if (!$xoopsUser) {
243  $cform->addElement(new XoopsFormText(_CM_USER, 'com_user', 50, 60, ''), true);
244  $cform->addElement(new XoopsFormText(_CM_EMAIL, 'com_email', 50, 60, ''), true);
245  $cform->addElement(new XoopsFormText(_CM_URL, 'com_url', 50, 60, ''), false);
246  }
247  $cform->addElement(new XoopsFormTextArea(_CM_MESSAGE, 'com_text', '', 10, 65), true);
248  if (!$xoopsUser) {
249  $cform->addElement(new XoopsFormCaptcha());
250  }
251 
252  $cform->addElement(new XoopsFormHidden('com_id', 0));
253  $cform->addElement(new XoopsFormHidden('com_pid', 0));
254  $cform->addElement(new XoopsFormHidden('com_rootid', 0));
255  $cform->addElement(new XoopsFormHidden('com_order', 0));
256  $cform->addElement(new XoopsFormHidden('com_itemid', $com_itemid));
257  $cform->addElement(new XoopsFormHidden('com_mode', $com_mode));
258  $cform->addElement(new xoopsFormHidden('dohtml', 0));
259  $cform->addElement(new xoopsFormHidden('dobr', 0));
260  $cform->addElement(new xoopsFormHidden('dosmiley', 0));
261  $cform->addElement(new xoopsFormHidden('doxcode', 0));
262 
263  // add module specific extra params
264  if ('system' != $xoopsModule->getVar('dirname')) {
265  $comment_config = $xoopsModule->getInfo('comments');
266  if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
267  $myts =& MyTextSanitizer::getInstance();
268  foreach ($comment_config['extraParams'] as $extra_param) {
269  // This routine is included from forms accessed via both GET and POST
270  if (isset($_POST[$extra_param])) {
271  $hidden_value = $myts->stripSlashesGPC($_POST[$extra_param]);
272  } else if (isset($_GET[$extra_param])) {
273  $hidden_value = $myts->stripSlashesGPC($_GET[$extra_param]);
274  } else {
275  $hidden_value = '';
276  }
277  $cform->addElement(new XoopsFormHidden($extra_param, $hidden_value));
278  }
279  }
280  }
281 
282  $button_tray = new XoopsFormElementTray('', '&nbsp;');
283  $button_tray->addElement(new XoopsFormButton('', 'com_dopost', _CM_POSTCOMMENT, 'submit'));
284  $cform->addElement($button_tray);
285  $xoopsTpl->assign('commentform', $cform->render());
286  } else {
287  $xoopsTpl->assign('commentform', '');
288  }
289  // End add by voltan
290 
291  $xoopsTpl->assign(array(
292  'commentsnav' => $navbar ,
293  'editcomment_link' => 'comment_edit.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra ,
294  'deletecomment_link' => 'comment_delete.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra ,
295  'replycomment_link' => 'comment_reply.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra));
296 
297  // assign some lang variables
298  $xoopsTpl->assign(array(
299  'lang_from' => _CM_FROM ,
300  'lang_joined' => _CM_JOINED ,
301  'lang_posts' => _CM_POSTS ,
302  'lang_poster' => _CM_POSTER ,
303  'lang_thread' => _CM_THREAD ,
304  'lang_edit' => _EDIT ,
305  'lang_delete' => _DELETE ,
306  'lang_reply' => _REPLY ,
307  'lang_subject' => _CM_REPLIES ,
308  'lang_posted' => _CM_POSTED ,
309  'lang_updated' => _CM_UPDATED ,
310  'lang_notice' => _CM_NOTICE));
311  }
312 }
313 ?>