| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* MetaSync - Google Index API Settings |
| 5 |
* |
| 6 |
* This view integrates Google Index API settings into MetaSync's general settings |
| 7 |
* |
| 8 |
* @package MetaSync |
| 9 |
* @subpackage GoogleIndexDirect |
| 10 |
* @version 1.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Prevent direct access |
| 14 |
if (!defined('ABSPATH')) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
?> |
| 19 |
|
| 20 |
<div style="padding: 20px;"> |
| 21 |
<!-- Requirements (Collapsible) --> |
| 22 |
<details style="margin-top: 20px; padding-top: 15px;"> |
| 23 |
<summary style="cursor: pointer; font-weight: 600; margin-bottom: 10px;">Requirements</summary> |
| 24 |
<div style="margin-top: 10px;"> |
| 25 |
<ul style="margin-left: 20px;"> |
| 26 |
<li>Google Cloud Project with Indexing API enabled</li> |
| 27 |
<li>Service Account with appropriate permissions</li> |
| 28 |
<li>Domain verified in Google Search Console</li> |
| 29 |
<li>Service account added as user in Search Console</li> |
| 30 |
</ul> |
| 31 |
</div> |
| 32 |
</details> |
| 33 |
|
| 34 |
<!-- Configuration Status --> |
| 35 |
<div style="margin-bottom: 20px;"> |
| 36 |
<?php if ($is_configured): ?> |
| 37 |
<div class="notice notice-success inline" style="margin: 0 0 15px 0; padding: 10px;"> |
| 38 |
<p style="margin: 0;"> |
| 39 |
<strong>Service Account Configured: </strong><br> |
| 40 |
<strong>Email:</strong> <?php echo esc_html($service_info['client_email']); ?><br> |
| 41 |
<strong>Project ID:</strong> <?php echo esc_html($service_info['project_id']); ?> |
| 42 |
</p> |
| 43 |
</div> |
| 44 |
<?php else: ?> |
| 45 |
<div class="notice notice-warning inline" style="margin: 0 0 15px 0; padding: 10px;"> |
| 46 |
<p style="margin: 0;"> |
| 47 |
<strong>Service Account Not Configured</strong><br> |
| 48 |
Please provide your Google service account JSON below. |
| 49 |
</p> |
| 50 |
</div> |
| 51 |
<?php endif; ?> |
| 52 |
</div> |
| 53 |
|
| 54 |
<!-- Settings Fields --> |
| 55 |
<table class="form-table" style="margin-top: 0;"> |
| 56 |
<tr> |
| 57 |
<th scope="row" style="width: 200px;"> |
| 58 |
<label for="google_index_service_account_json">Service Account JSON</label> |
| 59 |
<?php Metasync::render_tooltip_icon('google_index_service_account_json', 'Paste the private key file from a Google Cloud service account added to your Search Console property. This lets the plugin ask Google to crawl your pages. Treat it like a password. It is stored on your server and never shared.'); ?> |
| 60 |
</th> |
| 61 |
<td> |
| 62 |
<textarea name="google_index_service_account_json" |
| 63 |
id="google_index_service_account_json" |
| 64 |
class="large-text code" |
| 65 |
rows="8" |
| 66 |
placeholder="Paste your Google service account JSON here..."><?php |
| 67 |
if ($is_configured && !empty($saved_json_display)) { |
| 68 |
echo esc_textarea($saved_json_display); |
| 69 |
} |
| 70 |
?></textarea> |
| 71 |
<p class="description"> |
| 72 |
<strong>How to get this:</strong><br> |
| 73 |
1. Go to <a href="https://console.cloud.google.com/apis/credentials" target="_blank">Google Cloud Console → Credentials</a><br> |
| 74 |
2. Create or select a Service Account → Generate JSON key<br> |
| 75 |
3. Paste the JSON content above or upload the file below |
| 76 |
</p> |
| 77 |
</td> |
| 78 |
</tr> |
| 79 |
|
| 80 |
<tr> |
| 81 |
<th scope="row"> |
| 82 |
<label for="google_index_service_account_file">Upload JSON File</label> |
| 83 |
<?php Metasync::render_tooltip_icon('google_index_service_account_file', 'Upload the service account JSON key file you downloaded from Google Cloud instead of pasting it. The file fills in the Service Account JSON box above. It is only stored once you save.'); ?> |
| 84 |
</th> |
| 85 |
<td> |
| 86 |
<input type="file" |
| 87 |
name="google_index_service_account_file" |
| 88 |
id="google_index_service_account_file" |
| 89 |
accept=".json,application/json" |
| 90 |
class="regular-text" /> |
| 91 |
|
| 92 |
<!-- |
| 93 |
Selected-file row. Hidden until a file is chosen; the admin |
| 94 |
JS fills in the name and reveals it. "Remove" clears the |
| 95 |
input and restores the textarea to whatever it held before |
| 96 |
the file was read, so a mis-click does not destroy a saved |
| 97 |
(redacted) configuration the user never meant to replace. |
| 98 |
--> |
| 99 |
<p id="google-index-selected-file" style="display:none;margin:8px 0 0;"> |
| 100 |
<span class="dashicons dashicons-media-code" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> |
| 101 |
<strong id="google-index-selected-file-name"></strong> |
| 102 |
<button type="button" |
| 103 |
id="google-index-remove-file" |
| 104 |
class="button-link" |
| 105 |
style="margin-left:8px;color:var(--dashboard-error, #b32d2e);text-decoration:none;" |
| 106 |
aria-label="Remove the selected JSON file">× Remove</button> |
| 107 |
</p> |
| 108 |
|
| 109 |
<!-- Inline validation feedback; replaces the old alert(). --> |
| 110 |
<div id="google-index-file-messages" style="margin-top:8px;"></div> |
| 111 |
|
| 112 |
<p class="description"> |
| 113 |
Upload your service account JSON file. This will auto-populate the textarea above. |
| 114 |
</p> |
| 115 |
</td> |
| 116 |
</tr> |
| 117 |
</table> |
| 118 |
|
| 119 |
<!-- Action Buttons and Test Results --> |
| 120 |
<?php if ($is_configured): ?> |
| 121 |
<div style="margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;"> |
| 122 |
<button type="button" |
| 123 |
id="google-index-test-connection" |
| 124 |
class="button button-secondary"> |
| 125 |
<span class="dashicons dashicons-yes" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Test Connection |
| 126 |
</button> |
| 127 |
|
| 128 |
<button type="button" |
| 129 |
id="google-index-clear-config" |
| 130 |
class="button button-link-delete" |
| 131 |
style="margin-left: 10px;"> |
| 132 |
<span class="dashicons dashicons-trash" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Clear Configuration |
| 133 |
</button> |
| 134 |
|
| 135 |
<div id="google-index-test-results" style="margin-top: 15px;"></div> |
| 136 |
</div> |
| 137 |
<?php endif; ?> |
| 138 |
|
| 139 |
</div> |
| 140 |
|
| 141 |
<style> |
| 142 |
/* Additional styles for Google Index API section */ |
| 143 |
#google-index-test-results .notice { |
| 144 |
margin-top: 10px; |
| 145 |
} |
| 146 |
|
| 147 |
#google-index-test-results ul { |
| 148 |
margin-left: 20px; |
| 149 |
} |
| 150 |
|
| 151 |
.metasync-accordion-section details[open] summary { |
| 152 |
margin-bottom: 15px; |
| 153 |
} |
| 154 |
|
| 155 |
.metasync-accordion-section pre { |
| 156 |
font-size: 12px; |
| 157 |
line-height: 1.4; |
| 158 |
} |
| 159 |
|
| 160 |
.metasync-accordion-section .notice.inline { |
| 161 |
display: block; |
| 162 |
} |
| 163 |
</style> |
| 164 |
|
| 165 |
<!-- File upload handling and unsaved changes integration is now handled by the admin JavaScript --> |
| 166 |
|