From 611696099fbb5b44552493e310466c7bb9d5385f Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 16 Sep 2019 01:27:06 +0300 Subject: [PATCH] Add more checks on h-geo Now it checks that: 1. h-geo exists 2. it's a microformat 3. it's of type "h-geo" 4. that it has properties 5. that it has latitude 6. that it has longitude If all checks are true, lat and lon get replaced with values of h-geo object. --- lib/XRay/Formats/Mf2.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index c2c89f5..8c02259 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -341,9 +341,14 @@ class Mf2 extends Format { } } // If we have a geo property, it overrides p-latitude and p-longitude - if(array_key_exists('geo', $mf2) && in_array('h-geo', $mf2['geo']['type'])) { - $hcard['latitude'] = $mf2['geo']['latitude'][0]; - $hcard['longitude'] = $mf2['geo']['longitude'][0]; + if(array_key_exists('geo', $mf2) && + self::isMicroformat($mf2['geo'][0]) && + in_array('h-geo', $mf2['geo'][0]['type']) && + array_key_exists($mf2['geo'][0]['properties']) && + $lat=self::getPlaintext($mf2['geo'][0], 'latitude') && + $lon=self::getPlaintext($mf2['geo'][0], 'longitude')) { + $hcard['latitude'] = $lat; + $hcard['longitude'] = $lon; } return $hcard; }