/**
 * Formats address on print.  If address it not formatted, makes an on-the-fly call to GMaps for validation.
 *
 *
 * @since 1.04
 */
function wpp_format_address_attribute($data, $property = false, $format = "[street_number] [street_name], [city], [state]")
{
    global $wp_properties;
    if (!is_object($property)) {
        return $data;
    }
    $currenty_address = $property->{$wp_properties}['configuration']['address_attribute'];
    //** If the currently requested properties address has not been formatted, and on-the-fly geo-lookup has not been disabled, try to look up now */
    if ((!isset($property->address_is_formatted) || !$property->address_is_formatted) && $wp_properties['configuration']['do_not_automatically_geo_validate_on_property_view'] != 'true') {
        //** Silently attempt to validate address, right now */
        $geo_data = WPP_F::revalidate_all_addresses(array('property_ids' => array($property->ID), 'echo_result' => false, 'return_geo_data' => true));
        if ($this_geo_data = $geo_data['geo_data'][$property->ID]) {
            $street_number = $this_geo_data->street_number;
            $route = $this_geo_data->route;
            $city = $this_geo_data->city;
            $state = $this_geo_data->state;
            $state_code = $this_geo_data->state_code;
            $county = $this_geo_data->county;
            $country = $this_geo_data->country;
            $postal_code = $this_geo_data->postal_code;
        }
    } else {
        $street_number = isset($property->street_number) ? $property->street_number : false;
        $route = isset($property->route) ? $property->route : false;
        $city = isset($property->city) ? $property->city : false;
        $state = isset($property->state) ? $property->state : false;
        $state_code = isset($property->state_code) ? $property->state_code : false;
        $county = isset($property->county) ? $property->county : false;
        $country = isset($property->country) ? $property->country : false;
        $postal_code = isset($property->postal_code) ? $property->postal_code : false;
    }
    $display_address = $format;
    $display_address = str_replace("[street_number]", $street_number, $display_address);
    $display_address = str_replace("[street_name]", $route, $display_address);
    $display_address = str_replace("[city]", "{$city}", $display_address);
    $display_address = str_replace("[state]", "{$state}", $display_address);
    $display_address = str_replace("[state_code]", "{$state_code}", $display_address);
    $display_address = str_replace("[county]", "{$county}", $display_address);
    $display_address = str_replace("[country]", "{$country}", $display_address);
    $display_address = str_replace("[zip_code]", "{$postal_code}", $display_address);
    $display_address = str_replace("[zip]", "{$postal_code}", $display_address);
    $display_address = str_replace("[postal_code]", "{$postal_code}", $display_address);
    $display_address = preg_replace('/^\\n+|^[\\t\\s]*\\n+/m', "", $display_address);
    if (str_replace(array(' ', ','), '', $display_address) == '') {
        if (!empty($currenty_address)) {
            return $currenty_address;
        } else {
            return;
        }
    }
    // Remove empty lines
    foreach (explode("\n", $display_address) as $line) {
        $line = trim($line);
        // Remove line if comma is first character
        if (strlen($line) < 3 && (strpos($line, ',') === 1 || strpos($line, ',') === 0)) {
            continue;
        }
        $return[] = $line;
    }
    if (is_array($return)) {
        return implode("\n", $return);
    }
}