forked from GNUsocial/gnu-social
[UI][Attachment] Use Attachment methods to get the proper URL, rather than crafting it in a template
This commit is contained in:
parent
6799052ff5
commit
4b2a92d052
@ -143,8 +143,8 @@ 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'],
|
||||
[
|
||||
'attachment' => $vars['attachment'],
|
||||
'note' => $vars['note'],
|
||||
]);
|
||||
return Event::stop;
|
||||
|
@ -1,6 +1,7 @@
|
||||
<figure>
|
||||
<img class="u-photo" src="{{ path('attachment_thumbnail', thumbnail_parameters) }}"
|
||||
alt="{{ attachment.getFilename() }}">
|
||||
<img class="u-photo"
|
||||
alt="{{ attachment.getBestTitle(note) }}"
|
||||
src="{{ attachment.getThumbnailUrl() }}">
|
||||
<figcaption><a
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
||||
</figcaption>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<figure>
|
||||
<video class="u-video" src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail', thumbnail_parameters) }}">
|
||||
<video class="u-video" src="{{ attachment.getUrl() }}" controls poster="{{ attachment.getThumbnailUrl()}}">
|
||||
</video>
|
||||
<figcaption><a
|
||||
href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Core\Router\Router;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Core\GSFile;
|
||||
@ -315,9 +316,14 @@ class Attachment extends Entity
|
||||
return is_null($filename) ? null : Common::config('attachments', 'dir') . $filename;
|
||||
}
|
||||
|
||||
public function getAttachmentUrl()
|
||||
public function getUrl()
|
||||
{
|
||||
return Router::url('attachment_thumbnail', ['id' => $this->getAttachmentId(), 'w' => Common::config('attachment', 'width'), 'h' => Common::config('attachment', 'height')]);
|
||||
return Router::url('attachment_view', ['id' => $this->getId()]);
|
||||
}
|
||||
|
||||
public function getThumbnailUrl()
|
||||
{
|
||||
return Router::url('attachment_thumbnail', ['id' => $this->getId(), 'w' => Common::config('thumbnail', 'width'), 'h' => Common::config('thumbnail', 'height')]);;
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
|
@ -1,6 +1,5 @@
|
||||
{% 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, 'note': note}) %}
|
||||
{% for block in handle_event('ViewAttachment' ~ attachment.getMimetypeMajor() | capitalize , {'attachment': attachment, 'note': note}) %}
|
||||
{% set handled = true %}
|
||||
{{ block | raw }}
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user