| 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_Agent_Photo extends \Elementor\Widget_Base { |
| 23: | use EPL_Elementor_Dynamic_Widget; |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function get_name() { |
| 30: | return 'epl-agent-photo'; |
| 31: | } |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | public function get_title() { |
| 38: | return esc_html__( 'Photo', 'easy-property-listings' ); |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | public function get_icon() { |
| 46: | return 'eicon-image'; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function get_categories() { |
| 54: | return array( 'epl-staff', 'epl-author' ); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | public function get_keywords() { |
| 62: | return array( 'agent', 'photo', 'avatar', 'image', 'epl' ); |
| 63: | } |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | protected function register_controls() { |
| 70: | |
| 71: | $this->start_controls_section( |
| 72: | 'section_content', |
| 73: | array( |
| 74: | 'label' => esc_html__( 'Photo', 'easy-property-listings' ), |
| 75: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 76: | ) |
| 77: | ); |
| 78: | |
| 79: | $this->add_responsive_control( |
| 80: | 'photo_size', |
| 81: | array( |
| 82: | 'label' => esc_html__( 'Size', 'easy-property-listings' ), |
| 83: | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 84: | 'size_units' => array( 'px' ), |
| 85: | 'range' => array( |
| 86: | 'px' => array( |
| 87: | 'min' => 50, |
| 88: | 'max' => 400, |
| 89: | ), |
| 90: | ), |
| 91: | 'default' => array( |
| 92: | 'size' => 150, |
| 93: | 'unit' => 'px', |
| 94: | ), |
| 95: | 'selectors' => array( |
| 96: | '{{WRAPPER}} .epl-agent-photo img' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};', |
| 97: | ), |
| 98: | ) |
| 99: | ); |
| 100: | |
| 101: | $this->add_control( |
| 102: | 'link_to_author', |
| 103: | array( |
| 104: | 'label' => esc_html__( 'Link to Author Page', 'easy-property-listings' ), |
| 105: | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 106: | 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ), |
| 107: | 'label_off' => esc_html__( 'No', 'easy-property-listings' ), |
| 108: | 'return_value' => 'yes', |
| 109: | 'default' => '', |
| 110: | ) |
| 111: | ); |
| 112: | |
| 113: | $this->end_controls_section(); |
| 114: | |
| 115: | |
| 116: | $this->start_controls_section( |
| 117: | 'section_style', |
| 118: | array( |
| 119: | 'label' => esc_html__( 'Style', 'easy-property-listings' ), |
| 120: | 'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 121: | ) |
| 122: | ); |
| 123: | |
| 124: | $this->add_responsive_control( |
| 125: | 'border_radius', |
| 126: | array( |
| 127: | 'label' => esc_html__( 'Border Radius', 'easy-property-listings' ), |
| 128: | 'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 129: | 'size_units' => array( 'px', '%' ), |
| 130: | 'default' => array( |
| 131: | 'top' => '50', |
| 132: | 'right' => '50', |
| 133: | 'bottom' => '50', |
| 134: | 'left' => '50', |
| 135: | 'unit' => '%', |
| 136: | ), |
| 137: | 'selectors' => array( |
| 138: | '{{WRAPPER}} .epl-agent-photo img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 139: | ), |
| 140: | ) |
| 141: | ); |
| 142: | |
| 143: | $this->add_group_control( |
| 144: | \Elementor\Group_Control_Border::get_type(), |
| 145: | array( |
| 146: | 'name' => 'photo_border', |
| 147: | 'selector' => '{{WRAPPER}} .epl-agent-photo img', |
| 148: | ) |
| 149: | ); |
| 150: | |
| 151: | $this->add_group_control( |
| 152: | \Elementor\Group_Control_Box_Shadow::get_type(), |
| 153: | array( |
| 154: | 'name' => 'photo_shadow', |
| 155: | 'selector' => '{{WRAPPER}} .epl-agent-photo img', |
| 156: | ) |
| 157: | ); |
| 158: | |
| 159: | $this->end_controls_section(); |
| 160: | } |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | protected function render() { |
| 167: | $author = $this->get_current_agent(); |
| 168: | |
| 169: | if ( ! $author ) { |
| 170: | if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 171: | echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Agent Photo - No agent context.', 'easy-property-listings' ) . '</div>'; |
| 172: | } |
| 173: | return; |
| 174: | } |
| 175: | |
| 176: | $settings = $this->get_settings_for_display(); |
| 177: | $size = isset( $settings['photo_size']['size'] ) ? intval( $settings['photo_size']['size'] ) : 150; |
| 178: | $link = 'yes' === $settings['link_to_author']; |
| 179: | $permalink = apply_filters( 'epl_author_profile_link', get_author_posts_url( $author->author_id ), $author ); |
| 180: | |
| 181: | echo '<div class="epl-agent-photo">'; |
| 182: | |
| 183: | if ( $link ) { |
| 184: | echo '<a href="' . esc_url( $permalink ) . '">'; |
| 185: | } |
| 186: | |
| 187: | echo wp_kses_post( EPL_Elementor::get_agent_image( $author, $size ) ); |
| 188: | |
| 189: | if ( $link ) { |
| 190: | echo '</a>'; |
| 191: | } |
| 192: | |
| 193: | echo '</div>'; |
| 194: | } |
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | private function get_current_agent() { |
| 203: | global $epl_current_agent; |
| 204: | |
| 205: | |
| 206: | if ( ! empty( $epl_current_agent ) ) { |
| 207: | return $epl_current_agent; |
| 208: | } |
| 209: | |
| 210: | |
| 211: | $property = EPL_Elementor::setup_listing_context(); |
| 212: | |
| 213: | if ( $property ) { |
| 214: | $author = EPL_Elementor::get_listing_agent( $property ); |
| 215: | EPL_Elementor::restore_listing_context(); |
| 216: | return $author; |
| 217: | } |
| 218: | |
| 219: | EPL_Elementor::restore_listing_context(); |
| 220: | return null; |
| 221: | } |
| 222: | } |
| 223: | |