PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.0.6
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.0.6
7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 6.0.7 All 35 releases
mlsimport / includes / class-mlsimport.php

class-mlsimport.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.0.6, at includes/class-mlsimport.php

377 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Core plugin bootstrap class.
4 *
5 * Defines Mlsimport, the orchestrator instantiated from mlsimport.php. It loads the
6 * plugin's dependencies (loader, i18n, admin, custom post type, public), then registers
7 * every WordPress hook — admin enqueues, option-save handlers, admin menu, AJAX handlers,
8 * background-import actions, and the public-facing filters — through the Mlsimport_Loader.
9 * Calling run() finally hands the collected hooks to WordPress.
10 *
11 * @package MLSImport
12 */
13 // Abort if the file is accessed directly outside of WordPress.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly
16 }
17
18 /**
19 * The file that defines the core plugin class
20 *
21 * A class definition that includes attributes and functions used across both the
22 * public-facing side of the site and the admin area.
23 *
24 * @link http://mlsimport.com/
25 * @since 1.0.0
26 *
27 * @package Mlsimport
28 * @subpackage Mlsimport/includes
29 */
30
31 /**
32 * The core plugin class.
33 *
34 * This is used to define internationalization, admin-specific hooks, and
35 * public-facing site hooks.
36 *
37 * Also maintains the unique identifier of this plugin as well as the current
38 * version of the plugin.
39 *
40 * @since 1.0.0
41 * @package Mlsimport
42 * @subpackage Mlsimport/includes
43 * @author MlsImport <office@mlsimport.com>
44 */
45 class Mlsimport {
46
47 /**
48 * The loader that's responsible for maintaining and registering all hooks that power
49 * the plugin.
50 *
51 * @since 1.0.0
52 * @access protected
53 * @var Mlsimport_Loader $loader Maintains and registers all hooks for the plugin.
54 */
55 protected $loader;
56
57 /**
58 * The unique identifier of this plugin.
59 *
60 * @since 1.0.0
61 * @access protected
62 * @var string $plugin_name The string used to uniquely identify this plugin.
63 */
64 protected $plugin_name;
65
66 /**
67 * The current version of the plugin.
68 *
69 * @since 1.0.0
70 * @access protected
71 * @var string $version The current version of the plugin.
72 */
73 protected $version;
74
75 /**
76 * Define the core functionality of the plugin.
77 *
78 * Set the plugin name and the plugin version that can be used throughout the plugin.
79 * Load the dependencies, define the locale, and set the hooks for the admin area and
80 * the public-facing side of the site.
81 *
82 * @since 1.0.0
83 */
84
85 /**
86 * Store plugin admin class to allow public access.
87 *
88 * @since 20180622
89 * @var object The admin class.
90 */
91 public $admin;
92
93 /**
94 * Store plugin public class to allow public access.
95 *
96 * @since 20180622
97 * @var object The admin class.
98 */
99 public $public;
100
101 /**
102 * Set the plugin name/version and wire up all dependencies and hooks.
103 */
104 public function __construct() {
105 // Use the defined plugin version constant, else fall back to 1.0.0.
106 if ( defined( 'MLSIMPORT_VERSION' ) ) {
107 $this->version = MLSIMPORT_VERSION;
108 } else {
109 $this->version = '1.0.0';
110 }
111 // Unique plugin identifier used for option keys and hook names.
112 $this->plugin_name = 'mlsimport';
113
114 // Load classes, set translations, then register admin + public hooks.
115 $this->load_dependencies();
116 $this->set_locale();
117 $this->define_admin_hooks();
118 $this->define_public_hooks();
119 }
120
121 /**
122 * Load the required dependencies for this plugin.
123 *
124 * Include the following files that make up the plugin:
125 *
126 * - Mlsimport_Loader. Orchestrates the hooks of the plugin.
127 * - Mlsimport_i18n. Defines internationalization functionality.
128 * - Mlsimport_Admin. Defines all hooks for the admin area.
129 * - Mlsimport_Public. Defines all hooks for the public side of the site.
130 *
131 * Create an instance of the loader which will be used to register the hooks
132 * with WordPress.
133 *
134 * @since 1.0.0
135 * @access private
136 */
137 private function load_dependencies() {
138
139 /**
140 * The class responsible for orchestrating the actions and filters of the
141 * core plugin.
142 */
143 // Hook loader/registry.
144 require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-loader.php';
145
146 /**
147 * The class responsible for defining internationalization functionality
148 * of the plugin.
149 */
150 // Translation loading.
151 require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-i18n.php';
152
153 /**
154 * The class responsible for defining all actions that occur in the admin area.
155 */
156 // Admin monolith (settings, AJAX, imports).
157 require_once plugin_dir_path( __DIR__ ) . 'admin/class-mlsimport-admin.php';
158
159 /**
160 * The class responsible for custom post type
161 */
162 // mlsimport_item custom post type.
163 require_once plugin_dir_path( __DIR__ ) . 'includes/class-mlsimport-item.php';
164
165 /**
166 * The class responsible for defining all actions that occur in the public-facing
167 * side of the site.
168 */
169 // Public-facing side of the plugin.
170 require_once plugin_dir_path( __DIR__ ) . 'public/class-mlsimport-public.php';
171
172 // Instantiate the loader that collects all hook registrations.
173 $this->loader = new Mlsimport_Loader();
174 }
175
176 /**
177 * Define the locale for this plugin for internationalization.
178 *
179 * Uses the Mlsimport_i18n class in order to set the domain and to register the hook
180 * with WordPress.
181 *
182 * @since 1.0.0
183 * @access private
184 */
185 private function set_locale() {
186
187 // The i18n helper that loads the plugin's text domain.
188 $plugin_i18n = new Mlsimport_i18n();
189
190 // Load translations at `init` to ensure the locale is fully set.
191 // Loading earlier can trigger WordPress notices starting WP 6.7.
192 $this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' );
193 }
194
195 /**
196 * Register all of the hooks related to the admin area functionality
197 * of the plugin.
198 *
199 * @since 1.0.0
200 * @access private
201 */
202 private function define_admin_hooks() {
203
204 // Instantiate the admin class (kept public via $this->admin) and configure it.
205 $this->admin = $plugin_admin = new Mlsimport_Admin( $this->get_plugin_name(), $this->get_version() );
206
207 // Pass the current MLS provider and theme environment into the admin class.
208 $this->admin->admin_setup( $this->get_plugin_name(), $this->get_plugin_data( 'mls_enviroment' ), $this->get_plugin_data( 'theme_enviroment' ) );
209
210 // Enqueue admin CSS/JS.
211 $this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' );
212 $this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' );
213
214 // Register the mlsimport_item custom post type late on init (priority 999).
215 $plugin_post_types = new Mlsimport_Item();
216 $this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 );
217
218 // save and render metaboxed
219 // Import-task metaboxes: render on admin_init, persist on save_post.
220 $this->loader->add_action( 'admin_init', $plugin_admin, 'mlsimport_item_product_metaboxes' );
221 $this->loader->add_action( 'save_post', $plugin_admin, 'mlsimport_item_product_save_metaboxes', 1, 2 );
222
223 // Save/Update our plugin options
224 // Persist settings, and react to changes of the field-selection option.
225 $this->loader->add_action( 'admin_init', $this->admin, 'options_update' );
226 $this->loader->add_action( 'update_option_' . $this->plugin_name . '_admin_fields_select', $this->admin, 'update_option_mlsimport_admin_fields_select' );
227 $this->loader->add_action( 'add_option_' . $this->plugin_name . '_admin_fields_select', $this->admin, 'update_option_mlsimport_admin_fields_select' );
228
229 // React to changes of the administrative options.
230 $this->loader->add_action( 'update_option_' . $this->plugin_name . '_administrative_options', $this->admin, 'update_option_mlsimport_administrative_options' );
231
232 // Add menu item
233 $this->loader->add_action( 'admin_menu', $this->admin, 'add_plugin_admin_menu' );
234
235 // Add Settings link to the plugin list
236 // Build this plugin's basename to target the plugin-row action links filter.
237 $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
238 $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $this->admin, 'add_action_links' );
239
240 // Register additional metabox options on admin_init.
241 $this->loader->add_action( 'admin_init', $this->admin, 'mlsimport_meta_options' );
242
243 // AJAX: per-item move/stop/metadata handlers.
244 $this->loader->add_action( 'wp_ajax_mlsimport_move_files_per_item', $this->admin, 'mlsimport_move_files_per_item' );
245 $this->loader->add_action( 'wp_ajax_mlsimport_stop_import_per_item', $this->admin, 'mlsimport_stop_import_per_item' );
246 $this->loader->add_action( 'wp_ajax_mlsimport_saas_get_metadata_function', $this->admin, 'mlsimport_saas_get_metadata_function' );
247
248 // Background import processing actions (full run and initial batch).
249 $this->loader->add_action( 'mlsimport_background_process_per_item', $this->admin, 'mlsimport_background_process_per_item_function', 10, 1 );
250 $this->loader->add_action( 'mlsimport_background_process_per_item_inital_batch', $this->admin, 'mlsimport_background_process_per_item_inital_batch_function', 10, 1 );
251
252 // AJAX: logging and file-move handlers.
253 $this->loader->add_action( 'wp_ajax_mlsimport_logger_per_item', $this->admin, 'mlsimport_logger_per_item' );
254 // AJAX: file-move and AWS log-move handlers.
255 $this->loader->add_action( 'wp_ajax_mlsimport_move_files', $this->admin, 'mlsimport_move_files' );
256 $this->loader->add_action( 'wp_ajax_mlsimport_move_files_to_aws_logger', $this->admin, 'mlsimport_move_files_to_aws_logger' );
257 // AJAX: stop-move, cache clear, field reset, property delete, term lookup, exit survey.
258 $this->loader->add_action( 'wp_ajax_mlsimport_stop_moving_files', $this->admin, 'mlsimport_stop_moving_files' );
259 $this->loader->add_action( 'wp_ajax_mlsimport_delete_cache', $this->admin, 'mlsimport_delete_cache' );
260 $this->loader->add_action( 'wp_ajax_mlsimport_clear_fields_data', $this->admin, 'mlsimport_clear_fields_data' );
261 $this->loader->add_action( 'wp_ajax_mlsimport_delete_properties', $this->admin, 'mlsimport_delete_properties' );
262 $this->loader->add_action( 'wp_ajax_mlsimport_get_taxonomy_terms', $this->admin, 'mlsimport_get_taxonomy_terms' );
263 $this->loader->add_action( 'wp_ajax_mlsimport_exit_survey_submit', $this->admin, 'mlsimport_exit_survey_submit' );
264 }
265
266 /**
267 * Register all of the hooks related to the public-facing functionality
268 * of the plugin.
269 *
270 * @since 1.0.0
271 * @access private
272 */
273 private function define_public_hooks() {
274
275 // Instantiate the public-facing class.
276 $plugin_public = new Mlsimport_Public( $this->get_plugin_name(), $this->get_version() );
277
278 // Enqueue front-end CSS/JS.
279 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
280 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
281 // Rewrite attachment URLs for remotely-hosted MLS images.
282 $this->loader->add_filter( 'wp_get_attachment_url', $plugin_public, 'mlsimport_wp_get_attachment_url', 99, 2 );
283
284
285 }
286
287 /**
288 * Run the loader to execute all of the hooks with WordPress.
289 *
290 * @since 1.0.0
291 */
292 public function run() {
293 // Hand all collected hooks over to WordPress.
294 $this->loader->run();
295 }
296
297 /**
298 * The name of the plugin used to uniquely identify it within the context of
299 * WordPress and to define internationalization functionality.
300 *
301 * @since 1.0.0
302 * @return string The name of the plugin.
303 */
304 public function get_plugin_name() {
305 // Return the stored plugin identifier.
306 return $this->plugin_name;
307 }
308
309 /**
310 * The reference to the class that orchestrates the hooks with the plugin.
311 *
312 * @since 1.0.0
313 * @return Mlsimport_Loader Orchestrates the hooks of the plugin.
314 */
315 public function get_loader() {
316 // Return the hook loader instance.
317 return $this->loader;
318 }
319
320 /**
321 * Retrieve the version number of the plugin.
322 *
323 * @since 1.0.0
324 * @return string The version number of the plugin.
325 */
326 public function get_version() {
327 // Return the resolved plugin version.
328 return $this->version;
329 }
330
331 /**
332 * return plugin shema
333 *
334 * Placeholder schema accessor; currently returns an empty string.
335 *
336 * @since 1.0.0
337 * @access protected
338 * @var string $plugin_name
339 * @return string Empty string (no schema).
340 */
341 public function return_plugin_schema() {
342
343 // No schema defined at this level.
344 return '';
345 }
346
347 /**
348 * return plugin data
349 *
350 * Reads a single value from the plugin schema. When the MLS environment is
351 * Trestle and a server token is requested, returns the Trestle token instead.
352 *
353 * @since 1.0.0
354 * @access protected
355 * @var string $plugin_name
356 * @param string $what The schema key to fetch (e.g. 'mls_enviroment').
357 * @return mixed The requested value, or '' when unavailable.
358 */
359 public function get_plugin_data( $what ) {
360 // Pull the (currently empty) plugin schema.
361 $plugin_data = $this->return_plugin_schema();
362
363 // Special case: Trestle server token comes from a dedicated helper.
364 if ( isset( $plugin_data['mls_enviroment'] ) && 'TresleReso' === $plugin_data['mls_enviroment'] && 'server_token' === $what ) {
365 $tresle_token = $this->return_tresle_token();
366 return $tresle_token;
367 }
368
369 // Return the requested key when present, else empty string.
370 if ( isset( $plugin_data[ $what ] ) ) {
371 return $plugin_data[ $what ];
372 } else {
373 return '';
374 }
375 }
376 }
377