From af3d6a0ae373d8046f459a564f94867a865b7dd0 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 8 Sep 2019 23:18:17 +0300 Subject: [PATCH 1/4] Hack in h-geo support This adds h-geo microformat support. It's clunky but it should work. I'm no PHP gal so I hope you have CI or something that would test it. Test case: [this post by me](https://fireburn.ru/posts/1567956895) that should contain a checkin with h-geo embedded. Should be parsed with latitude and longitude, showing a map in applications like Monocle. --- lib/XRay/Formats/Mf2.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index 2d15acf..21f81f9 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -340,6 +340,11 @@ class Mf2 extends Format { $hcard[$p] = $v; } } + // If we have a geo property, it overrides p-latitude and p-longitude + if(array_key_exists($mf2, 'geo') && in_array('h-geo', $mf2['geo']['type']) { + $hcard['latitude'] = $mf2['geo']['latitude'][0]; + $hcard['longitude'] = $mf2['geo']['longitude'][0]; + } return $hcard; } } From 1cf87906e484b8957689bb0efca2c80f1238f57f Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 8 Sep 2019 23:34:25 +0300 Subject: [PATCH 2/4] Forgot a ) I'm not a PHP coder, I'm just a dummy :c --- lib/XRay/Formats/Mf2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index 21f81f9..b6eb661 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -341,7 +341,7 @@ class Mf2 extends Format { } } // If we have a geo property, it overrides p-latitude and p-longitude - if(array_key_exists($mf2, 'geo') && in_array('h-geo', $mf2['geo']['type']) { + if(array_key_exists($mf2, 'geo') && in_array('h-geo', $mf2['geo']['type'])) { $hcard['latitude'] = $mf2['geo']['latitude'][0]; $hcard['longitude'] = $mf2['geo']['longitude'][0]; } From 27580eec293abb5ec3a76d59074bbb1435185a80 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 8 Sep 2019 23:39:28 +0300 Subject: [PATCH 3/4] Fixed in_array arg order --- lib/XRay/Formats/Mf2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index b6eb661..c2c89f5 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -341,7 +341,7 @@ class Mf2 extends Format { } } // If we have a geo property, it overrides p-latitude and p-longitude - if(array_key_exists($mf2, 'geo') && in_array('h-geo', $mf2['geo']['type'])) { + 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]; } From 611696099fbb5b44552493e310466c7bb9d5385f Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 16 Sep 2019 01:27:06 +0300 Subject: [PATCH 4/4] 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; }