diff --git a/controllers/controllers.php b/controllers/controllers.php index a4baa0f..f9fad25 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -182,8 +182,11 @@ $app->get('/event', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); + $channels = $user->channels ? json_decode($user->channels, true) : []; + render('event', array( 'title' => 'Event', + 'channels' => $channels, 'authorizing' => false )); } @@ -362,6 +365,7 @@ $app->get('/settings', function() use($app) { 'title' => 'Settings', 'user' => $user, 'syndication_targets' => json_decode($user->syndication_targets, true), + 'channels' => json_decode($user->channels, true), 'authorizing' => false ]); } diff --git a/controllers/micropub.php b/controllers/micropub.php index 6eacd4a..cc1ca02 100644 --- a/controllers/micropub.php +++ b/controllers/micropub.php @@ -11,6 +11,17 @@ $app->get('/micropub/syndications', function() use($app) { } }); +$app->get('/micropub/channels', function() use($app) { + if($user=require_login($app)) { + $data = get_micropub_config($user, ['q'=>'config']); + $app->response()['Content-type'] = 'application/json'; + $app->response()->body(json_encode(array( + 'channels' => $data['channels'], + 'response' => $data['response'] + ))); + } +}); + $app->post('/micropub/post', function() use($app) { if($user=require_login($app)) { $params = $app->request()->params(); diff --git a/lib/helpers.php b/lib/helpers.php index 695ca27..48ada12 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -269,6 +269,7 @@ function parse_headers($headers) { function get_micropub_config(&$user, $query=[]) { $targets = []; + $channels = []; $r = micropub_get($user->micropub_endpoint, $query, $user->micropub_access_token); if($r['data'] && is_array($r['data']) && array_key_exists('syndicate-to', $r['data'])) { @@ -295,8 +296,13 @@ function get_micropub_config(&$user, $query=[]) { } } + if($r['data'] && is_array($r['data']) && array_key_exists('channels', $r['data']) && is_array($r['data']['channels'])) { + $channels = $r['data']['channels']; + } + // Reset the values so they can be overwritten $user->syndication_targets = ''; + $user->channels = ''; $user->supported_post_types = ''; $user->supported_visibility = ''; $user->micropub_media_endpoint = ''; @@ -304,6 +310,9 @@ function get_micropub_config(&$user, $query=[]) { if(count($targets)) $user->syndication_targets = json_encode($targets); + if(count($channels)) + $user->channels = json_encode($channels); + $media_endpoint = false; $supported_post_types = false; if($r['data'] && is_array($r['data'])) { @@ -325,6 +334,7 @@ function get_micropub_config(&$user, $query=[]) { return [ 'targets' => $targets, + 'channels' => $channels, 'response' => $r ]; } diff --git a/schema/migrations/0011.sql b/schema/migrations/0011.sql new file mode 100644 index 0000000..4b0ca61 --- /dev/null +++ b/schema/migrations/0011.sql @@ -0,0 +1,6 @@ +ALTER TABLE users +DROP COLUMN flightaware_username, +DROP COLUMN flightaware_apikey; + +ALTER TABLE users +ADD COLUMN `channels` TEXT AFTER syndication_targets; diff --git a/schema/mysql.sql b/schema/mysql.sql index 5a91e55..0a0accb 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -17,6 +17,7 @@ CREATE TABLE `users` ( `last_micropub_response_date` datetime DEFAULT NULL, `location_enabled` tinyint(4) NOT NULL DEFAULT '0', `syndication_targets` text, + `channels` text, `twitter_access_token` text, `twitter_token_secret` text, `twitter_username` varchar(255) DEFAULT NULL, diff --git a/schema/sqlite.sql b/schema/sqlite.sql index ca495cd..dd041b3 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -17,6 +17,7 @@ CREATE TABLE users ( last_micropub_response_date datetime, location_enabled INTEGER NOT NULL default 0, syndication_targets TEXT, + channels TEXT, twitter_access_token TEXT, twitter_token_secret TEXT, twitter_username TEXT, diff --git a/views/event.php b/views/event.php index 81742d8..c485f31 100644 --- a/views/event.php +++ b/views/event.php @@ -44,6 +44,24 @@ + channels): ?> +
Connecting a Twitter account will automatically "favorite" and "retweet" tweets on Twitter when you favorite and retweet a Twitter URL in Quill.
@@ -185,21 +209,6 @@ $(function(){ }); -function reload_syndications() { - $.getJSON("/micropub/syndications", function(data){ - if(data.targets) { - $("#syndication-container").html('