| 1 | <?php |
|---|
| 2 | // $Id: comment_view.php,v 1.2 2005/03/18 12:51:55 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program is distributed in the hope that it will be useful, // |
|---|
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|---|
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|---|
| 21 | // GNU General Public License for more details. // |
|---|
| 22 | // // |
|---|
| 23 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | // Author: Kazumi Ono (AKA onokazu) // |
|---|
| 28 | // URL: http://www.xoops.org/ http://jp.xoops.org/ http://www.myweb.ne.jp/ // |
|---|
| 29 | // Project: The XOOPS Project (http://www.xoops.org/) // |
|---|
| 30 | // ------------------------------------------------------------------------- // |
|---|
| 31 | |
|---|
| 32 | if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) { |
|---|
| 33 | exit(); |
|---|
| 34 | } |
|---|
| 35 | include_once XOOPS_ROOT_PATH.'/include/comment_constants.php'; |
|---|
| 36 | include_once XOOPS_ROOT_PATH.'/modules/system/constants.php'; |
|---|
| 37 | |
|---|
| 38 | if (XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) { |
|---|
| 39 | |
|---|
| 40 | $gperm_handler = & xoops_gethandler( 'groupperm' ); |
|---|
| 41 | $groups = ( $xoopsUser ) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS; |
|---|
| 42 | $xoopsTpl->assign( 'xoops_iscommentadmin', $gperm_handler->checkRight( 'system_admin', XOOPS_SYSTEM_COMMENT, $groups) ); |
|---|
| 43 | |
|---|
| 44 | include_once XOOPS_ROOT_PATH.'/language/'.$xoopsConfig['language'].'/comment.php'; |
|---|
| 45 | $comment_config = $xoopsModule->getInfo('comments'); |
|---|
| 46 | $com_itemid = (trim($comment_config['itemName']) != '' && isset($_GET[$comment_config['itemName']])) ? intval($_GET[$comment_config['itemName']]) : 0; |
|---|
| 47 | |
|---|
| 48 | if ($com_itemid > 0) { |
|---|
| 49 | $com_mode = isset($_GET['com_mode']) ? htmlspecialchars(trim($_GET['com_mode']), ENT_QUOTES) : ''; |
|---|
| 50 | if ($com_mode == '') { |
|---|
| 51 | if (is_object($xoopsUser)) { |
|---|
| 52 | $com_mode = $xoopsUser->getVar('umode'); |
|---|
| 53 | } else { |
|---|
| 54 | $com_mode = $xoopsConfig['com_mode']; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | $xoopsTpl->assign('comment_mode', $com_mode); |
|---|
| 58 | if (!isset($_GET['com_order'])) { |
|---|
| 59 | if (is_object($xoopsUser)) { |
|---|
| 60 | $com_order = $xoopsUser->getVar('uorder'); |
|---|
| 61 | } else { |
|---|
| 62 | $com_order = $xoopsConfig['com_order']; |
|---|
| 63 | } |
|---|
| 64 | } else { |
|---|
| 65 | $com_order = intval($_GET['com_order']); |
|---|
| 66 | } |
|---|
| 67 | if ($com_order != XOOPS_COMMENT_OLD1ST) { |
|---|
| 68 | $xoopsTpl->assign(array('comment_order' => XOOPS_COMMENT_NEW1ST, 'order_other' => XOOPS_COMMENT_OLD1ST)); |
|---|
| 69 | $com_dborder = 'DESC'; |
|---|
| 70 | } else { |
|---|
| 71 | $xoopsTpl->assign(array('comment_order' => XOOPS_COMMENT_OLD1ST, 'order_other' => XOOPS_COMMENT_NEW1ST)); |
|---|
| 72 | $com_dborder = 'ASC'; |
|---|
| 73 | } |
|---|
| 74 | // admins can view all comments and IPs, others can only view approved(active) comments |
|---|
| 75 | if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
|---|
| 76 | $admin_view = true; |
|---|
| 77 | } else { |
|---|
| 78 | $admin_view = false; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | $com_id = isset($_GET['com_id']) ? intval($_GET['com_id']) : 0; |
|---|
| 82 | $com_rootid = isset($_GET['com_rootid']) ? intval($_GET['com_rootid']) : 0; |
|---|
| 83 | $comment_handler =& xoops_gethandler('comment'); |
|---|
| 84 | if ($com_mode == 'flat') { |
|---|
| 85 | $comments =& $comment_handler->getByItemId($xoopsModule->getVar('mid'), $com_itemid, $com_dborder); |
|---|
| 86 | include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php'; |
|---|
| 87 | $renderer =& XoopsCommentRenderer::instance($xoopsTpl); |
|---|
| 88 | $renderer->setComments($comments); |
|---|
| 89 | $renderer->renderFlatView($admin_view); |
|---|
| 90 | } elseif ($com_mode == 'thread') { |
|---|
| 91 | // RMV-FIX... added extraParam stuff here |
|---|
| 92 | $comment_url = $comment_config['pageName'] . '?'; |
|---|
| 93 | if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) { |
|---|
| 94 | $extra_params = ''; |
|---|
| 95 | foreach ($comment_config['extraParams'] as $extra_param) { |
|---|
| 96 | // This page is included in the module hosting page -- param could be from anywhere |
|---|
| 97 | if (isset(${$extra_param})) { |
|---|
| 98 | $extra_params .= $extra_param .'='.${$extra_param}.'&'; |
|---|
| 99 | } elseif (isset($_POST[$extra_param])) { |
|---|
| 100 | $extra_params .= $extra_param .'='.$_POST[$extra_param].'&'; |
|---|
| 101 | } elseif (isset($_GET[$extra_param])) { |
|---|
| 102 | $extra_params .= $extra_param .'='.$_GET[$extra_param].'&'; |
|---|
| 103 | } else { |
|---|
| 104 | $extra_params .= $extra_param .'=&'; |
|---|
| 105 | } |
|---|
| 106 | //$extra_params .= isset(${$extra_param}) ? $extra_param .'='.${$extra_param}.'&' : $extra_param .'=&'; |
|---|
| 107 | } |
|---|
| 108 | $comment_url .= $extra_params; |
|---|
| 109 | } |
|---|
| 110 | $xoopsTpl->assign('comment_url', $comment_url.$comment_config['itemName'].'='.$com_itemid.'&com_mode=thread&com_order='.$com_order); |
|---|
| 111 | if (!empty($com_id) && !empty($com_rootid) && ($com_id != $com_rootid)) { |
|---|
| 112 | // Show specific thread tree |
|---|
| 113 | $comments =& $comment_handler->getThread($com_rootid, $com_id); |
|---|
| 114 | if (false != $comments) { |
|---|
| 115 | include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php'; |
|---|
| 116 | $renderer =& XoopsCommentRenderer::instance($xoopsTpl); |
|---|
| 117 | $renderer->setComments($comments); |
|---|
| 118 | $renderer->renderThreadView($com_id, $admin_view); |
|---|
| 119 | } |
|---|
| 120 | } else { |
|---|
| 121 | // Show all threads |
|---|
| 122 | $top_comments =& $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder); |
|---|
| 123 | $c_count = count($top_comments); |
|---|
| 124 | if ($c_count> 0) { |
|---|
| 125 | for ($i = 0; $i < $c_count; $i++) { |
|---|
| 126 | $comments =& $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id')); |
|---|
| 127 | if (false != $comments) { |
|---|
| 128 | include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php'; |
|---|
| 129 | $renderer =& XoopsCommentRenderer::instance($xoopsTpl); |
|---|
| 130 | $renderer->setComments($comments); |
|---|
| 131 | $renderer->renderThreadView($top_comments[$i]->getVar('com_id'), $admin_view); |
|---|
| 132 | } |
|---|
| 133 | unset($comments); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } else { |
|---|
| 138 | // Show all threads |
|---|
| 139 | $top_comments =& $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder); |
|---|
| 140 | $c_count = count($top_comments); |
|---|
| 141 | if ($c_count> 0) { |
|---|
| 142 | for ($i = 0; $i < $c_count; $i++) { |
|---|
| 143 | $comments =& $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id')); |
|---|
| 144 | include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php'; |
|---|
| 145 | $renderer =& XoopsCommentRenderer::instance($xoopsTpl); |
|---|
| 146 | $renderer->setComments($comments); |
|---|
| 147 | $renderer->renderNestView($top_comments[$i]->getVar('com_id'), $admin_view); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | // assign comment nav bar |
|---|
| 153 | $navbar = ' |
|---|
| 154 | <form method="get" action="'.$comment_config['pageName'].'"> |
|---|
| 155 | <table width="95%" class="outer" cellspacing="1"> |
|---|
| 156 | <tr> |
|---|
| 157 | <td class="even" align="center"><select name="com_mode"><option value="flat"'; |
|---|
| 158 | if ($com_mode == 'flat') { |
|---|
| 159 | $navbar .= ' selected="selected"'; |
|---|
| 160 | } |
|---|
| 161 | $navbar .= '>'._FLAT.'</option><option value="thread"'; |
|---|
| 162 | if ($com_mode == 'thread' || $com_mode == '') { |
|---|
| 163 | $navbar .= ' selected="selected"'; |
|---|
| 164 | } |
|---|
| 165 | $navbar .= '>'. _THREADED .'</option><option value="nest"'; |
|---|
| 166 | if ($com_mode == 'nest') { |
|---|
| 167 | $navbar .= ' selected="selected"'; |
|---|
| 168 | } |
|---|
| 169 | $navbar .= '>'. _NESTED .'</option></select> <select name="com_order"><option value="'.XOOPS_COMMENT_OLD1ST.'"'; |
|---|
| 170 | if ($com_order == XOOPS_COMMENT_OLD1ST) { |
|---|
| 171 | $navbar .= ' selected="selected"'; |
|---|
| 172 | } |
|---|
| 173 | $navbar .= '>'. _OLDESTFIRST .'</option><option value="'.XOOPS_COMMENT_NEW1ST.'"'; |
|---|
| 174 | if ($com_order == XOOPS_COMMENT_NEW1ST) { |
|---|
| 175 | $navbar .= ' selected="selected"'; |
|---|
| 176 | } |
|---|
| 177 | unset($postcomment_link); |
|---|
| 178 | $navbar .= '>'. _NEWESTFIRST .'</option></select><input type="hidden" name="'.$comment_config['itemName'].'" value="'.$com_itemid.'" /> <input type="submit" value="'. _CM_REFRESH .'" class="formButton" />'; |
|---|
| 179 | if (!empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser)) { |
|---|
| 180 | $postcomment_link = 'comment_new.php?com_itemid='.$com_itemid.'&com_order='.$com_order.'&com_mode='.$com_mode; |
|---|
| 181 | |
|---|
| 182 | $xoopsTpl->assign('anon_canpost', true); |
|---|
| 183 | } |
|---|
| 184 | $link_extra = ''; |
|---|
| 185 | if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) { |
|---|
| 186 | foreach ($comment_config['extraParams'] as $extra_param) { |
|---|
| 187 | if (isset(${$extra_param})) { |
|---|
| 188 | $link_extra .= '&'.$extra_param.'='.${$extra_param}; |
|---|
| 189 | $hidden_value = htmlspecialchars(${$extra_param}, ENT_QUOTES); |
|---|
| 190 | $extra_param_val = ${$extra_param}; |
|---|
| 191 | } elseif (isset($_POST[$extra_param])) { |
|---|
| 192 | $extra_param_val = $_POST[$extra_param]; |
|---|
| 193 | } elseif (isset($_GET[$extra_param])) { |
|---|
| 194 | $extra_param_val = $_GET[$extra_param]; |
|---|
| 195 | } |
|---|
| 196 | if (isset($extra_param_val)) { |
|---|
| 197 | $link_extra .= '&'.$extra_param.'='.$extra_param_val; |
|---|
| 198 | $hidden_value = htmlspecialchars($extra_param_val, ENT_QUOTES); |
|---|
| 199 | $navbar .= '<input type="hidden" name="'.$extra_param.'" value="'.$hidden_value.'" />'; |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | if (isset($postcomment_link)) { |
|---|
| 204 | $navbar .= ' <input type="button" onclick="self.location.href=\''.$postcomment_link.''.$link_extra.'\'" class="formButton" value="'._CM_POSTCOMMENT.'" />'; |
|---|
| 205 | } |
|---|
| 206 | $navbar .= ' |
|---|
| 207 | </td> |
|---|
| 208 | </tr> |
|---|
| 209 | </table> |
|---|
| 210 | </form>'; |
|---|
| 211 | $xoopsTpl->assign(array('commentsnav' => $navbar, 'editcomment_link' => 'comment_edit.php?com_itemid='.$com_itemid.'&com_order='.$com_order.'&com_mode='.$com_mode.''.$link_extra, 'deletecomment_link' => 'comment_delete.php?com_itemid='.$com_itemid.'&com_order='.$com_order.'&com_mode='.$com_mode.''.$link_extra, 'replycomment_link' => 'comment_reply.php?com_itemid='.$com_itemid.'&com_order='.$com_order.'&com_mode='.$com_mode.''.$link_extra)); |
|---|
| 212 | |
|---|
| 213 | // assign some lang variables |
|---|
| 214 | $xoopsTpl->assign(array('lang_from' => _CM_FROM, 'lang_joined' => _CM_JOINED, 'lang_posts' => _CM_POSTS, 'lang_poster' => _CM_POSTER, 'lang_thread' => _CM_THREAD, 'lang_edit' => _EDIT, 'lang_delete' => _DELETE, 'lang_reply' => _REPLY, 'lang_subject' => _CM_REPLIES, 'lang_posted' => _CM_POSTED, 'lang_updated' => _CM_UPDATED, 'lang_notice' => _CM_NOTICE)); |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | ?> |
|---|