forked from SimplyRETS/simplyretswp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimply-rets-maps.php
More file actions
166 lines (137 loc) · 4.34 KB
/
simply-rets-maps.php
File metadata and controls
166 lines (137 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
*
* simply-rets-maps.php - Copyright (C) 2014-2015 SimplyRETS
* This file provides the logic for the simply-rets custom post type pages.
*
*/
add_action('wp_head',
array('SrSearchMap', 'defineAjaxUrl'));
add_action('wp_ajax_nopriv_update_int_map_data',
array('SrSearchMap', 'update_int_map_data'));
add_action('wp_ajax_update_int_map_data',
array('SrSearchMap', 'update_int_map_data'));
/* Code starts here */
use Ivory\GoogleMap\Map;
use Ivory\GoogleMap\Helper\MapHelper;
use Ivory\GoogleMap\MapTypeId;
use Ivory\GoogleMap\Overlays\Animation;
use Ivory\GoogleMap\Overlays\Marker;
use Ivory\GoogleMap\Overlays\InfoWindow;
use Ivory\HttpAdapter\CurlHttpAdapter;
class SrSearchMap
{
public static function mapWithDefaults()
{
$map = new Map();
$map->setAsync(true);
$map->setHtmlContainerId('sr_map_canvas');
$map->setStylesheetOptions(array(
'width' => '100%',
'height' => '550px'
));
// Set API key if user has added one.
$apik = get_option('sr_google_api_key');
if (!empty($apik)) {
$map->setApiKey($apik);
}
return $map;
}
public static function markerWithDefaults()
{
$marker = new Marker();
$marker->setPrefixJavascriptVariable('marker_');
$marker->setOptions(array(
'clickable' => true
));
return $marker;
}
public static function infoWindowWithDefaults()
{
$iw = new InfoWindow();
$iw->setAutoClose(true);
$iw->setPrefixJavascriptVariable('info_window_');
$iw->setOpenEvent('click');
return $iw;
}
public static function srMapHelper()
{
return new MapHelper();
}
public static function infoWindowMarkup(
$link,
$photo,
$address,
$price,
$beds,
$baths,
$status,
$mlsid,
$propType,
$area,
$style,
$compliance_markup
) {
$markup = <<<HTML
<div class="sr-iw-inner">
<h4 class="sr-iw-addr">$address<small> $price</small></h4>
<div class="sr-iw-inner__img">
<a href='$link'>
<img id="sr-iw-inner__img-img" src='$photo'>
</a>
</div>
<div class="sr-iw-inner__primary">
<p>$beds Bed | $baths Bath | $status </p>
</div>
<hr>
<div class="sr-iw-inner__secondary">
<p><strong>MLS #:</strong> $mlsid</p>
<p><strong>Area:</strong> $area SqFt</p>
<p><strong>Property Type:</strong> $propType</p>
<p><strong>Property Style:</strong> $style</p>
$compliance_markup
</div>
<hr>
<div class="sr-iw-inner__view-details">
<a href='$link' class='sr-iw-inner__details-link'>View Details</a>
</div>
</div>
HTML;
return $markup;
}
public static function defineAjaxUrl()
{
?>
<script>
var sr_ajaxUrl = "<?php echo admin_url('admin-ajax.php'); ?>"
</script>
<?php
}
public static function update_int_map_data()
{
// Ensure we only capture SimplyRETS requests
if (array_key_exists('action', $_POST)
&& $_POST['action'] === "update_int_map_data") {
$permalink_struct = get_option('permalink_structure');
$showStatusText = get_option('sr_show_mls_status_text', false);
$site_root = get_site_url();
header("Content-Type: application/json");
$markup_opts = array(
"show_map" => "false"
);
$req = SimplyRetsApiHelper::makeApiRequest("?".$_POST['parameters']);
// We don't need this right now.
// $con = SimplyRetsApiHelper::srResidentialResultsGenerator($req, $markup_opts);
$response = array(
"result" => $req,
"markup" => $con,
"post" => $_POST,
"permalink_structure" => $permalink_struct,
"show_mls_status_text" => $showStatusText,
"site_root" => $site_root
);
wp_send_json($response);
}
return;
}
}