Fixed issue #17284: Formprotection persistToken method is called too often, causing...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_bedisplaylog.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains class for display of backend log
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 81: class t3lib_BEDisplayLog
42 * 106: function initArray()
43 * 123: function getTimeLabel($code)
44 * 139: function getUserLabel($code,$workspace=0)
45 * 154: function getTypeLabel($code)
46 * 168: function getActionLabel($code)
47 * 186: function getDetails($code,$text,$data,$sys_log_uid=0)
48 * 220: function reset()
49 * 234: function getErrorFormatting($sign, $error=0)
50 * 244: function formatDetailsForList($row)
51 * 261: function stripPath($inArr)
52 *
53 * TOTAL FUNCTIONS: 10
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59 /**
60 * This class holds some functions used to display the sys_log table-content.
61 * Used in the status-scripts and the log-module.
62 *
63 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
64 * @package TYPO3
65 * @subpackage t3lib
66 * @see tx_belog_webinfo, SC_mod_tools_log_index
67 */
68 class t3lib_BEDisplayLog {
69 var $lastTimeLabel = '';
70 var $lastUserLabel = '';
71 var $lastTypeLabel = '';
72 var $lastActionLabel = '';
73
74 var $detailsOn = 1; // If detailsOn, %s is substituted with values from the data-array (see getDetails())
75 var $stripPath = 1; // This strips the path from any value in the data-array when the data-array is parsed through stripPath()
76 var $errorSign = Array(
77 1 => '!',
78 2 => 'Sys!',
79 3 => 'Security!'
80 );
81 var $wsArray = array(
82 0 => 'LIVE',
83 -1 => 'Draft',
84 );
85
86 var $be_user_Array = array(); // Username array (set externally)
87
88 /**
89 * Initialize the log table array with header labels.
90 *
91 * @return array
92 */
93 function initArray() {
94 $codeArr = array();
95 $codeArr[0][] = 'Time'; // Time
96 $codeArr[0][] = 'User';
97 $codeArr[0][] = 'Type';
98 $codeArr[0][] = 'Error';
99 $codeArr[0][] = 'Action';
100 $codeArr[0][] = 'Details';
101 return $codeArr;
102 }
103
104 /**
105 * Get time label for log listing
106 *
107 * @param integer Timestamp to display
108 * @return string If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
109 */
110 function getTimeLabel($code) {
111 #$t=$GLOBALS['SOBE']->doc->formatTime($code,1);
112 $t = date('H:i:s', $code);
113
114 if ($this->lastTimeLabel != $t) {
115 $this->lastTimeLabel = $t;
116 return $t;
117 } else {
118 return '.';
119 }
120
121 }
122
123 /**
124 * Get user name label for log listing
125 *
126 * @param integer be_user uid
127 * @param integer Workspace ID
128 * @return string If username is different from last username then the username, otherwise "."
129 */
130 function getUserLabel($code, $workspace = 0) {
131 if ($this->lastUserLabel != $code . '_' . $workspace) {
132 $this->lastUserLabel = $code . '_' . $workspace;
133 $label = $this->be_user_Array[$code]['username'];
134 $ws = $this->wsArray[$workspace];
135 return ($label ? htmlspecialchars($label) : '[' . $code . ']') . '@' . ($ws ? $ws : $workspace);
136 } else {
137 return '.';
138 }
139 }
140
141 /**
142 * Get type label for log listing
143 *
144 * @param string Key for the type label in locallang
145 * @return string If labe is different from last type label then the label is returned, otherwise "."
146 */
147 function getTypeLabel($code) {
148 if ($this->lastTypeLabel != $code) {
149 $this->lastTypeLabel = $code;
150 $label = $GLOBALS['LANG']->getLL('type_' . $code);
151 return $label ? $label : '[' . $code . ']';
152 } else {
153 return '.';
154 }
155 }
156
157 /**
158 * Get action label for log listing
159 *
160 * @param string Key for the action label in locallang
161 * @return string If label is different from last action label then the label is returned, otherwise "."
162 */
163 function getActionLabel($code) {
164 if ($this->lastActionLabel != $code) {
165 $this->lastActionLabel = $code;
166 $label = $GLOBALS['LANG']->getLL('action_' . $code);
167 return $label ? htmlspecialchars($label) : '[' . $code . ']';
168 } else {
169 return '.';
170 }
171 }
172
173 /**
174 * Get details for the log entry
175 *
176 * @param string Suffix to "msg_" to get label from locallang.
177 * @param string Details text
178 * @param array Data array
179 * @param integer sys_log uid number
180 * @return string Text string
181 * @see formatDetailsForList()
182 */
183 function getDetails($code, $text, $data, $sys_log_uid = 0) {
184 // $code is used later on to substitute errormessages with language-corrected values...
185 if (is_array($data)) {
186 if ($this->detailsOn) {
187 if (is_object($GLOBALS['LANG'])) {
188 # $label = $GLOBALS['LANG']->getLL('msg_'.$code);
189 } else {
190 list($label) = explode(',', $text);
191 }
192 if ($label) {
193 $text = $label;
194 }
195 $text = sprintf($text, htmlspecialchars($data[0]), htmlspecialchars($data[1]), htmlspecialchars($data[2]), htmlspecialchars($data[3]), htmlspecialchars($data[4]));
196 } else {
197 $text = str_replace('%s', '', $text);
198 }
199 }
200 $text = htmlspecialchars($text);
201
202 // Finding the history for the record
203 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,fieldlist', 'sys_history', 'sys_log_uid=' . intval($sys_log_uid));
204 $newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
205 if (is_array($newRow)) {
206 $text .= ' ' . sprintf($GLOBALS['LANG']->getLL('changesInFields'), '<em>' . $newRow['fieldlist'] . '</em>');
207 $text .= ' <a href="' . htmlspecialchars($GLOBALS['BACK_PATH'] . 'show_rechis.php?sh_uid=' . $newRow['uid'] .
208 '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))) . '">' .
209 t3lib_iconWorks::getSpriteIcon(
210 'actions-document-history-open',
211 array('title' => $GLOBALS['LANG']->getLL('showHistory'))
212 ) .
213 '</a>';
214 }
215
216 return $text;
217 }
218
219 /**
220 * Reset all internal "last..." variables to blank string.
221 *
222 * @return void
223 */
224 function reset() {
225 $this->lastTimeLabel = '';
226 $this->lastUserLabel = '';
227 $this->lastTypeLabel = '';
228 $this->lastActionLabel = '';
229 }
230
231 /**
232 * Formats input string in red-colored font tags
233 *
234 * @param string Input value
235 * @param integer Error value
236 * @return string Input wrapped in red font-tag and bold
237 */
238 function getErrorFormatting($sign, $error = 0) {
239 return $GLOBALS['SOBE']->doc->icons($error >= 2 ? 3 : 2) . ' ' . $sign;
240 }
241
242 /**
243 * Formatting details text for the sys_log row inputted
244 *
245 * @param array sys_log row
246 * @return string Details string
247 */
248 function formatDetailsForList($row) {
249 $data = unserialize($row['log_data']);
250 if ($row['type'] == 2) {
251 $data = $this->stripPath($data);
252 }
253
254 return $this->getDetails($row['type'] . '_' . $row['action'] . '_' . $row['details_nr'], $row['details'], $data, $row['uid']) . ($row['details_nr'] > 0 ? ' (msg#' . $row['type'] . '.' . $row['action'] . '.' . $row['details_nr'] . ')' : '');
255 }
256
257 /**
258 * For all entries in the $inArray (expected to be filepaths) the basename is extracted and set as value (if $this->stripPath is set)
259 * This is done for log-entries from the FILE modules
260 *
261 * @param array Array of file paths
262 * @return array
263 * @see formatDetailsForList()
264 */
265 function stripPath($inArr) {
266 if ($this->stripPath && is_array($inArr)) {
267 foreach ($inArr as $key => $val) {
268 $inArr[$key] = basename($val);
269 }
270 }
271 return $inArr;
272 }
273 }
274
275
276 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php'])) {
277 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);
278 }
279 ?>