git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4899 709f56b5-9817-0410-a4d7...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_bedisplaylog.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 Kasper Skaarhoj (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 Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <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
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * This class holds some functions used to display the sys_log table-content.
74 * Used in the status-scripts and the log-module.
75 *
76 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
77 * @package TYPO3
78 * @subpackage t3lib
79 * @see tx_belog_webinfo, SC_mod_tools_log_index
80 */
81 class t3lib_BEDisplayLog {
82 var $lastTimeLabel = '';
83 var $lastUserLabel = '';
84 var $lastTypeLabel = '';
85 var $lastActionLabel = '';
86
87 var $detailsOn = 1; // If detailsOn, %s is substituted with values from the data-array (see getDetails())
88 var $stripPath = 1; // This strips the path from any value in the data-array when the data-array is parsed through stripPath()
89 var $errorSign = Array(
90 1 => '!',
91 2 => 'Sys!',
92 3 => 'Security!'
93 );
94 var $wsArray = array(
95 0 => 'LIVE',
96 -1 => 'Draft',
97 );
98
99 var $be_user_Array = array(); // Username array (set externally)
100
101 /**
102 * Initialize the log table array with header labels.
103 *
104 * @return array
105 */
106 function initArray() {
107 $codeArr=Array();
108 $codeArr[0][]='Time'; // Time
109 $codeArr[0][]='User';
110 $codeArr[0][]='Type';
111 $codeArr[0][]='Error';
112 $codeArr[0][]='Action';
113 $codeArr[0][]='Details';
114 return $codeArr;
115 }
116
117 /**
118 * Get time label for log listing
119 *
120 * @param integer Timestamp to display
121 * @return string If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
122 */
123 function getTimeLabel($code) {
124 #$t=$GLOBALS['SOBE']->doc->formatTime($code,1);
125 $t = date('H:i:s',$code);
126
127 if ($this->lastTimeLabel!=$t) {
128 $this->lastTimeLabel=$t;
129 return $t;
130 } else {
131 return '.';
132 }
133
134 }
135
136 /**
137 * Get user name label for log listing
138 *
139 * @param integer be_user uid
140 * @param integer Workspace ID
141 * @return string If username is different from last username then the username, otherwise "."
142 */
143 function getUserLabel($code,$workspace=0) {
144 if ($this->lastUserLabel!=$code.'_'.$workspace) {
145 $this->lastUserLabel=$code.'_'.$workspace;
146 $label = $this->be_user_Array[$code]['username'];
147 $ws = $this->wsArray[$workspace];
148 return ($label ? $label : '['.$code.']').'@'.($ws?$ws:$workspace);
149 } else return '.';
150 }
151
152 /**
153 * Get type label for log listing
154 *
155 * @param string Key for the type label in locallang
156 * @return string If labe is different from last type label then the label is returned, otherwise "."
157 */
158 function getTypeLabel($code) {
159 if ($this->lastTypeLabel!=$code) {
160 $this->lastTypeLabel=$code;
161 $label=$GLOBALS['LANG']->getLL('type_'.$code);
162 return $label ? $label : '['.$code.']';
163 } else return '.';
164 }
165
166 /**
167 * Get action label for log listing
168 *
169 * @param string Key for the action label in locallang
170 * @return string If labe is different from last action label then the label is returned, otherwise "."
171 */
172 function getActionLabel($code) {
173 if ($this->lastActionLabel!=$code) {
174 $this->lastActionLabel=$code;
175 $label=$GLOBALS['LANG']->getLL('action_'.$code);
176 return $label ? $label : '['.$code.']';
177 } else return '.';
178 }
179
180 /**
181 * Get details for the log entry
182 *
183 * @param string Suffix to "msg_" to get label from locallang.
184 * @param string Details text
185 * @param array Data array
186 * @param integer sys_log uid number
187 * @return string Text string
188 * @see formatDetailsForList()
189 */
190 function getDetails($code,$text,$data,$sys_log_uid=0) {
191 // $code is used later on to substitute errormessages with language-corrected values...
192 if (is_array($data)) {
193 if ($this->detailsOn) {
194 if (is_object($GLOBALS['LANG'])) {
195 # $label = $GLOBALS['LANG']->getLL('msg_'.$code);
196 } else {
197 list($label) = explode(',',$text);
198 }
199 if ($label) {$text=$label;}
200 $text = sprintf($text, htmlspecialchars($data[0]),htmlspecialchars($data[1]),htmlspecialchars($data[2]),htmlspecialchars($data[3]),htmlspecialchars($data[4]));
201 } else {
202 $text = str_replace('%s','',$text);
203 }
204 }
205
206 // Finding the history for the record
207 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,fieldlist', 'sys_history', 'sys_log_uid='.intval($sys_log_uid));
208 $newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
209 if (is_array($newRow)) {
210 $text.=' Changes in fields: <em>'.$newRow['fieldlist'].'</em>.';
211 $text.=' <a href="'.htmlspecialchars($GLOBALS['BACK_PATH'].'show_rechis.php?sh_uid='.$newRow['uid'].'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
212 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/history2.gif','width="13" height="12"').' title="Show History" alt="" />'.
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 while(list($key,$val)=each($inArr)) {
268 $inArr[$key]=basename($val);
269 }
270 }
271 return $inArr;
272 }
273 }
274
275
276 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']) {
277 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);
278 }
279 ?>