diff options
author | Aaron Parecki <aaron@parecki.com> | 2018-07-20 17:59:18 -0500 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2018-07-20 17:59:18 -0500 |
commit | b749bc6c124a02a6949dc67ea703d880e1acd2ac (patch) | |
tree | e6695ac1a3a2cb59977d77434179908295e93029 /lib/helpers.php | |
parent | 33796f7bd5def85a5753cc3b4430769379b60475 (diff) |
disable post type buttons if the server doesn't support them
Diffstat (limited to 'lib/helpers.php')
-rw-r--r-- | lib/helpers.php | 32 |
1 files changed, 28 insertions, 4 deletions
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', |