forked from SimplyRETS/simplyretswp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simply-rets-admin.php
582 lines (564 loc) · 23.8 KB
/
simply-rets-admin.php
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<?php
/*
* simply-rets-admin.php - Copyright (C) 2014-2015 SimplyRETS
* This file provides the logic for the SimplyRETS admin panel settings and features pages.
*
*/
/* Code starts here */
add_action("wp_loaded", array("SrAdminSettings", "createDemoPage"));
add_action("admin_notices", array("SrAdminSettings", "adminMessages"));
class SrAdminSettings {
public static function add_to_admin_menu() {
add_options_page('SimplyRETS Settings'
, 'SimplyRETS'
, 'manage_options'
, 'simplyrets-admin.php'
, array('SrAdminSettings', 'sr_admin_page')
);
}
public static function register_admin_settings() {
register_setting('sr_admin_settings', 'sr_api_name');
register_setting('sr_admin_settings', 'sr_api_key');
register_setting('sr_admin_settings', 'sr_contact_page');
register_setting('sr_admin_settings', 'sr_show_listingmeta');
register_setting('sr_admin_settings', 'sr_show_listing_remarks');
register_setting('sr_admin_settings', 'sr_show_agent_contact');
register_setting('sr_admin_settings', 'sr_listing_gallery');
register_setting('sr_admin_settings', 'sr_show_leadcapture');
register_setting('sr_admin_settings', 'sr_leadcapture_recipient');
register_setting('sr_admin_settings', 'sr_additional_rooms');
register_setting('sr_admin_settings', 'sr_listhub_analytics');
register_setting('sr_admin_settings', 'sr_listhub_analytics_id');
register_setting('sr_admin_settings', 'sr_listhub_analytics_test_events');
register_setting('sr_admin_settings', 'sr_search_map_position');
register_setting('sr_admin_settings', 'sr_permalink_structure');
register_setting('sr_admin_settings', 'sr_google_api_key');
register_setting('sr_admin_settings', 'sr_office_on_thumbnails');
register_setting('sr_admin_settings', 'sr_agent_on_thumbnails');
register_setting('sr_admin_settings', 'sr_thumbnail_idx_image');
register_setting('sr_admin_settings', 'sr_custom_disclaimer');
register_setting('sr_admin_settings', 'sr_custom_no_results_message');
register_setting('sr_admin_settings', 'sr_show_mls_status_text');
register_setting('sr_admin_settings', 'sr_agent_office_above_the_fold');
register_setting('sr_admin_settings', 'sr_show_mls_trademark_symbol');
register_setting('sr_admin_settings', 'sr_disable_listing_details_map');
}
public static function adminMessages () {
$page_created = get_option("sr_demo_page_created", false);
$show_msg = get_option("sr_show_admin_message", true);
if($page_created OR !$show_msg) {
return;
} else {
$notice = SimplyRetsCustomPostPages::onActivationNotice();
echo $notice;
}
}
public static function createDemoPage() {
if(isset( $_POST['sr_create_demo_page'])) {
$demo_post = array(
"post_content" => "[sr_map_search search_form=\"true\" list_view=\"true\"]",
"post_name" => "simplyrets-listings",
"post_title" => "SimplyRETS Demo Page",
"post_status" => "publish",
"post_type" => "page"
);
$post_id = wp_insert_post($demo_post);
$permalink = get_post_permalink($post_id);
update_option("sr_demo_page_created", true);
wp_redirect($permalink);
exit();
} else if(isset( $_POST['sr_dismiss_admin_msg'])) {
update_option("sr_show_admin_message", false);
} else {
return;
}
}
public static function sr_admin_page() {
global $wpdb;
$logo_path = plugin_dir_url(__FILE__) . 'assets/img/logo_button.png';
// update meta data fields manually
if( isset( $_POST['sr_update_meta'] ) ) {
echo '<div id="setting-error-settings_updated" class="updated settings-error notice is-dismissible">'.
'<p><strong>Meta Data Updated!</strong></p>'.
'<button type="button" class="notice-dismiss">'.
'<span class="screen-reader-text">Dismiss this notice.</span></button></div>';
SimplyRetsApiHelper::srUpdateAdvSearchOptions();
}
// Custom POST handler for updating the custom disclaimer
// so we can properly sanitize the input.
if (isset( $_POST['sr_custom_disclaimer'] )) {
update_option('sr_custom_disclaimer', htmlentities(stripslashes($_POST['sr_custom_disclaimer'])));
}
// Custom POST handler for updating the custom disclaimer
// so we can properly sanitize the input.
if (isset( $_POST['sr_custom_no_results_message'] )) {
update_option(
'sr_custom_no_results_message',
htmlentities(stripslashes($_POST['sr_custom_no_results_message']))
);
}
?>
<div class="wrap sr-admin-wrap">
<h2 id="message"></h2>
<img class="sr-admin-logo" src="<?php echo $logo_path; ?>">
<h1 class="sr-admin-title">SimplyRETS Admin Settings</h1>
<div class="sr-doc-links">
<p>
<a target="_blank" href="http://simplyrets.com">
simplyrets.com
</a> |
<a target="_blank" href="https://wordpress.org/plugins/simply-rets/other_notes/">
Plugin Docs
</a> |
<a target="_blank" href="http://docs.simplyrets.com">
API Docs
</a> |
<a target="_blank" href="http://status.simplyrets.com">
Service Status
</a> |
<a target="_blank" href="https://simplyrets.com/account">
Support Request
</a>
<form method="post" action="options-general.php?page=simplyrets-admin.php" style="display:inline-block;">
<?php submit_button( "Refresh Meta Data", "submit", "sr_update_meta", 0 ); ?>
</form>
<form method="post" action="options-general.php?page=simplyrets-admin.php" style="display:inline-block;">
<?php submit_button( "Create Demo Page", "submit", "sr_create_demo_page", 0 ); ?>
</form>
</p>
</div>
<hr>
<form method="post" action="options.php">
<?php settings_fields( 'sr_admin_settings'); ?>
<?php do_settings_sections( 'sr_admin_settings'); ?>
<div class="sr-admin-api">
<h2>Account Credentials</h2>
<p>
Enter your SimplyRETS API credentials in the fields below.
</p>
<table>
<tbody>
<tr>
<td>
<strong>API Key</strong>
</td>
<td>
<input type="text" name="sr_api_name" value="<?php echo esc_attr( get_option('sr_api_name') ); ?>" />
</td>
</tr>
<tr>
<td>
<strong>API Secret</strong>
</td>
<td>
<input type="text" name="sr_api_key" value="<?php echo esc_attr( get_option('sr_api_key') ); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
<div>
<span>
<i>Note - to use the SimplyRETS demo data, you can use these API credentials: </i>
<strong>API Key: </strong><span>simplyrets</span>
<strong>API Secret: </strong><span>simplyrets</span>
</span>
<div>
<?php submit_button(); ?>
<hr>
<div class="sr-admin-settings">
<h2>Single Listing Page Settings</h2>
<h3>Contact Form Lead Capture</h3>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_leadcapture" name="sr_show_leadcapture" value="1" '
. checked(1, get_option('sr_show_leadcapture'), false) . '/>'
?>
Enable Contact Form Lead Capture on single listing pages?
</label>
</td>
</tr>
<tr>
<td>
<p><strong>Send Lead Capture forms submissions to:<p></strong>
<input type="email" name="sr_leadcapture_recipient" value="<?php echo esc_attr( get_option('sr_leadcapture_recipient') ); ?>" />
</td>
</tr>
</tbody>
</table>
<h3>Map settings</h3>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_disable_listing_details_map" name="sr_disable_listing_details_map" value="1" '
. checked(1, get_option('sr_disable_listing_details_map'), false) . '/>'
?>
Disable map view on listing details page
</label>
</td>
</tr>
</tbody>
</table>
<h3>Show/Hide Fields</h3>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_listingmeta" name="sr_show_listingmeta" value="1" '
. checked(1, get_option('sr_show_listingmeta'), false) . '/>'
?>
Hide 'Listing Meta Information' fields from property details?
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_agent_contact" name="sr_show_agent_contact" value="1" '
. checked(1, get_option('sr_show_agent_contact'), false) . '/>'
?>
Do not show Agent and Office phone number and email address (names are still shown).
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_listing_remarks" name="sr_show_listing_remarks" value="1" '
. checked(1, get_option('sr_show_listing_remarks'), false) . '/>'
?>
Hide 'Listing Remarks' (description) field from property details?
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_additional_rooms" name="sr_additional_rooms" value="1" '
. checked(1, get_option('sr_additional_rooms'), false) . '/>'
?>
Show additional room details?
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_mls_status_text" name="sr_show_mls_status_text" value="1" '
. checked(1, get_option('sr_show_mls_status_text'), false) . '/>'
?>
Show MLS status text if available (in place of standardized status)?
</label>
</td>
</tr>
</tbody>
</table>
<h3>Image Gallery Settings</h3>
<table>
<tbody>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_listing_gallery" name="sr_listing_gallery" value="fancy" '
. checked('fancy', get_option('sr_listing_gallery'), false) . '/>'
?>
Fancy Gallery
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_listing_gallery" name="sr_listing_gallery" value="classic" '
. checked('classic', get_option('sr_listing_gallery'), false) . '/>'
?>
Classic Gallery
</label>
</td>
</tr>
</tbody>
</table>
</div>
<?php submit_button(); ?>
<hr>
<div class="sr-admin-settings">
<h2>Listing Compliance Settings</h2>
<h3>Show listing agent and office information</h3>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_office_on_thumbnails" name="sr_office_on_thumbnails" value="1" '
. checked(1, get_option('sr_office_on_thumbnails'), false) . '/>'
?>
Show listing office name on listing summary thumbnails
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_agent_on_thumbnails" name="sr_agent_on_thumbnails" value="1" '
. checked(1, get_option('sr_agent_on_thumbnails'), false) . '/>'
?>
Show listing agent name on listing summary thumbnails
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_agent_office_above_the_fold" name="sr_agent_office_above_the_fold" value="1" '
. checked(1, get_option('sr_agent_office_above_the_fold'), false) . '/>'
?>
Show Listing Agent and Office above the fold on single listing pages
</label>
</td>
</tr>
<tr>
<td>
<p>IDX image for listing thumbnails <i>(enter a URL)</i>: </p>
</td>
<td>
<input
type="text"
name="sr_thumbnail_idx_image"
value="<?php echo esc_attr( get_option('sr_thumbnail_idx_image') ); ?>"
/>
</td>
</tr>
</tbody>
</table>
<h3>MLS trademark symbol</h3>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_show_mls_trademark_symbol" name="sr_show_mls_trademark_symbol" value="1" '
. checked(1, get_option('sr_show_mls_trademark_symbol'), false) . '/>'
?>
Show trademark symbol next to MLS text (eg, "MLS®")
</label>
</td>
</tr>
</tbody>
</table>
</div>
<?php submit_button(); ?>
<hr>
<div class="sr-admin-settings-permalinks">
<h2>Permalink Structure</h2>
<p>
If you're using Wordpress' pretty permalinks, we have
a few different options you can choose from for single
listing pages.
</p>
<table>
<tbody>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_permalink_structure" name="sr_permalink_structure" value="pretty" '
. checked('pretty', get_option('sr_permalink_structure'), false) . '/>'
?>
Basic Pretty Links <i>(Ex: "/listings/{id}/{address})</i>
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_permalink_structure" name="sr_permalink_structure" value="pretty_extra" '
. checked('pretty_extra', get_option('sr_permalink_structure'), false) . '/>'
?>
Pretty Links Extra <i>(Ex: "/listings/{city}/{state}/{zip}/{address}/{id}
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_permalink_structure" name="sr_permalink_structure" value="query_string" '
. checked('query_string', get_option('sr_permalink_structure'), false) . '/>'
?>
Query String Links <i>(Ex: "/?sr-listings=sr-single&address={address}&listing_id={id}")</i>
</label>
</td>
</tr>
</tbody>
</table>
</div>
<?php submit_button(); ?>
<hr>
<div class="sr-admin-settings-map">
<h2>Map Settings</h2>
<p>On pages with multiple results, how would you like to show the map and list views?</p>
<table>
<tbody>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_search_map_position" name="sr_search_map_position" value="list_only" '
. checked('list_only', get_option('sr_search_map_position'), false) . '/>'
?>
Only Show List View
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_search_map_position" name="sr_search_map_position" value="map_only" '
. checked('map_only', get_option('sr_search_map_position'), false) . '/>'
?>
Only Show Map View
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_search_map_position" name="sr_search_map_position" value="map_above" '
. checked('map_above', get_option('sr_search_map_position'), false) . '/>'
?>
Show Map View Above List View
</label>
</td>
</tr>
<tr>
<td>
<label>
<?php echo
'<input type="radio" id="sr_search_map_position" name="sr_search_map_position" value="map_below" '
. checked('map_below', get_option('sr_search_map_position'), false) . '/>'
?>
Show Map View Below List View
</label>
</td>
</tr>
<tr>
<td>
<br/>
<strong>Google Maps API Key</strong>
<br>
<i>(Required for maps. Get one <a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,places_backend&keyType=CLIENT_SIDE&reusekey=true" target="_blank">here</a>.)</i>
</td>
<td>
<input type="text" name="sr_google_api_key" value="<?php echo esc_attr( get_option('sr_google_api_key') ); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
<?php submit_button(); ?>
<hr>
<div class="sr-admin-settings-lh">
<h2>Listhub Analytics Settings</h2>
<table>
<tbody>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_listhub_analytics" name="sr_listhub_analytics" value="1" '
. checked(1, get_option('sr_listhub_analytics'), false) . '/>'
?>
Enable Listhub Analytics? <i>(requires an account with Listhub)</i>
</label>
</td>
</tr>
<tr>
<td colspan="2">
<label>
<?php echo
'<input type="checkbox" id="sr_listhub_analytics_test_events" name="sr_listhub_analytics_test_events" value="1" '
. checked(1, get_option('sr_listhub_analytics_test_events'), false) . '/>'
?>
Send test events to ListHub <i>(disable for live events)</i>
</label>
</td>
</tr>
<tr>
<td>
<strong>Metrics Provider ID</strong><br><i> (provided by Listhub)</i>
</td>
<td>
<input type="text" name="sr_listhub_analytics_id" value="<?php echo esc_attr( get_option('sr_listhub_analytics_id') ); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
<?php submit_button(); ?>
</form>
<hr>
<div>
<h3>Custom disclaimer</h3>
<p>Custom disclaimer to be shown with all short-codes</p>
<form method="post" action="options-general.php?page=simplyrets-admin.php">
<textarea
id="sr_custom_disclaimer"
name="sr_custom_disclaimer"
cols="50"
rows="8"><?php echo esc_attr( get_option('sr_custom_disclaimer') ); ?></textarea>
<ul>
<li>
- Use the variable "{lastUpdate}" to interpolate
the time of the last feed update.
</li>
<li>
- You can use HTML or plain text.
</li>
</ul>
<?php submit_button(); ?>
</form>
</div>
<div>
<h3>No search results message</h3>
<p>The messasge shown when a search doesn't return results.</p>
<form method="post" action="options-general.php?page=simplyrets-admin.php">
<textarea
id="sr_custom_no_results_message"
name="sr_custom_no_results_message"
cols="50"
rows="5"><?php echo esc_attr( get_option('sr_custom_no_results_message') ); ?></textarea>
<div>
<i>
Default: There are 0 listings that match this
search. Try broadening your search criteria or
try again later.
</i>
</div>
<?php submit_button(); ?>
</form>
</div>
<?php
}
} ?>