From e320bec8993ee506f7d5d7609b8b4f05f89c8d6b Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 15 Feb 2017 18:34:47 +0000 Subject: [PATCH 001/129] Refactor method names/views for Articles --- app/Http/Controllers/ArticlesController.php | 10 +++++----- .../{articles.blade.php => articles/index.blade.php} | 0 resources/views/{ => articles}/rss.blade.php | 0 .../{article.blade.php => articles/show.blade.php} | 0 routes/web.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) rename resources/views/{articles.blade.php => articles/index.blade.php} (100%) rename resources/views/{ => articles}/rss.blade.php (100%) rename resources/views/{article.blade.php => articles/show.blade.php} (100%) diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php index be0d500c..b88656e8 100644 --- a/app/Http/Controllers/ArticlesController.php +++ b/app/Http/Controllers/ArticlesController.php @@ -12,14 +12,14 @@ class ArticlesController extends Controller * * @return \Illuminate\View\Factory view */ - public function showAllArticles($year = null, $month = null) + public function index($year = null, $month = null) { $articles = Article::where('published', '1') ->date($year, $month) ->orderBy('updated_at', 'desc') ->simplePaginate(5); - return view('articles', compact('articles')); + return view('articles.index', compact('articles')); } /** @@ -27,14 +27,14 @@ class ArticlesController extends Controller * * @return \Illuminate\View\Factory view */ - public function singleArticle($year, $month, $slug) + public function show($year, $month, $slug) { $article = Article::where('titleurl', $slug)->first(); if ($article->updated_at->year != $year || $article->updated_at->month != $month) { throw new \Exception; } - return view('article', compact('article')); + return view('articles.show', compact('article')); } /** @@ -63,7 +63,7 @@ class ArticlesController extends Controller $buildDate = $articles->first()->updated_at->toRssString(); return response() - ->view('rss', compact('articles', 'buildDate'), 200) + ->view('articles.rss', compact('articles', 'buildDate'), 200) ->header('Content-Type', 'application/rss+xml'); } } diff --git a/resources/views/articles.blade.php b/resources/views/articles/index.blade.php similarity index 100% rename from resources/views/articles.blade.php rename to resources/views/articles/index.blade.php diff --git a/resources/views/rss.blade.php b/resources/views/articles/rss.blade.php similarity index 100% rename from resources/views/rss.blade.php rename to resources/views/articles/rss.blade.php diff --git a/resources/views/article.blade.php b/resources/views/articles/show.blade.php similarity index 100% rename from resources/views/article.blade.php rename to resources/views/articles/show.blade.php diff --git a/routes/web.php b/routes/web.php index 6c8a4c36..2121becd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -84,8 +84,8 @@ Route::group(['domain' => config('url.longurl')], function () { //Blog pages using ArticlesController Route::get('blog/s/{id}', 'ArticlesController@onlyIdInURL'); - Route::get('blog/{year?}/{month?}', 'ArticlesController@showAllArticles'); - Route::get('blog/{year}/{month}/{slug}', 'ArticlesController@singleArticle'); + Route::get('blog/{year?}/{month?}', 'ArticlesController@index'); + Route::get('blog/{year}/{month}/{slug}', 'ArticlesController@show'); //micropub new notes page //this needs to be first so `notes/new` doesn't match `notes/{id}` From 5edb495bcbfef105ce2da9ab45d902cb1bd6fca7 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 15 Feb 2017 18:39:39 +0000 Subject: [PATCH 002/129] Refactor method names/views for Notes --- app/Http/Controllers/NotesController.php | 14 +++++++------- .../{notes.blade.php => notes/index.blade.php} | 0 .../views/{note.blade.php => notes/show.blade.php} | 0 .../tagged.blade.php} | 0 routes/web.php | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) rename resources/views/{notes.blade.php => notes/index.blade.php} (100%) rename resources/views/{note.blade.php => notes/show.blade.php} (100%) rename resources/views/{taggednotes.blade.php => notes/tagged.blade.php} (100%) diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index f964e52e..bf222430 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -24,7 +24,7 @@ class NotesController extends Controller * @param Illuminate\Http\Request request; * @return \Illuminte\View\Factory view */ - public function showNotes(Request $request) + public function index(Request $request) { $notes = Note::orderBy('id', 'desc')->with('webmentions', 'place', 'media')->paginate(10); foreach ($notes as $note) { @@ -63,7 +63,7 @@ class NotesController extends Controller $homepage = ($request->path() == '/'); - return view('notes', compact('notes', 'homepage')); + return view('notes.index', compact('notes', 'homepage')); } /** @@ -72,7 +72,7 @@ class NotesController extends Controller * @param string The id of the note * @return \Illuminate\View\Factory view */ - public function singleNote($urlId) + public function show($urlId) { $numbers = new Numbers(); $authorship = new Authorship(); @@ -161,7 +161,7 @@ class NotesController extends Controller } $note->photoURLs = $photoURLs; - return view('note', compact('note', 'replies', 'reposts', 'likes')); + return view('notes.show', compact('note', 'replies', 'reposts', 'likes')); } /** @@ -170,7 +170,7 @@ class NotesController extends Controller * @param string The decimal id of he note * @return \Illuminate\Routing\RedirectResponse redirect */ - public function singleNoteRedirect($decId) + public function redirect($decId) { $numbers = new Numbers(); $realId = $numbers->numto60($decId); @@ -186,7 +186,7 @@ class NotesController extends Controller * @param string The tag * @return \Illuminate\View\Factory view */ - public function taggedNotes($tag) + public function tagged($tag) { $notes = Note::whereHas('tags', function ($query) use ($tag) { $query->where('tag', $tag); @@ -196,7 +196,7 @@ class NotesController extends Controller $note->human_time = $note->updated_at->diffForHumans(); } - return view('taggednotes', compact('notes', 'tag')); + return view('notes.tagged', compact('notes', 'tag')); } /** diff --git a/resources/views/notes.blade.php b/resources/views/notes/index.blade.php similarity index 100% rename from resources/views/notes.blade.php rename to resources/views/notes/index.blade.php diff --git a/resources/views/note.blade.php b/resources/views/notes/show.blade.php similarity index 100% rename from resources/views/note.blade.php rename to resources/views/notes/show.blade.php diff --git a/resources/views/taggednotes.blade.php b/resources/views/notes/tagged.blade.php similarity index 100% rename from resources/views/taggednotes.blade.php rename to resources/views/notes/tagged.blade.php diff --git a/routes/web.php b/routes/web.php index 2121becd..53873c38 100644 --- a/routes/web.php +++ b/routes/web.php @@ -93,10 +93,10 @@ Route::group(['domain' => config('url.longurl')], function () { Route::post('notes/new', 'MicropubClientController@postNewNote'); //Notes pages using NotesController - Route::get('notes', 'NotesController@showNotes'); - Route::get('note/{id}', 'NotesController@singleNoteRedirect'); - Route::get('notes/{id}', 'NotesController@singleNote'); - Route::get('notes/tagged/{tag}', 'NotesController@taggedNotes'); + Route::get('notes', 'NotesController@index'); + Route::get('notes/{id}', 'NotesController@show'); + Route::get('note/{id}', 'NotesController@redirect'); + Route::get('notes/tagged/{tag}', 'NotesController@tagged'); //indieauth Route::any('beginauth', 'IndieAuthController@beginauth'); From 4af305ba3bc601b38ac10dd2e865ea91a414cbbf Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 15 Feb 2017 18:41:54 +0000 Subject: [PATCH 003/129] Refactor method names/views for Contacts --- app/Http/Controllers/ContactsController.php | 8 ++++---- .../{contacts.blade.php => contacts/index.blade.php} | 0 .../views/{contact.blade.php => contacts/show.blade.php} | 0 routes/web.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename resources/views/{contacts.blade.php => contacts/index.blade.php} (100%) rename resources/views/{contact.blade.php => contacts/show.blade.php} (100%) diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index 7824ef62..46573423 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -12,7 +12,7 @@ class ContactsController extends Controller * * @return \Illuminate\View\Factory view */ - public function showAll() + public function index() { $filesystem = new Filesystem(); $contacts = Contact::all(); @@ -25,7 +25,7 @@ class ContactsController extends Controller '/assets/profile-images/default-image'; } - return view('contacts', compact('contacts')); + return view('contacts.index', compact('contacts')); } /** @@ -33,7 +33,7 @@ class ContactsController extends Controller * * @return \Illuminate\View\Factory view */ - public function showSingle($nick) + public function show($nick) { $filesystem = new Filesystem(); $contact = Contact::where('nick', '=', $nick)->firstOrFail(); @@ -44,6 +44,6 @@ class ContactsController extends Controller : '/assets/profile-images/default-image'; - return view('contact', ['contact' => $contact]); + return view('contacts.show', ['contact' => $contact]); } } diff --git a/resources/views/contacts.blade.php b/resources/views/contacts/index.blade.php similarity index 100% rename from resources/views/contacts.blade.php rename to resources/views/contacts/index.blade.php diff --git a/resources/views/contact.blade.php b/resources/views/contacts/show.blade.php similarity index 100% rename from resources/views/contact.blade.php rename to resources/views/contacts/show.blade.php diff --git a/routes/web.php b/routes/web.php index 53873c38..5f732f3e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -118,8 +118,8 @@ Route::group(['domain' => config('url.longurl')], function () { Route::post('webmention', 'WebMentionsController@receive'); //Contacts - Route::get('contacts', 'ContactsController@showAll'); - Route::get('contacts/{nick}', 'ContactsController@showSingle'); + Route::get('contacts', 'ContactsController@index'); + Route::get('contacts/{nick}', 'ContactsController@show'); //Places Route::get('places', 'PlacesController@index'); From e032cd5861726f9b77175095aa4dad95b895c04e Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 15 Feb 2017 20:19:11 +0000 Subject: [PATCH 004/129] Refactor method names/views for the Micropub Client --- .../Controllers/MicropubClientController.php | 22 ++++++++----------- .../create.blade.php} | 4 +--- routes/web.php | 12 +++++----- 3 files changed, 16 insertions(+), 22 deletions(-) rename resources/views/{micropubnewnotepage.blade.php => micropub/create.blade.php} (91%) diff --git a/app/Http/Controllers/MicropubClientController.php b/app/Http/Controllers/MicropubClientController.php index 92848aa5..665cd45f 100644 --- a/app/Http/Controllers/MicropubClientController.php +++ b/app/Http/Controllers/MicropubClientController.php @@ -36,15 +36,12 @@ class MicropubClientController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\View\Factory view */ - public function newNotePage(Request $request) + public function create(Request $request) { $url = $request->session()->get('me'); $syndication = $request->session()->get('syndication'); - return view('micropubnewnotepage', [ - 'url' => $url, - 'syndication' => $syndication, - ]); + return view('micropub.create', compact('url', 'syndication')); } /** @@ -55,7 +52,7 @@ class MicropubClientController extends Controller * @param \Illuminate\Http\Request $request * @return mixed */ - public function postNewNote(Request $request) + public function store(Request $request) { $domain = $request->session()->get('me'); $token = $request->session()->get('token'); @@ -65,7 +62,7 @@ class MicropubClientController extends Controller $this->indieClient ); if (! $micropubEndpoint) { - return redirect('notes/new')->withErrors('Unable to determine micropub API endpoint', 'endpoint'); + return redirect(route('micropub-client'))->withErrors('Unable to determine micropub API endpoint', 'endpoint'); } $response = $this->postNoteRequest($request, $micropubEndpoint, $token); @@ -79,7 +76,7 @@ class MicropubClientController extends Controller return redirect($location); } - return redirect('notes/new')->withErrors('Endpoint didn’t create the note.', 'endpoint'); + return redirect(route('micropub-client'))->withErrors('Endpoint didn’t create the note.', 'endpoint'); } /** @@ -99,9 +96,8 @@ class MicropubClientController extends Controller $domain = $request->session()->get('me'); $token = $request->session()->get('token'); $micropubEndpoint = $this->indieAuthService->discoverMicropubEndpoint($domain, $this->indieClient); - if (! $micropubEndpoint) { - return redirect('notes/new')->withErrors('Unable to determine micropub API endpoint', 'endpoint'); + return redirect(route('micropub-client'))->withErrors('Unable to determine micropub API endpoint', 'endpoint'); } try { @@ -110,14 +106,14 @@ class MicropubClientController extends Controller 'query' => ['q' => 'syndicate-to'], ]); } catch (\GuzzleHttp\Exception\BadResponseException $e) { - return redirect('notes/new')->withErrors('Bad response when refreshing syndication targets', 'endpoint'); + return redirect(route('micropub-client'))->withErrors('Bad response when refreshing syndication targets', 'endpoint'); } $body = (string) $response->getBody(); $syndication = $this->parseSyndicationTargets($body); $request->session()->put('syndication', $syndication); - return redirect('notes/new'); + return redirect(route('micropub-client')); } /** @@ -184,7 +180,7 @@ class MicropubClientController extends Controller 'headers' => $headers, ]); } catch (\GuzzleHttp\Exception\BadResponseException $e) { - return redirect('notes/new') + return redirect(route('micropub-client')) ->withErrors('There was a bad response from the micropub endpoint.', 'endpoint'); } diff --git a/resources/views/micropubnewnotepage.blade.php b/resources/views/micropub/create.blade.php similarity index 91% rename from resources/views/micropubnewnotepage.blade.php rename to resources/views/micropub/create.blade.php index 48837ff8..bc44d769 100644 --- a/resources/views/micropubnewnotepage.blade.php +++ b/resources/views/micropub/create.blade.php @@ -26,7 +26,7 @@ New Note « @endif @include('templates.new-note-form', [ 'micropub' => true, - 'action' => '/notes/new' + 'action' => route('micropub-client-post') ]) @stop @@ -35,8 +35,6 @@ New Note « window.Promise || document.write(' - diff --git a/routes/web.php b/routes/web.php index 5f732f3e..174375c3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,7 +12,7 @@ */ Route::group(['domain' => config('url.longurl')], function () { - Route::get('/', 'NotesController@showNotes'); + Route::get('/', 'NotesController@index'); //Static project page Route::get('projects', function () { @@ -89,8 +89,7 @@ Route::group(['domain' => config('url.longurl')], function () { //micropub new notes page //this needs to be first so `notes/new` doesn't match `notes/{id}` - Route::get('notes/new', 'MicropubClientController@newNotePage'); - Route::post('notes/new', 'MicropubClientController@postNewNote'); + //Notes pages using NotesController Route::get('notes', 'NotesController@index'); @@ -104,10 +103,11 @@ Route::group(['domain' => config('url.longurl')], function () { Route::post('api/token', 'IndieAuthController@tokenEndpoint'); Route::get('logout', 'IndieAuthController@indieauthLogout'); - //micropub endoints - Route::post('api/post', 'MicropubController@post'); + // Micropub + Route::get('micropub/create', 'MicropubClientController@create')->name('micropub-client'); + Route::post('micropub', 'MicropubClientController@store')->name('micropub-client-post'); Route::get('api/post', 'MicropubController@getEndpoint'); - + Route::post('api/post', 'MicropubController@post'); //micropub refresh syndication targets Route::get('refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets'); From b4df7a1bbbca8b61ed4b690e987802d22536b464 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 15 Feb 2017 20:44:03 +0000 Subject: [PATCH 005/129] Convert all env() calls to config() calls --- app/Console/Commands/GenerateToken.php | 4 ++-- app/Http/Controllers/AdminController.php | 2 +- app/Http/Controllers/AuthController.php | 4 ++-- app/Http/Middleware/DevTokenMiddleware.php | 2 +- app/Jobs/SendWebMentions.php | 2 +- app/Services/TokenService.php | 4 ++-- config/admin.php | 25 ++++++++++++++++++++++ config/app.php | 24 ++++++++++++++++++++- resources/views/articles/rss.blade.php | 2 +- resources/views/master.blade.php | 6 +++--- 10 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 config/admin.php diff --git a/app/Console/Commands/GenerateToken.php b/app/Console/Commands/GenerateToken.php index dc07e917..9299206c 100644 --- a/app/Console/Commands/GenerateToken.php +++ b/app/Console/Commands/GenerateToken.php @@ -47,8 +47,8 @@ class GenerateToken extends Command public function handle(TokenService $tokenService) { $data = [ - 'me' => env('APP_URL'), - 'client_id' => env('APP_URL') . '/notes/new', + 'me' => config('app.url'), + 'client_id' => config('app.url') . '/notes/new', 'scope' => 'post', ]; $token = $tokenService->getNewToken($data); diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 7cb338e6..a587c266 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -20,7 +20,7 @@ class AdminController extends Controller */ public function __construct() { - $this->username = env('ADMIN_USER'); + $this->username = config('admin.user'); } /** diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index f752fa21..36be2076 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -15,9 +15,9 @@ class AuthController extends Controller */ public function login(Request $request) { - if ($request->input('username') === env('ADMIN_USER') + if ($request->input('username') === config('admin.user') && - $request->input('password') === env('ADMIN_PASS') + $request->input('password') === config('admin.pass') ) { session(['loggedin' => true]); diff --git a/app/Http/Middleware/DevTokenMiddleware.php b/app/Http/Middleware/DevTokenMiddleware.php index b1d5e02e..a711142b 100644 --- a/app/Http/Middleware/DevTokenMiddleware.php +++ b/app/Http/Middleware/DevTokenMiddleware.php @@ -17,7 +17,7 @@ class DevTokenMiddleware public function handle($request, Closure $next) { if (config('app.env') !== 'production') { - session(['me' => env('APP_URL')]); + session(['me' => config('app.url')]); if (Storage::exists('dev-token')) { session(['token' => Storage::get('dev-token')]); } diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index 41bd499b..dd4e2835 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -61,7 +61,7 @@ class SendWebMentions implements ShouldQueue public function discoverWebmentionEndpoint($url, $guzzle) { //let’s not send webmentions to myself - if (parse_url($url, PHP_URL_HOST) == env('LONG_URL', 'localhost')) { + if (parse_url($url, PHP_URL_HOST) == config('app.longurl')) { return false; } if (starts_with($url, '/notes/tagged/')) { diff --git a/app/Services/TokenService.php b/app/Services/TokenService.php index 4652d30b..1cabd925 100644 --- a/app/Services/TokenService.php +++ b/app/Services/TokenService.php @@ -24,7 +24,7 @@ class TokenService ->set('scope', $data['scope']) ->set('date_issued', time()) ->set('nonce', bin2hex(random_bytes(8))) - ->sign($signer, env('APP_KEY')) + ->sign($signer, config('app.key')) ->getToken(); return $token; @@ -46,7 +46,7 @@ class TokenService } catch (RuntimeException $e) { return; } - if ($token->verify($signer, env('APP_KEY'))) { + if ($token->verify($signer, config('app.key'))) { //signuture valid return $token; } diff --git a/config/admin.php b/config/admin.php new file mode 100644 index 00000000..b11b7dd5 --- /dev/null +++ b/config/admin.php @@ -0,0 +1,25 @@ + env('ADMIN_NAME'), + + /* + |-------------------------------------------------------------------------- + | Admin Password + |-------------------------------------------------------------------------- + | + | The password of the admin account. + */ + + 'pass' => env('ADMIN_PASS'), + +]; diff --git a/config/app.php b/config/app.php index ed3364de..57d672d9 100644 --- a/config/app.php +++ b/config/app.php @@ -53,6 +53,17 @@ return [ 'url' => env('APP_URL', 'http://localhost'), + /* + |-------------------------------------------------------------------------- + | Application Long URL + |-------------------------------------------------------------------------- + | + | The short URL for the application + | + */ + + 'longurl' => env('APP_LONGURL', 'longurl.local'), + /* |-------------------------------------------------------------------------- | Application Short URL @@ -62,7 +73,18 @@ return [ | */ - 'shorturl' => env('APP_SHORTURL', 'http://shorturl.local'), + 'shorturl' => env('APP_SHORTURL', 'shorturl.local'), + + /* + |-------------------------------------------------------------------------- + | Application Display Name + |-------------------------------------------------------------------------- + | + | The display name for the application, used for example in titles. + | + */ + + 'display_name' => env('DISPLAY_NAME', 'Joe Bloggs'), /* |-------------------------------------------------------------------------- diff --git a/resources/views/articles/rss.blade.php b/resources/views/articles/rss.blade.php index f6c0253f..792d8989 100644 --- a/resources/views/articles/rss.blade.php +++ b/resources/views/articles/rss.blade.php @@ -1,7 +1,7 @@ - {{ env('DISPLAY_NAME') }} + {{ config('app.display_name') }} An RSS feed of the blog posts found on {{ config('url.longurl') }} {{ config('app.url') }} diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index b5f67954..321a8492 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -2,7 +2,7 @@ - @if (App::environment() == 'local'){!! "[testing] -"!!}@endif @yield('title'){{ env('DISPLAY_NAME') }} + @if (App::environment() == 'local'){!! "[testing] -"!!}@endif @yield('title'){{ config('app.display_name') }} @@ -18,7 +18,7 @@