/** * Hooks into save_post function and saves additional property data * * @todo Add some sort of custom capability so not only admins can make properties as featured. i.e. Agents can make their own properties featured. * @since 1.04 * @param null $post_id * @return null */ function save_property($post_id = null) { global $wp_properties, $wp_version; $_wpnonce = (version_compare($wp_version, '3.5', '>=') ? 'update-post_' : 'update-property_') . $post_id; if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $_wpnonce) || $_POST['post_type'] !== 'property') { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } $update_data = $_REQUEST['wpp_data']['meta']; //** Neccessary meta data which is required by Supermap Premium Feature. Should be always set even the Supermap disabled. peshkov@UD */ if (empty($_REQUEST['exclude_from_supermap'])) { if (!metadata_exists('post', $post_id, 'exclude_from_supermap')) { $update_data['exclude_from_supermap'] = 'false'; } } if (!isset($update_data['latitude']) || (double) $update_data['latitude'] == 0) { $update_data['latitude'] = ''; } if (!isset($update_data['longitude']) || (double) $update_data['longitude'] == 0) { $update_data['longitude'] = ''; } /* get old coordinates and location */ $old_lat = get_post_meta($post_id, 'latitude', true); $old_lng = get_post_meta($post_id, 'longitude', true); $geo_data = array('old_coordinates' => empty($old_lat) || empty($old_lng) ? "" : array('lat' => $old_lat, 'lng' => $old_lng), 'old_location' => !empty($wp_properties['configuration']['address_attribute']) ? get_post_meta($post_id, $wp_properties['configuration']['address_attribute'], true) : ''); // die( '<pre>' . $post_id . print_r( $update_data, true ) . '</pre>' ); foreach ($update_data as $meta_key => $meta_value) { $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($meta_key); $meta_value = html_entity_decode($meta_value); $meta_value = stripslashes($meta_value); /* Handle logic for featured property. */ if ($meta_key == 'featured') { //* Only admins can mark properties as featured. */ if (!current_user_can('manage_options')) { //** But be sure that meta 'featured' exists at all */ if (!metadata_exists('post', $post_id, $meta_key)) { $meta_value = 'false'; } else { continue; } } do_action('wpp::toggle_featured', $meta_value, $post_id); } //* Remove certain characters */ if (isset($attribute_data['currency']) || isset($attribute_data['numeric'])) { $meta_value = str_replace(array("\$", ","), '', $meta_value); } //* Overwrite old post meta allowing only one value */ delete_post_meta($post_id, $meta_key); add_post_meta($post_id, $meta_key, $meta_value); } //* Check if property has children */ $children = get_children(array('post_parent' => $post_id, 'post_type' => 'property')); //* Write any data to children properties that are supposed to inherit things */ //* 1) Go through all children */ foreach ((array) $children as $child_id => $child_data) { //* Determine child property_type */ $child_property_type = get_post_meta($child_id, 'property_type', true); //* Check if child's property type has inheritence rules, and if meta_key exists in inheritance array */ if (isset($wp_properties['property_inheritance'][$child_property_type]) && is_array($wp_properties['property_inheritance'][$child_property_type])) { foreach ($wp_properties['property_inheritance'][$child_property_type] as $i_meta_key) { $parent_meta_value = get_post_meta($post_id, $i_meta_key, true); //* inheritance rule exists for this property_type for this meta_key */ update_post_meta($child_id, $i_meta_key, $parent_meta_value); } } } $_gpid = WPP_F::maybe_set_gpid($post_id); do_action('save_property', $post_id, array('children' => $children, 'gpid' => $_gpid, 'update_data' => $update_data, 'geo_data' => $geo_data)); /** * Flush all object caches related to current property */ \UsabilityDynamics\WPP\Property_Factory::flush_cache($post_id); /** * Flush WP-Property caches */ \WPP_F::clear_cache(); }
/** * Updates numeric and currency attribute of parent property on child property saving. * Sets attribute's value based on children values ( sets aggregated value ). * * * Tries to figure out which attributes can be handled as a "range". (legacy-logic) * * Iterates over all children of the parent and writes any computed ranges directly to parents meta. * * @param integer $post_id * @used WPP_F::save_property(); * @author peshkov@UD * @return null */ function wpp_save_property_aggregated_data($post_id) { global $wpdb, $wp_properties; if (empty($_REQUEST['parent_id'])) { return null; } //** Get all children */ $children = $wpdb->get_col($wpdb->prepare("\n SELECT ID\n FROM {$wpdb->posts}\n WHERE post_type = 'property'\n AND post_status = 'publish'\n AND post_parent = %s\n ORDER BY menu_order ASC\n ", $_REQUEST['parent_id'])); if (count($children) > 0) { $range = array(); //** Cycle through children and get necessary variables */ foreach ($children as $child_id) { $child_object = WPP_F::get_property($child_id, "load_parent=false"); //** Exclude variables from searchable attributes (to prevent ranges) */ $excluded_attributes = $wp_properties['geo_type_attributes']; $excluded_attributes[] = $wp_properties['configuration']['address_attribute']; foreach ($wp_properties['searchable_attributes'] as $searchable_attribute) { $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($searchable_attribute); if (!empty($attribute_data['numeric']) || !empty($attribute_data['currency'])) { if (!empty($child_object[$searchable_attribute]) && !in_array($searchable_attribute, $excluded_attributes)) { if (!isset($range[$searchable_attribute])) { $range[$searchable_attribute] = array(); } $range[$searchable_attribute][] = $child_object[$searchable_attribute]; } } } } foreach ($range as $range_attribute => $range_values) { //* Cycle through all values of this range (attribute), and fix any ranges that use dashes */ foreach ($range_values as $key => $single_value) { //* Remove dollar signs */ $single_value = str_replace("\$", '', $single_value); //* Fix ranges */ if (strpos($single_value, '–')) { $split = explode('–', $single_value); foreach ($split as $new_single_value) { if (!empty($new_single_value)) { array_push($range_values, trim($new_single_value)); } } //* Unset original value with dash */ unset($range_values[$key]); } } $average = isset($wp_properties['configuration']['show_aggregated_value_as_average']) ? $wp_properties['configuration']['show_aggregated_value_as_average'] : false; $val = @array_sum($range_values); $val = is_numeric($val) && $val > 0 ? $average == 'true' ? ceil($val / count($range_values)) : $val : 0; update_post_meta($_REQUEST['parent_id'], $range_attribute, $val); } } }
function wpp_render_search_input($args = false) { global $wp_properties; extract($args = wp_parse_args($args, array('type' => 'input', 'input_type' => false, 'search_values' => false, 'attrib' => false, 'random_element_id' => 'wpp_search_element_' . rand(1000, 9999), 'value' => false, 'placeholder' => false))); $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($args['attrib']); if (!empty($args['input_type'])) { $use_input_type = $args['input_type']; } else { $use_input_type = isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : false; } ob_start(); if (!empty($use_input_type)) { switch ($use_input_type) { case 'input': ?> <input id="<?php echo $random_element_id; ?> " class="<?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ]" value="<?php echo $value; ?> " placeholder="<?php echo $placeholder; ?> " type="text" /> <?php break; case 'range_input': /* Determine if $value has correct format, and if not - fix it. */ $value = !is_array($value) ? array('min' => '', 'max' => '') : $value; $value['min'] = in_array('min', $value) ? $value['min'] : ''; $value['max'] = in_array('max', $value) ? $value['max'] : ''; ?> <input id="<?php echo $random_element_id; ?> " class="wpp_search_input_field wpp_search_input_field_min wpp_search_input_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " type="text" name="wpp_search[<?php echo $attrib; ?> ][min]" value="<?php echo $value['min']; ?> " placeholder="<?php echo $placeholder['min']; ?> "/> <span class="wpp_dash">-</span> <input class="wpp_search_input_field wpp_search_input_field_max wpp_search_input_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " type="text" name="wpp_search[<?php echo $attrib; ?> ][max]" value="<?php echo $value['max']; ?> " placeholder="<?php echo $placeholder['max']; ?> "/> <?php break; case 'range_dropdown': ?> <?php $grouped_values = group_search_values($search_values[$attrib]); ?> <select id="<?php echo $random_element_id; ?> " class="wpp_search_select_field wpp_search_select_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ][min]"> <option value="-1"><?php _e('Any', ud_get_wp_property()->domain); ?> </option> <?php foreach ($grouped_values as $v) { ?> <option value='<?php echo (int) $v; ?> ' <?php if (isset($value['min']) && $value['min'] == $v) { echo " selected='true' "; } ?> > <?php echo apply_filters("wpp_stat_filter_{$attrib}", $v); ?> + </option> <?php } ?> </select> <?php break; case 'advanced_range_dropdown': ?> <?php $grouped_values = !empty($search_values[$attrib]) ? $search_values[$attrib] : group_search_values($search_values[$attrib]); ?> <select id="<?php echo $random_element_id; ?> " class="wpp_search_select_field wpp_search_select_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ][min]"> <option value=""><?php _e('Min', ud_get_wp_property()->domain); ?> </option> <?php foreach ($grouped_values as $v) { ?> <option value='<?php echo (int) $v; ?> ' <?php if (isset($value['min']) && $value['min'] == (int) $v) { echo " selected='selected' "; } ?> > <?php echo apply_filters("wpp_stat_filter_{$attrib}", $v); ?> </option> <?php } ?> </select> <span class="delimiter">-</span> <select id="<?php echo $random_element_id; ?> " class="wpp_search_select_field wpp_search_select_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ][max]"> <option value=""><?php _e('Max', ud_get_wp_property()->domain); ?> </option> <?php foreach ($grouped_values as $v) { ?> <option value='<?php echo (int) $v; ?> ' <?php if (isset($value['max']) && $value['max'] == (int) $v) { echo " selected='selected' "; } ?> > <?php echo apply_filters("wpp_stat_filter_{$attrib}", $v); ?> </option> <?php } ?> </select> <?php break; case 'dropdown': ?> <select id="<?php echo $random_element_id; ?> " class="wpp_search_select_field wpp_search_select_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ]"> <option value="-1"><?php _e('Any', ud_get_wp_property()->domain); ?> </option> <?php foreach ($search_values[$attrib] as $v) { ?> <option value="<?php echo esc_attr($v); ?> " <?php selected($value, $v); ?> ><?php echo esc_attr(apply_filters("wpp_stat_filter_{$attrib}", $v)); ?> </option> <?php } ?> </select> <?php break; case 'multi_checkbox': ?> <ul class="wpp_multi_checkbox <?php echo $attribute_data['ui_class']; ?> "> <?php foreach ($search_values[$attrib] as $value_label) { ?> <?php $unique_id = rand(10000, 99999); ?> <li> <input name="wpp_search[<?php echo $attrib; ?> ][]" <?php echo is_array($value) && in_array($value_label, $value) ? 'checked="true"' : ''; ?> id="wpp_attribute_checkbox_<?php echo $unique_id; ?> " type="checkbox" value="<?php echo $value_label; ?> "/> <label for="wpp_attribute_checkbox_<?php echo $unique_id; ?> " class="wpp_search_label_second_level"><?php echo $value_label; ?> </label> </li> <?php } ?> </ul> <?php break; case 'checkbox': ?> <input id="<?php echo $random_element_id; ?> " type="checkbox" class="<?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ]" <?php checked($value, 'true'); ?> value="true"/> <?php break; default: echo apply_filters('wpp::render_search_input::custom', '', $args); break; } } else { ?> <?php if (empty($search_values[$attrib])) { ?> <input id="<?php echo $random_element_id; ?> " class="wpp_search_input_field wpp_search_input_field_<?php echo $attrib; ?> " name="wpp_search[<?php echo $attrib; ?> ]" value="<?php echo $value; ?> " type="text"/> <?php //* Determine if attribute is a numeric range */ ?> <?php } elseif (WPP_F::is_numeric_range($search_values[$attrib])) { ?> <input class="wpp_search_input_field wpp_search_input_field_min wpp_search_input_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " type="text" name="wpp_search[<?php echo $attrib; ?> ][min]" value="<?php echo isset($value['min']) ? $value['min'] : ''; ?> "/> - <input class="wpp_search_input_field wpp_search_input_field_max wpp_search_input_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " type="text" name="wpp_search[<?php echo $attrib; ?> ][max]" value="<?php echo isset($value['max']) ? $value['max'] : ''; ?> "/> <?php } else { ?> <?php /* Not a numeric range */ ?> <select id="<?php echo $random_element_id; ?> " class="wpp_search_select_field wpp_search_select_field_<?php echo $attrib; ?> <?php echo $attribute_data['ui_class']; ?> " name="wpp_search[<?php echo $attrib; ?> ]"> <option value="<?php echo $attrib == 'property_type' && is_array($search_values[$attrib]) ? implode(',', array_flip($search_values[$attrib])) : '-1'; ?> "><?php _e('Any', ud_get_wp_property()->domain); ?> </option> <?php foreach ($search_values[$attrib] as $key => $v) { ?> <option value='<?php echo $attrib == 'property_type' ? $key : $v; ?> ' <?php if ($value == ($attrib == 'property_type' ? $key : $v)) { echo " selected='true' "; } ?> > <?php echo apply_filters("wpp_stat_filter_{$attrib}", $v); ?> </option> <?php } ?> </select> <?php } ?> <?php } echo apply_filters('wpp_render_search_input', ob_get_clean(), $args); }
/** * Returns a minified Google Maps Infobox * * Used in property map and supermap * * @filter wpp_google_maps_infobox * @version 1.11 - added return if $post or address attribute are not set to prevent fatal error * @since 1.081 * */ public static function google_maps_infobox($post, $args = false) { global $wp_properties; $map_image_type = $wp_properties['configuration']['single_property_view']['map_image_type']; $infobox_attributes = $wp_properties['configuration']['google_maps']['infobox_attributes']; $infobox_settings = $wp_properties['configuration']['google_maps']['infobox_settings']; if (empty($wp_properties['configuration']['address_attribute'])) { return; } if (empty($post)) { return; } if (is_array($post)) { $post = (object) $post; } $property = (array) prepare_property_for_display($post, array('load_gallery' => 'false', 'scope' => 'google_map_infobox')); //** Check if we have children */ if (!empty($property['children']) && (!isset($wp_properties['configuration']['google_maps']['infobox_settings']['do_not_show_child_properties']) || $wp_properties['configuration']['google_maps']['infobox_settings']['do_not_show_child_properties'] != 'true')) { foreach ($property['children'] as $child_property) { $child_property = (array) $child_property; $html_child_properties[] = '<li class="infobox_child_property"><a href="' . $child_property['permalink'] . '">' . $child_property['post_title'] . '</a></li>'; } } if (empty($infobox_attributes)) { $infobox_attributes = array('price', 'bedrooms', 'bathrooms'); } if (empty($infobox_settings)) { $infobox_settings = array('show_direction_link' => true, 'show_property_title' => true); } $infobox_style = !empty($infobox_settings['minimum_box_width']) ? 'style="min-width: ' . $infobox_settings['minimum_box_width'] . 'px;"' : ''; foreach ($infobox_attributes as $attribute) { if (!empty($wp_properties['property_stats'][$attribute])) { $property_stats[$attribute] = $wp_properties['property_stats'][$attribute]; } } $property_stats = WPP_F::get_stat_values_and_labels($property, array('property_stats' => $property_stats)); if (!empty($property['featured_image'])) { $image = wpp_get_image_link($property['featured_image'], $map_image_type, array('return' => 'array')); if (!empty($image) && is_array($image)) { $imageHTML = "<img width=\"{$image['width']}\" height=\"{$image['height']}\" src=\"{$image['link']}\" alt=\"" . addslashes($post->post_title) . "\" />"; if (@$wp_properties['configuration']['property_overview']['fancybox_preview'] == 'true' && !empty($property['featured_image_url'])) { $imageHTML = "<a href=\"{$property['featured_image_url']}\" class=\"fancybox_image thumbnail\">{$imageHTML}</a>"; } } } ob_start(); ?> <div id="infowindow" <?php echo $infobox_style; ?> > <?php if ($infobox_settings['show_property_title'] == 'true') { ?> <div class="wpp_google_maps_attribute_row_property_title"> <a href="<?php echo get_permalink($property['ID']); ?> "><?php echo $property['post_title']; ?> </a> </div> <?php } ?> <table cellpadding="0" cellspacing="0" class="wpp_google_maps_infobox_table" style=""> <tr> <?php if (!empty($imageHTML)) { ?> <td class="wpp_google_maps_left_col" style=" width: <?php echo $image['width']; ?> px"> <?php echo $imageHTML; ?> <?php if ($infobox_settings['show_direction_link'] == 'true' && !empty($property['latitude']) && !empty($property['longitude'])) { ?> <div class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_directions_link"> <a target="_blank" href="http://maps.google.com/maps?gl=us&daddr=<?php echo $property['latitude']; ?> ,<?php echo $property['longitude']; ?> " class="btn btn-info"><?php _e('Get Directions', ud_get_wp_property()->domain); ?> </a> </div> <?php } ?> </td> <?php } ?> <td class="wpp_google_maps_right_col" vertical-align="top" style="vertical-align: top;"> <?php if (!empty($imageHTML) && $infobox_settings['show_direction_link'] == 'true' && !empty($property['latitude']) && !empty($property['longitude'])) { ?> <div class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_directions_link"> <a target="_blank" href="http://maps.google.com/maps?gl=us&daddr=<?php echo $property['latitude']; ?> ,<?php echo $property['longitude']; ?> " class="btn btn-info"><?php _e('Get Directions', ud_get_wp_property()->domain); ?> </a> </div> <?php } $attributes = array(); $labels_to_keys = array_flip($wp_properties['property_stats']); if (is_array($property_stats)) { foreach ($property_stats as $attribute_label => $value) { $attribute_slug = $labels_to_keys[$attribute_label]; $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($attribute_slug); if (empty($value)) { continue; } if (!empty($attribute_data['data_input_type']) && $attribute_data['data_input_type'] == 'checkbox' && ($value == 'true' || $value == 1)) { if ($wp_properties['configuration']['google_maps']['show_true_as_image'] == 'true') { $value = '<div class="true-checkbox-image"></div>'; } else { $value = __('Yes', ud_get_wp_property()->domain); } } elseif ($value == 'false') { continue; } $attributes[] = '<li class="wpp_google_maps_attribute_row wpp_google_maps_attribute_row_' . $attribute_slug . '">'; $attributes[] = '<span class="attribute">' . $attribute_label . '</span>'; $attributes[] = '<span class="value">' . $value . '</span>'; $attributes[] = '</li>'; } } if (count($attributes) > 0) { echo '<ul class="wpp_google_maps_infobox">' . implode('', $attributes) . '<li class="wpp_google_maps_attribute_row wpp_fillter_element"> </li></ul>'; } if (!empty($html_child_properties)) { echo '<ul class="infobox_child_property_list">' . implode('', $html_child_properties) . '<li class="infobox_child_property wpp_fillter_element"> </li></ul>'; } ?> </td> </tr> </table> </div> <?php $data = ob_get_contents(); $data = preg_replace(array('/[\\r\\n]+/'), array(""), $data); $data = addslashes($data); ob_end_clean(); $data = apply_filters('wpp_google_maps_infobox', $data, $post); return $data; }