diff --git a/app/Http/Controllers/MicropubClientController.php b/app/Http/Controllers/MicropubClientController.php index 858822fb..60c714d4 100644 --- a/app/Http/Controllers/MicropubClientController.php +++ b/app/Http/Controllers/MicropubClientController.php @@ -37,9 +37,7 @@ class MicropubClientController extends Controller public function newNotePage(Request $request) { $url = $request->session()->get('me'); - $syndication = $this->parseSyndicationTargets( - $request->session()->get('syndication') - ); + $syndication = $request->session()->get('syndication'); return view('micropubnewnotepage', [ 'url' => $url, @@ -113,7 +111,7 @@ class MicropubClientController extends Controller return redirect('notes/new')->withErrors('Bad response when refreshing syndication targets', 'endpoint'); } $body = (string) $response->getBody(); - $syndication = str_replace(['&', '[]'], [';', ''], $body); + $syndication = $this->parseSyndicationTargets($body); $request->session()->put('syndication', $syndication); @@ -321,10 +319,9 @@ class MicropubClientController extends Controller return; } $syndicateTo = []; - $parts = explode(';', $syndicationTargets); - foreach ($parts as $part) { - $target = explode('=', $part); - $syndicateTo[] = urldecode($target[1]); + $data = json_decode($syndicationTargets, true); + foreach ($syndicateTo['syndicate-to'] as $syn) { + $syndicateTo[] = $syn['uid']; } if (count($syndicateTo) > 0) { return $syndicateTo; diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index b348ade1..3b180ee1 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -108,12 +108,22 @@ class MicropubController extends Controller } //we have a valid token, is `syndicate-to` set? if ($request->input('q') === 'syndicate-to') { - $content = http_build_query([ - 'syndicate-to' => 'twitter.com/jonnybarnes', + return response()->json([ + 'syndicate-to' => [[ + 'uid' => 'https://twitter.com/jonnybarnes', + 'name' => 'jonnybarnes on Twitter', + 'service' => [ + 'name' => 'Twitter', + 'url' => 'https://twitter.com', + 'photo' => 'https://upload.wikimedia.org/wikipedia/en/9/9f/Twitter_bird_logo_2012.svg', + ], + 'user' => [ + 'name' => 'jonnybarnes', + 'url' => 'https://twitter.com/jonnybarnes', + 'photo' => 'https://pbs.twimg.com/profile_images/1853565405/jmb-bw.jpg', + ], + ]], ]); - - return (new Response($content, 200)) - ->header('Content-Type', 'application/x-www-form-urlencoded'); } //nope, how about a geo URL? if (substr($request->input('q'), 0, 4) === 'geo:') { diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 4be6fe6d..087aa594 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -50,9 +50,9 @@ class NoteService if (//micropub request, syndication sent as array (is_array($request->input('syndicate-to')) && - (in_array('twitter.com/jonnybarnes', $request->input('syndicate-to'))) + (in_array('https://twitter.com/jonnybarnes', $request->input('syndicate-to'))) || //micropub request, syndication sent as string - ($request->input('syndicate-to') == 'twitter.com/jonnybarnes') + ($request->input('syndicate-to') == 'https://twitter.com/jonnybarnes') || //local admin cp request ($request->input('twitter') == true)) ) { diff --git a/changelog.md b/changelog.md index eadef67b..7009f734 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version {next} + - Use JSON for syndication endpoint query response + ## Version 0.0.6.3 (2016-06-29) - Fix an issue with dispatching the syndication job diff --git a/tests/MicropubTest.php b/tests/MicropubTest.php index 1854f3fb..cdc1e4a4 100644 --- a/tests/MicropubTest.php +++ b/tests/MicropubTest.php @@ -44,7 +44,7 @@ class MicropubTest extends TestCase public function testMicropubRequestForSyndication() { $this->call('GET', $this->appurl . '/api/post', ['q' => 'syndicate-to'], [], [], ['HTTP_Authorization' => 'Bearer ' . $this->getToken()]); - $this->see('twitter.com%2Fjonnybarnes'); + $this->seeJson(['uid' => 'https://twitter.com/jonnybarnes']); } public function testMicropubRequestForNearbyPlacesThatExist()