mambax7 /
newbb5
| 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 (http://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 | $uid = Request::getInt('uid', 0, 'GET'); |
||||||
| 20 | |||||||
| 21 | $op = Request::getCmd('op', Request::getCmd('op', '', 'POST'), 'GET'); |
||||||
| 22 | $op = in_array($op, ['approve', 'delete', 'restore', 'split'], true) ? $op : ''; |
||||||
| 23 | $mode = Request::getInt('mode', 1, 'GET'); |
||||||
| 24 | |||||||
| 25 | if (0 === count($post_id) || 0 === count($op)) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 26 | // irmtfan - issue with javascript:history.go(-1) |
||||||
| 27 | redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 2, _MD_NEWBB_NO_SELECTION); |
||||||
| 28 | } |
||||||
| 29 | ///** @var PostHandler $postHandler */ |
||||||
| 30 | //$postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
||||||
| 31 | ///** @var TopicHandler $topicHandler */ |
||||||
| 32 | //$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||||||
| 33 | ///** @var NewbbForumHandler $forumHandler */ |
||||||
| 34 | //$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
||||||
| 35 | if (empty($topic_id)) { |
||||||
| 36 | $forumObject = null; |
||||||
| 37 | } else { |
||||||
| 38 | $topicObject = $topicHandler->get($topic_id); |
||||||
| 39 | $forum_id = $topicObject->getVar('forum_id'); |
||||||
| 40 | $forumObject = $forumHandler->get($forum_id); |
||||||
| 41 | } |
||||||
| 42 | $isAdmin = newbbIsAdmin($forumObject); |
||||||
| 43 | |||||||
| 44 | if (!$isAdmin) { |
||||||
| 45 | redirect_header(XOOPS_URL . '/index.php', 2, _MD_NEWBB_NORIGHTTOACCESS); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | switch ($op) { |
||||||
| 49 | case 'restore': |
||||||
| 50 | $post_id = array_values($post_id); |
||||||
| 51 | sort($post_id); |
||||||
| 52 | $topics = []; |
||||||
| 53 | $forums = []; |
||||||
| 54 | foreach ($post_id as $post) { |
||||||
| 55 | $postObject = $postHandler->get($post); |
||||||
| 56 | if ($postObject->getVar('topic_id') < 1) { |
||||||
| 57 | continue; |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | $postHandler->approve($postObject, true); |
||||||
| 61 | $topics[$postObject->getVar('topic_id')] = 1; |
||||||
| 62 | $forums[$postObject->getVar('forum_id')] = 1; |
||||||
| 63 | unset($postObject); |
||||||
| 64 | } |
||||||
| 65 | foreach (array_keys($topics) as $topic) { |
||||||
| 66 | $topicHandler->synchronization($topic); |
||||||
| 67 | } |
||||||
| 68 | foreach (array_keys($forums) as $forum) { |
||||||
| 69 | $forumHandler->synchronization($forum); |
||||||
| 70 | } |
||||||
| 71 | break; |
||||||
| 72 | case 'approve': |
||||||
| 73 | $post_id = array_values($post_id); |
||||||
| 74 | sort($post_id); |
||||||
| 75 | $topics = []; |
||||||
| 76 | $forums = []; |
||||||
| 77 | $criteria = new \Criteria('post_id', '(' . implode(',', $post_id) . ')', 'IN'); |
||||||
| 78 | $postsObject = $postHandler->getObjects($criteria, true); |
||||||
| 79 | foreach ($post_id as $post) { |
||||||
| 80 | /** @var Newbb\Post $postObject */ |
||||||
| 81 | $postObject = $postsObject[$post]; |
||||||
| 82 | if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
||||||
| 83 | continue; |
||||||
| 84 | } |
||||||
| 85 | $postHandler->approve($postObject); |
||||||
| 86 | $topics[$postObject->getVar('topic_id')] = $post; |
||||||
| 87 | $forums[$postObject->getVar('forum_id')] = 1; |
||||||
| 88 | } |
||||||
| 89 | foreach (array_keys($topics) as $topic) { |
||||||
| 90 | $topicHandler->synchronization($topic); |
||||||
| 91 | } |
||||||
| 92 | foreach (array_keys($forums) as $forum) { |
||||||
| 93 | $forumHandler->synchronization($forum); |
||||||
| 94 | } |
||||||
| 95 | |||||||
| 96 | if (empty($GLOBALS['xoopsModuleConfig']['notification_enabled'])) { |
||||||
| 97 | break; |
||||||
| 98 | } |
||||||
| 99 | |||||||
| 100 | $criteria_topic = new \Criteria('topic_id', '(' . implode(',', array_keys($topics)) . ')', 'IN'); |
||||||
| 101 | $topic_list = $topicHandler->getList($criteria_topic, true); |
||||||
| 102 | |||||||
| 103 | $criteria_forum = new \Criteria('forum_id', '(' . implode(',', array_keys($forums)) . ')', 'IN'); |
||||||
| 104 | $forum_list = $forumHandler->getList($criteria_forum); |
||||||
| 105 | |||||||
| 106 | require_once __DIR__ . '/include/notification.inc.php'; |
||||||
| 107 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||||
| 108 | $notificationHandler = xoops_getHandler('notification'); |
||||||
| 109 | foreach ($post_id as $post) { |
||||||
| 110 | $tags = []; |
||||||
| 111 | /** @var Newbb\Post[] $postsObject [$post] */ |
||||||
| 112 | $tags['THREAD_NAME'] = $topic_list[$postsObject[$post]->getVar('topic_id')]; |
||||||
| 113 | $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $postsObject[$post]->getVar('topic_id') . '&forum=' . $postsObject[$post]->getVar('forum_id'); |
||||||
| 114 | $tags['FORUM_NAME'] = $forum_list[$postsObject[$post]->getVar('forum_id')]; |
||||||
| 115 | $tags['FORUM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewforum.php?forum=' . $postsObject[$post]->getVar('forum_id'); |
||||||
| 116 | $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $post; |
||||||
| 117 | $notificationHandler->triggerEvent('thread', $postsObject[$post]->getVar('topic_id'), 'new_post', $tags); |
||||||
|
0 ignored issues
–
show
'new_post' of type string is incompatible with the type integer expected by parameter $event of XoopsNotificationHandler::triggerEvent().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
'thread' of type string is incompatible with the type integer expected by parameter $category of XoopsNotificationHandler::triggerEvent().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 118 | $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_post', $tags); |
||||||
| 119 | $notificationHandler->triggerEvent('global', 0, 'new_post', $tags); |
||||||
| 120 | $tags['POST_CONTENT'] = $postsObject[$post]->getVar('post_text'); |
||||||
| 121 | $tags['POST_NAME'] = $postsObject[$post]->getVar('subject'); |
||||||
| 122 | $notificationHandler->triggerEvent('global', 0, 'new_fullpost', $tags); |
||||||
| 123 | $notificationHandler->triggerEvent('forum', $postsObject[$post]->getVar('forum_id'), 'new_fullpost', $tags); |
||||||
| 124 | } |
||||||
| 125 | break; |
||||||
| 126 | case 'delete': |
||||||
| 127 | $post_id = array_values($post_id); |
||||||
| 128 | rsort($post_id); |
||||||
| 129 | $topics = []; |
||||||
| 130 | $forums = []; |
||||||
| 131 | foreach ($post_id as $post) { |
||||||
| 132 | $postObject = $postHandler->get($post); |
||||||
| 133 | if (!empty($topic_id) && $topic_id !== $postObject->getVar('topic_id')) { |
||||||
| 134 | continue; |
||||||
| 135 | } |
||||||
| 136 | $topics[$postObject->getVar('topic_id')] = 1; |
||||||
| 137 | $forums[$postObject->getVar('forum_id')] = 1; |
||||||
| 138 | $postHandler->delete($postObject, true); |
||||||
| 139 | unset($postObject); |
||||||
| 140 | } |
||||||
| 141 | foreach (array_keys($topics) as $topic) { |
||||||
| 142 | $topicHandler->synchronization($topic); |
||||||
| 143 | } |
||||||
| 144 | foreach (array_keys($forums) as $forum) { |
||||||
| 145 | $forumHandler->synchronization($forum); |
||||||
| 146 | } |
||||||
| 147 | break; |
||||||
| 148 | case 'split': |
||||||
| 149 | /** @var Newbb\Post $postObject */ |
||||||
| 150 | $postObject = $postHandler->get($post_id); |
||||||
| 151 | if (0 === count($post_id) || $postObject->isTopic()) { |
||||||
| 152 | break; |
||||||
| 153 | } |
||||||
| 154 | $topic_id = $postObject->getVar('topic_id'); |
||||||
| 155 | |||||||
| 156 | $newtopic = $topicHandler->create(); |
||||||
| 157 | $newtopic->setVar('topic_title', $postObject->getVar('subject'), true); |
||||||
| 158 | $newtopic->setVar('topic_poster', $postObject->getVar('uid'), true); |
||||||
| 159 | $newtopic->setVar('forum_id', $postObject->getVar('forum_id'), true); |
||||||
| 160 | $newtopic->setVar('topic_time', $postObject->getVar('post_time'), true); |
||||||
| 161 | $newtopic->setVar('poster_name', $postObject->getVar('poster_name'), true); |
||||||
| 162 | $newtopic->setVar('approved', 1, true); |
||||||
| 163 | $topicHandler->insert($newtopic, true); |
||||||
| 164 | $new_topic_id = $newtopic->getVar('topic_id'); |
||||||
| 165 | |||||||
| 166 | $pid = $postObject->getVar('pid'); |
||||||
| 167 | |||||||
| 168 | $postObject->setVar('topic_id', $new_topic_id, true); |
||||||
| 169 | $postObject->setVar('pid', 0, true); |
||||||
| 170 | $postHandler->insert($postObject); |
||||||
| 171 | |||||||
| 172 | /* split a single post */ |
||||||
| 173 | if (1 === $mode) { |
||||||
| 174 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
||||||
| 175 | $criteria->add(new \Criteria('pid', $post_id)); |
||||||
|
0 ignored issues
–
show
$post_id of type array is incompatible with the type string expected by parameter $value of Criteria::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 176 | $postHandler->updateAll('pid', $pid, $criteria, true); |
||||||
| 177 | /* split a post and its children posts */ |
||||||
| 178 | } elseif (2 === $mode) { |
||||||
| 179 | require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
||||||
| 180 | $mytree = new \XoopsTree($GLOBALS['xoopsDB']->prefix('newbb_posts'), 'post_id', 'pid'); |
||||||
| 181 | $posts = $mytree->getAllChildId($post_id); |
||||||
| 182 | if (count($posts) > 0) { |
||||||
| 183 | $criteria = new \Criteria('post_id', '(' . implode(',', $posts) . ')', 'IN'); |
||||||
| 184 | $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
||||||
| 185 | } |
||||||
| 186 | /* split a post and all posts coming after */ |
||||||
| 187 | } elseif (3 === $mode) { |
||||||
| 188 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic_id)); |
||||||
| 189 | $criteria->add(new \Criteria('post_id', $post_id, '>')); |
||||||
| 190 | $postHandler->updateAll('topic_id', $new_topic_id, $criteria, true); |
||||||
| 191 | |||||||
| 192 | unset($criteria); |
||||||
| 193 | $criteria = new \CriteriaCompo(new \Criteria('topic_id', $new_topic_id)); |
||||||
| 194 | $criteria->add(new \Criteria('post_id', $post_id, '>')); |
||||||
| 195 | $postHandler->identifierName = 'pid'; |
||||||
| 196 | $posts = $postHandler->getList($criteria); |
||||||
| 197 | |||||||
| 198 | unset($criteria); |
||||||
| 199 | $post_update = []; |
||||||
| 200 | foreach ($posts as $postid => $pid) { |
||||||
| 201 | // if (!in_array($pid, array_keys($posts))) { |
||||||
| 202 | if (!array_key_exists($pid, $posts)) { |
||||||
| 203 | $post_update[] = $pid; |
||||||
| 204 | } |
||||||
| 205 | if (!array_key_exists($pid, $posts)) { |
||||||
| 206 | $post_update2[] = $pid; |
||||||
| 207 | } |
||||||
| 208 | } |
||||||
| 209 | if (count($post_update)) { |
||||||
| 210 | $criteria = new \Criteria('post_id', '(' . implode(',', $post_update) . ')', 'IN'); |
||||||
| 211 | $postHandler->updateAll('pid', $post_id, $criteria, true); |
||||||
| 212 | } |
||||||
| 213 | } |
||||||
| 214 | |||||||
| 215 | $forum_id = $postObject->getVar('forum_id'); |
||||||
| 216 | $topicHandler->synchronization($topic_id); |
||||||
| 217 | $topicHandler->synchronization($new_topic_id); |
||||||
| 218 | $sql = sprintf('UPDATE "%s" SET forum_topics = forum_topics+1 WHERE forum_id = "%u"', $GLOBALS['xoopsDB']->prefix('newbb_forums'), $forum_id); |
||||||
| 219 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||||||
| 220 | |||||||
| 221 | break; |
||||||
| 222 | } |
||||||
| 223 | if (!empty($topic_id)) { |
||||||
| 224 | redirect_header(XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=$topic_id", 2, _MD_NEWBB_DBUPDATED); |
||||||
| 225 | } elseif (!empty($forum_id)) { |
||||||
| 226 | redirect_header(XOOPS_URL . "/modules/newbb/viewforum.php?forum=$forum_id", 2, _MD_NEWBB_DBUPDATED); |
||||||
| 227 | } else { |
||||||
| 228 | redirect_header(XOOPS_URL . "/modules/newbb/viewpost.php?uid=$uid", 2, _MD_NEWBB_DBUPDATED); |
||||||
| 229 | } |
||||||
| 230 | // irmtfan move to footer.php |
||||||
| 231 | require_once __DIR__ . '/footer.php'; |
||||||
| 232 | require_once $GLOBALS['xoops']->path('footer.php'); |
||||||
| 233 |