X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=application%2Fcontrollers%2Fcatalog.php;h=581e147703fee8177fbe426a229e224862f69f46;hb=b56dce7ae724d5b955a96d7d3d5b3b476d2e28fb;hp=37b1a6cb32ecaa0ec1dae4c3d030068526fc13b1;hpb=6c67c9d74550575fbc96be0baad42260c2dbcb6a;p=living-lab-site.git diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index 37b1a6c..581e147 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -1,46 +1,305 @@ lang->load('catalog'); + } + public function index() { + $user_id = $this->session->userdata('user_id'); + if ($user_id) + { + if (intval($user_id) & USER_ROLE_ADMIN) + $allow_unactivated = TRUE; + else + $allow_unactivated = FALSE; + } + else + $allow_unactivated = FALSE; + + + // ** + // ** LOADING MODEL + // ** // Retrieve videos summary. $this->load->model('videos_model'); - $data['videos'] = $this->videos_model->get_videos_summary(); - - $params = array( 'title' => $this->config->item('site_name'), - //'stylesheets' => array(), - //'javascripts' => array(), - //'metas' => array('description'=>'','keywords'=>'') - ); + foreach ($this->config->item('categories') as $id => $name) + { + // Videos + $vs_data['videos'] = $this->videos_model->get_videos_summary( + $id, NULL, 0, $this->config->item('videos_per_row'), + $allow_unactivated); + + // Category + $vs_data['category_name'] = $name; + $vs_data['category_id'] = $id; + $videos_summary['category_name'] = $name; + $videos_summary['category_title'] = $name ? + $this->lang->line("ui_categ_$name") : $name; + + // Pagination (not required) + $vs_data['pagination'] = ''; + + $videos_summary['content'] = $this->load->view( + 'catalog/videos_summary_view', $vs_data, TRUE); + $data['videos_summaries'][] = $videos_summary; + } + + $params = array('title' => $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + 'js' => array('jquery.ui.thumbs.js'), + //'metas' => array('description'=>'','keywords'=>'') + ); $this->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** $this->load->view('html_begin', $this->html_head_params); - $this->load->view('header'); - - $this->load->view('catalog/index_view', $data); - + $this->load->view('header', array( + 'selected_menu' => 'home' + )); + + $main_params['content'] = $this->load->view('catalog/index_view', $data, + TRUE); + $main_params['side'] = $this->load->view('side_default', NULL, TRUE); + $this->load->view('main', $main_params); + $this->load->view('footer'); $this->load->view('html_end'); } - + public function test() { - $this->load->helper('url'); + $this->load->helper('av_info'); - echo 'link'; + var_dump(get_video_dar('./data/media/test.ogv')); + } + + public function category($category_name, $ordering = 'hottest', $offset = 0) + { + $user_id = $this->session->userdata('user_id'); + if ($user_id) + { + if (intval($user_id) & USER_ROLE_ADMIN) + $allow_unactivated = TRUE; + else + $allow_unactivated = FALSE; + } + else + $allow_unactivated = FALSE; + + // ** + // ** LOADING MODEL + // ** + // Video Category + $category_data = Catalog::_get_category_data($category_name); + + // Retrieve videos summary. + $this->load->model('videos_model'); + $vs_data['videos'] = $this->videos_model->get_videos_summary( + $category_data['category_id'], NULL, intval($offset), + $this->config->item('videos_per_page'), $ordering, + $allow_unactivated); + + $vs_data['ordering'] = $ordering; + + // Pagination + $this->load->library('pagination'); + $pg_config['base_url'] = site_url( + "catalog/category/$category_name/$ordering/"); + $pg_config['uri_segment'] = 5; + $pg_config['total_rows'] = $this->videos_model->get_videos_count( + $category_data['category_id'], NULL, $allow_unactivated); + $pg_config['per_page'] = $this->config->item('videos_per_page'); + $this->pagination->initialize($pg_config); + $vs_data['pagination'] = $this->pagination->create_links(); + $vs_data['category_name'] = $category_data['category_name']; + $vs_data['title'] = $category_data['category_title']; + + $params = array('title' => + $category_data['category_title'] . ' – ' + . $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + 'js' => array('jquery.ui.thumbs.js') + //'metas' => array('description'=>'','keywords'=>'') + ); + $this->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** + $this->load->view('html_begin', $this->html_head_params); + $this->load->view('header', array( + 'search_category_name' => $vs_data['category_name'] + )); + + $main_params['content'] = + $this->load->view('catalog/videos_summary_view', $vs_data, TRUE); + $main_params['side'] = $this->load->view('side_default', NULL, TRUE); + $this->load->view('main', $main_params); + + $this->load->view('footer'); + $this->load->view('html_end'); } - - public function search($query_str) + + public function search($search_query = "", $offset = 0, $category_name = NULL) + { + $this->load->model('videos_model'); + $this->load->library('security'); + + // Redirect to an URL which contains search string if data was passed + // via POST method and not via URL segments. + $str_post_search = $this->input->post('search'); + $str_post_category = $this->input->post('search-category'); + if ($search_query === "" && $str_post_search !== FALSE) + { + redirect('catalog/search/' + . $this->videos_model->encode_search_query($str_post_search) + . '/0' + . ($str_post_category === FALSE ? '' : "/$str_post_category")); + return; + } + + // ** + // ** LOADING MODEL + // ** + // Search query is encoded for URL and must be decoded. + $enc_search_query = $search_query; + $search_query = $this->videos_model->decode_search_query($search_query); + + // Security filtering + $search_query = $this->security->xss_clean($search_query); + $results_data['search_query'] = $search_query; + + // Category + $results_data = Catalog::_get_category_data($category_name); + if ($results_data === NULL) + $results_data = array('category_id' => NULL); + + // Page header data + $header_data['search_query'] = $search_query; + if ($category_name !== NULL) + { + $header_data['search_category_name'] = $results_data['category_name']; + } + + // Check if search string is valid. + if (strlen($search_query) === 0) + { + //$results_data['videos'] = NULL; + $this->error($this->lang->line('error_search_query_empty'), $header_data); + return; + } + else + { + // Retrieve search results. + $results_data['count'] = $this->videos_model->search_videos( + $search_query, 0, 0, $results_data['category_id']); + $results_data['videos'] = $this->videos_model->search_videos( + $search_query, intval($offset), $this->config->item( + 'search_results_per_page'), + $results_data['category_id']); + if ($results_data['videos'] === NULL) + $results_data['videos'] = array(); + + // Pagination + $this->load->library('pagination'); + $pg_config['base_url'] = site_url("catalog/search/$enc_search_query/"); + $pg_config['uri_segment'] = 4; + $pg_config['total_rows'] = $results_data['count']; + $pg_config['per_page'] = + $this->config->item('search_results_per_page'); + $this->pagination->initialize($pg_config); + $results_data['pagination'] = $this->pagination->create_links(); + } + + // HTML head parameters + $params = array('title' => 'Search Results – ' + . $this->config->item('site_name'), + 'css' => array( + 'catalog.css' + ), + 'js' => array('jquery.ui.thumbs.js'), + //'metas' => array('description'=>'','keywords'=>'') + ); + $this->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** + $this->load->view('html_begin', $this->html_head_params); + $this->load->view('header', $header_data); + + // Search Results + $main_params['content'] = + $this->load->view('catalog/search_results_view', $results_data, + TRUE); + $main_params['side'] = $this->load->view('side_default', NULL, TRUE); + $this->load->view('main', $main_params); + + $this->load->view('footer'); + $this->load->view('html_end'); + } + + public function error($msg, $header_data) { - echo $query_str; + $params = array('title' => 'Error – ' + . $this->config->item('site_name'), + //'css' => array(), + //'js' => array(), + //'metas' => array('description'=>'','keywords'=>'') + ); + $this->load->library('html_head_params', $params); + + // ** + // ** LOADING VIEWS + // ** + $this->load->view('html_begin', $this->html_head_params); + $this->load->view('header', $header_data); + + $main_params['content'] = $this->load->view('error_view', array( + 'msg' => $msg), TRUE); + $main_params['side'] = $this->load->view('side_default', NULL, TRUE); + $this->load->view('main', $main_params); + + $this->load->view('footer'); + $this->load->view('html_end'); + } + + public static function _get_category_data($category_name) + { + $ci = & get_instance(); + + if ($category_name === NULL) + return NULL; + + $categories = $ci->config->item('categories'); + $category_id = array_search($category_name, $categories); + $results_data['category_name'] = $category_name; + $results_data['category_id'] = $category_id; + $results_data['category_title'] = $category_name ? + $ci->lang->line("ui_categ_$category_name") : $category_name; + + return $results_data; } + } /* End of file catalog.php */ -/* Location: ./application/controllers/catalog.php */ +/* Location: ./application/controllers/catalog.php */ \ No newline at end of file