*/
class Aretk_Crea_Public {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private $property_details_arr;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function aretkcrea_enqueue_styles() {
/**
* An instance of this class should be passed to the run() function
* defined in Aretk_Crea_Loader as all of the hooks are defined
* in that particular class.
*
* The Aretk_Crea_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( 'jQuery-public-ui-style', plugin_dir_url( __FILE__ ) . 'css/jquery-public-ui.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/aretk-crea-public.css', array(), $this->version, 'all' );
wp_enqueue_style( 'jquery.bxslider-css', plugin_dir_url( __FILE__ ) . 'css/jquery.bxslider.css', array(), $this->version, 'all' );
wp_enqueue_style( 'nouislider-min-css', plugin_dir_url( __FILE__ ) . 'css/nouislider.min.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function aretkcrea_enqueue_scripts() {
/**
* An instance of this class should be passed to the run() function
* defined in Aretk_Crea_Loader as all of the hooks are defined
* in that particular class.
*
* The Aretk_Crea_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
global $post,$wpdb;
wp_enqueue_script('jquery-ui');
wp_enqueue_script('jquery-ui-slider');
$google_map_api = get_option('google-map-api-name');
$google_map_script_loaded_or_not = get_option('crea_google_map_script_load_or_not');
$google_map_api_key_pass = '';
if( isset( $google_map_api ) && !empty( $google_map_api) ) {
$google_map_api_results = $google_map_api;
$google_map_api_key_pass .= "?key=$google_map_api_results";
}
if( isset( $google_map_script_loaded_or_not ) && !empty( $google_map_script_loaded_or_not ) ){
if( $google_map_script_loaded_or_not === 'Yes') {
wp_enqueue_script( 'google-map-js', "https://maps.googleapis.com/maps/api/js$google_map_api_key_pass", array( 'jquery' ));
}
}
wp_enqueue_script( 'markerclusterer_compiled-js', plugin_dir_url( __FILE__ ) . 'js/markerclusterer_compiled.js', array( 'jquery' ));
if ( isset( $post->post_content ) ) {
if ( has_shortcode( $post->post_content, 'ARTEK-BF' ) || has_shortcode( $post->post_content, 'ARTEK-SF' ) || has_shortcode( $post->post_content, 'ARTEK-CF' ) ) {
wp_enqueue_script( 'crealead-js', plugin_dir_url( __FILE__ ) . 'js/jquery.validate.min.js', array( 'jquery' ), false, 'all' );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/shortcose_validation.js', array( 'jquery' ), false );
}
}
wp_enqueue_script( 'jquery-ui-accordion');
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/aretk-crea-public.js', array( 'jquery' ), false, 'all' );
wp_localize_script( $this->plugin_name, 'adminajaxjs', array('adminajaxjsurl' => admin_url( 'admin-ajax.php' )));
wp_enqueue_script( 'accordion-public', plugin_dir_url( __FILE__ ) . 'js/accordion-public.js', array( 'jquery' ), $this->version);
wp_enqueue_script( 'bxlsider-public', plugin_dir_url( __FILE__ ) . 'js/jquery.bxslider.js', array( 'jquery' ), $this->version);
wp_enqueue_script( 'nouislider-min-js', plugin_dir_url( __FILE__ ) . 'js/nouislider.min.js', array( 'jquery' ), $this->version);
wp_enqueue_script( 'loader-js-one', plugin_dir_url( __FILE__ ) . 'js/modernizr.js', array( 'jquery' ), $this->version);
}
/**
* Return property Address
*
* @param unknown_type $numpages
* @param unknown_type $pagerange
* @param unknown_type $paged
*/
public static function get_property_meta() {
global $wpdb, $posts;
$property_details_arr = NULL;
if (strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-detail') !== false || strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-details') !== false) {
if (strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-details') !== false){
$page_slug = 'listing-details';
} else {
$page_slug = 'listing-detail';
}
$real_url = rtrim($_SERVER['REQUEST_URI'],"/");
$listing_explode_array_results = explode('/',$real_url);
$listing_explode_array = array_reverse($listing_explode_array_results);
$listing_id = $listing_explode_array[1];
$is_exclusive = NULL;
if( $listing_id == 'exclusive' ){
$is_exclusive = 'exclusive';
$listing_id = $listing_explode_array[2];
}
# Ensure a listing ID has been set
if (isset($listing_id) && !empty($listing_id) && is_numeric($listing_id)) {
$propertyListId = $listing_id;
$getSubscriptionListingFeed = get_option('crea_subscription_status', true);
if( isset( $getSubscriptionListingFeed ) && $getSubscriptionListingFeed === 'valid' && $is_exclusive !== 'exclusive') {
$crea_user_name_table_name = $wpdb->prefix . ARETKCREA_USER_LISTING_DETAILS;
$getAllUsername = $wpdb->get_results("SELECT username FROM $crea_user_name_table_name");
$userNameList = '';
if (isset($getAllUsername) && !empty($getAllUsername)) {
foreach ($getAllUsername as $singleUsername) {
$userName = $singleUsername->username;
if ( !empty( $userName ) ){
$userNameList.=$userName.',';
}
unset($singleUsername);
}
unset($getAllUsername);
$userNameList = rtrim($userNameList,',');
$result_type = 'full';
$listings = Aretk_Crea_Admin::aretkcrea_get_property_detail_page_result($userNameList, $result_type,$propertyListId);
if ( isset($listings) && !empty($listings)) {
foreach ($listings as $listing_key => $listing ){
if ( !isset( $listing['TotalRecords'] ) && empty( $listing['TotalRecords'] ) ) {
$allListingArr[$listing['ID']] = $listing;
}
}
}
}
$property_details_arr = $allListingArr[$propertyListId];
if ( isset( $property_details_arr ) && !empty( $property_details_arr ) ) {
$property_exists = true;
$listing_full_address_path = '';
$listing_full_address = '';
if ( !empty( $property_details_arr['StreetAddress'] ) ) {
$listing_full_address .= $property_details_arr['StreetAddress'];
}
if ( !empty( $property_details_arr['City'] ) ) {
if ( !empty($listing_full_address) ){
$listing_full_address .= ', ';
}
$listing_full_address .= $property_details_arr['City'];
}
if ( !empty( $property_details_arr['Province'] ) ) {
if ( !empty($listing_full_address) ){
$listing_full_address .= ' ';
}
$listing_full_address .= $property_details_arr['Province'];
}
$listing_full_address_path = $property_details_arr['generated_address'];
$property_description = $property_details_arr['PublicRemarks'];
$listing_full_address = !empty( $listing_full_address ) ? $listing_full_address : 'Address not available';
# Property Images
$site_image_path = ARETK_CREA_PLUGIN_URL.'public/images/preview_img.jpg';
if ( $property_details_arr['listing_photos'] != null ) {
$property_photos = $property_details_arr['listing_photos'];
$domain_name = $_SERVER['SERVER_NAME'];
# Check if primary image is_valid
if ( isset( $property_photos) && !empty( $property_photos ) && !is_array($property_photos) ){
$singleListingimag_array = explode('/',$property_photos['URL']);
if( !empty($singleListingimag_array )){
$singleListingimage_domain = $singleListingimag_array[2];
if( $domain_name == $singleListingimage_domain ){
list($width, $height, $type, $attr) = getimagesize($property_photos['URL']);
if( !empty( $width ) && $width !='0') {
$property_image_path = $property_photos['URL'];
} else {
$property_image_path = $site_image_path;
}
} else if( $domain_name != $singleListingimage_domain && $singleListingimage_domain !='static.aretk.com' ) {
$property_image_path = $site_image_path;
} else {
$property_image_path = $property_photos['URL'];
}
}
} else {
# Get primary image for social sharing
$singleListingimag_array = explode('/',$property_photos[0]['URL']);
if( !empty($singleListingimag_array )){
$singleListingimage_domain = $singleListingimag_array[2];
if( $domain_name == $singleListingimage_domain ){
# Image stored locally
list($width, $height, $type, $attr) = getimagesize($property_photos[0]['URL']);
if( !empty( $width ) && $width !='0') {
$property_image_path = $property_photos[0]['URL'];
} else {
$property_image_path = $site_image_path;
}
} else if( $domain_name != $singleListingimage_domain && $singleListingimage_domain !='static.aretk.com' ) {
$property_image_path = $site_image_path;
} else {
$property_image_path = $property_photos[0]['URL'];
}
}
}
} else {
$property_image_path = $site_image_path;
}
$is_exclusive_list = '';
$property_link_url = '';
$propertyListId = $property_details_arr['ID'];
if ( !empty( $property_details_arr ) && $property_details_arr != '' ){
$property_link_url = site_url().'/'.$page_slug.'/'.$propertyListId.'/'.sanitize_title($listing_full_address_path);
}
} else {
$property_exists = false;
}
} else {
/*
* No valid ARETK Subscription
*/
$property_details_arr = array();
$data = array();
$wpdb->query("SELECT `meta_key`, `meta_value` FROM $wpdb->postmeta WHERE `post_id` = $listing_id");
foreach($wpdb->last_result as $k => $v){
$data[$v->meta_key] = $v->meta_value;
};
if (empty($data)){
$property_exists = false;
$listing_full_address = 'Property Not Found';
} else {
$property_exists = true;
$listing_type = get_post_meta($propertyListId,'listing_type',true);
$listingAddress = get_post_meta($propertyListId,'listingAddress',true);
$ListingCity = get_post_meta($propertyListId,'listingcity',true);
$listingProvince = get_post_meta($propertyListId,'listingProvince',true);
# build $property_details_arr to match aretk array.
$property_details_arr["ID"] = $listing_id;
$property_details_arr["LID"] = NULL;
$property_details_arr["LastUpdated"] = NULL;
$property_details_arr["mlsID"] = 'Exclusive';
$property_details_arr["AmmenitiesNearBy"] = $listing_id;
$property_details_arr["Board"] = $listing_id;
$property_details_arr["CommunityFeatures"] = $listing_id;
$property_details_arr["EquipmentType"] = $listing_id;
$property_details_arr["Features"] = implode(', ', json_decode(get_post_meta($propertyListId,'listingFeatureArr',true)));
$property_details_arr["Lease"] = NULL;
$property_details_arr["LeasePerTime"] = NULL;
$property_details_arr["LeasePerUnit"] = NULL;
$property_details_arr["ListingContractDate"] = NULL;
$property_details_arr["LocationDescription"] = NULL;
$property_details_arr["MaintenanceFee"] = NULL;
$property_details_arr["MaintenanceFeePaymentUnit"] = NULL;
$property_details_arr["MaintenanceFeeType"] = NULL;
$property_details_arr["ManagementCompany"] = NULL;
$property_details_arr["MoreInformationLink"] = NULL;
$property_details_arr["MunicipalId"] = NULL;
$property_details_arr["OwnershipType"] = NULL;
$property_details_arr["ParkingSpaceTotal"] = get_post_meta($propertyListId,'listingParkingSlot',true);
$property_details_arr["PoolType"] = NULL;
$property_details_arr["Price"] = get_post_meta($propertyListId,'listingPrice',true);
$property_details_arr["PropertyType"] = get_post_meta($propertyListId,'listingPropertyType',true);
$property_content_post = get_post($propertyListId);
if (!empty($property_content_post) && $property_content_post != '') {
$property_description = $property_content_post->post_content;
$property_details_arr["PublicRemarks"] = $property_content_post->post_content;
} else {
$property_details_arr["PublicRemarks"] = NULL;
}
$property_details_arr["RentalEquipmentType"] = NULL;
$property_details_arr["SignType"] = NULL;
$property_details_arr["Structure"] = get_post_meta($propertyListId,'listingStructureType',true);
$property_details_arr["TransactionType"] = get_post_meta($propertyListId,'listingAgentStatus',true);
$property_details_arr["AnalyticsClick"] = NULL;
$property_details_arr["AnalyticsView"] = NULL;
$property_details_arr["StreetAddress"] = get_post_meta($propertyListId,'listingAddress',true);
$property_details_arr["City"] = get_post_meta($propertyListId,'listingcity',true);
$property_details_arr["AddressLine1"] = NULL;
$property_details_arr["StreetNumber"] = NULL;
$property_details_arr["StreetName"] = NULL;
$property_details_arr["StreetSuffix"] = NULL;
$property_details_arr["StreetDirectionSuffix"] = NULL;
$property_details_arr["Province"] = get_post_meta($propertyListId,'listingProvince',true);
$property_details_arr["PostalCode"] = NULL;
$property_details_arr["Country"] = NULL;
$property_details_arr["CommunityName"] = NULL;
$property_details_arr["generated_address"] = NULL;
$property_details_arr["geocoded_latitude"] = get_post_meta($propertyListId,'crea_google_map_latitude',true);
$property_details_arr["geocoded_longitude"] = get_post_meta($propertyListId,'crea_google_map_longitude',true);
$property_details_arr["geocoded_status"] = NULL;
$property_details_arr["geocoded_provider"] = NULL;
$property_details_arr["geocoded_date"] = NULL;
$property_details_arr["PhotoLink"] = NULL;
$property_details_arr["VideoLink"] = get_post_meta($propertyListId,'listingTourUrl',true);
$property_details_arr["BrochureLink"] = NULL;
$property_details_arr["MapLink"] = NULL;
$property_details_arr["SoundLink"] = NULL;
$property_details_arr["Age"] = NULL;
$property_details_arr["Amenities"] = NULL;
$property_details_arr["Appliances"] = NULL;
$property_details_arr["ArchitecturalStyle"] = NULL;
$property_details_arr["BasementType"] = get_post_meta($propertyListId,'listingFinishedBasement',true);
$property_details_arr["BathroomTotal"] = get_post_meta($propertyListId,'listingBathrooms',true);
$property_details_arr["BedroomsTotal"] = get_post_meta($propertyListId,'listingBedRooms',true);
$property_details_arr["BedroomsAboveGround"] = NULL;
$property_details_arr["BedroomsBelowGround"] = NULL;
$property_details_arr["ConstructedDate"] = NULL;
$property_details_arr["ConstructionMaterial"] = NULL;
$property_details_arr["CoolingType"] = NULL;
$property_details_arr["ConstructionStyleAttachment"] = NULL;
$property_details_arr["ExteriorFinish"] = NULL;
$property_details_arr["FireplaceFuel"] = NULL;
$property_details_arr["FireplacePresent"] = NULL;
$property_details_arr["FireplaceType"] = NULL;
$property_details_arr["FlooringType"] = NULL;
$property_details_arr["FoundationType"] = NULL;
$property_details_arr["HalfBathTotal"] = get_post_meta($propertyListId,'listingBathroomsPartial',true);
$property_details_arr["HeatingFuel"] = NULL;
$property_details_arr["HeatingType"] = NULL;
$property_details_arr["SizeInterior"] = NULL;
$property_details_arr["StoriesTotal"] = NULL;
$property_details_arr["Type"] = NULL;
$property_details_arr["Utilities"] = implode(', ', json_decode(get_post_meta($propertyListId,'listingUtilityArr',true)));
$property_details_arr["UtilityPower"] = NULL;
$property_details_arr["UtilityWater"] = NULL;
$property_details_arr["BusinessType"] = NULL;
$property_details_arr["BusinessSubType"] = NULL;
$property_details_arr["SizeTotalText"] = NULL;
$property_details_arr["AccessType"] = NULL;
$property_details_arr["Acreage"] = NULL;
$property_details_arr["FenceType"] = NULL;
$property_details_arr["LandDisposition"] = NULL;
$property_details_arr["LandscapeFeatures"] = NULL;
$property_details_arr["Sewer"] = NULL;
$property_details_arr["ViewCount"] = get_post_meta($propertyListId,'crea_aretk_db_listing_page_count',true);
$property_details_arr["Feedtype"] = NULL;
$property_details_arr["listing_rooms"] = NULL;
// Open Houses
$OpenHouseArr = array();
$OpenHouseDecodeArr = json_decode(get_post_meta($propertyListId,'listingopenhosedatetimeArr',true));
if( $OpenHouseDecodeArr !='' && !empty($OpenHouseDecodeArr) ) {
$openHouse_Counter = 0;
foreach ( $OpenHouseDecodeArr as $OpenHouseDecodeArrKey=>$OpenHouseDecodeArrValue ){
$openHouse_Counter++;
$startDate = strtotime($OpenHouseDecodeArrValue->date);
$startTime = $OpenHouseDecodeArrValue->start_time;
$endTime =$OpenHouseDecodeArrValue->end_time;
$ohStartDate = date('m/d/Y', $startDate)." ".date('h:i:s A', strtotime($startTime));
$ohEndDate = date('m/d/Y', $startDate)." ".date('h:i:s A', strtotime($endTime));
if( $ohStartDate != "01/01/1970 12:00:00 AM" && $ohEndDate != "01/01/1970 12:00:00 AM" ){
$OpenHouseArr[] = array("sequence_id" => $openHouse_Counter,"StartDateTime" => $ohStartDate,"EndDateTime" => $ohEndDate, 'Comments' => NULL);
} else {
$agentOpenHouseArr = "";
}
}
}
$property_details_arr["listing_openHouses"] = $OpenHouseArr;
#Parking
$parking_spaces = array();
$parking_name = get_post_meta($propertyListId,'listingParkinggarage',true);
$parking_spaces = get_post_meta($propertyListId,'listingParkingSlot',true);
if (!empty($parking_name) && !empty($parking_spaces) ){
$parking_spaces = array();
$parking_spaces[] = array('SequenceID' => '1', 'Name' => get_post_meta($propertyListId,'listingParkinggarage',true), 'Spaces' => get_post_meta($propertyListId,'listingParkingSlot',true));
$property_details_arr["listing_parkingSpaces"] = $parking_spaces;
} else {
$property_details_arr["listing_parkingSpaces"] = NULL;
}
#Photos
$crea_listing_images_detail_table_name = $wpdb->prefix . ARETKCREA_LISTING_IMAGES_HISTORY;
$querySelectPropertyImages = "SELECT `image_url` FROM $crea_listing_images_detail_table_name WHERE `unique_id` = $propertyListId";
$site_image_path = ARETK_CREA_PLUGIN_URL.'public/images/preview_img.jpg';
$propertyimages = $wpdb->get_results($querySelectPropertyImages);
$property_photos = array();
if ( isset($propertyimages) && !empty($propertyimages) && is_array($propertyimages) ) {
foreach ( $propertyimages as $propertyimage ) {
if ( !empty( $propertyimage->image_url ) ) {
$property_photos[] = array('URL' => $propertyimage->image_url, 'description' => NULL);
}
}
} else {
$property_photos[] = array('URL' => $site_image_path, 'description' => NULL);
}
$property_image_path = $property_photos[0]['URL'];
$property_details_arr["listing_photos"] = $property_photos;
$listing_full_address_path = '';
$listing_full_address = '';
if ( !empty( $listingAddress ) ) {
$listingAddress = trim($listingAddress);
$listing_full_address .= trim($listingAddress);
$listingAddress = str_replace(' ', '-', $listingAddress);
$listingAddress = str_replace('#', '', $listingAddress);
$listingAddress = str_replace('-','-',$listingAddress);
$listingAddress = str_replace('--','-',$listingAddress);
$listingAddress = str_replace('---','-',$listingAddress);
$listingAddress = str_replace('----','-',$listingAddress);
$listing_full_address_path.= $listingAddress;
}
if ( !empty( $ListingCity ) ) {
$ListingCity = trim($ListingCity);
if (!empty($listing_full_address)){ $listing_full_address .= ', '; }
$listing_full_address .= $ListingCity;
$ListingCity = str_replace(' ', '-', $ListingCity);
$ListingCity = str_replace('#', '', $ListingCity);
$ListingCity = str_replace('-','-',$ListingCity);
$ListingCity = str_replace('--','-',$ListingCity);
$ListingCity = str_replace('---','-',$ListingCity);
$ListingCity = str_replace('----','-',$ListingCity);
$listing_full_address_path.='-'.$ListingCity;
}
if ( !empty( $listingProvince ) ) {
$listingProvince = trim($listingProvince);
if (!empty($listing_full_address)){ $listing_full_address .= ' '; }
$listing_full_address .= $listingProvince;
$listingProvince = str_replace(' ', '-', $listingProvince);
$listingProvince = str_replace('#', '', $listingProvince);
$listingProvince = str_replace('-','-',$listingProvince);
$listingProvince = str_replace('--','-',$listingProvince);
$listingProvince = str_replace('---','-',$listingProvince);
$listingProvince = str_replace('----','-',$listingProvince);
$listing_full_address_path.='-'.$listingProvince;
}
$property_link_url = site_url().'/'.$page_slug.'/'.$propertyListId.'/'.sanitize_title($listing_full_address_path);
}
}
$property_detail_meta = array(
"property_exists"=> $property_exists,
"is_exclusive" => $is_exclusive,
"aretk_subscription" => $getSubscriptionListingFeed,
"address_full" => $listing_full_address,
"slug" => sanitize_title($listing_full_address_path),
#"listing_type" => $listing_type,
"url_canonical" => $property_link_url,
"image_primary" => $property_image_path,
);
$new_url = sanitize_title('This Long Title is what My Post or Page might be');
if (!is_array($property_details_arr)){
$property_details_arr = array();
}
//Agents Array
$listingAgents = !empty($property_details_arr['listing_agents'])? $property_details_arr['listing_agents'] :'';
$listingAgents = !empty($listingAgents) ? $listingAgents : array();
$property_details_arr = $property_detail_meta + $property_details_arr;
$property_details_arr['listing_agents'] = $listingAgents;
return $property_details_arr;
}
}
}
/**
* Custom pagination function
*
* @param unknown_type $numpages
* @param unknown_type $pagerange
* @param unknown_type $paged
*/
public static function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
/**
* This first part of our function is a fallback
* for custom pagination inside a regular loop that
* uses the global $paged and global $wp_query variables.
*/
if ($paged == '') {
global $paged;
if (empty($paged)) {
$paged = 1;
}
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagenumber_id = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if ( is_numeric($pagenumber_id) ) {
$page_base_link = get_permalink() . '%_%';
} else {
$page_base_link = preg_replace('/\?.*/', '', get_pagenum_link(1)) . '%_%';
}
$pagination_args = array(
'base' => $page_base_link,
'format' => '%#%/',
'total' => $numpages,
'current' => $paged,
'show_all' => false,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => false,
'prev_text' => __(' «'),
'next_text' => __(' »'),
'type' => 'plain',
'add_fragment' => '',
'after_page_number' => '',
'before_page_number' =>'',
);
$paginate_links = paginate_links($pagination_args);
if ( $paginate_links ) {
$html = '';
$html .= '';
return $html;
}
}
/**
* Replace the default page title on the property details page
*
*/
function replace_title_propertydetails($title, $id) {
global $property_details_arr;
$item = get_post( $id );
if ( $item->post_type === 'nav_menu_item'){ return $title; }
if ( (strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-detail') !== false || strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-details') !== false) && in_the_loop() ) {
if ( empty($property_details_arr) ){
$property_details_arr = Aretk_Crea_Public::get_property_meta();
}
$title = $property_details_arr['address_full'];
}
return $title;
}
/**
* Reminder Cron Schedule
*
*/
function reminder_cron_schedule($schedules) {
$schedules['reminder_minute'] = array(
'interval' => 900, # 15 minutes
'display' => __( 'Reminder Every Minute' )
);
$schedules['every_one_minutes_check_subscription'] = array(
'interval' => 3600, # 60 minutes
'display' => __( 'Every 60 minutes' )
);
$schedules['every_one_hour_expiration_event'] = array(
'interval' => 1800, # 30 minutes
'display' => __( 'Every 30 minutes' )
);
return $schedules;
}
/**
* Cron function for get data
*
*/
function aretk_subscription_cron_function_to_run() {
global $wpdb;
$time = time();
$current_date = date_i18n( 'Y-m-d H:i' );
update_option('cron_subscription',$time.$current_date);
$getSubscriptionKey = get_option('crea_subscription_key');
$subscriptionKey = !empty($getSubscriptionKey) ? $getSubscriptionKey : '';
$domainName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
if (empty($domainName)){
$domainName = get_site_url();
$domainName = parse_url($domainName, PHP_URL_HOST);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ARETKCREA_SUBSCRIPTIONENDPOINT."?api-key=$subscriptionKey&domain_name=$domainName");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_REFERER,$domainName);
$data = curl_exec($ch);
curl_close($ch);
$resultSet = json_decode($data);
if ( isset($resultSet) && !empty($resultSet) ){
if ( $resultSet->code === 'success' ) {
update_option('crea_subscription_status','valid');
update_option('crea_subscription_key',"$subscriptionKey");
return 'valid';
} else {
update_option('crea_subscription_status','not-valid');
#update_option('crea_subscription_key',""); # keep
return 'not-valid';
}
} else {
update_option('crea_subscription_status','not-valid');
#update_option('crea_subscription_key',""); #keep
}
#-------------------------------------
//Cron Check if any property needs to be added
//code for subscription status in-active stored data record switch in aretk-api server
$getSubscriptionStatus = get_option('crea_subscription_status', '');
if (isset( $getSubscriptionStatus ) && !empty( $getSubscriptionStatus) && $getSubscriptionStatus === 'valid') {
$user_ID = get_current_user_id();
$exclusive_stored_add_id_option = get_option("exclusive_stored_add_id");
if ( !empty($exclusive_stored_add_id_option) && $exclusive_stored_add_id_option != '' ){
$exclusive_stored_add_id_results = '';
$exclusive_stored_add_id_results = json_decode(get_option("exclusive_stored_add_id"));
if ( isset($exclusive_stored_add_id_results) && !empty($exclusive_stored_add_id_results) ){
foreach ( $exclusive_stored_add_id_results as $exclusive_stored_add_id ) {
$postId = $exclusive_stored_add_id;
$get_option = json_decode(get_option('crea_subscription_active_stored_Id'));
$action = 'add';
if ($action === 'add' || $action === 'edit') {
$listingAgentID = get_post_meta($postId,'listingAgentId',true);
$listingAddress = get_post_meta($postId,'listingAddress',true);
$listingcity = get_post_meta($postId,'listingcity',true);
$listingProvince = get_post_meta($postId,'listingProvince',true);
$listingAgentStatus = get_post_meta($postId,'listingAgentStatus',true);
$listingPrice = get_post_meta($postId,'listingPrice',true);
$listingPropertyType = get_post_meta($postId,'listingPropertyType',true);
$listingStructureType = get_post_meta($postId,'listingStructureType',true);
$listingBedRooms = get_post_meta($postId,'listingBedRooms',true);
$listingBathrooms = get_post_meta($postId,'listingBathrooms',true);
$listingBathroomsPartial = get_post_meta($postId,'listingBathroomsPartial',true);
$listingFinishedBasement = get_post_meta($postId,'listingFinishedBasement',true);
$listingFeatureArr = get_post_meta($postId,'listingFeatureArr',true);
$listingParkinggarage = get_post_meta($postId,'listingParkinggarage',true);
$listingParkingSlot = get_post_meta($postId,'listingParkingSlot',true);
$listingTourUrl = get_post_meta($postId,'listingTourUrl',true);
$listingUtilityArr = get_post_meta($postId,'listingUtilityArr',true);
$listingopenhosedatetimeArr = get_post_meta($postId,'listingopenhosedatetimeArr',true);
$listingGoogleMapLatitude = get_post_meta($postId,'crea_google_map_latitude',true);
$listingGoogleMapLongitude = get_post_meta($postId,'crea_google_map_longitude',true);
$listing_full_address_path = '';
if ( !empty( $listingAddress) ) {
$listing_full_address_path.=sanitize_title($listingAddress);
}
if ( !empty( $listingcity ) ) {
$listing_full_address_path.='-'.sanitize_title($listingcity);
}
if ( !empty( $listingProvince ) ) {
$listing_full_address_path.='-'.sanitize_title($listingProvince);
}
$content_post = get_post($postId);
$content = $content_post->post_content;
$listing_public_remarks = $content;
$agentFeaturesDecodeArrValue ='';
//get agent ids array
$agentsIDArr = array();
$agentsDecodeArr = json_decode($listingAgentID);
$implode_agent_id ='';
if( $agentsDecodeArr !='' && !empty($agentsDecodeArr) ) {
$agent_id_counter = 1;
foreach ( $agentsDecodeArr as $agentsDecodekey=>$agentsDecodeArrValue ){
$agentFeaturesDecodeArrValue = trim($agentFeaturesDecodeArrValue);
if ( !empty( $agentsDecodeArrValue ) ){
$agentsIDArr[] = array("sequence_id" => $agent_id_counter , "agent_id" => $agentsDecodeArrValue );
}
$agent_id_counter = $agent_id_counter + 1;
}
}
// get agent features
$agentFeaturesArr = array();
$agentFeaturesFinaleArr = '';
$agentFeaturesDecodeArr = json_decode($listingFeatureArr);
if( $agentFeaturesDecodeArr != '' && !empty($agentFeaturesDecodeArr) ) {
foreach ( $agentFeaturesDecodeArr as $agentFeaturesDecodeArrValue ) {
$agentFeaturesDecodeArrValue = trim($agentFeaturesDecodeArrValue);
if ( !empty( $agentFeaturesDecodeArrValue ) ){
$agentFeaturesArr[] = trim($agentFeaturesDecodeArrValue);
}
}
$agentFeaturesFinaleArr = implode(",",$agentFeaturesArr);
}
// get agents utilitees
$agentUtilitiesArr = array();
$agentUtilitiesDecodeArr = json_decode($listingUtilityArr);
if( $agentUtilitiesDecodeArr != '' && !empty($agentUtilitiesDecodeArr) ) {
$utitlity_counter = 1;
foreach ($agentUtilitiesDecodeArr as $agentUtilitiesDecodeArrValue ) {
$agentUtilitiesDecodeArrValue = trim($agentUtilitiesDecodeArrValue);
if ( !empty( $agentUtilitiesDecodeArrValue ) ) {
$agentUtilitiesArr[] = array("sequence_id" => $utitlity_counter , "type" => $agentUtilitiesDecodeArrValue );
}
$utitlity_counter = $utitlity_counter + 1;
}
}
// get agent images
$agentPhotoArr = array();
$photoGelleryTable = $wpdb->prefix.'crea_listing_images_detail';
$photoQuery = "SELECT * FROM `$photoGelleryTable` WHERE `unique_id`= $postId ORDER BY `image_position` ASC";
$photoResultsArr = $wpdb->get_results($photoQuery);
if( $photoResultsArr != '' && !empty($photoResultsArr) ) {
$photo_counter = 1;
foreach ( $photoResultsArr as $photoResultsArrValue ) {
$agentPhotoArr[] = array("sequence_id" => $photo_counter , "url" => $photoResultsArrValue->image_url );
$photo_counter = $photo_counter + 1;
}
}
// get agent externaldocument
$agentDocumentArr = array();
$agentDocumentFinalArr = '';
$agentDocumentTable = $wpdb->prefix.'crea_listing_document_detail';
$agentDocumentQuery ="SELECT * FROM `$agentDocumentTable` WHERE `unique_id` = $postId ORDER BY `id`";
$agentDocumentResults = $wpdb->get_results($agentDocumentQuery);
if( $agentDocumentResults != '' && !empty($agentDocumentResults) ) {
foreach ( $agentDocumentResults as $agentDocumentResultsValue ) {
$agentDocumentArr[] = $agentDocumentResultsValue->document_url;
}
$agentDocumentFinalArr = implode(",",$agentDocumentArr);
}
// agent Open House date and time
$agentOpenHouseArr = array();
$agentOpenHouseDecodeArr = json_decode($listingopenhosedatetimeArr);
if( $agentOpenHouseDecodeArr !='' && !empty($agentOpenHouseDecodeArr) ) {
$openHouse_Counter = 1;
foreach ( $agentOpenHouseDecodeArr as $agentOpenHouseDecodeArrKey=>$agentOpenHouseDecodeArrValue ){
$startDate = strtotime($agentOpenHouseDecodeArrValue->date);
$startTime = $agentOpenHouseDecodeArrValue->start_time;
$endTime =$agentOpenHouseDecodeArrValue->end_time;
$agentStartDate = date('m/d/Y', $startDate)." ".date('h:i:s A', strtotime($startTime));
$agentEndDate = date('m/d/Y', $startDate)." ".date('h:i:s A', strtotime($endTime));
$agentFormatStartDate = $agentStartDate;
$agentFormatEndDate = $agentEndDate;
if( $agentFormatStartDate != "01/01/1970 12:00:00 AM" && $agentFormatEndDate != "01/01/1970 12:00:00 AM" ){
$agentOpenHouseArr[] = array("sequence_id" => $openHouse_Counter,"start_date" => $agentFormatStartDate,"end_date" => $agentFormatEndDate);
} else {
$agentOpenHouseArr = "";
}
$openHouse_Counter = $openHouse_Counter + 1;
}
}
if( $postId != '') {
if ( $listingGoogleMapLatitude == '57.678079218156' ) {
$listingGoogleMapLatitude = '';
}
if ( $listingGoogleMapLongitude == '-101.8051686875' ) {
$listingGoogleMapLongitude = '';
}
$add_listing_settinges_array = array();
$add_listing_settinges_array = array (
"agent_id" => $agentsIDArr,
"street_address" => $listingAddress,
"city" => $listingcity,
"province" => $listingProvince,
"transaction_type" => $listingAgentStatus,
"price" => $listingPrice,
"property_type" => $listingPropertyType,
"structure" => $listingStructureType,
"bedrooms_total" => $listingBedRooms,
"bathroom_total" => $listingBathrooms,
"halfbath_total" => $listingBathroomsPartial,
"basement_type" => $listingFinishedBasement,
"public_remarks" => $listing_public_remarks,
"features" => $agentFeaturesFinaleArr,
"garage" => $listingParkinggarage,
"no_of_parking_spot" => $listingParkingSlot,
"moreInformation_link" => $listingTourUrl,
"utilities" => $agentUtilitiesArr,
"photo" =>$agentPhotoArr,
"external_document" => $agentDocumentFinalArr,
"open_house" => $agentOpenHouseArr,
"generated_address" => $listing_full_address_path,
"geocoded_latitude" => $listingGoogleMapLatitude,
"geocoded_longitude" => $listingGoogleMapLongitude,
);
$post_string = http_build_query($add_listing_settinges_array);
$exclusive_property_id = array();
$exclusive_property_id[] = (string)$postId;
if ($action === 'add') {
if (isset( $getSubscriptionStatus ) && !empty( $getSubscriptionStatus) && $getSubscriptionStatus === 'valid') {
$addListing = curl_init();
curl_setopt($addListing, CURLOPT_HEADER, 0);
curl_setopt($addListing, CURLOPT_VERBOSE, 0);
curl_setopt($addListing, CURLOPT_URL, ARETKCREA_LISTING_BASEDONSERVER_API."/?key=$subscriptionKey&request=insert_listing");
curl_setopt($addListing, CURLOPT_POST, true);
curl_setopt($addListing, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($addListing, CURLOPT_RETURNTRANSFER,true);
curl_setopt($addListing, CURLOPT_REFERER,$domainName);
$addListingCurlExecute = curl_exec($addListing);
curl_close($addListing);
$addListingCurlExecuteResponse = ($addListingCurlExecute) . PHP_EOL;
$responseDecode = json_decode($addListingCurlExecuteResponse);
if ( isset($responseDecode->code) && !empty($responseDecode->code) ) {
if ($responseDecode->code === 200 && $responseDecode->status === 'success') {
if (isset($responseDecode->data->insert_id)) {
update_post_meta($postId,'aretk_server_listing_id',$responseDecode->data->insert_id);
$exclusive_old_property_id_array = array();
$mergerd_property_id_array = array();
$exclusive_stored_add_id_result = get_option("exclusive_stored_add_id");
if ( !empty( $exclusive_stored_add_id_result ) ) {
$exclusive_old_property_id_array = json_decode($exclusive_stored_add_id_result);
}
$mergerd_property_id_array = array_diff($exclusive_old_property_id_array,$exclusive_property_id);
$mergerd_property_id_array = json_encode($mergerd_property_id_array);
update_option("exclusive_stored_add_id",$mergerd_property_id_array);
}
} else {
$exclusive_old_property_id_array = array();
$mergerd_property_id_array = array();
$exclusive_stored_add_id_result = get_option("exclusive_stored_add_id");
if ( !empty( $exclusive_stored_add_id_result ) ) {
$exclusive_old_property_id_array = json_decode($exclusive_stored_add_id_result);
}
$mergerd_property_id_array = array_merge($exclusive_old_property_id_array,$exclusive_property_id);
$mergerd_property_id_array = array_unique($mergerd_property_id_array);
$mergerd_property_id_array = json_encode($mergerd_property_id_array);
update_option("exclusive_stored_add_id",$mergerd_property_id_array);
}
} else {
$exclusive_old_property_id_array = array();
$mergerd_property_id_array = array();
$exclusive_stored_add_id_result = get_option("exclusive_stored_add_id");
if ( !empty( $exclusive_stored_add_id_result ) ) {
$exclusive_old_property_id_array = json_decode($exclusive_stored_add_id_result);
}
$mergerd_property_id_array = array_merge($exclusive_old_property_id_array,$exclusive_property_id);
$mergerd_property_id_array = array_unique($mergerd_property_id_array);
$mergerd_property_id_array = json_encode($mergerd_property_id_array);
update_option("exclusive_stored_add_id",$mergerd_property_id_array);
}
}
}
}
}
}
}
}
}
//Delete Exclusive property from server
$exclusive_deleted_id_result = get_option("exclusive_deleted_ids");
if ( !empty( $exclusive_deleted_id_result ) && $exclusive_deleted_id_result != 'null' ) {
$exclusive_old_property_id_array = json_decode($exclusive_deleted_id_result);
if ( isset($exclusive_old_property_id_array) && !empty($exclusive_old_property_id_array) ) {
foreach ( $exclusive_old_property_id_array as $exclusive_old_property_id ) {
if (isset( $getSubscriptionStatus ) && !empty( $getSubscriptionStatus) && $getSubscriptionStatus === 'valid') {
$delete_listing = array (
"id" => (int)$exclusive_old_property_id
);
$post_string = http_build_query($delete_listing);
$deleteListing = curl_init();
curl_setopt($deleteListing, CURLOPT_HEADER, 0);
curl_setopt($deleteListing, CURLOPT_VERBOSE, 0);
curl_setopt($deleteListing, CURLOPT_RETURNTRANSFER, true);
curl_setopt($deleteListing, CURLOPT_URL, ARETKCREA_LISTING_BASEDONSERVER_API."/?key=$subscriptionKey&request=delete_listing");
curl_setopt($deleteListing, CURLOPT_POST, true);
curl_setopt($deleteListing, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($deleteListing, CURLOPT_REFERER,$domainName);
$deleteListingCurlExecute = curl_exec($deleteListing);
curl_close($deleteListing);
$deleteListingCurlExecuteResponse = ($deleteListingCurlExecute) . PHP_EOL;
$responseDecode = json_decode($deleteListingCurlExecuteResponse);
}
}
}
}
}
public function call_wp_schedule_event(){
// for reminder functionlity check every minute
if ( ! wp_next_scheduled( 'content_scheduler_reminder_every_minute' ) ) {
wp_schedule_event( time(), 'reminder_minute', 'content_scheduler_reminder_every_minute' );
}
// for expirations subscription call, run evey 60 minutes
if ( ! wp_next_scheduled( 'content_scheduler_subscription' ) ) {
wp_schedule_event( time(), 'every_one_minutes_check_subscription', 'content_scheduler_subscription' );
}
// run evey 30 minutes
if( !wp_next_scheduled( 'content_scheduler_expiration_event' ) ) {
wp_schedule_event( time(), 'every_one_hour_expiration_event', 'content_scheduler_expiration_event' );
}
}
function aretkcrea_answer_expiration_event() {
global $wpdb;
$getSubscriptionStatus = get_option('crea_subscription_status', '');
$current_date = date_i18n( 'Y-m-d H:i' );
update_option('cron_run',"");
update_option('cron_run_time',"");
update_option('cron_run_time',$current_date);
if( isset( $getSubscriptionStatus ) && !empty( $getSubscriptionStatus ) && $getSubscriptionStatus === 'valid' ){
$crea_user_name_table_name = $wpdb->prefix.ARETKCREA_USER_LISTING_DETAILS;
$getAllUsername = $wpdb->get_results("SELECT `username` FROM $crea_user_name_table_name");
$allListingArr = array();
//get all agent ids from database
$crea_agent_table_name = $wpdb->prefix . ARETKCREA_AGENT_TABLE;
$getAllAgentIds = $wpdb->get_results("SELECT `crea_agent_id` FROM $crea_agent_table_name");
$getAllAgentIdArray = array();
if ( isset($getAllAgentIds) && !empty($getAllAgentIds) ){
foreach ($getAllAgentIds as $agent_key => $agent ) {
$getAllAgentIdArray[] = $agent->crea_agent_id;
}
}
if ( isset($getAllAgentIdArray) && !empty($getAllAgentIdArray)) {
$agent_ids = implode(',',$getAllAgentIdArray);
} else {
$agent_ids = null;
}
$allListingArr = array();
$userNameList = '';
if (isset($getAllUsername) && !empty($getAllUsername)) {
foreach ($getAllUsername as $singleUsername) {
$userName = $singleUsername->username;
if ( !empty( $userName ) ){
$userNameList.=$userName.',';
}
unset($singleUsername);
}
unset($getAllUsername);
$userNameList = rtrim($userNameList,',');
$result_type = 'full';
if ( $agent_ids != null ){
$listings = Aretk_Crea_Admin::aretkcrea_get_listing_records_based_on_agents($userNameList, $result_type,$agent_ids);
if ( isset($listings) && !empty($listings)) {
foreach ($listings as $listing_key => $listing ){
if ( !isset( $listing->TotalRecords ) && empty( $listing->TotalRecords ) ) {
$allListingArr[$listing->mlsID] = $listing;
}
}
}
}
}
$args = array(
'posts_per_page' => -1,
'post_type' => 'aretk_listing',
'post_status' => 'publish'
);
$posts_array = (array) get_posts( $args );
$exclusiveArr = array();
foreach ($posts_array as $singlePost) {
$singlePost1 = (array) $singlePost;
$singlePost2 = (object) $singlePost1;
$exclusiveArr[] = $singlePost2;
}
$allListingFinalArr = array();
$allListingFinalArr = array_merge($allListingArr,$exclusiveArr);
$data = json_encode($allListingFinalArr);
update_option('cron_run',"");
update_option('cron_run',"$data");
$crea_user_listing_detail_table_name = $wpdb->prefix.ARETKCREA_USER_LISTING_DETAILS;
$getUsername = "SELECT `username`, `ddf_type` FROM $crea_user_listing_detail_table_name";
$resultUsernameSetArr = $wpdb->get_results($getUsername);
$firstUserName = isset($resultUsernameSetArr[0]->username) ? $resultUsernameSetArr[0]->username : '' ;
$secondUserName = isset($resultUsernameSetArr[1]->username) ? $resultUsernameSetArr[1]->username : '' ;
$thirdUserName = isset($resultUsernameSetArr[2]->username) ? $resultUsernameSetArr[2]->username : '' ;
$fourthUserName = isset($resultUsernameSetArr[3]->username) ? $resultUsernameSetArr[3]->username : '' ;
$fifthUserName = isset($resultUsernameSetArr[4]->username) ? $resultUsernameSetArr[4]->username : '' ;
if ($firstUserName != '') {
$firstUserNameresultSet = Aretk_Crea_Admin::aretkcrea_get_user_listing_data_by_username($firstUserName);
update_option('firstUserNameresultSet',"");
update_option('firstUserNameresultSet',"$firstUserNameresultSet");
}
if ($secondUserName != '') {
$secondUserNameresultSet = Aretk_Crea_Admin::aretkcrea_get_user_listing_data_by_username($secondUserName);
update_option('secondUserNameresultSet',"");
update_option('secondUserNameresultSet',"$secondUserNameresultSet");
}
if ($thirdUserName != '') {
$thirdUserNameresultSet = Aretk_Crea_Admin::aretkcrea_get_user_listing_data_by_username($thirdUserName);
update_option('thirdUserNameresultSet',"");
update_option('thirdUserNameresultSet',"$thirdUserNameresultSet");
}
if ($fourthUserName != '') {
$fourthUserNameresultSet = Aretk_Crea_Admin::aretkcrea_get_user_listing_data_by_username($fourthUserName);
update_option('fourthUserNameresultSet',"");
update_option('fourthUserNameresultSet',"$fourthUserNameresultSet");
}
if ($fifthUserName != '') {
$fifthUserNameresultSet = Aretk_Crea_Admin::aretkcrea_get_user_listing_data_by_username($fifthUserName);
update_option('fifthUserNameresultSet',"");
update_option('fifthUserNameresultSet',"$fifthUserNameresultSet");
}
} else {
$args = array(
'posts_per_page' => -1,
'post_type' => 'aretk_listing',
'post_status' => 'publish'
);
$posts_array = (array) get_posts( $args );
$exclusiveArr = array();
foreach ($posts_array as $singlePost) {
$singlePost1 = (array) $singlePost;
$singlePost2 = (object) $singlePost1;
$exclusiveArr[] = $singlePost2;
}
$allListingFinalArr = array();
$allListingFinalArr = $exclusiveArr;
$data = json_encode($allListingFinalArr);
update_option('cron_run',"");
update_option('cron_run',"$data");
}
}
/**
* function for add class in body
*
*
*/
function aretk_body_classes ( $classes ) {
$classes[] = 'aretk';
return $classes;
}
/**
* function to remove default canonical URLs from listing details pages
*
*
*/
function aretk_remove_listingdetails_default_canonical () {
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'rsd_link'); //removes EditURI/RSD (Really Simple Discovery) link.
remove_action('wp_head', 'wlwmanifest_link'); //removes wlwmanifest (Windows Live Writer) link.
remove_action('wp_head', 'wp_generator'); //removes meta name generator.
remove_action('wp_head', 'wp_shortlink_wp_head'); //removes shortlink.
remove_action('wp_head', 'feed_links', 2 ); //removes feed links.
remove_action('wp_head', 'feed_links_extra', 3 ); //removes comments feed.
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); // Removes prev and next article links
remove_action('wp_head', 'wp_oembed_add_discovery_links');
//add_filter('the_title','aretk_custom_page_title');
}
/**
* function for reminder cron schudule every 15 minutes
* @package aretk crea
* @return send reminder mail by date and minute
*/
function content_scheduler_reminder_minute_send_email() {
global $wpdb;
$TableName = $wpdb->prefix.'crea_lead_reminder_detail';
$reminderEveryMinQuery = "SELECT * FROM `$TableName`";
$reminderEveryMinReults = $wpdb->get_results($reminderEveryMinQuery);
$site_admin_email = get_option('admin_email');
$time = time();
$current_date = date_i18n( 'Y-m-d H:i' );
update_option('content_scheduler_reminder_minute_send_email',time().$current_date);
if( $reminderEveryMinReults !='' && !empty( $reminderEveryMinReults ) ) {
foreach ( $reminderEveryMinReults as $reminderEveryMinValues ) {
$reminder_id = $reminderEveryMinValues->id;
$reminder_email = $reminderEveryMinValues->reminder_email;
$reminder_subjects = $reminderEveryMinValues->reminder_subject;
$reminder_name = $reminderEveryMinValues->reminder_name;
$reminder_content = stripslashes($reminderEveryMinValues->reminder_comment);
$reminder_time = $reminderEveryMinValues->reminder_time;
$reminder_repeat = $reminderEveryMinValues->reminder_repeat;
if( $reminder_email !='' && !empty( $reminder_email ) ) {
if( $current_date >= $reminder_time ) {
$messageStart = '';
$messageStart .= '
'.ARETKCREA_REMINDER_MAIL_HEADER.'
';
$FinalMesage = $messageStart;
$Mesaage = '';
$To = $reminder_email;
$Subject = stripslashes($reminder_subjects);
$Mesaage .= $FinalMesage.'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$site_admin_email."> \r\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'content-type: text/html; charset=utf-8' . "\r\n";
wp_mail($reminder_email, $Subject, $Mesaage, $headers);
update_option('crea_reminder_mail_sucessfully','Reminder Mail sent sucessfully('.$reminder_email.')(' .$reminder_time.')');
$future_date = NULL;
if ($reminder_repeat === 'no-repeat'){
$reminderDeleteQuery = "DELETE FROM `$TableName` WHERE `id`= $reminder_id LIMIT 1";
$delete_record = $wpdb->query( $reminderDeleteQuery );
} else if ($reminder_repeat === 'daily'){
$future_date = date('Y-m-d H:i:s', strtotime($reminder_time .' +1 day'));
} else if ($reminder_repeat === 'weekly'){
$future_date = date('Y-m-d H:i:s', strtotime($reminder_time .' +1 week'));
} else if ($reminder_repeat === 'monthly'){
$future_date = date('Y-m-d H:i:s', strtotime($reminder_time .' +1 month'));
} else if ($reminder_repeat === 'yearly'){
$future_date = date('Y-m-d H:i:s', strtotime($reminder_time .' +1 year'));
}
if ( !empty($future_date) ){
$wpdb->update(
"$TableName",
array(
'reminder_time' => "$future_date",
'updated_time' => current_time('mysql', 1)
),
array( 'id' => $reminder_id ),
array(
'%s',
'%s',
),
array( '%d' )
);
}
}
}
}
}
}
public function view_project_template( $template ) {
return $template;
}
# Check if this function is neccassary
public function my_theme_redirect() {
if (strpos($_SERVER['REQUEST_URI'], 'listing-details') !== false) {
$serverArr = explode('/',$_SERVER['REQUEST_URI']);
$id = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (!is_numeric($id)) {
if ($serverArr[1] == 'listing-details' && is_numeric($serverArr[2])) {
wp_safe_redirect(site_url('/listing-details/'.$serverArr[2]));
exit;
}
}
}
if (strpos($_SERVER['REQUEST_URI'], 'listing-detail') !== false) {
$serverArr = explode('/',$_SERVER['REQUEST_URI']);
$id = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (!is_numeric($id)) {
if ($serverArr[1] == 'listing-detail' && is_numeric($serverArr[2])) {
wp_safe_redirect(site_url('/listing-detail/'.$serverArr[2]));
exit;
}
}
}
}
/**
* Create Genaral Contact Form
*
* @return return html for the Display the Genaral Contact Form
* @package Phase 1
* @since Phase 1
* @version
* @author ARETK
* @param
*/
public function crea_genaral_contactform(){
$url = ARETK_CREA_PLUGIN_URL.'includes/captcha_code.php';
$html .='';
$html .='';
return $html;
}
/**
* Create Buyer form with shortcode
*
* @return return html for display the buyer form
* @package Phase 1
* @since Phase 1
* @version
* @author ARETK
* @param
*/
public function crea_aretk_bfform(){
$url = ARETK_CREA_PLUGIN_URL.'includes/captcha_code.php';
$html .='';
$html.= '';
return $html;
}
/**
* Create Seller form Functinality
*
* @return return html for display the Seller form
* @package Phase 1
* @since Phase 1
* @version
* @author ARETK
* @param
*/
public function crea_aretk_sfform( ) {
$url = ARETK_CREA_PLUGIN_URL.'includes/captcha_code.php';
$html =''.__(ARETKCREA_SELLER_FORM_TITLE, ARETKCREA_PLUGIN_SLUG).'
';
$html .=''.__(ARETKCREA_SELLER_FORM_TITLE_ONE, ARETKCREA_PLUGIN_SLUG).'
';
$html .='';
$html.= '';
return $html;
}
/**
* Function is responsible for shortcode [ARTEK-DLS], Default - Listings Showcase
*/
function create_artekdls_shortcode() {
global $post,$wpdb;
$allListingArr = array();
$allListingFinalArr = array();
$filter_array = array();
$showcase_settings = array();
$postmeta_arr = array();
$result_type = 'basic';
$subscriptionKey = get_option('crea_subscription_key', '');
$site_image_path = ARETK_CREA_PLUGIN_URL.'public/images/preview_img.jpg';
$showcase_settings['default_listing_image'] = $site_image_path;
$getSubscriptionListing = get_option('crea_subscription_status', '');
$showcase_settings['aretk_subscription_status'] = get_option('crea_subscription_status', '');
$showcse_crea_display_theme_option = 'Listing View';
$showcase_settings['showcase_display_type'] = $showcse_crea_display_theme_option;
$filter_array['showcase_view'] = $showcse_crea_display_theme_option;
$filter_array['include_exclusive'] = 'yes';
$page_number_id = (int)basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if ( is_numeric($page_number_id) && $page_number_id !== 0) {
$showcase_settings['current_page_number'] = $page_number_id;
} else {
$page_number_id = 1;
$showcase_settings['current_page_number'] = 1;
}
$showcase_settings['display_items_per_page'] = 20;
if ( is_numeric($showcase_settings['current_page_number']) && empty($_POST) ) {
$offset = ( $showcase_settings['current_page_number'] - 1) * $showcase_settings['display_items_per_page'] + 1;
$filter_array['current_page_number'] = (int)$showcase_settings['current_page_number'];
} else {
$offset = 0;
$filter_array['current_page_number'] = 1;
}
$filter_array['record_offset'] = $offset;
if( $getSubscriptionListing === 'valid' ){
$crea_user_name_table_name = $wpdb->prefix.ARETKCREA_USER_LISTING_DETAILS;
$getAllUsername = $wpdb->get_results("SELECT username FROM $crea_user_name_table_name");
$userName = $getAllUsername[0]->username;
$showcse_crea_feed_ddf_type = !empty( $userName ) ? $userName : '';
$filter_array['crea_feed_id'] = $showcse_crea_feed_ddf_type;
}
$showcase_order_property_listing_results = "price-desc";
$showcase_settings['listings_sortby'] = "price-desc";
$showcase_settings['listings_local_orderby'] = "desc";
$showcase_settings['listings_local_orderon'] = "meta_value_num";
$filter_array['showcse_crea_filter_price_sorting'] = $showcase_order_property_listing_results;
$filter_array['listings_sortby'] = $showcase_order_property_listing_results;
$filter_array = Aretk_Crea_Public::aretk_listing_filters($filter_array, $postmeta_arr);
$transient_id = implode('|', $filter_array);
$transient_id = 'aretk_'. md5( $transient_id );
if ($_GET['cache'] === 'false'){ delete_transient($transient_id); }
$listing_results = get_transient($transient_id);
if ($showcse_crea_display_theme_option !== 'Map' ){
if ( false === $listing_results ) {
if( isset( $getSubscriptionListing ) && !empty( $getSubscriptionListing ) && !empty($showcse_crea_feed_ddf_type) && $getSubscriptionListing === 'valid' && $showcse_crea_display_theme_option !== 'Map' ){
$listing_results = Aretk_Crea_Public::aretk_get_listings_subsc($subscriptionKey, $filter_array);
} else if ( $showcse_crea_display_theme_option !== 'Map' ){
$listing_results = Aretk_Crea_Public::aretk_get_listings_localwp($showcase_id, $filter_array);
}
set_transient( $transient_id, $listing_results, 60*60 );
}
$allListingFinalArr = $listing_results['listing_data'];
$total_listing_records = $listing_results['TotalRecords'];
$RecordsReturned = $listing_results['RecordsReturned'];
if ( !empty( $total_listing_records ) && ($showcse_crea_display_theme_option === 'Grid View' || $showcse_crea_display_theme_option === 'Listing View') ){
$showcase_settings['max_numbers_pagination'] = ceil(($total_listing_records / $showcase_settings['display_items_per_page']));
}
}
$showcase_settings['display_searchbar'] = 'yes';
$showcase_settings['display_searchbar_min'] = 'no';
switch($showcse_crea_display_theme_option){
case 'Listing View':
$showcase_settings['display_openhouse_info'] ='yes';
$showcase_settings['display_listing_status'] = 'yes';
$showcase_settings['status_color_bg'] = '#FF9898';
$showcase_settings['status_color_txt'] = '#000';
$showcase_settings['open_house_color_bg'] = '111';
$showcase_settings['open_house_color_txt'] = 'fff';
$showcase_settings['maintxt_color'] = '000';
$showcase_settings['address_color'] = $txt_color;
$showcase_settings['price_color'] = $txt_color;
$showcase_settings['pagination_color_bg'] = '000';
$showcase_settings['pagination_color_txt'] = 'fff';
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/desc-view/template.php';
break;
case 'Grid View':
$showcase_settings['display_listing_status'] = 'yes';
$showcase_settings['display_max_columns'] = 4;
$grid_view_listing_class = 'grid-view-box pr aret-col-3';
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/grid-view/template.php';
break;
case 'Map':
$map_center_lat = !empty( $settings_arr['mapfilterlatitude'] ) ? $settings_arr['mapfilterlatitude'] : '57.67807921815639';
$map_center_long = !empty( $settings_arr['mapfilterlongitude'] ) ? $settings_arr['mapfilterlongitude'] : '-101.80516868749999';
$map_zoom = !empty( $settings_arr['showcasemapimagezoom'] ) ? $settings_arr['showcasemapimagezoom'] : '11';
$map_height = !empty( $settings_arr['mapviewdisplayhight'] ) ? $settings_arr['mapviewdisplayhight'] : '600';
$display_searchbar = 'yes';
$display_searchbar_closed = 'no';
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/map-view/template.php';
break;
}
return $html;
}
/**
* Function is responsible for add shortcode for ARTEK-LDS
*/
function create_arteklds_shortcode( $atts ) {
global $wpdb;
global $property_details_arr;
if ($property_details_arr['is_exclusive'] === 'exclusive' && !empty($property_details_arr['ID'])){
$aretk_listing_view_count = get_post_meta($property_details_arr['ID'], 'crea_aretk_db_listing_page_count', true);
if (is_numeric( $aretk_listing_view_count ) && !empty( $aretk_listing_view_count ) ){
$aretk_listing_view_count = $aretk_listing_view_count+1;
} else {
$aretk_listing_view_count = 1;
}
$testvar = update_post_meta($property_details_arr['ID'],'crea_aretk_db_listing_page_count',$aretk_listing_view_count);
} else if ($property_details_arr['aretk_subscription'] === 'valid'){
Aretk_Crea_Public::update_view_count( $property_details_arr['ID'], 1 );
}
// Property Details from settings
$property_detail_options = array(
'include_contact_form' => get_option( 'crea_listing_include_contact_form' ),
'include_map' => get_option( 'crea_listing_include_map' ),
'include_walk_score' => get_option( 'crea_listing_include_walk_score' ),
'include_print_btn' => get_option( 'crea_listing_include_print_btn' ),
'send_btn_color_txt' => get_option( 'crea_listing_include_price_color' ),
'send_btn_color_bg' => get_option( 'crea_listing_include_send_btn_color' ),
'include_agents_info' => get_option( 'crea_listing_include_information' ),
'include_agent_email' => get_option( 'crea_listing_include_email_address_of_agent' ),
'google-map-api-key' => get_option( 'google-map-api-name' ),
'walk-score-api-key' => get_option( 'walk-score-api-name' ),
'disclaimer' => get_option( 'aretk_crea_disclaimer1' ),
);
# Set defaults
if ( empty($property_detail_options['include_contact_form']) ){
$property_detail_options['include_contact_form'] = 'Yes';
}
if ( empty($property_detail_options['include_map']) ){
$property_detail_options['include_map'] = 'Yes';
}
if ( empty($property_detail_options['include_walk_score']) ){
$property_detail_options['include_walk_score'] = 'Yes';
}
if ( empty($property_detail_options['include_print_btn']) ){
$property_detail_options['include_print_btn'] = 'Yes';
}
if ( empty($property_detail_options['include_agents_info']) ){
$property_detail_options['include_agents_info'] = 'Yes';
}
if ( empty($property_detail_options['include_agent_email']) ){
$property_detail_options['include_agent_email'] = 'Yes';
}
if ( empty($property_detail_options['send_btn_color_txt']) ){
$property_detail_options['send_btn_color_txt'] = 'ffffff';
}
if ( empty($property_detail_options['send_btn_color_bg']) ){
$property_detail_options['send_btn_color_bg'] = '0001C8';
}
if ( empty($property_detail_options['disclaimer']) ){
$property_detail_options['disclaimer'] = 'I am an agent licensed to trade residential and commercial real estate. The out of province listing content on this website is not intended to solicit a trade in real estate. Any consumers interested in out of province listings must contact a person who is licensed to trade in real estate in that province.';
}
require_once plugin_dir_path( __FILE__ ) . '/templates/listing-details/t_1/template.php';
}
/**
* Set Canonical Url for custom template
*
*/
public function wp_head_custom() {
global $wpdb;
global $property_details_arr;
if (strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-detail') !== false || strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-details') !== false) {
if ( empty($property_details_arr) ){
$property_details_arr = Aretk_Crea_Public::get_property_meta();
}
echo '
';
if (!empty($property_details_arr['listing_photos'][0]['URL'])){
echo "\n".''."\n";
} else {
echo ''."\n";
}
}
}
/*
* Function to setup page meta title
*/
public function assignPageTitle( $title, $sep = '|' ) {
global $wpdb;
global $property_details_arr;
$site_description = get_bloginfo( 'name', 'display' );
if ( is_feed() ) { return $title; }
if (strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-detail') !== false || strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'listing-details') !== false) {
Aretk_Crea_Public::aretk_remove_listingdetails_default_canonical();
if ( empty($property_details_arr) ){
$property_details_arr = Aretk_Crea_Public::get_property_meta();
}
if ( !empty($property_details_arr['address_full']) ){
return $property_details_arr['address_full'].' '.$sep.' '.$site_description;
}
}
return $title;
}
function add_query_vars($aVars) {
$aVars[] = "msds_pif_cat"; // represents the name of the product category as shown in the URL
$aVars[] = "id"; // represents the name of the product category as shown in the URL
return $aVars;
}
// hook add_query_vars function into query_vars
function aretkcrea_add_rewrite_rules($aRules) {
$aNewRules = array('listing-details/(.?.+?)?(:/([0-9]+))?/?$' => 'index.php?pagename=listing-details&msds_pif_cat=$matches[1]&id=$matches[2]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
/**
* Function is responsible for add shortcode for ARTEK-DSS
*/
function create_artekdss_shortcode() {
$dss_shorctcode = true;
require_once plugin_dir_path( __FILE__ ) . 'templates/listings-search/template.php';
return $html;
}
function check_terms_and_condition_accept(){
$time = time();
if( empty( $_COOKIE["aretk_crea_terms_of_use"] ) ) {
setcookie("aretk_crea_terms_of_use", 'true', time()+ (3600*60) , COOKIEPATH ,COOKIE_DOMAIN );
}
die();
}
function check_terms_and_condition_decline(){
wp_safe_redirect(site_url());
die();
}
/**
* Update view count call API
*
* @param unknown_type $postId
*/
public static function update_view_count( $postId, $listing_count ){
global $wpdb;
$getSubscriptionKey = get_option('crea_subscription_key', '');
$subscriptionKey = !empty($getSubscriptionKey) ? $getSubscriptionKey : '';
$user_ID = get_current_user_id();
$getSubscriptionStatus = get_option('crea_subscription_status', '');
$domainName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
if (empty($domainName)){
$domainName = get_site_url();
$domainName = parse_url($domainName, PHP_URL_HOST);
}
if( $postId != '') {
$update_view_count_settinges_array = array (
"property_counts" => array(
array("id" => $postId,
"count" => $listing_count
)
)
);
$post_string = http_build_query($update_view_count_settinges_array);
if (isset( $getSubscriptionStatus ) && !empty( $getSubscriptionStatus) && $getSubscriptionStatus === 'valid') {
$updateCount = curl_init();
curl_setopt($updateCount, CURLOPT_HEADER, 0);
curl_setopt($updateCount, CURLOPT_VERBOSE, 0);
curl_setopt($updateCount, CURLOPT_URL, ARETKCREA_LISTING_BASEDONSERVER_API."/?key=$subscriptionKey&request=update_view_count");
curl_setopt($updateCount, CURLOPT_POST, true);
curl_setopt($updateCount, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($updateCount, CURLOPT_RETURNTRANSFER,true);
curl_setopt($updateCount, CURLOPT_REFERER,$domainName);
$updateCountCurlExecute = curl_exec($updateCount);
curl_close($updateCount);
}
}
}
/**
* Buyer Contact form
*
*/
public function buyer_lead_submit_form_front_end() {
global $wpdb;
session_start();
$bf_name = !empty( $_POST['bf_name'] ) ? $_POST['bf_name'] : '';
$bf_email = !empty( $_POST['bf_email'] ) ? $_POST['bf_email'] : '';
$bf_phone = !empty( $_POST['bf_phone'] ) ? $_POST['bf_phone'] : '';
$bf_phone_prefer = !empty( $_POST['bf_phone_prefer'] ) ? $_POST['bf_phone_prefer'] : '';
$bf_email_prefer = !empty( $_POST['bf_email_prefer'] ) ? $_POST['bf_email_prefer'] : '';
$bf_address = !empty( $_POST['bf_address'] ) ? $_POST['bf_address'] : '';
$bf_description = !empty( $_POST['bf_description'] ) ? $_POST['bf_description'] : '';
$bf_description_community = !empty( $_POST['bf_description_community'] ) ? $_POST['bf_description_community'] : '';
$bf_price = !empty( $_POST['bf_price'] ) ? $_POST['bf_price'] : '';
$bf_bedroom = !empty( $_POST['bf_bedroom'] ) ? $_POST['bf_bedroom'] : '';
$bf_bathroom = !empty( $_POST['bf_bathroom'] ) ? $_POST['bf_bathroom'] : '';
$bf_planning_to_buy = !empty( $_POST['bf_planning_to_buy'] ) ? $_POST['bf_planning_to_buy'] : '';
$bf_realtor = !empty( $_POST['bf_realtor'] ) ? $_POST['bf_realtor'] : '';
$bf_discription = !empty( $_POST['bf_discription'] ) ? $_POST['bf_discription'] : '';
$user_bf_form_captcha = !empty( $_POST['user_bf_form_captcha'] ) ? $_POST['user_bf_form_captcha'] : '';
$requuired_error = array();
if ( empty($bf_name) ){
$requuired_error[] = 'Name field is Required';
}
if ( empty($bf_email) ){
$requuired_error[] = 'Email field is Required';
}
if ( empty($bf_bedroom) ){
$requuired_error[] = 'Bedroom field is Required';
}
if ( empty($bf_bathroom) ){
$requuired_error[] = 'Bathroom field is Required';
}
if ( empty($bf_planning_to_buy) ){
$requuired_error[] = 'Planning to buy field is Required';
}
if ( empty($bf_realtor) ){
$requuired_error[] = 'Working with a REALTOR® field is Required';
}
if ( empty($user_bf_form_captcha) ){
$requuired_error[] = 'Captcha field is Required';
}
if ( $_SESSION["captcha_code"] === $user_bf_form_captcha && empty($requuired_error) ) {
$data_submit_html = 'The following information has been submitted from the Buyers Form on your website:
';
$data_submit_html .= '';
$send_email_text = stripslashes($data_submit_html);
$send_email_text = str_replace('"', '\"', $send_email_text);
$send_email_text = json_encode($send_email_text);
$send_email_text = str_replace('\r\n', '', $send_email_text);
$send_email_text = json_decode($send_email_text);
$post_table = $wpdb->prefix.'posts';
$post_meta_table = $wpdb->prefix.'postmeta';
$getAgentidResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_primary_email'";
$getAgentidResultsarray = $wpdb->get_results($getAgentidResults);
$getAgentemailResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_phone_email'";
$getAgentemailResultsarray = $wpdb->get_results($getAgentemailResults);
$add_primary_email_array = array();
foreach ( $getAgentidResultsarray as $getAgentidResultskey=>$getAgentidResultsvalue) {
if( $getAgentidResultsvalue->meta_value != '' ){
$add_primary_email_array [$getAgentidResultsvalue->post_id]= $getAgentidResultsvalue->meta_value;
}
}
$add_non_primary_email_array = array();
foreach ( $getAgentemailResultsarray as $getAgentemailResultkey=>$getAgentemailResultsvalue) {
$implode_array = maybe_unserialize($getAgentemailResultsvalue->meta_value);
$unserialize_array = maybe_unserialize($implode_array);
$lead_phone_email ='';
if( is_array($unserialize_array)) { $lead_phone_email = $unserialize_array[0]; } else{ $lead_phone_email =$unserialize_array; }
$add_non_primary_email_array[$getAgentemailResultsvalue->post_id] = $lead_phone_email;
}
$merge_email_array_duplicate = $add_primary_email_array + $add_non_primary_email_array;
$current_date = date_i18n( 'Y-m-d H:i' );
if( !empty( $merge_email_array_duplicate) && $merge_email_array_duplicate !='' ) {
foreach ( $merge_email_array_duplicate as $merge_email_array_key=>$merge_email_array_value ) {
if( $merge_email_array_value == $bf_email) {
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Buyer Lead Mail'; # message subject
$new_corrsponding_array[] = 'buyer inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($merge_email_array_key,$new_corrsponding_key,json_encode($new_corrsponding_array));
// Update modified date/time
$update_post = array( 'ID' => $merge_email_array_key, 'post_type' => 'aretk_lead' );
wp_update_post( $update_post );
}
}
}
if( !in_array($bf_email,$merge_email_array_duplicate) ) {
$new_lead = array (
'post_title' => $bf_name,
'post_content' => 'Lead created from website Buyers form submission',
'post_status' => 'publish',
'post_type' => 'aretk_lead'
);
$import_lead_post_id = wp_insert_post($new_lead);
update_post_meta($import_lead_post_id,'lead_primary_email',$bf_email);
update_post_meta($import_lead_post_id,'lead_phone_email',maybe_serialize($bf_email));
update_post_meta($import_lead_post_id,'lead_phone_no',maybe_serialize($bf_phone));
update_post_meta($import_lead_post_id,'bf_phone_prefer',$bf_phone_prefer);
update_post_meta($import_lead_post_id,'bf_email_prefer',$bf_email_prefer);
update_post_meta($import_lead_post_id,'lead_address_line',$bf_address);
update_post_meta($import_lead_post_id,'bf_description',$bf_description);
update_post_meta($import_lead_post_id,'bf_description_community',$bf_description_community);
update_post_meta($import_lead_post_id,'bf_price',$bf_price);
update_post_meta($import_lead_post_id,'bf_bedroom',$bf_bedroom);
update_post_meta($import_lead_post_id,'bf_bathroom',$bf_bathroom);
update_post_meta($import_lead_post_id,'bf_planning_to_buy',$bf_planning_to_buy);
update_post_meta($import_lead_post_id,'bf_realtor',$bf_realtor);
update_post_meta($import_lead_post_id,'lead_form_type','buyer');
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Buyer Lead Mail'; # message subject
$new_corrsponding_array[] = 'buyer inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($import_lead_post_id,$new_corrsponding_key,json_encode($new_corrsponding_array));
}
$admin_email_address = get_option('admin_email');
$to = $admin_email_address;
$subject = "Buyer Lead Mail";
$txt = '
'.ARETKCREA_BUYER_FORM_MAIL_HEADER.'
'.str_replace('\"', '"', $send_email_text).'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$bf_email."> \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
wp_mail($to,$subject,$txt,$headers);
echo ''.__(ARETKCREA_BUYER_FORM_SUCESS).'
';
} else {
echo "false";
}
die();
}
/**
* Seller Contact Form
*
*/
public function seller_lead_submit_form_front_end() {
global $wpdb;
session_start();
$sfform_name = !empty( $_POST['sfform_name'] ) ? $_POST['sfform_name'] : '';
$sfform_email = !empty( $_POST['sfform_email'] ) ? $_POST['sfform_email'] : '';
$sfform_phone = !empty( $_POST['sfform_phone'] ) ? $_POST['sfform_phone'] : '';
$sf_preferred_phone = !empty( $_POST['sf_preferred_phone'] ) ? $_POST['sf_preferred_phone'] : '';
$sf_preferred_email = !empty( $_POST['sf_preferred_email'] ) ? $_POST['sf_preferred_email'] : '';
$sfform_address = !empty( $_POST['sfform_address'] ) ? $_POST['sfform_address'] : '';
$sfform_description = !empty( $_POST['sfform_description'] ) ? $_POST['sfform_description'] : '';
$sfform_square_feet = !empty( $_POST['sfform_square_feet'] ) ? $_POST['sfform_square_feet'] : '';
$sfform_bedroom = !empty( $_POST['sfform_bedroom'] ) ? $_POST['sfform_bedroom'] : '';
$sfform_bathroom = !empty( $_POST['sfform_bathroom'] ) ? $_POST['sfform_bathroom'] : '';
$sfform_planning_to_buy = !empty( $_POST['sfform_planning_to_buy'] ) ? $_POST['sfform_planning_to_buy'] : '';
$sf_realtor = !empty( $_POST['sf_realtor'] ) ? $_POST['sf_realtor'] : '';
$discription = !empty( $_POST['discription'] ) ? $_POST['discription'] : '';
$user_seller_captcha = !empty( $_POST['user_seller_captcha'] ) ? $_POST['user_seller_captcha'] : '';
$requuired_error = array();
if ( empty($sfform_name) ){
$requuired_error[] = 'Name field is Required';
}
if ( empty($sfform_email) ){
$requuired_error[] = 'Email field is Required';
}
if ( empty($sf_preferred_phone) && empty($sf_preferred_email)){
$requuired_error[] = 'Method of contact field is Required';
}
if ( empty($sfform_planning_to_buy) ){
$requuired_error[] = 'This field is required';
}
if ( empty($sf_realtor) ){
$requuired_error[] = 'Working with a REALTOR® field is Required';
}
if ( empty($user_seller_captcha) ){
$requuired_error[] = 'Captcha field is Required';
}
if( $_SESSION["captcha_code"] === $user_seller_captcha && empty($requuired_error) ) {
$data_submit_html = 'The following information has been submitted from the Sellers Form on your website:
';
$data_submit_html .= '';
$send_email_text = stripslashes($data_submit_html);
$send_email_text = str_replace('"', '\"', $send_email_text);
$send_email_text = json_encode($send_email_text);
$send_email_text = str_replace('\r\n', '', $send_email_text);
$send_email_text = json_decode($send_email_text);
$post_table = $wpdb->prefix.'posts';
$post_meta_table = $wpdb->prefix.'postmeta';
$getAgentidResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_primary_email'";
$getAgentidResultsarray = $wpdb->get_results($getAgentidResults);
$getAgentemailResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_phone_email'";
$getAgentemailResultsarray = $wpdb->get_results($getAgentemailResults);
$add_primary_email_array = array();
foreach ( $getAgentidResultsarray as $getAgentidResultskey=>$getAgentidResultsvalue) {
if( $getAgentidResultsvalue->meta_value != '' ){
$add_primary_email_array [$getAgentidResultsvalue->post_id]= $getAgentidResultsvalue->meta_value;
}
}
$add_non_primary_email_array = array();
foreach ( $getAgentemailResultsarray as $getAgentemailResultkey=>$getAgentemailResultsvalue) {
$implode_array = maybe_unserialize($getAgentemailResultsvalue->meta_value);
$unserialize_array = maybe_unserialize($implode_array);
$lead_phone_email ='';
if( is_array($unserialize_array)) { $lead_phone_email = $unserialize_array[0]; } else{ $lead_phone_email =$unserialize_array; }
$add_non_primary_email_array[$getAgentemailResultsvalue->post_id] = $lead_phone_email;
}
$merge_email_array_duplicate = $add_primary_email_array + $add_non_primary_email_array;
$current_date = date_i18n( 'Y-m-d H:i' );
if( !empty( $merge_email_array_duplicate) && $merge_email_array_duplicate !='' ) {
foreach ( $merge_email_array_duplicate as $merge_email_array_key=>$merge_email_array_value ) {
if( $merge_email_array_value == $sfform_email) {
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Seller Lead Mail'; # message subject
$new_corrsponding_array[] = 'seller inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($merge_email_array_key,$new_corrsponding_key,json_encode($new_corrsponding_array));
// Update modified date/time
$update_post = array( 'ID' => $merge_email_array_key, 'post_type' => 'aretk_lead' );
wp_update_post( $update_post );
}
}
}
if( !in_array($sfform_email,$merge_email_array_duplicate)) {
$new_lead = array (
'post_title' => $sfform_name,
'post_content' => 'Lead created from website Sellers form submission',
'post_status' => 'publish',
'post_type' => 'aretk_lead'
);
$import_lead_post_id = wp_insert_post($new_lead);
update_post_meta($import_lead_post_id,'lead_primary_email',$sfform_email);
update_post_meta($import_lead_post_id,'lead_phone_email',maybe_serialize($sfform_email));
update_post_meta($import_lead_post_id,'lead_phone_no',maybe_serialize($sfform_phone));
update_post_meta($import_lead_post_id,'sf_preferred_phone',$sf_preferred_phone);
update_post_meta($import_lead_post_id,'sf_preferred_email',$sf_preferred_email);
update_post_meta($import_lead_post_id,'lead_address_line',$sfform_address);
update_post_meta($import_lead_post_id,'sfform_description',$sfform_description);
update_post_meta($import_lead_post_id,'sfform_square_feet',$sfform_square_feet);
update_post_meta($import_lead_post_id,'sfform_bedroom',$sfform_bedroom);
update_post_meta($import_lead_post_id,'sfform_bathroom',$sfform_bathroom);
update_post_meta($import_lead_post_id,'sfform_planning_to_buy',$sfform_planning_to_buy);
update_post_meta($import_lead_post_id,'sf_realtor',$sf_realtor);
update_post_meta($import_lead_post_id,'lead_form_type','seller');
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Seller Lead Mail'; # message subject
$new_corrsponding_array[] = 'seller inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($import_lead_post_id,$new_corrsponding_key,json_encode($new_corrsponding_array));
}
$admin_email_address = get_option('admin_email');
$to = $admin_email_address;
$subject = "Seller Lead Mail";
$txt = '
'.ARETKCREA_SELLER_FORM_MAIL_HEADER.'
'.str_replace('\"', '"', $send_email_text).'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$sfform_email."> \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
wp_mail($to,$subject,$txt,$headers);
echo ''.__(CREA_BUYER_FORM_SUCESS).'
';
} else {
echo "false";
}
die();
}
/**
* General Contact Form
*
*/
public function conatact_submit_form_front_end() {
global $wpdb;
session_start();
$user_name = !empty( $_POST['user_name'] ) ? $_POST['user_name'] : '';
$user_email = !empty( $_POST['user_email'] ) ? $_POST['user_email'] : '';
$user_phone = !empty( $_POST['user_phone'] ) ? $_POST['user_phone'] : '';
$discription = !empty( $_POST['discription'] ) ? $_POST['discription'] : '';
$user_captcha = !empty( $_POST['user_captcha'] ) ? $_POST['user_captcha'] : '';
$requuired_error = array();
if ( empty($user_name) ){
$requuired_error[] = 'Name field is Required';
}
if ( empty($user_email) ){
$requuired_error[] = 'Email field is Required';
}
if ( empty($user_phone) ){
$requuired_error[] = 'Phone field is Required';
}
if ( empty($discription) ){
$requuired_error[] = 'Message field is Required';
}
if( $_SESSION["captcha_code"] === $user_captcha && empty($requuired_error) ) {
$data_submit_html = 'The following information has been submitted from the Contact Form on your website:
';
$data_submit_html .= '';
$send_email_text = stripslashes($data_submit_html);
$send_email_text = str_replace('"', '\"', $send_email_text);
$send_email_text = json_encode($send_email_text);
$send_email_text = str_replace('\r\n', '', $send_email_text);
$send_email_text = json_decode($send_email_text);
$post_table = $wpdb->prefix.'posts';
$post_meta_table = $wpdb->prefix.'postmeta';
$getAgentidResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_primary_email'";
$getAgentidResultsarray = $wpdb->get_results($getAgentidResults);
$getAgentemailResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_phone_email'";
$getAgentemailResultsarray = $wpdb->get_results($getAgentemailResults);
$add_primary_email_array = array();
foreach ( $getAgentidResultsarray as $getAgentidResultskey=>$getAgentidResultsvalue) {
if( $getAgentidResultsvalue->meta_value != '' ){
$add_primary_email_array [$getAgentidResultsvalue->post_id]= $getAgentidResultsvalue->meta_value;
}
}
$add_non_primary_email_array = array();
foreach ( $getAgentemailResultsarray as $getAgentemailResultkey=>$getAgentemailResultsvalue) {
$implode_array = maybe_unserialize($getAgentemailResultsvalue->meta_value);
$unserialize_array = maybe_unserialize($implode_array);
$lead_phone_email ='';
if( is_array($unserialize_array)) { $lead_phone_email = $unserialize_array[0]; } else{ $lead_phone_email =$unserialize_array; }
$add_non_primary_email_array[$getAgentemailResultsvalue->post_id] = $lead_phone_email;
}
$merge_email_array_duplicate = $add_primary_email_array + $add_non_primary_email_array;
$current_date = date_i18n( 'Y-m-d H:i' );
if( !empty( $merge_email_array_duplicate) && $merge_email_array_duplicate !='' ) {
foreach ( $merge_email_array_duplicate as $merge_email_array_key=>$merge_email_array_value ) {
if( $merge_email_array_value == $user_email) {
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Contact Lead Mail'; # message subject
$new_corrsponding_array[] = 'general inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($merge_email_array_key,$new_corrsponding_key,json_encode($new_corrsponding_array));
// Update modified date/time
$update_post = array( 'ID' => $merge_email_array_key, 'post_type' => 'aretk_lead' );
wp_update_post( $update_post );
}
}
}
if( !in_array($user_email,$merge_email_array_duplicate)) {
$new_lead = array (
'post_title' => $user_name,
'post_content' => 'Lead created from website Contact form submission',
'post_status' => 'publish',
'post_type' => 'aretk_lead'
);
$import_lead_post_id = wp_insert_post($new_lead);
update_post_meta($import_lead_post_id,'lead_primary_email',$user_email);
update_post_meta($import_lead_post_id,'lead_phone_email',maybe_serialize($user_email));
update_post_meta($import_lead_post_id,'lead_phone_no',maybe_serialize($user_phone));
update_post_meta($import_lead_post_id,'user_subject',$user_subject);
update_post_meta($import_lead_post_id,'lead_form_type','general');
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Contact Lead Mail'; # message subject
$new_corrsponding_array[] = 'general inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($import_lead_post_id,$new_corrsponding_key,json_encode($new_corrsponding_array));
}
$admin_email_address = get_option('admin_email');
$to = $admin_email_address;
$subject = "Contact Lead Mail";
$txt = '
'.ARETKCREA_CONTACT_FORM_MAIL_HEADER.'
'.str_replace('\"', '"', $send_email_text).'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$user_email."> \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
wp_mail($to,$subject,$txt,$headers);
echo ''.__(CREA_BUYER_FORM_SUCESS).'
';
} else {
echo "false";
}
die();
}
/**
* Contact Form on Listing Details
*
*/
public function property_listing_contact_form () {
global $wpdb;
session_start();
$agent_table = $wpdb->prefix.ARETKCREA_AGENT_TABLE;
$get_contact_first_agent_id = isset( $_POST['get_contact_first_agent_id'] ) ? $_POST['get_contact_first_agent_id'] :'';
$get_contact_name = isset( $_POST['get_contact_name'] ) ? $_POST['get_contact_name'] :'';
$get_contact_email = isset( $_POST['get_contact_email'] ) ? $_POST['get_contact_email'] :'';
$get_contact_phone = isset( $_POST['get_contact_phone'] ) ? $_POST['get_contact_phone'] :'';
$get_contact_message = !empty( $_POST['get_contact_message'] ) ? $_POST['get_contact_message'] :'';
$get_contact_page_url = isset( $_POST['get_contact_page_url'] ) ? $_POST['get_contact_page_url'] :''; # Listing ID
$get_captcha_varification_code = isset( $_POST['captcha_varification_code'] ) ? $_POST['captcha_varification_code'] :'';
$get_listing_api_url = isset( $_POST['listing_api_url'] ) ? $_POST['listing_api_url'] :''; # Page URL
$contact_us_agent_email = !empty( $_POST['contact_us_agent_email'] ) ? $_POST['contact_us_agent_email'] :'';
if( !empty( $contact_us_agent_email )){
$contact_us_agent_email_resulst = explode(",",$contact_us_agent_email) ;
}
$requuired_error = array();
if ( empty($get_contact_name) ){
$requuired_error[] = 'Name field is Required';
}
if ( empty($get_contact_email) ){
$requuired_error[] = 'Email field is Required';
}
if ( empty($get_contact_phone) ){
$requuired_error[] = 'Phone field is Required';
}
if ( empty($get_contact_message) ){
$requuired_error[] = 'Message field is Required';
}
if( $_SESSION["captcha_code"] === $get_captcha_varification_code && empty($requuired_error) ) {
$data_submit_html = 'The following information has been submitted from a Listing Inquiry Form on your website:
';
$data_submit_html .= '';
$send_email_text = stripslashes($data_submit_html);
$send_email_text = str_replace('"', '\"', $send_email_text);
$send_email_text = json_encode($send_email_text);
$send_email_text = str_replace('\r\n', '', $send_email_text);
$send_email_text = json_decode($send_email_text);
$get_select_agents_mail_record = array();
foreach ( $contact_us_agent_email_resulst as $contact_us_agent_email_name ){
$contact_us_agent_email_name = $contact_us_agent_email_name;
$get_select_agents_mail_results = $wpdb->get_results("SELECT `crea_agent_email` FROM $agent_table WHERE `crea_agent_id` = $contact_us_agent_email_name");
foreach ( $get_select_agents_mail_results as $get_select_agents_mail_result ){
$get_select_agents_mail_record[] = $get_select_agents_mail_results[0]->crea_agent_email;
}
}
$get_select_agents_email_to_cc = '';
$get_select_agents_email_name_to_bd = implode("," ,$get_select_agents_mail_record);
if( !empty( $get_select_agents_email_name_to_bd )){
$get_select_agents_email_to_cc = $get_select_agents_email_name_to_bd;
}
$crea_listingAgentId = get_post_meta($get_contact_page_url, 'listingAgentId', true);
$agents_id = maybe_serialize($crea_listingAgentId);
$agents_name = json_decode($agents_id, true);
$agent_email_address_arr = array();
if( isset($agents_name) && !empty($agents_name) ) {
foreach ( $agents_name as $agents_name_key=>$agents_name_value ) {
$listing_agent_ids = $agents_name_value;
if( isset($listing_agent_ids) && !empty($listing_agent_ids) ) {
$get_agent_ids = $wpdb->get_results("SELECT `crea_agent_id`,`crea_agent_name`,`crea_agent_email` FROM $agent_table WHERE `crea_agent_id` = $listing_agent_ids");
foreach ( $get_agent_ids as $listing_get_agents_name ) {
$agent_email_address_arr[] = $listing_get_agents_name->crea_agent_email;
}
}
}
}
$post_table = $wpdb->prefix.'posts';
$post_meta_table = $wpdb->prefix.'postmeta';
$getAgentidResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_primary_email'";
$getAgentidResultsarray = $wpdb->get_results($getAgentidResults);
$getAgentemailResults = "SELECT * FROM $post_meta_table WHERE `meta_key`='lead_phone_email'";
$getAgentemailResultsarray = $wpdb->get_results($getAgentemailResults);
$add_primary_email_array = array();
foreach ( $getAgentidResultsarray as $getAgentidResultskey=>$getAgentidResultsvalue) {
if( $getAgentidResultsvalue->meta_value != '' ){
$add_primary_email_array [$getAgentidResultsvalue->post_id]= $getAgentidResultsvalue->meta_value;
}
}
$add_non_primary_email_array = array();
foreach ( $getAgentemailResultsarray as $getAgentemailResultkey=>$getAgentemailResultsvalue) {
$implode_array = maybe_unserialize($getAgentemailResultsvalue->meta_value);
$unserialize_array = maybe_unserialize($implode_array);
$lead_phone_email ='';
if( is_array($unserialize_array)) { $lead_phone_email = $unserialize_array[0]; } else{ $lead_phone_email =$unserialize_array; }
$add_non_primary_email_array[$getAgentemailResultsvalue->post_id] = $lead_phone_email;
}
$merge_email_array_duplicate = $add_primary_email_array + $add_non_primary_email_array;
$current_date = date_i18n( 'Y-m-d H:i' );
if( !empty( $merge_email_array_duplicate) && $merge_email_array_duplicate !='' ) {
foreach ( $merge_email_array_duplicate as $merge_email_array_key=>$merge_email_array_value ) {
if( $merge_email_array_value == $get_contact_email) {
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = $get_contact_page_url;
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Listing Lead Mail'; # message subject
$new_corrsponding_array[] = 'listing inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($merge_email_array_key,$new_corrsponding_key,json_encode($new_corrsponding_array));
}
}
}
if( !in_array($get_contact_email,$merge_email_array_duplicate)) {
$new_lead = array (
'post_title' => $get_contact_name,
'post_content' => 'Lead created from Listing Inquiry form submission',
'post_status' => 'publish',
'post_type' => 'aretk_lead'
);
$import_lead_post_id = wp_insert_post($new_lead);
$current_date = date_i18n( 'Y-m-d H:i' );
update_post_meta($import_lead_post_id,'lead_primary_email',$get_contact_email);
update_post_meta($import_lead_post_id,'lead_contact_date',$current_date);
update_post_meta($import_lead_post_id,'lead_detail_page_link',$get_listing_api_url);
update_post_meta($import_lead_post_id,'lead_phone_email',maybe_serialize($get_contact_email));
update_post_meta($import_lead_post_id,'lead_phone_no',maybe_serialize($get_contact_phone));
$new_corrsponding_key = 'crea_lead_corrsponding_text'.rand(100,999);
$new_corrsponding_array = array();
$new_corrsponding_array[] = '';
$new_corrsponding_array[] = $send_email_text;
$new_corrsponding_array[] = $current_date;
$new_corrsponding_array[] = 'Listing Lead Mail'; # message subject
$new_corrsponding_array[] = 'listing inquiry'; # message type: emailed, buyer inquiry, seller inquiry, general inquiry
update_post_meta($import_lead_post_id,$new_corrsponding_key,json_encode($new_corrsponding_array));
}
$admin_email_address = get_option('admin_email');
if( isset($agent_email_address_arr) && !empty($agent_email_address_arr)) {
foreach ($agent_email_address_arr as $agent_email_address_arr ) {
$to = $agent_email_address_arr;
$subject = "Listing Inquiry";
$txt = '
'.ARETKCREA_CONTACT_FORM_MAIL_HEADER.'
'.str_replace('\"', '"', $send_email_text).'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$get_contact_email."> \r\n";
$headers .= "cc:".$get_select_agents_email_to_cc."\r\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'content-type: text/html; charset=utf-8' . "\r\n";
wp_mail($to,$subject,$txt,$headers);
}
} else{
$to = $admin_email_address;
$subject = "Mail From Property detail";
$txt = '
'.ARETKCREA_CONTACT_FORM_MAIL_HEADER.'
'.str_replace('\"', '"', $send_email_text).'
';
$headers = "From: ".get_bloginfo( 'name' )." <".$get_contact_email."> \r\n";
$headers .= "cc:".$get_select_agents_email_to_cc."\r\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'content-type: text/html; charset=utf-8' . "\r\n";
wp_mail($to,$subject,$txt,$headers);
}
echo"sucessfullyadded";
} else {
echo "false";
}
die();
}
/**
* Aretk Listing showcase
*
*/
public function aretk_showcase_listing( $atts ) {
global $post,$wpdb;
$allListingArr = array();
$allListingFinalArr = array();
$filter_array = array();
$showcase_settings = array();
$result_type = 'basic';
$showcase_id = $atts['ls_id'];
$subscriptionKey = get_option('crea_subscription_key', '');
if ( is_numeric($showcase_id) ) {
$showcase_settings['showcase_id'] = $atts['ls_id'];
$site_image_path = ARETK_CREA_PLUGIN_URL.'public/images/preview_img.jpg';
$showcase_settings['default_listing_image'] = ARETK_CREA_PLUGIN_URL.'public/images/preview_img.jpg';
$getSubscriptionListing = get_option('crea_subscription_status', '');
$showcase_settings['aretk_subscription_status'] = get_option('crea_subscription_status', '');
$page_number_id = (int)basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if ( is_numeric($page_number_id) && $page_number_id !== 0) {
$showcase_settings['current_page_number'] = $page_number_id;
} else {
$page_number_id = 1;
$showcase_settings['current_page_number'] = 1;
}
$postmeta_arr = get_post_meta($showcase_id,'',false);
$showcse_crea_feed_ddf_type = !empty( $postmeta_arr['showcse_crea_feed_ddf_type'][0] ) ? $postmeta_arr['showcse_crea_feed_ddf_type'][0] : '';
if ($showcase_settings['aretk_subscription_status'] === 'not-valid'){
$filter_array['crea_feed_id'] = 'Exclusive Listing';
} else {
$filter_array['crea_feed_id'] = $showcse_crea_feed_ddf_type;
}
$showcse_crea_feed_include_exclude = !empty( $postmeta_arr['showcse_crea_feed_include_exclude'][0] ) ? $postmeta_arr['showcse_crea_feed_include_exclude'][0] : '';
$filter_array['include_exclusive'] = $showcse_crea_feed_include_exclude;
$showcse_crea_display_theme_option = !empty( $postmeta_arr['showcse_crea_display_theams_option'][0] ) ? $postmeta_arr['showcse_crea_display_theams_option'][0] : '';
$showcase_settings['showcase_display_type'] = $showcse_crea_display_theme_option;
$filter_array['showcase_view'] = $showcse_crea_display_theme_option;
switch( $showcse_crea_display_theme_option ){
case 'Listing View':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/desc-view/settings_get.php';
break;
case 'Grid View':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/grid-view/settings_get.php';
break;
case 'Carousel':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/carousel-view/settings_get.php';
break;
case 'Map':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/map-view/settings_get.php';
break;
case 'Slider':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/slider-view/settings_get.php';
break;
}
// If search form posted then the offset should be 0 regardless of what page the user was on when they submitted the form.
if ( is_numeric($showcase_settings['current_page_number']) && empty($_POST) ) {
$offset = ( $showcase_settings['current_page_number'] - 1) * $showcase_settings['display_items_per_page'] + 1;
$filter_array['current_page_number'] = (int)$showcase_settings['current_page_number'];
} else {
$offset = 0;
$filter_array['current_page_number'] = 1;
}
$filter_array['record_offset'] = $offset;
$filter_array['record_limit'] = $showcase_settings['display_items_per_page'];
$filter_array = Aretk_Crea_Public::aretk_listing_filters($filter_array, $postmeta_arr);
$transient_id = implode('|', $filter_array);
$transient_id = 'aretk_'. md5( $transient_id );
if ($_GET['cache'] === 'false'){ delete_transient($transient_id); }
$listing_results = get_transient($transient_id);
if ($showcse_crea_display_theme_option !== 'Map' ){
if ( false === $listing_results ) {
if( isset( $getSubscriptionListing ) && !empty( $getSubscriptionListing ) && !empty($showcse_crea_feed_ddf_type) && $getSubscriptionListing === 'valid' && $showcse_crea_display_theme_option !== 'Map' ){
$listing_results = Aretk_Crea_Public::aretk_get_listings_subsc($subscriptionKey, $filter_array);
} else if ( $showcse_crea_display_theme_option !== 'Map' ){
$listing_results = Aretk_Crea_Public::aretk_get_listings_localwp($showcase_id, $filter_array);
}
set_transient( $transient_id, $listing_results, 60*60 );
}
$allListingFinalArr = $listing_results['listing_data'];
$total_listing_records = $listing_results['TotalRecords'];
$RecordsReturned = $listing_results['RecordsReturned'];
if ( !empty( $total_listing_records ) && ($showcse_crea_display_theme_option === 'Grid View' || $showcse_crea_display_theme_option === 'Listing View') ){
$showcase_settings['max_numbers_pagination'] = ceil(($total_listing_records / $showcase_settings['display_items_per_page']));
}
}
switch($showcse_crea_display_theme_option){
case 'Listing View':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/desc-view/template.php';
break;
case 'Grid View':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/grid-view/template.php';
break;
case 'Carousel':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/carousel-view/template.php';
break;
case 'Map':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/map-view/template.php';
break;
case 'Slider':
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/slider-view/template.php';
break;
}
} else {
$html = 'Showcase id has not been specified';
}
return $html;
}
/**
* This function will return array with selected listing data
*
* @param SubscriptionKey, $filter_array
* @return array
*/
public static function aretk_get_listings_subsc( $subscriptionKey=NULL, $filter_array=NULL ){
if ( empty($subscriptionKey) ){ return false; }
$allListingArr = array();
$filter_qry_str = Aretk_Crea_Public::aretk_listings_filter_qry_str($filter_array);
$ccurl = "https://api.aretk.com/?key=$subscriptionKey&request=listings$filter_qry_str";
$listings = Aretk_Crea_Public::aretk_get_curl_results($ccurl);
if (is_null($listings)){
$listings = '[{"TotalRecords":0,"RecordsReturned":0}]';
}
$listings = json_decode($listings);
$listing_results = array(
'TotalRecords' => $listings[0]->TotalRecords,
'RecordsReturned' => $listings[0]->RecordsReturned
);
foreach ( $listings as $listing_key => $listing ){
if ( !isset( $listing->TotalRecords ) && empty( $listing->TotalRecords ) ) {
$allListingArr[$listing->ID] = $listing;
}
}
$listing_results['listing_data'] = $allListingArr;
return $listing_results;
}
/**
* This function will return array with selected listing data
*
* @param SubscriptionKey, $filter_array
* @return array
*/
public static function aretk_get_listings_subsc_json( $subscriptionKey=NULL, $filter_array=NULL ){
if ( empty($subscriptionKey) ){ return false; }
$allListingArr = array();
$filter_qry_str = Aretk_Crea_Public::aretk_listings_filter_qry_str($filter_array);
$ccurl = "https://api.aretk.com/?key=$subscriptionKey&request=listings$filter_qry_str";
$listings = Aretk_Crea_Public::aretk_get_curl_results($ccurl);
if (is_null($listings)){
$listings = '[{"TotalRecords":0,"RecordsReturned":0}]';
}
return $listings;
}
public static function aretk_listing_filters($filter_array = NULL, $postmeta_arr = NULL){
if ( !isset($filter_array) || !is_array($filter_array) ){
$filter_array = array();
}
// filter - brokerage
$showcse_crea_filter_brokerage = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_brokerage'][0] ) ){
$showcse_crea_filter_brokerage = $postmeta_arr['showcse_crea_filter_brokerage'][0];
$filter_array['showcse_crea_filter_board_id'] = $showcse_crea_filter_brokerage;
}
// filter - office
$showcse_crea_filter_office = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_office'][0] ) ){
$showcse_crea_filter_office = $postmeta_arr['showcse_crea_filter_office'][0];
$filter_array['showcse_crea_filter_office_id'] = $showcse_crea_filter_office;
}
// filter - agent
$showcse_crea_filter_agent_name = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_agent_name'][0] ) ){
$showcse_crea_filter_agent_name = $postmeta_arr['showcse_crea_filter_agent_name'][0];
$filter_array['showcse_crea_filter_agent_id'] = $showcse_crea_filter_agent_name;
}
// filter - listing
$showcse_crea_filter_listing = !empty( $postmeta_arr['showcse_crea_filter_listing'][0] ) ? $postmeta_arr['showcse_crea_filter_listing'][0] : '';
// filter - map radius
$showcse_crea_filter_by_map_km = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_by_map_km'][0] ) ){
$showcse_crea_filter_by_map_km = $postmeta_arr['showcse_crea_filter_by_map_km'][0];
$filter_array['showcse_crea_filter_by_map_km'] = $showcse_crea_filter_by_map_km;
// filter - latitude
$showcse_crea_filter_google_map_latitude = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_google_map_latitude'][0] ) ){
$showcse_crea_filter_google_map_latitude = $postmeta_arr['showcse_crea_filter_google_map_latitude'][0];
$filter_array['showcse_crea_filter_google_map_latitude'] = $showcse_crea_filter_google_map_latitude;
}
// filter - longitude
$showcse_crea_filter_google_map_longitude = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_google_map_longitude'][0] ) ){
$showcse_crea_filter_google_map_longitude = $postmeta_arr['showcse_crea_filter_google_map_longitude'][0];
$filter_array['showcse_crea_filter_google_map_longitude'] = $showcse_crea_filter_google_map_longitude;
}
}
// filter - other day
$showcse_crea_filter_by_other_day = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_by_other_day'][0] ) ){
$showcse_crea_filter_by_other_day = $postmeta_arr['showcse_crea_filter_by_other_day'][0];
$filter_array['showcse_crea_filter_by_other_day'] = $showcse_crea_filter_by_other_day;
}
// filter - open house => This setting if true will set the results to only return listings with future open houses
$showcse_crea_filter_inclue_open_house = '';
if ( !empty( $postmeta_arr['showcse_crea_filter_inclue_open_house'][0] ) ){
$showcse_crea_filter_inclue_open_house = $postmeta_arr['showcse_crea_filter_inclue_open_house'][0];
$filter_array['showcse_crea_filter_inclue_open_house'] = $showcse_crea_filter_inclue_open_house;
}
// filter - Price Min
if (!empty($_POST['min_amount'])){
$filter_array['min_amount'] = $_POST['min_amount'];
} else if (!empty($_GET['min_amount'])){
$filter_array['min_amount'] = $_GET['min_amount'];
} else if (!empty( $postmeta_arr['showcse_filter_price_min'][0] )){
// Slider, carousel
$filter_array['min_amount'] = $postmeta_arr['showcse_filter_price_min'][0];
}
// filter - Price Max
if (!empty($_POST['max_amount'])){
$filter_array['max_amount'] = $_POST['max_amount'];
} else if (!empty($_GET['max_amount'])){
$filter_array['max_amount'] = $_GET['max_amount'];
} else if (!empty( $postmeta_arr['showcse_filter_price_max'][0] )){
// Slider, carousel
$filter_array['max_amount'] = $postmeta_arr['showcse_filter_price_max'][0];
}
# If URL query parameters set then over-ride the filters set in the showcase settings
if (!empty($_POST['mapbound_lat_sw'])){
$filter_array['mapbound_lat_sw'] = $_POST['mapbound_lat_sw'];
} else if (!empty($_GET['mapbound_lat_sw'])){
$filter_array['mapbound_lat_sw'] = $_GET['mapbound_lat_sw'];
}
if (!empty($_POST['mapbound_lng_sw'])){
$filter_array['mapbound_lng_sw'] = $_POST['mapbound_lng_sw'];
} else if (!empty($_GET['mapbound_lng_sw'])){
$filter_array['mapbound_lng_sw'] = $_GET['mapbound_lng_sw'];
}
if (!empty($_POST['mapbound_lat_ne'])){
$filter_array['mapbound_lat_ne'] = $_POST['mapbound_lat_ne'];
} else if (!empty($_GET['mapbound_lat_ne'])){
$filter_array['mapbound_lat_ne'] = $_GET['mapbound_lat_ne'];
}
if (!empty($_POST['mapbound_lng_ne'])){
$filter_array['mapbound_lng_ne'] = $_POST['mapbound_lng_ne'];
} else if (!empty($_GET['mapbound_lng_ne'])){
$filter_array['mapbound_lng_ne'] = $_GET['mapbound_lng_ne'];
}
if (!empty($_POST['keyword'])){
$filter_array['keyword'] = $_POST['keyword'];
} else if (!empty($_GET['keyword'])){
$filter_array['keyword'] = $_GET['keyword'];
}
if (isset($_POST['property_types'])){
$filter_array['property_types'] = $_POST['property_types'];
} else if (isset($_GET['property_types'])){
$filter_array['property_types'] = $_GET['property_types'];
} else if ( !empty( $postmeta_arr['showcase_filter_property_types'][0] ) ){
$showcase_filter_property_types = implode(',', $postmeta_arr['showcase_filter_property_types']);
$filter_array['property_types'] = $showcase_filter_property_types;
}
if (isset($_POST['property_status'])){
$filter_array['transaction_type'] = $_POST['property_status'];
} else if (isset($_GET['property_status'])){
$filter_array['transaction_type'] = $_GET['property_status'];
} else if ( !empty( $postmeta_arr['showcase_filter_property_status'][0] ) ){
$showcase_filter_property_status = implode(',', $postmeta_arr['showcase_filter_property_status']);
$filter_array['transaction_type'] = $showcase_filter_property_status;
}
if (isset($_POST['agent_ids'])){
$filter_array['agent_ids'] = $_POST['agent_ids'];
} else if (isset($_GET['agent_ids'])){
$filter_array['agent_ids'] = $_GET['agent_ids'];
} else if ( !empty( $postmeta_arr['showcase_filter_listing_agent_ids'][0] ) ){
$showcase_filter_listing_agent_ids = implode(',', $postmeta_arr['showcase_filter_listing_agent_ids']);
$filter_array['agent_ids'] = $showcase_filter_listing_agent_ids;
}
if (!empty($_POST['structure_types'])){
$filter_array['structure_types'] = $_POST['structure_types'];
} else if (!empty($_GET['structure_types'])){
$filter_array['structure_types'] = $_GET['structure_types'];
}
if (!empty($_POST['bedrooms'])){
$filter_array['bedrooms'] = $_POST['bedrooms'];
} else if (!empty($_GET['bedrooms'])){
$filter_array['bedrooms'] = $_GET['bedrooms'];
}
if (!empty($_POST['bathrooms'])){
$filter_array['bathrooms'] = $_POST['bathrooms'];
} else if (!empty($_GET['bathrooms'])){
$filter_array['bathrooms'] = $_GET['bathrooms'];
}
return $filter_array;
}
function aretk_get_listings_localwp( $showcase_id, $filter_array = NULL ){
global $wpdb;
$searchArray = array();
$searh_posts_where = array();
$search_filter_vals = array();
$propertyDataArr = array();
$SQL_where = NULL;
$SQL_joins = NULL;
$price_join_set = false;
$Table_posts = $wpdb->prefix.'posts';
$Table_postmeta = $wpdb->prefix.'postmeta';
$property_array = array();
switch($filter_array['listings_sortby']){
case 'price-desc':
$sort_order_dir = "desc";
$sort_orderby = "meta_value_num";
break;
case 'price-asc':
$sort_order_dir = "asc";
$sort_orderby = "meta_value_num";
break;
case 'new2old':
$sort_order_dir = "desc";
$sort_orderby = "date";
break;
case 'old2new':
$sort_order_dir = "acs";
$sort_orderby = "date";
break;
case 'rand':
$sort_order_dir = "rand";
$sort_orderby = "rand";
break;
default:
$sort_order_dir = "desc";
$sort_orderby = "meta_value_num";
break;
}
if( !empty( $filter_array['property_ids'] ) && preg_match('/^[0-9,]+$/', $filter_array['property_ids']) )
{
$property_ids = explode(',', $filter_array['property_ids']);
$bind_pids = implode(',', array_fill(0, count($property_ids), '%d'));
foreach ($property_ids as $pid){
$search_filter_vals[] = (int)$pid;
}
$SQL_where .= " AND `$Table_posts`.`ID` IN (" . $bind_pids . ")";
}
if( !empty( $filter_array['agent_ids'] ) && preg_match('/^[0-9,]+$/', $filter_array['agent_ids']) )
{
$agent_ids = explode(',', $filter_array['agent_ids']);
$bind_aids = implode(',', array_fill(0, count($agent_ids), '%d'));
foreach ($agent_ids as $aid){
$search_filter_vals[] = (int)$aid;
}
$SQL_joins .= " LEFT JOIN `$Table_postmeta` agent ON agent.`post_id` = `$Table_posts`.`ID` AND agent.`meta_key` = 'listingAgentId'";
$SQL_where .= " AND agent.`meta_value` IN (" . $bind_pids . ")";
}
if( !empty( $filter_array['property_types'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` propertyType ON propertyType.`post_id` = `$Table_posts`.`ID` AND propertyType.`meta_key` = 'listingPropertyType'";
$SQL_where .= " AND propertyType.`meta_value` LIKE %s";
$search_filter_vals[] = $wpdb->esc_like( $filter_array['property_types'] );
$searchArray[] = array(
'key' => 'listingPropertyType',
'value' => $filter_array['property_types'],
'compare' => 'LIKE'
);
}
if( !empty( $filter_array['crea_advance_search_structure_type'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` structureType ON structureType.`post_id` = `$Table_posts`.`ID` AND structureType.`meta_key` = 'listingStructureType'";
$SQL_where .= " AND structureType.`meta_value` LIKE %s";
$search_filter_vals[] = $wpdb->esc_like( $filter_array['crea_advance_search_structure_type'] );
$searchArray[] = array(
'key' => 'listingStructureType',
'value' => $filter_array['crea_advance_search_structure_type'],
'compare' => 'LIKE'
);
}
if( !empty( $filter_array['transaction_type'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` status ON status.`post_id` = `$Table_posts`.`ID` AND status.`meta_key` = 'listingAgentStatus'";
$SQL_where .= " AND status.`meta_value` LIKE %s";
$search_filter_vals[] = $wpdb->esc_like( $filter_array['transaction_type'] );
$searchArray[] = array(
'key' => 'listingAgentStatus',
'value' => $filter_array['transaction_type'],
'compare' => '='
);
}
if( !empty( $filter_array['bedrooms'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` bedrooms ON bedrooms.`post_id` = `$Table_posts`.`ID` AND bedrooms.`meta_key` = 'listingBedRooms'";
$SQL_where .= " AND CAST( bedrooms.`meta_value` AS SIGNED ) >= %d";
$search_filter_vals[] = (int) $filter_array['bedrooms'];
$searchArray[] = array(
'key' => 'listingBedRooms',
'value' => $filter_array['bedrooms'],
'compare' => '>=',
'type' => 'numeric'
);
}
if( !empty( $filter_array['bathrooms'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` bathrooms ON bathrooms.`post_id` = `$Table_posts`.`ID` AND bathrooms.`meta_key` = 'listingBathrooms'";
$SQL_where .= " AND CAST( bathrooms.`meta_value` AS SIGNED ) >= %d";
$search_filter_vals[] = (int) $filter_array['bathrooms'];
$searchArray[] = array(
'key' => 'listingBathrooms',
'value' => $filter_array['bathrooms'],
'compare' => '>=',
'type' => 'numeric'
);
}
if( $filter_array['min_amount'] !='' && isset( $filter_array['min_amount'] ) )
{
$price_join_set = true;
$SQL_joins .= " LEFT JOIN `$Table_postmeta` price ON price.`post_id` = `$Table_posts`.`ID` AND price.`meta_key` = 'listingPrice'";
$SQL_where .= " AND CAST( price.`meta_value` AS SIGNED ) >= %d";
$search_filter_vals[] = (int) str_replace('$', '', $filter_array['min_amount']);
$searchArray[] = array(
'key' => 'listingPrice',
'value' => $filter_array['listingPrice'],
'compare' => '>=',
'type' => 'numeric',
);
}
if( $filter_array['max_amount'] !='' && isset( $filter_array['max_amount'] ) )
{
if( true !== $price_join_set )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` price ON price.`post_id` = `$Table_posts`.`ID` AND price.`meta_key` = 'listingPrice'";
}
$SQL_where .= " AND CAST( price.`meta_value` AS SIGNED ) <= %d";
$search_filter_vals[] = (int) str_replace('$', '', $filter_array['max_amount']);
$searchArray[] = array(
'key' => 'listingPrice',
'value' => $filter_array['max_amount'],
'compare' => '<=',
'type' => 'numeric',
);
}
if ( !empty( $filter_array['mapbound_lat_sw'] ) && !empty( $filter_array['mapbound_lng_sw'] ) && !empty( $filter_array['mapbound_lat_ne'] ) && !empty( $filter_array['mapbound_lng_ne'] ) )
{
$SQL_joins .= " LEFT JOIN `$Table_postmeta` latitude
ON latitude.`post_id` = `$Table_posts`.`ID` AND latitude.`meta_key` = 'crea_google_map_latitude'";
$SQL_joins .= " LEFT JOIN `$Table_postmeta` longitude ON longitude.`post_id` = `$Table_posts`.`ID` AND longitude.`meta_key` = 'crea_google_map_longitude'";
$SQL_where .= " AND (
( CAST(latitude.`meta_value` AS DECIMAL(20,10)) BETWEEN %f AND %f ) AND
( CAST(longitude.`meta_value` AS DECIMAL(20,10)) BETWEEN %f AND %f )
)";
$search_filter_vals[] = floatval($filter_array['mapbound_lat_sw']);
$search_filter_vals[] = floatval($filter_array['mapbound_lat_ne']);
$search_filter_vals[] = floatval($filter_array['mapbound_lng_sw']);
$search_filter_vals[] = floatval($filter_array['mapbound_lng_ne']);
}
if( !empty( $filter_array['keyword'] ) )
{
$SQL_joins .= "
LEFT JOIN `wp_gf1z3sbh3h_postmeta` address ON address.`post_id` = `$Table_posts`.`ID` AND address.`meta_key` = 'listingAddress'
LEFT JOIN `wp_gf1z3sbh3h_postmeta` city ON city.`post_id` = `$Table_posts`.`ID` AND city.`meta_key` = 'listingcity'";
$SQL_where .= " AND (
`wp_gf1z3sbh3h_posts`.`post_content` LIKE %s
OR address.`meta_value` LIKE %s
OR city.`meta_value` LIKE %s
)";
$keyword_escapded = $wpdb->esc_like( $filter_array['keyword'] );
$search_filter_vals[] = '%'.$keyword_escapded.'%';
$search_filter_vals[] = '%'.$keyword_escapded.'%';
$search_filter_vals[] = '%'.$keyword_escapded.'%';
$searchArray[] = array(
'key' => 'listingAddress',
'value' => $filter_array['keyword'],
'compare' => 'LIKE'
);
}
$SQL = "SELECT `ID` FROM `$Table_posts` $SQL_joins
WHERE `$Table_posts`.`post_type`='aretk_listing'
AND `$Table_posts`.`post_status`='publish'
$SQL_where
GROUP BY `$Table_posts`.`ID`";
$results = $wpdb->get_results( $wpdb->prepare( $SQL, $search_filter_vals ) );
foreach ($results as $result) {
$propertyDataArr[]= $result->ID;
}
if (!empty($propertyDataArr)){
if (empty($filter_array['record_limit'])){
$filter_array['record_limit'] = 20;
}
if (empty($filter_array['record_limit'])){
$filter_array['current_page_number'] = 1;
}
$args_property = array(
'post_type' => 'aretk_listing',
'posts_per_page' => $filter_array['record_limit'],
'paged' => $filter_array['current_page_number'],
'post_status' => 'publish',
'post__in' => $propertyDataArr,
'meta_key' => 'listingPrice',
'orderby' => $sort_orderby,
'order' => $sort_order_dir,
);
if( $filter_array['showcase_view'] === 'Map View' )
{
# Set 'posts_per_page' => -1,
}
$property_array = (array) get_posts( $args_property );
}
$exclusiveArr = array();
foreach ($property_array as $singlePost) {
$singlePost1 = (array) $singlePost;
$singlePost2 = (object) $singlePost1;
$exclusiveArr[] = $singlePost2;
}
$allListingArr = array();
$allListingArr = $exclusiveArr;
$total_listing_records = count($propertyDataArr);
$listing_results = array(
'TotalRecords' => $total_listing_records,
'RecordsReturned' => count($allListingArr),
'listing_data' => $allListingArr
);
return $listing_results;
}
function aretk_listings_filter_qry_str($filter_array){
if ( empty($filter_array) ){
return NULL;
}
$filter_str = NULL;
if ( $filter_array['showcse_crea_filter_inclue_open_house'] === 'yes'){
$filter_str .= '&openhouse=true';
}
if ( !empty($filter_array['property_ids']) ){
$filter_str .= '&ids='.$filter_array['property_ids'];
}
if ( !empty($filter_array['showcse_crea_filter_by_other_day']) ){
$filter_str .= '&daysactive='.$filter_array['showcse_crea_filter_by_other_day'];
}
if ( !empty($filter_array['showcse_crea_filter_by_map_km']) && !empty($filter_array['showcse_crea_filter_google_map_latitude']) && !empty($filter_array['showcse_crea_filter_google_map_longitude']) ){
$filter_str .= '&area='.$filter_array['showcse_crea_filter_by_map_km'].'('.$filter_array['showcse_crea_filter_google_map_latitude'].','.$filter_array['showcse_crea_filter_google_map_longitude'].')';
}
#if ( !empty($filter_array['showcse_crea_filter_price_sorting']) ) {
# $filter_str .= '&order='.$filter_array['showcse_crea_filter_price_sorting'];
#}
if ( !empty($filter_array['listings_sortby']) ) {
$filter_str .= '&order='.$filter_array['listings_sortby'];
}
if ( !empty($filter_array['showcse_crea_filter_office_id']) ) {
$filter_str .= '&office_ids='.$filter_array['showcse_crea_filter_office_id'];
}
if( !empty($filter_array['showcse_crea_filter_board_id']) ) {
$filter_str.= '&board='.$filter_array['showcse_crea_filter_board_id'];
}
if( !empty($filter_array['showcse_crea_filter_agent_id']) ) {
$filter_str.= '&agent_ids='.$filter_array['showcse_crea_filter_agent_id'];
}
if( !empty($filter_array['agent_ids']) ) {
$filter_str.= '&agent_ids='.$filter_array['agent_ids'];
}
if( !empty($filter_array['keyword']) ) {
$filter_str.= '&keyword='.rawurlencode($filter_array['keyword']);
}
if( !empty($filter_array['property_types']) ) {
$filter_str.= '&property_types='.rawurlencode($filter_array['property_types']);
}
if( !empty($filter_array['structure_types']) ) {
$filter_str.= '&structure_types='.rawurlencode($filter_array['structure_types']);
}
if( !empty($filter_array['transaction_type']) ) {
$filter_str.= '&transaction_type='.rawurlencode($filter_array['transaction_type']);
}
if( !empty($filter_array['bedrooms']) ) {
$filter_str.= '&bed_min='.$filter_array['bedrooms'];
}
if( !empty($filter_array['bathrooms']) ) {
$filter_str.= '&bath_min='.$filter_array['bathrooms'];
}
if( !empty($filter_array['city']) ) {
$filter_str.= '&city='.rawurlencode($filter_array['city']);
}
if( !empty($filter_array['min_amount']) ) {
$filter_str.= '&price_min='.$filter_array['min_amount'];
}
if( !empty($filter_array['max_amount']) ) {
$filter_str.= '&price_max='.$filter_array['max_amount'];
}
if( $filter_array['include_exclusive'] === 'yes' || $filter_array['include_exclusive'] === 'true') {
$filter_str.= '&exclusive=true';
}
if( !empty($filter_array['record_limit']) ) {
$filter_str.= '&limit='.$filter_array['record_limit'];
}
if( !empty($filter_array['record_offset']) ) {
$filter_str.= '&offset='.$filter_array['record_offset'];
}
switch($filter_array['result_type']){
case 'full':
case 'basic':
case 'mapmarkers':
$filter_str.= '&result_type='.$filter_array['result_type'];
break;
}
if( !empty($filter_array['mapbound_lat_ne']) ) {
$filter_str.= '&lat_ne='.$filter_array['mapbound_lat_ne'];
}
if( !empty($filter_array['mapbound_lat_sw']) ) {
$filter_str.= '&lat_sw='.$filter_array['mapbound_lat_sw'];
}
if( !empty($filter_array['mapbound_lng_ne']) ) {
$filter_str.= '&lng_ne='.$filter_array['mapbound_lng_ne'];
}
if( !empty($filter_array['mapbound_lng_sw']) ) {
$filter_str.= '&lng_sw='.$filter_array['mapbound_lng_sw'];
}
if ( !empty($filter_array['crea_feed_id']) && $filter_array['crea_feed_id'] !== 'Exclusive Listing' ){
$filter_str .= '&feed='.$filter_array['crea_feed_id'];
}
return $filter_str;
}
function aretk_domain() {
$domainName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
if (empty($domainName)){
$domainName = get_site_url();
$domainName = parse_url($domainName, PHP_URL_HOST);
}
return $domainName;
}
function aretk_get_curl_results($ccurl) {
if (empty($ccurl)){
return false;
}
$domainName = Aretk_Crea_Public::aretk_domain();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ccurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_REFERER,$domainName);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function aretk_ip(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
/**
* custom ajax call marker click property
*
*/
function custom_ajax_for_map_view_infobox($result_type='basic') {
global $wpdb;
$property_id = $_POST['property_id'];
$showcase_id = $_POST['scid'];
if ( is_numeric( $property_id ) && is_numeric( $showcase_id ) ){
$allListingArr = array();
$showcase_meta_arr = get_post_meta($showcase_id,'',false);
$subscriptionKey = get_option('crea_subscription_key', '');
$SubscriptionStatus = get_option('crea_subscription_status', '');
$crea_feed = !empty( $showcase_meta_arr['showcse_crea_feed_ddf_type'][0] ) ? $showcase_meta_arr['showcse_crea_feed_ddf_type'][0] : '';
$include_exclusives = !empty( $showcase_meta_arr['showcse_crea_feed_include_exclude'][0] ) ? $showcase_meta_arr['showcse_crea_feed_include_exclude'][0] : '';
$filter_array['showcase_id'] = $showcase_id;
$filter_array['showcase_view'] = 'Info Window';
$filter_array['property_ids'] = $property_id;
$filter_array['result_type'] = $result_type;
$filter_array['crea_feed_id'] = $crea_feed;
if ( $include_exclusives === 'yes' ){ $filter_array['include_exclusive'] = 'true'; }
$transient_id = 'aretk_infowindow_pid_'.$property_id;
if ($_GET['cache'] === 'false'){ delete_transient($transient_id); }
$html = get_transient($transient_id);
if ( false === $html ) {
if( isset( $SubscriptionStatus ) && !empty( $SubscriptionStatus ) && $SubscriptionStatus === 'valid' && !empty($crea_feed) ){
$listing_results = Aretk_Crea_Public::aretk_get_listings_subsc($subscriptionKey, $filter_array);
} else {
$listing_results = Aretk_Crea_Public::aretk_get_listings_localwp($showcase_id, $filter_array);
}
$allListingArr = $listing_results['listing_data'];
require_once plugin_dir_path( __FILE__ ) . '/templates/listings/map-infowindow/template.php';
set_transient($transient_id, $html, 60*60);
}
} else {
$html.= 'Error.
';
}
echo $html;
die();
}
/**
* Custom ajax call for map showcase
*
*/
function custom_ajax_for_map_view_dragend() {
$showcase_id = $_POST['scid'];
$property_map_array = array();
$propety_counter = 0;
if ( is_numeric( $showcase_id ) ){
$subscriptionKey = get_option('crea_subscription_key', '');
$showcase_meta_arr = get_post_meta($showcase_id,'',false);
$SubscriptionStatus = get_option('crea_subscription_status', '');
$filter_array = Aretk_Crea_Public::aretk_listing_filters($filter_array);
if ( $showcase_meta_arr['showcse_crea_feed_include_exclude'][0] === 'yes' ){ $filter_array['include_exclusive'] = 'true'; }
$filter_array['crea_feed_id'] = !empty( $showcase_meta_arr['showcse_crea_feed_ddf_type'][0] ) ? $showcase_meta_arr['showcse_crea_feed_ddf_type'][0] : NULL;
$filter_array['result_type'] = 'mapmarkers';
$transient_id = implode('_', $filter_array);
$transient_id = 'aretk_'.$transient_id;
if ($_GET['cache'] === 'false'){
delete_transient($transient_id);
}
$property_map_json = get_transient($transient_id);
if ( false === $property_map_json ) {
if ( !empty( $SubscriptionStatus ) && $SubscriptionStatus === 'valid' && !empty($filter_array['crea_feed_id']) ) {
$filter_qry_str = Aretk_Crea_Public::aretk_listings_filter_qry_str($filter_array);
$listing_results = Aretk_Crea_Public::aretk_get_listings_subsc_json($subscriptionKey, $filter_array);
$property_map_json = $listing_results;
} else {
$listing_results = Aretk_Crea_Public::aretk_get_listings_localwp($showcase_id, $filter_array);
$allListingArr = $listing_results['listing_data'];
foreach ( $allListingArr as $singleListing ) {
if ( isset( $singleListing->post_author ) && !empty( $singleListing->post_author ) ) {
$propety_lat = get_post_meta($singleListing->ID,'crea_google_map_latitude',true);
$propety_long = get_post_meta($singleListing->ID,'crea_google_map_longitude',true);
if ( !empty( $propety_lat ) && !empty( $propety_long ) ) {
if ( $propety_lat != '57.678079218156' && $propety_long != '-101.8051686875' ){
$property_map_array['property'][$propety_counter] = array('property_id'=>$singleListing->ID,'longitude'=>$propety_long,'latitude'=>$propety_lat);
$propety_counter++;
}
}
}
}
$property_map_array['count'] = $propety_counter;
$property_map_json = json_encode($property_map_array);
}
set_transient($transient_id, $property_map_json, 60*60);
}
}
echo $property_map_json;
die();
}
}