| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
class fmcPhotos extends fmcWidget { |
| 6 |
|
| 7 |
function fmcPhotos() { |
| 8 |
global $fmc_widgets; |
| 9 |
|
| 10 |
$widget_info = $fmc_widgets[ get_class($this) ]; |
| 11 |
|
| 12 |
$widget_ops = array( 'description' => $widget_info['description'] ); |
| 13 |
$this->WP_Widget( get_class($this) , $widget_info['title'], $widget_ops); |
| 14 |
|
| 15 |
// have WP replace instances of [first_argument] with the return from the second_argument function |
| 16 |
add_shortcode($widget_info['shortcode'], array(&$this, 'shortcode')); |
| 17 |
|
| 18 |
// register where the AJAX calls should be routed when they come in |
| 19 |
add_action('wp_ajax_'.get_class($this).'_shortcode', array(&$this, 'shortcode_form') ); |
| 20 |
add_action('wp_ajax_'.get_class($this).'_shortcode_gen', array(&$this, 'shortcode_generate') ); |
| 21 |
|
| 22 |
add_action('wp_ajax_'.get_class($this).'_additional_photos', array(&$this, 'additional_photos') ); |
| 23 |
add_action('wp_ajax_nopriv_'.get_class($this).'_additional_photos', array(&$this, 'additional_photos') ); |
| 24 |
|
| 25 |
add_action('wp_ajax_'.get_class($this).'_additional_slides', array(&$this, 'additional_slides') ); |
| 26 |
add_action('wp_ajax_nopriv_'.get_class($this).'_additional_slides', array(&$this, 'additional_slides') ); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
function jelly($args, $settings, $type) { |
| 32 |
global $fmc_api; |
| 33 |
global $fmc_plugin_url; |
| 34 |
|
| 35 |
extract($args); |
| 36 |
|
| 37 |
if ($type == "widget" && empty($settings['title']) && flexmlsConnect::use_default_titles()) { |
| 38 |
$settings['title'] = "Listings"; |
| 39 |
} |
| 40 |
|
| 41 |
$encoded_settings = urlencode( serialize($settings) ); |
| 42 |
|
| 43 |
$return = ''; |
| 44 |
|
| 45 |
$title = trim($settings['title']); |
| 46 |
$horizontal = trim($settings['horizontal']); |
| 47 |
$vertical = trim($settings['vertical']); |
| 48 |
$auto_rotate = trim($settings['auto_rotate']); |
| 49 |
$source = trim($settings['source']); |
| 50 |
$display = trim($settings['display']); |
| 51 |
$property_type = trim($settings['property_type']); |
| 52 |
$link = trim($settings['link']); |
| 53 |
$location = html_entity_decode(FlexmlsApiWp::clean_comma_list($settings['location'])); |
| 54 |
$sort = trim($settings['sort']); |
| 55 |
$page = trim($settings['page']); |
| 56 |
$additional_fields = trim($settings['additional_fields']); |
| 57 |
|
| 58 |
$show_additional_fields = array(); |
| 59 |
if (!empty($additional_fields)) { |
| 60 |
$show_additional_fields = explode(",", $additional_fields); |
| 61 |
} |
| 62 |
if (count($show_additional_fields) > 0) { |
| 63 |
$tall_carousel = true; |
| 64 |
} |
| 65 |
else { |
| 66 |
$tall_carousel = false; |
| 67 |
} |
| 68 |
|
| 69 |
if ($link == "default") { |
| 70 |
$link = flexmlsConnect::get_default_idx_link(); |
| 71 |
} |
| 72 |
|
| 73 |
if ($auto_rotate != 0 && $auto_rotate < 1000) { |
| 74 |
$auto_rotate = $auto_rotate * 1000; |
| 75 |
} |
| 76 |
|
| 77 |
if (empty($horizontal)) { |
| 78 |
$horizontal = 1; |
| 79 |
} |
| 80 |
if (flexmlsConnect::is_mobile() && $horizontal > 2) { |
| 81 |
$horizontal = 2; |
| 82 |
} |
| 83 |
if (empty($vertical)) { |
| 84 |
$vertical = 1; |
| 85 |
} |
| 86 |
if (empty($auto_rotate)) { |
| 87 |
$auto_rotate = 0; |
| 88 |
} |
| 89 |
if (empty($source)) { |
| 90 |
$source = "my"; |
| 91 |
} |
| 92 |
|
| 93 |
$total_listings_to_show = ($horizontal * $vertical); |
| 94 |
if ($total_listings_to_show > 25) { |
| 95 |
list($horizontal, $vertical) = flexmlsConnect::generate_appropriate_dimensions($horizontal, $vertical); |
| 96 |
} |
| 97 |
|
| 98 |
$api_limit = flexmlsConnect::generate_api_limit_value($horizontal, $vertical); |
| 99 |
|
| 100 |
$filter_conditions = array(); |
| 101 |
$outbound_criteria = ""; |
| 102 |
|
| 103 |
$params = array(); |
| 104 |
$params['_expand'] = 'PrimaryPhoto'; |
| 105 |
$params['_pagination'] = 1; |
| 106 |
if (!empty($page) && $page > 0) { |
| 107 |
$params['_page'] = $page; |
| 108 |
} |
| 109 |
$params['_limit'] = $api_limit; |
| 110 |
|
| 111 |
$hours = 24; |
| 112 |
if (date("l") == "Monday") { |
| 113 |
$hours = 72; |
| 114 |
} |
| 115 |
|
| 116 |
if ($display == "all") { |
| 117 |
// nothing to do |
| 118 |
} |
| 119 |
elseif ($display == "new") { |
| 120 |
$params['HotSheet'] = "new"; |
| 121 |
$outbound_criteria .= "&listingevent=new&listingeventhours={$hours}"; |
| 122 |
} |
| 123 |
elseif ($display == "open_houses") { |
| 124 |
$params['OpenHouses'] = 10; |
| 125 |
$params['_expand'] .= ',OpenHouses'; |
| 126 |
$outbound_criteria .= "&openhouse=10"; |
| 127 |
} |
| 128 |
elseif ($display == "price_changes") { |
| 129 |
$params['HotSheet'] = "price"; |
| 130 |
$outbound_criteria .= "&listingevent=price&listingeventhours={$hours}"; |
| 131 |
} |
| 132 |
elseif ($display == "recent_sales") { |
| 133 |
$params['HotSheet'] = "sold"; |
| 134 |
$outbound_criteria .= "&status=C&listingevent=status&listingeventhours={$hours}"; |
| 135 |
} |
| 136 |
|
| 137 |
if ($sort == "recently_changed") { |
| 138 |
// nothing to do. this is the default |
| 139 |
} |
| 140 |
elseif ($sort == "price_low_high") { |
| 141 |
$params['_orderby'] = "+ListPrice"; |
| 142 |
} |
| 143 |
elseif ($sort == "price_high_low") { |
| 144 |
$params['_orderby'] = "-ListPrice"; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
$api_system_info = $fmc_api->SystemInfo(); |
| 150 |
|
| 151 |
if ($source == "my") { |
| 152 |
$outbound_criteria .= "&my_listings=true"; |
| 153 |
// make a simple request to /my/listings with no _filter's |
| 154 |
$api_listings = $fmc_api->MyListings( $params ); |
| 155 |
} |
| 156 |
elseif ($source == "office") { |
| 157 |
$api_listings = $fmc_api->OfficeListings( $params ); |
| 158 |
} |
| 159 |
elseif ($source == "company") { |
| 160 |
$api_listings = $fmc_api->CompanyListings( $params ); |
| 161 |
} |
| 162 |
else { |
| 163 |
// parse the given Locations for the _filter |
| 164 |
|
| 165 |
$locations = flexmlsConnect::parse_location_search_string($location); |
| 166 |
|
| 167 |
$location_conditions = array(); |
| 168 |
$location_field_names = array(); |
| 169 |
|
| 170 |
foreach ($locations as $loc) { |
| 171 |
$location_conditions[] = "{$loc['f']} Eq '{$loc['v']}'"; |
| 172 |
$location_field_names[] = $loc['f']; |
| 173 |
} |
| 174 |
|
| 175 |
$uniq_location_field_names = array_unique($location_field_names); |
| 176 |
|
| 177 |
if (count($location_conditions) > 1) { |
| 178 |
return "<span style='color:red;'>flexmls® IDX: This IDX slideshow widget is configured with too many location search criteria options. Please reduce to 1.</span>"; |
| 179 |
} |
| 180 |
|
| 181 |
if (count($location_conditions) > 0) { |
| 182 |
$filter_conditions[] = implode(" Or ", $location_conditions); |
| 183 |
} |
| 184 |
if (!empty($property_type)) { |
| 185 |
$filter_conditions[] = "PropertyType Eq '{$property_type}'"; |
| 186 |
} |
| 187 |
|
| 188 |
$link_details = flexmlsConnect::get_idx_link_details($link); |
| 189 |
if ($link_details['LinkType'] == "SavedSearch") { |
| 190 |
$filter_conditions[] = "SavedSearch Eq '{$link_details['SearchId']}'"; |
| 191 |
} |
| 192 |
|
| 193 |
$params['_filter'] = implode(" And ", $filter_conditions); |
| 194 |
|
| 195 |
$api_listings = $fmc_api->Listings( $params ); |
| 196 |
} |
| 197 |
|
| 198 |
if ($api_listings === false || $api_system_info === false) { |
| 199 |
return flexmlsConnect::widget_not_available($fmc_api, false, $args, $settings); |
| 200 |
} |
| 201 |
|
| 202 |
if (!is_array($uniq_location_field_names)) { |
| 203 |
$uniq_location_field_names = array(); |
| 204 |
} |
| 205 |
|
| 206 |
if (!is_array($locations)) { |
| 207 |
$locations = array(); |
| 208 |
} |
| 209 |
|
| 210 |
$link_transform_params = array(); |
| 211 |
foreach ($uniq_location_field_names as $loc_name) { |
| 212 |
$link_transform_params["{$loc_name}"] = "*{$loc_name}*"; |
| 213 |
} |
| 214 |
|
| 215 |
$link_transform_params["PropertyType"] = "*PropertyType*"; |
| 216 |
|
| 217 |
// make the API call to translate standard field names |
| 218 |
$outbound_link = $fmc_api->GetTransformedIDXLink($link, $link_transform_params); |
| 219 |
$this_link = $outbound_link; |
| 220 |
|
| 221 |
foreach ($locations as $loc) { |
| 222 |
// start replacing the placeholders in the link with the real values for this link |
| 223 |
$this_link = preg_replace('/\*'.preg_quote($loc['f']).'\*/', $loc['v'], $this_link); |
| 224 |
} |
| 225 |
|
| 226 |
$this_link = preg_replace('/\*PropertyType\*/', $property_type, $this_link); |
| 227 |
// replace all remaining placeholders with a blank value since it doesn't apply to this link |
| 228 |
$this_link = preg_replace('/\*(.*?)\*/', "", $this_link); |
| 229 |
$this_link .= $outbound_criteria; |
| 230 |
|
| 231 |
|
| 232 |
$destination_link = ""; |
| 233 |
|
| 234 |
if (!empty($this_link) && !$fmc_api->HasBasicRole()) { |
| 235 |
$destination_link = $this_link; |
| 236 |
} |
| 237 |
|
| 238 |
$return .= $before_widget; |
| 239 |
|
| 240 |
$carousel_class = "flexmls_connect__carousel"; |
| 241 |
if ($tall_carousel) { |
| 242 |
$carousel_class .= " tall"; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
if ($type != "ajax") { |
| 247 |
$div_box = "<div class='{$carousel_class}' data-connect-vertical='{$vertical}' data-connect-horizontal='{$horizontal}' data-connect-autostart='{$auto_rotate}' data-connect-settings=\"{$encoded_settings}\" data-connect-total-pages='{$fmc_api->last_count}'>\n"; |
| 248 |
|
| 249 |
if ( !empty($title) ) { |
| 250 |
$title_line = "\t" . $before_title . $title . $after_title . "\n"; |
| 251 |
} |
| 252 |
|
| 253 |
if ($type == "widget") { |
| 254 |
$return .= $title_line . $div_box; |
| 255 |
} |
| 256 |
else { |
| 257 |
$return .= $div_box . $title_line; |
| 258 |
} |
| 259 |
|
| 260 |
if ($fmc_api->last_count == 1) { |
| 261 |
$show_count = "1 Listing"; |
| 262 |
} |
| 263 |
else { |
| 264 |
$show_count = number_format($fmc_api->last_count) . " Listings"; |
| 265 |
} |
| 266 |
|
| 267 |
$this_target = ""; |
| 268 |
if (flexmlsConnect::get_destination_window_pref() == "new") { |
| 269 |
$this_target = " target='_blank'"; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
if (!empty($destination_link)) { |
| 274 |
$return .= "\t<div class='flexmls_connect__count'><a href='".flexmlsConnect::make_destination_link($destination_link)."'{$this_target}>{$show_count}</a></div>\n"; |
| 275 |
} |
| 276 |
else { |
| 277 |
$return .= "\t<div class='flexmls_connect__count'>{$show_count}</div>\n"; |
| 278 |
} |
| 279 |
|
| 280 |
$return .= "\t<div class='flexmls_connect__container'>\n"; |
| 281 |
$return .= "\t\t<div class='flexmls_connect__slides'>\n"; |
| 282 |
|
| 283 |
} |
| 284 |
|
| 285 |
$rand = mt_rand(); |
| 286 |
|
| 287 |
$total_listings = 0; |
| 288 |
if (is_array($api_listings)) { |
| 289 |
foreach ($api_listings as $li) { |
| 290 |
$total_listings++; |
| 291 |
$show_idx_badge = ""; |
| 292 |
|
| 293 |
$listing = $li['StandardFields']; |
| 294 |
$one_line_address = "{$listing['StreetNumber']} {$listing['StreetDirPrefix']} {$listing['StreetName']} "; |
| 295 |
$one_line_address .= "{$listing['StreetSuffix']} {$listing['StreetDirSuffix']}"; |
| 296 |
$one_line_address = str_replace("********", "", $one_line_address); |
| 297 |
$one_line_address = flexmlsConnect::clean_spaces_and_trim($one_line_address); |
| 298 |
|
| 299 |
$first_line_address = $one_line_address; |
| 300 |
|
| 301 |
$second_line_address = "{$listing['City']}, {$listing['StateOrProvince']} {$listing['PostalCode']}"; |
| 302 |
$second_line_address = str_replace("********", "", $second_line_address); |
| 303 |
|
| 304 |
$one_line_address .= ", {$second_line_address}"; |
| 305 |
$one_line_address = flexmlsConnect::clean_spaces_and_trim($one_line_address); |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
$price = '$'. number_format($listing['ListPrice'], 0); |
| 310 |
|
| 311 |
if ($source != "my" && $source != "my_office") { |
| 312 |
if (array_key_exists('IdxLogoSmall', $api_system_info['Configuration'][0]) && !empty($api_system_info['Configuration'][0]['IdxLogoSmall'])) { |
| 313 |
$show_idx_badge = "<img src='{$api_system_info['Configuration'][0]['IdxLogoSmall']}' class='flexmls_connect__badge_image' title='{$listing['ListOfficeName']}' />\n"; |
| 314 |
} |
| 315 |
else { |
| 316 |
$show_idx_badge = "<span class='flexmls_connect__badge' title='{$listing['ListOfficeName']}'>IDX</span>\n"; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
$relevant_info_line = ""; |
| 321 |
|
| 322 |
if ($display == "open_houses") { |
| 323 |
$relevant_info_line = $listing['OpenHouses'][0]['Date'] . " " . $listing['OpenHouses'][0]['StartTime']; |
| 324 |
} |
| 325 |
else { |
| 326 |
$relevant_info_line = $price; |
| 327 |
} |
| 328 |
|
| 329 |
$tall_line = ""; |
| 330 |
$extra_title_line = ""; |
| 331 |
|
| 332 |
if ($tall_carousel) { |
| 333 |
$show_additional_field_line = array(); |
| 334 |
foreach ($show_additional_fields as $fi) { |
| 335 |
if ($fi == "beds") { |
| 336 |
$show_additional_field_line[] = "{$listing['BedsTotal']} beds"; |
| 337 |
} |
| 338 |
elseif ($fi == "baths") { |
| 339 |
$show_additional_field_line[] = "{$listing['BathsTotal']} baths"; |
| 340 |
} |
| 341 |
elseif ($fi == "sqft") { |
| 342 |
$show_additional_field_line[] = number_format($listing['BuildingAreaTotal'])." sqft"; |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
$extra_title_line = ' | '. implode(" | ", $show_additional_field_line); |
| 347 |
$tall_line = "<small class='dark'>". implode(" ", $show_additional_field_line) ."</small>"; |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
$link_to_start = "<a>"; |
| 353 |
$link_to_end = "</a>"; |
| 354 |
$this_link = ""; |
| 355 |
$this_target = ""; |
| 356 |
|
| 357 |
if (!empty($destination_link)) { |
| 358 |
$this_link = flexmlsConnect::make_destination_link("{$destination_link}&start=details&start_id={$listing['ListingKey']}"); |
| 359 |
if (flexmlsConnect::get_destination_window_pref() == "new") { |
| 360 |
$this_target = " target='_blank'"; |
| 361 |
} |
| 362 |
$link_to_start = "<a href='{$this_link}'{$this_target}>"; |
| 363 |
$link_to_end = "</a>"; |
| 364 |
} |
| 365 |
|
| 366 |
$main_photo_uri300 = ""; |
| 367 |
$main_photo_caption = ""; |
| 368 |
$main_photo_urilarge = ""; |
| 369 |
|
| 370 |
$photo_return = ''; |
| 371 |
|
| 372 |
$photo_count = 0; |
| 373 |
foreach ($listing['Photos'] as $photo) { |
| 374 |
$photo_count++; |
| 375 |
if ($photo_count == 1) { |
| 376 |
continue; |
| 377 |
} |
| 378 |
$caption = htmlspecialchars($photo['Caption'], ENT_QUOTES); |
| 379 |
$photo_return .= "<a href='{$photo['UriLarge']}' class='popup' rel='{$rand}-{$listing['ListingKey']}' title='{$caption}'></a>\n"; |
| 380 |
|
| 381 |
if ($photo['Primary'] == true) { |
| 382 |
$main_photo_caption = $caption; |
| 383 |
$main_photo_uri300 = $photo['Uri300']; |
| 384 |
$main_photo_urilarge = $photo['UriLarge']; |
| 385 |
} |
| 386 |
|
| 387 |
} |
| 388 |
|
| 389 |
// default to the first photo given if the primary isn't set |
| 390 |
if (empty($main_photo_urilarge)) { |
| 391 |
$main_photo_caption = htmlspecialchars($listing['Photos'][0]['Caption'], ENT_QUOTES); |
| 392 |
$main_photo_uri300 = $listing['Photos'][0]['Uri300']; |
| 393 |
$main_photo_urilarge = $listing['Photos'][0]['UriLarge']; |
| 394 |
} |
| 395 |
|
| 396 |
if (empty($main_photo_uri300)) { |
| 397 |
$main_photo_uri300 = "{$fmc_plugin_url}/images/nophoto.gif"; |
| 398 |
$listing['Photos'][0]['UriLarge'] = $main_photo_uri300; |
| 399 |
$main_photo_caption = "No Photo Available"; |
| 400 |
} |
| 401 |
|
| 402 |
$return .= "<!-- Listing --> |
| 403 |
<div title='{$first_line_address}, {$listing['City']}, {$listing['StateOrProvince']} {$listing['PostalCode']} | MLS #: {$listing['ListingId']} | {$price}{$extra_title_line}' link='{$this_link}' target=\"{$this_target}\"> |
| 404 |
<a href='{$listing['Photos'][0]['UriLarge']}' class='popup' rel='{$rand}-{$listing['ListingKey']}' title='{$main_photo_caption}'> |
| 405 |
<img src='{$main_photo_uri300}' style='width:134px;height:100px' alt='' /> |
| 406 |
</a> |
| 407 |
<p class='caption'> |
| 408 |
{$link_to_start} |
| 409 |
{$relevant_info_line} |
| 410 |
{$tall_line} |
| 411 |
<small>{$first_line_address}<br />{$second_line_address}</small> |
| 412 |
{$link_to_end} |
| 413 |
</p> |
| 414 |
{$show_idx_badge} |
| 415 |
<div class='flexmls_connect__hidden'> |
| 416 |
"; |
| 417 |
|
| 418 |
$return .= $photo_return; |
| 419 |
|
| 420 |
$return .= " </div> |
| 421 |
</div>\n\n"; |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
if ($type != "ajax") { |
| 426 |
// now that we use AJAX to load more, no need for the View All Listings slide |
| 427 |
// removed as a part of WP-7 by Brandon Medenwald on 3/8/2011 |
| 428 |
// if ($fmc_api->last_count > count($api_listings) && !empty($destination_link)) { |
| 429 |
// $return .= "\t<div title='Click to View All Listings'>\n"; |
| 430 |
// $this_target = ""; |
| 431 |
// if (flexmlsConnect::get_destination_window_pref() == "new") { |
| 432 |
// $this_target = " target='_blank'"; |
| 433 |
// } |
| 434 |
// $return .= "\t\t<p class='caption'><a href='".flexmlsConnect::make_destination_link($destination_link)."' class='flexmls_connect__more_anchor'{$this_target}>View All Listings<small>All ".number_format($fmc_api->last_count)." Listings</small></a>\n"; |
| 435 |
// $return .= "\t</div>\n"; |
| 436 |
// } |
| 437 |
|
| 438 |
$return .= "</div>\n"; |
| 439 |
$return .= "</div>\n"; |
| 440 |
|
| 441 |
if ($total_listings > 0) { |
| 442 |
$return .= "<a href='#' class='previous'>previous</a><a href='#' class='next'>next</a>"; |
| 443 |
|
| 444 |
if ($source != "my" && $source != "my_office") { |
| 445 |
$return .= "<p class='flexmls_connect__disclaimer'>\n"; |
| 446 |
|
| 447 |
if (array_key_exists('IdxLogoSmall', $api_system_info['Configuration'][0]) && !empty($api_system_info['Configuration'][0]['IdxLogoSmall'])) { |
| 448 |
$return .= "<img src='{$api_system_info['Configuration'][0]['IdxLogoSmall']}' class='flexmls_connect__badge_image' title='Read the full IDX Listings Disclosure' />\n"; |
| 449 |
} |
| 450 |
else { |
| 451 |
$return .= " <span class='flexmls_connect__badge' title='Read the full IDX Listings Disclosure'>IDX</span>\n"; |
| 452 |
} |
| 453 |
|
| 454 |
$return .= " <a title='Read the full IDX Listings Disclosure'>MLS IDX Listing Disclosure © ".date("Y")."</a>\n"; |
| 455 |
$return .= "</p>\n"; |
| 456 |
$return .= "<p class='flexmls_connect__hidden flexmls_connect__disclaimer_text'>\n"; |
| 457 |
$return .= $api_system_info['Configuration'][0]['IdxDisclaimer']; |
| 458 |
$return .= "\n"; |
| 459 |
$return .= "</p>\n"; |
| 460 |
} |
| 461 |
|
| 462 |
} |
| 463 |
|
| 464 |
$return .= "</div>\n"; |
| 465 |
|
| 466 |
$return .= $after_widget; |
| 467 |
} |
| 468 |
|
| 469 |
return $return; |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
function widget($args, $instance) { |
| 475 |
echo $this->cache_jelly($args, $instance, "widget"); |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
function shortcode($attr = array()) { |
| 480 |
|
| 481 |
$args = array( |
| 482 |
'before_title' => '<h3>', |
| 483 |
'after_title' => '</h3>', |
| 484 |
'before_widget' => '', |
| 485 |
'after_widget' => '' |
| 486 |
); |
| 487 |
|
| 488 |
return $this->cache_jelly($args, $attr, "shortcode"); |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
function settings_form($instance) { |
| 494 |
$title = esc_attr($instance['title']); |
| 495 |
$horizontal = esc_attr($instance['horizontal']); |
| 496 |
$vertical = esc_attr($instance['vertical']); |
| 497 |
$auto_rotate = esc_attr($instance['auto_rotate']); |
| 498 |
$source = esc_attr($instance['source']); |
| 499 |
$display = esc_attr($instance['display']); |
| 500 |
$property_type = esc_attr($instance['property_type']); |
| 501 |
$link = esc_attr($instance['link']); |
| 502 |
$location = $instance['location']; |
| 503 |
$sort = esc_attr($instance['sort']); |
| 504 |
$additional_fields = esc_attr($instance['additional_fields']); |
| 505 |
|
| 506 |
$selected_code = " selected='selected'"; |
| 507 |
$checked_code = " checked='checked'"; |
| 508 |
|
| 509 |
$horizontal_options = array(1, 2, 3, 4, 5, 6, 7, 8); |
| 510 |
|
| 511 |
$vertical_options = array(1, 2, 3, 4, 5, 6, 7, 8); |
| 512 |
|
| 513 |
$auto_rotate_options = array( |
| 514 |
0 => "Off", |
| 515 |
1000 => "1 second", |
| 516 |
2000 => "2 seconds", |
| 517 |
3000 => "3 seconds", |
| 518 |
4000 => "4 seconds", |
| 519 |
5000 => "5 seconds", |
| 520 |
6000 => "6 seconds", |
| 521 |
7000 => "7 seconds", |
| 522 |
8000 => "8 seconds", |
| 523 |
9000 => "9 seconds", |
| 524 |
10000 => "10 seconds", |
| 525 |
15000 => "15 seconds", |
| 526 |
20000 => "20 seconds", |
| 527 |
25000 => "25 seconds", |
| 528 |
30000 => "30 seconds", |
| 529 |
60000 => "1 minute" |
| 530 |
); |
| 531 |
|
| 532 |
$source_options = array( |
| 533 |
"my" => "My Listings", |
| 534 |
"office" => "My Office's Listings", |
| 535 |
"company" => "My Company's Listings" |
| 536 |
); |
| 537 |
|
| 538 |
$display_options = array( |
| 539 |
"all" => "All Listings", |
| 540 |
"new" => "New Listings", |
| 541 |
"open_houses" => "Open Houses", |
| 542 |
"price_changes" => "Recent Price Changes", |
| 543 |
"recent_sales" => "Recent Sales" |
| 544 |
); |
| 545 |
|
| 546 |
$sort_options = array( |
| 547 |
"recently_changed" => "Recently changed first", |
| 548 |
"price_low_high" => "Price, low to high", |
| 549 |
"price_high_low" => "Price, high to low" |
| 550 |
); |
| 551 |
|
| 552 |
$additional_field_options = array( |
| 553 |
'beds' => "Bedrooms", |
| 554 |
'baths' => "Bathrooms", |
| 555 |
'sqft' => "Square Footage" |
| 556 |
); |
| 557 |
|
| 558 |
$additional_fields_selected = array(); |
| 559 |
if (!empty($additional_fields)) { |
| 560 |
$additional_fields_selected = explode(",", $additional_fields); |
| 561 |
} |
| 562 |
|
| 563 |
$fmc_api = new FlexmlsApiWp; |
| 564 |
$api_property_type_options = $fmc_api->PropertyTypes(); |
| 565 |
$api_system_info = $fmc_api->SystemInfo(); |
| 566 |
$api_location_search_api = $fmc_api->GetLocationSearchApiUrl(); |
| 567 |
|
| 568 |
if ($api_property_type_options === false || $api_system_info === false || $api_location_search_api === false) { |
| 569 |
return flexmlsConnect::widget_not_available($fmc_api, true); |
| 570 |
} |
| 571 |
|
| 572 |
// only show the Location option if this user is allowed to show those types of listings |
| 573 |
if (!$fmc_api->HasBasicRole()) { |
| 574 |
$source_options['location'] = "Location"; |
| 575 |
} |
| 576 |
|
| 577 |
if (empty($source)) { |
| 578 |
$source = "location"; |
| 579 |
} |
| 580 |
|
| 581 |
if (array_key_exists('_instance_type', $instance) && $instance['_instance_type'] == "shortcode") { |
| 582 |
$special_neighborhood_title_ability = flexmlsConnect::special_location_tag_text(); |
| 583 |
} |
| 584 |
|
| 585 |
$return = ""; |
| 586 |
|
| 587 |
$return .= " |
| 588 |
|
| 589 |
<p> |
| 590 |
<label for='".$this->get_field_id('title')."'>" . __('Title:') . "</label> |
| 591 |
<input fmc-field='title' fmc-type='text' type='text' class='widefat' id='".$this->get_field_id('title')."' name='".$this->get_field_name('title')."' value='{$title}'> |
| 592 |
$special_neighborhood_title_ability |
| 593 |
</p> |
| 594 |
|
| 595 |
"; |
| 596 |
|
| 597 |
if (!$fmc_api->HasBasicRole()) { |
| 598 |
$api_links = $fmc_api->GetIDXLinks(); |
| 599 |
|
| 600 |
$return .= " |
| 601 |
<p> |
| 602 |
<label for='".$this->get_field_id('link')."'>" . __('IDX Link:') . "</label> |
| 603 |
<select fmc-field='link' fmc-type='select' id='".$this->get_field_id('link')."' name='".$this->get_field_name('link')."'> |
| 604 |
"; |
| 605 |
|
| 606 |
$is_selected = ($link == "default") ? $selected_code : ""; |
| 607 |
$return .= "<option value='default'{$is_selected}>(Use Saved Default)</option>\n"; |
| 608 |
|
| 609 |
foreach ($api_links as $my_l) { |
| 610 |
$is_selected = ($my_l['LinkId'] == $link) ? $selected_code : ""; |
| 611 |
$return .= "<option value='{$my_l['LinkId']}'{$is_selected}{$is_disabled}>{$my_l['Name']}</option>\n"; |
| 612 |
} |
| 613 |
|
| 614 |
$return .= " |
| 615 |
</select><br /><span class='description'>Link used when a listing is viewed</span> |
| 616 |
</p> |
| 617 |
"; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
$return .= " |
| 622 |
<p> |
| 623 |
<label for='".$this->get_field_id('horizontal')."'>" . __('Slideshow Dimensions:') . "</label> |
| 624 |
<select fmc-field='horizontal' fmc-type='select' id='".$this->get_field_id('horizontal')."' name='".$this->get_field_name('horizontal')."'> |
| 625 |
"; |
| 626 |
|
| 627 |
foreach ($horizontal_options as $k) { |
| 628 |
$is_selected = ($k == $horizontal) ? $selected_code : ""; |
| 629 |
$return .= "<option value='{$k}'{$is_selected}>{$k}</option>\n"; |
| 630 |
} |
| 631 |
|
| 632 |
$return .= " |
| 633 |
</select> × <select fmc-field='vertical' fmc-type='select' id='".$this->get_field_id('vertical')."' name='".$this->get_field_name('vertical')."'> |
| 634 |
"; |
| 635 |
|
| 636 |
foreach ($vertical_options as $k) { |
| 637 |
$is_selected = ($k == $vertical) ? $selected_code : ""; |
| 638 |
$return .= "<option value='{$k}'{$is_selected}>{$k}</option>\n"; |
| 639 |
} |
| 640 |
|
| 641 |
$return .= " |
| 642 |
</select> |
| 643 |
<br /><span class='description'>Horizontal × Vertical</span> |
| 644 |
</p> |
| 645 |
|
| 646 |
<p> |
| 647 |
<label for='".$this->get_field_id('auto_rotate')."'>" . __('Slideshow:') . " |
| 648 |
<select fmc-field='auto_rotate' fmc-type='select' id='".$this->get_field_id('auto_rotate')."' name='".$this->get_field_name('auto_rotate')."'> |
| 649 |
"; |
| 650 |
|
| 651 |
foreach ($auto_rotate_options as $k => $v) { |
| 652 |
$is_selected = ($k == $auto_rotate) ? $selected_code : ""; |
| 653 |
$return .= "<option value='{$k}'{$is_selected}>{$v}</option>\n"; |
| 654 |
} |
| 655 |
|
| 656 |
$return .= " |
| 657 |
</select> |
| 658 |
</label> |
| 659 |
</p> |
| 660 |
|
| 661 |
<p> |
| 662 |
<label for='".$this->get_field_id('source')."'>" . __('Filter by:') . "</label> |
| 663 |
<select fmc-field='source' fmc-type='select' id='".$this->get_field_id('source')."' name='".$this->get_field_name('source')."' class='flexmls_connect__listing_source'> |
| 664 |
"; |
| 665 |
|
| 666 |
foreach ($source_options as $k => $v) { |
| 667 |
$is_selected = ($k == $source) ? $selected_code : ""; |
| 668 |
$return .= "<option value='{$k}'{$is_selected}{$is_disabled}>{$v}</option>\n"; |
| 669 |
} |
| 670 |
|
| 671 |
$hidden_location = ($source != "location") ? " style='display:none;'" : ""; |
| 672 |
$no_filter_warning = ($source == "location") ? "display:none;" : ""; |
| 673 |
|
| 674 |
$return .= " |
| 675 |
</select><br /><span class='description'>Which listings to display</span> |
| 676 |
</p> |
| 677 |
|
| 678 |
<p style='{$no_filter_warning}color:red;' class='flexmls_connect__no_filters_applied'>Note: Criteria applied to the selected saved search link above will not affect listings displayed.</p> |
| 679 |
|
| 680 |
<p class='flexmls_connect__location_property_type_p' {$hidden_location}> |
| 681 |
<label for='".$this->get_field_id('property_type')."'>" . __('Property Type:') . "</label> |
| 682 |
<select fmc-field='property_type' class='flexmls_connect__property_type' fmc-type='select' id='".$this->get_field_id('property_type')."' name='".$this->get_field_name('property_type')."'> |
| 683 |
"; |
| 684 |
|
| 685 |
foreach ($api_property_type_options as $k => $v) { |
| 686 |
$is_selected = ($k == $property_type) ? $selected_code : ""; |
| 687 |
$return .= "<option value='{$k}'{$is_selected}{$is_disabled}>{$v}</option>\n"; |
| 688 |
} |
| 689 |
|
| 690 |
$return .= " |
| 691 |
</select> |
| 692 |
</p> |
| 693 |
|
| 694 |
<div class='flexmls_connect__location'{$hidden_location}> |
| 695 |
<p> |
| 696 |
<label for='horizontal'>Location:</label> |
| 697 |
<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.' /> |
| 698 |
<a href='javascript:void(0);' title='Click here to browse through available locations' class='flexmls_connect__location_browse'>Browse »</a> |
| 699 |
<div class='flexmls_connect__location_list' data-connect-multiple='false'> |
| 700 |
<p>All Locations Included</p> |
| 701 |
</div> |
| 702 |
<input type='hidden' name='tech_id' class='flexmls_connect__tech_id' value=\"x'{$api_system_info['Id']}'\" /> |
| 703 |
<input type='hidden' name='ma_tech_id' class='flexmls_connect__ma_tech_id' value=\"x'{$api_system_info['MlsId']}'\" /> |
| 704 |
<input fmc-field='location' fmc-type='text' type='hidden' name='".$this->get_field_name('location')."' class='flexmls_connect__location_fields' value=\"{$location}\" /> |
| 705 |
</p> |
| 706 |
</div> |
| 707 |
|
| 708 |
<p> |
| 709 |
<label for='".$this->get_field_id('display')."'>" . __('Display:') . " |
| 710 |
<select fmc-field='display' fmc-type='select' id='".$this->get_field_id('display')."' name='".$this->get_field_name('display')."'> |
| 711 |
"; |
| 712 |
|
| 713 |
foreach ($display_options as $k => $v) { |
| 714 |
$is_selected = ($k == $display) ? $selected_code : ""; |
| 715 |
$return .= "<option value='{$k}'{$is_selected}{$is_disabled}>{$v}</option>\n"; |
| 716 |
} |
| 717 |
|
| 718 |
$return .= " |
| 719 |
</select> |
| 720 |
</label> |
| 721 |
</p> |
| 722 |
|
| 723 |
<p> |
| 724 |
<label for='".$this->get_field_id('sort')."'>" . __('Sort by:') . " |
| 725 |
<select fmc-field='sort' fmc-type='select' id='".$this->get_field_id('sort')."' name='".$this->get_field_name('sort')."'> |
| 726 |
"; |
| 727 |
|
| 728 |
foreach ($sort_options as $k => $v) { |
| 729 |
$is_selected = ($k == $sort) ? $selected_code : ""; |
| 730 |
$return .= "<option value='{$k}'{$is_selected}{$is_disabled}>{$v}</option>\n"; |
| 731 |
} |
| 732 |
|
| 733 |
$return .= " |
| 734 |
</select> |
| 735 |
</label> |
| 736 |
</p> |
| 737 |
|
| 738 |
<p> |
| 739 |
<label for='".$this->get_field_id('additional_fields')."'>" . __('Additional Fields to Show:') . "</label> |
| 740 |
|
| 741 |
"; |
| 742 |
|
| 743 |
foreach ($additional_field_options as $k => $v) { |
| 744 |
$return .= "<div>"; |
| 745 |
$this_checked = (in_array($k, $additional_fields_selected)) ? $checked_code : ""; |
| 746 |
$return .= " <input fmc-field='additional_fields' fmc-type='checkbox' type='checkbox' name='".$this->get_field_name('additional_fields')."[{$k}]' value='{$k}' id='".$this->get_field_id('additional_fields')."-".$k."'{$this_checked} /> "; |
| 747 |
$return .= "<label for='".$this->get_field_id('additional_fields')."-".$k."'>{$v}</label>"; |
| 748 |
$return .= "</div>\n"; |
| 749 |
} |
| 750 |
|
| 751 |
$return .= " |
| 752 |
</p> |
| 753 |
|
| 754 |
<img src='x' class='flexmls_connect__bootloader' onerror='flexmls_connect.location_setup(this);' /> |
| 755 |
|
| 756 |
"; |
| 757 |
|
| 758 |
if ($fmc_api->HasBasicRole()) { |
| 759 |
$return .= "<p><span style='color:red;'>Note:</span> <a href='http://flexmls.com/' target='_blank'>flexmls® IDX subscription</a> is required in order to show IDX listings and to link listings to full detail pages.</p>"; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
$return .= "<input type='hidden' name='shortcode_fields_to_catch' value='title,link,horizontal,vertical,auto_rotate,source,property_type,location,display,sort,additional_fields' />\n"; |
| 764 |
$return .= "<input type='hidden' name='widget' value='". get_class($this) ."' />\n"; |
| 765 |
|
| 766 |
return $return; |
| 767 |
|
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
function update($new_instance, $old_instance) { |
| 774 |
$instance = $old_instance; |
| 775 |
|
| 776 |
$instance['title'] = strip_tags($new_instance['title']); |
| 777 |
$instance['horizontal'] = strip_tags($new_instance['horizontal']); |
| 778 |
$instance['vertical'] = strip_tags($new_instance['vertical']); |
| 779 |
$instance['auto_rotate'] = strip_tags($new_instance['auto_rotate']); |
| 780 |
$instance['source'] = strip_tags($new_instance['source']); |
| 781 |
$instance['display'] = strip_tags($new_instance['display']); |
| 782 |
$instance['property_type'] = strip_tags($new_instance['property_type']); |
| 783 |
$instance['link'] = strip_tags($new_instance['link']); |
| 784 |
$instance['location'] = strip_tags($new_instance['location']); |
| 785 |
$instance['sort'] = strip_tags($new_instance['sort']); |
| 786 |
|
| 787 |
$additional_fields_selected = ""; |
| 788 |
if (is_array($new_instance['additional_fields'])) { |
| 789 |
foreach ($new_instance['additional_fields'] as $v) { |
| 790 |
if (!empty($additional_fields_selected)) { |
| 791 |
$additional_fields_selected .= ","; |
| 792 |
} |
| 793 |
$additional_fields_selected .= strip_tags(trim($v)); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
$instance['additional_fields'] = $additional_fields_selected; |
| 798 |
|
| 799 |
return $instance; |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
function additional_photos() { |
| 804 |
|
| 805 |
$full_id = flexmlsConnect::wp_input_get_post('id'); |
| 806 |
$id = $full_id; |
| 807 |
$id = substr($id, -26, 26); |
| 808 |
|
| 809 |
$jsObj = new Moxiecode_JSON(); |
| 810 |
|
| 811 |
$fmc_api = new flexmlsApiWp(); |
| 812 |
|
| 813 |
$photos = $fmc_api->ListingPhotos($id); |
| 814 |
|
| 815 |
$return = array(); |
| 816 |
|
| 817 |
if (is_array($photos)) { |
| 818 |
foreach ($photos as $photo) { |
| 819 |
$return[] = array('photo' => $photo['UriLarge'], 'caption' => $photo['Caption']); |
| 820 |
} |
| 821 |
echo $jsObj->encode($return); |
| 822 |
} |
| 823 |
else { |
| 824 |
echo $jsObj->encode( false ); |
| 825 |
} |
| 826 |
|
| 827 |
die(); |
| 828 |
|
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
function additional_slides() { |
| 833 |
|
| 834 |
// no arguments need to be passed for prepping the AJAX response |
| 835 |
$args = array(); |
| 836 |
|
| 837 |
$settings_string = flexmlsConnect::wp_input_get_post('settings'); |
| 838 |
|
| 839 |
// these get parsed from the sent AJAX response |
| 840 |
$settings = unserialize($settings_string); |
| 841 |
$listings_from = flexmlsConnect::wp_input_get_post('page'); |
| 842 |
|
| 843 |
$horizontal = $settings['horizontal']; |
| 844 |
$vertical = $settings['vertical']; |
| 845 |
|
| 846 |
$total_listings_to_show = ($horizontal * $vertical); |
| 847 |
if ($total_listings_to_show > 25) { |
| 848 |
list($horizontal, $vertical) = flexmlsConnect::generate_appropriate_dimensions($horizontal, $vertical); |
| 849 |
} |
| 850 |
$total_listings_to_show = ($horizontal * $vertical); |
| 851 |
|
| 852 |
$api_limit = flexmlsConnect::generate_api_limit_value($horizontal, $vertical); |
| 853 |
|
| 854 |
$settings['page'] = ceil( $listings_from / ($api_limit / $total_listings_to_show) ); |
| 855 |
|
| 856 |
$type = "ajax"; |
| 857 |
|
| 858 |
echo $this->cache_jelly($args, $settings, $type); |
| 859 |
|
| 860 |
die(); |
| 861 |
|
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
} |
| 866 |
|