| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: oik bwtrace |
| 5 |
Plugin URI: http://www.oik-plugins.com/oik |
| 6 |
Description: Easy to use trace macros for oik plugins |
| 7 |
Version: 1.4 |
| 8 |
Author: bobbingwide |
| 9 |
Author URI: http://www.bobbingwide.com |
| 10 |
License: GPL2 |
| 11 |
|
| 12 |
Copyright 2011 Bobbing Wide (email : herb@bobbingwide.com ) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License version 2, |
| 16 |
as published by the Free Software Foundation. |
| 17 |
|
| 18 |
You may NOT assume that you can use any other version of the GPL. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
The license for this software can likely be found here: |
| 26 |
http://www.gnu.org/licenses/gpl-2.0.html |
| 27 |
|
| 28 |
*/ |
| 29 |
global $bw_trace_options, $bw_trace_on, $bw_trace_level; |
| 30 |
|
| 31 |
|
| 32 |
$bwapi_trace_test = 'bw_trace'; |
| 33 |
|
| 34 |
|
| 35 |
require_once( 'bwtrace.inc'); |
| 36 |
require_once( 'bobbfunc.inc' ); |
| 37 |
require_once( 'bobblink.inc' ); |
| 38 |
|
| 39 |
function oik_bwtrace_version() { |
| 40 |
return oik_version(); |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
function bw_this_plugin_first() { |
| 45 |
// ensure path to this file is via main wp plugin path |
| 46 |
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__); |
| 47 |
$this_plugin = plugin_basename(trim($wp_path_to_this_file)); |
| 48 |
$active_plugins = get_option('active_plugins'); |
| 49 |
$this_plugin_key = array_search($this_plugin, $active_plugins); |
| 50 |
if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue |
| 51 |
array_splice($active_plugins, $this_plugin_key, 1); |
| 52 |
array_unshift($active_plugins, $this_plugin); |
| 53 |
update_option('active_plugins', $active_plugins); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
if (function_exists( "add_action" )) { |
| 60 |
bw_trace_plugin_startup(); |
| 61 |
} |
| 62 |
|
| 63 |
function bw_trace_plugin_startup() { |
| 64 |
|
| 65 |
global $bw_trace_options; |
| 66 |
add_action("activated_plugin", "bw_this_plugin_first"); |
| 67 |
|
| 68 |
|
| 69 |
/* Shortcodes for each of the more useful APIs */ |
| 70 |
add_shortcode( 'bwtron', 'bw_trace_on' ); |
| 71 |
add_shortcode( 'bwtroff', 'bw_trace_off'); |
| 72 |
add_shortcode( 'bwtrace', 'bw_trace_button' ); |
| 73 |
|
| 74 |
add_filter('widget_text', 'do_shortcode'); |
| 75 |
add_filter('the_title', 'do_shortcode' ); |
| 76 |
add_filter('wpbody-content', 'do_shortcode' ); |
| 77 |
|
| 78 |
|
| 79 |
$bw_trace_options = get_option( 'bw_trace_options' ); |
| 80 |
|
| 81 |
$bw_trace_level = $bw_trace_options[ 'trace']; |
| 82 |
if ( $bw_trace_level > '0' ) { |
| 83 |
bw_trace_on(); |
| 84 |
} |
| 85 |
else { |
| 86 |
bw_trace_off(); |
| 87 |
} |
| 88 |
|
| 89 |
$bw_trace_reset = $bw_trace_options[ 'reset']; |
| 90 |
if ( $bw_trace_reset > '0' ) { |
| 91 |
bw_trace_reset(); |
| 92 |
} |
| 93 |
else { |
| 94 |
// Don't reset the trace file |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
//$bw_trace_errors = $bw_trace_options[ 'errors']; |
| 100 |
//bw_trace_errors( $bw_trace_errors ); |
| 101 |
|
| 102 |
// bw_trace_log( "Trace log starting" ); |
| 103 |
|
| 104 |
if ( $bw_trace_level > '0' ) { |
| 105 |
bw_trace( ABSPATH . $bw_trace_options['file'], __FUNCTION__, __LINE__, __FILE__, 'tracelog' ); |
| 106 |
bw_trace( $_SERVER, __FUNCTION__, __LINE__, __FILE__, "_SERVER" ); |
| 107 |
bw_trace( bw_getlocale(), __FUNCTION__, __LINE__, __FILE__, "locale" ); |
| 108 |
//bw_trace( $_GET, __FUNCTION__, __LINE__, __FILE__, "_GET" ); |
| 109 |
//bw_trace( $_POST, __FUNCTION__, __LINE__, __FILE__, "_POST" ); |
| 110 |
bw_trace( $_REQUEST, __FUNCTION__, __LINE__, __FILE__, "_REQUEST" ); |
| 111 |
//bw_trace( ABSPATH, __FUNCTION__, __LINE__, __FILE__, "ABSPATH" ); |
| 112 |
|
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
add_action('admin_init', 'bw_trace_options_init' ); |
| 117 |
add_action('admin_menu', 'bw_trace_options_add_page'); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
// Init plugin options to white list our options |
| 122 |
function bw_trace_options_init(){ |
| 123 |
register_setting( 'bw_trace_options_options', 'bw_trace_options', 'bw_trace_options_validate' ); |
| 124 |
} |
| 125 |
|
| 126 |
// Add menu page |
| 127 |
function bw_trace_options_add_page() { |
| 128 |
add_options_page('oik trace options', 'oik trace options', 'manage_options', 'bw_trace_options', 'bw_trace_options_do_page'); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
// Draw the menu page itself |
| 134 |
function bw_trace_options_do_page() { |
| 135 |
require_once( "bobbforms.inc" ); |
| 136 |
|
| 137 |
sdiv( "column span-14 wrap" ); |
| 138 |
h2( bw_oik(). " trace options" ); |
| 139 |
e( '<form method="post" action="options.php">' ); |
| 140 |
$options = get_option('bw_trace_options'); |
| 141 |
|
| 142 |
stag( 'table class="form-table"' ); |
| 143 |
bw_flush(); |
| 144 |
settings_fields('bw_trace_options_options'); |
| 145 |
|
| 146 |
textfield( "bw_trace_options[file]", 60, "Trace file", $options['file'] ); |
| 147 |
textfield( "bw_trace_options[trace]", 1 ,"Trace level (1=on)", $options['trace'] ); |
| 148 |
textfield( "bw_trace_options[reset]", 1 ,"Trace reset (1=each txn)", $options['reset'] ); |
| 149 |
// Trace error processing is not yet enabled. |
| 150 |
// textfield( "bw_trace_options[errors]", 1 ,"Trace errors (0=no,-1=all,1=E_ERROR,2=E_WARNING,4=E_PARSE, etc)", $options['errors'] ); |
| 151 |
|
| 152 |
|
| 153 |
tablerow( "", "<input type=\"submit\" name=\"ok\" value=\"Save changes\" />" ); |
| 154 |
|
| 155 |
etag( "table" ); |
| 156 |
etag( "form" ); |
| 157 |
|
| 158 |
ediv(); |
| 159 |
sediv( "clear" ); |
| 160 |
sdiv("column span-14 wrap"); |
| 161 |
|
| 162 |
h2( "Notes about " . bw_oik() . " trace" ); |
| 163 |
p("The tracing output produced by " .bw_oik(). " trace can be used for problem determination."); |
| 164 |
p("It's not for the faint hearted."); |
| 165 |
p("The oik plugin should <b>not</b> need to be activated on a live site"); |
| 166 |
p("If you do need to activate it, only do so for a short period of time." ); |
| 167 |
|
| 168 |
p("You will need to specify the trace file name (e.g. bwtrace.log )" ); |
| 169 |
p("Set trace level to 1 when you want to trace processing. 0 otherwise"); |
| 170 |
p("If you want to clear the trace output set trace reset to 1, save changes, then set it back to 0"); |
| 171 |
|
| 172 |
p("You may find the most recent trace output at..." ); |
| 173 |
$bw_trace_url = bw_trace_url(); |
| 174 |
|
| 175 |
alink( NULL, $bw_trace_url, $bw_trace_url, "View trace output in your browser."); |
| 176 |
p("If you want to trace processing within some content you can use two shortcodes"); |
| 177 |
p("Use [bwtron] to turn trace on and [bwtroff] to turn it off" ); |
| 178 |
|
| 179 |
p("For more information:" ); |
| 180 |
art_button( "http://www.oik-plugins.com/oik", bw_oik() . " documentation", "Read the documentation for the oik plugin" ); |
| 181 |
ediv(); |
| 182 |
bw_flush(); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
// Sanitize and validate input. Accepts an array, return a sanitized array. |
| 187 |
function bw_trace_options_validate($input) { |
| 188 |
// Our first value is either 0 or 1 |
| 189 |
//$input['option1'] = ( $input['option1'] == 1 ? 1 : 0 ); |
| 190 |
|
| 191 |
// Say our second option must be safe text with no HTML tags |
| 192 |
//$input['sometext'] = wp_filter_nohtml_kses($input['sometext']); |
| 193 |
|
| 194 |
return $input; |
| 195 |
} |
| 196 |
|
| 197 |
function bw_trace_url() { |
| 198 |
|
| 199 |
$options = get_option('bw_trace_options'); |
| 200 |
|
| 201 |
$bw_trace_url = get_site_url( NULL, $options['file'] ); |
| 202 |
return( $bw_trace_url ); |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|