4 * Class Catalog controls video hierarchy and searching
7 * @author Călin-Andrei Burloiu
9 class Catalog extends CI_Controller {
11 public function __construct()
13 parent::__construct();
15 //$this->lang->load('catalog');
18 public function index()
20 $user_id = $this->session->userdata('user_id');
23 if (intval($user_id) & USER_ROLE_ADMIN)
24 $allow_unactivated = TRUE;
26 $allow_unactivated = FALSE;
29 $allow_unactivated = FALSE;
35 // Retrieve videos summary.
36 $this->load->model('videos_model');
37 foreach ($this->config->item('categories') as $id => $name)
40 $vs_data['videos'] = $this->videos_model->get_videos_summary(
41 $id, NULL, 0, $this->config->item('videos_per_row'),
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;
51 // Pagination (not required)
52 $vs_data['pagination'] = '';
54 $videos_summary['content'] = $this->load->view(
55 'catalog/videos_summary_view', $vs_data, TRUE);
56 $data['videos_summaries'][] = $videos_summary;
59 $params = array('title' => $this->config->item('site_name'),
63 'js' => array('jquery.ui.thumbs.js'),
64 //'metas' => array('description'=>'','keywords'=>'')
66 $this->load->library('html_head_params', $params);
71 $this->load->view('html_begin', $this->html_head_params);
72 $this->load->view('header', array(
73 'selected_menu' => 'home'
76 $main_params['content'] = $this->load->view('catalog/index_view', $data,
78 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
79 $this->load->view('main', $main_params);
81 $this->load->view('footer');
82 $this->load->view('html_end');
85 public function test()
87 $this->load->helper('av_info');
89 var_dump(get_video_dar('./data/media/test.ogv'));
92 public function category($category_name, $ordering = 'hottest', $offset = 0)
94 $user_id = $this->session->userdata('user_id');
97 if (intval($user_id) & USER_ROLE_ADMIN)
98 $allow_unactivated = TRUE;
100 $allow_unactivated = FALSE;
103 $allow_unactivated = FALSE;
109 $category_data = Catalog::_get_category_data($category_name);
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,
118 $vs_data['ordering'] = $ordering;
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'];
133 $params = array('title' =>
134 $category_data['category_title'] . ' – '
135 . $this->config->item('site_name'),
139 'js' => array('jquery.ui.thumbs.js')
140 //'metas' => array('description'=>'','keywords'=>'')
142 $this->load->library('html_head_params', $params);
147 $this->load->view('html_begin', $this->html_head_params);
148 $this->load->view('header', array(
149 'search_category_name' => $vs_data['category_name']
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);
157 $this->load->view('footer');
158 $this->load->view('html_end');
161 public function search($search_query = "", $offset = 0, $category_name = NULL)
163 $this->load->model('videos_model');
164 $this->load->library('security');
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)
172 redirect('catalog/search/'
173 . $this->videos_model->encode_search_query($str_post_search)
175 . ($str_post_category === FALSE ? '' : "/$str_post_category"));
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);
186 // Security filtering
187 $search_query = $this->security->xss_clean($search_query);
188 $results_data['search_query'] = $search_query;
191 $results_data = Catalog::_get_category_data($category_name);
192 if ($results_data === NULL)
193 $results_data = array('category_id' => NULL);
196 $header_data['search_query'] = $search_query;
197 if ($category_name !== NULL)
199 $header_data['search_category_name'] = $results_data['category_name'];
202 // Check if search string is valid.
203 if (strlen($search_query) === 0)
205 //$results_data['videos'] = NULL;
206 $this->error($this->lang->line('error_search_query_empty'), $header_data);
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();
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();
232 // HTML head parameters
233 $params = array('title' => 'Search Results – '
234 . $this->config->item('site_name'),
238 'js' => array('jquery.ui.thumbs.js'),
239 //'metas' => array('description'=>'','keywords'=>'')
241 $this->load->library('html_head_params', $params);
246 $this->load->view('html_begin', $this->html_head_params);
247 $this->load->view('header', $header_data);
250 $main_params['content'] =
251 $this->load->view('catalog/search_results_view', $results_data,
253 $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
254 $this->load->view('main', $main_params);
256 $this->load->view('footer');
257 $this->load->view('html_end');
260 public function error($msg, $header_data)
262 $params = array('title' => 'Error – '
263 . $this->config->item('site_name'),
266 //'metas' => array('description'=>'','keywords'=>'')
268 $this->load->library('html_head_params', $params);
273 $this->load->view('html_begin', $this->html_head_params);
274 $this->load->view('header', $header_data);
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);
281 $this->load->view('footer');
282 $this->load->view('html_end');
285 public static function _get_category_data($category_name)
287 $ci = & get_instance();
289 if ($category_name === NULL)
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;
299 return $results_data;
304 /* End of file catalog.php */
305 /* Location: ./application/controllers/catalog.php */