82326c9b8e7e347091c759d8e42ec6540f08a826
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / Classes / ViewHelpers / FormatDetailsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Belog\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Create detail string from log entry
19 *
20 * @author Christian Kuhn <lolli@schwarzbu.ch>
21 * @internal
22 */
23 class FormatDetailsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
24
25 /**
26 * Create formatted detail string from log row.
27 *
28 * The method handles two properties of the model: details and logData
29 * Details is a string with possible %s placeholders, and logData an array
30 * with the substitutions.
31 * Furthermore, possible files in logData are stripped to their basename if
32 * the action logged was a file action
33 *
34 * @param \TYPO3\CMS\Belog\Domain\Model\LogEntry $logEntry
35 * @return string Formatted details
36 */
37 public function render(\TYPO3\CMS\Belog\Domain\Model\LogEntry $logEntry) {
38 $detailString = $logEntry->getDetails();
39 $substitutes = $logEntry->getLogData();
40 // Strip paths from file names if the log was a file action
41 if ($logEntry->getType() === 2) {
42 $substitutes = $this->stripPathFromFilenames($substitutes);
43 }
44 // Substitute
45 $detailString = vsprintf($detailString, $substitutes);
46 // Remove possible pending other %s
47 $detailString = str_replace('%s', '', $detailString);
48 return htmlspecialchars($detailString);
49 }
50
51 /**
52 * Strips path from array of file names
53 *
54 * @param array $files
55 * @return array
56 */
57 protected function stripPathFromFilenames(array $files = array()) {
58 foreach ($files as $key => $file) {
59 $files[$key] = basename($file);
60 }
61 return $files;
62 }
63
64 }