PluginProbe
WP Directory Kit / 1.1.8
WP Directory Kit v1.1.8
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.1.8, at elementor-extensions/class-hider.php

430 lines 13.4 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' => 'section',
56 'action' => 'section_advanced',
57 ),
58 array(
59 'element' => 'column',
60 'action' => 'section_advanced',
61 ),
62 );
63
64 private $supported_elements = array(
65 'heading'
66 );
67
68 public function __construct() {
69
70 /*
71 Controls_Manager::add_tab(
72 'wdk_hider',
73 __( 'Hider', 'wpdirectorykit' )
74 );*/
75
76 $this->init();
77 }
78
79 public function init( $param = null ) {
80 // Enqueue scripts
81 add_action( 'elementor/frontend/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
82
83 // Enqueue styles
84 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_styles' ] );
85
86 // Elementor hooks
87
88 if ( $this->is_common ) {
89 // Add the advanced section required to display controls
90 $this->add_common_sections_actions();
91 }
92
93 $this->add_actions();
94 }
95
96 public static function is_enabled() {
97 return true;
98 }
99
100 public function add_script_depends( $handler ) {
101 $this->depended_scripts[] = $handler;
102 }
103
104 public function add_style_depends( $handler ) {
105 $this->depended_styles[] = $handler;
106 }
107
108 public function get_script_depends() {
109 return $this->depended_scripts;
110 }
111
112 public function enqueue_scripts() {
113 foreach ( $this->get_script_depends() as $script ) {
114 wp_enqueue_script( $script );
115 }
116 }
117
118 public function get_style_depends() {
119 return $this->depended_styles;
120 }
121
122 public static function get_description() {
123 return '';
124 }
125
126 public function enqueue_styles() {
127 foreach ( $this->get_style_depends() as $style ) {
128 wp_enqueue_style( $style );
129 }
130 }
131
132 public function _enqueue_scripts() {
133 $scripts = $this->get_script_depends();
134 if ( ! empty( $scripts ) ) {
135 foreach ( $scripts as $script ) {
136 wp_enqueue_script( $script );
137 }
138 }
139 }
140
141 public function _enqueue_styles() {
142 $styles = $this->get_style_depends();
143 if ( ! empty( $styles ) ) {
144 foreach ( $styles as $style ) {
145 wp_enqueue_style( $style );
146 }
147 }
148 }
149
150 public function enqueue_all() {
151 $this->_enqueue_styles();
152 $this->_enqueue_scripts();
153 }
154
155 public function get_low_name() {
156 return 'hider';
157 }
158
159 final public function add_common_sections( $element, $args ) {
160 $low_name = $this->get_low_name();
161 $section_name = 'wdk_section_' . $low_name . '_advanced';
162
163 if ( ! $this->has_controls ) {
164 // no need settings
165 return false;
166 }
167
168 // Check if this section exists
169 $section_exists = \Elementor\Plugin::instance()->controls_manager->get_control_from_stack( $element->get_unique_name(), $section_name );
170
171 if ( ! is_wp_error( $section_exists ) ) {
172 // We can't and should try to add this section to the stack
173 return false;
174 }
175
176 $this->get_control_section( $section_name, $element );
177 }
178
179 public function add_common_sections_actions() {
180 foreach ( $this->common_sections_actions as $action ) {
181 // Activate action for elements
182 add_action('elementor/element/' . $action['element'] . '/' . $action['action'] . '/after_section_end', function ( $element, $args ) {
183 $this->add_common_sections( $element, $args );
184 }, 10, 2);
185 }
186 }
187
188 protected function add_actions() {
189
190 // WIDGET
191 add_action( 'elementor/frontend/widget/before_render', [ $this, '_start_element' ], 10, 1 );
192 add_action( 'elementor/frontend/widget/after_render', [ $this, '_end_element' ], 10, 1 );
193
194 // SECTION
195 add_action( 'elementor/frontend/section/before_render', [ $this, '_start_element' ], 10, 1 );
196 add_action( 'elementor/frontend/section/after_render', [ $this, '_end_element' ], 10, 1 );
197
198 // COLUMN
199 add_action( 'elementor/frontend/column/before_render', [ $this, '_start_element' ], 10, 1 );
200 add_action( 'elementor/frontend/column/after_render', [ $this, '_end_element' ], 10, 1 );
201
202
203 }
204
205 protected function remove_controls( $element, $controls = null ) {
206 if ( empty( $controls ) ) {
207 return;
208 }
209
210 if ( is_array( $controls ) ) {
211 $control_id = $controls;
212
213 foreach ( $controls as $control_id ) {
214 $element->remove_control( $control_id );
215 }
216 } else {
217 $element->remove_control( $controls );
218 }
219 }
220
221 public function get_control_section( $section_name, $element ) {
222 $low_name = $this->get_low_name();
223
224 $element->start_controls_section(
225 $section_name,
226 [
227 'label' => '<span class="color-wdk icon icon-dyn-logo-wdk pull-right ml-1"></span> ' . $this->name,
228 'tab' => 'advanced',
229 ]
230 );
231
232 $WMVC = &wdk_get_instance();
233 $WMVC->model('field_m');
234 $fields_data = $WMVC->field_m->get();
235 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
236 $order_i = 0;
237
238 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
239 $fields_list [(++$order_i).'__have_calendar'] = esc_html__('Listing have calendar', 'wpdirectorykit');
240 $fields_list [(++$order_i).'__havent_calendar'] = esc_html__('Listing not have calendar', 'wpdirectorykit');
241 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
242 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
243 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
244 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
245 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
246 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
247 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
248 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
249 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
250 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
251
252 foreach($fields_data as $field)
253 {
254 if(wmvc_show_data('field_type', $field) == 'SECTION') {
255 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
256 } else {
257 $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).']';
258 }
259 }
260
261 $element->add_control(
262 'wdk_related_field',
263 [
264 'label' => esc_html__('WDK Related FIeld', 'wpdirectorykit'),
265 'type' => Controls_Manager::SELECT,
266 'options' => $fields_list,
267 'default' => '',
268 'separator' => 'after',
269 ]
270 );
271
272 $element->end_controls_section();
273
274 }
275
276 public function _start_element( $element ) {
277 global $wdk_listing_id;
278
279 if(Plugin::$instance->editor->is_edit_mode() || empty($wdk_listing_id))return;
280 //if(!in_array($element->get_name(), $this->supported_elements))return;
281
282 $WMVC = &wdk_get_instance();
283 $WMVC->model('field_m');
284
285 $settings = $element->get_settings_for_display();
286
287 if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field']))
288 {
289 $field_id = NULL;
290 $field_value = NULL;
291 $field_empty = FALSE;
292 if(strpos($settings['wdk_related_field'], '__') !== FALSE){
293 $field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2);
294 }
295
296 if(is_null($field_id))return;
297
298 if($field_id == 'havent_calendar' || $field_id == 'have_calendar') {
299 if(function_exists('run_wdk_bookings')) {
300 global $Winter_MVC_wdk_bookings;
301 $Winter_MVC_wdk_bookings->model('calendar_m');
302 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id));
303 if($field_id == 'havent_calendar') {
304 if($calendar){
305 $field_empty = true;
306 }
307 } else if($field_id == 'have_calendar') {
308 if(!$calendar){
309 $field_empty = true;
310 }
311 }
312 }
313 } elseif(wdk_field_option($field_id, 'field_type') == "SECTION") {
314
315 // get all section fields
316 $sections_data = $WMVC->field_m->get_fields_section();
317
318 if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return;
319
320 // check if all subfields are empty
321 $field_empty = true;
322 foreach($sections_data[$field_id]['fields'] as $field) {
323 if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){
324 $field_empty = false;
325 break;
326 }
327 }
328 }
329 else
330 {
331 $field_value = wdk_field_value($field_id, $wdk_listing_id);
332
333 if(empty($field_value))$field_empty = TRUE;
334 }
335
336 if($field_empty)
337 {
338 /*
339 echo '<pre>';
340 var_dump($settings['wdk_related_field']);
341 echo '</pre>';
342 */
343
344 ob_start();
345 }
346
347 }
348 }
349
350 public function _end_element( $element ) {
351 global $wdk_listing_id;
352
353 if(Plugin::$instance->editor->is_edit_mode() || empty($wdk_listing_id))return;
354 //if(!in_array($element->get_name(), $this->supported_elements))return;
355
356 $WMVC = &wdk_get_instance();
357 $WMVC->model('field_m');
358
359 $settings = $element->get_settings_for_display();
360
361 if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field']))
362 {
363 $field_id = NULL;
364 $field_value = NULL;
365 $field_empty = FALSE;
366 if(strpos($settings['wdk_related_field'], '__') !== FALSE){
367 $field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2);
368 }
369
370 if(is_null($field_id))return;
371 if($field_id == 'havent_calendar' || $field_id == 'have_calendar') {
372 if(function_exists('run_wdk_bookings')) {
373 global $Winter_MVC_wdk_bookings;
374 $Winter_MVC_wdk_bookings->model('calendar_m');
375 $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id));
376 if($field_id == 'havent_calendar') {
377 if($calendar){
378 $field_empty = true;
379 }
380 } else if($field_id == 'have_calendar') {
381 if(!$calendar){
382 $field_empty = true;
383 }
384 }
385 }
386 } elseif(wdk_field_option($field_id, 'field_type') == "SECTION") {
387
388 // get all section fields
389 $sections_data = $WMVC->field_m->get_fields_section();
390
391 if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return;
392
393 // check if all subfields are empty
394 $field_empty = true;
395 foreach($sections_data[$field_id]['fields'] as $field) {
396 if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){
397 $field_empty = false;
398 break;
399 }
400 }
401 }
402 else
403 {
404 $field_value = wdk_field_value($field_id, $wdk_listing_id);
405
406 if(empty($field_value))$field_empty = TRUE;
407 }
408
409 if($field_empty)
410 {
411 /*
412 echo '<pre>';
413 var_dump($settings['wdk_related_field']);
414 echo '</pre>';
415 */
416
417 $content = ob_get_clean();
418 }
419
420 }
421 }
422
423 }
424
425
426
427
428
429
430