PluginProbe
Flexmls® IDX Plugin / 2.3
Flexmls® IDX Plugin v2.3
4.0.1 4.0.0 3.18.2 trunk 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 2.4.2 3.0.0 3.0.1 3.0.10 3.0.11 All 157 releases
flexmls-idx / lib / base.php

base.php in Flexmls® IDX Plugin 2.3, at lib/base.php

1,187 lines 32.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 class flexmlsConnect {
5
6
7 function __construct() {
8
9 }
10
11
12 function initial_init() {
13 global $fmc_plugin_url;
14
15 if (!is_admin()) {
16
17 wp_enqueue_script('jquery');
18
19 wp_register_script('fmc_connect', $fmc_plugin_url .'/includes/connect.min.js', array('jquery'));
20 wp_enqueue_script('fmc_connect');
21
22 wp_register_style('fmc_connect', $fmc_plugin_url .'/includes/connect.min.css');
23 wp_enqueue_style('fmc_connect');
24
25 if (flexmlsConnect::is_ie() && flexmlsConnect::ie_version() < 9) {
26 wp_register_script('fmc_excanvas', $fmc_plugin_url .'/includes/excanvas.min.js');
27 wp_enqueue_script('fmc_excanvas');
28 }
29
30 }
31 else {
32
33 wp_enqueue_script('jquery-ui-core');
34 wp_enqueue_script('jquery-ui-sortable');
35
36 wp_register_script('fmc_connect', $fmc_plugin_url .'/includes/connect_admin.min.js', array('jquery','jquery-ui-core'));
37 wp_enqueue_script('fmc_connect');
38
39 wp_register_style('fmc_connect', $fmc_plugin_url .'/includes/connect_admin.min.css');
40 wp_enqueue_style('fmc_connect');
41
42 wp_register_style('fmc_jquery_ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/ui-lightness/jquery-ui.css');
43 wp_enqueue_style('fmc_jquery_ui');
44
45 }
46
47 wp_localize_script('fmc_connect', 'fmcAjax', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'pluginurl' => $fmc_plugin_url ) );
48
49 add_shortcode("idx_frame", array('flexmlsConnect', 'shortcode'));
50
51 }
52
53
54 function widget_init() {
55 // Load all of the widgets we need for the plugin.
56
57 global $fmc_plugin_dir;
58 global $fmc_widgets;
59
60 foreach ($fmc_widgets as $class => $wdg) {
61 if ( file_exists($fmc_plugin_dir . "/components/{$wdg['component']}") ) {
62 require_once($fmc_plugin_dir . "/components/{$wdg['component']}");
63
64 $meets_key_reqs = false;
65 if ($wdg['requires_key'] == false || ($wdg['requires_key'] == true && flexmlsConnect::has_api_saved())) {
66 $meets_key_reqs = true;
67 }
68
69 if ( class_exists($class, false) && $meets_key_reqs && $wdg['widget'] == true) {
70 register_widget($class);
71 }
72 if ($wdg['widget'] == false) {
73 new $class();
74 }
75 }
76 }
77
78 // register where the AJAX calls should be routed when they come in
79 add_action('wp_ajax_fmcShortcodeContainer', array('flexmlsConnect', 'shortcode_container') );
80
81 }
82
83
84 function plugin_deactivate() {
85
86 flexmlsConnect::clear_temp_cache();
87 delete_transient('fmc_api');
88
89 }
90
91
92 function plugin_activate() {
93
94 flexmlsConnect::clear_temp_cache();
95 $options = get_option('fmc_settings');
96
97 if ($options === false) {
98 // plugin install is brand new
99
100 $new_page = array(
101 'post_title' => "Search",
102 'post_content' => "[idx_frame width='100%' height='600']",
103 'post_type' => 'page',
104 'post_status' => 'publish'
105 );
106
107 $new_page_id = wp_insert_post($new_page);
108
109 $options = array(
110 'default_titles' => true,
111 'destpref' => 'page',
112 'destlink' => $new_page_id,
113 'autocreatedpage' => $new_page_id,
114 'contact_notifications' => true
115 );
116
117 add_option('fmc_settings', $options);
118
119 }
120 else {
121 // plugin is only be re-activated with previous settings.
122 }
123
124 }
125
126
127 function admin_menus_init() {
128
129 // check if the user is able to manage options. if not, boot them out
130 if ( !function_exists('current_user_can') || !current_user_can('manage_options') ) {
131 return;
132 }
133
134 if ( function_exists('add_options_page') ) {
135 add_options_page('flexmls&reg; IDX Settings', 'flexmls&reg; IDX', 'manage_options', 'flexmls_connect', array('flexmlsConnect', 'settings_page') );
136 }
137
138 add_submenu_page('edit.php?post_type=page','Add New Neighborhood Page', 'Add Neighborhood', 'manage_options', 'flexmls_connect', array('flexmlsConnect', 'neighborhood_page') );
139
140 }
141
142 function neighborhood_page() {
143 echo "<div class='wrap'>\n";
144 screen_icon('page');
145 echo "<h2>flexmls&reg; IDX: Add New Neighborhood Page</h2>\n";
146
147 if ($_REQUEST['action'] == "save") {
148
149 if (empty($_REQUEST['template'])) {
150 $_REQUEST['template'] = "default";
151 }
152
153 $loc = flexmlsConnect::parse_location_search_string( flexmlsConnect::unescape_request_var($_REQUEST['location']) );
154 $loc_title = $loc[0]['l'];
155 $loc_raw = $loc[0]['r'];
156
157 $shortcode = "[neighborhood_page title=\"{$loc_title}\" location=\"{$loc_raw}\" template=\"{$_REQUEST['template']}\"]";
158
159 $new_page = array(
160 'post_title' => "{$loc_title}",
161 'post_content' => $shortcode,
162 'post_type' => 'page',
163 'post_status' => 'publish',
164 'post_parent' => $_REQUEST['parent']
165 );
166
167 $new_page_id = wp_insert_post($new_page);
168
169 $template_page_template = get_post_meta( flexmlsConnect::get_neighborhood_template_id($_REQUEST['template']), '_wp_page_template', true );
170 update_post_meta( $new_page_id, '_wp_page_template', $template_page_template);
171
172 echo "<p><b>Congratulations!</b> You just created a new neighborhood page. Now what?</p>";
173
174 echo "<p>";
175 echo "<a href='edit.php?post_type=page&page=flexmls_connect'>Create Another</a> &nbsp; or &nbsp; ";
176 echo "<a href='post.php?post={$new_page_id}&action=edit'>Edit Your New Page</a>";
177 echo "</p>";
178
179 }
180 else {
181
182 echo "<p>To create a new neighborhood page automatically, select your location and template below.</p>";
183 echo "<p>&nbsp;</p>";
184 echo "<h3>Neighborhood Page Details</h3>";
185
186 echo "<form action='edit.php?post_type=page&page=flexmls_connect' method='post'>\n";
187 echo "<input type='hidden' name='action' value='save' />";
188
189 $fmc_api = new flexmlsApiWP();
190 $api_system_info = $fmc_api->SystemInfo();
191 $api_location_search_api = $fmc_api->GetLocationSearchApiUrl();
192
193 echo "
194
195 <p>
196 <label for='parent'>Parent Page:</label>
197 ";
198
199 $args = array(
200 'name' => 'parent',
201 'post_status' => 'publish',
202 'echo' => true,
203 'show_option_none' => __('(no parent)')
204 );
205
206 wp_dropdown_pages($args);
207
208
209 echo "
210
211 </p>
212
213 <p>
214 <label for='template'>Neighborhood Template:</label>
215 ";
216
217
218 $args = array(
219 'name' => 'template',
220 'post_status' => 'draft',
221 'echo' => false,
222 'show_option_none' => '(Use Saved Default)'
223 );
224
225 $page_selection = wp_dropdown_pages($args);
226 if (!empty($page_selection)) {
227 echo $page_selection;
228 }
229 else {
230 echo "Please create a page as a draft to select it here.";
231 }
232
233 echo "
234 </p>
235
236 <div class='flexmls_connect__location'>
237 <p>
238 <label for='location'>Location:</label>
239 <input type='text' name='location_input' data-connect-url='{$api_location_search_api}' class='flexmls_connect__location_search' autocomplete='off' value='City, Postal Code, etc.' />
240 <a href='javascript:void(0);' title='Click here to browse through available locations' class='flexmls_connect__location_browse'>Browse &raquo;</a>
241 <div class='flexmls_connect__location_list' data-connect-multiple='false'>
242 <p>All Locations Included</p>
243 </div>
244 <input type='hidden' name='tech_id' class='flexmls_connect__tech_id' value=\"x'{$api_system_info['Id']}'\" />
245 <input type='hidden' name='ma_tech_id' class='flexmls_connect__ma_tech_id' value=\"x'{$api_system_info['MlsId']}'\" />
246 <input fmc-field='location' fmc-type='text' type='hidden' name='location' class='flexmls_connect__location_fields' value=\"\" />
247 <select style='display:none;' fmc-field='property_type' class='flexmls_connect__property_type' fmc-type='select' id='property_type' name='property_type'>
248 <option value='A' selected='selected'></option>
249 </select>
250 </p>
251 </div>
252
253 <img src='x' class='flexmls_connect__bootloader' onerror='flexmls_connect.location_setup(this);' />
254 ";
255
256
257 echo "<br/><input type='submit' value='Create Page' />\n";
258
259 echo "</form>\n";
260
261 }
262
263 echo "</div>\n";
264 }
265
266 function filter_mce_button($buttons) {
267 array_push( $buttons, '|', 'fmc_button' );
268 return $buttons;
269 }
270
271 function filter_mce_plugin($plugins) {
272 global $fmc_plugin_url;
273 $plugins['fmc'] = $fmc_plugin_url . '/includes/tinymce_plugin.min.js';
274 return $plugins;
275 }
276
277
278 function shortcode_container() {
279 global $fmc_widgets;
280
281 $return = '';
282
283 $return .= "<div id='fmc_box_body'>";
284 $return .= "<ul class='flexmls_connect__widget_menu'>\n";
285
286 foreach ($fmc_widgets as $class => $widg) {
287 $short_title = str_replace("flexmls&reg;: ", "", $widg['title']);
288 $return .= "<li class='flexmls_connect__widget_menu_item'><a class='fmc_which_shortcode' data-connect-shortcode='{$class}' style='cursor:pointer;'>{$short_title}</a></li>\n";
289 }
290 $return .= "</ul>\n";
291
292 $return .= "<div id='fmc_shortcode_window_content'><p class='first'>please select a widget to the left</p></div>";
293
294 $return .= "</div>";
295
296 $response['title'] = "";
297 $response['body'] = $return;
298 $js = new Moxiecode_JSON();
299 echo str_replace("\'", "'", $js->encode($response));
300 exit;
301 }
302
303
304 // called to put the start of the form on the shortcode generator page
305 function shortcode_header() {
306 $return = "\n\n";
307 $return .= "<form fmc-shortcode-form='true'>\n";
308
309 return $return;
310 }
311
312 // called to put the end of the form and submit button on the shortcode generator page
313 function shortcode_footer() {
314 $return = "";
315 $return .= "<p><input type='button' class='fmc_shortcode_submit button-primary' value='Insert Widget' /></p>\n";
316 $return .= "</form>\n";
317
318 $return .= "\n\n";
319
320 return $return;
321 }
322
323
324 function settings_init() {
325
326 if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
327 add_filter( 'mce_buttons', array('flexmlsConnect', 'filter_mce_button' ) );
328 add_filter( 'mce_external_plugins', array('flexmlsConnect', 'filter_mce_plugin' ) );
329 }
330
331 // register our settings with WordPress so it can automatically handle saving them
332 register_setting('fmc_settings_group', 'fmc_settings', array('flexmlsConnect', 'settings_validate') );
333
334 // add a section called fmc_settings_api to the settings page
335 add_settings_section('fmc_settings_api', '<br/>API Settings', array('flexmlsConnect', 'settings_overview_api') , 'flexmls_connect');
336
337 // add some setting fields to the fmc_settings_api section of the settings page
338 add_settings_field('fmc_api_key', 'API Key', array('flexmlsConnect', 'settings_field_api_key') , 'flexmls_connect', 'fmc_settings_api');
339 add_settings_field('fmc_api_secret', 'API Secret', array('flexmlsConnect', 'settings_field_api_secret') , 'flexmls_connect', 'fmc_settings_api');
340 add_settings_field('fmc_clear_cache', 'Clear Cache?', array('flexmlsConnect', 'settings_field_clear_cache') , 'flexmls_connect', 'fmc_settings_api');
341
342 add_settings_section('fmc_settings_plugin', '<br/>Plugin Behavior', array('flexmlsConnect', 'settings_overview_plugin') , 'flexmls_connect');
343 add_settings_field('fmc_default_titles', 'Use Default Widget Titles', array('flexmlsConnect', 'settings_field_default_titles') , 'flexmls_connect', 'fmc_settings_plugin');
344 add_settings_field('fmc_destlink', 'Open IDX Links', array('flexmlsConnect', 'settings_field_destlink') , 'flexmls_connect', 'fmc_settings_plugin');
345 add_settings_field('fmc_default_link', 'Default IDX Link', array('flexmlsConnect', 'settings_field_default_link') , 'flexmls_connect', 'fmc_settings_plugin');
346 add_settings_field('fmc_neigh_template', 'Neighborhood Page Template', array('flexmlsConnect', 'settings_field_neigh_template') , 'flexmls_connect', 'fmc_settings_plugin');
347 add_settings_field('fmc_contact_notifications', 'When a new lead is created', array('flexmlsConnect', 'settings_field_contact_notifications') , 'flexmls_connect', 'fmc_settings_plugin');
348
349 }
350
351
352 function settings_page() {
353
354 // put the settings page together
355
356 $options = get_option('fmc_settings');
357
358 echo "<div class='wrap'>\n";
359 screen_icon('options-general');
360 echo "<h2>flexmls&reg; IDX Settings</h2>\n";
361
362 echo "<form action='options.php' method='post'>\n";
363
364 settings_fields('fmc_settings_group');
365 do_settings_sections('flexmls_connect');
366
367 echo "<p class='submit'><input type='submit' name='Submit' type='submit' class='button-primary' value='" .__('Save Settings'). "' />\n";
368
369 echo "</form>\n";
370 echo "</div>\n";
371
372 }
373
374
375 function settings_validate($input) {
376 $options = get_option('fmc_settings');
377
378 foreach ($input as $key => $value) {
379 $input[$key] = trim($value);
380 }
381
382 if ($options['api_key'] != $input['api_key'] || $options['api_secret'] != $input['api_secret']) {
383 $input['clear_cache'] = "y";
384 }
385
386 $options['api_key'] = trim($input['api_key']);
387 $options['api_secret'] = trim($input['api_secret']);
388
389 if ($input['clear_cache'] == "y") {
390 // since clear_cache is checked, wipe out the contents of the fmc_cache_* transient items
391 // but don't do anything else since we aren't saving the state of this particular checkbox
392
393 flexmlsConnect::clear_temp_cache();
394 }
395
396 if ($input['default_titles'] == "y") {
397 $options['default_titles'] = true;
398 }
399 else {
400 $options['default_titles'] = false;
401 }
402
403 $options['destpref'] = $input['destpref'];
404 $options['destlink'] = $input['destlink'];
405 $options['destwindow'] = $input['destwindow'];
406 $options['default_link'] = $input['default_link'];
407 $options['neigh_template'] = $input['neigh_template'];
408
409 if ($input['contact_notifications'] == "y") {
410 $options['contact_notifications'] = true;
411 }
412 else {
413 $options['contact_notifications'] = false;
414 }
415
416 return $options;
417
418 }
419
420
421 function settings_overview_api() {
422 if (flexmlsConnect::has_api_saved() == false) {
423 echo "<p>Please call FBS Broker Agent Services at 800-437-4232, ext. 108, or email <a href='mailto:idx@flexmls.com'>idx@flexmls.com</a> to purchase a key to activate your plugin.</p>";
424 }
425 }
426
427 function settings_overview_plugin() {
428 //echo "<p>Tweak how the flexmls&reg; Connect plugin behaves.</p>";
429 }
430
431 function settings_overview_helpful() {
432 echo "<p>Here is some information you may find helpful.</p>";
433 }
434
435 function settings_field_api_key() {
436 global $fmc_plugin_url;
437 $options = get_option('fmc_settings');
438
439 $api_status_info = "";
440
441 if (flexmlsConnect::has_api_saved()) {
442 $fmc_api = new flexmlsApiWP;
443 $api_auth = $fmc_api->Authenticate(true);
444
445 if ($api_auth === false) {
446 $api_status_info = " <img src='{$fmc_plugin_url}/images/error.png'> Error with entered info";
447 }
448 else {
449 $api_status_info = " <img src='{$fmc_plugin_url}/images/accept.png'> It works!";
450 }
451 }
452
453 echo "<input type='text' id='fmc_api_key' name='fmc_settings[api_key]' value='{$options['api_key']}' size='16' maxlength='32' />{$api_status_info}\n";
454 }
455
456 function settings_field_api_secret() {
457 $options = get_option('fmc_settings');
458 echo "<input type='password' id='fmc_api_secret' name='fmc_settings[api_secret]' value='{$options['api_secret']}' size='14' maxlength='25' />\n";
459 }
460
461 function settings_field_default_titles() {
462 $options = get_option('fmc_settings');
463
464 $checked = "";
465
466 if ($options['default_titles'] == true) {
467 $checked_yes = " checked='checked'";
468 }
469 else {
470 $checked_no = " checked='checked'";
471 }
472
473 echo "<label><input type='radio' name='fmc_settings[default_titles]' value='y'{$checked_yes} /> Yes</label> &nbsp; ";
474 echo "<label><input type='radio' name='fmc_settings[default_titles]' value='n'{$checked_no} /> No</label><br />\n";
475 echo "<span class='description'>Use the default widget titles when no title is entered.</span>\n";
476 }
477
478 function settings_field_clear_cache() {
479 // stale option that doesn't pay attention to any saved option. this simply triggers the cache clearing
480 echo "<label><input type='checkbox' name='fmc_settings[clear_cache]' value='y' /> Clear the cached flexmls&reg; API responses</label>\n";
481 }
482
483
484 function settings_field_destlink() {
485 $options = get_option('fmc_settings');
486
487 $args = array(
488 'name' => 'fmc_settings[destlink]',
489 'selected' => $options['destlink']
490 );
491
492 $checked_code = " checked='checked'";
493
494 if ($options['destpref'] == "own") {
495 $checked_own = $checked_code;
496 }
497 elseif ($options['destpref'] == "page") {
498 $checked_page = $checked_code;
499 }
500 else {
501 $checked_own = $checked_code;
502 }
503
504 if ($options['destwindow'] == "new") {
505 $checked_new = $checked_code;
506 }
507
508 echo "<label><input type='checkbox' name='fmc_settings[destwindow]' value='new'{$checked_new} /> in a new window</label>";
509 echo "<br />\n";
510 echo "<br />\n";
511 echo "<label><input type='radio' name='fmc_settings[destpref]' value='own'{$checked_own} /> separate from WordPress</label><br />\n";
512 echo "<label><input type='radio' name='fmc_settings[destpref]' value='page'{$checked_page} /> framed within a WordPress page (select below)</label><br />\n";
513 echo "&nbsp; &nbsp; &nbsp; Page: ";
514 wp_dropdown_pages($args);
515 echo "<br/>";
516 echo "&nbsp; &nbsp; &nbsp; <span class='description'><a href='#' id='idx_frame_shortcode_docs_link'>View the documentation</a> for more details on how this works.</span> ";
517
518 echo "<div id='idx_frame_shortcode_docs' style='display: none; margin-left: 23px; width: 700px;'>";
519 echo "<p>In order for this feature to work, the page you point your links to must have the following shortcode in the body of the page:</p>";
520 echo "<blockquote><pre>[idx_frame width='100%' height='600']</pre></blockquote>";
521 echo "<p>By using this shortcode, it allows the flexmls&reg; IDX plugin to catch links and show the appropriate pages to your users. If the page with this shortcode is viewed and no link is provided, the 'Default IDX Link' (below) will be displayed.</p>";
522 echo "<p><b>Note:</b> When you activated this plugin, a page with this shortcode in the body <a href='".get_permalink($options['autocreatedpage'])."'>was created automatically</a>.</p>";
523 echo "<p><b>Another Note:</b> If you're using a SEO plugin, you may need to disable Permalink Cleaning for this feature to work.</p>";
524 echo "</div>";
525
526 }
527
528
529 function settings_field_default_link() {
530 $options = get_option('fmc_settings');
531
532 $selected_default_link = $options['default_link'];
533
534 if (flexmlsConnect::has_api_saved()) {
535
536 $fmc_api = new flexmlsApiWP;
537 $api_links = $fmc_api->GetIDXLinks();
538
539 if ($api_links === false) {
540 if ($fmc_api->last_error_code == 1500) {
541 echo "This functionality requires a subscription to flexmls&reg; IDX in order to work. <a href=''>Buy Now</a>.<input type='hidden' name='fmc_settings[default_link]' value='{$selected_default_link}' />";
542 }
543 else {
544 echo "Information not currently available due to API issue.<input type='hidden' name='fmc_settings[default_link]' value='{$selected_default_link}' />";
545 }
546 return;
547 }
548
549 echo "<select name='fmc_settings[default_link]'>\n";
550 foreach ($api_links as $link) {
551 $selected = ($link['LinkId'] == $selected_default_link) ? " selected='selected'" : "";
552 echo "<option value='{$link['LinkId']}'{$selected}>{$link['Name']}</option>\n";
553 }
554 echo "</select>\n";
555 echo "<br/>\n";
556 echo "<span class='description'>Select the default flexmls&reg; IDX link your widgets should use</span>";
557
558 }
559 else {
560 echo "<span class='description'>You must enter API key information to select this option.</span><input type='hidden' name='fmc_settings[default_link]' value='{$selected_default_link}' />";
561 }
562
563 }
564
565
566 function settings_field_neigh_template() {
567 $options = get_option('fmc_settings');
568
569 $selected_neigh_template = $options['neigh_template'];
570
571 $args = array(
572 'name' => 'fmc_settings[neigh_template]',
573 'selected' => $selected_neigh_template,
574 'post_status' => 'draft',
575 'echo' => false
576 );
577
578 $page_selection = wp_dropdown_pages($args);
579 if (!empty($page_selection)) {
580 echo $page_selection;
581 }
582 else {
583 echo "Please create a page as a draft to select it here.";
584 }
585
586 echo "<br/><span class='description'>Select the page to use as your default neighborhood page template.</span>";
587
588 }
589
590
591 function settings_field_contact_notifications() {
592 $options = get_option('fmc_settings');
593
594 $checked_code = " checked='checked'";
595
596 if (!array_key_exists('contact_notifications', $options)) {
597 $checked_yes = $checked_code;
598 }
599 elseif ($options['contact_notifications'] === true) {
600 $checked_yes = $checked_code;
601 }
602 else {
603 $checked_no = $checked_code;
604 }
605
606
607 echo "<label><input type='radio' name='fmc_settings[contact_notifications]' value='y'{$checked_yes} /> Notify me within flexmls&reg;</label> &nbsp; ";
608 echo "<label><input type='radio' name='fmc_settings[contact_notifications]' value='n'{$checked_no} /> Don't send any notification</label><br />\n";
609
610 }
611
612
613 function settings_helpful_proptypes() {
614
615 $fmc_api = new flexmlsApiWP;
616 $api_prop_types = $fmc_api->PropertyTypes();
617 $api_system_info = $fmc_api->SystemInfo();
618
619 if ($api_prop_types === false || $api_system_info === false) {
620 echo "Information not currently available due to API issue.";
621 return;
622 }
623
624 echo "<span class='description'>Below are the names and codes for each property type {$api_system_info['Mls']} supports:</span><br />\n";
625 echo "<table border='0' width='400'>\n";
626 echo " <tr><td><b>Code</b></td><td><b>Property Type</b></td></tr>\n";
627 foreach ($api_prop_types as $k => $v) {
628 echo " <tr><td>{$k}</td><td>{$v}</td></tr>\n";
629 }
630 echo "</table>\n";
631 }
632
633 function settings_helpful_idxlinks() {
634
635 $fmc_api = new flexmlsApiWP;
636 $api_links = $fmc_api->GetIDXLinks();
637
638 if ($api_links === false) {
639 if ($fmc_api->last_error_code == 1500) {
640 echo "This functionality requires a subscription to flexmls&reg; IDX in order to work. <a href=''>Buy Now</a>.";
641 }
642 else {
643 echo "Information not currently available due to API issue.";
644 }
645 return;
646 }
647
648 echo "<span class='description'>Below are the names and codes for saved IDX link you have:</span><br />\n";
649 echo "<table border='0' width='400'>\n";
650 echo " <tr><td><b>Code</b></td><td><b>Name</b></td></tr>\n";
651 foreach ($api_links as $link) {
652 echo " <tr><td>{$link['LinkId']}</td><td>{$link['Name']}</td></tr>\n";
653 }
654 echo "</table>\n";
655
656 }
657
658
659
660 function clean_spaces_and_trim($value) {
661 $value = trim($value);
662 // keep looking for sequences of multiple spaces until they no longer exist
663 while (preg_match('/\s\s+/', "{$value}")) {
664 $value = preg_replace('/\s\s+/', ' ', "{$value}");
665 }
666 return trim($value);
667 }
668
669
670 function strip_quotes($value) {
671 $value = stripslashes($value);
672
673 if (preg_match('/^\'(.*?)\'$/', $value)) {
674 return substr($value, 1, -1);
675 }
676 else {
677 return $value;
678 }
679 }
680
681
682 function widget_not_available(&$api, $detailed = false, $args = false, $settings = false) {
683 $return = "";
684
685 if (is_array($args)) {
686 $return .= $args['before_widget'];
687 $return .= $args['before_title'];
688 $return .= $settings['title'];
689 $return .= $args['after_title'];
690 }
691
692 if ($api->last_error_code == 1500) {
693 $message = "This widget requires a subscription to flexmls&reg; IDX in order to work. <a href=''>Buy Now</a>.";
694 }
695 elseif ($detailed == true) {
696 $message = "There was an issue communicating with the flexmls&reg; IDX API services required to generate this widget. Please refresh the page or try again later. Error code: ".$api->last_error_code;
697 }
698 else {
699 $message = "This widget is temporarily unavailable. Please refresh the page or try again later. Error code: ".$api->last_error_code;
700 }
701
702 $return .= $message;
703
704 if (is_array($args)) {
705 $return .= $args['after_widget'];
706 }
707
708 return $return;
709 }
710
711
712 function widget_missing_requirements($widget, $reqs_missing) {
713
714 if (is_user_logged_in()) {
715 return "<span style='color:red;'>flexmls&reg; IDX: {$reqs_missing} are required settings for the {$widget} widget.</span>";
716 }
717 else {
718 return false;
719 }
720
721 }
722
723
724 function shortcode($attr = array()) {
725
726 if (!is_array($attr)) {
727 $attr = array();
728 }
729
730 if (!array_key_exists('width', $attr)) {
731 $attr['width'] = 600;
732 }
733 if (!array_key_exists('height', $attr)) {
734 $attr['height'] = 500;
735 }
736
737 $show_link = flexmlsConnect::get_default_idx_link_url();
738
739 $query_url = flexmlsConnect::wp_input_get('url');
740
741 if (!empty($query_url)) {
742 $show_link = $query_url;
743 }
744 else {
745 $default_link = $attr['default'];
746 if (!empty($default_link)) {
747 $show_link = $default_link;
748 }
749 }
750
751 if (empty($show_link)) {
752 return;
753 }
754
755 if (!empty($query_url)) {
756 $show_link = $query_url;
757 }
758
759 return "<iframe src='{$show_link}' width='{$attr['width']}' height='{$attr['height']}' frameborder='0'></iframe>";
760 }
761
762
763 function is_mobile() {
764
765 $mobile_enabled = false;
766
767
768
769 // WPTouch: http://wordpress.org/extend/plugins/wptouch/
770 global $wptouch_plugin;
771
772 if (is_object($wptouch_plugin)) {
773 if ($wptouch_plugin->applemobile == true) {
774 $mobile_enabled = true;
775 }
776 }
777
778 // @todo add more later as deemed necessary
779
780 return $mobile_enabled;
781
782 }
783
784
785 function has_api_saved() {
786 $options = get_option('fmc_settings');
787
788 if ( empty($options['api_key']) || empty($options['api_secret']) ) {
789 return false;
790 }
791 else {
792 return true;
793 }
794
795 }
796
797 function use_default_titles() {
798 $options = get_option('fmc_settings');
799
800 if ($options['default_titles'] == true) {
801 return true;
802 }
803 else {
804 return false;
805 }
806 }
807
808
809 function get_destination_link() {
810 $options = get_option('fmc_settings');
811 $permalink = get_permalink($options['destlink']);
812 return $permalink;
813 }
814
815
816 function make_destination_link($link) {
817
818 $options = get_option('fmc_settings');
819
820 if (flexmlsConnect::get_destination_pref() == "own") {
821 return $link;
822 }
823
824 if (!empty($options['destlink'])) {
825
826 $permalink = get_permalink($options['destlink']);
827
828 if (empty($permalink)) {
829 return $link;
830 }
831
832 $return = "";
833
834 $link = urlencode($link);
835
836 if (strpos($permalink, '?') !== false) {
837 $return = $permalink . '&url=' . $link;
838 }
839 else {
840 $return = $permalink . '?url=' . $link;
841 }
842
843 return $return;
844
845 }
846 else {
847 return $link;
848 }
849
850 }
851
852
853 function get_destination_window_pref() {
854 $options = get_option('fmc_settings');
855 return $options['destwindow'];
856 }
857
858 function get_destination_pref() {
859 $options = get_option('fmc_settings');
860 return $options['destpref'];
861 }
862
863 function get_default_idx_link() {
864 $options = get_option('fmc_settings');
865
866 if (array_key_exists('default_link', $options) && !empty($options['default_link'])) {
867 return $options['default_link'];
868 }
869 else {
870 $fmc_api = new flexmlsApiWP;
871 $api_links = $fmc_api->GetIDXLinks();
872 return $api_links[0]['LinkId'];
873 }
874
875 }
876
877 function get_idx_link_details($my_link) {
878 $fmc_api = new flexmlsApiWP;
879 $api_links = $fmc_api->GetIDXLinks();
880
881 if (is_array($api_links)) {
882 foreach ($api_links as $link) {
883 if ($link['LinkId'] == $my_link) {
884 return $link;
885 }
886 }
887 }
888
889 return false;
890
891 }
892
893 function get_default_idx_link_url() {
894 $default_link = flexmlsConnect::get_default_idx_link();
895 $fmc_api = new flexmlsApiWP;
896 $api_links = $fmc_api->GetIDXLinks();
897
898 $valid_links = array();
899 foreach ($api_links as $link) {
900 $valid_links[$link['LinkId']] = array('Uri' => $link['Uri'], 'Name' => $link['Name']);
901 }
902
903 if (array_key_exists($default_link, $valid_links) && array_key_exists('Uri', $valid_links[$default_link])) {
904 return $valid_links[$default_link]['Uri'];
905 }
906 else {
907 return "";
908 }
909
910 }
911
912 function remove_starting_equals($val) {
913 if (preg_match('/^\=/', $val)) {
914 $val = substr($val, 1);
915 }
916 return $val;
917 }
918
919 function is_ie() {
920
921 $this_ua = getenv('HTTP_USER_AGENT');
922
923 if ($this_ua && (strpos($this_ua, 'MSIE') !== false) && (strpos($this_ua, 'Opera') === false) ) {
924 return true;
925 }
926 else {
927 return false;
928 }
929
930 }
931
932 function ie_version() {
933 ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg);
934 if(!isset($reg[1])) {
935 return -1;
936 } else {
937 return floatval($reg[1]);
938 }
939 }
940
941
942 function clear_temp_cache() {
943 // get list of transient items to clear
944 $cache_tracker = get_transient('fmc_cache_tracker');
945 if (is_array($cache_tracker)) {
946 foreach ($cache_tracker as $key => $value) {
947 delete_transient('fmc_cache_'. $key);
948 }
949 }
950 delete_transient('fmc_cache_tracker');
951 }
952
953 function greatest_fitting_number($num, $slide, $max) {
954 if (($num * ($slide + 1)) <= $max) {
955 return flexmlsConnect::greatest_fitting_number($num, $slide + 1, $max);
956 }
957 else {
958 return $num * $slide;
959 }
960 }
961
962 /**
963 *
964 * Used to calculate the API limit needed to fill as many
965 * slides as possible without having any partially filled.
966 */
967 function generate_api_limit_value($hor, $ver) {
968
969 // _limit number to shoot for if we can
970 $kind_limit = 10;
971
972 // maximum _limit is allowed to be
973 $max_limit = 25;
974
975 if (empty($hor)) {
976 $hor = 1;
977 }
978 if (empty($ver)) {
979 $ver = 1;
980 }
981
982 $total = $hor * $ver;
983
984 if ($total < $kind_limit) {
985 return flexmlsConnect::greatest_fitting_number($total, 1, $kind_limit);
986 }
987 elseif ($total >= $kind_limit && $total <= $max_limit) {
988 return $total;
989 }
990 else {
991 return $max_limit;
992 }
993
994 }
995
996
997 function generate_appropriate_dimensions($hor, $ver) {
998 $new_horizontal = $hor;
999
1000 if ($new_horizontal > 25) {
1001 $new_horizontal = 25;
1002 }
1003
1004 $initial_total = ($hor * $ver);
1005
1006 if ($initial_total > 25) {
1007 $room_to_grow = true;
1008 $new_vertical = 1;
1009 while ($room_to_grow) {
1010 if (($new_horizontal * ($new_vertical + 1)) >= 25) {
1011 $room_to_grow = false;
1012 }
1013 else {
1014 $new_vertical++;
1015 }
1016 }
1017 }
1018 else {
1019 // the grid is fine as-is
1020 $new_vertical = $ver;
1021 }
1022
1023 return array( $new_horizontal, $new_vertical );
1024 }
1025
1026
1027 function parse_location_search_string($location) {
1028 $locations = array();
1029 if (!empty($location)) {
1030 if (preg_match('/\|/', $location)) {
1031 $locations = explode("|", $location);
1032 }
1033 else {
1034 $locations[] = $location;
1035 }
1036 }
1037
1038 $return = array();
1039
1040 foreach ($locations as $loc) {
1041 list($loc_name, $loc_value) = explode("=", $loc, 2);
1042 list($loc_value, $loc_display) = explode("&", $loc_value);
1043 $loc_value_nice = preg_replace('/^\'(.*)\'$/', "$1", $loc_value);
1044 // if there weren't any single quotes, just use the original value
1045 if (empty($loc_value_nice)) {
1046 $loc_value_nice = $loc_value;
1047 }
1048 $loc_value_nice = flexmlsConnect::remove_starting_equals($loc_value_nice);
1049 $return[] = array(
1050 'r' => $loc,
1051 'f' => $loc_name,
1052 'v' => $loc_value_nice,
1053 'l' => $loc_display
1054 );
1055 }
1056
1057 return $return;
1058 }
1059
1060 function cache_turned_on() {
1061 return true;
1062 }
1063
1064
1065 function get_neighborhood_template_content($page_id = false) {
1066
1067 $neigh_template_page_id = flexmlsConnect::get_neighborhood_template_id($page_id);
1068
1069 if (!$neigh_template_page_id) {
1070 return false;
1071 }
1072
1073 $content = get_page($neigh_template_page_id);
1074 return $content->post_content;
1075
1076 }
1077
1078
1079 function get_neighborhood_template_id($page_id = false) {
1080
1081 if (!$page_id || $page_id == "default") {
1082 $options = get_option('fmc_settings');
1083 $neigh_template_page_id = $options['neigh_template'];
1084 }
1085 else {
1086 $neigh_template_page_id = $page_id;
1087 }
1088
1089 if (empty($neigh_template_page_id)) {
1090 return false;
1091 }
1092
1093 return $neigh_template_page_id;
1094
1095 }
1096
1097
1098 function unescape_request_var($string) {
1099 return stripslashes($string);
1100 }
1101
1102
1103 function special_location_tag_text() {
1104 return "<br /><span class='description'>You can use <code>{Location}</code> on neighborhood templates to customize.</span>";
1105 }
1106
1107
1108 function wp_input_get($key) {
1109
1110 if (isset($_GET) && is_array($_GET) && array_key_exists($key, $_GET)) {
1111 return self::wp_input_clean($_GET[$key]);
1112 }
1113 else {
1114 // parse the query string manually. some kind of internal redirect
1115 // or protection is keeping PHP from knowing what $_GET is
1116
1117 $full_requested_url = (preg_match('/^HTTP\//', $_SERVER['SERVER_PROTOCOL'])) ? "http" : "https";
1118 $full_requested_url .= "://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1119
1120 $query_string = parse_url($full_requested_url, PHP_URL_QUERY);
1121 $query_parts = explode("&", $query_string);
1122 $manual = array();
1123 foreach ($query_parts as $p) {
1124 list($k, $v) = @explode("=", $p, 2);
1125 if (array_key_exists($k, $manual)) {
1126 $manual[$k] .= ",".urldecode($v);
1127 }
1128 else {
1129 $manual[$k] = urldecode($v);
1130 }
1131 }
1132 return $manual[$key];
1133 }
1134 }
1135
1136
1137 function wp_input_post($key) {
1138 if (isset($_POST) && is_array($_POST) && array_key_exists($key, $_POST)) {
1139 return self::wp_input_clean($_POST[$key]);
1140 }
1141 else {
1142 return null;
1143 }
1144 }
1145
1146
1147 function wp_input_get_post($key) {
1148 $via_post = self::wp_input_post($key);
1149 if ($via_post !== null) {
1150 return $via_post;
1151 }
1152
1153 $via_get = self::wp_input_get($key);
1154 if ($via_get !== null) {
1155 return $via_get;
1156 }
1157
1158 return null;
1159 }
1160
1161
1162 function wp_input_clean($string) {
1163
1164 $string = stripslashes($string);
1165 return $string;
1166
1167 }
1168
1169
1170 function send_notification() {
1171
1172 $options = get_option('fmc_settings');
1173
1174 if (!array_key_exists('contact_notifications', $options)) {
1175 return true;
1176 }
1177 elseif ($options['contact_notifications'] === true) {
1178 return true;
1179 }
1180 else {
1181 return false;
1182 }
1183
1184 }
1185
1186 }
1187