From b749bc6c124a02a6949dc67ea703d880e1acd2ac Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 20 Jul 2018 17:59:18 -0500 Subject: disable post type buttons if the server doesn't support them --- lib/helpers.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'lib/helpers.php') diff --git a/lib/helpers.php b/lib/helpers.php index bfcdf63..d714c23 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -288,12 +288,19 @@ function get_micropub_config(&$user, $query=[]) { $user->syndication_targets = json_encode($targets); $media_endpoint = false; - if($r['data'] && is_array($r['data']) && array_key_exists('media-endpoint', $r['data'])) { - $media_endpoint = $r['data']['media-endpoint']; - $user->micropub_media_endpoint = $media_endpoint; + $supported_post_types = false; + if($r['data'] && is_array($r['data'])) { + if(isset($r['data']['media-endpoint'])) { + $media_endpoint = $r['data']['media-endpoint']; + $user->micropub_media_endpoint = $media_endpoint; + } + if(isset($r['data']['post-types'])) { + $supported_post_types = json_encode($r['data']['post-types']); + $user->supported_post_types = $supported_post_types; + } } - if(count($targets) || $media_endpoint) { + if(count($targets) || $media_endpoint || $supported_post_types) { $user->save(); } @@ -303,6 +310,23 @@ function get_micropub_config(&$user, $query=[]) { ]; } +function supports_post_type(&$user, $type) { + if(!$user->supported_post_types) + return true; + + $types = json_decode($user->supported_post_types, true); + if(!is_array($types)) + return true; // syntax error in response, fail safely + + foreach($types as $t) { + if(is_array($t) && isset($t['type']) && $t['type'] == $type) { + return true; + } + } + + return false; +} + function get_micropub_source(&$user, $url, $properties) { $r = micropub_get($user->micropub_endpoint, [ 'q' => 'source', -- cgit v1.2.3