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 +129 -31 1.6.51.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() {
@@ -156,9 +208,15 @@
156 208 // =====================================================================
157 209 // AJAX call to start the profiler.
158 210
159 211 function cpjs_start_profiler() {
212 +
160 213 'use strict';
214 +
215 + jQuery('html, body').animate( {
216 + scrollTop: jQuery('#button-adv-settings').offset().top
217 + }, 1000 );
218 +
161 219 // Get the nonce
162 220 var cp_nonce = jQuery('#cp_nonce').val();
163 221 if ( cp_nonce == '') {
164 222 alert( cpi18n.missing_nonce );
@@ -166,18 +224,25 @@
166 224 }
167 225
168 226 // Get the scan type (frontend/backend)
169 227 var post;
170 - var where = jQuery('input[name="where"]:checked').val();
171 - if ( where == 'frontend') {
228 + var x_end = jQuery('input[name="x_end"]:checked').val();
229 + if ( x_end == 'frontend') {
172 230 post = jQuery('#id-frontend').val();
173 231
174 - } else if ( where == 'backend') {
232 + } else if ( x_end == 'backend') {
175 233 post = jQuery('#id-backend').val();
176 234
177 - } else if ( where == 'custom') {
235 + } else if ( x_end == 'custom') {
178 236 post = jQuery('#id-custom').val().trim(); // Trim user input
179 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 +
180 245 } else {
181 246 alert( cpi18n.missing_frontbackend );
182 247 return;
183 248 }
@@ -193,16 +258,16 @@
193 258 jQuery('input[name="profile"]').focus();
194 259 return;
195 260 }
196 261
197 - var user = jQuery('input[name="user"]:checked').val();
198 - if ( user == '') {
262 + var x_auth = jQuery('input[name="x_auth"]:checked').val();
263 + if ( x_auth == '') {
199 264 alert( cpi18n.missing_userauth );
200 265 return;
201 266 }
202 267
203 268 var username = jQuery('#user-name').val().trim(); // Trim user input
204 - if ( user == 'authenticated') {
269 + if ( x_auth == 'authenticated') {
205 270 if ( username == '') {
206 271 alert( cpi18n.missing_username );
207 272 jQuery('#user-name').focus();
208 273 return;
@@ -208,13 +273,15 @@
208 273 return;
209 274 }
210 275 }
211 276
212 - var ua = jQuery('#ua-id').val();
213 - if ( ua == 'undefined') {
214 - ua = 'FireFox';
277 + var user_agent = jQuery('#ua-id').val();
278 + if ( user_agent == 'undefined') {
279 + user_agent = 'FireFox';
215 280 }
216 281
282 + var theme = jQuery('#id-theme').val();
283 +
217 284 // GET or POST
218 285 var method = jQuery('input[name="method"]:checked').val();
219 286 var payload = '';
220 287 if ( method == 'post') {
@@ -223,11 +290,30 @@
223 290 } else {
224 291 method = 'get';
225 292 }
226 293
227 - var cookies = jQuery('#cp-cookies').val();
228 - var headers = jQuery('#custom-headers').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 + }
229 311
312 + var cookies = jQuery('#cp-cookies').val();
313 + var headers = jQuery('#custom-headers').val();
314 + var exclusions = jQuery('#exclusions').val();
315 +
230 316 // Change buttons status and add animated image with status message
231 317 jQuery('#start-profile').prop('disabled', true);
232 318 jQuery('#cp-progress-div').slideDown();
233 319 jQuery('#progress-gif').slideDown();
@@ -237,18 +323,21 @@
237 323
238 324 var data = {
239 325 'action': 'codeprofiler_start_profiler',
240 326 'cp_nonce': cp_nonce,
241 - 'where': where,
327 + 'x_end': x_end,
242 328 'post': post,
329 + 'content_type': ct,
243 330 'profile': profile,
244 - 'user': user,
331 + 'x_auth': x_auth,
245 332 'username': username,
246 333 'cookies': cookies,
247 334 'custom_headers': headers,
335 + 'exclusions': exclusions,
248 336 'method': method,
249 337 'payload': payload,
250 - 'ua': ua
338 + 'user_agent': user_agent,
339 + 'theme': theme
251 340 };
252 341 // Send the request via AJAX
253 342 jQuery.ajax( {
254 343 type: 'POST',
@@ -509,11 +598,8 @@
509 598 type: 'bar',
510 599 options: {
511 600 animation: {
512 601 duration: 1000,
513 - onComplete: function() {
514 - document.getElementById('download-png-img').href = myChart.toBase64Image();
515 - }
516 602 },
517 603 indexAxis: _indexAxis,
518 604 plugins: chartPlugins
519 605 },
@@ -594,9 +680,8 @@
594 680 animation: {
595 681 duration: 700,
596 682 onComplete: function() {
597 683 jQuery('#cp-footer-buttons').slideDown(200);
598 - document.getElementById('download-png-img').href = myChart.toBase64Image();
599 684 }
600 685 },
601 686 indexAxis: _indexAxis,
602 687 plugins: chartPlugins
@@ -602,8 +687,15 @@
602 687 plugins: chartPlugins
603 688 },
604 689 plugins:[plugin]
605 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 + }
606 698 }
607 699
608 700 // =====================================================================
609 701 // File I/O chart.
@@ -623,11 +715,8 @@
623 715 type: 'line',
624 716 options: {
625 717 animation: {
626 718 duration: 1000,
627 - onComplete: function() {
628 - document.getElementById('download-png-img').href = myChart.toBase64Image();
629 - }
630 719 },
631 720 indexAxis: _indexAxis,
632 721 plugins: chartPlugins
633 722 },
@@ -695,9 +784,8 @@
695 784 animation: {
696 785 duration: 700,
697 786 onComplete: function() {
698 787 jQuery('#cp-footer-buttons').slideDown(200);
699 - document.getElementById('download-png-img').href = myChart.toBase64Image();
700 788 }
701 789 },
702 790 indexAxis: _indexAxis,
703 791 plugins: chartPlugins
@@ -704,8 +792,15 @@
704 792 },
705 793 plugins:[plugin]
706 794 });
707 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 +
708 803 }
709 804 // =====================================================================
710 805 // Disk I/O chart.
711 806
@@ -724,11 +819,8 @@
724 819 type: 'line',
725 820 options: {
726 821 animation: {
727 822 duration: 1000,
728 - onComplete: function() {
729 - document.getElementById('download-png-img').href = myChart.toBase64Image();
730 - }
731 823 },
732 824 indexAxis: _indexAxis,
733 825 plugins: chartPlugins
734 826 },
@@ -795,9 +887,8 @@
795 887 animation: {
796 888 duration: 700,
797 889 onComplete: function() {
798 890 jQuery('#cp-footer-buttons').slideDown(200);
799 - document.getElementById('download-png-img').href = myChart.toBase64Image();
800 891 }
801 892 },
802 893 indexAxis: _indexAxis,
803 894 plugins: chartPlugins
@@ -803,8 +894,15 @@
803 894 plugins: chartPlugins
804 895 },
805 896 plugins:[plugin]
806 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 + }
807 905 }
808 906
809 907 // =====================================================================
810 908 // Settings page