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