From 1dc3be5190290ee57ecf0e959cdbc6261495aa1d Mon Sep 17 00:00:00 2001 From: jackjamieson2 Date: Wed, 19 Jun 2019 15:55:31 -0400 Subject: [PATCH] Handle jsonfeeds where author information follows a format unexpected by Yarns. See #80 --- includes/class-yarns-microsub-parser.php | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/class-yarns-microsub-parser.php b/includes/class-yarns-microsub-parser.php index 588196f..5c9d7d2 100755 --- a/includes/class-yarns-microsub-parser.php +++ b/includes/class-yarns-microsub-parser.php @@ -118,6 +118,28 @@ public static function clean_post( $item, $feed ) { * @param array $feed_author */ public static function clean_author( $item, $feed ) { + + // Convert jsonfeed authors to an h-card. + // see https://github.com/jackjamieson2/yarns-microsub-server/issues/80 + if ('jsonfeed' === $feed['type'] && !isset($feed['author'])){ + if (isset($feed['name'])){ + $feed['author']['name'] = $feed['name']; + } + + if (isset($feed['url'])){ + $feed['author']['url'] = $feed['url']; + } + + if (isset($feed['photo'])){ + $feed['author']['photo'] = $feed['photo']; + } + + // Finally, if we were able to add any properties, make $feed['author'] an h-card + if (isset($feed['author'])){ + $feed['author']['type'] = 'card'; + } + } + // If author is just a string, replace it with an array // see https://github.com/jackjamieson2/yarns-microsub-server/issues/75 if (isset($item['author'])){ @@ -138,10 +160,10 @@ public static function clean_author( $item, $feed ) { } } - - if ( isset ( $feed['author'] ) && isset ( $item['author'] ) ) { $item['author'] = array_merge( $feed['author'], $item['author'] ); + } elseif ( isset( $feed['author']) && ! isset( $item['author'] ) ) { + $item['author'] = $feed['author']; } if ( ! isset($item['author'] ) ){