1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-29 11:15:09 +00:00
pixelfed/app/Http/Controllers/MicroController.php

68 lines
1.6 KiB
PHP
Raw Normal View History

2019-01-31 19:53:01 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\{
Profile,
Status,
};
use Auth, DB, Purify;
use Illuminate\Validation\Rule;
class MicroController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function composeText(Request $request)
{
$this->validate($request, [
'type' => [
'required',
'string',
Rule::in(['text'])
],
'title' => 'nullable|string|max:140',
'content' => 'required|string|max:500',
'visibility' => [
'required',
'string',
Rule::in([
'public',
'unlisted',
'private',
'draft'
])
]
]);
$profile = Auth::user()->profile;
$title = $request->input('title');
$content = $request->input('content');
$visibility = $request->input('visibility');
$status = DB::transaction(function() use($profile, $content, $visibility, $title) {
$status = new Status;
$status->type = 'text';
$status->profile_id = $profile->id;
$status->caption = strip_tags($content);
$status->rendered = Purify::clean($content);
$status->is_nsfw = false;
// TODO: remove deprecated visibility in favor of scope
$status->visibility = $visibility;
$status->scope = $visibility;
$status->entities = json_encode(['title'=>$title]);
$status->save();
return $status;
});
$fractal = new \League\Fractal\Manager();
$fractal->setSerializer(new \League\Fractal\Serializer\ArraySerializer());
$s = new \League\Fractal\Resource\Item($status, new \App\Transformer\Api\StatusTransformer());
return $fractal->createData($s)->toArray();
}
}