From e8c847579cddc1325dafd0ea2e4acf95f0e00b9d Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 16 Dec 2016 11:49:15 +0000 Subject: [PATCH] Squashed commit of the following: commit d0c1c0083ced0470500060f14d37cdfff3028795 Author: Jonny Barnes Date: Fri Dec 16 11:46:40 2016 +0000 remove done @todo commit f61a968bb8a7743c2b34ea3efcb25cfd73452cfc Author: Jonny Barnes Date: Fri Dec 16 11:43:22 2016 +0000 Comment for using empty array commit 9ad7cde20d259ff4527d315049e3df83f145fe0f Author: Jonny Barnes Date: Fri Dec 16 11:42:18 2016 +0000 Syndication targets are now dynamically checked --- app/Http/Controllers/MicropubController.php | 1 - app/Services/NoteService.php | 41 ++++++++++++--------- config/syndication.php | 1 + 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index 10e96ef4..2c344028 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -103,7 +103,6 @@ class MicropubController extends Controller * appropriately. Further if the request has the query parameter * synidicate-to we respond with the known syndication endpoints. * - * @todo Move the syndication endpoints into a .env variable * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 7d4d7fd8..b4da1df3 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -72,28 +72,35 @@ class NoteService dispatch(new SendWebMentions($note)); //syndication targets - //string sent from either local admin CP or micropub - if ($request->input('twitter') == true - || $request->input('syndicate-to') == 'https://twitter.com/jonnybarnes') { + //from admin CP + if ($request->input('twitter')) { dispatch(new SyndicateToTwitter($note)); } - if ($request->input('facebook') == true - || $request->input('syndicate-to') == 'https://facebook.com/jonnybarnes') { + if ($request->input('facebook')) { dispatch(new SyndicateToFacebook($note)); } - - //micropub request, syndication sent as array - if ((is_array($request->input('syndicate-to'))) - && - (in_array('https://twitter.com/jonnybarnes', $request->input('syndicate-to'))) - ) { - dispatch(new SyndicateToTwitter($note)); + //from a micropub request + $targets = array_pluck(config('syndication.targets'), 'uid', 'service.name'); + if (is_string($request->input('syndicate-to'))) { + $service = array_search($request->input('syndicate-to')); + if ($service == 'Twitter') { + dispatch(new SyndicateToTwitter($note)); + } + if ($service == 'Facebook') { + dispatch(new SyndicateToFacebook($note)); + } } - if ((is_array($request->input('syndicate-to'))) - && - (in_array('https://facebook.com/jonnybarnes', $request->input('syndicate-to'))) - ) { - dispatch(new SyndicateToFacebook($note)); + if (is_array($request->input('syndicate-to'))) { + foreach ($targets as $service => $target) { + if (in_array($target, $request->input('syndicate-to'))) { + if ($service == 'Twitter') { + dispatch(new SyndicateToTwitter($note)); + } + if ($service == 'Facebook') { + dispatch(new SyndicateToFacebook($note)); + } + } + } } return $note; diff --git a/config/syndication.php b/config/syndication.php index e5accd8b..18f3d755 100644 --- a/config/syndication.php +++ b/config/syndication.php @@ -6,6 +6,7 @@ */ return [ + // if you don’t have any targets, then set this to 'targets' => []; 'targets' => [ [ 'uid' => 'https://twitter.com/jonnybarnes',