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