forked from Daniel-KM/Omeka-S-module-BlockPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
113 lines (97 loc) · 3.84 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php declare(strict_types=1);
namespace BlockPlus;
if (!class_exists(\Generic\AbstractModule::class)) {
require file_exists(dirname(__DIR__) . '/Generic/AbstractModule.php')
? dirname(__DIR__) . '/Generic/AbstractModule.php'
: __DIR__ . '/src/Generic/AbstractModule.php';
}
use Generic\AbstractModule;
use Laminas\EventManager\Event;
use Laminas\EventManager\SharedEventManagerInterface;
/**
* BlockPlus
*
* @copyright Daniel Berthereau, 2018-2022
* @license http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*/
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
protected function preInstall(): void
{
$js = __DIR__ . '/asset/vendor/ThumbnailGridExpandingPreview/js/grid.js';
if (!file_exists($js)) {
$services = $this->getServiceLocator();
$t = $services->get('MvcTranslator');
throw new \Omeka\Module\Exception\ModuleCannotInstallException(
sprintf(
$t->translate('The library "%s" should be installed.'), // @translate
'javascript'
) . ' '
. $t->translate('See module’s installation documentation.')); // @translate
}
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
{
$sharedEventManager->attach(
'Omeka\Controller\SiteAdmin\Page',
'view.edit.before',
[$this, 'handleSitePageEditBefore']
);
$sharedEventManager->attach(
\Omeka\Stdlib\HtmlPurifier::class,
'htmlpurifier_config',
[$this, 'handleHtmlPurifier']
);
$sharedEventManager->attach(
\Omeka\Form\SettingForm::class,
'form.add_elements',
[$this, 'handleMainSettings']
);
$sharedEventManager->attach(
\Omeka\Form\SiteSettingsForm::class,
'form.add_elements',
[$this, 'handleSiteSettings']
);
}
public function handleSitePageEditBefore(Event $event): void
{
$view = $event->getTarget();
$assetUrl = $view->plugin('assetUrl');
$view->headLink()
->appendStylesheet($assetUrl('css/block-plus-admin.css', 'BlockPlus'));
}
public function handleHtmlPurifier(Event $event): void
{
// CKEditor footnotes uses `<section class="footnotes">` and some other
// elements and attributes, but they are not in the default config, designed for html 4.
// The same for HTML Purifier, that is based on html 4, and won't be
// updated to support html 5.
// @see https://github.com/ezyang/htmlpurifier/issues/160
/** @var \HTMLPurifier_Config $config */
$config = $event->getParam('config');
$config->set('Attr.EnableID', true);
$config->set('HTML.AllowedAttributes', [
'a.id',
'a.rel',
'a.href',
'a.target',
'li.id',
'li.data-footnote-id',
'section.class',
'sup.data-footnote-id',
]);
$config->set('HTML.TargetBlank', true);
$def = $config->getHTMLDefinition(true);
$def->addElement('article', 'Block', 'Flow', 'Common');
$def->addElement('section', 'Block', 'Flow', 'Common');
$def->addElement('header', 'Block', 'Flow', 'Common');
$def->addElement('footer', 'Block', 'Flow', 'Common');
$def->addAttribute('sup', 'data-footnote-id', 'ID');
// This is the same id than sup, but Html Purifier ID should be unique
// among all the submitted html ids, so use Class.
$def->addAttribute('li', 'data-footnote-id', 'Class');
$def->addAttribute('a', 'target', new \HTMLPurifier_AttrDef_Enum(['_blank', '_self', '_target', '_top']));
$event->setParam('config', $config);
}
}