From f0c5635c2f072448808f35990b7f8abd84b9607d Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 29 Sep 2019 15:36:59 +0200 Subject: add a dropdown to choose post visibility --- controllers/controllers.php | 1 + controllers/micropub.php | 2 +- lib/helpers.php | 5 +++++ schema/migrations/0007.sql | 2 ++ schema/mysql.sql | 1 + schema/sqlite.sql | 3 ++- views/new-post.php | 30 +++++++++++++++++++++++++++++- 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 schema/migrations/0007.sql diff --git a/controllers/controllers.php b/controllers/controllers.php index 2cbe56e..bf1cb86 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -72,6 +72,7 @@ $app->get('/new', function() use($app) { 'micropub_access_token' => $user->micropub_access_token, 'response_date' => $user->last_micropub_response_date, 'syndication_targets' => json_decode($user->syndication_targets, true), + 'supported_visibility' => json_decode($user->supported_visibility, true), 'location_enabled' => $user->location_enabled, 'user' => $user, 'authorizing' => false diff --git a/controllers/micropub.php b/controllers/micropub.php index a6ec9d5..fa8e477 100644 --- a/controllers/micropub.php +++ b/controllers/micropub.php @@ -2,7 +2,7 @@ $app->get('/micropub/syndications', function() use($app) { if($user=require_login($app)) { - $data = get_micropub_config($user, ['q'=>'syndicate-to']); + $data = get_micropub_config($user); $app->response()['Content-type'] = 'application/json'; $app->response()->body(json_encode(array( 'targets' => $data['targets'], diff --git a/lib/helpers.php b/lib/helpers.php index 7dca36d..57e3374 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -298,6 +298,7 @@ function get_micropub_config(&$user, $query=[]) { // Reset the values so they can be overwritten $user->syndication_targets = ''; $user->supported_post_types = ''; + $user->supported_visibility = ''; $user->micropub_media_endpoint = ''; if(count($targets)) @@ -316,6 +317,10 @@ function get_micropub_config(&$user, $query=[]) { } } + if(isset($r['data']['visibility']) && is_array($r['data']['visibility'])) { + $user->supported_visibility = json_encode($r['data']['visibility']); + } + $user->save(); return [ diff --git a/schema/migrations/0007.sql b/schema/migrations/0007.sql new file mode 100644 index 0000000..2d51a15 --- /dev/null +++ b/schema/migrations/0007.sql @@ -0,0 +1,2 @@ +ALTER TABLE users +ADD COLUMN `supported_visibility` LONGTEXT; diff --git a/schema/mysql.sql b/schema/mysql.sql index bbe0dd4..1007256 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -25,5 +25,6 @@ CREATE TABLE `users` ( `email_username` varchar(255) DEFAULT NULL, `default_timezone` varchar(255) DEFAULT NULL, `supported_post_types` longtext, + `supported_visibility` longtext, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/schema/sqlite.sql b/schema/sqlite.sql index 8eaa7b0..37365cd 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -24,5 +24,6 @@ CREATE TABLE users ( instagram_access_token TEXT, email_username TEXT, default_timezone TEXT, - supported_post_types TEXT + supported_post_types TEXT, + supported_visibility TEXT ); diff --git a/views/new-post.php b/views/new-post.php index aba4129..dad9427 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -79,8 +79,23 @@ + supported_visibility): ?> +
+ + +
+ + syndication_targets): ?> -
+