video thumbnails are displayed as slideshow when mouse is over; video widget bugs...
[living-lab-site.git] / application / controllers / catalog.php
1 <?php
2
3 /**
4  * Class Catalog controls video hierarchy and searching
5  *
6  * @category    Controller
7  * @author              Călin-Andrei Burloiu
8  */
9 class Catalog extends CI_Controller {
10
11         public function __construct()
12         {
13                 parent::__construct();
14
15                 //$this->lang->load('catalog');
16         }
17
18         public function index()
19         {
20                 $user_id = $this->session->userdata('user_id');
21                 if ($user_id)
22                 {
23                         if (intval($user_id) & USER_ROLE_ADMIN)
24                                 $allow_unactivated = TRUE;
25                         else
26                                 $allow_unactivated = FALSE;
27                 }
28                 else
29                         $allow_unactivated = FALSE;
30                         
31                 
32                 // **
33                 // ** LOADING MODEL
34                 // **
35                 // Retrieve videos summary.
36                 $this->load->model('videos_model');
37                 foreach ($this->config->item('categories') as $id => $name)
38                 {
39                         // Videos
40                         $vs_data['videos'] = $this->videos_model->get_videos_summary(
41                                         $id, NULL, 0, $this->config->item('videos_per_row'),
42                                         $allow_unactivated);
43
44                         // Category
45                         $vs_data['category_name'] = $name;
46                         $vs_data['category_id'] = $id;
47                         $videos_summary['category_name'] = $name;
48                         $videos_summary['category_title'] = $name ?
49                                         $this->lang->line("ui_categ_$name") : $name;
50
51                         // Pagination (not required)
52                         $vs_data['pagination'] = '';
53
54                         $videos_summary['content'] = $this->load->view(
55                                         'catalog/videos_summary_view', $vs_data, TRUE);
56                         $data['videos_summaries'][] = $videos_summary;
57                 }
58
59                 $params = array('title' => $this->config->item('site_name'),
60                         'css' => array(
61                                 'catalog.css'
62                         ),
63                                 'js' => array('jquery.ui.thumbs.js'),
64                                 //'metas' => array('description'=>'','keywords'=>'')
65                 );
66                 $this->load->library('html_head_params', $params);
67
68                 // **
69                 // ** LOADING VIEWS
70                 // **
71                 $this->load->view('html_begin', $this->html_head_params);
72                 $this->load->view('header', array(
73                         'selected_menu' => 'home'
74                 ));
75
76                 $main_params['content'] = $this->load->view('catalog/index_view', $data,
77                                 TRUE);
78                 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
79                 $this->load->view('main', $main_params);
80
81                 $this->load->view('footer');
82                 $this->load->view('html_end');
83         }
84
85         public function test()
86         {
87                 $this->load->helper('av_info');
88                 
89                 var_dump(get_video_dar('./data/media/test.ogv'));
90         }
91
92         public function category($category_name, $ordering = 'hottest', $offset = 0)
93         {
94                 $user_id = $this->session->userdata('user_id');
95                 if ($user_id)
96                 {
97                         if (intval($user_id) & USER_ROLE_ADMIN)
98                                 $allow_unactivated = TRUE;
99                         else
100                                 $allow_unactivated = FALSE;
101                 }
102                 else
103                         $allow_unactivated = FALSE;
104                 
105                 // **
106                 // ** LOADING MODEL
107                 // **
108                 // Video Category
109                 $category_data = Catalog::_get_category_data($category_name);
110
111                 // Retrieve videos summary.
112                 $this->load->model('videos_model');
113                 $vs_data['videos'] = $this->videos_model->get_videos_summary(
114                                 $category_data['category_id'], NULL, intval($offset), 
115                                 $this->config->item('videos_per_page'), $ordering,
116                                 $allow_unactivated);
117
118                 $vs_data['ordering'] = $ordering;
119
120                 // Pagination
121                 $this->load->library('pagination');
122                 $pg_config['base_url'] = site_url(
123                                 "catalog/category/$category_name/$ordering/");
124                 $pg_config['uri_segment'] = 5;
125                 $pg_config['total_rows'] = $this->videos_model->get_videos_count(
126                                 $category_data['category_id'], NULL, $allow_unactivated);
127                 $pg_config['per_page'] = $this->config->item('videos_per_page');
128                 $this->pagination->initialize($pg_config);
129                 $vs_data['pagination'] = $this->pagination->create_links();
130                 $vs_data['category_name'] = $category_data['category_name'];
131                 $vs_data['title'] = $category_data['category_title'];
132
133                 $params = array('title' =>
134                         $category_data['category_title'] . ' &ndash; '
135                         . $this->config->item('site_name'),
136                         'css' => array(
137                                 'catalog.css'
138                         ),
139                         'js' => array('jquery.ui.thumbs.js')
140                         //'metas' => array('description'=>'','keywords'=>'')
141                 );
142                 $this->load->library('html_head_params', $params);
143
144                 // **
145                 // ** LOADING VIEWS
146                 // **
147                 $this->load->view('html_begin', $this->html_head_params);
148                 $this->load->view('header', array(
149                         'search_category_name' => $vs_data['category_name']
150                 ));
151
152                 $main_params['content'] =
153                                 $this->load->view('catalog/videos_summary_view', $vs_data, TRUE);
154                 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
155                 $this->load->view('main', $main_params);
156
157                 $this->load->view('footer');
158                 $this->load->view('html_end');
159         }
160
161         public function search($search_query = "", $offset = 0, $category_name = NULL)
162         {
163                 $this->load->model('videos_model');
164                 $this->load->library('security');
165
166                 // Redirect to an URL which contains search string if data was passed
167                 // via POST method and not via URL segments.
168                 $str_post_search = $this->input->post('search');
169                 $str_post_category = $this->input->post('search-category');
170                 if ($search_query === "" && $str_post_search !== FALSE)
171                 {
172                         redirect('catalog/search/'
173                                         . $this->videos_model->encode_search_query($str_post_search)
174                                         . '/0'
175                                         . ($str_post_category === FALSE ? '' : "/$str_post_category"));
176                         return;
177                 }
178
179                 // **
180                 // ** LOADING MODEL
181                 // **
182                 // Search query is encoded for URL and must be decoded.
183                 $enc_search_query = $search_query;
184                 $search_query = $this->videos_model->decode_search_query($search_query);
185
186                 // Security filtering
187                 $search_query = $this->security->xss_clean($search_query);
188                 $results_data['search_query'] = $search_query;
189
190                 // Category
191                 $results_data = Catalog::_get_category_data($category_name);
192                 if ($results_data === NULL)
193                         $results_data = array('category_id' => NULL);
194
195                 // Page header data
196                 $header_data['search_query'] = $search_query;
197                 if ($category_name !== NULL)
198                 {
199                         $header_data['search_category_name'] = $results_data['category_name'];
200                 }
201
202                 // Check if search string is valid.
203                 if (strlen($search_query) === 0)
204                 {
205                         //$results_data['videos'] = NULL;
206                         $this->error($this->lang->line('error_search_query_empty'), $header_data);
207                         return;
208                 }
209                 else
210                 {
211                         // Retrieve search results.
212                         $results_data['count'] = $this->videos_model->search_videos(
213                                         $search_query, 0, 0, $results_data['category_id']);
214                         $results_data['videos'] = $this->videos_model->search_videos(
215                                         $search_query, intval($offset), $this->config->item(
216                                                         'search_results_per_page'), 
217                                         $results_data['category_id']);
218                         if ($results_data['videos'] === NULL)
219                                 $results_data['videos'] = array();
220
221                         // Pagination
222                         $this->load->library('pagination');
223                         $pg_config['base_url'] = site_url("catalog/search/$enc_search_query/");
224                         $pg_config['uri_segment'] = 4;
225                         $pg_config['total_rows'] = $results_data['count'];
226                         $pg_config['per_page'] =
227                                         $this->config->item('search_results_per_page');
228                         $this->pagination->initialize($pg_config);
229                         $results_data['pagination'] = $this->pagination->create_links();
230                 }
231
232                 // HTML head parameters
233                 $params = array('title' => 'Search Results &ndash; '
234                         . $this->config->item('site_name'),
235                         'css' => array(
236                                 'catalog.css'
237                         ),
238                         'js' => array('jquery.ui.thumbs.js'),
239                         //'metas' => array('description'=>'','keywords'=>'')
240                 );
241                 $this->load->library('html_head_params', $params);
242
243                 // **
244                 // ** LOADING VIEWS
245                 // **
246                 $this->load->view('html_begin', $this->html_head_params);
247                 $this->load->view('header', $header_data);
248
249                 // Search Results
250                 $main_params['content'] =
251                                 $this->load->view('catalog/search_results_view', $results_data,
252                                                 TRUE);
253                 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
254                 $this->load->view('main', $main_params);
255
256                 $this->load->view('footer');
257                 $this->load->view('html_end');
258         }
259
260         public function error($msg, $header_data)
261         {
262                 $params = array('title' => 'Error &ndash; '
263                         . $this->config->item('site_name'),
264                                 //'css' => array(),
265                                 //'js' => array(),
266                                 //'metas' => array('description'=>'','keywords'=>'')
267                 );
268                 $this->load->library('html_head_params', $params);
269
270                 // **
271                 // ** LOADING VIEWS
272                 // **
273                 $this->load->view('html_begin', $this->html_head_params);
274                 $this->load->view('header', $header_data);
275
276                 $main_params['content'] = $this->load->view('error_view', array(
277                         'msg' => $msg), TRUE);
278                 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
279                 $this->load->view('main', $main_params);
280
281                 $this->load->view('footer');
282                 $this->load->view('html_end');
283         }
284
285         public static function _get_category_data($category_name)
286         {
287                 $ci = & get_instance();
288
289                 if ($category_name === NULL)
290                         return NULL;
291
292                 $categories = $ci->config->item('categories');
293                 $category_id = array_search($category_name, $categories);
294                 $results_data['category_name'] = $category_name;
295                 $results_data['category_id'] = $category_id;
296                 $results_data['category_title'] = $category_name ?
297                                 $ci->lang->line("ui_categ_$category_name") : $category_name;
298
299                 return $results_data;
300         }
301
302 }
303
304 /* End of file catalog.php */
305 /* Location: ./application/controllers/catalog.php */