XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
comment_view.php
1<?php
13
14// Prevent direct access
15if (!defined('XOOPS_ROOT_PATH') || !is_object($xoopsModule)) {
16 exit();
17}
18
19require_once XOOPS_ROOT_PATH.'/include/comment_constants.php';
20
21if (XOOPS_COMMENT_APPROVENONE !== $xoopsModuleConfig['com_rule']) {
22 $gperm_handler = & xoops_gethandler('groupperm');
23 $groups = ($xoopsUser) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
24 $xoopsTpl->assign('xoops_iscommentadmin', $gperm_handler->checkRight('system_admin', LEGACY_SYSTEM_COMMENT, $groups));
25
26 $t_root =& XCube_Root::getSingleton();
27 $t_root->mLanguageManager->loadPageTypeMessageCatalog('comment');
28 $comment_config = $xoopsModule->getInfo('comments');
29 $com_itemid = ('' !== trim($comment_config['itemName']) && isset($_GET[$comment_config['itemName']])) ? (int)$_GET[$comment_config['itemName']] : 0;
30
31 if ($com_itemid > 0) {
32 $com_mode = isset($_GET['com_mode']) ? htmlspecialchars(trim($_GET['com_mode']), ENT_QUOTES) : '';
33 if ('' == $com_mode) {
34 if (is_object($xoopsUser)) {
35 $com_mode = $xoopsUser->getVar('umode');
36 } else {
37 $com_mode = $xoopsConfig['com_mode'];
38 }
39 }
40 $xoopsTpl->assign('comment_mode', $com_mode);
41 if (!isset($_GET['com_order'])) {
42 if (is_object($xoopsUser)) {
43 $com_order = $xoopsUser->getVar('uorder');
44 } else {
45 $com_order = $xoopsConfig['com_order'];
46 }
47 } else {
48 $com_order = (int)$_GET['com_order'];
49 }
50 if (XOOPS_COMMENT_OLD1ST !== $com_order) {
51 $xoopsTpl->assign(['comment_order' => XOOPS_COMMENT_NEW1ST, 'order_other' => XOOPS_COMMENT_OLD1ST]);
52 $com_dborder = 'DESC';
53 } else {
54 $xoopsTpl->assign(['comment_order' => XOOPS_COMMENT_OLD1ST, 'order_other' => XOOPS_COMMENT_NEW1ST]);
55 $com_dborder = 'ASC';
56 }
57 // admins can view all comments and IPs, others can only view approved(active) comments
58 if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
59 $admin_view = true;
60 } else {
61 $admin_view = false;
62 }
63
64 $com_id = isset($_GET['com_id']) ? (int)$_GET['com_id'] : 0;
65 $com_rootid = isset($_GET['com_rootid']) ? (int)$_GET['com_rootid'] : 0;
66 $comment_handler =& xoops_gethandler('comment');
67 if ('flat' == $com_mode) {
68 $comments =& $comment_handler->getByItemId($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
69 include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php';
70 //$renderer =& XoopsCommentRenderer::instance($xoopsTpl);
71 // Non-static : make call dynamic
72 $renderer =& (new XoopsCommentRenderer($tpl))->instance($xoopsTpl);
73 $renderer->setComments($comments);
74 $renderer->renderFlatView($admin_view);
75 } elseif ('thread' == $com_mode) {
76 // RMV-FIX... added extraParam stuff here
77 $comment_url = $comment_config['pageName'] . '?';
78
79 //
80 // Parse extra parameters from the request.
81 //
82 if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
83 foreach ($comment_config['extraParams'] as $extra_key) {
84 // This page is included in the module hosting page -- param could be from anywhere
85 if (isset($GLOBALS[$extra_key])) {
86 $comment_url .= $extra_key .'='. htmlspecialchars($GLOBALS[$extra_key], ENT_NOQUOTES).'&amp;';
87 } elseif (isset($_REQUEST[$extra_key])) {
88 $comment_url .= $extra_key .'='. htmlspecialchars($_REQUEST[$extra_key], ENT_NOQUOTES).'&amp;';
89 } else {
90 $comment_url .= $extra_key .'=&amp;';
91 }
92 }
93 }
94
95 $xoopsTpl->assign('comment_url', $comment_url.$comment_config['itemName'].'='.$com_itemid.'&amp;com_mode=thread&amp;com_order='.$com_order);
96 if (!empty($com_id) && !empty($com_rootid) && ($com_id != $com_rootid)) {
97 // Show specific thread tree
98 $comments =& $comment_handler->getThread($com_rootid, $com_id);
99 if (false !== $comments) {
100 require_once XOOPS_ROOT_PATH.'/class/commentrenderer.php';
101 $renderer =& (new XoopsCommentRenderer($tpl))->instance($xoopsTpl);
102 $renderer->setComments($comments);
103 $renderer->renderThreadView($com_id, $admin_view);
104 }
105 } else {
106 // Show all threads
107 $top_comments =& $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
108 $c_count = is_countable($top_comments) ? count($top_comments) : 0;
109 if ($c_count> 0) {
110 for ($i = 0; $i < $c_count; $i++) {
111 $comments =& $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id'));
112 if (false !== $comments) {
113 require_once XOOPS_ROOT_PATH.'/class/commentrenderer.php';
114 $renderer =& (new XoopsCommentRenderer($tpl))->instance($xoopsTpl);
115 $renderer->setComments($comments);
116 $renderer->renderThreadView($top_comments[$i]->getVar('com_id'), $admin_view);
117 }
118 unset($comments);
119 }
120 }
121 }
122 } else {
123 // Show all threads
124 $top_comments =& $comment_handler->getTopComments($xoopsModule->getVar('mid'), $com_itemid, $com_dborder);
125 $c_count = is_countable($top_comments) ? count($top_comments) : 0;
126 if ($c_count> 0) {
127 for ($i = 0; $i < $c_count; $i++) {
128 $comments =& $comment_handler->getThread($top_comments[$i]->getVar('com_rootid'), $top_comments[$i]->getVar('com_id'));
129 include_once XOOPS_ROOT_PATH.'/class/commentrenderer.php';
130 $renderer =& (new XoopsCommentRenderer($tpl))->instance($xoopsTpl);
131 $renderer->setComments($comments);
132 $renderer->renderNestView($top_comments[$i]->getVar('com_id'), $admin_view);
133 }
134 }
135 }
136
137 $renderSystem =& $t_root->getRenderSystem($t_root->mContext->mBaseRenderSystemName);
138 $renderTarget =& $renderSystem->createRenderTarget('main');
139
140 $renderTarget->setTemplateName('legacy_comment_navi.html');
141 $renderTarget->setAttribute('pageName', $comment_config['pageName']);
142
143 $modeOptions = ['nest' => _NESTED, 'flat' => _FLAT, 'thread' => _THREADED];
144 $renderTarget->setAttribute('modeOptions', $modeOptions);
145 $renderTarget->setAttribute('com_mode', $com_mode);
146
147 $orderOptions = [0 => _OLDESTFIRST, 1 => _NEWESTFIRST];
148 $renderTarget->setAttribute('orderOptions', $orderOptions);
149 $renderTarget->setAttribute('com_order', $com_order);
150
151 $renderTarget->setAttribute('itemName', $comment_config['itemName']);
152 $renderTarget->setAttribute('com_itemid', $com_itemid);
153 $renderTarget->setAttribute('com_anonpost', $xoopsModuleConfig['com_anonpost']);
154
155 $postcomment_link = '';
156 if (!empty($xoopsModuleConfig['com_anonpost']) || is_object($xoopsUser)) {
157 $postcomment_link = 'comment_new.php?com_itemid=' . $com_itemid . '&com_order=' . $com_order . '&com_mode=' . $com_mode;
158 }
159
160 //
161 // Parse extra parameters from the request.
162 // TODO The following lines are *CODE CLONE*
163 // $link_extra is raw data and not sanitized.
164 //
165 $link_extra = '';
166 $fetchParams = [];
167 if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
168 foreach ($comment_config['extraParams'] as $extra_key) {
169 //
170 // We deprecate that a developer depends on the following line.
171 //
172 if (isset($GLOBALS[$extra_key])) {
173 $fetchParams[$extra_key] = $GLOBALS[$extra_key];
174 } elseif (isset($_REQUEST[$extra_key])) {
175 $fetchParams[$extra_key] = xoops_getrequest($extra_key);
176 }
177 }
178
179 //
180 // Composite link_extra
181 //
182 foreach ($fetchParams as $key => $value) {
183 $link_extra .= '&' . $key . '=' . $value;
184 }
185 }
186
187 $renderTarget->setAttribute('extraParams', $fetchParams);
188 $renderTarget->setAttribute('link_extra', $link_extra);
189 $renderTarget->setAttribute('postcomment_link', $postcomment_link);
190
191 $renderSystem->render($renderTarget);
192
193 //
194 // TODO We change raw string data, we must change template for guarding XSS.
195 //
196 $xoopsTpl->assign(
197 ['commentsnav' => $renderTarget->getResult(), 'editcomment_link' => 'comment_edit.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . htmlspecialchars($link_extra, ENT_QUOTES), 'deletecomment_link' => 'comment_delete.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra, 'replycomment_link' => 'comment_reply.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra]
198 );
199
200 // assign some lang variables
201 $xoopsTpl->assign(
202 ['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]
203 );
204 }
205}