Merge branch 'release/0.0.13.5'

This commit is contained in:
Jonny Barnes 2016-10-05 16:17:28 +01:00
commit 04e6744806
11 changed files with 38 additions and 34 deletions

View file

@ -166,17 +166,11 @@ class MicropubClientController extends Controller
]; ];
} }
} }
if ($request->input('confirmlocation')) { if ($request->input('location')) {
$latLng = $request->input('location'); if ($request->input('location') !== 'no-location') {
$geoURL = 'geo:' . str_replace(' ', '', $latLng);
$multipart[] = [
'name' => 'location',
'contents' => $geoURL,
];
if ($request->input('address') != '') {
$multipart[] = [ $multipart[] = [
'name' => 'place_name', 'name' => 'location',
'contents' => $request->input('address'), 'contents' => $request->input('location'),
]; ];
} }
} }
@ -319,7 +313,6 @@ class MicropubClientController extends Controller
return response()->json([ return response()->json([
'error' => true, 'error' => true,
'error_description' => 'The endpoint returned a non-good response', 'error_description' => 'The endpoint returned a non-good response',
'error_stack' => $e->getMessage()
], 400); ], 400);
} }

View file

@ -118,7 +118,7 @@ class MicropubController extends Controller
return response()->json([ return response()->json([
'response' => 'error', 'response' => 'error',
'error' => 'invalid_token', 'error' => 'invalid_token',
'error_description' => 'The provided token did not pass validation' 'error_description' => 'The provided token did not pass validation',
], 400); ], 400);
} }
//we have a valid token, is `syndicate-to` set? //we have a valid token, is `syndicate-to` set?
@ -149,6 +149,9 @@ class MicropubController extends Controller
); );
$distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000; $distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000;
$places = Place::near($matches[0][0], $matches[0][1], $distance); $places = Place::near($matches[0][0], $matches[0][1], $distance);
foreach ($places as $place) {
$place->uri = config('app.url') . '/place/' . $place->slug;
}
return response()->json([ return response()->json([
'response' => 'places', 'response' => 'places',

View file

@ -48,14 +48,8 @@ class AppServiceProvider extends ServiceProvider
//allow micropub use in development //allow micropub use in development
if (env('APP_DEBUG') == true) { if (env('APP_DEBUG') == true) {
$tokenService = new \App\Services\TokenService();
$token = $tokenService->getNewToken([
'me' => 'https://jonnybarnes.localhost',
'client_id' => 'https://jonnybarnes.localhost/notes/new',
'scope' => 'post'
]);
session(['me' => 'https://jonnybarnes.localhost']); session(['me' => 'https://jonnybarnes.localhost']);
session(['token' => 'abc123']); session(['token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtZSI6Imh0dHBzOlwvXC9qb25ueWJhcm5lcy5sb2NhbGhvc3QiLCJjbGllbnRfaWQiOiJodHRwczpcL1wvam9ubnliYXJuZXMubG9jYWxob3N0XC9ub3Rlc1wvbmV3Iiwic2NvcGUiOiJwb3N0IiwiZGF0ZV9pc3N1ZWQiOjE0NzU1MTI0NDgsIm5vbmNlIjoiYzE0MzNmNzg5ZTY4Y2M1OSJ9.7Bj9yLnWJOyVre8BPihAom2G0MEsmS3tIUraDI-GRNg']);
} }
} }

View file

@ -22,14 +22,14 @@ class NoteService
if ($request->header('Content-Type') == 'application/json') { if ($request->header('Content-Type') == 'application/json') {
$content = $request->input('properties.content')[0]; $content = $request->input('properties.content')[0];
$inReplyTo = $request->input('properties.in-reply-to')[0]; $inReplyTo = $request->input('properties.in-reply-to')[0];
$placeSlug = $request->input('properties.location'); $place = $request->input('properties.location');
if (is_array($placeSlug)) { if (is_array($place)) {
$placeSlug = $placeSlug[0]; $place = $place[0];
} }
} else { } else {
$content = $request->input('content'); $content = $request->input('content');
$inReplyTo = $request->input('in-reply-to'); $inReplyTo = $request->input('in-reply-to');
$placeSlug = $request->input('location'); $place = $request->input('location');
} }
$note = Note::create( $note = Note::create(
@ -40,10 +40,24 @@ class NoteService
] ]
); );
if ($placeSlug !== null && $placeSlug !== 'no-location') { if ($place !== null && $place !== 'no-location') {
$place = Place::where('slug', '=', $placeSlug)->first(); if (substr($place, 0, strlen(config('app.url'))) == config('app.url')) {
$note->place()->associate($place); //uri of form http://host/place/slug, we want slug so chop off start
$note->save(); //thats the apps url plus `/place/`
$slug = mb_substr($place, mb_strlen(config('app.url')) + 7);
$placeModel = Place::where('slug', '=', $slug)->first();
$note->place()->associate($placeModel);
$note->save();
}
if (substr($place, 0, 4) == 'geo:') {
preg_match_all(
'/([0-9\.\-]+)/',
$place,
$matches
);
$note->location = $matches[0][0] . ', ' . $matches[0][1];
$note->save();
}
} }
//add images to media library //add images to media library

View file

@ -38,9 +38,6 @@ class TokenService
*/ */
public function validateToken($token) public function validateToken($token)
{ {
if (env('APP_DEBUG') == true) {
return true;
}
$signer = new Sha256(); $signer = new Sha256();
try { try {
$token = (new Parser())->parse((string) $token); $token = (new Parser())->parse((string) $token);

View file

@ -1,5 +1,8 @@
# Changelog # Changelog
## Version 0.0.13.5 (2016-10-05)
- Places can now be added to a new note created via micropub
## Version 0.0.13.4 (2016-10-03) ## Version 0.0.13.4 (2016-10-03)
- Better working code for places in newnote.js (issue#21) - Better working code for places in newnote.js (issue#21)
* In aid of this add ability to run micropub code locally * In aid of this add ability to run micropub code locally

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View file

@ -34,8 +34,8 @@ function addPlacesMap(latitude, longitude, uncertainty) {
for (i = 0; i < j.places.length; ++i) { for (i = 0; i < j.places.length; ++i) {
var latlng = parseLocation(j.places[i].location); var latlng = parseLocation(j.places[i].location);
var name = j.places[i].name; var name = j.places[i].name;
var slug = j.places[i].slug; var uri = j.places[i].uri;
places.push([name, slug, latlng[0], latlng[1]]); places.push([name, uri, latlng[0], latlng[1]]);
} }
//add a map with the nearby places //add a map with the nearby places
addMap(latitude, longitude, places); addMap(latitude, longitude, places);