forked from GNUsocial/gnu-social
[ATTACHMENTS] Add controller and templates for the attachment show page, which shows extra info about an attachment, such as related notes and tags
This commit is contained in:
parent
be91fb754d
commit
436528172c
@ -25,6 +25,7 @@ use App\Core\Controller;
|
|||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\GSFile;
|
use App\Core\GSFile;
|
||||||
|
use App\Core\Router\Router;
|
||||||
use App\Entity\AttachmentThumbnail;
|
use App\Entity\AttachmentThumbnail;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
use App\Util\Exception\ClientException;
|
use App\Util\Exception\ClientException;
|
||||||
@ -36,29 +37,56 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
|
|
||||||
class Attachment extends Controller
|
class Attachment extends Controller
|
||||||
{
|
{
|
||||||
public function attachment_show(Request $request, int $id)
|
private function attachment(int $id, callable $handle)
|
||||||
{
|
{
|
||||||
// If no one else claims this attachment, use the default representation
|
|
||||||
if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) {
|
if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) {
|
||||||
|
// If no one else claims this attachment, use the default representation
|
||||||
$res = GSFile::getAttachmentFileInfo($id);
|
$res = GSFile::getAttachmentFileInfo($id);
|
||||||
}
|
}
|
||||||
if (!empty($res)) {
|
if (!empty($res)) {
|
||||||
return GSFile::sendFile($res['filepath'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_INLINE);
|
return $handle($res);
|
||||||
} else {
|
} else {
|
||||||
throw new ClientException('No such attachment', 404);
|
throw new ClientException('No such attachment', 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page where the attachment and it's info is shown
|
||||||
|
*/
|
||||||
|
public function attachment_show(Request $request, int $id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$attachment = DB::findOneBy('attachment', ['id' => $id]);
|
||||||
|
return $this->attachment($id, function ($res) use ($id, $attachment) {
|
||||||
|
return [
|
||||||
|
'_template' => 'attachments/show.html.twig',
|
||||||
|
'title' => $res['title'],
|
||||||
|
'download' => Router::url('attachment_download', ['id' => $id]),
|
||||||
|
'attachment' => $attachment,
|
||||||
|
'related_notes' => DB::dql('select n from attachment_to_note an ' .
|
||||||
|
'join note n with n.id = an.note_id ' .
|
||||||
|
'where an.attachment_id = :attachment_id', ['attachment_id' => $id]),
|
||||||
|
'related_tags' => DB::dql('select distinct t.tag ' .
|
||||||
|
'from attachment_to_note an join note_tag t with an.note_id = t.note_id ' .
|
||||||
|
'where an.attachment_id = :attachment_id', ['attachment_id' => $id]),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
} catch (NotFoundException) {
|
||||||
|
throw new ClientException('No such attachment', 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the attachment inline
|
||||||
|
*/
|
||||||
public function attachment_view(Request $request, int $id)
|
public function attachment_view(Request $request, int $id)
|
||||||
{
|
{
|
||||||
$res = GSFile::getAttachmentFileInfo($id);
|
return $this->attachment($id, fn (array $res) => GSFile::sendFile($res['filepath'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_INLINE));
|
||||||
return GSFile::sendFile($res['filepath'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_INLINE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attachment_download(Request $request, int $id)
|
public function attachment_download(Request $request, int $id)
|
||||||
{
|
{
|
||||||
$res = GSFile::getAttachmentFileInfo($id);
|
return $this->attachment($id, fn (array $res) => GSFile::sendFile($res['filepath'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_ATTACHMENT));
|
||||||
return GSFile::sendFile($res['filepath'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_ATTACHMENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,16 +10,30 @@
|
|||||||
media="screen and (max-width: 750px)">
|
media="screen and (max-width: 750px)">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{# {% block header %} #}
|
|
||||||
{# {{ parent() }} #}
|
|
||||||
{# {% endblock %} #}
|
|
||||||
|
|
||||||
{# {% block left %} #}
|
|
||||||
{# {{ parent() }} #}
|
|
||||||
{# {% endblock %} #}
|
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
yooo
|
<div style="display: block">
|
||||||
|
<p> {{ title | escape }} </p>
|
||||||
|
<a href="{{download}}"> {{ 'Download link' | trans }}</a>
|
||||||
|
{% include '/attachments/view.html.twig' with {'attachment': attachment} only %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
||||||
|
{% block right %}
|
||||||
|
<div id="related-notes">
|
||||||
|
{{ 'Notes where this attachment appears' | trans }}
|
||||||
|
{% for note in related_notes %}
|
||||||
|
{% include '/note/view.html.twig' with {'note' : note, 'hide_attachments': true} only %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div id="related-tags">
|
||||||
|
{{ 'Tags for this attachment' | trans }}
|
||||||
|
<br/>
|
||||||
|
{% for tag in related_tags %}
|
||||||
|
<i>#{{tag['tag']}}</i>
|
||||||
|
{% else %}
|
||||||
|
{{ 'No tags' | trans }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock right %}
|
||||||
|
25
templates/attachments/view.html.twig
Normal file
25
templates/attachments/view.html.twig
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{% set thumbnail_parameters = {'id': attachment.getId(), 'w': config('thumbnail','width'), 'h': config('thumbnail','height')} %}
|
||||||
|
{% if attachment.mimetype starts with 'image/' %}
|
||||||
|
<div>
|
||||||
|
<figure>
|
||||||
|
<img src="{{ path('attachment_thumbnail', thumbnail_parameters) }}" alt="{{ attachment.getTitle() }}">
|
||||||
|
<figcaption> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </figcaption>
|
||||||
|
</figure>
|
||||||
|
</div>
|
||||||
|
{% elseif attachment.mimetype starts with 'video/' %}
|
||||||
|
<div>
|
||||||
|
<video src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail') }}, thumbnail_parameters">
|
||||||
|
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i>
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% for show in handle_event('ShowAttachment', attachment) %}
|
||||||
|
<div>
|
||||||
|
{{ show | raw }}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div>
|
||||||
|
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
@ -45,10 +45,14 @@
|
|||||||
<label for="toggle-right" id='right-panel'></label>
|
<label for="toggle-right" id='right-panel'></label>
|
||||||
</div>
|
</div>
|
||||||
<div class='rss'>
|
<div class='rss'>
|
||||||
|
<div> </div>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
{% block right %}
|
||||||
|
{% endblock right %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock header%}
|
{% endblock header%}
|
||||||
@ -59,3 +63,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -21,42 +21,20 @@
|
|||||||
{% include '/'~ other.name ~ '/view.html.twig' with {'vars': other.vars} only %}
|
{% include '/'~ other.name ~ '/view.html.twig' with {'vars': other.vars} only %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if hide_attachments is not defined and hide_attachments != true %}
|
||||||
<div class="note-attachments">
|
<div class="note-attachments">
|
||||||
{% for attachment in note.getAttachments() %}
|
{% for attachment in note.getAttachments() %}
|
||||||
{% set thumbnail_parameters = {'id': attachment.getId(), 'w': config('thumbnail','width'), 'h': config('thumbnail','height')} %}
|
{% include '/attachments/view.html.twig' with {'attachment': attachment} %}
|
||||||
{% if attachment.mimetype starts with 'image/' %}
|
|
||||||
<div>
|
|
||||||
<figure>
|
|
||||||
<img src="{{ path('attachment_thumbnail', thumbnail_parameters) }}" alt="{{ attachment.getTitle() }}">
|
|
||||||
<figcaption> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </figcaption>
|
|
||||||
</figure>
|
|
||||||
</div>
|
|
||||||
{% elseif attachment.mimetype starts with 'video/' %}
|
|
||||||
<div>
|
|
||||||
<video src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail') }}, thumbnail_parameters">
|
|
||||||
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i>
|
|
||||||
</video>
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
{% for show in handle_event('ShowAttachment', attachment) %}
|
|
||||||
<div>
|
|
||||||
{{ show | raw }}
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
<div>
|
|
||||||
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="note-actions">
|
<div class="note-actions">
|
||||||
{% if have_user %}
|
{# {% if have_user %} #}
|
||||||
{#{% for act in get_note_actions(note) %}#}
|
{# {\#{% for act in get_note_actions(note) %}#\} #}
|
||||||
{#{{ form(act) }}#}
|
{# {\#{{ form(act) }}#\} #}
|
||||||
{#{% endfor %}#}
|
{# {\#{% endfor %}#\} #}
|
||||||
{% endif %}
|
{# {% endif %} #}
|
||||||
</div>
|
</div>
|
||||||
{% if replies is defined %}
|
{% if replies is defined %}
|
||||||
<div class="replies">
|
<div class="replies">
|
||||||
|
Loading…
Reference in New Issue
Block a user