Skip to content

Line numbers if FirePHP class is renamed #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions lib/FirePHPCore/FirePHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// - cadorn, Christoph Dorn <[email protected]>, Copyright 2007, New BSD License
// - qbbr, Sokolov Innokenty <[email protected]>, Copyright 2011, New BSD License
// - cadorn, Christoph Dorn <[email protected]>, Copyright 2011, MIT License
// - kmcs, Timo Kiefer <[email protected]>, Copyright 2012, MIT License

/**
* *** BEGIN LICENSE BLOCK *****
Expand Down Expand Up @@ -205,7 +206,8 @@ class FirePHP {
'maxObjectDepth' => 5,
'maxArrayDepth' => 5,
'useNativeJsonEncode' => true,
'includeLineNumbers' => true);
'includeLineNumbers' => true,
'useGzipEncode' => false);

/**
* Filters used to exclude object members when encoding
Expand Down Expand Up @@ -237,6 +239,18 @@ class FirePHP {
* @var object
*/
protected $logToInsightConsole = null;

/**
* sent byes
* @var integer
*/
protected $sentBytes = 0;

/**
* max sent bytes
* @var integer
*/
protected $maxBytesToSent = 32000; //~32k

/**
* When the object gets serialized only include specific object members.
Expand Down Expand Up @@ -711,6 +725,9 @@ public function detectClientExtension()
// Check if FirePHP is installed on client via User-Agent header
if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si', $this->getUserAgent(), $m) &&
version_compare($m[1][0], '0.0.6', '>=')) {
if(!version_compare($m[1][0], '0.7', '>=')) {
$this->setOption('useGzipEncode', false);
}
return true;
} else
// Check if FirePHP is installed on client via X-FirePHP-Version header
Expand Down Expand Up @@ -1002,9 +1019,11 @@ public function fb($object)
if (isset($trace[$i]['class'])
&& isset($trace[$i]['file'])
&& ($trace[$i]['class'] == 'FirePHP'
|| $trace[$i]['class'] == 'FB')
|| $trace[$i]['class'] == 'FB'
|| $trace[$i]['class'] == __CLASS__)
&& (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php'
|| substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) {
|| substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php'
|| $this->_standardizePath($trace[$i]['file']) == __FILE__)) {
/* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
} else
if (isset($trace[$i]['class'])
Expand All @@ -1029,6 +1048,9 @@ public function fb($object)
}

$this->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
if($this->options['useGzipEncode'] && function_exists('gzencode')) {
$this->setHeader('X-Wf-Option-gzip', 'true');
}
$this->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . self::VERSION);

$structureIndex = 1;
Expand Down Expand Up @@ -1056,6 +1078,14 @@ public function fb($object)
$msg = '[' . $this->jsonEncode($msgMeta) . ',' . $this->jsonEncode($object, $skipFinalObjectEncode) . ']';
}

if($this->options['useGzipEncode'] && function_exists('gzencode')) {
$msg = base64_encode(gzencode($msg));
}

if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) {
return;
}

$parts = explode("\n", chunk_split($msg, 5000, "\n"));

for ($i = 0; $i < count($parts); $i++) {
Expand All @@ -1081,6 +1111,8 @@ public function fb($object)
}
}
}

$this->sentBytes += strlen($msg);

$this->setHeader('X-Wf-1-Index', $this->messageIndex - 1);

Expand Down Expand Up @@ -1825,4 +1857,4 @@ public function setRendererUrl($URL)
{
trigger_error('The FirePHP::setRendererUrl() method is no longer supported', E_USER_DEPRECATED);
}
}
}
38 changes: 35 additions & 3 deletions lib/FirePHPCore/FirePHP.class.php4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// - cadorn, Christoph Dorn <[email protected]>, Copyright 2007, New BSD License
// - qbbr, Michael Day <[email protected]>, Copyright 2008, New BSD License
// - cadorn, Christoph Dorn <[email protected]>, Copyright 2011, MIT License
// - kmcs, Timo Kiefer <[email protected]>, Copyright 2012, MIT License

/**
* *** BEGIN LICENSE BLOCK *****
Expand Down Expand Up @@ -148,7 +149,8 @@ class FirePHP {
var $options = array('maxObjectDepth' => 5,
'maxArrayDepth' => 5,
'useNativeJsonEncode' => true,
'includeLineNumbers' => true);
'includeLineNumbers' => true,
'useGzipEncode' => false);

/**
* Filters used to exclude object members when encoding
Expand All @@ -170,6 +172,18 @@ class FirePHP {
* @var boolean
*/
var $enabled = true;

/**
* sent byes
* @var integer
*/
var $sentBytes = 0;

/**
* max sent bytes
* @var integer
*/
var $maxBytesToSent = 32000; //~32k

/**
* The object constructor
Expand Down Expand Up @@ -486,6 +500,9 @@ class FirePHP {
// Check if FirePHP is installed on client via User-Agent header
if(@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) &&
version_compare($m[1][0],'0.0.6','>=')) {
if(!version_compare($m[1][0], '0.7', '>=')) {
$this->setOption('useGzipEncode', false);
}
return true;
} else
// Check if FirePHP is installed on client via X-FirePHP-Version header
Expand Down Expand Up @@ -629,9 +646,11 @@ class FirePHP {
if(isset($trace[$i]['class'])
&& isset($trace[$i]['file'])
&& ($trace[$i]['class']=='FirePHP'
|| $trace[$i]['class']=='FB')
|| $trace[$i]['class']=='FB'
|| $trace[$i]['class']==__CLASS__)
&& (substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
|| substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
|| substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php'
|| $this->_standardizePath($trace[$i]['file'])==__FILE__)) {
/* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
} else
if(isset($trace[$i]['class'])
Expand All @@ -657,6 +676,9 @@ class FirePHP {
}

$this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
if($this->options['useGzipEncode'] && function_exists('gzencode')) {
$this->setHeader('X-Wf-Option-gzip', 'true');
}
$this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.FirePHP_VERSION);

$structure_index = 1;
Expand Down Expand Up @@ -684,6 +706,14 @@ class FirePHP {
$msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']';
}

if($this->options['useGzipEncode'] && function_exists('gzencode')) {
$msg = base64_encode(gzencode($msg));
}

if($this->maxBytesToSent < ($this->sentBytes + strlen($msg))) {
return;
}

$parts = explode("\n",chunk_split($msg, 5000, "\n"));

for( $i=0 ; $i<count($parts) ; $i++) {
Expand All @@ -709,6 +739,8 @@ class FirePHP {
}
}
}

$this->sentBytes += strlen($msg);

$this->setHeader('X-Wf-1-Index',$this->messageIndex-1);

Expand Down