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