+ public function ajax_comment($video_id,
+ $ordering = 'newest', $offset = '0')
+ {
+ $this->_ajax_comment(FALSE, $video_id, $ordering, $offset);
+ }
+
+ public function _ajax_comment($return_output, $video_id,
+ $ordering = 'newest', $offset = '0')
+ {
+ $video_id = intval($video_id);
+
+ $this->load->library('form_validation');
+ $this->form_validation->set_error_delimiters('<span class="error">',
+ '</span>');
+
+ if ($this->form_validation->run('comment_video'))
+ {
+ $this->load->model('videos_model');
+ $user_id = intval($this->session->userdata('user_id'));
+ $comment = $this->input->post('comment');
+
+ $this->videos_model->comment_video($video_id, $user_id, $comment);
+ }
+
+ // **
+ // ** MODEL **
+ // **
+ $this->load->model('videos_model');
+ $data['comments'] = $this->videos_model->get_video_comments($video_id,
+ $offset, $this->config->item('video_comments_per_page'), $ordering);
+ $data['comments_count'] =
+ $this->videos_model->get_video_comments_count($video_id);
+ $data['hottest_comments'] = $this->videos_model->get_video_comments(
+ $video_id, 0, 2, 'hottest');
+ $data['video_id'] = $video_id;
+ $data['user_id'] = $this->session->userdata('user_id');
+
+ // Pagination
+ $this->load->library('pagination');
+ $pg_config['base_url'] = site_url("video/ajax_comment/$video_id/$ordering/");
+ $pg_config['uri_segment'] = 5;
+ $pg_config['total_rows'] = $data['comments_count'];
+ $pg_config['per_page'] = $this->config->item('video_comments_per_page');
+ $this->pagination->initialize($pg_config);
+ $data['comments_pagination'] = $this->pagination->create_links();
+
+ // **
+ // ** VIEWS **
+ // **
+ $output = $this->load->view('video/comments_view',
+ $data, $return_output);
+
+ if ($return_output)
+ return $output;
+ }
+
+ public function _is_user_loggedin($param)
+ {
+ if (! $this->session->userdata('user_id'))
+ return FALSE;
+
+ return TRUE;
+ }
+
+ public function _do_comment($comment)
+ {
+ // Note: Videos_model must be already loaded.
+ $this->load->model('videos_model');
+
+ $video_id = intval($this->input->post('video-id'));
+ $user_id = intval($this->session->userdata('user_id'));
+
+ $this->videos_model->comment_video($video_id, $user_id, $comment);
+ }
+
+ public function _valid_tags($tags)
+ {
+ $tok = strtok($tags, ',');
+ while ($tok != FALSE)
+ {
+ $tok = trim($tok);
+ if (!ctype_alnum($tok))
+ return FALSE;
+
+ $tok = strtok(',');
+ }
+
+ return TRUE;
+ }
+
+ public function _required_upload($file)
+ {
+ if ($_FILES['video-upload-file']['tmp_name'])
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ public function _valid_upload($file)
+ {
+ if ($_FILES['video-upload-file']['tmp_name'])
+ {
+ // Upload library
+ $config_upload = array();
+ $config_upload['upload_path'] = './data/upload';
+ $config_upload['allowed_types'] = '*';
+ $this->load->library('upload', $config_upload);
+
+ if ($this->upload->do_upload('video-upload-file'))
+ {
+ return TRUE;
+ }
+
+ $this->form_validation->set_message('_valid_upload',
+ $this->upload->display_errors('<span class="error">',
+ '</span>'));
+ }
+
+ return FALSE;
+ }
+