Total Complexity | 148 |
Total Lines | 1312 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like tx_dlf_helper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use tx_dlf_helper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class tx_dlf_helper { |
||
22 | |||
23 | /** |
||
24 | * The extension key |
||
25 | * |
||
26 | * @var string |
||
27 | * @access public |
||
28 | */ |
||
29 | public static $extKey = 'dlf'; |
||
30 | |||
31 | /** |
||
32 | * The locallang array for common use |
||
33 | * |
||
34 | * @var array |
||
35 | * @access protected |
||
36 | */ |
||
37 | protected static $locallang = array (); |
||
38 | |||
39 | /** |
||
40 | * Adds a message to the message queue. |
||
41 | * |
||
42 | * @access public |
||
43 | * |
||
44 | * @param \TYPO3\CMS\Core\Messaging\FlashMessage $message: Instance of \TYPO3\CMS\Core\Messaging\FlashMessage |
||
45 | * |
||
46 | * @return void |
||
47 | */ |
||
48 | public static function addMessage($message) { |
||
49 | |||
50 | $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'); |
||
51 | |||
52 | $flashMessageService->getMessageQueueByIdentifier()->enqueue($message); |
||
53 | |||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Implements array_merge_recursive_overrule() in a cross-version way |
||
58 | * This code is a copy from realurl, written by Dmitry Dulepov <[email protected]>. |
||
59 | * |
||
60 | * @access public |
||
61 | * |
||
62 | * @param array $array1: First array |
||
63 | * @param array $array2: Second array |
||
64 | * |
||
65 | * @return array Merged array with second array overruling first one |
||
66 | */ |
||
67 | static public function array_merge_recursive_overrule($array1, $array2) { |
||
80 | |||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Check if given identifier is a valid identifier of the German National Library |
||
85 | * @see http://support.d-nb.de/iltis/onlineRoutinen/Pruefziffernberechnung.htm |
||
86 | * |
||
87 | * @access public |
||
88 | * |
||
89 | * @param string $id: The identifier to check |
||
90 | * @param string $type: What type is the identifier supposed to be? |
||
91 | * Possible values: PPN, IDN, PND, ZDB, SWD, GKD |
||
92 | * |
||
93 | * @return boolean Is $id a valid GNL identifier of the given $type? |
||
94 | */ |
||
95 | public static function checkIdentifier($id, $type) { |
||
96 | |||
97 | $digits = substr($id, 0, 8); |
||
98 | |||
99 | $checksum = 0; |
||
100 | |||
101 | for ($i = 0, $j = strlen($digits); $i < $j; $i++) { |
||
102 | |||
103 | $checksum += (9 - $i) * intval(substr($digits, $i, 1)); |
||
104 | |||
105 | } |
||
106 | |||
107 | $checksum = (11 - ($checksum % 11)) % 11; |
||
108 | |||
109 | switch (strtoupper($type)) { |
||
110 | |||
111 | case 'PPN': |
||
112 | case 'IDN': |
||
113 | case 'PND': |
||
114 | |||
115 | if ($checksum == 10) { |
||
116 | |||
117 | $checksum = 'X'; |
||
118 | |||
119 | } |
||
120 | |||
121 | if (!preg_match('/[0-9]{8}[0-9X]{1}/i', $id)) { |
||
122 | |||
123 | return FALSE; |
||
124 | |||
125 | } elseif (strtoupper(substr($id, -1, 1)) != $checksum) { |
||
126 | |||
127 | return FALSE; |
||
128 | |||
129 | } |
||
130 | |||
131 | break; |
||
132 | |||
133 | case 'ZDB': |
||
134 | |||
135 | if ($checksum == 10) { |
||
136 | |||
137 | $checksum = 'X'; |
||
138 | |||
139 | } |
||
140 | |||
141 | if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) { |
||
142 | |||
143 | return FALSE; |
||
144 | |||
145 | } elseif (strtoupper(substr($id, -1, 1)) != $checksum) { |
||
146 | |||
147 | return FALSE; |
||
148 | |||
149 | } |
||
150 | |||
151 | break; |
||
152 | |||
153 | case 'SWD': |
||
154 | |||
155 | $checksum = 11 - $checksum; |
||
156 | |||
157 | if (!preg_match('/[0-9]{8}-[0-9]{1}/i', $id)) { |
||
158 | |||
159 | return FALSE; |
||
160 | |||
161 | } elseif ($checksum == 10) { |
||
162 | |||
163 | return self::checkIdentifier(($digits + 1).substr($id, -2, 2), 'SWD'); |
||
164 | |||
165 | } elseif (substr($id, -1, 1) != $checksum) { |
||
166 | |||
167 | return FALSE; |
||
168 | |||
169 | } |
||
170 | |||
171 | break; |
||
172 | |||
173 | case 'GKD': |
||
174 | |||
175 | $checksum = 11 - $checksum; |
||
176 | |||
177 | if ($checksum == 10) { |
||
178 | |||
179 | $checksum = 'X'; |
||
180 | |||
181 | } |
||
182 | |||
183 | if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) { |
||
184 | |||
185 | return FALSE; |
||
186 | |||
187 | } elseif (strtoupper(substr($id, -1, 1)) != $checksum) { |
||
188 | |||
189 | return FALSE; |
||
190 | |||
191 | } |
||
192 | |||
193 | break; |
||
194 | |||
195 | } |
||
196 | |||
197 | return TRUE; |
||
198 | |||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Decrypt encrypted value with given control hash |
||
203 | * @see http://yavkata.co.uk/weblog/php/securing-html-hidden-input-fields-using-encryption-and-hashing/ |
||
204 | * |
||
205 | * @access public |
||
206 | * |
||
207 | * @param string $encrypted: The encrypted value to decrypt |
||
208 | * @param string $hash: The control hash for decrypting |
||
209 | * |
||
210 | * @return mixed The decrypted value or NULL on error |
||
211 | */ |
||
212 | public static function decrypt($encrypted, $hash) { |
||
213 | |||
214 | $decrypted = NULL; |
||
215 | |||
216 | // Check for PHP extension "mcrypt". |
||
217 | if (!extension_loaded('mcrypt')) { |
||
218 | |||
219 | if (TYPO3_DLOG) { |
||
220 | |||
221 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] PHP extension "mcrypt" not available', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
222 | |||
223 | } |
||
224 | |||
225 | return; |
||
226 | |||
227 | } |
||
228 | |||
229 | if (empty($encrypted) || empty($hash)) { |
||
230 | |||
231 | if (TYPO3_DLOG) { |
||
232 | |||
233 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] Invalid parameters given for decryption', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
234 | |||
235 | } |
||
236 | |||
237 | return; |
||
238 | |||
239 | } |
||
240 | |||
241 | if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) { |
||
242 | |||
243 | if (TYPO3_DLOG) { |
||
244 | |||
245 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] No encryption key set in TYPO3 configuration', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
246 | |||
247 | } |
||
248 | |||
249 | return; |
||
250 | |||
251 | } |
||
252 | |||
253 | $iv = substr(md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CFB)); |
||
254 | |||
255 | $decrypted = mcrypt_decrypt(MCRYPT_BLOWFISH, substr($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 0, 56), base64_decode($encrypted), MCRYPT_MODE_CFB, $iv); |
||
256 | |||
257 | $salt = substr($hash, 0, 10); |
||
258 | |||
259 | $hashed = $salt.substr(sha1($salt.$decrypted), -10); |
||
260 | |||
261 | if ($hashed !== $hash) { |
||
262 | |||
263 | if (TYPO3_DLOG) { |
||
264 | |||
265 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] Invalid hash "'.$hash.'" given for decryption', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
266 | |||
267 | } |
||
268 | |||
269 | return; |
||
270 | |||
271 | } |
||
272 | |||
273 | return $decrypted; |
||
274 | |||
275 | } |
||
276 | |||
277 | /** |
||
278 | * Encrypt the given string |
||
279 | * @see http://yavkata.co.uk/weblog/php/securing-html-hidden-input-fields-using-encryption-and-hashing/ |
||
280 | * |
||
281 | * @access public |
||
282 | * |
||
283 | * @param string $string: The string to encrypt |
||
284 | * |
||
285 | * @return array Array with encrypted string and control hash |
||
286 | */ |
||
287 | public static function encrypt($string) { |
||
323 | |||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Get a backend user object (even in frontend mode) |
||
328 | * |
||
329 | * @access public |
||
330 | * |
||
331 | * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication Instance of \TYPO3\CMS\Core\Authentication\BackendUserAuthentication or NULL on failure |
||
332 | */ |
||
333 | public static function getBeUser() { |
||
334 | |||
335 | if (TYPO3_MODE === 'FE' || TYPO3_MODE === 'BE') { |
||
336 | |||
337 | // Initialize backend session with CLI user's rights. |
||
338 | $userObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication'); |
||
339 | |||
340 | $userObj->dontSetCookie = TRUE; |
||
341 | |||
342 | $userObj->start(); |
||
343 | |||
344 | $userObj->setBeUserByName('_cli_dlf'); |
||
345 | |||
346 | $userObj->backendCheckLogin(); |
||
347 | |||
348 | return $userObj; |
||
349 | |||
350 | } else { |
||
351 | |||
352 | if (TYPO3_DLOG) { |
||
353 | |||
354 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getBeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
355 | |||
356 | } |
||
357 | |||
358 | return; |
||
359 | |||
360 | } |
||
361 | |||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Clean up a string to use in an URL. |
||
366 | * |
||
367 | * @access public |
||
368 | * |
||
369 | * @param string $string: The string to clean up |
||
370 | * |
||
371 | * @return string The cleaned up string |
||
372 | */ |
||
373 | public static function getCleanString($string) { |
||
374 | |||
375 | // Convert to lowercase. |
||
376 | $string = strtolower($string); |
||
377 | |||
378 | // Remove non-alphanumeric characters. |
||
379 | $string = preg_replace('/[^a-z0-9_\s-]/', '', $string); |
||
380 | |||
381 | // Remove multiple dashes or whitespaces. |
||
382 | $string = preg_replace('/[\s-]+/', ' ', $string); |
||
383 | |||
384 | // Convert whitespaces and underscore to dash. |
||
385 | $string = preg_replace('/[\s_]/', '-', $string); |
||
386 | |||
387 | return $string; |
||
388 | |||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Get the current frontend user object |
||
393 | * |
||
394 | * @access public |
||
395 | * |
||
396 | * @return \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication Instance of \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication or NULL on failure |
||
397 | */ |
||
398 | public static function getFeUser() { |
||
399 | |||
400 | if (TYPO3_MODE === 'FE') { |
||
401 | |||
402 | // Check if a user is currently logged in. |
||
403 | if (!empty($GLOBALS['TSFE']->loginUser)) { |
||
404 | |||
405 | return $GLOBALS['TSFE']->fe_user; |
||
406 | |||
407 | } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID') !== NULL) { |
||
408 | |||
409 | return \TYPO3\CMS\Frontend\Utility\EidUtility::initFeUser(); |
||
410 | |||
411 | } |
||
412 | |||
413 | } else { |
||
414 | |||
415 | if (TYPO3_DLOG) { |
||
416 | |||
417 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getFeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
418 | |||
419 | } |
||
420 | |||
421 | } |
||
422 | |||
423 | return; |
||
424 | |||
425 | } |
||
426 | |||
427 | /** |
||
428 | * Get the registered hook objects for a class |
||
429 | * |
||
430 | * @access public |
||
431 | * |
||
432 | * @param string $scriptRelPath: The path to the class file |
||
433 | * |
||
434 | * @return array Array of hook objects for the class |
||
435 | */ |
||
436 | public static function getHookObjects($scriptRelPath) { |
||
437 | |||
438 | $hookObjects = array (); |
||
439 | |||
440 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'])) { |
||
441 | |||
442 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'] as $classRef) { |
||
443 | |||
444 | $hookObjects[] = &\TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); |
||
445 | |||
446 | } |
||
447 | |||
448 | } |
||
449 | |||
450 | return $hookObjects; |
||
451 | |||
452 | } |
||
453 | |||
454 | /** |
||
455 | * Get the "index_name" for an UID |
||
456 | * |
||
457 | * @access public |
||
458 | * |
||
459 | * @param integer $uid: The UID of the record |
||
460 | * @param string $table: Get the "index_name" from this table |
||
461 | * @param integer $pid: Get the "index_name" from this page |
||
462 | * |
||
463 | * @return string "index_name" for the given UID |
||
464 | */ |
||
465 | public static function getIndexName($uid, $table, $pid = -1) { |
||
466 | |||
467 | // Save parameters for logging purposes. |
||
468 | $_uid = $uid; |
||
469 | |||
470 | $_pid = $pid; |
||
471 | |||
472 | // Sanitize input. |
||
473 | $uid = max(intval($uid), 0); |
||
474 | |||
475 | if (!$uid || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'))) { |
||
476 | |||
477 | if (TYPO3_DLOG) { |
||
478 | |||
479 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] Invalid UID "'.$uid.'" or table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
480 | |||
481 | } |
||
482 | |||
483 | return ''; |
||
484 | |||
485 | } |
||
486 | |||
487 | $where = ''; |
||
488 | |||
489 | // Should we check for a specific PID, too? |
||
490 | if ($pid !== -1) { |
||
491 | |||
492 | $pid = max(intval($pid), 0); |
||
493 | |||
494 | $where = ' AND '.$table.'.pid='.$pid; |
||
495 | |||
496 | } |
||
497 | |||
498 | // Get index_name from database. |
||
499 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
500 | $table.'.index_name AS index_name', |
||
501 | $table, |
||
502 | $table.'.uid='.$uid.$where.self::whereClause($table), |
||
503 | '', |
||
504 | '', |
||
505 | '1' |
||
506 | ); |
||
507 | |||
508 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
509 | |||
510 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
511 | |||
512 | return $resArray['index_name']; |
||
513 | |||
514 | } else { |
||
515 | |||
516 | if (TYPO3_DLOG) { |
||
517 | |||
518 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] No "index_name" with UID "'.$uid.'" and PID "'.$pid.'" found in table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
519 | |||
520 | } |
||
521 | |||
522 | return ''; |
||
523 | |||
524 | } |
||
525 | |||
526 | } |
||
527 | |||
528 | /** |
||
529 | * Get the UID for a given "index_name" |
||
530 | * |
||
531 | * @access public |
||
532 | * |
||
533 | * @param integer $index_name: The index_name of the record |
||
534 | * @param string $table: Get the "index_name" from this table |
||
535 | * @param integer $pid: Get the "index_name" from this page |
||
536 | * |
||
537 | * @return string "uid" for the given index_name |
||
538 | */ |
||
539 | public static function getIdFromIndexName($index_name, $table, $pid = -1) { |
||
540 | |||
541 | // Save parameters for logging purposes. |
||
542 | $_index_name = $index_name; |
||
543 | |||
544 | $_pid = $pid; |
||
545 | |||
546 | if (!$index_name || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'))) { |
||
547 | |||
548 | if (TYPO3_DLOG) { |
||
549 | |||
550 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getIdFromIndexName('.$_index_name.', '.$table.', '.$_pid.')] Invalid UID "'.$index_name.'" or table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
551 | |||
552 | } |
||
553 | |||
554 | return ''; |
||
555 | |||
556 | } |
||
557 | |||
558 | $where = ''; |
||
559 | |||
560 | // Should we check for a specific PID, too? |
||
561 | if ($pid !== -1) { |
||
562 | |||
563 | $pid = max(intval($pid), 0); |
||
564 | |||
565 | $where = ' AND '.$table.'.pid='.$pid; |
||
566 | |||
567 | } |
||
568 | |||
569 | // Get index_name from database. |
||
570 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
571 | $table.'.uid AS uid', |
||
572 | $table, |
||
573 | $table.'.index_name="'.$index_name.'"'.$where.self::whereClause($table), |
||
574 | '', |
||
575 | '', |
||
576 | '1' |
||
577 | ); |
||
578 | |||
579 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
580 | |||
581 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
582 | |||
583 | return $resArray['uid']; |
||
584 | |||
585 | } else { |
||
586 | |||
587 | if (TYPO3_DLOG) { |
||
588 | |||
589 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getIdFromIndexName('.$_index_name.', '.$table.', '.$_pid.')] No UID for given "index_name" "'.$index_name.'" and PID "'.$pid.'" found in table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
590 | |||
591 | } |
||
592 | |||
593 | return ''; |
||
594 | |||
595 | } |
||
596 | |||
597 | } |
||
598 | |||
599 | /** |
||
600 | * Get language name from ISO code |
||
601 | * |
||
602 | * @access public |
||
603 | * |
||
604 | * @param string $code: ISO 639-1 or ISO 639-2/B language code |
||
605 | * |
||
606 | * @return string Localized full name of language or unchanged input |
||
607 | */ |
||
608 | public static function getLanguageName($code) { |
||
609 | |||
610 | // Analyze code and set appropriate ISO table. |
||
611 | $isoCode = strtolower(trim($code)); |
||
612 | |||
613 | if (preg_match('/^[a-z]{3}$/', $isoCode)) { |
||
614 | |||
615 | $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'lib/ISO-639/iso-639-2b.xml'; |
||
616 | |||
617 | } elseif (preg_match('/^[a-z]{2}$/', $isoCode)) { |
||
618 | |||
619 | $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'lib/ISO-639/iso-639-1.xml'; |
||
620 | |||
621 | } else { |
||
622 | |||
623 | // No ISO code, return unchanged. |
||
624 | return $code; |
||
625 | |||
626 | } |
||
627 | |||
628 | // Load ISO table and get localized full name of language. |
||
629 | if (TYPO3_MODE === 'FE') { |
||
630 | |||
631 | $iso639 = $GLOBALS['TSFE']->readLLfile($file); |
||
632 | |||
633 | if (!empty($iso639['default'][$isoCode])) { |
||
634 | |||
635 | $lang = $GLOBALS['TSFE']->getLLL($isoCode, $iso639); |
||
636 | |||
637 | } |
||
638 | |||
639 | } elseif (TYPO3_MODE === 'BE') { |
||
640 | |||
641 | $iso639 = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE); |
||
642 | |||
643 | if (!empty($iso639['default'][$isoCode])) { |
||
644 | |||
645 | $lang = $GLOBALS['LANG']->getLLL($isoCode, $iso639, FALSE); |
||
646 | |||
647 | } |
||
648 | |||
649 | } else { |
||
650 | |||
651 | if (TYPO3_DLOG) { |
||
652 | |||
653 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getLanguageName('.$code.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
654 | |||
655 | } |
||
656 | |||
657 | return $code; |
||
658 | |||
659 | } |
||
660 | |||
661 | if (!empty($lang)) { |
||
662 | |||
663 | return $lang; |
||
664 | |||
665 | } else { |
||
666 | |||
667 | if (TYPO3_DLOG) { |
||
668 | |||
669 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getLanguageName('.$code.')] Language code "'.$code.'" not found in ISO-639 table', self::$extKey, SYSLOG_SEVERITY_NOTICE); |
||
670 | |||
671 | } |
||
672 | |||
673 | return $code; |
||
674 | |||
675 | } |
||
676 | |||
677 | } |
||
678 | |||
679 | /** |
||
680 | * Wrapper function for getting localizations in frontend and backend |
||
681 | * |
||
682 | * @param string $key: The locallang key to translate |
||
683 | * @param boolean $hsc: Should the result be htmlspecialchar()'ed? |
||
684 | * @param string $default: Default return value if no translation is available |
||
685 | * |
||
686 | * @return string The translated string or the given key on failure |
||
687 | */ |
||
688 | public static function getLL($key, $hsc = FALSE, $default = '') { |
||
689 | |||
690 | // Set initial output to default value. |
||
691 | $translated = (string) $default; |
||
692 | |||
693 | // Load common locallang file. |
||
694 | if (empty(self::$locallang)) { |
||
695 | |||
696 | $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey, 'common/locallang.xml'); |
||
697 | |||
698 | if (TYPO3_MODE === 'FE') { |
||
699 | |||
700 | self::$locallang = $GLOBALS['TSFE']->readLLfile($file); |
||
701 | |||
702 | } elseif (TYPO3_MODE === 'BE') { |
||
703 | |||
704 | self::$locallang = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE); |
||
705 | |||
706 | } elseif (TYPO3_DLOG) { |
||
707 | |||
708 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getLL('.$key.', '.$default.', ['.($hsc ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
709 | |||
710 | } |
||
711 | |||
712 | } |
||
713 | |||
714 | // Get translation. |
||
715 | if (!empty(self::$locallang['default'][$key])) { |
||
716 | |||
717 | if (TYPO3_MODE === 'FE') { |
||
718 | |||
719 | $translated = $GLOBALS['TSFE']->getLLL($key, self::$locallang); |
||
720 | |||
721 | } elseif (TYPO3_MODE === 'BE') { |
||
722 | |||
723 | $translated = $GLOBALS['LANG']->getLLL($key, self::$locallang, FALSE); |
||
724 | |||
725 | } elseif (TYPO3_DLOG) { |
||
726 | |||
727 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getLL('.$key.', '.$default.', ['.($hsc ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
728 | |||
729 | } |
||
730 | |||
731 | } |
||
732 | |||
733 | // Escape HTML characters if applicable. |
||
734 | if ($hsc) { |
||
735 | |||
736 | $translated = htmlspecialchars($translated); |
||
737 | |||
738 | } |
||
739 | |||
740 | return $translated; |
||
741 | |||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Get the URN of an object |
||
746 | * @see http://www.persistent-identifier.de/?link=316 |
||
747 | * |
||
748 | * @access public |
||
749 | * |
||
750 | * @param string $base: The namespace and base URN |
||
751 | * @param string $id: The object's identifier |
||
752 | * |
||
753 | * @return string Uniform Resource Name as string |
||
754 | */ |
||
755 | public static function getURN($base, $id) { |
||
756 | |||
757 | $concordance = array ( |
||
758 | '0' => 1, |
||
759 | '1' => 2, |
||
760 | '2' => 3, |
||
761 | '3' => 4, |
||
762 | '4' => 5, |
||
763 | '5' => 6, |
||
764 | '6' => 7, |
||
765 | '7' => 8, |
||
766 | '8' => 9, |
||
767 | '9' => 41, |
||
768 | 'a' => 18, |
||
769 | 'b' => 14, |
||
770 | 'c' => 19, |
||
771 | 'd' => 15, |
||
772 | 'e' => 16, |
||
773 | 'f' => 21, |
||
774 | 'g' => 22, |
||
775 | 'h' => 23, |
||
776 | 'i' => 24, |
||
777 | 'j' => 25, |
||
778 | 'k' => 42, |
||
779 | 'l' => 26, |
||
780 | 'm' => 27, |
||
781 | 'n' => 13, |
||
782 | 'o' => 28, |
||
783 | 'p' => 29, |
||
784 | 'q' => 31, |
||
785 | 'r' => 12, |
||
786 | 's' => 32, |
||
787 | 't' => 33, |
||
788 | 'u' => 11, |
||
789 | 'v' => 34, |
||
790 | 'w' => 35, |
||
791 | 'x' => 36, |
||
792 | 'y' => 37, |
||
793 | 'z' => 38, |
||
794 | '-' => 39, |
||
795 | ':' => 17, |
||
796 | ); |
||
797 | |||
798 | $urn = strtolower($base.$id); |
||
799 | |||
800 | if (preg_match('/[^a-z0-9:-]/', $urn)) { |
||
801 | |||
802 | if (TYPO3_DLOG) { |
||
803 | |||
804 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->getURN('.$base.', '.$id.')] Invalid chars in given parameters', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
805 | |||
806 | } |
||
807 | |||
808 | return ''; |
||
809 | |||
810 | } |
||
811 | |||
812 | $digits = ''; |
||
813 | |||
814 | for ($i = 0, $j = strlen($urn); $i < $j; $i++) { |
||
815 | |||
816 | $digits .= $concordance[substr($urn, $i, 1)]; |
||
817 | |||
818 | } |
||
819 | |||
820 | $checksum = 0; |
||
821 | |||
822 | for ($i = 0, $j = strlen($digits); $i < $j; $i++) { |
||
823 | |||
824 | $checksum += ($i + 1) * intval(substr($digits, $i, 1)); |
||
825 | |||
826 | } |
||
827 | |||
828 | $checksum = substr(intval($checksum / intval(substr($digits, -1, 1))), -1, 1); |
||
829 | |||
830 | return $base.$id.$checksum; |
||
831 | |||
832 | } |
||
833 | |||
834 | /** |
||
835 | * Check if given ID is a valid Pica Production Number (PPN) |
||
836 | * |
||
837 | * @access public |
||
838 | * |
||
839 | * @param string $ppn: The identifier to check |
||
840 | * |
||
841 | * @return boolean Is $id a valid PPN? |
||
842 | */ |
||
843 | public static function isPPN($id) { |
||
844 | |||
845 | return self::checkIdentifier($id, 'PPN'); |
||
846 | |||
847 | } |
||
848 | |||
849 | /** |
||
850 | * Load value from user's session. |
||
851 | * |
||
852 | * @access public |
||
853 | * |
||
854 | * @param string $key: Session data key for retrieval |
||
855 | * |
||
856 | * @return mixed Session value for given key or NULL on failure |
||
857 | */ |
||
858 | public static function loadFromSession($key) { |
||
859 | |||
860 | // Save parameter for logging purposes. |
||
861 | $_key = $key; |
||
862 | |||
863 | // Cast to string for security reasons. |
||
864 | $key = (string) $key; |
||
865 | |||
866 | if (!$key) { |
||
867 | |||
868 | if (TYPO3_DLOG) { |
||
869 | |||
870 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->loadFromSession('.$_key.')] Invalid key "'.$key.'" for session data retrieval', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
871 | |||
872 | } |
||
873 | |||
874 | return; |
||
875 | |||
876 | } |
||
877 | |||
878 | // Get the session data. |
||
879 | if (TYPO3_MODE === 'FE') { |
||
880 | |||
881 | return $GLOBALS['TSFE']->fe_user->getKey('ses', $key); |
||
882 | |||
883 | } elseif (TYPO3_MODE === 'BE') { |
||
884 | |||
885 | return $GLOBALS['BE_USER']->getSessionData($key); |
||
886 | |||
887 | } else { |
||
888 | |||
889 | if (TYPO3_DLOG) { |
||
890 | |||
891 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->loadFromSession('.$_key.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
892 | |||
893 | } |
||
894 | |||
895 | return; |
||
896 | |||
897 | } |
||
898 | |||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Process a data and/or command map with TYPO3 core engine. |
||
903 | * |
||
904 | * @access public |
||
905 | * |
||
906 | * @param array $data: Data map |
||
907 | * @param array $cmd: Command map |
||
908 | * @param boolean $reverseOrder: Should the command map be processed first? |
||
909 | * @param boolean $be_user: Use current backend user's rights for processing? |
||
910 | * |
||
911 | * @return array Array of substituted "NEW..." identifiers and their actual UIDs. |
||
912 | */ |
||
913 | public static function processDB(array $data = array (), array $cmd = array (), $reverseOrder = FALSE, $be_user = FALSE) { |
||
914 | |||
915 | // Instantiate TYPO3 core engine. |
||
916 | $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); |
||
917 | |||
918 | // Set some configuration variables. |
||
919 | $tce->stripslashes_values = FALSE; |
||
920 | |||
921 | // Get backend user for processing. |
||
922 | if ($be_user && isset($GLOBALS['BE_USER'])) { |
||
923 | |||
924 | $user = $GLOBALS['BE_USER']; |
||
925 | |||
926 | } else { |
||
927 | |||
928 | $user = self::getBeUser(); |
||
929 | |||
930 | } |
||
931 | |||
932 | // Load data and command arrays. |
||
933 | $tce->start($data, $cmd, $user); |
||
934 | |||
935 | // Process command map first if default order is reversed. |
||
936 | if ($cmd && $reverseOrder) { |
||
937 | |||
938 | $tce->process_cmdmap(); |
||
939 | |||
940 | } |
||
941 | |||
942 | // Process data map. |
||
943 | if ($data) { |
||
944 | |||
945 | $tce->process_datamap(); |
||
946 | |||
947 | } |
||
948 | |||
949 | // Process command map if processing order is not reversed. |
||
950 | if ($cmd && !$reverseOrder) { |
||
951 | |||
952 | $tce->process_cmdmap(); |
||
953 | |||
954 | } |
||
955 | |||
956 | return $tce->substNEWwithIDs; |
||
957 | |||
958 | } |
||
959 | |||
960 | /** |
||
961 | * Process a data and/or command map with TYPO3 core engine as admin. |
||
962 | * |
||
963 | * @access public |
||
964 | * |
||
965 | * @param array $data: Data map |
||
966 | * @param array $cmd: Command map |
||
967 | * @param boolean $reverseOrder: Should the command map be processed first? |
||
968 | * |
||
969 | * @return array Array of substituted "NEW..." identifiers and their actual UIDs. |
||
970 | */ |
||
971 | public static function processDBasAdmin(array $data = array (), array $cmd = array (), $reverseOrder = FALSE) { |
||
972 | |||
973 | if (TYPO3_MODE === 'BE' && $GLOBALS['BE_USER']->isAdmin()) { |
||
974 | |||
975 | return self::processDB($data, $cmd, $reverseOrder, TRUE); |
||
976 | |||
977 | } else { |
||
978 | |||
979 | if (TYPO3_DLOG) { |
||
980 | |||
981 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->processDBasAdmin([data->data], [data->cmd], ['.($reverseOrder ? 'TRUE' : 'FALSE').'])] Current backend user has no admin privileges', self::$extKey, SYSLOG_SEVERITY_ERROR, array ('data' => $data, 'cmd' => $cmd)); |
||
982 | |||
983 | } |
||
984 | |||
985 | return array (); |
||
986 | |||
987 | } |
||
988 | |||
989 | } |
||
990 | |||
991 | /** |
||
992 | * Fetches and renders all available flash messages from the queue. |
||
993 | * |
||
994 | * @return string All flash messages in the queue rendered as HTML. |
||
995 | */ |
||
996 | public static function renderFlashMessages() { |
||
997 | |||
998 | $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'); |
||
999 | |||
1000 | $content = ''; |
||
1001 | |||
1002 | if (version_compare(TYPO3_branch, '7.4', '<')) { |
||
1003 | |||
1004 | // For TYPO3 6.2 - 7.3, we can use the existing method. |
||
1005 | $content .= $flashMessageService->getMessageQueueByIdentifier()->renderFlashMessages(); |
||
1006 | |||
1007 | } else { |
||
1008 | |||
1009 | // Since TYPO3 7.4.0, \TYPO3\CMS\Core\Messaging\FlashMessageQueue::renderFlashMessages |
||
1010 | // uses htmlspecialchars on all texts, but we have message text with HTML tags. |
||
1011 | // Therefore we copy the implementation from 7.4.0, but remove the htmlspecialchars call. |
||
1012 | $flashMessages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush(); |
||
1013 | |||
1014 | if (!empty($flashMessages)) { |
||
1015 | |||
1016 | $content .= '<ul class="typo3-messages">'; |
||
1017 | |||
1018 | foreach ($flashMessages as $flashMessage) { |
||
1019 | |||
1020 | $severityClass = sprintf('alert %s', $flashMessage->getClass()); |
||
1021 | |||
1022 | //~ $messageContent = htmlspecialchars($flashMessage->getMessage()); |
||
1023 | |||
1024 | $messageContent = $flashMessage->getMessage(); |
||
1025 | |||
1026 | if ($flashMessage->getTitle() !== '') { |
||
1027 | |||
1028 | $messageContent = sprintf('<h4>%s</h4>', htmlspecialchars($flashMessage->getTitle())).$messageContent; |
||
1029 | |||
1030 | } |
||
1031 | |||
1032 | $content .= sprintf('<li class="%s">%s</li>', htmlspecialchars($severityClass), $messageContent); |
||
1033 | |||
1034 | } |
||
1035 | |||
1036 | $content .= '</ul>'; |
||
1037 | |||
1038 | } |
||
1039 | |||
1040 | } |
||
1041 | |||
1042 | return $content; |
||
1043 | |||
1044 | } |
||
1045 | |||
1046 | /** |
||
1047 | * Save given value to user's session. |
||
1048 | * |
||
1049 | * @access public |
||
1050 | * |
||
1051 | * @param mixed $value: Value to save |
||
1052 | * @param string $key: Session data key for saving |
||
1053 | * |
||
1054 | * @return boolean TRUE on success, FALSE on failure |
||
1055 | */ |
||
1056 | public static function saveToSession($value, $key) { |
||
1057 | |||
1058 | // Save parameter for logging purposes. |
||
1059 | $_key = $key; |
||
1060 | |||
1061 | // Cast to string for security reasons. |
||
1062 | $key = (string) $key; |
||
1063 | |||
1064 | if (!$key) { |
||
1065 | |||
1066 | if (TYPO3_DLOG) { |
||
1067 | |||
1068 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->saveToSession([data], '.$_key.')] Invalid key "'.$key.'" for session data saving', self::$extKey, SYSLOG_SEVERITY_WARNING, $value); |
||
1069 | |||
1070 | } |
||
1071 | |||
1072 | return FALSE; |
||
1073 | |||
1074 | } |
||
1075 | |||
1076 | // Save value in session data. |
||
1077 | if (TYPO3_MODE === 'FE') { |
||
1078 | |||
1079 | $GLOBALS['TSFE']->fe_user->setKey('ses', $key, $value); |
||
1080 | |||
1081 | $GLOBALS['TSFE']->fe_user->storeSessionData(); |
||
1082 | |||
1083 | return TRUE; |
||
1084 | |||
1085 | } elseif (TYPO3_MODE === 'BE') { |
||
1086 | |||
1087 | $GLOBALS['BE_USER']->setAndSaveSessionData($key, $value); |
||
1088 | |||
1089 | return TRUE; |
||
1090 | |||
1091 | } else { |
||
1092 | |||
1093 | if (TYPO3_DLOG) { |
||
1094 | |||
1095 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->saveToSession([data], '.$_key.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR, $data); |
||
1096 | |||
1097 | } |
||
1098 | |||
1099 | return FALSE; |
||
1100 | |||
1101 | } |
||
1102 | |||
1103 | } |
||
1104 | |||
1105 | /** |
||
1106 | * This translates an internal "index_name" |
||
1107 | * |
||
1108 | * @access public |
||
1109 | * |
||
1110 | * @param string $index_name: The internal "index_name" to translate |
||
1111 | * @param string $table: Get the translation from this table |
||
1112 | * @param string $pid: Get the translation from this page |
||
1113 | * |
||
1114 | * @return string Localized label for $index_name |
||
1115 | */ |
||
1116 | public static function translate($index_name, $table, $pid) { |
||
1117 | |||
1118 | // Save parameters for logging purposes. |
||
1119 | $_index_name = $index_name; |
||
1120 | |||
1121 | $_pid = $pid; |
||
1122 | |||
1123 | // Load labels into static variable for future use. |
||
1124 | static $labels = array (); |
||
1125 | |||
1126 | // Sanitize input. |
||
1127 | $pid = max(intval($pid), 0); |
||
1128 | |||
1129 | if (!$pid) { |
||
1130 | |||
1131 | if (TYPO3_DLOG) { |
||
1132 | |||
1133 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] Invalid PID "'.$pid.'" for translation', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
1134 | |||
1135 | } |
||
1136 | |||
1137 | return $index_name; |
||
1138 | |||
1139 | } |
||
1140 | |||
1141 | // Check if "index_name" is an UID. |
||
1142 | if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($index_name)) { |
||
1143 | |||
1144 | $index_name = self::getIndexName($index_name, $table, $pid); |
||
1145 | |||
1146 | } |
||
1147 | |||
1148 | /* $labels already contains the translated content element, but with the index_name of the translated content element itself |
||
1149 | * and not with the $index_name of the original that we receive here. So we have to determine the index_name of the |
||
1150 | * associated translated content element. E.g. $labels['title0'] != $index_name = title. */ |
||
1151 | |||
1152 | // First fetch the uid of the received index_name |
||
1153 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
1154 | 'uid, l18n_parent', |
||
1155 | $table, |
||
1156 | 'pid='.$pid.' AND index_name="'.$index_name.'"'.self::whereClause($table, TRUE), |
||
1157 | '', |
||
1158 | '', |
||
1159 | '' |
||
1160 | ); |
||
1161 | |||
1162 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
1163 | |||
1164 | // Now we use the uid of the l18_parent to fetch the index_name of the translated content element. |
||
1165 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
1166 | |||
1167 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
1168 | 'index_name', |
||
1169 | $table, |
||
1170 | 'pid='.$pid.' AND uid='.$resArray['l18n_parent'].' AND sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).self::whereClause($table, TRUE), |
||
1171 | '', |
||
1172 | '', |
||
1173 | '' |
||
1174 | ); |
||
1175 | |||
1176 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
1177 | |||
1178 | // If there is an translated content element, overwrite the received $index_name. |
||
1179 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
1180 | |||
1181 | $index_name = $resArray['index_name']; |
||
1182 | |||
1183 | } |
||
1184 | |||
1185 | } |
||
1186 | |||
1187 | // Check if we already got a translation. |
||
1188 | if (empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { |
||
1189 | |||
1190 | // Check if this table is allowed for translation. |
||
1191 | if (in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'))) { |
||
1192 | |||
1193 | $additionalWhere = ' AND sys_language_uid IN (-1,0)'; |
||
1194 | |||
1195 | if ($GLOBALS['TSFE']->sys_language_content > 0) { |
||
1196 | |||
1197 | $additionalWhere = ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).' AND l18n_parent=0))'; |
||
1198 | |||
1199 | } |
||
1200 | |||
1201 | // Get labels from database. |
||
1202 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
1203 | '*', |
||
1204 | $table, |
||
1205 | 'pid='.$pid.$additionalWhere.self::whereClause($table, TRUE), |
||
1206 | '', |
||
1207 | '', |
||
1208 | '' |
||
1209 | ); |
||
1210 | |||
1211 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
1212 | |||
1213 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
1214 | |||
1215 | // Overlay localized labels if available. |
||
1216 | if ($GLOBALS['TSFE']->sys_language_content > 0) { |
||
1217 | |||
1218 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
1219 | |||
1220 | } |
||
1221 | |||
1222 | if ($resArray) { |
||
1223 | |||
1224 | $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$resArray['index_name']] = $resArray['label']; |
||
1225 | |||
1226 | } |
||
1227 | |||
1228 | } |
||
1229 | |||
1230 | } else { |
||
1231 | |||
1232 | if (TYPO3_DLOG) { |
||
1233 | |||
1234 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] No translation with PID "'.$pid.'" available in table "'.$table.'" or translation not accessible', self::extKey, SYSLOG_SEVERITY_NOTICE); |
||
1235 | |||
1236 | } |
||
1237 | |||
1238 | } |
||
1239 | |||
1240 | } else { |
||
1241 | |||
1242 | if (TYPO3_DLOG) { |
||
1243 | |||
1244 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] No translations available for table "'.$table.'"', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
1245 | |||
1246 | } |
||
1247 | |||
1248 | } |
||
1249 | |||
1250 | } |
||
1251 | |||
1252 | if (!empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { |
||
1253 | |||
1254 | return $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name]; |
||
1255 | |||
1256 | } else { |
||
1257 | |||
1258 | return $index_name; |
||
1259 | |||
1260 | } |
||
1261 | |||
1262 | } |
||
1263 | |||
1264 | /** |
||
1265 | * This returns the additional WHERE clause of a table based on its TCA configuration |
||
1266 | * |
||
1267 | * @access public |
||
1268 | * |
||
1269 | * @param string $table: Table name as defined in TCA |
||
1270 | * @param boolean $showHidden: Ignore the hidden flag? |
||
1271 | * |
||
1272 | * @return string Additional WHERE clause |
||
1273 | */ |
||
1274 | public static function whereClause($table, $showHidden = FALSE) { |
||
1275 | |||
1276 | if (TYPO3_MODE === 'FE') { |
||
1277 | |||
1278 | // Table "tx_dlf_formats" always has PID 0. |
||
1279 | if ($table == 'tx_dlf_formats') { |
||
1280 | |||
1281 | return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table); |
||
1282 | |||
1283 | } |
||
1284 | |||
1285 | // Should we ignore the record's hidden flag? |
||
1286 | $ignoreHide = -1; |
||
1287 | |||
1288 | if ($showHidden) { |
||
1289 | |||
1290 | $ignoreHide = 1; |
||
1291 | |||
1292 | } |
||
1293 | |||
1294 | // $GLOBALS['TSFE']->sys_page is not always available in frontend. |
||
1295 | if (is_object($GLOBALS['TSFE']->sys_page)) { |
||
1296 | |||
1297 | return $GLOBALS['TSFE']->sys_page->enableFields($table, $ignoreHide); |
||
1298 | |||
1299 | } else { |
||
1300 | |||
1301 | $pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); |
||
1302 | |||
1303 | $GLOBALS['TSFE']->includeTCA(); |
||
1304 | |||
1305 | return $pageRepository->enableFields($table, $ignoreHide); |
||
1306 | |||
1307 | } |
||
1308 | |||
1309 | } elseif (TYPO3_MODE === 'BE') { |
||
1310 | |||
1311 | return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table); |
||
1312 | |||
1313 | } else { |
||
1314 | |||
1315 | if (TYPO3_DLOG) { |
||
1316 | |||
1317 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->whereClause('.$table.', ['.($showHidden ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
1318 | |||
1319 | } |
||
1320 | |||
1321 | return ' AND 1=-1'; |
||
1322 | |||
1323 | } |
||
1324 | |||
1325 | } |
||
1326 | |||
1327 | /** |
||
1328 | * This is a static class, thus no instances should be created |
||
1329 | * |
||
1330 | * @access private |
||
1331 | */ |
||
1332 | private function __construct() {} |
||
1333 | |||
1334 | } |
||
1335 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.