| 1 |
<?php |
| 2 |
/** |
| 3 |
* Robots.txt Admin Page View |
| 4 |
* |
| 5 |
* @package Search Atlas SEO |
| 6 |
* @copyright Copyright (C) 2021-2025, Search Atlas Group - support@searchatlas.com |
| 7 |
* @since 2.5.6 |
| 8 |
*/ |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if (!defined('WPINC')) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
$site_url = get_site_url(); |
| 16 |
$robots_url = trailingslashit($site_url) . 'robots.txt'; |
| 17 |
?> |
| 18 |
<div class="metasync-robots-txt-page"> |
| 19 |
<?php if (!$is_writable): ?> |
| 20 |
<div class="notice notice-error"> |
| 21 |
<p> |
| 22 |
<strong><?php esc_html_e('Warning:', 'metasync'); ?></strong> |
| 23 |
<?php if ($file_exists): ?> |
| 24 |
<?php esc_html_e('The robots.txt file is not writable. Please check file permissions.', 'metasync'); ?> |
| 25 |
<?php else: ?> |
| 26 |
<?php esc_html_e('Cannot create robots.txt file. Please check that your WordPress root directory is writable.', 'metasync'); ?> |
| 27 |
<?php endif; ?> |
| 28 |
</p> |
| 29 |
</div> |
| 30 |
<?php endif; ?> |
| 31 |
|
| 32 |
<div class="metasync-robots-txt-container"> |
| 33 |
<div class="metasync-robots-txt-editor"> |
| 34 |
<div class="metasync-card"> |
| 35 |
<div class="metasync-card-header"> |
| 36 |
<h2><?php esc_html_e('Edit robots.txt', 'metasync'); ?></h2> |
| 37 |
<div class="metasync-robots-info"> |
| 38 |
<span class="metasync-robots-status"> |
| 39 |
<?php |
| 40 |
$robots_txt = Metasync_Robots_Txt::get_instance(); |
| 41 |
$is_virtual = $robots_txt->is_virtual_mode(); |
| 42 |
if ($file_exists): ?> |
| 43 |
<span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span> |
| 44 |
<?php esc_html_e('Generated', 'metasync'); ?> |
| 45 |
<?php if ($is_virtual): ?> |
| 46 |
<span style="color: #2271b1; font-size: 12px; margin-left: 5px;">(Virtual)</span> |
| 47 |
<?php endif; ?> |
| 48 |
<?php else: ?> |
| 49 |
<span class="dashicons dashicons-warning" style="color: #f0b849;"></span> |
| 50 |
<?php esc_html_e('Not Generated', 'metasync'); ?> |
| 51 |
<?php endif; ?> |
| 52 |
</span> |
| 53 |
<a href="<?php echo esc_url(admin_url('admin.php?page=' . Metasync_Admin::$page_slug . '-import-external&tab=robots')); ?>" class="button button-secondary" style="margin-right: 10px;"> |
| 54 |
<span class="dashicons dashicons-download" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> <?php esc_html_e('Import from SEO Plugins', 'metasync'); ?> |
| 55 |
</a> |
| 56 |
<a href="<?php echo esc_url($robots_url); ?>" target="_blank" class="button button-secondary"> |
| 57 |
<?php esc_html_e('View robots.txt', 'metasync'); ?> |
| 58 |
<span class="dashicons dashicons-external" style="margin-top: 4px;"></span> |
| 59 |
</a> |
| 60 |
</div> |
| 61 |
</div> |
| 62 |
|
| 63 |
<form method="post" action="" id="robots-txt-form"> |
| 64 |
<?php wp_nonce_field('metasync_save_robots_txt', 'metasync_robots_txt_nonce'); ?> |
| 65 |
|
| 66 |
<div class="metasync-editor-container"> |
| 67 |
<textarea |
| 68 |
id="robots-txt-editor" |
| 69 |
name="robots_content" |
| 70 |
rows="20" |
| 71 |
class="large-text code" |
| 72 |
<?php echo !$is_writable ? 'readonly' : ''; ?> |
| 73 |
><?php echo esc_textarea($current_content); ?></textarea> |
| 74 |
</div> |
| 75 |
|
| 76 |
<div class="metasync-editor-actions"> |
| 77 |
<?php if ($is_writable): ?> |
| 78 |
<button type="submit" id="save-robots-btn" class="button button-primary button-large"> |
| 79 |
<span class="dashicons dashicons-saved" style="margin-top: 4px;"></span> |
| 80 |
<?php esc_html_e('Save Changes', 'metasync'); ?> |
| 81 |
</button> |
| 82 |
<button type="button" id="reset-to-default" class="button button-secondary"> |
| 83 |
<span class="dashicons dashicons-image-rotate" style="margin-top: 4px;"></span> |
| 84 |
<?php esc_html_e('Reset to Default', 'metasync'); ?> |
| 85 |
</button> |
| 86 |
<?php endif; ?> |
| 87 |
<button type="button" id="validate-content" class="button button-secondary"> |
| 88 |
<span class="dashicons dashicons-yes-alt" style="margin-top: 4px;"></span> |
| 89 |
<?php esc_html_e('Validate', 'metasync'); ?> |
| 90 |
</button> |
| 91 |
</div> |
| 92 |
|
| 93 |
<div id="validation-results" class="metasync-validation-results" style="display: none;"></div> |
| 94 |
</form> |
| 95 |
|
| 96 |
<div class="metasync-robots-help"> |
| 97 |
<h3><?php esc_html_e('Quick Guide', 'metasync'); ?></h3> |
| 98 |
<div class="metasync-help-grid"> |
| 99 |
<div class="metasync-help-item"> |
| 100 |
<strong>User-agent:</strong> |
| 101 |
<p><?php esc_html_e('Specifies which crawler the rules apply to. Use * for all crawlers.', 'metasync'); ?></p> |
| 102 |
<code>User-agent: *</code> |
| 103 |
</div> |
| 104 |
<div class="metasync-help-item"> |
| 105 |
<strong>Disallow:</strong> |
| 106 |
<p><?php esc_html_e('Blocks access to specific paths or files.', 'metasync'); ?></p> |
| 107 |
<code>Disallow: /wp-admin/</code> |
| 108 |
</div> |
| 109 |
<div class="metasync-help-item"> |
| 110 |
<strong>Allow:</strong> |
| 111 |
<p><?php esc_html_e('Explicitly allows access to specific paths (overrides Disallow).', 'metasync'); ?></p> |
| 112 |
<code>Allow: /wp-admin/admin-ajax.php</code> |
| 113 |
</div> |
| 114 |
<div class="metasync-help-item"> |
| 115 |
<strong>Sitemap:</strong> |
| 116 |
<p><?php esc_html_e('Points crawlers to your XML sitemap.', 'metasync'); ?></p> |
| 117 |
<code>Sitemap: <?php echo esc_html($site_url); ?>/sitemap.xml</code> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
|
| 124 |
<div class="metasync-robots-txt-sidebar"> |
| 125 |
<div class="metasync-card"> |
| 126 |
<div class="metasync-card-header"> |
| 127 |
<h3><?php esc_html_e('Backup History', 'metasync'); ?></h3> |
| 128 |
</div> |
| 129 |
|
| 130 |
<?php if (!empty($backups)): ?> |
| 131 |
<div class="metasync-backups-list"> |
| 132 |
<?php foreach ($backups as $backup): ?> |
| 133 |
<div class="metasync-backup-item"> |
| 134 |
<div class="metasync-backup-info"> |
| 135 |
<strong><?php echo esc_html(get_date_from_gmt($backup['created_at'], get_option('date_format') . ' ' . get_option('time_format'))); ?></strong> |
| 136 |
<?php if (!empty($backup['created_by_name'])): ?> |
| 137 |
<span class="metasync-backup-author"> |
| 138 |
<?php printf(esc_html__('by %s', 'metasync'), esc_html($backup['created_by_name'])); ?> |
| 139 |
</span> |
| 140 |
<?php endif; ?> |
| 141 |
</div> |
| 142 |
<div class="metasync-backup-actions"> |
| 143 |
<button type="button" |
| 144 |
class="button button-small metasync-preview-backup" |
| 145 |
data-backup-id="<?php echo esc_attr($backup['id']); ?>" |
| 146 |
title="<?php esc_html_e('Preview', 'metasync'); ?>"> |
| 147 |
<span class="dashicons dashicons-visibility"></span> |
| 148 |
<?php esc_html_e('Preview', 'metasync'); ?> |
| 149 |
</button> |
| 150 |
<button type="button" |
| 151 |
class="button button-small metasync-restore-backup" |
| 152 |
data-backup-id="<?php echo esc_attr($backup['id']); ?>" |
| 153 |
data-nonce="<?php echo wp_create_nonce('metasync_restore_robots_backup'); ?>" |
| 154 |
title="<?php esc_html_e('Restore', 'metasync'); ?>"> |
| 155 |
<span class="dashicons dashicons-backup"></span> |
| 156 |
<?php esc_html_e('Restore', 'metasync'); ?> |
| 157 |
</button> |
| 158 |
<button type="button" |
| 159 |
class="button button-small button-link-delete metasync-delete-backup" |
| 160 |
data-backup-id="<?php echo esc_attr($backup['id']); ?>" |
| 161 |
data-nonce="<?php echo wp_create_nonce('metasync_delete_robots_backup'); ?>" |
| 162 |
title="<?php esc_html_e('Delete', 'metasync'); ?>"> |
| 163 |
<span class="dashicons dashicons-trash"></span> |
| 164 |
</button> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
<?php endforeach; ?> |
| 168 |
</div> |
| 169 |
<?php else: ?> |
| 170 |
<p class="description"><?php esc_html_e('No backups available yet. Backups are created automatically when you save changes.', 'metasync'); ?></p> |
| 171 |
<?php endif; ?> |
| 172 |
</div> |
| 173 |
|
| 174 |
<div class="metasync-card metasync-warnings-card"> |
| 175 |
<div class="metasync-card-header"> |
| 176 |
<h3><?php esc_html_e('Important Notes', 'metasync'); ?></h3> |
| 177 |
</div> |
| 178 |
<ul class="metasync-warnings-list"> |
| 179 |
<li> |
| 180 |
<span class="dashicons dashicons-warning" style="color: #f0b849;"></span> |
| 181 |
<?php esc_html_e('Never block your entire site (Disallow: /) as it will prevent all search engines from indexing your content.', 'metasync'); ?> |
| 182 |
</li> |
| 183 |
<li> |
| 184 |
<span class="dashicons dashicons-info" style="color: #2271b1;"></span> |
| 185 |
<?php esc_html_e('Changes to robots.txt take effect immediately but may take time for search engines to recognize.', 'metasync'); ?> |
| 186 |
</li> |
| 187 |
<li> |
| 188 |
<span class="dashicons dashicons-admin-plugins" style="color: #2271b1;"></span> |
| 189 |
<?php esc_html_e('Some hosting providers may override robots.txt files. Check with your host if changes don\'t work.', 'metasync'); ?> |
| 190 |
</li> |
| 191 |
</ul> |
| 192 |
</div> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
|
| 197 |
<!-- Validation Modal (Fixed Position Overlay) --> |
| 198 |
<div id="robots-validation-modal" class="metasync-modal" style="display: none;"> |
| 199 |
<div class="metasync-modal-overlay"></div> |
| 200 |
<div class="metasync-modal-content"> |
| 201 |
<div class="metasync-modal-header"> |
| 202 |
<h2 id="modal-title"></h2> |
| 203 |
<button type="button" class="metasync-modal-close">×</button> |
| 204 |
</div> |
| 205 |
<div class="metasync-modal-body" id="modal-body"></div> |
| 206 |
<div class="metasync-modal-footer" id="modal-footer"> |
| 207 |
<div class="metasync-modal-footer-left"> |
| 208 |
<button type="button" class="button button-primary metasync-modal-confirm" id="modal-confirm-btn"><?php esc_html_e('Save Anyway', 'metasync'); ?></button> |
| 209 |
</div> |
| 210 |
<div class="metasync-modal-footer-right"> |
| 211 |
<button type="button" class="button button-secondary metasync-modal-cancel"><?php esc_html_e('Cancel', 'metasync'); ?></button> |
| 212 |
</div> |
| 213 |
</div> |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
|
| 217 |
<?php |
| 218 |
// Load separate CSS and JS files |
| 219 |
require_once __DIR__ . '/styles.php'; |
| 220 |
require_once __DIR__ . '/scripts.php'; |
| 221 |
|