mambax7 /
newbb5
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 6 | // <http://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: phppp (D.J., [email protected]) // |
||
| 28 | // URL: http://xoops.org // |
||
| 29 | // Project: Article Project // |
||
| 30 | // ------------------------------------------------------------------------ // |
||
| 31 | |||
| 32 | use Xmf\Request; |
||
| 33 | |||
| 34 | include_once __DIR__ . '/header.php'; |
||
| 35 | |||
| 36 | $forum = Request::getInt('forum', 0, 'GET'); |
||
| 37 | $topic_id = Request::getInt('topic_id', 0, 'GET'); |
||
| 38 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
| 39 | $order = Request::getInt('order', 0, 'GET'); |
||
| 40 | $start = Request::getInt('start', 0, 'GET'); |
||
| 41 | |||
| 42 | View Code Duplication | if (!$topic_id && !$post_id) { |
|
| 43 | $redirect = empty($forum) ? 'index.php' : "viewforum.php?forum={$forum}"; |
||
| 44 | redirect_header($redirect, 2, _MD_NEWBB_ERRORTOPIC); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** @var NewbbForumHandler $forumHandler */ |
||
| 48 | $forumHandler = xoops_getModuleHandler('forum', 'newbb'); |
||
| 49 | /** @var NewbbTopicHandler $topicHandler */ |
||
| 50 | $topicHandler = xoops_getModuleHandler('topic', 'newbb'); |
||
| 51 | /** @var NewbbPostHandler $postHandler */ |
||
| 52 | $postHandler = xoops_getModuleHandler('post', 'newbb'); |
||
| 53 | |||
| 54 | if (!$pid = $post_id) { |
||
| 55 | $pid = $topicHandler->getTopPostId($topic_id); |
||
| 56 | } |
||
| 57 | $post_parent_obj = $postHandler->get($pid); |
||
| 58 | $topic_id = $post_parent_obj->getVar('topic_id'); |
||
| 59 | $forum = $post_parent_obj->getVar('forum_id'); |
||
| 60 | $post_obj = $postHandler->create(); |
||
| 61 | $post_obj->setVar('pid', $pid); |
||
| 62 | $post_obj->setVar('topic_id', $topic_id); |
||
| 63 | $post_obj->setVar('forum_id', $forum); |
||
| 64 | |||
| 65 | $forum_obj = $forumHandler->get($forum); |
||
| 66 | if (!$forumHandler->getPermission($forum_obj)) { |
||
| 67 | redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS); |
||
| 68 | } |
||
| 69 | |||
| 70 | $topic_obj = $topicHandler->get($topic_id); |
||
| 71 | $topic_status = $topic_obj->getVar('topic_status'); |
||
| 72 | View Code Duplication | if (!$topicHandler->getPermission($forum_obj, $topic_status, 'reply')) { |
|
| 73 | /* |
||
| 74 | * Build the page query |
||
| 75 | */ |
||
| 76 | $query_vars = ['topic_id', 'post_id', 'status', 'order', 'mode', 'viewmode']; |
||
| 77 | $query_array = []; |
||
| 78 | foreach ($query_vars as $var) { |
||
| 79 | if (Request::getString($var, '', 'GET')) { |
||
| 80 | $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | $page_query = htmlspecialchars(implode('&', array_values($query_array))); |
||
| 84 | unset($query_array); |
||
| 85 | |||
| 86 | redirect_header("viewtopic.php?{$page_query}", 2, _MD_NEWBB_NORIGHTTOREPLY); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) { |
||
| 90 | /** @var NewbbOnlineHandler $onlineHandler */ |
||
| 91 | $onlineHandler = xoops_getModuleHandler('online', 'newbb'); |
||
| 92 | $onlineHandler->init($forum_obj); |
||
| 93 | } |
||
| 94 | |||
| 95 | $xoopsOption['template_main'] = 'newbb_edit_post.tpl'; |
||
| 96 | $GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0; |
||
| 97 | // irmtfan remove and move to footer.php |
||
| 98 | //$xoopsOption['xoops_module_header']= $xoops_module_header; |
||
| 99 | // irmtfan include header.php after defining $xoopsOption['template_main'] |
||
| 100 | include_once $GLOBALS['xoops']->path('header.php'); |
||
| 101 | //$xoopsTpl->assign('xoops_module_header', $xoops_module_header); |
||
| 102 | |||
| 103 | /* |
||
| 104 | $xoopsTpl->assign('lang_forum_index', sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES))); |
||
| 105 | |||
| 106 | $categoryHandler = xoops_getModuleHandler("category"); |
||
| 107 | $category_obj = $categoryHandler->get($forum_obj->getVar("cat_id"), array("cat_title")); |
||
| 108 | $xoopsTpl->assign('category', array("id" => $forum_obj->getVar("cat_id"), "title" => $category_obj->getVar('cat_title'))); |
||
| 109 | |||
| 110 | $form_title = _MD_NEWBB_REPLY.": <a href=\"viewtopic.php?topic_id={$topic_id}\">".$topic_obj->getVar("topic_title"); |
||
| 111 | $xoopsTpl->assign("form_title", $form_title); |
||
| 112 | */ |
||
| 113 | |||
| 114 | View Code Duplication | if ((2 == $GLOBALS['xoopsModuleConfig']['disc_show']) || (3 == $GLOBALS['xoopsModuleConfig']['disc_show'])) { |
|
| 115 | $xoopsTpl->assign('disclaimer', $GLOBALS['xoopsModuleConfig']['disclaimer']); |
||
| 116 | } |
||
| 117 | |||
| 118 | $xoopsTpl->assign('parentforum', $forumHandler->getParents($forum_obj)); |
||
| 119 | |||
| 120 | $xoopsTpl->assign([ |
||
| 121 | 'forum_id' => $forum_obj->getVar('forum_id'), |
||
| 122 | 'forum_name' => $forum_obj->getVar('forum_name') |
||
| 123 | ]); |
||
| 124 | |||
| 125 | if ($post_parent_obj->getVar('uid')) { |
||
| 126 | $r_name = newbb_getUnameFromId($post_parent_obj->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']); |
||
| 127 | } else { |
||
| 128 | $poster_name = $post_parent_obj->getVar('poster_name'); |
||
| 129 | $r_name = empty($poster_name) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name; |
||
| 130 | } |
||
| 131 | |||
| 132 | $r_subject = $post_parent_obj->getVar('subject', 'E'); |
||
| 133 | |||
| 134 | $subject = $r_subject; |
||
| 135 | if (!preg_match('/^(Re|' . _MD_NEWBB_RE . '):/i', $r_subject)) { |
||
| 136 | $subject = _MD_NEWBB_RE . ': ' . $r_subject; |
||
| 137 | } |
||
| 138 | |||
| 139 | $q_message = $post_parent_obj->getVar('post_text', 'e'); |
||
| 140 | if ((!$GLOBALS['xoopsModuleConfig']['enable_karma'] || !$post_parent_obj->getVar('post_karma')) |
||
| 141 | && (!$GLOBALS['xoopsModuleConfig']['allow_require_reply'] || !$post_parent_obj->getVar('require_reply'))) { |
||
| 142 | if (1 === Request::getInt('quotedac', 0, 'GET')) { |
||
| 143 | $message = "[quote]\n"; |
||
| 144 | $message .= sprintf(_MD_NEWBB_USERWROTE, $r_name); |
||
| 145 | $message .= "\n" . $q_message . '[/quote]'; |
||
| 146 | $hidden = ''; |
||
| 147 | } else { |
||
| 148 | $hidden = "[quote]\n"; |
||
| 149 | $hidden .= sprintf(_MD_NEWBB_USERWROTE, $r_name); |
||
| 150 | $hidden .= "\n" . $q_message . '[/quote]'; |
||
| 151 | $message = ''; |
||
| 152 | } |
||
| 153 | } else { |
||
| 154 | $hidden = ''; |
||
| 155 | $message = ''; |
||
| 156 | } |
||
| 157 | |||
| 158 | $isreply = 1; |
||
| 159 | $istopic = 0; |
||
| 160 | $dohtml = 1; |
||
| 161 | $dosmiley = 1; |
||
| 162 | $doxcode = 1; |
||
| 163 | $dobr = 1; |
||
| 164 | $icon = ''; |
||
| 165 | $attachsig = (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->getVar('attachsig')) ? 1 : 0; |
||
| 166 | $post_karma = 0; |
||
| 167 | $require_reply = 0; |
||
| 168 | |||
| 169 | include __DIR__ . '/include/form.post.php'; |
||
| 170 | |||
| 171 | /** @var \NewbbKarmaHandler $karmaHandler */ |
||
| 172 | $karmaHandler = xoops_getModuleHandler('karma', 'newbb'); |
||
| 173 | $user_karma = $karmaHandler->getUserKarma(); |
||
| 174 | |||
| 175 | $posts_context = []; |
||
| 176 | //$posts_context_obj = $postHandler->getByLimit($topic_id, 5); //mb |
||
| 177 | $posts_context_obj = $postHandler->getByLimit(5, 0, null, null, true, $topic_id, 1); |
||
| 178 | /** @var \NewbbPost $post_context_obj */ |
||
| 179 | View Code Duplication | foreach ($posts_context_obj as $post_context_obj) { |
|
|
0 ignored issues
–
show
|
|||
| 180 | // Sorry, in order to save queries, we have to hide the non-open post_text even if you have replied or have adequate karma, even an admin. |
||
| 181 | if ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $post_context_obj->getVar('post_karma') > 0) { |
||
| 182 | $p_message = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, '***', $post_context_obj->getVar('post_karma')) . '</div>'; |
||
| 183 | } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $post_context_obj->getVar('require_reply')) { |
||
| 184 | $p_message = _MD_NEWBB_REPLY_REQUIREMENT; |
||
| 185 | } else { |
||
| 186 | $p_message = $post_context_obj->getVar('post_text'); |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($post_context_obj->getVar('uid')) { |
||
| 190 | $p_name = newbb_getUnameFromId($post_context_obj->getVar('uid'), $GLOBALS['xoopsModuleConfig']['show_realname']); |
||
| 191 | } else { |
||
| 192 | $poster_name = $post_context_obj->getVar('poster_name'); |
||
| 193 | $p_name = empty($poster_name) ? htmlspecialchars($GLOBALS['xoopsConfig']['anonymous']) : $poster_name; |
||
| 194 | } |
||
| 195 | $p_date = formatTimestamp($post_context_obj->getVar('post_time')); |
||
| 196 | $p_subject = $post_context_obj->getVar('subject'); |
||
| 197 | |||
| 198 | $posts_context[] = [ |
||
| 199 | 'subject' => $p_subject, |
||
| 200 | 'meta' => _MD_NEWBB_BY . ' ' . $p_name . ' ' . _MD_NEWBB_ON . ' ' . $p_date, |
||
| 201 | 'content' => $p_message |
||
| 202 | ]; |
||
| 203 | } |
||
| 204 | $xoopsTpl->assign_by_ref('posts_context', $posts_context); |
||
| 205 | // irmtfan move to footer.php |
||
| 206 | include_once __DIR__ . '/footer.php'; |
||
| 207 | include $GLOBALS['xoops']->path('footer.php'); |
||
| 208 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.