PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 1.4.62 All 260 releases
propertyhive / includes / admin / class-ph-admin-assets.php

class-ph-admin-assets.php in Property Hive 2.2.4, at includes/admin/class-ph-admin-assets.php

469 lines 23.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Load assets.
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! class_exists( 'PH_Admin_Assets' ) ) :
14
15 /**
16 * PH_Admin_Assets Class
17 */
18 class PH_Admin_Assets {
19
20 /**
21 * Hook in tabs.
22 */
23 public function __construct() {
24 add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ), 5 );
25 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 5 );
26 }
27
28 /**
29 * Enqueue styles
30 */
31 public function admin_styles() {
32 global $wp_scripts;
33
34 // Sitewide menu CSS
35 //wp_enqueue_style( 'propertyhive_admin_menu_styles', PH()->plugin_url() . '/assets/css/menu.css', array(), PH_VERSION );
36
37 $screen = get_current_screen();
38
39 if ( in_array( $screen->id, ph_get_screen_ids() ) ) {
40
41 $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2';
42
43 // Admin styles for PH pages only
44 wp_enqueue_style( 'propertyhive_admin_styles', PH()->plugin_url() . '/assets/css/admin.css', array(), PH_VERSION );
45
46 wp_enqueue_style( 'font_awesome', PH()->plugin_url() . '/assets/css/font-awesome.min.css', array(), PH_VERSION );
47
48 wp_enqueue_style( 'jquery-ui-style', PH()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.css', array(), PH_VERSION );
49 wp_enqueue_style( 'wp-color-picker' );
50
51 wp_enqueue_style( 'chosen', PH()->plugin_url() . '/assets/css/chosen.css', array(), PH_VERSION );
52
53 wp_enqueue_style( 'multiselect', PH()->plugin_url() . '/assets/css/jquery.multiselect.css', array(), '2.4.18' );
54
55 if ( apply_filters('propertyhive_disable_notes_mention', false) === false )
56 {
57 wp_enqueue_style( 'tinymce-mention', PH()->plugin_url() . '/assets/js/tinymce-mention-plugin/autocomplete.css', array(), PH_VERSION );
58 }
59
60 if ( get_option('propertyhive_maps_provider') == 'mapbox' )
61 {
62 wp_enqueue_style('mapbox', PH()->plugin_url() . '/assets/js/mapbox/mapbox-gl.css', array(), '3.8.0' );
63 }
64 }
65
66 if ( in_array( $screen->id, array( 'property' ) ) )
67 {
68 if ( isset($_GET['tutorial']) && sanitize_text_field($_GET['tutorial']) == 'yes' )
69 {
70 wp_register_style( 'tour-css', PH()->plugin_url() . '/assets/css/tours/style.css', array(), '1.0.1' );
71 wp_register_style( 'driver-css', PH()->plugin_url() . '/assets/css/tours/driver-js.css', array(), '1.0.1' );
72 wp_enqueue_style( 'tour-css' );
73 wp_enqueue_style( 'driver-css' );
74 }
75 }
76
77 if ( in_array( $screen->id, array( 'edit-contact', 'edit-enquiry', 'edit-appraisal', 'edit-viewing', 'edit-offer', 'edit-sale', 'edit-key_date' ) ) )
78 {
79 wp_enqueue_style( 'daterangepicker.css', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css' );
80 }
81
82 if ( in_array( $screen->id, array( 'edit-key_date') ) )
83 {
84 wp_enqueue_style( 'admin-hide-default-post-data.css', PH()->plugin_url() . '/assets/css/admin-hide-default-post-data.css', PH_VERSION );
85 }
86
87 if (
88 get_option('propertyhive_module_disabled_viewings', '') != 'yes' &&
89 in_array( $screen->id, array( 'property', 'contact' ) )
90 )
91 {
92 wp_enqueue_style( 'propertyhive_fancybox_css', PH()->plugin_url() . '/assets/css/jquery.fancybox.css', array(), '3.5.7' );
93 }
94
95 /*if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
96 wp_enqueue_style( 'propertyhive_admin_dashboard_styles', PH()->plugin_url() . '/assets/css/dashboard.css', array(), PH_VERSION );
97 }*/
98
99 if ( $screen->id === 'plugins' )
100 {
101 // Enqueue the CSS file
102 wp_enqueue_style(
103 'propertyhive_deactivate_survey',
104 PH()->plugin_url() . '/assets/css/deactivate-survey.css',
105 array(),
106 '1.0.0'
107 );
108 }
109
110 do_action( 'propertyhive_admin_css' );
111 }
112
113
114 /**
115 * Enqueue scripts
116 */
117 public function admin_scripts() {
118 global $wp_query, $post, $tabs;
119
120 $screen = get_current_screen();
121 $ph_screen_id = sanitize_title( __( 'PropertyHive', 'propertyhive' ) );
122 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
123
124 // Register scripts
125 wp_register_script( 'propertyhive_dashboard', PH()->plugin_url() . '/assets/js/admin/dashboard' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION );
126
127 wp_register_script( 'propertyhive_admin', PH()->plugin_url() . '/assets/js/admin/admin' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-tiptip' ), PH_VERSION );
128
129 wp_register_script( 'jquery-tiptip', PH()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true );
130
131 wp_register_script( 'propertyhive_admin_meta_boxes', PH()->plugin_url() . '/assets/js/admin/meta-boxes' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable' ), PH_VERSION );
132
133 wp_register_script( 'propertyhive_admin_settings', PH()->plugin_url() . '/assets/js/admin/settings' . /*$suffix .*/ '.js', array( 'jquery', 'wp-color-picker' ), PH_VERSION );
134
135 wp_register_script( 'propertyhive_admin_recently_viewed', PH()->plugin_url() . '/assets/js/admin/recently-viewed' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION );
136
137 wp_register_script( 'ajax-chosen', PH()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . /*$suffix .*/ '.js', array('jquery', 'chosen'), PH_VERSION );
138
139 wp_register_script( 'chosen', PH()->plugin_url() . '/assets/js/chosen/chosen.jquery' . /*$suffix .*/ '.js', array('jquery'), PH_VERSION );
140
141 wp_register_script( 'multiselect', PH()->plugin_url() . '/assets/js/multiselect/jquery.multiselect' . /*$suffix .*/ '.js', array('jquery'), '2.4.18' );
142
143 wp_register_script( 'flot', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), PH_VERSION );
144 wp_register_script( 'flot-resize', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION );
145 wp_register_script( 'flot-time', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION );
146 //wp_register_script( 'flot-pie', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION );
147 //wp_register_script( 'flot-stack', PH()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), PH_VERSION );
148
149 wp_enqueue_script( 'propertyhive_admin' );
150
151 $params = array();
152
153 // Add a bit better support for Gutenberg if enabled somehow (i.e. using Houzez) to load AJAX grids
154 if (
155 isset($post->ID) &&
156 function_exists( 'use_block_editor_for_post_type' ) &&
157 use_block_editor_for_post_type( get_post_type($post->ID) ) &&
158 !isset( $_GET['classic-editor'] ) &&
159 is_array($tabs) &&
160 !empty($tabs)
161 )
162 {
163 $ajax_actions = array();
164
165 foreach ( $tabs as $key => $tab )
166 {
167 if ( isset($tab['ajax_actions']) && !empty($tab['ajax_actions']) )
168 {
169 foreach ( $tab['ajax_actions'] as $ajax_action )
170 {
171 $ajax_actions[] = $ajax_action;
172 }
173 }
174 }
175
176 if ( !empty($ajax_actions) )
177 {
178 $params = array(
179 'ajax_actions' => $ajax_actions,
180 'post_id' => $post->ID,
181 );
182
183 }
184 }
185
186 wp_localize_script( 'propertyhive_admin', 'propertyhive_admin', $params );
187
188 $recently_viewed = get_user_meta( get_current_user_id(), '_propertyhive_recently_viewed', TRUE );
189 if ( !is_array($recently_viewed) )
190 {
191 $recently_viewed = array();
192 }
193
194 $params = array(
195 'recently_viewed' => $recently_viewed,
196 );
197 wp_localize_script( 'propertyhive_admin_recently_viewed', 'propertyhive_admin_recently_viewed', $params );
198
199 wp_localize_script( 'multiselect', 'propertyhive_multiselect_params', apply_filters( 'propertyhive_multiselect_params', array(
200 'search' => false,
201 'selected_text' => __( 'selected', 'propertyhive' ),
202 ) ) );
203
204 // PropertyHive admin pages
205 if ( in_array( $screen->id, array( 'dashboard' ) ) )
206 {
207 wp_enqueue_script( 'propertyhive_dashboard' );
208
209 $params = array(
210 'ajax_url' => admin_url('admin-ajax.php'),
211 );
212 wp_localize_script( 'propertyhive_dashboard', 'propertyhive_dashboard', $params );
213 }
214
215 if ( in_array( $screen->id, array( 'edit-contact', 'edit-enquiry', 'edit-appraisal', 'edit-viewing', 'edit-offer', 'edit-sale', 'edit-key_date' ) ) )
216 {
217 wp_enqueue_script( 'moment.js', '//cdn.jsdelivr.net/momentjs/latest/moment.min.js' );
218 wp_enqueue_script( 'daterangepicker.js', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js' );
219 wp_enqueue_script( 'date_range_filter.js', PH()->plugin_url() . '/assets/js/admin/date_range_filter.js', array('jquery', 'moment.js', 'daterangepicker.js'), PH_VERSION );
220 }
221
222 if ( in_array( $screen->id, array( 'edit-key_date' ) ) )
223 {
224 wp_enqueue_script( 'inline-edit-key_date.js', PH()->plugin_url() . '/assets/js/admin/inline-edit-key_date.js', array('jquery'), PH_VERSION );
225 }
226
227 if (
228 get_option('propertyhive_module_disabled_viewings', '') != 'yes' &&
229 in_array( $screen->id, array( 'property', 'contact' ) )
230 )
231 {
232 wp_enqueue_script( 'propertyhive_fancybox', PH()->plugin_url() . '/assets/js/fancybox/jquery.fancybox.js', array('jquery'), '3.5.7' );
233 }
234
235 if ( in_array( $screen->id, array( 'property' ) ) )
236 {
237 if ( ! class_exists( '_WP_Editors', false ) )
238 {
239 require( ABSPATH . WPINC . '/class-wp-editor.php' );
240 }
241 add_action( 'admin_print_footer_scripts', array( '_WP_Editors', 'print_default_editor_scripts' ) );
242
243 if ( isset($_GET['tutorial']) && sanitize_text_field($_GET['tutorial']) == 'yes' )
244 {
245 wp_enqueue_script( 'driver-js', PH()->plugin_url() . '/assets/js/tours/driver-js.js', array(), '1.0.1' );
246 wp_register_script( 'tour', PH()->plugin_url() . '/assets/js/tours/tour.js', array( 'driver-js' ), '1.0.1' );
247 wp_enqueue_script( 'tour' );
248
249 $tours = [
250 'add-property' => [
251 [
252 'element' => '#title',
253 'popover' => [
254 'title' => __( 'Enter the Property\'s Display Address', 'propertyhive' ),
255 'description' => __( 'This is the title or address that will be shown publicly. Make it clear and appealing for your audience.', 'propertyhive' ),
256 'side' => 'bottom',
257 ],
258 ],
259 [
260 'element' => '#propertyhive_metabox_tabs',
261 'popover' => [
262 'title' => __( 'Explore the Property Record', 'propertyhive' ),
263 'description' => __( 'The property record is organized into sections for easy navigation. Use these tabs to switch between sections.<br><br>Go ahead, try clicking them now.', 'propertyhive' ),
264 'side' => 'bottom',
265 'onPrevClick' => 'revert_to_first_tab',
266 'onNextClick' => 'revert_to_first_tab',
267 ],
268 ],
269 [
270 'element' => '#propertyhive-property-address',
271 'popover' => [
272 'title' => __( 'Enter the Property Details', 'propertyhive' ),
273 'description' => __( 'Use these fields to input essential property information like address, price, bedrooms, and more. You can also upload images to showcase the property.', 'propertyhive' ),
274 'side' => 'top',
275 'onNextClick' => 'revert_to_third_tab',
276 ],
277 ],
278 [
279 'element' => '#\\_on_market',
280 'popover' => [
281 'title' => __( 'Put it on the Market', 'propertyhive' ),
282 'description' => __( 'For a property to show on your website it will need to be set to \'On Market\' under the \'Marketing\' tab.', 'propertyhive' ),
283 'side' => 'top',
284 'onPrevClick' => 'revert_to_first_tab',
285 'onNextClick' => 'revert_to_first_tab',
286 ],
287 ],
288 [
289 'element' => '#submitdiv',
290 'popover' => [
291 'title' => __( 'Publish your Property', 'propertyhive' ),
292 'description' => __( 'When you\'re done and are ready to save your changes, simply click \'Publish\'', 'propertyhive' ),
293 'side' => 'left',
294 'onPrevClick' => 'revert_to_third_tab',
295 ],
296 ],
297 ],
298 ];
299 wp_localize_script(
300 'tour',
301 'tour_plugin',
302 array(
303 'tours' => $tours,
304 )
305 );
306 }
307 }
308
309 if ( in_array( $screen->id, ph_get_screen_ids() ) )
310 {
311 wp_enqueue_script( 'ajax-chosen' );
312 wp_enqueue_script( 'chosen' );
313 wp_enqueue_script( 'jquery-ui-sortable' );
314 wp_enqueue_script( 'wp-tinymce' );
315
316 if ( get_option('propertyhive_maps_provider') == 'mapbox' )
317 {
318 wp_register_script('mapbox', PH()->plugin_url() . '/assets/js/mapbox/mapbox-gl.js', false, '3.8.0');
319 wp_enqueue_script('mapbox');
320
321 if ( get_option('propertyhive_geocoding_provider') == '' )
322 {
323 $api_key = get_option('propertyhive_google_maps_geocoding_api_key');
324 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
325 wp_enqueue_script('googlemaps');
326 }
327 }
328 elseif ( get_option('propertyhive_maps_provider') == 'osm' )
329 {
330 wp_register_style('leaflet', PH()->plugin_url() . '/assets/js/leaflet/leaflet.css', array(), '1.9.4');
331 wp_enqueue_style('leaflet');
332
333 wp_register_script('leaflet', PH()->plugin_url() . '/assets/js/leaflet/leaflet.js', array(), '1.9.4', false);
334 wp_enqueue_script('leaflet');
335
336 if ( get_option('propertyhive_geocoding_provider') == '' )
337 {
338 $api_key = get_option('propertyhive_google_maps_geocoding_api_key');
339 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
340 wp_enqueue_script('googlemaps');
341 }
342 }
343 else
344 {
345 $api_key = get_option('propertyhive_google_maps_api_key');
346 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
347 wp_enqueue_script('googlemaps');
348 }
349
350 wp_enqueue_media();
351 wp_enqueue_script( 'propertyhive_admin_meta_boxes' );
352 wp_enqueue_script( 'propertyhive_admin_recently_viewed' );
353 wp_enqueue_script( 'jquery-ui-datepicker' );
354 wp_enqueue_script( 'jquery-ui-autocomplete' );
355 wp_enqueue_script( 'ajax-chosen' );
356 wp_enqueue_script( 'chosen' );
357
358 $params = array(
359 'plugin_url' => PH()->plugin_url(),
360 'ajax_url' => admin_url('admin-ajax.php'),
361 'post_id' => isset( $post->ID ) ? $post->ID : '',
362 'get_notes_nonce' => wp_create_nonce("get-notes"),
363 'pin_note_nonce' => wp_create_nonce("pin-note"),
364 'add_note_nonce' => wp_create_nonce("add-note"),
365 'delete_note_nonce' => wp_create_nonce("delete-note"),
366 'viewing_details_meta_nonce' => wp_create_nonce( 'viewing-details-meta-box' ),
367 'viewing_actions_nonce' => wp_create_nonce( 'viewing-actions' ),
368 'save_key_date_nonce' => wp_create_nonce( 'save-key-date' ),
369 'delete_key_date_nonce' => wp_create_nonce( 'delete-key-date' ),
370 'check_duplicate_reference_number_nonce' => wp_create_nonce("check-duplicate-reference-number"),
371 'enable_description_editor' => apply_filters('propertyhive_enable_description_editor', false),
372 'leasehold_tenures' => apply_filters('propertyhive_leasehold_tenure_names', array( 'leasehold', 'share of freehold' ) ),
373 'disable_notes_mention' => apply_filters('propertyhive_disable_notes_mention', false),
374 );
375 wp_localize_script( 'propertyhive_admin_meta_boxes', 'propertyhive_admin_meta_boxes', $params );
376
377 if ( is_rtl() )
378 {
379 wp_enqueue_script( 'chosen-rtl', PH()->plugin_url() . '/assets/js/chosen/chosen-rtl' . /*$suffix .*/ '.js', array( 'jquery' ), PH_VERSION, true );
380 }
381 }
382
383 if ( in_array( $screen->id, array('profile', 'user', 'user-edit') ) )
384 {
385 wp_enqueue_media();
386 }
387
388 if ( strpos($screen->id, 'page_ph-settings') !== FALSE )
389 {
390 wp_enqueue_script( 'propertyhive_admin_settings' );
391
392 $params = array(
393 'confirm_not_selected_warning' => __( 'Please check the box to confirm that you are happy to remove this term', 'propertyhive' ),
394 'no_departments_selected_warning' => __( 'Please select at least one active department', 'propertyhive' ),
395 'primary_department_not_active_warning' => __( 'The chosen primary department has not been selected as active', 'propertyhive' ),
396 'no_countries_selected' => __( 'Please select which countries you operate in', 'propertyhive' ),
397 'default_country_not_in_selected' => __( 'The default country hasn\'t been selected as a country you operate in', 'propertyhive' ),
398 'admin_url' => admin_url(),
399 'taxonomy_section' => ( ( isset($_GET['section']) ) ? sanitize_text_field($_GET['section']) : '' ),
400 'ajax_nonce' => wp_create_nonce("updates"),
401 'features_settings_url' => admin_url('admin.php?page=ph-settings&tab=features'),
402 );
403 if ( isset($_GET['tab']) && ph_clean($_GET['tab']) == 'licensekey' )
404 {
405 $params['valid_pro_license_key'] = PH()->license->is_valid_pro_license_key(true);
406 }
407 else
408 {
409 $params['valid_pro_license_key'] = PH()->license->is_valid_pro_license_key();
410 }
411 wp_localize_script( 'propertyhive_admin_settings', 'propertyhive_admin_settings', $params );
412 }
413
414 // Reports Pages
415 if ( strpos($screen->id, 'page_ph-reports') !== FALSE || in_array( $screen->id, array( 'property' ) ) )
416 {
417 //wp_register_script( 'ph-reports', PH()->plugin_url() . '/assets/js/admin/reports' . /*$suffix .*/ '.js', array( 'jquery', 'jquery-ui-datepicker' ), PH_VERSION );
418
419 //wp_enqueue_script( 'ph-reports' );
420 wp_enqueue_script( 'flot' );
421 wp_enqueue_script( 'flot-resize' );
422 wp_enqueue_script( 'flot-time' );
423 //wp_enqueue_script( 'flot-pie' );
424 //wp_enqueue_script( 'flot-stack' );
425 }
426
427 if ( $screen->id === 'plugins' )
428 {
429 // Enqueue the JavaScript file
430 wp_enqueue_script(
431 'propertyhive_deactivate_survey',
432 PH()->plugin_url() . '/assets/js/deactivate-survey.js',
433 array('jquery'), // Depend on jQuery
434 '1.0.0',
435 true // Load in footer
436 );
437
438 wp_localize_script('propertyhive_deactivate_survey', 'deactivation_survey', array(
439 'nonce' => wp_create_nonce('deactivate-survey'),
440
441 'modalTitle' => __('If you have a moment, please let us know why you are deactivating:', 'propertyhive'),
442 'modalHeader' => __('Quick Feedback', 'propertyhive'),
443 'skipDeactivate' => __('Skip & Deactivate', 'propertyhive'),
444 'cancel' => __('Cancel', 'propertyhive'),
445 'deactivate' => __('Submit & Deactivate', 'propertyhive'),
446
447 'brokeSite' => __('The plugin broke my site', 'propertyhive'),
448 'confusing' => __('The plugin is confusing', 'propertyhive'),
449 'inadequateSupport' => __('The support/documentation is inadequate', 'propertyhive'),
450 'poorPerformance' => __('The plugin is too slow/affects performance', 'propertyhive'),
451 'notNeeded' => __('I no longer need the plugin', 'propertyhive'),
452 'betterPlugin' => __('I found a better plugin', 'propertyhive'),
453 'temporary' => __('It\'s a temporary deactivation', 'propertyhive'),
454 'other' => __('Other', 'propertyhive'),
455
456 'brokeSiteLabel' => __('Oh no! Can you tell us more? (optional)', 'propertyhive'),
457 'betterPluginLabel' => __('What\'s the plugin\'s name? (optional)', 'propertyhive'),
458 'otherLabel' => __('Additional feedback or comments: (optional)', 'propertyhive'),
459
460 'anonymous' => __('Anonymous feedback', 'propertyhive'),
461 ));
462 }
463 }
464
465 }
466
467 endif;
468
469 return new PH_Admin_Assets();