Allow JSON requests to the micropub endpoint
This commit is contained in:
parent
50126828ff
commit
72e61032d8
4 changed files with 21 additions and 7 deletions
|
@ -56,8 +56,7 @@ class MicropubController extends Controller
|
||||||
$scopes = explode(' ', $tokenData->getClaim('scope'));
|
$scopes = explode(' ', $tokenData->getClaim('scope'));
|
||||||
if (array_search('post', $scopes) !== false) {
|
if (array_search('post', $scopes) !== false) {
|
||||||
$clientId = $tokenData->getClaim('client_id');
|
$clientId = $tokenData->getClaim('client_id');
|
||||||
$type = $request->input('h');
|
if (($request->input('h') == 'entry') || ($request->input('type')[0] == 'h-entry')) {
|
||||||
if ($type == 'entry') {
|
|
||||||
$note = $this->noteService->createNote($request, $clientId);
|
$note = $this->noteService->createNote($request, $clientId);
|
||||||
$content = <<<EOD
|
$content = <<<EOD
|
||||||
{
|
{
|
||||||
|
@ -70,7 +69,7 @@ EOD;
|
||||||
->header('Location', $note->longurl)
|
->header('Location', $note->longurl)
|
||||||
->header('Content-Type', 'application/json');
|
->header('Content-Type', 'application/json');
|
||||||
}
|
}
|
||||||
if ($type == 'card') {
|
if ($request->input('h') == 'card' || $request->input('type')[0] == 'h-card') {
|
||||||
$place = $this->placeService->createPlace($request);
|
$place = $this->placeService->createPlace($request);
|
||||||
$content = <<<EOD
|
$content = <<<EOD
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,15 +22,27 @@ class NoteService
|
||||||
*/
|
*/
|
||||||
public function createNote(Request $request, $clientId = null)
|
public function createNote(Request $request, $clientId = null)
|
||||||
{
|
{
|
||||||
|
if ($request->header('Content-Type') == 'application/json') {
|
||||||
|
$content = $request->input('properties.content')[0];
|
||||||
|
$inReplyTo = $request->input('properties.in-reply-to')[0];
|
||||||
|
$placeSlug = $request->input('proprties.location');
|
||||||
|
if (is_array($placeSlug)) {
|
||||||
|
$placeSlug = $placeSlug[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$content = $request->input('content');
|
||||||
|
$inReplyTo = $request->input('in-reply-to');
|
||||||
|
$placeSlug = $request->input('location');
|
||||||
|
}
|
||||||
|
|
||||||
$note = Note::create(
|
$note = Note::create(
|
||||||
[
|
[
|
||||||
'note' => $request->input('content'),
|
'note' => $content,
|
||||||
'in_reply_to' => $request->input('in-reply-to'),
|
'in_reply_to' => $inReplyTo,
|
||||||
'client_id' => $clientId,
|
'client_id' => $clientId,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$placeSlug = $request->input('location');
|
|
||||||
if ($placeSlug !== null && $placeSlug !== 'no-location') {
|
if ($placeSlug !== null && $placeSlug !== 'no-location') {
|
||||||
$place = Place::where('slug', '=', $placeSlug)->first();
|
$place = Place::where('slug', '=', $placeSlug)->first();
|
||||||
$note->place()->associate($place);
|
$note->place()->associate($place);
|
||||||
|
|
|
@ -14,7 +14,7 @@ class PlaceService
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \App\Place
|
* @return \App\Place
|
||||||
*/
|
*/
|
||||||
public function createplace(Request $request)
|
public function createPlace(Request $request)
|
||||||
{
|
{
|
||||||
//we’ll either have latitude and longitude sent together in a
|
//we’ll either have latitude and longitude sent together in a
|
||||||
//geo-url (micropub), or seperatley (/admin)
|
//geo-url (micropub), or seperatley (/admin)
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version {next}
|
||||||
|
- Allow new notes to be made by a JSON request from a micropub client
|
||||||
|
|
||||||
## Version 0.0.7.1 (2016-07-04)
|
## Version 0.0.7.1 (2016-07-04)
|
||||||
- Minor style fixes
|
- Minor style fixes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue