| 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 |
'enable_cache' => true, |
| 112 |
'destpref' => 'page', |
| 113 |
'destlink' => $new_page_id, |
| 114 |
'autocreatedpage' => $new_page_id |
| 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® IDX Settings', 'flexmls® 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® 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> or "; |
| 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> </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 »</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®: ", "", $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_plugin_cache', 'Enable API Cache', array('flexmlsConnect', 'settings_field_plugin_cache') , 'flexmls_connect', 'fmc_settings_api'); |
| 341 |
add_settings_field('fmc_clear_cache', 'Clear Cache?', array('flexmlsConnect', 'settings_field_clear_cache') , 'flexmls_connect', 'fmc_settings_api'); |
| 342 |
|
| 343 |
add_settings_section('fmc_settings_plugin', '<br/>Plugin Behavior', array('flexmlsConnect', 'settings_overview_plugin') , 'flexmls_connect'); |
| 344 |
add_settings_field('fmc_default_titles', 'Use Default Widget Titles', array('flexmlsConnect', 'settings_field_default_titles') , 'flexmls_connect', 'fmc_settings_plugin'); |
| 345 |
add_settings_field('fmc_destlink', 'Open IDX Links', array('flexmlsConnect', 'settings_field_destlink') , 'flexmls_connect', 'fmc_settings_plugin'); |
| 346 |
add_settings_field('fmc_default_link', 'Default IDX Link', array('flexmlsConnect', 'settings_field_default_link') , 'flexmls_connect', 'fmc_settings_plugin'); |
| 347 |
add_settings_field('fmc_neigh_template', 'Neighborhood Page Template', array('flexmlsConnect', 'settings_field_neigh_template') , '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® 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 |
// save the state of the Enable API Cache selection |
| 390 |
if ($input['enable_cache'] == "y") { |
| 391 |
$options['enable_cache'] = true; |
| 392 |
} |
| 393 |
else { |
| 394 |
$options['enable_cache'] = false; |
| 395 |
} |
| 396 |
|
| 397 |
if ($input['clear_cache'] == "y") { |
| 398 |
// since clear_cache is checked, wipe out the contents of the fmc_cache_* transient items |
| 399 |
// but don't do anything else since we aren't saving the state of this particular checkbox |
| 400 |
|
| 401 |
flexmlsConnect::clear_temp_cache(); |
| 402 |
} |
| 403 |
|
| 404 |
if ($input['default_titles'] == "y") { |
| 405 |
$options['default_titles'] = true; |
| 406 |
} |
| 407 |
else { |
| 408 |
$options['default_titles'] = false; |
| 409 |
} |
| 410 |
|
| 411 |
$options['destpref'] = $input['destpref']; |
| 412 |
$options['destlink'] = $input['destlink']; |
| 413 |
$options['destwindow'] = $input['destwindow']; |
| 414 |
$options['default_link'] = $input['default_link']; |
| 415 |
$options['neigh_template'] = $input['neigh_template']; |
| 416 |
|
| 417 |
return $options; |
| 418 |
|
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
function settings_overview_api() { |
| 423 |
if (flexmlsConnect::has_api_saved() == false) { |
| 424 |
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>"; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
function settings_overview_plugin() { |
| 429 |
//echo "<p>Tweak how the flexmls® Connect plugin behaves.</p>"; |
| 430 |
} |
| 431 |
|
| 432 |
function settings_overview_helpful() { |
| 433 |
echo "<p>Here is some information you may find helpful.</p>"; |
| 434 |
} |
| 435 |
|
| 436 |
function settings_field_api_key() { |
| 437 |
global $fmc_plugin_url; |
| 438 |
$options = get_option('fmc_settings'); |
| 439 |
|
| 440 |
$api_status_info = ""; |
| 441 |
|
| 442 |
if (flexmlsConnect::has_api_saved()) { |
| 443 |
$fmc_api = new flexmlsApiWP; |
| 444 |
$api_auth = $fmc_api->Authenticate(true); |
| 445 |
|
| 446 |
if ($api_auth === false) { |
| 447 |
$api_status_info = " <img src='{$fmc_plugin_url}/images/error.png'> Error with entered info"; |
| 448 |
} |
| 449 |
else { |
| 450 |
$api_status_info = " <img src='{$fmc_plugin_url}/images/accept.png'> It works!"; |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
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"; |
| 455 |
} |
| 456 |
|
| 457 |
function settings_field_api_secret() { |
| 458 |
$options = get_option('fmc_settings'); |
| 459 |
echo "<input type='password' id='fmc_api_secret' name='fmc_settings[api_secret]' value='{$options['api_secret']}' size='14' maxlength='25' />\n"; |
| 460 |
} |
| 461 |
|
| 462 |
function settings_field_plugin_cache() { |
| 463 |
$options = get_option('fmc_settings'); |
| 464 |
|
| 465 |
$checked = ""; |
| 466 |
|
| 467 |
if ($options['enable_cache'] == true) { |
| 468 |
$checked_yes = " checked='checked'"; |
| 469 |
} |
| 470 |
else { |
| 471 |
$checked_no = " checked='checked'"; |
| 472 |
} |
| 473 |
|
| 474 |
echo "<label><input type='radio' name='fmc_settings[enable_cache]' value='y'{$checked_yes} /> Yes</label> "; |
| 475 |
echo "<label><input type='radio' name='fmc_settings[enable_cache]' value='n'{$checked_no} /> No</label><br />\n"; |
| 476 |
echo "<span class='description'>Speed up your site by caching certain flexmls® API calls every few minutes.</span>\n"; |
| 477 |
} |
| 478 |
|
| 479 |
function settings_field_default_titles() { |
| 480 |
$options = get_option('fmc_settings'); |
| 481 |
|
| 482 |
$checked = ""; |
| 483 |
|
| 484 |
if ($options['default_titles'] == true) { |
| 485 |
$checked_yes = " checked='checked'"; |
| 486 |
} |
| 487 |
else { |
| 488 |
$checked_no = " checked='checked'"; |
| 489 |
} |
| 490 |
|
| 491 |
echo "<label><input type='radio' name='fmc_settings[default_titles]' value='y'{$checked_yes} /> Yes</label> "; |
| 492 |
echo "<label><input type='radio' name='fmc_settings[default_titles]' value='n'{$checked_no} /> No</label><br />\n"; |
| 493 |
echo "<span class='description'>Use the default widget titles when no title is entered.</span>\n"; |
| 494 |
} |
| 495 |
|
| 496 |
function settings_field_clear_cache() { |
| 497 |
// stale option that doesn't pay attention to any saved option. this simply triggers the cache clearing |
| 498 |
echo "<label><input type='checkbox' name='fmc_settings[clear_cache]' value='y' /> Clear the cached flexmls® API responses</label>\n"; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
function settings_field_destlink() { |
| 503 |
$options = get_option('fmc_settings'); |
| 504 |
|
| 505 |
$args = array( |
| 506 |
'name' => 'fmc_settings[destlink]', |
| 507 |
'selected' => $options['destlink'] |
| 508 |
); |
| 509 |
|
| 510 |
$checked_code = " checked='checked'"; |
| 511 |
|
| 512 |
if ($options['destpref'] == "own") { |
| 513 |
$checked_own = $checked_code; |
| 514 |
} |
| 515 |
elseif ($options['destpref'] == "page") { |
| 516 |
$checked_page = $checked_code; |
| 517 |
} |
| 518 |
else { |
| 519 |
$checked_own = $checked_code; |
| 520 |
} |
| 521 |
|
| 522 |
if ($options['destwindow'] == "new") { |
| 523 |
$checked_new = $checked_code; |
| 524 |
} |
| 525 |
|
| 526 |
echo "<label><input type='checkbox' name='fmc_settings[destwindow]' value='new'{$checked_new} /> in a new window</label>"; |
| 527 |
echo "<br />\n"; |
| 528 |
echo "<br />\n"; |
| 529 |
echo "<label><input type='radio' name='fmc_settings[destpref]' value='own'{$checked_own} /> separate from WordPress</label><br />\n"; |
| 530 |
echo "<label><input type='radio' name='fmc_settings[destpref]' value='page'{$checked_page} /> framed within a WordPress page (select below)</label><br />\n"; |
| 531 |
echo " Page: "; |
| 532 |
wp_dropdown_pages($args); |
| 533 |
echo "<br/>"; |
| 534 |
echo " <span class='description'><a href='#' id='idx_frame_shortcode_docs_link'>View the documentation</a> for more details on how this works.</span> "; |
| 535 |
|
| 536 |
echo "<div id='idx_frame_shortcode_docs' style='display: none; margin-left: 23px; width: 700px;'>"; |
| 537 |
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>"; |
| 538 |
echo "<blockquote><pre>[idx_frame width='100%' height='600']</pre></blockquote>"; |
| 539 |
echo "<p>By using this shortcode, it allows the flexmls® 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>"; |
| 540 |
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>"; |
| 541 |
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>"; |
| 542 |
echo "</div>"; |
| 543 |
|
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
function settings_field_default_link() { |
| 548 |
$options = get_option('fmc_settings'); |
| 549 |
|
| 550 |
$selected_default_link = $options['default_link']; |
| 551 |
|
| 552 |
if (flexmlsConnect::has_api_saved()) { |
| 553 |
|
| 554 |
$fmc_api = new flexmlsApiWP; |
| 555 |
$api_links = $fmc_api->GetIDXLinks(); |
| 556 |
|
| 557 |
if ($api_links === false) { |
| 558 |
if ($fmc_api->last_error_code == 1500) { |
| 559 |
echo "This functionality requires a subscription to flexmls® IDX in order to work. <a href=''>Buy Now</a>.<input type='hidden' name='fmc_settings[default_link]' value='{$selected_default_link}' />"; |
| 560 |
} |
| 561 |
else { |
| 562 |
echo "Information not currently available due to API issue.<input type='hidden' name='fmc_settings[default_link]' value='{$selected_default_link}' />"; |
| 563 |
} |
| 564 |
return; |
| 565 |
} |
| 566 |
|
| 567 |
echo "<select name='fmc_settings[default_link]'>\n"; |
| 568 |
foreach ($api_links as $link) { |
| 569 |
$selected = ($link['LinkId'] == $selected_default_link) ? " selected='selected'" : ""; |
| 570 |
echo "<option value='{$link['LinkId']}'{$selected}>{$link['Name']}</option>\n"; |
| 571 |
} |
| 572 |
echo "</select>\n"; |
| 573 |
echo "<br/>\n"; |
| 574 |
echo "<span class='description'>Select the default flexmls® IDX link your widgets should use</span>"; |
| 575 |
|
| 576 |
} |
| 577 |
else { |
| 578 |
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}' />"; |
| 579 |
} |
| 580 |
|
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
function settings_field_neigh_template() { |
| 585 |
$options = get_option('fmc_settings'); |
| 586 |
|
| 587 |
$selected_neigh_template = $options['neigh_template']; |
| 588 |
|
| 589 |
$args = array( |
| 590 |
'name' => 'fmc_settings[neigh_template]', |
| 591 |
'selected' => $selected_neigh_template, |
| 592 |
'post_status' => 'draft', |
| 593 |
'echo' => false |
| 594 |
); |
| 595 |
|
| 596 |
$page_selection = wp_dropdown_pages($args); |
| 597 |
if (!empty($page_selection)) { |
| 598 |
echo $page_selection; |
| 599 |
} |
| 600 |
else { |
| 601 |
echo "Please create a page as a draft to select it here."; |
| 602 |
} |
| 603 |
|
| 604 |
echo "<br/><span class='description'>Select the page to use as your default neighborhood page template.</span>"; |
| 605 |
|
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
function settings_helpful_proptypes() { |
| 610 |
|
| 611 |
$fmc_api = new flexmlsApiWP; |
| 612 |
$api_prop_types = $fmc_api->PropertyTypes(); |
| 613 |
$api_system_info = $fmc_api->SystemInfo(); |
| 614 |
|
| 615 |
if ($api_prop_types === false || $api_system_info === false) { |
| 616 |
echo "Information not currently available due to API issue."; |
| 617 |
return; |
| 618 |
} |
| 619 |
|
| 620 |
echo "<span class='description'>Below are the names and codes for each property type {$api_system_info['Mls']} supports:</span><br />\n"; |
| 621 |
echo "<table border='0' width='400'>\n"; |
| 622 |
echo " <tr><td><b>Code</b></td><td><b>Property Type</b></td></tr>\n"; |
| 623 |
foreach ($api_prop_types as $k => $v) { |
| 624 |
echo " <tr><td>{$k}</td><td>{$v}</td></tr>\n"; |
| 625 |
} |
| 626 |
echo "</table>\n"; |
| 627 |
} |
| 628 |
|
| 629 |
function settings_helpful_idxlinks() { |
| 630 |
|
| 631 |
$fmc_api = new flexmlsApiWP; |
| 632 |
$api_links = $fmc_api->GetIDXLinks(); |
| 633 |
|
| 634 |
if ($api_links === false) { |
| 635 |
if ($fmc_api->last_error_code == 1500) { |
| 636 |
echo "This functionality requires a subscription to flexmls® IDX in order to work. <a href=''>Buy Now</a>."; |
| 637 |
} |
| 638 |
else { |
| 639 |
echo "Information not currently available due to API issue."; |
| 640 |
} |
| 641 |
return; |
| 642 |
} |
| 643 |
|
| 644 |
echo "<span class='description'>Below are the names and codes for saved IDX link you have:</span><br />\n"; |
| 645 |
echo "<table border='0' width='400'>\n"; |
| 646 |
echo " <tr><td><b>Code</b></td><td><b>Name</b></td></tr>\n"; |
| 647 |
foreach ($api_links as $link) { |
| 648 |
echo " <tr><td>{$link['LinkId']}</td><td>{$link['Name']}</td></tr>\n"; |
| 649 |
} |
| 650 |
echo "</table>\n"; |
| 651 |
|
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
function clean_spaces_and_trim($value) { |
| 657 |
$value = trim($value); |
| 658 |
// keep looking for sequences of multiple spaces until they no longer exist |
| 659 |
while (preg_match('/\s\s+/', "{$value}")) { |
| 660 |
$value = preg_replace('/\s\s+/', ' ', "{$value}"); |
| 661 |
} |
| 662 |
return trim($value); |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
function strip_quotes($value) { |
| 667 |
if (get_magic_quotes_gpc()) { |
| 668 |
$value = stripslashes($value); |
| 669 |
} |
| 670 |
|
| 671 |
if (preg_match('/^\'(.*?)\'$/', $value)) { |
| 672 |
return substr($value, 1, -1); |
| 673 |
} |
| 674 |
else { |
| 675 |
return $value; |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
function widget_not_available(&$api, $detailed = false, $args = false, $settings = false) { |
| 681 |
$return = ""; |
| 682 |
|
| 683 |
if (is_array($args)) { |
| 684 |
$return .= $args['before_widget']; |
| 685 |
$return .= $args['before_title']; |
| 686 |
$return .= $settings['title']; |
| 687 |
$return .= $args['after_title']; |
| 688 |
} |
| 689 |
|
| 690 |
if ($api->last_error_code == 1500) { |
| 691 |
$message = "This widget requires a subscription to flexmls® IDX in order to work. <a href=''>Buy Now</a>."; |
| 692 |
} |
| 693 |
elseif ($detailed == true) { |
| 694 |
$message = "There was an issue communicating with the flexmls® IDX API services required to generate this widget. Please refresh the page or try again later. Error code: ".$api->last_error_code; |
| 695 |
} |
| 696 |
else { |
| 697 |
$message = "This widget is temporarily unavailable. Please refresh the page or try again later. Error code: ".$api->last_error_code; |
| 698 |
} |
| 699 |
|
| 700 |
$return .= $message; |
| 701 |
|
| 702 |
if (is_array($args)) { |
| 703 |
$return .= $args['after_widget']; |
| 704 |
} |
| 705 |
|
| 706 |
return $return; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
function widget_missing_requirements($widget, $reqs_missing) { |
| 711 |
|
| 712 |
if (is_user_logged_in()) { |
| 713 |
return "<span style='color:red;'>flexmls® IDX: {$reqs_missing} are required settings for the {$widget} widget.</span>"; |
| 714 |
} |
| 715 |
else { |
| 716 |
return false; |
| 717 |
} |
| 718 |
|
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
function shortcode($attr = array()) { |
| 723 |
|
| 724 |
if (!is_array($attr)) { |
| 725 |
$attr = array(); |
| 726 |
} |
| 727 |
|
| 728 |
if (!array_key_exists('width', $attr)) { |
| 729 |
$attr['width'] = 600; |
| 730 |
} |
| 731 |
if (!array_key_exists('height', $attr)) { |
| 732 |
$attr['height'] = 500; |
| 733 |
} |
| 734 |
|
| 735 |
$show_link = flexmlsConnect::get_default_idx_link_url(); |
| 736 |
|
| 737 |
$query_url = flexmlsConnect::get_var('url'); |
| 738 |
|
| 739 |
if (!empty($query_url)) { |
| 740 |
$show_link = $query_url; |
| 741 |
} |
| 742 |
else { |
| 743 |
$default_link = $attr['default']; |
| 744 |
if (!empty($default_link)) { |
| 745 |
$show_link = $default_link; |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
if (empty($show_link)) { |
| 750 |
return; |
| 751 |
} |
| 752 |
|
| 753 |
if (!empty($query_url)) { |
| 754 |
$show_link = $query_url; |
| 755 |
} |
| 756 |
|
| 757 |
return "<iframe src='{$show_link}' width='{$attr['width']}' height='{$attr['height']}' frameborder='0'></iframe>"; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
function is_mobile() { |
| 762 |
|
| 763 |
$mobile_enabled = false; |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
// WPTouch: http://wordpress.org/extend/plugins/wptouch/ |
| 768 |
global $wptouch_plugin; |
| 769 |
|
| 770 |
if (is_object($wptouch_plugin)) { |
| 771 |
if ($wptouch_plugin->applemobile == true) { |
| 772 |
$mobile_enabled = true; |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
// @todo add more later as deemed necessary |
| 777 |
|
| 778 |
return $mobile_enabled; |
| 779 |
|
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
function has_api_saved() { |
| 784 |
$options = get_option('fmc_settings'); |
| 785 |
|
| 786 |
if ( empty($options['api_key']) || empty($options['api_secret']) ) { |
| 787 |
return false; |
| 788 |
} |
| 789 |
else { |
| 790 |
return true; |
| 791 |
} |
| 792 |
|
| 793 |
} |
| 794 |
|
| 795 |
function use_default_titles() { |
| 796 |
$options = get_option('fmc_settings'); |
| 797 |
|
| 798 |
if ($options['default_titles'] == true) { |
| 799 |
return true; |
| 800 |
} |
| 801 |
else { |
| 802 |
return false; |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
|
| 807 |
function get_destination_link() { |
| 808 |
$options = get_option('fmc_settings'); |
| 809 |
$permalink = get_permalink($options['destlink']); |
| 810 |
return $permalink; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
function make_destination_link($link) { |
| 815 |
|
| 816 |
$options = get_option('fmc_settings'); |
| 817 |
|
| 818 |
if (flexmlsConnect::get_destination_pref() == "own") { |
| 819 |
return $link; |
| 820 |
} |
| 821 |
|
| 822 |
if (!empty($options['destlink'])) { |
| 823 |
|
| 824 |
$permalink = get_permalink($options['destlink']); |
| 825 |
|
| 826 |
if (empty($permalink)) { |
| 827 |
return $link; |
| 828 |
} |
| 829 |
|
| 830 |
$return = ""; |
| 831 |
|
| 832 |
$link = urlencode($link); |
| 833 |
|
| 834 |
if (strpos($permalink, '?') !== false) { |
| 835 |
$return = $permalink . '&url=' . $link; |
| 836 |
} |
| 837 |
else { |
| 838 |
$return = $permalink . '?url=' . $link; |
| 839 |
} |
| 840 |
|
| 841 |
return $return; |
| 842 |
|
| 843 |
} |
| 844 |
else { |
| 845 |
return $link; |
| 846 |
} |
| 847 |
|
| 848 |
} |
| 849 |
|
| 850 |
|
| 851 |
function get_destination_window_pref() { |
| 852 |
$options = get_option('fmc_settings'); |
| 853 |
return $options['destwindow']; |
| 854 |
} |
| 855 |
|
| 856 |
function get_destination_pref() { |
| 857 |
$options = get_option('fmc_settings'); |
| 858 |
return $options['destpref']; |
| 859 |
} |
| 860 |
|
| 861 |
function get_default_idx_link() { |
| 862 |
$options = get_option('fmc_settings'); |
| 863 |
|
| 864 |
if (array_key_exists('default_link', $options) && !empty($options['default_link'])) { |
| 865 |
return $options['default_link']; |
| 866 |
} |
| 867 |
else { |
| 868 |
$fmc_api = new flexmlsApiWP; |
| 869 |
$api_links = $fmc_api->GetIDXLinks(); |
| 870 |
return $api_links[0]['LinkId']; |
| 871 |
} |
| 872 |
|
| 873 |
} |
| 874 |
|
| 875 |
function get_idx_link_details($my_link) { |
| 876 |
$fmc_api = new flexmlsApiWP; |
| 877 |
$api_links = $fmc_api->GetIDXLinks(); |
| 878 |
|
| 879 |
if (is_array($api_links)) { |
| 880 |
foreach ($api_links as $link) { |
| 881 |
if ($link['LinkId'] == $my_link) { |
| 882 |
return $link; |
| 883 |
} |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
return false; |
| 888 |
|
| 889 |
} |
| 890 |
|
| 891 |
function get_default_idx_link_url() { |
| 892 |
$default_link = flexmlsConnect::get_default_idx_link(); |
| 893 |
$fmc_api = new flexmlsApiWP; |
| 894 |
$api_links = $fmc_api->GetIDXLinks(); |
| 895 |
|
| 896 |
$valid_links = array(); |
| 897 |
foreach ($api_links as $link) { |
| 898 |
$valid_links[$link['LinkId']] = array('Uri' => $link['Uri'], 'Name' => $link['Name']); |
| 899 |
} |
| 900 |
|
| 901 |
if (array_key_exists($default_link, $valid_links) && array_key_exists('Uri', $valid_links[$default_link])) { |
| 902 |
return $valid_links[$default_link]['Uri']; |
| 903 |
} |
| 904 |
else { |
| 905 |
return ""; |
| 906 |
} |
| 907 |
|
| 908 |
} |
| 909 |
|
| 910 |
function remove_starting_equals($val) { |
| 911 |
if (preg_match('/^\=/', $val)) { |
| 912 |
$val = substr($val, 1); |
| 913 |
} |
| 914 |
return $val; |
| 915 |
} |
| 916 |
|
| 917 |
function is_ie() { |
| 918 |
|
| 919 |
$this_ua = getenv('HTTP_USER_AGENT'); |
| 920 |
|
| 921 |
if ($this_ua && (strpos($this_ua, 'MSIE') !== false) && (strpos($this_ua, 'Opera') === false) ) { |
| 922 |
return true; |
| 923 |
} |
| 924 |
else { |
| 925 |
return false; |
| 926 |
} |
| 927 |
|
| 928 |
} |
| 929 |
|
| 930 |
function ie_version() { |
| 931 |
ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg); |
| 932 |
if(!isset($reg[1])) { |
| 933 |
return -1; |
| 934 |
} else { |
| 935 |
return floatval($reg[1]); |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
function clear_temp_cache() { |
| 941 |
// get list of transient items to clear |
| 942 |
$cache_tracker = get_transient('fmc_cache_tracker'); |
| 943 |
if (is_array($cache_tracker)) { |
| 944 |
foreach ($cache_tracker as $key => $value) { |
| 945 |
delete_transient('fmc_cache_'. $key); |
| 946 |
} |
| 947 |
} |
| 948 |
delete_transient('fmc_cache_tracker'); |
| 949 |
} |
| 950 |
|
| 951 |
function greatest_fitting_number($num, $slide, $max) { |
| 952 |
if (($num * ($slide + 1)) <= $max) { |
| 953 |
return flexmlsConnect::greatest_fitting_number($num, $slide + 1, $max); |
| 954 |
} |
| 955 |
else { |
| 956 |
return $num * $slide; |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* |
| 962 |
* Used to calculate the API limit needed to fill as many |
| 963 |
* slides as possible without having any partially filled. |
| 964 |
*/ |
| 965 |
function generate_api_limit_value($hor, $ver) { |
| 966 |
|
| 967 |
// _limit number to shoot for if we can |
| 968 |
$kind_limit = 10; |
| 969 |
|
| 970 |
// maximum _limit is allowed to be |
| 971 |
$max_limit = 25; |
| 972 |
|
| 973 |
if (empty($hor)) { |
| 974 |
$hor = 1; |
| 975 |
} |
| 976 |
if (empty($ver)) { |
| 977 |
$ver = 1; |
| 978 |
} |
| 979 |
|
| 980 |
$total = $hor * $ver; |
| 981 |
|
| 982 |
if ($total < $kind_limit) { |
| 983 |
return flexmlsConnect::greatest_fitting_number($total, 1, $kind_limit); |
| 984 |
} |
| 985 |
elseif ($total >= $kind_limit && $total <= $max_limit) { |
| 986 |
return $total; |
| 987 |
} |
| 988 |
else { |
| 989 |
return $max_limit; |
| 990 |
} |
| 991 |
|
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
function generate_appropriate_dimensions($hor, $ver) { |
| 996 |
$new_horizontal = $hor; |
| 997 |
|
| 998 |
if ($new_horizontal > 25) { |
| 999 |
$new_horizontal = 25; |
| 1000 |
} |
| 1001 |
|
| 1002 |
$initial_total = ($hor * $ver); |
| 1003 |
|
| 1004 |
if ($initial_total > 25) { |
| 1005 |
$room_to_grow = true; |
| 1006 |
$new_vertical = 1; |
| 1007 |
while ($room_to_grow) { |
| 1008 |
if (($new_horizontal * ($new_vertical + 1)) >= 25) { |
| 1009 |
$room_to_grow = false; |
| 1010 |
} |
| 1011 |
else { |
| 1012 |
$new_vertical++; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
} |
| 1016 |
else { |
| 1017 |
// the grid is fine as-is |
| 1018 |
$new_vertical = $ver; |
| 1019 |
} |
| 1020 |
|
| 1021 |
return array( $new_horizontal, $new_vertical ); |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
function parse_location_search_string($location) { |
| 1026 |
$locations = array(); |
| 1027 |
if (!empty($location)) { |
| 1028 |
if (preg_match('/\|/', $location)) { |
| 1029 |
$locations = explode("|", $location); |
| 1030 |
} |
| 1031 |
else { |
| 1032 |
$locations[] = $location; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
|
| 1036 |
$return = array(); |
| 1037 |
|
| 1038 |
foreach ($locations as $loc) { |
| 1039 |
list($loc_name, $loc_value) = explode("=", $loc, 2); |
| 1040 |
list($loc_value, $loc_display) = explode("&", $loc_value); |
| 1041 |
$loc_value_nice = preg_replace('/^\'(.*)\'$/', "$1", $loc_value); |
| 1042 |
// if there weren't any single quotes, just use the original value |
| 1043 |
if (empty($loc_value_nice)) { |
| 1044 |
$loc_value_nice = $loc_value; |
| 1045 |
} |
| 1046 |
$loc_value_nice = flexmlsConnect::remove_starting_equals($loc_value_nice); |
| 1047 |
$return[] = array( |
| 1048 |
'r' => $loc, |
| 1049 |
'f' => $loc_name, |
| 1050 |
'v' => $loc_value_nice, |
| 1051 |
'l' => $loc_display |
| 1052 |
); |
| 1053 |
} |
| 1054 |
|
| 1055 |
return $return; |
| 1056 |
} |
| 1057 |
|
| 1058 |
function cache_turned_on() { |
| 1059 |
$options = get_option('fmc_settings'); |
| 1060 |
if ($options['enable_cache'] == true) { |
| 1061 |
return true; |
| 1062 |
} |
| 1063 |
else { |
| 1064 |
return false; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
|
| 1069 |
function get_neighborhood_template_content($page_id = false) { |
| 1070 |
|
| 1071 |
$neigh_template_page_id = flexmlsConnect::get_neighborhood_template_id($page_id); |
| 1072 |
|
| 1073 |
if (!$neigh_template_page_id) { |
| 1074 |
return false; |
| 1075 |
} |
| 1076 |
|
| 1077 |
$content = get_page($neigh_template_page_id); |
| 1078 |
return $content->post_content; |
| 1079 |
|
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
function get_neighborhood_template_id($page_id = false) { |
| 1084 |
|
| 1085 |
if (!$page_id || $page_id == "default") { |
| 1086 |
$options = get_option('fmc_settings'); |
| 1087 |
$neigh_template_page_id = $options['neigh_template']; |
| 1088 |
} |
| 1089 |
else { |
| 1090 |
$neigh_template_page_id = $page_id; |
| 1091 |
} |
| 1092 |
|
| 1093 |
if (empty($neigh_template_page_id)) { |
| 1094 |
return false; |
| 1095 |
} |
| 1096 |
|
| 1097 |
return $neigh_template_page_id; |
| 1098 |
|
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
function unescape_request_var($string) { |
| 1103 |
if (get_magic_quotes_gpc()) { |
| 1104 |
return stripslashes($string); |
| 1105 |
} |
| 1106 |
else { |
| 1107 |
return $string; |
| 1108 |
} |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
function special_location_tag_text() { |
| 1113 |
return "<br /><span class='description'>You can use <code>{Location}</code> on neighborhood templates to customize.</span>"; |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
function get_var($key) { |
| 1118 |
|
| 1119 |
if (isset($_GET) && is_array($_GET) && array_key_exists($key, $_GET)) { |
| 1120 |
return $_GET[$key]; |
| 1121 |
} |
| 1122 |
else { |
| 1123 |
// parse the query string manually. some kind of internal redirect |
| 1124 |
// or protection is keeping PHP from knowing what $_GET is |
| 1125 |
$query_string = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY); |
| 1126 |
$query_parts = explode("&", $query_string); |
| 1127 |
$manual = array(); |
| 1128 |
foreach ($query_parts as $p) { |
| 1129 |
list($k, $v) = @explode("=", $p, 2); |
| 1130 |
if (array_key_exists($k, $manual)) { |
| 1131 |
$manual[$k] .= ",".urldecode($v); |
| 1132 |
} |
| 1133 |
else { |
| 1134 |
$manual[$k] = urldecode($v); |
| 1135 |
} |
| 1136 |
} |
| 1137 |
return $manual[$key]; |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
} |
| 1142 |
|