diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index d1c1bfdd2..a0e482671 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -1331,6 +1331,7 @@ CREATE TABLE IF NOT EXISTS `bb_topics` ( `topic_dl_type` tinyint(1) NOT NULL DEFAULT '0', `topic_last_post_time` int(11) NOT NULL DEFAULT '0', `topic_show_first_post` tinyint(1) unsigned NOT NULL DEFAULT '0', + `is_draft` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`topic_id`), KEY `forum_id` (`forum_id`), KEY `topic_last_post_id` (`topic_last_post_id`), diff --git a/upload/ajax.php b/upload/ajax.php index a87dd9237..fd81b174f 100644 --- a/upload/ajax.php +++ b/upload/ajax.php @@ -8,53 +8,51 @@ require('./common.php'); $ajax->init(); // Handle "board disabled via ON/OFF trigger" -if (file_exists(BB_DISABLED)) -{ +if (file_exists(BB_DISABLED)) { $ajax->ajax_die($bb_cfg['board_disabled_msg']); } // Load actions required modules -switch ($ajax->action) -{ +switch ($ajax->action) { case 'view_post': - require(INC_DIR .'bbcode.php'); - break; + require(INC_DIR . 'bbcode.php'); + break; case 'posts': case 'post_mod_comment': - require(INC_DIR .'bbcode.php'); - require(INC_DIR .'functions_post.php'); - require(INC_DIR .'functions_admin.php'); - break; + require(INC_DIR . 'bbcode.php'); + require(INC_DIR . 'functions_post.php'); + require(INC_DIR . 'functions_admin.php'); + break; case 'view_torrent': case 'mod_action': case 'change_tor_status': case 'gen_passkey'; - require(BB_ROOT .'attach_mod/attachment_mod.php'); - require(INC_DIR .'functions_torrent.php'); - break; + require(BB_ROOT . 'attach_mod/attachment_mod.php'); + require(INC_DIR . 'functions_torrent.php'); + break; case 'change_torrent': - require(BB_ROOT .'attach_mod/attachment_mod.php'); - require(INC_DIR .'functions_torrent.php'); - break; + require(BB_ROOT . 'attach_mod/attachment_mod.php'); + require(INC_DIR . 'functions_torrent.php'); + break; case 'user_register': - require(INC_DIR .'functions_validate.php'); - break; + require(INC_DIR . 'functions_validate.php'); + break; case 'manage_user': - require(INC_DIR .'functions_admin.php'); - break; + require(INC_DIR . 'functions_admin.php'); + break; case 'group_membership': - require(INC_DIR .'functions_group.php'); - break; + require(INC_DIR . 'functions_group.php'); + break; } // position in $ajax->valid_actions['xxx'] -define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin' +define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin' $user->session_start(); $ajax->exec(); @@ -64,88 +62,82 @@ $ajax->exec(); // class ajax_common { - var $request = array(); + var $request = array(); var $response = array(); var $valid_actions = array( - // ACTION NAME AJAX_AUTH + // ACTION NAME AJAX_AUTH 'edit_user_profile' => array('admin'), - 'change_user_rank' => array('admin'), - 'change_user_opt' => array('admin'), - 'manage_user' => array('admin'), + 'change_user_rank' => array('admin'), + 'change_user_opt' => array('admin'), + 'manage_user' => array('admin'), - 'mod_action' => array('mod'), - 'topic_tpl' => array('mod'), - 'group_membership' => array('mod'), + 'mod_action' => array('mod'), + 'topic_tpl' => array('mod'), + 'group_membership' => array('mod'), - 'gen_passkey' => array('user'), - 'change_torrent' => array('user'), + 'gen_passkey' => array('user'), + 'change_torrent' => array('user'), 'change_tor_status' => array('user'), + 'modify_draft' => array('user'), - 'view_post' => array('guest'), - 'view_torrent' => array('guest'), - 'user_register' => array('guest'), - 'posts' => array('guest'), - 'index_data' => array('guest'), + 'view_post' => array('guest'), + 'view_torrent' => array('guest'), + 'user_register' => array('guest'), + 'posts' => array('guest'), + 'index_data' => array('guest'), - 'post_mod_comment' => array('mod'), -); + 'post_mod_comment' => array('mod'), + ); var $action = null; /** - * Constructor - */ - function ajax_common () + * Constructor + */ + function ajax_common() { ob_start(array(&$this, 'ob_handler')); header('Content-Type: text/plain'); } /** - * Perform action - */ - function exec () + * Perform action + */ + function exec() { global $lang; // Exit if we already have errors - if (!empty($this->response['error_code'])) - { + if (!empty($this->response['error_code'])) { $this->send(); } // Check that requested action is valid $action = $this->action; - if (!$action || !is_string($action)) - { + if (!$action || !is_string($action)) { $this->ajax_die('no action specified'); - } - else if (!$action_params =& $this->valid_actions[$action]) - { - $this->ajax_die('invalid action: '. $action); + } else if (!$action_params =& $this->valid_actions[$action]) { + $this->ajax_die('invalid action: ' . $action); } // Auth check - switch ($action_params[AJAX_AUTH]) - { + switch ($action_params[AJAX_AUTH]) { // GUEST case 'guest': break; // USER case 'user': - if (IS_GUEST) - { + if (IS_GUEST) { $this->ajax_die($lang['NEED_TO_LOGIN_FIRST']); } break; // MOD case 'mod': - if (!IS_AM) - { + if (!IS_AM) { $this->ajax_die($lang['ONLY_FOR_MOD']); } $this->check_admin_session(); @@ -153,8 +145,7 @@ class ajax_common // ADMIN case 'admin': - if (!IS_ADMIN) - { + if (!IS_ADMIN) { $this->ajax_die($lang['ONLY_FOR_ADMIN']); } $this->check_admin_session(); @@ -172,9 +163,9 @@ class ajax_common } /** - * Exit on error - */ - function ajax_die ($error_msg, $error_code = E_AJAX_GENERAL_ERROR) + * Exit on error + */ + function ajax_die($error_msg, $error_code = E_AJAX_GENERAL_ERROR) { $this->response['error_code'] = $error_code; $this->response['error_msg'] = $error_msg; @@ -183,23 +174,22 @@ class ajax_common } /** - * Initialization - */ - function init () + * Initialization + */ + function init() { $this->request = $_POST; - $this->action =& $this->request['action']; + $this->action =& $this->request['action']; } /** - * Send data - */ - function send () + * Send data + */ + function send() { $this->response['action'] = $this->action; - if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) - { + if (DBG_USER && SQL_DEBUG && !empty($_COOKIE['sql_log'])) { $this->response['sql_log'] = get_sql_log(); } @@ -208,24 +198,20 @@ class ajax_common } /** - * OB Handler - */ - function ob_handler ($contents) + * OB Handler + */ + function ob_handler($contents) { - if (DBG_USER) - { - if ($contents) - { + if (DBG_USER) { + if ($contents) { $this->response['raw_output'] = $contents; } } $response_js = bb_json_encode($this->response); - if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) - { - if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000) - { + if (GZIP_OUTPUT_ALLOWED && !defined('NO_GZIP')) { + if (UA_GZIP_SUPPORTED && strlen($response_js) > 2000) { header('Content-Encoding: gzip'); $response_js = gzencode($response_js, 1); } @@ -235,26 +221,21 @@ class ajax_common } /** - * Admin session - */ - function check_admin_session () + * Admin session + */ + function check_admin_session() { global $user; - if (!$user->data['session_admin']) - { - if (empty($this->request['user_password'])) - { + if (!$user->data['session_admin']) { + if (empty($this->request['user_password'])) { $this->prompt_for_password(); - } - else - { + } else { $login_args = array( 'login_username' => $user->data['username'], 'login_password' => $_POST['user_password'], ); - if (!$user->login($login_args, true)) - { + if (!$user->login($login_args, true)) { $this->ajax_die('Wrong password'); } } @@ -262,184 +243,161 @@ class ajax_common } /** - * Prompt for password - */ - function prompt_for_password () + * Prompt for password + */ + function prompt_for_password() { $this->response['prompt_password'] = 1; $this->send(); } /** - * Prompt for confirmation - */ - function prompt_for_confirm ($confirm_msg) + * Prompt for confirmation + */ + function prompt_for_confirm($confirm_msg) { - if(empty($confirm_msg)) $this->ajax_die('false'); + if (empty($confirm_msg)) $this->ajax_die('false'); $this->response['prompt_confirm'] = 1; $this->response['confirm_msg'] = $confirm_msg; $this->send(); } - /** - * Verify mod rights - */ - function verify_mod_rights ($forum_id) + /** + * Verify mod rights + */ + function verify_mod_rights($forum_id) { global $userdata, $lang; $is_auth = auth(AUTH_MOD, $forum_id, $userdata); - if (!$is_auth['auth_mod']) - { + if (!$is_auth['auth_mod']) { $this->ajax_die($lang['ONLY_FOR_MOD']); } } - function edit_user_profile () + function edit_user_profile() { - require(AJAX_DIR .'edit_user_profile.php'); + require(AJAX_DIR . 'edit_user_profile.php'); } - function change_user_rank () + function change_user_rank() { global $datastore, $lang; - $ranks = $datastore->get('ranks'); + $ranks = $datastore->get('ranks'); $rank_id = intval($this->request['rank_id']); - if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) - { + if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) { $this->ajax_die("invalid user_id: $user_id"); } - if ($rank_id != 0 && !isset($ranks[$rank_id])) - { + if ($rank_id != 0 && !isset($ranks[$rank_id])) { $this->ajax_die("invalid rank_id: $rank_id"); } - DB()->query("UPDATE ". BB_USERS ." SET user_rank = $rank_id WHERE user_id = $user_id LIMIT 1"); + DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id LIMIT 1"); cache_rm_user_sessions($user_id); - $this->response['html'] = ($rank_id != 0) ? $lang['AWARDED_RANK'] . ' '. $ranks[$rank_id]['rank_title'] .'' : $lang['SHOT_RANK']; + $this->response['html'] = ($rank_id != 0) ? $lang['AWARDED_RANK'] . ' ' . $ranks[$rank_id]['rank_title'] . '' : $lang['SHOT_RANK']; } - function change_user_opt () + function change_user_opt() { global $bf, $lang; - $user_id = (int) $this->request['user_id']; + $user_id = (int)$this->request['user_id']; $new_opt = bb_json_decode($this->request['user_opt']); - if (!$user_id OR !$u_data = get_userdata($user_id)) - { + if (!$user_id OR !$u_data = get_userdata($user_id)) { $this->ajax_die('invalid user_id'); } - if (!is_array($new_opt)) - { + if (!is_array($new_opt)) { $this->ajax_die('invalid new_opt'); } - foreach ($bf['user_opt'] as $opt_name => $opt_bit) - { - if (isset($new_opt[$opt_name])) - { + foreach ($bf['user_opt'] as $opt_name => $opt_bit) { + if (isset($new_opt[$opt_name])) { setbit($u_data['user_opt'], $opt_bit, !empty($new_opt[$opt_name])); } } - DB()->query("UPDATE ". BB_USERS ." SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id LIMIT 1"); + DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id LIMIT 1"); - // Удаляем данные из кеша - cache_rm_user_sessions ($user_id); + // Удаляем данные из кеша + cache_rm_user_sessions($user_id); $this->response['resp_html'] = $lang['SAVED']; } - function gen_passkey () + function gen_passkey() { global $userdata, $lang; - $req_uid = (int) $this->request['user_id']; + $req_uid = (int)$this->request['user_id']; - if ($req_uid == $userdata['user_id'] || IS_ADMIN) - { - if (empty($this->request['confirmed'])) - { + if ($req_uid == $userdata['user_id'] || IS_ADMIN) { + if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); } - if (!$passkey = generate_passkey($req_uid, IS_ADMIN)) - { + if (!$passkey = generate_passkey($req_uid, IS_ADMIN)) { $this->ajax_die('Could not insert passkey'); } tracker_rm_user($req_uid); $this->response['passkey'] = $passkey; - } - else $this->ajax_die($lang['NOT_AUTHORISED']); + } else $this->ajax_die($lang['NOT_AUTHORISED']); } - // User groups membership - function group_membership () + // User groups membership + function group_membership() { global $lang, $user; - if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) - { + if (!$user_id = intval($this->request['user_id']) OR !$profiledata = get_userdata($user_id)) { $this->ajax_die("invalid user_id: $user_id"); } - if (!$mode = (string) $this->request['mode']) - { + if (!$mode = (string)$this->request['mode']) { $this->ajax_die('invalid mode (empty)'); } - switch ($mode) - { + switch ($mode) { case 'get_group_list': $sql = " SELECT ug.user_pending, g.group_id, g.group_type, g.group_name, g.group_moderator, self.user_id AS can_view - FROM ". BB_USER_GROUP ." ug - INNER JOIN ". BB_GROUPS ." g ON(g.group_id = ug.group_id AND g.group_single_user = 0) - LEFT JOIN ". BB_USER_GROUP ." self ON(self.group_id = g.group_id AND self.user_id = {$user->id} AND self.user_pending = 0) + FROM " . BB_USER_GROUP . " ug + INNER JOIN " . BB_GROUPS . " g ON(g.group_id = ug.group_id AND g.group_single_user = 0) + LEFT JOIN " . BB_USER_GROUP . " self ON(self.group_id = g.group_id AND self.user_id = {$user->id} AND self.user_pending = 0) WHERE ug.user_id = $user_id ORDER BY g.group_name "; $html = array(); - foreach (DB()->fetch_rowset($sql) as $row) - { - $class = ($row['user_pending']) ? 'med' : 'med bold'; + foreach (DB()->fetch_rowset($sql) as $row) { + $class = ($row['user_pending']) ? 'med' : 'med bold'; $class .= ($row['group_moderator'] == $user_id) ? ' colorMod' : ''; - $href = "groupcp.php?g={$row['group_id']}"; + $href = "groupcp.php?g={$row['group_id']}"; - if (IS_ADMIN) - { + if (IS_ADMIN) { $href .= "&u=$user_id"; - $link = ''. htmlCHR($row['group_name']) .''; + $link = '' . htmlCHR($row['group_name']) . ''; $html[] = $link; - } - else - { + } else { // скрытая группа и сам юзер не является её членом - if ($row['group_type'] == GROUP_HIDDEN && !$row['can_view']) - { + if ($row['group_type'] == GROUP_HIDDEN && !$row['can_view']) { continue; } - if ($row['group_moderator'] == $user->id) - { + if ($row['group_moderator'] == $user->id) { $class .= ' selfMod'; - $href .= "&u=$user_id"; // сам юзер модератор этой группы + $href .= "&u=$user_id"; // сам юзер модератор этой группы } - $link = ''. htmlCHR($row['group_name']) .''; + $link = '' . htmlCHR($row['group_name']) . ''; $html[] = $link; } } - if ($html) - { - $this->response['group_list_html'] = '
K | '. profile_url($userdata) .' '. $lang['WROTE'] .': '. bbcode2html($text) .' |
! | '. profile_url($userdata) .' '. $lang['WROTE'] .': '. bbcode2html($text) .' |
K | ' . profile_url($userdata) . ' ' . $lang['WROTE'] . ': ' . bbcode2html($text) . ' |
! | ' . profile_url($userdata) . ' ' . $lang['WROTE'] . ': ' . bbcode2html($text) . ' |
+ | + |