2 /***************************************************************
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Contains class for display of backend log
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
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)
54 * (This index is automatically created/updated by the extension "extdeveval")
73 * This class holds some functions used to display the sys_log table-content.
74 * Used in the status-scripts and the log-module.
76 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
79 * @see tx_belog_webinfo, SC_mod_tools_log_index
81 class t3lib_BEDisplayLog
{
82 var $lastTimeLabel = '';
83 var $lastUserLabel = '';
84 var $lastTypeLabel = '';
85 var $lastActionLabel = '';
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(
99 var $be_user_Array = array(); // Username array (set externally)
102 * Initialize the log table array with header labels.
106 function initArray() {
108 $codeArr[0][]='Time'; // Time
109 $codeArr[0][]='User';
110 $codeArr[0][]='Type';
112 $codeArr[0][]='Action';
113 $codeArr[0][]='Details';
118 * Get time label for log listing
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()
123 function getTimeLabel($code) {
124 $t=$GLOBALS['SOBE']->doc
->formatTime($code,1);
125 if ($this->lastTimeLabel
!=$t) {
126 $this->lastTimeLabel
=$t;
133 * Get user name label for log listing
135 * @param integer be_user uid
136 * @param integer Workspace ID
137 * @return string If username is different from last username then the username, otherwise "."
139 function getUserLabel($code,$workspace=0) {
140 if ($this->lastUserLabel
!=$code.'_'.$workspace) {
141 $this->lastUserLabel
=$code.'_'.$workspace;
142 $label = $this->be_user_Array
[$code]['username'];
143 $ws = $this->wsArray
[$workspace];
144 return ($label ?
$label : '['.$code.']').'@'.($ws?
$ws:$workspace);
149 * Get type label for log listing
151 * @param string Key for the type label in locallang
152 * @return string If labe is different from last type label then the label is returned, otherwise "."
154 function getTypeLabel($code) {
155 if ($this->lastTypeLabel
!=$code) {
156 $this->lastTypeLabel
=$code;
157 $label=$GLOBALS['LANG']->getLL('type_'.$code);
158 return $label ?
$label : '['.$code.']';
163 * Get action label for log listing
165 * @param string Key for the action label in locallang
166 * @return string If labe is different from last action label then the label is returned, otherwise "."
168 function getActionLabel($code) {
169 if ($this->lastActionLabel
!=$code) {
170 $this->lastActionLabel
=$code;
171 $label=$GLOBALS['LANG']->getLL('action_'.$code);
172 return $label ?
$label : '['.$code.']';
177 * Get details for the log entry
179 * @param string Suffix to "msg_" to get label from locallang.
180 * @param string Details text
181 * @param array Data array
182 * @param integer sys_log uid number
183 * @return string Text string
184 * @see formatDetailsForList()
186 function getDetails($code,$text,$data,$sys_log_uid=0) {
187 // $code is used later on to substitute errormessages with language-corrected values...
188 if (is_array($data)) {
189 if ($this->detailsOn
) {
190 if (is_object($GLOBALS['LANG'])) {
191 $label = $GLOBALS['LANG']->getLL('msg_'.$code);
193 list($label) = explode(',',$text);
195 if ($label) {$text=$label;}
196 $text = sprintf($text, htmlspecialchars($data[0]),htmlspecialchars($data[1]),htmlspecialchars($data[2]),htmlspecialchars($data[3]),htmlspecialchars($data[4]));
198 $text = str_replace('%s','',$text);
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.=' Changes in fields: <em>'.$newRow['fieldlist'].'</em>.';
207 $text.=' <a href="'.htmlspecialchars($GLOBALS['BACK_PATH'].'show_rechis.php?sh_uid='.$newRow['uid'].'&returnUrl='.rawurlencode(t3lib_div
::getIndpEnv('REQUEST_URI'))).'">'.
208 '<img'.t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'],'gfx/history2.gif','width="13" height="12"').' title="Show History" alt="" />'.
216 * Reset all internal "last..." variables to blank string.
221 $this->lastTimeLabel
='';
222 $this->lastUserLabel
='';
223 $this->lastTypeLabel
='';
224 $this->lastActionLabel
='';
228 * Formats input string in red-colored font tags
230 * @param string Input value
231 * @param integer Error value
232 * @return string Input wrapped in red font-tag and bold
234 function getErrorFormatting($sign, $error=0) {
235 return $GLOBALS['SOBE']->doc
->icons($error>=2 ?
3:2).$sign;
239 * Formatting details text for the sys_log row inputted
241 * @param array sys_log row
242 * @return string Details string
244 function formatDetailsForList($row) {
245 $data = unserialize($row['log_data']);
246 if ($row['type']==2) {
247 $data=$this->stripPath($data);
250 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 * For all entries in the $inArray (expected to be filepaths) the basename is extracted and set as value (if $this->stripPath is set)
255 * This is done for log-entries from the FILE modules
257 * @param array Array of file paths
259 * @see formatDetailsForList()
261 function stripPath($inArr) {
262 if ($this->stripPath
&& is_array($inArr)) {
263 while(list($key,$val)=each($inArr)) {
264 $inArr[$key]=basename($val);
272 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']) {
273 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);