[UI][NOTE] Post and see attachments
This commit is contained in:
parent
a5cf89674e
commit
6ed89c77f4
|
@ -24,8 +24,12 @@ use App\Core\Event;
|
||||||
use App\Core\Form;
|
use App\Core\Form;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Core\Module;
|
use App\Core\Module;
|
||||||
|
use App\Core\Security;
|
||||||
|
use App\Entity\FileToNote;
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
|
use Component\Media\Media;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
|
||||||
|
@ -33,12 +37,16 @@ class Posting extends Module
|
||||||
{
|
{
|
||||||
public function onStartTwigPopulateVars(array &$vars)
|
public function onStartTwigPopulateVars(array &$vars)
|
||||||
{
|
{
|
||||||
|
if (Common::user() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$request = $vars['request'];
|
$request = $vars['request'];
|
||||||
$form = Form::create([
|
$form = Form::create([
|
||||||
['content', TextareaType::class, ['label' => ' ']],
|
['content', TextareaType::class, ['label' => ' ']],
|
||||||
['send', SubmitType::class, ['label' => _m('Send')]],
|
['attachments', FileType::class, ['label' => _m('Attachments'), 'multiple' => true, 'required' => false]],
|
||||||
|
['send', SubmitType::class, ['label' => _m('Send')]],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
if ($form->isSubmitted()) {
|
if ($form->isSubmitted()) {
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
@ -46,7 +54,20 @@ class Posting extends Module
|
||||||
$content = $data['content'];
|
$content = $data['content'];
|
||||||
$id = Common::actor()->getId();
|
$id = Common::actor()->getId();
|
||||||
$note = Note::create(['gsactor_id' => $id, 'content' => $content]);
|
$note = Note::create(['gsactor_id' => $id, 'content' => $content]);
|
||||||
|
$files = [];
|
||||||
|
foreach ($data['attachments'] as $f) {
|
||||||
|
$nf = Media::validateAndStoreFile($f, Common::config('attachments', 'dir'),
|
||||||
|
Security::sanitize($title = $f->getClientOriginalName()),
|
||||||
|
$is_local = true, $actor_id = $id);
|
||||||
|
$files[] = $nf;
|
||||||
|
DB::persist($nf);
|
||||||
|
}
|
||||||
DB::persist($note);
|
DB::persist($note);
|
||||||
|
// Need file and note ids for the next step
|
||||||
|
DB::flush();
|
||||||
|
foreach ($files as $f) {
|
||||||
|
DB::persist(FileToNote::create(['file_id' => $f->getId(), 'note_id' => $note->getId()]));
|
||||||
|
}
|
||||||
DB::flush();
|
DB::flush();
|
||||||
} else {
|
} else {
|
||||||
// TODO Display error
|
// TODO Display error
|
||||||
|
|
|
@ -38,11 +38,24 @@ class NetworkPublic extends Controller
|
||||||
{
|
{
|
||||||
public function handle(Request $request)
|
public function handle(Request $request)
|
||||||
{
|
{
|
||||||
$notes = DB::findBy('note', [], ['created' => 'DESC']);
|
$notes = DB::findBy('note', [], ['created' => 'DESC']);
|
||||||
|
$attachments = [];
|
||||||
|
foreach ($notes as $n) {
|
||||||
|
$a = DB::dql(
|
||||||
|
'select f from App\Entity\File f ' .
|
||||||
|
'join App\Entity\FileToNote ftn with ftn.file_id = f.id ' .
|
||||||
|
'where ftn.note_id = :note_id',
|
||||||
|
['note_id' => $n->getId()]
|
||||||
|
);
|
||||||
|
$attachments[] = $a;
|
||||||
|
}
|
||||||
|
if ($notes === []) {
|
||||||
|
$notes = null;
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'_template' => 'network/public.html.twig',
|
'_template' => 'network/public.html.twig',
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
|
'attachments' => array_reverse($attachments),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ class UserPanel extends AbstractController
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
$sfile = $file_title = null;
|
$sfile = null;
|
||||||
if (isset($data['hidden'])) {
|
if (isset($data['hidden'])) {
|
||||||
// Cropped client side
|
// Cropped client side
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
@ -125,12 +125,7 @@ class UserPanel extends AbstractController
|
||||||
$data_user = base64_decode($data_user);
|
$data_user = base64_decode($data_user);
|
||||||
$filename = tempnam('/tmp/', 'avatar');
|
$filename = tempnam('/tmp/', 'avatar');
|
||||||
file_put_contents($filename, $data_user);
|
file_put_contents($filename, $data_user);
|
||||||
try {
|
$sfile = new SymfonyFile($filename);
|
||||||
$sfile = new SymfonyFile($filename);
|
|
||||||
$file_title = $data['avatar']->getFilename();
|
|
||||||
} finally {
|
|
||||||
// fclose($tmp_file);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Log::info('Avatar upload got an invalid encoding, something\'s fishy and/or wrong');
|
Log::info('Avatar upload got an invalid encoding, something\'s fishy and/or wrong');
|
||||||
}
|
}
|
||||||
|
@ -143,7 +138,7 @@ class UserPanel extends AbstractController
|
||||||
}
|
}
|
||||||
$actor = Common::actor();
|
$actor = Common::actor();
|
||||||
$actor_id = $actor->getId();
|
$actor_id = $actor->getId();
|
||||||
$file = Media::validateAndStoreFile($sfile, Common::config('avatar', 'dir'), $file_title, $is_local = true, $use_unique = $actor_id);
|
$file = Media::validateAndStoreFile($sfile, Common::config('avatar', 'dir'), $title = null, $is_local = true, $use_unique = $actor_id);
|
||||||
$old_file = null;
|
$old_file = null;
|
||||||
$avatar = DB::find('avatar', ['gsactor_id' => $actor_id]);
|
$avatar = DB::find('avatar', ['gsactor_id' => $actor_id]);
|
||||||
// Must get old id before inserting another one
|
// Must get old id before inserting another one
|
||||||
|
|
|
@ -52,9 +52,11 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="note-post">
|
{% if post_form is defined %}
|
||||||
{{ form(post_form) }}
|
<div class="note-post">
|
||||||
</div>
|
{{ form(post_form) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="timeline-nav">
|
<div class="timeline-nav">
|
||||||
<div class="notes">
|
<div class="notes">
|
||||||
{% if notes is defined %}
|
{% if notes is defined %}
|
||||||
|
@ -63,6 +65,12 @@
|
||||||
<img src="{{ note.getAvatarUrl() }}" alt="{{ note.getActorNickname() }}'s avatar" width="64px">
|
<img src="{{ note.getAvatarUrl() }}" alt="{{ note.getActorNickname() }}'s avatar" width="64px">
|
||||||
<b>{{ note.getActorNickname() }}</b>
|
<b>{{ note.getActorNickname() }}</b>
|
||||||
<div>{{ note.getContent() }}</div>
|
<div>{{ note.getContent() }}</div>
|
||||||
|
{% set id = note.getId() - 1 %}
|
||||||
|
{% for attachment in attachments[id] %}
|
||||||
|
<div>
|
||||||
|
<i> {{ attachment.getTitle() }} </i>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user