| 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: | |
| 24: | |
| 25: | |
| 26: | class EPL_Elementor_Listing_Results extends \Elementor\Widget_Base { |
| 27: | use EPL_Elementor_Dynamic_Widget; |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public function get_name() { |
| 36: | return 'epl-listing-results'; |
| 37: | } |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function get_title() { |
| 50: | return esc_html__( 'Listings Results', 'easy-property-listings' ); |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | public function get_icon() { |
| 60: | return 'eicon-archive-title'; |
| 61: | } |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | public function get_categories() { |
| 70: | return array( 'epl-archive' ); |
| 71: | } |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | public function get_keywords() { |
| 80: | return array( 'listing', 'results', 'archive', 'query', 'loop', 'property', 'epl' ); |
| 81: | } |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | protected function register_controls() { |
| 88: | $this->start_controls_section( |
| 89: | 'section_content', |
| 90: | array( |
| 91: | 'label' => esc_html__( 'Listing Results', 'easy-property-listings' ), |
| 92: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 93: | ) |
| 94: | ); |
| 95: | |
| 96: | $this->add_control( |
| 97: | 'results_notice', |
| 98: | array( |
| 99: | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 100: | 'raw' => esc_html__( 'Shows the archive, search or location listings. Use it on your Listings Archive Page.', 'easy-property-listings' ), |
| 101: | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 102: | ) |
| 103: | ); |
| 104: | |
| 105: | $this->add_control( |
| 106: | 'card_template_id', |
| 107: | array( |
| 108: | 'label' => esc_html__( 'Listing Card', 'easy-property-listings' ), |
| 109: | 'type' => \Elementor\Controls_Manager::SELECT2, |
| 110: | 'label_block' => true, |
| 111: | 'options' => $this->get_card_template_options(), |
| 112: | 'default' => (string) EPL_Elementor_Template_Seeder::get_default_card_id(), |
| 113: | 'description' => esc_html__( 'The card design for this page. Edit cards in Elementor > Templates.', 'easy-property-listings' ), |
| 114: | ) |
| 115: | ); |
| 116: | |
| 117: | $this->add_control( |
| 118: | 'tools_top', |
| 119: | array( |
| 120: | 'label' => esc_html__( 'Show Tools Above Results', 'easy-property-listings' ), |
| 121: | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 122: | 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ), |
| 123: | 'label_off' => esc_html__( 'No', 'easy-property-listings' ), |
| 124: | 'return_value' => 'yes', |
| 125: | 'default' => '', |
| 126: | 'description' => esc_html__( 'Sorter and grid/list view toggle.', 'easy-property-listings' ), |
| 127: | ) |
| 128: | ); |
| 129: | |
| 130: | $this->add_control( |
| 131: | 'tools_bottom', |
| 132: | array( |
| 133: | 'label' => esc_html__( 'Show Tools Below Results', 'easy-property-listings' ), |
| 134: | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 135: | 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ), |
| 136: | 'label_off' => esc_html__( 'No', 'easy-property-listings' ), |
| 137: | 'return_value' => 'yes', |
| 138: | 'default' => '', |
| 139: | ) |
| 140: | ); |
| 141: | |
| 142: | $this->add_control( |
| 143: | 'pagination', |
| 144: | array( |
| 145: | 'label' => esc_html__( 'Show Pagination', 'easy-property-listings' ), |
| 146: | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 147: | 'label_on' => esc_html__( 'Yes', 'easy-property-listings' ), |
| 148: | 'label_off' => esc_html__( 'No', 'easy-property-listings' ), |
| 149: | 'return_value' => 'yes', |
| 150: | 'default' => 'yes', |
| 151: | ) |
| 152: | ); |
| 153: | |
| 154: | $this->end_controls_section(); |
| 155: | |
| 156: | $this->start_controls_section( |
| 157: | 'section_layout', |
| 158: | array( |
| 159: | 'label' => esc_html__( 'Grid Layout', 'easy-property-listings' ), |
| 160: | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 161: | ) |
| 162: | ); |
| 163: | |
| 164: | $this->add_control( |
| 165: | 'grid_mode', |
| 166: | array( |
| 167: | 'label' => esc_html__( 'Layout', 'easy-property-listings' ), |
| 168: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 169: | 'default' => 'columns', |
| 170: | 'options' => array( |
| 171: | 'columns' => esc_html__( 'Fixed Columns', 'easy-property-listings' ), |
| 172: | 'auto' => esc_html__( 'Auto-Fit by Card Width', 'easy-property-listings' ), |
| 173: | ), |
| 174: | 'selectors' => array( |
| 175: | '{{WRAPPER}} .epl-template-blog' => 'display: grid;', |
| 176: | '{{WRAPPER}} .epl-template-blog > *' => 'min-width: 0; box-sizing: border-box;', |
| 177: | ), |
| 178: | ) |
| 179: | ); |
| 180: | |
| 181: | $this->add_responsive_control( |
| 182: | 'grid_columns', |
| 183: | array( |
| 184: | 'label' => esc_html__( 'Columns', 'easy-property-listings' ), |
| 185: | 'type' => \Elementor\Controls_Manager::SELECT, |
| 186: | 'default' => '3', |
| 187: | 'tablet_default' => '2', |
| 188: | 'mobile_default' => '1', |
| 189: | 'options' => array( |
| 190: | '1' => '1', |
| 191: | '2' => '2', |
| 192: | '3' => '3', |
| 193: | '4' => '4', |
| 194: | '5' => '5', |
| 195: | '6' => '6', |
| 196: | ), |
| 197: | 'condition' => array( 'grid_mode' => 'columns' ), |
| 198: | 'selectors' => array( |
| 199: | '{{WRAPPER}} .epl-template-blog' => 'grid-template-columns: repeat({{VALUE}}, minmax(0, 1fr));', |
| 200: | ), |
| 201: | ) |
| 202: | ); |
| 203: | |
| 204: | $this->add_responsive_control( |
| 205: | 'card_min_width', |
| 206: | array( |
| 207: | 'label' => esc_html__( 'Minimum Card Width', 'easy-property-listings' ), |
| 208: | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 209: | 'size_units' => array( 'px' ), |
| 210: | 'range' => array( |
| 211: | 'px' => array( |
| 212: | 'min' => 150, |
| 213: | 'max' => 600, |
| 214: | ), |
| 215: | ), |
| 216: | 'default' => array( |
| 217: | 'size' => 280, |
| 218: | 'unit' => 'px', |
| 219: | ), |
| 220: | 'condition' => array( 'grid_mode' => 'auto' ), |
| 221: | 'selectors' => array( |
| 222: | '{{WRAPPER}} .epl-template-blog' => 'grid-template-columns: repeat(auto-fill, minmax({{SIZE}}{{UNIT}}, 1fr));', |
| 223: | ), |
| 224: | ) |
| 225: | ); |
| 226: | |
| 227: | $this->add_responsive_control( |
| 228: | 'grid_gap', |
| 229: | array( |
| 230: | 'label' => esc_html__( 'Gap', 'easy-property-listings' ), |
| 231: | 'type' => \Elementor\Controls_Manager::GAPS, |
| 232: | 'size_units' => array( 'px', '%', 'em' ), |
| 233: | 'default' => array( |
| 234: | 'row' => '32', |
| 235: | 'column' => '24', |
| 236: | 'unit' => 'px', |
| 237: | 'isLinked' => false, |
| 238: | ), |
| 239: | 'selectors' => array( |
| 240: | '{{WRAPPER}} .epl-template-blog' => 'gap: {{ROW}}{{UNIT}} {{COLUMN}}{{UNIT}};', |
| 241: | ), |
| 242: | ) |
| 243: | ); |
| 244: | |
| 245: | $this->end_controls_section(); |
| 246: | } |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | |
| 252: | |
| 253: | |
| 254: | |
| 255: | private function get_card_template_options() { |
| 256: | $options = array( |
| 257: | '' => esc_html__( 'EPL Built-in Card', 'easy-property-listings' ), |
| 258: | ); |
| 259: | |
| 260: | $cards = get_posts( |
| 261: | array( |
| 262: | 'post_type' => 'elementor_library', |
| 263: | 'post_status' => 'publish', |
| 264: | 'posts_per_page' => -1, |
| 265: | 'orderby' => 'title', |
| 266: | 'order' => 'ASC', |
| 267: | 'meta_key' => '_elementor_template_type', |
| 268: | 'meta_value' => EPL_Elementor_Loop_Card_Document::TYPE, |
| 269: | ) |
| 270: | ); |
| 271: | |
| 272: | $bundled_default = EPL_Elementor_Template_Seeder::get_default_card_id(); |
| 273: | |
| 274: | foreach ( $cards as $card ) { |
| 275: | $options[ $card->ID ] = ( $card->ID === $bundled_default ) |
| 276: | |
| 277: | ? sprintf( esc_html__( '%s (Default)', 'easy-property-listings' ), $card->post_title ) |
| 278: | : $card->post_title; |
| 279: | } |
| 280: | |
| 281: | return $options; |
| 282: | } |
| 283: | |
| 284: | |
| 285: | |
| 286: | |
| 287: | |
| 288: | protected function render() { |
| 289: | if ( EPL_Elementor::is_editor() ) { |
| 290: | $this->render_editor_preview(); |
| 291: | return; |
| 292: | } |
| 293: | |
| 294: | $settings = $this->get_settings_for_display(); |
| 295: | $atts = array( |
| 296: | 'tools_top' => ! empty( $settings['tools_top'] ) ? 'on' : 'off', |
| 297: | 'tools_bottom' => ! empty( $settings['tools_bottom'] ) ? 'on' : 'off', |
| 298: | 'pagination' => ! empty( $settings['pagination'] ) ? 'on' : 'off', |
| 299: | ); |
| 300: | |
| 301: | $card_override = ! empty( $settings['card_template_id'] ) ? absint( $settings['card_template_id'] ) : 0; |
| 302: | if ( $card_override ) { |
| 303: | EPL_Elementor_Template_Router::begin_card_override( $card_override ); |
| 304: | } |
| 305: | |
| 306: | echo epl_listing_results_loop_callback( $atts ); |
| 307: | |
| 308: | if ( $card_override ) { |
| 309: | EPL_Elementor_Template_Router::end_card_override(); |
| 310: | } |
| 311: | } |
| 312: | |
| 313: | |
| 314: | |
| 315: | |
| 316: | |
| 317: | |
| 318: | private function render_editor_preview() { |
| 319: | echo '<div class="epl-elementor-listing-results-preview">'; |
| 320: | echo '<p class="epl-elementor-editor-notice">' . esc_html__( 'Preview only — shows the real archive, search or taxonomy results on the front end.', 'easy-property-listings' ) . '</p>'; |
| 321: | |
| 322: | $sample_posts = get_posts( |
| 323: | array( |
| 324: | 'post_type' => array_keys( epl_get_active_post_types() ), |
| 325: | 'post_status' => 'publish', |
| 326: | 'posts_per_page' => 6, |
| 327: | ) |
| 328: | ); |
| 329: | |
| 330: | if ( empty( $sample_posts ) ) { |
| 331: | echo '<p>' . esc_html__( 'No published listings found to preview.', 'easy-property-listings' ) . '</p>'; |
| 332: | echo '</div>'; |
| 333: | return; |
| 334: | } |
| 335: | |
| 336: | $settings = $this->get_settings_for_display(); |
| 337: | $card_override = ! empty( $settings['card_template_id'] ) ? absint( $settings['card_template_id'] ) : 0; |
| 338: | if ( $card_override ) { |
| 339: | EPL_Elementor_Template_Router::begin_card_override( $card_override ); |
| 340: | } |
| 341: | |
| 342: | global $post, $property; |
| 343: | $original_post = $post; |
| 344: | $original_property = isset( $property ) ? $property : null; |
| 345: | |
| 346: | echo '<div class="epl-template-blog">'; |
| 347: | foreach ( $sample_posts as $sample_post ) { |
| 348: | $post = $sample_post; |
| 349: | $property = new EPL_Property_Meta( $sample_post ); |
| 350: | setup_postdata( $post ); |
| 351: | do_action( 'epl_property_blog' ); |
| 352: | } |
| 353: | echo '</div>'; |
| 354: | |
| 355: | if ( $card_override ) { |
| 356: | EPL_Elementor_Template_Router::end_card_override(); |
| 357: | } |
| 358: | |
| 359: | $post = $original_post; |
| 360: | $property = $original_property; |
| 361: | if ( $post instanceof WP_Post ) { |
| 362: | setup_postdata( $post ); |
| 363: | } else { |
| 364: | wp_reset_postdata(); |
| 365: | } |
| 366: | |
| 367: | echo '</div>'; |
| 368: | } |
| 369: | } |
| 370: | |