cyberhobo / wordpress-geo-mashup

Official repository for Geo Mashup, the plugin that makes WordPress into a GeoCMS. Documentation:
https://github.com/cyberhobo/wordpress-geo-mashup/wiki/Getting-Started
63 stars 15 forks source link

Conflict with Search and Filter Pro query parameters #828

Closed nbeversl closed 5 years ago

nbeversl commented 5 years ago

I'm using GeoMashup to make a map of search results from a WordPress query. I don't think it matters for this issue I'm posting, but the website utilizes Search and Filter Pro to get the search results. Search and Filter Pro will return a WP query object for cases like this when passing search results to another plugin. I was getting an error (this same one) using that feature, so I eliminated possible interaction between the two plugins by directly accessing the search data and manually building a WordPress query to pass to GeoMashup. My code looks like this:

// Get search parameters from other plugin $categories = $sf_current_query->get_field_string("_sft_category"); $categories = str_replace('Categories: ', '', $categories); $search_terms = $sf_current_query->get_search_term(); // Make new query $map_args = array( 's' => $search_terms, 'cat' => $categories) $map_query = new WP_Query ($map_args); // Show Geomashup Map echo GeoMashup::map([ 'map_content' => $map_query, 'show_future' => True, ]);

Most of the time, though not all of the time, instead of getting a map I get this:

screen shot 2018-12-02 at 4 21 04 pm

Inspecting the HTML, it appears that characters are being escaped with backward slashes like so:

<iframe name="\&quot;gm-map-1\&quot;" src="\&quot;https:\/\/website.com\/?geo_mashup_content=render-map&amp;map_data_key=6669c66d9609d8f9a1821e6928f3c584&amp;map_content=global&amp;show_future=1&amp;name=gm-map-1&amp;object_ids=174371529565047,174371529565046,174371529663274,174371529663195,174371529609792,174371529596380,174371529596379,174371529609791,174371529596378,174371529538729,174371529610349,174371529538728,174371529610348,174371529538726,174371529538724,174371529610352,174371529561088,174371529561087,174371529561086,174371529633478&amp;sfid=174371529654519&amp;sf_action=get_data&amp;sf_data=results&amp;_sf_s=some_keyword&amp;post_date=12022018\\\\\\\\\\\\\\\\&quot;\\\\&quot;\&quot;" style="\&quot;position:" absolute;="" top:="" 0;="" left:="" width:="" 100%;="" height:="" border:="" none;="" overflow:="" hidden;\"=""><\/iframe><\/div><\/div>"}</iframe>

... and so on... This is evidently some kind of loop wherein an HTML container gets repeatedly written inside of itself, but I cannot figure out where this is occurring and how to prevent it.

I should also mention I'm putting GeoMashup::map() in an AJAX call ; this is working as expected in every case except when passing a WP_query object to GeoMashup.

cyberhobo commented 5 years ago

I think the search plugin query arguments could be causing this. Try this tag with a direction to ignore those:

echo GeoMashup::map([
'map_content' => $map_query,
'show_future' => true,
'ignore_url' => true,
]);
nbeversl commented 5 years ago

Thank you for the reply. I've just tried that and the issue persists.

Since posting the issue, I did discover a workaround that also points to the search plugin as the cause. Stripping out one of its URL attributes (within the Geomashup iframe URL only of course) prevents the issue:

$map = GeoMashup::map([
     'map_content' => $map_query,
     'show_future' => True,
     ]);
$map = str_replace('sf_data=results', '', $map);  
echo $map;

I've got a support ticket out to the search plugin's developed to try to isolate why this is happening. Glad to try any other fixes you suggest.

cyberhobo commented 5 years ago

One more adjustment to try - Geo Mashup sometimes requires a string instead of a boolean:

echo GeoMashup::map([
'map_content' => $map_query,
'show_future' => true,
'ignore_url' => 'true',
]);
nbeversl commented 5 years ago

Yes, that resolves it. Thank you. Do you suppose this is an anomalous interaction of using these two plugins together, or could this be called an expected behavior? In other words, is there some sort of bug/error in one of the two, or does 'ignore_url' parameter exist exactly to prevent potential conflicts like this?

cyberhobo commented 5 years ago

This is essentially the purpose of the ignore_url parameter. It's a legacy feature of Geo Mashup to pass query parameters from the page URL on to global maps on that page. It should really filter these against a whitelist, that would have prevented this issue.