Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Feb 25, 5:48 AM

in-portal

Index: branches/5.2.x/core/kernel/utility/debugger/debugger.js
===================================================================
--- branches/5.2.x/core/kernel/utility/debugger/debugger.js (revision 15529)
+++ branches/5.2.x/core/kernel/utility/debugger/debugger.js (revision 15530)
@@ -1,625 +1,626 @@
function DebugReq() {}
DebugReq.timeout = 5 * 60 * 1000; // 5 minutes
DebugReq.makeRequest = function(p_url, p_busyReq, p_progId, p_successCallBack, p_errorCallBack, p_pass, p_object) {
//p_url: the web service url
//p_busyReq: is a request for this object currently in progress?
//p_progId: element id where progress HTML should be shown
//p_successCallBack: callback function for successful response
//p_errorCallBack: callback function for erroneous response
//p_pass: string of params to pass to callback functions
//p_object: object of params to pass to callback functions
if (p_busyReq) {
return;
}
var req = DebugReq.getRequest();
if (req != null) {
p_busyReq = true;
DebugReq.showProgress(p_progId);
req.onreadystatechange = function() {
if (req.readyState == 4) {
p_busyReq = false;
window.clearTimeout(toId);
if (req.status == 200) {
p_successCallBack(req,p_pass,p_object);
} else {
p_errorCallBack(req,p_pass,p_object);
}
}
}
var $ajax_mark = (p_url.indexOf('?') ? '&' : '?') + 'ajax=yes';
req.open('GET', p_url + $ajax_mark, true);
req.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
req.send(null);
var toId = window.setTimeout( function() {if (p_busyReq) req.abort();}, DebugReq.timeout );
}
}
DebugReq.getRequest = function() {
var xmlHttp;
try { xmlHttp = new ActiveXObject('MSXML2.XMLHTTP'); return xmlHttp; } catch (e) {}
try { xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); return xmlHttp; } catch (e) {}
try { xmlHttp = new XMLHttpRequest(); return xmlHttp; } catch(e) {}
return null;
}
DebugReq.showProgress = function(p_id) {
$Debugger.AppendRow(DebugReq.getProgressHtml());
}
DebugReq.getProgressHtml = function() {
return 'Loading ...';
}
DebugReq.getErrorHtml = function(p_req) {
//TODO: implement accepted way to handle request error
return "<p>" + "(" + p_req.status + ") " + p_req.statusText + "</p>"
}
// Debugger
function Debugger($params) {
this.RowSeparator = '';
this.IsFatalError = false;
this.ErrorsCount = 0;
this.SQLCount = 0;
this.SQLTime = 0;
this.ScriptTime = 0;
this.ScriptMemory = 0;
this.Shortcut = 'F12';
for (var $param_name in $params) {
this[$param_name] = $params[$param_name];
}
this.IsQueried = false;
this.IsVisible = false;
this.DebuggerDIV = document.getElementById('debug_layer');
this.DebuggerTable = document.getElementById('debug_table');
this.RowCount = 0;
this.busyRequest = false;
this.DragObject = null;
this.LastDragObject = null;
this.MouseOffset = [0,0];
this.ResizeHappening = false;
this.ResizeTimer = null;
this.InitialPos = null;
// window.$Debugger = this; // this should be uncommented in case if debugger variable is not $Debugger
this.AddEvent(window, 'scroll', function (ev) { window.$Debugger.Resize(ev); });
this.AddEvent(window, 'resize', function (ev) { window.$Debugger.Resize(ev); });
this.AddEvent(document, 'keydown', function (ev) { window.$Debugger.KeyDown(ev); }); // don't work in IE
}
Debugger.prototype.createEnvironment = function($outer_width, $inner_width) {
if (!this.DebuggerDIV) {
// when debugger wasn't added already
var $container = document.createElement('DIV');
$container.id = 'debug_layer';
$container.className = 'debug_layer_container';
$container.style.display = 'none';
$container.style.width = $outer_width + 'px';
var $debug_layer = document.createElement('DIV');
$debug_layer.className = 'debug_layer';
$debug_layer.style.width = $inner_width + 'px';
$container.insertBefore($debug_layer, $container.firstChild);
var $table = document.createElement('TABLE');
$table.style.width = '100%';
$table.className = 'debug_layer_table';
$table.style.width = $inner_width + 'px';
$debug_layer.insertBefore($table, $debug_layer.firstChild);
var $tbody = document.createElement('TBODY');
$tbody.id = 'debug_table';
$table.insertBefore($tbody, $table.firstChild);
var $body = document.getElementsByTagName('BODY')[0];
$body.insertBefore($container, $body.lastChild);
this.DebuggerDIV = document.getElementById('debug_layer');
this.DebuggerTable = document.getElementById('debug_table');
}
else {
this.Clear();
}
}
Debugger.prototype.SetOpacity = function(opacity)
{
this.DebuggerToolbar.style.opacity = (opacity / 100);
this.DebuggerToolbar.style.MozOpacity = (opacity / 100);
this.DebuggerToolbar.style.KhtmlOpacity = (opacity / 100);
this.DebuggerToolbar.style.filter = "alpha(opacity=" + opacity + ")";
}
Debugger.prototype.ToolbarClick = function ($button) {
switch ($button.id) {
case 'dbg_ReloadFrame':
self.location.reload();
break;
case 'dbg_ShowDebugger':
this.Toggle();
break;
case 'dbg_TurnOff':
var $exdate = new Date();
$exdate.setDate( $exdate.getDate() + 365 );
document.cookie = 'debug_off=1; expires=' + $exdate.toUTCString() + '; path=' + this.BasePath + '/';
self.location.reload();
break;
}
}
Debugger.prototype.jQueryFound = function () {
return typeof jQuery == 'function';
}
Debugger.prototype.AddToolbar = function($var_name) {
if (document.getElementById('debug_toolbar_span')) {
// toolbar was already created before
if (this.jQueryFound()) {
$('#debug_toolbar_span').remove();
}
else {
return ;
}
}
var $span = document.createElement('SPAN');
$span.style.position = 'absolute';
$span.style.zIndex= 99;
$span.style.top = '0px';
$span.style.left = '0px';
$span.id = 'debug_toolbar_span';
document.body.style.textAlign = 'left';
var $toolbar_content = '<td class="dbg-button" id="dbg_ReloadFrame" onclick="' + $var_name + '.ToolbarClick(this);">Reload Frame</td>';
if (this.ErrorsCount > 0) {
$toolbar_content += '<td class="dbg-separator"></td><td class="dbg-button debug_error" style="font-weight: bold;" id="dbg_ShowDebugger" onclick="' + $var_name + '.ToolbarClick(this);">Show Debugger (' + this.ErrorsCount + ' errors)</td>';
}
else {
$toolbar_content += '<td class="dbg-button" id="dbg_ShowDebugger" onclick="' + $var_name + '.ToolbarClick(this);">Show Debugger</td>';
}
$toolbar_content += '<td class="dbg-button" id="dbg_TurnOff" onclick="' + $var_name + '.ToolbarClick(this);">Turn Off</td>';
if (this.SQLCount > 0) {
$toolbar_content += '<td class="dbg-separator"></td><td style="cursor: move"><strong>' + this.SQLCount + '</strong> sqls (' + this.SQLTime + ' s)</td>';
}
if (this.ScriptTime > 0) {
$toolbar_content += '<td class="dbg-separator"></td><td style="cursor: move">' + this.ScriptTime + ' s (' + this.ScriptMemory + ')</td>';
}
$span.innerHTML = '<table style="height: 30px" cellpadding="0" cellspacing="3" class="dbg-toolbar"><tr>' + $toolbar_content + '</tr></table>';
this.DebuggerToolbar = $span;
this.SetOpacity(20);
$span.onmouseover = function() {
$Debugger.SetOpacity(100);
}
$span.onmouseout = function() {
$Debugger.SetOpacity(20);
}
var $body = document.getElementsByTagName('BODY')[0];
$body.insertBefore($span, $body.firstChild);
// alert($span.offsetWidth)
this.MakeDragable('debug_toolbar_span', function() {}, function() {}, function() {});
}
Debugger.prototype.AppendRow = function($html) {
this.RowCount++;
var $tr = document.createElement('TR');
this.DebuggerTable.appendChild($tr);
$tr.className = 'debug_row_' + (this.RowCount % 2 ? 'odd' : 'even');
$tr.id = 'debug_row_' + this.RowCount;
var $td = document.createElement('TD');
$td.className = 'debug_cell';
$td.innerHTML = $html;
$tr.appendChild($td);
}
Debugger.prototype.RemoveRow = function($row_index) {
this.DebuggerTable.deleteRow($row_index);
this.RowCount--;
}
Debugger.prototype.Clear = function() {
if (!this.IsQueried) return false;
while (this.DebuggerTable.rows.length) {
this.RemoveRow(0);
}
this.Toggle(27);
this.IsQueried = false;
}
Debugger.prototype.KeyDown = function($e) {
var $matched_parts = 0,
$KeyCode = this.GetKeyCode($e),
$shortcut_parts = this.Shortcut.toLowerCase().split('+');
$e = ($e) ? $e : event;
var $modifier_map = {
'ctrl': $e.ctrlKey,
'shift': $e.shiftKey,
'alt': $e.altKey,
'meta': $e.metaKey
};
for (var $i = 0; $i < $shortcut_parts.length; $i++) {
for (var $modifier in $modifier_map) {
if ( $shortcut_parts[$i] == $modifier && $modifier_map[$modifier] ) {
$matched_parts++;
break;
}
}
if ( this.getKeyCodeFromString($shortcut_parts[$i]) == $KeyCode ) {
$matched_parts++;
}
}
if ( $matched_parts == $shortcut_parts.length || $KeyCode == 27 ) {// F12 or ESC
this.Toggle($KeyCode);
this.StopEvent($e);
}
}
Debugger.prototype.getKeyCodeFromString = function($string) {
var $special_keys = {
'esc': 27,
'escape': 27,
'tab': 9,
'space': 32,
'return': 13,
'enter': 13,
'backspace': 8,
'scrolllock': 145,
'scroll_lock': 145,
'scroll': 145,
'capslock': 20,
'caps_lock': 20,
'caps': 20,
'numlock': 144,
'num_lock': 144,
'num': 144,
'pause': 19,
'break': 19,
'insert': 45,
'home': 36,
'delete': 46,
'end': 35,
'pageup': 33,
'page_up': 33,
'pu': 33,
'pagedown': 34,
'page_down': 34,
'pd': 34,
'left': 37,
'up': 38,
'right': 39,
'down': 40,
'f1': 112,
'f2': 113,
'f3': 114,
'f4': 115,
'f5': 116,
'f6': 117,
'f7': 118,
'f8': 119,
'f9': 120,
'f10': 121,
'f11': 122,
'f12': 123
};
$string = $string.toLowerCase();
if ( $special_keys[$string] !== undefined ) {
return $special_keys[$string];
}
return $string.charCodeAt(0);
}
Debugger.prototype.OpenDOMViewer = function() {
var $value = document.getElementById('dbg_domviewer').value;
DOMViewerObj = ($value.indexOf('"') != -1) ? document.getElementById( $value.substring(1,$value.length-1) ) : eval($value);
window.open(this.DOMViewerURL);
return false;
}
Debugger.prototype.GetKeyCode = function($e) {
$e = ($e) ? $e : event;
var charCode = ($e.charCode) ? $e.charCode : (($e.which) ? $e.which : $e.keyCode);
if ( charCode == 27 ) {
// don't lowercase ESC
return charCode;
}
return String.fromCharCode(charCode).toLowerCase().charCodeAt(0);
}
Debugger.prototype.StopEvent = function($e) {
$e = ($e) ? $e : event;
$e.cancelBubble = true;
if ($e.stopPropagation) $e.stopPropagation();
}
Debugger.prototype.Toggle = function($KeyCode) {
if(!this.DebuggerDIV) return false;
this.IsVisible = this.DebuggerDIV.style.display == 'none' ? false : true;
if (!this.IsVisible && $KeyCode == 27) {
return false;
}
this.Resize(null);
if (!this.IsQueried) {
this.Query();
}
this.DebuggerDIV.style.display = this.IsVisible ? 'none' : 'block';
}
Debugger.prototype.Query = function() {
DebugReq.makeRequest(this.DebugURL, this.busyRequest, '', this.successCallback, this.errorCallback, '', this);
}
Debugger.prototype.successCallback = function(p_req, p_pass, p_object) {
if (p_pass == 'resetCache') {
alert('Requested action performed.');
return ;
}
var contents = p_req.responseText;
contents = contents.split(p_object.RowSeparator);
if (contents.length == 1) {
alert('error: '+p_req.responseText);
p_object.IsQueried = true;
return ;
}
for (var $i = 0; $i < contents.length - 1; $i++) {
p_object.AppendRow(contents[$i]);
}
if ( p_object.jQueryFound() ) {
var $stats_table = $('.dbg_stats_table:first').clone();
var $statistics_html = $( $('<div></div>').html($stats_table) ).html();
if ($statistics_html) {
$('.dbg_stats_table:first').remove();
p_object.AppendRow($statistics_html);
}
}
p_object.Refresh();
}
Debugger.prototype.errorCallback = function(p_req, p_pass, p_object) {
alert('AJAX ERROR: '+DebugReq.getErrorHtml(p_req));
p_object.Refresh();
}
Debugger.prototype.Refresh = function() {
- // progress mether row
+ // progress meter row
+
this.RemoveRow(0);
this.IsQueried = true;
this.DebuggerDIV.scrollTop = this.IsFatalError ? 10000000 : 0;
this.DebuggerDIV.scrollLeft = 0;
}
Debugger.prototype.Resize = function($e) {
if (!this.DebuggerDIV) return false;
var $pageTop = document.all ? document.body.offsetTop + document.body.scrollTop : window.scrollY;
this.DebuggerDIV.style.top = $pageTop + 'px';
this.DebuggerDIV.style.height = GetWindowHeight() + 'px';
return true;
}
function GetWindowHeight() {
var currWinHeight;
// if (document.body.clientHeight) {
// currWinHeight = document.body.clientHeight;
if (window.innerHeight) {//FireFox with correction for status bar at bottom of window
currWinHeight = window.innerHeight;
} else if (document.documentElement.clientHeight) {//IE 7 with correction for address bar
currWinHeight = document.documentElement.clientHeight;
} else if (document.body.offsetHeight) {//IE 4+
currWinHeight = document.body.offsetHeight + 10;
}
return currWinHeight - 10; // 10 - horizontal scrollbar height
}
/*function GetWinHeight() {
if (window.innerHeight) return window.innerHeight;
else if (document.documentElement.clientHeight) return document.documentElement.clientHeight;
else if (document.body.offsetHeight) return document.body.offsetHeight;
else return _winHeight;
}*/
Debugger.prototype.SetClipboard = function(copyText) {
if (window.clipboardData) {
// IE send-to-clipboard method.
window.clipboardData.setData('Text', copyText);
}
else if (window.netscape) {
// You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true);
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Store support string in an object.
var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
if (!str) {
return false;
}
str.data = copyText;
// Make transferable.
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) {
return false;
}
// Specify what datatypes we want to obtain, which is text in this case.
trans.addDataFlavor('text/unicode');
trans.setTransferData('text/unicode', str, copyText.length * 2);
var clipid = Components.interfaces.nsIClipboard;
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].getService(clipid);
if (!clip) {
return false;
}
clip.setData(trans, null, clipid.kGlobalClipboard);
}
}
Debugger.prototype.ShowProps = function($Obj, $Name) {
var $ret = '';
for ($Prop in $Obj) {
$ret += $Name + '.' + $Prop + ' = ' + $Obj[$Prop] + "\n";
}
return alert($ret);
}
Debugger.prototype.editFile = function($fileName, $lineNo) {
if (!document.all) {
alert('Only works in IE');
return;
}
if (!this.EditorPath) {
alert('Editor path not defined!');
return;
}
var $launch_object = new ActiveXObject('LaunchinIE.Launch');
var $editor_path = this.EditorPath;
$editor_path = $editor_path.replace('%F', $fileName);
$editor_path = $editor_path.replace('%L',$lineNo);
$launch_object.LaunchApplication($editor_path);
}
Debugger.prototype.ToggleTraceArgs = function($arguments_layer_id) {
var $arguments_layer = document.getElementById($arguments_layer_id);
$arguments_layer.style.display = ($arguments_layer.style.display == 'none') ? 'block' : 'none';
}
Debugger.prototype.AddEvent = function (el, evname, func) {
var $status = false;
if (document.all) {
$status = el.attachEvent('on' + evname, func);
} else {
$status = el.addEventListener(evname, func, true);
}
}
Debugger.prototype.resetCache = function ($event_source) {
var $events = document.getElementById($event_source);
var $event = $events.options[$events.selectedIndex].value;
if (!$event) {
alert('Please select action to perform first!');
}
else if (confirm('Really perform "' + $events.options[$events.selectedIndex].innerHTML + '"?')) {
DebugReq.makeRequest(this.EventURL + '&' + $event, this.busyRequest, '', this.successCallback, this.errorCallback, 'resetCache', this);
}
}
Debugger.prototype.mouseCoords = function(ev)
{
if(ev.pageX || ev.pageY){
var res = {x:ev.pageX, y:ev.pageY};
}
else {
var res = {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
return res;
}
Debugger.prototype.MakeDragable = function(object_id, startCallback, moveCallback, endCallback, options)
{
var drag_object = document.getElementById(object_id);
var cur_options = {'VerticalDrag': 1, 'HorizontalDrag': 1};
if (options) {
for(var i in options) {
cur_options[i] = options[i];
}
}
var the_debugger = this;
this.AddEvent(drag_object, 'mousedown', function(ev){
ev = ev || window.event;
the_debugger.InitialPos = dbg_findPos(drag_object);
var coords = the_debugger.mouseCoords(ev);
var pos = dbg_findPos(drag_object);
the_debugger.MouseOffset = [coords.x - pos[0], coords.y - pos[1]];
the_debugger.DragObject = drag_object;
the_debugger.LastDragObject = drag_object;
the_debugger.DragObject.style.position = 'absolute';
the_debugger.Options = cur_options;
startCallback(drag_object);
});
this.AddEvent(document, 'mousemove', function(ev) {
// window.status = 'mouse at: '+coords.x+','+coords.y;
if(the_debugger.DragObject){
ev = ev || window.event;
var coords = the_debugger.mouseCoords(ev);
if (the_debugger.Options.VerticalDrag) {
the_debugger.DragObject.style.top = (coords.y - the_debugger.MouseOffset[1] ) + 'px' // ;
}
if (the_debugger.Options.HorizontalDrag) {
the_debugger.DragObject.style.left = (coords.x - the_debugger.MouseOffset[0] ) + 'px' // ;
}
moveCallback(drag_object, coords)
return false;
}
});
this.AddEvent(document, 'mouseup', function(ev){
var tmp = the_debugger.DragObject;
the_debugger.DragObject = null;
if(tmp){
endCallback(tmp);
}
var pos = dbg_findPos(drag_object);
});
}
function dbg_findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}
\ No newline at end of file
Index: branches/5.2.x/core/kernel/utility/debugger/debugger.css
===================================================================
--- branches/5.2.x/core/kernel/utility/debugger/debugger.css (revision 15529)
+++ branches/5.2.x/core/kernel/utility/debugger/debugger.css (revision 15530)
@@ -1,135 +1,135 @@
#debug_layer code {
font-family: monospace;
}
#debug_layer b, #debug_layer strong {
font-weight: bold;
}
/* <br> tags inside <span> tags, produced by "hightlight_string" method call in PHP have strange bottom margin sometimes */
.dbg_profiler {
margin-top: 5px;
padding: 0px;
height: 10px;
border: 1px solid #000000;
float: left;
display: inline;
}
.dbg_flat_table, .dbg_stats_table, table.dbg_explain_table {
border-collapse: collapse;
width: auto;
margin: 0px;
}
table.dbg_explain_table TD {
border: 1px solid #000000;
padding: 4px;
}
table.dbg_explain_table tr.explain_header TD {
font-weight: bold;
text-align: center;
}
.dbg_flat_table TD, .dbg_stats_table TD {
border: 1px solid #CCCCCC;
padding: 4px;
}
.dbg_stats_table TD {
background-color: #FFFFFF;
font-family: Arial, Verdana;
font-size: 9pt;
text-align: left;
}
.debug_cell .dbg_stats_table td {
background-color: transparent;
}
.debug_layer_table {
border-collapse: collapse;
}
.debug_text, .debug_row_even TD, .debug_row_odd TD {
color: #000000;
font-family: Verdana;
font-size: 11px;
}
.debug_cell {
border: 1px solid #FF0000;
padding: 4px;
text-align: left;
}
.debug_row_even {
background-color: #CCCCFF;
}
.debug_row_odd {
background-color: #FFFFCC;
}
.debug_layer_container {
left: 2px;
top: 1px;
- z-index: +1000;
+ z-index: 1500000;
position: absolute;
overflow: auto;
border: 2px solid;
padding: 3px;
border-top-color: threedlightshadow;
border-left-color: threedlightshadow;
border-right-color: threeddarkshadow;
border-bottom-color: threeddarkshadow;
background-color: buttonface;
}
.debug_layer {
padding: 0px;
}
.debug_error {
color: #FF0000;
}
.dbg-toolbar {
border: 1px solid #000000;
background-color: #D4D0C8;
border-collapse: separate;
border-spacing: 2px;
width: auto;
}
.dbg-toolbar td {
font-size: 13px;
font-family: Tahoma;
padding: 1px 5px 1px 5px;
vertical-align: middle;
margin: 3px;
}
.dbg-toolbar td.dbg-button, .dbg-toolbar td.dbg-button:hover {
cursor: default;
}
.dbg-toolbar td.dbg-button {
border: 1px solid #D4D0C8;
background-color: #D4D0C8;
}
.dbg-toolbar td.dbg-button:hover {
border: 1px solid #0A246A;
background-color: #B5BDD2;
}
.dbg-toolbar td.dbg-separator {
background-color: #000000;
width: 1px;
padding: 0px;
}
Index: branches/5.2.x/core/kernel/utility/debugger.php
===================================================================
--- branches/5.2.x/core/kernel/utility/debugger.php (revision 15529)
+++ branches/5.2.x/core/kernel/utility/debugger.php (revision 15530)
@@ -1,1978 +1,1978 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
if( !class_exists('Debugger') ) {
/**
* Contains misc functions, used by debugger (mostly copied from kUtil class)
*/
class DebuggerUtil {
/**
* Checks if constant is defined and has positive value
*
* @param string $const_name
* @return bool
*/
public static function constOn($const_name)
{
return defined($const_name) && constant($const_name);
}
/**
* Define constant if it was not already defined before
*
* @param string $const_name
* @param string $const_value
* @access public
*/
public static function safeDefine($const_name, $const_value)
{
if ( !defined($const_name) ) {
define($const_name, $const_value);
}
}
/**
* Formats file/memory size in nice way
*
* @param int $bytes
* @return string
* @access public
*/
public static function formatSize($bytes)
{
if ($bytes >= 1099511627776) {
$return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
$suffix = "TB";
} elseif ($bytes >= 1073741824) {
$return = round($bytes / 1024 / 1024 / 1024, 2);
$suffix = "GB";
} elseif ($bytes >= 1048576) {
$return = round($bytes / 1024 / 1024, 2);
$suffix = "MB";
} elseif ($bytes >= 1024) {
$return = round($bytes / 1024, 2);
$suffix = "KB";
} else {
$return = $bytes;
$suffix = "Byte";
}
$return .= ' '.$suffix;
return $return;
}
/**
* Checks, that user IP address is within allowed range
*
* @param string $ip_list semi-column (by default) separated ip address list
* @param string $separator ip address separator (default ";")
*
* @return bool
*/
public static function ipMatch($ip_list, $separator = ';')
{
if ( !isset($_SERVER['REMOTE_ADDR']) ) {
// PHP CLI used -> never match
return false;
}
$ip_match = false;
$ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
foreach ($ip_addresses as $ip_address) {
if (self::netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
$ip_match = true;
break;
}
}
return $ip_match;
}
/**
* Checks, that given ip belongs to given subnet
*
* @param string $network
* @param string $ip
* @return bool
* @access public
*/
public static function netMatch($network, $ip) {
$network = trim($network);
$ip = trim($ip);
if ( preg_replace('/[\d\.\/-]/', '', $network) != '' ) {
$network = gethostbyname($network);
}
if ($network == $ip) {
// comparing two ip addresses directly
return true;
}
$d = strpos($network, '-');
if ($d !== false) {
// ip address range specified
$from = ip2long(trim(substr($network, 0, $d)));
$to = ip2long(trim(substr($network, $d + 1)));
$ip = ip2long($ip);
return ($ip >= $from && $ip <= $to);
}
elseif (strpos($network, '/') !== false) {
// single subnet specified
$ip_arr = explode('/', $network);
if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
$ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
}
$network_long = ip2long($ip_arr[0]);
$x = ip2long($ip_arr[1]);
$mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
$ip_long = ip2long($ip);
return ($ip_long & $mask) == ($network_long & $mask);
}
return false;
}
}
/**
* Main debugger class, that can be used with any In-Portal (or not) project
*/
class Debugger {
/**
* Holds reference to global KernelApplication instance
*
* @var kApplication
* @access private
*/
private $Application = null;
/**
* Set to true if fatal error occurred
*
* @var bool
* @access private
*/
private $IsFatalError = false;
/**
* Counts warnings on the page
*
* @var int
* @access public
*/
public $WarningCount = 0;
/**
* Allows to track compile errors, like "stack-overflow"
*
* @var bool
* @access private
*/
private $_compileError = false;
/**
* Debugger data for building report
*
* @var Array
* @access private
*/
private $Data = Array ();
/**
* Holds information about each profiler record (start/end/description)
*
* @var Array
* @access private
*/
private $ProfilerData = Array ();
/**
* Holds information about total execution time per profiler key (e.g. total sql time)
*
* @var Array
* @access private
*/
private $ProfilerTotals = Array ();
/**
* Counts how much each of total types were called (e.g. total error count)
*
* @var Array
* @access private
*/
private $ProfilerTotalCount = Array ();
/**
* Holds information about all profile points registered
*
* @var Array
* @access private
*/
private $ProfilePoints = Array ();
/**
* Prevent recursion when processing debug_backtrace() function results
*
* @var Array
* @access private
*/
private $RecursionStack = Array ();
/**
* Cross browser debugger report scrollbar width detection
*
* @var int
* @access private
*/
private $scrollbarWidth = 0;
/**
* Long errors are saved here, because trigger_error doesn't support error messages over 1KB in size
*
* @var Array
* @access private
*/
private $longErrors = Array ();
/**
* Remembers how much memory & time was spent on including files
*
* @var Array
* @access public
* @see kUtil::includeOnce
*/
public $IncludesData = Array ();
/**
* Remembers maximal include deep level
*
* @var int
* @access public
* @see kUtil::includeOnce
*/
public $IncludeLevel = 0;
/**
* Prevents report generation more then once
*
* @var bool
* @access private
*/
private $reportDone = false;
/**
* Transparent spacer image used in case of none spacer image defined via SPACER_URL constant.
* Used while drawing progress bars (memory usage, time usage, etc.)
*
* @var string
* @access private
*/
private $dummyImage = '';
/**
* Temporary files created by debugger will be stored here
*
* @var string
* @access private
*/
private $tempFolder = '';
/**
* Debug rows will be separated using this string before writing to debug file
*
* @var string
* @access private
*/
private $rowSeparator = '@@';
/**
* Base URL for debugger includes
*
* @var string
* @access private
*/
private $baseURL = '';
/**
* Sub-folder, where In-Portal is installed
*
* @var string
* @access private
*/
private $basePath = '';
/**
* Holds last recorded timestamp (for appendTimestamp)
*
* @var int
* @access private
*/
private $LastMoment;
/**
* Determines, that current request is AJAX request
*
* @var bool
* @access private
*/
private $_isAjax = false;
/**
* Creates instance of debugger
*/
public function __construct()
{
global $start, $dbg_options;
// check if user haven't defined DEBUG_MODE contant directly
if ( defined('DEBUG_MODE') && DEBUG_MODE ) {
die('error: constant DEBUG_MODE defined directly, please use <strong>$dbg_options</strong> array instead');
}
// check IP before enabling debug mode
$ip_match = DebuggerUtil::ipMatch(isset($dbg_options['DBG_IP']) ? $dbg_options['DBG_IP'] : '');
if ( !$ip_match || (isset($_COOKIE['debug_off']) && $_COOKIE['debug_off']) ) {
define('DEBUG_MODE', 0);
return;
}
// debug is allowed for user, continue initialization
$this->InitDebugger();
$this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4', $start);
$this->profileStart('script_runtime', 'Script runtime', $start);
$this->LastMoment = $start;
error_reporting(E_ALL);
// show errors on screen in case if not in Zend Studio debugging
ini_set('display_errors', DebuggerUtil::constOn('DBG_ZEND_PRESENT') ? 0 : 1);
// vertical scrollbar width differs in Firefox and other browsers
$this->scrollbarWidth = $this->isGecko() ? 22 : 25;
$this->appendRequest();
}
/**
* Set's default values to constants debugger uses
*
*/
function InitDebugger()
{
global $dbg_options;
unset($dbg_options['DBG_IP']);
// Detect fact, that this session being debugged by Zend Studio
foreach ($_COOKIE as $cookie_name => $cookie_value) {
if (substr($cookie_name, 0, 6) == 'debug_') {
DebuggerUtil::safeDefine('DBG_ZEND_PRESENT', 1);
break;
}
}
DebuggerUtil::safeDefine('DBG_ZEND_PRESENT', 0); // set this constant value to 0 (zero) to debug debugger using Zend Studio
// set default values for debugger constants
$dbg_constMap = Array (
'DBG_USE_HIGHLIGHT' => 1, // highlight output same as php code using "highlight_string" function
'DBG_WINDOW_WIDTH' => 700, // set width of debugger window (in pixels) for better viewing large amount of debug data
'DBG_USE_SHUTDOWN_FUNC' => DBG_ZEND_PRESENT ? 0 : 1, // use shutdown function to include debugger code into output
'DBG_HANDLE_ERRORS' => DBG_ZEND_PRESENT ? 0 : 1, // handle all allowed by php (see php manual) errors instead of default handler
'DBG_IGNORE_STRICT_ERRORS' => 0, // ignore PHP5 errors about private/public view modified missing in class declarations
'DBG_DOMVIEWER' => '/temp/domviewer.html', // path to DOMViewer on website
'DOC_ROOT' => str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']) ), // windows hack
'DBG_LOCAL_BASE_PATH' => 'w:', // replace DOC_ROOT in filenames (in errors) using this path
'DBG_SHORTCUT' => 'F12', // Defines debugger activation shortcut (any symbols or Ctrl/Alt/Shift are allowed, e.g. Ctrl+Alt+F12)
);
// only for IE, in case if no windows php script editor defined
if (!defined('DBG_EDITOR')) {
// $dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\UltraEdit\uedit32.exe %F/%L';
$dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\Zend\ZendStudio-5.2.0\bin\ZDE.exe %F';
}
// debugger is initialized before kHTTPQuery, so do jQuery headers check here too
if (array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
$this->_isAjax = true;
}
elseif (array_key_exists('ajax', $_GET) && $_GET['ajax'] == 'yes') {
$this->_isAjax = true;
}
// user defined options override debugger defaults
$dbg_constMap = array_merge($dbg_constMap, $dbg_options);
if ($this->_isAjax && array_key_exists('DBG_SKIP_AJAX', $dbg_constMap) && $dbg_constMap['DBG_SKIP_AJAX']) {
$dbg_constMap['DBG_SKIP_REPORTING'] = 1;
}
// allows to validate unit configs via request variable
if ( !array_key_exists('DBG_VALIDATE_CONFIGS', $dbg_constMap) ) {
$dbg_constMap['DBG_VALIDATE_CONFIGS'] = array_key_exists('validate_configs', $_GET) ? (int)$_GET['validate_configs'] : 0;
}
// when validation configs, don't show sqls for better validation error displaying
if ($dbg_constMap['DBG_VALIDATE_CONFIGS']) {
$dbg_constMap['DBG_SQL_PROFILE'] = 0;
}
// when showing explain make shure, that debugger window is large enough
if (array_key_exists('DBG_SQL_EXPLAIN', $dbg_constMap) && $dbg_constMap['DBG_SQL_EXPLAIN']) {
$dbg_constMap['DBG_WINDOW_WIDTH'] = 1000;
}
foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) {
DebuggerUtil::safeDefine($dbg_constName, $dbg_constValue);
}
}
/**
* Performs debugger initialization
*
* @return void
*/
private function InitReport()
{
if ( !class_exists('kApplication') ) {
return;
}
$application =& kApplication::Instance();
// string used to separate debugger records while in file (used in debugger dump filename too)
$this->rowSeparator = '@' . (/*is_object($application->Factory) &&*/ $application->InitDone ? $application->GetSID() : 0) . '@';
// $this->rowSeparator = '@' . rand(0, 100000) . '@';
// include debugger files from this url
$reg_exp = '/^' . preg_quote(FULL_PATH, '/') . '/';
$kernel_path = preg_replace($reg_exp, '', KERNEL_PATH, 1);
$this->baseURL = PROTOCOL . SERVER_NAME . (defined('PORT') ? ':' . PORT : '') . rtrim(BASE_PATH, '/') . $kernel_path . '/utility/debugger';
// store debugger cookies at this path
$this->basePath = rtrim(BASE_PATH, '/');
// save debug output in this folder
$this->tempFolder = defined('RESTRICTED') ? RESTRICTED : WRITEABLE . '/cache';
}
/**
* Allows to overcome short error message problem in tigger_error function
*
* @param string $msg
* @return int
* @access public
*/
public function mapLongError($msg)
{
$key = $this->generateID();
$this->longErrors[$key] = $msg;
return $key;
}
/**
* Appends all passed variable values (without variable names) to debug output
*
* @return void
* @access public
*/
public function dumpVars()
{
$dump_mode = 'var_dump';
$dumpVars = func_get_args();
if ( $dumpVars[count($dumpVars) - 1] === 'STRICT' ) {
$dump_mode = 'strict_var_dump';
array_pop($dumpVars);
}
foreach ($dumpVars as $varValue) {
$this->Data[] = Array ('value' => $varValue, 'debug_type' => $dump_mode);
}
}
/**
* Transforms collected data at given index into human-readable HTML to place in debugger report
*
* @param int $dataIndex
* @return string
* @access private
*/
private function prepareHTML($dataIndex)
{
static $errors_displayed = 0;
$Data =& $this->Data[$dataIndex];
if ( $Data['debug_type'] == 'html' ) {
return $Data['html'];
}
switch ($Data['debug_type']) {
case 'error':
$errors_displayed++;
$fileLink = $this->getFileLink($Data['file'], $Data['line']);
$ret = '<b class="debug_error">' . $this->getErrorNameByCode($Data['no']) . ' (#' . $errors_displayed . ')</b>: ' . $Data['str'];
$ret .= ' in <b>' . $fileLink . '</b> on line <b>' . $Data['line'] . '</b>';
return $ret;
break;
case 'exception':
$fileLink = $this->getFileLink($Data['file'], $Data['line']);
$ret = '<b class="debug_error">' . $Data['exception_class'] . '</b>: ' . $Data['str'];
$ret .= ' in <b>' . $fileLink . '</b> on line <b>' . $Data['line'] . '</b>';
return $ret;
break;
case 'var_dump':
return $this->highlightString($this->print_r($Data['value'], true));
break;
case 'strict_var_dump':
return $this->highlightString(var_export($Data['value'], true));
break;
case 'trace':
ini_set('memory_limit', '500M');
$trace =& $Data['trace'];
$i = 0;
$traceCount = count($trace);
$ret = '';
while ( $i < $traceCount ) {
$traceRec =& $trace[$i];
$argsID = 'trace_args_' . $dataIndex . '_' . $i;
$has_args = isset($traceRec['args']);
if ( isset($traceRec['file']) ) {
$func_name = isset($traceRec['class']) ? $traceRec['class'] . $traceRec['type'] . $traceRec['function'] : $traceRec['function'];
$args_link = $has_args ? '<a href="javascript:$Debugger.ToggleTraceArgs(\'' . $argsID . '\');" title="Show/Hide Function Arguments"><b>Function</b></a>' : '<strong>Function</strong>';
$ret .= $args_link . ': ' . $this->getFileLink($traceRec['file'], $traceRec['line'], $func_name);
$ret .= ' in <b>' . basename($traceRec['file']) . '</b> on line <b>' . $traceRec['line'] . '</b><br>';
}
else {
$ret .= 'no file information available';
}
if ( $has_args ) {
// if parameter value is longer then 200 symbols, then leave only first 50
$args = $this->highlightString($this->print_r($traceRec['args'], true));
$ret .= '<div id="' . $argsID . '" style="display: none;">' . $args . '</div>';
}
$i++;
}
return $ret;
break;
case 'profiler':
$profileKey = $Data['profile_key'];
$Data =& $this->ProfilerData[$profileKey];
$runtime = ($Data['ends'] - $Data['begins']); // in seconds
$totals_key = getArrayValue($Data, 'totalsKey');
if ( $totals_key ) {
$total_before = $Data['totalsBefore'];
$total = $this->ProfilerTotals[$totals_key];
$div_width = Array ();
$total_width = ($this->getWindowWidth() - 10);
$div_width['before'] = round(($total_before / $total) * $total_width);
$div_width['current'] = round(($runtime / $total) * $total_width);
$div_width['left'] = round((($total - $total_before - $runtime) / $total) * $total_width);
$subtitle = array_key_exists('subtitle', $Data) ? ' (' . $Data['subtitle'] . ')' : '';
$ret = '<b>Name' . $subtitle . '</b>: ' . $Data['description'] . '<br />';
$additional = isset($Data['additional']) ? $Data['additional'] : Array ();
if ( isset($Data['file']) ) {
array_unshift($additional, Array ('name' => 'File', 'value' => $this->getFileLink($Data['file'], $Data['line'], basename($Data['file']) . ':' . $Data['line'])));
}
array_unshift($additional, Array ('name' => 'Runtime', 'value' => $runtime . 's'));
$ret .= '<div>'; //FF 3.5 needs this!
foreach ($additional as $mixed_param) {
$ret .= '[<strong>' . $mixed_param['name'] . '</strong>: ' . $mixed_param['value'] . '] ';
}
/*if ( isset($Data['file']) ) {
$ret .= '[<b>Runtime</b>: ' . $runtime . 's] [<b>File</b>: ' . $this->getFileLink($Data['file'], $Data['line'], basename($Data['file']) . ':' . $Data['line']) . ']<br />';
}
else {
$ret .= '<b>Runtime</b>: ' . $runtime . 's<br />';
}*/
$ret .= '</div>';
$ret .= '<div class="dbg_profiler" style="width: ' . $div_width['before'] . 'px; border-right: 0px; background-color: #298DDF;"><img src="' . $this->dummyImage . '" width="1" height="1"/></div>';
$ret .= '<div class="dbg_profiler" style="width: ' . $div_width['current'] . 'px; border-left: 0px; border-right: 0px; background-color: #EF4A4A;"><img src="' . $this->dummyImage . '" width="1" height="1"/></div>';
$ret .= '<div class="dbg_profiler" style="width: ' . $div_width['left'] . 'px; border-left: 0px; background-color: #DFDFDF;"><img src="' . $this->dummyImage . '" width="1" height="1"/></div>';
return $ret;
}
else {
return '<b>Name</b>: ' . $Data['description'] . '<br><b>Runtime</b>: ' . $runtime . 's';
}
break;
default:
return 'incorrect debug data';
break;
}
}
/**
* Returns debugger report window width excluding scrollbar
*
* @return int
* @access private
*/
private function getWindowWidth()
{
return DBG_WINDOW_WIDTH - $this->scrollbarWidth - 8;
}
/**
* Tells debugger to skip objects that are heavy in plan of memory usage while printing debug_backtrace results
*
* @param Object $object
* @return bool
* @access private
*/
private function IsBigObject(&$object)
{
$skip_classes = Array(
defined('APPLICATION_CLASS') ? APPLICATION_CLASS : 'kApplication',
'kFactory',
'kUnitConfigReader',
'NParser',
);
foreach ($skip_classes as $class_name) {
if ( strtolower(get_class($object)) == strtolower($class_name) ) {
return true;
}
}
return false;
}
/**
* Advanced version of print_r (for debugger only). Don't print objects recursively
*
* @param Array $array
* @param bool $return_output return output or print it out
* @param int $tab_count offset in tabs
* @return string
* @access private
*/
private function print_r(&$array, $return_output = false, $tab_count = -1)
{
static $first_line = true;
// not an array at all
if ( !is_array($array) ) {
switch ( gettype($array) ) {
case 'NULL':
return 'NULL' . "\n";
break;
case 'object':
return $this->processObject($array, $tab_count);
break;
default:
// number or string
if ( strlen($array) > 200 ) {
$array = substr($array, 0, 50) . ' ...';
}
return $array . "\n";
break;
}
}
$output = '';
$tab_count++;
$output .= "Array\n" . str_repeat(' ', $tab_count) . "(\n";
$tab_count++;
$tabsign = $tab_count ? str_repeat(' ', $tab_count) : '';
$array_keys = array_keys($array);
foreach ($array_keys as $key) {
switch ( gettype($array[$key]) ) {
case 'array':
$output .= $tabsign . '[' . $key . '] = ' . $this->print_r($array[$key], true, $tab_count);
break;
case 'boolean':
$output .= $tabsign . '[' . $key . '] = ' . ($array[$key] ? 'true' : 'false') . "\n";
break;
case 'integer':
case 'double':
case 'string':
if ( strlen($array[$key]) > 200 ) {
$array[$key] = substr($array[$key], 0, 50) . ' ...';
}
$output .= $tabsign . '[' . $key . '] = ' . $array[$key] . "\n";
break;
case 'NULL':
$output .= $tabsign . '[' . $key . "] = NULL\n";
break;
case 'object':
$output .= $tabsign . '[' . $key . "] = ";
$output .= "Object (" . get_class($array[$key]) . ") = \n" . str_repeat(' ', $tab_count + 1) . "(\n";
$output .= $this->processObject($array[$key], $tab_count + 2);
$output .= str_repeat(' ', $tab_count + 1) . ")\n";
break;
default:
$output .= $tabsign . '[' . $key . '] unknown = ' . gettype($array[$key]) . "\n";
break;
}
}
$tab_count--;
$output .= str_repeat(' ', $tab_count) . ")\n";
if ( $first_line ) {
$first_line = false;
$output .= "\n";
}
$tab_count--;
if ( $return_output ) {
return $output;
}
else {
echo $output;
}
return true;
}
/**
* Returns string representation of given object (more like print_r, but with recursion prevention check)
*
* @param Object $object
* @param int $tab_count
* @return string
* @access private
*/
private function processObject(&$object, $tab_count)
{
$object_class = get_class($object);
if ( !in_array($object_class, $this->RecursionStack) ) {
if ( $this->IsBigObject($object) ) {
return 'SKIPPED (class: ' . $object_class . ")\n";
}
$attribute_names = get_class_vars($object_class);
if ( !$attribute_names ) {
return "NO_ATTRIBUTES\n";
}
else {
$output = '';
array_push($this->RecursionStack, $object_class);
$tabsign = $tab_count ? str_repeat(' ', $tab_count) : '';
foreach ($attribute_names as $attribute_name => $attribute_value) {
if ( is_object($object->$attribute_name) ) {
// it is object
$output .= $tabsign . '[' . $attribute_name . '] = ' . $this->processObject($object->$attribute_name, $tab_count + 1);
}
else {
$output .= $tabsign . '[' . $attribute_name . '] = ' . $this->print_r($object->$attribute_name, true, $tab_count);
}
}
array_pop($this->RecursionStack);
return $output;
}
}
else {
// object [in recursion stack]
return '*** RECURSION *** (class: ' . $object_class . ")\n";
}
}
/**
* Format SQL Query using predefined formatting
* and highlighting techniques
*
* @param string $sql
* @return string
* @access public
*/
public function formatSQL($sql)
{
$sql = trim(preg_replace('/(\n|\t| )+/is', ' ', $sql));
// whitespace in the beginning of the regex is to avoid splitting inside words, for example "FROM int_ConfigurationValues" into "FROM intConfiguration\n\tValues"
$formatted_sql = preg_replace('/\s(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY)\s/is', "\n\t$1 ", ' ' . $sql);
$formatted_sql = $this->highlightString($formatted_sql);
if ( defined('DBG_SQL_EXPLAIN') && DBG_SQL_EXPLAIN ) {
if ( substr($sql, 0, 6) == 'SELECT' ) {
$formatted_sql .= '<br/>' . '<strong>Explain</strong>:<br /><br />';
$explain_result = $this->Application->Conn->Query('EXPLAIN ' . $sql, null, true);
$explain_table = '';
foreach ($explain_result as $explain_row) {
if ( !$explain_table ) {
// first row -> draw header
$explain_table .= '<tr class="explain_header"><td>' . implode('</td><td>', array_keys($explain_row)) . '</td></tr>';
}
$explain_table .= '<tr><td>' . implode('</td><td>', $explain_row) . '</td></tr>';
}
$formatted_sql .= '<table class="dbg_explain_table">' . $explain_table . '</table>';
}
}
return $formatted_sql;
}
/**
* Highlights given string using "highlight_string" method
*
* @param string $string
* @return string
* @access public
*/
public function highlightString($string)
{
if ( !(defined('DBG_USE_HIGHLIGHT') && DBG_USE_HIGHLIGHT) || $this->_compileError ) {
return nl2br($string);
}
$string = str_replace(Array ('\\', '/'), Array ('_no_match_string_', '_n_m_s_'), $string);
$this->_compileError = true; // next line is possible cause of compile error
$string = highlight_string('<?php ' . $string . ' ?>', true);
$this->_compileError = false;
$string = str_replace(Array ('_no_match_string_', '_n_m_s_'), Array ('\\', '/'), $string);
if ( strlen($string) >= 65536 ) {
// preg_replace will fail, when string is longer, then 65KB
return str_replace(Array ('&lt;?php&nbsp;', '?&gt;'), '', $string);
}
return preg_replace('/&lt;\?(.*)php&nbsp;(.*)\?&gt;/Us', '\\2', $string);
}
/**
* Determine by php type of browser used to show debugger
*
* @return bool
* @access private
*/
private function isGecko()
{
// we need isset because we may run scripts from shell with no user_agent at all
return isset($_SERVER['HTTP_USER_AGENT']) && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'firefox') !== false;
}
/**
* Returns link for editing php file (from error) in external editor
*
* @param string $file filename with path from root folder
* @param int $lineno line number in file where error is found
* @param string $title text to show on file edit link
* @return string
* @access public
*/
public function getFileLink($file, $lineno = 1, $title = '')
{
if ( !$title ) {
$title = str_replace('/', '\\', $this->getLocalFile($file));
}
if ( $this->isGecko() ) {
return '<a href="file://' . $this->getLocalFile($file) . '">' . $title . '</a>';
}
else {
return '<a href="javascript:$Debugger.editFile(\'' . $this->getLocalFile($file) . '\', ' . $lineno . ');" title="' . $file . '">' . $title . '</a>';
}
}
/**
* Converts filepath on server to filepath in mapped DocumentRoot on developer pc
*
* @param string $remoteFile
* @return string
* @access private
*/
private function getLocalFile($remoteFile)
{
return preg_replace('/^' . preg_quote(DOC_ROOT, '/') . '/', DBG_LOCAL_BASE_PATH, $remoteFile, 1);
}
/**
* Appends call trace till this method call
*
* @param int $levels_to_shift
* @return void
* @access public
*/
public function appendTrace($levels_to_shift = 1)
{
$levels_shifted = 0;
$trace = debug_backtrace();
while ( $levels_shifted < $levels_to_shift ) {
array_shift($trace);
$levels_shifted++;
}
$this->Data[] = Array ('trace' => $trace, 'debug_type' => 'trace');
}
/**
* Appends call trace till this method call
*
* @param Exception $exception
* @return void
* @access private
*/
private function appendExceptionTrace(&$exception)
{
$trace = $exception->getTrace();
$this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace');
}
/**
* Adds memory usage statistics
*
* @param string $msg
* @param int $used
* @return void
* @access public
*/
public function appendMemoryUsage($msg, $used = null)
{
if ( !isset($used) ) {
$used = round(memory_get_usage() / 1024);
}
$this->appendHTML('<b>Memory usage</b> ' . $msg . ' ' . $used . 'Kb');
}
/**
* Appends HTML code without transformations
*
* @param string $html
* @return void
* @access public
*/
public function appendHTML($html)
{
$this->Data[] = Array ('html' => $html, 'debug_type' => 'html');
}
/**
* Returns instance of FirePHP class
*
* @return FirePHP
* @link http://www.firephp.org/HQ/Use.htm
*/
function firePHP()
{
require_once('FirePHPCore/FirePHP.class.php');
return FirePHP::getInstance(true);
}
/**
* Change debugger info that was already generated before.
* Returns true if html was set.
*
* @param int $index
* @param string $html
* @param string $type = {'append','prepend','replace'}
* @return bool
* @access public
*/
public function setHTMLByIndex($index, $html, $type = 'append')
{
if ( !isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html' ) {
return false;
}
switch ( $type ) {
case 'append':
$this->Data[$index]['html'] .= '<br>' . $html;
break;
case 'prepend':
$this->Data[$index]['html'] = $this->Data[$index]['html'] . '<br>' . $html;
break;
case 'replace':
$this->Data[$index]['html'] = $html;
break;
}
return true;
}
/**
* Move $debugLineCount lines of input from debug output
* end to beginning.
*
* @param int $debugLineCount
* @return void
* @access private
*/
private function moveToBegin($debugLineCount)
{
$lines = array_splice($this->Data, count($this->Data) - $debugLineCount, $debugLineCount);
$this->Data = array_merge($lines, $this->Data);
}
/**
* Moves all debugger report lines after $debugLineCount into $new_row position
*
* @param int $new_row
* @param int $debugLineCount
* @return void
* @access private
*/
private function moveAfterRow($new_row, $debugLineCount)
{
$lines = array_splice($this->Data, count($this->Data) - $debugLineCount, $debugLineCount);
$rows_before = array_splice($this->Data, 0, $new_row, $lines);
$this->Data = array_merge($rows_before, $this->Data);
}
/**
* Appends HTTP REQUEST information to debugger report
*
* @return void
* @access private
*/
private function appendRequest()
{
if ( isset($_SERVER['SCRIPT_FILENAME']) ) {
$script = $_SERVER['SCRIPT_FILENAME'];
}
else {
$script = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];
}
$this->appendHTML('ScriptName: <b>' . $this->getFileLink($script, 1, basename($script)) . '</b> (<b>' . dirname($script) . '</b>)');
if ( $this->_isAjax ) {
$this->appendHTML('RequestURI: ' . $_SERVER['REQUEST_URI'] . ' (QS Length:' . strlen($_SERVER['QUERY_STRING']) . ')');
}
$tools_html = ' <table style="width: ' . $this->getWindowWidth() . 'px;">
<tr>
<td>' . $this->_getDomViewerHTML() . '</td>
<td>' . $this->_getToolsHTML() . '</td>
</tr>
</table>';
$this->appendHTML($tools_html);
ob_start();
?>
<table border="0" cellspacing="0" cellpadding="0" class="dbg_flat_table" style="width: <?php echo $this->getWindowWidth(); ?>px;">
<thead style="font-weight: bold;">
<td width="20">Src</td><td>Name</td><td>Value</td>
</thead>
<?php
foreach ($_REQUEST as $key => $value) {
if ( !is_array($value) && trim($value) == '' ) {
$value = '<b class="debug_error">no value</b>';
}
else {
$value = htmlspecialchars($this->print_r($value, true));
}
$in_cookie = isset($_COOKIE[$key]);
$src = isset($_GET[$key]) && !$in_cookie ? 'GE' : (isset($_POST[$key]) && !$in_cookie ? 'PO' : ($in_cookie ? 'CO' : '?'));
echo '<tr><td>' . $src . '</td><td>' . $key . '</td><td>' . $value . '</td></tr>';
}
?>
</table>
<?php
$this->appendHTML(ob_get_contents());
ob_end_clean();
}
/**
* Appends php session content to debugger output
*
* @return void
* @access private
*/
private function appendSession()
{
if ( isset($_SESSION) && $_SESSION ) {
$this->appendHTML('PHP Session: [<b>' . ini_get('session.name') . '</b>]');
$this->dumpVars($_SESSION);
$this->moveToBegin(2);
}
}
/**
* Starts profiling of a given $key
*
* @param string $key
* @param string $description
* @param int $timeStamp
* @return void
* @access public
*/
public function profileStart($key, $description = null, $timeStamp = null)
{
if ( !isset($timeStamp) ) {
$timeStamp = microtime(true);
}
$this->ProfilerData[$key] = Array ('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data));
if ( isset($description) ) {
$this->ProfilerData[$key]['description'] = $description;
}
if ( substr($key, 0, 4) == 'sql_' ) {
// append place from what was called
$trace_results = debug_backtrace();
$trace_count = count($trace_results);
$i = 0;
while ( $i < $trace_count ) {
if ( !isset($trace_results[$i]['file']) ) {
$i++;
continue;
}
$trace_file = basename($trace_results[$i]['file']);
if ( $trace_file != 'db_connection.php' && $trace_file != 'db_load_balancer.php' && $trace_file != 'adodb.inc.php' ) {
break;
}
$i++;
}
$this->ProfilerData[$key]['file'] = $trace_results[$i]['file'];
$this->ProfilerData[$key]['line'] = $trace_results[$i]['line'];
if ( array_key_exists('object', $trace_results[$i + 1]) && isset($trace_results[$i + 1]['object']->Prefix) ) {
$object =& $trace_results[$i + 1]['object'];
/* @var $object kBase */
$prefix_special = rtrim($object->Prefix . '.' . $object->Special, '.');
$this->ProfilerData[$key]['prefix_special'] = $prefix_special;
}
unset($trace_results);
}
$this->Data[] = Array ('profile_key' => $key, 'debug_type' => 'profiler');
}
/**
* Ends profiling for a given $key
*
* @param string $key
* @param string $description
* @param int $timeStamp
* @return void
* @access public
*/
public function profileFinish($key, $description = null, $timeStamp = null)
{
if ( !isset($timeStamp) ) {
$timeStamp = microtime(true);
}
$this->ProfilerData[$key]['ends'] = $timeStamp;
if ( isset($description) ) {
$this->ProfilerData[$key]['description'] = $description;
}
if ( substr($key, 0, 4) == 'sql_' ) {
$func_arguments = func_get_args();
$rows_affected = $func_arguments[3];
$additional = Array ();
if ( $rows_affected > 0 ) {
$additional[] = Array ('name' => 'Affected Rows', 'value' => $rows_affected);
if ( isset($func_arguments[4]) ) {
if ( strlen($func_arguments[4]) > 200 ) {
$func_arguments[4] = substr($func_arguments[4], 0, 50) . ' ...';
}
$additional[] = Array ('name' => 'Result', 'value' => $func_arguments[4]);
}
}
$additional[] = Array ('name' => 'Query Number', 'value' => $func_arguments[5]);
if ( $func_arguments[6] ) {
$this->profilerAddTotal('cachable_queries', $key);
$this->ProfilerData[$key]['subtitle'] = 'cachable';
}
if ( (string)$func_arguments[7] !== '' ) {
$additional[] = Array ('name' => 'Server #', 'value' => $func_arguments[7]);
}
if ( array_key_exists('prefix_special', $this->ProfilerData[$key]) ) {
$additional[] = Array ('name' => 'PrefixSpecial', 'value' => $this->ProfilerData[$key]['prefix_special']);
}
$this->ProfilerData[$key]['additional'] =& $additional;
}
}
/**
* Collects total execution time from profiler record
*
* @param string $total_key
* @param string $key
* @param int $value
* @return void
* @access public
*/
public function profilerAddTotal($total_key, $key = null, $value = null)
{
if ( !isset($this->ProfilerTotals[$total_key]) ) {
$this->ProfilerTotals[$total_key] = 0;
$this->ProfilerTotalCount[$total_key] = 0;
}
if ( !isset($value) ) {
$value = $this->ProfilerData[$key]['ends'] - $this->ProfilerData[$key]['begins'];
}
if ( isset($key) ) {
$this->ProfilerData[$key]['totalsKey'] = $total_key;
$this->ProfilerData[$key]['totalsBefore'] = $this->ProfilerTotals[$total_key];
}
$this->ProfilerTotals[$total_key] += $value;
$this->ProfilerTotalCount[$total_key]++;
}
/**
* Traces relative code execution speed between this method calls
*
* @param string $message
* @return void
* @access public
*/
public function appendTimestamp($message)
{
global $start;
$time = microtime(true);
$from_last = $time - $this->LastMoment;
$from_start = $time - $start;
$this->appendHTML(sprintf("<strong>%s</strong> %.5f from last %.5f from start", $message, $from_last, $from_start));
$this->LastMoment = $time;
}
/**
* Returns unique ID for each method call
*
* @return int
* @access public
*/
public function generateID()
{
list($usec, $sec) = explode(' ', microtime());
$id_part_1 = substr($usec, 4, 4);
$id_part_2 = mt_rand(1, 9);
$id_part_3 = substr($sec, 6, 4);
$digit_one = substr($id_part_1, 0, 1);
if ( $digit_one == 0 ) {
$digit_one = mt_rand(1, 9);
$id_part_1 = preg_replace('/^0/', '', $id_part_1);
$id_part_1 = $digit_one . $id_part_1;
}
return $id_part_1 . $id_part_2 . $id_part_3;
}
/**
* Returns error name based on it's code
*
* @param int $error_code
* @return string
* @access private
*/
private function getErrorNameByCode($error_code)
{
$error_map = Array (
'Fatal Error' => Array (E_USER_ERROR),
'Warning' => Array (E_WARNING, E_USER_WARNING),
'Notice' => Array (E_NOTICE, E_USER_NOTICE),
);
if ( defined('E_STRICT') ) {
// since PHP 5
$error_map['PHP5 Strict'] = Array (E_STRICT);
}
if ( defined('E_RECOVERABLE_ERROR') ) {
// since PHP 5.2
$error_map['Fatal Error (recoverable)'] = Array (E_RECOVERABLE_ERROR);
}
if ( defined('E_DEPRECATED') ) {
// since PHP 5.3
$error_map['PHP5 Depricated'] = Array (E_DEPRECATED, E_USER_DEPRECATED);
}
foreach ($error_map as $error_name => $error_codes) {
if ( in_array($error_code, $error_codes) ) {
return $error_name;
}
}
return '';
}
/**
* Returns profile total key (check against missing key too)
*
* @param string $key
* @return int
* @access private
*/
private function getProfilerTotal($key)
{
if ( isset($this->ProfilerTotalCount[$key]) ) {
return (int)$this->ProfilerTotalCount[$key];
}
return 0;
}
/**
* Counts how much calls were made to a place, where this method is called (basic version of profiler)
*
* @param string $title
* @param int $level
* @return void
* @access public
*/
public function ProfilePoint($title, $level = 1)
{
$trace_results = debug_backtrace();
$level = min($level, count($trace_results) - 1);
do {
$point = $trace_results[$level];
$location = $point['file'] . ':' . $point['line'];
$level++;
$has_more = isset($trace_results[$level]);
} while ( $has_more && $point['function'] == $trace_results[$level]['function'] );
if ( !isset($this->ProfilePoints[$title]) ) {
$this->ProfilePoints[$title] = Array ();
}
if ( !isset($this->ProfilePoints[$title][$location]) ) {
$this->ProfilePoints[$title][$location] = 0;
}
$this->ProfilePoints[$title][$location]++;
}
/**
* Generates report
*
* @param bool $returnResult
* @param bool $clean_output_buffer
*
* @return string
* @access public
*/
public function printReport($returnResult = false, $clean_output_buffer = true)
{
if ( $this->reportDone ) {
// don't print same report twice (in case if shutdown function used + compression + fatal error)
return '';
}
$this->profileFinish('script_runtime');
$this->breakOutofBuffering(!$returnResult);
$debugger_start = memory_get_usage();
if ( defined('SPACER_URL') ) {
$this->dummyImage = SPACER_URL;
}
$this->InitReport(); // set parameters required by AJAX
// defined here, because user can define this constant while script is running, not event before debugger is started
DebuggerUtil::safeDefine('DBG_RAISE_ON_WARNINGS', 0);
DebuggerUtil::safeDefine('DBG_TOOLBAR_BUTTONS', 1);
$this->appendSession(); // show php session if any
// ensure, that 1st line of debug output always is this one:
$top_line = '<table cellspacing="0" cellpadding="0" style="width: ' . $this->getWindowWidth() . 'px; margin: 0px;"><tr><td align="left" width="50%">[<a href="javascript:window.location.reload();">Reload Frame</a>] [<a href="javascript:$Debugger.Toggle(27);">Hide Debugger</a>] [<a href="javascript:$Debugger.Clear();">Clear Debugger</a>]</td><td align="right" width="50%">[Current Time: <b>' . date('H:i:s') . '</b>] [File Size: <b>#DBG_FILESIZE#</b>]</td></tr></table>';
$this->appendHTML($top_line);
$this->moveToBegin(1);
if ( count($this->ProfilePoints) > 0 ) {
foreach ($this->ProfilePoints as $point => $locations) {
arsort($this->ProfilePoints[$point]);
}
$this->appendHTML($this->highlightString($this->print_r($this->ProfilePoints, true)));
}
if ( DebuggerUtil::constOn('DBG_SQL_PROFILE') && isset($this->ProfilerTotals['sql']) ) {
// sql query profiling was enabled -> show totals
if ( array_key_exists('cachable_queries', $this->ProfilerTotalCount) ) {
$append = ' <strong>Cachable queries</strong>: ' . $this->ProfilerTotalCount['cachable_queries'];
}
else {
$append = '';
}
$this->appendHTML('<b>SQL Total time:</b> ' . $this->ProfilerTotals['sql'] . ' <b>Number of queries</b>: ' . $this->ProfilerTotalCount['sql'] . $append);
}
if ( DebuggerUtil::constOn('DBG_PROFILE_INCLUDES') && isset($this->ProfilerTotals['includes']) ) {
// included file profiling was enabled -> show totals
$this->appendHTML('<b>Included Files Total time:</b> ' . $this->ProfilerTotals['includes'] . ' Number of includes: ' . $this->ProfilerTotalCount['includes']);
}
if ( DebuggerUtil::constOn('DBG_PROFILE_MEMORY') ) {
// detailed memory usage reporting by objects was enabled -> show totals
$this->appendHTML('<b>Memory used by Objects:</b> ' . round($this->ProfilerTotals['objects'] / 1024, 2) . 'Kb');
}
if ( DebuggerUtil::constOn('DBG_INCLUDED_FILES') ) {
$files = get_included_files();
$this->appendHTML('<strong>Included files:</strong>');
foreach ($files as $file) {
$this->appendHTML($this->getFileLink($this->getLocalFile($file)) . ' (' . round(filesize($file) / 1024, 2) . 'Kb)');
}
}
if ( DebuggerUtil::constOn('DBG_PROFILE_INCLUDES') ) {
$totals = $totals_configs = Array ('mem' => 0, 'time' => 0);
$this->appendHTML('<b>Included files statistics:</b>' . (DebuggerUtil::constOn('DBG_SORT_INCLUDES_MEM') ? ' (sorted by memory usage)' : ''));
if ( is_array($this->IncludesData['mem']) ) {
if ( DebuggerUtil::constOn('DBG_SORT_INCLUDES_MEM') ) {
array_multisort($this->IncludesData['mem'], SORT_DESC, $this->IncludesData['file'], $this->IncludesData['time'], $this->IncludesData['level']);
}
foreach ($this->IncludesData['file'] as $key => $file_name) {
$this->appendHTML(str_repeat('&nbsp;->&nbsp;', ($this->IncludesData['level'][$key] >= 0 ? $this->IncludesData['level'][$key] : 0)) . $file_name . ' Mem: ' . sprintf("%.4f Kb", $this->IncludesData['mem'][$key] / 1024) . ' Time: ' . sprintf("%.4f", $this->IncludesData['time'][$key]));
if ( $this->IncludesData['level'][$key] == 0 ) {
$totals['mem'] += $this->IncludesData['mem'][$key];
$totals['time'] += $this->IncludesData['time'][$key];
}
elseif ( $this->IncludesData['level'][$key] == -1 ) {
$totals_configs['mem'] += $this->IncludesData['mem'][$key];
$totals_configs['time'] += $this->IncludesData['time'][$key];
}
}
$this->appendHTML('<b>Sub-Total classes:</b> ' . ' Mem: ' . sprintf("%.4f Kb", $totals['mem'] / 1024) . ' Time: ' . sprintf("%.4f", $totals['time']));
$this->appendHTML('<b>Sub-Total configs:</b> ' . ' Mem: ' . sprintf("%.4f Kb", $totals_configs['mem'] / 1024) . ' Time: ' . sprintf("%.4f", $totals_configs['time']));
$this->appendHTML('<span class="error"><b>Grand Total:</b></span> ' . ' Mem: ' . sprintf("%.4f Kb", ($totals['mem'] + $totals_configs['mem']) / 1024) . ' Time: ' . sprintf("%.4f", $totals['time'] + $totals_configs['time']));
}
}
$skip_reporting = DebuggerUtil::constOn('DBG_SKIP_REPORTING') || DebuggerUtil::constOn('DBG_ZEND_PRESENT');
if ( ($this->_isAjax && !DebuggerUtil::constOn('DBG_SKIP_AJAX')) || !$skip_reporting ) {
$debug_file = $this->tempFolder . '/debug_' . $this->rowSeparator . '.txt';
if ( file_exists($debug_file) ) {
unlink($debug_file);
}
$i = 0;
$fp = fopen($debug_file, 'a');
$lineCount = count($this->Data);
while ( $i < $lineCount ) {
fwrite($fp, $this->prepareHTML($i) . $this->rowSeparator);
$i++;
}
fclose($fp);
}
if ( $skip_reporting ) {
// let debugger write report and then don't output anything
$this->reportDone = true;
return '';
}
$application =& kApplication::Instance();
$dbg_path = str_replace(FULL_PATH, '', $this->tempFolder);
$debugger_params = Array (
'RowSeparator' => $this->rowSeparator,
'ErrorsCount' => (int)$this->getProfilerTotal('error_handling'),
'IsFatalError' => $this->IsFatalError,
'SQLCount' => (int)$this->getProfilerTotal('sql'),
'SQLTime' => isset($this->ProfilerTotals['sql']) ? sprintf('%.5f', $this->ProfilerTotals['sql']) : 0,
'ScriptTime' => sprintf('%.5f', $this->ProfilerData['script_runtime']['ends'] - $this->ProfilerData['script_runtime']['begins']),
'ScriptMemory' => DebuggerUtil::formatSize($this->getMemoryUsed($debugger_start)),
'Shortcut' => DBG_SHORTCUT,
);
ob_start();
// the <script .. /script> and hidden div helps browser to break out of script tag or attribute esacped
// with " or ' in case fatal error (or user-error) occurs inside it in compiled template,
// otherwise it has no effect
?>
<div style="display: none" x='nothing'><script></script></div><html><body></body></html>
- <link rel="stylesheet" rev="stylesheet" href="<?php echo $this->baseURL; ?>/debugger.css" type="text/css" media="screen" />
+ <link rel="stylesheet" rev="stylesheet" href="<?php echo $this->baseURL; ?>/debugger.css?v2" type="text/css" media="screen" />
<script type="text/javascript" src="<?php echo $this->baseURL; ?>/debugger.js?v4"></script>
<script type="text/javascript">
var $Debugger = new Debugger(<?php echo json_encode($debugger_params); ?>);
$Debugger.createEnvironment(<?php echo DBG_WINDOW_WIDTH; ?>, <?php echo $this->getWindowWidth(); ?>);
$Debugger.DOMViewerURL = '<?php echo constant('DBG_DOMVIEWER'); ?>';
$Debugger.EditorPath = '<?php echo defined('DBG_EDITOR') ? addslashes(DBG_EDITOR) : '' ?>';
$Debugger.DebugURL = '<?php echo $this->baseURL.'/debugger_responce.php?sid='.$this->rowSeparator.'&path='.urlencode($dbg_path); ?>';
$Debugger.EventURL = '<?php echo /*is_object($application->Factory) &&*/ $application->InitDone ? $application->HREF('dummy', '', Array ('pass' => 'm', '__NO_REWRITE__' => 1)) : ''; ?>';
$Debugger.BasePath = '<?php echo $this->basePath; ?>';
<?php
$is_install = defined('IS_INSTALL') && IS_INSTALL;
if ( $this->IsFatalError || (!$is_install && DBG_RAISE_ON_WARNINGS && $this->WarningCount) ) {
echo '$Debugger.Toggle();';
}
if ( DBG_TOOLBAR_BUTTONS ) {
echo '$Debugger.AddToolbar("$Debugger");';
}
?>
window.focus();
</script>
<?php
if ( $returnResult ) {
$ret = ob_get_contents();
if ( $clean_output_buffer ) {
ob_end_clean();
}
$ret .= $this->getShortReport($this->getMemoryUsed($debugger_start));
$this->reportDone = true;
return $ret;
}
else {
if ( !DebuggerUtil::constOn('DBG_HIDE_FULL_REPORT') ) {
$this->breakOutofBuffering();
}
elseif ( $clean_output_buffer ) {
ob_clean();
}
echo $this->getShortReport($this->getMemoryUsed($debugger_start));
$this->reportDone = true;
}
return '';
}
function getMemoryUsed($debugger_start)
{
if ( !isset($this->ProfilerTotals['error_handling']) ) {
$memory_used = $debugger_start;
$this->ProfilerTotalCount['error_handling'] = 0;
}
else {
$memory_used = $debugger_start - $this->ProfilerTotals['error_handling'];
}
return $memory_used;
}
/**
* Format's memory usage report by debugger
*
* @param int $memory_used
* @return string
* @access private
*/
private function getShortReport($memory_used)
{
if ( DebuggerUtil::constOn('DBG_TOOLBAR_BUTTONS') ) {
// evenrything is in toolbar - don't duplicate
return '';
}
else {
// toolbar not visible, then show sql & error count too
$info = Array (
'Script Runtime' => 'PROFILE:script_runtime',
'SQL\'s Runtime' => 'PROFILE_T:sql',
'-' => 'SEP:-',
'Notice / Warning' => 'PROFILE_TC:error_handling',
'SQLs Count' => 'PROFILE_TC:sql',
);
}
$ret = ''; // '<tr><td>Application:</td><td><b>' . DebuggerUtil::formatSize($memory_used) . '</b> (' . $memory_used . ')</td></tr>';
foreach ($info as $title => $value_key) {
list ($record_type, $record_data) = explode(':', $value_key, 2);
switch ( $record_type ) {
case 'PROFILE': // profiler totals value
$Data =& $this->ProfilerData[$record_data];
$profile_time = ($Data['ends'] - $Data['begins']); // in seconds
$ret .= '<tr><td>' . $title . ':</td><td><b>' . sprintf('%.5f', $profile_time) . ' s</b></td></tr>';
break;
case 'PROFILE_TC': // profile totals record count
$record_cell = '<td>';
if ( $record_data == 'error_handling' && $this->ProfilerTotalCount[$record_data] > 0 ) {
$record_cell = '<td class="debug_error">';
}
$ret .= '<tr>' . $record_cell . $title . ':</td>' . $record_cell . '<b>' . $this->ProfilerTotalCount[$record_data] . '</b></td></tr>';
break;
case 'PROFILE_T': // profile total
$record_cell = '<td>';
$total = array_key_exists($record_data, $this->ProfilerTotals) ? $this->ProfilerTotals[$record_data] : 0;
$ret .= '<tr>' . $record_cell . $title . ':</td>' . $record_cell . '<b>' . sprintf('%.5f', $total) . ' s</b></td></tr>';
break;
case 'SEP':
$ret .= '<tr><td colspan="2" style="height: 1px; background-color: #000000; padding: 0px;"><img src="' . $this->dummyImage . '" height="1" alt=""/></td></tr>';
break;
}
}
return '<br /><table class="dbg_stats_table"><tr><td style="border-color: #FFFFFF;"><table class="dbg_stats_table" align="left">' . $ret . '</table></td></tr></table>';
}
/**
* User-defined error handler
*
* @throws Exception
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param array $errcontext
* @return bool
* @access public
*/
public function saveError($errno, $errstr, $errfile = null, $errline = null, $errcontext = Array ())
{
$this->ProfilerData['error_handling']['begins'] = memory_get_usage();
$errorType = $this->getErrorNameByCode($errno);
if (!$errorType) {
throw new Exception('Unknown error type [' . $errno . ']');
return false;
}
elseif ( substr($errorType, 0, 5) == 'Fatal' ) {
$this->IsFatalError = true;
$this->appendTrace(4);
}
if ( DebuggerUtil::constOn('DBG_IGNORE_STRICT_ERRORS') && defined('E_STRICT') && ($errno == E_STRICT) ) {
return false;
}
$this->expandError($errstr, $errfile, $errline);
$this->Data[] = Array (
'no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline,
'context' => $errcontext, 'debug_type' => 'error'
);
$this->ProfilerData['error_handling']['ends'] = memory_get_usage();
$this->profilerAddTotal('error_handling', 'error_handling');
if ($errorType == 'Warning') {
$this->WarningCount++;
}
if ( $this->IsFatalError ) {
// append debugger report to data in buffer & clean buffer afterwards
die( $this->breakOutofBuffering(false) . $this->printReport(true) );
}
return true;
}
/**
* Adds exception details into debugger but don't cause fatal error
*
* @param Exception $exception
* @return void
* @access public
*/
public function appendException($exception)
{
$this->ProfilerData['error_handling']['begins'] = memory_get_usage();
$this->appendExceptionTrace($exception);
$errno = $exception->getCode();
$errstr = $exception->getMessage();
$errfile = $exception->getFile();
$errline = $exception->getLine();
$this->expandError($errstr, $errfile, $errline);
$this->Data[] = Array (
'no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline,
'exception_class' => get_class($exception), 'debug_type' => 'exception'
);
$this->ProfilerData['error_handling']['ends'] = memory_get_usage();
$this->profilerAddTotal('error_handling', 'error_handling');
}
/**
* User-defined exception handler
*
* @param Exception $exception
* @return void
* @access public
*/
public function saveException($exception)
{
$this->appendException($exception);
$this->IsFatalError = true;
// append debugger report to data in buffer & clean buffer afterwards
die( $this->breakOutofBuffering(false) . $this->printReport(true) );
}
/**
* Transforms short error messages into long ones
*
* @param string $errstr
* @param string $errfile
* @param int $errline
* @return void
* @access private
*/
private function expandError(&$errstr, &$errfile, &$errline)
{
if ( preg_match('/(.*)#([\d]+)$/', $errstr, $rets) ) {
// replace short message with long one (due triger_error limitations on message size)
$long_id = $rets[2];
$errstr = $this->longErrors[$long_id];
unset($this->longErrors[$long_id]);
}
if ( strpos($errfile, 'eval()\'d code') !== false ) {
$errstr = '[<b>EVAL</b>, line <b>' . $errline . '</b>]: ' . $errstr;
$tmpStr = $errfile;
$pos = strpos($tmpStr, '(');
$errfile = substr($tmpStr, 0, $pos);
$pos++;
$errline = substr($tmpStr, $pos, strpos($tmpStr, ')', $pos) - $pos);
}
}
/**
* Break buffering in case if fatal error is happened in the middle
*
* @param bool $flush
* @return string
* @access private
*/
private function breakOutofBuffering($flush = true)
{
$buffer_content = Array ();
while ( ob_get_level() ) {
$buffer_content[] = ob_get_clean();
}
$ret = implode('', array_reverse($buffer_content));
if ( $flush ) {
echo $ret;
flush();
}
return $ret;
}
/**
* Saves given message to "vb_debug.txt" file in DocumentRoot
*
* @param string $msg
* @return void
* @access public
*/
public function saveToFile($msg)
{
$fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/vb_debug.txt', 'a');
fwrite($fp, $msg . "\n");
fclose($fp);
}
/**
* Prints given constant values in a table
*
* @param mixed $constants
* @return void
* @access public
*/
public function printConstants($constants)
{
if ( !is_array($constants) ) {
$constants = explode(',', $constants);
}
$constant_tpl = '<tr><td>%s</td><td><b>%s</b></td></tr>';
$ret = '<table class="dbg_flat_table" style="width: ' . $this->getWindowWidth() . 'px;">';
foreach ($constants as $constant_name) {
$ret .= sprintf($constant_tpl, $constant_name, constant($constant_name));
}
$ret .= '</table>';
$this->appendHTML($ret);
}
/**
* Attaches debugger to Application
*
* @return void
* @access public
*/
public function AttachToApplication()
{
if ( !DebuggerUtil::constOn('DBG_HANDLE_ERRORS') ) {
return;
}
if ( class_exists('kApplication') ) {
// replace application error/exception handler with own
restore_error_handler();
restore_exception_handler();
$this->Application =& kApplication::Instance();
$this->Application->Debugger =& $this;
$this->Application->errorHandlers[] = Array (&$this, 'saveError');
$this->Application->exceptionHandlers[] = Array (&$this, 'saveException');
}
else {
set_error_handler( Array (&$this, 'saveError') );
set_exception_handler( Array (&$this, 'saveException') );
}
}
/**
* Returns HTML for tools section
*
* @return string
* @access private
*/
private function _getToolsHTML()
{
$html = '<table>
<tr>
<td>System Tools:</td>
<td>
<select id="reset_cache" style="border: 1px solid #000000;">
<option value=""></option>
<option value="events[adm][OnResetModRwCache]">Reset mod_rewrite Cache</option>
<option value="events[adm][OnResetCMSMenuCache]">Reset SMS Menu Cache</option>
<option value="events[adm][OnResetSections]">Reset Sections Cache</option>
<option value="events[adm][OnResetConfigsCache]">Reset Configs Cache</option>
<option value="events[adm][OnRebuildThemes]">Re-build Themes Files</option>
<option value="events[lang][OnReflectMultiLingualFields]">Re-build Multilanguage Fields</option>
<option value="events[adm][OnDeleteCompiledTemplates]">Delete Compiled Templates</option>
</select>
</td>
<td>
<input type="button" class="button" onclick="$Debugger.resetCache(\'reset_cache\');" value="Go"/>
</td>
</tr>
</table>';
return $html;
}
/**
* Returns HTML for dom viewer section
*
* @return string
* @access private
*/
private function _getDomViewerHTML()
{
$html = '<table>
<tr>
<td>
<a href="http://www.brainjar.com/dhtml/domviewer/" target="_blank">DomViewer</a>:
</td>
<td>
<input id="dbg_domviewer" type="text" value="window" style="border: 1px solid #000000;"/>
</td>
<td>
<button class="button" onclick="return $Debugger.OpenDOMViewer();">Show</button>
</td>
</tr>
</table>';
return $html;
}
}
if ( !function_exists('memory_get_usage') ) {
// PHP 4.x and compiled without --enable-memory-limit option
function memory_get_usage()
{
return -1;
}
}
if ( !DebuggerUtil::constOn('DBG_ZEND_PRESENT') ) {
$debugger = new Debugger();
}
if ( DebuggerUtil::constOn('DBG_USE_SHUTDOWN_FUNC') ) {
register_shutdown_function(Array (&$debugger, 'printReport'));
}
}
\ No newline at end of file
Index: branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.css
===================================================================
--- branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.css (revision 15529)
+++ branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.css (revision 15530)
@@ -1,185 +1,185 @@
/* ----------------------------------------------------------------------------------------------------------------*/
/* ---------->>> global settings needed for thickbox <<<-----------------------------------------------------------*/
/* ----------------------------------------------------------------------------------------------------------------*/
/* *{padding: 0; margin: 0;} */
/* ----------------------------------------------------------------------------------------------------------------*/
/* ---------->>> thickbox specific link and font settings <<<------------------------------------------------------*/
/* ----------------------------------------------------------------------------------------------------------------*/
#TB_window, .TB_window {
font: 12px Arial, Helvetica, sans-serif;
color: #333333;
}
#TB_secondLine {
font: 10px Arial, Helvetica, sans-serif;
color:#666666;
}
#TB_window a:link, .TB_window a:link {color: #666666;}
#TB_window a:visited, .TB_window a:visited {color: #666666;}
#TB_window a:hover, .TB_window a:hover {color: #000;}
#TB_window a:active, .TB_window a:active {color: #666666;}
#TB_window a:focus, .TB_window a:focus {color: #666666;}
/* ----------------------------------------------------------------------------------------------------------------*/
/* ---------->>> thickbox settings <<<-----------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------------------------------------------*/
#TB_overlay {
position: fixed;
- z-index: 100;
+ z-index: 1000100;
top: 0px;
left: 0px;
height:100%;
width:100%;
}
.TB_overlayMacFFBGHack {background: url(macFFBgHack.png) repeat;}
.TB_overlayBG {
background-color:#000;
filter:alpha(opacity=75);
-moz-opacity: 0.75;
opacity: 0.75;
}
* html #TB_overlay { /* ie6 hack */
position: absolute;
height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
}
#TB_window, .TB_window {
background: #ffffff;
- z-index: 102;
+ z-index: 1000102;
color:#000000;
display:none;
border: 4px solid #525252;
text-align:left;
position: absolute;
top: 10px;
left: 10px;
/*position: fixed;
top:50%;
left:50%;*/
}
/** html #TB_window, * html .TB_window { /* ie6 hack */
position: absolute;
margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px');
}*/
#TB_window img#TB_Image, .TB_window img#TB_Image {
display:block;
margin: 15px 0 0 15px;
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
border-top: 1px solid #666;
border-left: 1px solid #666;
}
#TB_caption, .TB_caption {
height:25px;
padding:7px 30px 10px 25px;
float:left;
}
#TB_closeWindow, .TB_closeWindow {
height:25px;
padding:11px 25px 10px 0;
float:right;
}
#TB_closeAjaxWindow, .TB_closeAjaxWindow {
padding: 6px 10px 6px 0px;
/*margin-bottom: 1px;*/
text-align: right;
float: right;
}
#TB_ajaxWindowTitle, .TB_ajaxWindowTitle {
float: left;
padding: 6px 0px 6px 10px;
/*margin-bottom: 1px;*/
font-weight: bold;
}
#TB_title, .TB_title {
background-color:#e8e8e8;
height:27px;
}
#TB_ajaxContent, .TB_ajaxContent {
clear:both;
padding:2px 15px 15px 15px;
overflow:auto;
text-align:left;
line-height:1.4em;
}
#TB_ajaxContent.TB_modal, .TB_ajaxContent.TB_modal {
padding:15px;
}
#TB_ajaxContent p, .TB_ajaxContent p {
padding:5px 0px 5px 0px;
}
#TB_load {
position: fixed;
display:none;
height:13px;
width:208px;
- z-index: 103;
+ z-index: 1000103;
top: 50%;
left: 50%;
margin: -6px 0 0 -104px; /* -height/2 0 0 -width/2 */
}
* html #TB_load { /* ie6 hack */
position: absolute;
margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px');
}
#TB_HideSelect {
- z-index: 99;
+ z-index: 1000099;
position:fixed;
top: 0;
left: 0;
background-color:#fff;
border:none;
filter:alpha(opacity=0);
-moz-opacity: 0;
opacity: 0;
height:100%;
width:100%;
}
* html #TB_HideSelect { /* ie6 hack */
position: absolute;
height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
}
#TB_iframeContent, .TB_iframeContent {
clear:both;
border:none;
margin-bottom:-1px;
/*margin-top:1px;*/
_margin-bottom:1px;
}
/* jQuery UI CSS */
/* .ui-resizable { position: relative;} */
-.ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block;}
+.ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 1099999; display: block;}
.ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; }
.ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0px; }
.ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0px; }
.ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0px; height: 100%; }
.ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0px; height: 100%; }
.ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; }
.ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; }
.ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; }
.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}
.ui-draggable .TB_title { cursor: move; }
\ No newline at end of file
Index: branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.js
===================================================================
--- branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.js (revision 15529)
+++ branches/5.2.x/core/admin_templates/js/jquery/thickbox/thickbox.js (revision 15530)
@@ -1,759 +1,759 @@
/*
* Thickbox 3.1 - One Box To Rule Them All.
* By Cody Lindley (http://www.codylindley.com)
* Copyright (c) 2007 cody lindley
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
// on page load call TB.init
$(document).ready(
function() {
// pass where to apply thickbox
TB.init('a.thickbox, area.thickbox, input.thickbox');
// preload image
TB.imgLoader = new Image();
TB.imgLoader.src = TB.pathToImage;
}
);
function TB () {}
TB.pathToImage = 'images/loadingAnimation.gif';
TB.Width = null;
TB.Height = null;
TB.lastParams = {};
TB.windows = new Array();
TB.windowMetaData = new Array ();
TB.useStack = true;
TB.closeHtml = '<img src="img/close_window15.gif" width="15" height="15" alt="close"/><br/>'; // 'close';
TB.lastOverflow = '';
//add thickbox to href & area elements that have a class of .thickbox
TB.init = function (domChunk) {
$(domChunk).click(
function() {
var t = this.title || this.name || null;
var a = this.href || this.alt;
var g = this.rel || false;
TB.show( {caption: t, url: a, imageGroup: g} );
this.blur();
return false;
}
);
}
TB.getId = function ($id, $diff) {
var $length = TB.windows.length;
if ($diff !== undefined) {
$length += $diff;
}
if ($length == 0) {
return $id;
}
return $id + $length;
}
// function called when the user clicks on a thickbox link
TB.show = function (params) {
TB.lastParams = params;
// caption, url, imageGroup, onDataReceived, onAfterShow, onAfterClose, postParams
if (TB.imgLoader === undefined) {
// loader image is set from $(document).ready(...) and when some slow javascript
// makes page busy and user clicks on something, that opens window, then there will
// be an error
return ;
}
try {
if (TB.useStack) {
// increment window counter
if (TB.windows.length == 0) {
getFrame('head').$FrameResizer.fullScreen();
$(window).scroll(TB.position);
TB.lastOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
}
TB.windows[TB.windows.length] = '#' + TB.getId('TB_window', 1);
TB.windowMetaData[TB.windowMetaData.length] = {};
}
if (typeof document.body.style.maxHeight === 'undefined') {
// if IE6 browser only
$('body', 'html').css( {height: '100%', width: '100%'} );
$('html').css('overflow', 'hidden');
if ($('#TB_overlay').length == 0) {
// create overlay
$('body').append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div>");
$('#TB_overlay').click(TB.remove);
}
if (document.getElementById( TB.getId('TB_window') ) === null) {
// iframe to hide select elements in ie6
$('body').append("<div id='" + TB.getId('TB_window') + "' class='TB_window'></div>");
}
} else {
// all other browsers
if ($('#TB_overlay').length == 0) {
// create overlay
$('body').append("<div id='TB_overlay'></div>");
$('#TB_overlay').click(TB.remove);
}
if ( $('#' + TB.getId('TB_window') ).length == 0) {
$('body').append("<div id='" + TB.getId('TB_window') + "' class='TB_window'></div>");
}
}
if (TB.detectMacXFF()) {
$('#TB_overlay').addClass('TB_overlayMacFFBGHack'); // use png overlay so hide flash
} else {
$('#TB_overlay').addClass('TB_overlayBG'); // use background and opacity
}
if (params.caption === null) {
params.caption = '';
}
$('body').append("<div id='TB_load'><img src='" + TB.imgLoader.src + "' /></div>"); // add loader to the page
$('#TB_load').show(); // show loader
var baseURL;
if (params.url.indexOf('?') !== -1) {
// ff there is a query string involved
baseURL = params.url.substr(0, params.url.indexOf('?'));
} else {
baseURL = params.url;
}
var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
var url_params = {};
if ( baseURL.toLowerCase().match(urlString) ) {
TB.processImages(params, urlString);
} else {
var queryString = params.url.replace(/^[^\?]+\??/,'');
url_params = TB.parseQuery(queryString);
TB.processDialog(params, url_params);
}
if (url_params['modal'] != 'true') {
$(document).bind(
'keyup',
function(e){
if (e.which == 27){
// close
TB.remove();
}
}
);
}
} catch(e) {
//nothing here
alert("An exception occurred in the script.\nError name: " + e.name + ".\nError message: " + e.message);
}
}
// helper functions below
TB.processImages = function (params, urlString) {
// code to show images
var TB_PrevCaption = '';
var TB_PrevURL = '';
var TB_PrevHTML = '';
var TB_NextCaption = '';
var TB_NextURL = '';
var TB_NextHTML = '';
var TB_imageCount = '';
var TB_FoundURL = false;
if (params.imageGroup) {
// scan images in group to create Prev/Next links
var TB_TempArray = $('a[rel=' + params.imageGroup + ']').get();
for (var TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === '')); TB_Counter++) {
var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
if (!(TB_TempArray[TB_Counter].href == params.url)) {
if (TB_FoundURL) {
TB_NextCaption = TB_TempArray[TB_Counter].title;
TB_NextURL = TB_TempArray[TB_Counter].href;
TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
} else {
TB_PrevCaption = TB_TempArray[TB_Counter].title;
TB_PrevURL = TB_TempArray[TB_Counter].href;
TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
}
} else {
TB_FoundURL = true;
TB_imageCount = 'Image ' + (TB_Counter + 1) + ' of ' + TB_TempArray.length;
}
}
}
var imgPreloader = new Image();
$(imgPreloader).bind(
'load',
function() {
$(this).unbind('load');
var $image_size = TB.scaleImage.call(TB, this);
TB.Width = $image_size.width + 30;
TB.Height = $image_size.height + 60;
$('#' + TB.getId('TB_window')).append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='" + params.url + "' width='" + $image_size.width + "' height='" + $image_size.height + "' alt='" + params.caption + "'/></a>" + "<div id='" + TB.getId('TB_caption') + "'>" + params.caption + "<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='" + TB.getId('TB_closeWindow') + "'><a href='#' id='" + TB.getId('TB_closeWindowButton') + "' title='Close'>close</a> or Esc Key</div>");
$('#' + TB.getId('TB_closeWindowButton')).click(TB.remove);
if (TB_PrevHTML !== '') {
function goPrev() {
$('#' + TB.getId('TB_window')).remove();
$('body').append("<div id='" + TB.getId('TB_window') + "' class='TB_window'></div>");
TB.show( {caption: TB_PrevCaption, url: TB_PrevURL, imageGroup: params.imageGroup} );
return false;
}
$('#TB_prev').click(goPrev);
}
if (TB_NextHTML !== '') {
function goNext() {
$('#' + TB.getId('TB_window')).remove();
$('body').append("<div id='" + TB.getId('TB_window') + "' class='TB_window'></div>");
TB.show( {caption: TB_NextCaption, url: TB_NextURL, imageGroup: params.imageGroup} );
return false;
}
$('#TB_next').click(goNext);
}
$(document).bind(
'keydown',
function(e) {
var keycode = e.which;
if (keycode == 27) { // close
TB.remove();
} else if (keycode == 190) {
// display previous image
if (TB_NextHTML != '') {
$(this).unbind('keydown');
goNext();
}
} else if (keycode == 188) {
// display next image
if(TB_PrevHTML != ''){
$(this).unbind('keydown');
goPrev();
}
}
}
);
// show image after it's loaded
TB.position();
$('#TB_load').remove();
$('#TB_ImageOff').click(TB.remove);
$('#' + TB.getId('TB_window')).css('display', 'block'); // for safari using css instead of show
}
);
imgPreloader.src = params.url;
}
TB.scaleImage = function ($image) {
// resizing large images - orginal by Christian Montoya edited by me
var pagesize = TB.getPageSize();
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = $image.width;
var imageHeight = $image.height;
if ($image.src !== undefined) {
if (imageWidth > x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
if (imageHeight > y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
}
} else if (imageHeight > y) {
imageWidth = imageWidth * (y / imageHeight);
imageHeight = y;
if (imageWidth > x) {
imageHeight = imageHeight * (x / imageWidth);
imageWidth = x;
}
}
}
else {
if (imageWidth > x) {
imageWidth = x;
}
if (imageHeight > y) {
imageHeight = y;
}
}
return {width: imageWidth, height: imageHeight};
}
TB.processDialog = function (params, url_params) {
// code to show html
// window size is global
var $fake_image = {
width: (url_params['width'] * 1) || 600, // defaults to 630 if no paramaters were added to URL
height: (url_params['height'] * 1) || 400 // defaults to 440 if no paramaters were added to URL
}
var $image_size = TB.scaleImage.call(TB, $fake_image);
TB.setWindowMetaData('window_size', $image_size);
TB.setWindowMetaData('window_maximized', false);
TB.Width = $image_size.width + 30;
TB.Height = $image_size.height + 40;
var ajaxContentW = TB.Width - 30;
var ajaxContentH = TB.Height - 45;
var $modal = url_params['modal'] == 'true';
if (params.url.indexOf('TB_iframe') != -1) {
// either iframe or ajax window
urlNoQuery = params.url.split('TB_');
$('#' + TB.getId('TB_iframeContent')).remove();
if ($modal) {
// iframe modal -> don't close when clicking on grayed-out area
$('#TB_overlay').unbind();
}
var $caption_html = "<div id='" + TB.getId('TB_title') + "' class='TB_title'><div id='" + TB.getId('TB_ajaxWindowTitle') + "' class='TB_ajaxWindowTitle'>" + params.caption + "</div><div id='" + TB.getId('TB_closeAjaxWindow') + "' class='TB_closeAjaxWindow'><a href='#' id='" + TB.getId('TB_closeWindowButton') + "' class='TB_closeWindowButton' title='Close'>" + TB.closeHtml + "</a>" + ($modal ? '' : ' or Esc Key') + "</div></div>";
$('#' + TB.getId('TB_window')).append($caption_html + "<iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='" + TB.getId('TB_iframeContent') + "' name='" + TB.getId('TB_iframeContent' + Math.round(Math.random() * 1000)) + "' onload='TB.showIframe()' class='TB_iframeContent' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;'> </iframe>");
} else {
// not an iframe, ajax
if ($('#' + TB.getId('TB_window')).css('display') != 'block') {
var $caption_html = "<div id='" + TB.getId('TB_title') + "' class='TB_title'><div id='" + TB.getId('TB_ajaxWindowTitle') + "' class='TB_ajaxWindowTitle'>" + params.caption + "</div><div id='" + TB.getId('TB_closeAjaxWindow') + "' class='TB_closeAjaxWindow'><a href='#' id='" + TB.getId('TB_closeWindowButton') + "' class='TB_closeWindowButton'>" + TB.closeHtml + "</a>" + ($modal ? '' : ' or Esc Key') + "</div></div>";
if (!$modal) {
// ajax no modal
$('#' + TB.getId('TB_window')).append($caption_html + "<div id='" + TB.getId('TB_ajaxContent') + "' class='TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px'></div>");
} else {
// ajax modal
$('#TB_overlay').unbind();
$('#' + TB.getId('TB_window')).append($caption_html + "<div id='" + TB.getId('TB_ajaxContent') + "' class='TB_modal TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px;'></div>");
}
} else {
// this means the window is already up, we are just loading new content via ajax
var $ajax_content = $('#' + TB.getId('TB_ajaxContent')).get(0);
$ajax_content.style.width = ajaxContentW + 'px';
$ajax_content.style.height = ajaxContentH + 'px';
$ajax_content.scrollTop = 0;
$('#' + TB.getId('TB_ajaxWindowTitle')).html(params.caption);
}
}
$('#' + TB.getId('TB_closeWindowButton')).click(TB.remove);
if (params.url.indexOf('TB_inline') != -1) {
$('#' + TB.getId('TB_ajaxContent')).html( $('#' + url_params['inlineId']).html() );
$('#' + TB.getId('TB_window')).unload(
function () {
// move elements back when you're finished
$('#' + url_params['inlineId']).html( $('#' + TB.getId('TB_ajaxContent')).html() );
}
);
TB.position();
$('#TB_load').remove();
$('#' + TB.getId('TB_window')).css('display', 'block');
if ( $.isFunction(params.onAfterShow) ) {
params.onAfterShow();
}
} else if (params.url.indexOf('TB_iframe') != -1) {
TB.position();
if ($.browser.safari) {
// safari needs help because it will not fire iframe onload
$('#TB_load').remove();
$('#' + TB.getId('TB_window')).css('display', 'block');
}
} else {
$.ajaxSetup({cache: false});
var $content_url = params.url;
if (params.postParams === undefined) {
$.get(
$content_url,
function ($data) {
TB.onDataReceived($data, params);
}
);
}
else {
$.post(
$content_url,
params.postParams,
function ($data) {
TB.onDataReceived($data, params);
}
);
}
}
TB.updateZIndex(); // update z-index on window open
}
TB.setWindowTitle = function ($title) {
if (TB.useStack) {
// remember window titles
if (TB.windowMetaData.length == 0) {
// remember title of topmost window too
TB.windowMetaData[TB.windowMetaData.length] = {window_name: 'main'};
}
TB.setWindowMetaData('title', $title);
}
$('#' + TB.getId('TB_ajaxWindowTitle') ).html($title);
}
TB.parseRedirect = function ($data) {
var $match_redirect = new RegExp('^#redirect#(.*?)($|\\s.*)').exec($data);
if ($match_redirect != null) {
// redirect to external template requested
return $match_redirect[1];
}
return false;
}
TB.onDataReceived = function ($data, $params) {
if ( $.isFunction($params.onDataReceived) ) {
$data = $params.onDataReceived($data);
if ($data === false) {
// this callback even could prevent redirect action
// callback requested to stop processing
return ;
}
}
var $redirect = TB.parseRedirect($data);
if ($redirect !== false) {
window.location.href = $redirect;
return ;
}
$('#' + TB.getId('TB_ajaxContent')).html($data);
TB.position();
$('#TB_load').remove();
TB.init('#' + TB.getId('TB_ajaxContent') + ' a.thickbox');
$('#' + TB.getId('TB_window')).css('display', 'block');
if ( $.isFunction($params.onAfterShow) ) {
$params.onAfterShow();
}
}
TB.showIframe = function () {
$('#TB_load').remove();
$('#' + TB.getId('TB_window')).css('display', 'block');
try {
if ( $.isFunction(TB.lastParams.onAfterShow) ) {
TB.lastParams.onAfterShow();
}
}
catch (e) {
// IE gives "Can't execute code from a freed script" when iframe is closed and parent window is reloaded
// It's not a big problem, that our method is not called in this case, becase it doesn't do anything in
// such case either
}
}
TB.remove = function ($e, $on_close) {
if (TB.useStack && TB.windows.length == 0) {
// no windows opened, but TB.remove called -> ignore
return ;
}
var $last_window = TB.useStack && TB.windows.length <= 1;
if ( !$.isFunction($on_close) && $.isFunction(TB.lastParams.onAfterClose) ) {
$on_close = TB.lastParams.onAfterClose;
}
$('#TB_imageOff').unbind('click');
$('#' + TB.getId('TB_closeWindowButton')).unbind('click');
/*$('#' + TB.getId('TB_window')).fadeOut(
'fast',
function() {
TB.onAfterFade($last_window);
}
)*/
$('#' + TB.getId('TB_window')).hide();
TB.onAfterFade($last_window, $on_close);
if ($last_window) {
$('#TB_load').remove();
if (typeof document.body.style.maxHeight == 'undefined') {
// if IE 6
$('body','html').css( {height: 'auto', width: 'auto'} );
$('html').css('overflow', '');
}
$(document).unbind('keydown').unbind('keyup');
document.body.style.overflow = TB.lastOverflow;
}
return false;
}
TB.onAfterFade = function ($last_window, $on_close) {
if ($last_window) {
// hide overlays first
$('#TB_overlay,#TB_HideSelect').remove();
}
if ($.isFunction($on_close)) {
// use close callback, because iframe will be removed later in this method
$on_close();
}
$('#' + TB.getId('TB_window')).unload().remove();
if (TB.useStack) {
// tricky window removing to prevent memory leaks
var n_nesting = TB.windows.length - 1;
$(TB.windows[n_nesting]).remove();
TB.windows[n_nesting] = null;
TB.windows.length = n_nesting;
// window meta data has one more record at beginning for topmost window
TB.windowMetaData[n_nesting + 1] = null;
TB.windowMetaData.length = n_nesting + 1;
TB.updateZIndex(); // update z-index on window close
set_window_title(TB.windowMetaData[TB.windowMetaData.length - 1].title);
if (TB.windows.length == 0) {
getFrame('head').$FrameResizer.fullScreen(true);
}
}
}
TB.position = function () {
var pagesize = TB.getPageSize();
var $window = $('#' + TB.getId('TB_window'));
var $borders = {
horizontal: $window.outerWidth() - $window.width(),
vertical: $window.outerHeight() - $window.height()
};
var $top = $(window).scrollTop() + Math.round((pagesize[1] - TB.Height - $borders.vertical) / 2);
var $left = Math.round((pagesize[0] - TB.Width - $borders.horizontal) / 2);
$window.css(
{
width: TB.Width + 'px',
height: TB.Height + 'px'
}
);
if ($left > 0) {
// when something large is opened from right, then we got negative left
// (negative values breaks down "draggable.containment")
$window.css('left', $left + 'px');
}
if ($top > 0) {
// when Firebug console is opened from bottom, then we got negative top
// (negative values breaks down "draggable.containment")
$window.css('top', $top + 'px');
}
$window
.resizable(
{
alsoResize: '#' + TB.getId('TB_iframeContent'),
stop: function(event, ui) {
if (TB.getWindowMetaData('window_maximized')) {
return ;
}
var $window = $(this);
var $window_size = {
width: $window.width() - 30,
height: $window.height() - 40
}
TB.setWindowMetaData('window_size', $window_size);
}
}
)
.draggable(
{
handle: '.TB_title',
containment: 'window'
}
);
$('#' + TB.getId('TB_title')).dblclick(
function($e) {
var $window = $('#' + TB.getId('TB_window'));
var $maximized = TB.getWindowMetaData('window_maximized');
var $borders = {
horizontal: $window.outerWidth() - $window.width(),
vertical: $window.outerHeight() - $window.height()
};
if ($maximized) {
var $window_size = TB.getWindowMetaData('window_size');
var $new_width = $window_size.width + 30;
var $new_height = $window_size.height + 40;
TB.setWindowMetaData('window_maximized', false);
}
else {
var $new_width = pagesize[0] - $borders.horizontal;
var $new_height = pagesize[1] - $borders.vertical;
TB.setWindowMetaData('window_maximized', true);
}
var $window_width = $window.width();
var $window_height = $window.height();
$window.css(
{
width: $new_width + 'px',
height: $new_height + 'px',
left: Math.round((pagesize[0] - $new_width - $borders.horizontal) / 2) + 'px',
top: $(window).scrollTop() + Math.round((pagesize[1] - $new_height - $borders.vertical) / 2) + 'px'
}
);
var $width_diff = $new_width - $window_width;
var $height_diff = $new_height - $window_height;
var $iframe = $('#' + TB.getId('TB_iframeContent'));
$iframe.width( $iframe.width() + $width_diff );
$iframe.height( $iframe.height() + $height_diff );
if ( $('#scroll_container').length == 1 ) {
Form.Resize();
}
}
);
/*$('#' + TB.getId('TB_window')).css( {marginLeft: '-' + parseInt((TB.Width / 2), 10) + 'px', width: TB.Width + 'px'} );
if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) {
// take away IE6
$('#' + TB.getId('TB_window')).css( {marginTop: '-' + parseInt((TB.Height / 2), 10) + 'px'} );
}*/
}
TB.parseQuery = function (query) {
var Params = {};
if (!query) {
// return empty object
return Params;
}
var Pairs = query.split(/[;&]/);
for (var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if (!KeyVal || KeyVal.length != 2) {
continue;
}
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
TB.getPageSize = function () {
var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
return [w, h];
}
TB.detectMacXFF = function () {
var userAgent = navigator.userAgent.toLowerCase();
return userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1;
}
TB.updateZIndex = function () {
- // #TB_overlay - 100
- // .TB_window - 102 [ok]
- // #TB_load - 103 [ok]
- // #TB_HideSelect - 99
+ // #TB_overlay - 1000100
+ // .TB_window - 1000102 [ok]
+ // #TB_load - 1000103 [ok]
+ // #TB_HideSelect - 1000099
var n_nesting = TB.windows.length - 1;
- var $window_index = 102 + n_nesting + TB.windows.length;
+ var $window_index = 1000102 + n_nesting + TB.windows.length;
// alert('nesting ' + n_nesting + ', window index ' + $window_index);
$(TB.windows[n_nesting]).css('z-index', $window_index); // window position is dependend on it's opening order
$('#TB_load').css('z-index', $window_index + 1); // progress bar is over window
$('#TB_overlay').css('z-index', $window_index - 1); // overlay is under window
}
TB.setWindowMetaData = function ($title, $value) {
TB.windowMetaData[TB.windowMetaData.length - 1][$title] = $value;
}
TB.getWindowMetaData = function ($title) {
return TB.windowMetaData[TB.windowMetaData.length - 1][$title];
}
TB.findWindow = function ($name, $diff) {
if (!isset($diff)) {
$diff = 0;
}
for (var $i = TB.windowMetaData.length - 1; $i >= 0; $i--) {
// alert('comparing [' + TB.windowMetaData[$i].window_name + '] to [' + $name + ']');
if (TB.windowMetaData[$i].window_name == $name) {
break;
}
}
var $window_index = $i + $diff;
if ($i == 0 || $window_index <= 0) {
// not found or "main" window was requested -> it's not in TB.windows array anyway
return window;
}
return $found_window = $('.TB_iframeContent', TB.windows[$window_index - 1]).get(0).contentWindow;
}
\ No newline at end of file
Index: branches/5.2.x/core/admin_templates/incs/cms.css
===================================================================
--- branches/5.2.x/core/admin_templates/incs/cms.css (revision 15529)
+++ branches/5.2.x/core/admin_templates/incs/cms.css (revision 15530)
@@ -1,398 +1,398 @@
/* === Common styles for "Section Properties" and "Edit" buttons === */
div.cms-btn-image {
float: left;
height: 15px;
vertical-align: middle;
}
div.cms-btn-text {
margin-left: 3px;
float: left;
white-space: nowrap;
vertical-align: middle;
}
div.cms-btn-content {
padding: 5px;
}
.cms-edit-btn {
padding: 2px 5px;
font-family: Arial, Verdana;
font-size: 13px;
font-weight: normal;
color: black;
cursor: pointer;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
}
.cms-section-properties-btn, .cms-edit-btn, .cms-edit-block-btn, .cms-edit-design-btn {
width: auto;
position: absolute;
- z-index: 99;
+ z-index: 1000099;
}
.cms-edit-btn, .cms-edit-block-btn, .cms-edit-design-btn {
margin-top: -10px;
}
div.cms-edit-design-btn-container {
position: absolute;
margin-left: -10px;
margin-top: -10px;
display: none;
}
div.cms-edit-design-btn-container .cms-edit-block-btn, div.cms-edit-design-btn-container .cms-edit-design-btn {
float: left;
display: block;
position: relative;
margin: 0px;
}
div.cms-edit-design-btn-container .cms-edit-design-btn {
margin-left: 4px;
}
/* === Styles for "Section Properties" button === */
.cms-section-properties-btn {
float: right;
position: relative;
border-color: #A1D0A1;
background-color: #CCFF00;
}
div.cms-section-properties-btn-container {
border: 1px dashed #A1D0A1;
margin: 10px;
}
/* === Styles for "Edit" button === */
.cms-btn-new {
cursor: pointer;
background: url(@templates_base@/img/top_frame/icons/content_mode.png) #CCFF00 3px center no-repeat;
padding: 2px 2px 2px 17px;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border: 2px solid #A1D0A1;
opacity: 0.5;
filter: alpha(opacity=50);
color: black;
font-family: Arial, Verdana;
font-size: 13px;
font-weight: normal;
}
.cms-btn-new:hover {
opacity: 1;
filter: alpha(opacity=100);
}
div.cms-edit-btn-container {
border: 1px dashed #FF6E00;
}
div.cms-edit-btn {
border: 2px solid #FF6E00;
}
.cms-edit-btn {
margin-left: -10px;
border-color: #FF6E00;
background-color: #FFCC00;
}
.cms-edit-block-btn {
border-color: #FF6E00;
background-color: #FFCC00;
display: none;
}
.cms-edit-design-btn {
border-color: #A1D0A1;
background-color: #CCFF00;
display: none;
}
.admin-edit-btn {
border-color: #A1D0A1;
background-color: #CCFF00;
}
/* === Styles for "Save" and "Cancel" buttons (for layout) === */
div.cms-layout-btn-container {
position: absolute;
display: none;
- z-index: 99;
+ z-index: 1000099;
}
.cms-save-layout-btn, .cms-cancel-layout-btn {
float: left;
width: auto;
}
.cms-save-layout-btn {
color: white;
border-color: #1C960C;
background-color: #24B30D;
}
.cms-cancel-layout-btn {
color: white;
border-color: #C81900;
background-color: #DE2A00;
}
.cms-cancel-layout-btn {
margin-left: 4px;
}
/* === Styles for Template Editor === */
div.block-edit-block-btn-container, div.block-edit-design-btn-container {
border: 1px dashed transparent;
}
div.block-edit-block-btn-container .cms-btn-new, div.block-edit-design-btn-container .cms-btn-new {
opacity: 1;
filter: alpha(opacity = 100);
}
div.block-edit-block-btn-container-over, div.block-edit-design-btn-container-over {
border-color: #FF6E00;
}
/*div.block-edit-design-btn-container-over {
border-color: #A1D0A1;
}*/
/* === Styles for element moving/sorting in theme === */
div.movable-area {
min-height: 200px;
}
.move-helper {
border: 3px dashed #666;
/*width: auto !important;*/
}
/* === Styles for phrase translation links === */
span[name='cms-translate-phrase'] {
text-decoration: none;
border: 1px dashed transparent;
padding: 3px;
}
span[name='cms-translate-phrase']:hover {
border-color: #FF6E00;
}
span[name='cms-translate-phrase'] .cms-btn-text {
font-size: 9px;
}
span[name='cms-translate-phrase'] .cms-edit-btn, span[name='cms-translate-phrase'] .admin-edit-btn {
display: none;
opacity: 1;
filter: alpha(opacity=100);
}
/* === Misc Styles for "Content Revision Control" button === */
.cms-clear { clear: both; }
.cms-right { float: right; }
.cms-left { float: left; }
/* === Current Revision Information === */
#cms-current-revision-info {
color: #4b4b4b;
font-size: 11px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
white-space: nowrap;
float: left;
padding: 0px 30px;
}
#cms-current-revision-info span {
display: block;
/*color: #008c1b;*/
font-size: 16px;
display: block;
padding: 10px 0px 3px 0px;
}
#cms-current-revision-info span.cms-revision-published { color: #15b300; }
#cms-current-revision-info span.cms-revision-pending { color: #ff9600; }
#cms-current-revision-info span.cms-revision-declined { color: #f90000; }
/* === Revision Editing Toolbar === */
#cms-revision-toolbar {
background-color: #F0F1EB;
border-collapse: collapse;
border-color: #aaaaaa;
border-style: solid;
border-width: 0 1px 1px;
font-size: 8pt;
}
#cms-revision-toolbar-layer {
position: fixed;
width: 630px;
top: 0px;
- z-index: 100;
+ z-index: 1000100;
}
.toolbar-button, .toolbar-button-disabled, .toolbar-button-over {
float: left;
text-align: center;
font-size: 8pt;
padding: 5px;
vertical-align: middle;
color: #006F99;
}
.toolbar-button-over {
color: #000;
}
.toolbar-button-disabled {
color: #444;
}
a#cms-toggle-revision-toolbar {
display: block;
background: url(@templates_base@/img/top_frame/revision_control/button_vp_right.png) top right no-repeat;
padding-right: 24px;
float: right;
margin-top: -1px;
text-decoration: none;
}
a#cms-toggle-revision-toolbar span {
display: block;
background: url(@templates_base@/img/top_frame/revision_control/button_vp_left.png) top left no-repeat;
line-height: 30px;
color: #000000;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
padding: 0px 10px 0px 15px;
}
a#cms-toggle-revision-toolbar:hover span {
color: #666666;
}
a#cms-toggle-revision-toolbar.opened {
background: url(@templates_base@/img/top_frame/revision_control/button_vp_right2.png) top right no-repeat;
}
#cms-close-toolbar {
float: right;
display: block;
width: 10px;
height: 10px;
background: url(@templates_base@/img/top_frame/revision_control/close_black.gif) top left;
overflow: hidden;
margin: 10px 10px 0 0;
}
/* === Revision Editing Notice === */
#cms-editing-notice {
width: 230px;
position: fixed;
- z-index: 101;
+ z-index: 1000101;
margin-top: 50px;
margin-left: 10px;
display: none;
}
#cms-editing-notice .top {
background: url(@templates_base@/img/top_frame/revision_control/message_background_red.png) left top no-repeat;
padding: 30px 20px 10px 20px;
color: #FFFFFF;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
#cms-editing-notice .bottom {
background: url(@templates_base@/img/top_frame/revision_control/message_background_red.png) left bottom no-repeat;
height: 6px;
}
#cms-close-editing-notice {
float:right;
display:block;
width:10px;
height:10px;
background:url(@templates_base@/img/top_frame/revision_control/close_white.gif) top left;
overflow:hidden;
margin:-5px -10px 0 0;
}
/* === Revision Dropdown === */
#cms-revision-dropdown {
width: 240px;
position: fixed;
margin-left: 260px;
margin-top: 30px;
- z-index: 102;
+ z-index: 1000102;
display: none;
}
#cms-revision-dropdown .top {
border-top: 1px solid #aaaaaa;
border-left: 1px solid #aaaaaa;
border-right: 1px solid #aaaaaa;
}
#cms-revision-dropdown .item, #cms-revision-dropdown .item:hover {
color: #666666;
background: url(@templates_base@/img/top_frame/revision_control/history_item_background.gif) top left repeat-x #FFFFFF;
padding: 10px 13px;
border-top: 1px solid #e7e7e7;
font-size: 11px;
cursor: pointer;
}
#cms-revision-dropdown .item:hover {
background: url(@templates_base@/img/top_frame/revision_control/history_item_background_hover.gif) top left repeat-x #F8F8F8;
}
#cms-revision-dropdown .item .red {
color: #FF0000;
padding-top: 6px;
}
#cms-revision-dropdown .bottom {
background: url(@templates_base@/img/top_frame/revision_control/history_bottom.png) top left no-repeat;
height: 6px;
}
.item .cms-revision-published, .item .cms-revision-pending, .item .cms-revision-declined {
display: block;
font-size: 13px;
font-weight: bold;
padding-bottom: 8px;
}
.item .cms-revision-published, .item .cms-revision-published a { color: #15b300 !important; }
.item .cms-revision-published a:hover { color: #1ada00 !important; }
.item .cms-revision-pending, .item .cms-revision-pending a { color: #ff9600 !important; }
.item .cms-revision-pending a:hover { color: #ffba58 !important; }
.item .cms-revision-declined, .item .cms-revision-declined a { color: #f90000 !important; }
.item .cms-revision-declined a:hover { color: #ff6666 !important; }
\ No newline at end of file

Event Timeline