Beispiel #1
0
 function before()
 {
     parent::before();
     $this->response->headers('Pragma', 'no-cache');
     $this->settings = Kohana::$config->load('settings');
     $this->site_name = $this->settings['site_name'];
     // Стили
     $this->add_css('assets/css/reset.css');
     $this->add_css('assets/js/multiselect/jquery.multiselect.css');
     $this->add_css('assets/js/gallery/css/jquery.lightbox-0.5.css');
     $this->add_css('assets/css/rmsform.css');
     $this->add_css('assets/js/css/flick/jquery-ui-1.8.16.custom.css');
     $this->add_css('assets/css/bootstrap_frontend.css');
     $this->add_css('assets/css/main_min.css?version=781');
     // Скрипты
     $this->add_js('assets/js/jquery-1.7.1.js');
     $this->add_js('assets/js/jquery-ui-1.8.17.custom.min.js');
     $this->add_js('assets/js/jquery.columnizer.min.js');
     $this->add_js('assets/js/jquery.scrollTo-min.js');
     $this->add_js('assets/js/jquery.showpassword.js');
     $this->add_js('assets/js/ckeditor/ckeditor.js');
     $this->add_js('assets/js/multiselect/jquery.multiselect.js');
     $this->add_js('assets/js/multiselect/jquery.multiselect.filter.js');
     $this->add_js('assets/js/gallery/jquery.lightbox-0.5.js');
     $this->add_js('assets/js/jquery.qtip-1.0.0-rc3.js');
     $this->add_js('assets/js/main.js?version=780');
     $this->add_js('http://userapi.com/js/api/openapi.js?48', 'before');
     // Count of notices
     if ($this->user) {
         $this->template->notice_count = ORM::factory('notice')->get_notices_count($this->user);
     }
     $this->template->css_class = '';
     $this->template->bc['/'] = 'Главная';
     //$current_city = $this->session->get('current_city', 'moscow');
     $items = array('cars' => array('name' => 'cars', 'ids' => NULL), 'works' => array('name' => 'works', 'ids' => NULL));
     $this->_geo_params = Geography::get_geography_params();
     $this->_selected_city_ids = Geography::set_selected_city_id($this->_geo_params['cities'], Cookie::get('filter_city'));
     // Cities select on header
     $this->template->cities = $this->_geo_params['cities']['total'];
     uasort($this->template->cities, array('Model_City', 'cmp'));
     $this->template->selected_city_ids = array('total' => $this->_selected_city_ids['total'], 'has_cars' => $this->_selected_city_ids['has_cars']);
     $this->template->assoc_news = ORM::factory('newsportal');
 }
Beispiel #2
0
 function action_index()
 {
     $this->auto_render = FALSE;
     $sitemap = new Sitemap();
     $base_url = 'http://www.as-avtoservice.ru/';
     // Basic urls
     $base_urls = Kohana::$config->load('settings.sitemap_urls');
     foreach ($base_urls as $u) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $u);
         $sitemap->add($url);
     }
     // Standart contents
     $content = ORM::factory('content_site');
     foreach ($content->where('active', '!=', 0)->find_all() as $c) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $c->url);
         //$unix_time = strtotime($c->date);
         //$url->set_last_mod($unix_time);
         $sitemap->add($url);
     }
     // Shops page
     $shop = ORM::factory('service')->where('type', '=', 2);
     foreach ($shop->find_all() as $s) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'shops/' . $s->id);
         //$unix_time = (int) strtotime($s->date_create);
         //$url->set_last_mod($unix_time);
         $sitemap->add($url);
     }
     // Services page
     $service = ORM::factory('service')->where('type', '=', 1);
     foreach ($service->find_all() as $s) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'services/' . $s->id);
         $sitemap->add($url);
     }
     unset($s);
     // Service news
     $service_all_news_urls = array();
     $news_service = ORM::factory('newsservice')->where('active', '=', 1);
     foreach ($news_service->find_all() as $news) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'services/' . $news->service->id . '/news/' . $news->id);
         $sitemap->add($url);
         if (!array_key_exists($news->service->id, $service_all_news_urls)) {
             $service_all_news_urls[$news->service->id] = 'services/' . $news->service->id . '/news';
         }
     }
     unset($news);
     foreach ($service_all_news_urls as $all_news_url) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $all_news_url);
         $sitemap->add($url);
     }
     // Site news
     $news_portal = ORM::factory('newsportal')->where('active', '!=', 0);
     foreach ($news_portal->find_all() as $news) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'news/association/' . $news->id);
         $sitemap->add($url);
     }
     unset($news);
     // World news
     $news_world = ORM::factory('newsworld')->where('active', '!=', 0)->find_all();
     if (count($news_world) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'news/world');
         $sitemap->add($url);
         foreach ($news_world as $news) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'news/world/' . $news->id);
             $sitemap->add($url);
         }
     }
     // Articles
     $article = ORM::factory('content_article')->where('active', '!=', 0)->find_all();
     if (count($article) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'articles');
         $sitemap->add($url);
         foreach ($article as $a) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'articles/' . $a->id);
             $sitemap->add($url);
         }
     }
     // Reviews
     $service_all_reviews_urls = array();
     $review = ORM::factory('review')->where('active', '!=', 0)->find_all();
     if (count($review) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'reviews');
         $sitemap->add($url);
         foreach ($review as $r) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/' . $r->service->id . '/reviews/' . $r->id);
             $sitemap->add($url);
             if (!array_key_exists($r->service->id, $service_all_reviews_urls)) {
                 $service_all_reviews_urls[$r->service->id] = 'services/' . $r->service->id . '/reviews';
             }
         }
     }
     foreach ($service_all_reviews_urls as $all_reviews_url) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $all_reviews_url);
         $sitemap->add($url);
     }
     // Services stocks (акции)
     $service_all_stocks_urls = array();
     $stock = ORM::factory('stock')->where('active', '!=', 0)->find_all();
     if (count($stock) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'stocks');
         $sitemap->add($url);
         foreach ($stock as $s) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/' . $s->service->id . '/stocks/' . $s->id);
             $sitemap->add($url);
             if (!array_key_exists($s->service->id, $service_all_stocks_urls)) {
                 $service_all_stocks_urls[$s->service->id] = 'services/' . $s->service->id . '/stocks';
             }
         }
     }
     foreach ($service_all_stocks_urls as $all_stocks_url) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $all_stocks_url);
         $sitemap->add($url);
     }
     // Services Vacancies (вакансии)
     $service_all_vacancies_urls = array();
     foreach (ORM::factory('vacancy')->get_vacancies() as $v) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'services/' . $v->service->id . '/vacancies/' . $v->id);
         $sitemap->add($url);
         if (!array_key_exists($v->service->id, $service_all_vacancies_urls)) {
             $service_all_vacancies_urls[$v->service->id] = 'services/' . $v->service->id . '/vacancies';
         }
     }
     foreach ($service_all_vacancies_urls as $all_vacancies_url) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . $all_vacancies_url);
         $sitemap->add($url);
     }
     // Q&A (запросы пользователей)
     $question = ORM::factory('question')->where('active', '!=', 0)->find_all();
     if (count($question) > 0) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'messages');
         $sitemap->add($url);
         foreach ($question as $q) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'messages/' . $q->id);
             $sitemap->add($url);
         }
     }
     $geo_params = Geography::get_geography_params();
     // Tags pages
     // Auto tags and search pages
     foreach ($geo_params['cities']['has_cars'] as $city) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'filter/auto/city_' . $city['city_id']);
         $sitemap->add($url);
         foreach ($city['cars'] as $car_id) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/search/car_' . $car_id . '/city_' . $city['city_id']);
             $sitemap->add($url);
         }
     }
     unset($city);
     // Works tags and search pages
     foreach ($geo_params['cities']['has_works'] as $city) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'filter/work/city_' . $city['city_id']);
         $sitemap->add($url);
         foreach ($city['works'] as $work_id) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/search/work_' . $work_id . '/city_' . $city['city_id']);
             $sitemap->add($url);
         }
     }
     unset($city);
     // Districts tags and search pages
     foreach ($geo_params['cities']['has_district'] as $city) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'filter/district/city_' . $city['city_id']);
         $sitemap->add($url);
     }
     unset($city);
     foreach ($geo_params['districts'] as $id => $value) {
         if (!empty($value['cars']) or !empty($value['works'])) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/search/district_' . $id);
             $sitemap->add($url);
         }
     }
     // Metro stations tags and search pages
     foreach ($geo_params['cities']['has_metro'] as $city) {
         $url = new Sitemap_URL();
         $url->set_loc($base_url . 'filter/metro/city_' . $city['city_id']);
         $sitemap->add($url);
     }
     foreach ($geo_params['metro_stations'] as $id => $value) {
         if (!empty($value['cars']) or !empty($value['works'])) {
             $url = new Sitemap_URL();
             $url->set_loc($base_url . 'services/search/metro_' . $id);
             $sitemap->add($url);
         }
     }
     $this->response->headers('Content-type', 'text/xml');
     $this->response->body($sitemap);
 }
Beispiel #3
0
 /**
  * Фильтр услуг и прочего
  * @return mixed
  */
 public function action_fast_filter()
 {
     $geo_params = Geography::get_geography_params();
     // Типы быстрого поиска на главной
     $types = array('has_cars', 'has_works', 'has_metro', 'has_district');
     if ($this->request->query('type') and in_array($this->request->query('type'), $types)) {
         Cookie::set('fast_filter_type', $this->request->query('type'));
         $filter_type = $this->request->query('type');
     } else {
         $filter_type = Cookie::get('fast_filter_type', 'has_cars');
         if (!in_array($filter_type, $types)) {
             $filter_type = 'has_cars';
         }
     }
     if ($this->request->query('city') and array_key_exists($this->request->query('city'), $geo_params['cities']['total'])) {
         Cookie::set('filter_city', $this->request->query('city'));
         $city_id = $this->request->query('city');
     } else {
         $city_id = Cookie::get('filter_city');
     }
     $selected_city_ids = Geography::set_selected_city_id($geo_params['cities'], $city_id);
     $params = array('city' => array('field' => 'city_id', 'op' => '=', 'value' => $selected_city_ids[$filter_type]));
     $header_cities_view = View::factory('frontend/navigation/header_cities')->set('cities', $geo_params['cities']['total'])->set('current_city', $selected_city_ids['total'])->render();
     if ($this->request->query('mode') == 'without_filter') {
         $result = array('header_cities' => $header_cities_view, 'auto_filter_city_id' => $selected_city_ids['has_cars']);
         echo json_encode($result);
         return;
     }
     $config = Kohana::$config->load('settings');
     $current_city = array('name' => $geo_params['cities']['total'][$selected_city_ids[$filter_type]]->name, 'genitive_name' => $geo_params['cities']['total'][$selected_city_ids[$filter_type]]->genitive_name);
     $primary_cities = array_intersect_key($geo_params['cities']['total'], $geo_params['cities'][$filter_type]);
     $other_cities = NULL;
     // Получение городов, основных и "других"
     if (count($primary_cities) > $config['max_fast_filter_cities']) {
         $primary_cities = array_intersect_key($primary_cities, array_flip($config['fast_filter_cities']));
         if (!array_key_exists($selected_city_ids[$filter_type], $primary_cities)) {
             array_pop($primary_cities);
             $primary_cities = array($selected_city_ids[$filter_type] => $geo_params['cities']['total'][$selected_city_ids[$filter_type]]) + $primary_cities;
         }
         $other_cities = array_diff_key(array_intersect_key($geo_params['cities']['total'], $geo_params['cities'][$filter_type]), $primary_cities);
     }
     $filter_type_view = View::factory('frontend/navigation/fast_filter_types')->set('types', $types)->set('current_type', $filter_type)->render();
     $cities_view = View::factory('frontend/navigation/fast_filter_cities')->set('cities', $primary_cities)->set('other_cities', $other_cities)->set('city_id', $selected_city_ids[$filter_type])->render();
     switch ($filter_type) {
         case 'has_cars':
             $car_brand = ORM::factory('car_brand')->set_params($params)->get_cars();
             if (count($car_brand) > $config['max_fast_filter_models']) {
                 $primary_cars = array_intersect_key($car_brand, array_flip($config['fast_filter_models']));
                 if (count($primary_cars) < $config['max_fast_filter_models']) {
                     $primary_cars = $primary_cars + array_slice(array_diff_key($car_brand, $primary_cars), 0, $config['max_fast_filter_models'] - count($primary_cars), TRUE);
                 }
                 $car_brand = $primary_cars;
             }
             $items_view = View::factory('frontend/fast_filter/car_brands')->set('city_id', $params['city']['value'])->set('car_brands', $car_brand)->render();
             break;
         case 'has_works':
             $work = ORM::factory('work')->set_params($params)->get_works();
             if (count($work) > $config['max_fast_filter_works']) {
                 $primary_works = array_intersect_key($work, array_flip($config['fast_filter_works']));
                 if (count($primary_works) < $config['max_fast_filter_works']) {
                     $primary_works = $primary_works + array_slice(array_diff_key($work, $primary_works), 0, $config['max_fast_filter_works'] - count($primary_works), TRUE);
                 }
                 $work = $primary_works;
             }
             $items_view = View::factory('frontend/fast_filter/works')->set('works', $work)->set('city_id', $params['city']['value'])->render();
             break;
         case 'has_metro':
             $metro = ORM::factory('metro')->get_metro($geo_params, $params['city']['value']);
             if (count($metro) > $config['max_fast_filter_metro']) {
                 $metro = array_slice($metro, 0, $config['max_fast_filter_metro'], TRUE);
             }
             $items_view = View::factory('frontend/fast_filter/metro')->set('metro_stations', $metro)->set('city_id', $params['city']['value'])->render();
             break;
         case 'has_district':
             $district = ORM::factory('district')->get_districts($geo_params, $params['city']['value']);
             if (count($district) > $config['max_fast_filter_districts']) {
                 $district = array_slice($district, 0, $config['max_fast_filter_districts'], TRUE);
             }
             $items_view = View::factory('frontend/fast_filter/districts')->set('districts', $district)->set('city_id', $params['city']['value'])->render();
             break;
     }
     $result = array('filter_type' => $filter_type_view, 'cities' => $cities_view, 'items' => $items_view, 'header_cities' => $header_cities_view, 'current_city' => $current_city, 'auto_filter_url' => URL::site('filter/auto/city_' . $selected_city_ids['has_cars']));
     if ($this->request->is_ajax()) {
         echo json_encode($result);
     } else {
         $this->response->body($result['filter_type'] . $result['cities'] . $result['items']);
     }
 }