diff --git a/controllers/controllers.php b/controllers/controllers.php index 9a49305..237c4bb 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -47,7 +47,8 @@ $app->get('/dashboard', function() use($app) { if($user=require_login($app)) { render('dashboard', array( 'title' => 'Dashboard', - 'authorizing' => false + 'authorizing' => false, + 'user' => $user, )); } }); 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', diff --git a/schema/migrations/0006.sql b/schema/migrations/0006.sql new file mode 100644 index 0000000..3ca725c --- /dev/null +++ b/schema/migrations/0006.sql @@ -0,0 +1,2 @@ +ALTER TABLE users +ADD COLUMN `supported_post_types` LONGTEXT; diff --git a/schema/mysql.sql b/schema/mysql.sql index 402218a..bbe0dd4 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -24,5 +24,6 @@ CREATE TABLE `users` ( `instagram_access_token` text, `email_username` varchar(255) DEFAULT NULL, `default_timezone` varchar(255) DEFAULT NULL, + `supported_post_types` longtext, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/sqlite.sql b/schema/sqlite.sql index 00e5f1c..948b3ef 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -23,5 +23,6 @@ CREATE TABLE users ( twitter_username TEXT, instagram_access_token TEXT, email_username TEXT, - default_timezone TEXT -); \ No newline at end of file + default_timezone TEXT, + supported_post_types TEXT, +); diff --git a/views/dashboard.php b/views/dashboard.php index adde977..7b8af63 100644 --- a/views/dashboard.php +++ b/views/dashboard.php @@ -3,14 +3,30 @@
@@ -27,4 +43,4 @@ float: left; margin-right: 12px; } - \ No newline at end of file + diff --git a/views/layout.php b/views/layout.php index 0850537..450d982 100644 --- a/views/layout.php +++ b/views/layout.php @@ -77,10 +77,18 @@
+ user, 'photo')): ?> + + +
diff --git a/views/settings.php b/views/settings.php index 6b69bc2..247aaf6 100644 --- a/views/settings.php +++ b/views/settings.php @@ -20,6 +20,21 @@ media endpoint user->micropub_media_endpoint ? ''.$this->user->micropub_media_endpoint.'' : 'no media endpoint' ?> + user->supported_post_types): ?> + + supported post types + + + + + access token user->micropub_access_token ?>