| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| 7 | 7 | | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | | |
| 8 | 8 | | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| | |
| 9 | 9 | | | |
| 10 | - | (c) Jerome Bruandet ~ https://code-profiler.com/ | | |
| 10 | + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ | | |
| 11 | 11 | +=====================================================================+ |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | if (! defined('ABSPATH') ) { die('Forbidden'); } |
| @@ -42,8 +42,11 @@ | ||
| 42 | 42 | |
| 43 | 43 | // Clear the log if it's too big |
| 44 | 44 | code_profiler_clearlog(); |
| 45 | 45 | |
| 46 | +// Clean-up temp files left in the profiles folder | |
| 47 | +code_profiler_cleantmpfiles(); | |
| 48 | + | |
| 46 | 49 | $home = home_url('/'); // Frontend |
| 47 | 50 | $site = site_url('/'); // Backend |
| 48 | 51 | // Get user login name |
| 49 | 52 | $current_user = wp_get_current_user(); |
| @@ -66,8 +69,12 @@ | ||
| 66 | 69 | } |
| 67 | 70 | if ( empty( $cp_options['mem_method'] ) ) { |
| 68 | 71 | $cp_options['mem_method'] = 'get'; |
| 69 | 72 | } |
| 73 | +$default_theme = get_option('stylesheet'); | |
| 74 | +if ( empty( $cp_options['mem_theme'] ) ) { | |
| 75 | + $cp_options['mem_theme'] = $default_theme; | |
| 76 | +} | |
| 70 | 77 | if ( empty( $cp_options['ua'] ) ) { |
| 71 | 78 | $cp_options['ua'] = 'Firefox'; |
| 72 | 79 | } |
| 73 | 80 | $cookies = ''; |
| @@ -72,17 +79,28 @@ | ||
| 72 | 79 | } |
| 73 | 80 | $cookies = ''; |
| 74 | 81 | $payload = ''; |
| 75 | 82 | $custom_headers = ''; |
| 83 | +$exclusions = []; | |
| 84 | + | |
| 76 | 85 | if ( isset( $cp_options['cookies'] ) ) { |
| 77 | - $cookies = trim( json_decode( $cp_options['cookies'] ) ); | |
| 86 | + // stripslashes is only needed for cookies | |
| 87 | + $cookies = trim( stripslashes( json_decode( $cp_options['cookies'] ) ) ); | |
| 78 | 88 | } |
| 89 | +if ( empty( $cp_options['mem_content_type'] ) || | |
| 90 | + ! in_array( $cp_options['mem_content_type'], [ 1, 2 ] ) ) { | |
| 91 | + | |
| 92 | + $cp_options['mem_content_type'] = 1; | |
| 93 | +} | |
| 79 | 94 | if ( isset( $cp_options['payload'] ) ) { |
| 80 | - $payload = trim( json_decode( $cp_options['payload'] ) ); | |
| 95 | + $payload = trim( json_decode( $cp_options['payload'] ) ); | |
| 81 | 96 | } |
| 82 | 97 | if ( isset( $cp_options['custom_headers'] ) ) { |
| 83 | 98 | $custom_headers = trim( json_decode( $cp_options['custom_headers'] ) ); |
| 84 | 99 | } |
| 100 | +if ( isset( $cp_options['exclusions'] ) ) { | |
| 101 | + $exclusions = json_decode( $cp_options['exclusions'] ); | |
| 102 | +} | |
| 85 | 103 | ?> |
| 86 | 104 | <table class="form-table"> |
| 87 | 105 | <tr> |
| 88 | 106 | <th scope="row"><?php esc_html_e('Page to profile', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Select the page you want the profiler to analyze. It can be in the frontend of the site, in the admin backend or a custom URL.', 'code-profiler') ?>"></span></th> |
| @@ -148,8 +166,27 @@ | ||
| 148 | 166 | <p><label><?php esc_html_e('User:', 'code-profiler') ?> <input type="text" name="username" id="user-name" value ="<?php esc_attr_e( $username ) ?>"<?php disabled( $cp_options['mem_user'], 'unauthenticated') ?> /></label></p> |
| 149 | 167 | </td> |
| 150 | 168 | </tr> |
| 151 | 169 | <tr> |
| 170 | + <th scope="row"><?php esc_html_e('Theme', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('If you want to profile different themes, you can use this option so that you don\'t need to modify your WordPress settings. The change will not affect your visitors, but only the profiler when it is running.', 'code-profiler') ?>"></span></th> | |
| 171 | + <td> | |
| 172 | + <select name="theme" id="id-theme"> | |
| 173 | + <?php | |
| 174 | + $themes = code_profiler_get_themes(); | |
| 175 | + foreach( $themes as $slug => $name ) { | |
| 176 | + if ( $slug == $default_theme ) { | |
| 177 | + echo '<option value=""'. selected( $cp_options['mem_theme'], $slug, false ) .'>'. | |
| 178 | + esc_html( $name['n'] ) .' '. __('(active theme)', 'code-profiler') .'</option>'; | |
| 179 | + } else { | |
| 180 | + echo '<option value="'. esc_attr( $slug ) .'"'. selected( $cp_options['mem_theme'], $slug, false ) .'>'. | |
| 181 | + esc_html( $name['n'] ) .'</option>'; | |
| 182 | + } | |
| 183 | + } | |
| 184 | + ?> | |
| 185 | + </select> | |
| 186 | + </td> | |
| 187 | + </tr> | |
| 188 | + <tr> | |
| 152 | 189 | <th scope="row"><?php esc_html_e('User agent', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Some themes and plugins may execute different code depending on the type of device used to visit the website (e.g., a desktop computer, a mobile phone, a search engine bot etc). This option lets you change the User-Agent request header used by Code Profiler.', 'code-profiler') ?>"></span></th> |
| 153 | 190 | <td> |
| 154 | 191 | <select name="ua" id="ua-id"> |
| 155 | 192 | <?php |
| @@ -172,9 +209,9 @@ | ||
| 172 | 209 | </td> |
| 173 | 210 | </tr> |
| 174 | 211 | </table> |
| 175 | 212 | <?php |
| 176 | -if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post') { | |
| 213 | +if (! empty( $cookies ) || ! empty( $custom_headers ) || $cp_options['mem_method'] == 'post' || ! empty( $exclusions ) ) { | |
| 177 | 214 | echo '<div id="cp-advanced-settings">'; |
| 178 | 215 | $disabled_button = ' disabled'; |
| 179 | 216 | } else { |
| 180 | 217 | echo '<div id="cp-advanced-settings" style="display:none">'; |
| @@ -184,12 +221,34 @@ | ||
| 184 | 221 | <table class="form-table"> |
| 185 | 222 | <tr> |
| 186 | 223 | <th scope="row"><?php esc_html_e('HTTP Method', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('You can select which HTTP method will be used by the profiler: GET or POST. If you select POST, you can also send an optional payload.', 'code-profiler') ?>"></span></th> |
| 187 | 224 | <td> |
| 188 | - <p><label><input onclick="cpjs_get_post(0);" type="radio" name="method" value="get" id="get-method"<?php checked( $cp_options['mem_method'], 'get') ?> /> <?php esc_html_e('GET (default)', 'code-profiler') ?></label></p> | |
| 189 | - <p><label><input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem_method'], 'post') ?> /> POST</label></p> | |
| 190 | - <p><textarea name="post-value" id="post-value" class="regular-text code"<?php disabled( $cp_options['mem_method'], 'get') ?> maxlength="4000" rows="6"><?php echo esc_textarea( $payload ) ?></textarea></p> | |
| 191 | - <p class="description"><?php printf( esc_html__('Optional POST payload in %s format, one item per line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?> </p> | |
| 225 | + <p> | |
| 226 | + <label> | |
| 227 | + <input onclick="cpjs_get_post(0);" type="radio" name="method" value="get" id="get-method"<?php checked( $cp_options['mem_method'], 'get') ?> /> GET(<?php esc_html_e('default', 'code-profiler') ?>) | |
| 228 | + </label> | |
| 229 | + </p> | |
| 230 | + <p> | |
| 231 | + <label> | |
| 232 | + <input onclick="cpjs_get_post(1);" type="radio" name="method" value="post" id="post-method"<?php checked( $cp_options['mem_method'], 'post') ?> /> POST | |
| 233 | + </label> | |
| 234 | + </p> | |
| 235 | + <p> | |
| 236 | + <?php esc_html_e('Content-type:', 'code-profiler') ?> | |
| 237 | + <select name="cp-content-type" id="id-content-type"<?php disabled( $cp_options['mem_method'], 'get') ?> onChange="cpjs_content_type(this.value);"> | |
| 238 | + <option value="1"<?php selected( $cp_options['mem_content_type'], 1 )?>>application/x-www-form-urlencoded (<?php esc_html_e('default', 'code-profiler') ?>)</option> | |
| 239 | + <option value="2"<?php selected( $cp_options['mem_content_type'], 2 )?>>application/json</option> | |
| 240 | + </select> | |
| 241 | + </p> | |
| 242 | + <p> | |
| 243 | + <textarea name="post-value" id="post-value" class="regular-text code"<?php disabled( $cp_options['mem_method'], 'get') ?> maxlength="4000" rows="6"><?php echo esc_textarea( $payload ) ?></textarea> | |
| 244 | + </p> | |
| 245 | + <p class="description" id="ct-1"<?php echo code_profiler_hide( $cp_options['mem_content_type'], 2) ?>> | |
| 246 | + <?php printf( esc_html__('Optional POST payload in %s format, one item per line.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method-1.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?> | |
| 247 | + </p> | |
| 248 | + <p class="description" id="ct-2"<?php echo code_profiler_hide( $cp_options['mem_content_type'], 1) ?>> | |
| 249 | + <?php printf( esc_html__('Optional JSON-encoded payload.', 'code-profiler'), '<code>name=value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/http_method-2.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?> | |
| 250 | + </p> | |
| 192 | 251 | </td> |
| 193 | 252 | </tr> |
| 194 | 253 | <tr> |
| 195 | 254 | <th scope="row"><?php esc_html_e('Cookie', 'code-profiler') ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('Some websites may execute different code if the user has one or more specific cookies. You can use this field for that purpose.', 'code-profiler') ?>"></span></th> |
| @@ -204,16 +263,27 @@ | ||
| 204 | 263 | <textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="custom-headers" name="custom_headers" class="regular-text code" rows="6"><?php echo esc_textarea( $custom_headers ) ?></textarea> |
| 205 | 264 | <p class="description"><?php printf( esc_html__('Optional HTTP header in %s format, one item per line.', 'code-profiler'), '<code>name: value</code>') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/custom_headers.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?></p> |
| 206 | 265 | </td> |
| 207 | 266 | </tr> |
| 267 | + <tr> | |
| 268 | + <th scope="row" class="row-med"><?php esc_html_e('File and folder exclusions', 'code-profiler'); ?> <span class="code-profiler-tip" data-tip="<?php esc_attr_e('This option lets you exclude files and folders from the profiling process. It can be a full path, a file or a folder name, or any part of them (substring). Values are case-sensitive and only ASCII printable characters are allowed.', 'code-profiler') ?>"></span></th> | |
| 269 | + <td> | |
| 270 | + <textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" id="exclusions" name="exclusions" class="regular-text code" rows="6"><?php | |
| 271 | + foreach( $exclusions as $item ) { | |
| 272 | + echo esc_textarea( $item ) ."\n"; | |
| 273 | + } | |
| 274 | + ?></textarea> | |
| 275 | + <p class="description"><?php esc_html_e('One item per line.', 'code-profiler') ?> <?php printf( esc_html__('%sView example%s', 'code-profiler'), '<a href="'. plugins_url('/static/help/exclusions.png', dirname( __FILE__ ) ) .'" target="_blank" rel="noopener noreferrer">', '</a>') ?></p> | |
| 276 | + </td> | |
| 277 | + </tr> | |
| 208 | 278 | </table> |
| 209 | 279 | </div> |
| 210 | 280 | <?php wp_nonce_field('start_profiler_nonce', 'cp_nonce', 0); ?> |
| 211 | 281 | <br /> |
| 212 | 282 | <div> |
| 213 | - <input type="button" class="button-secondary" id="button-adv-settings" name="adv-settings" value="<?php esc_attr_e('Advanced Options', 'code-profiler') ?>" onclick="cpjs_show_adv_settings();"<?php echo $disabled_button ?> /> | |
| 283 | + <input type="button" class="button button-secondary" id="button-adv-settings" name="adv-settings" value="<?php esc_attr_e('Advanced Options', 'code-profiler') ?>" onclick="cpjs_show_adv_settings();"<?php echo $disabled_button ?> /> | |
| 214 | 284 | |
| 215 | - <input type="button" class="button-primary" id="start-profile" name="start-profile" onClick="cpjs_start_profiler();" value="<?php esc_attr_e('Start Profiling', 'code-profiler') ?> »" title="<?php esc_attr_e('Click to start profiling your code.', 'code-profiler') ?>" /> | |
| 285 | + <input type="button" class="button button-primary" id="start-profile" name="start-profile" onClick="cpjs_start_profiler();" value="<?php esc_attr_e('Start Profiling', 'code-profiler') ?> »" title="<?php esc_attr_e('Click to start profiling your code.', 'code-profiler') ?>" /> | |
| 216 | 286 | </div> |
| 217 | 287 | <div id="cp-progress-div" style="display:none"> |
| 218 | 288 | <br /> |
| 219 | 289 | <div class="cp-progress-bar"><span id="cp-span-progress" style="width:0%"></span></div> |
| @@ -325,9 +395,8 @@ | ||
| 325 | 395 | esc_html__('Dashboard', 'code-profiler') |
| 326 | 396 | ); |
| 327 | 397 | |
| 328 | 398 | } |
| 329 | - | |
| 330 | 399 | return $backend; |
| 331 | 400 | } |
| 332 | 401 | |
| 333 | 402 | // ===================================================================== |