Completed
Push — master ( 366a5b...a17b2a )
by
unknown
17:34 queued 14:29
created

Helper::processDBasAdmin()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 9
nop 4
dl 0
loc 28
rs 8.4444
c 0
b 0
f 0
1
<?php
2
namespace Kitodo\Dlf\Common;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
/**
15
 * Helper class for the 'dlf' extension
16
 *
17
 * @author Sebastian Meyer <[email protected]>
18
 * @author Henrik Lochmann <[email protected]>
19
 * @package TYPO3
20
 * @subpackage dlf
21
 * @access public
22
 */
23
class Helper {
24
    /**
25
     * The extension key
26
     *
27
     * @var string
28
     * @access public
29
     */
30
    public static $extKey = 'dlf';
31
32
    /**
33
     * The locallang array for flash messages
34
     *
35
     * @var array
36
     * @access protected
37
     */
38
    protected static $messages = [];
39
40
    /**
41
     * Generates a flash message and adds it to a message queue.
42
     *
43
     * @access public
44
     *
45
     * @param string $message: The body of the message
0 ignored issues
show
Documentation introduced by
There is no parameter named $message:. Did you maybe mean $message?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
46
     * @param string $title: The title of the message
0 ignored issues
show
Documentation introduced by
There is no parameter named $title:. Did you maybe mean $title?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
47
     * @param integer $severity: The message's severity
0 ignored issues
show
Documentation introduced by
There is no parameter named $severity:. Did you maybe mean $severity?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
48
     * @param boolean $session: Should the message be saved in the user's session?
0 ignored issues
show
Documentation introduced by
There is no parameter named $session:. Did you maybe mean $session?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
49
     * @param string $queue: The queue's unique identifier
0 ignored issues
show
Documentation introduced by
There is no parameter named $queue:. Did you maybe mean $queue?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
50
     *
51
     * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue The queue the message was added to
52
     */
53
    public static function addMessage($message, $title, $severity, $session = FALSE, $queue = 'kitodo.default.flashMessages') {
54
        $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
55
        $flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier($queue);
56
        $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
57
            \TYPO3\CMS\Core\Messaging\FlashMessage::class,
58
            $message,
59
            $title,
60
            $severity,
61
            $session
62
        );
63
        $flashMessageQueue->enqueue($flashMessage);
64
        return $flashMessageQueue;
65
    }
66
67
    /**
68
     * Check if given identifier is a valid identifier of the German National Library
69
     *
70
     * @access public
71
     *
72
     * @param string $id: The identifier to check
0 ignored issues
show
Bug introduced by
There is no parameter named $id:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
73
     * @param string $type: What type is the identifier supposed to be?
0 ignored issues
show
Bug introduced by
There is no parameter named $type:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
     *                      Possible values: PPN, IDN, PND, ZDB, SWD, GKD
75
     *
76
     * @return boolean Is $id a valid GNL identifier of the given $type?
77
     */
78
    public static function checkIdentifier($id, $type) {
79
        $digits = substr($id, 0, 8);
80
        $checksum = 0;
81 View Code Duplication
        for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
            $checksum += (9 - $i) * intval(substr($digits, $i, 1));
83
        }
84
        $checksum = (11 - ($checksum % 11)) % 11;
85
        switch (strtoupper($type)) {
86
            case 'PPN':
87
            case 'IDN':
88 View Code Duplication
            case 'PND':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
                if ($checksum == 10) {
90
                    $checksum = 'X';
91
                }
92
                if (!preg_match('/[0-9]{8}[0-9X]{1}/i', $id)) {
93
                    return FALSE;
94
                } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
95
                    return FALSE;
96
                }
97
                break;
98 View Code Duplication
            case 'ZDB':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
                if ($checksum == 10) {
100
                    $checksum = 'X';
101
                }
102
                if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
103
                    return FALSE;
104
                } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
105
                    return FALSE;
106
                }
107
                break;
108
            case 'SWD':
109
                $checksum = 11 - $checksum;
110
                if (!preg_match('/[0-9]{8}-[0-9]{1}/i', $id)) {
111
                    return FALSE;
112
                } elseif ($checksum == 10) {
113
                    return self::checkIdentifier(($digits + 1).substr($id, -2, 2), 'SWD');
114
                } elseif (substr($id, -1, 1) != $checksum) {
115
                    return FALSE;
116
                }
117
                break;
118 View Code Duplication
            case 'GKD':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
                $checksum = 11 - $checksum;
120
                if ($checksum == 10) {
121
                    $checksum = 'X';
122
                }
123
                if (!preg_match('/[0-9]{8}-[0-9X]{1}/i', $id)) {
124
                    return FALSE;
125
                } elseif (strtoupper(substr($id, -1, 1)) != $checksum) {
126
                    return FALSE;
127
                }
128
                break;
129
        }
130
        return TRUE;
131
    }
132
133
    /**
134
     * Decrypt encrypted value with given control hash
135
     *
136
     * @access public
137
     *
138
     * @param string $encrypted: The encrypted value to decrypt
0 ignored issues
show
Documentation introduced by
There is no parameter named $encrypted:. Did you maybe mean $encrypted?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
139
     * @param string $hash: The control hash for decrypting
0 ignored issues
show
Bug introduced by
There is no parameter named $hash:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
140
     *
141
     * @return mixed The decrypted value or NULL on error
142
     */
143
    public static function decrypt($encrypted, $hash) {
144
        $decrypted = NULL;
0 ignored issues
show
Unused Code introduced by
$decrypted is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
145
        if (empty($encrypted)
146
            || empty($hash)) {
147
            self::devLog('Invalid parameters given for decryption', DEVLOG_SEVERITY_ERROR);
148
            return;
149
        }
150
        if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
151
            self::devLog('No encryption key set in TYPO3 configuration', DEVLOG_SEVERITY_ERROR);
152
            return;
153
        }
154
        $iv = substr(md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, openssl_cipher_iv_length('BF-CFB'));
155
        $decrypted = openssl_decrypt($encrypted, 'BF-CFB', substr($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 0, 56), 0, $iv);
156
        $salt = substr($hash, 0, 10);
157
        $hashed = $salt.substr(sha1($salt.$decrypted), -10);
158
        if ($hashed !== $hash) {
159
            self::devLog('Invalid hash "'.$hash.'" given for decryption', DEVLOG_SEVERITY_WARNING);
160
            return;
161
        }
162
        return $decrypted;
163
    }
164
165
    /**
166
     * Add a message to the TYPO3 developer log
167
     *
168
     * @access public
169
     *
170
     * @param string $message: The message to log
0 ignored issues
show
Documentation introduced by
There is no parameter named $message:. Did you maybe mean $message?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
171
     * @param integer $severity: The severity of the message
0 ignored issues
show
Documentation introduced by
There is no parameter named $severity:. Did you maybe mean $severity?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
172
     *                           0 is info, 1 is notice, 2 is warning, 3 is fatal error, -1 is "OK" message
173
     *
174
     * @return void
175
     */
176
    public static function devLog($message, $severity = 0) {
177
        if (TYPO3_DLOG) {
178
            $stacktrace = debug_backtrace(0, 2);
179
            // Set some defaults.
180
            $caller = 'Kitodo\Dlf\Default\UnknownClass::unknownMethod';
181
            $args = [];
182
            $data = [];
183
            if (!empty($stacktrace[1])) {
184
                $caller = $stacktrace[1]['class'].$stacktrace[1]['type'].$stacktrace[1]['function'];
185
                foreach ($stacktrace[1]['args'] as $arg) {
186
                    if (is_bool($arg)) {
187
                        $args[] = ($arg ? 'TRUE' : 'FALSE');
188
                    } elseif (is_scalar($arg)) {
189
                        $args[] = (string) $arg;
190
                    } elseif (is_null($arg)) {
191
                        $args[] = 'NULL';
192
                    } elseif (is_array($arg)) {
193
                        $args[] = '[data]';
194
                        $data[] = $arg;
195
                    } elseif (is_object($arg)) {
196
                        $args[] = '['.get_class($arg).']';
197
                        $data[] = $arg;
198
                    }
199
                }
200
            }
201
            $arguments = '('.implode(', ', $args).')';
202
            $additionalData = (empty($data) ? FALSE : $data);
203
            \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('['.$caller.$arguments.'] '.$message, self::$extKey, $severity, $additionalData);
204
        }
205
    }
206
207
    /**
208
     * Encrypt the given string
209
     *
210
     * @access public
211
     *
212
     * @param string $string: The string to encrypt
0 ignored issues
show
Documentation introduced by
There is no parameter named $string:. Did you maybe mean $string?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
213
     *
214
     * @return array Array with encrypted string and control hash
215
     */
216
    public static function encrypt($string) {
217
        if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
218
            self::devLog('No encryption key set in TYPO3 configuration', DEVLOG_SEVERITY_ERROR);
219
            return;
220
        }
221
        $iv = substr(md5($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']), 0, openssl_cipher_iv_length('BF-CFB'));
222
        $encrypted = openssl_encrypt($string, 'BF-CFB', substr($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 0, 56), 0, $iv);
223
        $salt = substr(md5(uniqid(rand(), TRUE)), 0, 10);
224
        $hash = $salt.substr(sha1($salt.$string), -10);
225
        return ['encrypted' => $encrypted, 'hash' => $hash];
226
    }
227
228
    /**
229
     * Get the unqualified name of a class
230
     *
231
     * @access public
232
     *
233
     * @param string $qualifiedClassname: The qualified class name from get_class()
0 ignored issues
show
Documentation introduced by
There is no parameter named $qualifiedClassname:. Did you maybe mean $qualifiedClassname?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
234
     *
235
     * @return string The unqualified class name
236
     */
237
    public static function getUnqualifiedClassName($qualifiedClassname) {
238
        $nameParts = explode('\\', $qualifiedClassname);
239
        return end($nameParts);
240
    }
241
242
    /**
243
     * Clean up a string to use in an URL.
244
     *
245
     * @access public
246
     *
247
     * @param string $string: The string to clean up
0 ignored issues
show
Documentation introduced by
There is no parameter named $string:. Did you maybe mean $string?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
248
     *
249
     * @return string The cleaned up string
250
     */
251
    public static function getCleanString($string) {
252
        // Convert to lowercase.
253
        $string = strtolower($string);
254
        // Remove non-alphanumeric characters.
255
        $string = preg_replace('/[^a-z0-9_\s-]/', '', $string);
256
        // Remove multiple dashes or whitespaces.
257
        $string = preg_replace('/[\s-]+/', ' ', $string);
258
        // Convert whitespaces and underscore to dash.
259
        $string = preg_replace('/[\s_]/', '-', $string);
260
        return $string;
261
    }
262
263
    /**
264
     * Get the registered hook objects for a class
265
     *
266
     * @access public
267
     *
268
     * @param string $scriptRelPath: The path to the class file
0 ignored issues
show
Documentation introduced by
There is no parameter named $scriptRelPath:. Did you maybe mean $scriptRelPath?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
269
     *
270
     * @return array Array of hook objects for the class
271
     */
272
    public static function getHookObjects($scriptRelPath) {
273
        $hookObjects = [];
274
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'])) {
275
            foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][self::$extKey.'/'.$scriptRelPath]['hookClass'] as $classRef) {
276
                $hookObjects[] = &\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($classRef);
277
            }
278
        }
279
        return $hookObjects;
280
    }
281
282
    /**
283
     * Get the "index_name" for an UID
284
     *
285
     * @access public
286
     *
287
     * @param integer $uid: The UID of the record
0 ignored issues
show
Bug introduced by
There is no parameter named $uid:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
288
     * @param string $table: Get the "index_name" from this table
0 ignored issues
show
Documentation introduced by
There is no parameter named $table:. Did you maybe mean $table?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
289
     * @param integer $pid: Get the "index_name" from this page
0 ignored issues
show
Bug introduced by
There is no parameter named $pid:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
290
     *
291
     * @return string "index_name" for the given UID
292
     */
293
    public static function getIndexNameFromUid($uid, $table, $pid = -1) {
294
        // Sanitize input.
295
        $uid = max(intval($uid), 0);
296 View Code Duplication
        if (!$uid
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
297
            || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'])) {
298
            self::devLog('Invalid UID "'.$uid.'" or table "'.$table.'"', DEVLOG_SEVERITY_ERROR);
299
            return '';
300
        }
301
        $where = '';
302
        // Should we check for a specific PID, too?
303 View Code Duplication
        if ($pid !== -1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
304
            $pid = max(intval($pid), 0);
305
            $where = ' AND '.$table.'.pid='.$pid;
306
        }
307
        // Get index_name from database.
308
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
309
            $table.'.index_name AS index_name',
310
            $table,
311
            $table.'.uid='.$uid
312
                .$where
313
                .self::whereClause($table),
314
            '',
315
            '',
316
            '1'
317
        );
318 View Code Duplication
        if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
319
            $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
320
            return $resArray['index_name'];
321
        } else {
322
            self::devLog('No "index_name" with UID '.$uid.' and PID '.$pid.' found in table "'.$table.'"', DEVLOG_SEVERITY_WARNING);
323
            return '';
324
        }
325
    }
326
327
    /**
328
     * Get language name from ISO code
329
     *
330
     * @access public
331
     *
332
     * @param string $code: ISO 639-1 or ISO 639-2/B language code
0 ignored issues
show
Bug introduced by
There is no parameter named $code:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
333
     *
334
     * @return string Localized full name of language or unchanged input
335
     */
336
    public static function getLanguageName($code) {
337
        // Analyze code and set appropriate ISO table.
338
        $isoCode = strtolower(trim($code));
339
        if (preg_match('/^[a-z]{3}$/', $isoCode)) {
340
            $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'Resources/Private/Data/iso-639-2b.xml';
341
        } elseif (preg_match('/^[a-z]{2}$/', $isoCode)) {
342
            $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey).'Resources/Private/Data/iso-639-1.xml';
343
        } else {
344
            // No ISO code, return unchanged.
345
            return $code;
346
        }
347
        // Load ISO table and get localized full name of language.
348
        if (TYPO3_MODE === 'FE') {
349
            $iso639 = $GLOBALS['TSFE']->readLLfile($file);
350 View Code Duplication
            if (!empty($iso639['default'][$isoCode])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
351
                $lang = $GLOBALS['TSFE']->getLLL($isoCode, $iso639);
352
            }
353
        } elseif (TYPO3_MODE === 'BE') {
354
            $iso639 = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE);
355 View Code Duplication
            if (!empty($iso639['default'][$isoCode])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
356
                $lang = $GLOBALS['LANG']->getLLL($isoCode, $iso639, FALSE);
357
            }
358
        } else {
359
            self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
360
            return $code;
361
        }
362
        if (!empty($lang)) {
363
            return $lang;
364
        } else {
365
            self::devLog('Language code "'.$code.'" not found in ISO-639 table', DEVLOG_SEVERITY_NOTICE);
366
            return $code;
367
        }
368
    }
369
370
    /**
371
     * Wrapper function for getting localized messages in frontend and backend
372
     *
373
     * @access public
374
     *
375
     * @param string $key: The locallang key to translate
0 ignored issues
show
Bug introduced by
There is no parameter named $key:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
376
     * @param boolean $hsc: Should the result be htmlspecialchar()'ed?
0 ignored issues
show
Bug introduced by
There is no parameter named $hsc:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
377
     * @param string $default: Default return value if no translation is available
0 ignored issues
show
Documentation introduced by
There is no parameter named $default:. Did you maybe mean $default?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
378
     *
379
     * @return string The translated string or the given key on failure
380
     */
381
    public static function getMessage($key, $hsc = FALSE, $default = '') {
382
        // Set initial output to default value.
383
        $translated = (string) $default;
384
        // Load common messages file.
385
        if (empty(self::$messages)) {
386
            $file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(self::$extKey, 'Resources/Private/Language/FlashMessages.xml');
387 View Code Duplication
            if (TYPO3_MODE === 'FE') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
388
                self::$messages = $GLOBALS['TSFE']->readLLfile($file);
389
            } elseif (TYPO3_MODE === 'BE') {
390
                self::$messages = $GLOBALS['LANG']->includeLLFile($file, FALSE, TRUE);
391
            } else {
392
                self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
393
            }
394
        }
395
        // Get translation.
396
        if (!empty(self::$messages['default'][$key])) {
397 View Code Duplication
            if (TYPO3_MODE === 'FE') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
                $translated = $GLOBALS['TSFE']->getLLL($key, self::$messages);
399
            } elseif (TYPO3_MODE === 'BE') {
400
                $translated = $GLOBALS['LANG']->getLLL($key, self::$messages, FALSE);
401
            } else {
402
                self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
403
            }
404
        }
405
        // Escape HTML characters if applicable.
406
        if ($hsc) {
407
            $translated = htmlspecialchars($translated);
408
        }
409
        return $translated;
410
    }
411
412
    /**
413
     * Get the UID for a given "index_name"
414
     *
415
     * @access public
416
     *
417
     * @param integer $index_name: The index_name of the record
0 ignored issues
show
Documentation introduced by
There is no parameter named $index_name:. Did you maybe mean $index_name?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
418
     * @param string $table: Get the "index_name" from this table
0 ignored issues
show
Documentation introduced by
There is no parameter named $table:. Did you maybe mean $table?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
419
     * @param integer $pid: Get the "index_name" from this page
0 ignored issues
show
Bug introduced by
There is no parameter named $pid:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
420
     *
421
     * @return string "uid" for the given index_name
422
     */
423
    public static function getUidFromIndexName($index_name, $table, $pid = -1) {
424 View Code Duplication
        if (!$index_name
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
425
            || !in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures', 'tx_dlf_solrcores'])) {
426
            self::devLog('Invalid UID '.$index_name.' or table "'.$table.'"', DEVLOG_SEVERITY_ERROR);
427
            return '';
428
        }
429
        $where = '';
430
        // Should we check for a specific PID, too?
431 View Code Duplication
        if ($pid !== -1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
            $pid = max(intval($pid), 0);
433
            $where = ' AND '.$table.'.pid='.$pid;
434
        }
435
        // Get index_name from database.
436
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
437
            $table.'.uid AS uid',
438
            $table,
439
            $table.'.index_name="'.$index_name.'"'
440
                .$where
441
                .self::whereClause($table),
442
            '',
443
            '',
444
            '1'
445
        );
446 View Code Duplication
        if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
447
            $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
448
            return $resArray['uid'];
449
        } else {
450
            self::devLog('No UID for given index_name "'.$index_name.'" and PID '.$pid.' found in table "'.$table.'"', DEVLOG_SEVERITY_WARNING);
451
            return '';
452
        }
453
    }
454
455
    /**
456
     * Get the URN of an object
457
     * @see http://www.persistent-identifier.de/?link=316
458
     *
459
     * @access public
460
     *
461
     * @param string $base: The namespace and base URN
0 ignored issues
show
Bug introduced by
There is no parameter named $base:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
462
     * @param string $id: The object's identifier
0 ignored issues
show
Bug introduced by
There is no parameter named $id:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
463
     *
464
     * @return string Uniform Resource Name as string
465
     */
466
    public static function getURN($base, $id) {
467
        $concordance = [
468
            '0' => 1,
469
            '1' => 2,
470
            '2' => 3,
471
            '3' => 4,
472
            '4' => 5,
473
            '5' => 6,
474
            '6' => 7,
475
            '7' => 8,
476
            '8' => 9,
477
            '9' => 41,
478
            'a' => 18,
479
            'b' => 14,
480
            'c' => 19,
481
            'd' => 15,
482
            'e' => 16,
483
            'f' => 21,
484
            'g' => 22,
485
            'h' => 23,
486
            'i' => 24,
487
            'j' => 25,
488
            'k' => 42,
489
            'l' => 26,
490
            'm' => 27,
491
            'n' => 13,
492
            'o' => 28,
493
            'p' => 29,
494
            'q' => 31,
495
            'r' => 12,
496
            's' => 32,
497
            't' => 33,
498
            'u' => 11,
499
            'v' => 34,
500
            'w' => 35,
501
            'x' => 36,
502
            'y' => 37,
503
            'z' => 38,
504
            '-' => 39,
505
            ':' => 17,
506
        ];
507
        $urn = strtolower($base.$id);
508
        if (preg_match('/[^a-z0-9:-]/', $urn)) {
509
            self::devLog('Invalid chars in given parameters', DEVLOG_SEVERITY_WARNING);
510
            return '';
511
        }
512
        $digits = '';
513 View Code Duplication
        for ($i = 0, $j = strlen($urn); $i < $j; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
514
            $digits .= $concordance[substr($urn, $i, 1)];
515
        }
516
        $checksum = 0;
517 View Code Duplication
        for ($i = 0, $j = strlen($digits); $i < $j; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
518
            $checksum += ($i + 1) * intval(substr($digits, $i, 1));
519
        }
520
        $checksum = substr(intval($checksum / intval(substr($digits, -1, 1))), -1, 1);
521
        return $base.$id.$checksum;
522
    }
523
524
    /**
525
     * Check if given ID is a valid Pica Production Number (PPN)
526
     *
527
     * @access public
528
     *
529
     * @param string $id: The identifier to check
0 ignored issues
show
Bug introduced by
There is no parameter named $id:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
530
     *
531
     * @return boolean Is $id a valid PPN?
532
     */
533
    public static function isPPN($id) {
534
        return self::checkIdentifier($id, 'PPN');
535
    }
536
537
    /**
538
     * Load value from user's session.
539
     *
540
     * @access public
541
     *
542
     * @param string $key: Session data key for retrieval
0 ignored issues
show
Bug introduced by
There is no parameter named $key:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
543
     *
544
     * @return mixed Session value for given key or NULL on failure
545
     */
546
    public static function loadFromSession($key) {
547
        // Cast to string for security reasons.
548
        $key = (string) $key;
549
        if (!$key) {
550
            self::devLog('Invalid key "'.$key.'" for session data retrieval', DEVLOG_SEVERITY_WARNING);
551
            return;
552
        }
553
        // Get the session data.
554
        if (TYPO3_MODE === 'FE') {
555
            return $GLOBALS['TSFE']->fe_user->getKey('ses', $key);
556
        } elseif (TYPO3_MODE === 'BE') {
557
            return $GLOBALS['BE_USER']->getSessionData($key);
558
        } else {
559
            self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
560
            return;
561
        }
562
    }
563
564
    /**
565
     * Merges two arrays recursively and actually returns the modified array.
566
     * @see \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule()
567
     *
568
     * @access public
569
     *
570
     * @param array $original: Original array
0 ignored issues
show
Documentation introduced by
There is no parameter named $original:. Did you maybe mean $original?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
571
     * @param array $overrule: Overrule array, overruling the original array
0 ignored issues
show
Documentation introduced by
There is no parameter named $overrule:. Did you maybe mean $overrule?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
572
     * @param boolean $addKeys: If set to FALSE, keys that are not found in $original will not be set
0 ignored issues
show
Documentation introduced by
There is no parameter named $addKeys:. Did you maybe mean $addKeys?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
573
     * @param boolean $includeEmptyValues: If set, values from $overrule will overrule if they are empty
0 ignored issues
show
Documentation introduced by
There is no parameter named $includeEmptyValues:. Did you maybe mean $includeEmptyValues?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
574
     * @param boolean $enableUnsetFeature: If set, special value "__UNSET" can be used in the overrule array to unset keys in the original array
0 ignored issues
show
Documentation introduced by
There is no parameter named $enableUnsetFeature:. Did you maybe mean $enableUnsetFeature?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
575
     *
576
     * @return array Merged array
577
     */
578
    public static function mergeRecursiveWithOverrule(array $original, array $overrule, $addKeys = TRUE, $includeEmptyValues = TRUE, $enableUnsetFeature = TRUE) {
579
        \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($original, $overrule, $addKeys, $includeEmptyValues, $enableUnsetFeature);
580
        return $original;
581
    }
582
583
     /**
584
     * Process a data and/or command map with TYPO3 core engine as admin.
585
     *
586
     * @access public
587
     *
588
     * @param array $data: Data map
0 ignored issues
show
Bug introduced by
There is no parameter named $data:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
589
     * @param array $cmd: Command map
0 ignored issues
show
Bug introduced by
There is no parameter named $cmd:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
590
     * @param boolean $reverseOrder: Should the data map be reversed?
0 ignored issues
show
Documentation introduced by
There is no parameter named $reverseOrder:. Did you maybe mean $reverseOrder?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
591
     * @param boolean $cmdFirst: Should the command map be processed first?
0 ignored issues
show
Documentation introduced by
There is no parameter named $cmdFirst:. Did you maybe mean $cmdFirst?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
592
     *
593
     * @return array Array of substituted "NEW..." identifiers and their actual UIDs.
594
     */
595
    public static function processDBasAdmin(array $data = [], array $cmd = [], $reverseOrder = FALSE, $cmdFirst = FALSE) {
596
        if (TYPO3_MODE === 'BE'
597
            && $GLOBALS['BE_USER']->isAdmin()) {
598
            // Instantiate TYPO3 core engine.
599
            $dataHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
600
            // Load data and command arrays.
601
            $dataHandler->start($data, $cmd);
602
            // Process command map first if default order is reversed.
603
            if (!empty($cmd)
604
                && $cmdFirst) {
605
                $dataHandler->process_cmdmap();
606
            }
607
            // Process data map.
608
            if (!empty($data)) {
609
                $dataHandler->reverseOrder = $reverseOrder;
610
                $dataHandler->process_datamap();
611
            }
612
            // Process command map if processing order is not reversed.
613
            if (!empty($cmd)
614
                && !$cmdFirst) {
615
                $dataHandler->process_cmdmap();
616
            }
617
            return $dataHandler->substNEWwithIDs;
618
        } else {
619
            self::devLog('Current backend user has no admin privileges', DEVLOG_SEVERITY_ERROR);
620
            return [];
621
        }
622
    }
623
624
    /**
625
     * Fetches and renders all available flash messages from the queue.
626
     *
627
     * @access public
628
     *
629
     * @param string $queue: The queue's unique identifier
0 ignored issues
show
Documentation introduced by
There is no parameter named $queue:. Did you maybe mean $queue?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
630
     *
631
     * @return string All flash messages in the queue rendered as HTML.
632
     */
633
    public static function renderFlashMessages($queue = 'kitodo.default.flashMessages') {
634
        $flashMessageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
635
        $flashMessageQueue = $flashMessageService->getMessageQueueByIdentifier($queue);
636
        // \TYPO3\CMS\Core\Messaging\FlashMessage::getMessageAsMarkup() uses htmlspecialchars()
637
        // on all messages, but we have messages with HTML tags. Therefore we copy the official
638
        // implementation and remove the htmlspecialchars() call on the message body.
639
        $content = '';
640
        $flashMessages = $flashMessageQueue->getAllMessagesAndFlush();
641
        if (!empty($flashMessages)) {
642
            $content .= '<div class="typo3-messages">';
643
            foreach ($flashMessages as $flashMessage) {
644
                $messageTitle = $flashMessage->getTitle();
645
                $markup = [];
646
                $markup[] = '<div class="alert '.htmlspecialchars($flashMessage->getClass()).'">';
647
                $markup[] = '    <div class="media">';
648
                $markup[] = '        <div class="media-left">';
649
                $markup[] = '            <span class="fa-stack fa-lg">';
650
                $markup[] = '                <i class="fa fa-circle fa-stack-2x"></i>';
651
                $markup[] = '                <i class="fa fa-'.htmlspecialchars($flashMessage->getIconName()).' fa-stack-1x"></i>';
652
                $markup[] = '            </span>';
653
                $markup[] = '        </div>';
654
                $markup[] = '        <div class="media-body">';
655
                if (!empty($messageTitle)) {
656
                    $markup[] = '            <h4 class="alert-title">'.htmlspecialchars($messageTitle).'</h4>';
657
                }
658
                $markup[] = '            <p class="alert-message">'.$flashMessage->getMessage().'</p>'; // Removed htmlspecialchars() here.
659
                $markup[] = '        </div>';
660
                $markup[] = '    </div>';
661
                $markup[] = '</div>';
662
                $content .= implode('', $markup);
663
            }
664
            $content .= '</div>';
665
        }
666
        return $content;
667
    }
668
669
    /**
670
     * Save given value to user's session.
671
     *
672
     * @access public
673
     *
674
     * @param mixed $value: Value to save
0 ignored issues
show
Documentation introduced by
There is no parameter named $value:. Did you maybe mean $value?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
675
     * @param string $key: Session data key for saving
0 ignored issues
show
Bug introduced by
There is no parameter named $key:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
676
     *
677
     * @return boolean TRUE on success, FALSE on failure
678
     */
679
    public static function saveToSession($value, $key) {
680
        // Cast to string for security reasons.
681
        $key = (string) $key;
682
        if (!$key) {
683
            self::devLog('Invalid key "'.$key.'" for session data saving', DEVLOG_SEVERITY_WARNING);
684
            return FALSE;
685
        }
686
        // Save value in session data.
687
        if (TYPO3_MODE === 'FE') {
688
            $GLOBALS['TSFE']->fe_user->setKey('ses', $key, $value);
689
            $GLOBALS['TSFE']->fe_user->storeSessionData();
690
            return TRUE;
691
        } elseif (TYPO3_MODE === 'BE') {
692
            $GLOBALS['BE_USER']->setAndSaveSessionData($key, $value);
693
            return TRUE;
694
        } else {
695
            self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
696
            return FALSE;
697
        }
698
    }
699
700
    /**
701
     * This translates an internal "index_name"
702
     *
703
     * @access public
704
     *
705
     * @param string $index_name: The internal "index_name" to translate
0 ignored issues
show
Documentation introduced by
There is no parameter named $index_name:. Did you maybe mean $index_name?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
706
     * @param string $table: Get the translation from this table
0 ignored issues
show
Documentation introduced by
There is no parameter named $table:. Did you maybe mean $table?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
707
     * @param string $pid: Get the translation from this page
0 ignored issues
show
Bug introduced by
There is no parameter named $pid:. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
708
     *
709
     * @return string Localized label for $index_name
710
     */
711
    public static function translate($index_name, $table, $pid) {
712
        // Load labels into static variable for future use.
713
        static $labels = [];
714
        // Sanitize input.
715
        $pid = max(intval($pid), 0);
716
        if (!$pid) {
717
            self::devLog('Invalid PID '.$pid.' for translation', DEVLOG_SEVERITY_WARNING);
718
            return $index_name;
719
        }
720
        // Check if "index_name" is an UID.
721
        if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($index_name)) {
722
            $index_name = self::getIndexNameFromUid($index_name, $table, $pid);
723
        }
724
        /* $labels already contains the translated content element, but with the index_name of the translated content element itself
725
         * and not with the $index_name of the original that we receive here. So we have to determine the index_name of the
726
         * associated translated content element. E.g. $labels['title0'] != $index_name = title. */
727
        // First fetch the uid of the received index_name
728
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
729
            'uid, l18n_parent',
730
            $table,
731
            'pid='.$pid
732
                .' AND index_name="'.$index_name.'"'
733
                .self::whereClause($table, TRUE),
734
            '',
735
            '',
736
            ''
737
        );
738
        if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
739
            // Now we use the uid of the l18_parent to fetch the index_name of the translated content element.
740
            $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
741
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
742
                'index_name',
743
                $table,
744
                'pid='.$pid
745
                    .' AND uid='.$resArray['l18n_parent']
746
                    .' AND sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content)
747
                    .self::whereClause($table, TRUE),
748
                '',
749
                '',
750
                ''
751
            );
752
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
753
                // If there is an translated content element, overwrite the received $index_name.
754
                $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
755
                $index_name = $resArray['index_name'];
756
            }
757
        }
758
        // Check if we already got a translation.
759
        if (empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) {
760
            // Check if this table is allowed for translation.
761
            if (in_array($table, ['tx_dlf_collections', 'tx_dlf_libraries', 'tx_dlf_metadata', 'tx_dlf_structures'])) {
762
                $additionalWhere = ' AND sys_language_uid IN (-1,0)';
763
                if ($GLOBALS['TSFE']->sys_language_content > 0) {
764
                    $additionalWhere = ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid='.intval($GLOBALS['TSFE']->sys_language_content).' AND l18n_parent=0))';
765
                }
766
                // Get labels from database.
767
                $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
768
                    '*',
769
                    $table,
770
                    'pid='.$pid
771
                        .$additionalWhere
772
                        .self::whereClause($table, TRUE),
773
                    '',
774
                    '',
775
                    ''
776
                );
777
                if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) {
778
                    while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
779
                        // Overlay localized labels if available.
780
                        if ($GLOBALS['TSFE']->sys_language_content > 0) {
781
                            $resArray = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $resArray, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
782
                        }
783
                        if ($resArray) {
784
                            $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$resArray['index_name']] = $resArray['label'];
785
                        }
786
                    }
787
                } else {
788
                    self::devLog('No translation with PID '.$pid.' available in table "'.$table.'" or translation not accessible', DEVLOG_SEVERITY_NOTICE);
789
                }
790
            } else {
791
                self::devLog('No translations available for table "'.$table.'"', DEVLOG_SEVERITY_WARNING);
792
            }
793
        }
794
        if (!empty($labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name])) {
795
            return $labels[$table][$pid][$GLOBALS['TSFE']->sys_language_content][$index_name];
796
        } else {
797
            return $index_name;
798
        }
799
    }
800
801
    /**
802
     * This returns the additional WHERE clause of a table based on its TCA configuration
803
     *
804
     * @access public
805
     *
806
     * @param string $table: Table name as defined in TCA
0 ignored issues
show
Documentation introduced by
There is no parameter named $table:. Did you maybe mean $table?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
807
     * @param boolean $showHidden: Ignore the hidden flag?
0 ignored issues
show
Documentation introduced by
There is no parameter named $showHidden:. Did you maybe mean $showHidden?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
808
     *
809
     * @return string Additional WHERE clause
810
     */
811
    public static function whereClause($table, $showHidden = FALSE) {
812
        if (TYPO3_MODE === 'FE') {
813
            // Table "tx_dlf_formats" always has PID 0.
814
            if ($table == 'tx_dlf_formats') {
815
                return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
816
            }
817
            // Should we ignore the record's hidden flag?
818
            $ignoreHide = -1;
819
            if ($showHidden) {
820
                $ignoreHide = 1;
821
            }
822
            // $GLOBALS['TSFE']->sys_page is not always available in frontend.
823
            if (is_object($GLOBALS['TSFE']->sys_page)) {
824
                return $GLOBALS['TSFE']->sys_page->enableFields($table, $ignoreHide);
825
            } else {
826
                $pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
827
                $GLOBALS['TSFE']->includeTCA();
828
                return $pageRepository->enableFields($table, $ignoreHide);
829
            }
830
        } elseif (TYPO3_MODE === 'BE') {
831
            return \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($table);
832
        } else {
833
            self::devLog('Unexpected TYPO3_MODE "'.TYPO3_MODE.'"', DEVLOG_SEVERITY_ERROR);
834
            return ' AND 1=-1';
835
        }
836
    }
837
838
    /**
839
     * This is a static class, thus no instances should be created
840
     *
841
     * @access private
842
     */
843
    private function __construct() {}
844
}
845