/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } switch ($this->ads_type) { case 'popular': $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 'featured': $ads->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc'); break; case 'latest': default: $ads->order_by('published', 'desc'); break; } $ads = $ads->limit($this->ads_limit)->cached()->find_all(); //die(print_r($ads)); $this->ads = $ads; }
public function action_index() { //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; $this->template->meta_description = Core::config('general.site_description'); //setting main view/template and render pages // swith to decide on ads_in_home $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); switch (core::config('advertisement.ads_in_home')) { case 2: $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 1: $ads->where('featured', 'IS NOT', NULL)->where('featured', 'BETWEEN', array(DB::expr('NOW()'), Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60)))->order_by('featured', 'desc'); break; case 0: default: $ads->order_by('published', 'desc'); break; } //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', DB::expr('NOW()')); } $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all(); $this->ads = $ads; $categs = Model_Category::get_category_count(); $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs)); }
public function action_index() { if (core::config('general.auto_locate')) { Theme::$scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7'; Theme::$scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js'; } //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; if (core::config('general.site_description') != '') { $this->template->meta_description = core::config('general.site_description'); } else { $this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.'); } //setting main view/template and render pages // swith to decide on ads_in_home $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); $ads_in_home = core::config('advertisement.ads_in_home'); //in case we do not count visits we cant show popular if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) { $ads_in_home = 0; } switch ($ads_in_home) { case 2: $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 1: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc'); break; case 4: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()')); break; case 0: default: $ads->order_by('published', 'desc'); break; } //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all(); $categs = Model_Category::get_category_count(); $locats = Model_Location::get_location_count(); $auto_locats = NULL; if (core::config('general.auto_locate') and Model_User::get_userlatlng()) { $auto_locats = new Model_Location(); $auto_locats = $auto_locats->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL)->having('distance', '<=', '100')->order_by('distance', 'desc')->find_all()->as_array(); } $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs, 'locats' => $locats, 'auto_locats' => $auto_locats)); }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); switch ($this->ads_type) { case 'popular': $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 'featured': $ads->where('featured', 'IS NOT', NULL)->where('featured', 'BETWEEN', array(DB::expr('NOW()'), Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60)))->order_by('featured', 'desc'); break; case 'latest': default: $ads->order_by('published', 'desc'); break; } $ads = $ads->limit($this->ads_limit)->cached()->find_all(); //die(print_r($ads)); $this->ads = $ads; }
/** * Handle GET requests. */ public function action_index() { try { if (is_numeric($this->request->param('id'))) { $this->action_get(); } else { $output = array(); $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //search with lat and long!! nice! if (isset($this->_params['latitude']) and isset($this->_params['longitude'])) { $ads->select(array(DB::expr('degrees(acos(sin(radians(' . $this->_params['latitude'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $this->_params['latitude'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $this->_params['longitude'] . ' - `longitude`))))) * 69.172'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL); //we unset the search by lat and long if not will be duplicated unset($this->_filter_params['latitude']); unset($this->_filter_params['longitude']); } //only published ads $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } //make a search with q? param if (isset($this->_params['q']) and strlen($this->_params['q'])) { if (core::config('general.search_by_description') == TRUE) { $ads->where_open()->where('title', 'like', '%' . $this->_params['q'] . '%')->or_where('description', 'like', '%' . $this->_params['q'] . '%')->where_close(); } else { $ads->where('title', 'like', '%' . $this->_params['q'] . '%'); } } //getting all the ads of a category. if (isset($this->_filter_params['id_category']) and is_numeric($this->_filter_params['id_category']['value'])) { $category = new Model_Category($this->_filter_params['id_category']['value']); if ($category->loaded()) { $ads->where('id_category', 'in', $category->get_siblings_ids()); unset($this->_filter_params['id_category']); } } //getting all the ads of a location. if (isset($this->_filter_params['id_location']) and is_numeric($this->_filter_params['id_location']['value'])) { $location = new Model_Location($this->_filter_params['id_location']['value']); if ($location->loaded()) { $ads->where('id_location', 'in', $location->get_siblings_ids()); unset($this->_filter_params['id_location']); } } //filter results by param, verify field exists and has a value $ads->api_filter($this->_filter_params); //how many? used in header X-Total-Count $count = $ads->count_all(); //by default sort by published date if (empty($this->_sort)) { $this->_sort['published'] = 'desc'; } //after counting sort values $ads->api_sort($this->_sort); //we add the order by in case was specified, this is not a column so we need to do it manually if (isset($this->_sort['distance']) and isset($this->_params['latitude']) and isset($this->_params['longitude'])) { $ads->order_by('distance', $this->_sort['distance']); } //pagination with headers $pagination = $ads->api_pagination($count, $this->_params['items_per_page']); $ads = $ads->cached()->find_all(); //as array foreach ($ads as $ad) { $a = $ad->as_array(); $a['price'] = i18n::money_format($ad->price); $a['thumb'] = $ad->get_first_image(); $a['customfields'] = Model_Field::get_by_category($ad->id_category); //sorting by distance, lets add it! if (isset($ad->distance)) { $a['distance'] = i18n::format_measurement($ad->distance); } $a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)); $output[] = $a; } $this->rest_output(array('ads' => $output), 200, $count, $pagination !== FALSE ? $pagination : NULL); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
/** * gets data to the view and filters the ads * @param Model_Category $category * @param Model_Location $location * @return array */ public function list_logic($category = NULL, $location = NULL) { //user recognition $user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user(); $ads = new Model_Ad(); //filter by category or location if ($category !== NULL) { $ads->where('id_category', 'in', $category->get_siblings_ids()); } if ($location !== NULL) { $ads->where('id_location', 'in', $location->get_siblings_ids()); } //only published ads $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } //if sort by distance if (core::request('sort') == 'distance' and Model_User::get_userlatlng()) { $ads->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 69.172'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL); } // featured ads $featured = NULL; if (Theme::get('listing_slider') == 2) { $featured = clone $ads; $featured = $featured->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc')->limit(Theme::get('num_home_latest_ads', 4))->find_all(); } elseif (Theme::get('listing_slider') == 3) { $featured = clone $ads; $featured = $featured->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()'))->limit(Theme::get('num_home_latest_ads', 4))->find_all(); } $res_count = clone $ads; $res_count = $res_count->count_all(); // check if there are some advet.-s if ($res_count > 0) { // pagination module $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('advertisement.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL, 'location' => $location !== NULL ? $location->seoname : NULL)); Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->current_page)); /** * order depending on the sort parameter */ switch (core::request('sort', core::config('advertisement.sort_by'))) { //title z->a case 'title-asc': $ads->order_by('title', 'asc')->order_by('published', 'desc'); break; //title a->z //title a->z case 'title-desc': $ads->order_by('title', 'desc')->order_by('published', 'desc'); break; //cheaper first //cheaper first case 'price-asc': $ads->order_by('price', 'asc')->order_by('published', 'desc'); break; //expensive first //expensive first case 'price-desc': $ads->order_by('price', 'desc')->order_by('published', 'desc'); break; //featured //featured case 'featured': $ads->order_by('featured', 'desc')->order_by('published', 'desc'); break; //rating //rating case 'rating': $ads->order_by('rate', 'desc')->order_by('published', 'desc'); break; //distance //distance case 'distance': if (Model_User::get_userlatlng()) { $ads->order_by('distance', 'asc')->order_by('published', 'asc'); } break; //oldest first //oldest first case 'published-asc': $ads->order_by('published', 'asc'); break; //newest first //newest first case 'published-desc': default: $ads->order_by('published', 'desc'); break; } //we sort all ads with few parameters $ads = $ads->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); } else { // array of categories sorted for view return array('ads' => NULL, 'pagination' => NULL, 'user' => $user, 'category' => $category, 'location' => $location, 'featured' => NULL); } // array of categories sorted for view return array('ads' => $ads, 'pagination' => $pagination, 'user' => $user, 'category' => $category, 'location' => $location, 'featured' => $featured); }
public function action_index() { $this->auto_render = FALSE; $info = array('title' => 'RSS ' . htmlspecialchars(Core::config('general.site_name'), ENT_QUOTES), 'pubDate' => date("r"), 'description' => htmlspecialchars(__('Latest published'), ENT_QUOTES), 'generator' => 'Yclas'); $items = array(); //last ads, you can modify this value at: advertisement.feed_elements $ads = new Model_Ad(); //only published ads $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); //filter by category aor location if (Model_Category::current()->loaded()) { $ads->where('id_category', '=', Model_Category::current()->id_category); } if (Model_Location::current()->loaded()) { $ads->where('id_location', '=', Model_Location::current()->id_location); } //order depending on the sort parameter switch (core::request('sort', core::config('advertisement.sort_by'))) { //title z->a case 'title-asc': $ads->order_by('title', 'asc')->order_by('published', 'desc'); break; //title a->z //title a->z case 'title-desc': $ads->order_by('title', 'desc')->order_by('published', 'desc'); break; //cheaper first //cheaper first case 'price-asc': $ads->order_by('price', 'asc')->order_by('published', 'desc'); break; //expensive first //expensive first case 'price-desc': $ads->order_by('price', 'desc')->order_by('published', 'desc'); break; //featured //featured case 'featured': $ads->order_by('featured', 'desc')->order_by('published', 'desc'); break; //rating //rating case 'rating': $ads->order_by('rate', 'desc')->order_by('published', 'desc'); break; //favorited //favorited case 'favorited': $ads->order_by('favorited', 'desc')->order_by('published', 'desc'); break; //oldest first //oldest first case 'published-asc': $ads->order_by('published', 'asc'); break; //newest first //newest first case 'published-desc': default: $ads->order_by('published', 'desc'); break; } $ads = $ads->limit(Core::config('advertisement.feed_elements'))->cached()->find_all(); foreach ($ads as $a) { $url = Route::url('ad', array('category' => $a->category->seoname, 'seotitle' => $a->seotitle)); $item = array('title' => htmlspecialchars($a->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($a->published), 'description' => htmlspecialchars(Text::removebbcode($a->description), ENT_QUOTES), 'guid' => $url); if ($a->get_first_image() !== NULL) { $item['description'] = '<img src="' . $a->get_first_image() . '" />' . $item['description']; } $items[] = $item; } $xml = Feed::create($info, $items); $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
public function action_index() { if (core::config('general.auto_locate')) { if ($user_location = Core::post('user_location')) { Cookie::set('user_location', $user_location); $this->auto_render = FALSE; $this->template = View::factory('js'); $this->template->content = TRUE; return; } elseif (Core::get('user_location') == '0') { Cookie::delete('user_location'); } Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initAutoLocate'; } //template header $this->template->title = ''; // $this->template->meta_keywords = 'keywords'; if (core::config('general.site_description') != '') { $this->template->meta_description = core::config('general.site_description'); } else { $this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.'); } //setting main view/template and render pages // get user location if any $user_location = NULL; if (is_numeric($user_id_location = Cookie::get('user_location'))) { $user_location = new Model_Location($user_id_location); if (!$user_location->loaded()) { $user_location = NULL; } } // swith to decide on ads_in_home $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); if ($user_location) { $ads->where('id_location', 'in', $user_location->get_siblings_ids()); } $ads_in_home = core::config('advertisement.ads_in_home'); //in case we do not count visits we cant show popular if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) { $ads_in_home = 0; } switch ($ads_in_home) { case 2: $id_ads = array_keys(Model_Visit::popular_ads()); if (count($id_ads) > 0) { $ads->where('id_ad', 'IN', $id_ads); } break; case 1: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc'); break; case 4: $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()')); break; case 0: default: $ads->order_by('published', 'desc'); break; } //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql()); } $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all(); $categs = Model_Category::get_category_count(TRUE, $user_location); $hide_categories = json_decode(Core::config('general.hide_homepage_categories'), TRUE); $auto_locats = NULL; $auto_location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance'); if (core::config('general.auto_locate') and !isset($_COOKIE['cancel_auto_locate']) and Model_User::get_userlatlng()) { $auto_locats = new Model_Location(); $auto_locats = $auto_locats->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL)->having('distance', '<=', $auto_location_distance)->order_by('distance', 'asc')->find_all()->as_array(); } $this->template->bind('content', $content); $this->template->content = View::factory('pages/home', compact('ads', 'categs', 'auto_locats', 'user_location', 'hide_categories')); }