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