PluginProbe
Autoptimize / 3.1.16
Autoptimize v3.1.16
3.1.16 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 All 108 releases
← All changes | classes/critcss-inc/admin_settings_queue.js.php +51 -20 2.7.5 → 3.1.16 View file →
@@ -38,8 +38,14 @@
38 38 sortList: [[0,0]],
39 39 headers: {6: {sorter: false}}
40 40 });
41 41 }
42 +
43 + // unhide queuerunner button conditionally (we don't want people running the queue continuously) and attach event to it.
44 + if (queueBodyEl > 4 || ( queueBodyEl > 0 && jQuery('#rules > tr').length < 1 ) ) {
45 + jQuery('#queuerunner-container').show();
46 + jQuery("#queuerunner").click(function(){queuerunner();});
47 + }
42 48 });
43 49 }
44 50
45 51 // Render the queue in a table
@@ -56,41 +62,46 @@
56 62 rbtn = false;
57 63 dbtn = false;
58 64 hbtn = false;
59 65
66 + // don't list jobs that don't have a type, they are irrelevant and this also avoids "type.replace is not a function".
67 + if ( type == false ) {
68 + return;
69 + }
70 +
60 71 // Prepare job statuses
61 72 if (keys.jqstat === 'NEW') {
62 73 // Status: NEW (N, sort order 1)
63 74 status = '<span class="hidden">1</span>N';
64 75 statusClass = 'new';
65 - title = '<?php _e( 'New', 'autoptimize' ); ?> (' + ljid + ')';
66 - buttons = '<?php _e( 'None', 'autoptimize' ); ?>';
76 + title = '<?php esc_html_e( 'New', 'autoptimize' ); ?> (' + ljid + ')';
77 + buttons = '<?php esc_html_e( 'None', 'autoptimize' ); ?>';
67 78 } else if (keys.jqstat === 'JOB_QUEUED' || keys.jqstat === 'JOB_ONGOING') {
68 79 // Status: PENDING (P, sort order 2)
69 80 status = '<span class="hidden">2</span>P';
70 81 statusClass = 'pending';
71 - title = '<?php _e( 'PENDING', 'autoptimize' ); ?> (' + ljid + ')';
72 - buttons = '<?php _e( 'None', 'autoptimize' ); ?>';
82 + title = '<?php esc_html_e( 'PENDING', 'autoptimize' ); ?> (' + ljid + ')';
83 + buttons = '<?php esc_html_e( 'None', 'autoptimize' ); ?>';
73 84 } else if (keys.jqstat === 'JOB_DONE' && keys.jrstat === 'GOOD' && (keys.jvstat === 'WARN' || keys.jvstat === 'BAD')) {
74 85 // Status: REVIEW (R, sort order 5)
75 86 status = '<span class="hidden">5</span>R';
76 87 statusClass = 'review';
77 - title = "<?php _e( 'REVIEW', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
78 - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
88 + title = "<?php esc_html_e( 'REVIEW', 'autoptimize' ); ?> (" + ljid + ")\n<?php esc_html_e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php esc_html_e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php esc_html_e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php esc_html_e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php esc_html_e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
89 + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php esc_html_e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
79 90 dbtn = true;
80 91 } else if (keys.jqstat === 'JOB_DONE') {
81 92 // Status: DONE (D, sort order 6)
82 93 status = '<span class="hidden">6</span>D';
83 94 statusClass = 'done';
84 - title = '<?php _e( 'DONE', 'autoptimize' ); ?> (' + ljid + ')';
85 - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
95 + title = '<?php esc_html_e( 'DONE', 'autoptimize' ); ?> (' + ljid + ')';
96 + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php esc_html_e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span>';
86 97 dbtn = true;
87 98 } else if (keys.jqstat === 'JOB_FAILED' || keys.jqstat === 'STATUS_JOB_BAD' || keys.jqstat === 'INVALID_JWT_TOKEN' || keys.jqstat === 'NO_CSS' || keys.jqstat === 'NO_RESPONSE') {
88 99 // Status: ERROR (E, sort order 4)
89 100 status = '<span class="hidden">4</span>E';
90 101 statusClass = 'error';
91 - title = "<?php _e( 'ERROR', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
92 - buttons = '<span class="button-secondary" id="' + ljid + '_retry" title="<?php _e( 'Retry Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-update"></span></span><span class="button-secondary to-right" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
102 + title = "<?php esc_html_e( 'ERROR', 'autoptimize' ); ?> (" + ljid + ")\n<?php esc_html_e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php esc_html_e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php esc_html_e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php esc_html_e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php esc_html_e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
103 + buttons = '<span class="button-secondary" id="' + ljid + '_retry" title="<?php esc_html_e( 'Retry Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-update"></span></span><span class="button-secondary to-right" id="' + ljid + '_remove" title="<?php esc_html_e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php esc_html_e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
93 104 rbtn = true;
94 105 dbtn = true;
95 106 hbtn = true;
96 107 } else {
@@ -96,10 +107,10 @@
96 107 } else {
97 108 // Status: UNKNOWN (U, sort order 5)
98 109 status = '<span class="hidden">5</span>U';
99 110 statusClass = 'unknown';
100 - title = "<?php _e( 'UNKNOWN', 'autoptimize' ); ?> (" + ljid + ")\n<?php _e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php _e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php _e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php _e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php _e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
101 - buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php _e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php _e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
111 + title = "<?php esc_html_e( 'UNKNOWN', 'autoptimize' ); ?> (" + ljid + ")\n<?php esc_html_e( 'Info from criticalcss.com:', 'autoptimize' ); ?>\n<?php esc_html_e( '- Job ID: ', 'autoptimize' ); ?>" + keys.jid + "\n<?php esc_html_e( '- Status: ', 'autoptimize' ); ?>" + keys.jqstat + "\n<?php esc_html_e( '- Result: ', 'autoptimize' ); ?>" + keys.jrstat + "\n<?php esc_html_e( '- Validation: ', 'autoptimize' ); ?>" + keys.jvstat;
112 + buttons = '<span class="button-secondary" id="' + ljid + '_remove" title="<?php esc_html_e( 'Delete Job', 'autoptimize' ); ?>"><span class="dashicons dashicons-trash"></span></span><span class="button-secondary to-right" id="' + ljid + '_help" title="<?php esc_html_e( 'Get Help', 'autoptimize' ); ?>"><span class="dashicons dashicons-sos"></span></span>';
102 113 dbtn = true;
103 114 hbtn = true;
104 115 }
105 116
@@ -104,15 +115,15 @@
104 115 }
105 116
106 117 // Prepare job finish time
107 118 if (keys.jftime === null) {
108 - ftime = '<?php _e( 'N/A', 'autoptimize' ); ?>';
119 + ftime = '<?php esc_html_e( 'N/A', 'autoptimize' ); ?>';
109 120 } else {
110 121 ftime = EpochToDate(keys.jftime);
111 122 }
112 123
113 124 // Append job entry
114 - jQuery("#queue").append("<tr id='" + ljid + "' class='job " + statusClass + "'><td class='status'><span class='badge " + statusClass + "' title='<?php _e( 'Job status is ', 'autoptimize' ); ?>" + title + "'>" + status + "</span></td><td>" + target.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + path + "</td><td>" + type.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + ctime + "</td><td>" + ftime + "</td><td class='btn'>" + buttons + "</td></tr>");
125 + jQuery("#queue").append("<tr id='" + ljid + "' class='job " + statusClass + "'><td class='status'><span class='badge " + statusClass + "' title='<?php esc_html_e( 'Job status is ', 'autoptimize' ); ?>" + title + "'>" + status + "</span></td><td>" + target.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + encodeURI(path) + "</td><td>" + type.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td>" + ctime + "</td><td>" + ftime + "</td><td class='btn'>" + buttons + "</td></tr>");
115 126
116 127 // Attach button actions
117 128 if (rbtn) {
118 129 jQuery('#' + ljid + '_retry').click(function(){retryJob(queue, this.id, path);});
@@ -133,14 +144,14 @@
133 144 resizable: false,
134 145 height: 180,
135 146 modal: true,
136 147 buttons: {
137 - "<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
148 + "<?php esc_html_e( 'Delete', 'autoptimize' ); ?>": function() {
138 149 delete queue[jpath];
139 150 updateQueue(queue);
140 151 jQuery(this).dialog('close' );
141 152 },
142 - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
153 + "<?php esc_html_e( 'Cancel', 'autoptimize' ); ?>": function() {
143 154 jQuery(this).dialog('close' );
144 155 }
145 156 }
146 157 });
@@ -151,14 +162,14 @@
151 162 resizable: false,
152 163 height:235,
153 164 modal: true,
154 165 buttons: {
155 - "<?php _e( 'Delete all jobs?', 'autoptimize' ); ?>": function() {
166 + "<?php esc_html_e( 'Delete all jobs?', 'autoptimize' ); ?>": function() {
156 167 queue=[];
157 168 updateQueue(queue);
158 169 jQuery( this ).dialog( "close" );
159 170 },
160 - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
171 + "<?php esc_html_e( 'Cancel', 'autoptimize' ); ?>": function() {
161 172 jQuery( this ).dialog( "close" );
162 173 }
163 174 }
164 175 });
@@ -171,9 +182,9 @@
171 182 resizable: false,
172 183 height: 180,
173 184 modal: true,
174 185 buttons: {
175 - "<?php _e( 'Retry', 'autoptimize' ); ?>": function() {
186 + "<?php esc_html_e( 'Retry', 'autoptimize' ); ?>": function() {
176 187 <?php
177 188 if ( $ao_ccss_debug ) {
178 189 echo "console.log( 'SHOULD retry job:', jid[0], jpath );\n";
179 190 }
@@ -186,9 +197,9 @@
186 197 queue[jpath].jftime = null;
187 198 updateQueue(queue);
188 199 jQuery(this).dialog('close' );
189 200 },
190 - "<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
201 + "<?php esc_html_e( 'Cancel', 'autoptimize' ); ?>": function() {
191 202 jQuery(this).dialog('close' );
192 203 }
193 204 }
194 205 });
@@ -204,8 +215,28 @@
204 215 if ( $ao_ccss_debug ) {
205 216 echo "console.log('Updated Queue Object:', queue);\n";
206 217 }
207 218 ?>
219 +}
220 +
221 +// Run the queue manually (in case of cron issues/ impatient users).
222 +function queuerunner() {
223 + var data = {
224 + 'action': 'ao_ccss_queuerunner',
225 + 'ao_ccss_queuerunner_nonce': '<?php echo wp_create_nonce( 'ao_ccss_queuerunner_nonce' ); ?>',
226 + };
227 +
228 + jQuery.post(ajaxurl, data, function(response) {
229 + response_array=JSON.parse(response);
230 + if (response_array['code'] == 200) {
231 + displayNotice( '<?php esc_html_e( 'Queue processed, reloading page.', 'autoptimize' ); ?>', 'success' )
232 + setTimeout(window.location.reload.bind(window.location), 1.5*1000);
233 + } else if ( response_array['code'] == 302 ) {
234 + displayNotice( '<?php esc_html_e( 'The queue is locked, retry in a couple of minutes. If this problem persists and the queue is not moving at all remove the <code>wp-content/uploads/ao_ccss/queue.lock</code> file.', 'autoptimize' ); ?>', 'warning' )
235 + } else {
236 + displayNotice( '<?php esc_html_e( 'Could not process queue.', 'autoptimize' ); ?>', 'error' )
237 + }
238 + });
208 239 }
209 240
210 241 // Convert epoch to date for job times
211 242 function EpochToDate(epoch) {