forked from GNUsocial/gnu-social
[AttachmentToNote][Attachment] Add title getter to Attachment
This commit is contained in:
parent
c12eacc758
commit
9781ddc8e0
@ -126,7 +126,11 @@ class ImageEncoder extends Plugin
|
||||
*/
|
||||
public function onViewAttachmentImage(array $vars, array &$res): bool
|
||||
{
|
||||
$res[] = Formatting::twigRenderFile('imageEncoder/imageEncoderView.html.twig', ['attachment' => $vars['attachment'], 'thumbnail_parameters' => $vars['thumbnail_parameters']]);
|
||||
$res[] = Formatting::twigRenderFile('imageEncoder/imageEncoderView.html.twig',
|
||||
['attachment' => $vars['attachment'],
|
||||
'thumbnail_parameters' => $vars['thumbnail_parameters'],
|
||||
'note' => $vars['note'],
|
||||
]);
|
||||
return Event::stop;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
<img class="u-photo" src="{{ path('attachment_thumbnail', thumbnail_parameters) }}"
|
||||
alt="{{ attachment.getFilename() }}">
|
||||
<figcaption><a
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getFilename() }}</a>
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
|
@ -78,7 +78,11 @@ class VideoEncoder extends Plugin
|
||||
*/
|
||||
public function onViewAttachmentVideo(array $vars, array &$res): bool
|
||||
{
|
||||
$res[] = Formatting::twigRenderFile('videoEncoder/videoEncoderView.html.twig', ['attachment' => $vars['attachment'], 'thumbnail_parameters' => $vars['thumbnail_parameters']]);
|
||||
$res[] = Formatting::twigRenderFile('videoEncoder/videoEncoderView.html.twig',
|
||||
['attachment' => $vars['attachment'],
|
||||
'thumbnail_parameters' => $vars['thumbnail_parameters'],
|
||||
'note' => $vars['note'],
|
||||
]);
|
||||
return Event::stop;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
<video class="u-video" src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail', thumbnail_parameters) }}">
|
||||
</video>
|
||||
<figcaption><a
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getFilename() }}</a>
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
</div>
|
@ -24,6 +24,7 @@ namespace App\Entity;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Core\GSFile;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Log;
|
||||
use App\Util\Common;
|
||||
use DateTimeInterface;
|
||||
@ -129,6 +130,39 @@ class Attachment extends Entity
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Maybe this isn't the best way of handling titles
|
||||
*
|
||||
* @param null|Note $note
|
||||
*
|
||||
* @throws \App\Util\Exception\DuplicateFoundException
|
||||
* @throws \App\Util\Exception\NotFoundException
|
||||
* @throws \App\Util\Exception\ServerException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBestTitle(?Note $note = null): string
|
||||
{
|
||||
// If we have a note, then the best title is the title itself
|
||||
if (!is_null(($note))) {
|
||||
$attachment_to_note = DB::findOneBy('attachment_to_note', [
|
||||
'attachment_id' => $this->getId(),
|
||||
'note_id' => $note->getId(),
|
||||
]);
|
||||
if (!is_null($attachment_to_note->getTitle())) {
|
||||
return $attachment_to_note->getTitle();
|
||||
}
|
||||
}
|
||||
// Else
|
||||
if (!is_null($filename = $this->getFilename())) {
|
||||
// A filename would do just as well
|
||||
return $filename;
|
||||
} else {
|
||||
// Welp
|
||||
return _m('Untitled Attachment.');
|
||||
}
|
||||
}
|
||||
|
||||
public function setSize(?int $size): self
|
||||
{
|
||||
$this->size = $size;
|
||||
|
@ -13,6 +13,6 @@
|
||||
{% block body %}
|
||||
<div class="content">
|
||||
<a href="{{ download }}"> {{ 'Download link' | trans }}</a>
|
||||
{% include '/attachments/view.html.twig' with {'attachment': attachment} only %}
|
||||
{% include '/attachments/view.html.twig' with {'attachment': attachment, 'note': null} only %}
|
||||
</div>
|
||||
{% endblock body %}
|
@ -1,12 +1,12 @@
|
||||
{% set thumbnail_parameters = {'id': attachment.getId(), 'w': config('thumbnail','width'), 'h': config('thumbnail','height')} %}
|
||||
{% set handled = false %}
|
||||
{% for block in handle_event('ViewAttachment' ~ attachment.getMimetypeMajor() | capitalize , {'attachment': attachment, 'thumbnail_parameters': thumbnail_parameters}) %}
|
||||
{% for block in handle_event('ViewAttachment' ~ attachment.getMimetypeMajor() | capitalize , {'attachment': attachment, 'thumbnail_parameters': thumbnail_parameters, 'note': note}) %}
|
||||
{% set handled = true %}
|
||||
{{ block | raw }}
|
||||
{% endfor %}
|
||||
{% if not handled %}
|
||||
<div>
|
||||
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getFilename() }}</a> </i>
|
||||
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a> </i>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
{% if hide_attachments is not defined %}
|
||||
<div class="note-attachments">
|
||||
{% for attachment in note.getAttachments() %}
|
||||
{% include '/attachments/view.html.twig' with {'attachment': attachment} %}
|
||||
{% include '/attachments/view.html.twig' with {'attachment': attachment, 'note': note} only%}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user