public function display($instance = array()) { /** check access **/ if (!wpl_users::check_access('propertylisting')) { /** import message tpl **/ $this->message = __("You don't have access to this part!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } $this->tpl = wpl_request::getVar('tpl', 'default'); $this->method = wpl_request::getVar('wplmethod', NULL); /** global settings **/ $this->settings = wpl_settings::get_settings(); /** listing settings **/ $this->page_number = wpl_request::getVar('wplpage', 1, '', true); $this->limit = wpl_request::getVar('limit', $this->settings['default_page_size']); $this->start = wpl_request::getVar('start', ($this->page_number - 1) * $this->limit, '', true); $this->orderby = wpl_request::getVar('wplorderby', $this->settings['default_orderby'], '', true); $this->order = wpl_request::getVar('wplorder', $this->settings['default_order'], '', true); /** Set Property CSS class **/ $this->property_css_class = !$this->wplraw ? wpl_request::getVar('wplpcc', NULL) : NULL; if (!$this->property_css_class) { $this->property_css_class = wpl_request::getVar('wplpcc', 'grid_box', 'COOKIE'); } $this->property_css_class_switcher = wpl_request::getVar('wplpcc_switcher', '1'); $this->property_listview = wpl_request::getVar('wplplv', '1'); #Show listview or not /** RSS Feed Setting **/ $this->listings_rss_enabled = isset($this->settings['listings_rss_enabled']) ? $this->settings['listings_rss_enabled'] : 0; /** detect kind **/ $this->kind = wpl_request::getVar('kind', 0); if (!$this->kind) { $this->kind = wpl_request::getVar('sf_select_kind', 0); } if (!in_array($this->kind, wpl_flex::get_valid_kinds())) { /** import message tpl **/ $this->message = __('Invalid Request!', WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } /** pagination types **/ $this->wplpagination = wpl_request::getVar('wplpagination', 'normal', '', true); wpl_request::setVar('wplpagination', $this->wplpagination); /** property listing model **/ $this->model = new wpl_property(); /** set page if start var passed **/ $this->page_number = $this->start / $this->limit + 1; wpl_request::setVar('wplpage', $this->page_number); $where = array('sf_select_confirmed' => 1, 'sf_select_finalized' => 1, 'sf_select_deleted' => 0, 'sf_select_expired' => 0, 'sf_select_kind' => $this->kind); /** Add search conditions to the where **/ $vars = array_merge(wpl_request::get('POST'), wpl_request::get('GET')); $where = array_merge($vars, $where); /** start search **/ $this->model->start($this->start, $this->limit, $this->orderby, $this->order, $where, $this->kind); $this->model->total = $this->model->get_properties_count(); /** validation for page_number **/ $this->total_pages = ceil($this->model->total / $this->limit); if ($this->page_number <= 0 or $this->page_number > $this->total_pages) { $this->model->start = 0; } /** run the search **/ $query = $this->model->query(); $properties = $this->model->search(); /** finish search **/ $this->model->finish(); $plisting_fields = $this->model->get_plisting_fields('', $this->kind); $wpl_properties = array(); foreach ($properties as $property) { $wpl_properties[$property->id] = $this->model->full_render($property->id, $plisting_fields, $property); } /** define current index **/ $wpl_properties['current'] = array(); /** apply filters (This filter must place after all proccess) **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('property_listing_after_render', array('wpl_properties' => $wpl_properties))); $this->pagination = wpl_pagination::get_pagination($this->model->total, $this->limit, true, $this->wplraw); $this->wpl_properties = $wpl_properties; if ($this->wplraw and $this->method == 'get_markers') { $markers = array('markers' => $this->model->render_markers($wpl_properties), 'total' => $this->model->total); echo json_encode($markers); exit; } elseif ($this->wplraw and $this->method == 'get_listings') { if ($this->return_listings) { return $wpl_properties; } else { echo json_encode($wpl_properties); exit; } } /** import tpl **/ $this->tpl = wpl_flex::get_kind_tpl($this->tpl_path, $this->tpl, $this->kind); return parent::render($this->tpl_path, $this->tpl, false, true); }
/** * Generate location text of User * @author Howard R <*****@*****.**> * @static * @param array $user_data * @param int $user_id * @param string $glue * @return string */ public static function generate_location_text($user_data, $user_id = 0, $glue = ',') { /** fetch user data if user id is setted **/ if ($user_id) { $user_data = (array) wpl_users::get_wpl_user($user_id); } if (!$user_id) { $user_id = $user_data['id']; } $locations = array(); if (isset($user_data['location7_name']) and trim($user_data['location7_name']) != '') { $locations['location7_name'] = __($user_data['location7_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location6_name']) and trim($user_data['location6_name']) != '') { $locations['location6_name'] = __($user_data['location6_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location5_name']) and trim($user_data['location5_name']) != '') { $locations['location5_name'] = __($user_data['location5_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location4_name']) and trim($user_data['location4_name']) != '') { $locations['location4_name'] = __($user_data['location4_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location3_name']) and trim($user_data['location3_name']) != '') { $locations['location3_name'] = __($user_data['location3_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location2_name']) and trim($user_data['location2_name']) != '') { $locations['location2_name'] = __($user_data['location2_name'], WPL_TEXTDOMAIN); } if (isset($user_data['zip_name']) and trim($user_data['zip_name']) != '') { $locations['zip_name'] = __($user_data['zip_name'], WPL_TEXTDOMAIN); } if (isset($user_data['location1_name']) and trim($user_data['location1_name']) != '') { $locations['location1_name'] = __($user_data['location1_name'], WPL_TEXTDOMAIN); } $location_pattern = wpl_global::get_setting('user_location_pattern'); if (trim($location_pattern) == '') { $location_pattern = '[location5_name][glue][location4_name][glue][location3_name][glue][location2_name][glue][location1_name] [zip_name]'; } $location_text = ''; $location_text = isset($locations['location7_name']) ? str_replace('[location7_name]', $locations['location7_name'], $location_pattern) : str_replace('[location7_name]', '', $location_pattern); $location_text = isset($locations['location6_name']) ? str_replace('[location6_name]', $locations['location6_name'], $location_pattern) : str_replace('[location6_name]', '', $location_pattern); $location_text = isset($locations['location5_name']) ? str_replace('[location5_name]', $locations['location5_name'], $location_pattern) : str_replace('[location5_name]', '', $location_pattern); $location_text = isset($locations['location4_name']) ? str_replace('[location4_name]', $locations['location4_name'], $location_text) : str_replace('[location4_name]', '', $location_text); $location_text = isset($locations['location3_name']) ? str_replace('[location3_name]', $locations['location3_name'], $location_text) : str_replace('[location3_name]', '', $location_text); $location_text = isset($locations['location2_name']) ? str_replace('[location2_name]', $locations['location2_name'], $location_text) : str_replace('[location2_name]', '', $location_text); $location_text = isset($locations['zip_name']) ? str_replace('[zip_name]', $locations['zip_name'], $location_text) : str_replace('[zip_name]', '', $location_text); $location_text = isset($locations['location1_name']) ? str_replace('[location1_name]', $locations['location1_name'], $location_text) : str_replace('[location1_name]', '', $location_text); $location_text = str_replace('[glue]', $glue, $location_text); /** apply filters **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('generate_user_location_text', array('location_text' => $location_text, 'glue' => $glue, 'user_data' => $user_data))); $final = ''; $ex = explode($glue, $location_text); foreach ($ex as $value) { if (trim($value) == '') { continue; } $final .= trim($value) . $glue . ' '; } $location_text = trim($final, $glue . ' '); $column = 'location_text'; $field_id = wpl_flex::get_dbst_id($column, 2); $field = wpl_flex::get_field($field_id); if (isset($field->multilingual) and $field->multilingual and wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } /** update **/ $query = "UPDATE `#__wpl_users` SET `{$column}`='" . $location_text . "' WHERE `id`='{$user_id}'"; wpl_db::q($query, 'update'); return $location_text; }
public function display($instance = array()) { /** do cronjobs **/ _wpl_import('libraries.events'); wpl_events::do_cronjobs(); /** check access **/ if (!wpl_users::check_access('propertyshow')) { /** import message tpl **/ $this->message = __("You don't have access to this part!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } $this->tpl = wpl_request::getVar('tpl', 'default'); /** property listing model **/ $this->model = new wpl_property(); $this->pid = wpl_request::getVar('pid', 0); $listing_id = wpl_request::getVar('mls_id', 0); if (trim($listing_id)) { $this->pid = wpl_property::pid($listing_id); wpl_request::setVar('pid', $this->pid); } $property = $this->model->get_property_raw_data($this->pid); /** no property found **/ if (!$property or $property['finalized'] == 0 or $property['confirmed'] == 0 or $property['deleted'] == 1 or $property['expired'] >= 1) { /** import message tpl **/ $this->message = __("No property found or it's not available now!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } $this->pshow_fields = $this->model->get_pshow_fields('', $property['kind']); $this->pshow_categories = wpl_flex::get_categories('', '', " AND `enabled`>='1' AND `kind`='" . $property['kind'] . "' AND `pshow`='1'"); $wpl_properties = array(); /** define current index **/ $wpl_properties['current']['data'] = (array) $property; $wpl_properties['current']['raw'] = (array) $property; $find_files = array(); $rendered_fields = $this->model->render_property($property, $this->pshow_fields, $find_files, true); $wpl_properties['current']['rendered_raw'] = $rendered_fields['ids']; $wpl_properties['current']['materials'] = $rendered_fields['columns']; foreach ($this->pshow_categories as $pshow_category) { $pshow_cat_fields = $this->model->get_pshow_fields($pshow_category->id, $property['kind']); $wpl_properties['current']['rendered'][$pshow_category->id]['self'] = (array) $pshow_category; $wpl_properties['current']['rendered'][$pshow_category->id]['data'] = $this->model->render_property($property, $pshow_cat_fields); } $wpl_properties['current']['items'] = wpl_items::get_items($this->pid, '', $property['kind'], '', 1); /** property location text **/ $wpl_properties['current']['location_text'] = $this->model->generate_location_text((array) $property); /** property full link **/ $wpl_properties['current']['property_link'] = $this->model->get_property_link((array) $property); /** property page title **/ $wpl_properties['current']['property_page_title'] = $this->model->update_property_page_title($property); /** property title **/ $wpl_properties['current']['property_title'] = $this->model->update_property_title($property); /** apply filters (This filter must place after all proccess) **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('property_listing_after_render', array('wpl_properties' => $wpl_properties))); $this->wpl_properties = $wpl_properties; $this->kind = $property['kind']; $this->property = $wpl_properties['current']; /** updating the visited times and etc **/ wpl_property::property_visited($this->pid); /** trigger event **/ wpl_global::event_handler('property_show', array('id' => $this->pid)); /** import tpl **/ $this->tpl = wpl_flex::get_kind_tpl($this->tpl_path, $this->tpl, $this->kind); return parent::render($this->tpl_path, $this->tpl, false, true); }
/** * Blocks user access based on WPL user role * @author Howard <*****@*****.**> * @static * @param string $role * @param int $user_id */ public static function min_access($role = 'guest', $user_id = '') { /** apply filters **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('wpl_check_min_access', array('role' => $role, 'user_id' => $user_id))); if (!wpl_global::has_permission($role, $user_id)) { echo __("You don't have access to this page!", WPL_TEXTDOMAIN); exit; } }
/** * Updates property title * @author Howard <*****@*****.**> * @static * @param array $property_data * @param int $property_id * @param boolean $force * @return string */ public static function update_property_title($property_data, $property_id = 0, $force = false) { /** fetch property data if property id is setted **/ if ($property_id) { $property_data = self::get_property_raw_data($property_id); } if (!$property_id) { $property_id = $property_data['id']; } $column = 'field_313'; $field_id = wpl_flex::get_dbst_id($column, $property_data['kind']); $field = wpl_flex::get_field($field_id); $base_column = NULL; if (isset($field->multilingual) and $field->multilingual and wpl_global::check_multilingual_status()) { $base_column = wpl_global::get_current_language() == wpl_addon_pro::get_default_language() ? $column : NULL; $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } /** return current title if exists **/ if (isset($property_data[$column]) and trim($property_data[$column]) != '' and !$force) { return $property_data[$column]; } /** first validation **/ if (!$property_data) { return ''; } $listing_data = wpl_global::get_listings($property_data['listing']); $listing = isset($listing_data->name) ? $listing_data->name : ''; $property_type_data = wpl_global::get_property_types($property_data['property_type']); $property_type = isset($property_type_data->name) ? $property_type_data->name : ''; $title = array(); $title['property_type'] = __($property_type, WPL_TEXTDOMAIN); $title['listing'] = __($listing, WPL_TEXTDOMAIN); if ($property_data['kind']) { $kind_label = wpl_flex::get_kind_label($property_data['kind']); if (trim($kind_label)) { $title['kind'] = '(' . __($kind_label, WPL_TEXTDOMAIN) . ')'; } } $title_str = implode(' ', $title); /** apply filters **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('generate_property_title', array('title' => $title, 'title_str' => $title_str))); /** update **/ if (wpl_db::columns('wpl_properties', $column)) { $query = "UPDATE `#__wpl_properties` SET `" . $column . "`='" . $title_str . "' WHERE `id`='" . $property_id . "'"; wpl_db::q($query, 'update'); } /** update **/ if ($base_column and wpl_db::columns('wpl_properties', $base_column)) { $query = "UPDATE `#__wpl_properties` SET `" . $base_column . "`='" . $title_str . "' WHERE `id`='" . $property_id . "'"; wpl_db::q($query, 'update'); } return $title_str; }
/** * Returns WPL Main rewrite rule * @author Howard R <*****@*****.**> * @static * @return string */ public static function get_main_rewrite_rule() { $main_permalink = wpl_sef::get_wpl_permalink(); $wpl_rules = array(); if (wpl_global::check_multilingual_status()) { $lang_options = wpl_addon_pro::get_wpl_language_options(); $lang_str = '.+'; foreach ($lang_options as $lang_option) { $lang_str .= $lang_option['shortcode'] . '|'; } $lang_str = trim($lang_str, '|.+ '); $wpl_rules[] = array('regex' => '(' . $lang_str . ')/(' . $main_permalink . ')/(.+)$', 'url' => 'index.php?pagename=$matches[2]&wpl_qs=$matches[3]'); $wpl_rules[] = array('regex' => 'language/(' . $lang_str . ')/(' . $main_permalink . ')/(.+)$', 'url' => 'index.php?pagename=$matches[2]&wpl_qs=$matches[3]'); } $wpl_rules[] = array('regex' => '(' . $main_permalink . ')/(.+)$', 'url' => 'index.php?pagename=$matches[1]&wpl_qs=$matches[2]'); /** apply filters (This filter must place after all proccess) **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('main_rewrite_rule', array('wpl_rules' => $wpl_rules))); return $wpl_rules; }
public function display($instance = array()) { /** property listing model **/ $this->model = new wpl_users(); /** global settings **/ $settings = wpl_settings::get_settings(); /** listing settings **/ $this->page_number = wpl_request::getVar('wplpage', 1, '', true); $this->limit = wpl_request::getVar('limit', $settings['default_profile_page_size'], '', true); $this->start = wpl_request::getVar('start', ($this->page_number - 1) * $this->limit, '', true); $this->orderby = wpl_request::getVar('wplorderby', $settings['default_profile_orderby'], '', true); $this->order = wpl_request::getVar('wplorder', $settings['default_profile_order'], '', true); /** Set Property CSS class **/ $this->property_css_class = wpl_request::getVar('wplpcc', NULL); if (!$this->property_css_class) { $this->property_css_class = wpl_request::getVar('wplpcc', 'grid_box', 'COOKIE'); } $this->property_css_class_switcher = wpl_request::getVar('wplpcc_switcher', '1'); /** set page if start var passed **/ $this->page_number = $this->start / $this->limit + 1; wpl_request::setVar('wplpage', $this->page_number); /** detect kind **/ $this->kind = wpl_request::getVar('kind', 2); if (!in_array($this->kind, wpl_flex::get_valid_kinds())) { /** import message tpl **/ $this->message = __('Invalid Request!', WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } /** pagination types **/ $this->wplpagination = wpl_request::getVar('wplpagination', 'normal', '', true); wpl_request::setVar('wplpagination', $this->wplpagination); $where = array('sf_tmin_id' => 1, 'sf_select_access_public_profile' => 1, 'sf_select_expired' => 0); /** Add search conditions to the where **/ $vars = array_merge(wpl_request::get('POST'), wpl_request::get('GET')); $where = array_merge($vars, $where); /** start search **/ $this->model->start($this->start, $this->limit, $this->orderby, $this->order, $where); $this->model->total = $this->model->get_users_count(); /** validation for page_number **/ $this->total_pages = ceil($this->model->total / $this->limit); if ($this->page_number <= 0 or $this->page_number > $this->total_pages) { $this->model->start = 0; } /** run the search **/ $query = $this->model->query(); $profiles = $this->model->search(); /** finish search **/ $this->model->finish(); $plisting_fields = $this->model->get_plisting_fields(); $wpl_profiles = array(); foreach ($profiles as $profile) { $wpl_profiles[$profile->id] = $this->model->full_render($profile->id, $plisting_fields); } /** define current index **/ $wpl_profiles['current'] = array(); /** apply filters (This filter must place after all proccess) **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('profile_listing_after_render', array('wpl_profiles' => $wpl_profiles))); $this->pagination = wpl_pagination::get_pagination($this->model->total, $this->limit, true); $this->wpl_profiles = $wpl_profiles; /** import tpl **/ return parent::render($this->tpl_path, $this->tpl, false, true); }
/** * written by Francis * description: initialize pagination and properties for property manager page */ private function init_page() { /** global settings **/ $settings = wpl_settings::get_settings(); /** listing settings **/ $this->page_number = wpl_request::getVar('wplpage', 1); $limit = wpl_request::getVar('limit', $settings['default_page_size']); $start = wpl_request::getVar('start', ($this->page_number - 1) * $limit); $orderby = wpl_request::getVar('orderby', $settings['default_orderby']); $order = wpl_request::getVar('order', $settings['default_order']); $current_user_id = wpl_users::get_cur_user_id(); $where = array(); /** set page if start var passed **/ $this->page_number = $start / $limit + 1; wpl_request::setVar('wplpage', $this->page_number); $this->model = new wpl_property(); /** load user properties **/ if (!wpl_users::is_administrator($current_user_id)) { $where['sf_select_user_id'] = $current_user_id; } /** detect kind **/ $this->kind = wpl_request::getVar('kind', 0); if (!in_array($this->kind, wpl_flex::get_valid_kinds())) { /** import message tpl **/ $this->message = __('Invalid Request!', WPL_TEXTDOMAIN); parent::render($this->tpl_path, 'message'); return false; } /** Access **/ $access = true; _wpl_import('libraries.filters'); @extract(wpl_filters::apply('listing_manager_access', array('kind' => $this->kind, 'user_id' => $current_user_id))); if (!$access) { /** import message tpl **/ $this->message = __("You don't have access to this page!", WPL_TEXTDOMAIN); parent::render($this->tpl_path, 'message'); return false; } $this->kind_label = wpl_flex::get_kind_label($this->kind); $where['sf_select_kind'] = $this->kind; /** Add search conditions to the where **/ $vars = array_merge(wpl_request::get('POST'), wpl_request::get('GET')); $where = array_merge($vars, $where); $this->model->start($start, $limit, $orderby, $order, $where, $this->kind); $query = $this->model->query(); $properties = $this->model->search($query); $this->model->finish(); /** get the number of all properties according to our query **/ $properties_count = $this->model->get_properties_count(); /** set pagination according to the number of items and limit **/ $this->pagination = wpl_pagination::get_pagination($properties_count, $limit); $plisting_fields = $this->model->get_plisting_fields(); $wpl_properties = array(); foreach ($properties as $property) { $wpl_properties[$property->id] = $this->model->full_render($property->id, $plisting_fields, $property); } $this->wpl_properties = $wpl_properties; $this->client = wpl_global::get_client(); if ($this->client) { $this->backend = true; $this->frontend = false; $this->add_link = wpl_global::add_qs_var('kind', $this->kind, wpl_global::get_wpl_admin_menu('wpl_admin_add_listing')); } else { $this->backend = false; $this->frontend = true; $this->add_link = wpl_global::add_qs_var('kind', $this->kind, wpl_global::add_qs_var('wplmethod', 'wizard')); } return true; }
/** * Returns property meta description, This function calls on sef service when meta description of listing is empty * @author Howard <*****@*****.**> * @static * @param array $property_data * @param int $property_id * @return string */ public static function get_meta_description($property_data, $property_id = 0) { /** fetch property data if property id is setted **/ if ($property_id) { $property_data = self::get_property_raw_data($property_id); } if (!$property_id) { $property_id = $property_data['id']; } $locale = wpl_global::get_current_language(); $column = 'field_308'; if (wpl_global::check_multilingual_status() and wpl_addon_pro::get_multiligual_status_by_column($column, $property_data['kind'])) { $column = wpl_addon_pro::get_column_lang_name($column, $locale, false); } $description = substr($property_data[$column], 0, 250); /** apply filters **/ _wpl_import('libraries.filters'); @extract(wpl_filters::apply('generate_meta_description', array('description' => $description, 'property_data' => $property_data))); return $description; }