This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexmls_connect.php
executable file
·285 lines (243 loc) · 12.4 KB
/
flexmls_connect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/*
Plugin Name: Flexmls® Powered by Spark
Plugin URI: https://wpdemo.flexblogs.flexmls.com/
Description: Provides Flexmls® customers with live real estate listings and IDX features powered by the <a href="https://sparkplatform.com/" target="_blank">Spark API</a> from FBS Data. <strong>Tips:</strong> <a href="admin.php?page=fmc_admin_settings">Activate your Flexmls® IDX plugin</a> on the settings page; <a href="widgets.php">add widgets to your sidebar</a> using the Widgets Admin under Appearance; and include widgets on your posts or pages using the Flexmls® IDX Widget Short-Code Generator on the Visual page editor.
Author: FBS
Version: 4.0.0
Author URI: https://www.flexmls.com/
*/
// Don't load this file if WordPress isn't being used
defined( 'ABSPATH' ) or die( 'This plugin requires WordPress' );
// Constants used throughout the plugin
const FLEXMLS_API_URL = 'https://sparkapi.com';
const FLEXMLS_API_VERSION = 'v1';
const FLEXMLS_PLUGIN_VERSION = '4.0.0';
define( 'FLEXMLS_PLUGIN_DIR_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'FLEXMLS_PLUGIN_DIR_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
// Utility function to test for Flexmls debug mode
if( !function_exists( 'in_flexmls_debug_mode' ) ){
function in_flexmls_debug_mode(){
if( defined( 'FMC_DEV' ) && FMC_DEV && WP_DEBUG ){
return true;
}
return false;
}
}
// If in development mode, move the debug log to the plugin folder for easier viewing
if( in_flexmls_debug_mode() ){
ini_set( 'error_log', FLEXMLS_PLUGIN_DIR_PATH . '/debug.log' );
}
// Utility function to write to the debug log
if( !function_exists( 'write_log' ) ){
function write_log( $log, $title = 'Flexmls Log Item' ){
if( defined( 'DOING_CRON' ) ){
$title = 'CRON: ' . $title;
}
error_log( '********** ' . $title . ' **********' );
if( is_array( $log ) || is_object( $log ) ){
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
function fmc_array_get($array, $key, $default = null)
{
if (is_null($key)) return $array;
if (isset($array[$key])) return $array[$key];
foreach (explode('.', $key) as $segment)
{
if ( ! is_array($array) || ! array_key_exists($segment, $array))
{
return $default;
}
$array = $array[$segment];
}
return $array;
}
// Autoload all of the supporting classes
include_once( FLEXMLS_PLUGIN_DIR_PATH . '/autoloader.php' );
// Main plugin class. All actions, filters, and shortcodes are hooked here.
class Flexmls {
public $listings_order_by;
public $listings_per_page;
public $oauth_tokens;
public static $default_options = array(
'credentials' => array(
'api_key' => '',
'api_secret' => '',
'oauth_key' => '',
'oauth_secret' => ''
),
'general' => array(
'default_search_link' => '',
'display_widget_titles' => 1,
'lead_notify' => 1,
'listing_not_available_page' => '',
'listing_not_available' => 'std_404',
'multiple_summaries' => 0,
'property_types' => array(),
'search_results_fields' => array(
'PropertyType' => 'Property Type',
'BedsTotal' => '# of Bedrooms',
'BathsTotal' => '# of Bathrooms',
'BuildingAreaTotal' => 'Square Footage',
'YearBuilt' => 'Year Built',
'MLSAreaMinor' => 'Area',
'SubdivisionName' => 'Subdivision',
'PublicRemarks' => 'Description'
),
'search_results_default' => '',
'search_results_page' => '',
'sold_listings' => 0,
),
'gmaps' => array(
'api_key' => '',
'height' => 450,
'units' => 'px',
'no_js' => 0
),
'other' => array(
'plugin_version' => FLEXMLS_PLUGIN_VERSION
),
'portal' => array(
'delay' => array(
'time_on_page' => '',
'time_on_site' =>'',
'summary_page_views' => '',
'detail_page_views' => ''
),
'popup_summaries' => 0,
'popup_details' => 0,
'portal_title' => 'Sign Up',
'require_login' => 0,
'registration_text' => 'Create an account to save and hide listings.',
'allow_carts' => 1
),
'seo' => array(
'permalink_base' => 'idx'
)
);
function __construct(){
//add_action( 'admin_head-nav-menus.php', array( 'FBS\Admin\NavMenus', 'add_saved_searches_meta_boxes' ) );
add_action( 'admin_init', array( $this, 'init_and_maybe_flush_permalinks' ), 0 );
add_action( 'admin_menu', array( FBS\Admin\Settings::class, 'admin_menu' ) );
add_action( 'admin_notices', array( FBS\Admin\Settings::class, 'notice_test_environment' ), 9 );
add_action( 'admin_enqueue_scripts', array( FBS\Admin\Enqueue::class, 'admin_enqueue_scripts' ) );
add_action( 'before_delete_post', array( $this, 'prevent_delete_flexmls_search_page' ), 10, 1 );
add_action( 'edit_form_after_title', array( FBS\Pages\Page::class, 'neighborhood_template_page_notice' ), 9 );
add_action( 'edit_form_after_title', array( FBS\Pages\Page::class, 'search_results_page_notice' ), 9 );
add_action( 'init', array( FBS\Admin\Settings::class, 'update_settings' ), 9 );
add_action( 'init', array( FBS\Pages\Page::class, 'custom_rewrite_rules' ), 10, 0 );
add_action( 'init', array( FBS\Pages\Page::class, 'set_global_listing_vars' ) );
add_action( 'init', array( SparkAPI\Oauth::class, 'custom_rewrite_rules' ), 10, 0 );
add_action( 'parse_request', array( SparkAPI\Oauth::class, 'test_if_oauth_action' ) );
add_action( 'preload_related_search_results', array( FBS\Pages\Page::class, 'preload_related_search_results' ) );
add_action( 'post_updated', array( FBS\Pages\Page::class, 'maybe_update_permalink' ), 10, 3 );
add_action( 'publish_page', array( $this, 'prevent_publish_flexmls_neighborhood_page' ), 10, 2 );
add_action( 'widgets_init', array( FBS\Widgets\Widgets::class, 'widgets_init' ) );
add_action( 'wp', array( FBS\Pages\Page::class, 'test_if_idx_page' ), 9 );
add_action( 'wp_ajax_clear_spark_api_cache', array( $this, 'ajax_clear_cache' ) );
add_action( 'wp_ajax_flexmls_leadgen', array( FBS\Widgets\LeadGeneration::class, 'flexmls_leadgen' ) );
add_action( 'wp_ajax_nopriv_flexmls_leadgen', array( FBS\Widgets\LeadGeneration::class, 'flexmls_leadgen' ) );
add_action( 'wp_ajax_flexmls_listing_ask_question', array( FBS\Pages\Page::class, 'ask_question' ) );
add_action( 'wp_ajax_nopriv_flexmls_listing_ask_question', array( FBS\Pages\Page::class, 'ask_question' ) );
add_action( 'wp_ajax_flexmls_get_background_slides', array( FBS\Widgets\Slideshow::class, 'get_background_slides' ) );
add_action( 'wp_ajax_nopriv_flexmls_get_background_slides', array( FBS\Widgets\Slideshow::class, 'get_background_slides' ) );
add_action( 'wp_ajax_get_listing_media', array( FBS\Pages\Page::class, 'listing_media' ) );
add_action( 'wp_ajax_nopriv_get_listing_media', array( FBS\Pages\Page::class, 'listing_media' ) );
add_action( 'wp_ajax_flexmls_listing_schedule_showing', array( FBS\Pages\Page::class, 'schedule_showing' ) );
add_action( 'wp_ajax_nopriv_flexmls_listing_schedule_showing', array( FBS\Pages\Page::class, 'schedule_showing' ) );
add_action( 'wp_ajax_toggle_cart_status', array( SparkAPI\Oauth::class, 'toggle_cart_status' ) );
add_action( 'wp_ajax_nopriv_toggle_cart_status', array( SparkAPI\Oauth::class, 'toggle_cart_status' ) );
add_action( 'wp_ajax_location_search_form', array( FBS\Widgets\LocationSearch::class, 'ajax_form' ) );
add_action( 'wp_ajax_slideshow_form', array( FBS\Widgets\Slideshow::class, 'ajax_form' ) );
add_action( 'wp_ajax_general_search_form', array( FBS\Widgets\Search::class, 'ajax_form' ) );
add_action( 'wp_ajax_idx_links_form', array( FBS\Widgets\IDXLinks::class, 'ajax_form' ) );
add_action( 'wp_ajax_lead_generation_form', array( FBS\Widgets\LeadGeneration::class, 'ajax_form' ) );
add_action( 'wp_ajax_market_stats_form', array( FBS\Widgets\MarketStats::class, 'ajax_form' ) );
add_action( 'wp_ajax_portal_form', array( FBS\Widgets\Portal::class, 'ajax_form' ) );
add_action( 'wp_enqueue_scripts', array( FBS\Admin\Enqueue::class, 'wp_enqueue_scripts' ) );
add_action( 'wp_trash_post', array( $this, 'prevent_delete_flexmls_search_page' ), 10, 1 );
add_filter( 'body_class', array( $this, 'body_class' ) );
add_filter( 'nav_menu_css_class' , array( FBS\Pages\Page::class, 'nav_menu_css_class' ), 10, 2 );
add_filter( 'mce_buttons', array( FBS\Admin\TinyMCE::class, 'mce_buttons' ) );
add_filter( 'mce_external_plugins', array( FBS\Admin\TinyMCE::class, 'mce_external_plugins' ) );
//add_filter( 'nav_menu_meta_box_object', array( 'FBS\Admin\NavMenus', 'nav_menu_meta_box_object' ) );
add_filter( 'script_loader_tag', array( FBS\Admin\Enqueue::class, 'script_loader_tag' ), 10, 2 );
add_shortcode( 'flexmls_general_search', array( FBS\Widgets\Shortcodes::class, 'flexmls_general_search' ) );
add_shortcode( 'flexmls_idxlinks', array( FBS\Widgets\Shortcodes::class, 'flexmls_idxlinks' ) );
add_shortcode( 'flexmls_leadgen', array( FBS\Widgets\Shortcodes::class, 'flexmls_leadgen' ) );
add_shortcode( 'flexmls_portal', array( FBS\Widgets\Shortcodes::class, 'flexmls_portal' ) );
add_shortcode( 'flexmls_market_stats', array( FBS\Widgets\Shortcodes::class, 'flexmls_market_stats' ) );
add_shortcode( 'flexmls_location_search', array( FBS\Widgets\Shortcodes::class, 'flexmls_location_search' ) );
}
function ajax_clear_cache(){
$SparkAPI = new \SparkAPI\Core();
$SparkAPI->clear_cache( true );
exit( json_encode( array(
'success' => 1
) ) );
}
public static function activate(){
$flexmls_settings = get_option( 'flexmls_settings' );
if( !$flexmls_settings ){
// This is a fresh install.
$flexmls_settings = Flexmls::$default_options;
$post_id = wp_insert_post( array(
'post_name' => 'idx',
'post_status' => 'publish',
'post_title' => 'Real Estate Listings Powered By Flexmls®',
'post_type' => 'page'
) );
$flexmls_settings[ 'general' ][ 'search_results_page' ] = $post_id;
update_option( 'flexmls_do_flush_permalinks', 1 );
update_option( 'flexmls_settings', $flexmls_settings, true );
update_option( 'flexmls_version', FLEXMLS_PLUGIN_VERSION, false );
flush_rewrite_rules();
return;
}
// This is a plugin reactivation or upgrade.
FBS\Admin\Upgrade::maybe_do_upgrade();
$SparkAPI = new SparkAPI\Core();
$SparkAPI->clear_cache( true );
}
function body_class( $classes ){
$classes[] = 'flexmls';
$classes[] = 'flexmls-theme-default';
$classes[] = 'flexmls-no-js';
return $classes;
}
function init_and_maybe_flush_permalinks(){
// We have to flush permalinks early on the next request if the admin changed
// the main search page slug because it can't happen on the save_post action
if( get_option( 'flexmls_do_flush_permalinks' ) ){
flush_rewrite_rules();
delete_option( 'flexmls_do_flush_permalinks' );
}
}
function prevent_delete_flexmls_search_page( $post_id ){
$flexmls_settings = get_option( 'flexmls_settings' );
$search_results_page = $flexmls_settings[ 'general' ][ 'search_results_page' ];
if( $post_id == $search_results_page ){
wp_die( '<h2>Flexmls® Plugin Notice</h2><p>This page is required by your Flexmls® IDX plugin. To delete it, you must first <a href="' . admin_url( 'admin.php?page=flexmls_settings' ) . '">set a different page as your Flexmls® search results page</a>.</p><p>If you want to temporarily disable IDX searches and listings on your site, you can unpublish this page (set it to <em>draft</em> status); however, to delete it entirely, you must first set a new page as your search results page or disable the Flexmls® IDX plugin entirely.</p><p><a href="' . admin_url( 'edit.php?post_type=page' ) . '">← Back to Pages</a></p>', 'Flexmls Plugin Warning' );
}
}
function prevent_publish_flexmls_neighborhood_page( $ID, $post ){
$flexmls_settings = get_option( 'flexmls_settings' );
$neighborhood_template = 0;
if( isset( $flexmls_settings[ 'general' ][ 'neighborhood_template' ] ) ){
$neighborhood_template = $flexmls_settings[ 'general' ][ 'neighborhood_template' ];
}
if( $ID == $neighborhood_template ){
wp_update_post( array(
'ID' => $neighborhood_template,
'post_status' => 'draft'
) );
wp_die( '<h2>Flexmls® Plugin Notice</h2><p>This page is the neighborhood template of your Flexmls® plugin and must remain as a draft. To publish it, you must first <a href="' . admin_url( 'admin.php?page=flexmls_settings&tab=neighborhoods' ) . '">set a different page as your Flexmls® neighborhood template page</a>.</p><p><a href="' . admin_url( 'edit.php?post_type=page' ) . '">← Back to Pages</a></p>', 'Flexmls Plugin Warning' );
}
}
}
register_activation_hook( __FILE__, array( 'Flexmls', 'activate' ) );
$Flexmls = new Flexmls();