示例#1
0
 public function action_get()
 {
     try {
         if (is_numeric($id_category = $this->request->param('id'))) {
             $cat = array();
             $category = new Model_Category($id_category);
             if ($category->loaded()) {
                 $cat = $category->as_array();
                 $cat['price'] = i18n::money_format($category->price);
                 $cat['parents'] = $category->get_parents_ids();
                 $cat['siblings'] = $category->get_siblings_ids();
                 $cat['customfields'] = Model_Field::get_by_category($category->id_category);
                 $cat['icon'] = $category->get_icon();
                 $this->rest_output(array('category' => $cat));
             } else {
                 $this->_error(__('Category not found'), 404);
             }
         } else {
             $this->_error(__('Category not found'), 404);
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
         return;
     }
 }
示例#2
0
 /**
  * Function for saving emails to subscribers
  */
 public static function find_subscribers($data, $price, $seotitle, $email)
 {
     // locations are optional , get wiget settings for locations and categories
     $jsonObj = json_decode(core::config('widget.Widget_Subscribers_1373877069'), true);
     $subscribers = new Model_Subscribe();
     $category = new Model_Category($data['cat']);
     if ($category->loaded()) {
         if ($category->id_category_parent !== 1) {
             $cat_parent = $category->id_category_parent;
         }
     }
     //only min/max price is required in widget settings
     if ($price !== '0') {
         $subscribers->where('min_price', '<=', $price)->where('max_price', '>=', $price);
     } else {
         $subscribers->where('min_price', '<=', 0)->where('max_price', '>=', 0);
     }
     //location is set
     if ($data['loc'] != NULL and $jsonObj['data']['locations'] !== '0') {
         $subscribers = $subscribers->where('id_location', '=', $data['loc']);
     }
     //category is set
     if ($jsonObj['data']['categories'] !== '0') {
         $subscribers = $subscribers->where('id_category', 'IN', array($data['cat'], $cat_parent));
     }
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         $user = new Model_User();
         $user = $user->where('email', '=', $email)->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->find();
         // Send mails like in newsletter, to multiple users simultaneously @TODO NOT YET READY
         if (count($users) > 0) {
             $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
             if (!Email::send($users, '', "Advertisement is created on " . core::config('general.site_name') . "!", "Hello, You may be interested in this one: \n\n " . $data['title'] . "! \n\n\n                                        You can visit this link to see advertisement " . $url_ad, "no-reply " . core::config('general.site_name'), core::config('email.notify_email'))) {
                 Alert::set(Alert::ERROR, __('Error on mail delivery, not sent'));
             }
         }
     }
 }
示例#3
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;
 }
示例#4
0
 /**
  * CRUD controller: DELETE
  */
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $category = new Model_Category($this->request->param('id'));
     //update the elements related to that ad
     if ($category->loaded()) {
         //update all the siblings this category has and set the category parent
         $query = DB::update('categories')->set(array('id_category_parent' => $category->id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
         //update all the ads this category has and set the category parent
         $query = DB::update('ads')->set(array('id_category' => $category->id_category_parent))->where('id_category', '=', $category->id_category)->execute();
         try {
             $category->delete();
             $this->template->content = 'OK';
             Alert::set(Alert::SUCCESS, __('Category deleted'));
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, $e->getMessage());
         }
     } else {
         Alert::set(Alert::SUCCESS, __('Category not deleted'));
     }
     Request::current()->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
 }
示例#5
0
 /**
  * This function will upgrade DB that didn't existed in versions prior to 2.3.0
  */
 public function action_230()
 {
     //Cron update
     try {
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 3 * * *' WHERE callback='Sitemap::generate' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 5 * * *' WHERE callback='Core::delete_cache' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 4 1 * *' WHERE callback='Core::optimize_db' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 7 * * *' WHERE callback='Cron_Ad::unpaid' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 8 * * *' WHERE callback='Cron_Ad::expired_featured' LIMIT 1")->execute();
         DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 9 * * *' WHERE callback='Cron_Ad::expired' LIMIT 1")->execute();
     } catch (exception $e) {
     }
     //control login attempts
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute();
     } catch (exception $e) {
     }
     //categories/locations/users/ads has_image/last_modified
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "locations` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "ads` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     //new configs
     $configs = array(array('config_key' => 'aws_s3_active', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'aws_access_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_secret_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_bucket', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_domain', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'disallow_nudes', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'html_head', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'html_footer', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'login_to_contact', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'custom_css', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'custom_css_version', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'only_admin_post', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'map_active', 'group_name' => 'appearance', 'config_value' => 1), array('config_key' => 'map_jscode', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'map_settings', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'recaptcha_active', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_secretkey', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_sitekey', 'group_name' => 'general', 'config_value' => ''));
     Model_Config::config_array($configs);
     //upgrade has_image field to use it as images count
     $ads = new Model_Ad();
     $ads = $ads->where('has_images', '>', 0)->find_all();
     if (count($ads)) {
         foreach ($ads as $ad) {
             $ad->has_images = 0;
             //begin with 0 images
             $route = $ad->image_path();
             $folder = DOCROOT . $route;
             $image_keys = array();
             if (is_dir($folder)) {
                 //retrive ad pictures
                 foreach (new DirectoryIterator($folder) as $file) {
                     if (!$file->isDot()) {
                         $key = explode('_', $file->getFilename());
                         $key = end($key);
                         $key = explode('.', $key);
                         $key = isset($key[0]) ? $key[0] : NULL;
                         if (is_numeric($key)) {
                             if (strpos($file->getFilename(), 'thumb_') === 0) {
                                 $image_keys[] = $key;
                             }
                         }
                     }
                 }
                 //count images and reordering file names
                 if (count($image_keys)) {
                     asort($image_keys);
                     foreach ($image_keys as $image_key) {
                         $ad->has_images++;
                         @rename($folder . $ad->seotitle . '_' . $image_key . '.jpg', $folder . $ad->seotitle . '_' . $ad->has_images . '.jpg');
                         @rename($folder . 'thumb_' . $ad->seotitle . '_' . $image_key . '.jpg', $folder . 'thumb_' . $ad->seotitle . '_' . $ad->has_images . '.jpg');
                     }
                 }
             }
             //update has_images count
             try {
                 $ad->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     //upgrade categories has_image
     $images_path = DOCROOT . 'images/categories';
     if (is_dir($images_path)) {
         //retrive cat pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile()) {
                 $cat_name = str_replace('.png', '', $file->getFilename());
                 $cat = new Model_Category();
                 $cat->where('seoname', '=', $cat_name)->find();
                 if ($cat->loaded()) {
                     $cat->has_image = 1;
                     $cat->save();
                 }
             }
         }
     }
     //upgrade locations has_image
     $images_path = DOCROOT . 'images/locations';
     if (is_dir($images_path)) {
         //retrive loc pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile()) {
                 $loc_name = str_replace('.png', '', $file->getFilename());
                 $loc = new Model_Location();
                 $loc->where('seoname', '=', $loc_name)->find();
                 if ($loc->loaded()) {
                     $loc->has_image = 1;
                     $loc->save();
                 }
             }
         }
     }
     //upgrade users has_image
     $images_path = DOCROOT . 'images/users';
     if (is_dir($images_path)) {
         //retrive user pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile() and is_numeric($id_user = str_replace('.png', '', $file->getFilename()))) {
                 $user = new Model_User($id_user);
                 if ($user->loaded()) {
                     $user->has_image = 1;
                     $user->save();
                 }
             }
         }
     }
 }
示例#6
0
 /**
  * CRUD controller: DELETE
  */
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $category = new Model_Category($this->request->param('id'));
     //update the elements related to that ad
     if ($category->loaded()) {
         //check if the parent is loaded/exists avoiding errors, if doesnt exist to the root
         $parent_cat = new Model_Category($category->id_category_parent);
         if ($parent_cat->loaded()) {
             $id_category_parent = $category->id_category_parent;
         } else {
             $id_category_parent = 1;
         }
         //update all the siblings this category has and set the category parent
         $query = DB::update('categories')->set(array('id_category_parent' => $id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
         //update all the ads this category has and set the category parent
         $query = DB::update('ads')->set(array('id_category' => $id_category_parent))->where('id_category', '=', $category->id_category)->execute();
         //delete icon_delete
         $root = DOCROOT . 'images/categories/';
         //root folder
         if (is_dir($root)) {
             @unlink($root . $category->seoname . '.png');
             // delete icon from Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->deleteObject(core::config('image.aws_s3_bucket'), 'images/categories/' . $category->seoname . '.png');
             }
             // update category info
             $category->has_image = 0;
             $category->last_modified = Date::unix2mysql();
             $category->save();
         }
         try {
             $category->delete();
             $this->template->content = 'OK';
             //recalculating the deep of all the categories
             $this->action_deep();
             Core::delete_cache();
             Alert::set(Alert::SUCCESS, __('Category deleted'));
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, $e->getMessage());
         }
     } else {
         Alert::set(Alert::ERROR, __('Category not deleted'));
     }
     HTTP::redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
 }
示例#7
0
 /**
  * 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);
     }
 }
示例#8
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;
     $user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user();
     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 (!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));
             $ads = $ads->order_by('published', 'desc')->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()));
 }
示例#9
0
 /**
  * 
  * NEW ADVERTISEMENT 
  * 
  */
 public function action_index()
 {
     //Detect early spam users, show him alert
     if (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) {
         Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.'));
         $this->redirect('default');
     }
     //advertisement.only_admin_post
     if (Core::config('advertisement.only_admin_post') == 1 and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role != Model_Role::ROLE_ADMIN)) {
         $this->redirect('default');
     }
     if (Core::post('ajaxValidateCaptcha')) {
         $this->auto_render = FALSE;
         $this->template = View::factory('js');
         if (captcha::check('publish_new', TRUE)) {
             $this->template->content = 'true';
         } else {
             $this->template->content = 'false';
         }
         return;
     }
     //template header
     $this->template->title = __('Publish new advertisement');
     $this->template->meta_description = __('Publish new advertisement');
     $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.css' => 'screen');
     $this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js';
     $this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js';
     $this->template->scripts['footer'][] = 'js/jquery.chained.min.js';
     $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.js';
     $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js';
     if (core::config('advertisement.map_pub_new')) {
         $this->template->scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7';
         $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js';
     }
     $this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION;
     // redirect to login, if conditions are met
     if (core::config('advertisement.login_to_post') == TRUE and !Auth::instance()->logged_in()) {
         Alert::set(Alert::INFO, __('Please, login before posting advertisement!'));
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')));
     }
     //find all, for populating form select fields
     $categories = Model_Category::get_as_array();
     $order_categories = Model_Category::get_multidimensional();
     $order_parent_deep = Model_Category::get_by_deep();
     // NO categories redirect ADMIN to categories panel
     if (count($order_categories) == 0) {
         if (Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role == Model_Role::ROLE_ADMIN) {
             Alert::set(Alert::INFO, __('Please, first create some categories.'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
         } else {
             Alert::set(Alert::INFO, __('Posting advertisements is not yet available.'));
             $this->redirect('default');
         }
     }
     //get locations
     $locations = Model_Location::get_as_array();
     $order_locations = Model_Location::get_multidimensional();
     $loc_parent_deep = Model_Location::get_by_deep();
     // bool values from DB, to show or hide this fields in view
     $form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price'));
     $id_category = NULL;
     $selected_category = new Model_Category();
     //if theres a category by post or by get
     if (Core::request('category') !== NULL) {
         if (is_numeric(Core::request('category'))) {
             $selected_category->where('id_category', '=', core::request('category'))->limit(1)->find();
         } else {
             $selected_category->where('seoname', '=', core::request('category'))->limit(1)->find();
         }
         if ($selected_category->loaded()) {
             $id_category = $selected_category->id_category;
         }
     }
     $id_location = NULL;
     $selected_location = new Model_Location();
     //if theres a location by post or by get
     if (Core::request('location') !== NULL) {
         if (is_numeric(Core::request('location'))) {
             $selected_location->where('id_location', '=', core::request('location'))->limit(1)->find();
         } else {
             $selected_location->where('seoname', '=', core::request('location'))->limit(1)->find();
         }
         if ($selected_location->loaded()) {
             $id_location = $selected_location->id_location;
         }
     }
     //render view publish new
     $this->template->content = View::factory('pages/ad/new', array('categories' => $categories, 'order_categories' => $order_categories, 'order_parent_deep' => $order_parent_deep, 'locations' => $locations, 'order_locations' => $order_locations, 'loc_parent_deep' => $loc_parent_deep, 'form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all()));
     if ($this->request->post()) {
         if (captcha::check('publish_new')) {
             $data = $this->request->post();
             $validation = Validation::factory($data);
             //validate location since its optional
             if (core::config('advertisement.location')) {
                 if (count($locations) > 1) {
                     $validation = $validation->rule('location', 'not_empty')->rule('location', 'digit');
                 }
             }
             //user is not logged in validate input
             if (!Auth::instance()->logged_in()) {
                 $validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145));
             }
             if ($validation->check()) {
                 // User detection, if doesnt exists create
                 if (!Auth::instance()->logged_in()) {
                     $user = Model_User::create_email(core::post('email'), core::post('name'));
                 } else {
                     $user = Auth::instance()->get_user();
                 }
                 //to make it backward compatible with older themes: UGLY!!
                 if (isset($data['category']) and is_numeric($data['category'])) {
                     $data['id_category'] = $data['category'];
                     unset($data['category']);
                 }
                 if (isset($data['location']) and is_numeric($data['location'])) {
                     $data['id_location'] = $data['location'];
                     unset($data['location']);
                 }
                 //lets create!!
                 $return = Model_Ad::new_ad($data, $user);
                 //there was an error on the validation
                 if (isset($return['validation_errors']) and is_array($return['validation_errors'])) {
                     foreach ($return['validation_errors'] as $f => $err) {
                         Alert::set(Alert::ALERT, $err);
                     }
                 } elseif (isset($return['error'])) {
                     Alert::set($return['error_type'], $return['error']);
                 } elseif (isset($return['message']) and isset($return['ad'])) {
                     $new_ad = $return['ad'];
                     // IMAGE UPLOAD
                     $filename = NULL;
                     for ($i = 0; $i < core::config('advertisement.num_images'); $i++) {
                         if (isset($_FILES['image' . $i])) {
                             $filename = $new_ad->save_image($_FILES['image' . $i]);
                         }
                         if ($filename) {
                             $new_ad->has_images++;
                         }
                     }
                     //since theres images save the ad again...
                     if ($new_ad->has_images > 0) {
                         try {
                             $new_ad->save();
                         } catch (Exception $e) {
                             throw HTTP_Exception::factory(500, $e->getMessage());
                         }
                     }
                     Alert::set(Alert::SUCCESS, $return['message']);
                     //redirect user
                     if (isset($return['checkout_url']) and !empty($return['checkout_url'])) {
                         $this->redirect($return['checkout_url']);
                     } else {
                         $this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad)));
                     }
                 }
             } else {
                 $errors = $validation->errors('ad');
                 foreach ($errors as $f => $err) {
                     Alert::set(Alert::ALERT, $err);
                 }
             }
         } else {
             Alert::set(Alert::ALERT, __('Captcha is not correct'));
         }
     }
 }
示例#10
0
 public function action_import_tool()
 {
     $this->template->title = __('Import tool for locations and categories');
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     //sending a CSV
     if ($_POST) {
         foreach ($_FILES as $file => $path) {
             $csv = $path["tmp_name"];
             $csv_2[] = $file;
             if ($path['size'] > 1048576) {
                 Alert::set(Alert::ERROR, __('1 MB file'));
                 $this->redirect(Route::url('oc-panel', array('controller' => 'tools', 'action' => 'import_tool')));
             }
             if ($file == 'csv_file_categories' and $csv != FALSE) {
                 $expected_header = array('name', 'category_parent', 'price');
                 $cat_array = Core::csv_to_array($csv, $expected_header);
                 if (count($cat_array) > 10000) {
                     Alert::set(Alert::ERROR, __('limited to 10.000 at a time'));
                     $this->redirect(Route::url('oc-panel', array('controller' => 'tools', 'action' => 'import_tool')));
                 }
                 if ($cat_array === FALSE) {
                     Alert::set(Alert::ERROR, __('Something went wrong, please check format of the file! Remove single quotes or strange characters, in case you have any.'));
                 } else {
                     foreach ($cat_array as $cat) {
                         //category parent was sent?
                         if ($cat[1]) {
                             $category_parent = new Model_Category();
                             $category_parent->where('name', '=', $cat[1])->limit(1)->find();
                             if ($category_parent->loaded()) {
                                 $cat[1] = $category_parent->id_category;
                             } else {
                                 $cat[1] = 1;
                             }
                         } else {
                             $cat[1] = 1;
                         }
                         Model_Category::create_name($cat[0], 0, $cat[1], 0, $cat[2]);
                     }
                     Core::delete_cache();
                     Alert::set(Alert::SUCCESS, __('Categories successfully imported.'));
                 }
             } elseif ($file == 'csv_file_locations' and $csv != FALSE) {
                 $expected_header = array('name', 'location_parent', 'latitude', 'longitude');
                 $loc_array = Core::csv_to_array($csv, $expected_header);
                 if (count($loc_array) > 10000) {
                     Alert::set(Alert::ERROR, __('limited to 10.000 at a time'));
                     $this->redirect(Route::url('oc-panel', array('controller' => 'tools', 'action' => 'import_tool')));
                 }
                 if ($loc_array === FALSE) {
                     Alert::set(Alert::ERROR, __('Something went wrong, please check format of the file! Remove single quotes or strange characters, in case you have any.'));
                 } else {
                     foreach ($loc_array as $loc) {
                         //location parent was sent?
                         if ($loc[1]) {
                             $location_parent = new Model_Location();
                             $location_parent->where('name', '=', $loc[1])->limit(1)->find();
                             if ($location_parent->loaded()) {
                                 $loc[1] = $location_parent->id_location;
                             } else {
                                 $loc[1] = 1;
                             }
                         } else {
                             $loc[1] = 1;
                         }
                         Model_Location::create_name($loc[0], 0, $loc[1], 0, $loc[2], $loc[3]);
                     }
                     Core::delete_cache();
                     Alert::set(Alert::SUCCESS, __('Locations successfully imported.'));
                 }
             }
         }
     }
     $this->template->content = View::factory('oc-panel/pages/tools/import_tool');
 }
示例#11
0
 /**
  * This function will upgrade configs
  */
 public function action_170()
 {
     //deleted classes moved to common
     File::delete(DOCROOT . 'oc/classes/bitpay.php');
     File::delete(DOCROOT . 'oc/classes/paymill.php');
     File::delete(DOCROOT . 'oc/classes/stripeko.php');
     File::delete(DOCROOT . 'themes/default/views/pages/authorize/button.php');
     File::delete(DOCROOT . 'themes/default/views/pages/bitpay/button_loged.php');
     File::delete(DOCROOT . 'themes/default/views/pages/paymill/button_loged.php');
     //crontabs
     try {
         DB::query(Database::UPDATE, "INSERT INTO `" . self::$db_prefix . "crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES\n                                    ('Unpaid Orders', '0 7 * * *', 'Model_Order::cron_unpaid', NULL, 'Notify by email unpaid orders 2 days after was created', 1);")->execute();
     } catch (exception $e) {
     }
     //url buy
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "products` ADD `url_buy` varchar(245) ;")->execute();
     } catch (exception $e) {
     }
     //control login attempts
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute();
     } catch (exception $e) {
     }
     //EU VAT
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users`  ADD `VAT_number` VARCHAR(65) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users`   ADD `country` VARCHAR(3) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `city` VARCHAR(65) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users`  ADD `postal_code` VARCHAR(20) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `address` VARCHAR(150) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     //eu vat orders
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders`  ADD `VAT` decimal(14,3) NOT NULL DEFAULT '0.000'")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders`  ADD `VAT_number` VARCHAR(65) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders`   ADD `country` VARCHAR(3) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders` ADD `city` VARCHAR(65) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders`  ADD `postal_code` VARCHAR(20) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders` ADD `address` VARCHAR(150) NULL DEFAULT NULL")->execute();
     } catch (exception $e) {
     }
     //categories/users has_image/last_modified
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute();
     } catch (exception $e) {
     }
     //configs
     $configs = array(array('config_key' => 'aws_s3_active', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'aws_access_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_secret_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_bucket', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_domain', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'html_head', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'html_footer', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'custom_css', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'custom_css_version', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'eu_vat', 'group_name' => 'general', 'config_value' => 0), array('config_key' => 'vat_number', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'company_name', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'vat_excluded_countries', 'group_name' => 'general', 'config_value' => ''));
     Model_Config::config_array($configs);
     //new mails
     $contents = array(array('order' => 0, 'title' => 'Receipt for [ORDER.DESC] #[ORDER.ID]', 'seotitle' => 'new-order', 'description' => "Hello [USER.NAME],Thanks for buying [ORDER.DESC].\n\nPlease complete the payment here [URL.CHECKOUT]", 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1'));
     Model_Content::content_array($contents);
     //upgrade has_image field to use it as images count
     $products = new Model_Product();
     $products = $products->where('has_images', '=', 0)->find_all();
     if (count($products)) {
         foreach ($products as $product) {
             $product->has_images = 0;
             //begin with 0 images
             $route = $product->image_path();
             $folder = DOCROOT . $route;
             $image_keys = array();
             if (is_dir($folder)) {
                 //retrive ad pictures
                 foreach (new DirectoryIterator($folder) as $file) {
                     if (!$file->isDot()) {
                         $key = explode('_', $file->getFilename());
                         $key = end($key);
                         $key = explode('.', $key);
                         $key = isset($key[0]) ? $key[0] : NULL;
                         if (is_numeric($key)) {
                             if (strpos($file->getFilename(), 'thumb_') === 0) {
                                 $image_keys[] = $key;
                             }
                         }
                     }
                 }
                 //count images and reordering file names
                 if (count($image_keys)) {
                     asort($image_keys);
                     foreach ($image_keys as $image_key) {
                         $product->has_images++;
                         @rename($folder . $product->seotitle . '_' . $image_key . '.jpg', $folder . $product->seotitle . '_' . $product->has_images . '.jpg');
                         @rename($folder . 'thumb_' . $product->seotitle . '_' . $image_key . '.jpg', $folder . 'thumb_' . $product->seotitle . '_' . $product->has_images . '.jpg');
                     }
                 }
             }
             //update has_images count
             try {
                 $product->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     //TODO
     //update has images
     //upgrade categories has_image
     $images_path = DOCROOT . 'images/categories';
     if (is_dir($images_path)) {
         //retrive cat pictures
         foreach (new DirectoryIterator($images_path) as $file) {
             if ($file->isFile()) {
                 $cat_name = str_replace('.png', '', $file->getFilename());
                 $cat = new Model_Category();
                 $cat->where('seoname', '=', $cat_name)->find();
                 if ($cat->loaded()) {
                     $cat->has_image = 1;
                     $cat->save();
                 }
             }
         }
     }
     //update crontabs
 }
示例#12
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));
 }
示例#13
0
 /**
  * API that return the products.
  * Allows api/products/<category_optional>?order1=rate&sort=asc&order2=version&sort=desc
  * @return [type] [description]
  */
 public function action_products()
 {
     $this->auto_render = FALSE;
     $sort_allowed = array('asc', 'desc');
     $order_allowed = array('id_category', 'created', 'updated', 'price', 'title', 'rate');
     $order1 = Core::get('order1');
     //default value
     if (!in_array($order1, $order_allowed) or $order1 === NULL) {
         $order1 = 'id_category';
     }
     $sort1 = Core::get('sort1');
     //default value
     if (!in_array($sort1, $sort_allowed) or $sort1 === NULL) {
         $sort1 = 'asc';
     }
     $order2 = Core::get('order2');
     //default value
     if (!in_array($order2, $order_allowed) or $order2 === NULL) {
         $order2 = 'price';
     }
     $sort2 = Core::get('sort2');
     //default value
     if (!in_array($sort2, $sort_allowed) or $sort2 === NULL) {
         $sort2 = 'asc';
     }
     $items = array();
     //products filtered
     $products = new Model_Product();
     $products = $products->where('status', '=', Model_Product::STATUS_ACTIVE)->order_by($order1, $sort1)->order_by($order2, $sort2);
     //filter by category
     $seo_category = $this->request->param('id');
     if ($seo_category !== NULL) {
         $category = new Model_Category();
         $category->where('seoname', '=', $seo_category)->limit(1)->find();
         if ($category->loaded()) {
             $products->where('id_category', '=', $category->id_category);
         }
     }
     $products = $products->cached()->find_all();
     $i = 0;
     foreach ($products as $p) {
         $url = Route::url('product', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname));
         $urlmin = Route::url('product-minimal', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname));
         $in_offer = Date::mysql2unix($p->offer_valid) > time() ? TRUE : FALSE;
         $items[] = array('id_product' => $p->id_product, 'order' => $i, 'title' => $p->title, 'seoname' => $p->seotitle, 'skins' => $p->skins, 'url_more' => $url, 'url_buy' => $url, 'url_demo' => !empty($p->url_demo) ? Route::url('product-demo', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname)) : '', 'url_screenshot' => URL::base() . $p->get_first_image('image'), 'type' => $p->category->seoname, 'price' => $p->price, 'currency' => $p->currency, 'price_offer' => $in_offer === TRUE ? $p->price_offer : NULL, 'offer_valid' => $in_offer === TRUE ? $p->offer_valid : NULL, 'rate' => $p->rate, 'created' => $p->created, 'updated' => $p->updated, 'version' => $p->version, 'description' => Text::removebbcode(preg_replace('/&(?!\\w+;)/', '&amp;', $p->description)));
         $i++;
     }
     $this->response->headers('Content-type', 'application/javascript');
     $this->response->body(json_encode($items));
 }
示例#14
0
 /**
  * 
  * NEW ADVERTISEMENT 
  * 
  */
 public function action_index()
 {
     //advertisement.only_admin_post
     if (Core::config('advertisement.only_admin_post') == TRUE and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and !$this->user->is_admin())) {
         $this->redirect(Route::url('default'));
     } elseif ((Core::config('advertisement.login_to_post') == TRUE or Core::config('payment.stripe_connect') == TRUE or Core::config('general.subscriptions') == TRUE) and !Auth::instance()->logged_in()) {
         Alert::set(Alert::INFO, __('Please, login before posting advertisement!'));
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')) . '?auth_redirect=' . URL::current());
     } elseif (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) {
         Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.'));
         $this->redirect(Route::url('default'));
     } elseif (Core::config('payment.stripe_connect') == TRUE and empty($this->user->stripe_user_id)) {
         Alert::set(Alert::INFO, __('Please, connect with Stripe'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit')));
     } elseif (Core::config('general.subscriptions') == TRUE and Theme::get('premium') == TRUE) {
         $subscription = $this->user->subscription();
         //if theres no subscription or expired or without free ads
         if (!$subscription->loaded() or $subscription->loaded() and (Date::mysql2unix($subscription->expire_date) < time() or $subscription->amount_ads_left == 0)) {
             Alert::set(Alert::INFO, __('Please, choose a plan first'));
             HTTP::redirect(Route::url('pricing'));
         }
     }
     //validates captcha
     if (Core::post('ajaxValidateCaptcha')) {
         $this->auto_render = FALSE;
         $this->template = View::factory('js');
         if (captcha::check('publish_new', TRUE)) {
             $this->template->content = 'true';
         } else {
             $this->template->content = 'false';
         }
         return;
     }
     Controller::$full_width = TRUE;
     //template header
     $this->template->title = __('Publish new advertisement');
     $this->template->meta_description = __('Publish new advertisement');
     $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen');
     $this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js';
     $this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js';
     $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js';
     $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js';
     $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js';
     $this->template->scripts['footer'][] = 'js/canvasResize.js';
     if (core::config('advertisement.map_pub_new')) {
         $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap';
     }
     $this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION;
     $categories = new Model_Category();
     $categories = $categories->where('id_category_parent', '=', '1');
     // NO categories redirect ADMIN to categories panel
     if ($categories->count_all() == 0) {
         if (Auth::instance()->logged_in() and Auth::instance()->get_user()->is_admin()) {
             Alert::set(Alert::INFO, __('Please, first create some categories.'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
         } else {
             Alert::set(Alert::INFO, __('Posting advertisements is not yet available.'));
             $this->redirect(Route::url('default'));
         }
     }
     //get locations
     $locations = new Model_Location();
     $locations = $locations->where('id_location', '!=', '1');
     // bool values from DB, to show or hide this fields in view
     $form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'description' => core::config('advertisement.description'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price'));
     $id_category = NULL;
     $selected_category = new Model_Category();
     //if theres a category by post or by get
     if (Core::request('category') !== NULL) {
         if (is_numeric(Core::request('category'))) {
             $selected_category->where('id_category', '=', core::request('category'))->limit(1)->find();
         } else {
             $selected_category->where('seoname', '=', core::request('category'))->limit(1)->find();
         }
         if ($selected_category->loaded()) {
             $id_category = $selected_category->id_category;
         }
     }
     $id_location = NULL;
     $selected_location = new Model_Location();
     //if theres a location by post or by get
     if (Core::request('location') !== NULL) {
         if (is_numeric(Core::request('location'))) {
             $selected_location->where('id_location', '=', core::request('location'))->limit(1)->find();
         } else {
             $selected_location->where('seoname', '=', core::request('location'))->limit(1)->find();
         }
         if ($selected_location->loaded()) {
             $id_location = $selected_location->id_location;
         }
     }
     //render view publish new
     $this->template->content = View::factory('pages/ad/new', array('form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all()));
     if ($this->request->post()) {
         if (captcha::check('publish_new')) {
             $data = $this->request->post();
             $validation = Validation::factory($data);
             //validate location since its optional
             if (core::config('advertisement.location')) {
                 if ($locations->count_all() > 1) {
                     $validation = $validation->rule('location', 'not_empty')->rule('location', 'digit');
                 }
             }
             //user is not logged in validate input
             if (!Auth::instance()->logged_in()) {
                 $validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145));
             }
             // Optional banned words validation
             if (core::config('advertisement.validate_banned_words')) {
                 $validation = $validation->rule('title', 'no_banned_words');
                 $validation = $validation->rule('description', 'no_banned_words');
             }
             if ($validation->check()) {
                 // User detection, if doesnt exists create
                 if (!Auth::instance()->logged_in()) {
                     $user = Model_User::create_email(core::post('email'), core::post('name'));
                 } else {
                     $user = Auth::instance()->get_user();
                 }
                 //to make it backward compatible with older themes: UGLY!!
                 if (isset($data['category']) and is_numeric($data['category'])) {
                     $data['id_category'] = $data['category'];
                     unset($data['category']);
                 }
                 if (isset($data['location']) and is_numeric($data['location'])) {
                     $data['id_location'] = $data['location'];
                     unset($data['location']);
                 }
                 //lets create!!
                 $return = Model_Ad::new_ad($data, $user);
                 //there was an error on the validation
                 if (isset($return['validation_errors']) and is_array($return['validation_errors'])) {
                     foreach ($return['validation_errors'] as $f => $err) {
                         Alert::set(Alert::ALERT, $err);
                     }
                 } elseif (isset($return['error'])) {
                     Alert::set($return['error_type'], $return['error']);
                 } elseif (isset($return['message']) and isset($return['ad'])) {
                     $new_ad = $return['ad'];
                     // IMAGE UPLOAD
                     $filename = NULL;
                     for ($i = 0; $i < core::config('advertisement.num_images'); $i++) {
                         if (Core::post('base64_image' . $i)) {
                             $filename = $new_ad->save_base64_image(Core::post('base64_image' . $i));
                         } elseif (isset($_FILES['image' . $i])) {
                             $filename = $new_ad->save_image($_FILES['image' . $i]);
                         }
                     }
                     Alert::set(Alert::SUCCESS, $return['message']);
                     //redirect user
                     if (isset($return['checkout_url']) and !empty($return['checkout_url'])) {
                         $this->redirect($return['checkout_url']);
                     } else {
                         $this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad)));
                     }
                 }
             } else {
                 $errors = $validation->errors('ad');
                 foreach ($errors as $f => $err) {
                     Alert::set(Alert::ALERT, $err);
                 }
             }
         } else {
             Alert::set(Alert::ALERT, __('Captcha is not correct'));
         }
     }
 }
示例#15
0
文件: ad.php 项目: Wildboard/WbWebApp
 public function action_advanced_search()
 {
     //template header
     $this->template->title = __('Advanced Search');
     $this->template->meta_description = __('Advanced Search');
     //breadcrumbs
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     $this->template->scripts['footer'] = array('js/search.js');
     // $cat_obj = new Model_Category();
     // $loc_obj = new Model_Location();
     list($cat_obj, $order_categories) = Model_Category::get_all();
     list($loc_obj, $order_locations) = Model_Location::get_all();
     $pagination = NULL;
     $ads = NULL;
     $user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user();
     if ($this->request->query()) {
         // variables
         $search_advert = core::get('title');
         $search_loc = core::get('location');
         // filter by each variable
         $ads = new Model_Ad();
         //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()'));
         }
         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;
         //filter by category
         if (core::get('category') !== NULL) {
             $category = new Model_Category();
             $category->where('seoname', '=', core::get('category'))->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'))->limit(1)->find();
             if ($location->loaded()) {
                 $ads->where('id_location', 'IN', $location->get_siblings_ids());
             }
         }
         //filter by price
         if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) {
             $ads->where('price', 'BETWEEN', array(core::get('price-min'), core::get('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 . '%');
                 }
             }
         }
         $ads = $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
         // 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('general.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));
             $ads = $ads->order_by('published', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
         }
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => $cat_obj, 'order_categories' => $order_categories, 'locations' => $loc_obj, 'order_locations' => $order_locations, 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all()));
 }
示例#16
0
 /**
  * CRUD controller: DELETE
  */
 public function action_delete()
 {
     $this->auto_render = FALSE;
     $categories = array();
     if ($id_category = $this->request->param('id')) {
         $categories[] = $id_category;
     } elseif (core::post('categories')) {
         $categories = core::post('categories');
     }
     if (count($categories) > 0) {
         foreach ($categories as $id_category) {
             $category = new Model_Category($id_category);
             //update the elements related to that ad
             if ($category->loaded()) {
                 //check if the parent is loaded/exists avoiding errors, if doesnt exist to the root
                 $parent_cat = new Model_Category($category->id_category_parent);
                 if ($parent_cat->loaded()) {
                     $id_category_parent = $category->id_category_parent;
                 } else {
                     $id_category_parent = 1;
                 }
                 //update all the siblings this category has and set the category parent
                 $query = DB::update('categories')->set(array('id_category_parent' => $id_category_parent))->where('id_category_parent', '=', $category->id_category)->execute();
                 //update all the ads this category has and set the category parent
                 $query = DB::update('ads')->set(array('id_category' => $id_category_parent))->where('id_category', '=', $category->id_category)->execute();
                 try {
                     $category_name = $category->name;
                     $category->delete();
                     $this->template->content = 'OK';
                     //recalculating the deep of all the categories
                     $this->action_deep();
                     Core::delete_cache();
                     Alert::set(Alert::SUCCESS, sprintf(__('Category %s deleted'), $category_name));
                 } catch (Exception $e) {
                     Alert::set(Alert::ERROR, $e->getMessage());
                 }
             } else {
                 Alert::set(Alert::ERROR, __('Category not deleted'));
             }
         }
     }
     HTTP::redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index')));
 }
示例#17
0
 /**
  * remove category from custom field
  * @return void 
  */
 public function action_remove_category()
 {
     if (Core::get('id_category')) {
         $name = $this->request->param('id');
         $field = new Model_Field();
         $field_data = $field->get($name);
         $category = new Model_Category(Core::get('id_category'));
         // category or custom field not found
         if (!$category->loaded() or !$field_data) {
             $this->redirect(Route::get('oc-panel')->uri(array('controller' => Request::current()->controller(), 'action' => 'index')));
         }
         // remove current category from custom field categories
         if (is_array($field_data['categories']) and ($key = array_search($category->id_category, $field_data['categories'])) !== FALSE) {
             unset($field_data['categories'][$key]);
         }
         try {
             // update custom field categories
             if ($field->update($name, $field_data['values'], $field_data['categories'], $field_data)) {
                 Core::delete_cache();
                 Alert::set(Alert::SUCCESS, sprintf(__('Field %s removed'), $name));
             } else {
                 Alert::set(Alert::ERROR, sprintf(__('Field %s cannot be removed'), $name));
             }
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         $this->redirect(Route::get('oc-panel')->uri(array('controller' => 'category', 'action' => 'update', 'id' => $category->id_category)));
     }
     $this->redirect(Route::get('oc-panel')->uri(array('controller' => Request::current()->controller(), 'action' => 'index')));
 }
示例#18
0
 public function action_search()
 {
     //template header
     $this->template->title = __('Advanced Search');
     $this->template->meta_description = __('Search in') . ' ' . Core::config('general.site_name');
     $this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen');
     $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js');
     //breadcrumbs
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     $categories = Model_Category::get_as_array();
     $order_categories = Model_Category::get_multidimensional();
     $pagination = NULL;
     $products = NULL;
     if ($this->request->query()) {
         $products = new Model_Product();
         $category = NULL;
         //filter by category
         if (core::get('category') !== NULL) {
             $category = new Model_Category();
             $category->where('seoname', '=', core::get('category'))->limit(1)->find();
             if ($category->loaded()) {
                 $products->where('id_category', 'IN', $category->get_siblings_ids());
             }
         }
         //filter by title description
         if (core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
             $products->where_open()->where('title', 'like', '%' . core::get('search') . '%')->or_where('description', 'like', '%' . core::get('search') . '%')->where_close();
         }
         //filter by price
         if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) {
             $products->where('price', 'BETWEEN', array(core::get('price-min'), core::get('price-max')));
         }
         //only published products
         $products->where('status', '=', Model_Product::STATUS_ACTIVE);
         $res_count = $products->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('general.products_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->current_page));
             //we sort all products with few parameters
             $products = $products->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
         }
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/search', array('categories' => $categories, 'order_categories' => $order_categories, 'products' => $products, 'pagination' => $pagination));
 }