PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.6
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.6
2.7.1 2.7.2 2.7.0 2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 All 141 releases
metasync / robots-txt / views / scripts.php

scripts.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.6, at robots-txt/views/scripts.php

499 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Robots.txt Admin Page Scripts
4 *
5 * @package Search Atlas SEO
6 * @copyright Copyright (C) 2021-2025, Search Atlas Group - [email protected]
7 * @since 2.5.6
8 */
9
10 // If this file is called directly, abort.
11 if (!defined('WPINC')) {
12 die;
13 }
14 ?>
15 <script>
16 jQuery(document).ready(function($) {
17 let allowSave = false;
18
19 // Check for restore success message after page reload
20 const restoreMessage = sessionStorage.getItem('metasync_robots_restore_message');
21 if (restoreMessage) {
22 // Remove the message from sessionStorage
23 sessionStorage.removeItem('metasync_robots_restore_message');
24
25 // Display the success message
26 const $notice = $('<div class="notice notice-success is-dismissible" style="margin: 20px 0;"><p>' + restoreMessage + '</p></div>');
27 $('.metasync-robots-txt-page').prepend($notice);
28
29 // Scroll to top to show the message
30 $('html, body').animate({ scrollTop: 0 }, 300);
31
32 // Auto-dismiss after 5 seconds
33 setTimeout(function() {
34 $notice.fadeOut(300, function() {
35 $(this).remove();
36 });
37 }, 5000);
38 }
39
40 // Modal functions
41 function showModal(type, title, message, showConfirm) {
42 const $modal = $('#robots-validation-modal');
43 const $header = $modal.find('.metasync-modal-header');
44 const $confirmBtn = $('#modal-confirm-btn');
45
46 // Set header style
47 $header.removeClass('error warning success').addClass(type);
48
49 // Set icon
50 let icon = '';
51 if (type === 'error') {
52 icon = '<div class="metasync-modal-icon error"><span class="dashicons dashicons-dismiss"></span></div>';
53 } else if (type === 'warning') {
54 icon = '<div class="metasync-modal-icon warning"><span class="dashicons dashicons-warning"></span></div>';
55 } else {
56 icon = '<div class="metasync-modal-icon success"><span class="dashicons dashicons-yes-alt"></span></div>';
57 }
58
59 // Set content
60 $('#modal-title').html(title);
61 $('#modal-body').html(icon + '<div class="metasync-modal-message">' + message + '</div>');
62
63 // Show/hide confirm button
64 if (showConfirm) {
65 $confirmBtn.show();
66 } else {
67 $confirmBtn.hide();
68 }
69
70 // Show modal
71 $modal.fadeIn(200);
72 }
73
74 function closeModal() {
75 const $modal = $('#robots-validation-modal');
76 const $modalContent = $modal.find('.metasync-modal-content');
77 const $confirmBtn = $('#modal-confirm-btn');
78 const $cancelBtn = $('.metasync-modal-cancel');
79
80 // Remove preview class when closing
81 $modalContent.removeClass('preview');
82
83 // Reset confirm button to original state
84 $confirmBtn.removeClass('button-restore')
85 .addClass('button-primary')
86 .text('<?php esc_html_e('Save Anyway', 'metasync'); ?>')
87 .removeData('backup-id')
88 .removeData('nonce');
89
90 // Reset cancel button
91 $cancelBtn.text('<?php esc_html_e('Cancel', 'metasync'); ?>');
92
93 $modal.fadeOut(200);
94 }
95
96 // Close modal on overlay or close button click
97 $('.metasync-modal-overlay, .metasync-modal-close, .metasync-modal-cancel').on('click', function() {
98 closeModal();
99 });
100
101 // Prevent closing when clicking modal content
102 $('.metasync-modal-content').on('click', function(e) {
103 e.stopPropagation();
104 });
105
106 // Form submission with validation
107 $('#robots-txt-form').on('submit', function(e) {
108 if (allowSave) {
109 allowSave = false;
110 return true; // Allow form submission
111 }
112
113 e.preventDefault();
114
115 const content = $('#robots-txt-editor').val();
116
117 // Validate via AJAX
118 $.ajax({
119 url: ajaxurl,
120 type: 'POST',
121 data: {
122 action: 'metasync_validate_robots',
123 content: content
124 },
125 success: function(response) {
126 if (response.success && response.data) {
127 // Check for errors
128 if (response.data.errors && response.data.errors.length > 0) {
129 let errorHtml = '<div><strong><?php esc_html_e('The following errors must be fixed before saving:', 'metasync'); ?></strong><ul style="margin: 16px 0 0 20px; text-align: left;">';
130 response.data.errors.forEach(function(error) {
131 errorHtml += '<li>' + error + '</li>';
132 });
133 errorHtml += '</ul></div>';
134
135 showModal('error', '<?php esc_html_e('Syntax Errors Found', 'metasync'); ?>', errorHtml, false);
136 return;
137 }
138
139 // Check for warnings
140 if (response.data.warnings && response.data.warnings.length > 0) {
141 let warningHtml = '<div><strong><?php esc_html_e('The following warnings were detected:', 'metasync'); ?></strong><ul style="margin: 16px 0 0 20px; text-align: left;">';
142 response.data.warnings.forEach(function(warning) {
143 warningHtml += '<li>' + warning + '</li>';
144 });
145 warningHtml += '</ul><p style="margin-top: 16px;"><strong><?php esc_html_e('Do you want to save anyway?', 'metasync'); ?></strong></p></div>';
146
147 showModal('warning', '<?php esc_html_e('Validation Warnings', 'metasync'); ?>', warningHtml, true);
148 return;
149 }
150
151 // No errors or warnings, submit form
152 allowSave = true;
153 $('#robots-txt-form').submit();
154 }
155 }
156 });
157 });
158
159 // Confirm button handler (for warnings and restore from preview)
160 $('#modal-confirm-btn').on('click', function() {
161 const $btn = $(this);
162
163 // Check if this is a restore action from preview
164 if ($btn.hasClass('button-restore')) {
165 const backupId = $btn.data('backup-id');
166 const nonce = $btn.data('nonce');
167
168 if (!backupId) {
169 alert('<?php esc_html_e('Invalid backup ID', 'metasync'); ?>');
170 return;
171 }
172
173 if (!confirm('<?php esc_html_e('Are you sure you want to restore this backup? Current content will be backed up automatically.', 'metasync'); ?>')) {
174 return;
175 }
176
177 // Show loading state
178 const originalText = $btn.text();
179 $btn.prop('disabled', true).html('<span class="dashicons dashicons-update dashicons-spin"></span> <?php esc_html_e('Restoring...', 'metasync'); ?>');
180
181 // Close the modal
182 closeModal();
183
184 // Perform restore via AJAX
185 $.ajax({
186 url: ajaxurl,
187 type: 'POST',
188 data: {
189 action: 'metasync_restore_robots_backup',
190 backup_id: backupId,
191 nonce: nonce
192 },
193 success: function(response) {
194 if (response.success) {
195 // Store success message in sessionStorage
196 if (response.data && response.data.message) {
197 sessionStorage.setItem('metasync_robots_restore_message', response.data.message);
198 }
199
200 // Reload the page
201 window.location.reload();
202 } else {
203 // Show error message
204 const errorMessage = response.data && response.data.message ? response.data.message : '<?php esc_html_e('Failed to restore backup.', 'metasync'); ?>';
205 alert(errorMessage);
206
207 // Restore button
208 $btn.prop('disabled', false).text(originalText);
209 }
210 },
211 error: function() {
212 alert('<?php esc_html_e('An error occurred while restoring the backup.', 'metasync'); ?>');
213
214 // Restore button
215 $btn.prop('disabled', false).text(originalText);
216 }
217 });
218
219 return;
220 }
221
222 // Original behavior for validation warnings
223 closeModal();
224 allowSave = true;
225 $('#robots-txt-form').submit();
226 });
227
228 // Reset to default
229 $('#reset-to-default').on('click', function() {
230 if (confirm('<?php esc_html_e('Are you sure you want to reset to default content? This will replace your current content.', 'metasync'); ?>')) {
231 $.ajax({
232 url: ajaxurl,
233 type: 'POST',
234 data: {
235 action: 'metasync_get_default_robots'
236 },
237 success: function(response) {
238 if (response.success) {
239 $('#robots-txt-editor').val(response.data.content);
240 }
241 }
242 });
243 }
244 });
245
246 // Validate content button
247 $('#validate-content').on('click', function() {
248 const content = $('#robots-txt-editor').val();
249
250 $.ajax({
251 url: ajaxurl,
252 type: 'POST',
253 data: {
254 action: 'metasync_validate_robots',
255 content: content
256 },
257 success: function(response) {
258 const $results = $('#validation-results');
259 $results.show();
260
261 if (response.success && response.data && response.data.valid) {
262 $results.removeClass('error warning').addClass('success');
263 $results.html('<strong><?php esc_html_e('Validation passed!', 'metasync'); ?></strong> <?php esc_html_e('Your robots.txt syntax is correct.', 'metasync'); ?>');
264
265 if (response.data.warnings && response.data.warnings.length > 0) {
266 $results.removeClass('success').addClass('warning');
267 let html = '<strong><?php esc_html_e('Validation passed with warnings:', 'metasync'); ?></strong><ul style="margin: 8px 0 0 20px;">';
268
269 response.data.warnings.forEach(function(warning) {
270 html += '<li>' + warning + '</li>';
271 });
272
273 html += '</ul>';
274 $results.html(html);
275 }
276 } else {
277 $results.removeClass('success warning').addClass('error');
278 let html = '<strong><?php esc_html_e('Validation failed:', 'metasync'); ?></strong><ul style="margin: 8px 0 0 20px;">';
279
280 if (response.data.errors) {
281 response.data.errors.forEach(function(error) {
282 html += '<li>' + error + '</li>';
283 });
284 }
285
286 html += '</ul>';
287 $results.html(html);
288 }
289 }
290 });
291 });
292
293 // Auto-resize textarea
294 $('#robots-txt-editor').on('input', function() {
295 this.style.height = 'auto';
296 this.style.height = (this.scrollHeight) + 'px';
297 });
298
299 // Preview backup content
300 $('.metasync-preview-backup').on('click', function(e) {
301 e.preventDefault();
302 const backupId = $(this).data('backup-id');
303
304 // Show loading state
305 const $button = $(this);
306 const originalText = $button.html();
307 $button.prop('disabled', true).html('<span class="dashicons dashicons-update dashicons-spin" style="margin-top: 3px;"></span> <?php esc_html_e('Loading...', 'metasync'); ?>');
308
309 $.ajax({
310 url: ajaxurl,
311 type: 'POST',
312 data: {
313 action: 'metasync_preview_robots_backup',
314 backup_id: backupId
315 },
316 success: function(response) {
317 if (response.success && response.data) {
318 // Format the date
319 let dateInfo = '';
320 if (response.data.created_at) {
321 dateInfo = '<p style="margin-bottom: 16px;"><strong><?php esc_html_e('Created:', 'metasync'); ?></strong> ' + response.data.created_at;
322 if (response.data.created_by_name) {
323 dateInfo += ' <?php esc_html_e('by', 'metasync'); ?> ' + response.data.created_by_name;
324 }
325 dateInfo += '</p>';
326 }
327
328 // Create preview content with pre/code block for display
329 const previewContent = dateInfo +
330 '<pre class="metasync-preview-code"><code>' +
331 $('<div>').text(response.data.content).html() +
332 '</code></pre>';
333
334 // Show in modal
335 const $modal = $('#robots-validation-modal');
336 const $modalContent = $modal.find('.metasync-modal-content');
337 const $header = $modal.find('.metasync-modal-header');
338 const $confirmBtn = $('#modal-confirm-btn');
339 const $cancelBtn = $('.metasync-modal-cancel');
340
341 // Add preview class for larger width
342 $modalContent.addClass('preview');
343
344 // Set header style
345 $header.removeClass('error warning success').addClass('preview');
346
347 // Set content
348 $('#modal-title').html('<?php esc_html_e('Backup Preview', 'metasync'); ?>');
349 $('#modal-body').html(previewContent);
350
351 // Configure restore button (on the left)
352 $confirmBtn.html('<span class="dashicons dashicons-backup" style="margin-top: 3px;"></span> <?php esc_html_e('Restore', 'metasync'); ?>')
353 .removeClass('button-primary')
354 .addClass('button-restore')
355 .data('backup-id', backupId)
356 .data('nonce', '<?php echo wp_create_nonce('metasync_restore_robots_backup'); ?>')
357 .show();
358
359 // Hide close button for preview
360 $cancelBtn.hide();
361
362 // Show modal
363 $modal.fadeIn(200);
364 } else {
365 alert('<?php esc_html_e('Failed to load backup content.', 'metasync'); ?>');
366 }
367
368 // Restore button state
369 $button.prop('disabled', false).html(originalText);
370 },
371 error: function() {
372 alert('<?php esc_html_e('An error occurred while loading the backup.', 'metasync'); ?>');
373 // Restore button state
374 $button.prop('disabled', false).html(originalText);
375 }
376 });
377 });
378
379 // Restore backup with AJAX
380 $(document).on('click', '.metasync-restore-backup', function(e) {
381 e.preventDefault();
382
383 if (!confirm('<?php esc_html_e('Are you sure you want to restore this backup? Current content will be backed up automatically.', 'metasync'); ?>')) {
384 return;
385 }
386
387 const $button = $(this);
388 const backupId = $button.data('backup-id');
389 const nonce = $button.data('nonce');
390
391 // Show loading state
392 const originalHtml = $button.html();
393 $button.prop('disabled', true).html('<span class="dashicons dashicons-update dashicons-spin" style="margin-top: 3px;"></span> <?php esc_html_e('Restoring...', 'metasync'); ?>');
394
395 $.ajax({
396 url: ajaxurl,
397 type: 'POST',
398 data: {
399 action: 'metasync_restore_robots_backup',
400 backup_id: backupId,
401 nonce: nonce
402 },
403 success: function(response) {
404 if (response.success) {
405 // Store success message in sessionStorage
406 if (response.data && response.data.message) {
407 sessionStorage.setItem('metasync_robots_restore_message', response.data.message);
408 }
409
410 // Reload the page to show updated content and backup list
411 window.location.reload();
412 } else {
413 // Show error message
414 const errorMessage = response.data && response.data.message ? response.data.message : '<?php esc_html_e('Failed to restore backup.', 'metasync'); ?>';
415 alert(errorMessage);
416
417 // Restore button state
418 $button.prop('disabled', false).html(originalHtml);
419 }
420 },
421 error: function() {
422 alert('<?php esc_html_e('An error occurred while restoring the backup.', 'metasync'); ?>');
423
424 // Restore button state
425 $button.prop('disabled', false).html(originalHtml);
426 }
427 });
428 });
429
430 // Delete backup with AJAX
431 $(document).on('click', '.metasync-delete-backup', function(e) {
432 e.preventDefault();
433
434 if (!confirm('<?php esc_html_e('Are you sure you want to delete this backup?', 'metasync'); ?>')) {
435 return;
436 }
437
438 const $button = $(this);
439 const backupId = $button.data('backup-id');
440 const nonce = $button.data('nonce');
441 const $backupItem = $button.closest('.metasync-backup-item');
442
443 // Show loading state
444 const originalHtml = $button.html();
445 $button.prop('disabled', true).html('<span class="dashicons dashicons-update dashicons-spin"></span>');
446
447 $.ajax({
448 url: ajaxurl,
449 type: 'POST',
450 data: {
451 action: 'metasync_delete_robots_backup',
452 backup_id: backupId,
453 nonce: nonce
454 },
455 success: function(response) {
456 if (response.success) {
457 // Fade out and remove the backup item
458 $backupItem.fadeOut(300, function() {
459 $(this).remove();
460
461 // Check if there are any backups left
462 if ($('.metasync-backup-item').length === 0) {
463 $('.metasync-backups-list').html('<p class="description" style="text-align: center; padding: 20px;"><?php esc_html_e('No backups available yet. Backups are created automatically when you save changes.', 'metasync'); ?></p>');
464 }
465 });
466
467 // Show success message (you can add a notification system here)
468 if (response.data && response.data.message) {
469 // Create a temporary success notice
470 const $notice = $('<div class="notice notice-success is-dismissible" style="margin: 20px 0;"><p>' + response.data.message + '</p></div>');
471 $('.metasync-robots-txt-page').prepend($notice);
472
473 // Auto-dismiss after 3 seconds
474 setTimeout(function() {
475 $notice.fadeOut(300, function() {
476 $(this).remove();
477 });
478 }, 3000);
479 }
480 } else {
481 // Show error message
482 const errorMessage = response.data && response.data.message ? response.data.message : '<?php esc_html_e('Failed to delete backup.', 'metasync'); ?>';
483 alert(errorMessage);
484
485 // Restore button state
486 $button.prop('disabled', false).html(originalHtml);
487 }
488 },
489 error: function() {
490 alert('<?php esc_html_e('An error occurred while deleting the backup.', 'metasync'); ?>');
491
492 // Restore button state
493 $button.prop('disabled', false).html(originalHtml);
494 }
495 });
496 });
497 });
498 </script>
499