/** * Edit topic * * @param mixed $data * @return bool|string */ public function editTopic($data) { global $db, $TNB_GLOBALS; $title = get_secure_string($data['title']); $category = get_secure_string($data['category']); $content = $data['content']; if (!$title || !$category || !$content || !isset($data['id'])) { return MSG_ALL_FIELDS_REQUIRED; } //Check Category ID is valid or not $query = $db->prepare("SELECT categoryID FROM " . TABLE_FORUM_CATEGORIES . " WHERE categoryID=%d", $category); $categoryID = $db->getVar($query); if (!$categoryID) { return MSG_INVALID_REQUEST; } $content = buckys_remove_tags_inside_code($content); //Remove Invalid Image URLs $content = buckys_remove_invalid_image_urls($content); $query = "UPDATE " . TABLE_FORUM_TOPICS . " SET \n `topicTitle`='" . $db->escapeInput($title) . "',\n `topicContent`='" . $db->escapeInput($content, false) . "',\n `categoryID`='" . $db->escapeInput($categoryID) . "'\n WHERE\n `topicID`='" . $db->escapeInput($data['id']) . "'"; $db->query($query); // $db->updateFromArray(TABLE_FORUM_TOPICS, $updateData, array('topicID'=>$data['id'])); return true; }
/** * Create Post Reply * * @param mixed $data * @return null|string */ public static function createReply($data) { global $db, $TNB_GLOBALS; $content = trim($data['content']); if (!$content) { return MSG_ALL_FIELDS_REQUIRED; } $content = buckys_remove_invalid_image_urls($content); $content = buckys_remove_tags_inside_code($content); //Check Category ID is valid or not $query = $db->prepare("SELECT topicID, categoryID, creatorID FROM " . TABLE_FORUM_TOPICS . " WHERE topicID=%d AND status='publish'", $data['topicID']); $topic = $db->getRow($query); if (!$topic) { return MSG_INVALID_REQUEST; } $query = "INSERT INTO " . TABLE_FORUM_REPLIES . "(\n `topicID`,\n `replyContent`,\n `creatorID`,\n `createdDate`,\n `votes`,\n `status`\n )VALUES(\n '" . $topic['topicID'] . "',\n '" . $db->escapeInput($content, false) . "',\n '" . $TNB_GLOBALS['user']['userID'] . "',\n '" . date("Y-m-d H:i:s") . "',\n '0',\n 'pending'\n )"; $db->query($query); $newID = $db->getLastInsertId(); if (!$newID) { return $db->getLastError(); } //If the user has more than 5 actived topics, update the topic status to 1 $count1 = $db->getVar("SELECT count(1) FROM " . TABLE_FORUM_TOPICS . " WHERE creatorID=" . $TNB_GLOBALS['user']['userID'] . " AND `status`='publish'"); $count2 = $db->getVar("SELECT count(1) FROM " . TABLE_FORUM_REPLIES . " WHERE creatorID=" . $TNB_GLOBALS['user']['userID'] . " AND `status`='publish'"); if ($count1 + $count2 >= 5) { //Publish Reply $db->updateFromArray(TABLE_FORUM_REPLIES, array('status' => 'publish'), array('replyID' => $newID)); //Update Topic Table $db->query("UPDATE " . TABLE_FORUM_TOPICS . " SET lastReplyID=" . $newID . ", `replies`=`replies` + 1, lastReplyDate='" . date('Y-m-d H:i:s') . "', lastReplierID=" . $TNB_GLOBALS['user']['userID'] . " WHERE topicID=" . $topic['topicID']); $db->query("UPDATE " . TABLE_FORUM_CATEGORIES . " SET `replies`=`replies` + 1, lastTopicID='" . $topic['topicID'] . "' WHERE categoryID=" . $topic['categoryID']); //Increase user posts count $db->query("UPDATE " . TABLE_USERS . " SET `posts_count`=`posts_count` + 1 WHERE userID=" . $TNB_GLOBALS['user']['userID']); //Add Notifications $forumNotification = new BuckysForumNotification(); $forumNotification->addNotificationsForReplies($topic['creatorID'], $topic['topicID'], $newID); if ($topic['creatorID'] != $TNB_GLOBALS['user']['userID']) { $forumNotification->addNotificationsForTopic($topic['creatorID'], $topic['topicID'], $newID); } //Update User Stats BuckysUser::updateStats($topic['creatorID'], 'replies', 1); return 'publish'; } return 'pending'; }