/** * Allows updating of topics, stuck or closed, and posts * @global array * @global array * @param integer $id post we are editing * @param string $topic post subject * @param string $content post content * @param integer $reply id of topic we are replying to * @param boolean $sticky are we sticking it to the top? * @param boolean $closed are we closing it? * @return string|int */ function update($id, $topic, $content, $sticky = false, $closed = false) { global $config, $user_data; // The time. milliseconds / seconds may change. $time = time(); // Is the id numeric? if (!alpha($id, 'numeric')) { return lang_parse('error_given_not_numeric', array(lang('post') . " " . lang('id'))); } // Grab the data for the update. $post_data = topic($id); // Check to see if the post or topic was found. if (!$post_data) { return lang('error_post_missing'); } // Pre-Parse $topic = clean_input(strip_repeat($topic)); $content = htmlentities($content); $content = clean_input(stripslashes($content)); // Is the user currently logged in? If not we can't update return error. if ($_SESSION['logged_in']) { // Editing a topic not post if ($post_data['reply'] == 0) { if ($topic == "") { return lang_parse('error_no_given', array(lang('username'))); } } else { if ($topic == "") { $topic = "re:"; } } // Is the subject valid? if (!alpha($topic, 'alpha-extra')) { return lang_parse('error_invalid_chars', array(lang('subject'))); } // Did they give us any content to work with? if ($content != "") { if (!is_string(length($content, $config['message_minimum_length'], $config['message_max_length']))) { // Check to see if the user is an admin and able to sticky / close the topic if ($_SESSION['admin'] || $_SESSION['moderator']) { // Sticky $sticky = $sticky ? '1' : '0'; // Closed $closed = $closed ? '1' : '0'; // Admin functions update_field($id, 'sticky', $sticky); update_field($id, 'closed', $closed); } // Parsing $content = htmlspecialchars($content); // Update the post already inside of the database with the new data $result = mysql_query("UPDATE `forum` SET `subject`='{$topic}', `message`='{$content}', `updated`='{$time}', `replies`='{$replies}' WHERE id = '{$id}'") or die(mysql_error()); // Did it work? if ($result) { return true; } else { return false; } } else { return lang_parse('error_message_length', array($config['message_max_length'], $config['message_minimum_length'])); } } else { return lang_parse('error_no_given', array(lang('message'))); } } else { return lang('error_not_logged'); } }
/** * Allows updating of topics, stuck or closed, and posts * @global array * @global array * @global resource * @param integer $id post we are editing * @param string $topic post subject * @param string $content post content * @param integer $reply id of topic we are replying to * @param boolean $sticky are we sticking it to the top? * @param boolean $closed are we closing it? * @return string|int */ function update($id, $category, $topic, $content, $sticky = false, $closed = false) { global $config, $user_data, $database; // The time. milliseconds / seconds may change. $time = time(); // Is the id numeric? if (!alpha($id, 'numeric')) { return lang_parse('error_given_not_numeric', array(lang('post') . " " . lang('id'))); } // Grab the data for the update. $post_data = topic($id); // Check to see if the post or topic was found. if (!$post_data) { return lang('error_post_missing'); } // Pre-Parse $topic = strip_repeat($topic); // Can't update a replies category! if ($post_data['reply']) { $category = $post_data['category']; } // Check validity of category as numeric if (!alpha($category, 'numeric')) { return lang('error_invalid_category'); } // Check to see if category exists $category = category($category); if (!$category) { return lang('error_invalid_category'); } // Check category settings against user if (!$user_data['admin']) { if ($category['aop'] && $post_data['reply']) { if (!$user_data['admin'] || !$user_data['moderator']) { return lang('error_invalid_category'); } } if ($category['aot'] && !$post_data['reply']) { if ($user_data['id'] != $category['aot']) { return lang('error_invalid_category'); } } } // Is the user currently logged in? If not we can't update return error. if ($_SESSION['logged_in']) { // Editing a topic not post if ($post_data['reply'] == 0) { // Is there a topic? if ($topic == "") { return lang_parse('error_no_given', array(lang('username'))); } } else { // If there was no topic put re: on it. if ($topic == "") { $topic = "re:"; } } // Is the subject valid? if (!alpha($topic, 'alpha-extra')) { return lang_parse('error_invalid_chars', array(lang('subject'))); } // Did they give us any content to work with? if ($content != "") { if (!is_string(length($content, $config['message_minimum_length'], $config['message_max_length']))) { // Check to see if the user is an admin and able to sticky / close the topic if ($_SESSION['admin'] || $_SESSION['moderator']) { // Sticky $sticky = $sticky ? '1' : '0'; // Closed $closed = $closed ? '1' : '0'; // Admin functions update_field($id, 'sticky', $sticky); update_field($id, 'closed', $closed); } // Parsing $topic = $database->escape($topic); $content = $database->escape($content); // Update the post already inside of the database with the new data $result = $database->query("UPDATE `forum` SET `category`='{$category['id']}', `subject`='{$topic}', `message`='{$content}', `updated`='{$time}', `replies`='{$replies}' WHERE id = '{$id}'") or die(mysql_error()); // Did it work? if ($result) { // Update replies with category if ($category != $post_data['category'] && !$post_data['reply']) { $database->query("UPDATE `forum` SET `category`='{$category['id']}' WHERE `reply` = {$id}"); } return true; } else { return false; } } else { return lang_parse('error_message_length', array($config['message_max_length'], $config['message_minimum_length'])); } } else { return lang_parse('error_no_given', array(lang('message'))); } } else { return lang('error_not_logged'); } }