231
231
// Check for PHP extension "mcrypt".
232
232
if (!extension_loaded('mcrypt')) {
234
trigger_error('PHP extension "mcrypt" not available', E_USER_WARNING);
236
t3lib_div::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] PHP extension "mcrypt" not available', $this->extKey, SYSLOG_SEVERITY_WARNING);
240
244
if (empty($encrypted) || empty($hash)) {
248
t3lib_div::devLog('[tx_dlf_helper->decrypt('.$encrypted.', '.$hash.')] Invalid parameters given for decryption', $this->extKey, SYSLOG_SEVERITY_ERROR);
276
292
// Check for PHP extension "mcrypt".
277
293
if (!extension_loaded('mcrypt')) {
279
trigger_error('PHP extension "mcrypt" not available', E_USER_WARNING);
297
t3lib_div::devLog('[tx_dlf_helper->encrypt('.$string.')] PHP extension "mcrypt" not available', $this->extKey, SYSLOG_SEVERITY_WARNING);
306
326
if (TYPO3_MODE === 'FE') {
308
// TODO: Anpassen! (aus typo3/init.php übernommen)
309
$userObj = t3lib_div::makeInstance('t3lib_beUserAuth');
313
$userObj->backendCheckLogin();
328
// Check for existing backend login.
329
if ($GLOBALS['TSFE']->beUserLogin > 0 && isset($GLOBALS['BE_USER'])) {
331
return $GLOBALS['BE_USER'];
333
} elseif (!isset($_COOKIE['be_typo_user'])) {
335
// Initialize backend session with CLI user's rights.
336
$userObj = t3lib_div::makeInstance('t3lib_beUserAuth');
338
$userObj->dontSetCookie = TRUE;
342
$userObj->setBeUserByName('_cli_dlf');
344
$userObj->backendCheckLogin();
352
t3lib_div::devLog('[tx_dlf_helper->getBeUser()] Could not determine current user\'s login status', $this->extKey, SYSLOG_SEVERITY_ERROR);
317
360
} elseif (TYPO3_MODE === 'BE') {
362
// Return current backend user.
319
363
return $GLOBALS['BE_USER'];
323
trigger_error('Unexpected TYPO3_MODE', E_USER_WARNING);
369
t3lib_div::devLog('[tx_dlf_helper->getBeUser()] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
342
390
public static function getIndexName($uid, $table, $pid = -1) {
392
// Save parameters for logging purposes.
344
398
$uid = max(intval($uid), 0);
346
400
if (!$uid || !in_array($table, array ('tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'))) {
348
trigger_error('At least one argument is not valid: UID='.$uid.' or TABLE='.$table, E_USER_WARNING);
404
t3lib_div::devLog('[tx_dlf_helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] Invalid UID "'.$uid.'" or table "'.$table.'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
364
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
423
// Get index_name from database.
424
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
365
425
$table.'.index_name AS index_name',
367
427
$table.'.uid='.$uid.$where.self::whereClause($table),
373
if ($GLOBALS['TYPO3_DB']->sql_num_rows($_result) > 0) {
433
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
375
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result);
435
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
377
437
return $resArray['index_name'];
443
t3lib_div::devLog('[tx_dlf_helper->getIndexName('.$_uid.', '.$table.', '.$_pid.')] No "index_name" with UID "'.$uid.'" and PID "'.$pid.'" found in table "'.$table.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);
381
trigger_error('No "index_name" with UID '.$uid.' found for PID '.$pid.' in TABLE '.$table, E_USER_WARNING);
396
462
public static function getLanguageName($code) {
398
$_code = strtolower(trim($code));
400
if (preg_match('/^[a-z]{3}$/', $_code)) {
402
$_file = t3lib_extMgm::extPath(self::$extKey).'lib/ISO-639/iso-639-2b.xml';
404
} elseif (preg_match('/^[a-z]{2}$/', $_code)) {
406
$_file = t3lib_extMgm::extPath(self::$extKey).'lib/ISO-639/iso-639-1.xml';
464
// Analyze code and set appropriate ISO table.
465
$isoCode = strtolower(trim($code));
467
if (preg_match('/^[a-z]{3}$/', $isoCode)) {
469
$file = t3lib_extMgm::extPath(self::$extKey).'lib/ISO-639/iso-639-2b.xml';
471
} elseif (preg_match('/^[a-z]{2}$/', $isoCode)) {
473
$file = t3lib_extMgm::extPath(self::$extKey).'lib/ISO-639/iso-639-1.xml';
477
// No ISO code, return unchanged.
482
// Load ISO table and get localized full name of language.
414
483
if (TYPO3_MODE === 'FE') {
416
$iso639 = $GLOBALS['TSFE']->readLLfile($_file);
418
if (!empty($iso639['default'][$_code])) {
420
$lang = $GLOBALS['TSFE']->getLLL($_code, $iso639);
485
$iso639 = $GLOBALS['TSFE']->readLLfile($file);
487
if (!empty($iso639['default'][$isoCode])) {
489
$lang = $GLOBALS['TSFE']->getLLL($isoCode, $iso639);
424
493
} elseif (TYPO3_MODE === 'BE') {
426
$iso639 = $GLOBALS['LANG']->includeLLFile($_file, FALSE, TRUE);
428
if (!empty($iso639['default'][$_code])) {
430
$lang = $GLOBALS['LANG']->getLLL($_code, $iso639, FALSE);
495
$iso639 = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE);
497
if (!empty($iso639['default'][$isoCode])) {
499
$lang = $GLOBALS['LANG']->getLLL($isoCode, $iso639, FALSE);
436
trigger_error('Unexpected TYPO3_MODE', E_USER_WARNING);
507
t3lib_div::devLog('[tx_dlf_helper->getLanguageName('.$code.')] Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', $this->extKey, SYSLOG_SEVERITY_ERROR);
512
589
if (preg_match('/[^a-z0-9:-]/', $urn)) {
514
trigger_error('Invalid chars in URN', E_USER_WARNING);
593
t3lib_div::devLog('[tx_dlf_helper->getURN('.$base.', '.$id.')] Invalid chars in given parameters', $this->extKey, SYSLOG_SEVERITY_WARNING);
562
* @param string $key: Session key for retrieval
643
* @param string $key: Session data key for retrieval
564
645
* @return mixed Session value for given key or NULL on failure
566
647
public static function loadFromSession($key) {
649
// Save parameter for logging purposes.
568
652
// Cast to string for security reasons.
569
653
$key = (string) $key;
573
trigger_error('No session key given', E_USER_WARNING);
659
t3lib_div::devLog('[tx_dlf_helper->loadFromSession('.$_key.')] Invalid key "'.$key.'" for session data retrieval', $this->extKey, SYSLOG_SEVERITY_WARNING);
667
// Get the session data.
579
668
if (TYPO3_MODE === 'FE') {
581
670
return $GLOBALS['TSFE']->fe_user->getKey('ses', $key);
649
742
* @param string $value: Value to save
650
* @param string $key: Session key for retrieval
743
* @param string $key: Session data key for saving
652
745
* @return boolean TRUE on success, FALSE on failure
654
747
public static function saveToSession($value, $key) {
749
// Save parameter for logging purposes.
656
752
// Cast to string for security reasons.
657
753
$key = (string) $key;
661
trigger_error('No session key given', E_USER_WARNING);
759
t3lib_div::devLog('[tx_dlf_helper->saveToSession('.$value.', '.$_key.')] Invalid key "'.$key.'" for session data saving', $this->extKey, SYSLOG_SEVERITY_WARNING);
767
// Save value in session data.
667
768
if (TYPO3_MODE === 'FE') {
669
770
$GLOBALS['TSFE']->fe_user->setKey('ses', $key, $value);
692
* This validates a METS file against its schemas
693
* TODO: nicht funktionstüchtig!
697
* @param SimpleXMLElement $xml:
701
public static function schemaValidate(SimpleXMLElement $xml) {
703
$_libxmlErrors = libxml_use_internal_errors(TRUE);
705
// Get schema locations.
706
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
708
$_schemaLocations = $xml->xpath('//*[@xsi:schemaLocation]');
710
foreach ($_schemaLocations as $_schemaLocation) {
712
$_schemas = explode(' ', (string) $_schemaLocation->attributes('http://www.w3.org/2001/XMLSchema-instance')->schemaLocation);
714
for ($i = 1, $j = count($_schemas); $i <= $j; $i++) {
716
if ($_schemas[$i] == 'http://www.loc.gov/METS/') {
718
$schema['mets'] = $_schemas[$i + 1];
720
} elseif ($_schemas[$i] == 'http://www.loc.gov/mods/v3') {
722
$schema['mods'] = $_schemas[$i + 1];
729
// TODO: Error-Handling (keine Schemas gefunden)
731
// Validate METS part against schema.
732
$dom = new DOMDocument('1.0', 'UTF-8');
734
$dom->appendChild($dom->importNode(dom_import_simplexml($this->mets), TRUE));
736
$dom->schemaValidate($schema['mets']);
738
// TODO: Error-Handling (invalider METS-Part)
739
// libxml_get_last_error() || libxml_get_errors() || libxml_clear_errors()
741
// Validate dmdSec parts against schema.
742
foreach ($this->dmdSec as $dmdSec) {
744
switch ($dmdSec['type']) {
748
$dom = new DOMDocument('1.0', 'UTF-8');
750
$dom->appendChild($dom->importNode(dom_import_simplexml($dmdSec['xml']), TRUE));
752
$dom->schemaValidate($schema['mods']);
754
// TODO: Error-Handling (invalider MODS-Part)
755
// libxml_get_last_error() || libxml_get_errors() || libxml_clear_errors()
763
libxml_use_internal_errors($_libxmlErrors);
768
797
* This translates an internal "index_name"
778
807
public static function translate($index_name, $table, $pid) {
809
// Save parameters for logging purposes.
810
$_index_name = $index_name;
814
// Load labels into static variable for future use.
780
815
static $labels = array ();
782
818
$pid = max(intval($pid), 0);
786
trigger_error('No PID given for translations', E_USER_WARNING);
824
t3lib_div::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] Invalid PID "'.$pid.'" for translation', $this->extKey, SYSLOG_SEVERITY_WARNING);
788
828
return $index_name;
813
853
// Get labels from database.
814
$_result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
854
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
817
857
'pid='.$pid.$additionalWhere.self::whereClause($table),
823
if ($GLOBALS['TYPO3_DB']->sql_num_rows($_result) > 0) {
863
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
825
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($_result)) {
865
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
827
867
// Overlay localized labels if available.
828
868
if ($GLOBALS['TSFE']->sys_language_content > 0) {
844
trigger_error('There are no entries with PID '.$pid.' in table '.$table.' or you are not allowed to access them', E_USER_ERROR);
886
t3lib_div::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] No translation with PID "'.$pid.'" available in table "'.$table.'" or translation not accessible', $this->extKey, SYSLOG_SEVERITY_NOTICE);
850
trigger_error('The table '.$table.' is not allowed for translation', E_USER_ERROR);
896
t3lib_div::devLog('[tx_dlf_helper->translate('.$_index_name.', '.$table.', '.$_pid.')] No translations available for table "'.$table.'"', $this->extKey, SYSLOG_SEVERITY_WARNING);