";
$response['title'] = "";
$response['body'] = $return;
$js = new Moxiecode_JSON();
echo str_replace("\'", "'", $js->encode($response));
exit;
}
// called to put the start of the form on the shortcode generator page
function shortcode_header() {
$return = "\n\n";
$return .= "\n";
$return .= "\n\n";
return $return;
}
function settings_init() {
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
add_filter( 'mce_buttons', array('flexmlsConnect', 'filter_mce_button' ) );
add_filter( 'mce_external_plugins', array('flexmlsConnect', 'filter_mce_plugin' ) );
}
// register our settings with WordPress so it can automatically handle saving them
register_setting('fmc_settings_group', 'fmc_settings', array('flexmlsConnect', 'settings_validate') );
// add a section called fmc_settings_api to the settings page
add_settings_section('fmc_settings_api', ' API Settings', array('flexmlsConnect', 'settings_overview_api') , 'flexmls_connect');
// add some setting fields to the fmc_settings_api section of the settings page
add_settings_field('fmc_api_key', 'API Key', array('flexmlsConnect', 'settings_field_api_key') , 'flexmls_connect', 'fmc_settings_api');
add_settings_field('fmc_api_secret', 'API Secret', array('flexmlsConnect', 'settings_field_api_secret') , 'flexmls_connect', 'fmc_settings_api');
add_settings_field('fmc_clear_cache', 'Clear Cache?', array('flexmlsConnect', 'settings_field_clear_cache') , 'flexmls_connect', 'fmc_settings_api');
add_settings_section('fmc_settings_plugin', ' Plugin Behavior', array('flexmlsConnect', 'settings_overview_plugin') , 'flexmls_connect');
add_settings_field('fmc_default_titles', 'Use Default Widget Titles', array('flexmlsConnect', 'settings_field_default_titles') , 'flexmls_connect', 'fmc_settings_plugin');
add_settings_field('fmc_destlink', 'Open IDX Links', array('flexmlsConnect', 'settings_field_destlink') , 'flexmls_connect', 'fmc_settings_plugin');
add_settings_field('fmc_default_link', 'Default IDX Link', array('flexmlsConnect', 'settings_field_default_link') , 'flexmls_connect', 'fmc_settings_plugin');
add_settings_field('fmc_neigh_template', 'Neighborhood Page Template', array('flexmlsConnect', 'settings_field_neigh_template') , 'flexmls_connect', 'fmc_settings_plugin');
add_settings_field('fmc_contact_notifications', 'When a new lead is created', array('flexmlsConnect', 'settings_field_contact_notifications') , 'flexmls_connect', 'fmc_settings_plugin');
}
function settings_page() {
// put the settings page together
$options = get_option('fmc_settings');
echo "
\n";
screen_icon('options-general');
echo "
flexmls® IDX Settings
\n";
echo "\n";
echo "
\n";
}
function settings_validate($input) {
$options = get_option('fmc_settings');
foreach ($input as $key => $value) {
$input[$key] = trim($value);
}
if ($options['api_key'] != $input['api_key'] || $options['api_secret'] != $input['api_secret']) {
$input['clear_cache'] = "y";
}
$options['api_key'] = trim($input['api_key']);
$options['api_secret'] = trim($input['api_secret']);
if ($input['clear_cache'] == "y") {
// since clear_cache is checked, wipe out the contents of the fmc_cache_* transient items
// but don't do anything else since we aren't saving the state of this particular checkbox
flexmlsConnect::clear_temp_cache();
}
if ($input['default_titles'] == "y") {
$options['default_titles'] = true;
}
else {
$options['default_titles'] = false;
}
$options['destpref'] = $input['destpref'];
$options['destlink'] = $input['destlink'];
$options['destwindow'] = $input['destwindow'];
$options['default_link'] = $input['default_link'];
$options['neigh_template'] = $input['neigh_template'];
if ($input['contact_notifications'] == "y") {
$options['contact_notifications'] = true;
}
else {
$options['contact_notifications'] = false;
}
return $options;
}
function settings_overview_api() {
if (flexmlsConnect::has_api_saved() == false) {
echo "
Please call FBS Broker Agent Services at 800-437-4232, ext. 108, or email idx@flexmls.com to purchase a key to activate your plugin.
";
}
}
function settings_overview_plugin() {
//echo "
Tweak how the flexmls® Connect plugin behaves.
";
}
function settings_overview_helpful() {
echo "
Here is some information you may find helpful.
";
}
function settings_field_api_key() {
global $fmc_plugin_url;
$options = get_option('fmc_settings');
$api_status_info = "";
if (flexmlsConnect::has_api_saved()) {
$fmc_api = new flexmlsApiWP;
$api_auth = $fmc_api->Authenticate(true);
if ($api_auth === false) {
$api_status_info = " Error with entered info";
}
else {
$api_status_info = " It works!";
}
}
echo "{$api_status_info}\n";
}
function settings_field_api_secret() {
$options = get_option('fmc_settings');
echo "\n";
}
function settings_field_default_titles() {
$options = get_option('fmc_settings');
$checked = "";
if ($options['default_titles'] == true) {
$checked_yes = " checked='checked'";
}
else {
$checked_no = " checked='checked'";
}
echo " ";
echo " \n";
echo "Use the default widget titles when no title is entered.\n";
}
function settings_field_clear_cache() {
// stale option that doesn't pay attention to any saved option. this simply triggers the cache clearing
echo "\n";
}
function settings_field_destlink() {
$options = get_option('fmc_settings');
$args = array(
'name' => 'fmc_settings[destlink]',
'selected' => $options['destlink']
);
$checked_code = " checked='checked'";
if ($options['destpref'] == "own") {
$checked_own = $checked_code;
}
elseif ($options['destpref'] == "page") {
$checked_page = $checked_code;
}
else {
$checked_own = $checked_code;
}
if ($options['destwindow'] == "new") {
$checked_new = $checked_code;
}
echo "";
echo " \n";
echo " \n";
echo " \n";
echo " \n";
echo " Page: ";
wp_dropdown_pages($args);
echo " ";
echo " View the documentation for more details on how this works. ";
echo "
";
echo "
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:
";
echo "
[idx_frame width='100%' height='600']
";
echo "
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.
";
echo "
Note: When you activated this plugin, a page with this shortcode in the body was created automatically.
";
echo "
Another Note: If you're using a SEO plugin, you may need to disable Permalink Cleaning for this feature to work.
";
echo "
";
}
function settings_field_default_link() {
$options = get_option('fmc_settings');
$selected_default_link = $options['default_link'];
if (flexmlsConnect::has_api_saved()) {
$fmc_api = new flexmlsApiWP;
$api_links = $fmc_api->GetIDXLinks();
if ($api_links === false) {
if ($fmc_api->last_error_code == 1500) {
echo "This functionality requires a subscription to flexmls® IDX in order to work. Buy Now.";
}
else {
echo "Information not currently available due to API issue.";
}
return;
}
echo "\n";
echo " \n";
echo "Select the default flexmls® IDX link your widgets should use";
}
else {
echo "You must enter API key information to select this option.";
}
}
function settings_field_neigh_template() {
$options = get_option('fmc_settings');
$selected_neigh_template = $options['neigh_template'];
$args = array(
'name' => 'fmc_settings[neigh_template]',
'selected' => $selected_neigh_template,
'post_status' => 'draft',
'echo' => false
);
$page_selection = wp_dropdown_pages($args);
if (!empty($page_selection)) {
echo $page_selection;
}
else {
echo "Please create a page as a draft to select it here.";
}
echo " Select the page to use as your default neighborhood page template.";
}
function settings_field_contact_notifications() {
$options = get_option('fmc_settings');
$checked_code = " checked='checked'";
if (!array_key_exists('contact_notifications', $options)) {
$checked_yes = $checked_code;
}
elseif ($options['contact_notifications'] === true) {
$checked_yes = $checked_code;
}
else {
$checked_no = $checked_code;
}
echo " ";
echo " \n";
}
function settings_helpful_proptypes() {
$fmc_api = new flexmlsApiWP;
$api_prop_types = $fmc_api->PropertyTypes();
$api_system_info = $fmc_api->SystemInfo();
if ($api_prop_types === false || $api_system_info === false) {
echo "Information not currently available due to API issue.";
return;
}
echo "Below are the names and codes for each property type {$api_system_info['Mls']} supports: \n";
echo "
\n";
echo "
Code
Property Type
\n";
foreach ($api_prop_types as $k => $v) {
echo "
{$k}
{$v}
\n";
}
echo "
\n";
}
function settings_helpful_idxlinks() {
$fmc_api = new flexmlsApiWP;
$api_links = $fmc_api->GetIDXLinks();
if ($api_links === false) {
if ($fmc_api->last_error_code == 1500) {
echo "This functionality requires a subscription to flexmls® IDX in order to work. Buy Now.";
}
else {
echo "Information not currently available due to API issue.";
}
return;
}
echo "Below are the names and codes for saved IDX link you have: \n";
echo "
\n";
echo "
Code
Name
\n";
foreach ($api_links as $link) {
echo "
{$link['LinkId']}
{$link['Name']}
\n";
}
echo "
\n";
}
function clean_spaces_and_trim($value) {
$value = trim($value);
// keep looking for sequences of multiple spaces until they no longer exist
while (preg_match('/\s\s+/', "{$value}")) {
$value = preg_replace('/\s\s+/', ' ', "{$value}");
}
return trim($value);
}
function strip_quotes($value) {
$value = stripslashes($value);
if (preg_match('/^\'(.*?)\'$/', $value)) {
return substr($value, 1, -1);
}
else {
return $value;
}
}
function widget_not_available(&$api, $detailed = false, $args = false, $settings = false) {
$return = "";
if (is_array($args)) {
$return .= $args['before_widget'];
$return .= $args['before_title'];
$return .= $settings['title'];
$return .= $args['after_title'];
}
if ($api->last_error_code == 1500) {
$message = "This widget requires a subscription to flexmls® IDX in order to work. Buy Now.";
}
elseif ($detailed == true) {
$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;
}
else {
$message = "This widget is temporarily unavailable. Please refresh the page or try again later. Error code: ".$api->last_error_code;
}
$return .= $message;
if (is_array($args)) {
$return .= $args['after_widget'];
}
return $return;
}
function widget_missing_requirements($widget, $reqs_missing) {
if (is_user_logged_in()) {
return "flexmls® IDX: {$reqs_missing} are required settings for the {$widget} widget.";
}
else {
return false;
}
}
function shortcode($attr = array()) {
if (!is_array($attr)) {
$attr = array();
}
if (!array_key_exists('width', $attr)) {
$attr['width'] = 600;
}
if (!array_key_exists('height', $attr)) {
$attr['height'] = 500;
}
$show_link = flexmlsConnect::get_default_idx_link_url();
$query_url = flexmlsConnect::wp_input_get('url');
if (!empty($query_url)) {
$show_link = $query_url;
}
else {
$default_link = $attr['default'];
if (!empty($default_link)) {
$show_link = $default_link;
}
}
if (empty($show_link)) {
return;
}
if (!empty($query_url)) {
$show_link = $query_url;
}
return "";
}
function is_mobile() {
$mobile_enabled = false;
// WPTouch: http://wordpress.org/extend/plugins/wptouch/
global $wptouch_plugin;
if (is_object($wptouch_plugin)) {
if ($wptouch_plugin->applemobile == true) {
$mobile_enabled = true;
}
}
// @todo add more later as deemed necessary
return $mobile_enabled;
}
function has_api_saved() {
$options = get_option('fmc_settings');
if ( empty($options['api_key']) || empty($options['api_secret']) ) {
return false;
}
else {
return true;
}
}
function use_default_titles() {
$options = get_option('fmc_settings');
if ($options['default_titles'] == true) {
return true;
}
else {
return false;
}
}
function get_destination_link() {
$options = get_option('fmc_settings');
$permalink = get_permalink($options['destlink']);
return $permalink;
}
function make_destination_link($link) {
$options = get_option('fmc_settings');
if (flexmlsConnect::get_destination_pref() == "own") {
return $link;
}
if (!empty($options['destlink'])) {
$permalink = get_permalink($options['destlink']);
if (empty($permalink)) {
return $link;
}
$return = "";
$link = urlencode($link);
if (strpos($permalink, '?') !== false) {
$return = $permalink . '&url=' . $link;
}
else {
$return = $permalink . '?url=' . $link;
}
return $return;
}
else {
return $link;
}
}
function get_destination_window_pref() {
$options = get_option('fmc_settings');
return $options['destwindow'];
}
function get_destination_pref() {
$options = get_option('fmc_settings');
return $options['destpref'];
}
function get_default_idx_link() {
$options = get_option('fmc_settings');
if (array_key_exists('default_link', $options) && !empty($options['default_link'])) {
return $options['default_link'];
}
else {
$fmc_api = new flexmlsApiWP;
$api_links = $fmc_api->GetIDXLinks();
return $api_links[0]['LinkId'];
}
}
function get_idx_link_details($my_link) {
$fmc_api = new flexmlsApiWP;
$api_links = $fmc_api->GetIDXLinks();
if (is_array($api_links)) {
foreach ($api_links as $link) {
if ($link['LinkId'] == $my_link) {
return $link;
}
}
}
return false;
}
function get_default_idx_link_url() {
$default_link = flexmlsConnect::get_default_idx_link();
$fmc_api = new flexmlsApiWP;
$api_links = $fmc_api->GetIDXLinks();
$valid_links = array();
foreach ($api_links as $link) {
$valid_links[$link['LinkId']] = array('Uri' => $link['Uri'], 'Name' => $link['Name']);
}
if (array_key_exists($default_link, $valid_links) && array_key_exists('Uri', $valid_links[$default_link])) {
return $valid_links[$default_link]['Uri'];
}
else {
return "";
}
}
function remove_starting_equals($val) {
if (preg_match('/^\=/', $val)) {
$val = substr($val, 1);
}
return $val;
}
function is_ie() {
$this_ua = getenv('HTTP_USER_AGENT');
if ($this_ua && (strpos($this_ua, 'MSIE') !== false) && (strpos($this_ua, 'Opera') === false) ) {
return true;
}
else {
return false;
}
}
function ie_version() {
ereg('MSIE ([0-9]\.[0-9])',$_SERVER['HTTP_USER_AGENT'],$reg);
if(!isset($reg[1])) {
return -1;
} else {
return floatval($reg[1]);
}
}
function clear_temp_cache() {
// get list of transient items to clear
$cache_tracker = get_transient('fmc_cache_tracker');
if (is_array($cache_tracker)) {
foreach ($cache_tracker as $key => $value) {
delete_transient('fmc_cache_'. $key);
}
}
delete_transient('fmc_cache_tracker');
}
function greatest_fitting_number($num, $slide, $max) {
if (($num * ($slide + 1)) <= $max) {
return flexmlsConnect::greatest_fitting_number($num, $slide + 1, $max);
}
else {
return $num * $slide;
}
}
/**
*
* Used to calculate the API limit needed to fill as many
* slides as possible without having any partially filled.
*/
function generate_api_limit_value($hor, $ver) {
// _limit number to shoot for if we can
$kind_limit = 10;
// maximum _limit is allowed to be
$max_limit = 25;
if (empty($hor)) {
$hor = 1;
}
if (empty($ver)) {
$ver = 1;
}
$total = $hor * $ver;
if ($total < $kind_limit) {
return flexmlsConnect::greatest_fitting_number($total, 1, $kind_limit);
}
elseif ($total >= $kind_limit && $total <= $max_limit) {
return $total;
}
else {
return $max_limit;
}
}
function generate_appropriate_dimensions($hor, $ver) {
$new_horizontal = $hor;
if ($new_horizontal > 25) {
$new_horizontal = 25;
}
$initial_total = ($hor * $ver);
if ($initial_total > 25) {
$room_to_grow = true;
$new_vertical = 1;
while ($room_to_grow) {
if (($new_horizontal * ($new_vertical + 1)) >= 25) {
$room_to_grow = false;
}
else {
$new_vertical++;
}
}
}
else {
// the grid is fine as-is
$new_vertical = $ver;
}
return array( $new_horizontal, $new_vertical );
}
function parse_location_search_string($location) {
$locations = array();
if (!empty($location)) {
if (preg_match('/\|/', $location)) {
$locations = explode("|", $location);
}
else {
$locations[] = $location;
}
}
$return = array();
foreach ($locations as $loc) {
list($loc_name, $loc_value) = explode("=", $loc, 2);
list($loc_value, $loc_display) = explode("&", $loc_value);
$loc_value_nice = preg_replace('/^\'(.*)\'$/', "$1", $loc_value);
// if there weren't any single quotes, just use the original value
if (empty($loc_value_nice)) {
$loc_value_nice = $loc_value;
}
$loc_value_nice = flexmlsConnect::remove_starting_equals($loc_value_nice);
$return[] = array(
'r' => $loc,
'f' => $loc_name,
'v' => $loc_value_nice,
'l' => $loc_display
);
}
return $return;
}
function cache_turned_on() {
return true;
}
function get_neighborhood_template_content($page_id = false) {
$neigh_template_page_id = flexmlsConnect::get_neighborhood_template_id($page_id);
if (!$neigh_template_page_id) {
return false;
}
$content = get_page($neigh_template_page_id);
return $content->post_content;
}
function get_neighborhood_template_id($page_id = false) {
if (!$page_id || $page_id == "default") {
$options = get_option('fmc_settings');
$neigh_template_page_id = $options['neigh_template'];
}
else {
$neigh_template_page_id = $page_id;
}
if (empty($neigh_template_page_id)) {
return false;
}
return $neigh_template_page_id;
}
function unescape_request_var($string) {
return stripslashes($string);
}
function special_location_tag_text() {
return " You can use {Location} on neighborhood templates to customize.";
}
function wp_input_get($key) {
if (isset($_GET) && is_array($_GET) && array_key_exists($key, $_GET)) {
return self::wp_input_clean($_GET[$key]);
}
else {
// parse the query string manually. some kind of internal redirect
// or protection is keeping PHP from knowing what $_GET is
$full_requested_url = (preg_match('/^HTTP\//', $_SERVER['SERVER_PROTOCOL'])) ? "http" : "https";
$full_requested_url .= "://". $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$query_string = parse_url($full_requested_url, PHP_URL_QUERY);
$query_parts = explode("&", $query_string);
$manual = array();
foreach ($query_parts as $p) {
list($k, $v) = @explode("=", $p, 2);
if (array_key_exists($k, $manual)) {
$manual[$k] .= ",".urldecode($v);
}
else {
$manual[$k] = urldecode($v);
}
}
return $manual[$key];
}
}
function wp_input_post($key) {
if (isset($_POST) && is_array($_POST) && array_key_exists($key, $_POST)) {
return self::wp_input_clean($_POST[$key]);
}
else {
return null;
}
}
function wp_input_get_post($key) {
$via_post = self::wp_input_post($key);
if ($via_post !== null) {
return $via_post;
}
$via_get = self::wp_input_get($key);
if ($via_get !== null) {
return $via_get;
}
return null;
}
function wp_input_clean($string) {
$string = stripslashes($string);
return $string;
}
function send_notification() {
$options = get_option('fmc_settings');
if (!array_key_exists('contact_notifications', $options)) {
return true;
}
elseif ($options['contact_notifications'] === true) {
return true;
}
else {
return false;
}
}
}