| 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: | |
| 23: | class EPL_Elementor_Agent_Position extends \Elementor\Widget_Base { |
| 24: | use EPL_Elementor_Dynamic_Widget; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function get_name() { |
| 31: | return 'epl-agent-position'; |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function get_title() { |
| 39: | return esc_html__( 'Position', 'easy-property-listings' ); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | public function get_icon() { |
| 47: | return 'eicon-text'; |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | public function get_categories() { |
| 55: | return array( 'epl-staff', 'epl-author' ); |
| 56: | } |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | public function get_keywords() { |
| 63: | return array( 'agent', 'position', 'title', 'job', 'epl' ); |
| 64: | } |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | protected function register_controls() { |
| 71: | |
| 72: | |
| 73: | $this->start_controls_section( |
| 74: | 'section_style', |
| 75: | array( |
| 76: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 77: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 78: | ) |
| 79: | ); |
| 80: | |
| 81: | $this->add_control( |
| 82: | 'text_color', |
| 83: | array( |
| 84: | 'label' => esc_html__( 'Color', 'easy-property-listings' ), |
| 85: | 'type' => \Elementor\Controls_Manager::COLOR, |
| 86: | 'selectors' => array( |
| 87: | '{{WRAPPER}} .epl-agent-position' => 'color: {{VALUE}};', |
| 88: | ), |
| 89: | ) |
| 90: | ); |
| 91: | |
| 92: | $this->add_group_control( |
| 93: | \Elementor\Group_Control_Typography::get_type(), |
| 94: | array( |
| 95: | 'name' => 'typography', |
| 96: | 'selector' => '{{WRAPPER}} .epl-agent-position', |
| 97: | ) |
| 98: | ); |
| 99: | |
| 100: | $this->add_responsive_control( |
| 101: | 'text_align', |
| 102: | array( |
| 103: | 'label' => esc_html__( 'Alignment', 'easy-property-listings' ), |
| 104: | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 105: | 'options' => array( |
| 106: | 'left' => array( |
| 107: | 'title' => esc_html__( 'Left', 'easy-property-listings' ), |
| 108: | 'icon' => 'eicon-text-align-left', |
| 109: | ), |
| 110: | 'center' => array( |
| 111: | 'title' => esc_html__( 'Center', 'easy-property-listings' ), |
| 112: | 'icon' => 'eicon-text-align-center', |
| 113: | ), |
| 114: | 'right' => array( |
| 115: | 'title' => esc_html__( 'Right', 'easy-property-listings' ), |
| 116: | 'icon' => 'eicon-text-align-right', |
| 117: | ), |
| 118: | ), |
| 119: | 'selectors' => array( |
| 120: | '{{WRAPPER}} .epl-agent-position' => 'text-align: {{VALUE}};', |
| 121: | ), |
| 122: | ) |
| 123: | ); |
| 124: | |
| 125: | $this->end_controls_section(); |
| 126: | } |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | protected function render() { |
| 133: | $author = $this->get_current_agent(); |
| 134: | |
| 135: | if ( ! $author ) { |
| 136: | if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 137: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Position - No agent context.', 'easy-property-listings' ) . '</div>'; |
| 138: | } |
| 139: | return; |
| 140: | } |
| 141: | |
| 142: | $position = $author->get_author_position(); |
| 143: | |
| 144: | if ( empty( $position ) ) { |
| 145: | return; |
| 146: | } |
| 147: | |
| 148: | echo '<div class="epl-agent-position">' . esc_html( $position ) . '</div>'; |
| 149: | } |
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | private function get_current_agent() { |
| 158: | global $epl_current_agent; |
| 159: | |
| 160: | if ( ! empty( $epl_current_agent ) ) { |
| 161: | return $epl_current_agent; |
| 162: | } |
| 163: | |
| 164: | $property = EPL_Elementor::setup_listing_context(); |
| 165: | |
| 166: | if ( $property ) { |
| 167: | $author = EPL_Elementor::get_listing_agent( $property ); |
| 168: | EPL_Elementor::restore_listing_context(); |
| 169: | return $author; |
| 170: | } |
| 171: | |
| 172: | EPL_Elementor::restore_listing_context(); |
| 173: | return null; |
| 174: | } |
| 175: | } |
| 176: | |