Example #1
0
 /**
  * Topic Reply
  *
  * Post a reply to a topic
  *
  * @access  public
  * @param   int
  * @return  json
  */
 public function topic_reply($topic_id = 0)
 {
     if (!$this->session->userdata('user_id')) {
         redirect('signin');
     }
     if (is_numeric($topic_id)) {
         $topic_data = $this->forum_engine->get_topic_data($topic_id);
     } else {
         show_error('The topic id must be a valid number!');
     }
     $this->load->helper('forum');
     $this->load->library('form_validation');
     $this->load->model('user_engine');
     $this->form_validation->set_rules('message', 'Message', 'required|xss_clean|addslashes');
     if ($topic_data == FALSE) {
         show_404('forum');
     } elseif ($topic_data['staff'] == 1) {
         if ($this->session->userdata('user_level') == 'user' || !$this->system->is_staff()) {
             $this->system->yield('error', lang('header_staff_only'), lang('staff_only_error'));
             return;
         }
     } elseif ($topic_data['topic_status'] == 'locked') {
         $this->system->yield('error', 'Topic locked!', 'Replies cannot be made to locked topics.');
         return;
     }
     if ($this->form_validation->run() == TRUE) {
         $message = htmlspecialchars($this->input->post('message'));
         if ($message == $this->cache->get('old_message_topic:' . $this->system->userdata['user_id'])) {
             if ($topic_data['total_posts'] > 11) {
                 show_error('You cannot post the same thing twice in a row!');
             }
         }
         $this->cache->save('old_message_topic:' . $this->system->userdata['user_id'], $message, 60);
         $last_id = $this->forum_engine->create_post($message, $topic_data, $this->system->userdata['user_id']);
         if ($topic_data['palladium_enabled'] == 1) {
             $palladium = parse_earned_palladium($message);
             $this->user_engine->add('user_palladium', $palladium);
             // This is for events only
             // $this->db->set('special_currency', '(special_currency+1)', FALSE)->where('user_id', $this->system->userdata['user_id'])->update('users');
         } elseif ($topic_data['forum_id'] == 32) {
             $this->user_engine->add('user_palladium', 1);
         } else {
             $palladium = 0;
         }
         $this->cache->save('topic_total_posts' . $topic_id, $topic_data['total_posts'] + 1, 2400);
         $page_id = get_topic_page($topic_data['total_posts']);
         $full_replies = array();
         preg_match_all('/@([A-Za-z0-9\\s]+):\\s((\\w+\\s){0,}\\w+.)/', $message, $replies);
         if (isset($replies[0]) && count($replies[0]) > 0) {
             foreach ($replies[0] as $key => $reply) {
                 $full_replies[strtolower($replies[1][$key])] = $replies[2][$key];
             }
             $reply_users = $this->db->select('user_id, username')->where_in('username', array_keys($full_replies))->limit(count($full_replies))->get('users');
             foreach ($reply_users->result_array() as $user) {
                 $string = $full_replies[strtolower($user['username'])];
                 $reply = strlen($string) > 18 ? substr($string, 0, 18) . '...' : $string;
                 $this->notification->broadcast(array('receiver' => $user['username'], 'receiver_id' => $user['user_id'], 'notification_text' => $this->system->userdata['username'] . ' mentioned you: ' . $reply, 'attachment_id' => $last_id, 'attatchment_type' => 'mention', 'attatchment_url' => '/topic/view/' . $topic_id . '/' . $page_id . '#' . $last_id), FALSE);
             }
         }
         if ($this->input->is_ajax_request() == TRUE) {
             $json['post_html'] = $this->load->view('forum/partials/post_template', array('post' => array('post_body' => parse_bbcode(stripslashes(nl2br($this->input->post('message')))), 'user_signature' => parse_bbcode(stripslashes(nl2br($this->system->userdata['user_signature']))), 'username' => $this->system->userdata['username'], 'post_id' => $last_id, 'user_id' => $this->system->userdata['user_id'], 'last_action' => time(), 'donated' => $this->system->userdata['donated'], 'user_level' => $this->system->userdata['user_level'], 'post_time' => date("Y-m-d H:i:s", time()))), TRUE);
             $this->output->set_content_type('application/json')->set_output(json_encode($json, JSON_NUMERIC_CHECK));
         } else {
             redirect('topic/view/' . $topic_id . '/' . $page_id . '#footer');
         }
     }
 }
Example #2
0
 <?php 
        echo $topic['total_posts'] > 1 ? 'replies' : 'reply';
        ?>
				</td>
				<td>
					<span class="large"><?php 
        echo human_time($topic['last_post']);
        ?>
</span>
					<br />
					by <?php 
        echo substr($topic['last_post_username'], 0, 18);
        ?>
 |
					<?php 
        echo anchor('topic/view/' . $topic['topic_id'] . '/' . get_topic_page($topic['total_posts']) . '/#footer', 'View post &rsaquo;');
        ?>
					<?php 
        if ($staff == true) {
            ?>
					<div class="checkbox_holder">
						<input class="multi_select" type="checkbox" name="topic_id[]" value="<?php 
            echo $topic['topic_id'];
            ?>
" />
					</div>
					<?php 
        }
        ?>
				</td>
			</tr>