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()
25 * The page used for watching a video
27 * @param string $id DB id of the video
28 * @param string $name `name` of the video from DB
29 * @param string $plugin video plugin ('ns-vlc', 'ns-html5'). If it's set
30 * to NULL or 'auto', the plugin is automatically selected.
32 public function watch($id, $name = NULL, $plugin = NULL)
37 // Retrieve video information.
38 $this->load->model('videos_model');
39 $this->videos_model->inc_views($id);
40 $data['video'] = $this->videos_model->get_video($id, $name);
41 $categories = $this->config->item('categories');
42 $data['video']['category_name'] =
43 $categories[ $data['video']['category_id'] ];
44 $data['plugin_type'] = ($plugin === NULL ? 'auto' : $plugin);
45 $data['user_id'] = $this->session->userdata('user_id');
46 if ($data['user_id'] === FALSE)
47 $data['user_id'] = '';
50 $params = array( 'title' => $data['video']['title'] . ' – '
51 . $this->config->item('site_name'),
53 'jquery.ui.nsvideo.css',
57 'jquery.ui.nsvideo.js'
59 //'metas' => array('description'=>'','keywords'=>'')
61 $this->load->library('html_head_params', $params);
63 // Preloading video plugin.
64 // TODO plugin auto: type and format
65 if ($data['plugin_type'] == 'auto')
66 $data['plugin_type'] = 'ns-html5';
67 $data['asset_index'] = 0;
69 // TODO remove old AJAX plugin content
70 // $data['plugin_content'] = $this->_plugin('ns-html5',
71 // $data['video']['url'][0], TRUE);
76 $this->load->view('html_begin', $this->html_head_params);
77 $this->load->view('header');
79 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
80 $this->load->view('video/watch_view', $data);
82 $this->load->view('footer');
83 $this->load->view('html_end');
87 * Increments likes count for video with the specified id and returns to
88 * the client as plain text the number if likes.
90 * @param string $action 'like' or 'dislike'
91 * @param string $video_id
92 * @param string $user_id
94 public function ajax_vote($action, $video_id, $user_id = NULL)
96 $video_id = intval($video_id);
97 $user_id = intval($user_id);
98 $this->load->model('videos_model');
100 $res = $this->videos_model->vote($video_id, $user_id,
101 (strcmp($action, 'like') == 0 ? TRUE : FALSE));
108 * AJAX page which retrieves a video plugin.
110 * The view associated with this controller should be parameter type
111 * concatenated with '_plugin_view' and must be located in
112 * 'application/views/video'.
114 * @param string $type 'ns-vlc', 'ns-html5'
116 public function plugin($type)
118 $url = $this->input->post('url', TRUE);
120 $this->_plugin($type, $url);
124 * Video plugin controller
126 * See plugin function for details. If the second parameter is TRUE
127 * the output is return instead of being displayed (used in preloading).
129 public function _plugin($type, $url, $return_output=FALSE)
131 if ($type == 'ns-html5')
132 $data['url'] = 'tribe://' . $url;
133 else if ($type == 'ns-vlc')
136 $output = $this->load->view('video/'. $type . '_plugin_view', $data,
145 /* End of file video.php */
146 /* Location: ./application/controllers/video.php */