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\Common; |
14
|
|
|
|
15
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
16
|
|
|
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService; |
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
18
|
|
|
use TYPO3\CMS\Core\Utility\HttpUtility; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract plugin class for the 'dlf' extension |
22
|
|
|
* |
23
|
|
|
* @author Sebastian Meyer <[email protected]> |
24
|
|
|
* @package TYPO3 |
25
|
|
|
* @subpackage dlf |
26
|
|
|
* @access public |
27
|
|
|
* @abstract |
28
|
|
|
*/ |
29
|
|
|
abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
public $extKey = 'dlf'; |
32
|
|
|
public $prefixId = 'tx_dlf'; |
33
|
|
|
public $scriptRelPath = 'Classes/Common/AbstractPlugin.php'; |
34
|
|
|
// Plugins are cached by default (@see setCache()). |
35
|
|
|
public $pi_USER_INT_obj = false; |
36
|
|
|
public $pi_checkCHash = true; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* This holds the current document |
40
|
|
|
* |
41
|
|
|
* @var \Kitodo\Dlf\Common\Document |
42
|
|
|
* @access protected |
43
|
|
|
*/ |
44
|
|
|
protected $doc; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* This holds the plugin's parsed template |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
* @access protected |
51
|
|
|
*/ |
52
|
|
|
protected $template = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* This holds the plugin's service for template |
56
|
|
|
* |
57
|
|
|
* @var \TYPO3\CMS\Core\Service\MarkerBasedTemplateService |
58
|
|
|
* @access protected |
59
|
|
|
*/ |
60
|
|
|
protected $templateService; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Read and parse the template file |
64
|
|
|
* |
65
|
|
|
* @access protected |
66
|
|
|
* |
67
|
|
|
* @param string $part: Name of the subpart to load |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
protected function getTemplate($part = '###TEMPLATE###') |
72
|
|
|
{ |
73
|
|
|
$this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class); |
74
|
|
|
if (!empty($this->conf['templateFile'])) { |
75
|
|
|
// Load template file from configuration. |
76
|
|
|
$templateFile = $this->conf['templateFile']; |
77
|
|
|
} else { |
78
|
|
|
// Load default template from extension. |
79
|
|
|
$templateFile = 'EXT:' . $this->extKey . '/Resources/Private/Templates/' . Helper::getUnqualifiedClassName(get_class($this)) . '.tmpl'; |
80
|
|
|
} |
81
|
|
|
// Substitute strings like "EXT:" in given template file location. |
82
|
|
|
$fileResource = $GLOBALS['TSFE']->tmpl->getFileName($templateFile); |
83
|
|
|
$this->template = $this->templateService->getSubpart(file_get_contents($fileResource), $part); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* All the needed configuration values are stored in class variables |
88
|
|
|
* Priority: Flexforms > TS-Templates > Extension Configuration > ext_localconf.php |
89
|
|
|
* |
90
|
|
|
* @access protected |
91
|
|
|
* |
92
|
|
|
* @param array $conf: Configuration array from TS-Template |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function init(array $conf) |
97
|
|
|
{ |
98
|
|
|
// Read FlexForm configuration. |
99
|
|
|
$flexFormConf = []; |
100
|
|
|
$this->cObj->readFlexformIntoConf($this->cObj->data['pi_flexform'], $flexFormConf); |
101
|
|
|
if (!empty($flexFormConf)) { |
102
|
|
|
$conf = Helper::mergeRecursiveWithOverrule($flexFormConf, $conf); |
103
|
|
|
} |
104
|
|
|
// Read plugin TS configuration. |
105
|
|
|
$pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_' . strtolower(Helper::getUnqualifiedClassName(get_class($this))) . '.']; |
106
|
|
|
if (is_array($pluginConf)) { |
107
|
|
|
$conf = Helper::mergeRecursiveWithOverrule($pluginConf, $conf); |
108
|
|
|
} |
109
|
|
|
// Read general TS configuration. |
110
|
|
|
$generalConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId . '.']; |
111
|
|
|
if (is_array($generalConf)) { |
112
|
|
|
$conf = Helper::mergeRecursiveWithOverrule($generalConf, $conf); |
113
|
|
|
} |
114
|
|
|
// Read extension configuration. |
115
|
|
|
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]); |
116
|
|
|
if (is_array($extConf)) { |
117
|
|
|
$conf = Helper::mergeRecursiveWithOverrule($extConf, $conf); |
118
|
|
|
} |
119
|
|
|
// Read TYPO3_CONF_VARS configuration. |
120
|
|
|
$varsConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]; |
121
|
|
|
if (is_array($varsConf)) { |
122
|
|
|
$conf = Helper::mergeRecursiveWithOverrule($varsConf, $conf); |
123
|
|
|
} |
124
|
|
|
$this->conf = $conf; |
|
|
|
|
125
|
|
|
// Set default plugin variables. |
126
|
|
|
$this->pi_setPiVarDefaults(); |
127
|
|
|
// Load translation files. |
128
|
|
|
$this->pi_loadLL('EXT:' . $this->extKey . '/Resources/Private/Language/' . Helper::getUnqualifiedClassName(get_class($this)) . '.xml'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Loads the current document into $this->doc |
133
|
|
|
* |
134
|
|
|
* @access protected |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
protected function loadDocument() |
139
|
|
|
{ |
140
|
|
|
// Check for required variable. |
141
|
|
|
if ( |
142
|
|
|
!empty($this->piVars['id']) |
143
|
|
|
&& !empty($this->conf['pages']) |
144
|
|
|
) { |
145
|
|
|
// Should we exclude documents from other pages than $this->conf['pages']? |
146
|
|
|
$pid = (!empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0); |
147
|
|
|
// Get instance of \Kitodo\Dlf\Common\Document. |
148
|
|
|
$this->doc = Document::getInstance($this->piVars['id'], $pid); |
149
|
|
|
if (!$this->doc->ready) { |
150
|
|
|
// Destroy the incomplete object. |
151
|
|
|
$this->doc = null; |
152
|
|
|
Helper::devLog('Failed to load document with UID ' . $this->piVars['id'], DEVLOG_SEVERITY_ERROR); |
153
|
|
|
} else { |
154
|
|
|
// Set configuration PID. |
155
|
|
|
$this->doc->cPid = $this->conf['pages']; |
156
|
|
|
} |
157
|
|
|
} elseif (!empty($this->piVars['recordId'])) { |
158
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
159
|
|
|
->getQueryBuilderForTable('tx_dlf_documents'); |
160
|
|
|
|
161
|
|
|
// Get UID of document with given record identifier. |
162
|
|
|
$result = $queryBuilder |
163
|
|
|
->select('tx_dlf_documents.uid AS uid') |
164
|
|
|
->from('tx_dlf_documents') |
165
|
|
|
->where( |
166
|
|
|
$queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($this->piVars['recordId'])), |
167
|
|
|
Helper::whereExpression('tx_dlf_documents') |
168
|
|
|
) |
169
|
|
|
->setMaxResults(1) |
170
|
|
|
->execute(); |
171
|
|
|
|
172
|
|
|
if ($resArray = $result->fetch()) { |
173
|
|
|
$this->piVars['id'] = $resArray['uid']; |
|
|
|
|
174
|
|
|
// Set superglobal $_GET array and unset variables to avoid infinite looping. |
175
|
|
|
$_GET[$this->prefixId]['id'] = $this->piVars['id']; |
176
|
|
|
unset($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']); |
177
|
|
|
// Try to load document. |
178
|
|
|
$this->loadDocument(); |
179
|
|
|
} else { |
180
|
|
|
Helper::devLog('Failed to load document with record ID "' . $this->piVars['recordId'] . '"', DEVLOG_SEVERITY_ERROR); |
181
|
|
|
} |
182
|
|
|
} else { |
183
|
|
|
Helper::devLog('Invalid UID ' . $this->piVars['id'] . ' or PID ' . $this->conf['pages'] . ' for document loading', DEVLOG_SEVERITY_ERROR); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* The main method of the PlugIn |
189
|
|
|
* |
190
|
|
|
* @access public |
191
|
|
|
* |
192
|
|
|
* @param string $content: The PlugIn content |
193
|
|
|
* @param array $conf: The PlugIn configuration |
194
|
|
|
* |
195
|
|
|
* @abstract |
196
|
|
|
* |
197
|
|
|
* @return string The content that is displayed on the website |
198
|
|
|
*/ |
199
|
|
|
abstract public function main($content, $conf); |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Parses a string into a Typoscript array |
203
|
|
|
* |
204
|
|
|
* @access protected |
205
|
|
|
* |
206
|
|
|
* @param string $string: The string to parse |
207
|
|
|
* |
208
|
|
|
* @return array The resulting typoscript array |
209
|
|
|
*/ |
210
|
|
|
protected function parseTS($string = '') |
211
|
|
|
{ |
212
|
|
|
$parser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class); |
213
|
|
|
$parser->parse($string); |
214
|
|
|
return $parser->setup; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Link string to the current page. |
219
|
|
|
* @see \TYPO3\CMS\Frontend\Plugin\AbstractPlugin->pi_linkTP() |
220
|
|
|
* |
221
|
|
|
* @access public |
222
|
|
|
* |
223
|
|
|
* @param string $str: The content string to wrap in <a> tags |
224
|
|
|
* @param array $urlParameters: Array with URL parameters as key/value pairs |
225
|
|
|
* @param bool $cache: Should the "no_cache" parameter be added? |
226
|
|
|
* @param int $altPageId: Alternative page ID for the link. |
227
|
|
|
* |
228
|
|
|
* @return string The input string wrapped in <a> tags |
229
|
|
|
*/ |
230
|
|
|
public function pi_linkTP($str, $urlParameters = [], $cache = false, $altPageId = 0) |
231
|
|
|
{ |
232
|
|
|
$conf = []; |
233
|
|
|
if (!$cache) { |
234
|
|
|
$conf['no_cache'] = true; |
235
|
|
|
} |
236
|
|
|
$conf['parameter'] = $altPageId ?: ($this->pi_tmpPageId ?: 'current'); |
237
|
|
|
$conf['additionalParams'] = $this->conf['parent.']['addParams'] . HttpUtility::buildQueryString($urlParameters, '&', true) . $this->pi_moreParams; |
238
|
|
|
// Add additional configuration for absolute URLs. |
239
|
|
|
$conf['forceAbsoluteUrl'] = !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0; |
240
|
|
|
$conf['forceAbsoluteUrl.']['scheme'] = !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'; |
241
|
|
|
return $this->cObj->typoLink($str, $conf); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Wraps the input string in a <div> tag with the class attribute set to the class name |
246
|
|
|
* @see \TYPO3\CMS\Frontend\Plugin\AbstractPlugin->pi_wrapInBaseClass() |
247
|
|
|
* |
248
|
|
|
* @access public |
249
|
|
|
* |
250
|
|
|
* @param string $content: HTML content to wrap in the div-tags with the class of the plugin |
251
|
|
|
* |
252
|
|
|
* @return string HTML content wrapped, ready to return to the parent object. |
253
|
|
|
*/ |
254
|
|
|
public function pi_wrapInBaseClass($content) |
255
|
|
|
{ |
256
|
|
|
if (!$this->frontendController->config['config']['disableWrapInBaseClass']) { |
257
|
|
|
// Use class name instead of $this->prefixId for content wrapping because $this->prefixId is the same for all plugins. |
258
|
|
|
$content = '<div class="tx-dlf-' . strtolower(Helper::getUnqualifiedClassName(get_class($this))) . '">' . $content . '</div>'; |
259
|
|
|
if (!$this->frontendController->config['config']['disablePrefixComment']) { |
260
|
|
|
$content = "\n\n<!-- BEGIN: Content of extension '" . $this->extKey . "', plugin '" . Helper::getUnqualifiedClassName(get_class($this)) . "' -->\n\n" . $content . "\n\n<!-- END: Content of extension '" . $this->extKey . "', plugin '" . Helper::getUnqualifiedClassName(get_class($this)) . "' -->\n\n"; |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
return $content; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Sets some configuration variables if the plugin is cached. |
268
|
|
|
* |
269
|
|
|
* @access protected |
270
|
|
|
* |
271
|
|
|
* @param bool $cache: Should the plugin be cached? |
272
|
|
|
* |
273
|
|
|
* @return void |
274
|
|
|
*/ |
275
|
|
|
protected function setCache($cache = true) |
276
|
|
|
{ |
277
|
|
|
if ($cache) { |
278
|
|
|
// Set cObject type to "USER" (default). |
279
|
|
|
$this->pi_USER_INT_obj = false; |
280
|
|
|
$this->pi_checkCHash = true; |
281
|
|
|
if (count($this->piVars)) { |
282
|
|
|
// Check cHash or disable caching. |
283
|
|
|
$GLOBALS['TSFE']->reqCHash(); |
284
|
|
|
} |
285
|
|
|
} else { |
286
|
|
|
// Set cObject type to "USER_INT". |
287
|
|
|
$this->pi_USER_INT_obj = true; |
288
|
|
|
$this->pi_checkCHash = false; |
289
|
|
|
// Plugins are of type "USER" by default, so convert it to "USER_INT". |
290
|
|
|
$this->cObj->convertToUserIntObject(); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths