4 * Class Video controls video items handling: watching, commenting, rating,
8 * @author Călin-Andrei Burloiu
10 class Video extends CI_Controller {
12 public function __construct()
14 parent::__construct();
16 $this->lang->load('video');
19 public function index()
24 public function test($video_id)
27 $params = array( 'title' => $this->config->item('site_name'),
32 'jquery.ui.ajax_links_maker.js'
34 //'metas' => array('description'=>'','keywords'=>'')
36 $this->load->library('html_head_params', $params);
41 $this->load->view('html_begin', $this->html_head_params);
42 $this->load->view('header');
44 $main_params['content'] =
45 $this->load->view('echo', array('output'=>
46 $this->_ajax_comment(TRUE, $video_id)),
48 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
49 $this->load->view('main', $main_params);
51 $this->load->view('footer');
52 $this->load->view('html_end');
56 * The page used for watching a video
58 * @param string $id DB id of the video
59 * @param string $name `name` of the video from DB
60 * @param string $plugin video plugin ('ns-vlc', 'ns-html5'). If it's set
61 * to NULL or 'auto', the plugin is automatically selected.
63 public function watch($id, $name = NULL, $plugin = NULL)
68 // Retrieve video information.
69 $this->load->model('videos_model');
70 $this->videos_model->inc_views($id);
71 $data['video'] = $this->videos_model->get_video($id, $name);
72 $categories = $this->config->item('categories');
73 $data['video']['category_name'] =
74 $categories[ $data['video']['category_id'] ];
75 $data['plugin_type'] = ($plugin === NULL ? 'auto' : $plugin);
76 $data['user_id'] = $this->session->userdata('user_id');
77 if ($data['user_id'] === FALSE)
78 $data['user_id'] = '';
81 $params = array( 'title' => $data['video']['title'] . ' – '
82 . $this->config->item('site_name'),
84 'jquery.ui.nsvideo.css',
88 'jquery.ui.nsvideo.js',
89 'jquery.ui.ajax_links_maker.js'
91 //'metas' => array('description'=>'','keywords'=>'')
93 $this->load->library('html_head_params', $params);
95 // Preloading video plugin.
96 // TODO plugin auto: type and format
97 if ($data['plugin_type'] == 'auto')
98 $data['plugin_type'] = 'ns-html5';
99 $data['asset_index'] = 0;
101 // TODO remove old AJAX plugin content
102 // $data['plugin_content'] = $this->_plugin('ns-html5',
103 // $data['video']['url'][0], TRUE);
106 $data['comments'] = $this->_ajax_comment(TRUE, $id);
111 $this->load->view('html_begin', $this->html_head_params);
112 $this->load->view('header');
114 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
115 $this->load->view('video/watch_view', $data);
117 $this->load->view('footer');
118 $this->load->view('html_end');
122 * Increments (dis)likes count for video with the specified id and returns to
123 * the client as plain text the number if likes.
125 * @param string $action 'like' or 'dislike'
126 * @param string $video_id
127 * @param string $user_id
129 public function ajax_vote($action, $video_id)
131 $video_id = intval($video_id);
132 $user_id = $this->session->userdata('user_id');
133 $this->load->model('videos_model');
135 $res = $this->videos_model->vote($video_id, $user_id,
136 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
142 * Increments (dis)likes count for a comment with a specified id and returns
143 * to the client as plain text the number if likes.
145 * @param string $action 'like' or 'dislike'
146 * @param string $comment_id
148 public function ajax_vote_comment($action, $comment_id)
150 $comment_id = intval($comment_id);
151 $user_id = $this->session->userdata('user_id');
152 $this->load->model('videos_model');
154 $res = $this->videos_model->vote_comment($comment_id, $user_id,
155 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
161 public function ajax_comment($video_id,
162 $ordering = 'newest', $offset = '0')
164 $this->_ajax_comment(FALSE, $video_id, $ordering, $offset);
167 public function _ajax_comment($return_output, $video_id,
168 $ordering = 'newest', $offset = '0')
170 $video_id = intval($video_id);
172 $this->load->library('form_validation');
173 $this->form_validation->set_error_delimiters('<span class="error">',
176 if ($this->form_validation->run('comment_video'))
178 $this->load->model('videos_model');
179 $user_id = intval($this->session->userdata('user_id'));
180 $comment = $this->input->post('comment');
182 $this->videos_model->comment_video($video_id, $user_id, $comment);
188 $this->load->model('videos_model');
189 $data['comments'] = $this->videos_model->get_video_comments($video_id,
190 $offset, $this->config->item('video_comments_per_page'), $ordering);
191 $data['comments_count'] =
192 $this->videos_model->get_video_comments_count($video_id);
193 $data['hottest_comments'] = $this->videos_model->get_video_comments(
194 $video_id, 0, 2, 'hottest');
195 $data['video_id'] = $video_id;
196 $data['user_id'] = $this->session->userdata('user_id');
199 $this->load->library('pagination');
200 $pg_config['base_url'] = site_url("video/ajax_comment/$video_id/$ordering/");
201 $pg_config['uri_segment'] = 5;
202 $pg_config['total_rows'] = $data['comments_count'];
203 $pg_config['per_page'] = $this->config->item('video_comments_per_page');
204 $this->pagination->initialize($pg_config);
205 $data['comments_pagination'] = $this->pagination->create_links();
210 $output = $this->load->view('video/comments_view',
211 $data, $return_output);
217 public function _is_user_loggedin($param)
219 if (! $this->session->userdata('user_id'))
225 public function _do_comment($comment)
227 // Note: Videos_model must be already loaded.
228 $this->load->model('videos_model');
230 $video_id = intval($this->input->post('video-id'));
231 $user_id = intval($this->session->userdata('user_id'));
233 $this->videos_model->comment_video($video_id, $user_id, $comment);
237 * OBSOLETE: AJAX page which retrieves a video plugin.
239 * The view associated with this controller should be parameter type
240 * concatenated with '_plugin_view' and must be located in
241 * 'application/views/video'.
243 * @param string $type 'ns-vlc', 'ns-html5'
245 public function plugin($type)
247 $url = $this->input->post('url', TRUE);
249 $this->_plugin($type, $url);
253 * OBSOLETE: Video plugin controller
255 * See plugin function for details. If the second parameter is TRUE
256 * the output is return instead of being displayed (used in preloading).
258 public function _plugin($type, $url, $return_output=FALSE)
260 if ($type == 'ns-html5')
261 $data['url'] = 'tribe://' . $url;
262 else if ($type == 'ns-vlc')
265 $output = $this->load->view('video/'. $type . '_plugin_view', $data,
274 /* End of file video.php */
275 /* Location: ./application/controllers/video.php */