-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsitemap.php
More file actions
63 lines (51 loc) · 2.17 KB
/
sitemap.php
File metadata and controls
63 lines (51 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
use App\Services\S3Client\S3SitemapClient;
if (! defined('ABSPATH')) {
exit;
}
add_action('admin_menu', function () {
add_menu_page('Sitemap Manager', 'Sitemap Upload', 'edit_posts', 'sitemap-manager', 'render_sitemap_uploader', 'dashicons-admin-site-alt3', 55);
});
function render_sitemap_uploader()
{
if (!current_user_can('edit_posts')) return;
$S3_Client = new S3SitemapClient();
if (isset($_FILES['sitemap_file'])) {
$file = $_FILES['sitemap_file'];
$upload_result = $S3_Client->uploadUserXmlToS3($file['tmp_name'], 'sitemap.xml');
if ($upload_result) {
echo '<div class="updated"><p>Sitemap synced to S3 successfully!</p></div>';
} else {
echo '<div class="error"><p>S3 Upload failed. Check AWS IAM Role permissions.</p></div>';
}
}
$s3_data = $S3_Client->getS3SitemapMetadata();
$last_modified = $s3_data['exists'] ? date("F d, Y @ H:i:s", $s3_data['last_modified']) : 'No file found';
$file_size = $s3_data['exists'] ? size_format($s3_data['size']) : '0 KB';
?>
<div class="wrap">
<h1>Sitemap Manager</h1>
<div style="background: #fff; border: 1px solid #ccd0d4; padding: 20px; max-width: 600px; margin-top: 20px; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
<h3>Current Sitemap Status</h3>
<table class="wp-list-table widefat fixed striped" style="margin-bottom: 20px;">
<tr>
<td><strong>Last Updated:</strong></td>
<td><?php echo $last_modified; ?></td>
</tr>
<tr>
<td><strong>File Size:</strong></td>
<td><?php echo $file_size; ?></td>
</tr>
</table>
<hr />
<h3>Upload New Sitemap</h3>
<form method="post" enctype="multipart/form-data" style="margin-top: 15px;">
<input type="file" name="sitemap_file" accept=".xml" required>
<div style="margin-top: 15px;">
<?php submit_button('Upload and Overwrite', 'primary', 'submit', false); ?>
</div>
</form>
</div>
</div>
<?php
}