. */ // exit if add_action or plugins_url functions do not exist !defined('ABSPATH') || !function_exists('add_action') || !function_exists('plugins_url') || !function_exists('add_management_page') || !function_exists('wp_die') && exit; /******************************************************************************************************************************************************************************************************** FUNCTIONS ********************************************************************************************************************************************************************************************************/ if (!function_exists('wp_die')) : function wp_die ($message = 'wp_die') { die($message); } endif; if (!function_exists('absint')): function absint( $maybeint ) { return abs( intval( $maybeint ) ); } endif; if (!function_exists('is_a')) : function is_a($o, $c) { return (!is_object($o)) ? false : ((strtolower(get_class($o)) == strtolower($c)) ? true : is_subclass_of($o, $c)); } endif; if (!function_exists('stripos')) : function stripos($haystack, $needle, $offset = 0) { return strpos(strtolower($haystack), strtolower($needle), $offset); } endif; if (!function_exists('wp_die')): function wp_die($m = 'wp_die'){ die($m); } endif; if(!class_exists('AA_DEBUG')): /******************************************************************************************************************************************************************************************************** DEFINES ********************************************************************************************************************************************************************************************************/ !defined('NET_SOCKET_READ') && define('NET_SOCKET_READ', 1); !defined('NET_SOCKET_WRITE') && define('NET_SOCKET_WRITE', 2); !defined('NET_SOCKET_ERROR') && define('NET_SOCKET_ERROR', 4); !defined('STREAM_CRYPTO_METHOD_TLS_CLIENT') && define('STREAM_CRYPTO_METHOD_TLS_CLIENT', 3); !defined('STREAM_CRYPTO_METHOD_SSLv3_CLIENT') && define('STREAM_CRYPTO_METHOD_SSLv3_CLIENT', 1); !defined('STREAM_CRYPTO_METHOD_SSLv23_CLIENT') && define('STREAM_CRYPTO_METHOD_SSLv23_CLIENT', 2); !defined('STREAM_CRYPTO_METHOD_SSLv2_CLIENT') && define('STREAM_CRYPTO_METHOD_SSLv2_CLIENT', 0); !defined('ABSPATH') || !function_exists('add_management_page') || !function_exists('wp_die') && die('death by askapache firing squad'); !defined('WP_CONTENT_DIR') && define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down !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 - WP_CONTENT_DIR is defined further up !defined('WP_PLUGIN_URL') && define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); // full url, no trailing slash !defined('S_IFMT') && define('S_IFMT', 0170000); // mask for all types !defined('S_IFSOCK') && define('S_IFSOCK', 0140000); // type: socket !defined('S_IFLNK') && define('S_IFLNK', 0120000); // type: symbolic link !defined('S_IFREG') && define('S_IFREG', 0100000); // type: regular file !defined('S_IFBLK') && define('S_IFBLK', 0060000); // type: block device !defined('S_IFDIR') && define('S_IFDIR', 0040000); // type: directory !defined('S_IFCHR') && define('S_IFCHR', 0020000); // type: character device !defined('S_IFIFO') && define('S_IFIFO', 0010000); // type: fifo !defined('S_ISUID') && define('S_ISUID', 0004000); // set-uid bit !defined('S_ISGID') && define('S_ISGID', 0002000); // set-gid bit !defined('S_ISVTX') && define('S_ISVTX', 0001000); // sticky bit !defined('S_IRWXU') && define('S_IRWXU', 00700); // mask for owner permissions !defined('S_IRUSR') && define('S_IRUSR', 00400); // owner: read permission !defined('S_IWUSR') && define('S_IWUSR', 00200); // owner: write permission !defined('S_IXUSR') && define('S_IXUSR', 00100); // owner: execute permission !defined('S_IRWXG') && define('S_IRWXG', 00070); // mask for group permissions !defined('S_IRGRP') && define('S_IRGRP', 00040); // group: read permission !defined('S_IWGRP') && define('S_IWGRP', 00020); // group: write permission !defined('S_IXGRP') && define('S_IXGRP', 00010); // group: execute permission !defined('S_IRWXO') && define('S_IRWXO', 00007); // mask for others permissions !defined('S_IROTH') && define('S_IROTH', 00004); // others: read permission !defined('S_IWOTH') && define('S_IWOTH', 00002); // others: write permission !defined('S_IXOTH') && define('S_IXOTH', 00001); // others: execute permission !defined('S_IRWXUGO') && define('S_IRWXUGO', (S_IRWXU | S_IRWXG | S_IRWXO)); !defined('S_IALLUGO') && define('S_IALLUGO', (S_ISUID | S_ISGID | S_ISVTX | S_IRWXUGO)); !defined('S_IRUGO') && define('S_IRUGO', (S_IRUSR | S_IRGRP | S_IROTH)); !defined('S_IWUGO') && define('S_IWUGO', (S_IWUSR | S_IWGRP | S_IWOTH)); !defined('S_IXUGO') && define('S_IXUGO', (S_IXUSR | S_IXGRP | S_IXOTH)); !defined('S_IRWUGO') && define('S_IRWUGO', (S_IRUGO | S_IWUGO)); !defined('FS_CHMOD_DIR') && define('FS_CHMOD_DIR', (S_IRWUGO & ~ umask())); !defined('FS_CHMOD_FILE') && define('FS_CHMOD_FILE', (S_IRWXUGO & ~ umask())); /** * AA_DEBUG * * @package * @author life * @copyright Copyright (c) 2010 * @version $Id$ * @access public */ class AA_DEBUG { var $options = array(); // an array of options and values var $plugin = array(); // array to hold plugin information var $debug = 0; var $old_inis; var $old_track_errors; var $old_error_reporting; var $debug_mods = array( 1 => array('included', 'Files included by php'), 2 => array('functions', 'Function Information'), 4 => array('classes', 'Information about Loaded Classes'), 8 => array('globals', 'Global Server/Request Information'), 16 => array('extensions', 'Extensions Loaded by PHP'), 32 => array('defined', 'Defined Constants and variables'), 64 => array('inis', 'Your PHP.ini settings'), 128 => array('phpinfo', 'Information from phpinfo'), 256 => array('permissions','Information about Owner/User/File permissions'), 512 => array('interfaces', 'Declared interfaces in the current script'), 1024 => array('sockets', 'Socket and Stream Debugging'), 2048 => array('rewrites', 'WordPress Rewrites'), 4096 => array('queries', 'View DB Queries') ); /** AA_DEBUG::AA_DEBUG() * */ function AA_DEBUG(){register_shutdown_function(array(&$this, '__destruct'));return $this->__construct();} /** AA_DEBUG::__construct() * */ function __construct(){/*error_log( 'PHP CLASS: AA_DEBUG started!');*/$this->t(__FILE__);} function __destruct(){error_reporting($this->old_error_reporting); @ini_set('track_errors', $this->old_track_errors);$this->t(__FILE__);/*error_log('PHP CLASS: AA_DEBUG destroyed!');*/} /** AA_DEBUG::LoadOptions() * * @return */ function LoadOptions() { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $this->plugin = $this->get_plugin_data('tools'); $this->options=get_option('askapache_debug_options'); } /** AA_DEBUG::SaveOptions() * * @return */ function SaveOptions() { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); update_option('askapache_debug_options', $this->options); update_option('askapache_debug_plugin', $this->plugin); } /** AA_DEBUG::default_options() * * @return */ /* AA_DEBUG::default_options() [askapache_debug_options] => Array [logfile] => /home/askapach/sites/askapache.com/logs/php_error.log [log_errors] => 0 [debug_live] => 0 [error_reporting] => 0 [debug_mods_verbose] => 0 [debug_mods] => 0 */ function default_options() { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); delete_option("askapache_debug_options"); delete_option("askapache_debug_plugin"); // get all the plugin array data $this->plugin = $this->get_plugin_data('tools'); $this->options=array( 'logfile' => $this->get_error_log(), 'log_errors' => 0, 'debug_live' => '1', 'admin_footer' => '1', 'wp_footer' => '0', 'error_reporting' => 0, 'debug_level' => 0, 'debug_mods_verbose' => 0, 'debug_mods' => 0, ); // Save all these variables to database $this->SaveOptions(); } /** AA_DEBUG::management_page() * * @return */ function management_page() { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); echo '
';
}
/** AA_DEBUG::wp_footer()
*
* @return
*/
function wp_footer()
{
$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" );
if(!current_user_can('administrator'))return;
$this->LoadOptions();
if($this->options['wp_footer']!=='1') return;
ob_start();
echo '
'; } /** AA_DEBUG::live_debug() * * @return */ function live_debug() { if ( $this->options['debug_live'] == '0' ) return; $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); static $started = false; if ( $started === true ) { foreach ( (array )$this->old_inis as $key => $val ) if ( ! empty($val) ) ini_set( $key, $val ); return error_reporting( $this->old_inis['error_reporting'] ); } $this->old_inis['error_reporting'] = error_reporting(); $ini_overwrites = array( 'display_errors' => 'Off', 'display_startup_errors' => 'Off', 'ignore_repeated_errors' => 'Off', 'ignore_repeated_source' => 'Off', 'html_errors' => 'Off', 'report_memleaks' => 'On', 'track_errors' => 'On', 'log_errors' => 'On' ); foreach ( $ini_overwrites as $key => $newval ) { $oldval = ''; $oldval = strval( ini_get($key) ); if ( ! empty($oldval) && $oldval != $newval ) $this->old_inis[$key] = ( $oldval == '1' ? 'On' : $oldval ); ini_set( $key, $newval ); } $started = true; error_reporting( (version_compare(phpversion(), '5.0', '>=')) ? E_ALL | E_STRICT : E_ALL ); return true; } /** AA_DEBUG::handle_post() * * @return */ function handle_post() { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if (isset($_POST['save_debug_options'])) { if ( !wp_verify_nonce($_POST['_wpnonce'], 'aadebug_settings_form') ) wp_die( 'ERROR: Incorrect Form Submission, please try again.' ); if ( isset($_POST['log_errors']) ) isset($_POST['log_errors']); $this->options['debug_live'] = isset($_POST['debug_live']); $this->options['admin_footer'] = (isset($_POST['admin_footer']) ? '1' : '0'); $this->options['wp_footer'] = (isset($_POST['wp_footer']) ? '1' : '0'); if( isset($_POST['log_errors'])) $this->options['logfile']=$this->get_error_log(); if (isset($_POST['logfile'])) $this->options['logfile'] = trim($_POST['logfile']); if (isset($_POST['debug_level'])) $this->options['debug_level'] = trim(intval($_POST['debug_level'])); if (isset($_POST['plugin_debug_level'])) $this->options['plugin_debug_level'] = trim(intval($_POST['debug_debug_level'])); if (isset($_POST['error_reporting']) && ($this->options['error_reporting'] = 0)!==false) foreach( array_map( 'intval', (array) $_POST['error_reporting'] ) as $bit) $this->options['error_reporting'] |= $bit; if (isset($_POST['debug_mods']) && ($this->options['debug_mods'] = 0)!==false) foreach(array_map( 'intval', (array) $_POST['debug_mods'] ) as $bit) $this->options['debug_mods'] |= $bit; if (isset($_POST['debug_mods_verbose']) && ($this->options['debug_mods_verbose'] = 0)!==false) foreach(array_map( 'intval', (array) $_POST['debug_mods_verbose'] ) as $bit) $this->options['debug_mods_verbose'] |= $bit; $this->SaveOptions(); } } function wb($id) { //$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $id=intval($id); $o=array(); if( ($id & 1) == 1 ) $o[]=1; if( ($id & 2) == 2 ) $o[]=2; if( ($id & 4) == 4 ) $o[]=4; if( ($id & 8) == 8 ) $o[]=8; if( ($id & 16) == 16 ) $o[]=16; if( ($id & 32) == 32 ) $o[]=32; if( ($id & 64) == 64 ) $o[]=64; if( ($id & 128) == 128 ) $o[]=128; if( ($id & 256) == 256 ) $o[]=256; if( ($id & 512) == 512 ) $o[]=512; if( ($id & 1024) == 1024 ) $o[]=1024; if( ($id & 2048) == 2048 ) $o[]=2048; if( ($id & 4096) == 4096 ) $o[]=4096; if( ($id & 8192) == 8192 ) $o[]=8192; if( ($id & 16384) == 16384 ) $o[]=16384; if( ($id & 32768) == 32768 ) $o[]=32768; return $o; /* $o=''; if( ($id & 1) == 1 ) $o.="|".$array[1][0]; if( ($id & 2) == 2 ) $o.="|".$array[2][0]; if( ($id & 4) == 4 ) $o.="|".$array[4][0]; if( ($id & 8) == 8 ) $o.="|".$array[8][0]; if( ($id & 16) == 16 ) $o.="|".$array[16][0]; if( ($id & 32) == 32 ) $o.="|".$array[32][0]; if( ($id & 64) == 64 ) $o.="|".$array[64][0]; if( ($id & 128) == 128 ) $o.="|".$array[128][0]; if( ($id & 256) == 256 ) $o.="|".$array[256][0]; echo $id." is ".trim($o,'|')."\n"; */ } function _checkedd($val, $d=false) { //$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $val=intval($val); $er=intval($this->options['error_reporting']); $str=(($val <= $er) && ($er & $val) === $val) ? ' checked="checked"' : ''; if(!$d)return $str; else echo $str; } function _checked($checked, $var, $d=false) { $str = ''; if($_SERVER['REQUEST_METHOD']=='POST')if(!isset($_POST[$checked]))return $str; elseif (!isset($_POST[$checked]) && !isset($this->options[$checked])) return $str; if(in_array($checked,array('debug_mods','debug_mods_verbose','error_reporting'))) $str = ( in_array($var, $this->wb($this->options[$checked]) ) ? ' checked="checked"' : '' ); else { $checked = (isset($_POST[$checked])) ? $_POST[$checked] : $this->options[$checked]; if (is_array($checked) && in_array($var, $checked)) $str = ' checked="checked"'; elseif ($checked == $var || $checked === true) $str = ' checked="checked"'; } if(!$d)return $str; else echo $str; return; } /** AA_DEBUG::get_plugin_data() * * @param string $type * @return */ /* [askapache_debug_plugin] => Array [plugin-name] => AskApache Debug Viewer [short-name] => AA Debug [description] => Displays Advanced Debugging Output [author] => AskApache [version] => 1.1.1 [requires-at-least] => 2.7 [tested-up-to] => 3.0 [tags] => debug, debugging, error, errors, problems, support, admin, programmer, developer, plugin, development, information, stats, logs [contributors] => AskApache [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/deb [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] => tools_page_askapache-debug-viewer [action] => tools.php?page=askapache-debug-viewer.php [op] => adv_ */ function get_plugin_data($type='settings') { $pp = get_option("askapache_debug_plugin"); if(is_array($pp) && sizeof($pp)>10) return $pp; $data = $this->_readfile(__FILE__, 750); $mtx = $plugin = array(); preg_match_all('/[^a-z0-9]+((?:[a-z0-9]{2,25})(?:\ ?[a-z0-9]{2,25})?(?:\ ?[a-z0-9]{2,25})?)\:[\s\t]*(.+)/i', $data, $mtx, PREG_SET_ORDER); foreach ($mtx as $m) $plugin[trim(str_replace(' ', '-', strtolower($m[1])))] = str_replace(array("\r", "\n", "\t"), '', trim($m[2])); $plugin['title'] = '' . $plugin['plugin-name'] . ''; $plugin['author'] = '' . $plugin['author'] . ''; $plugin['pb'] = preg_replace('|^' . preg_quote(WP_PLUGIN_DIR, '|') . '/|', '', __FILE__); $plugin['page'] = basename(__FILE__); $plugin['pagenice'] = rtrim($plugin['page'], '.php'); $plugin['nonce'] = 'form_' . $plugin['pagenice']; $plugin['hook'] = $type.'_page_' . $plugin['pagenice']; $type = ($type=='settings') ? 'options-general' : $type; $plugin['action'] = $type.'.php?page=' . $plugin['page']; if (preg_match_all('#(?:([^\W_]{1})(?:[^\W_]*?\W+)?)?#i', $plugin['pagenice'] . '.' . $plugin['version'], $m, PREG_SET_ORDER))$plugin['op'] = ''; foreach($m as $k) sizeof($k == 2) && $plugin['op'] .= $k[1]; $plugin['op'] = substr($plugin['op'], 0, 3) . '_'; return $plugin; } /** AA_DEBUG::_ls() * * @param string $folder * @param integer $levels * @return */ function _ls( $folder = '', $levels = 2 ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( empty($folder) || ! $levels ) return false; $files = array(); if ( ($dir = opendir($folder)) !== false ) { while ( ($file = readdir($dir)) !== false ) { if ( in_array($file, array('.', '..')) ) continue; if ( is_dir($folder . '/' . $file) ) { $files2 = $this->_ls( $folder . '/' . $file, ($levels - 1) ); if ( $files2 ) $files = array_merge( $files, $files2 ); else $files[] = $folder . '/' . $file . '/'; } else $files[] = $folder . '/' . $file; } } closedir( $dir ); return $files; } /** AA_DEBUG::_pls() * * @param string $folder * @param integer $levels * @param integer $format * @return */ function _pls( $folder = '.', $levels = 2, $format = 1 ) { // $folder = ($folder=='.') ? getcwd() : realpath("."); $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $list = $fls = array(); $fls = $this->_ls( $folder, $levels ); foreach ( $fls as $file ) { $fs = $this->_stat( $file ); $list[] = sprintf( "%10s %04s %06s %' 8s %s %' 15s %s", $fs['human'], $fs['octal'], $fs['decimal'], $fs['owner_name'], $fs['group_name'], $fs['size'] . ' bytes', str_replace(dirname($folder), '/', realpath($file)) ); } echo '
'; echo join( "\n", array_merge(array($folder . " Listing"), $list) ); echo ''; } /** AA_DEBUG::_is_readable() * * @param mixed $fl * @return */ function _is_readable( $fl ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( is_dir($fl) ) return is_readable( $fl ); return ( $this->_file_exists($fl) && (is_readable($fl) || $this->_fclose($this->_fopen($fl, 'rb'))) ) ? true : false; } /** AA_DEBUG::_file_exists() * * @param mixed $fl * @return */ function _file_exists( $fl ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); return ( ((file_exists($fl)) === false && (@realpath($fl)) === false) || ($s = @stat($fl)) === false ) ? false : true; } /** AA_DEBUG::_stat() * * @param mixed $fl * @return */ function _stat( $fl ) { static $ftypes = false; if ( !$ftypes && false !==($this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ))) $ftypes = array(S_IFSOCK=>'ssocket', S_IFLNK=>'llink', S_IFREG=>'-file', S_IFBLK=>'bblock', S_IFDIR=>'ddir', S_IFCHR=>'cchar', S_IFIFO=>'pfifo'); $s = $ss = array(); if ( ($ss = stat($fl)) === false ) return $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "Couldnt stat {$fl}"); $p = $ss['mode']; $t = decoct($p & S_IFMT); $q = octdec($t); $type = (array_key_exists($q,$ftypes))?substr($ftypes[$q],1):'?'; $s = array( 'filename' => $fl, 'human' => ( substr($ftypes[$q],0,1) .(($p & S_IRUSR)?'r':'-') .(($p & S_IWUSR)?'w':'-') .(($p & S_ISUID)?(($p & S_IXUSR)?'s':'S'):(($p & S_IXUSR)?'x':'-')) .(($p & S_IRGRP)?'r':'-') .(($p & S_IWGRP)?'w':'-') .(($p & S_ISGID)?(($p & S_IXGRP)?'s':'S'):(($p & S_IXGRP)?'x':'-')) .(($p & S_IROTH)?'r':'-') .(($p & S_IWOTH)?'w':'-') .(($p & S_ISVTX)?(($p & S_IXOTH)?'t':'T'):(($p & S_IXOTH)?'x':'-'))), 'octal' => sprintf("%o",($ss['mode'] & 007777)), 'hex' => sprintf("0x%x", $ss['mode']), 'decimal' => sprintf("%d", $ss['mode']), 'binary' => sprintf("%b", $ss['mode']), 'base_convert' => base_convert($ss['mode'], 10, 8), 'fileperms' => ($this->_cf('fileperms') ? fileperms($fl) : ''), 'mode' => $p, 'fileuid' => $ss['uid'], 'filegid' => $ss['gid'], 'owner_name' => $this->get_posix_info('user', $ss['uid'], 'name'), 'group_name' => $this->get_posix_info('group', $ss['gid'], 'name'), 'dirname' => dirname($fl), 'type_octal' => sprintf("%07o", $q), 'type' => $type, 'device' => $ss['dev'], 'device_number' => $ss['rdev'], 'inode' => $ss['ino'], 'is_file' => is_file($fl) ? 1 : 0, 'is_dir' => is_dir($fl) ? 1 : 0, 'is_link' => is_link($fl) ? 1 : 0, 'is_readable' => is_readable($fl) ? 1 : 0, 'is_writable' => is_writable($fl) ? 1 : 0, 'link_count' => $ss['nlink'], 'size' => $ss['size'], 'blocks' => $ss['blocks'], 'block_size' => $ss['blksize'], 'accessed' => date('Y M D H:i:s', $ss['atime']), 'modified' => date('Y M D H:i:s', $ss['mtime']), 'created' => date('Y M D H:i:s', $ss['ctime']), 'mtime' => $ss['mtime'], 'atime' => $ss['atime'], 'ctime' => $ss['ctime'] ); if ( is_link($fl) ) $s['link_to'] = readlink( $fl ); if ( realpath($fl) != $fl ) $s['real_filename'] = realpath( $fl ); return $s; } /** AA_DEBUG::_fclose() * * @param mixed $fh * @return */ function _fclose( &$fh ) { $this->t( __FUNCTION__ ); return ( ((@fclose($fh)) !== false && ($fh=null)!== false) || ! is_resource($fh) ) ? true : false; } /** AA_DEBUG::_fopen() * * @param mixed $file * @param mixed $mode * @return */ function _fopen( $file, $mode ) { $this->t( __FUNCTION__ ); //$filemodes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+', 'xb', 'xb+', 'rt', 'rt+', 'wt', 'wt+', 'at', 'at+', 'xt', 'xt+'); // $out='';foreach((array)stream_get_meta_data($fh) as $k=>$v)$out.="$k => $v\n";$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "$out"); return ( (strspn($mode, 'abrtwx+')==strlen($mode)) && ($fh = @fopen($file, $mode)) !== false ) ? $fh : false; } /** AA_DEBUG::_fread() * * @param mixed $fh * @param mixed $ts * @param integer $bs * @return */ function _fread( &$fh, $ts = false, $bs = 2048 ) { $this->t( __FUNCTION__ ); for ( $d = $b = '', $rt = $at = $r = 0; ($fh !== false && ! feof($fh) && $b !== false && $at < 50000000 && $rt < $ts); $r = $ts - $rt, $bs = (($bs > $r) ? $r : $bs), $this->t("R: {$rt}"), $b = fread($fh, $bs), $br = strlen($b), $d .= $b, $this->t("R: {$rt}"), $rt += $br, $at++ ,$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, " [RT: {$rt}]\t[BR: {$br}" . (($ts != 50000000) ? "]\t\t [{$r} / {$ts}]" : " : {$bs}]\t[{$at}]")) ) ; $this->t( __FUNCTION__ ); return ( (strlen($d) != 0) ) ? $d : false; } /** AA_DEBUG::_fwrite() * * @param mixed $fh * @param mixed $d * @param integer $bs * @return */ function _fwrite( &$fh, $d, $bs = 512 ) { for ( $bw = $wt = $at = 0, $ts = strlen($d), $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, " starting write.. {$ts} bytes total with blocksize {$bs}"); ($fh !== false && $bw !== false && $at < 1000 && $wt < $ts); $r = $ts - $wt, $bs = ($bs > $r) ? $r : $bs, $bw = fwrite($fh, substr($d, $wt), $bs), $wt += $bw, $at++ ); $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, " {$at}: {$bw} / {$wt} of {$ts}" ); return ( $wt == $ts ) ? true : false; } /** AA_DEBUG::_readfile() * * @param mixed $file * @param mixed $len * @return */ function _readfile( $file, $len = false ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( ! $this->_file_exists($file) ) return $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "no such file! {$file}"); if ( ! $len ) $len = filesize( $file ); if ( ($fh = $this->_fopen($file, 'rb')) === false ) return $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "Error opening rb handle for {$file}"); $data = $this->_fread( $fh, $len ); return ( ! $this->_fclose($fh) ) ? $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "Error closing rb handle on {$file}") : $data; } /** AA_DEBUG::_mkdir() * * @param mixed $dir * @param integer $mode * @return */ function _mkdir( $dir, $mode = 0755 ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( ! wp_mkdir_p($dir) ) return $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "Couldnt create directory! ${dir}" ); } /** AA_DEBUG::_rmdir() * * @param mixed $dir * @return */ function _rmdir( $dir ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $dir = rtrim( str_replace('//', '/', $dir), '/' ); if ( is_dir($dir) && ! is_link($dir) ) { $d = dir( $dir ); while ( false !== ($r = $d->read()) ) { if ( $r == "." || $r == ".." || (($f = $d->path . '/' . $r) && is_link($f)) ) continue; if ( ! $this->_rmdir($f) ) return $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "Error Deleting: " . $f); } $d->close(); return rmdir( $dir ); } else return $this->_unlink( $dir ); } /** AA_DEBUG::_unlink() * * @param mixed $f * @return */ function _unlink( $f ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( unlink($f) || ! $this->_file_exists($f) ) return true; if ( ! $this->_file_exists($f) ) return true; if ( is_dir($f) ) return $this->_rmdir( $f ); else chmod( $f, FS_CHMOD_DIR ); return ( unlink($f) || ! $this->_file_exists($f) ); } /** AA_DEBUG::_is_writable() * * @param mixed $fl * @return */ function _is_writable( $fl ) { // if ( is_dir( $fl ) || $fl{strlen( $fl ) - 1} == '/' ) $fl = $this->tslashit($fl).microtime().'.tmp'; $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); if ( is_writable($fl) || touch($fl) ) return true; $exists = ( bool )$this->_file_exists( $fl ); $dir = ( bool )is_dir( $fl ); if ( $exists && ! @chmod($fl, FS_CHMOD_FILE) && ! @chmod(dirname($file), FS_CHMOD_DIR) && ! @chmod($file, FS_CHMOD_FILE) && ! @touch($fl) ) return false; if ( $dir === true ) $tfl = $fl . '/' . $this->_get_rand_str( 8 ) . '.tmp'; $w = ( bool )( $this->_fclose($this->_fopen($fl, 'a')) || $this->_fclose($this->_fopen($fl, 'x')) || $this->_fclose($this->_fopen($fl, 'w')) ) ? true : false; if ( $d === true || $e === false ) $this->_unlink( $fl ); return $w; } /** AA_DEBUG::_get_rand_str() * * @param mixed $l * @param mixed $c * @return */ function _get_rand_str($l=null,$c=null) { $this->to_log(__FUNCTION__ . ':' . __LINE__); static $chars; !is_null($c) && $chars=$c; is_null($chars) && $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; is_null($l) && $l = rand(4,8); return substr(str_shuffle($chars . $chars . $chars), 0, $l); } /** AA_DEBUG::_stripdeep() * * @param mixed $value * @return */ function _stripdeep(&$value){ return(is_array($value) ? array_map(array($this,'_stripdeep'), $value) : stripslashes($value));} /** AA_DEBUG::_parse_args() * * @param mixed $a * @param string $d * @param string $r * @return */ function _parse_args($a,$d='',$r=''){ return(false!==($r=(is_object($a)?get_object_vars($a):((!is_array($a)&&false!==(parse_str($a,$r)))?$r:$a)))&&is_array($d)?array_merge($d,$r):$r); } function tt($id = 'new', $d = false) { static $a = array(); $ct = array_sum(explode(chr(32), microtime())); if (!isset($a[$id])) return $a[$id] = $ct; elseif ($d) return sprintf("%.4f", ($ct - $a[$id])); } function t($f = '') { if (($this->tt($f, 1)) == '') return; //error_log('PHP AA DEBUG: TIME: [' . $this->tt($f, 1) . '] [' . $this->tt(__FILE__, 1)."] [{".$this->mem_usage(1)."}] {$f}", 0); } /** AA_DEBUG::_cf() * * @param mixed $f * @return */ function _cf($f) { static $b=NULL,$g = array(); if(is_null($b)) $b = ( function_exists('ini_get') ) ? explode(',',strtolower(ini_get('disable_functions'))) : array(); if ( false!==($f=strtolower($f)) && ( in_array($f, $g) || in_array($f, $b)) ) return (in_array($f, $g)); return (!function_exists($f)) ? !( $b[] = $f ) : !!( $g[] = $f ); } /** AA_DEBUG::mem_usage() * * @param mixed $raw * @return */ function mem_usage($raw = false) { static $v=NULL,$m=NULL; if(is_null($m)) $m = $this->_cf('memory_get_usage'); if ($m === false) return 1; if(is_null($v)) $v = version_compare(phpversion(), '5.2.0', '>='); $mem = (($v === false) ? memory_get_usage(true) : memory_get_usage()); return(($raw !== false) ? $this->bytes($mem) : $mem); } /** AA_DEBUG::bytes() * * @param integer $b * @return */ function bytes($b = 0) { static $s=NULL; if(is_null($s)) $s = array('B', 'Kb', 'MB', 'GB', 'TB', 'PB'); $e = floor(log($b) / log(1024)); return sprintf('%.2f ' . $s[$e], (($b > 0) ? ($b / pow(1024, floor($e))) : 0)); } /** AA_DEBUG::_do_update() * * @param mixed $check_time * @param integer $newer_than * @return */ function _do_update( $check_time, $newer_than = 300 ) { $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $time = ( time() - $check_time ); return ( $newer_than < $time ) ? true : false; } /** AA_DEBUG::pp() * * @param mixed $text * @param integer $format * @return */ function pp( $obj, $format = 1 ) { $out=''; if (is_array($obj) || is_object($obj)) $out.="\n".print_r($obj,1)."\n"; else { if(is_string($obj))$out.=$obj; else { ob_start(); var_dump($obj); $out.=ob_get_clean();} } printf( '
%s', htmlspecialchars($out) ); return true; } function d($level=0) { return (bool) ( isset($GLOBALS["aa_debug_object"]) && absint($GLOBALS["aa_debug_object"]->debug) > absint($level) ) ? true : false; } function aadv_logg($f='', $fu='', $l='', $m='') { $this->t($f.'::'.$fu); $msg="PHP AA_DEBUG Notice: {$fu}() {$m}"; if($this->options['log_errors']=1) if($this->d(20))echo($this->debug . ' ' . $msg."\n"); elseif($this->d(4)) error_log($msg); } /** AA_DEBUG::get_error_log()ions['logfile']=$log_file=@ini_get( 'error_log' ); $log_file * * @return */ function get_error_log() { $this->opt = ( is_array($this->options) && isset($this->options['logfile']) ) ? $this->options['logfile'] : @ini_get( 'error_log' ); $log_file = ($log_file !== false && ! empty($log_file) ) ? $log_file : false; return $log_file; } /** AA_DEBUG::get_error_levels() * * @return */ function get_error_levels() { /* $err_type = array ( 1 => "Error", // E_ERROR 2 => "Warning", // E_WARINING 4 => "Parsing Error", // E_PARSE 8 => "Notice", // E_NOTICE 16 => "Core Error", // E_CORE_ERROR 32 => "Core Warning", // E_CORE_WARNING 64 => "Compile Error", // E_COMPILE_ERROR 128 => "Compile Warning", // E_COMPILE_WARNING 256 => "User Error", // E_USER_ERROR 512 => "User Warning", // E_USER_WARMING 1024=> "User Notice", // E_USER_NOTICE 2048=> "Strict Notice", // E_STRICT 4096=> "Catchable fatal error", // E_RECOVERABLE_ERROR ); */ $this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); $error_levels=array( 'E_ERROR','E_WARNING','E_PARSE','E_NOTICE','E_CORE_ERROR','E_CORE_WARNING','E_COMPILE_ERROR','E_COMPILE_WARNING','E_USER_ERROR','E_USER_WARNING','E_USER_NOTICE','E_STRICT','E_RECOVERABLE_ERROR','E_DEPRECATED','E_USER_DEPRECATED','E_ALL' ); $eany=0; foreach($error_levels as $k) { if(defined($k)){ $ev=constant($k); $eany |= $ev; $e[$k]=$ev; } } $e['E_ANY']=$eany; return $e; } /** AA_DEBUG::get_posix_info() * * @param string $type * @param string $id * @param mixed $item * @return */ function get_posix_info( $type = 'all', $id = '', $item = false ) { static $egid,$pwuid,$grgid,$euid; if(!$egid && $this->_cf('posix_getegid')) $egid=posix_getegid(); if(!$euid && $this->_cf('posix_geteuid')) $euid=posix_geteuid(); if(!$pwuid && $this->_cf('posix_getpwuid')) $pwuid=posix_getpwuid($egid); if(!$grgid && $this->_cf('posix_getgrgid')) $grgid=posix_getgrgid($euid); // 'Group Info by Name' => array('posix_getgrnam', $group_info['name'] ) //$this->aadv_logg(__FILE__,__FUNCTION__,__LINE__, "" ); //$ownerIsMe = PHP_OS == 'WIN' ? fileowner(__FILE__) == getmyuid() : function_exists( 'posix_geteuid' ) && fileowner(__FILE__) == posix_geteuid(); /* if( !(function_exists('posix_geteuid'))) { function posix_geteuid() { return false; } } */ /* if ( function_exists('curl_init') ) { return true; } else { return false; } return extension_loaded('curl'); */ /* strpos(php_sapi_name(), 'cgi') === 0 preg_match( "|uid=(\d+)\((\S+)\)\s+gid=(\d+)\((\S+)\)\s+groups=(.+)|i", $id_raw, $matches); if ($matches[5]) { $gs = $matches[5]; $gs = explode(',', $gs); foreach ($gs as $groupstr) { preg_match("/(\d+)\(([^\)]+)\)/", $groupstr, $subs); $groups[$subs[1]] = $subs[2]; } ksort($groups); $id_data['groups'] = $groups; } if (!$success && function_exists("posix_getpwuid") && function_exists("posix_geteuid") && function_exists('posix_getgrgid') && function_exists('posix_getgroups') ) { $data = posix_getpwuid( posix_getuid() ); $id_data['uid'] = $data['uid']; $id_data['username'] = $data['name']; $id_data['gid'] = $data['gid']; //$group_data = posix_getgrgid( posix_getegid() ); //$id_data['group'] = $group_data['name']; $groups = posix_getgroups(); foreach ( $groups as $gid ) { //$group_data = posix_getgrgid(posix_getgid()); $id_data['groups'][$gid] = '
define(\'SAVEQUERIES\', true);' . __('in your') . ' wp-config.phpSAVEQUERIES' . ' ' . __('at') . ' TRUE ' . __('in your') . ' wp-config.php".htmlspecialchars(ob_get_clean())."";')); } */ /** AA_DEBUG::get_debug_loaded_extensions() * * @param mixed $vb * @return */ function get_debug_loaded_extensions( $vb = false ) { $oa = array(); foreach ((array)(($this->_cf('get_loaded_extensions')?get_loaded_extensions():array())) as $k=>$v) $oa[$v]=(($vb===false)?'':(array)($this->_cf('get_extension_funcs')?get_extension_funcs($v):array())); return $oa; } /** AA_DEBUG::get_debug_defined() * * @param mixed $vb * @return */ function get_debug_defined( $vb = false ) { $oa = array(); foreach ((array)(($this->_cf('get_defined_constants')?get_defined_constants():array())) as $k=>$v) if(($vb===true)||(!$vb&&in_array($k,array('ABSPATH','WP_ADMIN'))&&$vb=true))$oa[$k]=$v; foreach (array('WP_TEMP_DIR','WP_SITEURL','WP_HOME','ABSPATH','WP_CONTENT_URL','WP_CONTENT_DIR','WP_PLUGIN_DIR','WP_PLUGIN_URL','WP_LANG_DIR','TEMPLATEPATH','STYLESHEETPATH','WPINC','COOKIEPATH','SITECOOKIEPATH','ADMIN_COOKIE_PATH','PLUGINS_COOKIE_PATH','PHP_SAPI','PHP_OS','PHP_VERSION') as $d) if(defined($d)&&$v=constant($d)&&!empty($v)) $oa[$d]=$v; return array($oa); } /** AA_DEBUG::get_debug_inis() * * @param mixed $vb * @return */ function get_debug_inis( $vb = false ) { $oa = array(); if($this->_cf('ini_get')) { foreach ( array( 'Error Log' => 'error_log', 'Session Data Path' => 'session.save_path', 'Upload Tmp Dir' => 'upload_tmp_dir', 'Include Path' => 'include_path', 'Memory Limit' => 'memory_limit', 'Max Execution Time' => 'max_execution_time', 'Display Errors' => 'display_errors', 'Allow url fopen' => 'allow_url_fopen', 'Disabled Functions' => 'disable_functions', 'Safe Mode' => 'safe_mode', 'Open Basedir' => 'open_basedir', 'File Uploads' => 'file_uploads', 'Max Upload Filesize' => 'upload_max_filesize', 'Max POST Size' => 'post_max_size', 'Open Basedir' => 'open_basedir' ) as $t=>$n)$oa[$n]=strval(ini_get($n)); } if ($vb!==false && $this->_cf('ini_get_all')) foreach ((array)@ini_get_all() as $k=>$v) $oa[$k]=(($v['global_value']==$v['local_value'])?$v['global_value']:$v); return array($oa); } /** AA_DEBUG::get_debug_phpinfo() * * @return */ function get_debug_phpinfo() { $oa = array(); if($this->_cf('phpinfo')) { ob_start(); phpinfo( -1 ); $oa = preg_replace(array('#^.*(.*).*$#ms','#