Browse Source

add / to URL if it doesn't have a path

pull/39/head
Aaron Parecki 8 years ago
parent
commit
7075254d56
3 changed files with 17 additions and 7 deletions
  1. +1
    -3
      controllers/Parse.php
  2. +11
    -4
      lib/Formats/Mf2.php
  3. +5
    -0
      lib/helpers.php

+ 1
- 3
controllers/Parse.php View File

@ -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);

+ 11
- 4
lib/Formats/Mf2.php View File

@ -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;
}

+ 5
- 0
lib/helpers.php View File

@ -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;
}

Loading…
Cancel
Save