Skip to content

Commit

Permalink
Merge pull request #152 from SimplyRETS/fix-details-page-url-encoding
Browse files Browse the repository at this point in the history
Handle "/" characters in listing details page links
  • Loading branch information
CodyReichert committed Dec 6, 2019
2 parents 1090ad7 + ad7f350 commit 9986898
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## 2.8.3
* FIX: Handle "/" characters in single listing page URLs.

## 2.8.2
* FIX: Add error handling for openhouses API requests
* FIX: Add error handling for openhouses API requests.

## 2.8.1
* ENHANCEMENT: Add support for open houses short-code and search results.
Expand Down
5 changes: 4 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: SimplyRETS
Tags: rets, idx, idx plugin, mls, mls listings, real estate, simply rets, realtor, rets feed, idx feed
Requires at least: 3.0.1
Tested up to: 5.3.0
Stable tag: 2.8.2
Stable tag: 2.8.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -236,6 +236,9 @@ listing sidebar widget.

== Changelog ==

= 2.8.3 =
* FIX: Handle "/" characters in single listing page URLs.

= 2.8.2 =
* FIX: Add error handling for openhouses API requests

Expand Down
4 changes: 2 additions & 2 deletions src/simply-rets-api-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static function srApiOptionsRequest( $url ) {
$php_version = phpversion();
$site_url = get_site_url();

$ua_string = "SimplyRETSWP/2.8.2 Wordpress/{$wp_version} PHP/{$php_version}";
$ua_string = "SimplyRETSWP/2.8.3 Wordpress/{$wp_version} PHP/{$php_version}";
$accept_header = "Accept: application/json; q=0.2, application/vnd.simplyrets-v0.1+json";

if( is_callable( 'curl_init' ) ) {
Expand Down Expand Up @@ -240,7 +240,7 @@ public static function srApiRequest( $url ) {
$wp_version = get_bloginfo('version');
$php_version = phpversion();

$ua_string = "SimplyRETSWP/2.8.2 Wordpress/{$wp_version} PHP/{$php_version}";
$ua_string = "SimplyRETSWP/2.8.3 Wordpress/{$wp_version} PHP/{$php_version}";
$accept_header = "Accept: application/json; q=0.2, application/vnd.simplyrets-v0.1+json";

if( is_callable( 'curl_init' ) ) {
Expand Down
15 changes: 11 additions & 4 deletions src/simply-rets-post-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,20 @@ public static function srCreateDynamicPost( $posts ) {
(!empty($wpq['sr-listings']) AND $wpq['sr-listings'] == "sr-single")
) {

$post_id = urldecode(get_query_var( 'listing_id', '' ));
$post_addr = urldecode(get_query_var( 'listing_title', '' ));
$post_price = urldecode(get_query_var( 'listing_price', '' ));
$post_id = urldecode(get_query_var('listing_id', ''));
$post_price = urldecode(get_query_var('listing_price', ''));
$post_addr = SrUtils::decodeStringForUrl(
urldecode(get_query_var('listing_title', ''))
);

$listing_USD = $post_price == '' ? '' : '$' . number_format( $post_price );
$title_normalize = "background-color:transparent;padding:0px;";
$post_title = "{$post_addr} <span style='{$title_normalize}'><small><i> {$listing_USD}</i></small></span>";
$post_title = "{$post_addr} "
. "<span style='{$title_normalize}'>"
. " <small>"
. " <i> {$listing_USD}</i>"
. " </small>"
. "</span>";

$post = (object)array(
"ID" => $post_id,
Expand Down
20 changes: 19 additions & 1 deletion src/simply-rets-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ public static function buildFullAddressString($listing) {
return $address . $comma . $city . ', ' . $state . ' ' . $zip;
}

/**
* Encode specific characters in a string to work in a URL. For
* example, a `/` character cannot be normally encoded as %2F
* because Apache url decodes the string and treats it as a path
* separator. See: https://stackoverflow.com/a/3235361/3464723
*/
public static function encodeStringForUrl($str) {
return str_replace("/", "_", $str);
}

// Decode a string encoded with `encodeStringForUrl`
public static function decodeStringForUrl($str) {
return str_replace("_", "/", $str);
}

/**
* Builds a link to a listings' details page. Used in search results.
*/
Expand Down Expand Up @@ -150,8 +165,11 @@ public static function buildDetailsLink($listing, $params = array()) {
$listing_city = $listing->address->city;
$listing_state = $listing->address->state;
$listing_zip = $listing->address->postalCode;

$listing_address = $listing->address->full;
$listing_address_full = SrUtils::buildFullAddressString($listing);
$listing_address_full = SrUtils::encodeStringForUrl(
SrUtils::buildFullAddressString($listing)
);

if($prettify && $custom_permalink_struct === "pretty_extra") {

Expand Down
2 changes: 1 addition & 1 deletion src/simply-rets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://simplyrets.com
Description: Show your Real Estate listings on your Wordpress site. SimplyRETS provides a very simple set up and full control over your listings.
Author: SimplyRETS
Version: 2.8.2
Version: 2.8.3
License: GNU General Public License v3 or later
Copyright (c) SimplyRETS 2014 - 2015
Expand Down

0 comments on commit 9986898

Please sign in to comment.