private function save_params() { $table = wpl_request::getVar('table'); $id = wpl_request::getVar('id'); $post = wpl_request::get('post'); $keys = (isset($post['wpl_params']) and is_array($post['wpl_params']['keys'])) ? $post['wpl_params']['keys'] : array(); $values = (isset($post['wpl_params']) and is_array($post['wpl_params']['values'])) ? $post['wpl_params']['values'] : array(); $params = array(); foreach ($keys as $key => $value) { if (trim($value) == '') { continue; } $params[$value] = $values[$key]; } /** save params **/ wpl_global::set_params($table, $id, $params); /** trigger event **/ wpl_global::event_handler('params_saved', array('table' => $table, 'id' => $id, 'params' => $params)); $res = 1; $message = $res ? __('Params Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN); $data = NULL; $response = array('success' => $res, 'message' => $message, 'data' => $data); echo json_encode($response); exit; }
public function display($instance = array()) { $this->uid = wpl_request::getVar('uid', 0); if (!$this->uid) { $this->uid = wpl_request::getVar('sf_select_user_id', 0); wpl_request::setVar('uid', $this->uid); } /** check user id **/ if (!$this->uid) { /** import message tpl **/ $this->message = __("No profile found or it's not available now!", WPL_TEXTDOMAIN); return parent::render($this->tpl_path, 'message', false, true); } /** set the user id to search credentials **/ wpl_request::setVar('sf_select_user_id', $this->uid); /** set the kind **/ $this->kind = wpl_request::getVar('kind', '0'); wpl_request::setVar('kind', $this->kind); /** User Type **/ $this->user_type = wpl_users::get_user_user_type($this->uid); /** trigger event **/ wpl_global::event_handler('profile_show', array('id' => $this->uid, 'kind' => $this->kind)); /** import tpl **/ $this->tpl = wpl_users::get_user_type_tpl($this->tpl_path, $this->tpl, $this->user_type); /** import tpl **/ return parent::render($this->tpl_path, $this->tpl, false, true); }
/** * Removes property type * @author Howard R <*****@*****.**> * @static * @param int $property_type_id * @return boolean */ public static function remove_property_type($property_type_id) { /** trigger event **/ wpl_global::event_handler('property_type_removed', array('id' => $property_type_id)); $query = "DELETE FROM `#__wpl_property_types` WHERE `id`='{$property_type_id}'"; $result = wpl_db::q($query); return $result; }
/** * Updates wpl_sort_options table * @author Howard <*****@*****.**> * @static * @param string $table * @param int $id * @param string $key * @param string $value * @return boolean */ public static function update($table = 'wpl_sort_options', $id, $key, $value = '') { /** first validation **/ if (trim($table) == '' or trim($id) == '' or trim($key) == '') { return false; } /** trigger event **/ wpl_global::event_handler('sort_options_updated', array('id' => $id, 'key' => $value)); return wpl_db::set($table, $id, $key, $value); }
/** * Add a new listing type * @author Howard R <*****@*****.**> * @static * @param type $parent * @param type $name * @param type $gicon * @return type */ public static function insert_listing_type($parent, $name, $gicon = NULL) { $query = "INSERT INTO `#__wpl_listing_types` (`parent`,`enabled`,`editable`,`gicon`,`name`) VALUES ('{$parent}','1','2','{$gicon}','{$name}')"; $id = wpl_db::q($query, 'insert'); $query = "UPDATE `#__wpl_listing_types` SET `index`='{$id}.00' WHERE `id`='{$id}'"; wpl_db::q($query); /** trigger event **/ wpl_global::event_handler('listing_type_added', array('name' => $name)); return $id; }
/** * Updates a file * @author Howard R <*****@*****.**> * @static * @param string $file_name * @param int $parent_id * @param array $values * @return boolean */ public static function update_file($file_name, $parent_id, $values = array()) { /** first validation **/ if (!trim($file_name) or !trim($parent_id) or count($values) == 0) { return false; } $q = ''; foreach ($values as $key => $value) { $q .= "`{$key}`='{$value}', "; } $q = trim($q, ", "); $file_name = trim($file_name); $query = "UPDATE `#__wpl_items` SET " . $q . " WHERE `parent_id`='{$parent_id}' AND `item_name`='{$file_name}'"; $affected_rows = wpl_db::q($query, 'update'); /** trigger event **/ wpl_global::event_handler('item_updated', array('file_name' => $file_name, 'parent_id' => $parent_id)); return $affected_rows; }
/** * Adds a new room type * @author Howard <*****@*****.**> * @static * @param string $name * @return int */ public static function save_room_type($name) { $query = "INSERT INTO `#__wpl_room_types` (`name`,`icon`) VALUES ('{$name}', 'default.png')"; $id = wpl_db::q($query, 'insert'); /** trigger event **/ wpl_global::event_handler('room_type_added', array('id' => $id)); return $id; }
private function gicon_delete($icon) { if (trim($icon) == '') { $icon = wpl_request::getVar('icon'); } $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'listing_types' . DS . 'gicon' . DS . $icon; if (wpl_file::exists($dest)) { wpl_file::delete($dest); } /** trigger event **/ wpl_global::event_handler('gicon_removed', array('icon' => $icon)); exit; }
/** * Removes a dbst field from dbst table * @author Howard R <*****@*****.**> * @static * @param int $dbst_id * @return boolean */ public static function remove_dbst($dbst_id) { /** first validation **/ if (!$dbst_id) { return false; } /** Multilingual **/ if (wpl_global::check_addon('pro')) { wpl_addon_pro::remove_multilingual($dbst_id); } /** trigger event **/ wpl_global::event_handler('dbst_removed', $dbst_id); wpl_db::delete("wpl_dbst", $dbst_id); }
/** * Removes WPL cached data * @author Howard <*****@*****.**> * @static * @param type $cache_type * @return boolean */ public static function clear_cache($cache_type = 'all') { /** first validation **/ $cache_type = strtolower($cache_type); if (trim($cache_type) == '') { return false; } /** import libraries **/ _wpl_import('libraries.property'); _wpl_import('libraries.items'); if ($cache_type == 'unfinalized_properties' or $cache_type == 'all') { $properties = wpl_db::select("SELECT `id` FROM `#__wpl_properties` WHERE `finalized`='0'", 'loadAssocList'); foreach ($properties as $property) { wpl_property::purge($property['id']); } } if ($cache_type == 'properties_cached_data' or $cache_type == 'all') { $q = " `location_text`='', `rendered`='', `alias`=''"; if (wpl_global::check_multilingual_status()) { $q = self::get_multilingual_query(array('alias', 'location_text', 'rendered')); } $query = "UPDATE `#__wpl_properties` SET " . $q; wpl_db::q($query); } if ($cache_type == 'location_texts' or $cache_type == 'all') { $q = " `location_text`=''"; if (wpl_global::check_multilingual_status()) { $q = self::get_multilingual_query(array('location_text')); } $query = "UPDATE `#__wpl_properties` SET " . $q; wpl_db::q($query); } if ($cache_type == 'listings_thumbnails' or $cache_type == 'all') { $properties = wpl_db::select("SELECT `id`, `kind` FROM `#__wpl_properties` WHERE `id`>0", 'loadAssocList'); $ext_array = array('jpg', 'jpeg', 'gif', 'png'); foreach ($properties as $property) { $path = wpl_items::get_path($property['id'], $property['kind']); $thumbnails = wpl_folder::files($path, 'th.*\\.(' . implode('|', $ext_array) . ')$', 3, true); foreach ($thumbnails as $thumbnail) { wpl_file::delete($thumbnail); } } } if ($cache_type == 'users_cached_data' or $cache_type == 'all') { $q = " `location_text`='', `rendered`=''"; if (wpl_global::check_multilingual_status()) { $q = self::get_multilingual_query(array('location_text', 'rendered'), 'wpl_users'); } $query = "UPDATE `#__wpl_users` SET " . $q; wpl_db::q($query); } if ($cache_type == 'users_thumbnails' or $cache_type == 'all') { $users = wpl_db::select("SELECT `id` FROM `#__wpl_users` WHERE `id`>0", 'loadAssocList'); $ext_array = array('jpg', 'jpeg', 'gif', 'png'); foreach ($users as $user) { $path = wpl_items::get_path($user['id'], 2); $thumbnails = wpl_folder::files($path, 'th.*\\.(' . implode('|', $ext_array) . ')$', 3, true); foreach ($thumbnails as $thumbnail) { wpl_file::delete($thumbnail); } } } /** trigger event **/ wpl_global::event_handler('cache_cleared', array('cache_type' => $cache_type)); return true; }
private function update_package() { $sid = wpl_request::getVar('sid'); $tmp_directory = wpl_global::init_tmp_folder(); $dest = $tmp_directory . 'package.zip'; $zip_file = wpl_global::get_web_page('http://billing.realtyna.com/index.php?option=com_rls&view=downloadables&task=download&sid=' . $sid . '&randomkey=' . rand(1, 100)); if (!$zip_file) { $this->response(array('success' => '0', 'error' => __('Error: #U202, Could not download the update package!', WPL_TEXTDOMAIN), 'message' => '')); } if (!class_exists('ZipArchive')) { $this->response(array('success' => '0', 'error' => __('Error: #U205, Your PHP has no ZipArchive support enabled!', WPL_TEXTDOMAIN), 'message' => '')); } if (!wpl_file::write($dest, $zip_file)) { $this->response(array('success' => '0', 'error' => __('Error: #U203, Could not create the update file!', WPL_TEXTDOMAIN), 'message' => '')); } if (!wpl_global::zip_extract($dest, $tmp_directory)) { $this->response(array('success' => '0', 'error' => __('Error: #U204, Could not extract the update file!', WPL_TEXTDOMAIN), 'message' => '')); } $script_file = $tmp_directory . 'installer.php'; if (!wpl_file::exists($script_file)) { $this->response(array('error' => __("Installer file doesn't exist!", WPL_TEXTDOMAIN), 'message' => '')); } if (!is_writable(WPL_ABSPATH . 'WPL.php')) { $this->response(array('error' => __("PHP doesn't have write access to the files and directories!", WPL_TEXTDOMAIN), 'message' => '')); } /** including installer and run the install method **/ include $script_file; if (!class_exists('wpl_installer')) { $this->response(array('error' => __("Installer class doesn't exist!", WPL_TEXTDOMAIN), 'message' => '')); } /** run install script **/ $wpl_installer = new wpl_installer(); $wpl_installer->path = $tmp_directory; if (!$wpl_installer->run()) { $this->response(array('error' => $wpl_installer->error, 'message' => '')); } /** Trigger Event **/ wpl_global::event_handler('package_updated', array('package_id' => isset($wpl_installer->addon_id) ? $wpl_installer->addon_id : 0)); $message = $wpl_installer->message ? $wpl_installer->message : __('Addon Updated.', WPL_TEXTDOMAIN); $this->response(array('error' => '', 'message' => $message)); }
/** * Update one currency exchange rate * @author Howard <*****@*****.**> * @static * @param type $unit_id * @param type $currency_code * @return int */ public static function update_a_exchange_rate($unit_id, $currency_code) { $exchange_rate = self::currency_converter($currency_code, 'USD', 1); $result = self::update($unit_id, 'tosi', $exchange_rate); /** trigger event **/ wpl_global::event_handler('exchange_rate_updated', array('unit_id' => $unit_id, 'currency_code' => $currency_code)); if ($result) { return $exchange_rate; } else { return 0; } }
/** * 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); }
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); }
private function delete_location($level, $location_id) { $res = wpl_locations::delete_location($location_id, $level, true); /** trigger event **/ wpl_global::event_handler('location_deleted', array('level' => $level, 'location_id' => $location_id)); $res = $res ? 1 : 0; $message = $res ? __('Location(s) Deleted.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN); $data = NULL; $response = array('success' => $res, 'message' => $message, 'data' => $data); echo json_encode($response); exit; }
private function remove_dbst($dbst_id) { $dbst_type = wpl_flex::get_dbst_key('type', $dbst_id); $dbst_kind = wpl_flex::get_dbst_key('kind', $dbst_id); $is_deletable = wpl_flex::get_dbst_key('deletable', $dbst_id); if ($is_deletable) { /** delete dbst row **/ wpl_flex::remove_dbst($dbst_id); /** run queries **/ wpl_flex::run_dbst_type_queries($dbst_id, $dbst_type, $dbst_kind, 'delete'); /** trigger event **/ wpl_global::event_handler('dbst_deleted', array('id' => $dbst_id, 'kind' => $dbst_kind, 'type' => $dbst_type)); $success = 1; $message = __('Field saved.', WPL_TEXTDOMAIN); } else { $success = 0; $message = __('Field is not deletable.', WPL_TEXTDOMAIN); } /** echo response **/ echo json_encode(array('success' => $success, 'message' => $message, 'data' => NULL)); exit; }
/** * Changes user (Agent) of a property * @author Howard <*****@*****.**> * @static * @param int $property_id * @param int $user_id * @return boolean */ public static function change_user($property_id, $user_id) { /** first validation **/ if (!trim($property_id) or !trim($user_id)) { return false; } /** running the query **/ wpl_db::q("UPDATE `#__wpl_properties` SET `user_id`='{$user_id}' WHERE `id`='{$property_id}'"); /** trigger event **/ wpl_global::event_handler('property_user_changed', array('property_id' => $property_id, 'user_id' => $user_id)); return true; }
/** * Changes Membership of a user * @author Howard R <*****@*****.**> * @static * @param int $user_id * @param int $membership_id * @param boolean $trigger_event */ public static function change_membership($user_id, $membership_id = -1, $trigger_event = true) { $user_data = wpl_users::get_wpl_data($user_id); /** Add user to WPL if not added **/ if (!$user_data) { wpl_users::add_user_to_wpl($user_id); $user_data = wpl_users::get_wpl_data($user_id); } $method = (isset($user_data->membership_id) and $user_data->membership_id != $membership_id) ? 'membership_changed' : 'access_updated'; $membership_data = wpl_users::get_wpl_data($membership_id); $query1 = ''; foreach ($membership_data as $key => $value) { if (substr($key, 0, 7) != 'access_' and substr($key, 0, 8) != 'maccess_') { continue; } $query1 .= "`{$key}`='{$value}', "; } $query1 = trim($query1, ', '); $query = "UPDATE `#__wpl_users` SET " . $query1 . ", `membership_id`='" . $membership_id . "' WHERE `id`='" . $user_id . "'"; wpl_db::q($query); /** user assigned to a new group **/ if ($method == 'membership_changed' and wpl_global::check_addon('membership')) { /** Import library **/ _wpl_import('libraries.addon_membership'); $membership = new wpl_addon_membership(); $membership->update_expiry_date($user_id, NULL, true); } /** trigger event **/ $params = array('user_id' => $user_id, 'previous_membership' => $user_data->membership_id, 'new_membership' => $membership_id); if ($trigger_event and $method == 'access_updated') { wpl_global::event_handler('user_access_updated', $params); } elseif ($trigger_event and $method == 'membership_changed') { wpl_global::event_handler('user_membership_changed', $params); } }
/** * Runs after user login * @author Howard R. <*****@*****.**> * @param string $username * @param object $user */ public function user_loggedin($username, $user) { /** trigger event **/ $id = self::get_id_by_username($username); wpl_global::event_handler('user_loggedin', array('username' => $username, 'user' => $user, 'user_id' => $id)); }