| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | if ( ! defined( 'ABSPATH' ) ) { |
| 12: | exit; |
| 13: | } |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | class EPL_Elementor_Listing_Search extends \Elementor\Widget_Base { |
| 21: | use EPL_Elementor_Dynamic_Widget; |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function get_name() { |
| 30: | return 'epl-listing-search'; |
| 31: | } |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | public function get_title() { |
| 40: | return esc_html__( 'Listing Search', 'easy-property-listings' ); |
| 41: | } |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function get_icon() { |
| 50: | return 'eicon-form-vertical'; |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | public function get_categories() { |
| 60: | return array( 'epl-archive' ); |
| 61: | } |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | public function get_keywords() { |
| 70: | return array( 'listing', 'search', 'property', 'filter', 'epl' ); |
| 71: | } |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | protected function register_controls() { |
| 78: | |
| 79: | $this->start_controls_section( |
| 80: | 'section_content', |
| 81: | array( |
| 82: | 'label' => esc_html__( 'Search Form', 'easy-property-listings' ), |
| 83: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 84: | ) |
| 85: | ); |
| 86: | |
| 87: | |
| 88: | |
| 89: | foreach ( epl_search_widget_fields() as $field ) { |
| 90: | $this->register_search_control( $field ); |
| 91: | } |
| 92: | |
| 93: | $this->end_controls_section(); |
| 94: | |
| 95: | |
| 96: | $this->start_controls_section( |
| 97: | 'section_style', |
| 98: | array( |
| 99: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 100: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 101: | ) |
| 102: | ); |
| 103: | |
| 104: | $this->add_control( |
| 105: | 'button_color', |
| 106: | array( |
| 107: | 'label' => esc_html__( 'Button Color', 'easy-property-listings' ), |
| 108: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 109: | 'selectors' => array( |
| 110: | '{{WRAPPER}} .epl-search-btn' => 'background-color: {{VALUE}};', |
| 111: | ), |
| 112: | ) |
| 113: | ); |
| 114: | |
| 115: | $this->add_control( |
| 116: | 'button_text_color', |
| 117: | array( |
| 118: | 'label' => esc_html__( 'Button Text Color', 'easy-property-listings' ), |
| 119: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 120: | 'selectors' => array( |
| 121: | '{{WRAPPER}} .epl-search-btn' => 'color: {{VALUE}};', |
| 122: | ), |
| 123: | ) |
| 124: | ); |
| 125: | |
| 126: | $this->end_controls_section(); |
| 127: | } |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | protected function render() { |
| 134: | $settings = $this->get_settings_for_display(); |
| 135: | $atts = array(); |
| 136: | |
| 137: | foreach ( epl_search_widget_fields() as $field ) { |
| 138: | $key = $field['key']; |
| 139: | if ( array_key_exists( $key, $settings ) ) { |
| 140: | $atts[ $key ] = $settings[ $key ]; |
| 141: | } |
| 142: | } |
| 143: | |
| 144: | echo '<div class="epl-search-widget">'; |
| 145: | |
| 146: | if ( ! empty( $atts['title'] ) ) { |
| 147: | echo '<h3 class="epl-search-title">' . esc_html( $atts['title'] ) . '</h3>'; |
| 148: | } |
| 149: | |
| 150: | |
| 151: | |
| 152: | echo epl_shortcode_listing_search_callback( $atts ); |
| 153: | |
| 154: | echo '</div>'; |
| 155: | } |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | private function register_search_control( $field ) { |
| 164: | if ( empty( $field['key'] ) || empty( $field['type'] ) ) { |
| 165: | return; |
| 166: | } |
| 167: | |
| 168: | $key = sanitize_key( $field['key'] ); |
| 169: | $default = isset( $field['default'] ) ? $field['default'] : ''; |
| 170: | $args = array( |
| 171: | 'label' => isset( $field['label'] ) ? $field['label'] : $key, |
| 172: | 'default' => $default, |
| 173: | 'description' => isset( $field['help'] ) ? wp_strip_all_tags( $field['help'] ) : '', |
| 174: | ); |
| 175: | |
| 176: | switch ( $field['type'] ) { |
| 177: | case 'checkbox': |
| 178: | $args['type'] = \Elementor\Controls_Manager::SWITCHER; |
| 179: | $args['label_on'] = esc_html__( 'Yes', 'easy-property-listings' ); |
| 180: | $args['label_off'] = esc_html__( 'No', 'easy-property-listings' ); |
| 181: | $args['return_value'] = 'on'; |
| 182: | break; |
| 183: | |
| 184: | case 'select': |
| 185: | $args['type'] = ! empty( $field['multiple'] ) ? \Elementor\Controls_Manager::SELECT2 : \Elementor\Controls_Manager::SELECT; |
| 186: | $args['options'] = isset( $field['options'] ) ? $field['options'] : array(); |
| 187: | $args['multiple'] = ! empty( $field['multiple'] ); |
| 188: | $args['label_block'] = true; |
| 189: | break; |
| 190: | |
| 191: | case 'number': |
| 192: | $args['type'] = \Elementor\Controls_Manager::NUMBER; |
| 193: | break; |
| 194: | |
| 195: | case 'textarea': |
| 196: | $args['type'] = \Elementor\Controls_Manager::TEXTAREA; |
| 197: | break; |
| 198: | |
| 199: | case 'hidden': |
| 200: | $args['type'] = \Elementor\Controls_Manager::HIDDEN; |
| 201: | break; |
| 202: | |
| 203: | case 'text': |
| 204: | default: |
| 205: | $args['type'] = \Elementor\Controls_Manager::TEXT; |
| 206: | $args['label_block'] = true; |
| 207: | break; |
| 208: | } |
| 209: | |
| 210: | $this->add_control( $key, $args ); |
| 211: | } |
| 212: | } |
| 213: | |