Notes created via the micropub client can now have associated places

Squashed commit of the following:

commit d98a19ac59d29540f9eeca473013da4e52ad99eb
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 5 16:09:33 2016 +0100

    Get places working again, location info will add a place to a note

commit 98ec16174cb4431e6e0e13f5f1d3303ceafcd7b1
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 5 16:08:32 2016 +0100

    gulp build assets from js

commit 2e7e50a6f6f7f8b129bb472d92a38801575020a8
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Wed Oct 5 16:07:21 2016 +0100

    Use full URIs instead of slugs for places
This commit is contained in:
Jonny Barnes 2016-10-05 16:10:00 +01:00
parent d924f9916e
commit ac7f002293
8 changed files with 33 additions and 22 deletions

View file

@ -166,17 +166,11 @@ class MicropubClientController extends Controller
];
}
}
if ($request->input('confirmlocation')) {
$latLng = $request->input('location');
$geoURL = 'geo:' . str_replace(' ', '', $latLng);
$multipart[] = [
'name' => 'location',
'contents' => $geoURL,
];
if ($request->input('address') != '') {
if ($request->input('location')) {
if ($request->input('location') !== 'no-location') {
$multipart[] = [
'name' => 'place_name',
'contents' => $request->input('address'),
'name' => 'location',
'contents' => $request->input('location')
];
}
}

View file

@ -149,6 +149,9 @@ class MicropubController extends Controller
);
$distance = (count($matches[0]) == 3) ? 100 * $matches[0][2] : 1000;
$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([
'response' => 'places',

View file

@ -22,14 +22,14 @@ class NoteService
if ($request->header('Content-Type') == 'application/json') {
$content = $request->input('properties.content')[0];
$inReplyTo = $request->input('properties.in-reply-to')[0];
$placeSlug = $request->input('properties.location');
if (is_array($placeSlug)) {
$placeSlug = $placeSlug[0];
$place = $request->input('properties.location');
if (is_array($place)) {
$place = $place[0];
}
} else {
$content = $request->input('content');
$inReplyTo = $request->input('in-reply-to');
$placeSlug = $request->input('location');
$place = $request->input('location');
}
$note = Note::create(
@ -40,10 +40,24 @@ class NoteService
]
);
if ($placeSlug !== null && $placeSlug !== 'no-location') {
$place = Place::where('slug', '=', $placeSlug)->first();
$note->place()->associate($place);
$note->save();
if ($place !== null && $place !== 'no-location') {
if (substr($place, 0, strlen(config('app.url'))) == config('app.url')) {
//uri of form http://host/place/slug, we want slug so chop off start
//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

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) {
var latlng = parseLocation(j.places[i].location);
var name = j.places[i].name;
var slug = j.places[i].slug;
places.push([name, slug, latlng[0], latlng[1]]);
var uri = j.places[i].uri;
places.push([name, uri, latlng[0], latlng[1]]);
}
//add a map with the nearby places
addMap(latitude, longitude, places);