PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.2.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.2.1
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / includes / live / live-card.php

live-card.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.2.1, at includes/live/live-card.php

56 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Live mode: rebuild the card view model from the live row.
4 *
5 * The mlsimport_card_view() helper derives address/permalink/thumbnail from post meta and
6 * attachments — all empty on a synthetic negative-ID post. The card-view filter
7 * fires last with the row in hand, so this one callback re-derives those pieces
8 * from the raw record in $row->_live. Scalars (price, specs, status) already
9 * come from the row and need no help.
10 *
11 * @package Mlsimport
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Fill the card view from the raw RESO record carried by a live row.
20 *
21 * Keys on the row carrying _live rather than the gate: a payload built while
22 * live mode was on should render correctly even if rendering happens later.
23 *
24 * @param array $view The view model mlsimport_card_view() built.
25 * @param WP_Post $post The (synthetic) listing post.
26 * @param object|null $row The live row.
27 * @return array
28 */
29 function mlsimport_live_card_view( array $view, $post, $row ): array {
30 // Not a live row (no raw record attached): leave the stored-mode view as-is.
31 if ( ! is_object( $row ) || empty( $row->_live ) || ! is_array( $row->_live ) ) {
32 return $view;
33 }
34 $record = $row->_live;
35
36 // Address: the raw record's UnparsedAddress, if present and non-blank.
37 $address = isset( $record['UnparsedAddress'] ) ? trim( (string) $record['UnparsedAddress'] ) : '';
38 if ( '' !== $address ) {
39 $view['address'] = $address;
40 }
41
42 // Permalink points at the virtual single-listing URL keyed by ListingKey;
43 // office name comes straight off the record.
44 $view['permalink'] = mlsimport_live_url( isset( $row->listing_key ) ? (string) $row->listing_key : '' );
45 $view['office'] = isset( $record['ListOfficeName'] ) ? trim( (string) $record['ListOfficeName'] ) : '';
46
47 // Thumbnail: the first media URL the row resolved; has_thumb flags whether
48 // the card should render an image at all.
49 $thumb = isset( $row->thumb ) ? (string) $row->thumb : '';
50 $view['thumb'] = $thumb;
51 $view['has_thumb'] = '' !== $thumb;
52
53 return $view;
54 }
55 add_filter( 'mlsimport_card_view', 'mlsimport_live_card_view', 10, 3 );
56