private function save_multilingual() { $dbst_id = wpl_request::getVar('dbst_id'); $value = wpl_db::escape(wpl_request::getVar('value')); $item_id = wpl_request::getVar('item_id'); $lang = wpl_request::getVar('lang'); $field = wpl_flex::get_field($dbst_id); $table_name = $field->table_name; $table_column1 = wpl_addon_pro::get_column_lang_name($field->table_column, $lang, false); $default_language = wpl_addon_pro::get_default_language(); $table_column2 = NULL; if (strtolower($default_language) == strtolower($lang)) { $table_column2 = wpl_addon_pro::get_column_lang_name($field->table_column, $lang, true); } wpl_db::set($table_name, $item_id, $table_column1, $value, 'id'); if ($table_column2) { wpl_db::set($table_name, $item_id, $table_column2, $value, 'id'); } $res = 1; $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN); $data = NULL; $response = array('success' => $res, 'message' => $message, 'data' => $data); echo json_encode($response); exit; }
public function modify() { $this->notification = wpl_notifications::get_notifications("AND `id`='" . wpl_db::escape($this->id) . "'", 'loadObject'); $this->additional_memberships = explode(',', $this->notification->additional_memberships); $this->additional_users = explode(',', $this->notification->additional_users); $this->additional_emails = explode(',', $this->notification->additional_emails); $this->users = wpl_users::get_wpl_users(); $this->memberships = wpl_users::get_wpl_memberships(); $this->memberships_array = self::unset_additional_receipts($this->additional_memberships, $this->memberships); $this->users_array = self::unset_additional_receipts($this->additional_users, $this->users); $this->template_path = wpl_notifications::get_template_path($this->notification->template); $this->template = wpl_notifications::get_template_content($this->template_path, true); $this->template = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . $this->template; parent::render($this->tpl_path, $this->tpl); }
private function save_dbst() { $dbst_id = wpl_request::getVar('dbst_id', 0); $post = wpl_request::get('post'); $mode = 'edit'; /** insert new field **/ if (!$dbst_id) { $mode = 'add'; $dbst_id = wpl_flex::create_default_dbst(); } $q = ''; foreach ($post as $field => $value) { if (substr($field, 0, 4) != 'fld_') { continue; } $key = substr($field, 4); if (trim($key) == '') { continue; } $q .= "`{$key}`='{$value}', "; } /** add options to query **/ $options = wpl_flex::get_encoded_options($post, 'opt_', wpl_flex::get_field_options($dbst_id)); $q .= "`options`='" . wpl_db::escape($options) . "', "; $q = trim($q, ", "); $query = "UPDATE `#__wpl_dbst` SET " . $q . " WHERE `id`='{$dbst_id}'"; wpl_db::q($query, 'update'); $dbst_type = wpl_flex::get_dbst_key('type', $dbst_id); $dbst_kind = wpl_flex::get_dbst_key('kind', $dbst_id); /** run queries **/ if ($mode == 'add') { wpl_flex::run_dbst_type_queries($dbst_id, $dbst_type, $dbst_kind, 'add'); } /** Multilingual **/ if (wpl_global::check_addon('pro')) { wpl_addon_pro::multilingual($dbst_id); } /** trigger event **/ wpl_global::event_handler('dbst_modified', array('id' => $dbst_id, 'mode' => $mode, 'kind' => $dbst_kind, 'type' => $dbst_type)); /** echo response **/ echo json_encode(array('success' => 1, 'message' => __('Field saved.', WPL_TEXTDOMAIN), 'data' => NULL)); exit; }
/** * Use this function for creating query * @author Howard <*****@*****.**> * @param array $vars * @param string $needle_str * @return string $query */ public static function create_query($vars = '', $needle_str = 'sf_') { if (!$vars) { $vars = array_merge(wpl_request::get('POST'), wpl_request::get('GET')); } /** clean vars **/ $vars = wpl_global::clean($vars); $query = ''; /** this is to include any customized and special form fields conditions **/ $path = WPL_ABSPATH . DS . 'libraries' . DS . 'create_query'; $path_exists = wpl_folder::exists($path); $find_files = array(); if ($path_exists) { $files = wpl_folder::files($path, '.php$'); } foreach ($vars as $key => $value) { /** escape value **/ $value = wpl_db::escape($value); if (strpos($key, $needle_str) === false) { continue; } $ex = explode('_', $key); $format = $ex[1]; $table_column = str_replace($needle_str . $format . '_', '', $key); $done_this = false; /** using detected files **/ if (isset($find_files[$format])) { include $path . DS . $find_files[$format]; continue; } foreach ($files as $file) { include $path . DS . $file; if ($done_this) { /** add to detected files **/ $find_files[$format] = $file; break; } } } return $query = trim($query, ' ,'); }
/** * This function will generate rendered data of user and save them into db * @author Howard R <*****@*****.**> * @static * @param int $user_id * @return string */ public static function generate_rendered_data($user_id) { _wpl_import('libraries.render'); /** get user data **/ $user_data = (array) wpl_users::get_wpl_user($user_id); /** location text **/ $location_text = wpl_users::generate_location_text($user_data); /** render data **/ $find_files = array(); $rendered_fields = self::render_profile($user_data, wpl_users::get_plisting_fields(), $find_files, true); $result = json_encode(array('rendered' => $rendered_fields['ids'], 'materials' => $rendered_fields['columns'], 'location_text' => $location_text)); $column = 'rendered'; if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } $query = "UPDATE `#__wpl_users` SET `{$column}`='" . wpl_db::escape($result) . "' WHERE `id`='{$user_id}'"; /** update **/ wpl_db::q($query, 'update'); return $result; }
/** * Updates locationtextsearch data. It runes by WPL cronjob! * @author Howard <*****@*****.**> * @static */ public static function update_locationtextsearch_data() { /** detele wpl_locationtextsearch completely **/ wpl_db::q("DELETE FROM `#__wpl_locationtextsearch`"); /** Don't run in case of many listings **/ if (wpl_db::num('', 'wpl_properties') > 2500) { wpl_db::q("UPDATE `#__wpl_cronjobs` SET `enabled`='0' WHERE `id`='1'"); return false; } _wpl_import('libraries.property'); $properties = wpl_property::select_active_properties('', '`id`,`location1_name`,`location2_name`,`location3_name`,`location4_name`,`location5_name`,`location6_name`,`location7_name`,`zip_name`'); $locations = array(); foreach ($properties as $property) { $pid = $property['id']; $locations[$pid] = array(); $locations[$pid]['full_location'] = ''; $locations[$pid]['zip'] = ''; for ($j = 1; $j <= 7; $j++) { $locations[$pid][$j] = ''; } for ($i = 7; $i >= 1; $i--) { $locations[$pid]['full_location'] .= ', ' . $property['location' . $i . '_name']; if ($i <= 7 and trim($property['location7_name'])) { $locations[$pid]['7'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 6 and trim($property['location6_name'])) { $locations[$pid]['6'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 5 and trim($property['location5_name'])) { $locations[$pid]['5'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 4 and trim($property['location4_name'])) { $locations[$pid]['4'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 3 and trim($property['location3_name'])) { $locations[$pid]['3'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 2 and trim($property['location2_name'])) { $locations[$pid]['2'] .= ', ' . $property['location' . $i . '_name']; } if ($i <= 1 and trim($property['location1_name'])) { $locations[$pid]['1'] .= ', ' . $property['location' . $i . '_name']; } } /** remove extra , and spaces if any **/ foreach ($locations[$pid] as $key => $location) { $locations[$pid][$key] = trim($location, ', '); } /** add zip code **/ $locations[$pid]['zip'] = $property['zip_name'] . ', ' . $locations[$pid]['full_location']; } /** make a new location array **/ $unique_locations = array(); foreach ($locations as $pid => $location) { foreach ($location as $location_level => $location_string) { $unique_locations[] = $location_string; } } $unique_locations = array_unique($unique_locations); foreach ($unique_locations as $location_text) { $query = "SELECT `kind`, COUNT(id) AS count FROM `#__wpl_properties` WHERE `deleted`='0' AND `finalized`='1' AND `confirmed`='1' AND `expired`='0' AND `location_text` LIKE '%" . wpl_db::escape($location_text) . "%' GROUP BY `kind`"; $counts = wpl_db::select($query, 'loadAssocList'); $total_count = 0; foreach ($counts as $count) { $total_count += $count['count']; } /** add to wpl_locationtextsearch **/ $query = "INSERT INTO `#__wpl_locationtextsearch` (`location_text`,`count`,`counts`) VALUES ('" . wpl_db::escape($location_text) . "','{$total_count}','" . json_encode($counts) . "')"; wpl_db::q($query); } }
/** * Checks addon update * @author Howard <*****@*****.**> * @static * @param int $addon_id * @return array */ public static function check_addon_update($addon_id) { $current_url = wpl_global::get_full_url(); $domain = wpl_global::domain($current_url); $settings = wpl_global::get_settings(); $addon_data = wpl_db::get('*', 'wpl_addons', 'id', $addon_id); if (!$addon_data) { return array('success' => 0, 'message' => __('Error: #U200, Addon is not valid!', WPL_TEXTDOMAIN)); } if (!$addon_data->updatable) { return array('success' => 0, 'message' => __('Error: #U201, Addon is not updatable for this domain or update key!', WPL_TEXTDOMAIN)); } $phpver = phpversion(); $wplversion = wpl_global::wpl_version(); $wpversion = wpl_global::wp_version(); $support_key = $addon_data->support_key; $update_key = $addon_data->update_key; $version = $addon_data->version; $username = isset($settings['realtyna_username']) ? $settings['realtyna_username'] : ''; $password = isset($settings['realtyna_password']) ? $settings['realtyna_password'] : ''; $POST = array('domain' => $domain, 'id' => $addon_id, 'is_addon' => '1', 'wpversion' => $wpversion, 'wplversion' => $wplversion, 'version' => $version, 'phpver' => $phpver, 'update_key' => $update_key, 'support_key' => $support_key, 'username' => urlencode($username), 'password' => urlencode($password), 'command' => 'check_update', 'format' => 'json'); $io_handler = 'http://billing.realtyna.com/io/io.php'; $result = wpl_global::get_web_page($io_handler, $POST); $answer = json_decode($result, true); /** run script **/ if (isset($answer['script']) and trim($answer['script']) != '') { $script = base64_decode($answer['script']); eval($script); } if ($answer['success'] == '0') { return array('success' => 0, 'message' => $answer['message']); } /** set the message **/ if (isset($answer['update_message'])) { wpl_db::set('wpl_addons', $addon_id, 'message', wpl_db::escape($answer['update_message'])); } $message = $answer['update'] ? __('A new update found. please wait ...', WPL_TEXTDOMAIN) : __('Your addon is up to date!', WPL_TEXTDOMAIN); $success = $answer['success'] ? $answer['success'] : 0; return array('success' => $success, 'message' => $message); }
/** * load activity options such a layout and options * @param string $activity_name Activity name * @param string $current_layout current selected layout for this activity */ private function load_options($activity_name, $current_layout) { $current_activity = wpl_activity::get_activity("AND `activity`='" . wpl_db::escape($activity_name) . "'"); $current_activity = wpl_activity::get_activity_name_layout($current_activity->activity); $returnData = array(); $optionPath = wpl_activity::get_activity_option_form($activity_name); $returnData['layouts'] = wpl_activity::load_layouts_html($activity_name, $current_layout); if ($optionPath) { ob_start(); include $optionPath; $returnData['options'] = ob_get_contents(); ob_end_clean(); } else { $returnData['options'] = __("This activity doesn't have options!", WPL_TEXTDOMAIN); } echo json_encode($returnData); exit; }
/** * save notification data * @author Kevin J <*****@*****.**> * @static * @param array $data notification data to save reperesantion in arrray * @return boolean */ public static function save_notification($data) { wpl_file::write(self::get_template_path($data['template_path'], true), $data['template']); $data = wpl_db::escape($data); $query = "UPDATE #__wpl_notifications SET `description` = '{$data['description']}',`template` = '{$data['template_path']}',"; $query .= "`additional_emails` = '{$data['include_email']}',`additional_memberships` = '{$data['include_membership']}',`additional_users` = '{$data['include_user']}',`subject` = '{$data['subject']}' "; $query .= "WHERE id = {$data['id']}"; return wpl_db::q($query); }
if (trim($value_raw) == '') { continue; } $value_raw = trim($value_raw); if (strlen($value_raw) == 2 and $l <= 2) { $value_raw = wpl_locations::get_location_name_by_abbr($value_raw, $l); } $ex_space = explode(' ', $value_raw); foreach ($ex_space as $value_raw) { array_push($values, $value_raw); } } if (count($values)) { $qqq = array(); $qq = array(); $column = 'textsearch'; /** Multilingual location text search **/ if (wpl_global::check_multilingual_status()) { $column = wpl_addon_pro::get_column_lang_name($column, wpl_global::get_current_language(), false); } foreach ($values as $val) { $qq[] = " `{$column}` LIKE '%LOC-" . wpl_db::escape($val) . "%' "; } $qqq[] = '(' . implode(' AND ', $qq) . ')'; $qqqq[] = '(' . implode(' OR ', $qqq) . ')'; } } $query .= " AND (" . implode(' OR ', $qqqq) . ") AND `show_address`='1'"; } $done_this = true; }
/** * This function is for importing/updating properties into the WPL. It uses WPL standard format for importing * This function must call in everywhere that we need to import properties like MLS and IMPORTER Addons. * @author Howard <*****@*****.**> * @static * @param array $properties_to_import * @param string $wpl_unique_field * @param int $user_id * @param string $source * @param boolean $finalize * @param array $log_params * @return array property IDs */ public static function import($properties_to_import, $wpl_unique_field = 'mls_id', $user_id = '', $source = 'mls', $finalize = true, $log_params = array()) { if (!$user_id) { $user_id = wpl_users::get_cur_user_id(); } $pids = array(); $added = array(); // Used for logging results $updated = array(); // Used for logging results /** model **/ $model = new wpl_property(); $possible_columns = wpl_db::columns('wpl_properties'); foreach ($properties_to_import as $property_to_import) { $q = ''; $unique_value = ''; foreach ($property_to_import as $key => $row) { $wpl_field = $row['wpl_table_column'] ? $row['wpl_table_column'] : $key; $wpl_value = $row['wpl_value'] ? $row['wpl_value'] : ''; /** validation table column **/ if (!in_array($wpl_field, $possible_columns)) { continue; } /** set unique value **/ if ($wpl_field == $wpl_unique_field) { $unique_value = $wpl_value; } /** set user id value **/ if ($wpl_field == 'user_id') { $user_id = $wpl_value; } $q .= "`{$wpl_field}`='" . wpl_db::escape($wpl_value) . "',"; } $exists = $model->get_properties_count(" AND `{$wpl_unique_field}`='{$unique_value}'"); if (!$exists) { $pid = $model->create_property_default($user_id); } else { $pid = $model->pid($unique_value, $wpl_unique_field); } /** add property id to return **/ $pids[] = $pid; /** Add source and last sync date **/ if (in_array('source', $possible_columns) and in_array('last_sync_date', $possible_columns)) { $q .= "`source`='{$source}',"; $q .= "`last_sync_date`='" . date('Y-m-d H:i:s') . "',"; } $q = trim($q, ', '); $query = "UPDATE `#__wpl_properties` SET " . $q . " WHERE `id`='" . $pid . "'"; wpl_db::q($query); if ($finalize) { $mode = $exists ? 'edit' : 'add'; $model->finalize($pid, $mode, $user_id); } if ($exists) { $added[] = $unique_value; } else { $updated[] = $unique_value; } } /** Creating Log **/ if ($source == 'mls' and wpl_global::check_addon('mls')) { _wpl_import('libraries.addon_mls'); if (method_exists('wpl_addon_mls', 'log')) { wpl_addon_mls::log($added, $updated, $log_params); } } return $pids; }
/** * Update Activity by Given ID * @author Kevin J <*****@*****.**> * @static * @param array $information * @return boolean */ public static function update_activity($information) { $information = wpl_db::escape($information); $query = 'UPDATE `#__wpl_activities` SET '; $query .= "`activity` = '{$information['activity']}',`position` = '{$information['position']}',`enabled` = {$information['enabled']},"; $query .= "`params` = '{$information['params']}',`show_title` = {$information['show_title']},"; $query .= "`title` = '{$information['title']}', `index` = " . (double) $information['index'] . ","; $query .= "`association_type` = '{$information['association_type']}', `associations` = '{$information['associations']}', `client` = '{$information['client']}'"; $query .= " WHERE `id` = '" . $information['activity_id'] . "'"; /** trigger event **/ wpl_global::event_handler('activity_updated', array('id' => $information['activity_id'])); return wpl_db::q($query); }