commit c835e6e220950dd2f95976eae2a50f71a1c532d1 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Nov 7 11:49:26 2016 +0000 Change visibilty of a method commit e67d6bfd54cb677e738f934544e0c45c3de59891 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Nov 6 19:42:07 2016 +0000 Edit method to send webmentions using the new job method commit fe9839572148b644c5e0e0f32f639650ffbb968c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Nov 6 19:10:32 2016 +0000 Updated changelog commit 1b09744404459e7a6a164788f09ebcc6468b7055 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sun Nov 6 19:08:45 2016 +0000 Allow notes to be deleted
132 lines
3.2 KiB
PHP
132 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Note;
|
|
use Validator;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\NoteService;
|
|
use App\Jobs\SendWebMentions;
|
|
|
|
class NotesAdminController extends Controller
|
|
{
|
|
protected $noteService;
|
|
|
|
public function __construct(NoteService $noteService = null)
|
|
{
|
|
$this->noteService = $noteService ?? new NoteService();
|
|
}
|
|
|
|
/**
|
|
* Show the form to make a new note.
|
|
*
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function newNotePage()
|
|
{
|
|
return view('admin.newnote');
|
|
}
|
|
|
|
/**
|
|
* List the notes that can be edited.
|
|
*
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function listNotesPage()
|
|
{
|
|
$notes = Note::select('id', 'note')->orderBy('id', 'desc')->get();
|
|
foreach ($notes as $note) {
|
|
$note->originalNote = $note->getOriginal('note');
|
|
}
|
|
|
|
return view('admin.listnotes', ['notes' => $notes]);
|
|
}
|
|
|
|
/**
|
|
* The delete note page.
|
|
*
|
|
* @param int id
|
|
* @return view
|
|
*/
|
|
public function deleteNotePage($id)
|
|
{
|
|
return view('admin.deletenote', ['id' => $id]);
|
|
}
|
|
|
|
/**
|
|
* Display the form to edit a specific note.
|
|
*
|
|
* @param string The note id
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function editNotePage($noteId)
|
|
{
|
|
$note = Note::find($noteId);
|
|
$note->originalNote = $note->getOriginal('note');
|
|
|
|
return view('admin.editnote', ['id' => $noteId, 'note' => $note]);
|
|
}
|
|
|
|
/**
|
|
* Process a request to make a new note.
|
|
*
|
|
* @param Illuminate\Http\Request $request
|
|
* @todo Sort this mess out
|
|
*/
|
|
public function createNote(Request $request)
|
|
{
|
|
$validator = Validator::make(
|
|
$request->all(),
|
|
['photo' => 'photosize'],
|
|
['photosize' => 'At least one uploaded file exceeds size limit of 5MB']
|
|
);
|
|
if ($validator->fails()) {
|
|
return redirect('/admin/note/new')
|
|
->withErrors($validator)
|
|
->withInput();
|
|
}
|
|
|
|
$note = $this->noteService->createNote($request);
|
|
|
|
return view('admin.newnotesuccess', [
|
|
'id' => $note->id,
|
|
'shorturl' => $note->shorturl,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Process a request to edit a note. Easy since this can only be done
|
|
* from the admin CP.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function editNote($noteId, Request $request)
|
|
{
|
|
//update note data
|
|
$note = Note::findOrFail($noteId);
|
|
$note->note = $request->input('content');
|
|
$note->in_reply_to = $request->input('in-reply-to');
|
|
$note->save();
|
|
|
|
if ($request->input('webmentions')) {
|
|
dispatch(new SendWebMentions($note));
|
|
}
|
|
|
|
return view('admin.editnotesuccess', ['id' => $noteId]);
|
|
}
|
|
|
|
/**
|
|
* Delete the note.
|
|
*
|
|
* @param int id
|
|
* @return view
|
|
*/
|
|
public function deleteNote($id)
|
|
{
|
|
$note = Note::findOrFail($id);
|
|
$note->delete();
|
|
|
|
return view('admin.deletenotesuccess');
|
|
}
|
|
}
|