PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.9.6
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.9.6
1.9.6 1.9.5 1.9.4 1.9.3 trunk 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.6 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 All 41 releases
← All changes | static/code-profiler.js +231 -32 1.5.11.9.6 View file →
@@ -5,9 +5,9 @@
5 5 | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| |
6 6 | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | |
7 7 | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| |
8 8 | |
9 - | (c) Jerome Bruandet ~ https://code-profiler.com/ |
9 + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ |
10 10 +=====================================================================+
11 11 */
12 12
13 13 // =====================================================================
@@ -68,28 +68,41 @@
68 68 function cpjs_front_or_backend( item ) {
69 69 'use strict';
70 70 // Enable/disable frontend/backend select box
71 71 // depending on user's choice
72 - if ( item == 1 ) {
72 + if ( item == 'frontend') {
73 73 jQuery('#p-frontend').show();
74 74 jQuery('#p-backend').hide();
75 75 jQuery('#p-custom').hide();
76 + jQuery('#p-wpcron').hide();
76 77 jQuery('#id-frontend').focus();
77 78 jQuery('#user-unauthenticated').prop('disabled', false);
78 - } else if ( item == 2 ) {
79 + jQuery('#user-authenticated').prop('disabled', false);
80 + } else if ( item == 'backend') {
79 81 jQuery('#p-backend').show();
80 82 jQuery('#p-frontend').hide();
81 83 jQuery('#p-custom').hide();
84 + jQuery('#p-wpcron').hide();
82 85 jQuery('#id-backend').focus();
83 86 jQuery('#user-unauthenticated').prop('disabled', true);
87 + jQuery('#user-authenticated').prop('disabled', false);
84 88 jQuery('#user-authenticated').prop('checked', true);
85 89 jQuery('#user-name').prop('disabled', false);
86 - } else {
90 + } else if ( item == 'custom') {
87 91 jQuery('#p-custom').show();
88 92 jQuery('#p-frontend').hide();
89 93 jQuery('#p-backend').hide();
94 + jQuery('#p-wpcron').hide();
90 95 jQuery('#id-custom').focus();
91 96 jQuery('#user-unauthenticated').prop('disabled', false);
97 + jQuery('#user-authenticated').prop('disabled', false);
98 + } else {
99 + jQuery('#p-wpcron').show();
100 + jQuery('#p-custom').hide();
101 + jQuery('#p-frontend').hide();
102 + jQuery('#p-backend').hide();
103 + jQuery('#id-wpcron').focus();
104 + jQuery('#user-unauthenticated').prop('disabled', false);
92 105 }
93 106 }
94 107
95 108 function cpjs_authenticated( id ) {
@@ -108,14 +121,53 @@
108 121
109 122 function cpjs_get_post( id ) {
110 123 if ( id == 1 ) {
111 124 jQuery('#post-value').prop('disabled', false);
125 + jQuery('#id-content-type').prop('disabled', false);
112 126 jQuery('#post-value').focus();
113 127 } else {
114 128 jQuery('#post-value').prop('disabled', true);
129 + jQuery('#id-content-type').prop('disabled', true);
115 130 }
116 131 }
117 132
133 +function cpjs_content_type( value ) {
134 + if ( value == 1 ) {
135 + jQuery('#ct-1').slideDown();
136 + jQuery('#ct-3').slideUp();
137 + jQuery('#ct-2').slideUp();
138 + } else if ( value == 2 ) {
139 + jQuery('#ct-2').slideDown();
140 + jQuery('#ct-3').slideUp();
141 + jQuery('#ct-1').slideUp();
142 + } else {
143 + jQuery('#ct-3').slideDown();
144 + jQuery('#ct-1').slideUp();
145 + jQuery('#ct-2').slideUp();
146 + }
147 +}
148 +
149 +function cpjs_isJSON( data ) {
150 +
151 + if ( jQuery('#id-content-type').val() == 1 || jQuery('#get-method').prop('checked') == true ) {
152 + // Ignore
153 + return 1;
154 + }
155 + try {
156 + return JSON.parse( data );
157 + } catch (e) {
158 + // Not a JSON-encoded string
159 + return null;
160 + }
161 +}
162 +
163 +function cpjs_ismultiline( data ) {
164 + if ( data.match( /[\n\r]/) ) {
165 + return true;
166 + }
167 + return false;
168 +}
169 +
118 170 // =====================================================================
119 171 // Log page: filter and delete the log.
120 172
121 173 function cpjs_filter_log() {
@@ -124,8 +176,9 @@
124 176 var bitmask = 0;
125 177 if ( document.cplogform.info.checked == true ) { bitmask += 1; }
126 178 if ( document.cplogform.warn.checked == true ) { bitmask += 2; }
127 179 if ( document.cplogform.error.checked == true ) { bitmask += 4; }
180 + if ( document.cplogform.debug.checked == true ) { bitmask += 8; }
128 181
129 182 // Clear the textarea
130 183 document.cplogform.cptxtlog.value = '';
131 184
@@ -155,9 +208,15 @@
155 208 // =====================================================================
156 209 // AJAX call to start the profiler.
157 210
158 211 function cpjs_start_profiler() {
212 +
159 213 'use strict';
214 +
215 + jQuery('html, body').animate( {
216 + scrollTop: jQuery('#button-adv-settings').offset().top
217 + }, 1000 );
218 +
160 219 // Get the nonce
161 220 var cp_nonce = jQuery('#cp_nonce').val();
162 221 if ( cp_nonce == '') {
163 222 alert( cpi18n.missing_nonce );
@@ -165,18 +224,25 @@
165 224 }
166 225
167 226 // Get the scan type (frontend/backend)
168 227 var post;
169 - var where = jQuery('input[name="where"]:checked').val();
170 - if ( where == 'frontend') {
228 + var x_end = jQuery('input[name="x_end"]:checked').val();
229 + if ( x_end == 'frontend') {
171 230 post = jQuery('#id-frontend').val();
172 231
173 - } else if ( where == 'backend') {
232 + } else if ( x_end == 'backend') {
174 233 post = jQuery('#id-backend').val();
175 234
176 - } else if ( where == 'custom') {
235 + } else if ( x_end == 'custom') {
177 236 post = jQuery('#id-custom').val().trim(); // Trim user input
178 237
238 + } else if ( x_end == 'wpcron') {
239 + post = jQuery('#id-wpcron').val();
240 + if ( post == 0 ) {
241 + alert( cpi18n.missing_wpcron );
242 + return;
243 + }
244 +
179 245 } else {
180 246 alert( cpi18n.missing_frontbackend );
181 247 return;
182 248 }
@@ -192,16 +258,16 @@
192 258 jQuery('input[name="profile"]').focus();
193 259 return;
194 260 }
195 261
196 - var user = jQuery('input[name="user"]:checked').val();
197 - if ( user == '') {
262 + var x_auth = jQuery('input[name="x_auth"]:checked').val();
263 + if ( x_auth == '') {
198 264 alert( cpi18n.missing_userauth );
199 265 return;
200 266 }
201 267
202 268 var username = jQuery('#user-name').val().trim(); // Trim user input
203 - if ( user == 'authenticated') {
269 + if ( x_auth == 'authenticated') {
204 270 if ( username == '') {
205 271 alert( cpi18n.missing_username );
206 272 jQuery('#user-name').focus();
207 273 return;
@@ -207,13 +273,15 @@
207 273 return;
208 274 }
209 275 }
210 276
211 - var ua = jQuery('#ua-id').val();
212 - if ( ua == 'undefined') {
213 - ua = 'FireFox';
277 + var user_agent = jQuery('#ua-id').val();
278 + if ( user_agent == 'undefined') {
279 + user_agent = 'FireFox';
214 280 }
215 281
282 + var theme = jQuery('#id-theme').val();
283 +
216 284 // GET or POST
217 285 var method = jQuery('input[name="method"]:checked').val();
218 286 var payload = '';
219 287 if ( method == 'post') {
@@ -222,10 +290,30 @@
222 290 } else {
223 291 method = 'get';
224 292 }
225 293
226 - var cookies = jQuery('#cp-cookies').val();
294 + //Content type
295 + var ct = jQuery('#id-content-type').val();
296 + if ( ct == 2 ) {
297 + // application/json
298 + if ( cpjs_isJSON( payload ) == null ) {
299 + alert( cpi18n.missing_ajax );
300 + jQuery('#user-name').focus();
301 + return;
302 + }
303 + } else if ( ct == 3 ) {
304 + // Raw format must be on one single line
305 + if ( cpjs_ismultiline( payload.trim() ) == true ) {
306 + alert( cpi18n.multiline_raw );
307 + jQuery('#post-value').focus();
308 + return;
309 + }
310 + }
227 311
312 + var cookies = jQuery('#cp-cookies').val();
313 + var headers = jQuery('#custom-headers').val();
314 + var exclusions = jQuery('#exclusions').val();
315 +
228 316 // Change buttons status and add animated image with status message
229 317 jQuery('#start-profile').prop('disabled', true);
230 318 jQuery('#cp-progress-div').slideDown();
231 319 jQuery('#progress-gif').slideDown();
@@ -235,17 +323,21 @@
235 323
236 324 var data = {
237 325 'action': 'codeprofiler_start_profiler',
238 326 'cp_nonce': cp_nonce,
239 - 'where': where,
327 + 'x_end': x_end,
240 328 'post': post,
329 + 'content_type': ct,
241 330 'profile': profile,
242 - 'user': user,
331 + 'x_auth': x_auth,
243 332 'username': username,
244 333 'cookies': cookies,
334 + 'custom_headers': headers,
335 + 'exclusions': exclusions,
245 336 'method': method,
246 337 'payload': payload,
247 - 'ua': ua
338 + 'user_agent': user_agent,
339 + 'theme': theme
248 340 };
249 341 // Send the request via AJAX
250 342 jQuery.ajax( {
251 343 type: 'POST',
@@ -316,9 +408,9 @@
316 408 } else if ( xhr.status == 403 ) {
317 409 cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
318 410 // Internal error
319 411 } else if ( xhr.status == 500 ) {
320 - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>');
412 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
321 413 } else {
322 414 cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
323 415 }
324 416 return;
@@ -349,9 +441,9 @@
349 441 } else if ( xhr.status == 403 ) {
350 442 cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
351 443 // Internal error
352 444 } else if ( xhr.status == 500 ) {
353 - cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.</p>');
445 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
354 446 } else {
355 447 cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
356 448 }
357 449 return;
@@ -389,8 +481,106 @@
389 481 }
390 482 return false;
391 483 }
392 484
485 +// Hide/show the edit box and buttons when renaming a profile.
486 +function cpjs_toggle_name( row ) {
487 + if ( jQuery('#profile_div_'+ row).css('display') == 'none') {
488 + jQuery('#profile_name_'+ row).hide();
489 + jQuery('#profile_div_'+ row).show();
490 + jQuery('#edit-'+ row).val( jQuery('#profile_name_'+ row).html() );
491 + jQuery('#edit-'+ row).focus();
492 + } else {
493 + jQuery('#profile_div_'+ row).hide();
494 + jQuery('#profile_name_'+ row).show();
495 + }
496 +}
497 +
498 +// Edit the profile name via AJAX endpoint.
499 +function cpjs_edit_name( profile, id, cp_nonce, row ) {
500 +
501 + 'use strict';
502 +
503 + if ( cp_nonce == '') {
504 + alert( cpi18n.missing_nonce );
505 + return;
506 + }
507 + if ( profile == '') {
508 + alert( cpi18n.missing_profileid );
509 + return;
510 + }
511 +
512 + var new_name = jQuery('#edit-'+ id).val().trim();
513 + if ( new_name == '') {
514 + alert( cpi18n.missing_profilename );
515 + return;
516 + }
517 +
518 + jQuery('#profile_spinner_'+ row).addClass('is-active');
519 +
520 + var data = {
521 + 'action': 'codeprofiler_rename',
522 + 'cp_nonce': cp_nonce,
523 + 'new_name': new_name,
524 + 'profile': profile,
525 + };
526 +
527 + // Send the request via AJAX
528 + jQuery.ajax( {
529 + type: 'POST',
530 + url: ajaxurl,
531 + data: data,
532 + dataType: 'json',
533 + success: function( response ) {
534 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
535 +
536 + if (typeof response === 'undefined') {
537 + alert( cpi18n.unknown_error );
538 + return;
539 + }
540 +
541 + if ( response.status != 'success') {
542 + alert( response.message );
543 + return;
544 + }
545 +
546 + // Success: update the name in the table
547 + jQuery('#profile_name_'+ id).html( response.newname );
548 + cpjs_toggle_name(row);
549 + },
550 + // Display non-200 HTTP response
551 + error: function( xhr, status, err ) {
552 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
553 + if ( err != '') {
554 + if ( xhr.status != 0 ) {
555 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
556 + // Timeout
557 + if ( xhr.status == 503 || xhr.status == 504 ) {
558 + alert( message +'<br />'+ cpi18n.timeout_error );
559 + // Redirections, not found
560 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
561 + alert( message +'<br />'+ cpi18n.notfound_error );
562 + // Forbidden
563 + } else if ( xhr.status == 403 ) {
564 + alert( message +'<br />'+ cpi18n.forbidden_error );
565 + // Internal error
566 + } else if ( xhr.status == 500 ) {
567 + alert( message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error );
568 + } else {
569 + alert( cpi18n.http_error +' '+ xhr.status +' '+ err );
570 + }
571 + return;
572 +
573 + } else {
574 + alert( cpi18n.unknown_error +' '+ err );
575 + return;
576 + }
577 + }
578 + return;
579 + }
580 + });
581 +}
582 +
393 583 // =====================================================================
394 584 // Plugins/Theme chart.
395 585
396 586 function cpjs_plugins_chart( caxis, clabel, cdata, ctotal_time ) {
@@ -408,11 +598,8 @@
408 598 type: 'bar',
409 599 options: {
410 600 animation: {
411 601 duration: 1000,
412 - onComplete: function() {
413 - document.getElementById('download-png-img').href = myChart.toBase64Image();
414 - }
415 602 },
416 603 indexAxis: _indexAxis,
417 604 plugins: chartPlugins
418 605 },
@@ -493,9 +680,8 @@
493 680 animation: {
494 681 duration: 700,
495 682 onComplete: function() {
496 683 jQuery('#cp-footer-buttons').slideDown(200);
497 - document.getElementById('download-png-img').href = myChart.toBase64Image();
498 684 }
499 685 },
500 686 indexAxis: _indexAxis,
501 687 plugins: chartPlugins
@@ -501,8 +687,15 @@
501 687 plugins: chartPlugins
502 688 },
503 689 plugins:[plugin]
504 690 });
691 +
692 + document.getElementById('download-png-img').onclick = function() {
693 + var a = document.createElement('a');
694 + a.href = myChart.toBase64Image();
695 + a.download = jQuery('#download-png-img').attr('download');
696 + a.click();
697 + }
505 698 }
506 699
507 700 // =====================================================================
508 701 // File I/O chart.
@@ -522,11 +715,8 @@
522 715 type: 'line',
523 716 options: {
524 717 animation: {
525 718 duration: 1000,
526 - onComplete: function() {
527 - document.getElementById('download-png-img').href = myChart.toBase64Image();
528 - }
529 719 },
530 720 indexAxis: _indexAxis,
531 721 plugins: chartPlugins
532 722 },
@@ -594,9 +784,8 @@
594 784 animation: {
595 785 duration: 700,
596 786 onComplete: function() {
597 787 jQuery('#cp-footer-buttons').slideDown(200);
598 - document.getElementById('download-png-img').href = myChart.toBase64Image();
599 788 }
600 789 },
601 790 indexAxis: _indexAxis,
602 791 plugins: chartPlugins
@@ -603,8 +792,15 @@
603 792 },
604 793 plugins:[plugin]
605 794 });
606 795
796 + document.getElementById('download-png-img').onclick = function() {
797 + var a = document.createElement('a');
798 + a.href = myChart.toBase64Image();
799 + a.download = jQuery('#download-png-img').attr('download');
800 + a.click();
801 + }
802 +
607 803 }
608 804 // =====================================================================
609 805 // Disk I/O chart.
610 806
@@ -623,11 +819,8 @@
623 819 type: 'line',
624 820 options: {
625 821 animation: {
626 822 duration: 1000,
627 - onComplete: function() {
628 - document.getElementById('download-png-img').href = myChart.toBase64Image();
629 - }
630 823 },
631 824 indexAxis: _indexAxis,
632 825 plugins: chartPlugins
633 826 },
@@ -694,9 +887,8 @@
694 887 animation: {
695 888 duration: 700,
696 889 onComplete: function() {
697 890 jQuery('#cp-footer-buttons').slideDown(200);
698 - document.getElementById('download-png-img').href = myChart.toBase64Image();
699 891 }
700 892 },
701 893 indexAxis: _indexAxis,
702 894 plugins: chartPlugins
@@ -702,8 +894,15 @@
702 894 plugins: chartPlugins
703 895 },
704 896 plugins:[plugin]
705 897 });
898 +
899 + document.getElementById('download-png-img').onclick = function() {
900 + var a = document.createElement('a');
901 + a.href = myChart.toBase64Image();
902 + a.download = jQuery('#download-png-img').attr('download');
903 + a.click();
904 + }
706 905 }
707 906
708 907 // =====================================================================
709 908 // Settings page