jonnybarnes.uk/app/Http/Controllers/NotesController.php
Jonny Barnes 309864ba76 Squashed commit of the following:
commit f02ac2b94326054a842a65ed5a2b851351c1d533
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sat Sep 16 18:44:52 2017 +0100

    update changelog

commit 2e77668cae03246189d8ce931f9ab29d2531d522
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sat Sep 16 18:44:45 2017 +0100

    Add a middleware for adding AS2.0 header links

commit 931ba1fe5dd2eacf32e4da3eefec081173dee8de
Author: Jonny Barnes <jonny@jonnybarnes.uk>
Date:   Sat Sep 16 18:44:16 2017 +0100

    remove references to AS2.0 links
2017-09-16 18:45:06 +01:00

76 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Note;
use Illuminate\Http\Request;
use Jonnybarnes\IndieWeb\Numbers;
use App\Services\ActivityStreamsService;
// Need to sort out Twitter and webmentions!
class NotesController extends Controller
{
/**
* Show all the notes. This is also the homepage.
*
* @return \Illuminte\View\Factory view
*/
public function index()
{
if (request()->wantsActivityStream()) {
return (new ActivityStreamsService)->siteOwnerResponse();
}
$notes = Note::latest()
->with('place', 'media', 'client')
->withCount(['webmentions As replies' => function ($query) {
$query->where('type', 'in-reply-to');
}])->paginate(10);
return view('notes.index', compact('notes'));
}
/**
* Show a single note.
*
* @param string The id of the note
* @return \Illuminate\View\Factory view
*/
public function show($urlId)
{
$note = Note::nb60($urlId)->with('webmentions')->firstOrFail();
if (request()->wantsActivityStream()) {
return (new ActivityStreamsService)->singleNoteResponse($note);
}
return view('notes.show', compact('note'));
}
/**
* Redirect /note/{decID} to /notes/{nb60id}.
*
* @param string The decimal id of he note
* @return \Illuminate\Routing\RedirectResponse redirect
*/
public function redirect($decId)
{
return redirect(config('app.url') . '/notes/' . (new Numbers())->numto60($decId));
}
/**
* Show all notes tagged with {tag}.
*
* @param string The tag
* @return \Illuminate\View\Factory view
*/
public function tagged($tag)
{
$notes = Note::whereHas('tags', function ($query) use ($tag) {
$query->where('tag', $tag);
})->get();
return view('notes.tagged', compact('notes', 'tag'));
}
}