public function __construct() { parent::__construct(); $this->load->model('comment_m'); $this->load->model('topic_m'); $this->load->model('notification_m'); $this->load->model('user_m'); $this->load->helper('auth'); is_login_exit(); is_user_active_exit(); }
/** * 添加新主题 */ public function add() { $this->load->helper('auth'); is_login_exit(); is_user_active_exit(); $this->load->helper('form'); $this->load->library('form_validation'); $this->load->model('node_m'); $this->form_validation->set_rules('title', '标题', 'trim|required|min_length[4]'); $this->form_validation->set_rules('nid', '节点', 'required'); $this->form_validation->set_rules('content'); if ($this->form_validation->run() == FALSE) { //form failed $data['nodes'] = $this->node_m->get_nodes(); $data['site_title'] = '创建新主题'; $this->load->view('topic_add', $data); } else { //form success $node = $this->node_m->get_node_byid($this->input->post('nid')); if (!$node) { $string = ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script> alert("无法向不存在的节点添加主题"); top.location="' . $this->input->server('HTTP_REFERER') . '"; </script> '; exit($string); } $this->load->model('site_m'); $site_settings = $this->site_m->get_site_settings(); $this->load->library('XssHtml'); $this->xsshtml->inputHtml($this->input->post('content')); $data = array('nid' => $this->input->post('nid'), 'uid' => $this->session->userdata('uid'), 'title' => htmlspecialchars($this->input->post('title')), 'content' => $this->xsshtml->getHtml(), 'addtime' => time(), 'replytime' => time(), 'status' => $site_settings['site_topic_status']); $insert_id = $this->topic_m->add($data); //更新用户发表帖子数量 $this->db->set('topic', 'topic+1', FALSE)->where('uid', $this->session->userdata('uid'))->update('letsbbs_user'); //更新网站统计信息 主题 $this->db->set('ovalue', 'ovalue+1', FALSE)->where('oname', 'site_topic_number')->update('letsbbs_option'); redirect('topic/' . $insert_id); } }