Initial commit to new repo
This commit is contained in:
parent
a267f9bfcc
commit
a5173c981b
292 changed files with 17472 additions and 0 deletions
67
app/Services/NoteService.php
Normal file
67
app/Services/NoteService.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Note;
|
||||
use App\Place;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Jobs\SyndicateToTwitter;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Http\Controllers\WebMentionsController;
|
||||
|
||||
class NoteService
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* Create a new note.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $clientId
|
||||
* @return \App\Note $note
|
||||
*/
|
||||
public function createNote(Request $request, $clientId = null)
|
||||
{
|
||||
$note = Note::create(
|
||||
[
|
||||
'note' => $request->input('content'),
|
||||
'in_reply_to' => $request->input('in-reply-to'),
|
||||
'client_id' => $clientId,
|
||||
]
|
||||
);
|
||||
|
||||
$placeSlug = $request->input('location');
|
||||
if ($placeSlug !== null && $placeSlug !== 'no-location') {
|
||||
$place = Place::where('slug', '=', $placeSlug)->first();
|
||||
$note->place()->associate($place);
|
||||
$note->save();
|
||||
}
|
||||
|
||||
//add images to media library
|
||||
if ($request->hasFile('photo')) {
|
||||
$files = $request->file('photo');
|
||||
foreach ($files as $file) {
|
||||
$note->addMedia($file)->toMediaLibraryOnDisk('images', 's3');
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->input('webmentions')) {
|
||||
$wmc = new WebMentionsController();
|
||||
$wmc->send($note);
|
||||
}
|
||||
|
||||
if (//micropub request, syndication sent as array
|
||||
(is_array($request->input('mp-syndicate-to'))
|
||||
&&
|
||||
(in_array('twitter.com/jonnybarnes', $request->input('mp-syndicate-to')))
|
||||
|| //micropub request, syndication sent as string
|
||||
($request->input('mp-syndicate-to') == 'twitter.com/jonnybarnes')
|
||||
|| //local admin cp request
|
||||
($request->input('twitter') == true))
|
||||
) {
|
||||
$this->dispatch(new SyndicateToTwitter($note));
|
||||
}
|
||||
|
||||
return $note;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue