1: <?php
2: /**
3: * Scripts & Styles
4: *
5: * @package EPL
6: * @subpackage Assets/ScriptsStyles
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: /**
18: * Get admin screens that EPL uses
19: *
20: * @return mixed|void
21: *
22: * @since 3.4
23: */
24: function epl_get_admin_screens() {
25:
26: $screens = array(
27: 'easy-property-listings_page_epl-addons',
28: 'easy-property-listings_page_epl-tools',
29: 'toplevel_page_epl-general',
30: 'easy-property-listings_page_epl-settings',
31: 'easy-property-listings_page_epl-contacts',
32: 'easy-property-listings_page_epl-reports',
33: 'easy-property-listings_page_epl-extensions',
34: 'easy-property-listings_page_epl-licenses',
35: 'dashboard_page_epl-about',
36: 'dashboard_page_epl-getting-started',
37: 'edit.php',
38: 'index.php',
39: 'widgets.php',
40: );
41:
42: return apply_filters( 'epl_admin_screens', $screens );
43: }
44:
45: /**
46: * Load and enqueue admin scripts and stylesheets.
47: *
48: * @param string $screen Page hook.
49: *
50: * @since 1.0.0
51: * @since 3.4.44 Fixed callback error for google maps.
52: * @since 3.5 Renamed Google Maps script name to: epl-google-map-v-3. Display hidden fields. Added Google maps error message.
53: * @since 3.5.2 New: Google Maps load Asynchronous.
54: * @since 3.5.4 Display warning note when display address is unchecked.
55: * @since 3.5.8 Using version 3.55 of gmap to avoid Deprecation notice for markers.
56: * @since 3.5.16 New: Unified image management featured for use in extensions.
57: *
58: * @return void
59: */
60: function epl_admin_enqueue_scripts( $screen ) {
61:
62: $mode = epl_get_option( 'epl_plugin_mode', 'development' );
63: $suffix = 'production' === $mode ? '.min' : '';
64: $current_dir_path = plugins_url( '', __FILE__ );
65: $display_address_note = sprintf(
66: // Translators: %1$s: is Location Label, %2$ is the link start, and %3$s is the link end.
67: __( 'When \'Display Street Address\' is unchecked, the map pin uses %1$s for positioning. Refer to the %2$s codex %3$s for further details.', 'easy-property-listings' ),
68: epl_get_option( 'label_suburb' ),
69: '<a href="' . esc_url( 'https://codex.easypropertylistings.com.au/article/430-how-the-address-system-works' ) . '" target="_blank">',
70: '</a>'
71: );
72:
73: $js_vars = array(
74: 'default_map_address' => apply_filters( 'epl_default_map_address', epl_get_option( 'epl_default_country', 'Australia' ) ),
75: 'ajax_nonce' => wp_create_nonce( 'epl_ajax_nonce' ),
76: 'display_hidden_fields' => epl_get_option( 'display_hidden_fields', 0 ),
77: 'google_api_error' => __( 'Ensure you have set a Google Maps API Key from Dashboard > Easy Property Listings > Settings', 'easy-property-listings' ),
78: 'google_api_key' => epl_get_option( 'epl_google_api_key' ),
79: 'google_map_disabled' => epl_get_option( 'epl_disable_google_api' ),
80: 'display_address_note' => esc_html( $display_address_note ),
81: 'add_images_button_text' => __( 'Add Images', 'easy-property-listings' ),
82: );
83:
84: wp_register_script( 'epl-admin-scripts', $current_dir_path . '/js/jquery-admin-scripts' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
85: wp_register_script( 'wp-color-picker-alpha', $current_dir_path . '/js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), EPL_PROPERTY_VER, false );
86:
87: wp_localize_script( 'epl-admin-scripts', 'epl_admin_vars', $js_vars );
88:
89: if ( 'edit.php' === $screen || 'post.php' === $screen || 'post-new.php' === $screen || 'easy-property-listings_page_epl-extensions' === $screen || 'easy-property-listings_page_epl-settings' === $screen || 'easy-property-listings_page_epl-extensions' === $screen ) {
90:
91: $googleapiurl = 'https://maps.googleapis.com/maps/api/js?v=3.55&callback=Function.prototype&loading=async';
92: $epl_google_api_key = epl_get_option( 'epl_google_api_key' );
93: if ( ! empty( $epl_google_api_key ) ) {
94: $googleapiurl = $googleapiurl . '&key=' . epl_get_option( 'epl_google_api_key' );
95: }
96:
97: // Intentionally ignores the "Google Maps API: Disable" setting (epl_disable_google_api).
98: // That setting is for sites where the theme or another plugin already loads Google Maps
99: // on the front end. Those rarely load it in admin, so EPL always loads it here to keep the
100: // listing edit map, pin and coordinates lookup working. Map add-ons that replace Google
101: // (e.g. OpenStreetMap) should dequeue 'epl-google-map-v-3' themselves.
102: wp_enqueue_script( 'epl-google-map-v-3', $googleapiurl, array(), EPL_PROPERTY_VER, false );
103:
104: wp_enqueue_style( 'epl-jquery-validation-engine-style', $current_dir_path . '/css/validationEngine-jquery' . $suffix . '.css', false, EPL_PROPERTY_VER );
105: wp_enqueue_script( 'epl-jquery-validation-engine-lang-scripts', $current_dir_path . '/js/jquery-validationEngine-en' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
106: wp_enqueue_script( 'epl-jquery-validation-engine-scripts', $current_dir_path . '/js/jquery-validationEngine' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
107: wp_enqueue_script( 'jquery-datetime-picker', $current_dir_path . '/js/jquery-datetime-picker' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
108: wp_enqueue_style( 'jquery-ui-datetime-picker-style', $current_dir_path . '/css/jquery-ui' . $suffix . '.css', false, EPL_PROPERTY_VER );
109:
110: wp_enqueue_style( 'epl-admin-styles', $current_dir_path . '/css/style-admin' . $suffix . '.css', false, EPL_PROPERTY_VER );
111:
112: }
113:
114: // load admin style on help & documentation pages as well.
115: if ( in_array( $screen, epl_get_admin_screens(), true ) ) {
116:
117: wp_enqueue_style( 'epl-admin-styles', $current_dir_path . '/css/style-admin' . $suffix . '.css', false, EPL_PROPERTY_VER );
118: }
119:
120: wp_enqueue_script( 'epl-js-lib', $current_dir_path . '/js/epl' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
121:
122: wp_enqueue_script( 'epl-admin-scripts' );
123: }
124: add_action( 'admin_enqueue_scripts', 'epl_admin_enqueue_scripts' );
125:
126: /**
127: * Load and enqueue front end scripts and stylesheets.
128: *
129: * @since 1.0
130: * @since 3.4.44 Fix: Callback error for google maps.
131: * @since 3.4.48 Fix: Price formatting as per settings in price slider.
132: * @since 3.5.1 Tweak: Google Maps Prefixed to: epl-google-map-v-3
133: * @since 3.5.2 New: Google Maps load asynchoronously.
134: * @since 3.5.3 Ajax nonce in JS vars.
135: */
136: function epl_wp_enqueue_scripts() {
137:
138: $mode = epl_get_option( 'epl_plugin_mode', 'development' );
139: $suffix = 'production' === $mode ? '.min' : '';
140: $epl_default_view_type = epl_get_option( 'display_archive_view_type', 'list' );
141: $current_dir_path = plugins_url( '', __FILE__ );
142: wp_register_script( 'epl-front-scripts', $current_dir_path . '/js/jquery-front-scripts' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
143:
144: if ( is_epl_post() && shortcode_exists( 'listing_map' ) ) {
145:
146: $googleapiurl = 'https://maps.googleapis.com/maps/api/js?v=3.55&libraries=marker&loading=async&callback=EPL_Default_Map_Loader';
147: $epl_google_api_key = epl_get_option( 'epl_google_api_key' );
148: if ( ! empty( $epl_google_api_key ) ) {
149: $googleapiurl = $googleapiurl . '&key=' . epl_get_option( 'epl_google_api_key' );
150: }
151:
152: // Front end only. Admin always loads Google Maps, see epl_admin_enqueue_scripts().
153: if ( epl_get_option( 'epl_disable_google_api' ) !== 'on' ) {
154: wp_enqueue_script( 'epl-google-map-v-3', $googleapiurl, array(), EPL_PROPERTY_VER, false );
155: }
156: }
157:
158: // All CSS including Structural.
159: if ( 'on' === epl_get_option( 'epl_use_core_css', 'off' ) ) {
160: // Dont use css.
161: } else {
162:
163: // Legacy CSS: on is to enable visual css, default off.
164: if ( epl_get_option( 'epl_css_legacy', 'off' ) === 'on' ) {
165:
166: wp_enqueue_style( 'epl-front-styles', $current_dir_path . '/css/style-legacy' . $suffix . '.css', false, EPL_PROPERTY_VER );
167:
168: } else {
169: // Structural CSS.
170: wp_enqueue_style( 'epl-css-lib', $current_dir_path . '/css/style-structure' . $suffix . '.css', false, EPL_PROPERTY_VER );
171: wp_enqueue_style( 'epl-style', $current_dir_path . '/css/style' . $suffix . '.css', false, EPL_PROPERTY_VER );
172: }
173:
174: // Enhanced CSS: on is to enable visual css, default on for new installations.
175: if ( epl_get_option( 'epl_css_enhanced', 'off' ) === 'on' ) {
176: wp_enqueue_style( 'epl-style-enhanced', $current_dir_path . '/css/style-enhanced' . $suffix . '.css', false, EPL_PROPERTY_VER );
177: }
178:
179: wp_enqueue_style( 'epl-field-sliders', $current_dir_path . '/css/field-slider' . $suffix . '.css', false, EPL_PROPERTY_VER );
180:
181: /**
182: * Load theme specific stylesheet for epl, if exists
183: * Loaded at the end to override any styles in plugin
184: */
185: if ( file_exists( get_stylesheet_directory() . '/easypropertylistings/style.css' ) ) {
186: wp_enqueue_style( 'epl-theme-style', get_stylesheet_directory_uri() . '/easypropertylistings/style.css', false, EPL_PROPERTY_VER );
187: }
188:
189: if ( is_epl_post_archive() && file_exists( get_stylesheet_directory() . '/easypropertylistings/style-archive.css' ) ) {
190: wp_enqueue_style( 'epl-theme-style-archive', get_stylesheet_directory_uri() . '/easypropertylistings/style-archive.css', false, EPL_PROPERTY_VER );
191: }
192:
193: if ( is_epl_post_single() && file_exists( get_stylesheet_directory() . '/easypropertylistings/style-single.css' ) ) {
194: wp_enqueue_style( 'epl-theme-style-single', get_stylesheet_directory_uri() . '/easypropertylistings/style-single.css', false, EPL_PROPERTY_VER );
195: }
196: }
197:
198: $js_vars = array(
199: 'ajax_nonce' => wp_create_nonce( 'epl_ajax_nonce' ),
200: 'site_url' => esc_url( home_url( '/' ) ),
201: 'epl_default_view_type' => $epl_default_view_type,
202: 'ajaxurl' => admin_url( 'admin-ajax.php' ),
203: 'image_base' => EPL_PLUGIN_URL . 'lib/assets/images/',
204: 'field_sliders' => epl_get_field_sliders(),
205: 'range_html' => epl_get_range_slider_label_html(),
206: 'thousand_sep' => epl_get_option( 'currency_thousands_separator' ),
207: 'decimal_sep' => epl_get_option( 'currency_decimal_separator' ),
208:
209: );
210: wp_enqueue_script( 'jquery-ui-slider' );
211: wp_enqueue_script( 'jquery-touch-punch' );
212:
213: wp_enqueue_script( 'epl-js-lib', $current_dir_path . '/js/epl' . $suffix . '.js', array( 'jquery' ), EPL_PROPERTY_VER, false );
214:
215: wp_localize_script( 'epl-front-scripts', 'epl_frontend_vars', $js_vars );
216: wp_enqueue_script( 'epl-front-scripts' );
217: }
218: add_action( 'wp_enqueue_scripts', 'epl_wp_enqueue_scripts' );
219:
220: /**
221: * Load and enqueue admin styles.
222: *
223: * @since 1.0
224: * @since 3.6 The thumbnail column stays at most 320 pixels wide now that the medium crop is 600x400.
225: */
226: function epl_admin_styles() {
227:
228: global $current_screen;
229:
230: if ( ! is_null( $current_screen ) && 'edit' !== $current_screen->base ) {
231: return;
232: }
233:
234: $active_size = epl_get_option( 'epl_admin_thumb_size', 'admin-list-thumb' );
235: $sizes = get_epl_image_sizes();
236: $width = '120px';
237:
238: foreach ( $sizes as $size ) {
239: if ( $size['id'] === $active_size ) {
240: // Shown at most 300 pixels wide, so the 600x400 medium crop keeps the column it had at 300x200.
241: $width = min( (int) $size['width'], 300 ) + 20 . 'px'; // Add 20 pixels for padding.
242: break;
243: }
244: }
245:
246: ?>
247: <style>
248: .column-property_thumb {
249: width: <?php echo esc_html( $width ); ?>;
250: }
251: .column-property_thumb img {
252: max-width: 100%;
253: height: auto;
254: }
255: .column-property_featured {
256: width: 60px;
257: }
258: .column-property_featured .dashicons-star-filled {
259: color: orange;
260: }
261: .column-property_featured .dashicons-star-empty {
262: color: #aaaaaa;
263: }
264: .column-property_featured .epl-manage-featured {
265: display: none;
266: }
267: </style>
268: <?php
269: }
270: add_action( 'admin_head', 'epl_admin_styles' );
271:
272: /**
273: * Template for range slider label
274: *
275: * @since 3.4.4
276: *
277: * @return string
278: */
279: function epl_get_range_slider_label_html() {
280:
281: ob_start();
282: ?>
283: <span class="epl-lf-label-txt"> {range_start} {range_sep} {range_end} </span>
284: <?php
285:
286: $html = ob_get_clean();
287:
288: return apply_filters( 'epl_get_range_slider_label_html', $html );
289: }
290: