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');
121 // public function upload()
123 // $this->load->library('form_validation');
125 // $this->form_validation->set_error_delimiters('<span class="error">',
127 // $error_upload = '';
129 // if ($this->form_validation->run('upload'))
131 // if ($_FILES['video-upload-file']['tmp_name'])
134 // $config_upload['upload_path'] = './data/upload';
135 // $this->load->library('upload', $config_upload);
137 // $b_validation = $this->upload->do_upload('video-upload-file');
139 // $this->upload->display_errors('<span class="error">',
144 // $b_validation = FALSE;
148 // $b_validation = FALSE;
150 // if ($b_validation === FALSE)
152 // $params = array('title' =>
153 // $this->lang->line('ui_nav_menu_upload')
155 // . $this->config->item('site_name'),
156 // //'metas' => array('description'=>'')
158 // $this->load->library('html_head_params', $params);
161 // // ** LOADING VIEWS
163 // $this->load->view('html_begin', $this->html_head_params);
164 // $this->load->view('header',
165 // array('selected_menu' => 'upload'));
167 // $main_params['content'] = $this->load->view(
168 // 'video/upload_view',
169 // array('error_upload'=> $error_upload),
171 // $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
172 // $this->load->view('main', $main_params);
174 // $this->load->view('footer');
175 // $this->load->view('html_end');
183 public function upload()
185 $this->load->library('form_validation');
187 $this->form_validation->set_error_delimiters('<span class="error">',
191 if ($this->form_validation->run('upload') === FALSE)
193 $params = array('title' =>
194 $this->lang->line('ui_nav_menu_upload')
196 . $this->config->item('site_name'),
197 //'metas' => array('description'=>'')
199 $this->load->library('html_head_params', $params);
204 $this->load->view('html_begin', $this->html_head_params);
205 $this->load->view('header',
206 array('selected_menu' => 'upload'));
208 $main_params['content'] = $this->load->view(
210 array('error_upload'=> $error_upload),
212 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
213 $this->load->view('main', $main_params);
215 $this->load->view('footer');
216 $this->load->view('html_end');
225 * Increments (dis)likes count for video with the specified id and returns to
226 * the client as plain text the number if likes.
228 * @param string $action 'like' or 'dislike'
229 * @param string $video_id
230 * @param string $user_id
232 public function ajax_vote($action, $video_id)
234 $video_id = intval($video_id);
235 $user_id = $this->session->userdata('user_id');
236 $this->load->model('videos_model');
238 $res = $this->videos_model->vote($video_id, $user_id,
239 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
245 * Increments (dis)likes count for a comment with a specified id and returns
246 * to the client as plain text the number if likes.
248 * @param string $action 'like' or 'dislike'
249 * @param string $comment_id
251 public function ajax_vote_comment($action, $comment_id)
253 $comment_id = intval($comment_id);
254 $user_id = $this->session->userdata('user_id');
255 $this->load->model('videos_model');
257 $res = $this->videos_model->vote_comment($comment_id, $user_id,
258 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
264 public function ajax_comment($video_id,
265 $ordering = 'newest', $offset = '0')
267 $this->_ajax_comment(FALSE, $video_id, $ordering, $offset);
270 public function _ajax_comment($return_output, $video_id,
271 $ordering = 'newest', $offset = '0')
273 $video_id = intval($video_id);
275 $this->load->library('form_validation');
276 $this->form_validation->set_error_delimiters('<span class="error">',
279 if ($this->form_validation->run('comment_video'))
281 $this->load->model('videos_model');
282 $user_id = intval($this->session->userdata('user_id'));
283 $comment = $this->input->post('comment');
285 $this->videos_model->comment_video($video_id, $user_id, $comment);
291 $this->load->model('videos_model');
292 $data['comments'] = $this->videos_model->get_video_comments($video_id,
293 $offset, $this->config->item('video_comments_per_page'), $ordering);
294 $data['comments_count'] =
295 $this->videos_model->get_video_comments_count($video_id);
296 $data['hottest_comments'] = $this->videos_model->get_video_comments(
297 $video_id, 0, 2, 'hottest');
298 $data['video_id'] = $video_id;
299 $data['user_id'] = $this->session->userdata('user_id');
302 $this->load->library('pagination');
303 $pg_config['base_url'] = site_url("video/ajax_comment/$video_id/$ordering/");
304 $pg_config['uri_segment'] = 5;
305 $pg_config['total_rows'] = $data['comments_count'];
306 $pg_config['per_page'] = $this->config->item('video_comments_per_page');
307 $this->pagination->initialize($pg_config);
308 $data['comments_pagination'] = $this->pagination->create_links();
313 $output = $this->load->view('video/comments_view',
314 $data, $return_output);
320 public function _is_user_loggedin($param)
322 if (! $this->session->userdata('user_id'))
328 public function _do_comment($comment)
330 // Note: Videos_model must be already loaded.
331 $this->load->model('videos_model');
333 $video_id = intval($this->input->post('video-id'));
334 $user_id = intval($this->session->userdata('user_id'));
336 $this->videos_model->comment_video($video_id, $user_id, $comment);
339 public function _valid_tags($tags)
341 $tok = strtok($tags, ',');
342 while ($tok != FALSE)
345 if (!ctype_alnum($tok))
354 public function _required_upload($file)
356 if ($_FILES['video-upload-file']['tmp_name'])
364 public function _valid_upload($file)
366 if ($_FILES['video-upload-file']['tmp_name'])
369 $config_upload = array();
370 $config_upload['upload_path'] = './data/upload';
371 $config_upload['allowed_types'] = '*';
372 $this->load->library('upload', $config_upload);
374 if ($this->upload->do_upload('video-upload-file'))
379 $this->form_validation->set_message('_valid_upload',
380 $this->upload->display_errors('<span class="error">',
388 * OBSOLETE: AJAX page which retrieves a video plugin.
390 * The view associated with this controller should be parameter type
391 * concatenated with '_plugin_view' and must be located in
392 * 'application/views/video'.
394 * @param string $type 'ns-vlc', 'ns-html5'
396 public function plugin($type)
398 $url = $this->input->post('url', TRUE);
400 $this->_plugin($type, $url);
404 * OBSOLETE: Video plugin controller
406 * See plugin function for details. If the second parameter is TRUE
407 * the output is return instead of being displayed (used in preloading).
409 public function _plugin($type, $url, $return_output=FALSE)
411 if ($type == 'ns-html5')
412 $data['url'] = 'tribe://' . $url;
413 else if ($type == 'ns-vlc')
416 $output = $this->load->view('video/'. $type . '_plugin_view', $data,
425 /* End of file video.php */
426 /* Location: ./application/controllers/video.php */