PluginProbe
Code Profiler – WordPress Performance Profiling and Debugging Made Easy / 1.7.4
Code Profiler – WordPress Performance Profiling and Debugging Made Easy v1.7.4
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 1.6.8 All 40 releases
← All changes | static/code-profiler.js +279 -49 1.41.7.4 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 // =====================================================================
@@ -15,9 +15,9 @@
15 15
16 16 // TipTip tooltip
17 17 jQuery( document ).ready(function( $ ) {
18 18 'use strict';
19 - $( '.code-profiler-tip' ).tipTip( {
19 + $('.code-profiler-tip').tipTip( {
20 20 'attribute': 'data-tip',
21 21 'fadeIn': 50,
22 22 'fadeOut': 50,
23 23 'delay': 100,
@@ -28,9 +28,9 @@
28 28 // if the user reloaded the page that would throw an error:
29 29 var url = window.location.href;
30 30 window.history.replaceState({},
31 31 document.title,
32 - url.replace( /&action=delete_profiles&.+/, '' )
32 + url.replace( /&action=delete_profiles&.+/, '')
33 33 );
34 34
35 35 });
36 36
@@ -44,21 +44,21 @@
44 44 // Case sensitivity
45 45 if ( jQuery('#case-search-input').is(':checked') === true ) {
46 46 query += '&c=1';
47 47 }
48 - jQuery("#profile-form").attr('action', jQuery("#profile-form").attr('action')+ query );
48 + jQuery('#profile-form').attr('action', jQuery('#profile-form').attr('action')+ query );
49 49
50 50 } else {
51 - jQuery("#profile-form").attr('action','' );
51 + jQuery('#profile-form').attr('action','');
52 52 var url = window.location.href;
53 53 window.history.replaceState({},
54 54 document.title,
55 - url.replace( /&s=[^&$]+/, '' )
55 + url.replace( /&s=[^&$]+/, '')
56 56 );
57 57 var url = window.location.href;
58 58 window.history.replaceState({},
59 59 document.title,
60 - url.replace( /&c=1/, '' )
60 + url.replace( /&c=1/, '')
61 61 );
62 62 }
63 63 }
64 64
@@ -69,29 +69,79 @@
69 69 'use strict';
70 70 // Enable/disable frontend/backend select box
71 71 // depending on user's choice
72 72 if ( item == 1 ) {
73 - jQuery('#id-frontend').prop('disabled', false);
73 + jQuery('#p-frontend').show();
74 + jQuery('#p-backend').hide();
75 + jQuery('#p-custom').hide();
74 76 jQuery('#id-frontend').focus();
75 - jQuery('#id-backend').prop('disabled', true);
76 - jQuery('#id-custom').prop('disabled', true);
77 77 jQuery('#user-unauthenticated').prop('disabled', false);
78 78 } else if ( item == 2 ) {
79 - jQuery('#id-backend').prop('disabled', false);
79 + jQuery('#p-backend').show();
80 + jQuery('#p-frontend').hide();
81 + jQuery('#p-custom').hide();
80 82 jQuery('#id-backend').focus();
81 - jQuery('#id-frontend').prop('disabled', true);
82 - jQuery('#id-custom').prop('disabled', true);
83 83 jQuery('#user-unauthenticated').prop('disabled', true);
84 - jQuery('#user-authenticated').prop('checked', true)
84 + jQuery('#user-authenticated').prop('checked', true);
85 + jQuery('#user-name').prop('disabled', false);
85 86 } else {
86 - jQuery('#id-custom').prop('disabled', false);
87 + jQuery('#p-custom').show();
88 + jQuery('#p-frontend').hide();
89 + jQuery('#p-backend').hide();
87 90 jQuery('#id-custom').focus();
88 - jQuery('#id-backend').prop('disabled', true);
89 - jQuery('#id-frontend').prop('disabled', true);
90 91 jQuery('#user-unauthenticated').prop('disabled', false);
91 92 }
92 93 }
93 94
95 +function cpjs_authenticated( id ) {
96 + if ( id == 1 ) {
97 + jQuery('#user-name').prop('disabled', false);
98 + jQuery('#user-name').focus();
99 + } else {
100 + jQuery('#user-name').prop('disabled', true);
101 + }
102 +}
103 +
104 +function cpjs_show_adv_settings() {
105 + jQuery('#cp-advanced-settings').slideDown();
106 + jQuery('#button-adv-settings').prop('disabled', true);
107 +}
108 +
109 +function cpjs_get_post( id ) {
110 + if ( id == 1 ) {
111 + jQuery('#post-value').prop('disabled', false);
112 + jQuery('#id-content-type').prop('disabled', false);
113 + jQuery('#post-value').focus();
114 + } else {
115 + jQuery('#post-value').prop('disabled', true);
116 + jQuery('#id-content-type').prop('disabled', true);
117 + }
118 +}
119 +
120 +function cpjs_content_type( value ) {
121 + if ( value == 1 ) {
122 + jQuery('#ct-1').slideDown();
123 + jQuery('#ct-2').slideUp();
124 + } else {
125 + jQuery('#ct-2').slideDown();
126 + jQuery('#ct-1').slideUp();
127 + }
128 +}
129 +
130 +function cpjs_isJSON( data ) {
131 +
132 + if ( jQuery('#id-content-type').val() == 1 || jQuery('#get-method').prop('checked') == true ) {
133 + // Ignore
134 + return 1;
135 + }
136 + try {
137 + return JSON.parse( data );
138 + } catch (e) {
139 + // Not a JSON-encoded string
140 + return null;
141 + }
142 +}
143 +
94 144 // =====================================================================
95 145 // Log page: filter and delete the log.
96 146
97 147 function cpjs_filter_log() {
@@ -100,8 +150,9 @@
100 150 var bitmask = 0;
101 151 if ( document.cplogform.info.checked == true ) { bitmask += 1; }
102 152 if ( document.cplogform.warn.checked == true ) { bitmask += 2; }
103 153 if ( document.cplogform.error.checked == true ) { bitmask += 4; }
154 + if ( document.cplogform.debug.checked == true ) { bitmask += 8; }
104 155
105 156 // Clear the textarea
106 157 document.cplogform.cptxtlog.value = '';
107 158
@@ -109,9 +160,9 @@
109 160 var cp_count = 0;
110 161 var i = 0;
111 162 for ( i = 0; i < cplog_array.length; ++i ) {
112 163 var line = decodeURIComponent( cplog_array[i] );
113 - var line_array = line.split( '~~', 2 );
164 + var line_array = line.split('~~', 2 );
114 165 if ( line_array[0] & bitmask ) {
115 166 document.cplogform.cptxtlog.value += line_array[1];
116 167 ++cp_count;
117 168 }
@@ -134,9 +185,9 @@
134 185 function cpjs_start_profiler() {
135 186 'use strict';
136 187 // Get the nonce
137 188 var cp_nonce = jQuery('#cp_nonce').val();
138 - if ( cp_nonce == '' ) {
189 + if ( cp_nonce == '') {
139 190 alert( cpi18n.missing_nonce );
140 191 return;
141 192 }
142 193
@@ -142,15 +193,15 @@
142 193
143 194 // Get the scan type (frontend/backend)
144 195 var post;
145 196 var where = jQuery('input[name="where"]:checked').val();
146 - if ( where == 'frontend' ) {
197 + if ( where == 'frontend') {
147 198 post = jQuery('#id-frontend').val();
148 199
149 - } else if ( where == 'backend' ) {
200 + } else if ( where == 'backend') {
150 201 post = jQuery('#id-backend').val();
151 202
152 - } else if ( where == 'custom' ) {
203 + } else if ( where == 'custom') {
153 204 post = jQuery('#id-custom').val().trim(); // Trim user input
154 205
155 206 } else {
156 207 alert( cpi18n.missing_frontbackend );
@@ -155,9 +206,9 @@
155 206 } else {
156 207 alert( cpi18n.missing_frontbackend );
157 208 return;
158 209 }
159 - if ( post == '' ) {
210 + if ( post == '') {
160 211 alert( cpi18n.missing_post );
161 212 return;
162 213 }
163 214
@@ -162,9 +213,9 @@
162 213 }
163 214
164 215 // Get the profile's name
165 216 var profile = jQuery('input[name="profile"]').val();
166 - if ( profile == '' ) {
217 + if ( profile == '') {
167 218 alert( cpi18n.missing_profilename );
168 219 jQuery('input[name="profile"]').focus();
169 220 return;
170 221 }
@@ -169,18 +220,54 @@
169 220 return;
170 221 }
171 222
172 223 var user = jQuery('input[name="user"]:checked').val();
173 - if ( user == '' ) {
224 + if ( user == '') {
174 225 alert( cpi18n.missing_userauth );
175 226 return;
176 227 }
177 228
229 + var username = jQuery('#user-name').val().trim(); // Trim user input
230 + if ( user == 'authenticated') {
231 + if ( username == '') {
232 + alert( cpi18n.missing_username );
233 + jQuery('#user-name').focus();
234 + return;
235 + }
236 + }
237 +
178 238 var ua = jQuery('#ua-id').val();
179 - if ( ua == 'undefined' ) {
239 + if ( ua == 'undefined') {
180 240 ua = 'FireFox';
181 241 }
182 242
243 + var theme = jQuery('#id-theme').val();
244 +
245 + // GET or POST
246 + var method = jQuery('input[name="method"]:checked').val();
247 + var payload = '';
248 + if ( method == 'post') {
249 + // Payload
250 + payload = jQuery('#post-value').val();
251 + } else {
252 + method = 'get';
253 + }
254 +
255 + //Content type
256 + var ct = jQuery('#id-content-type').val();
257 + // application/json
258 + if ( ct == 2 ) {
259 + if ( cpjs_isJSON( payload ) == null ) {
260 + alert( cpi18n.missing_ajax );
261 + jQuery('#user-name').focus();
262 + return;
263 + }
264 + }
265 +
266 + var cookies = jQuery('#cp-cookies').val();
267 + var headers = jQuery('#custom-headers').val();
268 + var exclusions = jQuery('#exclusions').val();
269 +
183 270 // Change buttons status and add animated image with status message
184 271 jQuery('#start-profile').prop('disabled', true);
185 272 jQuery('#cp-progress-div').slideDown();
186 273 jQuery('#progress-gif').slideDown();
@@ -192,15 +279,23 @@
192 279 'action': 'codeprofiler_start_profiler',
193 280 'cp_nonce': cp_nonce,
194 281 'where': where,
195 282 'post': post,
283 + 'content_type': ct,
196 284 'profile': profile,
197 285 'user': user,
198 - 'ua': ua
286 + 'username': username,
287 + 'cookies': cookies,
288 + 'custom_headers': headers,
289 + 'exclusions': exclusions,
290 + 'method': method,
291 + 'payload': payload,
292 + 'ua': ua,
293 + 'theme': theme
199 294 };
200 295 // Send the request via AJAX
201 296 jQuery.ajax( {
202 - type: "POST",
297 + type: 'POST',
203 298 url: ajaxurl,
204 299 data: data,
205 300 dataType: 'json',
206 301 success: function( response ) {
@@ -205,14 +300,14 @@
205 300 dataType: 'json',
206 301 success: function( response ) {
207 302
208 303 if (typeof response === 'undefined') {
209 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
304 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
210 305 return;
211 306 }
212 307
213 - if ( response.status != 'success' ) {
214 - cpjs_start_error( '<p>'+ response.message +'</p>' );
308 + if ( response.status != 'success') {
309 + cpjs_start_error('<p>'+ response.message +'</p>');
215 310 return;
216 311 }
217 312
218 313 // ------------------------------------------------------------
@@ -222,9 +317,9 @@
222 317
223 318 data['action'] = 'codeprofiler_prepare_report';
224 319 data['microtime'] = response.microtime;
225 320 jQuery.ajax( {
226 - type: "POST",
321 + type: 'POST',
227 322 url: ajaxurl,
228 323 data: data,
229 324 dataType: 'json',
230 325 success: function( response ) {
@@ -229,18 +324,18 @@
229 324 dataType: 'json',
230 325 success: function( response ) {
231 326
232 327 if (typeof response === 'undefined') {
233 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +'</p>' );
328 + cpjs_start_error('<p>'+ cpi18n.unknown_error +'</p>');
234 329 return;
235 330 }
236 331
237 - if ( response.status != 'success' ) {
238 - cpjs_start_error( '<p>'+ response.message +'</p>' );
332 + if ( response.status != 'success') {
333 + cpjs_start_error('<p>'+ response.message +'</p>');
239 334 return;
240 335 }
241 336 var cp_uri;
242 - if (response.cp_profile !== 'undefined' && response.cp_profile != '' ) {
337 + if (response.cp_profile !== 'undefined' && response.cp_profile != '') {
243 338 cp_uri = '&cptab=profiles_list&action=view_profile&id=' + response.cp_profile + '&section=1';
244 339 } else {
245 340 cp_uri = '&cptab=profiles_list';
246 341 }
@@ -253,16 +348,30 @@
253 348 },
254 349
255 350 // Display non-200 HTTP response
256 351 error: function( xhr, status, err ) {
257 - if ( err != '' ) {
258 -
352 + if ( err != '') {
259 353 if ( xhr.status != 0 ) {
260 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
354 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
355 + // Timeout
356 + if ( xhr.status == 503 || xhr.status == 504 ) {
357 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.timeout_error +'.</p>');
358 + // Redirections, not found
359 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
360 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.notfound_error +'.</p>');
361 + // Forbidden
362 + } else if ( xhr.status == 403 ) {
363 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
364 + // Internal error
365 + } else if ( xhr.status == 500 ) {
366 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
367 + } else {
368 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
369 + }
261 370 return;
262 371
263 372 } else {
264 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
373 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
265 374 return;
266 375 }
267 376 }
268 377 return;
@@ -272,16 +381,30 @@
272 381 },
273 382
274 383 // Display non-200 HTTP response
275 384 error: function( xhr, status, err ) {
276 - if ( err != '' ) {
277 -
385 + if ( err != '') {
278 386 if ( xhr.status != 0 ) {
279 - cpjs_start_error( '<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>' );
387 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
388 + // Timeout
389 + if ( xhr.status == 503 || xhr.status == 504 ) {
390 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.timeout_error +'.</p>');
391 + // Redirections, not found
392 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
393 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.notfound_error +'.</p>');
394 + // Forbidden
395 + } else if ( xhr.status == 403 ) {
396 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.forbidden_error +'.</p>');
397 + // Internal error
398 + } else if ( xhr.status == 500 ) {
399 + cpjs_start_error('<p>'+ message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error +'.</p>');
400 + } else {
401 + cpjs_start_error('<p>'+ cpi18n.http_error +' '+ xhr.status +' '+ err +'.</p>');
402 + }
280 403 return;
281 404
282 405 } else {
283 - cpjs_start_error( '<p>'+ cpi18n.unknown_error +' '+ err +'.</p>' );
406 + cpjs_start_error('<p>'+ cpi18n.unknown_error +' '+ err +'.</p>');
284 407 return;
285 408 }
286 409 }
287 410 return;
@@ -312,8 +435,106 @@
312 435 }
313 436 return false;
314 437 }
315 438
439 +// Hide/show the edit box and buttons when renaming a profile.
440 +function cpjs_toggle_name( row ) {
441 + if ( jQuery('#profile_div_'+ row).css('display') == 'none') {
442 + jQuery('#profile_name_'+ row).hide();
443 + jQuery('#profile_div_'+ row).show();
444 + jQuery('#edit-'+ row).val( jQuery('#profile_name_'+ row).html() );
445 + jQuery('#edit-'+ row).focus();
446 + } else {
447 + jQuery('#profile_div_'+ row).hide();
448 + jQuery('#profile_name_'+ row).show();
449 + }
450 +}
451 +
452 +// Edit the profile name via AJAX endpoint.
453 +function cpjs_edit_name( profile, id, cp_nonce, row ) {
454 +
455 + 'use strict';
456 +
457 + if ( cp_nonce == '') {
458 + alert( cpi18n.missing_nonce );
459 + return;
460 + }
461 + if ( profile == '') {
462 + alert( cpi18n.missing_profileid );
463 + return;
464 + }
465 +
466 + var new_name = jQuery('#edit-'+ id).val().trim();
467 + if ( new_name == '') {
468 + alert( cpi18n.missing_profilename );
469 + return;
470 + }
471 +
472 + jQuery('#profile_spinner_'+ row).addClass('is-active');
473 +
474 + var data = {
475 + 'action': 'codeprofiler_rename',
476 + 'cp_nonce': cp_nonce,
477 + 'new_name': new_name,
478 + 'profile': profile,
479 + };
480 +
481 + // Send the request via AJAX
482 + jQuery.ajax( {
483 + type: 'POST',
484 + url: ajaxurl,
485 + data: data,
486 + dataType: 'json',
487 + success: function( response ) {
488 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
489 +
490 + if (typeof response === 'undefined') {
491 + alert( cpi18n.unknown_error );
492 + return;
493 + }
494 +
495 + if ( response.status != 'success') {
496 + alert( response.message );
497 + return;
498 + }
499 +
500 + // Success: update the name in the table
501 + jQuery('#profile_name_'+ id).html( response.newname );
502 + cpjs_toggle_name(row);
503 + },
504 + // Display non-200 HTTP response
505 + error: function( xhr, status, err ) {
506 + jQuery('#profile_spinner_'+ row ).removeClass('is-active');
507 + if ( err != '') {
508 + if ( xhr.status != 0 ) {
509 + var message = cpi18n.http_error +' '+ xhr.status +' '+ err;
510 + // Timeout
511 + if ( xhr.status == 503 || xhr.status == 504 ) {
512 + alert( message +'<br />'+ cpi18n.timeout_error );
513 + // Redirections, not found
514 + } else if ( xhr.status == 301 || xhr.status == 302 || xhr.status == 404 ) {
515 + alert( message +'<br />'+ cpi18n.notfound_error );
516 + // Forbidden
517 + } else if ( xhr.status == 403 ) {
518 + alert( message +'<br />'+ cpi18n.forbidden_error );
519 + // Internal error
520 + } else if ( xhr.status == 500 ) {
521 + alert( message +'<br />'+ cpi18n.internal_error +'.<br />'+ cpi18n.timeout_error );
522 + } else {
523 + alert( cpi18n.http_error +' '+ xhr.status +' '+ err );
524 + }
525 + return;
526 +
527 + } else {
528 + alert( cpi18n.unknown_error +' '+ err );
529 + return;
530 + }
531 + }
532 + return;
533 + }
534 + });
535 +}
536 +
316 537 // =====================================================================
317 538 // Plugins/Theme chart.
318 539
319 540 function cpjs_plugins_chart( caxis, clabel, cdata, ctotal_time ) {
@@ -320,9 +541,9 @@
320 541 'use strict';
321 542 // Switch between vertical and horizontal bars
322 543 var _indexAxis = caxis;
323 544 document.getElementById('htov').onclick = function() {
324 - if ( _indexAxis == 'x' ) {
545 + if ( _indexAxis == 'x') {
325 546 _indexAxis = 'y';
326 547 } else {
327 548 _indexAxis = 'x';
328 549 }
@@ -361,15 +582,15 @@
361 582 const total_time = ctotal_time;
362 583 const footer = (tooltipItems) => {
363 584 var sum;
364 585 tooltipItems.forEach(function(tooltipItem) {
365 - if ( _indexAxis == 'x' ) {
586 + if ( _indexAxis == 'x') {
366 587 sum = Math.round( ( tooltipItem.parsed.y / total_time ) * 100 );
367 588 } else {
368 589 sum = Math.round( ( tooltipItem.parsed.x / total_time ) * 100 );
369 590 }
370 591 });
371 - return '('+ sum + cpi18n.pc_plugins +')';
592 + return sum + cpi18n.pc_plugins;
372 593 };
373 594
374 595 var chartPlugins = {
375 596 title: {
@@ -434,9 +655,9 @@
434 655 'use strict';
435 656 // Switch between vertical and horizontal bars
436 657 var _indexAxis = caxis;
437 658 document.getElementById('htov').onclick = function() {
438 - if ( _indexAxis == 'x' ) {
659 + if ( _indexAxis == 'x') {
439 660 _indexAxis = 'y';
440 661 } else {
441 662 _indexAxis = 'x';
442 663 }
@@ -535,9 +756,9 @@
535 756 'use strict';
536 757 // Switch between vertical and horizontal bars
537 758 var _indexAxis = caxis;
538 759 document.getElementById('htov').onclick = function() {
539 - if ( _indexAxis == 'x' ) {
760 + if ( _indexAxis == 'x') {
540 761 _indexAxis = 'y';
541 762 } else {
542 763 _indexAxis = 'x';
543 764 }
@@ -625,8 +846,17 @@
625 846 plugins: chartPlugins
626 847 },
627 848 plugins:[plugin]
628 849 });
850 +}
851 +
852 +// =====================================================================
853 +// Settings page
854 +
855 +function cpjs_copy_textarea( id ) {
856 + document.getElementById(id).select();
857 + document.execCommand('copy');
858 + alert( cpi18n.text_copied );
629 859 }
630 860
631 861 // =====================================================================
632 862 // EOF