Location: PHPKode > scripts > Simple Debug > simple-debug/plugin-admin.php
<?php

class Simple_Debug_Admin extends Simple_Debug {
	/**
	 * Error messages to diplay
	 *
	 * @var array
	 */
	private $_messages = array();
	
	private $_hook_count = 0;
	
	
	/**
	 * Class constructor
	 *
	 */
	public function __construct() {
		$this->_plugin_dir   = DIRECTORY_SEPARATOR . str_replace(basename(__FILE__), null, plugin_basename(__FILE__));
		$this->_settings_url = 'options-general.php?page=' . plugin_basename(__FILE__);
		
		$allowed_options = array(
			
		);
		
		$_SESSION['simple_debug'] = NULL;
		unset($_SESSION['simple_debug']);
		
		if ( !defined( 'SAVEQUERIES' ) )
			define( 'SAVEQUERIES', TRUE );
		
		
		add_action('init', array(&$this, 'save_options'));
		

		// register installer function
		register_activation_hook(SD_LOADER, array(&$this, 'activateSimpleDebug'));
	
		// add plugin "Settings" action on plugin list
		add_action('plugin_action_links_' . plugin_basename(SD_LOADER), array(&$this, 'add_plugin_actions'));
		
		// add links for plugin help, donations,...
		add_filter('plugin_row_meta', array(&$this, 'add_plugin_links'), 10, 2);
		
		// push options page link, when generating admin menu
		add_action('admin_menu', array(&$this, 'adminMenu'));
		
		
		

		//add help menu
		add_filter('contextual_help', array(&$this,'adminHelp'), 10, 3);
		
		
		add_action("shutdown", array(&$this, 'process_shutdown'));
		

		$debug_enabled = $this->get_option('simple_debug_enabled'); 
		if($debug_enabled === "true"){
			//adds debug output below the footer
			add_action( 'all', array(&$this, 'log_hook_debug'),10,1);
		}
		
		

		$debug_log_enabled = $this->get_option('simple_debug_log_enabled'); 
		if( "true" === $debug_log_enabled ){
			// basically the same as setting WP_DEBUG = true in wp-config.php
			// will create a debug.log file in the wp-content directory
			add_action('init', array(&$this, 'enable_wp_debug_mode'));
			
			$debug_log_manager = new Simple_Debug_Log_Manager();
			$this->debug_log_manager = $debug_log_manager;

			add_action( 'admin_head', array($debug_log_manager, 'screen_options') );
			add_action( 'admin_menu', array($debug_log_manager, 'simple_debug_log_admin_menu') );
		
		}
		
		//$mwa_plugins_list = new MWA_Plugins_List();
		//$this->mwa_plugins_list = $mwa_plugins_list;

		//add_action( 'admin_head', array($mwa_plugins_list, 'screen_options') );
		//add_action( 'admin_menu', array($mwa_plugins_list, 'mwa_plugins_list_page_admin_menu') );
		
		
	}
	
	

	


	function save_options(){
		if(is_admin()){
			if(isset($_GET['page']) &&  "simple-debug/plugin-admin.php" == $_GET['page']){
				if(isset($_POST['Submit'])) {
					foreach($this->_options as $option => $value) {
						if(array_key_exists($option, $_POST)) {
							update_option($option, $_POST[$option]);
						} else {
							update_option($option, $value);
						}
					}
		
					$this->_messages['updated'][] = 'Options updated!';
				}
		
			}
		}
	
	}




	public function enable_wp_debug_mode(){
	
		error_reporting( E_ALL );
		ini_set( 'display_errors', 0 );
		ini_set( 'log_errors', 1 );
		ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
		
		//error_log('Simple Debug Plugin: Debug Log Test!');
		
	}

		
	
	/**
	 * Add "Settings" action on installed plugin list
	 */
	public function add_plugin_actions($links) {
		array_unshift($links, '<a href="options-general.php?page=' . plugin_basename(__FILE__) . '">' . __('Settings') . '</a>');
		
		return $links;
	}
	
	/**
	 * Add links on installed plugin list
	 */
	public function add_plugin_links($links, $file) {
		if($file == plugin_basename(SD_LOADER)) {
			$rate_url = 'http://wordpress.org/support/view/plugin-reviews/' . basename(dirname(__FILE__)) . '?rate=5#postform';
			$links[] = '<a href="'.$rate_url.'" target="_blank" title="Click Here to Rate and Review this Plugin on WordPress.org">Rate This Plugin</a>';

		}
		
		return $links;
	}
	
	/**
	 * Add menu entry for Simple Debug settings and attach style and script include methods
	 */
	public function adminMenu() {		
		// add option in admin menu
		global $simple_debug_admin_page;
		$simple_debug_admin_page = add_options_page('Simple Debug Plugin Options', 'Simple Debug', 'manage_options', __FILE__, array(&$this, 'optionsPage'));

		add_action('admin_print_styles-' . $simple_debug_admin_page,     array(&$this, 'installStyles'));
	}
	
	
	
	public function adminHelp($contextual_help, $screen_id, $screen){
	
		global $simple_debug_admin_page;
		
		if ($screen_id == $simple_debug_admin_page) {
			
			$support_the_dev = $this->display_support_us();
			$screen->add_help_tab(array(
				'id' => 'developer-support',
				'title' => "Support the Developer",
				'content' => "<h2>Support the Developer</h2><p>".$support_the_dev."</p>"
			));
			
			$screen->add_help_tab(array(
				'id' => 'plugin-support',
				'title' => "Plugin Support",
				'content' => "<h2>Support</h2><p>For Plugin Support please visit <a href='http://mywebsiteadvisor.com/support/' target='_blank'>MyWebsiteAdvisor.com</a></p>"
			));
			
			$faqs = "<p><b>Question: What do the site debugging tools do?</b><br>Answer: These tools can be used to isolate slow functions and to look for errors causing your website to perform poorly.</p>";
			
			$faqs .= "<p><b>Question: What do the PHP Settings Tools Do?</b><br>Answer: These can be used to inspect the current Web Server PHP settings for variables such as memory allocation.</p>";
			
			$faqs .= "<p><b>Question: What do the Database Tools Do?</b><br>Answer: These tools can be used to view and analyze the MySQL Database server performance variables such as the query cache.</p>";
			
			
			$screen->add_help_tab(array(
				'id' => 'plugin-faq',
				'title' => "Plugin FAQ's",
				'content' => "<h2>Frequently Asked Questions</h2>".$faqs
			));
			
			$screen->add_help_tab(array(
				'id' => 'plugin-upgrades',
				'title' => "Plugin Upgrades",
				'content' => "<h2>Plugin Upgrades</h2><p>Learn about all of our free plugins for WordPress here: <a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/' target='_blank'>MyWebsiteAdvisor.com</a></p>"
			));
	
			$screen->set_help_sidebar("<p>Please Visit us online for more Free WordPress Plugins!</p><p><a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/' target='_blank'>MyWebsiteAdvisor.com</a></p><br>");
			//$contextual_help = 'HELP!';
		}
			
		//return $contextual_help;

	}

	
	
	
		
	public function display_support_us(){
				
		$string = '<p><b>Thank You for using the Simple Debug Plugin for WordPress!</b></p>';
		$string .= "<p>Please take a moment to <b>Support the Developer</b> by doing some of the following items:</p>";
		
		$rate_url = 'http://wordpress.org/support/view/plugin-reviews/' . basename(dirname(__FILE__)) . '?rate=5#postform';
		$string .= "<li><a href='$rate_url' target='_blank' title='Click Here to Rate and Review this Plugin on WordPress.org'>Click Here</a> to Rate and Review this Plugin on WordPress.org!</li>";
		
		$string .= "<li><a href='http://facebook.com/MyWebsiteAdvisor' target='_blank' title='Click Here to Follow us on Facebook'>Click Here</a> to Follow MyWebsiteAdvisor on Facebook!</li>";
		$string .= "<li><a href='http://twitter.com/MWebsiteAdvisor' target='_blank' title='Click Here to Follow us on Twitter'>Click Here</a> to Follow MyWebsiteAdvisor on Twitter!</li>";
		$string .= "<li><a href='http://mywebsiteadvisor.com/tools/premium-wordpress-plugins/' target='_blank' title='Click Here to Purchase one of our Premium WordPress Plugins'>Click Here</a> to Purchase Premium WordPress Plugins!</li>";
	
		return $string;
	}

	
	
	
	
	/**
	 * Include styles used by Simple Debug Plugin
	 */
	public function installStyles() {
		//wp_enqueue_style('simple-backup', WP_PLUGIN_URL . $this->_plugin_dir . 'style.css');
	}
	


	function setup_simple_debug_logger(){
	
		add_action( 'all', array(&$this, 'log_hook_debug'),10,1);
	
	}
	
	
	private function exec_tail_file($filename, $count = 10){
		
		ob_start();
		passthru("tail -n $count $filename");
		$result=ob_get_contents();
		
		ob_end_clean();
		
		return $result;
	}
	
	
	
	public function get_debug_log(){
	
		
		$log_txt = $this->exec_tail_file($log_file, 100);
		$log_contents = explode("\n", $log_txt);
		
		$messages = array();
		foreach($log_contents as $item){
			$messages[] = $item;
		}
		
		return $messages;
	
	
	}
	
	
	
	public function display_error_log($log_file){
	
		if( ini_get('safe_mode') ){
			echo "<p><font color='red'>PHP Safe Mode is enabled!<br><b>Disable Safe Mode in php.ini!</b></font></p>";
		}

		if(strpos(ini_get('disable_functions'), 'passthru')  !== false){
			echo "<p><font color='red'>Disabled Functions: ".ini_get('disable_functions')."<br><b>Please enable 'exec' function in php.ini!</b></font></p>";
		}
				
		echo "<p>Reading Log File: $log_file<p>";
		
		
		$log_txt = $this->exec_tail_file($log_file, 10);
		$log_contents = explode("\n", $log_txt);
		
		foreach($log_contents as $item){
			echo "<p>$item</p>";
		}
	
	}
	
	
	
	
	
	public function display_db_vars_table($result){
		if (mysql_num_rows($result)){
			echo "<table border='1'>";
			echo "<tr><th>Variable Name</th><th>Value</th></tr>";
			while ($row = mysql_fetch_assoc($result)){
				echo "<tr>";
				
					echo "<td>" . $row['Variable_name'] . "</td>";
					echo "<td>" . $row['Value'] . "</td>";
				
				echo "<tr>";
			}
			echo "</table>";
		}
	}
	
	
	public function db_performance_check(){

		$query = 'show variables where Variable_Name IN ("max_connections", "wait_timeout", "thread_cache_size", "table_cache", "key_buffer_size", "tmp_table_size");';
		$result = mysql_query($query);
		if (mysql_num_rows($result)){
			echo "DB Performance Variables<br>";
			$this->display_db_vars_table($result);
			echo "<br>";
		}


		$perf_query = "show variables like '%query_cache%'";
		$result = mysql_query($perf_query);
		if (mysql_num_rows($result)){
			//while ($row = mysql_fetch_assoc($result)){
				echo "DB Query Cache Variables<br>";
				$this->display_db_vars_table($result);
				echo "<br>";
	
			//}
		}
		
		$perf_query2 = "SHOW STATUS LIKE 'Qc%';";
		$result = mysql_query($perf_query2);
		if (mysql_num_rows($result)){
			//while ($row = mysql_fetch_assoc($result)){
				echo "DB Status Variables";
				$this->display_db_vars_table($result);
	
			//}
		}
	}
	
	
	
	public function performDatabaseOptimization(){
		
		$initial_table_size = 0;
		$final_table_size = 0;
		
		//$debug_enabled = $this->get_option('debug_enabled');
		
		
		
		echo "<br>Optimizing Database...<br>";
		
		$local_query = 'SHOW TABLE STATUS FROM `'. DB_NAME.'`';
		$result = mysql_query($local_query);
		if (mysql_num_rows($result)){
			
			while ($row = mysql_fetch_array($result)){
				//var_dump($row);
				
				$table_size = ($row[ "Data_length" ] + $row[ "Index_length" ]) / 1024;
				
				$optimize_query = "OPTIMIZE TABLE ".$row['Name'];
				if(mysql_query($optimize_query)){
				
					//if( $debug_enabled == "true"){
						echo "Table: " . $row['Name'] . " optimized!";
						echo "<br>";
					//}
				}
				
				$initial_table_size += $table_size; 
				
			}
			
			echo "Done!<br>";
			
		}
		
		
		
		
		$local_query = 'SHOW TABLE STATUS FROM `'. DB_NAME.'`';
		$result = mysql_query($local_query);
		if (mysql_num_rows($result)){
			while ($row = mysql_fetch_array($result)){
				$table_size = ($row[ "Data_length" ] + $row[ "Index_length" ]) / 1024;
				$final_table_size += $table_size;
			}
		}
		
		
		
		echo "<br>";
		echo "Initial DB Size: " . number_format($initial_table_size, 2) . " KB<br>";
		echo "Final DB Size: " . number_format($final_table_size, 2) . " KB<br>";
		
		$space_saved = $initial_table_size - $final_table_size;
		$opt_pctg = 100 * ($space_saved / $initial_table_size);
		echo "Space Saved: " . number_format($space_saved,2) . " KB  (" .  number_format($opt_pctg, 2) . "%)<br>";
		echo "<br>";
	
	}
	


	
	
	
	
	function log_hook_debug($hook){
		
		global $wpdb;
		
		//$previous_hook = $this->_hook_count - 1;
		if($this->_hook_count == 0){
			$_SESSION['simple_debug'] = NULL;
			unset($_SESSION['simple_debug']);
		}
		
		$hook_log['name'] = $hook;
		$hook_log['order'] = $this->_hook_count;
		
		//$hook_log['arguments'] = func_get_args();
		//$hook_log['backtrace'] = debug_backtrace();

		
		$hook_log['mem_useage'] = memory_get_usage();
		$hook_log['max_mem_useage'] = memory_get_peak_usage();
		
		//log query count as well as calculate elapsed 'new' queries
		$hook_log['query_count'] = get_num_queries();
		
		$previous_hook_query_count = ($this->_hook_count > 0) ? $_SESSION['simple_debug'][($this->_hook_count - 1)]['query_count'] : $hook_log['query_count'];
		$hook_log['elapsed_query_count'] = $hook_log['query_count'] - $previous_hook_query_count;
		
		//log time as well as calculate elapsed time since last hook
		$hook_log['time'] =  (float) microtime(true); 
		
		$previous_hook_time = ($this->_hook_count > 0) ? $_SESSION['simple_debug'][($this->_hook_count - 1)]['time'] : $hook_log['time'];
		$hook_log['elapsed_time'] =  (float) $hook_log['time'] - $previous_hook_time;
		
		//$_SESSION['simple_debug'] = NULL;
		//unset($_SESSION['simple_debug']);
		
		$_SESSION['simple_debug'][$this->_hook_count] = $hook_log;
		$this->_hook_count++;
	}
	
	

	function print_debug_data(){
	
		global $wpdb;
		
		$original_list = $_SESSION['simple_debug'];
		
		usort($_SESSION['simple_debug'], function($a, $b){
			if ($b['elapsed_time'] == $a['elapsed_time']) {
        		return 0;
    		}
    		return ($b['elapsed_time'] < $a['elapsed_time']) ? -1 : 1;
			//return  $b['elapsed_time'] - $a['elapsed_time'];
	
		});
	
		
		
		//$this->HtmlPrintBoxHeader('simple_debug',__('Simple Debug Plugin','simple_debug'),true); 
	
	echo "<h2>Simple Debug</h2>";
		echo "<hr>";
			?>
		
		<div  style="height:20px; vertical-align:top; width:50%; float:right; text-align:right; margin-top:5px; padding-right:16px; position:relative;">

		<div id="fb-root"></div>
		<script>(function(d, s, id) {
		  var js, fjs = d.getElementsByTagName(s)[0];
		  if (d.getElementById(id)) return;
		  js = d.createElement(s); js.id = id;
		  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=253053091425708";
		  fjs.parentNode.insertBefore(js, fjs);
		}(document, 'script', 'facebook-jssdk'));</script>
		
		<div class="fb-like" data-href="http://www.facebook.com/MyWebsiteAdvisor" data-send="true" data-layout="button_count" data-width="450" data-show-faces="false"></div>
		
		
		<a href="https://twitter.com/MWebsiteAdvisor" class="twitter-follow-button" data-show-count="false"  >Follow @MWebsiteAdvisor</a>
		<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
	
	
	</div>
	
	<?php
	
	
		
		
		$debug_count = count($_SESSION['simple_debug']);
		echo "<p>Analyzed ".$debug_count." functions.</p>";
		
		$final_hook_number = ($debug_count-1);
		$total_et = number_format(($original_list[$final_hook_number]['time'] - $original_list[0]['time']), 6);
		
		//echo "<p>Page Start Time: ". $original_list[0]['time'] ." seconds.</p>";
		//echo "<p>Page Finish Time: ". $original_list[$final_hook_number]['time'] ." seconds.</p>";
		
		
		echo "<table border=1 width='400px'>";
		
	
		echo "<tr>";
		echo "<td>Total Page Execution Time</td><td>". $total_et ." seconds.</td>";
		echo "</tr>";
	
	
		
		
		//if ( QUERY_CACHE_TYPE_OFF )
			//$wpdb->query( 'SET SESSION query_cache_type = 0;' );
			
		if ( $wpdb->queries ) {
			$total_query_time = 0;
			
			foreach ( $wpdb->queries as $q ) {

				$total_query_time += $q[1];
				
			}
		}
	
		echo "<tr>";
		echo "<td>Total Query Time </td><td>" . number_format($total_query_time, 6)." seconds.</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td>Average Hook Execution Time</td><td>". number_format(($total_et / $debug_count),8) ." seconds. </td>";
		echo "</tr>";
		echo "</table>";
		
		
		
		echo "<br>";
		echo "<h2>Slowest Function Call</h2>";
		echo "<table border=1 width='400px'>";
		
		echo "<tr>";
		echo "<th>Function Name</th>";
		echo "<th>Execution Order #</th>";
		echo "<th>Time to Execute Function</th>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td>". $_SESSION['simple_debug'][0]['name'] . "</td>";
		echo "<td>" . $_SESSION['simple_debug'][0]['order'] . "</td>";
		echo "<td>" . number_format($_SESSION['simple_debug'][0]['elapsed_time'], 6) ." seconds. </td>";
		echo "</tr>";
		echo "</table>";
		
		
		
		echo "<br>";
		echo "<h2>Top 5 Slowest Function/Hooks</h2>";
		echo "<table border=1 width='400px'>";
		
		echo "<tr>";
		echo "<th>Function Name</th>";
		echo "<th>Time to Execute Function</th>";
		echo "</tr>";
		
		foreach(array_slice($_SESSION['simple_debug'], 0, 5) as $slow_hook){
		
			echo "<tr>";
			echo "<td>" . $slow_hook['name'] . " </td>";
			echo "<td>" . number_format($slow_hook['elapsed_time'], 6) . " seconds. </td>";
			echo "</tr>";
		
		}
		echo "</table>";
		
		
		
		//$this->HtmlPrintBoxFooter(true);
		
		
	}
	
	
	
	

	function process_shutdown(){
	
		// Only show the data if the user is an administrator
		global $user_ID;

		$debug_enabled = $this->get_option('simple_debug_enabled');

		if( $user_ID ){
			if( current_user_can('level_10') && $debug_enabled === 'true'){
			
				echo "<div style='padding:20px;'>";
				$this->print_debug_data();
				echo "</div >";
				
			}
		}
	}






	function HtmlPrintBoxHeader($id, $title, $right = false) {
		
		?>
		<div id="<?php echo $id; ?>" class="postbox">
			<h3 class="hndle"><span><?php echo $title ?></span></h3>
			<div class="inside">
		<?php
		
		
	}
	
	function HtmlPrintBoxFooter( $right = false) {
		?>
			</div>
		</div>
		<?php
		
	}







		public function display_social_media(){
	
	$social = '<style>

.fb_edge_widget_with_comment {
	position: absolute;
	top: 0px;
	right: 200px;
}

</style>

<div  style="height:20px; vertical-align:top; width:50%; float:right; text-align:right; margin-top:5px; padding-right:16px; position:relative;">

	<div id="fb-root"></div>
	<script>(function(d, s, id) {
	  var js, fjs = d.getElementsByTagName(s)[0];
	  if (d.getElementById(id)) return;
	  js = d.createElement(s); js.id = id;
	  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=253053091425708";
	  fjs.parentNode.insertBefore(js, fjs);
	}(document, "script", "facebook-jssdk"));</script>
	
	<div class="fb-like" data-href="http://www.facebook.com/MyWebsiteAdvisor" data-send="true" data-layout="button_count" data-width="450" data-show-faces="false"></div>
	
	
	<a href="https://twitter.com/MWebsiteAdvisor" class="twitter-follow-button" data-show-count="false"  >Follow @MWebsiteAdvisor</a>
	<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>


</div>';

return $social;


}	






	
	/**
	 * Display options page
	 */
	public function optionsPage() {
		// if user clicked "Save Changes" save them
		/**
		if(isset($_POST['Submit'])) {
			foreach($this->_options as $option => $value) {
				if(array_key_exists($option, $_POST)) {
					update_option($option, $_POST[$option]);
				} else {
					update_option($option, $value);
				}
			}

			$this->_messages['updated'][] = 'Options updated!';
		}

**/
		
		
	
		foreach($this->_messages as $namespace => $messages) {
			foreach($messages as $message) {
?>
<div class="<?php echo $namespace; ?>">
	<p>
		<strong><?php echo $message; ?></strong>
	</p>
</div>
<?php
			}
		}
		
		
			
			
				
?>


<style>
.form-table{clear:left;};
</style>
	
	
									  
<script type="text/javascript">var wpurl = "<?php bloginfo('wpurl'); ?>";</script>

<?php echo $this->display_social_media(); ?>

<div class="wrap" id="sm_div">

	<div id="icon-options-general" class="icon32"><br /></div>
	<h2>Simple Debug Plugin Settings</h2>
	
	<?php if('true' === get_option('simple_debug_log_enabled') ){ ?>
		<?php echo "<p float='left'><a  href='".admin_url()."tools.php?page=debug_log' >View Simple Debug Log</a></p>"; ?>
	<?php } ?>
		
	<div id="poststuff" class="metabox-holder has-right-sidebar">
		<div class="inner-sidebar">
			<div id="side-sortables" class="meta-box-sortabless ui-sortable" style="position:relative;">
			
<?php $this->HtmlPrintBoxHeader('pl_diag',__('Plugin Diagnostic Check','diagnostic'),true); ?>

				<?php
				
				echo "<p>Plugin Version: ".$this->version."</p>";
				
				echo "<p>Server OS: ".PHP_OS."</p>";
				
				echo "<p>Required PHP Version: 5.3+<br>";
				echo "Current PHP Version: " . phpversion() . "</p>";
					
				echo "<p>Memory Use: " . number_format(memory_get_usage()/1024/1024, 1) . " / " . ini_get('memory_limit') . "</p>";
				
				echo "<p>Peak Memory Use: " . number_format(memory_get_peak_usage()/1024/1024, 1) . " / " . ini_get('memory_limit') . "</p>";
				
				if(function_exists('sys_getloadavg')){
					$lav = sys_getloadavg();
					echo "<p>Server Load Average: ".$lav[0].", ".$lav[1].", ".$lav[2]."</p>";
				}
				
				?>

<?php $this->HtmlPrintBoxFooter(true); ?>



<?php $this->HtmlPrintBoxHeader('pl_resources',__('Plugin Resources','resources'),true); ?>

	<p><a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/simple-debug/' target='_blank'>Plugin Homepage</a></p>
	<p><a href='http://mywebsiteadvisor.com/contact-us/'  target='_blank'>Plugin Support</a></p>
	<p><a href='http://mywebsiteadvisor.com/contact-us/'  target='_blank'>Contact Us</a></p>
	<p><a href='http://wordpress.org/support/view/plugin-reviews/simple-debug?rate=5#postform'  target='_blank'>Rate and Review This Plugin</a></p>
	
<?php $this->HtmlPrintBoxFooter(true); ?>


<?php $this->HtmlPrintBoxHeader('more_plugins',__('More Plugins','more_plugins'),true); ?>
	
	<p><a href='http://mywebsiteadvisor.com/tools/premium-wordpress-plugins/'  target='_blank'>Premium WordPress Plugins!</a></p>
	<p><a href='http://profiles.wordpress.org/MyWebsiteAdvisor/'  target='_blank'>Free Plugins on Wordpress.org!</a></p>
	<p><a href='http://mywebsiteadvisor.com/tools/wordpress-plugins/'  target='_blank'>Free Plugins on MyWebsiteAdvisor.com!</a></p>	
				
<?php $this->HtmlPrintBoxFooter(true); ?>


<?php $this->HtmlPrintBoxHeader('follow',__('Follow MyWebsiteAdvisor','follow'),true); ?>

	<p><a href='http://facebook.com/MyWebsiteAdvisor/'  target='_blank'>Follow us on Facebook!</a></p>
	<p><a href='http://twitter.com/MWebsiteAdvisor/'  target='_blank'>Follow us on Twitter!</a></p>
	<p><a href='http://www.youtube.com/mywebsiteadvisor'  target='_blank'>Watch us on YouTube!</a></p>
	<p><a href='http://MyWebsiteAdvisor.com/'  target='_blank'>Visit our Website!</a></p>	
	
<?php $this->HtmlPrintBoxFooter(true); ?>


</div>
</div>



	<div class="has-sidebar sm-padded" >			
		<div id="post-body-content" class="has-sidebar-content">
			<div class="meta-box-sortabless">
	
			<form method='post'>
	
			
			
				
				<?php $this->HtmlPrintBoxHeader('site_debugging',__('Site Debugging','site-debugging'),false); ?>
					
					<table class='form-table'>
					<tr>
					<th>Enable Slow Function Debugging?</th>
					<td>
					<?php $debug_enabled = $this->get_option('simple_debug_enabled'); ?>
					<?php if($debug_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> Debug Enabled</label></p>
					<p>(Scans for Slow Functions)</p>
					<p>WARNING: Do not leave this enabled all the time, it will cause a slight decrease in performance because it is checking every function that runs. </p>	
					</td>
					</tr>
					
					<tr>
					<th>Display Debug Log?</th>
					<td>
					<?php $simple_debug_log_enabled = $this->get_option('simple_debug_log_enabled'); ?>
					<?php if($simple_debug_log_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_log_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> Display Debug Log Enabled</label></p>
					<p>(Recommended)</p>
					</td>
					</tr>
					
					<tr>
					<th>Display Error Log?</th>
					<td>
					<?php $simple_debug_display_error_log = $this->get_option('simple_debug_display_error_log'); ?>
					<?php if($simple_debug_display_error_log === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_display_error_log' type='checkbox' value='true' <?php echo $selected; ?> /> Display Error Log Enabled</label></p>
					<p>(Advanced)</p>
					</td>
					</tr>
					</table>
					
					<p><input type="submit" name='Submit' class='button-primary' value='Save Settings' /></p>
					
			<?php $this->HtmlPrintBoxFooter(false); ?>						
			
			
			
			<?php $this->HtmlPrintBoxHeader('php_settings',__('PHP Settings','php-settings'),false); ?>
						
					<table class='form-table'>
					<tr>
					<th>Display PHP.ini Info for Debugging?</th>
					<td>			
					<?php $phpini_enabled = $this->get_option('simple_debug_phpini_enabled'); ?>
					<?php if($phpini_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_phpini_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> PHP.ini Display Enabled</label></p>
					</td>
					</tr>
					
					<tr>
					<th>Display phpinfo() Function for Debugging?</th>
					<td>
					<?php $phpinfo_enabled = $this->get_option('simple_debug_phpinfo_enabled'); ?>
					<?php if($phpinfo_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_phpinfo_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> phpinfo() Function Display Enabled</label></p>
					</td>
					</tr>
					</table>
					
					<p><input type="submit" name='Submit' class='button-primary' value='Save Settings' /></p>
					
			<?php $this->HtmlPrintBoxFooter(false); ?>		
			
			
			
			<?php $this->HtmlPrintBoxHeader('db_info',__('Database Information','db-info'),false); ?>
					
					<table class='form-table'>
					<tr>
					<th>Display Database Optimization Tool</th>
					<td>	
					<?php $db_optimization_enabled = $this->get_option('simple_debug_db_optimization_enabled'); ?>
					<?php if($db_optimization_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_db_optimization_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> DB Optimization Tools Enabled</label></p>
					</td>
					</tr>
					
					<tr>
					<th>Display Database Performance Info</th>
					<td>
					<?php $db_performance_enabled = $this->get_option('simple_debug_db_performance_enabled'); ?>
					<?php if($db_performance_enabled === "true"){$selected = "checked='checked'";}else{$selected="";}; ?>
					<p><label><input name='simple_debug_db_performance_enabled' type='checkbox' value='true' <?php echo $selected; ?> /> DB Performance Analysis Enabled</label></p>
					</td>
					</tr>
					</table>
					
					<p><input type="submit" name='Submit' class='button-primary' value='Save Settings' /></p>
					
			<?php $this->HtmlPrintBoxFooter(false); ?>		
			
					
	
			
			<?php if( $this->get_option('simple_debug_phpini_enabled')){ ?>
			
				<?php $this->HtmlPrintBoxHeader('php.ini',__('PHP.ini settings','php.ini-settings'),false); ?>
					<div style="overflow: scroll; height:400px;">
					<table border="1" width="400px">
					
					<tr>
					<th>Setting Name</th>
					
					<th>Value</th>
					
					</tr>
					
					<?php 
					foreach(ini_get_all() as $key=>$data){
						echo "<tr>";
						echo "<td>".$key."</td>";
						//echo "<td>".$data['global_value']."</td>";
						echo "<td>".$data['local_value']."</td>";
						//echo "<td>".$data['access']."</td>";
						echo "<tr>";
					}
					
					
					?>
					</table>
					
					</div>
				<?php $this->HtmlPrintBoxFooter(false); ?>
				
			<?php } ?>
			
			
			
			<?php if( $this->get_option('simple_debug_phpinfo_enabled')){ ?>
				<?php $this->HtmlPrintBoxHeader('php_config',__('PHP Configuration Information','php-config'),false); ?>
					<div style="overflow:scroll; height:350px;">
					<style>
					
						.center {text-align: center;}
						.center table { margin-left: auto; margin-right: auto; text-align: left;}
						.center th { text-align: center !important; }
						
						.p {text-align: left;}
						.e {background-color: #ccccff; font-weight: bold; color: #000000;}
						.h {background-color: #9999cc; font-weight: bold; color: #000000;}
						.v {background-color: #cccccc; color: #000000;}
						.vr {background-color: #cccccc; text-align: right; color: #000000;}

					</style>
					<?php
					
						ob_start();
						phpinfo();
						$pinfo = ob_get_contents();
						ob_end_clean();
						 
						$pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1',$pinfo);
						echo $pinfo;	
						
					?>
					</div>
				<?php $this->HtmlPrintBoxFooter(false); ?>
			<?php } ?>
			
			
			
			<?php if( $this->get_option('simple_debug_db_optimization_enabled')){ ?>
				<?php $this->HtmlPrintBoxHeader('db-optimization',__('Database Optimization','db-optimization-settings'),false); ?>
					
					
						<input type='submit' name='Optimize_Database' value='Optimize Database'  class='button-primary' />
					
					
					<?php
						if(isset($_POST['Optimize_Database']) && $_POST['Optimize_Database'] == "Optimize Database"){
							$this->performDatabaseOptimization();	
						}
					?>

				<?php $this->HtmlPrintBoxFooter(false); ?>
			<?php } ?>
			
		
			<?php if( $this->get_option('simple_debug_db_performance_enabled')){ ?>
				<?php $this->HtmlPrintBoxHeader('db-performance',__('Database Performance','db-performance-settings'),false); ?>
					
					<?php
					
						$this->db_performance_check();	
						
					?>
					
				<?php $this->HtmlPrintBoxFooter(false); ?>
			<?php } ?>
				
			
			
			<?php if( $this->get_option('simple_debug_display_error_log')){ ?>
				<?php $this->HtmlPrintBoxHeader('error-log',__('Error Log','display-error-log'),false); ?>
					<?php
					
						$error_logging_enabled = ini_get('log_errors') && (ini_get('log_errors') != 'Off');
						if(!$error_logging_enabled){
							echo "<p>Error Logging is Disabled!<p>";
						}else{
					
							if(ini_get('error_log')){
								$log_file = ini_get('error_log');
							}
							if(isset($_POST['simple_debug_error_log_location']) && $_POST['simple_debug_error_log_location'] != ''){
								$log_file = $this->get_option('simple_debug_error_log_location');
							}
							
						
							?>
							Log File: (full path and filename)<br />
							<input type='text' size="100" name='simple_debug_error_log_location' value='<?php echo $log_file; ?>' />
							<input type="submit" name="Submit" value="Submit" class='button-primary'/>
							<?php
						
							$this->display_error_log($log_file);	
						
						}
						
					?>
					
				<?php $this->HtmlPrintBoxFooter(false); ?>
			<?php } ?>
		
			</form>
			
		
</div></div></div></div>

</div>


<?php
	}
	
}

?>
Return current item: Simple Debug