| 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 |
$fields_allow_for_get = array(); |
| 244 |
$fields_allow_for_compare = array(); |
| 245 |
$fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit'); |
| 246 |
|
| 247 |
$fields_list [(++$order_i).'__hide_on_get'] = esc_html__('Hide if GET is', 'wpdirectorykit'); |
| 248 |
$fields_allow_for_get[] = $order_i.'__hide_on_get'; |
| 249 |
$fields_list [(++$order_i).'__show_on_get'] = esc_html__('Show if GET is', 'wpdirectorykit'); |
| 250 |
$fields_allow_for_get[] = $order_i.'__show_on_get'; |
| 251 |
|
| 252 |
$fields_list [(++$order_i).'__profile_have_agency'] = esc_html__('Profile page is agency', 'wpdirectorykit'); |
| 253 |
$fields_list [(++$order_i).'__profile_have_listings'] = esc_html__('Profile page have listings', 'wpdirectorykit'); |
| 254 |
$fields_list [(++$order_i).'__profile_nothave_listings'] = esc_html__('Profile page haven\'t listings', 'wpdirectorykit'); |
| 255 |
$fields_list [(++$order_i).'__profile_have_membership'] = esc_html__('Profile page have membership', 'wpdirectorykit'); |
| 256 |
$fields_list [(++$order_i).'__profile_nothave_membership'] = esc_html__('Profile page haven\'t membership', 'wpdirectorykit'); |
| 257 |
$fields_list [(++$order_i).'__have_agency'] = esc_html__('Listing have agency', 'wpdirectorykit'); |
| 258 |
$fields_list [(++$order_i).'__have_sublistings'] = esc_html__('Listing have sublistings', 'wpdirectorykit'); |
| 259 |
$fields_list [(++$order_i).'__have_wdk_rating'] = esc_html__('Exists WDK Rating', 'wpdirectorykit'); |
| 260 |
$fields_list [(++$order_i).'__havent_wdk_rating'] = esc_html__('WDK Rating is not exists', 'wpdirectorykit'); |
| 261 |
$fields_list [(++$order_i).'__have_calendar'] = esc_html__('Listing have calendar', 'wpdirectorykit'); |
| 262 |
$fields_list [(++$order_i).'__havent_calendar'] = esc_html__('Listing not have calendar', 'wpdirectorykit'); |
| 263 |
$fields_list [(++$order_i).'__havent_images'] = esc_html__('Listing not have images', 'wpdirectorykit'); |
| 264 |
$fields_list [(++$order_i).'__have_images'] = esc_html__('Listing have images', 'wpdirectorykit'); |
| 265 |
$fields_list [(++$order_i).'__havent_plan_images'] = esc_html__('Listing not have plan images', 'wpdirectorykit'); |
| 266 |
$fields_list [(++$order_i).'__have_plan_images'] = esc_html__('Listing have plan images', 'wpdirectorykit'); |
| 267 |
|
| 268 |
$fields_list [(++$order_i).'__membership_subscription_id_visitor'] = esc_html__('Id Membership Subscription Visitor', 'wpdirectorykit'); |
| 269 |
$fields_allow_for_compare[] = ($order_i).'__membership_subscription_id_visitor'; |
| 270 |
|
| 271 |
$fields_list [(++$order_i).'__membership_subscription_id_owner'] = esc_html__('Id Membership Subscription Owner', 'wpdirectorykit'); |
| 272 |
$fields_allow_for_compare[] = ($order_i).'__membership_subscription_id_owner'; |
| 273 |
|
| 274 |
$fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit'); |
| 275 |
$fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit'); |
| 276 |
$fields_allow_for_compare[] = ($order_i).'__post_id'; |
| 277 |
$fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit'); |
| 278 |
$fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit'); |
| 279 |
$fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit'); |
| 280 |
$fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit'); |
| 281 |
$fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit'); |
| 282 |
$fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit'); |
| 283 |
$fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit'); |
| 284 |
$fields_allow_for_compare[] = ($order_i).'__category_id'; |
| 285 |
$fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit'); |
| 286 |
$fields_allow_for_compare[] = ($order_i).'__location_id'; |
| 287 |
foreach($fields_data as $field) |
| 288 |
{ |
| 289 |
if(wmvc_show_data('field_type', $field) == 'SECTION') { |
| 290 |
$fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --'; |
| 291 |
} else { |
| 292 |
$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).']'; |
| 293 |
$fields_allow_for_compare[] = ($order_i).'__'.wmvc_show_data('idfield', $field); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
$element->add_control( |
| 298 |
'class_hider_important_note', |
| 299 |
[ |
| 300 |
'label' => '', |
| 301 |
'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 302 |
'raw' => esc_html__('Element will be hidden if related field is empty or condition is met.', 'wpdirectorykit'), |
| 303 |
'content_classes' => 'wdk_elementor_hint', |
| 304 |
'separator' => 'after', |
| 305 |
] |
| 306 |
); |
| 307 |
|
| 308 |
$element->add_control( |
| 309 |
'wdk_related_field', |
| 310 |
[ |
| 311 |
'label' => esc_html__('WDK Related FIeld', 'wpdirectorykit'), |
| 312 |
'type' => Controls_Manager::SELECT, |
| 313 |
'options' => $fields_list, |
| 314 |
'default' => '', |
| 315 |
'return_value' => 'section', |
| 316 |
'frontend_available' => true, |
| 317 |
'render_type' => 'none', |
| 318 |
] |
| 319 |
); |
| 320 |
|
| 321 |
$element->add_control( |
| 322 |
'wdk_related_show_on_get_key', |
| 323 |
[ |
| 324 |
'label' => __( 'Key', 'wpdirectorykit' ), |
| 325 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 326 |
'default' => '', |
| 327 |
'condition' => [ |
| 328 |
'wdk_related_field' => $fields_allow_for_get, |
| 329 |
], |
| 330 |
] |
| 331 |
); |
| 332 |
|
| 333 |
$element->add_control( |
| 334 |
'wdk_related_show_on_get_value', |
| 335 |
[ |
| 336 |
'label' => __( 'Value', 'wpdirectorykit' ), |
| 337 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 338 |
'default' => '', |
| 339 |
'condition' => [ |
| 340 |
'wdk_related_field' => $fields_allow_for_get, |
| 341 |
], |
| 342 |
] |
| 343 |
); |
| 344 |
|
| 345 |
$element->add_control( |
| 346 |
'wdk_related_compare_type', |
| 347 |
[ |
| 348 |
'label' => __( 'Compare Type', 'wpdirectorykit' ), |
| 349 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 350 |
'default' => '', |
| 351 |
'options' => [ |
| 352 |
'' => esc_html__('Default (if not empty)', 'wpdirectorykit'), |
| 353 |
'==' => esc_html__('==', 'wpdirectorykit'), |
| 354 |
'!=' => esc_html__('!=', 'wpdirectorykit'), |
| 355 |
'>' => esc_html__('>', 'wpdirectorykit'), |
| 356 |
'<' => esc_html__('<', 'wpdirectorykit'), |
| 357 |
'!in' => esc_html__('!in', 'wpdirectorykit'), |
| 358 |
'in' => esc_html__('in', 'wpdirectorykit'), |
| 359 |
], |
| 360 |
'condition' => [ |
| 361 |
'wdk_related_field' => $fields_allow_for_compare, |
| 362 |
], |
| 363 |
] |
| 364 |
); |
| 365 |
|
| 366 |
$element->add_control( |
| 367 |
'wdk_related_compare_value', |
| 368 |
[ |
| 369 |
'label' => __( 'Value', 'wpdirectorykit' ), |
| 370 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 371 |
'default' => '', |
| 372 |
'condition' => [ |
| 373 |
'wdk_related_field' => $fields_allow_for_compare, |
| 374 |
], |
| 375 |
] |
| 376 |
); |
| 377 |
|
| 378 |
$element->end_controls_section(); |
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
public function _start_element( $element ) { |
| 383 |
global $wdk_listing_id; |
| 384 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 385 |
|
| 386 |
//if(Plugin::$instance->editor->is_edit_mode())return; |
| 387 |
if(Plugin::$instance->editor->is_edit_mode() || (empty($wdk_listing_id) && empty($wdkmembership_user_id)))return; |
| 388 |
//if(!in_array($element->get_name(), $this->supported_elements))return; |
| 389 |
|
| 390 |
$WMVC = &wdk_get_instance(); |
| 391 |
$WMVC->model('field_m'); |
| 392 |
$WMVC->load_helper('listing'); |
| 393 |
$settings = $element->get_settings_for_display(); |
| 394 |
|
| 395 |
if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field'])) |
| 396 |
{ |
| 397 |
|
| 398 |
$field_id = NULL; |
| 399 |
$field_value = NULL; |
| 400 |
$field_empty = FALSE; |
| 401 |
if(strpos($settings['wdk_related_field'], '__') !== FALSE){ |
| 402 |
$field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2); |
| 403 |
} |
| 404 |
|
| 405 |
if(is_null($field_id))return; |
| 406 |
if($field_id == 'show_on_get' || $field_id == 'hide_on_get') { |
| 407 |
if(!empty($settings['wdk_related_show_on_get_key']) && !empty($settings['wdk_related_show_on_get_value'])) { |
| 408 |
$get_val = null; |
| 409 |
if(isset($_GET[$settings['wdk_related_show_on_get_key']])){ |
| 410 |
$get_val = sanitize_text_field($_GET[$settings['wdk_related_show_on_get_key']]); |
| 411 |
} |
| 412 |
|
| 413 |
if($field_id == 'hide_on_get') { |
| 414 |
if($get_val == $settings['wdk_related_show_on_get_value']){ |
| 415 |
$field_empty = true; |
| 416 |
} |
| 417 |
} else if($field_id == 'show_on_get') { |
| 418 |
if($get_val !== $settings['wdk_related_show_on_get_value']){ |
| 419 |
$field_empty = true; |
| 420 |
} |
| 421 |
} |
| 422 |
} |
| 423 |
}elseif($field_id == 'havent_wdk_rating' || $field_id == 'have_wdk_rating') { |
| 424 |
if(function_exists('run_wdk_reviews')) { |
| 425 |
global $Winter_MVC_wdk_reviews; |
| 426 |
$Winter_MVC_wdk_reviews->model('reviews_m'); |
| 427 |
$generate_avg_total = null; |
| 428 |
|
| 429 |
if($wdkmembership_user_id) { |
| 430 |
$generate_avg_total = $Winter_MVC_wdk_reviews->reviews_m->generate_avg_total($wdkmembership_user_id); |
| 431 |
} else { |
| 432 |
$generate_avg_total = $Winter_MVC_wdk_reviews->reviews_m->generate_avg_total($wdk_listing_id); |
| 433 |
} |
| 434 |
|
| 435 |
if($field_id == 'havent_wdk_rating') { |
| 436 |
|
| 437 |
if($generate_avg_total && !empty($generate_avg_total['reviewers_total'])){ |
| 438 |
$field_empty = true; |
| 439 |
} |
| 440 |
} else if($field_id == 'have_wdk_rating') { |
| 441 |
if(!$generate_avg_total || ($generate_avg_total && empty($generate_avg_total['reviewers_total']))){ |
| 442 |
$field_empty = true; |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
}elseif($field_id == 'havent_calendar' || $field_id == 'have_calendar') { |
| 447 |
if(function_exists('run_wdk_bookings')) { |
| 448 |
global $Winter_MVC_wdk_bookings; |
| 449 |
$Winter_MVC_wdk_bookings->model('calendar_m'); |
| 450 |
$calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id, 'is_activated' => 1)); |
| 451 |
if($field_id == 'havent_calendar') { |
| 452 |
if($calendar){ |
| 453 |
$field_empty = true; |
| 454 |
} |
| 455 |
} else if($field_id == 'have_calendar') { |
| 456 |
if(!$calendar){ |
| 457 |
$field_empty = true; |
| 458 |
} |
| 459 |
} |
| 460 |
} |
| 461 |
} elseif($field_id == 'profile_have_agency') { |
| 462 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 463 |
$field_empty = true; |
| 464 |
|
| 465 |
|
| 466 |
if($wdkmembership_user_id) { |
| 467 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 468 |
if($user && wmvc_is_user_in_role($user['userdata'], 'wdk_agency')) { |
| 469 |
$field_empty = false; |
| 470 |
} |
| 471 |
|
| 472 |
} |
| 473 |
} elseif($field_id == 'profile_have_listings') { |
| 474 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 475 |
$field_empty = true; |
| 476 |
|
| 477 |
|
| 478 |
if($wdkmembership_user_id) { |
| 479 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 480 |
$WMVC->model('listing_m'); |
| 481 |
if($WMVC->listing_m->total(array('is_activated' => 1,'is_approved'=>1), TRUE, $wdkmembership_user_id, TRUE)) { |
| 482 |
$field_empty = false; |
| 483 |
} |
| 484 |
} |
| 485 |
} elseif($field_id == 'profile_nothave_listings') { |
| 486 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 487 |
$field_empty = true; |
| 488 |
|
| 489 |
|
| 490 |
if($wdkmembership_user_id) { |
| 491 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 492 |
$WMVC->model('listing_m'); |
| 493 |
if(!$WMVC->listing_m->total(array('is_activated' => 1,'is_approved'=>1), TRUE, $wdkmembership_user_id, TRUE)) { |
| 494 |
$field_empty = false; |
| 495 |
} |
| 496 |
} |
| 497 |
} elseif($field_id == 'profile_have_listings') { |
| 498 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 499 |
$field_empty = true; |
| 500 |
|
| 501 |
|
| 502 |
if($wdkmembership_user_id) { |
| 503 |
if(wdk_membership_subscription_booking_enabled($wdkmembership_user_id)) { |
| 504 |
$field_empty = false; |
| 505 |
} |
| 506 |
} |
| 507 |
} elseif($field_id == 'profile_nothave_membership') { |
| 508 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 509 |
$field_empty = true; |
| 510 |
|
| 511 |
if($wdkmembership_user_id) { |
| 512 |
if(!wdk_membership_subscription_booking_enabled($wdkmembership_user_id)) { |
| 513 |
$field_empty = false; |
| 514 |
} |
| 515 |
} |
| 516 |
} elseif($field_id == 'have_agency') { |
| 517 |
$field_empty = true; |
| 518 |
if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) { |
| 519 |
if(wdk_field_value ('user_id_editor', $wdk_listing_id)) { |
| 520 |
$agent_id = wdk_field_value ('user_id_editor', $wdk_listing_id); |
| 521 |
global $Winter_MVC_wdk_membership; |
| 522 |
$Winter_MVC_wdk_membership->model('agency_agent_m'); |
| 523 |
$agent_agency = $Winter_MVC_wdk_membership->agency_agent_m->get_by(array('agent_id' => $agent_id, 'status' => 'CONFIRMED'), TRUE); |
| 524 |
if($agent_agency) { |
| 525 |
$user = wdk_get_user_data( wmvc_show_data('agency_id', $agent_agency, 0)); |
| 526 |
if($user){ |
| 527 |
$field_empty = false; |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
} |
| 532 |
} elseif($field_id == 'have_sublistings') { |
| 533 |
|
| 534 |
$field_empty = true; |
| 535 |
if(!empty(wdk_field_value('listing_related_ids', $wdk_listing_id))){ |
| 536 |
foreach (explode(',',wdk_field_value('listing_related_ids', $wdk_listing_id)) as $key => $child_idlisting) { |
| 537 |
if(!wdk_field_value('is_activated', $child_idlisting) || !wdk_field_value('is_approved', $child_idlisting)) continue; |
| 538 |
|
| 539 |
$field_empty = false; |
| 540 |
break; |
| 541 |
} |
| 542 |
} |
| 543 |
} elseif($field_id == 'havent_images' || $field_id == 'have_images') { |
| 544 |
$images = wdk_field_value('listing_images', $wdk_listing_id); |
| 545 |
if($field_id == 'havent_images') { |
| 546 |
if($images){ |
| 547 |
$field_empty = true; |
| 548 |
} |
| 549 |
} else if($field_id == 'have_images') { |
| 550 |
if(!$images){ |
| 551 |
$field_empty = true; |
| 552 |
} |
| 553 |
} |
| 554 |
} elseif($field_id == 'havent_plan_images' || $field_id == 'have_plan_images') { |
| 555 |
$images = wdk_field_value('listing_plans_documents', $wdk_listing_id); |
| 556 |
if($field_id == 'havent_plan_images') { |
| 557 |
if($images){ |
| 558 |
$field_empty = true; |
| 559 |
} |
| 560 |
} else if($field_id == 'have_plan_images') { |
| 561 |
if(!$images){ |
| 562 |
$field_empty = true; |
| 563 |
} |
| 564 |
} |
| 565 |
} elseif(wdk_field_option($field_id, 'field_type') == "SECTION") { |
| 566 |
|
| 567 |
// get all section fields |
| 568 |
$sections_data = $WMVC->field_m->get_fields_section(); |
| 569 |
|
| 570 |
if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return; |
| 571 |
|
| 572 |
// check if all subfields are empty |
| 573 |
$field_empty = true; |
| 574 |
foreach($sections_data[$field_id]['fields'] as $field) { |
| 575 |
if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){ |
| 576 |
$field_empty = false; |
| 577 |
break; |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
else |
| 582 |
{ |
| 583 |
$field_value = wdk_field_value($field_id, $wdk_listing_id); |
| 584 |
|
| 585 |
if($field_id == 'membership_subscription_id_visitor') { |
| 586 |
if(get_current_user_id()) { |
| 587 |
$field_value = wdk_get_user_subscription_id(get_current_user_id()); |
| 588 |
} else { |
| 589 |
$field_value = 0; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
if($field_id == 'membership_subscription_id_owner') { |
| 594 |
if(wdk_field_value('user_id_editor', $wdk_listing_id)) { |
| 595 |
$field_value = wdk_get_user_subscription_id(wdk_field_value('user_id_editor', $wdk_listing_id)); |
| 596 |
} else { |
| 597 |
$field_value = 0; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
if(!empty($settings['wdk_related_compare_type'])) { |
| 602 |
switch ($settings['wdk_related_compare_type']) { |
| 603 |
case '==': |
| 604 |
if($field_value == $settings['wdk_related_compare_value']) { |
| 605 |
$field_empty = TRUE; |
| 606 |
} |
| 607 |
break; |
| 608 |
case '!=': |
| 609 |
if($field_value != $settings['wdk_related_compare_value']) { |
| 610 |
$field_empty = TRUE; |
| 611 |
} |
| 612 |
break; |
| 613 |
case '>': |
| 614 |
if($field_value > $settings['wdk_related_compare_value']) { |
| 615 |
$field_empty = TRUE; |
| 616 |
} |
| 617 |
break; |
| 618 |
case '<': |
| 619 |
if($field_value < $settings['wdk_related_compare_value']) { |
| 620 |
$field_empty = TRUE; |
| 621 |
} |
| 622 |
break; |
| 623 |
case 'in': |
| 624 |
// Accept comma separated values or array |
| 625 |
$compare_values = $settings['wdk_related_compare_value']; |
| 626 |
if (!is_array($compare_values)) { |
| 627 |
$compare_values = array_map('trim', explode(',', $compare_values)); |
| 628 |
// dump($compare_values); |
| 629 |
} |
| 630 |
if (in_array($field_value, $compare_values)) { |
| 631 |
$field_empty = TRUE; |
| 632 |
} |
| 633 |
break; |
| 634 |
case '!in': |
| 635 |
// Accept comma separated values or array |
| 636 |
$compare_values = $settings['wdk_related_compare_value']; |
| 637 |
if (!is_array($compare_values)) { |
| 638 |
$compare_values = array_map('trim', explode(',', $compare_values)); |
| 639 |
} |
| 640 |
if (!in_array($field_value, $compare_values)) { |
| 641 |
$field_empty = TRUE; |
| 642 |
} |
| 643 |
break; |
| 644 |
default: |
| 645 |
// No action |
| 646 |
break; |
| 647 |
} |
| 648 |
} else { |
| 649 |
if(empty($field_value))$field_empty = TRUE; |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
if($field_empty) |
| 654 |
{ |
| 655 |
/* |
| 656 |
echo '<pre>'; |
| 657 |
var_dump($settings['wdk_related_field']); |
| 658 |
echo '</pre>'; |
| 659 |
*/ |
| 660 |
|
| 661 |
ob_start(); |
| 662 |
} |
| 663 |
|
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
public function _end_element( $element ) { |
| 668 |
global $wdk_listing_id; |
| 669 |
|
| 670 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 671 |
|
| 672 |
//if(Plugin::$instance->editor->is_edit_mode())return; |
| 673 |
if(Plugin::$instance->editor->is_edit_mode() || (empty($wdk_listing_id) && empty($wdkmembership_user_id)))return; |
| 674 |
//if(!in_array($element->get_name(), $this->supported_elements))return; |
| 675 |
|
| 676 |
$WMVC = &wdk_get_instance(); |
| 677 |
$WMVC->model('field_m'); |
| 678 |
$WMVC->load_helper('listing'); |
| 679 |
$settings = $element->get_settings_for_display(); |
| 680 |
|
| 681 |
if(isset($settings['wdk_related_field']) && !empty($settings['wdk_related_field'])) |
| 682 |
{ |
| 683 |
$field_id = NULL; |
| 684 |
$field_value = NULL; |
| 685 |
$field_empty = FALSE; |
| 686 |
if(strpos($settings['wdk_related_field'], '__') !== FALSE){ |
| 687 |
$field_id = substr($settings['wdk_related_field'], strpos($settings['wdk_related_field'],'__')+2); |
| 688 |
} |
| 689 |
|
| 690 |
if(is_null($field_id))return; |
| 691 |
if($field_id == 'show_on_get' || $field_id == 'hide_on_get') { |
| 692 |
if(!empty($settings['wdk_related_show_on_get_key']) && !empty($settings['wdk_related_show_on_get_value'])) { |
| 693 |
$get_val = null; |
| 694 |
if(isset($_GET[$settings['wdk_related_show_on_get_key']])){ |
| 695 |
$get_val = sanitize_text_field($_GET[$settings['wdk_related_show_on_get_key']]); |
| 696 |
} |
| 697 |
if($field_id == 'hide_on_get') { |
| 698 |
if($get_val == $settings['wdk_related_show_on_get_value']){ |
| 699 |
$field_empty = true; |
| 700 |
} |
| 701 |
} else if($field_id == 'show_on_get') { |
| 702 |
if($get_val !== $settings['wdk_related_show_on_get_value']){ |
| 703 |
$field_empty = true; |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
}elseif($field_id == 'havent_wdk_rating' || $field_id == 'have_wdk_rating') { |
| 708 |
if(function_exists('run_wdk_reviews')) { |
| 709 |
global $Winter_MVC_wdk_reviews; |
| 710 |
$Winter_MVC_wdk_reviews->model('reviews_m'); |
| 711 |
$generate_avg_total = null; |
| 712 |
|
| 713 |
if($wdkmembership_user_id) { |
| 714 |
$generate_avg_total = $Winter_MVC_wdk_reviews->reviews_m->generate_avg_total($wdkmembership_user_id); |
| 715 |
} else { |
| 716 |
$generate_avg_total = $Winter_MVC_wdk_reviews->reviews_m->generate_avg_total($wdk_listing_id); |
| 717 |
} |
| 718 |
|
| 719 |
if($field_id == 'havent_wdk_rating') { |
| 720 |
if($generate_avg_total && !empty($generate_avg_total['reviewers_total'])){ |
| 721 |
$field_empty = true; |
| 722 |
} |
| 723 |
} else if($field_id == 'have_wdk_rating') { |
| 724 |
if(!$generate_avg_total || ($generate_avg_total && empty($generate_avg_total['reviewers_total']))){ |
| 725 |
$field_empty = true; |
| 726 |
} |
| 727 |
} |
| 728 |
} |
| 729 |
}elseif($field_id == 'havent_calendar' || $field_id == 'have_calendar') { |
| 730 |
if(function_exists('run_wdk_bookings')) { |
| 731 |
global $Winter_MVC_wdk_bookings; |
| 732 |
$Winter_MVC_wdk_bookings->model('calendar_m'); |
| 733 |
$calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id' => $wdk_listing_id, 'is_activated' => 1)); |
| 734 |
if($field_id == 'havent_calendar') { |
| 735 |
if($calendar){ |
| 736 |
$field_empty = true; |
| 737 |
} |
| 738 |
} else if($field_id == 'have_calendar') { |
| 739 |
if(!$calendar){ |
| 740 |
$field_empty = true; |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
} elseif($field_id == 'have_sublistings') { |
| 745 |
|
| 746 |
$field_empty = true; |
| 747 |
if(!empty(wdk_field_value('listing_related_ids', $wdk_listing_id))){ |
| 748 |
foreach (explode(',',wdk_field_value('listing_related_ids', $wdk_listing_id)) as $key => $child_idlisting) { |
| 749 |
if(!wdk_field_value('is_activated', $child_idlisting) || !wdk_field_value('is_approved', $child_idlisting)) continue; |
| 750 |
|
| 751 |
$field_empty = false; |
| 752 |
break; |
| 753 |
} |
| 754 |
} |
| 755 |
} elseif($field_id == 'profile_have_listings') { |
| 756 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 757 |
$field_empty = true; |
| 758 |
|
| 759 |
|
| 760 |
if($wdkmembership_user_id) { |
| 761 |
if(wdk_membership_subscription_booking_enabled($wdkmembership_user_id)) { |
| 762 |
$field_empty = false; |
| 763 |
} |
| 764 |
} |
| 765 |
} elseif($field_id == 'profile_nothave_membership') { |
| 766 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 767 |
$field_empty = true; |
| 768 |
|
| 769 |
if($wdkmembership_user_id) { |
| 770 |
if(!wdk_membership_subscription_booking_enabled($wdkmembership_user_id)) { |
| 771 |
$field_empty = false; |
| 772 |
} |
| 773 |
} |
| 774 |
} elseif($field_id == 'have_agency') { |
| 775 |
$field_empty = true; |
| 776 |
if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) { |
| 777 |
if(wdk_field_value ('user_id_editor', $wdk_listing_id)) { |
| 778 |
$agent_id = wdk_field_value ('user_id_editor', $wdk_listing_id); |
| 779 |
global $Winter_MVC_wdk_membership; |
| 780 |
$Winter_MVC_wdk_membership->model('agency_agent_m'); |
| 781 |
$agent_agency = $Winter_MVC_wdk_membership->agency_agent_m->get_by(array('agent_id' => $agent_id, 'status' => 'CONFIRMED'), TRUE); |
| 782 |
if($agent_agency) { |
| 783 |
$user = wdk_get_user_data( wmvc_show_data('agency_id', $agent_agency, 0)); |
| 784 |
if($user){ |
| 785 |
$field_empty = false; |
| 786 |
} |
| 787 |
} |
| 788 |
} |
| 789 |
} |
| 790 |
} elseif($field_id == 'profile_have_agency') { |
| 791 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 792 |
$field_empty = true; |
| 793 |
if($wdkmembership_user_id) { |
| 794 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 795 |
if($user && wmvc_is_user_in_role($user['userdata'], 'wdk_agency')) { |
| 796 |
$field_empty = false; |
| 797 |
} |
| 798 |
|
| 799 |
} |
| 800 |
} elseif($field_id == 'profile_have_listings') { |
| 801 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 802 |
$field_empty = true; |
| 803 |
|
| 804 |
|
| 805 |
if($wdkmembership_user_id) { |
| 806 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 807 |
$WMVC->model('listing_m'); |
| 808 |
if($WMVC->listing_m->total(array('is_activated' => 1,'is_approved'=>1), TRUE, $wdkmembership_user_id, TRUE)) { |
| 809 |
$field_empty = false; |
| 810 |
} |
| 811 |
} |
| 812 |
} elseif($field_id == 'profile_nothave_listings') { |
| 813 |
$wdkmembership_user_id = wdk_get_profile_page_id(); |
| 814 |
$field_empty = true; |
| 815 |
|
| 816 |
|
| 817 |
if($wdkmembership_user_id) { |
| 818 |
$user = wdk_get_user_data($wdkmembership_user_id); |
| 819 |
$WMVC->model('listing_m'); |
| 820 |
if(!$WMVC->listing_m->total(array('is_activated' => 1,'is_approved'=>1), TRUE, $wdkmembership_user_id, TRUE)) { |
| 821 |
$field_empty = false; |
| 822 |
} |
| 823 |
} |
| 824 |
} elseif($field_id == 'havent_images' || $field_id == 'have_images') { |
| 825 |
$images = wdk_field_value('listing_images', $wdk_listing_id); |
| 826 |
if($field_id == 'havent_images') { |
| 827 |
if($images){ |
| 828 |
$field_empty = true; |
| 829 |
} |
| 830 |
} else if($field_id == 'have_images') { |
| 831 |
if(!$images){ |
| 832 |
$field_empty = true; |
| 833 |
} |
| 834 |
} |
| 835 |
} elseif($field_id == 'havent_plan_images' || $field_id == 'have_plan_images') { |
| 836 |
$images = wdk_field_value('listing_plans_documents', $wdk_listing_id); |
| 837 |
if($field_id == 'havent_plan_images') { |
| 838 |
if($images){ |
| 839 |
$field_empty = true; |
| 840 |
} |
| 841 |
} else if($field_id == 'have_plan_images') { |
| 842 |
if(!$images){ |
| 843 |
$field_empty = true; |
| 844 |
} |
| 845 |
} |
| 846 |
} elseif(wdk_field_option($field_id, 'field_type') == "SECTION") { |
| 847 |
|
| 848 |
// get all section fields |
| 849 |
$sections_data = $WMVC->field_m->get_fields_section(); |
| 850 |
|
| 851 |
if(!isset($sections_data[$field_id]) || !isset($sections_data[$field_id]['fields']))return; |
| 852 |
|
| 853 |
// check if all subfields are empty |
| 854 |
$field_empty = true; |
| 855 |
foreach($sections_data[$field_id]['fields'] as $field) { |
| 856 |
if(!empty(wdk_field_value(wmvc_show_data('idfield', $field), $wdk_listing_id))){ |
| 857 |
$field_empty = false; |
| 858 |
break; |
| 859 |
} |
| 860 |
} |
| 861 |
} |
| 862 |
else |
| 863 |
{ |
| 864 |
$field_value = wdk_field_value($field_id, $wdk_listing_id); |
| 865 |
|
| 866 |
if($field_id == 'membership_subscription_id_visitor') { |
| 867 |
if(get_current_user_id()) { |
| 868 |
$field_value = wdk_get_user_subscription_id(get_current_user_id()); |
| 869 |
} else { |
| 870 |
$field_value = 0; |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
if($field_id == 'membership_subscription_id_owner') { |
| 875 |
if(wdk_field_value('user_id_editor', $wdk_listing_id)) { |
| 876 |
$field_value = wdk_get_user_subscription_id(wdk_field_value('user_id_editor', $wdk_listing_id)); |
| 877 |
} else { |
| 878 |
$field_value = 0; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
if(!empty($settings['wdk_related_compare_type'])) { |
| 883 |
switch ($settings['wdk_related_compare_type']) { |
| 884 |
case '==': |
| 885 |
if($field_value == $settings['wdk_related_compare_value']) { |
| 886 |
$field_empty = TRUE; |
| 887 |
} |
| 888 |
break; |
| 889 |
case '!=': |
| 890 |
if($field_value != $settings['wdk_related_compare_value']) { |
| 891 |
$field_empty = TRUE; |
| 892 |
} |
| 893 |
break; |
| 894 |
case '>': |
| 895 |
if($field_value > $settings['wdk_related_compare_value']) { |
| 896 |
$field_empty = TRUE; |
| 897 |
} |
| 898 |
break; |
| 899 |
case '<': |
| 900 |
if($field_value < $settings['wdk_related_compare_value']) { |
| 901 |
$field_empty = TRUE; |
| 902 |
} |
| 903 |
break; |
| 904 |
case 'in': |
| 905 |
// Accept comma separated values or array |
| 906 |
$compare_values = $settings['wdk_related_compare_value']; |
| 907 |
if (!is_array($compare_values)) { |
| 908 |
$compare_values = array_map('trim', explode(',', $compare_values)); |
| 909 |
} |
| 910 |
if (in_array($field_value, $compare_values)) { |
| 911 |
$field_empty = TRUE; |
| 912 |
} |
| 913 |
break; |
| 914 |
case '!in': |
| 915 |
// Accept comma separated values or array |
| 916 |
$compare_values = $settings['wdk_related_compare_value']; |
| 917 |
if (!is_array($compare_values)) { |
| 918 |
$compare_values = array_map('trim', explode(',', $compare_values)); |
| 919 |
} |
| 920 |
if (!in_array($field_value, $compare_values)) { |
| 921 |
$field_empty = TRUE; |
| 922 |
} |
| 923 |
break; |
| 924 |
default: |
| 925 |
// No action |
| 926 |
break; |
| 927 |
} |
| 928 |
} else { |
| 929 |
if(empty($field_value))$field_empty = TRUE; |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
if($field_empty) |
| 934 |
{ |
| 935 |
/* |
| 936 |
echo '<pre>'; |
| 937 |
var_dump($settings['wdk_related_field']); |
| 938 |
echo '</pre>'; |
| 939 |
*/ |
| 940 |
|
| 941 |
$content = ob_get_clean(); |
| 942 |
} |
| 943 |
|
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|