=') ) {
exit('Suspect requires PHP 5.2.x or higher to run. You are currently running PHP ' . PHP_VERSION . '.');
}
global $wp_version;
if( ! version_compare($wp_version, '2.9', '>=') ) {
exit('Suspect requires Wordpress 2.9.x or higher to run. You are currently running Wordpress ' . $wp_version . '.');
}
define('SUSPECTPATH', dirname(__FILE__));
require(SUSPECTPATH . '/keywords.php');
/**
* Suspect Class
*
* Generate basic profiling information
*/
class Suspect {
public $total_query_time = 0;
/**
* Suspect Constructor
*
* Add actions and hook everything up
*/
public function __construct() {
add_action('wp_print_footer_scripts', array($this, 'run'), 20);
add_action('init', array($this, 'init'));
if ( !defined('SAVEQUERIES') )
define('SAVEQUERIES', TRUE);
}
/**
* Run Suspect
*
* @return void
*/
public function run() {
global $wp_actions, $wpdb;
include(SUSPECTPATH.'/views/suspect_view.php');
}
/**
* Output POST data
*
* @return void
*/
public function post_data() {
$output = "\n";
if( count($_POST) == 0 ) {
$output .= "
| No POST data |
\n";
}
else {
foreach( $_POST as $key => $val ) {
if( !is_numeric($key) ) {
$key = "'{$key}'";
}
$output .= "| $_POST[{$key}] | ";
$output .= "";
if( is_array($val) ) {
$output .= "" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . " ";
}
else {
$output .= htmlspecialchars(stripslashes($val));
}
$output .= " |
\n";
}
}
echo $output;
}
/**
* Output database information
*
* @return void
*/
public function wpdb_data()
{
global $wpdb, $sp_mysql_keywords;
$output = "\n";
// Key words highlight pattern
$pattern = implode('\b|\b', $sp_mysql_keywords);
$pattern = "/(\b{$pattern}\b)/";
if( count($wpdb->queries) == 0 ) {
$output .= "| No queries |
\n";
} else {
foreach( $wpdb->queries as $key => $val ) {
$query = $val[0];
$index = $key + 1;
$this->total_query_time += $val[1];
// Highlight key words
$query = preg_replace($pattern, '$1', $query);
// Highlight strings
$query = preg_replace("%'([a-zA-Z_]+)?'%", '\'$1\'', $query);
$output .= '| ' . $index . ' | ' . $query . ' | ' . (number_format($val[1], 4) * 1000) . ' |
';
}
}
echo $output;
}
/**
* Enqueue Javascript & CSS files
*
* @return void
*/
public function init() {
wp_enqueue_script('jquery-cookie', WP_PLUGIN_URL . '/suspect/js/jquery.cookie.js', array('jquery'));
wp_enqueue_script('suspect_script', WP_PLUGIN_URL . '/suspect/js/suspect.js', array('jquery'), '0.1');
wp_enqueue_style('suspect_styles', WP_PLUGIN_URL . '/suspect/css/suspect.css', array(), '0.1', 'screen');
}
}
$suspect = new Suspect();