Skip to content

Commit

Permalink
Merge pull request #6 from SimplyRETS/bug-img-url-encoding
Browse files Browse the repository at this point in the history
v2.0.3 - Allow multiple statuses and fix image url handling
  • Loading branch information
CodyReichert committed Apr 3, 2016
2 parents 04c0e2a + c6c18d9 commit b72cc4f
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 13 deletions.
25 changes: 23 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 2.0.3
- FEATURE: Allow multiple statuses in the sr_listings short-code.
- BUGFIX: Fix image rendering when image URL contains forward slashes.

## 2.0.2
* BUGFIX: Fix sr_ptypes query parameter when using multiple property types.

## 2.0.1
* BUGFIX: Fix sr_listings_slider links to listing details

## 2.0.0
* FEATURE: Support for pretty permalinks!
* FEATURE: Pretty permalink options in the admin panel
* IMPROVEMENT: URL's not longer contain the listing's price, so they
are much more easily shareable on social media.
* BUGS: Misc, minor bugs and code cleanup.

## 1.7.2
* FEATURE: Adds the ability to configure sr_search_form to search
specified property type(s) via short-code attributes.

## 1.7.1
* BUG FIX: Fix population of property-types dropdown on the
sr_map_search search form
Expand Down Expand Up @@ -139,15 +160,15 @@
* New Image Gallery Option! With full screen and thumbnails
* Add option to show/hide listing description (remarks)
* Better handling of fields that may or may not be present
* other fixes and improvements
* other fixes and improvements

## 1.2.0
* Add graphical shortcode/page builder got creating listing shortcodes
* Add support for listing limit and pagination for multiple pages of listings
* Add support for agent ID query parameter in shortcode & custom post type
* Add more styling and clean up text in admin settings panel
* better error handling
* other fixes and improvements
* other fixes and improvements

## 1.1.5
* Automatically save test credentials when plugin is activated to make it easier to get started.
Expand Down
15 changes: 12 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: SimplyRETS
Tags: rets, idx, real estate listings, real estate, listings, rets listings, simply rets, realtor, rets feed, idx feed
Requires at least: 3.0.1
Tested up to: 4.4
Stable tag: 2.0.2
Stable tag: 2.0.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -235,6 +235,10 @@ listing sidebar widget.

== Changelog ==

= 2.0.3 =
* FEATURE: Allow multiple statuses in the sr_listings short-code.
* BUGFIX: Fix image rendering when image URL contains forward slashes.

= 2.0.2 =
* BUGFIX: Fix sr_ptypes query parameter when using multiple property types.

Expand Down Expand Up @@ -451,8 +455,11 @@ Fetches a single listing by it's mlsid.
`[sr_listings mlsid="12345"]`

* **status**
Refines listings by a certain status, like Active, Pending, or Closed.
Refines listings by a certain status, like Active, Pending, or Closed. (Separate multiple with a semicolon ';')
`[sr_listings status="Closed"]`
`[sr_listings status="Active; Pending"]`

*Note: By default, Active and Pending are queried*

* **minprice**
Refines listings to a minimum price.
Expand Down Expand Up @@ -519,7 +526,7 @@ Refines listings to a given set of features. (Separate multiple with a semi-colo
`[sr_listings cities="Tennis Court; Waterfront"]`

* **vendor**
Refines listings by a certain vendor or MLS Board. (This is only available when your account has multiple MLS's).
Refines listings by a certain vendor or MLS Board. (This is required when your account has multiple MLS's).
`[sr_listings vendor="MFRMLS"]`

* **limit**
Expand All @@ -537,6 +544,8 @@ Displays the listings in a specific order.
(The available sort options are `listprice`, `-listprice`, `listdate`, `-listdate`, `baths`, `-baths`, `beds`, and `-beds`.
Options starting the a minus (-) are high to low, no minus sign is low to high).

*Note: By default, the listings are sorted by modification time, newest first*

* **advanced**
This attribute is to turn the basic search form into an advanced search form.
`[sr_search_form advanced="true"]`
Expand Down
6 changes: 4 additions & 2 deletions simply-rets-api-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function srApiOptionsRequest( $url ) {
$php_version = phpversion();
$site_url = get_site_url();

$ua_string = "SimplyRETSWP/2.0.2 Wordpress/{$wp_version} PHP/{$php_version}";
$ua_string = "SimplyRETSWP/2.0.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 @@ -209,7 +209,7 @@ public static function srApiRequest( $url ) {
$wp_version = get_bloginfo('version');
$php_version = phpversion();

$ua_string = "SimplyRETSWP/2.0.2 Wordpress/{$wp_version} PHP/{$php_version}";
$ua_string = "SimplyRETSWP/2.0.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 @@ -1108,6 +1108,7 @@ public static function srResidentialResultsGenerator( $response, $settings ) {
$listingPhotos[0] = plugins_url( 'assets/img/defprop.jpg', __FILE__ );
}
$main_photo = trim($listingPhotos[0]);
$main_photo = str_replace("\\", "", $main_photo);

// listing link to details
$link = SrUtils::buildDetailsLink(
Expand Down Expand Up @@ -1303,6 +1304,7 @@ public static function srWidgetListingGenerator( $response ) {
$listingPhotos[0] = plugins_url( 'assets/img/defprop.jpg', __FILE__ );
}
$main_photo = $listingPhotos[0];
$main_photo = str_replace("\\", "", $main_photo);

// create link to listing
$link = SrUtils::buildDetailsLink(
Expand Down
62 changes: 60 additions & 2 deletions simply-rets-post-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,22 @@ public static function srPostDefaultContent( $content ) {
get_option('sr_search_map_position'));


/**
* Check if there is multiple 'types' being searched.
* HACK: This is a bit of hack because sometimes the parameters
* are in an array() and sometimes they are in a string that needs
* to be made into an array. The others aren't like that,
* so we should fix this one.
*/

/** Multiple Types */
$p_types = isset($_GET['sr_ptype']) ? $_GET['sr_ptype'] : '';
$ptypes_string = '';
if(!is_array($p_types)) {
if(strpos($p_types, ";") !== FALSE) {
$p_types = explode(';', $p_types);
} else {
$ptypes_string = "&type=$p_types";
}
}
if(is_array($p_types) && !empty($p_types)) {
Expand All @@ -565,6 +577,39 @@ public static function srPostDefaultContent( $content ) {
}
}


/** Multiple Statuses */
$statuses = isset($_GET['sr_status']) ? $_GET['sr_status'] : $status;
$statuses_string = '';
if(!is_array($statuses)) {
if(strpos($statuses, ";") !== FALSE) {
$statuses = explode(';', $statuses);
} else {
$statuses_string = "&status=$statuses";
}
}
if(is_array($statuses) && !empty($statuses)) {
foreach((array)$statuses as $key => $stat) {
$final = trim($stat);
$statuses_string .= "&status=$final";
}
}

/**
* The loops below check if the short-code has multiple
* values for any query parameter. Eg, multiple cities.
* Since they support multiple, we do the following for
* each:
*
*
* - Split string on ';' delimeter (which returns a single
item array if there is none)
*
* - Make each array item into a query (eg, &status=Closed)
*
* - Concat them together (eg,&status=Active&status=Closed)
*/

$features = isset($_GET['sr_features']) ? $_GET['sr_features'] : '';
if(!empty($features)) {
foreach((array)$features as $key => $feature) {
Expand Down Expand Up @@ -599,7 +644,13 @@ public static function srPostDefaultContent( $content ) {
}
}

// these should correlate with what the api expects as filters
/**
* Make a new array with all query parameters.
*
* Note: We're only using params that weren't transformed
* above.
*/

$listing_params = array(
"q" => $keywords,
"brokers" => $brokers,
Expand All @@ -618,7 +669,6 @@ public static function srPostDefaultContent( $content ) {
/** Advanced Search */
"lotsize" => $lotsize,
"area" => $area,
"status" => $status,
"sort" => $sort,

/** Multi MLS */
Expand All @@ -643,6 +693,9 @@ public static function srPostDefaultContent( $content ) {
}
}

/**
* Make advanced search page with new query
*/
if( !$advanced || !$advanced == "true" ) {
$qs = '?'
. http_build_query( array_filter( $listing_params ) )
Expand All @@ -651,6 +704,7 @@ public static function srPostDefaultContent( $content ) {
. $neighborhoods_string
. $agents_string
. $ptypes_string
. $statuses_string
. $amenities_string;

$qs = str_replace(' ', '%20', $qs);
Expand All @@ -659,6 +713,9 @@ public static function srPostDefaultContent( $content ) {
$content .= $listings_content;
return $content;

/**
* Make regular search page with new query
*/
} else {

$qs = '?';
Expand All @@ -668,6 +725,7 @@ public static function srPostDefaultContent( $content ) {
$qs .= $agents_string;
$qs .= $ptypes_string;
$qs .= $neighborhoods_string;
$qs .= $statuses_string;
$qs .= $amenities_string;

$qs = str_replace(' ', '%20', $qs);
Expand Down
38 changes: 35 additions & 3 deletions simply-rets-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public static function sr_int_map_search($atts) {
public function sr_residential_shortcode( $atts ) {
global $wp_query;

/**
* Check if `mlsId` was supplied. If so, just query that.
*/
if(!empty($atts['mlsid'])) {
$qs = '/' . $atts['mlsid'];
if(array_key_exists('vendor', $atts) && !empty($atts['vendor'])) {
Expand All @@ -186,11 +189,19 @@ public function sr_residential_shortcode( $atts ) {
$listing_params = $atts;
}

/**
* The below parameters currently support multiple values via
* a semicolon delimeter. Eg, status="Active; Closed"
*
* Before we send them, build a proper query string that the API
* can understand. Eg, status=Active&status=Closed
*/
if( !isset($listing_params['neighborhoods'])
&& !isset($listing_params['postalcodes'])
&& !isset($listing_params['cities'])
&& !isset($listing_params['agent'])
&& !isset($listing_params['type'])
&& !isset($listing_params['status'])
)
{
$listings_content = SimplyRetsApiHelper::retrieveRetsListings( $listing_params, $atts );
Expand Down Expand Up @@ -236,9 +247,6 @@ public function sr_residential_shortcode( $atts ) {
$ptypes_string = str_replace(' ', '%20', $ptypes_string );
}

/**
* Postal Codes filter is being used - check for multiple values and build query accordingly
*/
if( isset( $listing_params['postalcodes'] ) && !empty( $listing_params['postalcodes'] ) ) {
$postalcodes = explode( ';', $listing_params['postalcodes'] );
foreach( $postalcodes as $key => $postalcode ) {
Expand All @@ -248,24 +256,48 @@ public function sr_residential_shortcode( $atts ) {
$postalcodes_string = str_replace(' ', '%20', $postalcodes_string );
}

/**
* Multiple statuses
*/
if( isset( $listing_params['status'] ) && !empty( $listing_params['status'] ) ) {

$statuses = explode( ';', $listing_params['status'] );

foreach( $statuses as $key => $stat) {
$stat = trim($stat);
$statuses_string .= "status=$stat&";
}

$statuses_string = str_replace(' ', '%20', $statuses_string );
}

/**
* Build a regular query string for everything else
*/
foreach( $listing_params as $key => $value ) {
// Skip params that support multiple
if( $key !== 'postalcodes'
&& $key !== 'neighborhoods'
&& $key !== 'cities'
&& $key !== 'agent'
&& $key !== 'type'
&& $key !== 'status'
) {
$params_string .= $key . "=" . $value . "&";
}
}

/**
* Final query string
*/
$qs = '?';
$qs .= $neighborhoods_string;
$qs .= $cities_string;
$qs .= $postalcodes_string;
$qs .= $params_string;
$qs .= $agents_string;
$qs .= $ptypes_string;
$qs .= $statuses_string;

$listings_content = SimplyRetsApiHelper::retrieveRetsListings( $qs, $atts );
return $listings_content;
Expand Down
2 changes: 1 addition & 1 deletion 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.0.2
Version: 2.0.3
License: GNU General Public License v3 or later
Copyright (c) SimplyRETS 2014 - 2015
Expand Down

0 comments on commit b72cc4f

Please sign in to comment.