From 7075254d5615ad9a8c451312a349c21965e48fa9 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 20 Feb 2016 17:42:20 -0800 Subject: [PATCH] add / to URL if it doesn't have a path --- controllers/Parse.php | 4 +--- lib/Formats/Mf2.php | 15 +++++++++++---- lib/helpers.php | 5 +++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/controllers/Parse.php b/controllers/Parse.php index 3871d50..6141a59 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -59,9 +59,7 @@ class Parse { ]); } - if(parse_url($url, PHP_URL_PATH) == '') { - $url = $url . '/'; - } + $url = \normalize_url($url); // Now fetch the URL and check for any curl errors $result = $this->http->get($url); diff --git a/lib/Formats/Mf2.php b/lib/Formats/Mf2.php index a839038..a001c25 100644 --- a/lib/Formats/Mf2.php +++ b/lib/Formats/Mf2.php @@ -15,11 +15,14 @@ class Mf2 { foreach($mf2['items'] as $i) { if(in_array('h-card', $i['type']) and array_key_exists('url', $i['properties']) - and in_array($url, $i['properties']['url']) ) { - // TODO: check for children h-entrys (like tantek.com), or sibling h-entries (like aaronparecki.com) - // and return the result as a feed instead - return self::parseHCard($i, $http, $url); + $urls = $i['properties']['url']; + $urls = array_map('\normalize_url', $urls); + if(in_array($url, $urls)) { + // TODO: check for children h-entrys (like tantek.com), or sibling h-entries (like aaronparecki.com) + // and return the result as a feed instead + return self::parseHCard($i, $http, $url); + } } } @@ -130,11 +133,15 @@ class Mf2 { foreach($properties as $p) { if($p == 'url' && $authorURL) { // If there is a matching author URL, use that one + $found = false; foreach($item['properties']['url'] as $url) { + $url = \normalize_url($url); if($url == $authorURL) { $data['url'] = $url; + $found = true; } } + if(!$found) $data['url'] = $item['properties']['url'][0]; } else if($v = self::getPlaintext($item, $p)) { $data[$p] = $v; } diff --git a/lib/helpers.php b/lib/helpers.php index c0c11f7..2982154 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -4,3 +4,8 @@ function view($template, $data=[]) { global $templates; return $templates->render($template, $data); } + +// Adds slash if no path is in the URL +function normalize_url($url) { + return parse_url($url, PHP_URL_PATH) == '' ? $url.'/' : $url; +}