From ecd468d03f175c58ded7ec872fb4ed1347ca04f0 Mon Sep 17 00:00:00 2001 From: Andreas Hubel Date: Mon, 7 Jun 2021 00:46:06 +0200 Subject: [PATCH] chore: cleanup --- .../settings/tab/contributors.php | 2 +- lib/modules/social/rest_api.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/modules/contributors/settings/tab/contributors.php b/lib/modules/contributors/settings/tab/contributors.php index 28f602d20..375405c64 100644 --- a/lib/modules/contributors/settings/tab/contributors.php +++ b/lib/modules/contributors/settings/tab/contributors.php @@ -97,7 +97,7 @@ private function contributor_form($form_args, $contributor, $action) 'field_options' => [ 'label' => __('URI', 'podlove-podcasting-plugin-for-wordpress'), 'description' => __('A globally unique identifier to match contributors across podcasts on the internet,
e.g. URL of contributor’s personal home page or social media profile.', 'podlove-podcasting-plugin-for-wordpress'), - 'html' => ['class' => 'podlove-check-input podlove-contributor-field'], + 'html' => ['class' => 'podlove-check-input podlove-contributor-field', 'data-podlove-input-type' => 'url'], ], ], 'realname' => [ diff --git a/lib/modules/social/rest_api.php b/lib/modules/social/rest_api.php index c9998e25b..645b77504 100644 --- a/lib/modules/social/rest_api.php +++ b/lib/modules/social/rest_api.php @@ -111,32 +111,39 @@ public function lookup_person($request) switch ( $service ) { case 'gravatar.com': // $contributor needs to be either hash of email address or gravatar.com username - // if email, than create md5 hash + // if email, then create md5 hash if (strpos($contributor, '@')) { $contributor = md5($contributor); } $url = "https://$service/$contributor.json"; $clean = function ($x) { return $x->entry[0]; }; - break; + break; case 'json': $host = parse_url($contributor, PHP_URL_HOST) ?: parse_url('//' . $contributor, PHP_URL_HOST); $path = parse_url($contributor, PHP_URL_PATH); $url = "https://${host}${path}"; - break; + break; // TODO: OpenGraph? via library (e.g. https://github.com/shweshi/OpenGraph) or manual? default: $host = parse_url($contributor, PHP_URL_HOST) ?: parse_url('//' . $contributor, PHP_URL_HOST); $url = "https://$host/.well-known/webfinger?resource=" . urlencode($contributor); - break; + break; } try { $response = wp_remote_get($url, ['headers' => ['Accept' => 'application/json']]); + if (is_wp_error($response)) { + return new \WP_Error( + 'podlove_rest_contributor_lookup_error', + $response->get_error_message(), + ['status' => 400, 'url' => $url] + ); + } $result = $clean(json_decode($response['body'])); - if (is_wp_error($response) || $response['response']['code'] !== 200 || !$result) { + if ($response['response']['code'] !== 200 || !$result) { return new \WP_Error( 'podlove_rest_contributor_lookup_not_found', - $response['response']['message'] ?: $response->get_error_message(), + $response['response']['message'], ['status' => 404, 'url' => $url] ); }