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));
 }
Beispiel #2
0
 public function action_index()
 {
     $this->before('/pages/maps');
     $this->template->title = __('Map');
     $this->template->height = Core::get('height', '100%');
     $this->template->width = Core::get('width', '100%');
     $this->template->zoom = Core::get('zoom', core::config('advertisement.map_zoom'));
     $this->template->height_thumb = Core::config('image.height_thumb') / 4;
     $this->template->width_thumb = Core::config('image.width_thumb') / 4;
     if (Model_User::get_userlatlng()) {
         $this->template->center_lon = $_COOKIE['mylng'];
         $this->template->center_lat = $_COOKIE['mylat'];
     } else {
         $this->template->center_lon = Core::get('lon', core::config('advertisement.center_lon'));
         $this->template->center_lat = Core::get('lat', core::config('advertisement.center_lat'));
     }
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('address', 'IS NOT', NULL)->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
     //filter by category
     if (core::get('category') !== NULL) {
         $category = new Model_Category();
         $category->where('seoname', '=', core::get('category'))->cached()->limit(1)->find();
         if ($category->loaded()) {
             $ads->where('id_category', 'IN', $category->get_siblings_ids());
         }
     }
     //filter by location
     if (core::get('location') !== NULL) {
         $location = new Model_location();
         $location->where('seoname', '=', core::get('location'))->cached()->limit(1)->find();
         if ($location->loaded()) {
             $ads->where('id_location', 'IN', $location->get_siblings_ids());
         }
     }
     //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 only 1 ad
     if (is_numeric(core::get('id_ad'))) {
         $ads = $ads->where('id_ad', '=', core::get('id_ad'));
     }
     $ads = $ads->order_by('published', 'desc')->limit(Core::config('advertisement.map_elements'))->find_all();
     $this->template->ads = $ads;
 }
            echo HTML::entities($ad->category->name);
            ?>
&amp;size=14&amp;auto=yes" class="img-responsive" alt="<?php 
            echo HTML::chars($ad->title);
            ?>
"> 
                      <?php 
        }
        ?>
                  </figure>
              </a>
          </div>
          
          <ul>
              <?php 
        if (core::request('sort') == 'distance' and Model_User::get_userlatlng()) {
            ?>
                  <li><b><?php 
            echo __('Distance');
            ?>
:</b> <?php 
            echo i18n::format_measurement($ad->distance);
            ?>
</li>
              <?php 
        }
        ?>
              <?php 
        if ($ad->published != 0) {
            ?>
                  <li><b><?php 
 /**
  * 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);
 }
Beispiel #5
0
echo core::config('image.height_thumb');
?>
?<?php 
echo str_replace('+', ' ', http_build_query(array('text' => $ad->category->name, 'size' => 14, 'auto' => 'yes')));
?>
" class="img-responsive" alt="<?php 
echo HTML::chars($ad->title);
?>
"> 
                      <?endif?>
                  </figure>
              </a>
          </div>
          
          <ul>
              <?if (core::request('sort') == 'distance' AND Model_User::get_userlatlng()) :?>
                  <li><b><?php 
echo __('Distance');
?>
:</b> <?php 
echo i18n::format_measurement($ad->distance);
?>
</li>
              <?endif?>
              <?if ($ad->published!=0){?>
                  <li><b><?php 
echo __('Publish Date');
?>
:</b> <?php 
echo Date::format($ad->published, core::config('general.date_format'));
?>
Beispiel #6
0
 public function action_advanced_search()
 {
     if (Theme::get('infinite_scroll')) {
         $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js';
         $this->template->scripts['footer'][] = 'js/listing.js';
     }
     if (core::config('general.auto_locate') or core::config('advertisement.map')) {
         Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry,places&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap';
     }
     $this->template->scripts['footer'][] = 'js/jquery.toolbar.js';
     $this->template->scripts['footer'][] = 'js/sort.js';
     //template header
     $this->template->title = __('Advanced Search');
     $this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name');
     //breadcrumbs
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     $pagination = NULL;
     $ads = NULL;
     $res_count = NULL;
     $user = $this->user ? $this->user : NULL;
     if ($this->request->query()) {
         // variables
         $search_advert = core::get('title');
         $search_loc = core::get('location');
         // filter by each variable
         $ads = new Model_Ad();
         //if sort by distance
         if ((core::request('sort', core::config('advertisement.sort_by')) == 'distance' or core::request('userpos') == 1) 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`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
         }
         // early filter
         $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 (core::request('userpos') == 1 and Model_User::get_userlatlng()) {
             if (is_numeric(Core::cookie('mydistance')) and Core::cookie('mydistance') <= 500) {
                 $location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::cookie('mydistance') * 1.60934) : Core::cookie('mydistance');
             } else {
                 $location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance');
             }
             $ads->where(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'), '<=', $location_distance);
         }
         if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
             // if user is using search from header
             if (core::get('search')) {
                 $search_advert = core::get('search');
             }
             if (core::config('general.search_by_description') == TRUE) {
                 $ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
             } else {
                 $ads->where('title', 'like', '%' . $search_advert . '%');
             }
         }
         //cf filter arrays
         $cf_fields = array();
         $cf_user_fields = array();
         foreach ($this->request->query() as $name => $field) {
             if (isset($field) and $field != NULL) {
                 // get by prefix cf
                 if (strpos($name, 'cf_') !== FALSE and array_key_exists(str_replace('cf_', '', $name), Model_Field::get_all())) {
                     $cf_fields[$name] = $field;
                     //checkbox when selected return string 'on' as a value
                     if ($field == 'on') {
                         $cf_fields[$name] = 1;
                     } elseif (empty($field)) {
                         $cf_fields[$name] = NULL;
                     }
                 } elseif (strpos($name, 'cfuser_') !== FALSE and array_key_exists(str_replace('cfuser_', '', $name), Model_UserField::get_all())) {
                     $name = str_replace('cfuser_', 'cf_', $name);
                     $cf_user_fields[$name] = $field;
                     //checkbox when selected return string 'on' as a value
                     if ($field == 'on') {
                         $cf_user_fields[$name] = 1;
                     } elseif (empty($field)) {
                         $cf_user_fields[$name] = NULL;
                     }
                 }
             }
         }
         $category = NULL;
         $location = NULL;
         if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) {
             //filter by category
             if (is_array(core::get('category'))) {
                 $cat_siblings_ids = array();
                 foreach (core::get('category') as $cat) {
                     if ($cat !== NULL) {
                         $category = new Model_Category();
                         $category->where('seoname', '=', $cat)->cached()->limit(1)->find();
                         if ($category->loaded()) {
                             $cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids());
                         }
                     }
                 }
                 if (count($cat_siblings_ids) > 0) {
                     $ads->where('id_category', 'IN', $cat_siblings_ids);
                 }
             }
             //filter by location
             if (is_array(core::get('location'))) {
                 $loc_siblings_ids = array();
                 foreach (core::get('location') as $loc) {
                     if ($loc !== NULL) {
                         $location = new Model_location();
                         $location->where('seoname', '=', $loc)->cached()->limit(1)->find();
                         if ($location->loaded()) {
                             $loc_siblings_ids = array_merge($loc_siblings_ids, $location->get_siblings_ids());
                         }
                     }
                 }
                 if (count($loc_siblings_ids) > 0) {
                     $ads->where('id_location', 'IN', $loc_siblings_ids);
                 }
             }
         } else {
             if (core::get('category') !== NULL) {
                 $category = new Model_Category();
                 $category->where('seoname', is_array(core::get('category')) ? 'in' : '=', core::get('category'))->cached()->limit(1)->find();
                 if ($category->loaded()) {
                     $ads->where('id_category', 'IN', $category->get_siblings_ids());
                 }
             }
             $location = NULL;
             //filter by location
             if (core::get('location') !== NULL) {
                 $location = new Model_location();
                 $location->where('seoname', is_array(core::get('location')) ? 'in' : '=', core::get('location'))->cached()->limit(1)->find();
                 if ($location->loaded()) {
                     $ads->where('id_location', 'IN', $location->get_siblings_ids());
                 }
             }
         }
         //filter by price(s)
         if (is_numeric($price_min = str_replace(',', '.', core::get('price-min')))) {
             // handle comma (,) used in some countries for prices
             $price_min = (double) $price_min;
         }
         // round((float)$price_min,2)
         if (is_numeric($price_max = str_replace(',', '.', core::get('price-max')))) {
             // handle comma (,) used in some countries for prices
             $price_max = (double) $price_max;
         }
         // round((float)$price_max,2)
         if (is_numeric($price_min) and is_numeric($price_max)) {
             // swap 2 values
             if ($price_min > $price_max) {
                 $aux = $price_min;
                 $price_min = $price_max;
                 $price_max = $aux;
                 unset($aux);
             }
             $ads->where('price', 'BETWEEN', array($price_min, $price_max));
         } elseif (is_numeric($price_min)) {
             $ads->where('price', '>=', $price_min);
         } elseif (is_numeric($price_max)) {
             $ads->where('price', '<=', $price_max);
         }
         //filter by CF ads
         if (count($cf_fields) > 0) {
             foreach ($cf_fields as $key => $value) {
                 //filter by range
                 if (array_key_exists(str_replace('cf_', '', $key), Model_Field::get_all()) and Model_Field::get_all()[str_replace('cf_', '', $key)]['type'] == 'range') {
                     $cf_min = isset($value[0]) ? $value[0] : NULL;
                     $cf_max = isset($value[1]) ? $value[1] : NULL;
                     if (is_numeric($cf_min = str_replace(',', '.', $cf_min))) {
                         // handle comma (,) used in some countries
                         $cf_min = (double) $cf_min;
                     }
                     if (is_numeric($cf_max = str_replace(',', '.', $cf_max))) {
                         // handle comma (,) used in some countries
                         $cf_max = (double) $cf_max;
                     }
                     if (is_numeric($cf_min) and is_numeric($cf_max)) {
                         // swap 2 values
                         if ($cf_min > $cf_max) {
                             $aux = $cf_min;
                             $cf_min = $cf_max;
                             $cf_max = $aux;
                             unset($aux);
                         }
                         $ads->where($key, 'BETWEEN', array($cf_min, $cf_max));
                     } elseif (is_numeric($cf_min)) {
                         // only min cf has been provided
                         $ads->where($key, '>=', $cf_min);
                     } elseif (is_numeric($cf_max)) {
                         // only max cf has been provided
                         $ads->where($key, '<=', $cf_max);
                     }
                 } elseif (is_numeric($value)) {
                     $ads->where($key, '=', $value);
                 } elseif (is_string($value)) {
                     $ads->where($key, 'like', '%' . $value . '%');
                 } elseif (is_array($value)) {
                     if (!empty($value = array_filter($value))) {
                         $ads->where($key, 'IN', $value);
                     }
                 }
             }
         }
         //filter by user
         if (count($cf_user_fields) > 0) {
             $users = new Model_User();
             foreach ($cf_user_fields as $key => $value) {
                 if (is_numeric($value)) {
                     $users->where($key, '=', $value);
                 } elseif (is_string($value)) {
                     $users->where($key, 'like', '%' . $value . '%');
                 } elseif (is_array($value)) {
                     if (!empty($value = array_filter($value))) {
                         $ads->where($key, 'IN', $value);
                     }
                 }
             }
             $users = $users->find_all();
             if ($users->count() > 0) {
                 $ads->where('id_user', 'in', $users->as_array());
             } else {
                 $ads->where('id_user', '=', 0);
             }
         }
         // count them for pagination
         $res_count = $ads->count_all();
         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));
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->offset));
             /**
              * 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;
                     //distance
                 //distance
                 case 'distance':
                     if (Model_User::get_userlatlng() and core::config('general.auto_locate')) {
                         $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 {
             $ads = NULL;
         }
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => Model_Category::get_as_array(), 'order_categories' => Model_Category::get_multidimensional(), 'locations' => Model_Location::get_as_array(), 'order_locations' => Model_Location::get_multidimensional(), 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all(), 'total_ads' => $res_count));
 }
Beispiel #7
0
        ?>
											</a>							
										</h2>
										<p class="ad_meta clearfix">
											<?php 
        if ($ad->published != 0) {
            ?>
												<span><i class="glyphicon glyphicon-calendar"></i> <?php 
            echo Date::format($ad->published, core::config('general.date_format'));
            ?>
</span>
											<?php 
        }
        ?>
											<?php 
        if ($ad->id_location and core::request('sort') == 'distance' and Model_User::get_userlatlng()) {
            ?>
												<span> - <i class="glyphicon glyphicon-map-marker"></i> <?php 
            echo i18n::format_measurement($ad->distance);
            ?>
 away</span>
											<?php 
        }
        ?>
										</p>
						
										<?php 
        if (core::config('advertisement.description') != FALSE) {
            ?>
											<p class="ad_desc"><?php 
            echo core::cookie('list/grid') == 1 ? Text::limit_chars(Text::removebbcode($ad->description), 255, NULL, TRUE) : Text::limit_chars(Text::removebbcode($ad->description), 30, NULL, TRUE);
Beispiel #8
0
 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'));
 }
Beispiel #9
0
 public function action_advanced_search()
 {
     $this->template->scripts['footer'][] = 'js/jquery.toolbar.js';
     $this->template->scripts['footer'][] = 'js/sort.js';
     //template header
     $this->template->title = __('Advanced Search');
     $this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name');
     //breadcrumbs
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     $pagination = NULL;
     $ads = NULL;
     $res_count = NULL;
     $user = $this->user ? $this->user : NULL;
     if ($this->request->query()) {
         // variables
         $search_advert = core::get('title');
         $search_loc = core::get('location');
         // filter by each variable
         $ads = new Model_Ad();
         // early filter
         $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);
         }
         if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
             // if user is using search from header
             if (core::get('search')) {
                 $search_advert = core::get('search');
             }
             $ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
         }
         $cf_fields = array();
         foreach ($this->request->query() as $name => $field) {
             // get by prefix
             if (strpos($name, 'cf_') !== false) {
                 $cf_fields[$name] = $field;
                 //checkbox when selected return string 'on' as a value
                 if ($field == 'on') {
                     $cf_fields[$name] = 1;
                 } elseif (empty($field)) {
                     $cf_fields[$name] = NULL;
                 }
             }
         }
         $category = NULL;
         $location = NULL;
         if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) {
             //filter by category
             if (is_array(core::get('category'))) {
                 $cat_siblings_ids = array();
                 foreach (core::get('category') as $cat) {
                     if ($cat !== NULL) {
                         $category = new Model_Category();
                         $category->where('seoname', '=', $cat)->cached()->limit(1)->find();
                         if ($category->loaded()) {
                             $cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids());
                         }
                     }
                 }
                 if (count($cat_siblings_ids) > 0) {
                     $ads->where('id_category', 'IN', $cat_siblings_ids);
                 }
             }
             //filter by location
             if (is_array(core::get('location'))) {
                 $loc_siblings_ids = array();
                 foreach (core::get('location') as $loc) {
                     if ($loc !== NULL) {
                         $location = new Model_location();
                         $location->where('seoname', '=', $loc)->cached()->limit(1)->find();
                         if ($location->loaded()) {
                             $loc_siblings_ids = array_merge($loc_siblings_ids, $location->get_siblings_ids());
                         }
                     }
                 }
                 if (count($loc_siblings_ids) > 0) {
                     $ads->where('id_location', 'IN', $loc_siblings_ids);
                 }
             }
         } else {
             if (core::get('category') !== NULL) {
                 $category = new Model_Category();
                 $category->where('seoname', '=', core::get('category'))->cached()->limit(1)->find();
                 if ($category->loaded()) {
                     $ads->where('id_category', 'IN', $category->get_siblings_ids());
                 }
             }
             $location = NULL;
             //filter by location
             if (core::get('location') !== NULL) {
                 $location = new Model_location();
                 $location->where('seoname', '=', core::get('location'))->cached()->limit(1)->find();
                 if ($location->loaded()) {
                     $ads->where('id_location', 'IN', $location->get_siblings_ids());
                 }
             }
         }
         //filter by price(s)
         if (is_numeric($price_min = str_replace(',', '.', core::get('price-min')))) {
             // handle comma (,) used in some countries for prices
             $price_min = (double) $price_min;
         }
         // round((float)$price_min,2)
         if (is_numeric($price_max = str_replace(',', '.', core::get('price-max')))) {
             // handle comma (,) used in some countries for prices
             $price_max = (double) $price_max;
         }
         // round((float)$price_max,2)
         if ($price_min and $price_max) {
             if ($price_min > $price_max) {
                 // swap 2 values
                 $price_min = $price_max + $price_min - ($price_max = $price_min);
             }
             $ads->where('price', 'BETWEEN', array($price_min, $price_max));
         } elseif ($price_min) {
             $ads->where('price', '>=', $price_min);
         } elseif ($price_max) {
             $ads->where('price', '<=', $price_max);
         }
         foreach ($cf_fields as $key => $value) {
             if (isset($value) and $value != NULL) {
                 if (is_numeric($value)) {
                     $ads->where($key, '=', $value);
                 } elseif (is_string($value)) {
                     $ads->where($key, 'like', '%' . $value . '%');
                 }
             }
         }
         // count them for pagination
         $res_count = $ads->count_all();
         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));
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->offset));
             /**
              * 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;
                     //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 {
             $ads = NULL;
         }
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => Model_Category::get_as_array(), 'order_categories' => Model_Category::get_multidimensional(), 'locations' => Model_Location::get_as_array(), 'order_locations' => Model_Location::get_multidimensional(), 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all(), 'total_ads' => $res_count));
 }