PluginProbe
WP Directory Kit / 1.2.9
WP Directory Kit v1.2.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / elementor-extensions / class-hider.php

class-hider.php in WP Directory Kit 1.2.9, at elementor-extensions/class-hider.php

543 lines 19.7 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 use Elementor\Plugin;
7 use Elementor\Controls_Manager;
8 use Elementor\Modules\DynamicTags\Module;
9
10 add_action( 'elementor/init', function() {
11
12 $listing_page_id = get_option('wdk_listing_page');
13
14 if(!empty($listing_page_id))
15 {
16 new WDK_Extension_Hider();
17
18 /*
19 if(isset($_GET['post']) && $_GET['post'] == $listing_page_id)
20 {
21 new WDK_Extension_Hider();
22 }
23 elseif(!Plugin::$instance->editor->is_edit_mode())
24 {
25 new WDK_Extension_Hider();
26 }*/
27 }
28 });
29
30 /**
31 * WDK_Extension_Hider
32 *
33 * Class to extend Elementor controls functionality, adding hide feature based on specific wdk field
34 *
35 */
36
37 class WDK_Extension_Hider {
38
39 public $name = 'WDK Hider';
40
41 private $is_common = true;
42
43 private $depended_scripts = [];
44
45 private $depended_styles = [];
46
47 private $has_controls = TRUE;
48
49 public $common_sections_actions = array(
50 array(
51 'element' => 'common',
52 'action' => '_section_style',
53 ),
54 array(
55 'element' => 'container',
56 'action' => 'section_layout',
57 ),
58 array(
59 'element' => 'section',
60 'action' => 'section_advanced',
61 ),
62 array(
63 'element' => 'column',
64 'action' => 'section_advanced',
65 ),
66 );
67
68 private $supported_elements = array(
69 'heading'
70 );
71
72 public function __construct() {
73
74 /*
75 Controls_Manager::add_tab(
76 'wdk_hider',
77 __( 'Hider', 'wpdirectorykit' )
78 );*/
79
80 $this->init();
81 }
82
83 public function init( $param = null ) {
84 // Enqueue scripts
85 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
86
87 // Enqueue styles
88 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_styles' ] );
89
90 // Elementor hooks
91
92 if ( $this->is_common ) {
93 // Add the advanced section required to display controls
94 $this->add_common_sections_actions();
95 }
96
97 $this->add_actions();
98 }
99
100 public static function is_enabled() {
101 return true;
102 }
103
104 public function add_script_depends( $handler ) {
105 $this->depended_scripts[] = $handler;
106 }
107
108 public function add_style_depends( $handler ) {
109 $this->depended_styles[] = $handler;
110 }
111
112 public function get_script_depends() {
113 return $this->depended_scripts;
114 }
115
116 public function enqueue_scripts() {
117 foreach ( $this->get_script_depends() as $script ) {
118 wp_enqueue_script( $script );
119 }
120 }
121
122 public function get_style_depends() {
123 return $this->depended_styles;
124 }
125
126 public static function get_description() {
127 return '';
128 }
129
130 public function enqueue_styles() {
131 foreach ( $this->get_style_depends() as $style ) {
132 wp_enqueue_style( $style );
133 }
134 }
135
136 public function _enqueue_scripts() {
137 $scripts = $this->get_script_depends();
138 if ( ! empty( $scripts ) ) {
139 foreach ( $scripts as $script ) {
140 wp_enqueue_script( $script );
141 }
142 }
143 }
144
145 public function _enqueue_styles() {
146 $styles = $this->get_style_depends();
147 if ( ! empty( $styles ) ) {
148 foreach ( $styles as $style ) {
149 wp_enqueue_style( $style );
150 }
151 }
152 }
153
154 public function enqueue_all() {
155 $this->_enqueue_styles();
156 $this->_enqueue_scripts();
157 }
158
159 public function get_low_name() {
160 return 'hider';
161 }
162
163 final public function add_common_sections( $element, $args ) {
164 $low_name = $this->get_low_name();
165 $section_name = 'wdk_section_' . $low_name . '_advanced';
166
167 if ( ! $this->has_controls ) {
168 // no need settings
169 return false;
170 }
171
172 // Check if this section exists
173 $section_exists = \Elementor\Plugin::instance()->controls_manager->get_control_from_stack( $element->get_unique_name(), $section_name );
174
175 if ( ! is_wp_error( $section_exists ) ) {
176 // We can't and should try to add this section to the stack
177 return false;
178 }
179
180 $this->get_control_section( $section_name, $element );
181 }
182
183 public function add_common_sections_actions() {
184 foreach ( $this->common_sections_actions as $action ) {
185 // Activate action for elements
186 add_action('elementor/element/' . $action['element'] . '/' . $action['action'] . '/after_section_end', function ( $element, $args ) {
187 $this->add_common_sections( $element, $args );
188 }, 10, 2);
189 }
190 }
191
192 protected function add_actions() {
193
194 // WIDGET
195 add_action( 'elementor/frontend/widget/before_render', [ $this, '_start_element' ], 10, 1 );
196 add_action( 'elementor/frontend/widget/after_render', [ $this, '_end_element' ], 10, 1 );
197
198 // SECTION
199 add_action( 'elementor/frontend/section/before_render', [ $this, '_start_element' ], 10, 1 );
200 add_action( 'elementor/frontend/section/after_render', [ $this, '_end_element' ], 10, 1 );
201
202 // CONTAINER
203 add_action( 'elementor/frontend/container/before_render', [ $this, '_start_element' ], 10, 1 );
204 add_action( 'elementor/frontend/container/after_render', [ $this, '_end_element' ], 10, 1 );
205
206 // COLUMN
207 add_action( 'elementor/frontend/column/before_render', [ $this, '_start_element' ], 10, 1 );
208 add_action( 'elementor/frontend/column/after_render', [ $this, '_end_element' ], 10, 1 );
209
210
211 }
212
213 protected function remove_controls( $element, $controls = null ) {
214 if ( empty( $controls ) ) {
215 return;
216 }
217
218 if ( is_array( $controls ) ) {
219 $control_id = $controls;
220
221 foreach ( $controls as $control_id ) {
222 $element->remove_control( $control_id );
223 }
224 } else {
225 $element->remove_control( $controls );
226 }
227 }
228
229 public function get_control_section( $section_name, $element ) {
230 $low_name = $this->get_low_name();
231
232 $element->start_controls_section(
233 $section_name,
234 [
235 'label' => '<span class="color-wdk icon icon-dyn-logo-wdk pull-right ml-1"></span> ' . $this->name,
236 'tab' => 'advanced',
237 ]
238 );
239
240 $fields_data = wdk_cached_field_get();
241 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
242 $order_i = 0;
243
244 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
245 $fields_list [(++$order_i).'__profile_have_agency'] = esc_html__('Profile page is agency', 'wpdirectorykit');
246 $fields_list [(++$order_i).'__have_agency'] = esc_html__('Listing have agency', 'wpdirectorykit');
247 $fields_list [(++$order_i).'__have_sublistings'] = esc_html__('Listing have sublistings', 'wpdirectorykit');
248 $fields_list [(++$order_i).'__have_calendar'] = esc_html__('Listing have calendar', 'wpdirectorykit');
249 $fields_list [(++$order_i).'__havent_calendar'] = esc_html__('Listing not have calendar', 'wpdirectorykit');
250 $fields_list [(++$order_i).'__havent_images'] = esc_html__('Listing not have images', 'wpdirectorykit');
251 $fields_list [(++$order_i).'__have_images'] = esc_html__('Listing have images', 'wpdirectorykit');
252 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
253 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
254 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
255 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
256 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
257 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
258 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
259 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
260 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
261 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
262
263 foreach($fields_data as $field)
264 {
265 if(wmvc_show_data('field_type', $field) == 'SECTION') {
266 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
267 } else {
268 $fields_list[(++$order_i).'__'.wmvc_show_data('idfield', $field)] = '#'.wmvc_show_data('idfield', $field).' '.wmvc_show_data('field_label', $field).'['.wmvc_show_data('field_type', $field).']';
269 }
270 }
271
272 $element->add_control(
273 'wdk_related_field',
274 [
275 'label' => esc_html__('WDK Related FIeld', 'wpdirectorykit'),
276 'type' => Controls_Manager::SELECT,
277 'options' => $fields_list,
278 'default' => '',
279 'return_value' => 'section',
280 'frontend_available' => true,
281 'render_type' => 'none',
282 ]
283 );
284
285 $element->end_controls_section();
286
287 }
288
289 public function _start_element( $element ) {
290 global $wdk_listing_id;
291 $wdkmembership_user_id = wdk_get_profile_page_id();
292
293 if(Plugin::$instance->editor->is_edit_mode() || (empty($wdk_listing_id) && empty($wdkmembership_user_id)))return;
294 //if(!in_array($element->get_name(), $this->supported_elements))return;
295
296 $WMVC = &wdk_get_instance();
297 $WMVC->model('field_m');
298 $WMVC->load_helper('listing');
299 $settings = $element->get_settings_for_display();
300
301 if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field']))
302 {
303
304 $field_id = NULL;
305 $field_value = NULL;
306 $field_empty = FALSE;
307 if(strpos($settings['wdk_related_field'], '__') !== FALSE){
308 $field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2);
309 }
310 if(is_null($field_id))return;
311 if($field_id == 'havent_calendar' || $field_id == 'have_calendar') {
312 if(function_exists('run_wdk_bookings')) {
313 global $Winter_MVC_wdk_bookings;
314 $Winter_MVC_wdk_bookings->model('calendar_m');
315 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id, 'is_activated' => 1));
316 if($field_id == 'havent_calendar') {
317 if($calendar){
318 $field_empty = true;
319 }
320 } else if($field_id == 'have_calendar') {
321 if(!$calendar){
322 $field_empty = true;
323 }
324 }
325 }
326 } elseif($field_id == 'profile_have_agency') {
327 $wdkmembership_user_id = wdk_get_profile_page_id();
328 $field_empty = true;
329
330
331 if($wdkmembership_user_id) {
332 $user = wdk_get_user_data($wdkmembership_user_id);
333 if($user && wmvc_is_user_in_role($user['userdata'], 'wdk_agency')) {
334 $field_empty = false;
335 }
336
337 }
338 } elseif($field_id == 'have_agency') {
339 $field_empty = true;
340 if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
341 if(wdk_field_value ('user_id_editor', $wdk_listing_id)) {
342 $agent_id = wdk_field_value ('user_id_editor', $wdk_listing_id);
343 global $Winter_MVC_wdk_membership;
344 $Winter_MVC_wdk_membership->model('agency_agent_m');
345 $agent_agency = $Winter_MVC_wdk_membership->agency_agent_m->get_by(array('agent_id' => $agent_id, 'status' => 'CONFIRMED'), TRUE);
346 if($agent_agency) {
347 $user = wdk_get_user_data( wmvc_show_data('agency_id', $agent_agency, 0));
348 if($user){
349 $field_empty = false;
350 }
351 }
352 }
353 }
354 } elseif($field_id == 'have_sublistings') {
355
356 $field_empty = true;
357 if(!empty(wdk_field_value('listing_related_ids', $wdk_listing_id))){
358 foreach (explode(',',wdk_field_value('listing_related_ids', $wdk_listing_id)) as $key => $child_idlisting) {
359 if(!wdk_field_value('is_activated', $child_idlisting) || !wdk_field_value('is_approved', $child_idlisting)) continue;
360
361 $field_empty = false;
362 break;
363 }
364 }
365 } elseif($field_id == 'havent_images' || $field_id == 'have_images') {
366 $images = wdk_field_value('listing_images', $wdk_listing_id);
367 if($field_id == 'havent_images') {
368 if($images){
369 $field_empty = true;
370 }
371 } else if($field_id == 'have_images') {
372 if(!$images){
373 $field_empty = true;
374 }
375 }
376 } elseif(wdk_field_option($field_id, 'field_type') == "SECTION") {
377
378 // get all section fields
379 $sections_data = $WMVC->field_m->get_fields_section();
380
381 if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return;
382
383 // check if all subfields are empty
384 $field_empty = true;
385 foreach($sections_data[$field_id]['fields'] as $field) {
386 if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){
387 $field_empty = false;
388 break;
389 }
390 }
391 }
392 else
393 {
394 $field_value = wdk_field_value($field_id, $wdk_listing_id);
395
396 if(empty($field_value))$field_empty = TRUE;
397 }
398
399 if($field_empty)
400 {
401 /*
402 echo '<pre>';
403 var_dump($settings['wdk_related_field']);
404 echo '</pre>';
405 */
406
407 ob_start();
408 }
409
410 }
411 }
412
413 public function _end_element( $element ) {
414 global $wdk_listing_id;
415
416 $wdkmembership_user_id = wdk_get_profile_page_id();
417
418 if(Plugin::$instance->editor->is_edit_mode() || (empty($wdk_listing_id) && empty($wdkmembership_user_id)))return;
419 //if(!in_array($element->get_name(), $this->supported_elements))return;
420
421 $WMVC = &wdk_get_instance();
422 $WMVC->model('field_m');
423 $WMVC->load_helper('listing');
424 $settings = $element->get_settings_for_display();
425
426 if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field']))
427 {
428 $field_id = NULL;
429 $field_value = NULL;
430 $field_empty = FALSE;
431 if(strpos($settings['wdk_related_field'], '__') !== FALSE){
432 $field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2);
433 }
434
435 if(is_null($field_id))return;
436 if($field_id == 'havent_calendar' || $field_id == 'have_calendar') {
437 if(function_exists('run_wdk_bookings')) {
438 global $Winter_MVC_wdk_bookings;
439 $Winter_MVC_wdk_bookings->model('calendar_m');
440 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id, 'is_activated' => 1));
441 if($field_id == 'havent_calendar') {
442 if($calendar){
443 $field_empty = true;
444 }
445 } else if($field_id == 'have_calendar') {
446 if(!$calendar){
447 $field_empty = true;
448 }
449 }
450 }
451 } elseif($field_id == 'have_sublistings') {
452
453 $field_empty = true;
454 if(!empty(wdk_field_value('listing_related_ids', $wdk_listing_id))){
455 foreach (explode(',',wdk_field_value('listing_related_ids', $wdk_listing_id)) as $key => $child_idlisting) {
456 if(!wdk_field_value('is_activated', $child_idlisting) || !wdk_field_value('is_approved', $child_idlisting)) continue;
457
458 $field_empty = false;
459 break;
460 }
461 }
462 } elseif($field_id == 'have_agency') {
463 $field_empty = true;
464 if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
465 if(wdk_field_value ('user_id_editor', $wdk_listing_id)) {
466 $agent_id = wdk_field_value ('user_id_editor', $wdk_listing_id);
467 global $Winter_MVC_wdk_membership;
468 $Winter_MVC_wdk_membership->model('agency_agent_m');
469 $agent_agency = $Winter_MVC_wdk_membership->agency_agent_m->get_by(array('agent_id' => $agent_id, 'status' => 'CONFIRMED'), TRUE);
470 if($agent_agency) {
471 $user = wdk_get_user_data( wmvc_show_data('agency_id', $agent_agency, 0));
472 if($user){
473 $field_empty = false;
474 }
475 }
476 }
477 }
478 } elseif($field_id == 'profile_have_agency') {
479 $wdkmembership_user_id = wdk_get_profile_page_id();
480 $field_empty = true;
481 if($wdkmembership_user_id) {
482 $user = wdk_get_user_data($wdkmembership_user_id);
483 if($user && wmvc_is_user_in_role($user['userdata'], 'wdk_agency')) {
484 $field_empty = false;
485 }
486
487 }
488 } elseif($field_id == 'havent_images' || $field_id == 'have_images') {
489 $images = wdk_field_value('listing_images', $wdk_listing_id);
490 if($field_id == 'havent_images') {
491 if($images){
492 $field_empty = true;
493 }
494 } else if($field_id == 'have_images') {
495 if(!$images){
496 $field_empty = true;
497 }
498 }
499 } elseif(wdk_field_option($field_id, 'field_type') == "SECTION") {
500
501 // get all section fields
502 $sections_data = $WMVC->field_m->get_fields_section();
503
504 if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return;
505
506 // check if all subfields are empty
507 $field_empty = true;
508 foreach($sections_data[$field_id]['fields'] as $field) {
509 if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){
510 $field_empty = false;
511 break;
512 }
513 }
514 }
515 else
516 {
517 $field_value = wdk_field_value($field_id, $wdk_listing_id);
518
519 if(empty($field_value))$field_empty = TRUE;
520 }
521
522 if($field_empty)
523 {
524 /*
525 echo '<pre>';
526 var_dump($settings['wdk_related_field']);
527 echo '</pre>';
528 */
529
530 $content = ob_get_clean();
531 }
532
533 }
534 }
535
536 }
537
538
539
540
541
542
543