mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
137 lines
5.1 KiB
PHP
137 lines
5.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\DocStoreBundle\Templating;
|
|
|
|
use ChampsLibres\WopiLib\Contract\Service\Discovery\DiscoveryInterface;
|
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
|
use Twig\Environment;
|
|
use Twig\Extension\RuntimeExtensionInterface;
|
|
|
|
use function in_array;
|
|
|
|
final class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
|
|
{
|
|
public const SUPPORTED_MIMES = [
|
|
'image/svg+xml',
|
|
'application/vnd.ms-powerpoint',
|
|
'application/vnd.ms-excel',
|
|
'application/vnd.sun.xml.writer',
|
|
'application/vnd.oasis.opendocument.text',
|
|
'application/vnd.oasis.opendocument.text-flat-xml',
|
|
'application/vnd.sun.xml.calc',
|
|
'application/vnd.oasis.opendocument.spreadsheet',
|
|
'application/vnd.oasis.opendocument.spreadsheet-flat-xml',
|
|
'application/vnd.sun.xml.impress',
|
|
'application/vnd.oasis.opendocument.presentation',
|
|
'application/vnd.oasis.opendocument.presentation-flat-xml',
|
|
'application/vnd.sun.xml.draw',
|
|
'application/vnd.oasis.opendocument.graphics',
|
|
'application/vnd.oasis.opendocument.graphics-flat-xml',
|
|
'application/vnd.oasis.opendocument.chart',
|
|
'application/vnd.sun.xml.writer.global',
|
|
'application/vnd.oasis.opendocument.text-master',
|
|
'application/vnd.sun.xml.writer.template',
|
|
'application/vnd.oasis.opendocument.text-template',
|
|
'application/vnd.oasis.opendocument.text-master-template',
|
|
'application/vnd.sun.xml.calc.template',
|
|
'application/vnd.oasis.opendocument.spreadsheet-template',
|
|
'application/vnd.sun.xml.impress.template',
|
|
'application/vnd.oasis.opendocument.presentation-template',
|
|
'application/vnd.sun.xml.draw.template',
|
|
'application/vnd.oasis.opendocument.graphics-template',
|
|
'application/msword',
|
|
'application/msword',
|
|
'application/vnd.ms-excel',
|
|
'application/vnd.ms-powerpoint',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
'application/vnd.ms-word.document.macroEnabled.12',
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
|
|
'application/vnd.ms-word.template.macroEnabled.12',
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
|
|
'application/vnd.ms-excel.template.macroEnabled.12',
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
|
|
'application/vnd.ms-excel.sheet.macroEnabled.12',
|
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
|
|
'application/vnd.openxmlformats-officedocument.presentationml.template',
|
|
'application/vnd.ms-powerpoint.template.macroEnabled.12',
|
|
'application/vnd.wordperfect',
|
|
'application/x-aportisdoc',
|
|
'application/x-hwp',
|
|
'application/vnd.ms-works',
|
|
'application/x-mswrite',
|
|
'application/x-dif-document',
|
|
'text/spreadsheet',
|
|
'text/csv',
|
|
'application/x-dbase',
|
|
'application/vnd.lotus-1-2-3',
|
|
'image/cgm',
|
|
'image/vnd.dxf',
|
|
'image/x-emf',
|
|
'image/x-wmf',
|
|
'application/coreldraw',
|
|
'application/vnd.visio2013',
|
|
'application/vnd.visio',
|
|
'application/vnd.ms-visio.drawing',
|
|
'application/x-mspublisher',
|
|
'application/x-sony-bbeb',
|
|
'application/x-gnumeric',
|
|
'application/macwriteii',
|
|
'application/x-iwork-numbers-sffnumbers',
|
|
'application/vnd.oasis.opendocument.text-web',
|
|
'application/x-pagemaker',
|
|
'text/rtf',
|
|
'text/plain',
|
|
'application/x-fictionbook+xml',
|
|
'application/clarisworks',
|
|
'image/x-wpg',
|
|
'application/x-iwork-pages-sffpages',
|
|
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
|
|
'application/x-iwork-keynote-sffkey',
|
|
|
|
'application/x-abiword',
|
|
'image/x-freehand',
|
|
'application/vnd.sun.xml.chart',
|
|
'application/x-t602',
|
|
'image/bmp',
|
|
'image/png',
|
|
'image/gif',
|
|
'image/tiff',
|
|
'image/jpg',
|
|
'image/jpeg',
|
|
'application/pdf',
|
|
];
|
|
|
|
private const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig';
|
|
|
|
private DiscoveryInterface $discovery;
|
|
|
|
public function __construct(DiscoveryInterface $discovery)
|
|
{
|
|
$this->discovery = $discovery;
|
|
}
|
|
|
|
public function isEditable(StoredObject $document): bool
|
|
{
|
|
return in_array($document->getType(), self::SUPPORTED_MIMES, true);
|
|
}
|
|
|
|
public function renderEditButton(Environment $environment, StoredObject $document, ?array $options = null): string
|
|
{
|
|
return $environment->render(self::TEMPLATE, [
|
|
'document' => $document,
|
|
'options' => $options,
|
|
]);
|
|
}
|
|
}
|