initial commit
This commit is contained in:
59
exp/Plugin/DebugKit/View/Elements/debug_toolbar.ctp
Normal file
59
exp/Plugin/DebugKit/View/Elements/debug_toolbar.ctp
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* Debug Toolbar Element
|
||||
*
|
||||
* Renders all of the other panel elements.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<div id="debug-kit-toolbar">
|
||||
<?php if (empty($debugToolbarPanels)) :?>
|
||||
<p class="warning"><?php echo __d('debug_kit', 'There are no active panels. You must enable a panel to see its output.'); ?></p>
|
||||
<?php else: ?>
|
||||
<ul id="panel-tabs">
|
||||
<li class="panel-tab icon">
|
||||
<a href="#hide" id="hide-toolbar">
|
||||
<?php echo $this->Html->image('/debug_kit/img/cake.icon.png', array('alt' => 'CakePHP')); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php foreach ($debugToolbarPanels as $panelName => $panelInfo): ?>
|
||||
<?php $panelUnderscore = Inflector::underscore($panelName);?>
|
||||
<li class="panel-tab">
|
||||
<?php
|
||||
$title = (empty($panelInfo['title'])) ? Inflector::humanize($panelUnderscore) : $panelInfo['title'];
|
||||
echo $this->Toolbar->panelStart($title, $panelUnderscore);
|
||||
?>
|
||||
<div class="panel-content" id="<?php echo $panelUnderscore ?>-tab">
|
||||
<a href="#" class="panel-toggle ui-control ui-button">+</a>
|
||||
<div class="panel-resize-region">
|
||||
<div class="panel-content-data">
|
||||
<?php
|
||||
echo $this->element($panelInfo['elementName'], $panelInfo, array(
|
||||
'plugin' => (empty($panelInfo['plugin'])) ? null : Inflector::camelize($panelInfo['plugin'])
|
||||
));
|
||||
?>
|
||||
</div>
|
||||
<div class="panel-content-data panel-history" id="<?php echo $panelUnderscore; ?>-history">
|
||||
<!-- content here -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-resize-handle ui-control">====</div>
|
||||
</div>
|
||||
<?php $this->Toolbar->panelEnd(); ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
84
exp/Plugin/DebugKit/View/Elements/environment_panel.ctp
Normal file
84
exp/Plugin/DebugKit/View/Elements/environment_panel.ctp
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Environment Panel Element
|
||||
*
|
||||
* Shows information about the current app environment
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('debug_kit', 'App Constants'); ?></h2>
|
||||
<?php
|
||||
if (!empty($content['app'])) {
|
||||
$cakeRows = array();
|
||||
foreach ($content['app'] as $key => $val) {
|
||||
$cakeRows[] = array(
|
||||
$key,
|
||||
$val
|
||||
);
|
||||
}
|
||||
$headers = array('Constant', 'Value');
|
||||
echo $this->Toolbar->table($cakeRows, $headers, array('title' => 'Application Environment Vars'));
|
||||
} else {
|
||||
echo "No application environment available.";
|
||||
} ?>
|
||||
|
||||
<h2><?php echo __d('debug_kit', 'CakePHP Constants'); ?></h2>
|
||||
<?php
|
||||
if (!empty($content['cake'])) {
|
||||
$cakeRows = array();
|
||||
foreach ($content['cake'] as $key => $val) {
|
||||
$cakeRows[] = array(
|
||||
h($key),
|
||||
h($val)
|
||||
);
|
||||
}
|
||||
$headers = array('Constant', 'Value');
|
||||
echo $this->Toolbar->table($cakeRows, $headers, array('title' => 'CakePHP Environment Vars'));
|
||||
} else {
|
||||
echo "CakePHP environment unavailable.";
|
||||
} ?>
|
||||
|
||||
<h2><?php echo __d('debug_kit', 'PHP Environment');?></h2>
|
||||
<?php
|
||||
$headers = array('Environment Variable', 'Value');
|
||||
|
||||
if (!empty($content['php'])) {
|
||||
$phpRows = array();
|
||||
foreach ($content['php'] as $key => $val) {
|
||||
$phpRows[] = array(
|
||||
h(Inflector::humanize(strtolower($key))),
|
||||
h($val)
|
||||
);
|
||||
}
|
||||
echo $this->Toolbar->table($phpRows, $headers, array('title' => 'CakePHP Environment Vars'));
|
||||
} else {
|
||||
echo "PHP environment unavailable.";
|
||||
}
|
||||
|
||||
if (isset($content['hidef'])) {
|
||||
echo '<h2>' . __d('debug_kit', 'Hidef Environment') . '</h2>';
|
||||
if (!empty($content['hidef'])) {
|
||||
$cakeRows = array();
|
||||
foreach ($content['hidef'] as $key => $val) {
|
||||
$cakeRows[] = array(
|
||||
h($key),
|
||||
h($val)
|
||||
);
|
||||
}
|
||||
$headers = array('Constant', 'Value');
|
||||
echo $this->Toolbar->table($cakeRows, $headers, array('title' => 'Hidef Environment Vars'));
|
||||
} else {
|
||||
echo "No Hidef environment available.";
|
||||
}
|
||||
}
|
||||
32
exp/Plugin/DebugKit/View/Elements/history_panel.ctp
Normal file
32
exp/Plugin/DebugKit/View/Elements/history_panel.ctp
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* View Variables Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 1.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2> <?php echo __d('debug_kit', 'Request History'); ?></h2>
|
||||
<?php if (empty($content)): ?>
|
||||
<p class="warning"><?php echo __d('debug_kit', 'No previous requests logged.'); ?></p>
|
||||
<?php else: ?>
|
||||
<?php echo count($content); ?> <?php echo __d('debug_kit', 'previous requests available') ?>
|
||||
<ul class="history-list">
|
||||
<li><?php echo $this->Html->link(__d('debug_kit', 'Restore to current request'),
|
||||
'#', array('class' => 'history-link', 'id' => 'history-restore-current')); ?>
|
||||
</li>
|
||||
<?php foreach ($content as $previous): ?>
|
||||
<li><?php echo $this->Html->link($previous['title'], $previous['url'], array('class' => 'history-link')); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif;
|
||||
34
exp/Plugin/DebugKit/View/Elements/include_panel.ctp
Normal file
34
exp/Plugin/DebugKit/View/Elements/include_panel.ctp
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Included Files Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 2.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
**/
|
||||
?>
|
||||
<h2> <?php echo __d('debug_kit', 'Included Files'); ?></h2>
|
||||
|
||||
<h4>Include Paths</h4>
|
||||
<?php
|
||||
foreach ($content['paths'] as $i => $path) {
|
||||
if (strstr($path, CAKE)) {
|
||||
$content['paths'][$i] = '-> ' . $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
echo $this->Toolbar->makeNeatArray(array_filter($content['paths']));
|
||||
unset($content['paths']);
|
||||
?>
|
||||
|
||||
<h4>Included Files</h4>
|
||||
<?php echo $this->Toolbar->makeNeatArray($content);
|
||||
41
exp/Plugin/DebugKit/View/Elements/log_panel.ctp
Normal file
41
exp/Plugin/DebugKit/View/Elements/log_panel.ctp
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Log Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('debug_kit', 'Logs') ?></h2>
|
||||
<div class="code-table">
|
||||
<?php if ($content instanceof DebugKitLog): ?>
|
||||
<?php foreach ($content->logs as $logName => $logs): ?>
|
||||
<h3><?php echo $logName ?></h3>
|
||||
<?php
|
||||
$len = count($logs);
|
||||
if ($len > 0):
|
||||
$headers = array(__d('debug_kit', 'Time'), __d('debug_kit', 'Message'));
|
||||
$rows = array();
|
||||
for ($i = 0; $i < $len; $i++):
|
||||
$rows[] = array(
|
||||
$logs[$i][0], h($logs[$i][1])
|
||||
);
|
||||
endfor;
|
||||
echo $this->Toolbar->table($rows, $headers, array('title' => $logName));
|
||||
endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($content->logs)): ?>
|
||||
<p class="info"><?php echo __d('debug_kit', 'There were no log entries made this request'); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
50
exp/Plugin/DebugKit/View/Elements/request_panel.ctp
Normal file
50
exp/Plugin/DebugKit/View/Elements/request_panel.ctp
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Request Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2> <?php echo __d('debug_kit', 'Request'); ?></h2>
|
||||
|
||||
<h4>Cake Params</h4>
|
||||
<?php echo $this->Toolbar->makeNeatArray($content['params']); ?>
|
||||
|
||||
<h4>Post data</h4>
|
||||
<?php
|
||||
if (empty($content['data'])):
|
||||
echo '<p class="info">' . __d('debug_kit', 'No post data.') . '</p>';
|
||||
else:
|
||||
echo $this->Toolbar->makeNeatArray($content['data']);
|
||||
endif;
|
||||
?>
|
||||
|
||||
<h4>Query string</h4>
|
||||
<?php
|
||||
if (empty($content['query'])):
|
||||
echo '<p class="info">' . __d('debug_kit', 'No querystring data.') . '</p>';
|
||||
else:
|
||||
echo $this->Toolbar->makeNeatArray($content['query']);
|
||||
endif;
|
||||
?>
|
||||
|
||||
<h4>Cookie</h4>
|
||||
<?php if (isset($content['cookie'])): ?>
|
||||
<?php echo $this->Toolbar->makeNeatArray($content['cookie']); ?>
|
||||
<?php else: ?>
|
||||
<p class="info">To view Cookies, add CookieComponent to Controller</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<h4><?php echo __d('debug_kit', 'Current Route') ?></h4>
|
||||
<?php echo $this->Toolbar->makeNeatArray($content['currentRoute']);
|
||||
20
exp/Plugin/DebugKit/View/Elements/session_panel.ctp
Normal file
20
exp/Plugin/DebugKit/View/Elements/session_panel.ctp
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Session Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 1.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('debug_kit', 'Session'); ?></h2>
|
||||
<?php echo $this->Toolbar->makeNeatArray($content);
|
||||
80
exp/Plugin/DebugKit/View/Elements/sql_log_panel.ctp
Normal file
80
exp/Plugin/DebugKit/View/Elements/sql_log_panel.ctp
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* SQL Log Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$headers = array('Query', 'Affected', 'Num. rows', 'Took (ms)', 'Actions');
|
||||
if (isset($debugKitInHistoryMode)) {
|
||||
$content = $this->Toolbar->readCache('sql_log', $this->request->params['pass'][0]);
|
||||
}
|
||||
?>
|
||||
<h2><?php echo __d('debug_kit', 'Sql Logs')?></h2>
|
||||
<?php if (!empty($content)) : ?>
|
||||
<?php foreach ($content['connections'] as $dbName => $explain): ?>
|
||||
<div class="sql-log-panel-query-log">
|
||||
<h4><?php echo $dbName ?></h4>
|
||||
<?php
|
||||
if (!isset($debugKitInHistoryMode)):
|
||||
$queryLog = $this->Toolbar->getQueryLogs($dbName, array(
|
||||
'explain' => $explain, 'threshold' => $content['threshold']
|
||||
));
|
||||
else:
|
||||
$queryLog = $content[$dbName];
|
||||
endif;
|
||||
if (empty($queryLog['queries'])):
|
||||
if (Configure::read('debug') < 2):
|
||||
echo ' ' . __d('debug_kit', 'No query logs when debug < 2.');
|
||||
else:
|
||||
echo ' ' . __d('debug_kit', 'No query logs.');
|
||||
endif;
|
||||
else:
|
||||
$hashes = array();
|
||||
$duplicate = 0;
|
||||
foreach ($queryLog['queries'] as $key => $val) {
|
||||
$hash = sha1($val['query']);
|
||||
if (!isset($hashes[$hash]) || $hashes[$hash] !== $val['affected']) {
|
||||
$hashes[$hash] = $val['affected'];
|
||||
continue;
|
||||
}
|
||||
$duplicate++;
|
||||
|
||||
$queryLog['queries'][$key]['query'] = '<span class="alert-duplicate">' . $val['query'] . '</span>';
|
||||
}
|
||||
|
||||
echo '<h5>';
|
||||
echo __d(
|
||||
'debug_kit',
|
||||
'Total Time: %s ms <br />Total Queries: %s queries',
|
||||
$queryLog['time'],
|
||||
$queryLog['count']
|
||||
);
|
||||
echo '</h5>';
|
||||
echo $this->Toolbar->table($queryLog['queries'], $headers, array('title' => 'SQL Log ' . $dbName));
|
||||
if ($duplicate) {
|
||||
echo '<p class="alert alert-warning">' . __d('debug_kit', '%s duplicate queries run.', $duplicate) . '</p>';
|
||||
}
|
||||
?>
|
||||
<h4><?php echo __d('debug_kit', 'Query Explain:'); ?></h4>
|
||||
<div id="sql-log-explain-<?php echo $dbName ?>">
|
||||
<a id="debug-kit-explain-<?php echo $dbName ?>"> </a>
|
||||
<p><?php echo __d('debug_kit', 'Click an "Explain" link above, to see the query explanation.'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else:
|
||||
echo $this->Toolbar->message('Warning', __d('debug_kit', 'No active database connections'));
|
||||
endif;
|
||||
110
exp/Plugin/DebugKit/View/Elements/timer_panel.ctp
Normal file
110
exp/Plugin/DebugKit/View/Elements/timer_panel.ctp
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Timer Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$this->Number = $this->Helpers->load('Number');
|
||||
$this->SimpleGraph = $this->Helpers->load('DebugKit.SimpleGraph');
|
||||
|
||||
if (!isset($debugKitInHistoryMode)):
|
||||
$timers = DebugTimer::getAll(true);
|
||||
$currentMemory = DebugKitDebugger::getMemoryUse();
|
||||
$peakMemory = DebugKitDebugger::getPeakMemoryUse();
|
||||
$requestTime = DebugTimer::requestTime();
|
||||
else:
|
||||
$content = $this->Toolbar->readCache('timer', $this->request->params['pass'][0]);
|
||||
if (is_array($content)):
|
||||
extract($content);
|
||||
endif;
|
||||
endif;
|
||||
?>
|
||||
<div class="debug-info">
|
||||
<h2><?php echo __d('debug_kit', 'Memory'); ?></h2>
|
||||
<div class="peak-mem-use">
|
||||
<?php
|
||||
echo $this->Toolbar->message(__d('debug_kit', 'Peak Memory Use'), $this->Number->toReadableSize($peakMemory)); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$headers = array(__d('debug_kit', 'Message'), __d('debug_kit', 'Memory use'));
|
||||
$memoryPoints = DebugKitDebugger::getMemoryPoints();
|
||||
|
||||
$rows = array();
|
||||
foreach ($memoryPoints as $key => $value):
|
||||
$rows[] = array($key, $this->Number->toReadableSize($value));
|
||||
endforeach;
|
||||
|
||||
echo $this->Toolbar->table($rows, $headers);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="debug-info debug-timers">
|
||||
<h2><?php echo __d('debug_kit', 'Timers'); ?></h2>
|
||||
<div class="request-time">
|
||||
<?php $totalTime = __d('debug_kit', '%s (ms)', $this->Number->precision($requestTime * 1000, 0)); ?>
|
||||
<?php echo $this->Toolbar->message(__d('debug_kit', 'Total Request Time:'), $totalTime)?>
|
||||
</div>
|
||||
<?php
|
||||
$rows = array();
|
||||
$end = end($timers);
|
||||
$maxTime = $end['end'];
|
||||
|
||||
$headers = array(
|
||||
__d('debug_kit', 'Message'),
|
||||
__d('debug_kit', 'Time in ms'),
|
||||
__d('debug_kit', 'Graph')
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
$values = array_values($timers);
|
||||
|
||||
foreach ($timers as $timerName => $timeInfo):
|
||||
$indent = 0;
|
||||
for ($j = 0; $j < $i; $j++) {
|
||||
if (($values[$j]['end'] > $timeInfo['start']) && ($values[$j]['end']) > ($timeInfo['end'])) {
|
||||
$indent++;
|
||||
}
|
||||
}
|
||||
$indent = str_repeat(' » ', $indent);
|
||||
$rows[] = array(
|
||||
$indent . $timeInfo['message'],
|
||||
$this->Number->precision($timeInfo['time'] * 1000, 2),
|
||||
$this->SimpleGraph->bar(
|
||||
$this->Number->precision($timeInfo['time'] * 1000, 2),
|
||||
$this->Number->precision($timeInfo['start'] * 1000, 2),
|
||||
array(
|
||||
'max' => $maxTime * 1000,
|
||||
'requestTime' => $requestTime * 1000,
|
||||
)
|
||||
)
|
||||
);
|
||||
$i++;
|
||||
endforeach;
|
||||
|
||||
if (strtolower($this->Toolbar->getName()) === 'firephptoolbar'):
|
||||
for ($i = 0, $len = count($rows); $i < $len; $i++):
|
||||
unset($rows[$i][2]);
|
||||
endfor;
|
||||
unset($headers[2]);
|
||||
endif;
|
||||
|
||||
echo $this->Toolbar->table($rows, $headers, array('title' => 'Timers'));
|
||||
|
||||
if (!isset($debugKitInHistoryMode)):
|
||||
$this->Toolbar->writeCache('timer', compact('timers', 'currentMemory', 'peakMemory', 'requestTime'));
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
23
exp/Plugin/DebugKit/View/Elements/variables_panel.ctp
Normal file
23
exp/Plugin/DebugKit/View/Elements/variables_panel.ctp
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* View Variables Panel Element
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2> <?php echo __d('debug_kit', 'View Variables'); ?></h2>
|
||||
<?php
|
||||
$content['$this->validationErrors'] = $this->validationErrors;
|
||||
$content['Loaded Helpers'] = $this->Helpers->attached();
|
||||
echo $this->Toolbar->makeNeatArray($content);
|
||||
90
exp/Plugin/DebugKit/View/Helper/DebugTimerHelper.php
Normal file
90
exp/Plugin/DebugKit/View/Helper/DebugTimerHelper.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 2.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DebugTimer', 'DebugKit.Lib');
|
||||
App::uses('DebugMemory', 'DebugKit.Lib');
|
||||
App::uses('Helper', 'View');
|
||||
|
||||
/**
|
||||
* Class DebugTimerHelper
|
||||
*
|
||||
* Tracks time and memory usage while rendering view.
|
||||
*
|
||||
*/
|
||||
class DebugTimerHelper extends Helper {
|
||||
|
||||
/**
|
||||
* Set to true when rendering is complete.
|
||||
* Used to not add timers for rendering the toolbar.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_renderComplete = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param View $View
|
||||
* @param array $settings
|
||||
*/
|
||||
public function __construct(View $View, $settings = array()) {
|
||||
parent::__construct($View, $settings);
|
||||
DebugTimer::start(
|
||||
'viewRender',
|
||||
__d('debug_kit', 'Rendering View')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a timer point before rendering a file.
|
||||
*
|
||||
* @param string $viewFile The view being rendered
|
||||
*/
|
||||
public function beforeRenderFile($viewFile) {
|
||||
if ($this->_renderComplete) {
|
||||
return;
|
||||
}
|
||||
DebugTimer::start(
|
||||
'render_' . basename($viewFile),
|
||||
__d('debug_kit', 'Rendering %s',
|
||||
Debugger::trimPath($viewFile))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the timer point before rendering a file.
|
||||
*
|
||||
* @param string $viewFile The view being rendered
|
||||
* @param string $content The contents of the view.
|
||||
*/
|
||||
public function afterRenderFile($viewFile, $content) {
|
||||
if ($this->_renderComplete) {
|
||||
return;
|
||||
}
|
||||
DebugTimer::stop('render_' . basename($viewFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop timers for rendering.
|
||||
*
|
||||
* @param string $layoutFile
|
||||
*/
|
||||
public function afterLayout($layoutFile) {
|
||||
DebugTimer::stop('viewRender');
|
||||
DebugTimer::stop('controllerRender');
|
||||
DebugMemory::record(__d('debug_kit', 'View render complete'));
|
||||
$this->_renderComplete = true;
|
||||
}
|
||||
|
||||
}
|
||||
106
exp/Plugin/DebugKit/View/Helper/FirePhpToolbarHelper.php
Normal file
106
exp/Plugin/DebugKit/View/Helper/FirePhpToolbarHelper.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
|
||||
App::uses('FireCake', 'DebugKit.Lib');
|
||||
|
||||
/**
|
||||
* FirePHP Toolbar Helper
|
||||
*
|
||||
* Injects the toolbar elements into non-HTML layouts via FireCake.
|
||||
*
|
||||
*/
|
||||
class FirePhpToolbarHelper extends ToolbarHelper {
|
||||
|
||||
/**
|
||||
* settings property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array('format' => 'firePHP', 'forceEnable' => false);
|
||||
|
||||
/**
|
||||
* send method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function send() {
|
||||
$view = $this->_View;
|
||||
$view->element('debug_toolbar', array('disableTimer' => true), array('plugin' => 'DebugKit'));
|
||||
}
|
||||
|
||||
/**
|
||||
* makeNeatArray.
|
||||
*
|
||||
* wraps FireCake::dump() allowing panel elements to continue functioning
|
||||
*
|
||||
* @param string $values
|
||||
* @return void
|
||||
*/
|
||||
public function makeNeatArray($values) {
|
||||
FireCake::info($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a simple message
|
||||
*
|
||||
* @param string $label Label of message
|
||||
* @param string $message Message content
|
||||
* @return void
|
||||
*/
|
||||
public function message($label, $message) {
|
||||
FireCake::log($message, $label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a table with FireCake
|
||||
*
|
||||
* @param array $rows Rows to print
|
||||
* @param array $headers Headers for table
|
||||
* @param array $options Additional options and params
|
||||
* @return void
|
||||
*/
|
||||
public function table($rows, $headers, $options = array()) {
|
||||
$title = $headers[0];
|
||||
if (isset($options['title'])) {
|
||||
$title = $options['title'];
|
||||
}
|
||||
foreach ($rows as $i => $row) {
|
||||
$rows[$i] = array_values($row);
|
||||
}
|
||||
array_unshift($rows, $headers);
|
||||
FireCake::table($title, $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a panel which is a 'Group' in FirePHP
|
||||
*
|
||||
* @param $title
|
||||
* @param $anchor
|
||||
* @return void
|
||||
*/
|
||||
public function panelStart($title, $anchor) {
|
||||
FireCake::group($title);
|
||||
}
|
||||
|
||||
/**
|
||||
* End a panel (Group)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function panelEnd() {
|
||||
FireCake::groupEnd();
|
||||
}
|
||||
|
||||
}
|
||||
238
exp/Plugin/DebugKit/View/Helper/HtmlToolbarHelper.php
Normal file
238
exp/Plugin/DebugKit/View/Helper/HtmlToolbarHelper.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
|
||||
App::uses('Security', 'Utility');
|
||||
|
||||
/**
|
||||
* Html Toolbar Helper
|
||||
*
|
||||
* Injects the toolbar elements into HTML layouts.
|
||||
* Contains helper methods for
|
||||
*
|
||||
* @since DebugKit 0.1
|
||||
*/
|
||||
class HtmlToolbarHelper extends ToolbarHelper {
|
||||
|
||||
/**
|
||||
* helpers property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $helpers = array('Html', 'Form');
|
||||
|
||||
/**
|
||||
* settings property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array('format' => 'html', 'forceEnable' => false);
|
||||
|
||||
/**
|
||||
* Recursively goes through an array and makes neat HTML out of it.
|
||||
*
|
||||
* @param mixed $values Array to make pretty.
|
||||
* @param integer $openDepth Depth to add open class
|
||||
* @param integer $currentDepth current depth.
|
||||
* @param boolean $doubleEncode
|
||||
* @return string
|
||||
*/
|
||||
public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubleEncode = false) {
|
||||
static $printedObjects = null;
|
||||
if ($currentDepth === 0) {
|
||||
$printedObjects = new SplObjectStorage();
|
||||
}
|
||||
$className = "neat-array depth-$currentDepth";
|
||||
if ($openDepth > $currentDepth) {
|
||||
$className .= ' expanded';
|
||||
}
|
||||
$nextDepth = $currentDepth + 1;
|
||||
$out = "<ul class=\"$className\">";
|
||||
if (!is_array($values)) {
|
||||
if (is_bool($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
if ($values === null) {
|
||||
$values = array(null);
|
||||
}
|
||||
}
|
||||
if (empty($values)) {
|
||||
$values[] = '(empty)';
|
||||
}
|
||||
foreach ($values as $key => $value) {
|
||||
$out .= '<li><strong>' . h($key, $doubleEncode) . '</strong>';
|
||||
if (is_array($value) && count($value) > 0) {
|
||||
$out .= '(array)';
|
||||
} elseif (is_object($value)) {
|
||||
$out .= '(object)';
|
||||
}
|
||||
if ($value === null) {
|
||||
$value = '(null)';
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = '(false)';
|
||||
}
|
||||
if ($value === true) {
|
||||
$value = '(true)';
|
||||
}
|
||||
if (empty($value) && $value != 0) {
|
||||
$value = '(empty)';
|
||||
}
|
||||
if ($value instanceof Closure) {
|
||||
$value = 'function';
|
||||
}
|
||||
|
||||
$isObject = is_object($value);
|
||||
if ($isObject && $printedObjects->contains($value)) {
|
||||
$isObject = false;
|
||||
$value = ' - recursion';
|
||||
}
|
||||
|
||||
if ($isObject) {
|
||||
$printedObjects->attach($value);
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
$value instanceof ArrayAccess ||
|
||||
$value instanceof Iterator ||
|
||||
is_array($value) ||
|
||||
$isObject
|
||||
) && !empty($value)
|
||||
) {
|
||||
$out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode);
|
||||
} else {
|
||||
$out .= h($value, $doubleEncode);
|
||||
}
|
||||
$out .= '</li>';
|
||||
}
|
||||
$out .= '</ul>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTML message
|
||||
*
|
||||
* @param string $label label content
|
||||
* @param string $message message content
|
||||
* @return string
|
||||
*/
|
||||
public function message($label, $message) {
|
||||
return sprintf('<p><strong>%s</strong> %s</p>', $label, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a panel.
|
||||
* Make a link and anchor.
|
||||
*
|
||||
* @param $title
|
||||
* @param $anchor
|
||||
* @return string
|
||||
*/
|
||||
public function panelStart($title, $anchor) {
|
||||
$link = $this->Html->link($title, '#' . $anchor);
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a table.
|
||||
*
|
||||
* @param array $rows Rows to make.
|
||||
* @param array $headers Optional header row.
|
||||
* @return string
|
||||
*/
|
||||
public function table($rows, $headers = array()) {
|
||||
$out = '<table class="debug-table">';
|
||||
if (!empty($headers)) {
|
||||
$out .= $this->Html->tableHeaders($headers);
|
||||
}
|
||||
$out .= $this->Html->tableCells($rows, array('class' => 'odd'), array('class' => 'even'), false, false);
|
||||
$out .= '</table>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function send() {
|
||||
if (!$this->settings['forceEnable'] && Configure::read('debug') == 0) {
|
||||
return;
|
||||
}
|
||||
$view = $this->_View;
|
||||
$head = '';
|
||||
if (isset($view->viewVars['debugToolbarCss']) && !empty($view->viewVars['debugToolbarCss'])) {
|
||||
$head .= $this->Html->css($view->viewVars['debugToolbarCss']);
|
||||
}
|
||||
|
||||
$js = sprintf('window.DEBUGKIT_JQUERY_URL = "%s";', $this->webroot('/debug_kit/js/jquery.js'));
|
||||
$head .= $this->Html->scriptBlock($js);
|
||||
|
||||
if (isset($view->viewVars['debugToolbarJavascript'])) {
|
||||
foreach ($view->viewVars['debugToolbarJavascript'] as $script) {
|
||||
if ($script) {
|
||||
$head .= $this->Html->script($script);
|
||||
}
|
||||
}
|
||||
}
|
||||
$search = '</head>';
|
||||
$pos = strpos($view->output, $search);
|
||||
if ($pos !== false) {
|
||||
$view->output = substr_replace($view->output, $head . "\n</head>", $pos, strlen($search));
|
||||
}
|
||||
$toolbar = $view->element('debug_toolbar', array('disableTimer' => true), array('plugin' => 'DebugKit'));
|
||||
$search = '</body>';
|
||||
$pos = strrpos($view->output, $search);
|
||||
if ($pos !== false) {
|
||||
$view->output = substr_replace($view->output, $toolbar . "\n</body>", $pos, strlen($search));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a SQL explain link for a given query
|
||||
*
|
||||
* @param string $sql SQL query string you want an explain link for.
|
||||
* @param $connection
|
||||
* @return string Rendered Html link or '' if the query is not a select/describe
|
||||
*/
|
||||
public function explainLink($sql, $connection) {
|
||||
if (!preg_match('/^[\s()]*SELECT/i', $sql)) {
|
||||
return '';
|
||||
}
|
||||
$sql = str_replace(array("\n", "\t"), ' ', $sql);
|
||||
$hash = Security::hash($sql . $connection, 'sha1', true);
|
||||
$url = array(
|
||||
'plugin' => 'debug_kit',
|
||||
'controller' => 'toolbar_access',
|
||||
'action' => 'sql_explain'
|
||||
);
|
||||
foreach (Router::prefixes() as $prefix) {
|
||||
$url[$prefix] = false;
|
||||
}
|
||||
$this->explainLinkUid = (isset($this->explainLinkUid) ? $this->explainLinkUid + 1 : 0);
|
||||
$uid = $this->explainLinkUid . '_' . rand(0, 10000);
|
||||
$form = $this->Form->create('log', array('url' => $url, 'id' => "logForm{$uid}"));
|
||||
$form .= $this->Form->hidden('log.ds', array('id' => "logDs{$uid}", 'value' => $connection));
|
||||
$form .= $this->Form->hidden('log.sql', array('id' => "logSql{$uid}", 'value' => $sql));
|
||||
$form .= $this->Form->hidden('log.hash', array('id' => "logHash{$uid}", 'value' => $hash));
|
||||
$form .= $this->Form->submit(__d('debug_kit', 'Explain'), array(
|
||||
'div' => false,
|
||||
'class' => 'sql-explain-link'
|
||||
));
|
||||
$form .= $this->Form->end();
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
88
exp/Plugin/DebugKit/View/Helper/SimpleGraphHelper.php
Normal file
88
exp/Plugin/DebugKit/View/Helper/SimpleGraphHelper.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 1.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
App::uses('HtmlHelper', 'View/Helper');
|
||||
|
||||
/**
|
||||
* Class SimpleGraphHelper
|
||||
*
|
||||
* Allows creation and display of extremely simple graphing elements
|
||||
*
|
||||
* @since DebugKit 1.0
|
||||
*/
|
||||
class SimpleGraphHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Helpers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* Default settings to be applied to each Simple Graph
|
||||
*
|
||||
* Allowed options:
|
||||
*
|
||||
* - max => (int) Maximum value in the graphs
|
||||
* - width => (int)
|
||||
* - valueType => string (value, percentage)
|
||||
* - style => array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaultSettings = array(
|
||||
'max' => 100,
|
||||
'width' => 350,
|
||||
'valueType' => 'value',
|
||||
);
|
||||
|
||||
/**
|
||||
* bar method
|
||||
*
|
||||
* @param $value Value to be graphed
|
||||
* @param $offset how much indentation
|
||||
* @param array|\Graph $options Graph options
|
||||
* @return string Html graph
|
||||
*/
|
||||
public function bar($value, $offset, $options = array()) {
|
||||
$settings = array_merge($this->_defaultSettings, $options);
|
||||
extract($settings);
|
||||
|
||||
$graphValue = ($value / $max) * $width;
|
||||
$graphValue = max(round($graphValue), 1);
|
||||
|
||||
if ($valueType === 'percentage') {
|
||||
$graphOffset = 0;
|
||||
} else {
|
||||
$graphOffset = ($offset / $max) * $width;
|
||||
$graphOffset = round($graphOffset);
|
||||
}
|
||||
return $this->Html->div(
|
||||
'debug-kit-graph-bar',
|
||||
$this->Html->div(
|
||||
'debug-kit-graph-bar-value',
|
||||
' ',
|
||||
array(
|
||||
'style' => "margin-left: {$graphOffset}px; width: {$graphValue}px",
|
||||
'title' => __d('debug_kit', "Starting %sms into the request, taking %sms", $offset, $value),
|
||||
)
|
||||
),
|
||||
array('style' => "width: {$width}px;"),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
171
exp/Plugin/DebugKit/View/Helper/TidyHelper.php
Normal file
171
exp/Plugin/DebugKit/View/Helper/TidyHelper.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since v 1.0 (22-Jun-2009)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('File', 'Utility');
|
||||
|
||||
/**
|
||||
* TidyHelper class
|
||||
*
|
||||
* Passes html through tidy on the command line, and reports markup errors
|
||||
*
|
||||
* @uses AppHelper
|
||||
* @since v 1.0 (22-Jun-2009)
|
||||
*/
|
||||
class TidyHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* helpers property
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $helpers = array('DebugKit.Toolbar');
|
||||
|
||||
/**
|
||||
* results property
|
||||
*
|
||||
* @var mixed null
|
||||
*/
|
||||
public $results = null;
|
||||
|
||||
/**
|
||||
* Return a nested array of errors for the passed html string
|
||||
* Fudge the markup slightly so that the tag which is invalid is highlighted
|
||||
*
|
||||
* @param string $html ''
|
||||
* @param string $out ''
|
||||
* @return array
|
||||
*/
|
||||
public function process($html = '', &$out = '') {
|
||||
$errors = $this->tidyErrors($html, $out);
|
||||
|
||||
if (!$errors) {
|
||||
return array();
|
||||
}
|
||||
$result = array('Error' => array(), 'Warning' => array(), 'Misc' => array());
|
||||
$errors = explode("\n", $errors);
|
||||
$markup = explode("\n", $out);
|
||||
foreach ($errors as $error) {
|
||||
preg_match('@line (\d+) column (\d+) - (\w+): (.*)@', $error, $matches);
|
||||
if ($matches) {
|
||||
list($original, $line, $column, $type, $message) = $matches;
|
||||
$line = $line - 1;
|
||||
|
||||
$string = '</strong>';
|
||||
if (isset($markup[$line - 1])) {
|
||||
$string .= h($markup[$line - 1]);
|
||||
}
|
||||
$string .= '<strong>' . h(@$markup[$line]) . '</strong>';
|
||||
if (isset($markup[$line + 1])) {
|
||||
$string .= h($markup[$line + 1]);
|
||||
}
|
||||
$string .= '</strong>';
|
||||
|
||||
$result[$type][$string][] = h($message);
|
||||
} elseif ($error) {
|
||||
$message = $error;
|
||||
$result['Misc'][h($message)][] = h($message);
|
||||
}
|
||||
}
|
||||
$this->results = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* report method
|
||||
*
|
||||
* Call process if a string is passed, or no prior results exist - and return the results using
|
||||
* the toolbar helper to generate a nested navigatable array
|
||||
*
|
||||
* @param mixed $html null
|
||||
* @return string
|
||||
*/
|
||||
public function report($html = null) {
|
||||
if ($html) {
|
||||
$this->process($html);
|
||||
} elseif ($this->results === null) {
|
||||
$this->process($this->_View->output);
|
||||
}
|
||||
if (!$this->results) {
|
||||
return '<p>' . __d('debug_kit', 'No markup errors found') . '</p>';
|
||||
}
|
||||
foreach ($this->results as &$results) {
|
||||
foreach ($results as $type => &$messages) {
|
||||
foreach ($messages as &$message) {
|
||||
$message = html_entity_decode($message, ENT_COMPAT, Configure::read('App.encoding'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->Toolbar->makeNeatArray(array_filter($this->results), 0, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the html string through tidy, and return the (raw) errors. pass back a reference to the
|
||||
* normalized string so that the error messages can be linked to the line that caused them.
|
||||
*
|
||||
* @param string $in ''
|
||||
* @param string $out ''
|
||||
* @return string
|
||||
*/
|
||||
public function tidyErrors($in = '', &$out = '') {
|
||||
$out = preg_replace('@>\s*<@s', ">\n<", $in);
|
||||
|
||||
// direct access? windows etc
|
||||
if (function_exists('tidy_parse_string')) {
|
||||
$tidy = tidy_parse_string($out, array(), 'UTF8');
|
||||
$tidy->cleanRepair();
|
||||
$errors = $tidy->errorBuffer . "\n";
|
||||
return $errors;
|
||||
}
|
||||
|
||||
// cli
|
||||
$File = new File(rtrim(TMP, DS) . DS . rand() . '.html', true);
|
||||
$File->write($out);
|
||||
$path = $File->pwd();
|
||||
$errors = $path . '.err';
|
||||
$this->_exec("tidy -eq -utf8 -f $errors $path");
|
||||
$File->delete();
|
||||
|
||||
if (!file_exists($errors)) {
|
||||
return '';
|
||||
}
|
||||
$Error = new File($errors);
|
||||
$errors = $Error->read();
|
||||
$Error->delete();
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* exec method
|
||||
*
|
||||
* @param mixed $cmd
|
||||
* @param mixed $out null
|
||||
* @return boolean True if successful
|
||||
*/
|
||||
protected function _exec($cmd, &$out = null) {
|
||||
if (DS === '/') {
|
||||
$_out = exec($cmd . ' 2>&1', $out, $return);
|
||||
} else {
|
||||
$_out = exec($cmd, $out, $return);
|
||||
}
|
||||
|
||||
if (Configure::read('debug')) {
|
||||
$source = Debugger::trace(array('depth' => 1, 'start' => 2)) . "\n";
|
||||
//CakeLog::write('system_calls_' . date('Y-m-d'), "\n" . $source . Debugger::exportVar(compact('cmd','out','return')));
|
||||
//CakeLog::write('system_calls', "\n" . $source . Debugger::exportVar(compact('cmd','out','return')));
|
||||
}
|
||||
if ($return) {
|
||||
return false;
|
||||
}
|
||||
return $_out ? $_out : true;
|
||||
}
|
||||
}
|
||||
226
exp/Plugin/DebugKit/View/Helper/ToolbarHelper.php
Normal file
226
exp/Plugin/DebugKit/View/Helper/ToolbarHelper.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DebugKitDebugger', 'DebugKit.Lib');
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
App::uses('ConnectionManager', 'Model');
|
||||
|
||||
/**
|
||||
* Provides Base methods for content specific debug toolbar helpers.
|
||||
* Acts as a facade for other toolbars helpers as well.
|
||||
*
|
||||
* @since DebugKit 0.1
|
||||
*/
|
||||
class ToolbarHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* settings property to be overloaded. Subclasses should specify a format
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array();
|
||||
|
||||
/**
|
||||
* flag for whether or not cache is enabled.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_cacheEnabled = false;
|
||||
|
||||
/**
|
||||
* Construct the helper and make the backend helper.
|
||||
*
|
||||
* @param $View
|
||||
* @param array|string $options
|
||||
* @return \ToolbarHelper
|
||||
*/
|
||||
public function __construct($View, $options = array()) {
|
||||
$this->_myName = strtolower(get_class($this));
|
||||
$this->settings = array_merge($this->settings, $options);
|
||||
|
||||
if ($this->_myName !== 'toolbarhelper') {
|
||||
parent::__construct($View, $options);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($options['output'])) {
|
||||
$options['output'] = 'DebugKit.HtmlToolbar';
|
||||
}
|
||||
$className = $options['output'];
|
||||
if (strpos($options['output'], '.') !== false) {
|
||||
list($plugin, $className) = explode('.', $options['output']);
|
||||
}
|
||||
$this->_backEndClassName = $className;
|
||||
$this->helpers[$options['output']] = $options;
|
||||
if (isset($options['cacheKey']) && isset($options['cacheConfig'])) {
|
||||
$this->_cacheKey = $options['cacheKey'];
|
||||
$this->_cacheConfig = $options['cacheConfig'];
|
||||
$this->_cacheEnabled = true;
|
||||
}
|
||||
|
||||
parent::__construct($View, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* afterLayout callback
|
||||
*
|
||||
* @param string $layoutFile
|
||||
* @return void
|
||||
*/
|
||||
public function afterLayout($layoutFile) {
|
||||
if (!$this->request->is('requested')) {
|
||||
$this->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the backend Helper
|
||||
* used to conditionally trigger toolbar output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->_backEndClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* call__
|
||||
*
|
||||
* Allows method calls on backend helper
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed $params
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
if (method_exists($this->{$this->_backEndClassName}, $method)) {
|
||||
return $this->{$this->_backEndClassName}->dispatchMethod($method, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows for writing to panel cache from view.
|
||||
* Some panels generate all variables in the view by
|
||||
* necessity ie. Timer. Using this method, will allow you to replace in full
|
||||
* the content for a panel.
|
||||
*
|
||||
* @param string $name Name of the panel you are replacing.
|
||||
* @param string $content Content to write to the panel.
|
||||
* @return boolean Success of write.
|
||||
*/
|
||||
public function writeCache($name, $content) {
|
||||
if (!$this->_cacheEnabled) {
|
||||
return false;
|
||||
}
|
||||
$existing = (array)Cache::read($this->_cacheKey, $this->_cacheConfig);
|
||||
$existing[0][$name]['content'] = $content;
|
||||
return Cache::write($this->_cacheKey, $existing, $this->_cacheConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the toolbar
|
||||
*
|
||||
* @param string $name Name of the panel you want cached data for
|
||||
* @param integer $index
|
||||
* @return mixed Boolean false on failure, array of data otherwise.
|
||||
*/
|
||||
public function readCache($name, $index = 0) {
|
||||
if (!$this->_cacheEnabled) {
|
||||
return false;
|
||||
}
|
||||
$existing = (array)Cache::read($this->_cacheKey, $this->_cacheConfig);
|
||||
if (!isset($existing[$index][$name]['content'])) {
|
||||
return false;
|
||||
}
|
||||
return $existing[$index][$name]['content'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the query logs for the given connection names.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - explain - Whether explain links should be generated for this connection.
|
||||
* - cache - Whether the toolbar_state Cache should be updated.
|
||||
* - threshold - The threshold at which a visual 'maybe slow' flag should be added.
|
||||
* results with rows/ms lower than $threshold will be marked.
|
||||
*
|
||||
* @param string $connection Connection name to get logs for.
|
||||
* @param array $options Options for the query log retrieval.
|
||||
* @return array Array of data to be converted into a table.
|
||||
*/
|
||||
public function getQueryLogs($connection, $options = array()) {
|
||||
$options += array('explain' => false, 'cache' => true, 'threshold' => 20);
|
||||
$db = ConnectionManager::getDataSource($connection);
|
||||
|
||||
if (!method_exists($db, 'getLog')) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$log = $db->getLog();
|
||||
|
||||
$out = array(
|
||||
'queries' => array(),
|
||||
'count' => $log['count'],
|
||||
'time' => $log['time']
|
||||
);
|
||||
foreach ($log['log'] as $i => $query) {
|
||||
$query += array('query' => null);
|
||||
$isSlow = (
|
||||
$query['took'] > 0 &&
|
||||
$query['numRows'] / $query['took'] != 1 &&
|
||||
$query['numRows'] / $query['took'] <= $options['threshold']
|
||||
);
|
||||
$query['actions'] = '';
|
||||
$isHtml = ($this->getName() === 'HtmlToolbar');
|
||||
if ($isSlow && $isHtml) {
|
||||
$query['actions'] = sprintf(
|
||||
'<span class="slow-query">%s</span>',
|
||||
__d('debug_kit', 'maybe slow')
|
||||
);
|
||||
} elseif ($isSlow) {
|
||||
$query['actions'] = '*';
|
||||
}
|
||||
if ($options['explain'] && $isHtml) {
|
||||
$query['actions'] .= $this->explainLink($query['query'], $connection);
|
||||
}
|
||||
if ($isHtml) {
|
||||
$query['query'] = h($query['query']);
|
||||
if (!empty($query['params']) && is_array($query['params'])) {
|
||||
$bindParam = $bindType = null;
|
||||
if (preg_match('/.+ :.+/', $query['query'])) {
|
||||
$bindType = true;
|
||||
}
|
||||
foreach ($query['params'] as $bindKey => $bindVal) {
|
||||
if ($bindType === true) {
|
||||
$bindParam .= h($bindKey) . " => " . h($bindVal) . ", ";
|
||||
} else {
|
||||
$bindParam .= h($bindVal) . ", ";
|
||||
}
|
||||
}
|
||||
$query['query'] .= " [ " . rtrim($bindParam, ', ') . " ]";
|
||||
}
|
||||
}
|
||||
unset($query['params']);
|
||||
$out['queries'][] = $query;
|
||||
}
|
||||
if ($options['cache']) {
|
||||
$existing = $this->readCache('sql_log');
|
||||
$existing[$connection] = $out;
|
||||
$this->writeCache('sql_log', $existing);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
}
|
||||
30
exp/Plugin/DebugKit/View/ToolbarAccess/history_state.ctp
Normal file
30
exp/Plugin/DebugKit/View/ToolbarAccess/history_state.ctp
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Toolbar history state view.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 1.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$panels = array();
|
||||
foreach ($toolbarState as $panelName => $panel) {
|
||||
if (!empty($panel) && !empty($panel['elementName'])) {
|
||||
$panels[$panelName] = $this->element($panel['elementName'], array(
|
||||
'content' => $panel['content']
|
||||
), array(
|
||||
'plugin' => Inflector::camelize($panel['plugin'])
|
||||
));
|
||||
}
|
||||
}
|
||||
echo json_encode($panels);
|
||||
Configure::write('debug', 0);
|
||||
11
exp/Plugin/DebugKit/View/ToolbarAccess/sql_explain.ctp
Normal file
11
exp/Plugin/DebugKit/View/ToolbarAccess/sql_explain.ctp
Normal file
@@ -0,0 +1,11 @@
|
||||
<table class="sql-log-query-explain debug-table">
|
||||
<?php
|
||||
$headers = array_shift($result);
|
||||
|
||||
echo $this->Html->tableHeaders($headers);
|
||||
echo $this->Html->tableCells($result);
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
// Consume and toss out the timers
|
||||
$timers = DebugKitDebugger::getTimers(true);
|
||||
Reference in New Issue
Block a user