We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 152 |
| Total Lines | 1332 |
| 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) { |
||
| 68 | |||
| 69 | if (class_exists('\\TYPO3\\CMS\\Core\\Utility\\ArrayUtility')) { |
||
| 70 | |||
| 71 | \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($array1, $array2); |
||
| 72 | |||
| 73 | } else { |
||
| 74 | |||
| 75 | $array1 = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($array1, $array2); |
||
|
|
|||
| 76 | |||
| 77 | } |
||
| 78 | |||
| 79 | return $array1; |
||
| 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) { |
||
| 288 | |||
| 289 | // Check for PHP extension "mcrypt". |
||
| 290 | if (!extension_loaded('mcrypt')) { |
||
| 291 | |||
| 292 | if (TYPO3_DLOG) { |
||
| 293 | |||
| 294 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->encrypt('.$string.')] PHP extension "mcrypt" not available', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
| 295 | |||
| 296 | } |
||
| 297 | |||
| 298 | return; |
||
| 299 | |||
| 300 | } |
||
| 301 | |||
| 302 | if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) { |
||
| 303 | |||
| 304 | if (TYPO3_DLOG) { |
||
| 305 | |||
| 306 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->encrypt('.$string.')] No encryption key set in TYPO3 configuration', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
| 307 | |||
| 308 | } |
||
| 309 | |||
| 310 | return; |
||
| 311 | |||
| 312 | } |
||
| 313 | |||
| 314 | $iv = substr(md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CFB)); |
||
| 315 | |||
| 316 | $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, substr($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 0, 56), $string, MCRYPT_MODE_CFB, $iv)); |
||
| 317 | |||
| 318 | $salt = substr(md5(uniqid(rand(), TRUE)), 0, 10); |
||
| 319 | |||
| 320 | $hash = $salt.substr(sha1($salt.$string), -10); |
||
| 321 | |||
| 322 | return array ('encrypted' => $encrypted, 'hash' => $hash); |
||
| 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) { |
||
| 846 | |||
| 847 | } |
||
| 848 | |||
| 849 | /** |
||
| 850 | * Determine whether or not $url is a valid URL using HTTP or HTTPS scheme. |
||
| 851 | * |
||
| 852 | * @param string $url |
||
| 853 | * |
||
| 854 | * @return bool |
||
| 855 | */ |
||
| 856 | public static function isValidHttpUrl($url) |
||
| 857 | { |
||
| 858 | if (!\TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl($url)) { |
||
| 859 | return false; |
||
| 860 | } |
||
| 861 | |||
| 862 | $parsed = parse_url($url); |
||
| 863 | $scheme = isset($parsed['scheme']) ? $parsed['scheme'] : ''; |
||
| 864 | $schemeNormalized = strtolower($scheme); |
||
| 865 | |||
| 866 | return $schemeNormalized === 'http' || $schemeNormalized === 'https'; |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Load value from user's session. |
||
| 871 | * |
||
| 872 | * @access public |
||
| 873 | * |
||
| 874 | * @param string $key: Session data key for retrieval |
||
| 875 | * |
||
| 876 | * @return mixed Session value for given key or NULL on failure |
||
| 877 | */ |
||
| 878 | public static function loadFromSession($key) { |
||
| 879 | |||
| 880 | // Save parameter for logging purposes. |
||
| 881 | $_key = $key; |
||
| 882 | |||
| 883 | // Cast to string for security reasons. |
||
| 884 | $key = (string) $key; |
||
| 885 | |||
| 886 | if (!$key) { |
||
| 887 | |||
| 888 | if (TYPO3_DLOG) { |
||
| 889 | |||
| 890 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->loadFromSession('.$_key.')] Invalid key "'.$key.'" for session data retrieval', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
| 891 | |||
| 892 | } |
||
| 893 | |||
| 894 | return; |
||
| 895 | |||
| 896 | } |
||
| 897 | |||
| 898 | // Get the session data. |
||
| 899 | if (TYPO3_MODE === 'FE') { |
||
| 900 | |||
| 901 | return $GLOBALS['TSFE']->fe_user->getKey('ses', $key); |
||
| 902 | |||
| 903 | } elseif (TYPO3_MODE === 'BE') { |
||
| 904 | |||
| 905 | return $GLOBALS['BE_USER']->getSessionData($key); |
||
| 906 | |||
| 907 | } else { |
||
| 908 | |||
| 909 | if (TYPO3_DLOG) { |
||
| 910 | |||
| 911 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->loadFromSession('.$_key.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
| 912 | |||
| 913 | } |
||
| 914 | |||
| 915 | return; |
||
| 916 | |||
| 917 | } |
||
| 918 | |||
| 919 | } |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Process a data and/or command map with TYPO3 core engine. |
||
| 923 | * |
||
| 924 | * @access public |
||
| 925 | * |
||
| 926 | * @param array $data: Data map |
||
| 927 | * @param array $cmd: Command map |
||
| 928 | * @param boolean $reverseOrder: Should the command map be processed first? |
||
| 929 | * @param boolean $be_user: Use current backend user's rights for processing? |
||
| 930 | * |
||
| 931 | * @return array Array of substituted "NEW..." identifiers and their actual UIDs. |
||
| 932 | */ |
||
| 933 | public static function processDB(array $data = array (), array $cmd = array (), $reverseOrder = FALSE, $be_user = FALSE) { |
||
| 934 | |||
| 935 | // Instantiate TYPO3 core engine. |
||
| 936 | $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); |
||
| 937 | |||
| 938 | // Set some configuration variables. |
||
| 939 | $tce->stripslashes_values = FALSE; |
||
| 940 | |||
| 941 | // Get backend user for processing. |
||
| 942 | if ($be_user && isset($GLOBALS['BE_USER'])) { |
||
| 943 | |||
| 944 | $user = $GLOBALS['BE_USER']; |
||
| 945 | |||
| 946 | } else { |
||
| 947 | |||
| 948 | $user = self::getBeUser(); |
||
| 949 | |||
| 950 | } |
||
| 951 | |||
| 952 | // Load data and command arrays. |
||
| 953 | $tce->start($data, $cmd, $user); |
||
| 954 | |||
| 955 | // Process command map first if default order is reversed. |
||
| 956 | if ($cmd && $reverseOrder) { |
||
| 957 | |||
| 958 | $tce->process_cmdmap(); |
||
| 959 | |||
| 960 | } |
||
| 961 | |||
| 962 | // Process data map. |
||
| 963 | if ($data) { |
||
| 964 | |||
| 965 | $tce->process_datamap(); |
||
| 966 | |||
| 967 | } |
||
| 968 | |||
| 969 | // Process command map if processing order is not reversed. |
||
| 970 | if ($cmd && !$reverseOrder) { |
||
| 971 | |||
| 972 | $tce->process_cmdmap(); |
||
| 973 | |||
| 974 | } |
||
| 975 | |||
| 976 | return $tce->substNEWwithIDs; |
||
| 977 | |||
| 978 | } |
||
| 979 | |||
| 980 | /** |
||
| 981 | * Process a data and/or command map with TYPO3 core engine as admin. |
||
| 982 | * |
||
| 983 | * @access public |
||
| 984 | * |
||
| 985 | * @param array $data: Data map |
||
| 986 | * @param array $cmd: Command map |
||
| 987 | * @param boolean $reverseOrder: Should the command map be processed first? |
||
| 988 | * |
||
| 989 | * @return array Array of substituted "NEW..." identifiers and their actual UIDs. |
||
| 990 | */ |
||
| 991 | public static function processDBasAdmin(array $data = array (), array $cmd = array (), $reverseOrder = FALSE) { |
||
| 992 | |||
| 993 | if (TYPO3_MODE === 'BE' && $GLOBALS['BE_USER']->isAdmin()) { |
||
| 994 | |||
| 995 | return self::processDB($data, $cmd, $reverseOrder, TRUE); |
||
| 996 | |||
| 997 | } else { |
||
| 998 | |||
| 999 | if (TYPO3_DLOG) { |
||
| 1000 | |||
| 1001 | \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)); |
||
| 1002 | |||
| 1003 | } |
||
| 1004 | |||
| 1005 | return array (); |
||
| 1006 | |||
| 1007 | } |
||
| 1008 | |||
| 1009 | } |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Fetches and renders all available flash messages from the queue. |
||
| 1013 | * |
||
| 1014 | * @return string All flash messages in the queue rendered as HTML. |
||
| 1015 | */ |
||
| 1016 | public static function renderFlashMessages() { |
||
| 1017 | |||
| 1018 | $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService'); |
||
| 1019 | |||
| 1020 | $content = ''; |
||
| 1021 | |||
| 1022 | if (version_compare(TYPO3_branch, '7.4', '<')) { |
||
| 1023 | |||
| 1024 | // For TYPO3 6.2 - 7.3, we can use the existing method. |
||
| 1025 | $content .= $flashMessageService->getMessageQueueByIdentifier()->renderFlashMessages(); |
||
| 1026 | |||
| 1027 | } else { |
||
| 1028 | |||
| 1029 | // Since TYPO3 7.4.0, \TYPO3\CMS\Core\Messaging\FlashMessageQueue::renderFlashMessages |
||
| 1030 | // uses htmlspecialchars on all texts, but we have message text with HTML tags. |
||
| 1031 | // Therefore we copy the implementation from 7.4.0, but remove the htmlspecialchars call. |
||
| 1032 | $flashMessages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush(); |
||
| 1033 | |||
| 1034 | if (!empty($flashMessages)) { |
||
| 1035 | |||
| 1036 | $content .= '<ul class="typo3-messages">'; |
||
| 1037 | |||
| 1038 | foreach ($flashMessages as $flashMessage) { |
||
| 1039 | |||
| 1040 | $severityClass = sprintf('alert %s', $flashMessage->getClass()); |
||
| 1041 | |||
| 1042 | //~ $messageContent = htmlspecialchars($flashMessage->getMessage()); |
||
| 1043 | |||
| 1044 | $messageContent = $flashMessage->getMessage(); |
||
| 1045 | |||
| 1046 | if ($flashMessage->getTitle() !== '') { |
||
| 1047 | |||
| 1048 | $messageContent = sprintf('<h4>%s</h4>', htmlspecialchars($flashMessage->getTitle())).$messageContent; |
||
| 1049 | |||
| 1050 | } |
||
| 1051 | |||
| 1052 | $content .= sprintf('<li class="%s">%s</li>', htmlspecialchars($severityClass), $messageContent); |
||
| 1053 | |||
| 1054 | } |
||
| 1055 | |||
| 1056 | $content .= '</ul>'; |
||
| 1057 | |||
| 1058 | } |
||
| 1059 | |||
| 1060 | } |
||
| 1061 | |||
| 1062 | return $content; |
||
| 1063 | |||
| 1064 | } |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Save given value to user's session. |
||
| 1068 | * |
||
| 1069 | * @access public |
||
| 1070 | * |
||
| 1071 | * @param mixed $value: Value to save |
||
| 1072 | * @param string $key: Session data key for saving |
||
| 1073 | * |
||
| 1074 | * @return boolean TRUE on success, FALSE on failure |
||
| 1075 | */ |
||
| 1076 | public static function saveToSession($value, $key) { |
||
| 1077 | |||
| 1078 | // Save parameter for logging purposes. |
||
| 1079 | $_key = $key; |
||
| 1080 | |||
| 1081 | // Cast to string for security reasons. |
||
| 1082 | $key = (string) $key; |
||
| 1083 | |||
| 1084 | if (!$key) { |
||
| 1085 | |||
| 1086 | if (TYPO3_DLOG) { |
||
| 1087 | |||
| 1088 | \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); |
||
| 1089 | |||
| 1090 | } |
||
| 1091 | |||
| 1092 | return FALSE; |
||
| 1093 | |||
| 1094 | } |
||
| 1095 | |||
| 1096 | // Save value in session data. |
||
| 1097 | if (TYPO3_MODE === 'FE') { |
||
| 1098 | |||
| 1099 | $GLOBALS['TSFE']->fe_user->setKey('ses', $key, $value); |
||
| 1100 | |||
| 1101 | $GLOBALS['TSFE']->fe_user->storeSessionData(); |
||
| 1102 | |||
| 1103 | return TRUE; |
||
| 1104 | |||
| 1105 | } elseif (TYPO3_MODE === 'BE') { |
||
| 1106 | |||
| 1107 | $GLOBALS['BE_USER']->setAndSaveSessionData($key, $value); |
||
| 1108 | |||
| 1109 | return TRUE; |
||
| 1110 | |||
| 1111 | } else { |
||
| 1112 | |||
| 1113 | if (TYPO3_DLOG) { |
||
| 1114 | |||
| 1115 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->saveToSession([data], '.$_key.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR, $data); |
||
| 1116 | |||
| 1117 | } |
||
| 1118 | |||
| 1119 | return FALSE; |
||
| 1120 | |||
| 1121 | } |
||
| 1122 | |||
| 1123 | } |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * This translates an internal "index_name" |
||
| 1127 | * |
||
| 1128 | * @access public |
||
| 1129 | * |
||
| 1130 | * @param string $index_name: The internal "index_name" to translate |
||
| 1131 | * @param string $table: Get the translation from this table |
||
| 1132 | * @param string $pid: Get the translation from this page |
||
| 1133 | * |
||
| 1134 | * @return string Localized label for $index_name |
||
| 1135 | */ |
||
| 1136 | public static function translate($index_name, $table, $pid) { |
||
| 1137 | |||
| 1138 | // Save parameters for logging purposes. |
||
| 1139 | $_index_name = $index_name; |
||
| 1140 | |||
| 1141 | $_pid = $pid; |
||
| 1142 | |||
| 1143 | // Load labels into static variable for future use. |
||
| 1144 | static $labels = array (); |
||
| 1145 | |||
| 1146 | // Sanitize input. |
||
| 1147 | $pid = max(intval($pid), 0); |
||
| 1148 | |||
| 1149 | if (!$pid) { |
||
| 1150 | |||
| 1151 | if (TYPO3_DLOG) { |
||
| 1152 | |||
| 1153 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] Invalid PID "'.$pid.'" for translation', self::$extKey, SYSLOG_SEVERITY_WARNING); |
||
| 1154 | |||
| 1155 | } |
||
| 1156 | |||
| 1157 | return $index_name; |
||
| 1158 | |||
| 1159 | } |
||
| 1160 | |||
| 1161 | // Check if "index_name" is an UID. |
||
| 1162 | if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($index_name)) { |
||
| 1163 | |||
| 1164 | $index_name = self::getIndexName($index_name, $table, $pid); |
||
| 1165 | |||
| 1166 | } |
||
| 1167 | |||
| 1168 | /* $labels already contains the translated content element, but with the index_name of the translated content element itself |
||
| 1169 | * and not with the $index_name of the original that we receive here. So we have to determine the index_name of the |
||
| 1170 | * associated translated content element. E.g. $labels['title0'] != $index_name = title. */ |
||
| 1171 | |||
| 1172 | // First fetch the uid of the received index_name |
||
| 1173 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 1174 | 'uid, l18n_parent', |
||
| 1175 | $table, |
||
| 1176 | 'pid='.$pid.' AND index_name="'.$index_name.'"'.self::whereClause($table, TRUE), |
||
| 1177 | '', |
||
| 1178 | '', |
||
| 1179 | '' |
||
| 1180 | ); |
||
| 1181 | |||
| 1182 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
| 1183 | |||
| 1184 | // Now we use the uid of the l18_parent to fetch the index_name of the translated content element. |
||
| 1185 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
| 1186 | |||
| 1187 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 1188 | 'index_name', |
||
| 1189 | $table, |
||
| 1190 | 'pid='.$pid.' AND uid='.$resArray['l18n_parent'].' AND sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).self::whereClause($table, TRUE), |
||
| 1191 | '', |
||
| 1192 | '', |
||
| 1193 | '' |
||
| 1194 | ); |
||
| 1195 | |||
| 1196 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
| 1197 | |||
| 1198 | // If there is an translated content element, overwrite the received $index_name. |
||
| 1199 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
| 1200 | |||
| 1201 | $index_name = $resArray['index_name']; |
||
| 1202 | |||
| 1203 | } |
||
| 1204 | |||
| 1205 | } |
||
| 1206 | |||
| 1207 | // Check if we already got a translation. |
||
| 1208 | if (empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { |
||
| 1209 | |||
| 1210 | // Check if this table is allowed for translation. |
||
| 1211 | if (in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'))) { |
||
| 1212 | |||
| 1213 | $additionalWhere = ' AND sys_language_uid IN (-1,0)'; |
||
| 1214 | |||
| 1215 | if ($GLOBALS['TSFE']->sys_language_content > 0) { |
||
| 1216 | |||
| 1217 | $additionalWhere = ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).' AND l18n_parent=0))'; |
||
| 1218 | |||
| 1219 | } |
||
| 1220 | |||
| 1221 | // Get labels from database. |
||
| 1222 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 1223 | '*', |
||
| 1224 | $table, |
||
| 1225 | 'pid='.$pid.$additionalWhere.self::whereClause($table, TRUE), |
||
| 1226 | '', |
||
| 1227 | '', |
||
| 1228 | '' |
||
| 1229 | ); |
||
| 1230 | |||
| 1231 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { |
||
| 1232 | |||
| 1233 | while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) { |
||
| 1234 | |||
| 1235 | // Overlay localized labels if available. |
||
| 1236 | if ($GLOBALS['TSFE']->sys_language_content > 0) { |
||
| 1237 | |||
| 1238 | $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL); |
||
| 1239 | |||
| 1240 | } |
||
| 1241 | |||
| 1242 | if ($resArray) { |
||
| 1243 | |||
| 1244 | $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$resArray['index_name']] = $resArray['label']; |
||
| 1245 | |||
| 1246 | } |
||
| 1247 | |||
| 1248 | } |
||
| 1249 | |||
| 1250 | } else { |
||
| 1251 | |||
| 1252 | if (TYPO3_DLOG) { |
||
| 1253 | |||
| 1254 | \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); |
||
| 1255 | |||
| 1256 | } |
||
| 1257 | |||
| 1258 | } |
||
| 1259 | |||
| 1260 | } else { |
||
| 1261 | |||
| 1262 | if (TYPO3_DLOG) { |
||
| 1263 | |||
| 1264 | \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); |
||
| 1265 | |||
| 1266 | } |
||
| 1267 | |||
| 1268 | } |
||
| 1269 | |||
| 1270 | } |
||
| 1271 | |||
| 1272 | if (!empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) { |
||
| 1273 | |||
| 1274 | return $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name]; |
||
| 1275 | |||
| 1276 | } else { |
||
| 1277 | |||
| 1278 | return $index_name; |
||
| 1279 | |||
| 1280 | } |
||
| 1281 | |||
| 1282 | } |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * This returns the additional WHERE clause of a table based on its TCA configuration |
||
| 1286 | * |
||
| 1287 | * @access public |
||
| 1288 | * |
||
| 1289 | * @param string $table: Table name as defined in TCA |
||
| 1290 | * @param boolean $showHidden: Ignore the hidden flag? |
||
| 1291 | * |
||
| 1292 | * @return string Additional WHERE clause |
||
| 1293 | */ |
||
| 1294 | public static function whereClause($table, $showHidden = FALSE) { |
||
| 1295 | |||
| 1296 | if (TYPO3_MODE === 'FE') { |
||
| 1297 | |||
| 1298 | // Table "tx_dlf_formats" always has PID 0. |
||
| 1299 | if ($table == 'tx_dlf_formats') { |
||
| 1300 | |||
| 1301 | return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table); |
||
| 1302 | |||
| 1303 | } |
||
| 1304 | |||
| 1305 | // Should we ignore the record's hidden flag? |
||
| 1306 | $ignoreHide = -1; |
||
| 1307 | |||
| 1308 | if ($showHidden) { |
||
| 1309 | |||
| 1310 | $ignoreHide = 1; |
||
| 1311 | |||
| 1312 | } |
||
| 1313 | |||
| 1314 | // $GLOBALS['TSFE']->sys_page is not always available in frontend. |
||
| 1315 | if (is_object($GLOBALS['TSFE']->sys_page)) { |
||
| 1316 | |||
| 1317 | return $GLOBALS['TSFE']->sys_page->enableFields($table, $ignoreHide); |
||
| 1318 | |||
| 1319 | } else { |
||
| 1320 | |||
| 1321 | $pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); |
||
| 1322 | |||
| 1323 | $GLOBALS['TSFE']->includeTCA(); |
||
| 1324 | |||
| 1325 | return $pageRepository->enableFields($table, $ignoreHide); |
||
| 1326 | |||
| 1327 | } |
||
| 1328 | |||
| 1329 | } elseif (TYPO3_MODE === 'BE') { |
||
| 1330 | |||
| 1331 | return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table); |
||
| 1332 | |||
| 1333 | } else { |
||
| 1334 | |||
| 1335 | if (TYPO3_DLOG) { |
||
| 1336 | |||
| 1337 | \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_helper->whereClause('.$table.', ['.($showHidden ? 'TRUE' : 'FALSE').'])] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', self::$extKey, SYSLOG_SEVERITY_ERROR); |
||
| 1338 | |||
| 1339 | } |
||
| 1340 | |||
| 1341 | return ' AND 1=-1'; |
||
| 1342 | |||
| 1343 | } |
||
| 1344 | |||
| 1345 | } |
||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * This is a static class, thus no instances should be created |
||
| 1349 | * |
||
| 1350 | * @access private |
||
| 1351 | */ |
||
| 1352 | private function __construct() {} |
||
| 1353 | |||
| 1354 | } |
||
| 1355 |
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.