/** * author Francis * @param int $pid * @param string $action * @param int $value * description: update 'confirmed' and 'deleted' fields of one property */ private function update_property($pid, $action, $value) { /** property data **/ $property_data = wpl_property::get_property_raw_data($pid); if ($action == 'confirm') { if (wpl_users::check_access('confirm', $property_data['user_id'])) { /** confirm property **/ $res = wpl_property::confirm($pid, $value, true); $message = __("Operation was successful.", WPL_TEXTDOMAIN); } else { $res = 0; $message = __("You don't have access to this action.", WPL_TEXTDOMAIN); } } elseif ($action == 'trash') { if (wpl_users::check_access('delete', $property_data['user_id'])) { /** delete property **/ $res = wpl_property::delete($pid, $value, true); $message = __("Operation was successful.", WPL_TEXTDOMAIN); } else { $res = 0; $message = __("You don't have access to this action.", WPL_TEXTDOMAIN); } } /** echo response **/ $res = (int) $res; $data = NULL; echo json_encode(array('success' => $res, 'message' => $message, 'data' => $data)); exit; }
/** * Listing Contact activity. It's for contacting to a listing agent. * @author Howard <*****@*****.**> * @static * @param array $params * @return boolean */ public static function contact_agent($params) { $replacements = $params[0]; $notification = new wpl_notifications('email'); $notification->prepare(2, $replacements); /** Disabled **/ if (!$notification->notification_data['enabled']) { return false; } $property = wpl_property::get_property_raw_data($params[0]['property_id']); $user = wpl_users::get_user($property['user_id']); $replacements['listing_id'] = $property['mls_id']; $notification->replacements = $notification->set_replacements($replacements); $notification->rendered_content = $notification->render_notification_content(); $notification->recipients = $notification->set_recipients(array($user->data->user_email)); $notification->send(); return true; }
public function wizard($instance = array()) { /** load assets **/ $this->load_assets(); /** check access **/ if (!wpl_users::check_access('propertywizard')) { /** import message tpl **/ $this->message = __("You don't have access to this part!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } $this->kind = trim(wpl_request::getVar('kind')) != '' ? wpl_request::getVar('kind') : 0; $this->property_id = trim(wpl_request::getVar('pid')) != '' ? wpl_request::getVar('pid') : 0; $this->mode = $this->property_id ? 'edit' : 'add'; if ($this->mode == 'add') { /** checking access **/ if (!wpl_users::check_access($this->mode)) { $this->message = __("Limit reached. You can not add more property!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } /** generate new property **/ $this->property_id = wpl_property::create_property_default('', $this->kind); } $this->values = wpl_property::get_property_raw_data($this->property_id); $this->finalized = isset($this->values['finalized']) ? $this->values['finalized'] : 0; $this->kind = isset($this->values['kind']) ? $this->values['kind'] : 0; $this->field_categories = wpl_flex::get_categories(0, $this->kind); $this->kind_label = wpl_flex::get_kind_label($this->kind); if ($this->mode == 'edit') { if (!$this->values) { $this->message = __("Property does not exist!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } /** checking access **/ if (!wpl_users::check_access($this->mode, $this->values['user_id'])) { $this->message = __("You can not edit this property.", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message'); } } /** import tpl **/ $this->tpl = wpl_flex::get_kind_tpl($this->tpl_path, 'wizard', $this->kind); parent::render($this->tpl_path, $this->tpl); }
private function set_parent() { $parent_id = wpl_request::getVar('parent_id', 0); $item_id = wpl_request::getVar('item_id', 0); $parent_data = wpl_property::get_property_raw_data($parent_id); $forbidden_fields = array('id', 'kind', 'deleted', 'mls_id', 'parent', 'pic_numb', 'att_numb', 'sent_numb', 'contact_numb', 'user_id', 'add_date', 'finalized', 'confirmed', 'visit_time', 'visit_date', 'last_modified_time_stamp', 'sp_featured', 'sp_hot', 'sp_openhouse', 'sp_forclosure', 'textsearch', 'property_title', 'location_text', 'vids_numb', 'rendered', 'alias'); $q = ''; foreach ($parent_data as $key => $value) { if (in_array($key, $forbidden_fields)) { continue; } $q .= "`{$key}`='{$value}', "; } $q .= trim($q, ', '); $query = "UPDATE `#__wpl_properties` SET `parent`='{$parent_id}', {$q} WHERE `id`='{$item_id}'"; wpl_db::q($query); echo json_encode(array('success' => 1)); exit; }
/** * Updates latitude and longitude of a property * @author Howard <*****@*****.**> * @static * @param type $property_data * @param type $property_id * @return type */ public static function update_LatLng($property_data, $property_id = NULL) { /** fetch property data if property id is setted **/ if ($property_id) { $property_data = wpl_property::get_property_raw_data($property_id); } if (!$property_id) { $property_id = $property_data['id']; } $location_text = wpl_property::generate_location_text($property_data); $LatLng = self::get_LatLng($location_text); if ($LatLng[0] and $LatLng[1]) { $query = "UPDATE `#__wpl_properties` SET `googlemap_lt`='" . $LatLng[0] . "', `googlemap_ln`='" . $LatLng[1] . "' WHERE `id`='{$property_id}'"; wpl_db::q($query); } $latitude = $LatLng[0] ? $LatLng[0] : $property_data['googlemap_lt']; $longitude = $LatLng[1] ? $LatLng[1] : $property_data['googlemap_ln']; return array($latitude, $longitude); }
private function query($instance) { /** property listing model **/ $model = new wpl_property(); $data = $instance['data']; $this->start = 0; $this->limit = $data['limit']; $this->orderby = urldecode($data['orderby']); $this->order = $data['order']; /** detect kind **/ if (isset($data['kind']) and (trim($data['kind']) != '' or trim($data['kind']) != '-1')) { $kind = $data['kind']; } else { $kind = 0; } $where = array('sf_select_confirmed' => 1, 'sf_select_finalized' => 1, 'sf_select_deleted' => 0, 'sf_select_expired' => 0, 'sf_select_kind' => $kind); if (trim($data['listing']) and $data['listing'] != '-1') { $where['sf_select_listing'] = $data['listing']; } if (trim($data['property_type']) and $data['property_type'] != '-1') { $where['sf_select_property_type'] = $data['property_type']; } if (trim($data['property_ids'])) { $where['sf_multiple_id'] = trim($data['property_ids'], ', '); } if (trim($data['only_featured'])) { $where['sf_select_sp_featured'] = 1; } if (trim($data['only_hot'])) { $where['sf_select_sp_hot'] = 1; } if (trim($data['only_openhouse'])) { $where['sf_select_sp_openhouse'] = 1; } if (trim($data['only_forclosure'])) { $where['sf_select_sp_forclosure'] = 1; } /** Parent **/ if (isset($data['parent']) and trim($data['parent'])) { $where['sf_parent'] = $data['parent']; } if (isset($data['auto_parent']) and trim($data['auto_parent'])) { /** current proeprty id - This features works only in single property page **/ $property_data = NULL; $pid = wpl_request::getVar('pid', 0); if ($pid) { $property_data = $model->get_property_raw_data($pid); } if (isset($property_data['mls_id'])) { $where['sf_parent'] = $property_data['mls_id']; } } if (isset($data['random']) and trim($data['random']) and trim($data['property_ids']) == '') { $query_rand = "SELECT p.`id` FROM `#__wpl_properties` AS p WHERE 1 " . wpl_db::create_query($where) . " ORDER BY RAND() LIMIT " . $this->limit; $results = wpl_db::select($query_rand); $rand_ids = array(); foreach ($results as $result) { $rand_ids[] = $result->id; } $where['sf_multiple_id'] = implode(',', $rand_ids); } /** Similar properties **/ if (isset($data['sml_only_similars']) and $data['sml_only_similars']) { $sml_where = array('sf_select_confirmed' => 1, 'sf_select_finalized' => 1, 'sf_select_deleted' => 0, 'sf_select_expired' => 0); /** current proeprty id - This features works only in single property page **/ $pid = wpl_request::getVar('pid', 0); $property_data = wpl_property::get_property_raw_data($pid); if ($property_data) { $sml_where['sf_notselect_id'] = $pid; $sml_where['sf_select_kind'] = $property_data['kind']; if (isset($data['sml_inc_listing']) and $data['sml_inc_listing']) { $sml_where['sf_select_listing'] = $property_data['listing']; } if (isset($data['sml_inc_property_type']) and $data['sml_inc_property_type']) { $sml_where['sf_select_property_type'] = $property_data['property_type']; } if (isset($data['sml_inc_price']) and $data['sml_inc_price']) { $down_rate = $data['sml_price_down_rate'] ? $data['sml_price_down_rate'] : 0.8; $up_rate = $data['sml_price_up_rate'] ? $data['sml_price_up_rate'] : 1.2; $price_down_range = $property_data['price_si'] * $down_rate; $price_up_range = $property_data['price_si'] * $up_rate; $sml_where['sf_tmin_price_si'] = $price_down_range; $sml_where['sf_tmax_price_si'] = $price_up_range; } if (isset($data['sml_inc_radius']) and $data['sml_inc_radius']) { $latitude = $property_data['googlemap_lt']; $longitude = $property_data['googlemap_ln']; $radius = $data['sml_radius']; $unit_id = $data['sml_radius_unit']; if ($latitude and $longitude and $radius and $unit_id) { $sml_where['sf_radiussearchunit'] = $unit_id; $sml_where['sf_radiussearch_lat'] = $latitude; $sml_where['sf_radiussearch_lng'] = $longitude; $sml_where['sf_radiussearchradius'] = $radius; } } } /** overwrite $where if similar where is correct **/ if (count($sml_where) > 3) { $where = $sml_where; } } /** start search **/ $model->start($this->start, $this->limit, $this->orderby, $this->order, $where); /** run the search **/ return $model->query(); }
/** * Updates text search field * @author Howard <*****@*****.**> * @static * @param int $property_id */ public static function update_text_search_field($property_id) { $property_data = wpl_property::get_property_raw_data($property_id); /** get text_search fields **/ $fields = wpl_flex::get_fields('', 1, $property_data['kind'], 'text_search', '1'); $rendered = self::render_property($property_data, $fields); $text_search_data = array(); foreach ($rendered as $data) { if (!isset($data['type'])) { continue; } if (isset($data['type']) and !trim($data['type']) or isset($data['value']) and !trim($data['value'])) { continue; } /** default value **/ $value = isset($data['value']) ? $data['value'] : ''; $value2 = ''; $type = $data['type']; if ($type == 'text' or $type == 'textarea') { $value = $data['name'] . ' ' . $data['value']; } elseif ($type == 'neighborhood') { $value = $data['name'] . (isset($data['distance']) ? ' (' . $data['distance'] . ' ' . __('MINUTES', WPL_TEXTDOMAIN) . ' ' . __('BY', WPL_TEXTDOMAIN) . ' ' . $data['by'] . ')' : ''); } elseif ($type == 'feature') { $feature_value = $data['name']; if (isset($data['values'][0])) { $feature_value .= ' '; foreach ($data['values'] as $val) { $feature_value .= $val . ', '; } $feature_value = rtrim($feature_value, ', '); } $value = $feature_value; } elseif ($type == 'locations' and isset($data['locations']) and is_array($data['locations'])) { $location_value = ''; foreach ($data['locations'] as $location_level => $value) { $location_value .= $data['keywords'][$location_level] . ' '; $abbr = wpl_locations::get_location_abbr_by_name($data['raw'][$location_level], $location_level); $name = wpl_locations::get_location_name_by_abbr($abbr, $location_level); $location_value .= $name . ' ' . ($name != $abbr ? $abbr . ' ' : NULL); } $location_value .= __('County', WPL_TEXTDOMAIN); $value = $location_value; } elseif (isset($data['value'])) { $value = $data['name'] . ' ' . $data['value']; if (is_numeric($data['value'])) { $value2 = $data['name'] . ' ' . wpl_global::number_to_word($data['value']); } } /** set value in text search data **/ if (trim($value) != '') { $text_search_data[] = strip_tags($value); } if (trim($value2) != '') { $text_search_data[] = strip_tags($value2); } } $column = 'textsearch'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } wpl_db::set('wpl_properties', $property_id, $column, wpl_db::escape(implode(' ', $text_search_data))); }
/** * Sets Dublin Core Meta Tags * @author Howard <*****@*****.**> * @return boolean */ public function dublincore() { $settings = wpl_global::get_settings(); $dc_status = isset($settings['dc_status']) ? $settings['dc_status'] : false; /** check status of geo tags **/ if (!$dc_status) { return false; } $current_link_url = wpl_global::get_full_url(); $html = wpl_html::getInstance(); /** WPL views and WordPress views (Page/Post) **/ if (trim($this->view) != '' and $dc_status == 2 or $dc_status == 1) { if (trim($settings['dc_coverage']) != '') { $html->set_custom_tag('<meta name="DC.coverage" content="' . $settings['dc_coverage'] . '" />'); } if (trim($settings['dc_contributor']) != '') { $html->set_custom_tag('<meta name="DC.contributor" content="' . $settings['dc_contributor'] . '" />'); } if (trim($settings['dc_publisher']) != '') { $html->set_custom_tag('<meta name="DC.publisher" content="' . $settings['dc_publisher'] . '" />'); } if (trim($settings['dc_copyright']) != '') { $html->set_custom_tag('<meta name="DC.rights" content="' . $settings['dc_copyright'] . '" />'); } if (trim($settings['dc_source']) != '') { $html->set_custom_tag('<meta name="DC.source" content="' . $settings['dc_source'] . '" />'); } if (trim($settings['dc_relation']) != '') { $html->set_custom_tag('<meta name="DC.relation" content="' . $settings['dc_relation'] . '" />'); } $html->set_custom_tag('<meta name="DC.type" content="Text" />'); $html->set_custom_tag('<meta name="DC.format" content="text/html" />'); $html->set_custom_tag('<meta name="DC.identifier" content="' . $current_link_url . '" />'); $locale = apply_filters('plugin_locale', get_locale(), WPL_TEXTDOMAIN); $html->set_custom_tag('<meta name="DC.language" scheme="RFC1766" content="' . $locale . '" />'); } if ($this->view == 'property_show') { $proeprty_id = wpl_request::getVar('pid'); $property_data = wpl_property::get_property_raw_data($proeprty_id); $user_data = (array) wpl_users::get_user($property_data['user_id']); $html->set_custom_tag('<meta name="DC.title" content="' . $this->property_page_title . '" />'); $html->set_custom_tag('<meta name="DC.subject" content="' . $this->property_page_title . '" />'); $html->set_custom_tag('<meta name="DC.description" content="' . $this->property_description . '" />'); $html->set_custom_tag('<meta name="DC.date" content="' . $property_data['add_date'] . '" />'); $html->set_custom_tag('<meta name="DC.creator" content="' . $user_data['data']->user_login . '" />'); } elseif ($this->view == 'profile_show') { $user_id = wpl_request::getVar('uid'); $user_data = (array) wpl_users::get_user($user_id); $html->set_custom_tag('<meta name="DC.title" content="' . $this->user_title . '" />'); $html->set_custom_tag('<meta name="DC.subject" content="' . $this->user_title . '" />'); $html->set_custom_tag('<meta name="DC.description" content="' . $this->user_description . '" />'); $html->set_custom_tag('<meta name="DC.date" content="' . $user_data['data']->user_registered . '" />'); $html->set_custom_tag('<meta name="DC.creator" content="' . $user_data['data']->user_login . '" />'); } elseif (is_single()) { $post_author_id = wpl_global::get_post_field('post_author'); $author_username = wpl_global::get_the_author_meta('user_login', $post_author_id); $html->set_custom_tag('<meta name="DC.title" content="' . wpl_global::get_the_title() . '" />'); $html->set_custom_tag('<meta name="DC.subject" content="' . wpl_global::get_the_title() . '" />'); $html->set_custom_tag('<meta name="DC.date" content="' . wpl_global::get_the_date() . '" />'); $html->set_custom_tag('<meta name="DC.creator" content="' . $author_username . '" />'); } }
/** * Updates text search field * @author Howard <*****@*****.**> * @static * @param int $property_id */ public static function update_text_search_field($property_id) { $property_data = wpl_property::get_property_raw_data($property_id); $kind = wpl_property::get_property_kind($property_id); /** get text_search fields **/ $fields = wpl_flex::get_fields('', 1, $property_data['kind'], 'text_search', '1'); $rendered = self::render_property($property_data, $fields); $text_search_data = array(); foreach ($rendered as $data) { if (!isset($data['type'])) { continue; } if (isset($data['type']) and !trim($data['type']) or isset($data['value']) and !trim($data['value'])) { continue; } /** default value **/ $value = isset($data['value']) ? $data['value'] : ''; $value2 = ''; $type = $data['type']; if ($type == 'text' or $type == 'textarea') { $value = $data['name'] . ' ' . $data['value']; } elseif ($type == 'neighborhood') { $value = $data['name'] . (isset($data['distance']) ? ' (' . $data['distance'] . ' ' . __('MINUTES', WPL_TEXTDOMAIN) . ' ' . __('BY', WPL_TEXTDOMAIN) . ' ' . $data['by'] . ')' : ''); } elseif ($type == 'feature') { $feature_value = $data['name']; if (isset($data['values'][0])) { $feature_value .= ' '; foreach ($data['values'] as $val) { $feature_value .= $val . ', '; } $feature_value = rtrim($feature_value, ', '); } $value = $feature_value; } elseif ($type == 'locations' and isset($data['locations']) and is_array($data['locations'])) { $location_values = array(); foreach ($data['locations'] as $location_level => $value) { array_push($location_values, $data['keywords'][$location_level]); $abbr = wpl_locations::get_location_abbr_by_name($data['raw'][$location_level], $location_level); $name = wpl_locations::get_location_name_by_abbr($abbr, $location_level); $ex_space = explode(' ', $name); foreach ($ex_space as $value_raw) { array_push($location_values, $value_raw); } if ($name !== $abbr) { array_push($location_values, $abbr); } } /** Add all location fields to the location text search **/ $location_category = wpl_flex::get_category(NULL, " AND `kind`='{$kind}' AND `prefix`='ad'"); $location_fields = wpl_flex::get_fields($location_category->id, 1, $kind); foreach ($location_fields as $location_field) { if (!isset($rendered[$location_field->id])) { continue; } if (!trim($location_field->table_column)) { continue; } if (!isset($rendered[$location_field->id]['value']) or isset($rendered[$location_field->id]['value']) and !trim($rendered[$location_field->id]['value'])) { continue; } $ex_space = explode(' ', strip_tags($rendered[$location_field->id]['value'])); foreach ($ex_space as $value_raw) { array_push($location_values, $value_raw); } } $location_suffix_prefix = wpl_locations::get_location_suffix_prefix(); foreach ($location_suffix_prefix as $suffix_prefix) { array_push($location_values, $suffix_prefix); } $location_string = ''; $location_values = array_unique($location_values); foreach ($location_values as $location_value) { $location_string .= 'LOC-' . __($location_value, WPL_TEXTDOMAIN) . ' '; } $value = trim($location_string); } elseif (isset($data['value'])) { $value = $data['name'] . ' ' . $data['value']; if (is_numeric($data['value'])) { $value2 = $data['name'] . ' ' . wpl_global::number_to_word($data['value']); } } /** set value in text search data **/ if (trim($value) != '') { $text_search_data[] = strip_tags($value); } if (trim($value2) != '') { $text_search_data[] = strip_tags($value2); } } $column = 'textsearch'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } wpl_db::set('wpl_properties', $property_id, $column, wpl_db::escape(implode(' ', $text_search_data))); }