1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Hooks; |
14
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Helper; |
16
|
|
|
use Kitodo\Dlf\Common\Solr; |
17
|
|
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
18
|
|
|
use TYPO3\CMS\Core\Core\Bootstrap; |
19
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
20
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
21
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
22
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
23
|
|
|
use TYPO3\CMS\Core\Utility\VersionNumberUtility; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Hooks and helper for \TYPO3\CMS\Core\TypoScript\ConfigurationForm |
27
|
|
|
* |
28
|
|
|
* @author Sebastian Meyer <[email protected]> |
29
|
|
|
* @package TYPO3 |
30
|
|
|
* @subpackage dlf |
31
|
|
|
* @access public |
32
|
|
|
*/ |
33
|
|
|
class ConfigurationForm |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* This holds the current configuration |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
* @access protected |
40
|
|
|
*/ |
41
|
|
|
protected $conf = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Check if a connection to a Solr server could be established with the given credentials. |
45
|
|
|
* |
46
|
|
|
* @access public |
47
|
|
|
* |
48
|
|
|
* @return string Message informing the user of success or failure |
49
|
|
|
*/ |
50
|
|
|
public function checkSolrConnection() |
51
|
|
|
{ |
52
|
|
|
$solr = Solr::getInstance(); |
53
|
|
|
if ($solr->ready) { |
54
|
|
|
Helper::addMessage( |
55
|
|
|
$this->getLanguageService()->getLL('solr.status'), |
56
|
|
|
$this->getLanguageService()->getLL('solr.connected'), |
57
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
58
|
|
|
); |
59
|
|
|
} else { |
60
|
|
|
Helper::addMessage( |
61
|
|
|
$this->getLanguageService()->getLL('solr.error'), |
62
|
|
|
$this->getLanguageService()->getLL('solr.notConnected'), |
63
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
return Helper::renderFlashMessages(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Make sure the essential namespaces are defined. |
71
|
|
|
* |
72
|
|
|
* @access public |
73
|
|
|
* |
74
|
|
|
* @return string Message informing the user of success or failure |
75
|
|
|
*/ |
76
|
|
|
public function checkMetadataFormats() |
77
|
|
|
{ |
78
|
|
|
if (explode('.', VersionNumberUtility::getCurrentTypo3Version())[0] < 10) { |
79
|
|
|
// We need to do some bootstrapping manually in TYPO3 9. |
80
|
|
|
// Load table configuration array into $GLOBALS['TCA']. |
81
|
|
|
ExtensionManagementUtility::loadBaseTca(false); |
82
|
|
|
// Get extension configuration from dlf/ext_localconf.php. |
83
|
|
|
ExtensionManagementUtility::loadExtLocalconf(false); |
84
|
|
|
// Initialize backend user into $GLOBALS['BE_USER']. |
85
|
|
|
Bootstrap::initializeBackendUser(); |
86
|
|
|
// Initialize backend and ensure authenticated access. |
87
|
|
|
Bootstrap::initializeBackendAuthentication(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$nsDefined = [ |
91
|
|
|
'MODS' => false, |
92
|
|
|
'TEIHDR' => false, |
93
|
|
|
'ALTO' => false, |
94
|
|
|
'IIIF1' => false, |
95
|
|
|
'IIIF2' => false, |
96
|
|
|
'IIIF3' => false |
97
|
|
|
]; |
98
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
99
|
|
|
->getQueryBuilderForTable('tx_dlf_formats'); |
100
|
|
|
|
101
|
|
|
// Check existing format specifications. |
102
|
|
|
$result = $queryBuilder |
103
|
|
|
->select('tx_dlf_formats.type AS type') |
104
|
|
|
->from('tx_dlf_formats') |
105
|
|
|
->where( |
106
|
|
|
'1=1' |
107
|
|
|
) |
108
|
|
|
->execute(); |
109
|
|
|
|
110
|
|
|
while ($resArray = $result->fetch()) { |
111
|
|
|
$nsDefined[$resArray['type']] = true; |
112
|
|
|
} |
113
|
|
|
// Build data array. |
114
|
|
|
$data = []; |
115
|
|
|
// Add MODS namespace. |
116
|
|
|
if (!$nsDefined['MODS']) { |
117
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
118
|
|
|
'pid' => 0, |
119
|
|
|
'type' => 'MODS', |
120
|
|
|
'root' => 'mods', |
121
|
|
|
'namespace' => 'http://www.loc.gov/mods/v3', |
122
|
|
|
'class' => 'Kitodo\\Dlf\\Format\\Mods' |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
// Add TEIHDR namespace. |
126
|
|
|
if (!$nsDefined['TEIHDR']) { |
127
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
128
|
|
|
'pid' => 0, |
129
|
|
|
'type' => 'TEIHDR', |
130
|
|
|
'root' => 'teiHeader', |
131
|
|
|
'namespace' => 'http://www.tei-c.org/ns/1.0', |
132
|
|
|
'class' => 'Kitodo\\Dlf\\Format\\TeiHeader' |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
// Add ALTO namespace. |
136
|
|
|
if (!$nsDefined['ALTO']) { |
137
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
138
|
|
|
'pid' => 0, |
139
|
|
|
'type' => 'ALTO', |
140
|
|
|
'root' => 'alto', |
141
|
|
|
'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#', |
142
|
|
|
'class' => 'Kitodo\\Dlf\\Format\\Alto' |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
// Add IIIF Metadata API 1 context |
146
|
|
|
if (!$nsDefined['IIIF1']) { |
147
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
148
|
|
|
'pid' => 0, |
149
|
|
|
'type' => 'IIIF1', |
150
|
|
|
'root' => 'IIIF1', |
151
|
|
|
'namespace' => 'http://www.shared-canvas.org/ns/context.json', |
152
|
|
|
'class' => '' |
153
|
|
|
]; |
154
|
|
|
} |
155
|
|
|
// Add IIIF Presentation 2 context |
156
|
|
|
if (!$nsDefined['IIIF2']) { |
157
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
158
|
|
|
'pid' => 0, |
159
|
|
|
'type' => 'IIIF2', |
160
|
|
|
'root' => 'IIIF2', |
161
|
|
|
'namespace' => 'http://iiif.io/api/presentation/2/context.json', |
162
|
|
|
'class' => '' |
163
|
|
|
]; |
164
|
|
|
} |
165
|
|
|
// Add IIIF Presentation 3 context |
166
|
|
|
if (!$nsDefined['IIIF3']) { |
167
|
|
|
$data['tx_dlf_formats'][uniqid('NEW')] = [ |
168
|
|
|
'pid' => 0, |
169
|
|
|
'type' => 'IIIF3', |
170
|
|
|
'root' => 'IIIF3', |
171
|
|
|
'namespace' => 'http://iiif.io/api/presentation/3/context.json', |
172
|
|
|
'class' => '' |
173
|
|
|
]; |
174
|
|
|
} |
175
|
|
|
if (!empty($data)) { |
176
|
|
|
// Process changes. |
177
|
|
|
$substUid = Helper::processDBasAdmin($data); |
178
|
|
|
if (!empty($substUid)) { |
179
|
|
|
Helper::addMessage( |
180
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsCreatedMsg'), |
181
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsCreated'), |
182
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::INFO |
183
|
|
|
); |
184
|
|
|
} else { |
185
|
|
|
Helper::addMessage( |
186
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsNotCreatedMsg'), |
187
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsNotCreated'), |
188
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
} else { |
192
|
|
|
Helper::addMessage( |
193
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsOkayMsg'), |
194
|
|
|
$this->getLanguageService()->getLL('metadataFormats.nsOkay'), |
195
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::OK |
196
|
|
|
); |
197
|
|
|
} |
198
|
|
|
return Helper::renderFlashMessages(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* This is the constructor. |
203
|
|
|
* |
204
|
|
|
* @access public |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function __construct() |
209
|
|
|
{ |
210
|
|
|
// Load backend localization file. |
211
|
|
|
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_be.xlf'); |
212
|
|
|
|
213
|
|
|
// Get current configuration. |
214
|
|
|
$this->conf = array_merge(GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'), (array) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('data')); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Returns the LanguageService |
219
|
|
|
* |
220
|
|
|
* @return LanguageService |
221
|
|
|
*/ |
222
|
|
|
protected function getLanguageService(): LanguageService |
223
|
|
|
{ |
224
|
|
|
return $GLOBALS['LANG']; |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|