login works; working at register
[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                 // **
35                 // ** LOADING MODEL
36                 // **
37                 // Retrieve video information.
38                 $this->load->model('videos_model');
39                 $this->videos_model->inc_video_var($id, 'views');
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                 
46                 // Display page.
47                 $params = array(        'title' => $data['video']['title'] . ' &ndash; '
48                                                                 . $this->config->item('site_name'),
49                                                         'css' => array(
50                                                                 'jquery.ui.nsvideo.css',
51                                                                 'video.css'
52                                                         ),
53                                                         'js' => array(
54                                                                 'jquery.ui.nsvideo.js'
55                                                         ),
56                                                         //'metas' => array('description'=>'','keywords'=>'')
57                                                         );
58                 $this->load->library('html_head_params', $params);
59                 
60                 // Preloading video plugin.
61                 // TODO plugin auto: type and format
62                 if ($data['plugin_type'] == 'auto')
63                         $data['plugin_type'] = 'ns-html5';
64                 $data['asset_index'] = 0;
65                 
66                 // TODO remove old AJAX plugin content
67 //              $data['plugin_content'] = $this->_plugin('ns-html5', 
68 //                      $data['video']['url'][0], TRUE);
69                 
70                 // **
71                 // ** LOADING VIEWS
72                 // **
73                 $this->load->view('html_begin', $this->html_head_params);
74                 $this->load->view('header');
75                 
76                 //$main_params['content'] = $this->load->view('video/watch_view', $data, TRUE);
77                 $this->load->view('video/watch_view', $data);
78                 
79                 $this->load->view('footer');
80                 $this->load->view('html_end');
81         }
82         
83         /**
84          * AJAX page which retrieves a video plugin.
85          *
86          * The view associated with this controller should be parameter type
87          * concatenated with '_plugin_view' and must be located in
88          * 'application/views/video'.
89          *
90          * @param       string $type    'ns-vlc', 'ns-html5'
91          */
92         public function plugin($type)
93         {
94                 $url = $this->input->post('url', TRUE);
95                 
96                 $this->_plugin($type, $url);
97         }
98         
99         /**
100          * Video plugin controller
101          *
102          * See plugin function for details. If the second parameter is TRUE
103          * the output is return instead of being displayed (used in preloading).
104          */
105         public function _plugin($type, $url, $return_output=FALSE)
106         {       
107                 if ($type == 'ns-html5')
108                         $data['url'] = 'tribe://' . $url;
109                 else if ($type == 'ns-vlc')
110                         $data['url'] = $url;
111                 
112                 $output = $this->load->view('video/'. $type . '_plugin_view', $data, 
113                         $return_output);
114                 
115                 if ($return_output)
116                         return $output;
117         }
118         
119 }
120
121 /* End of file video.php */
122 /* Location: ./application/controllers/video.php */