TYPO3  7.6
NoneElement.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Element;
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 
20 
25 {
31  public function render()
32  {
33  $parameterArray = $this->data['parameterArray'];
34  $config = $parameterArray['fieldConf']['config'];
35  $itemValue = $parameterArray['itemFormElValue'];
36 
37  if ($config['format']) {
38  $itemValue = $this->formatValue($config, $itemValue);
39  }
40  if (!$config['pass_content']) {
41  $itemValue = htmlspecialchars($itemValue);
42  }
43 
44  $resultArray = $this->initializeResultArray();
45  $rows = (int)$config['rows'];
46  // Render as textarea
47  if ($rows > 1 || $config['type'] === 'text') {
48  if (!$config['pass_content']) {
49  $itemValue = nl2br($itemValue);
50  }
51  $cols = MathUtility::forceIntegerInRange($config['cols'] ?: $this->defaultInputWidth, 5, $this->maxInputWidth);
52  $width = $this->formMaxWidth($cols);
53  $html = '
54  <div class="form-control-wrap"' . ($width ? ' style="max-width: ' . $width . 'px"' : '') . '>
55  <textarea class="form-control" rows="' . $rows . '" disabled>' . $itemValue . '</textarea>
56  </div>';
57  } else {
58  $cols = $config['cols'] ?: ($config['size'] ?: $this->defaultInputWidth);
59  $size = MathUtility::forceIntegerInRange($cols ?: $this->defaultInputWidth, 5, $this->maxInputWidth);
60  $width = $this->formMaxWidth($size);
61  $html = '
62  <div class="form-control-wrap"' . ($width ? ' style="max-width: ' . $width . 'px"' : '') . '>
63  <input class="form-control" value="' . $itemValue . '" type="text" disabled>
64  </div>';
65  }
66  $resultArray['html'] = $html;
67  return $resultArray;
68  }
69 
77  protected function formatValue($config, $itemValue)
78  {
79  $format = trim($config['format']);
80  switch ($format) {
81  case 'date':
82  if ($itemValue) {
83  $option = trim($config['format.']['option']);
84  if ($option) {
85  if ($config['format.']['strftime']) {
86  $value = strftime($option, $itemValue);
87  } else {
88  $value = date($option, $itemValue);
89  }
90  } else {
91  $value = date('d-m-Y', $itemValue);
92  }
93  } else {
94  $value = '';
95  }
96  if ($config['format.']['appendAge']) {
98  $GLOBALS['EXEC_TIME'] - $itemValue,
99  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
100  );
101  $value .= ' (' . $age . ')';
102  }
103  $itemValue = $value;
104  break;
105  case 'datetime':
106  // compatibility with "eval" (type "input")
107  if ($itemValue !== '' && !is_null($itemValue)) {
108  $itemValue = date('H:i d-m-Y', (int)$itemValue);
109  }
110  break;
111  case 'time':
112  // compatibility with "eval" (type "input")
113  if ($itemValue !== '' && !is_null($itemValue)) {
114  $itemValue = date('H:i', (int)$itemValue);
115  }
116  break;
117  case 'timesec':
118  // compatibility with "eval" (type "input")
119  if ($itemValue !== '' && !is_null($itemValue)) {
120  $itemValue = date('H:i:s', (int)$itemValue);
121  }
122  break;
123  case 'year':
124  // compatibility with "eval" (type "input")
125  if ($itemValue !== '' && !is_null($itemValue)) {
126  $itemValue = date('Y', (int)$itemValue);
127  }
128  break;
129  case 'int':
130  $baseArr = array('dec' => 'd', 'hex' => 'x', 'HEX' => 'X', 'oct' => 'o', 'bin' => 'b');
131  $base = trim($config['format.']['base']);
132  $format = $baseArr[$base] ?: 'd';
133  $itemValue = sprintf('%' . $format, $itemValue);
134  break;
135  case 'float':
136  $precision = MathUtility::forceIntegerInRange($config['format.']['precision'], 1, 10, 2);
137  $itemValue = sprintf('%.' . $precision . 'f', $itemValue);
138  break;
139  case 'number':
140  $format = trim($config['format.']['option']);
141  $itemValue = sprintf('%' . $format, $itemValue);
142  break;
143  case 'md5':
144  $itemValue = md5($itemValue);
145  break;
146  case 'filesize':
147  // We need to cast to int here, otherwise empty values result in empty output,
148  // but we expect zero.
149  $value = GeneralUtility::formatSize((int)$itemValue);
150  if ($config['format.']['appendByteSize']) {
151  $value .= ' (' . $itemValue . ')';
152  }
153  $itemValue = $value;
154  break;
155  case 'user':
156  $func = trim($config['format.']['userFunc']);
157  if ($func) {
158  $params = [
159  'value' => $itemValue,
160  'args' => $config['format.']['userFunc'],
161  'config' => $config,
162  ];
163  $itemValue = GeneralUtility::callUserFunction($func, $params, $this);
164  }
165  break;
166  default:
167  // Do nothing e.g. when $format === ''
168  }
169  return $itemValue;
170  }
171 }