Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
saerdnaer committed Jun 6, 2021
1 parent 4e5256d commit ecd468d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/modules/contributors/settings/tab/contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, <br/> 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' => [
Expand Down
19 changes: 13 additions & 6 deletions lib/modules/social/rest_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down

0 comments on commit ecd468d

Please sign in to comment.