breadcrumbs.php
6 months ago
copyright.php
6 months ago
current-time.php
6 months ago
logo.php
6 months ago
menu.php
6 months ago
modern-search.php
6 months ago
search.php
6 months ago
select.php
6 months ago
shopping-cart.php
6 months ago
site-title.php
6 months ago
search.php
514 lines
| 1 | <?php |
| 2 | namespace Auxin\Plugin\CoreElements\Elementor\Elements\Theme_Elements; |
| 3 | |
| 4 | use Elementor\Plugin; |
| 5 | use Elementor\Widget_Base; |
| 6 | use Elementor\Controls_Manager; |
| 7 | use Elementor\Group_Control_Typography; |
| 8 | use Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 9 | use Elementor\Group_Control_Border; |
| 10 | |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // Exit if accessed directly. |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Elementor 'SearchBox' widget. |
| 18 | * |
| 19 | * Elementor widget that displays an 'SearchBox'. |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | class SearchBox extends Widget_Base { |
| 24 | |
| 25 | /** |
| 26 | * Get widget name. |
| 27 | * |
| 28 | * Retrieve 'SearchBox' widget name. |
| 29 | * |
| 30 | * @since 1.0.0 |
| 31 | * @access public |
| 32 | * |
| 33 | * @return string Widget name. |
| 34 | */ |
| 35 | public function get_name() { |
| 36 | return 'aux_search_box'; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get widget title. |
| 41 | * |
| 42 | * Retrieve 'SearchBox' widget title. |
| 43 | * |
| 44 | * @since 1.0.0 |
| 45 | * @access public |
| 46 | * |
| 47 | * @return string Widget title. |
| 48 | */ |
| 49 | public function get_title() { |
| 50 | return __('Search Form', 'auxin-elements' ); |
| 51 | } |
| 52 | |
| 53 | public function has_widget_inner_wrapper(): bool { |
| 54 | return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Get widget icon. |
| 60 | * |
| 61 | * Retrieve 'SearchBox' widget icon. |
| 62 | * |
| 63 | * @since 1.0.0 |
| 64 | * @access public |
| 65 | * |
| 66 | * @return string Widget icon. |
| 67 | */ |
| 68 | public function get_icon() { |
| 69 | return 'eicon-search auxin-badge'; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get widget categories. |
| 74 | * |
| 75 | * Retrieve 'SearchBox' widget icon. |
| 76 | * |
| 77 | * @since 1.0.0 |
| 78 | * @access public |
| 79 | * |
| 80 | * @return string Widget icon. |
| 81 | */ |
| 82 | public function get_categories() { |
| 83 | return array( 'auxin-core', 'auxin-theme-elements' ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Register 'SearchBox' widget controls. |
| 88 | * |
| 89 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 90 | * |
| 91 | * @since 1.0.0 |
| 92 | * @access protected |
| 93 | */ |
| 94 | protected function register_controls() { |
| 95 | |
| 96 | $this->start_controls_section( |
| 97 | 'general', |
| 98 | array( |
| 99 | 'label' => __('General', 'auxin-elements' ), |
| 100 | ) |
| 101 | ); |
| 102 | |
| 103 | $this->add_control( |
| 104 | 'type', |
| 105 | array( |
| 106 | 'label' => __('Type', 'auxin-elements'), |
| 107 | 'type' => Controls_Manager::SELECT, |
| 108 | 'default' => 'icon', |
| 109 | 'options' => array( |
| 110 | 'form' => __('Form' , 'auxin-elements' ), |
| 111 | 'icon' => __('Icon' , 'auxin-elements' ) |
| 112 | ) |
| 113 | ) |
| 114 | ); |
| 115 | |
| 116 | $this->add_control( |
| 117 | 'submit_type', |
| 118 | array( |
| 119 | 'label' => __('Submit Button Type', 'auxin-elements'), |
| 120 | 'type' => Controls_Manager::SELECT, |
| 121 | 'default' => 'none', |
| 122 | 'options' => array( |
| 123 | 'none' => __('None' , 'auxin-elements' ), |
| 124 | 'icon' => __('Icon' , 'auxin-elements' ), |
| 125 | 'button' => __('Button' , 'auxin-elements' ), |
| 126 | ), |
| 127 | 'condition' => array( |
| 128 | 'type' => 'form' |
| 129 | ) |
| 130 | ) |
| 131 | ); |
| 132 | |
| 133 | $this->add_control( |
| 134 | 'aux_search_icon', |
| 135 | array( |
| 136 | 'label' => __('Icon','auxin-elements' ), |
| 137 | 'description' => __('Please choose an icon from the list.', 'auxin-elements'), |
| 138 | 'type' => Controls_Manager::ICONS, |
| 139 | 'conditions' => array( |
| 140 | 'relation' => 'or', |
| 141 | 'terms' => array( |
| 142 | array( |
| 143 | 'name' => 'type', |
| 144 | 'operator' => '===', |
| 145 | 'value' => 'icon' |
| 146 | ), |
| 147 | array( |
| 148 | 'name' => 'submit_type', |
| 149 | 'operator' => '===', |
| 150 | 'value' => 'icon' |
| 151 | ) |
| 152 | ) |
| 153 | ) |
| 154 | ) |
| 155 | ); |
| 156 | |
| 157 | $this->add_control( |
| 158 | 'has_category', |
| 159 | array( |
| 160 | 'label' => __('Search by Category', 'auxin-elements'), |
| 161 | 'type' => Controls_Manager::SWITCHER, |
| 162 | 'label_on' => __( 'On', 'auxin-elements' ), |
| 163 | 'label_off' => __( 'Off', 'auxin-elements' ), |
| 164 | 'return_value' => true, |
| 165 | 'default' => false, |
| 166 | 'condition' => array( |
| 167 | 'type' => 'form' |
| 168 | ) |
| 169 | ) |
| 170 | ); |
| 171 | |
| 172 | $this->end_controls_section(); |
| 173 | |
| 174 | /*-----------------------------------------------------------------------------------*/ |
| 175 | /* Style TAB |
| 176 | /*-----------------------------------------------------------------------------------*/ |
| 177 | |
| 178 | /* Icon Section |
| 179 | /*-------------------------------------*/ |
| 180 | $this->start_controls_section( |
| 181 | 'icon_section', |
| 182 | array( |
| 183 | 'label' => __( 'Icon', 'auxin-elements' ), |
| 184 | 'tab' => Controls_Manager::TAB_STYLE, |
| 185 | 'conditions' => array( |
| 186 | 'relation' => 'or', |
| 187 | 'terms' => array( |
| 188 | array( |
| 189 | 'name' => 'type', |
| 190 | 'operator' => '===', |
| 191 | 'value' => 'icon' |
| 192 | ), |
| 193 | array( |
| 194 | 'name' => 'submit_type', |
| 195 | 'operator' => '===', |
| 196 | 'value' => 'icon' |
| 197 | ) |
| 198 | ) |
| 199 | ) |
| 200 | ) |
| 201 | ); |
| 202 | |
| 203 | $this->add_control( |
| 204 | 'icon_background_color', |
| 205 | array( |
| 206 | 'label' => __('Background Color', 'auxin-elements'), |
| 207 | 'type' => Controls_Manager::COLOR, |
| 208 | 'default' => 'transparent', |
| 209 | 'selectors' => array( |
| 210 | '{{WRAPPER}} .aux-search-form .aux-submit-icon-container,{{WRAPPER}} .aux-search-section button.aux-search-icon, {{WRAPPER}} .aux-search-section svg.aux-search-icon' => 'background-color: {{VALUE}}', |
| 211 | ) |
| 212 | ) |
| 213 | ); |
| 214 | |
| 215 | $this->add_responsive_control( |
| 216 | 'icon_size', |
| 217 | array( |
| 218 | 'label' => __( 'Size', 'auxin-elements' ), |
| 219 | 'type' => Controls_Manager::SLIDER, |
| 220 | 'size_units' => array( 'px', 'em' ), |
| 221 | 'range' => array( |
| 222 | 'px' => array( |
| 223 | 'max' => 100 |
| 224 | ), |
| 225 | 'em' => array( |
| 226 | 'max' => 10 |
| 227 | ) |
| 228 | ), |
| 229 | 'selectors' => array( |
| 230 | '{{WRAPPER}} .aux-search-icon:before, {{WRAPPER}} .aux-submit-icon-container:before, {{WRAPPER}} .aux-submit-icon-container i' => 'font-size: {{SIZE}}{{UNIT}};', |
| 231 | '{{WRAPPER}} svg' => 'font-size: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};width: auto;', |
| 232 | ) |
| 233 | ) |
| 234 | ); |
| 235 | |
| 236 | $this->add_control( |
| 237 | 'icon_color', |
| 238 | array( |
| 239 | 'label' => __('Icon color', 'auxin-elements'), |
| 240 | 'type' => Controls_Manager::COLOR, |
| 241 | 'default' => '#303030', |
| 242 | 'selectors' => array( |
| 243 | '{{WRAPPER}} .aux-search-icon:before, {{WRAPPER}} .aux-submit-icon-container:before' => 'color: {{VALUE}}', |
| 244 | '{{WRAPPER}} svg' => 'fill: {{VALUE}};', |
| 245 | ) |
| 246 | ) |
| 247 | ); |
| 248 | |
| 249 | $this->add_responsive_control( |
| 250 | 'icon_margin', |
| 251 | array( |
| 252 | 'label' => __( 'Icon Margin', 'auxin-elements' ), |
| 253 | 'type' => Controls_Manager::DIMENSIONS, |
| 254 | 'size_units' => array( 'px', '%' ), |
| 255 | 'selectors' => array( |
| 256 | '{{WRAPPER}} .aux-search-icon, {{WRAPPER}} .aux-submit-icon-container' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 257 | ) |
| 258 | ) |
| 259 | ); |
| 260 | |
| 261 | $this->end_controls_section(); |
| 262 | |
| 263 | /* Icon Section |
| 264 | /*-------------------------------------*/ |
| 265 | $this->start_controls_section( |
| 266 | 'form_section', |
| 267 | array( |
| 268 | 'label' => __( 'Form', 'auxin-elements' ), |
| 269 | 'tab' => Controls_Manager::TAB_STYLE, |
| 270 | 'conditions' => array( |
| 271 | 'relation' => 'or', |
| 272 | 'terms' => array( |
| 273 | array( |
| 274 | 'name' => 'type', |
| 275 | 'operator' => '===', |
| 276 | 'value' => 'form' |
| 277 | ) |
| 278 | ) |
| 279 | ) |
| 280 | ) |
| 281 | ); |
| 282 | |
| 283 | $this->add_group_control( |
| 284 | Group_Control_Typography::get_type(), |
| 285 | array( |
| 286 | 'name' => 'form_typgraphy', |
| 287 | 'global' => [ |
| 288 | 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, |
| 289 | ], |
| 290 | 'selector' => '{{WRAPPER}} .aux-search-form .aux-search-field' |
| 291 | ) |
| 292 | ); |
| 293 | |
| 294 | |
| 295 | $this->add_responsive_control( |
| 296 | 'form_width', |
| 297 | array( |
| 298 | 'label' => __('Width','auxin-elements' ), |
| 299 | 'type' => Controls_Manager::SLIDER, |
| 300 | 'size_units' => array('px', 'em','%'), |
| 301 | 'range' => array( |
| 302 | '%' => array( |
| 303 | 'min' => 1, |
| 304 | 'max' => 120, |
| 305 | 'step' => 1 |
| 306 | ), |
| 307 | 'em' => array( |
| 308 | 'min' => 1, |
| 309 | 'max' => 120, |
| 310 | 'step' => 1 |
| 311 | ), |
| 312 | 'px' => array( |
| 313 | 'min' => 1, |
| 314 | 'max' => 1900, |
| 315 | 'step' => 1 |
| 316 | ) |
| 317 | ), |
| 318 | 'selectors' => array( |
| 319 | '{{WRAPPER}} .aux-search-form .aux-search-field' => 'max-width:{{SIZE}}{{UNIT}};' |
| 320 | ), |
| 321 | ) |
| 322 | ); |
| 323 | |
| 324 | $this->add_responsive_control( |
| 325 | 'form_margin', |
| 326 | array( |
| 327 | 'label' => __( 'Margin', 'auxin-elements' ), |
| 328 | 'type' => Controls_Manager::DIMENSIONS, |
| 329 | 'size_units' => array( 'px', '%' ), |
| 330 | 'selectors' => array( |
| 331 | '{{WRAPPER}} .aux-search-form .aux-search-field' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 332 | ) |
| 333 | ) |
| 334 | ); |
| 335 | |
| 336 | $this->add_responsive_control( |
| 337 | 'form_padding', |
| 338 | array( |
| 339 | 'label' => __( 'Padding', 'auxin-elements' ), |
| 340 | 'type' => Controls_Manager::DIMENSIONS, |
| 341 | 'size_units' => array( 'px', '%' ), |
| 342 | 'selectors' => array( |
| 343 | '{{WRAPPER}} .aux-search-form .aux-search-field' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 344 | ) |
| 345 | ) |
| 346 | ); |
| 347 | |
| 348 | $this->add_control( |
| 349 | 'form_color', |
| 350 | array( |
| 351 | 'label' => __('Form Background Color', 'auxin-elements'), |
| 352 | 'type' => Controls_Manager::COLOR, |
| 353 | 'default' => '#FFF', |
| 354 | 'selectors' => array( |
| 355 | '{{WRAPPER}} .aux-search-form .aux-search-field, {{WRAPPER}} .aux-search-form select' => 'background-color: {{VALUE}}', |
| 356 | ) |
| 357 | ) |
| 358 | ); |
| 359 | |
| 360 | $this->add_group_control( |
| 361 | Group_Control_Border::get_type(), |
| 362 | array( |
| 363 | 'name' => 'form_border', |
| 364 | 'selector' => '{{WRAPPER}} .aux-search-form .aux-search-field', |
| 365 | 'separator' => 'none' |
| 366 | ) |
| 367 | ); |
| 368 | |
| 369 | $this->add_control( |
| 370 | 'form_border_radius', |
| 371 | array( |
| 372 | 'label' => __( 'Border Radius', 'auxin-elements' ), |
| 373 | 'type' => Controls_Manager::DIMENSIONS, |
| 374 | 'size_units' => array( 'px', 'em', '%' ), |
| 375 | 'selectors' => array( |
| 376 | '{{WRAPPER}} .aux-search-form .aux-search-field' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; overflow:hidden;' |
| 377 | ), |
| 378 | 'allowed_dimensions' => 'all', |
| 379 | 'separator' => 'after' |
| 380 | ) |
| 381 | ); |
| 382 | |
| 383 | $this->end_controls_section(); |
| 384 | |
| 385 | /* Icon Section |
| 386 | /*-------------------------------------*/ |
| 387 | $this->start_controls_section( |
| 388 | 'button_section', |
| 389 | array( |
| 390 | 'label' => __( 'Button', 'auxin-elements' ), |
| 391 | 'tab' => Controls_Manager::TAB_STYLE, |
| 392 | 'conditions' => array( |
| 393 | 'relation' => 'and', |
| 394 | 'terms' => array( |
| 395 | array( |
| 396 | 'name' => 'type', |
| 397 | 'operator' => '===', |
| 398 | 'value' => 'form' |
| 399 | ), |
| 400 | array( |
| 401 | 'name' => 'submit_type', |
| 402 | 'operator' => '===', |
| 403 | 'value' => 'button' |
| 404 | ) |
| 405 | ) |
| 406 | ) |
| 407 | ) |
| 408 | ); |
| 409 | |
| 410 | $this->add_control( |
| 411 | 'button_color', |
| 412 | array( |
| 413 | 'label' => __('Background Color', 'auxin-elements'), |
| 414 | 'type' => Controls_Manager::COLOR, |
| 415 | 'default' => '#303030', |
| 416 | 'selectors' => array( |
| 417 | '{{WRAPPER}} .aux-search-form .aux-search-submit' => 'background-color: {{VALUE}}', |
| 418 | ) |
| 419 | ) |
| 420 | ); |
| 421 | |
| 422 | $this->add_responsive_control( |
| 423 | 'button_padding', |
| 424 | array( |
| 425 | 'label' => __( 'Padding', 'auxin-elements' ), |
| 426 | 'type' => Controls_Manager::DIMENSIONS, |
| 427 | 'size_units' => array( 'px', '%' ), |
| 428 | 'selectors' => array( |
| 429 | '{{WRAPPER}} .aux-search-form .aux-search-submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 430 | ) |
| 431 | ) |
| 432 | ); |
| 433 | |
| 434 | $this->add_responsive_control( |
| 435 | 'button_margin', |
| 436 | array( |
| 437 | 'label' => __( 'Margin', 'auxin-elements' ), |
| 438 | 'type' => Controls_Manager::DIMENSIONS, |
| 439 | 'size_units' => array( 'px', '%' ), |
| 440 | 'selectors' => array( |
| 441 | '{{WRAPPER}} .aux-search-form .aux-search-submit' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 442 | ) |
| 443 | ) |
| 444 | ); |
| 445 | |
| 446 | $this->add_group_control( |
| 447 | Group_Control_Typography::get_type(), |
| 448 | array( |
| 449 | 'name' => 'button_typgraphy', |
| 450 | 'global' => [ |
| 451 | 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, |
| 452 | ], |
| 453 | 'selector' => '{{WRAPPER}} .aux-search-form .aux-search-submit' |
| 454 | ) |
| 455 | ); |
| 456 | |
| 457 | $this->end_controls_section(); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Render image box widget output on the frontend. |
| 462 | * |
| 463 | * Written in PHP and used to generate the final HTML. |
| 464 | * |
| 465 | * @since 1.0.0 |
| 466 | * @access protected |
| 467 | */ |
| 468 | protected function render() { |
| 469 | $settings = $this->get_settings_for_display(); |
| 470 | |
| 471 | $args = []; |
| 472 | |
| 473 | $is_edit = \Elementor\Plugin::instance()->editor->is_edit_mode(); |
| 474 | $is_preview = isset( $_GET['preview'] ) && $_GET['preview'] ? true : false; |
| 475 | |
| 476 | if ( $is_edit || $is_preview ) { |
| 477 | auxin_add_hidden_blocks(); |
| 478 | } |
| 479 | |
| 480 | if ( 'icon' === $settings['type'] ) { |
| 481 | $args['has_form'] = false; |
| 482 | $args['is_ajax'] = false; |
| 483 | $args['toggle_icon_class'] = 'aux-overlay-search'; |
| 484 | |
| 485 | } else { |
| 486 | $args['has_toggle_icon'] = false; |
| 487 | $args['has_category'] = $settings['has_category']; |
| 488 | |
| 489 | switch( $settings['submit_type'] ) { |
| 490 | case 'none' : |
| 491 | $args['has_submit'] = false; |
| 492 | break; |
| 493 | case 'icon' : |
| 494 | $args['has_submit_icon'] = true; |
| 495 | break; |
| 496 | case 'button' : |
| 497 | $args['has_submit'] = true; |
| 498 | break; |
| 499 | default : |
| 500 | break; |
| 501 | } |
| 502 | |
| 503 | } |
| 504 | |
| 505 | $icon_value = ! empty( $settings['aux_search_icon']['value'] ) ? $settings['aux_search_icon'] : ( ! empty( $settings['icon'] ) ? $settings['icon'] : 'auxicon-search-4' ) ; |
| 506 | |
| 507 | $args['icon_classname'] = $icon_value; |
| 508 | $args['css_class'] = 'aux-search-elementor-element'; |
| 509 | |
| 510 | echo auxin_get_search_box( $args ); |
| 511 | } |
| 512 | |
| 513 | } |
| 514 |