Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 595f045

Browse files
committed
Store location in WordPress Geodata
1 parent ada0a23 commit 595f045

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

includes/class-linkbacks-mf2-handler.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,32 @@ public static function generate_commentdata( $commentdata ) {
191191
$properties['syndication'] = $rels['syndication'];
192192
}
193193

194+
// Check and parse for location property
195+
if ( array_key_exists( 'location', $properties ) ) {
196+
$location = $properties['location'];
197+
if ( is_array( $location ) ) {
198+
if ( array_key_exists( 'latitude', $location ) ) {
199+
$commentdata['comment_meta']['geo_latitude'] = $location['latitude'];
200+
}
201+
if ( array_key_exists( 'longitude', $location ) ) {
202+
$commentdata['comment_meta']['geo_longitude'] = $location['longitude'];
203+
}
204+
if ( array_key_exists( 'name', $location ) ) {
205+
$commentdata['comment_meta']['geo_address'] = $location['name'];
206+
}
207+
} else {
208+
if ( substr( $location, 0, 4 ) == 'geo:' ) {
209+
$geo = explode( ':', substr( urldecode( $location ), 4 ) );
210+
$geo = explode( ';', $geo[0] );
211+
$coords = explode( ',', $geo[0] );
212+
$commentdata['comment_meta']['geo_latitude'] = trim( $coords[0] );
213+
$commentdata['comment_meta']['geo_longitude'] = trim( $coords[1] );
214+
} else {
215+
$commentdata['comment_meta']['geo_address'] = $location;
216+
}
217+
}
218+
}
219+
194220
// check rsvp property
195221
if ( isset( $properties['rsvp'] ) ) {
196222
$commentdata['comment_meta']['semantic_linkbacks_type'] = wp_slash( 'rsvp:' . $properties['rsvp'] );
@@ -223,7 +249,7 @@ public static function get_property( $key, $properties ) {
223249
}
224250
return null;
225251
}
226-
252+
227253
/**
228254
* Is string a URL.
229255
*

0 commit comments

Comments
 (0)