|
1
|
|
|
<?php |
|
2
|
|
|
namespace Kitodo\Dlf\Common; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU General Public License version 3 or later. |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Abstract plugin class for the 'dlf' extension |
|
16
|
|
|
* |
|
17
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
18
|
|
|
* @package TYPO3 |
|
19
|
|
|
* @subpackage dlf |
|
20
|
|
|
* @access public |
|
21
|
|
|
* @abstract |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractPlugin extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin { |
|
24
|
|
|
public $extKey = 'dlf'; |
|
25
|
|
|
public $prefixId = 'tx_dlf'; |
|
26
|
|
|
public $scriptRelPath = 'Classes/Common/AbstractPlugin.php'; |
|
27
|
|
|
// Plugins are cached by default (@see setCache()). |
|
28
|
|
|
public $pi_USER_INT_obj = FALSE; |
|
29
|
|
|
public $pi_checkCHash = TRUE; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* This holds the current document |
|
33
|
|
|
* |
|
34
|
|
|
* @var \Kitodo\Dlf\Common\Document |
|
35
|
|
|
* @access protected |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $doc; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* This holds the plugin's parsed template |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
* @access protected |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $template = ''; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Read and parse the template file |
|
49
|
|
|
* |
|
50
|
|
|
* @access protected |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $part: Name of the subpart to load |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function getTemplate($part = '###TEMPLATE###') { |
|
57
|
|
|
if (!empty($this->conf['templateFile'])) { |
|
58
|
|
|
// Load template file from configuration. |
|
59
|
|
|
$this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['templateFile']), $part); |
|
|
|
|
|
|
60
|
|
|
} else { |
|
61
|
|
|
// Load default template file. |
|
62
|
|
|
$this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/Resources/Private/Templates/'.Helper::getUnqualifiedClassName(get_class($this)).'.tmpl'), $part); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* All the needed configuration values are stored in class variables |
|
68
|
|
|
* Priority: Flexforms > TS-Templates > Extension Configuration > ext_localconf.php |
|
69
|
|
|
* |
|
70
|
|
|
* @access protected |
|
71
|
|
|
* |
|
72
|
|
|
* @param array $conf: configuration array from TS-Template |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function init(array $conf) { |
|
77
|
|
|
// Read FlexForm configuration. |
|
78
|
|
|
$flexFormConf = []; |
|
79
|
|
|
$this->cObj->readFlexformIntoConf($this->cObj->data['pi_flexform'], $flexFormConf); |
|
80
|
|
|
if (!empty($flexFormConf)) { |
|
81
|
|
|
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($flexFormConf, $conf); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
// Read plugin TS configuration. |
|
84
|
|
|
$pluginConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_dlf_'.strtolower(Helper::getUnqualifiedClassName(get_class($this))).'.']; |
|
85
|
|
|
if (is_array($pluginConf)) { |
|
86
|
|
|
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConf, $conf); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
// Read general TS configuration. |
|
89
|
|
|
$generalConf = $GLOBALS['TSFE']->tmpl->setup['plugin.'][$this->prefixId.'.']; |
|
90
|
|
|
if (is_array($generalConf)) { |
|
91
|
|
|
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($generalConf, $conf); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
// Read extension configuration. |
|
94
|
|
|
$extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]); |
|
95
|
|
|
if (is_array($extConf)) { |
|
96
|
|
|
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($extConf, $conf); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
// Read TYPO3_CONF_VARS configuration. |
|
99
|
|
|
$varsConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]; |
|
100
|
|
|
if (is_array($varsConf)) { |
|
101
|
|
|
$conf = \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($varsConf, $conf); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
$this->conf = $conf; |
|
104
|
|
|
// Set default plugin variables. |
|
105
|
|
|
$this->pi_setPiVarDefaults(); |
|
106
|
|
|
// Load translation files. |
|
107
|
|
|
$this->pi_loadLL('EXT:'.$this->extKey.'/Resources/Private/Language/'.Helper::getUnqualifiedClassName(get_class($this)).'.xml'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Loads the current document into $this->doc |
|
112
|
|
|
* |
|
113
|
|
|
* @access protected |
|
114
|
|
|
* |
|
115
|
|
|
* @return void |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function loadDocument() { |
|
118
|
|
|
// Check for required variable. |
|
119
|
|
|
if (!empty($this->piVars['id']) |
|
120
|
|
|
&& !empty($this->conf['pages'])) { |
|
121
|
|
|
// Should we exclude documents from other pages than $this->conf['pages']? |
|
122
|
|
|
$pid = (!empty($this->conf['excludeOther']) ? intval($this->conf['pages']) : 0); |
|
123
|
|
|
// Get instance of \Kitodo\Dlf\Common\Document. |
|
124
|
|
|
$this->doc = Document::getInstance($this->piVars['id'], $pid); |
|
125
|
|
|
if (!$this->doc->ready) { |
|
|
|
|
|
|
126
|
|
|
// Destroy the incomplete object. |
|
127
|
|
|
$this->doc = NULL; |
|
128
|
|
|
Helper::devLog('Failed to load document with UID '.$this->piVars['id'], DEVLOG_SEVERITY_ERROR); |
|
129
|
|
|
} else { |
|
130
|
|
|
// Set configuration PID. |
|
131
|
|
|
$this->doc->cPid = $this->conf['pages']; |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} elseif (!empty($this->piVars['recordId'])) { |
|
134
|
|
|
// Get UID of document with given record identifier. |
|
135
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
136
|
|
|
'tx_dlf_documents.uid', |
|
137
|
|
|
'tx_dlf_documents', |
|
138
|
|
|
'tx_dlf_documents.record_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['recordId'], 'tx_dlf_documents') |
|
139
|
|
|
.Helper::whereClause('tx_dlf_documents'), |
|
140
|
|
|
'', |
|
141
|
|
|
'', |
|
142
|
|
|
'1' |
|
143
|
|
|
); |
|
144
|
|
|
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) == 1) { |
|
145
|
|
|
list ($this->piVars['id']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
|
146
|
|
|
// Set superglobal $_GET array and unset variables to avoid infinite looping. |
|
147
|
|
|
$_GET[$this->prefixId]['id'] = $this->piVars['id']; |
|
148
|
|
|
unset ($this->piVars['recordId'], $_GET[$this->prefixId]['recordId']); |
|
149
|
|
|
// Try to load document. |
|
150
|
|
|
$this->loadDocument(); |
|
151
|
|
|
} else { |
|
152
|
|
|
Helper::devLog('Failed to load document with record ID "'.$this->piVars['recordId'].'"', DEVLOG_SEVERITY_ERROR); |
|
153
|
|
|
} |
|
154
|
|
|
} else { |
|
155
|
|
|
Helper::devLog('Invalid UID '.$this->piVars['id'].' or PID '.$this->conf['pages'].' for document loading', DEVLOG_SEVERITY_ERROR); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* The main method of the PlugIn |
|
161
|
|
|
* |
|
162
|
|
|
* @access public |
|
163
|
|
|
* |
|
164
|
|
|
* @param string $content: The PlugIn content |
|
165
|
|
|
* @param array $conf: The PlugIn configuration |
|
166
|
|
|
* |
|
167
|
|
|
* @abstract |
|
168
|
|
|
* |
|
169
|
|
|
* @return string The content that is displayed on the website |
|
170
|
|
|
*/ |
|
171
|
|
|
abstract public function main($content, $conf); |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Wraps the input string in a tag with the class attribute set to the class name |
|
175
|
|
|
* |
|
176
|
|
|
* @access public |
|
177
|
|
|
* |
|
178
|
|
|
* @param string $content: HTML content to wrap in the div-tags with the class of the plugin |
|
179
|
|
|
* |
|
180
|
|
|
* @return string HTML content wrapped, ready to return to the parent object. |
|
181
|
|
|
*/ |
|
182
|
|
|
public function pi_wrapInBaseClass($content) { |
|
183
|
|
|
if (!$GLOBALS['TSFE']->config['config']['disableWrapInBaseClass']) { |
|
184
|
|
|
// Use class name instead of $this->prefixId for content wrapping because $this->prefixId is the same for all plugins. |
|
185
|
|
|
$content = '<div class="tx-dlf-'.Helper::getUnqualifiedClassName(get_class($this)).'">'.$content.'</div>'; |
|
186
|
|
|
if (!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) { |
|
187
|
|
|
$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"; |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
return $content; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Parses a string into a Typoscript array |
|
195
|
|
|
* |
|
196
|
|
|
* @access protected |
|
197
|
|
|
* |
|
198
|
|
|
* @param string $string: The string to parse |
|
199
|
|
|
* |
|
200
|
|
|
* @return array The resulting typoscript array |
|
201
|
|
|
*/ |
|
202
|
|
|
protected function parseTS($string = '') { |
|
203
|
|
|
$parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class); |
|
204
|
|
|
$parser->parse($string); |
|
205
|
|
|
return $parser->setup; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Sets some configuration variables if the plugin is cached. |
|
210
|
|
|
* |
|
211
|
|
|
* @access protected |
|
212
|
|
|
* |
|
213
|
|
|
* @param boolean $cache: Should the plugin be cached? |
|
214
|
|
|
* |
|
215
|
|
|
* @return void |
|
216
|
|
|
*/ |
|
217
|
|
|
protected function setCache($cache = TRUE) { |
|
218
|
|
|
if ($cache) { |
|
219
|
|
|
// Set cObject type to "USER" (default). |
|
220
|
|
|
$this->pi_USER_INT_obj = FALSE; |
|
221
|
|
|
$this->pi_checkCHash = TRUE; |
|
222
|
|
|
if (count($this->piVars)) { |
|
223
|
|
|
// Check cHash or disable caching. |
|
224
|
|
|
$GLOBALS['TSFE']->reqCHash(); |
|
225
|
|
|
} |
|
226
|
|
|
} else { |
|
227
|
|
|
// Set cObject type to "USER_INT". |
|
228
|
|
|
$this->pi_USER_INT_obj = TRUE; |
|
229
|
|
|
$this->pi_checkCHash = FALSE; |
|
230
|
|
|
// Plugins are of type "USER" by default, so convert it to "USER_INT". |
|
231
|
|
|
$this->cObj->convertToUserIntObject(); |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.