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