.
*/
// function to replace wp_die if it doesn't exist
if (!function_exists('wp_die')) : function wp_die ($message = 'wp_die') { die($message); } endif;
// don't load directly - exit if add_action or plugins_url functions do not exist
if (!defined('ABSPATH') || !function_exists('add_action') || !function_exists('plugins_url')) die('death by askapache firing squad');
if(!class_exists('AA_DEBUG')):
/******************************************************************************************************************************************************************
PHP DEFINES
* __LINE__ The current line number of the file.
* __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned
* __DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. Does not have a trailing slash unless it is the root directory.
* __FUNCTION__ The function name. As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
* __CLASS__ The class name. As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
* __METHOD__ The class method name. The method name is returned as it was declared (case-sensitive).
* __NAMESPACE__ The name of the current namespace (case-sensitive). This constant is defined in compile-time
******************************************************************************************************************************************************************/
!defined('__DIR__') && define('__DIR__', realpath(dirname(__FILE__)));
!defined('FILE_BINARY') && define('FILE_BINARY', 0);
if (!defined("PHP_VERSION_ID"))
{
list($major, $minor, $bug) = explode(".", phpversion(), 3);
$bug = ((int)$bug < 10) ? "0".(int)$bug : (int)$bug; // Many distros make up their own versions
define("PHP_VERSION_ID", "{$major}0{$minor}$bug");
!defined("PHP_MAJOR_VERSION") && define("PHP_MAJOR_VERSION", $major);
}
if (!defined('PHP_EOL')) {
switch (strtoupper(substr(PHP_OS, 0, 3))) {
case 'WIN': define('PHP_EOL', "\r\n"); break;
case 'DAR': define('PHP_EOL', "\r"); break;
default:define('PHP_EOL', "\n"); break;
}
}
/******************************************************************************************************************************************************************
WORDPRESS DEFINES
******************************************************************************************************************************************************************/
!defined('WP_CONTENT_DIR') && define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); // no trailing slash, full paths only
!defined('WP_PLUGIN_DIR') && define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins'); // full path, no trailing slash
!defined('WP_CONTENT_URL') && define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url
!defined('WP_PLUGIN_URL') && define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); // full url, no trailing slash
!defined('CRLF') && define('CRLF', chr(13).chr(10));
/******************************************************************************************************************************************************************
FUNCTION DEFINES
******************************************************************************************************************************************************************/
/** aadv_error_log($msg='')
* since 2.3.2
*/
function aadv_error_log($msg='')
{
return error_log("1".$msg);
}
/** aadv_DEFINE_function()
* since 2.3.3
*/
function aadv_DEFINE_function($f='')
{
$funcs=array('absint','array_walk_recursive','curl_setopt_array','get_include_path','inet_ntop','inet_pton','ini_get_all','is_a','is_callable','is_scalar','md5_file','mhash','microtime','mkdir','ob_clean','ob_flush','ob_get_clean','ob_get_flush','pathinfo','php_ini_loaded_file','restore_include_path','scandir','set_include_path','sys_get_temp_dir','time_sleep_until','var_export','wp_die');
if(empty($f)) return $funcs;
//aadv_error_log("Defining function {$f}");
switch($f)
{
case 'absint':
function absint( $maybeint )
{
return abs( intval( $maybeint ) );
}
break;
case 'array_walk_recursive':
function array_walk_recursive(&$input, $funcname)
{
if (!is_callable($funcname))
{
if (is_array($funcname)) $funcname = $funcname[0] . '::' . $funcname[1];
user_error('array_walk_recursive() Not a valid callback ' . $funcname, E_USER_WARNING);
return;
}
if (!is_array($input))
{
user_error('array_walk_recursive() The argument should be an array', E_USER_WARNING);
return;
}
$args = func_get_args();
foreach ($input as $key => $item)
{
$callArgs = $args;
if (is_array($item)) {
$thisCall = 'array_walk_recursive';
$callArgs[1] = $funcname;
} else {
$thisCall = $funcname;
$callArgs[1] = $key;
}
$callArgs[0] = &$input[$key];
call_user_func_array($thisCall, $callArgs);
}
};
break;
case 'curl_setopt_array':
function curl_setopt_array(&$ch, $curl_options)
{
$curl_info=array(
'url'=>'Last effective URL',
'content_type'=>'Content-type of downloaded object',
'http_code'=>'Last received HTTP code',
'header_size'=>'Total size of all headers received',
'request_size'=>'Total size of issued requests, currently only for HTTP requests',
'filetime'=>'Remote time of the retrieved document',
'ssl_verify_result'=>'Result of SSL certification verification requested',
'redirect_count'=>'Total number of redirects',
'total_time'=>'Total transaction time in seconds for last transfer',
'namelookup_time'=>'Time in seconds until name resolving was complete',
'connect_time'=>'Time in seconds it took to establish the connection',
'pretransfer_time'=>'Time in seconds from start until just before file transfer begins',
'size_upload'=>'Total number of bytes uploaded',
'size_download'=>'Total number of bytes downloaded',
'speed_download'=>'Average download speed',
'speed_upload'=>'Average upload speed',
'download_content_length'=>'content-length of download, read from Content-Length: field',
'upload_content_length'=>'Specified size of upload',
'starttransfer_time'=>'Time in seconds until the first byte is about to be transferred',
'redirect_time'=>'Time in seconds of all redirection steps before final transaction was started'
);
foreach ($curl_options as $option => $value) {
if (!curl_setopt($ch, $option, $value)) return false;
}
return true;
}
break;
case 'get_include_path':
function get_include_path()
{
return ini_get('include_path');
};
break;
case 'inet_ntop':
function inet_ntop($in_addr)
{
switch (strlen($in_addr)) {
case 4:
list(,$r) = unpack('N', $in_addr);
return long2ip($r);
case 16:
$r = substr(chunk_split(bin2hex($in_addr), 4, ':'), 0, -1);
$r = preg_replace( array('/(?::?\b0+\b:?){2,}/', '/\b0+([^0])/e'), array('::', '(int)"$1"?"$1":"0$1"'), $r);
return $r;
}
return false;
};
break;
case 'inet_pton':
function inet_pton($address)
{
$r = ip2long($address);
if ($r !== false && $r != -1) return pack('N', $r);
$delim_count = substr_count($address, ':');
if ($delim_count < 1 || $delim_count > 7) return false;
$r = explode(':', $address);
$rcount = count($r);
if (($doub = array_search('', $r, 1)) !== false) {
$length = (!$doub || $doub == $rcount - 1 ? 2 : 1);
array_splice($r, $doub, $length, array_fill(0, 8 + $length - $rcount, 0));
}
$r = array_map('hexdec', $r);
array_unshift($r, 'n*');
$r = call_user_func_array('pack', $r);
return $r;
};
break;
case 'ini_get_all':
function ini_get_all($extension=null)
{
// Sanity check
if ($extension !== null && !is_scalar($extension)) {
user_error('ini_get_all() expects parameter 1 to be string, ' . gettype($extension) . ' given', E_USER_WARNING);
return false;
}
// Get the location of php.ini
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_clean();
$info = explode("\n", $info);
$line = array_values(preg_grep('#php\.ini#', $info));
// Plain vs HTML output
if (substr($line[0], 0, 4) === '
') {
list (, $value) = explode('', $line[0], 2);
$inifile = trim(strip_tags($value));
} else {
list (, $value) = explode(' => ', $line[0], 2);
$inifile = trim($value);
}
// Check the file actually exists
if (!file_exists($inifile)) return false;
};
break;
case 'restore_include_path':
function restore_include_path()
{
return ini_restore('include_path');
};
break;
case 'scandir':
function scandir($directory, $sorting_order = 0)
{
if (!is_string($directory)) {
user_error('scandir() expects parameter 1 to be string, ' . gettype($directory) . ' given', E_USER_WARNING);
return;
}
if (!is_int($sorting_order) && !is_bool($sorting_order)) {
user_error('scandir() expects parameter 2 to be long, ' . gettype($sorting_order) . ' given', E_USER_WARNING);
return;
}
if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
user_error('scandir() failed to open dir: Invalid argument', E_USER_WARNING);
return false;
}
$files = array ();
while (false !== ($filename = readdir($fh))) $files[] = $filename;
closedir($fh);
if ($sorting_order == 1) rsort($files);
else sort($files);
return $files;
};
break;
case 'set_include_path':
function set_include_path($new_include_path)
{
return ini_set('include_path', $new_include_path);
};
break;
case 'sys_get_temp_dir':
function sys_get_temp_dir()
{
if (!empty($_ENV['TMP'])) return realpath($_ENV['TMP']);
if (!empty($_ENV['TMPDIR'])) return realpath( $_ENV['TMPDIR']);
if (!empty($_ENV['TEMP'])) return realpath( $_ENV['TEMP']);
$tempfile = tempnam(uniqid(rand(),TRUE),'');
if (file_exists($tempfile)) {
unlink($tempfile);
return realpath(dirname($tempfile));
}
};
break;
case 'time_sleep_until':
function time_sleep_until($timestamp)
{
list($usec, $sec) = explode(' ', microtime());
$now = $sec + $usec;
if ($timestamp <= $now) {
user_error('Specified timestamp is in the past', E_USER_WARNING);
return false;
}
$diff = $timestamp - $now;
usleep($diff * 1000000);
return true;
};
break;
case 'var_export':
function var_export($var, $return = false, $level = 0, $inObject = false)
{
$indent = ' ';
$doublearrow = ' => ';
$lineend = ",\n";
$stringdelim = '\'';
$newline = "\n";
$find = array(null, '\\', '\'');
$replace = array('NULL', '\\\\', '\\\'');
$out = '';
// Indent
$level++;
for ($i = 1, $previndent = ''; $i < $level; $i++) $previndent .= $indent;
$varType = gettype($var);
// Handle object indentation oddity
if ($inObject && $varType != 'object') $previndent = substr($previndent, 0, -1);
// Handle each type
switch ($varType)
{
case 'array':
if ($inObject) $out .= $newline . $previndent;
$out .= 'array (' . $newline;
foreach ($var as $key => $value) {
if (is_string($key)) {
// Make key safe
$key = str_replace($find, $replace, $key);
$key = $stringdelim . $key . $stringdelim;
}
// Value
if (is_array($value)) {
$export = var_export($value, true, $level);
$value = $newline . $previndent . $indent . $export;
} else {
$value = var_export($value, true, $level);
}
// Piece line together
$out .= $previndent . $indent . $key . $doublearrow . $value . $lineend;
}
// End string
$out .= $previndent . ')';
break;
case 'string':
// Make the string safe
for ($i = 0, $c = count($find); $i < $c; $i++) $var = str_replace($find[$i], $replace[$i], $var);
$out = $stringdelim . $var . $stringdelim;
break;
case 'integer':
case 'double':
$out = (string) $var;
break;
case 'boolean':
$out = $var ? 'true' : 'false';
break;
case 'NULL':
case 'resource':
$out = 'NULL';
break;
case 'object':
// Start the object export
$out = $newline . $previndent;
$out .= get_class($var) . '::__set_state(array(' . $newline;
// Export the object vars
foreach(get_object_vars($var) as $key => $value) $out .= $previndent . $indent . ' ' . $stringdelim . $key . $stringdelim . $doublearrow . var_export($value, true, $level, true) . $lineend;
$out .= $previndent . '))';
break;
}
// Method of output
if ($return === true) return $out;
else echo $out;
};
break;
case 'wp_die':
function wp_die ($message = 'wp_die')
{
die($message);
}
break;
}
}
// This is a cool workaround to defining functions already defined but throwing errors
foreach(aadv_DEFINE_function() as $f) if(!function_exists($f)) aadv_DEFINE_function($f);
/**
* A class for displaying various tree-like structures.
*
* @package WordPress
* @author askapache
* @copyright Copyright (c) 2011
* @version $Id$
* @access public
*/
class AA_DEBUG
{
/**
* Quick Name used as prefix for plugin options and plugin info
*
* Stored in global wp_options under $_qn + '_options' and $_qn + '_plugin'
*
* @since 2.2.8
* @access private
* @var string
*/
var $_qn='askapache_debug';
/**
* The debug level of this class
*
* Set to options['plugin_debug_level'] in __construct, turns logging and extra debugging on/off depending on its value. 0 is no debugging, 100 is max.
*
* @since 2.2.8
* @access private
* @var int
*/
var $_debug=0;
/**
* Contains Plugin Name and Settings from parsing this file
*
* 'plugin-name' => 'AskApache Debug Viewer',
* 'short-name' => 'AA Debug',
* 'description' => 'Displays Advanced Debugging Output',
* 'author' => 'askapache,cduke250',
* 'version' => '2.4.1',
* 'updated' => '12/20/2012 - 9:08 PM',
* 'requires-at-least' => '3.1.0',
* 'tested-up-to' => '3.5',
* 'tags' => 'debug, debugging, error, errors, warning, problem, bug, problems, support, admin, programmer, developer, plugin, development, information, stats, logs, queries, htaccess, password, error, support, askapache, apache, rewrites',
* 'contributors' => 'askapache,cduke250',
* 'wordpress-uri' => 'http://wordpress.org/extend/plugins/askapache-debug-viewer/',
* 'author-uri' => 'http://www.askapache.com/',
* 'donate-uri' => 'http://www.askapache.com/donate/',
* 'plugin-uri' => 'http://www.askapache.com/wordpress/debug-viewer-plugin.html',
* 'role' => 'administrator',
* 'capability' => 'askapache_debug_output',
* 'qn' => 'askapache_debug',
* 'file' => '~/wp-content/plugins/askapache-debug-viewer/askapache-debug-viewer.php',
* 'title' => 'AskApache Debug Viewer',
* 'pb' => 'askapache-debug-viewer/askapache-debug-viewer.php',
* 'page' => 'askapache-debug-viewer.php',
* 'pagenice' => 'askapache-debug-viewer',
* 'nonce' => 'form_askapache-debug-viewer',
* 'hook' => 'settings_page_askapache-debug-viewer',
* 'action' => 'options-general.php?page=askapache-debug-viewer.php',
* 'op' => 'adv7',
* @since 2.2.8
* @var array
*/
var $plugin = array(); // array to hold plugin information
/**
* The Options for this plugin
* -------------------------------
*
* [options] => Array
* [page] => home
* [logfile] => php_error.log
* [dirtoexplore] => /tmp
* [log_errors] => 1
* [debug_live] => 0
* [admin_footer] => 1
* [wp_footer] => 1
* [error_reporting] => 4983
* [plugin_debug_level] => 5
* [debug_mods_v] => 5
* [debug_mods] => 5
* [admin_bar] => 1
*
* @since 2.2.8
* @var array
*/
var $options = array(
'page'=> 'home',
'logfile' => '',
'dirtoexplore' => '',
'key' => '',
'log_errors' => '0',
'debug_live' => '0',
'display_height' => 300,
'admin_footer' => '1',
'wp_footer' => '1',
'admin_bar' => '1',
'error_reporting' => 4983,
'plugin_debug_level' => 0,
'debug_mods_v' => 0,
'debug_mods' => 107197
);
/**
* The Pages for Navigating to
*
* @since 2.2.8
* @access private
* @var bool
* @var array
*/
var $pages = array(
'home' => array('name'=>'Settings', 'title'=>'Setup Debugging Options', 'nonce'=>''),
'wpconfig' => array('name'=>'wp-config File', 'title'=>'wp-config.php file', 'nonce'=>''),
'phpinfo' => array('name'=>'PHPINFO', 'title'=>'phpinfo', 'nonce'=>''),
'server-status' => array('name'=>'Server Status', 'title'=>'Server Status', 'nonce'=>''),
'server-info' => array('name'=>'Server Info', 'title'=>'Server Info', 'nonce'=>''),
'server-env' => array('name'=>'Server Env', 'title'=>'Printenv Output', 'nonce'=>''),
'server-parsed' => array('name'=>'Server Parsed', 'title'=>'SHTML Printenv', 'nonce'=>'')
//'files' => array('name'=>'Directory File Browser', 'title'=>'Browse files and directories', 'nonce'=>'')
);
/**
* The Actions for immediate effect
*
* @since 2.2.8
* @var array
*/
var $actions = array(
//'adminbaroff' =>array('title'=>'Disable Front Admin Bar', 'nonce'=>''),
'disable' =>array('title'=>'Disable', 'nonce'=>''),
'enable' =>array('title'=>'Enable', 'nonce'=>'')
);
/**
* The debug mods
*
* @since 2.2.8
* @var array
*/
var $debug_mods = array();
/**
* The ini_overwrites
*
* @since 2.2.8
* @var array
*/
var $ini_overwrites=array(
//'output_handler' => '',
//'session.auto_start' => '0',
//'zlib.output_compression' => 0,
//'output_buffering' => 0,
//'precision'=>'14',
//'report_zend_debug' => 0,
'open_basedir' => '',
'tidy.clean_output' => 0,
'xdebug.default_enable' => 0,
'mbstring.func_overload' => 0,
'error_prepend_string' => '',
'error_append_string' => '',
'auto_prepend_file' => '',
'auto_append_file' => '',
'disable_functions' => '',
'safe_mode' => 0,
'request_order' => 'GPCES',
'register_globals' => 1,
'register_long_arrays' => 1,
'register_argc_argv' => 1,
'always_populate_raw_post_data' => 1,
'error_reporting' => 0,
'display_errors' => 0,
'display_startup_errors' => 0,
'log_errors' => 1,
'html_errors' => 0,// Turn off HTML tags in error messages. The new format for HTML errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by docref_root and docref_ext.
'track_errors' => 1,
'report_memleaks' => 1,
'magic_quotes_runtime' => 0,
'magic_quotes_gpc' => 0,
'ignore_repeated_errors' => 1,
'ignore_repeated_source' => 1,
'log_errors_max_len'=>'0'
);
/**
* The Old Ini Settings for storage
*
* @since 2.2.8
* @var array
*/
var $old_inis = array();
/** AA_DEBUG::AA_DEBUG()
*/
function AA_DEBUG()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if(version_compare(PHP_VERSION, '5.0.0', 'lt')){
$this->__construct();
register_shutdown_function(array($this,"__destruct"));
}
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::__construct()
*/
function __construct()
{
/* PRINT ERROR_GET_LAST ON SHUTDOWN
* register_shutdown_function(create_function('',
* 'error_log("print error_get_last '.error_log("print error_get_last").'");$l=error_get_last();if(isset($l["type"])&&$l["type"]===E_ERROR)echo "fatal error";echo (isset($php_errormsg)?PHP_EOL.$php_errormsg:"").PHP_EOL.print_r($l,1).PHP_EOL;'));
*/
$this->options=get_option($this->_qn.'_options');
$this->_debug=$this->options['plugin_debug_level'];
if($this->_debug > 0)error_log(str_repeat("\n",5).str_repeat("=",235));
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',50);
$this->_plugin = $this->get_plugin_data();
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',50);
}
/** AA_DEBUG::LoadOptions()
*/
function LoadOptions()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
$this->options=get_option($this->_qn.'_options');
$this->_plugin = $this->get_plugin_data();
$this->_debug=absint($this->options['plugin_debug_level']);
$D = array();
$D[(1 << sizeof($D))]=array('get_debug_footerhelper', 'Footer Helper');
$D[(1 << sizeof($D))]=array('get_debug_templates', 'Templates');
$D[(1 << sizeof($D))]=array('get_debug_options', 'WP Options');
$D[(1 << sizeof($D))]=array('get_debug_aa_plugin', 'Debug Plugin');
$D[(1 << sizeof($D))]=array('get_debug_request', 'Request');
$D[(1 << sizeof($D))]=array('get_debug_wordpress', 'WordPress Globals');
$D[(1 << sizeof($D))]=array('get_debug_globalprint', 'GLOBALS Print');
$D[(1 << sizeof($D))]=array('get_debug_globalvars', 'Variables in Scope');
$D[(1 << sizeof($D))]=array('get_debug_rewrites', 'Rewrites');
$D[(1 << sizeof($D))]=array('get_debug_included', 'Included Files');
$D[(1 << sizeof($D))]=array('get_debug_extensions', 'Extensions');
$D[(1 << sizeof($D))]=array('get_debug_classes', 'Classes');
$D[(1 << sizeof($D))]=array('get_debug_functions', 'Functions');
$D[(1 << sizeof($D))]=array('get_debug_defined', 'Constants');
$D[(1 << sizeof($D))]=array('get_debug_posix', 'Posix Info');
$D[(1 << sizeof($D))]=array('get_debug_inis', 'PHP ini settings');
$D[(1 << sizeof($D))]=array('get_debug_permissions', 'User/File/Process permissions');
$D[(1 << sizeof($D))]=array('get_debug_interfaces', 'Interfaces');
$D[(1 << sizeof($D))]=array('get_debug_sockets', 'Sockets');
$D[(1 << sizeof($D))]=array('get_debug_queries', 'DataBase Queries');
$D[(1 << sizeof($D))]=array('get_debug_crons', 'WordPress Crons');
$D[(1 << sizeof($D))]=array('get_debug_plugins', 'WordPress Plugins');
$D[(1 << sizeof($D))]=array('get_debug_filters', 'WordPress Actions/Filters');
$this->debug_mods=$D;
unset($D);
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::SaveOptions()
*/
function SaveOptions()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if( function_exists('current_user_can') && !current_user_can('administrator') ) wp_die(__FUNCTION__.':'.__LINE__);
update_option($this->_qn.'_options', $this->options);
update_option($this->_qn.'_plugin', $this->_plugin);
$this->LoadOptions();
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::DefaultOptions()
*
* @uses wp_hash_password() Used to encrypt the user's password before passing to the database
*
*
* @since 2.2.1
* @version 1.1
*
* @param array $a The array
* @param string $s The text
* @param int $i The int
* @param string|array $query_args Passed to {@link parse_request()}
* @param WP_Error|null $a WP_Error object or null.
* @return bool True on success. False on failure.
* @return int The int.
* @return array The array.
* @return string The string.
* @return null Null on failure.
*/
function DefaultOptions($save=false)
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
// get all the plugin array data
$this->_plugin = $this->get_plugin_data(true);
// save the $this->_plugin to $this->_qn_plugin
$this->SaveOptions();
$key=wp_generate_password(24,false,false);
// default array of options
$ret=array(
'page'=> 'home',
'logfile' => $this->get_error_log(),
'dirtoexplore' => __DIR__,
'log_errors' => '1',
'key' => $key,
'debug_live' => '0',
'admin_footer' => '1',
'wp_footer' => '1',
'admin_bar' => '1',
'error_reporting' => 4983,
'plugin_debug_level' => 0,
'display_height' => 300,
'debug_mods_v' => 0,
'debug_mods' => 107197
);
// if $save is true
if($save===true) {
//save $ret to $this->options
$this->options=$ret;
// save both $this->options and $this->_plugin
$this->SaveOptions();
// reset $ret to equal true for return;
$ret=true;
}
// Save all these variables to database
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
return $ret;
}
/** AA_DEBUG::Activate()
*/
function Activate()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
$old_options=$old_plugin=$default_options=false;
// load the default options without saving ::options
$new_options=$this->DefaultOptions(false);
// get old options
$old_options=get_option($this->_qn.'_options');
// if old_options exist, merge the old settings into the new
if ($old_options !==false && is_array($old_options) && array_key_exists('plugin_debug_level', $old_options) && !array_key_exists('admin_bar_fix', $old_options) ) {
aadv_error_log(print_r(array_diff($old_options, $new_options),1));
$this->options = wp_parse_args($old_options, $new_options);
}
// delete the existing options
delete_option($this->_qn.'_options');
delete_option($this->_qn.'_plugin');
// add the new options
//add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
add_option($this->_qn.'_options', $this->options, '', 'yes');
add_option($this->_qn.'_plugin', $this->_plugin, '', 'yes');
$this->SaveOptions();
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::DeActivate()
*/
function DeActivate()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if( function_exists('current_user_can') && !current_user_can('administrator') ) wp_die(__FUNCTION__.':'.__LINE__);
$this->deactivate_ff_htaccess();
delete_option($this->_qn.'_plugin');
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::Uninstall()
*/
function Uninstall()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
delete_option($this->_qn.'_options');
delete_option($this->_qn.'_plugin');
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::RegisterPluginSettings()
*/
function RegisterPluginSettings($l=array())
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
$ret = array_merge( array('Settings'), $l);
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
return $ret;
}
/** AA_DEBUG::Init()
*/
function Init()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if( !$this->check_auth() ) return;
// Load options
$this->LoadOptions();
// adminbar
add_action( 'admin_bar_menu', array(&$this, 'AdminBar'), 9983 );
// add admin-specific stuff
if(is_admin()):
add_action("admin_head-{$this->_plugin['hook']}", array(&$this, 'AddHelp') );
add_filter("plugin_action_links_{$this->_plugin['pb']}", array(&$this, 'RegisterPluginSettings') );
add_action("load-{$this->_plugin['hook']}", array(&$this, 'Load'));
add_action('admin_menu', create_function('','$AA_DEBUG=&_aa_debug_object(); $p=$AA_DEBUG->_plugin; add_options_page( $p["plugin-name"], $p["short-name"], $p["role"], $p["page"], array(&$AA_DEBUG,"AdminPage") );'));
register_uninstall_hook(__FILE__, array(&$this,'Uninstall'));
register_activation_hook(__FILE__, array(&$this,'Activate'));
register_deactivation_hook(__FILE__, array(&$this,'DeActivate'));
endif;
// enqueue styles
wp_enqueue_style($this->_plugin['pagenice'], plugins_url('/f/admin.css',__FILE__), false, $this->_plugin['version'], "all");
wp_enqueue_style($this->_plugin['pagenice'].'1', 'http'. (is_ssl() ? 's' : '' ).'://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css', false, $this->_plugin['version'], "all");
// enqueue script
wp_enqueue_script($this->_plugin['pagenice'], plugins_url('/f/admin.js',__FILE__), array('jquery','jquery-ui-core','jquery-ui-resizable', 'jquery-ui-tabs', 'jquery-ui-draggable'), $this->_plugin['version']);
// add old inis to class var and create shutdown function to reset
foreach($this->ini_overwrites as $k=>$v)$this->old_inis[$k]=@ini_get($k);
$this->old_inis['error_reporting']=error_reporting();
register_shutdown_function(create_function('','$oe='.$this->old_inis['error_reporting'].';$ne='.error_reporting($this->options['error_reporting']).';error_reporting($oe);'));
foreach ($this->pages as $id => $idv) {
$this->pages[$id]['nonce']=wp_nonce_url(admin_url("{$this->_plugin['action']}&{$this->_plugin['op']}_page={$id}"), "{$this->_plugin['op']}_page_{$id}");
}
foreach ($this->actions as $id=>$idv) {
$this->actions[$id]['nonce']=wp_nonce_url(admin_url("{$this->_plugin['action']}&{$this->_plugin['op']}_action={$id}"), "{$this->_plugin['op']}_action_{$id}");
}
/*
foreach ($this->_debug_mods as $id => $info) {
$this->actions[]=array('title'=>'Enable '.$info[1], 'nonce'=>wp_nonce_url(admin_url("{$this->_plugin['action']}&{$this->_plugin['op']}_action={$id}"), "{$this->_plugin['op']}_action_{$id}"));
}
*/
// add to admin footer
if($this->options['admin_footer']=='1') add_action( "admin_footer", array(&$this,'footer_output'));
// add to wp footer
if($this->options['wp_footer']=='1') add_action( "wp_footer", array(&$this,'footer_output'));
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::AddHelp($text, $screen)
*/
function AddHelp()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',20);
$current_screen=get_current_screen();
add_contextual_help( $current_screen,
'Fixing Status Headers'
.'For super-advanced users, or those with access and knowledge of Apache .htaccess/httpd.conf files'
.' you should check that your error pages are correctly returning a 404 Not Found'
.' HTTP Header and not a 200 OK Header which appears to be the default for many WP installs, this plugin attempts to fix this using PHP, but the best way I have found'
.' is to add the following to your .htaccess file. '
. 'ErrorDocument 404 /index.php?error=404'."\n".'Redirect 404 /index.php?error=404 '
.'Comments/QuestionsPlease visit AskApache.com or send me an email at webmaster@askapache.com '
);
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',20);
}
/** AA_DEBUG::AdminBar()
*/
function AdminBar($wp_admin_bar)
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if(!is_object($wp_admin_bar))return aadv_error_log(__FUNCTION__.':'.__LINE__.' wp_admin_bar is not an object');
//if($this->options['wp_footer']=='1' && $this->options['admin_bar']=='1' ) {
//$pref = get_user_option( "show_admin_bar_front", $user->ID );
//update_user_option($user->ID, "show_admin_bar_front", '');
//}
//isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'
//
$wp_admin_bar->add_menu(array(
'id' => $this->_plugin['op'].'menu',
'title' => $this->_plugin["short-name"],
'href' => admin_url($this->_plugin["action"])
));
foreach ($this->pages as $id => $idv) {
$wp_admin_bar->add_menu(array(
'parent'=> $this->_plugin['op'].'menu',
'id' => $this->_plugin['op'].$id,
'title' => $idv['title'],
'href' => $idv['nonce']
));
}
foreach ($this->actions as $id => $idv) {
$wp_admin_bar->add_menu(array(
'parent'=> $this->_plugin['op'].'menu',
'id' => $this->_plugin['op'].$id,
'title' => $idv['title'],
'href' => $idv['nonce']
));
}
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::Load()
*/
function Load()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
//global $show_admin_bar;
// Handle page
foreach (array_keys($this->pages) as $w) {
if (isset($_GET["{$this->_plugin['op']}_page"]) && $_GET["{$this->_plugin['op']}_page"] == $w) {
check_admin_referer("{$this->_plugin['op']}_page_" . $w);
$this->options['page'] = $w;
break;
}
}
// Handle actions
foreach (array_keys($this->actions) as $w) {
if (isset($_GET["{$this->_plugin['op']}_action"]) && $_GET["{$this->_plugin['op']}_action"] == $w) {
check_admin_referer("{$this->_plugin['op']}_action_" . $w);
if($w=='disable') $this->options["admin_footer"]=$this->options["wp_footer"]=$this->options["log_errors"]='0';
elseif($w=='enable') $this->options["admin_footer"]=$this->options["wp_footer"]='1';
elseif($w=='adminbaroff') $this->options["admin_bar"]='0';
wp_redirect($_SERVER['HTTP_REFERER']);
break;
}
}
// parse and handle post requests to plugin
if('POST' === $_SERVER['REQUEST_METHOD']) $this->HandlePost();
$this->SaveOptions();
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::HandlePost()
*/
function HandlePost()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
if ( !current_user_can('administrator') ) wp_die( 'ERROR: User does not have permission to manage options. '.__FUNCTION__.':'.__LINE__ );
$op = $this->_plugin['op'];
// verify nonce, if not verified, then DIE
if(isset($_POST["_{$this->_plugin['nonce']}"])) wp_verify_nonce($_POST["_{$this->_plugin['nonce']}"], $this->_plugin['nonce']) || wp_die('ERROR: Incorrect Form Submission, please try again.');
elseif(isset($_POST["_{$this->_plugin['nonce']}_reset"])) wp_verify_nonce($_POST["_{$this->_plugin['nonce']}_reset"], $_POST["_{$this->_plugin['nonce']}_reset"]) || wp_die('ERROR: Incorrect Form Submission, please try again.');
// resets options to default values
if(isset($_POST["{$op}_action_reset"])) return $this->DefaultOptions(true);
if (isset($_POST["{$op}_save_debug_options"]))
{
//if ( !wp_verify_nonce($_POST['_wpnonce'], 'aadebug_settings_form') ) wp_die( 'ERROR: Incorrect Form Submission, please try again.' );
foreach(array('log_errors','debug_live','admin_footer','wp_footer', 'admin_bar') as $k) $this->options["{$k}"] = (isset($_POST["{$op}_{$k}"]) ? '1' : '0');
if( isset($_POST["{$op}_log_errors"]) || empty($this->options['logfile']) ) $this->options['logfile']=$this->get_error_log();
if (isset($_POST["{$op}_logfile"]) && !empty($_POST["{$op}_logfile"])) $this->options['logfile'] = trim($_POST["{$op}_logfile"]);
if (isset($_POST["{$op}_dirtoexplore"]) && !empty($_POST["{$op}_dirtoexplore"])) $this->options['dirtoexplore'] = trim($_POST["{$op}_dirtoexplore"]);
if (isset($_POST["{$op}_error_reporting"])){
$this->options['error_reporting'] = absint($_POST["{$op}_error_reporting"]);
if(strpos($_POST["{$op}_error_reporting"],'E')!==FALSE) $this->options['error_reporting']=$this->get_error_levels(trim($_POST["{$op}_error_reporting"],'|'),'string2error');
elseif(strpos($_POST["{$op}_error_reporting"],'|')!==FALSE) $this->options['error_reporting']=$this->get_error_levels($this->get_error_levels(trim($_POST["{$op}_error_reporting"],'|'),'error2string'),'string2error');
}
if (isset($_POST["{$op}_plugin_debug_level"])) $this->_debug = $this->options['plugin_debug_level'] = absint($_POST["{$op}_plugin_debug_level"]);
if (isset($_POST["{$op}_display_height"])) $this->options['display_height'] = absint($_POST["{$op}_display_height"]);
if (isset($_POST["{$op}_error_reporting"]) && ($this->options['error_reporting'] = 0)==0) {
foreach( array_map( 'intval', (array) $_POST["{$op}_error_reporting"] ) as $bit) $this->options['error_reporting'] |= $bit;
}
// checked('1', $this->options[$id],false)
if (isset($_POST["{$op}_debug_mods"]) && ($this->options['debug_mods'] = 0)==0) {
foreach(array_map( 'intval', (array) $_POST["{$op}_debug_mods"] ) as $bit) $this->options['debug_mods'] |= $bit;
}
if (isset($_POST["{$op}_debug_mods_v"]) && ($this->options['debug_mods_v'] = 0)==0) {
foreach(array_map( 'intval', (array) $_POST["{$op}_debug_mods_v"] ) as $bit) $this->options['debug_mods_v'] |= $bit;
} else {
$this->options['debug_mods_v'] = 0;
}
}
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',10);
}
/** AA_DEBUG::AdminPage()
* @version 1.2
*/
function AdminPage()
{
$this->t(__FILE__,__CLASS__,__FUNCTION__,__LINE__,'',5);
if( !$this->check_auth() ) wp_die();
global $screen, $current_screen, $wp_meta_boxes, $_wp_contextual_help;
echo ''.($this->_cf('screen_icon') ? screen_icon() : '').' ' . $this->_plugin['plugin-name'].' - '.$this->pages[$this->options['page']]['title'].'';
$this->display_navigation_menu();
switch($this->options['page'])
{
case 'server-info':
echo $this->get_socket_request('server-info');
break;
case 'server-status':
echo $this->get_socket_request('server-status');
break;
case 'server-env':
echo ' '.$this->get_socket_request('server-env.cgi', '0744').'';
break;
case 'server-parsed':
echo $this->get_socket_request('server-parsed.shtml');
break;
case 'phpinfo':
echo ' ';
echo $this->get_debug_phpinfo(0);
echo ' ';
break;
case 'files':
//echo ' AskApache Debugging Options';
//printf( " UMASK: %04o | DIR: %04o | FILE: %04o ", umask(), (0755 & ~ umask()), (0644 & ~ umask()).' ');
//echo '
|