diff --git a/lib/Formats/Mf2.php b/lib/Formats/Mf2.php index 84e453a..73227d9 100644 --- a/lib/Formats/Mf2.php +++ b/lib/Formats/Mf2.php @@ -5,6 +5,12 @@ use HTMLPurifier, HTMLPurifier_Config; class Mf2 { + private static function _debug($msg) { + syslog(LOG_INFO, $msg); + if(array_key_exists('REMOTE_ADDR', $_SERVER)) + header("X-Parse-Debug: " . $msg); + } + public static function parse($mf2, $url, $http) { if(count($mf2['items']) == 0) return false; @@ -19,6 +25,7 @@ class Mf2 { $urls = $item['properties']['url']; $urls = array_map('\normalize_url', $urls); if(in_array($url, $urls)) { + self::_debug("1: Recognized $url as an h-entry because an h-entry on the page matched the URL of the request"); return self::parseAsHEntry($mf2, $item, $http, $url); } $lastSeenEntry = $item; @@ -29,12 +36,14 @@ class Mf2 { // If there was more than one h-entry on the page, treat the whole page as a feed if($hentrys > 1) { + self::_debug("2: Recognized $url as an h-feed because there are more than one h-entry on the page"); return self::parseAsHFeed($mf2, $http); } // If the first item is an h-feed, parse as a feed $first = $mf2['items'][0]; if(in_array('h-feed', $first['type'])) { + self::_debug("3: Recognized $url as an h-feed because the first item is an h-feed"); return self::parseAsHFeed($mf2, $http); } @@ -48,6 +57,7 @@ class Mf2 { 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 + self::_debug("4: Recognized $url as an h-card because an h-card on the page matched the URL of the request"); return self::parseAsHCard($item, $http, $url); } } @@ -59,6 +69,7 @@ class Mf2 { $urls = $lastSeenEntry['properties']['url']; $urls = array_map('\normalize_url', $urls); if(count($urls) && !in_array($url, $urls)) { + self::_debug("5: Recognized $url as an h-feed no h-entrys on the page matched the URL of the request"); return self::parseAsHFeed($mf2, $http); } } @@ -68,10 +79,13 @@ class Mf2 { foreach($mf2['items'] as $item) { // Otherwise check for an h-entry if(in_array('h-entry', $item['type']) || in_array('h-cite', $item['type'])) { + self::_debug("6: $url is falling back to the first h-entry on the page"); return self::parseAsHEntry($mf2, $item, $http); } } + self::_debug("E: No object at $url was recognized"); + return false; }