Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_timetrack.patch

Administrator Admin, 2010-11-24 18:38

View differences:

t3lib/class.t3lib_timetrack.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
* Copyright notice
*
* (c) 1999-2010 Kasper Sk?rh?j (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Contains class with time tracking functions
*
* $Id: class.t3lib_timetrack.php 9098 2010-10-16 17:34:50Z benni $
* Revised for TYPO3 3.6 July/2003 by Kasper Sk?rh?j
* XHTML compliant
*
* @author Kasper Sk?rh?j <kasperYYYY@typo3.com>
*/
* Contains class with time tracking functions
*
* $Id: class.t3lib_timetrack.php 9098 2010-10-16 17:34:50Z benni $
* Revised for TYPO3 3.6 July/2003 by Kasper Sk?rh?j
* XHTML compliant
*
* @author Kasper Sk?rh?j <kasperYYYY@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
......
*
* 88: class t3lib_timeTrack
*
* SECTION: Logging parsing times in the scripts
* SECTION: Logging parsing times in the scripts
* 144: function start()
* 144: function start()
* 164: function push($tslabel, $value='')
* 164: function push($tslabel, $value='')
* 189: function pull($content='')
* 189: function pull($content='')
* 207: function setTSlogMessage($content,$num=0)
* 207: function setTSlogMessage($content,$num=0)
* 221: function setTSselectQuery($query,$msg)
* 221: function setTSselectQuery($query,$msg)
* 234: function incStackPointer()
* 234: function incStackPointer()
* 245: function decStackPointer()
* 245: function decStackPointer()
* 255: function mtime()
* 255: function mtime()
* 265: function convertMicrotime($microtime)
* 265: function convertMicrotime($microtime)
*
* SECTION: Printing the parsing time information (for Admin Panel)
* SECTION: Printing the parsing time information (for Admin Panel)
* 298: function printTSlog()
* 298: function printTSlog()
* 447: function fixContent(&$arr, $content, $depthData='', $first=0, $vKey='')
* 447: function fixContent(&$arr, $content, $depthData='', $first=0, $vKey='')
* 511: function fixCLen($c,$v)
* 511: function fixCLen($c,$v)
* 527: function fw($str)
* 527: function fw($str)
* 541: function createHierarchyArray(&$arr,$pointer,$uniqueId)
* 541: function createHierarchyArray(&$arr,$pointer,$uniqueId)
* 561: function debug_typo3PrintError($header,$text,$js,$baseUrl='')
* 561: function debug_typo3PrintError($header,$text,$js,$baseUrl='')
*
* TOTAL FUNCTIONS: 15
* (This index is automatically created/updated by the extension "extdeveval")
......
*/
/**
* Frontend Timetracking functions
*
......
* @see t3lib_tsfeBeUserAuth, tslib_fe, tslib_cObj, TSpagegen
*/
class t3lib_timeTrack {
var $starttime = 0; // Is loaded with the millisecond time when this object is created
var $starttime = 0; // Is loaded with the millisecond time when this object is created
var $LR = 1; // Log Rendering flag. If set, ->push() and ->pull() is called from the cObj->cObjGetSingle(). This determines whether or not the TypoScript parsing activity is logged. But it also slows down the rendering
var $LR = 1; // Log Rendering flag. If set, ->push() and ->pull() is called from the cObj->cObjGetSingle(). This determines whether or not the TypoScript parsing activity is logged. But it also slows down the rendering
var $printConf=array(
var $printConf = array(
'showParentKeys' => 1,
'contentLength' => 10000, // Determines max lenght of displayed content before it gets cropped.
'contentLength' => 10000, // Determines max lenght of displayed content before it gets cropped.
'contentLength_FILE' => 400, // Determines max lenght of displayed content FROM FILE cObjects before it gets cropped. Reason is that most FILE cObjects are huge and often used as template-code.
'contentLength_FILE' => 400, // Determines max lenght of displayed content FROM FILE cObjects before it gets cropped. Reason is that most FILE cObjects are huge and often used as template-code.
'flag_tree' => 1,
'flag_messages' => 1,
'flag_queries' => 0,
......
var $tsStackPointer = 0;
var $currentHashPointer = array();
var $highlightLongerThan = 0; // Log entries that take than this number of milliseconds (own time) will be highlighted during log display. Set 0 to disable highlighting.
var $highlightLongerThan = 0; // Log entries that take than this number of milliseconds (own time) will be highlighted during log display. Set 0 to disable highlighting.
/*******************************************
*
* Logging parsing times in the scripts
*
*******************************************/
*
* Logging parsing times in the scripts
*
*******************************************/
/**
* Constructor
......
*/
public function start() {
$this->wrapError = array(
0 => array('',''),
0 => array('', ''),
1 => array('<strong>','</strong>'),
1 => array('<strong>', '</strong>'),
2 => array('<strong style="color:#ff6600;">','</strong>'),
2 => array('<strong style="color:#ff6600;">', '</strong>'),
3 => array('<strong style="color:#ff0000;">','</strong>')
3 => array('<strong style="color:#ff0000;">', '</strong>')
);
$this->wrapIcon = array(
0 => '',
1 => '<img src="'.TYPO3_mainDir.'gfx/icon_note.gif" width="18" height="16" align="absmiddle" alt="" />',
1 => '<img src="' . TYPO3_mainDir . 'gfx/icon_note.gif" width="18" height="16" align="absmiddle" alt="" />',
2 => '<img src="'.TYPO3_mainDir.'gfx/icon_warning.gif" width="18" height="16" align="absmiddle" alt="" />',
2 => '<img src="' . TYPO3_mainDir . 'gfx/icon_warning.gif" width="18" height="16" align="absmiddle" alt="" />',
3 => '<img src="'.TYPO3_mainDir.'gfx/icon_fatalerror.gif" width="18" height="16" align="absmiddle" alt="" />'
3 => '<img src="' . TYPO3_mainDir . 'gfx/icon_fatalerror.gif" width="18" height="16" align="absmiddle" alt="" />'
);
$this->starttime = $this->getMilliseconds();
......
*/
public function push($tslabel, $value = '') {
array_push($this->tsStack[$this->tsStackPointer], $tslabel);
array_push($this->currentHashPointer, 'timetracker_'.$this->uniqueCounter++);
array_push($this->currentHashPointer, 'timetracker_' . $this->uniqueCounter++);
$this->tsStackLevel++;
$this->tsStackLevelMax[] = $this->tsStackLevel;
......
'level' => $this->tsStackLevel,
'tsStack' => $this->tsStack,
'value' => $value,
'starttime' => microtime(true),
'starttime' => microtime(TRUE),
'stackPointer' => $this->tsStackPointer
);
}
......
*/
public function pull($content = '') {
$k = end($this->currentHashPointer);
$this->tsStackLog[$k]['endtime'] = microtime(true);
$this->tsStackLog[$k]['endtime'] = microtime(TRUE);
$this->tsStackLog[$k]['content'] = $content;
$this->tsStackLevel--;
......
end($this->currentHashPointer);
$k = current($this->currentHashPointer);
if (strlen($content)>30) { // Enlarge the "details" column by adding a wide clear.gif
if (strlen($content) > 30) { // Enlarge the "details" column by adding a wide clear.gif
$placeholder = '<br /><img src="'.TYPO3_mainDir.'clear.gif" width="300" height="1" alt="" />';
$placeholder = '<br /><img src="' . TYPO3_mainDir . 'clear.gif" width="300" height="1" alt="" />';
}
$this->tsStackLog[$k]['message'][] = $this->wrapIcon[$num].$this->wrapError[$num][0].htmlspecialchars($content).$this->wrapError[$num][1].$placeholder;
$this->tsStackLog[$k]['message'][] = $this->wrapIcon[$num] . $this->wrapError[$num][0] . htmlspecialchars($content) . $this->wrapError[$num][1] . $placeholder;
}
/**
......
*/
public function incStackPointer() {
$this->tsStackPointer++;
$this->tsStack[$this->tsStackPointer]=array();
$this->tsStack[$this->tsStackPointer] = array();
}
/**
......
public function convertMicrotime($microtime) {
t3lib_div::logDeprecatedFunction();
$parts = explode(' ',$microtime);
$parts = explode(' ', $microtime);
return round(($parts[0]+$parts[1])*1000);
return round(($parts[0] + $parts[1]) * 1000);
}
/**
......
*/
public function getMilliseconds($microtime = NULL) {
if (!isset($microtime)) {
$microtime = microtime(true);
$microtime = microtime(TRUE);
}
return round($microtime * 1000);
}
......
}
/*******************************************
*
* Printing the parsing time information (for Admin Panel)
*
*******************************************/
*
* Printing the parsing time information (for Admin Panel)
*
*******************************************/
/**
* Print TypoScript parsing log
......
$out = '';
foreach ($outputArr as $row) {
$out.= '
$out .= '
<th style="text-align:center; background:#ABBBB4;"><strong>'.$row.'</strong></th>';
<th style="text-align:center; background:#ABBBB4;"><strong>' . $row . '</strong></th>';
}
$out = '<tr>'.$out.'</tr>';
$out = '<tr>' . $out . '</tr>';
$flag_tree = $this->printConf['flag_tree'];
$flag_messages = $this->printConf['flag_messages'];
......
$col = $this->printConf['col'];
$highlight_col = $this->printConf['highlight_col'];
$c=0;
$c = 0;
foreach ($this->tsStackLog as $uniqueId => $data) {
$bgColor = ' background-color:'.($c%2 ? t3lib_div::modifyHTMLColor($col,$factor,$factor,$factor) : $col).';';
$bgColor = ' background-color:' . ($c % 2 ? t3lib_div::modifyHTMLColor($col, $factor, $factor, $factor) : $col) . ';';
if ($this->highlightLongerThan && intval($data['owntime']) > intval($this->highlightLongerThan)) {
$bgColor = ' background-color:'.$highlight_col.';';
$bgColor = ' background-color:' . $highlight_col . ';';
}
$item = '';
if (!$c) { // If first...
if (!$c) { // If first...
$data['icons'] = '';
$data['key'] = 'Script Start';
$data['value'] = '';
......
if (!$flag_tree && $data['stackPointer']) {
$temp = array();
foreach ($data['tsStack'] as $k => $v) {
$temp[] = t3lib_div::fixed_lgd_cs(implode($v,$k?'.':'/'),-$keyLgd);
$temp[] = t3lib_div::fixed_lgd_cs(implode($v, $k ? '.' : '/'), -$keyLgd);
}
array_pop($temp);
$temp = array_reverse($temp);
array_pop($temp);
if (count($temp)) {
$keyLabel = '<br /><span style="color:#999999;">'.implode($temp,'<br />').'</span>';
$keyLabel = '<br /><span style="color:#999999;">' . implode($temp, '<br />') . '</span>';
}
}
if ($flag_tree) {
$tmp = t3lib_div::trimExplode('.',$data['key'],1);
$tmp = t3lib_div::trimExplode('.', $data['key'], 1);
$theLabel = end($tmp);
} else {
$theLabel = $data['key'];
}
$theLabel = t3lib_div::fixed_lgd_cs($theLabel, -$keyLgd);
$theLabel = $data['stackPointer'] ? '<span style="color:maroon;">'.$theLabel.'</span>' : $theLabel;
$theLabel = $data['stackPointer'] ? '<span style="color:maroon;">' . $theLabel . '</span>' : $theLabel;
$keyLabel = $theLabel.$keyLabel;
$keyLabel = $theLabel . $keyLabel;
$item.= '<td valign="top" style="text-align:left; white-space:nowrap; padding-left:2px;'.$bgColor.'">'.($flag_tree?$data['icons']:'').$this->fw($keyLabel).'</td>';
$item .= '<td valign="top" style="text-align:left; white-space:nowrap; padding-left:2px;' . $bgColor . '">' . ($flag_tree ? $data['icons'] : '') . $this->fw($keyLabel) . '</td>';
// key value:
$keyValue = $data['value'];
$item.= '<td valign="top" style="text-align:left; white-space:nowrap;'.$bgColor.'">'.$this->fw(htmlspecialchars($keyValue)).'</td>';
$item .= '<td valign="top" style="text-align:left; white-space:nowrap;' . $bgColor . '">' . $this->fw(htmlspecialchars($keyValue)) . '</td>';
if ($this->printConf['allTime']) {
$item.= '<td valign="top" style="text-align:right; white-space:nowrap;'.$bgColor.'"> '.$this->fw($data['starttime']).'</td>';
$item .= '<td valign="top" style="text-align:right; white-space:nowrap;' . $bgColor . '"> ' . $this->fw($data['starttime']) . '</td>';
$item.= '<td valign="top" style="text-align:right; white-space:nowrap;'.$bgColor.'"> '.$this->fw($data['owntime']).'</td>';
$item .= '<td valign="top" style="text-align:right; white-space:nowrap;' . $bgColor . '"> ' . $this->fw($data['owntime']) . '</td>';
$item.= '<td valign="top" style="text-align:left; white-space:nowrap;'.$bgColor.'"> '.$this->fw($data['subtime'] ? '+'.$data['subtime'] : '').'</td>';
$item .= '<td valign="top" style="text-align:left; white-space:nowrap;' . $bgColor . '"> ' . $this->fw($data['subtime'] ? '+' . $data['subtime'] : '') . '</td>';
$item.= '<td valign="top" style="text-align:left; white-space:nowrap;'.$bgColor.'"> '.$this->fw($data['subtime'] ? '='.$data['deltatime'] : '').'</td>';
$item .= '<td valign="top" style="text-align:left; white-space:nowrap;' . $bgColor . '"> ' . $this->fw($data['subtime'] ? '=' . $data['deltatime'] : '') . '</td>';
} else {
$item.= '<td valign="top" style="text-align:right; white-space:nowrap;'.$bgColor.'"> '.$this->fw($data['owntime']).'</td>';
$item .= '<td valign="top" style="text-align:right; white-space:nowrap;' . $bgColor . '"> ' . $this->fw($data['owntime']) . '</td>';
}
......
if ($flag_queries && is_array($data['selectQuery'])) {
$msgArr[] = t3lib_utility_Debug::viewArray($data['selectQuery']);
}
if ($flag_content && strcmp($data['content'],'')) {
if ($flag_content && strcmp($data['content'], '')) {
$maxlen = 120;
if (preg_match_all('/(\S{'.$maxlen.',})/', $data['content'], $reg)) { // Break lines which are too longer than $maxlen chars (can happen if content contains long paths...)
if (preg_match_all('/(\S{' . $maxlen . ',})/', $data['content'], $reg)) { // Break lines which are too longer than $maxlen chars (can happen if content contains long paths...)
foreach ($reg[1] as $key=>$match) {
foreach ($reg[1] as $key => $match) {
$match = preg_replace('/(.{'.$maxlen.'})/', '$1 ', $match);
$match = preg_replace('/(.{' . $maxlen . '})/', '$1 ', $match);
$data['content'] = str_replace($reg[0][$key], $match, $data['content']);
}
}
$msgArr[] = '<span style="color:#000066;">'.nl2br($data['content']).'</span>';
$msgArr[] = '<span style="color:#000066;">' . nl2br($data['content']) . '</span>';
}
if (count($msgArr)) {
$msg = implode($msgArr,'<hr />');
$msg = implode($msgArr, '<hr />');
}
$item.= '<td valign="top" style="text-align:left;'.$bgColor.'">'.$this->fw($msg).'</td>';
$item .= '<td valign="top" style="text-align:left;' . $bgColor . '">' . $this->fw($msg) . '</td>';
$out.= '<tr>'.$item.'</tr>';
$out .= '<tr>' . $item . '</tr>';
$c++;
}
$out = '<table border="0" cellpadding="0" cellspacing="0" summary="">'.$out.'</table>';
$out = '<table border="0" cellpadding="0" cellspacing="0" summary="">' . $out . '</table>';
return $out;
}
......
* @return string Returns the $content string generated/modified. Also the $arr array is modified!
*/
protected function fixContent(&$arr, $content, $depthData = '', $first = 0, $vKey = '') {
$ac=0;
$ac = 0;
$c=0;
$c = 0;
// First, find number of entries
foreach ($arr as $k => $v) {
if (t3lib_div::testInt($k)) {
......
}
}
// Traverse through entries
$subtime=0;
$subtime = 0;
foreach ($arr as $k => $v) {
if (t3lib_div::testInt($k)) {
$c++;
$deeper = is_array($arr[$k.'.']) ? 1 : 0;
$deeper = is_array($arr[$k . '.']) ? 1 : 0;
$PM = 'join';
$LN = ($ac==$c)?'blank':'line';
$LN = ($ac == $c) ? 'blank' : 'line';
$BTM = ($ac==$c)?'bottom':'';
$BTM = ($ac == $c) ? 'bottom' : '';
$PM = is_array($arr[$k.'.']) ? ($deeper ? 'minus':'plus') : 'join';
$PM = is_array($arr[$k . '.']) ? ($deeper ? 'minus' : 'plus') : 'join';
$this->tsStackLog[$v]['icons'] = $depthData.($first?'':'<img src="'.TYPO3_mainDir.'gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />');
$this->tsStackLog[$v]['icons'] = $depthData . ($first ? '' : '<img src="' . TYPO3_mainDir . 'gfx/ol/' . $PM . $BTM . '.gif" width="18" height="16" align="top" border="0" alt="" />');
if (strlen($this->tsStackLog[$v]['content'])) {
$content = str_replace($this->tsStackLog[$v]['content'],$v, $content);
$content = str_replace($this->tsStackLog[$v]['content'], $v, $content);
}
if (is_array($arr[$k.'.'])) {
if (is_array($arr[$k . '.'])) {
$this->tsStackLog[$v]['content'] = $this->fixContent($arr[$k.'.'], $this->tsStackLog[$v]['content'], $depthData.($first?'':'<img src="'.TYPO3_mainDir.'gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" border="0" alt="" />'), 0, $v);
$this->tsStackLog[$v]['content'] = $this->fixContent($arr[$k . '.'], $this->tsStackLog[$v]['content'], $depthData . ($first ? '' : '<img src="' . TYPO3_mainDir . 'gfx/ol/' . $LN . '.gif" width="18" height="16" align="top" border="0" alt="" />'), 0, $v);
} else {
$this->tsStackLog[$v]['content'] = $this->fixCLen($this->tsStackLog[$v]['content'], $this->tsStackLog[$v]['value']);
$this->tsStackLog[$v]['subtime'] = '';
$this->tsStackLog[$v]['owntime'] = $this->tsStackLog[$v]['deltatime'];
}
$subtime+= $this->tsStackLog[$v]['deltatime'];
$subtime += $this->tsStackLog[$v]['deltatime'];
}
}
// Set content with special chars
if (isset($this->tsStackLog[$vKey])) {
$this->tsStackLog[$vKey]['subtime'] = $subtime;
$this->tsStackLog[$vKey]['owntime'] = $this->tsStackLog[$vKey]['deltatime']-$subtime;
$this->tsStackLog[$vKey]['owntime'] = $this->tsStackLog[$vKey]['deltatime'] - $subtime;
}
$content=$this->fixCLen($content, $this->tsStackLog[$vKey]['value']);
$content = $this->fixCLen($content, $this->tsStackLog[$vKey]['value']);
// Traverse array again, this time substitute the unique hash with the red key
foreach ($arr as $k => $v) {
if (t3lib_div::testInt($k)) {
if (strlen($this->tsStackLog[$v]['content'])) {
$content = str_replace($v, '<strong style="color:red;">['.$this->tsStackLog[$v]['key'].']</strong>', $content);
$content = str_replace($v, '<strong style="color:red;">[' . $this->tsStackLog[$v]['key'] . ']</strong>', $content);
}
}
}
......
* @return string
*/
protected function fixCLen($c, $v) {
$len = $v=='FILE'?$this->printConf['contentLength_FILE']:$this->printConf['contentLength'];
$len = $v == 'FILE' ? $this->printConf['contentLength_FILE'] : $this->printConf['contentLength'];
if (strlen($c)>$len) {
if (strlen($c) > $len) {
$c = '<span style="color:green;">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($c,$len)).'</span>';
$c = '<span style="color:green;">' . htmlspecialchars(t3lib_div::fixed_lgd_cs($c, $len)) . '</span>';
} else {
$c = htmlspecialchars($c);
}
......
* @return string
*/
protected function fw($str) {
return '<span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px; color:black; vertical-align:top;">'.$str.'&nbsp;</span>';
return '<span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px; color:black; vertical-align:top;">' . $str . '&nbsp;</span>';
}
/**
......
if (!is_array($arr)) {
$arr = array();
}
if ($pointer>0) {
if ($pointer > 0) {
end($arr);
$k = key($arr);
$this->createHierarchyArray($arr[intval($k).'.'],$pointer-1,$uniqueId);
$this->createHierarchyArray($arr[intval($k) . '.'], $pointer - 1, $uniqueId);
} else {
$arr[] = $uniqueId;
}
......
'baseUrl' => $baseUrl,
'errorMessage' => &$errorMessage
);
$null = null;
$null = NULL;
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_timetrack.php']['debug_typo3PrintError'] as $hookMethod) {
t3lib_div::callUserFunction($hookMethod, $params, $null);
}
(64-64/93)