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