first stage finished: ready to publish to production; does not support users and...
[living-lab-site.git] / application / controllers / video.php
1 <?php
2
3 /**
4  * Class Video controls video items handling: watching, commenting, rating,
5  * adding etc.
6  *
7  * @category    Controller
8  * @author              Călin-Andrei Burloiu
9  */
10 class Video extends CI_Controller {
11
12         public function __construct()
13         {
14                 parent::__construct();
15                 
16                 //$this->lang->load('video');
17         }
18         
19         public function index()
20         {
21                 
22         }
23         
24         /**
25          * The page used for watching a video
26          *
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.
31          */
32         public function watch($id, $name = NULL, $plugin = NULL)
33         {
34                 $this->load->helper('url');
35                 
36                 // **
37                 // ** LOADING MODEL
38                 // **
39                 // Retrieve video information.
40                 $this->load->model('videos_model');
41                 $this->videos_model->inc_video_var($id, 'views');
42                 $data['video'] = $this->videos_model->get_video($id, $name);
43                 $categories = $this->config->item('categories');
44                 $data['video']['category_name'] = 
45                         $categories[ $data['video']['category_id'] ];
46                 $data['plugin_type'] = ($plugin === NULL ? 'auto' : $plugin);
47                 
48                 // Display page.
49                 $params = array(        'title' => $data['video']['title'] . ' -- '
50                                                                 . $this->config->item('site_name'),
51                                                         'css' => array(
52                                                                 'jquery.ui.nsvideo.css',
53                                                                 'video.css'
54                                                         ),
55                                                         'js' => array(
56                                                                 'jquery.ui.nsvideo.js'
57                                                         ),
58                                                         //'metas' => array('description'=>'','keywords'=>'')
59                                                         );
60                 $this->load->library('html_head_params', $params);
61                 
62                 // Preloading video plugin.
63                 // TODO plugin auto: type and format
64                 if ($data['plugin_type'] == 'auto')
65                         $data['plugin_type'] = 'ns-html5';
66                 $data['asset_index'] = 0;
67                 
68                 // TODO remove old AJAX plugin content
69 //              $data['plugin_content'] = $this->_plugin('ns-html5', 
70 //                      $data['video']['url'][0], TRUE);
71                 
72                 // **
73                 // ** LOADING VIEWS
74                 // **
75                 $this->load->view('html_begin', $this->html_head_params);
76                 $this->load->view('header');
77                 
78                 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
79                 $this->load->view('video/watch_view', $data);
80                 
81                 $this->load->view('footer');
82                 $this->load->view('html_end');
83         }
84         
85         /**
86          * AJAX page which retrieves a video plugin.
87          *
88          * The view associated with this controller should be parameter type
89          * concatenated with '_plugin_view' and must be located in
90          * 'application/views/video'.
91          *
92          * @param       string $type    'ns-vlc', 'ns-html5'
93          */
94         public function plugin($type)
95         {
96                 $url = $this->input->post('url', TRUE);
97                 
98                 $this->_plugin($type, $url);
99         }
100         
101         /**
102          * Video plugin controller
103          *
104          * See plugin function for details. If the second parameter is TRUE
105          * the output is return instead of being displayed (used in preloading).
106          */
107         public function _plugin($type, $url, $return_output=FALSE)
108         {       
109                 if ($type == 'ns-html5')
110                         $data['url'] = 'tribe://' . $url;
111                 else if ($type == 'ns-vlc')
112                         $data['url'] = $url;
113                 
114                 $output = $this->load->view('video/'. $type . '_plugin_view', $data, 
115                         $return_output);
116                 
117                 if ($return_output)
118                         return $output;
119         }
120         
121 }
122
123 /* End of file video.php */
124 /* Location: ./application/controllers/video.php */