| 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: | |
| 21: | |
| 22: | class EPL_Elementor_Property_Heading extends \Elementor\Widget_Base { |
| 23: | use EPL_Elementor_Dynamic_Widget; |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | public function get_name() { |
| 32: | return 'epl-property-heading'; |
| 33: | } |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public function get_title() { |
| 42: | return esc_html__( 'Heading', 'easy-property-listings' ); |
| 43: | } |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | public function get_icon() { |
| 52: | return 'eicon-heading'; |
| 53: | } |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | public function get_categories() { |
| 62: | return array( 'epl-elements' ); |
| 63: | } |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | public function get_keywords() { |
| 72: | return array( 'property', 'heading', 'headline', 'epl' ); |
| 73: | } |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | protected function register_controls() { |
| 80: | |
| 81: | $this->start_controls_section( |
| 82: | 'section_content', |
| 83: | array( |
| 84: | 'label' => esc_html__( 'Content', 'easy-property-listings' ), |
| 85: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 86: | ) |
| 87: | ); |
| 88: | |
| 89: | $this->add_control( |
| 90: | 'html_tag', |
| 91: | array( |
| 92: | 'label' => esc_html__( 'HTML Tag', 'easy-property-listings' ), |
| 93: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 94: | 'options' => array( |
| 95: | 'h1' => 'H1', |
| 96: | 'h2' => 'H2', |
| 97: | 'h3' => 'H3', |
| 98: | 'h4' => 'H4', |
| 99: | 'h5' => 'H5', |
| 100: | 'h6' => 'H6', |
| 101: | 'div' => 'div', |
| 102: | 'span' => 'span', |
| 103: | 'p' => 'p', |
| 104: | ), |
| 105: | 'default' => 'h3', |
| 106: | ) |
| 107: | ); |
| 108: | |
| 109: | $this->end_controls_section(); |
| 110: | |
| 111: | |
| 112: | $this->start_controls_section( |
| 113: | 'section_style', |
| 114: | array( |
| 115: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 116: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 117: | ) |
| 118: | ); |
| 119: | |
| 120: | $this->add_control( |
| 121: | 'text_color', |
| 122: | array( |
| 123: | 'label' => esc_html__( 'Color', 'easy-property-listings' ), |
| 124: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 125: | 'selectors' => array( |
| 126: | '{{WRAPPER}} .epl-property-heading' => 'color: {{VALUE}};', |
| 127: | ), |
| 128: | ) |
| 129: | ); |
| 130: | |
| 131: | $this->add_group_control( |
| 132: | \Elementor\Group_Control_Typography::get_type(), |
| 133: | array( |
| 134: | 'name' => 'typography', |
| 135: | 'selector' => '{{WRAPPER}} .epl-property-heading', |
| 136: | ) |
| 137: | ); |
| 138: | |
| 139: | $this->add_responsive_control( |
| 140: | 'text_align', |
| 141: | array( |
| 142: | 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), |
| 143: | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 144: | 'options' => array( |
| 145: | 'left' => array( |
| 146: | 'title' => esc_html__( 'Left', 'easy-property-listings' ), |
| 147: | 'icon' => 'eicon-text-align-left', |
| 148: | ), |
| 149: | 'center' => array( |
| 150: | 'title' => esc_html__( 'Center', 'easy-property-listings' ), |
| 151: | 'icon' => 'eicon-text-align-center', |
| 152: | ), |
| 153: | 'right' => array( |
| 154: | 'title' => esc_html__( 'Right', 'easy-property-listings' ), |
| 155: | 'icon' => 'eicon-text-align-right', |
| 156: | ), |
| 157: | ), |
| 158: | 'selectors' => array( |
| 159: | '{{WRAPPER}} .epl-property-heading' => 'text-align: {{VALUE}};', |
| 160: | ), |
| 161: | ) |
| 162: | ); |
| 163: | |
| 164: | $this->end_controls_section(); |
| 165: | } |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | protected function render() { |
| 172: | $property = EPL_Elementor::setup_listing_context(); |
| 173: | $is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode(); |
| 174: | |
| 175: | if ( ! $property ) { |
| 176: | if ( $is_editor ) { |
| 177: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Property Heading - No listings found.', 'easy-property-listings' ) . '</div>'; |
| 178: | } |
| 179: | EPL_Elementor::restore_listing_context(); |
| 180: | return; |
| 181: | } |
| 182: | |
| 183: | $settings = $this->get_settings_for_display(); |
| 184: | $tag = \Elementor\Utils::validate_html_tag( $settings['html_tag'] ); |
| 185: | $heading = $property->get_property_meta( 'property_heading' ); |
| 186: | |
| 187: | |
| 188: | if ( empty( $heading ) ) { |
| 189: | $heading = get_the_title( $property->post->ID ); |
| 190: | } |
| 191: | |
| 192: | if ( empty( $heading ) ) { |
| 193: | EPL_Elementor::restore_listing_context(); |
| 194: | return; |
| 195: | } |
| 196: | |
| 197: | echo '<' . esc_attr( $tag ) . ' class="epl-property-heading">'; |
| 198: | echo esc_html( $heading ); |
| 199: | echo '</' . esc_attr( $tag ) . '>'; |
| 200: | |
| 201: | EPL_Elementor::restore_listing_context(); |
| 202: | } |
| 203: | } |
| 204: | |