PluginProbe
Property Hive / 2.2.3
Property Hive v2.2.3
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 / class-ph-elementor.php

class-ph-elementor.php in Property Hive 2.2.3, at includes/class-ph-elementor.php

400 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 class PH_Elementor {
8
9 public function __construct()
10 {
11 add_action( 'plugins_loaded', array( $this, 'setup_propertyhive_elementor_functionality' ) );
12 add_action( 'elementor/query/onmarketpropertyquery', array( $this, 'elementor_query_on_market_only' ) );
13 add_action( 'elementor/query/onmarketsalespropertyquery', array( $this, 'elementor_query_on_market_sales_only' ) );
14 add_action( 'elementor/query/onmarketlettingspropertyquery', array( $this, 'elementor_query_on_market_lettings_only' ) );
15 add_action( 'elementor/query/onmarketcommercialpropertyquery', array( $this, 'elementor_query_on_market_commercial_only' ) );
16 add_action( 'elementor/query/featuredpropertyquery', array( $this, 'elementor_query_featured_only' ) );
17 add_filter( 'elementor/query/query_args', array( $this, 'elementor_query_args' ), 10, 2 );
18 }
19
20 public function elementor_query_args( $query_vars, $widget )
21 {
22 // Check to see if this is the right Widget.
23 $settings = $widget->get_data( 'settings' );
24
25 if ( isset($settings['post_query_query_id']) && $settings['post_query_query_id'] == 'onmarketpropertyquery' )
26 {
27 $ordering = PH()->query->get_search_results_ordering_args();
28
29 $query_vars['orderby'] = $ordering['orderby'] . ' post_title';
30 $query_vars['order'] = $ordering['order'];
31 if ( isset( $ordering['meta_key'] ) )
32 {
33 $query_vars['meta_key'] = $ordering['meta_key'];
34 }
35 }
36
37 return $query_vars;
38 }
39
40 public function setup_propertyhive_elementor_functionality()
41 {
42 add_filter( 'elementor_pro/utils/get_public_post_types', array( $this, 'register_public_post_type' ) );
43
44 add_action( 'elementor/elements/categories_registered', array( $this, 'add_elementor_widget_category' ) );
45
46 add_filter( 'elementor/image_size/get_attachment_image_html', array( $this, 'portfolio_use_property_image_url'), 10, 4 );
47
48 add_action( 'elementor/preview/enqueue_scripts', array( 'PH_Frontend_Scripts', 'load_scripts' ) );
49 add_action( 'elementor/preview/enqueue_scripts', array( $this, 'load_elementor_scripts' ) );
50
51 if ( did_action( 'elementor/loaded' ) )
52 {
53 // Widgets
54 add_action( 'init', array( $this, 'register_widgets' ) );
55 }
56 }
57
58 public function elementor_query_on_market_only( $query )
59 {
60 PH()->query->property_query( $query );
61
62 // Set the custom post type
63 $query->set( 'post_type', [ 'property' ] );
64
65 // ensure a department is set as not set by default from property_query
66 $meta_query = $query->get('meta_query');
67
68 $new_meta_query = $meta_query;
69 $department_found = false;
70 foreach ( $meta_query as $key => $value )
71 {
72 if ( isset($value['key']) && $value['key'] == '_department' )
73 {
74 $department_found = true;
75 break;
76 }
77 }
78
79 if ( !$department_found )
80 {
81 $new_meta_query[] = array(
82 'key' => '_department',
83 'value' => get_option( 'propertyhive_primary_department', 'residential-sales' )
84 );
85 }
86
87 $query->set( 'meta_query', $new_meta_query );
88 }
89
90 public function elementor_query_on_market_sales_only( $query )
91 {
92 $original_department = isset($_REQUEST['department']) ? $_REQUEST['department'] : '';
93
94 $_GET['department'] = 'residential-sales';
95 $_REQUEST['department'] = 'residential-sales';
96
97 PH()->query->property_query( $query );
98
99 $_GET['department'] = $original_department;
100 $_REQUEST['department'] = $original_department;
101
102 // Set the custom post type
103 $query->set( 'post_type', [ 'property' ] );
104
105 // ensure a department is set as not set by default from property_query
106 $new_meta_query = $this->remove_department_from_query( $query );
107
108 $new_meta_query[] = array(
109 'key' => '_department',
110 'value' => 'residential-sales'
111 );
112
113 $query->set( 'meta_query', $new_meta_query );
114 }
115
116 public function elementor_query_on_market_lettings_only( $query )
117 {
118 $original_department = isset($_REQUEST['department']) ? $_REQUEST['department'] : '';
119
120 $_GET['department'] = 'residential-lettings';
121 $_REQUEST['department'] = 'residential-lettings';
122
123 PH()->query->property_query( $query );
124
125 $_GET['department'] = $original_department;
126 $_REQUEST['department'] = $original_department;
127
128 // Set the custom post type
129 $query->set( 'post_type', [ 'property' ] );
130
131 // ensure a department is set as not set by default from property_query
132 $new_meta_query = $this->remove_department_from_query( $query );
133
134 $new_meta_query[] = array(
135 'key' => '_department',
136 'value' => 'residential-lettings'
137 );
138
139 $query->set( 'meta_query', $new_meta_query );
140 }
141
142 public function elementor_query_on_market_commercial_only( $query )
143 {
144 $original_department = isset($_REQUEST['department']) ? $_REQUEST['department'] : '';
145
146 $_GET['department'] = 'commercial';
147 $_REQUEST['department'] = 'commercial';
148
149 PH()->query->property_query( $query );
150
151 $_GET['department'] = $original_department;
152 $_REQUEST['department'] = $original_department;
153
154 // Set the custom post type
155 $query->set( 'post_type', [ 'property' ] );
156
157 // ensure a department is set as not set by default from property_query
158 $new_meta_query = $this->remove_department_from_query( $query );
159
160 $new_meta_query[] = array(
161 'key' => '_department',
162 'value' => 'commercial'
163 );
164
165 $query->set( 'meta_query', $new_meta_query );
166 }
167
168 public function elementor_query_featured_only( $query )
169 {
170 $original_orderby = $query->get( 'orderby' );
171 $original_order = $query->get( 'order' );
172
173 PH()->query->property_query( $query );
174
175 // Set the custom post type
176 $query->set( 'post_type', [ 'property' ] );
177
178 $meta_query = $this->remove_department_from_query( $query );
179
180 $new_meta_query = $meta_query;
181
182 $new_meta_query[] = array(
183 'key' => '_featured',
184 'value' => 'yes'
185 );
186
187 $query->set( 'meta_query', $new_meta_query );
188
189 $query->set( 'orderby', $original_orderby );
190 $query->set( 'order', $original_order );
191 }
192
193 private function remove_department_from_query( $query )
194 {
195 $new_meta_query = array();
196
197 $meta_query = $query->get('meta_query');
198
199 foreach ( $meta_query as $key => $value )
200 {
201 if ( isset($value['key']) && $value['key'] == '_department' )
202 {
203 // remove department
204 }
205 else
206 {
207 $new_meta_query[$key] = $value;
208 }
209 }
210
211 return $new_meta_query;
212 }
213
214 public function load_elementor_scripts()
215 {
216 $suffix = '';
217 $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/';
218
219 wp_enqueue_script( 'propertyhive_fancybox' );
220 wp_enqueue_style( 'propertyhive_fancybox_css' );
221
222 wp_enqueue_script( 'flexslider', $assets_path . 'js/flexslider/jquery.flexslider' . $suffix . '.js', array( 'jquery' ), '2.2.2', true );
223 wp_enqueue_script( 'flexslider-init', $assets_path . 'js/flexslider/jquery.flexslider.init' . $suffix . '.js', array( 'jquery','flexslider' ), PH_VERSION, true );
224 wp_enqueue_style( 'flexslider_css', $assets_path . 'css/flexslider.css' );
225
226 $api_key = get_option('propertyhive_google_maps_api_key');
227 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
228 wp_enqueue_script('googlemaps');
229
230 wp_enqueue_script( 'propertyhive_elementor', $assets_path . 'js/elementor/elementor.js', array( 'jquery','flexslider' ), PH_VERSION, true );
231 }
232
233 public function add_elementor_widget_category( $elements_manager )
234 {
235 $elements_manager->add_category(
236 'property-hive',
237 [
238 'title' => __( 'Property Hive', 'propertyhive' ),
239 'icon' => 'fa fa-home',
240 ]
241 );
242 }
243
244 public function register_widgets()
245 {
246 $widgets = array(
247 'Property Search Form',
248 'Property Tabbed Details',
249 'Property Images',
250 'Property Image',
251 'Property Gallery',
252 'Property Address Name Number',
253 'Property Address Street',
254 'Property Address Line 2',
255 'Property Address Town City',
256 'Property Address County',
257 'Property Address Postcode',
258 'Property Address Full',
259 );
260
261 if ( taxonomy_exists('location') )
262 {
263 $args = array(
264 'taxonomy' => 'location',
265 'hide_empty' => false,
266 'parent' => 0,
267 'number' => 1,
268 'fields' => 'ids',
269 );
270 $terms = get_terms( $args );
271
272 if ( !empty( $terms ) && !is_wp_error( $terms ) )
273 {
274 $widgets[] = 'Property Location';
275 }
276 }
277
278 $widgets = array_merge( $widgets, array(
279 'Property Price',
280 'Property Price Qualifier',
281 'Property Features',
282 'Property Summary Description',
283 'Property Full Description',
284 'Property Actions',
285 'Property Meta',
286 'Property Availability',
287 'Property Type',
288 'Property Bedrooms',
289 'Property Bathrooms',
290 'Property Reception Rooms',
291 'Property Reference Number',
292 'Property Floor Area',
293 'Property Tenure',
294 'Property Council Tax Band',
295 'Property Let Available Date',
296 'Property Deposit',
297 'Property Furnished',
298 'Property Marketing Flag',
299 'Property Map',
300 'Property Map Link',
301 'Property Street View',
302 'Property Floorplans',
303 'Property Floorplans Link',
304 'Property EPCs',
305 'Property EPCs Link',
306 'Property Enquiry Form',
307 'Property Enquiry Form Link',
308 'Property Brochures Link',
309 'Property Embedded Virtual Tours',
310 'Property Virtual Tours Link',
311 'Property Office Name',
312 'Property Office Telephone Number',
313 'Property Office Email Address',
314 'Property Office Address',
315 'Property Negotiator Name',
316 'Property Negotiator Telephone Number',
317 'Property Negotiator Email Address',
318 'Property Negotiator Photo',
319 'Property Not On Market Message',
320 'Back To Search',
321 'Property Search Result Count',
322 'Property Search Order',
323 ) );
324
325 $current_settings = get_option( 'propertyhive_template_assistant', array() );
326
327 $custom_fields = ( (isset($current_settings['custom_fields'])) ? $current_settings['custom_fields'] : array() );
328
329 foreach ( $custom_fields as $custom_field )
330 {
331 if ( substr($custom_field['meta_box'], 0, 9) == 'property_' || substr($custom_field['meta_box'], 0, 7) == 'office_' )
332 {
333 $widgets[] = 'Property Additional Field';
334 break;
335 }
336 }
337
338 $widgets = apply_filters( 'propertyhive_elementor_widgets', $widgets );
339
340 foreach ( $widgets as $widget )
341 {
342 $widget_dir = 'elementor-widgets';
343 $widget_dir = apply_filters( 'propertyhive_elementor_widget_directory', dirname(__FILE__) . "/" . $widget_dir, $widget );
344 if ( file_exists( $widget_dir . "/" . sanitize_title($widget) . ".php" ) )
345 {
346 require_once( $widget_dir . "/" . sanitize_title($widget) . ".php" );
347 $class_name = '\Elementor_' . str_replace(" ", "_", $widget) . '_Widget';
348 \Elementor\Plugin::instance()->widgets_manager->register( new $class_name() );
349 }
350 }
351 }
352
353 public function register_public_post_type( $post_types ) {
354
355 if ( isset($post_types['property']) )
356 {
357 return $post_types;
358 }
359
360 $post_types['property'] = __( 'Property', 'propertyhive' );
361
362 return $post_types;
363 }
364
365 public function portfolio_use_property_image_url( $html, $settings, $image_size_key, $image_key )
366 {
367 global $post;
368
369 if ( !isset($settings['posts_post_type']) || ( isset($settings['posts_post_type']) && $settings['posts_post_type'] != 'property' ) )
370 {
371 return $html;
372 }
373
374 // We're viewing a property
375
376 if ( get_option('propertyhive_images_stored_as', '') != 'urls' )
377 {
378 return $html;
379 }
380
381 // Images are stored as URLs
382
383 $images = get_post_meta( $post->ID, '_photo_urls', TRUE );
384
385 if ( empty($images) )
386 {
387 return $html;
388 }
389
390 $image_src = $images[0]['url'];
391
392 $image_class = ! empty( $settings['hover_animation'] ) ? 'elementor-animation-' . $settings['hover_animation'] : '';
393 $image_class_html = ! empty( $image_class ) ? ' class="' . $image_class . '"' : '';
394
395 $html = sprintf( '<img src="%s" title="" alt=""%s />', esc_attr( $image_src ), $image_class_html );
396 return $html;
397 }
398 }
399
400 new PH_Elementor();