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'),
33 //'metas' => array('description'=>'','keywords'=>'')
35 $this->load->library('html_head_params', $params);
40 $this->load->view('html_begin', $this->html_head_params);
41 $this->load->view('header');
43 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
44 $this->load->view('echo', array('output'=>
45 $this->_ajax_comment(TRUE, $video_id)));
47 $this->load->view('footer');
48 $this->load->view('html_end');
52 * The page used for watching a video
54 * @param string $id DB id of the video
55 * @param string $name `name` of the video from DB
56 * @param string $plugin video plugin ('ns-vlc', 'ns-html5'). If it's set
57 * to NULL or 'auto', the plugin is automatically selected.
59 public function watch($id, $name = NULL, $plugin = NULL)
64 // Retrieve video information.
65 $this->load->model('videos_model');
66 $this->videos_model->inc_views($id);
67 $data['video'] = $this->videos_model->get_video($id, $name);
68 $categories = $this->config->item('categories');
69 $data['video']['category_name'] =
70 $categories[ $data['video']['category_id'] ];
71 $data['plugin_type'] = ($plugin === NULL ? 'auto' : $plugin);
72 $data['user_id'] = $this->session->userdata('user_id');
73 if ($data['user_id'] === FALSE)
74 $data['user_id'] = '';
77 $params = array( 'title' => $data['video']['title'] . ' – '
78 . $this->config->item('site_name'),
80 'jquery.ui.nsvideo.css',
84 'jquery.ui.nsvideo.js'
86 //'metas' => array('description'=>'','keywords'=>'')
88 $this->load->library('html_head_params', $params);
90 // Preloading video plugin.
91 // TODO plugin auto: type and format
92 if ($data['plugin_type'] == 'auto')
93 $data['plugin_type'] = 'ns-html5';
94 $data['asset_index'] = 0;
96 // TODO remove old AJAX plugin content
97 // $data['plugin_content'] = $this->_plugin('ns-html5',
98 // $data['video']['url'][0], TRUE);
103 $this->load->view('html_begin', $this->html_head_params);
104 $this->load->view('header');
106 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
107 $this->load->view('video/watch_view', $data);
109 $this->load->view('footer');
110 $this->load->view('html_end');
114 * Increments likes count for video with the specified id and returns to
115 * the client as plain text the number if likes.
117 * @param string $action 'like' or 'dislike'
118 * @param string $video_id
119 * @param string $user_id
121 public function ajax_vote($action, $video_id, $user_id = NULL)
123 $video_id = intval($video_id);
124 $user_id = intval($user_id);
125 $this->load->model('videos_model');
127 $res = $this->videos_model->vote($video_id, $user_id,
128 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
134 public function ajax_comment($video_id,
135 $ordering = 'newest', $offset = '0')
137 $this->_ajax_comment(FALSE, $video_id, $ordering, $offset);
140 public function _ajax_comment($return_output, $video_id,
141 $ordering = 'newest', $offset = '0')
143 $video_id = intval($video_id);
145 $this->load->library('form_validation');
146 $this->form_validation->set_error_delimiters('<span class="error">',
148 $this->form_validation->run('comment_video');
153 $this->load->model('videos_model');
154 $data['comments'] = $this->videos_model->get_video_comments($video_id,
155 $offset, $this->config->item('video_comments_per_page'), $ordering);
156 $data['comments_count'] =
157 $this->videos_model->get_video_comments_count($video_id);
158 $data['video_id'] = $video_id;
161 $this->load->library('pagination');
162 $pg_config['base_url'] = site_url("video/ajax_comment/$video_id/$ordering/");
163 $pg_config['uri_segment'] = 5;
164 $pg_config['total_rows'] = $data['comments_count'];
165 $pg_config['per_page'] = $this->config->item('video_comments_per_page');
166 $this->pagination->initialize($pg_config);
167 $data['comments_pagination'] = $this->pagination->create_links();
172 $output = $this->load->view('video/comments_view',
173 $data, $return_output);
179 public function _is_user_loggedin($param)
181 if (! $this->session->userdata('user_id'))
187 public function _do_comment($comment)
189 // Note: Videos_model must be already loaded.
190 $this->load->model('videos_model');
192 $video_id = intval($this->input->post('video-id'));
193 $user_id = intval($this->session->userdata('user_id'));
195 $this->videos_model->comment_video($video_id, $user_id, $comment);
199 * OBSOLETE: AJAX page which retrieves a video plugin.
201 * The view associated with this controller should be parameter type
202 * concatenated with '_plugin_view' and must be located in
203 * 'application/views/video'.
205 * @param string $type 'ns-vlc', 'ns-html5'
207 public function plugin($type)
209 $url = $this->input->post('url', TRUE);
211 $this->_plugin($type, $url);
215 * OBSOLETE: Video plugin controller
217 * See plugin function for details. If the second parameter is TRUE
218 * the output is return instead of being displayed (used in preloading).
220 public function _plugin($type, $url, $return_output=FALSE)
222 if ($type == 'ns-html5')
223 $data['url'] = 'tribe://' . $url;
224 else if ($type == 'ns-vlc')
227 $output = $this->load->view('video/'. $type . '_plugin_view', $data,
236 /* End of file video.php */
237 /* Location: ./application/controllers/video.php */