diff --git a/app/Http/Controllers/MicropubClientController.php b/app/Http/Controllers/MicropubClientController.php index adac3d33..9035bae8 100644 --- a/app/Http/Controllers/MicropubClientController.php +++ b/app/Http/Controllers/MicropubClientController.php @@ -204,34 +204,37 @@ class MicropubClientController extends Controller */ public function postNewPlace(Request $request) { + if ($request->session()->has('token') === false) { + return response()->json([ + 'error' => true, + 'error_description' => 'No known token', + ], 400); + } $domain = $request->session()->get('me'); $token = $request->session()->get('token'); $micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient); if (! $micropubEndpoint) { - return (new Response(json_encode([ + return response()->json([ 'error' => true, - 'message' => 'Could not determine the micropub endpoint.', - ]), 400)) - ->header('Content-Type', 'application/json'); + 'error_description' => 'Could not determine the micropub endpoint.', + ], 400); } $place = $this->postPlaceRequest($request, $micropubEndpoint, $token); if ($place === false) { - return (new Response(json_encode([ + return response()->json([ 'error' => true, - 'message' => 'Unable to create the new place', - ]), 400)) - ->header('Content-Type', 'application/json'); + 'error_description' => 'Unable to create the new place', + ], 400); } - return (new Response(json_encode([ + return response()->json([ 'url' => $place, 'name' => $request->input('place-name'), 'latitude' => $request->input('place-latitude'), 'longitude' => $request->input('place-longitude'), - ]), 200)) - ->header('Content-Type', 'application/json'); + ]); } /** @@ -263,7 +266,7 @@ class MicropubClientController extends Controller 'headers' => $headers, ]); } catch (ClientException $e) { - //not sure yet... + return false; } if ($response->getStatusCode() == 201) { return $response->getHeader('Location')[0]; @@ -285,12 +288,22 @@ class MicropubClientController extends Controller $latitude, $longitude ) { + if ($request->session()->has('token') === false) { + return response()->json([ + 'error' => true, + 'error_description' => 'No known token', + ], 400); + } $domain = $request->session()->get('me'); $token = $request->session()->get('token'); + $micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient); if (! $micropubEndpoint) { - return; + return response()->json([ + 'error' => true, + 'error_description' => 'No known endpoint', + ], 400); } try { @@ -299,7 +312,10 @@ class MicropubClientController extends Controller 'query' => ['q' => 'geo:' . $latitude . ',' . $longitude], ]); } catch (\GuzzleHttp\Exception\BadResponseException $e) { - return; + return response()->json([ + 'error' => true, + 'error_description' => 'The endpoint returned a non-good response', + ], 400); } return (new Response($response->getBody(), 200)) diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index 0ff28497..a3dd6939 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -57,54 +57,44 @@ class MicropubController extends Controller if (array_search('post', $scopes) !== false) { $clientId = $tokenData->getClaim('client_id'); if (($request->input('h') == 'entry') || ($request->input('type')[0] == 'h-entry')) { - $note = $this->noteService->createNote($request, $clientId); - $content = <<longurl" -} -EOD; + try { + $note = $this->noteService->createNote($request, $clientId); + } catch (Exception $exception) { + return response()->json(['error' => true], 400); + } - return (new Response($content, 201)) - ->header('Location', $note->longurl) - ->header('Content-Type', 'application/json'); + return response()->json([ + 'response' => 'created', + 'location' => $note->longurl, + ], 201)->header('Location', $note->longurl); } if ($request->input('h') == 'card' || $request->input('type')[0] == 'h-card') { - $place = $this->placeService->createPlace($request); - $content = <<longurl" -} -EOD; + try { + $place = $this->placeService->createPlace($request); + } catch (Exception $exception) { + return response()->json(['error' => true], 400); + } - return (new Response($content, 201)) - ->header('Location', $place->longurl) - ->header('Content-Type', 'application/json'); + return response()->json([ + 'response' => 'created', + 'location' => $place->longurl, + ], 201)->header('Location', $place->longurl); } } } - $content = <<<'EOD' -{ - "response": "error", - "error": "invalid_token", - "error_description": "The token provided is not valid or does not have the necessary scope", -} -EOD; - return (new Response($content, 400)) - ->header('Content-Type', 'application/json'); + return response()->json([ + 'response' => 'error', + 'error' => 'invalid_token', + 'error_description' => 'The token provided is not valid or does not have the necessary scope', + ], 400); } - $content = <<<'EOD' -{ - "response": "error", - "error": "no_token", - "error_description": "No OAuth token sent with request" -} -EOD; - return (new Response($content, 400)) - ->header('Content-Type', 'application/json'); + return response()->json([ + 'response' => 'error', + 'error' => 'no_token', + 'error_description' => 'No OAuth token sent with request', + ], 400); } /** diff --git a/app/Place.php b/app/Place.php index 7ce34599..13daa290 100644 --- a/app/Place.php +++ b/app/Place.php @@ -4,9 +4,7 @@ namespace App; use DB; use Illuminate\Database\Eloquent\Model; -use Phaza\LaravelPostgis\Geometries\Point; use MartinBean\Database\Eloquent\Sluggable; -use Phaza\LaravelPostgis\Geometries\Polygon; use Phaza\LaravelPostgis\Eloquent\PostgisTrait; class Place extends Model @@ -33,8 +31,8 @@ class Place extends Model * @var array */ protected $postgisFields = [ - 'location' => Point::class, - 'polygon' => Polygon::class, + 'location', + 'polygon', ]; /** diff --git a/app/Services/PlaceService.php b/app/Services/PlaceService.php index c5e49b18..85a27972 100644 --- a/app/Services/PlaceService.php +++ b/app/Services/PlaceService.php @@ -16,21 +16,26 @@ class PlaceService */ public function createPlace(Request $request) { - //we’ll either have latitude and longitude sent together in a - //geo-url (micropub), or seperatley (/admin) - if ($request->input('geo') !== null) { - $parts = explode(':', $request->input('geo')); - $latlng = explode(',', $parts[1]); - $latitude = $latlng[0]; - $longitude = $latlng[1]; + if ($request->header('Content-Type') == 'application/json') { + $name = $request->input('properties.name'); + $description = $request->input('properties.description') ?? null; + $geo = $request->input('properties.geo'); + } else { + $name = $request->input('name'); + $description = $request->input('description'); + $geo = $request->input('geo'); } + $parts = explode(':', $geo); + $latlng = explode(',', $parts[1]); + $latitude = $latlng[0]; + $longitude = $latlng[1]; if ($request->input('latitude') !== null) { $latitude = $request->input('latitude'); $longitude = $request->input('longitude'); } $place = new Place(); - $place->name = $request->input('name'); - $place->description = $request->input('description'); + $place->name = $name; + $place->description = $description; $place->location = new Point((float) $latitude, (float) $longitude); $place->save(); diff --git a/changelog.md b/changelog.md index 50f6d584..e3f4e4a6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## Version 0.0.13 (2016-09-26) + - Better places support, particularly with micropub (issue#9) + - Uglify js for better performance (issue#19) + - Autolink spotify links (issue#18) + ## Version 0.0.12 (2016-09-21) - Better indication of number of replies to a note (issue#17) - Use generic twitter status URL so my own profile name isn’t hardcoded (issue#14) diff --git a/composer.lock b/composer.lock index f0e4f1b3..7d946298 100644 --- a/composer.lock +++ b/composer.lock @@ -58,16 +58,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.19.9", + "version": "3.19.10", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "55da42fee5ff26f962b2366b08e4f32e348cd1d9" + "reference": "eb9488f671175e708cf68c74cc04bd9115c96761" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/55da42fee5ff26f962b2366b08e4f32e348cd1d9", - "reference": "55da42fee5ff26f962b2366b08e4f32e348cd1d9", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/eb9488f671175e708cf68c74cc04bd9115c96761", + "reference": "eb9488f671175e708cf68c74cc04bd9115c96761", "shasum": "" }, "require": { @@ -134,7 +134,7 @@ "s3", "sdk" ], - "time": "2016-09-20 22:11:12" + "time": "2016-09-22 19:32:03" }, { "name": "barnabywalters/mf-cleaner", @@ -2891,16 +2891,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "4.8.4", + "version": "4.9.1", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "8c862e270d49e8bbff6f0993900c8bb59ea165ea" + "reference": "bb8786724f87c2d187897809849b7dc79a84a4d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/8c862e270d49e8bbff6f0993900c8bb59ea165ea", - "reference": "8c862e270d49e8bbff6f0993900c8bb59ea165ea", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/bb8786724f87c2d187897809849b7dc79a84a4d9", + "reference": "bb8786724f87c2d187897809849b7dc79a84a4d9", "shasum": "" }, "require": { @@ -2910,7 +2910,7 @@ "illuminate/support": "~5.1.16|~5.2.0|~5.3.0", "php": "^7.0", "spatie/laravel-glide": "^3.0.0", - "spatie/pdf-to-image": "^1.0.1", + "spatie/pdf-to-image": "^1.2", "spatie/string": "^2.0.0" }, "conflict": { @@ -2919,8 +2919,7 @@ "require-dev": { "doctrine/dbal": "^2.5.2", "mockery/mockery": "^0.9.4", - "orchestra/database": "3.3.x-dev", - "orchestra/testbench": "3.3.x-dev", + "orchestra/testbench": "^3.1", "phpunit/phpunit": "^5.0.0", "scrutinizer/ocular": "^1.1" }, @@ -2954,7 +2953,7 @@ "media", "spatie" ], - "time": "2016-09-14 16:31:49" + "time": "2016-09-23 11:54:31" }, { "name": "spatie/pdf-to-image", @@ -4031,28 +4030,28 @@ "packages-dev": [ { "name": "barryvdh/laravel-debugbar", - "version": "V2.2.3", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-debugbar.git", - "reference": "ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd" + "reference": "0c87981df959c7c1943abe227baf607c92f204f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd", - "reference": "ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/0c87981df959c7c1943abe227baf607c92f204f9", + "reference": "0c87981df959c7c1943abe227baf607c92f204f9", "shasum": "" }, "require": { "illuminate/support": "5.1.*|5.2.*|5.3.*", - "maximebf/debugbar": "~1.11.0|~1.12.0", + "maximebf/debugbar": "~1.13.0", "php": ">=5.5.9", "symfony/finder": "~2.7|~3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.3-dev" } }, "autoload": { @@ -4081,7 +4080,7 @@ "profiler", "webprofiler" ], - "time": "2016-07-29 15:00:36" + "time": "2016-09-15 14:05:56" }, { "name": "doctrine/instantiator", @@ -4232,16 +4231,16 @@ }, { "name": "maximebf/debugbar", - "version": "v1.12.0", + "version": "v1.13.0", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988" + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988", - "reference": "e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/5f49a5ed6cfde81d31d89378806670d77462526e", + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e", "shasum": "" }, "require": { @@ -4260,7 +4259,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.13-dev" } }, "autoload": { @@ -4289,7 +4288,7 @@ "debug", "debugbar" ], - "time": "2016-05-15 13:11:34" + "time": "2016-09-15 14:01:59" }, { "name": "mockery/mockery", diff --git a/config/app.php b/config/app.php index 5ac83ad3..ffe7b4b3 100644 --- a/config/app.php +++ b/config/app.php @@ -222,6 +222,7 @@ return [ 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, 'Blade' => Illuminate\Support\Facades\Blade::class, + 'Bus' => Illuminate\Support\Facades\Bus::class, 'Cache' => Illuminate\Support\Facades\Cache::class, 'Config' => Illuminate\Support\Facades\Config::class, 'Cookie' => Illuminate\Support\Facades\Cookie::class, diff --git a/gulpfile.js b/gulpfile.js index 35220c94..b4517563 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,8 +1,10 @@ 'use strict'; var gulp = require('gulp'); +var pump = require('pump'); var sass = require('gulp-sass'); var brotli = require('gulp-brotli'); +var uglify = require('gulp-uglify'); var zopfli = require('gulp-zopfli'); var sourcemaps = require('gulp-sourcemaps'); var autoprefixer = require('gulp-autoprefixer'); @@ -17,7 +19,12 @@ gulp.task('sass', function () { }); gulp.task('js-assets', function () { + //return gulp.src(['resources/assets/js/**/*']) + // .pipe(gulp.dest('./public/assets/js')); return gulp.src(['resources/assets/js/**/*']) + .pipe(sourcemaps.init()) + .pipe(uglify()) + .pipe(sourcemaps.write('./maps')) .pipe(gulp.dest('./public/assets/js')); }); diff --git a/package.json b/package.json index 26d366d5..e06d86b4 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "gulp-brotli": "^1.0.1", "gulp-sass": "^2.3.2", "gulp-sourcemaps": "^1.6.0", + "gulp-uglify": "^2.0.0", "gulp-zopfli": "^1.0.0", "lint-staged": "^1.0.1", "pre-commit": "^1.1.3", diff --git a/public/assets/bower/Autolinker.min.js.gz b/public/assets/bower/Autolinker.min.js.gz index 5c9da878..f55c52ab 100644 Binary files a/public/assets/bower/Autolinker.min.js.gz and b/public/assets/bower/Autolinker.min.js.gz differ diff --git a/public/assets/bower/alertify.css.gz b/public/assets/bower/alertify.css.gz index 0ea203b1..2387b322 100644 Binary files a/public/assets/bower/alertify.css.gz and b/public/assets/bower/alertify.css.gz differ diff --git a/public/assets/bower/alertify.js.gz b/public/assets/bower/alertify.js.gz index df917bcf..f5fe54b0 100644 Binary files a/public/assets/bower/alertify.js.gz and b/public/assets/bower/alertify.js.gz differ diff --git a/public/assets/bower/fetch.js.gz b/public/assets/bower/fetch.js.gz index f1534130..e1a9f982 100644 Binary files a/public/assets/bower/fetch.js.gz and b/public/assets/bower/fetch.js.gz differ diff --git a/public/assets/bower/marked.min.js.gz b/public/assets/bower/marked.min.js.gz index 23d8aff6..6f889623 100644 Binary files a/public/assets/bower/marked.min.js.gz and b/public/assets/bower/marked.min.js.gz differ diff --git a/public/assets/bower/sanitize.css.gz b/public/assets/bower/sanitize.css.gz index 07dcaf64..9c6f46b2 100644 Binary files a/public/assets/bower/sanitize.css.gz and b/public/assets/bower/sanitize.css.gz differ diff --git a/public/assets/bower/store2.min.js.gz b/public/assets/bower/store2.min.js.gz index 657123f1..40ab6bd7 100644 Binary files a/public/assets/bower/store2.min.js.gz and b/public/assets/bower/store2.min.js.gz differ diff --git a/public/assets/css/projects.css.gz b/public/assets/css/projects.css.gz index deca5763..f773d147 100644 Binary files a/public/assets/css/projects.css.gz and b/public/assets/css/projects.css.gz differ diff --git a/public/assets/js/form-save.js b/public/assets/js/form-save.js index 20d8f0a7..ce4018c5 100644 --- a/public/assets/js/form-save.js +++ b/public/assets/js/form-save.js @@ -1,69 +1,2 @@ -/* global alertify, store */ -var feature = { - addEventListener : !!window.addEventListener, - querySelectorAll : !!document.querySelectorAll -}; - -if (feature.addEventListener && feature.querySelectorAll) { - var keys = getKeys(); - for (var i = 0; i < keys.length; i++) { - if (store.get(keys[i])) { - var formId = keys[i].split('~')[1]; - document.getElementById(formId).value = store.get(keys[i]); - } - } -} - -var timerId = window.setInterval(function() { - var saved = false; - var inputs = document.querySelectorAll('input[type=text], textarea'); - for (var i = 0; i < inputs.length; i++) { - var key = getFormElement(inputs[i]).id + '~' + inputs[i].id; - if (store.get(key) !== inputs[i].value && inputs[i].value !== '') { - store.set(key, inputs[i].value); - saved = true; - } - } - if (saved === true) { - alertify.logPosition('top right'); - alertify.success('Auto saved text'); - } -}, 5000); -var forms = document.querySelectorAll('form'); -for (var f = 0; f < forms.length; f++) { - var form = forms[f]; - form.addEventListener('submit', function() { - window.clearInterval(timerId); - var formId = form.id; - var storedKeys = store.keys(); - for (var i = 0; i < storedKeys.length; i++) { - if (storedKeys[i].indexOf(formId) > -1) { - store.remove(storedKeys[i]); - } - } - }); -} -function getKeys() { - var keys = []; - var formFields = document.querySelectorAll('input[type=text], textarea'); - for (var f = 0; f < formFields.length; f++) { - var parent = getFormElement(formFields[f]); - if (parent !== false) { - var key = parent.id + '~' + formFields[f].id; - keys.push(key); - } - } - return keys; -} -function getFormElement(elem) { - if (elem.nodeName.toLowerCase() !== 'body') { - var parent = elem.parentNode; - if (parent.nodeName.toLowerCase() === 'form') { - return parent; - } else { - return getFormElement(parent); - } - } else { - return false; - } -} +function getKeys(){for(var e=[],t=document.querySelectorAll("input[type=text], textarea"),r=0;r-1&&store.remove(t[r])})} +//# sourceMappingURL=maps/form-save.js.map diff --git a/public/assets/js/form-save.js.br b/public/assets/js/form-save.js.br index dcc9331e..75fa6a9d 100644 Binary files a/public/assets/js/form-save.js.br and b/public/assets/js/form-save.js.br differ diff --git a/public/assets/js/form-save.js.gz b/public/assets/js/form-save.js.gz index 585ad2b2..ab71f29c 100644 Binary files a/public/assets/js/form-save.js.gz and b/public/assets/js/form-save.js.gz differ diff --git a/public/assets/js/links.js b/public/assets/js/links.js index 5871e0e3..84468c6d 100644 --- a/public/assets/js/links.js +++ b/public/assets/js/links.js @@ -1,26 +1,2 @@ -/* global Autolinker */ -//the autlinker object -var autolinker = new Autolinker(); - -//the youtube regex -var ytidregex = /watch\?v=([A-Za-z0-9\-_]+)/; - -//grab the notes and loop through them -var notes = document.querySelectorAll('.e-content'); -for (var i = 0; i < notes.length; i++) { - //get Youtube ID - var ytid = notes[i].textContent.match(ytidregex); - if (ytid !== null) { - var id = ytid[1]; - var iframe = document.createElement('iframe'); - iframe.classList.add('youtube'); - iframe.setAttribute('src', '//www.youtube.com/embed/' + id); - iframe.setAttribute('frameborder', 0); - iframe.setAttribute('allowfullscreen', 'true'); - notes[i].appendChild(iframe); - } - //now linkify everything - var orig = notes[i].innerHTML; - var linked = autolinker.link(orig); - notes[i].innerHTML = linked; -} +for(var autolinker=new Autolinker,ytidregex=/watch\?v=([A-Za-z0-9\-_]+)/,spotifyregex=/https\:\/\/play\.spotify\.com\/(.*)\b/,notes=document.querySelectorAll(".e-content"),i=0;i, then adds map -var mapDivs = document.querySelectorAll('.map'); -for (var i = 0; i < mapDivs.length; i++) { - var mapDiv = mapDivs[i]; - var latitude = mapDiv.dataset.latitude; - var longitude = mapDiv.dataset.longitude; - L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w'; - var map = L.mapbox.map(mapDiv, 'jonnybarnes.gnoihnim') - .setView([latitude, longitude], 15) - .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', { - detectRetina: true - })); - L.marker([latitude, longitude]).addTo(map); - map.scrollWheelZoom.disable(); -} +for(var mapDivs=document.querySelectorAll(".map"),i=0;i -1) {\n store.remove(storedKeys[i]);\n }\n }\n });\n}\nfunction getKeys() {\n var keys = [];\n var formFields = document.querySelectorAll('input[type=text], textarea');\n for (var f = 0; f < formFields.length; f++) {\n var parent = getFormElement(formFields[f]);\n if (parent !== false) {\n var key = parent.id + '~' + formFields[f].id;\n keys.push(key);\n }\n }\n return keys;\n}\nfunction getFormElement(elem) {\n if (elem.nodeName.toLowerCase() !== 'body') {\n var parent = elem.parentNode;\n if (parent.nodeName.toLowerCase() === 'form') {\n return parent;\n } else {\n return getFormElement(parent);\n }\n } else {\n return false;\n }\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/maps/links.js.map b/public/assets/js/maps/links.js.map new file mode 100644 index 00000000..7c55b6a0 --- /dev/null +++ b/public/assets/js/maps/links.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["links.js"],"names":["autolinker","Autolinker","ytidregex","spotifyregex","notes","document","querySelectorAll","i","length","ytid","textContent","match","yid","yiframe","createElement","classList","add","setAttribute","appendChild","spotifyid","sid","replace","siframe","orig","innerHTML","linked","link"],"mappings":"AAWA,IAAK,GATDA,YAAa,GAAIC,YAGjBC,UAAY,6BAEZC,aAAe,wCAGfC,MAAQC,SAASC,iBAAiB,cAC7BC,EAAI,EAAGA,EAAIH,MAAMI,OAAQD,IAAK,CAEnC,GAAIE,MAAOL,MAAMG,GAAGG,YAAYC,MAAMT,UACtC,IAAa,OAATO,KAAe,CACf,GAAIG,KAAMH,KAAK,GACXI,QAAUR,SAASS,cAAc,SACrCD,SAAQE,UAAUC,IAAI,WACtBH,QAAQI,aAAa,MAAO,2BAA6BL,KACzDC,QAAQI,aAAa,cAAe,GACpCJ,QAAQI,aAAa,kBAAmB,QACxCb,MAAMG,GAAGW,YAAYL,SAGzB,GAAIM,WAAYf,MAAMG,GAAGG,YAAYC,MAAMR,aAC3C,IAAkB,OAAdgB,UAAoB,CACpB,GAAIC,KAAMD,UAAU,GAAGE,QAAQ,IAAK,KAChCC,QAAUjB,SAASS,cAAc,SACrCQ,SAAQP,UAAUC,IAAI,WACtBM,QAAQL,aAAa,MAAO,0CAA4CG,KACxEE,QAAQL,aAAa,cAAe,GACpCK,QAAQL,aAAa,oBAAqB,QAC1Cb,MAAMG,GAAGW,YAAYI,SAGzB,GAAIC,MAAOnB,MAAMG,GAAGiB,UAChBC,OAASzB,WAAW0B,KAAKH,KAC7BnB,OAAMG,GAAGiB,UAAYC","file":"links.js","sourcesContent":["/* global Autolinker */\n//the autlinker object\nvar autolinker = new Autolinker();\n\n//the youtube regex\nvar ytidregex = /watch\\?v=([A-Za-z0-9\\-_]+)/;\n\nvar spotifyregex = /https\\:\\/\\/play\\.spotify\\.com\\/(.*)\\b/;\n\n//grab the notes and loop through them\nvar notes = document.querySelectorAll('.e-content');\nfor (var i = 0; i < notes.length; i++) {\n //get Youtube ID\n var ytid = notes[i].textContent.match(ytidregex);\n if (ytid !== null) {\n var yid = ytid[1];\n var yiframe = document.createElement('iframe');\n yiframe.classList.add('youtube');\n yiframe.setAttribute('src', '//www.youtube.com/embed/' + yid);\n yiframe.setAttribute('frameborder', 0);\n yiframe.setAttribute('allowfullscreen', 'true');\n notes[i].appendChild(yiframe);\n }\n //get Spotify ID\n var spotifyid = notes[i].textContent.match(spotifyregex);\n if (spotifyid !== null) {\n var sid = spotifyid[1].replace('/', ':');\n var siframe = document.createElement('iframe');\n siframe.classList.add('spotify');\n siframe.setAttribute('src', 'https://embed.spotify.com/?uri=spotify:' + sid);\n siframe.setAttribute('frameborder', 0);\n siframe.setAttribute('allowtransparency', 'true');\n notes[i].appendChild(siframe);\n }\n //now linkify everything\n var orig = notes[i].innerHTML;\n var linked = autolinker.link(orig);\n notes[i].innerHTML = linked;\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/maps/maps.js.map b/public/assets/js/maps/maps.js.map new file mode 100644 index 00000000..2380c714 --- /dev/null +++ b/public/assets/js/maps/maps.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["maps.js"],"names":["mapDivs","document","querySelectorAll","i","length","mapDiv","latitude","dataset","longitude","L","mapbox","accessToken","map","setView","addLayer","tileLayer","detectRetina","marker","addTo","scrollWheelZoom","disable"],"mappings":"AAGA,IAAK,GADDA,SAAUC,SAASC,iBAAiB,QAC/BC,EAAI,EAAGA,EAAIH,QAAQI,OAAQD,IAAK,CACrC,GAAIE,QAASL,QAAQG,GACjBG,SAAWD,OAAOE,QAAQD,SAC1BE,UAAaH,OAAOE,QAAQC,SAChCC,GAAEC,OAAOC,YAAc,wEACvB,IAAIC,KAAMH,EAAEC,OAAOE,IAAIP,OAAQ,wBAC1BQ,SAASP,SAAUE,WAAY,IAC/BM,SAASL,EAAEC,OAAOK,UAAU,wBACzBC,cAAc,IAEtBP,GAAEQ,QAAQX,SAAUE,YAAYU,MAAMN,KACtCA,IAAIO,gBAAgBC","file":"maps.js","sourcesContent":["/* global L */\n//This code runs on page load and looks for
, then adds map\nvar mapDivs = document.querySelectorAll('.map');\nfor (var i = 0; i < mapDivs.length; i++) {\n var mapDiv = mapDivs[i];\n var latitude = mapDiv.dataset.latitude;\n var longitude = mapDiv.dataset.longitude;\n L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';\n var map = L.mapbox.map(mapDiv, 'jonnybarnes.gnoihnim')\n .setView([latitude, longitude], 15)\n .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {\n detectRetina: true\n }));\n L.marker([latitude, longitude]).addTo(map);\n map.scrollWheelZoom.disable();\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/maps/newnote.js.map b/public/assets/js/maps/newnote.js.map new file mode 100644 index 00000000..e2027f6f --- /dev/null +++ b/public/assets/js/maps/newnote.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["newnote.js"],"names":["getLocation","navigator","geolocation","getCurrentPosition","position","addPlacesMap","coords","latitude","longitude","fetch","credentials","method","then","response","json","j","error","alertify","reset","error_description","length","i","places","latlng","parseLocation","location","name","slug","push","addMap","catch","err","console","arguments","form","button","parentNode","div","document","createElement","setAttribute","appendChild","L","mapbox","accessToken","map","setView","addLayer","tileLayer","detectRetina","marker","draggable","addTo","on","placeFormLatitude","querySelector","value","getLatitudeFromMapboxMarker","getLatLng","placeFormLongitude","getLongitudeFromMapboxMarker","selectEl","noLocation","noLocText","createTextNode","insertBefore","forEach","item","option","text","dataset","placeMarker","icon","marker-size","marker-symbol","marker-color","bindPopup","closeButton","panTo","selectPlace","addEventListener","placeLat","selectedIndex","placeLon","newLocButton","nameLabel","classList","add","nameEl","descLabel","descEl","latLabel","latEl","lonLabel","lonEl","placeSubmit","formData","FormData","append","body","placeJson","Error","urlParts","split","pop","removeChild","labels","querySelectorAll","removeLayer","newOption","newPlaceMarker","newName","placeError","point","re","resultArray","exec","selected","replace","disabled"],"mappings":"AAWA,QAASA,eACLC,UAAUC,YAAYC,mBAAmB,SAAUC,GAE/CC,aAAaD,EAASE,OAAOC,SAAUH,EAASE,OAAOE,aAI/D,QAASH,cAAaE,EAAUC,GAE5BC,MAAM,gBAAkBF,EAAW,IAAMC,GACrCE,YAAa,cACbC,OAAQ,QACTC,KAAK,SAAUC,GACd,MAAOA,GAASC,SACjBF,KAAK,SAAUG,GAKd,GAJe,GAAXA,EAAEC,QACFC,SAASC,QACTD,SAASD,MAAMD,EAAEI,oBAEjBJ,EAAEK,OAAS,EAAG,CACd,GAAIC,GACAC,IACJ,KAAKD,EAAI,EAAGA,EAAIN,EAAEK,SAAUC,EAAG,CAC3B,GAAIE,GAASC,cAAcT,EAAEM,GAAGI,UAC5BC,EAAOX,EAAEM,GAAGK,KACZC,EAAOZ,EAAEM,GAAGM,IAChBL,GAA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IAEjBiC,EAAezD,GAAG,QAAS,WACvBR,EAAIiC,OAAOsB,EAAoB,SAAGA,EAAqB,YACvDrB,YAAYpD,KAGhBoD,YAAYpD,KACbG,MAAM,SAAUkF,GACf/F,SAASC,QACTD,SAASD,MAAMgG,SAI3B9E,EAAK+B,aAAamB,EAAc/C,GAGpC,QAASb,eAAcyF,GACnB,GAAIC,GAAK,WACLC,EAAcD,EAAGE,KAAKH,GACtBxF,EAAW0F,EAAY,GAAGZ,MAAM,IAEpC,QAAQ9E,EAAS,GAAIA,EAAS,IAGlC,QAASsD,aAAYpD,GACjBW,SAASiB,cAAc,iBAAmB5B,EAAO,KAAK0F,UAAW,EAGrE,QAAS5D,6BAA4BlC,GACjC,GAAI4F,GAAc,WAAWC,KAAK7F,GAC9BE,EAAW0F,EAAY,GAAGZ,MAAM,IAEpC,OAAO9E,GAAS,GAAG6F,QAAQ,IAAK,IAGpC,QAAS1D,8BAA6BrC,GAClC,GAAI4F,GAAc,WAAWC,KAAK7F,GAC9BE,EAAW0F,EAAY,GAAGZ,MAAM,IAEpC,OAAO9E,GAAS,GAvRpB,GAAI,eAAiBxB,WAAW,CAC5B,GAAIkC,QAASG,SAASiB,cAAc,UAChCpB,QAAO6C,mBAGP7C,OAAOoF,UAAW,EAClBpF,OAAO6C,iBAAiB,QAAShF","file":"newnote.js","sourcesContent":["/* global L, alertify */\nif ('geolocation' in navigator) {\n var button = document.querySelector('#locate');\n if (button.addEventListener) {\n //if we have javascript, event listeners and geolocation, make the locate\n //button clickable and add event\n button.disabled = false;\n button.addEventListener('click', getLocation);\n }\n}\n\nfunction getLocation() {\n navigator.geolocation.getCurrentPosition(function (position) {\n //the locate button has been clicked so add the places/map\n addPlacesMap(position.coords.latitude, position.coords.longitude);\n });\n}\n\nfunction addPlacesMap(latitude, longitude) {\n //get the nearby places\n fetch('/places/near/' + latitude + '/' + longitude, {\n credentials: 'same-origin',\n method: 'get'\n }).then(function (response) {\n return response.json();\n }).then(function (j) {\n if (j.error == true) {\n alertify.reset();\n alertify.error(j.error_description);\n }\n if (j.length > 0) {\n var i;\n var places = [];\n for (i = 0; i < j.length; ++i) {\n var latlng = parseLocation(j[i].location);\n var name = j[i].name;\n var slug = j[i].slug;\n places.push([name, slug, latlng[0], latlng[1]]);\n }\n //add a map with the nearby places\n addMap(latitude, longitude, places);\n } else {\n //add a map with just current location\n addMap(latitude, longitude);\n }\n }).catch(function (err) {\n console.error(err);\n });\n}\n\nfunction addMap(latitude, longitude, places) {\n //make places null if not supplied\n if (arguments.length == 2) {\n places = null;\n }\n var form = button.parentNode;\n var div = document.createElement('div');\n div.setAttribute('id', 'map');\n //add the map div\n form.appendChild(div);\n L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';\n var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')\n .setView([latitude, longitude], 15)\n .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {\n detectRetina: true\n }));\n //add a marker for the current location\n var marker = L.marker([latitude, longitude], {\n draggable: true\n }).addTo(map);\n //when the location marker is dragged, if the new place form elements exist\n //update the lat/lng values\n marker.on('dragend', function () {\n var placeFormLatitude = document.querySelector('#place-latitude');\n if (placeFormLatitude !== null) {\n placeFormLatitude.value = getLatitudeFromMapboxMarker(marker.getLatLng());\n }\n var placeFormLongitude = document.querySelector('#place-longitude');\n if (placeFormLongitude !== null) {\n placeFormLongitude.value = getLongitudeFromMapboxMarker(marker.getLatLng());\n }\n });\n //create the \n places.forEach(function (item) {\n var option = document.createElement('option');\n option.setAttribute('value', item[1]);\n var text = document.createTextNode(item[0]);\n option.appendChild(text);\n option.dataset.latitude = item[2];\n option.dataset.longitude = item[3];\n selectEl.appendChild(option);\n var placeMarker = L.marker([item[2], item[3]], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n var name = 'Name: ' + item[0];\n placeMarker.bindPopup(name, {\n closeButton: true\n });\n placeMarker.on('click', function () {\n map.panTo([item[2], item[3]]);\n selectPlace(item[1]);\n });\n });\n //add an event listener\n selectEl.addEventListener('change', function () {\n if (selectEl.value !== 'no-location') {\n var placeLat = selectEl[selectEl.selectedIndex].dataset.latitude;\n var placeLon = selectEl[selectEl.selectedIndex].dataset.longitude;\n map.panTo([placeLat, placeLon]);\n }\n });\n }\n //add a button to add a new place\n var newLocButton = document.createElement('button');\n newLocButton.setAttribute('type', 'button');\n newLocButton.setAttribute('id', 'create-new-place');\n newLocButton.appendChild(document.createTextNode('Create New Place?'));\n //the event listener\n newLocButton.addEventListener('click', function() {\n //add the form elements\n var nameLabel = document.createElement('label');\n nameLabel.setAttribute('for', 'place-name');\n nameLabel.classList.add('place-label');\n nameLabel.appendChild(document.createTextNode('Place Name:'));\n var nameEl = document.createElement('input');\n nameEl.setAttribute('placeholder', 'Name');\n nameEl.setAttribute('name', 'place-name');\n nameEl.setAttribute('id', 'place-name');\n nameEl.setAttribute('type', 'text');\n var descLabel = document.createElement('label');\n descLabel.setAttribute('for', 'place-description');\n descLabel.classList.add('place-label');\n descLabel.appendChild(document.createTextNode('Place Description:'));\n var descEl = document.createElement('input');\n descEl.setAttribute('placeholder', 'Description');\n descEl.setAttribute('name', 'place-description');\n descEl.setAttribute('id', 'place-description');\n descEl.setAttribute('type', 'text');\n var latLabel = document.createElement('label');\n latLabel.setAttribute('for', 'place-latitude');\n latLabel.classList.add('place-label');\n latLabel.appendChild(document.createTextNode('Place Latitude:'));\n var latEl = document.createElement('input');\n latEl.setAttribute('name', 'place-latitude');\n latEl.setAttribute('id', 'place-latitude');\n latEl.setAttribute('type', 'text');\n latEl.value = getLatitudeFromMapboxMarker(marker.getLatLng());\n var lonLabel = document.createElement('label');\n lonLabel.setAttribute('for', 'place-longitude');\n lonLabel.classList.add('place-label');\n lonLabel.appendChild(document.createTextNode('Place Longitude:'));\n var lonEl = document.createElement('input');\n lonEl.setAttribute('name', 'place-longitude');\n lonEl.setAttribute('id', 'place-longitude');\n lonEl.setAttribute('type', 'text');\n lonEl.value = getLongitudeFromMapboxMarker(marker.getLatLng());\n var placeSubmit = document.createElement('button');\n placeSubmit.setAttribute('id', 'place-submit');\n placeSubmit.setAttribute('value', 'Submit New Place');\n placeSubmit.setAttribute('name', 'place-submit');\n placeSubmit.setAttribute('type', 'button');\n placeSubmit.appendChild(document.createTextNode('Submit New Place'));\n form.appendChild(nameLabel);\n form.appendChild(nameEl);\n form.appendChild(descLabel);\n form.appendChild(descEl);\n form.appendChild(latLabel);\n form.appendChild(latEl);\n form.appendChild(lonLabel);\n form.appendChild(lonEl);\n form.appendChild(placeSubmit);\n //the event listener for the new place form\n placeSubmit.addEventListener('click', function () {\n //create the form data to send\n var formData = new FormData();\n formData.append('place-name', document.querySelector('#place-name').value);\n formData.append('place-description', document.querySelector('#place-description').value);\n formData.append('place-latitude', document.querySelector('#place-latitude').value);\n formData.append('place-longitude', document.querySelector('#place-longitude').value);\n //post the new place\n fetch('/places/new', {\n //send cookies with the request\n credentials: 'same-origin',\n method: 'post',\n body: formData\n })\n .then(function (response) {\n return response.json();\n })\n .then(function (placeJson) {\n if (placeJson.error == true) {\n throw new Error(placeJson.error_description);\n }\n //create the slug from the url\n var urlParts = placeJson.split('/');\n var slug = urlParts.pop();\n //remove un-needed form elements\n form.removeChild(document.querySelector('#place-name'));\n form.removeChild(document.querySelector('#place-description'));\n form.removeChild(document.querySelector('#place-latitude'));\n form.removeChild(document.querySelector('#place-longitude'));\n var labels = document.querySelectorAll('.place-label');\n for (var i = 0; i < labels.length; ++i) {\n form.removeChild(labels[i]);\n }\n form.removeChild(document.querySelector('#place-submit'));\n form.removeChild(document.querySelector('#create-new-place'));\n //remove location marker\n map.removeLayer(marker);\n //add place marker\n var newOption = document.createElement('option');\n newOption.setAttribute('value', slug);\n newOption.appendChild(document.createTextNode(placeJson['name']));\n newOption.dataset.latitude = placeJson['latitude'];\n newOption.dataset.longitude = placeJson['longitude'];\n selectEl.appendChild(newOption);\n var newPlaceMarker = L.marker([placeJson['latitude'], placeJson['longitude']], {\n icon: L.mapbox.marker.icon({\n 'marker-size': 'large',\n 'marker-symbol': 'building',\n 'marker-color': '#fa0'\n })\n }).addTo(map);\n var newName = 'Name: ' + placeJson['name'];\n newPlaceMarker.bindPopup(newName, {\n closeButton: true\n });\n newPlaceMarker.on('click', function () {\n map.panTo([placeJson['latitude'], placeJson['longitude']]);\n selectPlace(slug);\n });\n //make selected\n selectPlace(slug);\n }).catch(function (placeError) {\n alertify.reset();\n alertify.error(placeError);\n });\n });\n });\n form.insertBefore(newLocButton, div);\n}\n\nfunction parseLocation(point) {\n var re = /\\((.*)\\)/;\n var resultArray = re.exec(point);\n var location = resultArray[1].split(' ');\n\n return [location[1], location[0]];\n}\n\nfunction selectPlace(slug) {\n document.querySelector('select [value=' + slug + ']').selected = true;\n}\n\nfunction getLatitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[0].replace(',', '');\n}\n\nfunction getLongitudeFromMapboxMarker(latlng) {\n var resultArray = /\\((.*)\\)/.exec(latlng);\n var location = resultArray[1].split(' ');\n\n return location[1];\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/maps/newplace.js.map b/public/assets/js/maps/newplace.js.map new file mode 100644 index 00000000..1a6a5855 --- /dev/null +++ b/public/assets/js/maps/newplace.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["newplace.js"],"names":["getLocation","navigator","geolocation","getCurrentPosition","position","updateForm","coords","latitude","longitude","addMap","inputLatitude","document","querySelector","inputLongitude","value","form","div","createElement","setAttribute","appendChild","L","mapbox","accessToken","map","setView","addLayer","tileLayer","detectRetina","marker","draggable","addTo","on","markerLocation","getLatLng","lat","lng","button","addEventListener","attachEvent"],"mappings":"AASA,QAASA,eACD,eAAiBC,YACjBA,UAAUC,YAAYC,mBAAmB,SAASC,GAC9CC,WAAWD,EAASE,OAAOC,SAAUH,EAASE,OAAOE,WACrDC,OAAOL,EAASE,OAAOC,SAAUH,EAASE,OAAOE,aAK7D,QAASH,YAAWE,EAAUC,GAC1B,GAAIE,GAAgBC,SAASC,cAAc,aACvCC,EAAiBF,SAASC,cAAc,aAC5CF,GAAcI,MAAQP,EACtBM,EAAeC,MAAQN,EAG3B,QAASC,QAAOF,EAAUC,GACtB,GAAIO,GAAOJ,SAASC,cAAc,QAC9BI,EAAML,SAASM,cAAc,MACjCD,GAAIE,aAAa,KAAM,OACvBH,EAAKI,YAAYH,GACjBI,EAAEC,OAAOC,YAAc,wEACvB,IAAIC,GAAMH,EAAEC,OAAOE,IAAI,MAAO,wBACzBC,SAASjB,EAAUC,GAAY,IAC/BiB,SAASL,EAAEC,OAAOK,UAAU,wBACzBC,cAAc,KAElBC,EAASR,EAAEQ,QAAQrB,EAAUC,IAC7BqB,WAAW,IACZC,MAAMP,EACTK,GAAOG,GAAG,UAAW,WACjB,GAAIC,GAAiBJ,EAAOK,WAC5B5B,YAAW2B,EAAeE,IAAKF,EAAeG,OAxCtD,GAAIC,QAASzB,SAASC,cAAc,UAEhCwB,QAAOC,iBACPD,OAAOC,iBAAiB,QAASrC,aAEjCoC,OAAOE,YAAY,UAAWtC","file":"newplace.js","sourcesContent":["/* global L */\nvar button = document.querySelector('#locate');\n\nif (button.addEventListener) {\n button.addEventListener('click', getLocation);\n} else {\n button.attachEvent('onclick', getLocation);\n}\n\nfunction getLocation() {\n if ('geolocation' in navigator) {\n navigator.geolocation.getCurrentPosition(function(position) {\n updateForm(position.coords.latitude, position.coords.longitude);\n addMap(position.coords.latitude, position.coords.longitude);\n });\n }\n}\n\nfunction updateForm(latitude, longitude) {\n var inputLatitude = document.querySelector('#latitude');\n var inputLongitude = document.querySelector('#longitude');\n inputLatitude.value = latitude;\n inputLongitude.value = longitude;\n}\n\nfunction addMap(latitude, longitude) {\n var form = document.querySelector('form');\n var div = document.createElement('div');\n div.setAttribute('id', 'map');\n form.appendChild(div);\n L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w';\n var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim')\n .setView([latitude, longitude], 15)\n .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', {\n detectRetina: true\n }));\n var marker = L.marker([latitude, longitude], {\n draggable: true\n }).addTo(map);\n marker.on('dragend', function () {\n var markerLocation = marker.getLatLng();\n updateForm(markerLocation.lat, markerLocation.lng);\n });\n}\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/public/assets/js/newnote.js b/public/assets/js/newnote.js index 54d2edd5..80ed1088 100644 --- a/public/assets/js/newnote.js +++ b/public/assets/js/newnote.js @@ -1,281 +1,2 @@ -/* global L */ -if ('geolocation' in navigator) { - var button = document.querySelector('#locate'); - if (button.addEventListener) { - //if we have javascript, event listeners and geolocation, make the locate - //button clickable and add event - button.disabled = false; - button.addEventListener('click', getLocation); - } -} - -function getLocation() { - navigator.geolocation.getCurrentPosition(function (position) { - //the locate button has been clicked so add the places/map - addPlaces(position.coords.latitude, position.coords.longitude); - }); -} - -function addPlaces(latitude, longitude) { - //get the nearby places - fetch('/places/near/' + latitude + '/' + longitude, { - credentials: 'same-origin', - method: 'get' - }).then(function (response) { - return response.json(); - }).then(function (j) { - if (j.length > 0) { - var i; - var places = []; - for (i = 0; i < j.length; ++i) { - var latlng = parseLocation(j[i].location); - var name = j[i].name; - var slug = j[i].slug; - places.push([name, slug, latlng[0], latlng[1]]); - } - //add a map with the nearby places - addMap(latitude, longitude, places); - } else { - //add a map with just current location - addMap(latitude, longitude); - } - }).catch(function (err) { - console.error(err); - }); -} - -function addMap(latitude, longitude, places) { - //make places null if not supplied - if (arguments.length == 2) { - places = null; - } - var form = button.parentNode; - var div = document.createElement('div'); - div.setAttribute('id', 'map'); - //add the map div - form.appendChild(div); - L.mapbox.accessToken = 'pk.eyJ1Ijoiam9ubnliYXJuZXMiLCJhIjoiVlpndW1EYyJ9.aP9fxAqLKh7lj0LpFh5k1w'; - var map = L.mapbox.map('map', 'jonnybarnes.gnoihnim') - .setView([latitude, longitude], 15) - .addLayer(L.mapbox.tileLayer('jonnybarnes.gnoihnim', { - detectRetina: true - })); - //add a marker for the current location - var marker = L.marker([latitude, longitude], { - draggable: true - }).addTo(map); - //when the location marker is dragged, if the new place form elements exist - //update the lat/lng values - marker.on('dragend', function () { - var placeFormLatitude = document.querySelector('#place-latitude'); - if (placeFormLatitude !== null) { - placeFormLatitude.value = getLatitudeFromMapboxMarker(marker.getLatLng()); - } - var placeFormLongitude = document.querySelector('#place-longitude'); - if (placeFormLongitude !== null) { - placeFormLongitude.value = getLongitudeFromMapboxMarker(marker.getLatLng()); - } - }); - //create the - places.forEach(function (item) { - var option = document.createElement('option'); - option.setAttribute('value', item[1]); - var text = document.createTextNode(item[0]); - option.appendChild(text); - option.dataset.latitude = item[2]; - option.dataset.longitude = item[3]; - selectEl.appendChild(option); - var placeMarker = L.marker([item[2], item[3]], { - icon: L.mapbox.marker.icon({ - 'marker-size': 'large', - 'marker-symbol': 'building', - 'marker-color': '#fa0' - }) - }).addTo(map); - var name = 'Name: ' + item[0]; - placeMarker.bindPopup(name, { - closeButton: true - }); - placeMarker.on('click', function () { - map.panTo([item[2], item[3]]); - selectPlace(item[1]); - }); - }); - //add an event listener - selectEl.addEventListener('change', function () { - if (selectEl.value !== 'no-location') { - var placeLat = selectEl[selectEl.selectedIndex].dataset.latitude; - var placeLon = selectEl[selectEl.selectedIndex].dataset.longitude; - map.panTo([placeLat, placeLon]); - } - }); - } - //add a button to add a new place - var newLocButton = document.createElement('button'); - newLocButton.setAttribute('type', 'button'); - newLocButton.setAttribute('id', 'create-new-place'); - newLocButton.appendChild(document.createTextNode('Create New Place?')); - //the event listener - newLocButton.addEventListener('click', function() { - //add the form elements - var nameLabel = document.createElement('label'); - nameLabel.setAttribute('for', 'place-name'); - nameLabel.classList.add('place-label'); - nameLabel.appendChild(document.createTextNode('Place Name:')); - var nameEl = document.createElement('input'); - nameEl.setAttribute('placeholder', 'Name'); - nameEl.setAttribute('name', 'place-name'); - nameEl.setAttribute('id', 'place-name'); - nameEl.setAttribute('type', 'text'); - var descLabel = document.createElement('label'); - descLabel.setAttribute('for', 'place-description'); - descLabel.classList.add('place-label'); - descLabel.appendChild(document.createTextNode('Place Description:')); - var descEl = document.createElement('input'); - descEl.setAttribute('placeholder', 'Description'); - descEl.setAttribute('name', 'place-description'); - descEl.setAttribute('id', 'place-description'); - descEl.setAttribute('type', 'text'); - var latLabel = document.createElement('label'); - latLabel.setAttribute('for', 'place-latitude'); - latLabel.classList.add('place-label'); - latLabel.appendChild(document.createTextNode('Place Latitude:')); - var latEl = document.createElement('input'); - latEl.setAttribute('name', 'place-latitude'); - latEl.setAttribute('id', 'place-latitude'); - latEl.setAttribute('type', 'text'); - latEl.value = getLatitudeFromMapboxMarker(marker.getLatLng()); - var lonLabel = document.createElement('label'); - lonLabel.setAttribute('for', 'place-longitude'); - lonLabel.classList.add('place-label'); - lonLabel.appendChild(document.createTextNode('Place Longitude:')); - var lonEl = document.createElement('input'); - lonEl.setAttribute('name', 'place-longitude'); - lonEl.setAttribute('id', 'place-longitude'); - lonEl.setAttribute('type', 'text'); - lonEl.value = getLongitudeFromMapboxMarker(marker.getLatLng()); - var placeSubmit = document.createElement('button'); - placeSubmit.setAttribute('id', 'place-submit'); - placeSubmit.setAttribute('value', 'Submit New Place'); - placeSubmit.setAttribute('name', 'place-submit'); - placeSubmit.setAttribute('type', 'button'); - placeSubmit.appendChild(document.createTextNode('Submit New Place')); - form.appendChild(nameLabel); - form.appendChild(nameEl); - form.appendChild(descLabel); - form.appendChild(descEl); - form.appendChild(latLabel); - form.appendChild(latEl); - form.appendChild(lonLabel); - form.appendChild(lonEl); - form.appendChild(placeSubmit); - //the event listener for the new place form - placeSubmit.addEventListener('click', function () { - //create the form data to send - var formData = new FormData(); - formData.append('place-name', document.querySelector('#place-name').value); - formData.append('place-description', document.querySelector('#place-description').value); - formData.append('place-latitude', document.querySelector('#place-latitude').value); - formData.append('place-longitude', document.querySelector('#place-longitude').value); - //post the new place - fetch('/places/new', { - //send cookies with the request - credentials: 'same-origin', - method: 'post', - body: formData - }) - .then(function (response) { - if (response.status >= 200 && response.status < 300) { - return Promise.resolve(response); - } else { - return Promise.reject(new Error(response.statusText)); - } - }) - .then(function (response) { - return response.json(); - }) - .then(function (placeJson) { - //create the slug from the url - var urlParts = placeJson.split('/'); - var slug = urlParts.pop(); - //remove un-needed form elements - form.removeChild(document.querySelector('#place-name')); - form.removeChild(document.querySelector('#place-description')); - form.removeChild(document.querySelector('#place-latitude')); - form.removeChild(document.querySelector('#place-longitude')); - var labels = document.querySelectorAll('.place-label'); - for (var i = 0; i < labels.length; ++i) { - form.removeChild(labels[i]); - } - form.removeChild(document.querySelector('#place-submit')); - form.removeChild(document.querySelector('#create-new-place')); - //remove location marker - map.removeLayer(marker); - //add place marker - var newOption = document.createElement('option'); - newOption.setAttribute('value', slug); - newOption.appendChild(document.createTextNode(placeJson['name'])); - newOption.dataset.latitude = placeJson['latitude']; - newOption.dataset.longitude = placeJson['longitude']; - selectEl.appendChild(newOption); - var newPlaceMarker = L.marker([placeJson['latitude'], placeJson['longitude']], { - icon: L.mapbox.marker.icon({ - 'marker-size': 'large', - 'marker-symbol': 'building', - 'marker-color': '#fa0' - }) - }).addTo(map); - var newName = 'Name: ' + placeJson['name']; - newPlaceMarker.bindPopup(newName, { - closeButton: true - }); - newPlaceMarker.on('click', function () { - map.panTo([placeJson['latitude'], placeJson['longitude']]); - selectPlace(slug); - }); - //make selected - selectPlace(slug); - }).catch(function (placeError) { - console.error(placeError); - }); - }); - }); - form.insertBefore(newLocButton, div); -} - -function parseLocation(point) { - var re = /\((.*)\)/; - var resultArray = re.exec(point); - var location = resultArray[1].split(' '); - - return [location[1], location[0]]; -} - -function selectPlace(slug) { - document.querySelector('select [value=' + slug + ']').selected = true; -} - -function getLatitudeFromMapboxMarker(latlng) { - var resultArray = /\((.*)\)/.exec(latlng); - var location = resultArray[1].split(' '); - - return location[0].replace(',', ''); -} - -function getLongitudeFromMapboxMarker(latlng) { - var resultArray = /\((.*)\)/.exec(latlng); - var location = resultArray[1].split(' '); - - return location[1]; -} +function getLocation(){navigator.geolocation.getCurrentPosition(function(e){addPlacesMap(e.coords.latitude,e.coords.longitude)})}function addPlacesMap(e,t){fetch("/places/near/"+e+"/"+t,{credentials:"same-origin",method:"get"}).then(function(e){return e.json()}).then(function(a){if(1==a.error&&(alertify.reset(),alertify.error(a.error_description)),a.length>0){var n,r=[];for(n=0;n 0) { var i; var places = []; @@ -195,17 +199,13 @@ function addMap(latitude, longitude, places) { method: 'post', body: formData }) - .then(function (response) { - if (response.status >= 200 && response.status < 300) { - return Promise.resolve(response); - } else { - return Promise.reject(new Error(response.statusText)); - } - }) .then(function (response) { return response.json(); }) .then(function (placeJson) { + if (placeJson.error == true) { + throw new Error(placeJson.error_description); + } //create the slug from the url var urlParts = placeJson.split('/'); var slug = urlParts.pop(); @@ -247,7 +247,8 @@ function addMap(latitude, longitude, places) { //make selected selectPlace(slug); }).catch(function (placeError) { - console.error(placeError); + alertify.reset(); + alertify.error(placeError); }); }); }); diff --git a/tests/MicropubTest.php b/tests/MicropubTest.php index 26addf48..88a9838f 100644 --- a/tests/MicropubTest.php +++ b/tests/MicropubTest.php @@ -116,6 +116,103 @@ class MicropubTest extends TestCase ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] )->seeJson([ 'response' => 'created' + ])->assertResponseStatus(201); + } + + public function testMicropubJSONRequestCreateNewNoteWithoutToken() + { + $faker = \Faker\Factory::create(); + $note = $faker->text; + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'content' => [$note], + ], + ] + )->seeJson([ + 'response' => 'error', + 'error' => 'no_token' + ])->assertResponseStatus(400); + } + + public function testMicropubJSONRequestCreateNewNoteWithInvalidToken() + { + $faker = \Faker\Factory::create(); + $note = $faker->text; + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'content' => [$note], + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getInvalidToken()] + )->seeJson([ + 'response' => 'error', + 'error' => 'invalid_token' + ]); + } + + public function testMicropubJSONRequestCreateNewPlace() + { + $faker = \Faker\Factory::create(); + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => $faker->name, + 'geo' => 'geo:' . $faker->latitude . ',' . $faker->longitude + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + )->seeJson([ + 'response' => 'created' + ])->assertResponseStatus(201); + } + + public function testMicropubJSONRequestCreateNewPlaceWithoutToken() + { + $faker = \Faker\Factory::create(); + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'name' => $faker->name, + 'geo' => 'geo:' . $faker->latitude . ',' . $faker->longitude + ], + ] + )->seeJson([ + 'response' => 'error', + 'error' => 'no_token' + ])->assertResponseStatus(400); + } + + public function testMicropubJSONRequestCreateNewPlaceWithInvalidToken() + { + $faker = \Faker\Factory::create(); + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'name' => $faker->name, + 'geo' => 'geo:' . $faker->latitude . ',' . $faker->longitude + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getInvalidToken()] + )->seeJson([ + 'response' => 'error', + 'error' => 'invalid_token' ]); } @@ -132,4 +229,18 @@ class MicropubTest extends TestCase return $token; } + + private function getInvalidToken() + { + $signer = new Sha256(); + $token = (new Builder()) + ->set('client_id', 'https://quill.p3k.io') + ->set('me', 'https://jonnybarnes.localhost') + ->set('scope', 'view') + ->set('issued_at', time()) + ->sign($signer, env('APP_KEY')) + ->getToken(); + + return $token; + } }