Ejemplo n.º 1
0
 function index()
 {
     $ajax = isset($_POST['ajax']);
     $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
     $this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
     $this->form_validation->set_rules('category[]', 'Category', 'required|exact_length[1]|integer');
     $this->form_validation->set_rules('content', 'Content', 'trim|required');
     if ($this->form_validation->run()) {
         $subject = $this->form_validation->set_value('subject');
         $content = $this->form_validation->set_value('content');
         $category = $this->form_validation->set_value('category[]');
         $comment = array('user_id' => $this->session->userdata('user_id'), 'category' => (int) $category[0], 'subject' => $subject, 'content' => _process_post($content), 'original_content' => $content);
         $comment['thread_id'] = $this->thread_dal->new_thread($comment);
         $this->user_dal->update_thread_count($comment['user_id']);
         $this->thread_dal->new_comment($comment);
         $url = '/thread/' . $comment['thread_id'] . '/' . url_title($subject, 'dash', TRUE);
         if ($ajax) {
             return send_json($this->output, 201, array('ok' => true, 'url' => $url));
         } else {
             redirect($url);
         }
     } else {
         if ($_SERVER['REQUEST_METHOD'] === 'POST' && $ajax) {
             return send_json($this->output, 400, array('error' => true, 'reason' => validation_errors()));
         }
     }
     $this->load->view('shared/header');
     $this->load->view('newthread');
     $this->load->view('shared/footer');
 }
Ejemplo n.º 2
0
 /**
  * Get a count of all the comments for a given thread id
  *
  * @param	int
  * @param	int
  */
 private function get_comments($thread_id)
 {
     $sql = "SELECT\n\t\t\t\tSQL_CALC_FOUND_ROWS\n\t      comments.comment_id,\n\t      comments.content,\n\t      comments.original_content,\n\t      comments.created,\n\t      comments.deleted,\n\t      comments.user_id AS author_id,\n\t      users.username AS author_name,\n\t      users.banned AS author_banned,\n\t      users.emoticon,\n\t      IFNULL(acquaintances.type, 0) AS author_acquaintance_type\n\t    FROM comments\n\t    LEFT JOIN users\n\t      ON comments.user_id = users.id\n\t    LEFT JOIN acquaintances\n\t      ON acquaintances.acq_user_id = users.id\n\t      AND acquaintances.user_id = ?\n\t    WHERE comments.thread_id = ?\n\t    ORDER BY comments.created\n\t    LIMIT ?, ?";
     $result = $this->db->query($sql, array($this->meta['user_id'], $thread_id, $this->page, $this->meta['comments_shown']));
     if (!$result->num_rows()) {
         return NULL;
     } else {
         $return = array();
         $i = 0;
         foreach ($result->result() as $row) {
             if ($row->deleted == '0') {
                 $return[$i] = (object) array('comment_id' => $row->comment_id, 'content' => $row->content, 'created' => strtotime($row->created), 'deleted' => 0, 'author_id' => (int) $row->author_id, 'author_name' => $row->author_name, 'author_banned' => (bool) $row->author_banned, 'url_safe_author_name' => url_title($row->author_name, 'dash'), 'emoticon' => (bool) $row->emoticon, 'author_acquaintance_type' => (int) $row->author_acquaintance_type, 'author_acquaintance_name' => $row->author_acquaintance_type == 1 ? 'buddy' : ($row->author_acquaintance_type == 2 ? 'enemy' : NULL), 'owner' => $this->meta['user_id'] == $row->author_id, 'editable' => $this->meta['user_id'] == $row->author_id && $row->created < time() - 60 * 60 * 24, 'show_controls' => $this->page == 0 && $this->meta['user_id'] == $row->author_id && !$i);
                 // update comments if the content doesnt match original
                 if ($row->content === '' && $row->content == _process_post($row->original_content)) {
                     $return[$i]->content = _process_post($row->original_content);
                     $this->db->query("UPDATE comments SET content = ? WHERE comment_id = ?", array($return[$i]->content, $row->comment_id));
                 }
                 if ($return[$i]->author_acquaintance_type == 2) {
                     ++$this->return->information->enemies;
                 }
             } else {
                 $return[$i] = (object) array('comment_id' => (int) $row->comment_id, 'created' => $row->created, 'deleted' => 1);
             }
             ++$i;
         }
         return $return;
     }
 }
Ejemplo n.º 3
0
 function load($thread_id)
 {
     $segments = $this->uri->segment_array();
     while ($seg = next($segments)) {
         if ($seg == 'p') {
             $page = (int) next($segments);
         }
     }
     if (!isset($page)) {
         $page = 0;
     }
     $thread = $this->thread_model->get_thread($thread_id, $this->meta, $page);
     $uri = '/thread/' . $thread_id . '/' . url_title($thread->information->subject, 'dash', TRUE);
     // if they roll in with something unexpected
     // or the thread doesnt exist
     // send them home
     if ($thread == null) {
         redirect('/');
     }
     // if the thread is closed then we're not accepting any new data
     if (!$thread->information->closed || $thread->information->author_acquaintance_type == 2) {
         // we're going to go ahead and do the form processing for the reply now
         // if they're submitting data, we're going to refresh the page anyways
         // so theres no point in running the query below the form validation
         $this->form_validation->set_rules('content', 'Content', 'required');
         $this->form_validation->set_rules('ajax', 'ajax');
         // if a comment was submitted
         if ($this->form_validation->run()) {
             $content = $this->form_validation->set_value('content');
             $ajax = $this->form_validation->set_value('ajax');
             $comment_id = $this->thread_model->new_comment((object) array('thread_id' => $thread_id, 'user_id' => $this->meta['user_id'], 'content' => _process_post($content), 'original_content' => $content));
             $this->user_dal->update_comment_count($this->meta['user_id']);
             $this->thread_model->update_comment_count($thread_id);
             $shown = $this->meta['comments_shown'];
             $last_page = ceil(($thread->information->comment_count + 1) / $this->meta['comments_shown']) * $this->meta['comments_shown'] - $this->meta['comments_shown'];
             // Append some unique junk to make sure the page path is different,
             // otherwise wont redirecr
             $redirection = $uri . '/p/' . $last_page . '/' . '#bottom';
             if ($ajax || $this->is_request_json()) {
                 return send_json($this->output, 201, array('ok' => true, 'url' => $redirection, 'comment_id' => $comment_id, 'thread_id' => $thread_id));
             } else {
                 redirect($redirection);
             }
         }
     }
     $this->pagination->initialize(array('num_links' => 3, 'base_url' => $uri .= '/p/', 'total_rows' => $thread->information->comment_count, 'uri_segment' => 5, 'per_page' => $this->meta['comments_shown'], 'full_tag_open' => '<div class="main-pagination">', 'full_tag_close' => '</div>', 'cur_tag_open' => '<div class="selected-page">', 'cur_tag_close' => '</div>', 'num_tag_open' => '', 'num_tag_close' => ''));
     $uri .= isset($uri_assoc['p']) ? (int) $uri_assoc['p'] : 0;
     $thread->pagination = (object) array('links' => $this->pagination->create_links(), 'lower_limit' => $page + 1, 'upper_limit' => min(array($page + $this->meta['comments_shown'], $thread->information->comment_count)), 'category' => '<a href="/f/' . strtolower($thread->information->category) . '">' . $thread->information->category . '</a>', 'thread' => '<a href="/thread/' . $thread_id . '/' . url_title($thread->information->subject, 'dash', TRUE) . '">' . $thread->information->subject . '</a>');
     $thread->pagination_object = $this->pagination;
     $thread->pagination_row_offset = (int) $page;
     $thread->information->page = $page;
     $this->load->helper('content_render');
     $this->load->view('shared/header', array('page_title' => $thread->information->subject));
     $this->load->view('thread', $thread);
     $this->load->view('shared/footer');
 }
Ejemplo n.º 4
0
 function preview()
 {
     echo _process_post($this->input->post('content'));
 }