2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
use App\Models\Note;
|
2020-08-09 15:54:10 +01:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2019-10-27 19:31:33 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2019-10-27 19:31:33 +00:00
|
|
|
use Illuminate\Http\Response;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\View\View;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Jonnybarnes\IndieWeb\Numbers;
|
|
|
|
|
2023-07-28 11:48:07 +01:00
|
|
|
/**
|
|
|
|
* @todo Need to sort out Twitter and webmentions!
|
2023-07-28 12:05:11 +01:00
|
|
|
*
|
2023-07-28 11:48:07 +01:00
|
|
|
* @psalm-suppress UnusedClass
|
|
|
|
*/
|
2016-05-19 15:01:28 +01:00
|
|
|
class NotesController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2017-09-11 15:56:47 +01:00
|
|
|
* Show all the notes. This is also the homepage.
|
2016-05-19 15:01:28 +01:00
|
|
|
*/
|
2023-07-28 11:48:07 +01:00
|
|
|
public function index(): View|Response
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-09-16 18:27:02 +01:00
|
|
|
$notes = Note::latest()
|
2017-06-22 14:30:10 +01:00
|
|
|
->with('place', 'media', 'client')
|
2023-11-25 16:08:07 +00:00
|
|
|
->withCount(['webmentions AS replies' => function ($query) {
|
2017-06-22 14:30:10 +01:00
|
|
|
$query->where('type', 'in-reply-to');
|
2023-11-25 16:08:07 +00:00
|
|
|
}])
|
|
|
|
->withCount(['webmentions AS likes' => function ($query) {
|
|
|
|
$query->where('type', 'like-of');
|
|
|
|
}])
|
|
|
|
->withCount(['webmentions AS reposts' => function ($query) {
|
|
|
|
$query->where('type', 'repost-of');
|
2017-06-22 14:30:10 +01:00
|
|
|
}])->paginate(10);
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-09-16 18:45:06 +01:00
|
|
|
return view('notes.index', compact('notes'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a single note.
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function show(string $urlId): View|JsonResponse|Response
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2020-08-09 15:54:10 +01:00
|
|
|
try {
|
2023-11-25 16:08:07 +00:00
|
|
|
$note = Note::nb60($urlId)->with('place', 'media', 'client')
|
|
|
|
->withCount(['webmentions AS replies' => function ($query) {
|
|
|
|
$query->where('type', 'in-reply-to');
|
|
|
|
}])
|
|
|
|
->withCount(['webmentions AS likes' => function ($query) {
|
|
|
|
$query->where('type', 'like-of');
|
|
|
|
}])
|
|
|
|
->withCount(['webmentions AS reposts' => function ($query) {
|
|
|
|
$query->where('type', 'repost-of');
|
|
|
|
}])->firstOrFail();
|
2020-08-09 15:54:10 +01:00
|
|
|
} catch (ModelNotFoundException $exception) {
|
|
|
|
abort(404);
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-09-16 18:45:06 +01:00
|
|
|
return view('notes.show', compact('note'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect /note/{decID} to /notes/{nb60id}.
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
public function redirect(int $decId): RedirectResponse
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-06-22 15:57:31 +01:00
|
|
|
return redirect(config('app.url') . '/notes/' . (new Numbers())->numto60($decId));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show all notes tagged with {tag}.
|
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
public function tagged(string $tag): View
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2016-05-29 13:49:30 +01:00
|
|
|
$notes = Note::whereHas('tags', function ($query) use ($tag) {
|
|
|
|
$query->where('tag', $tag);
|
|
|
|
})->get();
|
2016-05-19 15:01:28 +01:00
|
|
|
|
2017-02-15 18:39:39 +00:00
|
|
|
return view('notes.tagged', compact('notes', 'tag'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
2022-08-13 16:00:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Page to create a new note.
|
|
|
|
*
|
|
|
|
* Dummy page for now.
|
|
|
|
*/
|
|
|
|
public function create(): View
|
|
|
|
{
|
|
|
|
return view('notes.create');
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|