mambax7 /
newbb5
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * NewBB 5.0x, the forum module for XOOPS project |
||
| 4 | * |
||
| 5 | * @copyright XOOPS Project (https://xoops.org) |
||
| 6 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 7 | * @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
||
| 8 | * @since 4.00 |
||
| 9 | * @package module::newbb |
||
| 10 | */ |
||
| 11 | |||
| 12 | use Xmf\Request; |
||
| 13 | use XoopsModules\Newbb; |
||
| 14 | |||
| 15 | require_once __DIR__ . '/header.php'; |
||
| 16 | |||
| 17 | $topic_id = Request::getInt('topic_id', 0, 'POST'); |
||
| 18 | //$post_id = Request::getArray('post_id', Request::getArray('post_id', [], 'POST'), 'GET'); |
||
| 19 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
| 20 | if (Request::hasVar('post_id', 'POST')) { |
||
| 21 | Request::getArray('post_id', $post_id, 'POST'); |
||
| 22 | } |
||
| 23 | |||
| 24 | // !empty($_POST['post_id']) ? $_POST['post_id'] : $post_id; |
||
| 25 | |||
| 26 | $uid = Request::getInt('uid', 0, 'GET'); |
||
| 27 | |||
| 28 | $op = Request::getCmd('op', Request::getCmd('op', '', 'POST'), 'GET'); |
||
| 29 | $op = in_array($op, ['approve', 'delete', 'restore', 'split']) ? $op : ''; |
||
| 30 | $mode = Request::getInt('mode', 1, 'GET'); |
||
| 31 | |||
| 32 | if (0 === $post_id || '' === $op) { |
||
| 33 | // irmtfan - issue with javascript:history.go(-1) |
||
| 34 | redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_NO_SELECTION); |
||
| 35 | } |
||
| 36 | ///** @var PostHandler $postHandler */ |
||
| 37 | //$postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post'); |
||
| 38 | ///** @var TopicHandler $topicHandler */ |
||
| 39 | //$topicHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 40 | ///** @var NewbbForumHandler $forumHandler */ |
||
| 41 | //$forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
||
| 42 | if (0 === $topic_id) { |
||
| 43 | $forumObject = null; |
||
| 44 | } else { |
||
| 45 | $topicObject = $topicHandler->get($topic_id); |
||
| 46 | $forum_id = $topicObject->getVar('forum_id'); |
||
| 47 | $forumObject = $forumHandler->get($forum_id); |
||
| 48 | } |
||
| 49 | $isAdmin = newbbIsAdmin($forumObject); |
||
| 50 | |||
| 51 | if (!$isAdmin) { |
||
| 52 | redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS); |
||
| 53 | } |
||
| 54 | |||
| 55 | switch ($op) { |
||
| 56 | case 'restore': |
||
| 57 | $post_id = array_values($post_id); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 58 | sort($post_id); |
||
| 59 | $topics = []; |
||
| 60 | $forums = []; |
||
| 61 | foreach ($post_id as $post) { |
||
| 62 | $postObject = $postHandler->get($post); |
||
| 63 | if ($postObject->getVar('topic_id') < 1) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | $postHandler->approve($postObject, true); |
||
| 68 | $topics[$postObject->getVar('topic_id')] = 1; |
||
| 69 | $forums[$postObject->getVar('forum_id')] = 1; |
||
| 70 | unset($postObject); |
||
| 71 | } |
||
| 72 | foreach (array_keys($topics) as $topic) { |
||
| 73 | $topicHandler->synchronization($topic); |
||
| 74 | } |
||
| 75 | foreach (array_keys($forums) as $forum) { |
||
| 76 | $forumHandler->synchronization($forum); |
||
| 77 | } |
||
| 78 | break; |
||
| 79 | case 'approve': |
||
| 80 | $post_id = array_values($post_id); |
||
| 81 | sort($post_id); |
||
| 82 | $topics = []; |
||
| 83 | $forums = []; |
||
| 84 | $criteria = new \Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN'); |
||
| 85 | $postsObject = $postHandler->getObjects($criteria, true); |
||
| 86 | foreach ($post_id as $post) { |
||
| 87 | /** @var Newbb\Post $postObject */ |
||
| 88 | $postObject = $postsObject[$post]; |
||
| 89 | if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | $postHandler->approve($postObject); |
||
| 93 | $topics[$postObject->getVar('topic_id')] = $post; |
||
| 94 | $forums[$postObject->getVar('forum_id')] = 1; |
||
| 95 | } |
||
| 96 | foreach (array_keys($topics) as $topic) { |
||
| 97 | $topicHandler->synchronization($topic); |
||
| 98 | } |
||
| 99 | foreach (array_keys($forums) as $forum) { |
||
| 100 | $forumHandler->synchronization($forum); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
||
| 104 | break; |
||
| 105 | } |
||
| 106 | |||
| 107 | $criteria_topic = new \Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN'); |
||
| 108 | $topic_list = $topicHandler->getList($criteria_topic, true); |
||
| 109 | |||
| 110 | $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
||
| 111 | $forum_list = $forumHandler->getList($criteria_forum); |
||
| 112 | |||
| 113 | require_once __DIR__ . '/include/notification.inc.php'; |
||
| 114 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||
| 115 | $notificationHandler = xoops_getHandler('notification'); |
||
| 116 | foreach ($post_id as $post) { |
||
| 117 | $tags = []; |
||
| 118 | /** @var Newbb\Post[] $postsObject [$post] */ |
||
| 119 | $tags['THREAD_NAME'] = $topic_list[$postsObject[$post]->getVar('topic_id')]; |
||
| 120 | $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postsObject[$post]->getVar('topic_id') . '&forum=' . $postsObject[$post]->getVar('forum_id'); |
||
| 121 | $tags['FORUM_NAME'] = $forum_list[$postsObject[$post]->getVar('forum_id')]; |
||
| 122 | $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $postsObject[$post]->getVar('forum_id'); |
||
| 123 | $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post; |
||
| 124 | $notificationHandler->triggerEvent('thread', $postsObject[$post]->getVar('topic_id'), 'new_post', $tags); |
||
| 125 | $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_post', $tags); |
||
| 126 | $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
||
| 127 | $tags['POST_CONTENT'] = $postsObject[$post]->getVar('post_text'); |
||
| 128 | $tags['POST_NAME'] = $postsObject[$post]->getVar('subject'); |
||
| 129 | $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
||
| 130 | $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_fullpost', $tags); |
||
| 131 | } |
||
| 132 | break; |
||
| 133 | case 'delete': |
||
| 134 | $post_id = array_values($post_id); |
||
| 135 | rsort($post_id); |
||
| 136 | $topics = []; |
||
| 137 | $forums = []; |
||
| 138 | foreach ($post_id as $post) { |
||
| 139 | $postObject = $postHandler->get($post); |
||
| 140 | if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
||
| 141 | continue; |
||
| 142 | } |
||
| 143 | $topics[$postObject->getVar('topic_id')] = 1; |
||
| 144 | $forums[$postObject->getVar('forum_id')] = 1; |
||
| 145 | $postHandler->delete($postObject, true); |
||
| 146 | unset($postObject); |
||
| 147 | } |
||
| 148 | foreach (array_keys($topics) as $topic) { |
||
| 149 | $topicHandler->synchronization($topic); |
||
| 150 | } |
||
| 151 | foreach (array_keys($forums) as $forum) { |
||
| 152 | $forumHandler->synchronization($forum); |
||
| 153 | } |
||
| 154 | break; |
||
| 155 | case 'split': |
||
| 156 | /** @var Newbb\Post $postObject */ |
||
| 157 | $postObject = $postHandler->get($post_id); |
||
| 158 | if ((is_array($post_id) && 0 === count($post_id)) || $postObject->isTopic()) { |
||
|
0 ignored issues
–
show
|
|||
| 159 | break; |
||
| 160 | } |
||
| 161 | $topic_id = $postObject->getVar('topic_id'); |
||
| 162 | |||
| 163 | $newtopic = $topicHandler->create(); |
||
| 164 | $newtopic->setVar('topic_title', $postObject->getVar('subject'), true); |
||
| 165 | $newtopic->setVar('topic_poster', $postObject->getVar('uid'), true); |
||
| 166 | $newtopic->setVar('forum_id', $postObject->getVar('forum_id'), true); |
||
| 167 | $newtopic->setVar('topic_time', $postObject->getVar('post_time'), true); |
||
| 168 | $newtopic->setVar('poster_name', $postObject->getVar('poster_name'), true); |
||
| 169 | $newtopic->setVar('approved', 1, true); |
||
| 170 | $topicHandler->insert($newtopic, true); |
||
| 171 | $new_topic_id = $newtopic->getVar('topic_id'); |
||
| 172 | |||
| 173 | $pid = $postObject->getVar('pid'); |
||
| 174 | |||
| 175 | $postObject->setVar('topic_id', $new_topic_id, true); |
||
| 176 | $postObject->setVar('pid', 0, true); |
||
| 177 | $postHandler->insert($postObject); |
||
| 178 | |||
| 179 | /* split a single post */ |
||
| 180 | if (1 === $mode) { |
||
| 181 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
||
| 182 | $criteria->add(new \Criteria('pid', $post_id)); |
||
| 183 | $postHandler->updateAll('pid', $pid, $criteria, true); |
||
| 184 | /* split a post and its children posts */ |
||
| 185 | } elseif (2 === $mode) { |
||
| 186 | require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
||
| 187 | $mytree = new Newbb\Tree($GLOBALS['xoopsDB']->prefix('newbb_posts'), 'post_id', 'pid'); |
||
| 188 | $posts = $mytree->getAllChildId($post_id); |
||
| 189 | if (count($posts) > 0) { |
||
| 190 | $criteria = new \Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN'); |
||
| 191 | $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
||
| 192 | } |
||
| 193 | /* split a post and all posts coming after */ |
||
| 194 | } elseif (3 === $mode) { |
||
| 195 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
||
| 196 | $criteria->add(new \Criteria('post_id', $post_id, '>')); |
||
| 197 | $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
||
| 198 | |||
| 199 | unset($criteria); |
||
| 200 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $new_topic_id)); |
||
| 201 | $criteria->add(new \Criteria('post_id', $post_id, '>')); |
||
| 202 | $postHandler->identifierName = 'pid'; |
||
| 203 | $posts = $postHandler->getList($criteria); |
||
| 204 | |||
| 205 | unset($criteria); |
||
| 206 | $post_update = []; |
||
| 207 | foreach ($posts as $postid => $pid) { |
||
| 208 | // if (!in_array($pid, array_keys($posts))) { |
||
| 209 | if (!array_key_exists($pid, $posts)) { |
||
| 210 | $post_update[] = $pid; |
||
| 211 | } |
||
| 212 | if (!array_key_exists($pid, $posts)) { |
||
| 213 | $post_update2[] = $pid; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | if (count($post_update)) { |
||
| 217 | $criteria = new \Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN'); |
||
| 218 | $postHandler->updateAll('pid', $post_id, $criteria, true); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | $forum_id = $postObject->getVar('forum_id'); |
||
| 223 | $topicHandler->synchronization($topic_id); |
||
| 224 | $topicHandler->synchronization($new_topic_id); |
||
| 225 | $sql = sprintf('UPDATE "%s" SET forum_topics = forum_topics+1 WHERE forum_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id); |
||
| 226 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
| 227 | |||
| 228 | break; |
||
| 229 | } |
||
| 230 | if (!empty($topic_id)) { |
||
| 231 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id", 2, _MD_NEWBB_DBUPDATED); |
||
| 232 | } elseif (!empty($forum_id)) { |
||
| 233 | redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum=$forum_id", 2, _MD_NEWBB_DBUPDATED); |
||
| 234 | } else { |
||
| 235 | redirect_header(XOOPS_URL . "/modules/newbb/viewpost.php?uid=$uid", 2, _MD_NEWBB_DBUPDATED); |
||
| 236 | } |
||
| 237 | // irmtfan move to footer.php |
||
| 238 | require_once __DIR__ . '/footer.php'; |
||
| 239 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 240 |