PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.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-map-reso.php

live-map-reso.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at includes/live/live-map-reso.php

73 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Live mode: raw RESO record -> the row/view-model shapes the render stack
4 * already consumes.
5 *
6 * The row mirrors a wp_mlsimport_listings flat row (same columns, built by the
7 * same reso-map via Mlsimport_Standalone_Row::build_columns()) so the card and
8 * grid code read live rows unchanged. _live carries the raw record so the card
9 * view and single-page VM can rebuild richer data without another fetch.
10 *
11 * @package Mlsimport
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 require_once dirname( __DIR__ ) . '/standalone/class-mlsimport-standalone-row.php';
19
20 /**
21 * Build a flat-table-shaped row object from a raw RESO record.
22 *
23 * @param array $record Raw RESO property (PascalCase fields, Media[] optional).
24 * @return object Row with the flat-table columns + listing_key, thumb, _live.
25 */
26 function mlsimport_live_row_from_reso( array $record ): object {
27 // Same reso-map the flat-table build uses, so live rows match stored rows.
28 $row = Mlsimport_Standalone_Row::build_columns( $record );
29
30 // Carry the ListingKey for permalinks/media lookups.
31 $row['listing_key'] = isset( $record['ListingKey'] ) ? (string) $record['ListingKey'] : '';
32
33 // First photo URL as the thumbnail (empty when the record has no media).
34 $urls = mlsimport_live_media_urls( $record );
35 $row['thumb'] = array() === $urls ? '' : $urls[0];
36 // Stash the raw record for the card/single rebuilds that need richer data.
37 $row['_live'] = $record;
38
39 // Hand back an object (the render stack reads rows as objects).
40 return (object) $row;
41 }
42
43 /**
44 * The record's public property-photo URLs, in delivered order — the same
45 * filter the import applies (MediaCategory Property Photo/Photo, non-empty
46 * MediaURL) but returning CDN URLs instead of sideloading.
47 *
48 * @param array $record Raw RESO property.
49 * @return string[] Photo URLs.
50 */
51 function mlsimport_live_media_urls( array $record ): array {
52 // No media collection at all: no URLs.
53 if ( empty( $record['Media'] ) || ! is_array( $record['Media'] ) ) {
54 return array();
55 }
56
57 $urls = array();
58 // Keep delivered order; filter to property photos with a real URL.
59 foreach ( $record['Media'] as $item ) {
60 // Skip malformed items and ones with no MediaURL.
61 if ( ! is_array( $item ) || empty( $item['MediaURL'] ) ) {
62 continue;
63 }
64 // When a category is present, keep only Property Photo / Photo.
65 if ( isset( $item['MediaCategory'] ) && ! in_array( $item['MediaCategory'], array( 'Property Photo', 'Photo' ), true ) ) {
66 continue;
67 }
68 $urls[] = (string) $item['MediaURL'];
69 }
70
71 return $urls;
72 }
73