1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AOE\Languagevisibility; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2016 AOE GmbH <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
* @author Daniel Poetzinger <[email protected]> |
31
|
|
|
* @coauthor Tolleiv Nietsch <[email protected]> |
32
|
|
|
* @coauthor Timo Schmidt <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class Language { |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private $row; |
40
|
|
|
|
41
|
|
|
protected static $flagCache; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Holds the exploded fallBackOrderArray |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $defaultFallBackOrderArray; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Holds the exploded elementFallBackOrderArray |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $elementFallBackOrderArray; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Holds the exploded newFallBackOrderArray |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $newsFallBackOrderArray; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var holds the lg_iso_2 isocode |
66
|
|
|
*/ |
67
|
|
|
protected $lg_iso_2; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param array $row |
71
|
|
|
*/ |
72
|
|
|
public function setData($row) { |
73
|
|
|
$this->row = $row; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the fallback order of this language as array. |
78
|
|
|
* |
79
|
|
|
* @param Element $contextElement |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getFallbackOrder(Element $contextElement) { |
83
|
|
|
// determine and explode only once |
84
|
|
|
if (! isset($this->defaultFallBackOrderArray)) { |
85
|
|
|
// unfortunatly defaultlangauge is 999 instead of 0 (reason in formrendering of typo3): |
86
|
|
|
$tx_languagevisibility_fallbackorder = str_replace('999', '0', $this->row['tx_languagevisibility_fallbackorder']); |
87
|
|
|
$this->defaultFallBackOrderArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tx_languagevisibility_fallbackorder); |
88
|
|
|
} |
89
|
|
|
return $this->triggerFallbackHooks('getFallbackOrder', $this->defaultFallBackOrderArray, $contextElement); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns the fallback order for this language for elements |
94
|
|
|
* |
95
|
|
|
* @param Element $contextElement |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function getFallbackOrderElement(Element $contextElement) { |
99
|
|
|
// determine and explode only once |
100
|
|
|
if (! isset($this->elementFallBackOrderArray)) { |
101
|
|
|
if ($this->usesComplexFallbackSettings()) { |
102
|
|
|
$tx_languagevisibility_fallbackorderel = str_replace('999', '0', $this->row['tx_languagevisibility_fallbackorderel']); |
103
|
|
|
$this->elementFallBackOrderArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tx_languagevisibility_fallbackorderel); |
104
|
|
|
} else { |
105
|
|
|
$this->elementFallBackOrderArray = $this->getFallbackOrder($contextElement); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $this->triggerFallbackHooks('getFallbackOrderElement', $this->elementFallBackOrderArray, $contextElement); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns the fallback order for news elements as array |
114
|
|
|
* |
115
|
|
|
* @param Element $contextElement |
116
|
|
|
* @return array |
117
|
|
|
*/ |
118
|
|
|
public function getFallbackOrderTTNewsElement(Element $contextElement) { |
119
|
|
|
// determine and explode only once |
120
|
|
|
if (! isset($this->newsFallBackOrderArray)) { |
121
|
|
|
if ($this->usesComplexFallbackSettings()) { |
122
|
|
|
$tx_languagevisibility_fallbackorderttnewel = str_replace('999', '0', $this->row['tx_languagevisibility_fallbackorderttnewsel']); |
123
|
|
|
$this->newsFallBackOrderArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $tx_languagevisibility_fallbackorderttnewel); |
124
|
|
|
} else { |
125
|
|
|
$this->newsFallBackOrderArray = $this->getFallbackOrder($contextElement); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $this->triggerFallbackHooks('getFallbackOrderTTNewsElement', $this->newsFallBackOrderArray, $contextElement); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* |
134
|
|
|
* @param unknown_type $key |
135
|
|
|
* @param unknown_type $fallbackorder |
136
|
|
|
* @param Element $contextElement |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
|
protected function triggerFallbackHooks($key, $fallbackorder, Element $contextElement) { |
140
|
|
|
$result = array( |
141
|
|
|
'priority' => 10, |
142
|
|
|
'fallbackorder' => $fallbackorder, |
143
|
|
|
); |
144
|
|
|
$fallback = $result; |
145
|
|
|
if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility'][$key])) { |
146
|
|
|
|
147
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility'][$key] as $classRef) { |
148
|
|
|
$hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); |
149
|
|
|
if (method_exists($hookObj, $key)) { |
150
|
|
|
$result = $hookObj->$key($this, $fallback, $contextElement); |
151
|
|
|
if ($result['priority'] > $fallback['priority']) { |
152
|
|
|
$fallback = $result; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
return $fallback['fallbackorder']; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Method to check if complex fallback settings should be used. |
163
|
|
|
* |
164
|
|
|
* @return boolean |
165
|
|
|
*/ |
166
|
|
|
public function usesComplexFallbackSettings() { |
167
|
|
|
return intval($this->row['tx_languagevisibility_complexfallbacksetting']) > 0; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Method to read the defaultVisibility setting of pages. |
172
|
|
|
* |
173
|
|
|
* @param Element $contextElement |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
|
|
public function getDefaultVisibilityForPage(Element $contextElement) { |
177
|
|
|
return $this->triggerDefaultVisibilityHooks('getDefaultVisibilityForPage', $this->row['tx_languagevisibility_defaultvisibility'], $contextElement); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Method to read the defaultVisibility for elements |
182
|
|
|
* |
183
|
|
|
* @param Element $contextElement |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function getDefaultVisibilityForElement(Element $contextElement) { |
187
|
|
|
return $this->triggerDefaultVisibilityHooks('getDefaultVisibilityForElement', $this->row['tx_languagevisibility_defaultvisibilityel'], $contextElement); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Method to read the visibility for tt news Elements. |
192
|
|
|
* |
193
|
|
|
* @param Element $contextElement |
194
|
|
|
* @return boolean |
195
|
|
|
*/ |
196
|
|
|
public function getDefaultVisibilityForTTNewsElement(Element $contextElement) { |
197
|
|
|
return $this->triggerDefaultVisibilityHooks('getDefaultVisibilityForTTNewsElement', $this->row['tx_languagevisibility_defaultvisibilityttnewsel'], $contextElement); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $key |
202
|
|
|
* @param $visibilityDefault |
203
|
|
|
* @param Element $contextElement |
204
|
|
|
* @return mixed |
205
|
|
|
*/ |
206
|
|
|
protected function triggerDefaultVisibilityHooks($key, $visibilityDefault, Element $contextElement) { |
207
|
|
|
$result = array( |
208
|
|
|
'priority' => 10, |
209
|
|
|
'visibility' => $visibilityDefault, |
210
|
|
|
); |
211
|
|
|
$visibility = $result; |
212
|
|
|
if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility'][$key])) { |
213
|
|
|
|
214
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['languagevisibility'][$key] as $classRef) { |
215
|
|
|
$hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); |
216
|
|
|
if (method_exists($hookObj, $key)) { |
217
|
|
|
$result = $hookObj->$key($this, $visibility, $contextElement); |
218
|
|
|
if ($result['priority'] > $visibility['priority']) { |
219
|
|
|
$visibility = $result; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
return $visibility['visibility']; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Method to get the primary key of the language record. |
229
|
|
|
* |
230
|
|
|
* @return int |
231
|
|
|
*/ |
232
|
|
|
public function getUid() { |
233
|
|
|
return $this->row['uid']; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Method to determine the lg_iso_2 code from the static languages record. |
238
|
|
|
* |
239
|
|
|
* @return string |
240
|
|
|
*/ |
241
|
|
|
public function getIsoCode() { |
242
|
|
|
if (! isset($this->lg_iso_2)) { |
243
|
|
|
// Finding the ISO code: |
244
|
|
|
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('lg_iso_2', 'static_languages', 'uid=' . intval($this->row['static_lang_isocode']), '', ''); |
245
|
|
|
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
246
|
|
|
$this->lg_iso_2 = $row['lg_iso_2']; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return $this->lg_iso_2; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Returns the title of the language. |
254
|
|
|
* |
255
|
|
|
* @param $pidForDefault |
256
|
|
|
* @return string |
257
|
|
|
*/ |
258
|
|
|
public function getTitle($pidForDefault = '') { |
259
|
|
|
if ($this->getUid() == '0') { |
260
|
|
|
if ($pidForDefault == '') { |
261
|
|
|
$pidForDefault = $this->_guessCurrentPid(); |
262
|
|
|
} |
263
|
|
|
$sharedTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pidForDefault, 'mod.SHARED'); |
|
|
|
|
264
|
|
|
|
265
|
|
|
return strlen($sharedTSconfig['properties']['defaultLanguageLabel']) ? $sharedTSconfig['properties']['defaultLanguageLabel'] : 'Default'; |
266
|
|
|
} else { |
267
|
|
|
return $this->row['title']; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
protected function _guessCurrentPid() { |
272
|
|
|
return \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param Optional the pid of the page. This can be used to get the correct flag for default language (which is set in tsconfig) |
277
|
|
|
**/ |
278
|
|
|
public function getFlagImg($pidForDefault = '') { |
279
|
|
|
$cache_key = 'pid:' . $pidForDefault . 'uid:' . $this->getUid(); |
280
|
|
|
if ( !isset(self::$flagCache[$cache_key]) ) { |
281
|
|
|
self::$flagCache[$cache_key] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon($this->getFlagName($pidForDefault)); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return self::$flagCache[$cache_key]; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $pidForDefault |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
protected function getFlagName($pidForDefault = '') { |
292
|
|
|
if ($this->getUid() == '0') { |
293
|
|
|
$sharedTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pidForDefault, 'mod.SHARED'); |
294
|
|
|
$flag = $sharedTSconfig['properties']['defaultLanguageFlag']; |
295
|
|
|
} else { |
296
|
|
|
$flag = $this->row['flag']; |
297
|
|
|
} |
298
|
|
|
return 'flags-' . $flag; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @param Optional the pid of the page. This can be used to get the correct flagpath for default language (which is set in tsconfig) |
303
|
|
|
**/ |
304
|
|
|
public function getFlagImgPath($pidForDefault = '', $BACK_PATH = '') { |
305
|
|
|
$flagAbsPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($GLOBALS['TCA']['sys_language']['columns']['flag']['config']['fileFolder']); |
306
|
|
|
|
307
|
|
|
$flagIconPath = $BACK_PATH . '../' . substr($flagAbsPath, strlen(PATH_site)); |
308
|
|
|
if ($this->getUid() == '0') { |
309
|
|
|
if ($pidForDefault == '') { |
310
|
|
|
$pidForDefault = $this->_guessCurrentPid(); |
311
|
|
|
} |
312
|
|
|
$sharedTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pidForDefault, 'mod.SHARED'); |
|
|
|
|
313
|
|
|
$path = strlen($sharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath . $sharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath . $sharedTSconfig['properties']['defaultLanguageFlag'] : NULL; |
314
|
|
|
} else { |
315
|
|
|
$path = $flagIconPath . $this->row['flag']; |
316
|
|
|
} |
317
|
|
|
return $path; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* checks if the given languageid is part of the fallback of this language |
322
|
|
|
* (used for permission options in the backend) |
323
|
|
|
* |
324
|
|
|
* @param int uid |
325
|
|
|
* @param Element $el |
326
|
|
|
* @return boolean |
327
|
|
|
*/ |
328
|
|
|
public function isLanguageUidInFallbackOrder($uid, Element $el) { |
329
|
|
|
$fallbacks = $this->getFallbackOrder($el); |
330
|
|
|
return in_array($uid, $fallbacks); |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: