| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Print HTML Option page : wpLingua Register |
| 11 |
* |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
function wplng_option_page_register() { |
| 15 |
|
| 16 |
if ( is_multisite() ) { |
| 17 |
?> |
| 18 |
<div class="wplng-notice notice notice-info"> |
| 19 |
<p><?php esc_html_e( 'wpLingua is not compatible with Multisite.', 'wplingua' ); ?></p> |
| 20 |
</div> |
| 21 |
<?php |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$api_key = wplng_get_api_key(); |
| 26 |
$json_request_key = get_option( 'wplng_request_free_key' ); |
| 27 |
$error_validation = get_transient( 'wplng_api_key_error' ); |
| 28 |
$error_validation = sanitize_text_field( $error_validation ); |
| 29 |
|
| 30 |
delete_transient( 'wplng_api_key_data' ); |
| 31 |
|
| 32 |
if ( ! empty( $error_validation ) |
| 33 |
&& is_string( $error_validation ) |
| 34 |
) : |
| 35 |
|
| 36 |
delete_transient( 'wplng_api_key_error' ); |
| 37 |
|
| 38 |
$message = ''; |
| 39 |
$message .= __( 'Message: ', 'wplingua' ); |
| 40 |
$message .= $error_validation; |
| 41 |
|
| 42 |
?> |
| 43 |
<div class="wplng-notice notice notice-error is-dismissible"> |
| 44 |
<p> |
| 45 |
<strong><?php esc_html_e( 'An error occurred with API key.', 'wplingua' ); ?></strong> |
| 46 |
<br> |
| 47 |
<?php echo esc_html( $message ); ?> |
| 48 |
</p> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
|
| 52 |
elseif ( get_option( 'wplng_api_key' ) !== $api_key |
| 53 |
&& empty( wplng_get_api_data() ) |
| 54 |
) : |
| 55 |
|
| 56 |
update_option( 'wplng_api_key', '' ); |
| 57 |
|
| 58 |
if ( ! empty( get_option( 'wplng_api_key' ) ) ) : |
| 59 |
?> |
| 60 |
<div class="wplng-notice notice notice-error is-dismissible"> |
| 61 |
<p><strong><?php esc_html_e( 'Invalid API key.', 'wplingua' ); ?></strong></p> |
| 62 |
</div> |
| 63 |
<?php |
| 64 |
endif; |
| 65 |
|
| 66 |
elseif ( ! empty( $json_request_key ) ) : |
| 67 |
|
| 68 |
delete_option( 'wplng_request_free_key' ); |
| 69 |
|
| 70 |
$data_request_key = json_decode( $json_request_key, true ); |
| 71 |
$response = wplng_api_call_request_api_key( $data_request_key ); |
| 72 |
|
| 73 |
if ( ! empty( $response['error'] ) ) { |
| 74 |
|
| 75 |
$message = ''; |
| 76 |
|
| 77 |
if ( ! empty( $response['message'] ) ) { |
| 78 |
$message .= __( 'Message: ', 'wplingua' ); |
| 79 |
$message .= $response['message']; |
| 80 |
} |
| 81 |
|
| 82 |
?> |
| 83 |
<div class="wplng-notice notice notice-error is-dismissible"> |
| 84 |
<p> |
| 85 |
<strong><?php esc_html_e( 'An error occurred while creating the API key.', 'wplingua' ); ?></strong> |
| 86 |
<br> |
| 87 |
<?php echo esc_html( $message ); ?> |
| 88 |
</p> |
| 89 |
</div> |
| 90 |
<?php |
| 91 |
} elseif ( ! empty( $response['register'] ) ) { |
| 92 |
|
| 93 |
$mail = ''; |
| 94 |
|
| 95 |
if ( ! empty( $data_request_key['mail_address'] ) |
| 96 |
&& is_email( $data_request_key['mail_address'] ) |
| 97 |
) { |
| 98 |
$mail = sanitize_email( $data_request_key['mail_address'] ); |
| 99 |
} |
| 100 |
|
| 101 |
?> |
| 102 |
<div class="wplng-notice notice notice-success is-dismissible"> |
| 103 |
<p><strong> |
| 104 |
<?php |
| 105 |
esc_html_e( 'The API key has been correctly created and sent to the following e-mail address: ', 'wplingua' ); |
| 106 |
echo esc_html( $mail ); |
| 107 |
?> |
| 108 |
</strong></p> |
| 109 |
</div> |
| 110 |
<?php |
| 111 |
} |
| 112 |
endif; |
| 113 |
?> |
| 114 |
<div class="wrap"> |
| 115 |
|
| 116 |
<h1 class="wp-heading-inline"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Register API key', 'wplingua' ); ?></h1> |
| 117 |
|
| 118 |
<hr class="wp-header-end"> |
| 119 |
|
| 120 |
<form method="post" action="options.php"> |
| 121 |
<?php |
| 122 |
settings_fields( 'wplng_settings' ); |
| 123 |
do_settings_sections( 'wplng_settings' ); |
| 124 |
?> |
| 125 |
<table class="form-table wplng-form-table"> |
| 126 |
|
| 127 |
<tr> |
| 128 |
<th scope="row"><?php esc_html_e( 'Start with wpLingua', 'wplingua' ); ?></th> |
| 129 |
<td> |
| 130 |
<p><strong><?php esc_html_e( 'You are just a few clicks away from making your site multilingual!', 'wplingua' ); ?></strong></p> |
| 131 |
|
| 132 |
<p><?php esc_html_e( 'For wpLingua to work, an API key is required so that your website has access to the automatic translation service. On this page you can enter your API key if you already have one, or create one for free.', 'wplingua' ); ?></p> |
| 133 |
</td> |
| 134 |
</tr> |
| 135 |
|
| 136 |
<tr> |
| 137 |
<th scope="row"><?php esc_html_e( 'Set API Key', 'wplingua' ); ?></th> |
| 138 |
<td> |
| 139 |
<?php wplng_register_part_api_key( $api_key ); ?> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
|
| 143 |
<tr> |
| 144 |
<th scope="row"><?php esc_html_e( 'Get free API key', 'wplingua' ); ?></th> |
| 145 |
<td> |
| 146 |
<?php wplng_register_part_free_api_key(); ?> |
| 147 |
</td> |
| 148 |
</tr> |
| 149 |
|
| 150 |
<tr> |
| 151 |
<th scope="row"><?php esc_html_e( 'Get advanced API features', 'wplingua' ); ?></th> |
| 152 |
<td> |
| 153 |
<?php wplng_register_part_premium(); ?> |
| 154 |
</td> |
| 155 |
</tr> |
| 156 |
|
| 157 |
</table> |
| 158 |
</form> |
| 159 |
</div> |
| 160 |
<?php |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
/** |
| 165 |
* Print HTML subsection of Option page : wpLingua Register - API Key |
| 166 |
* |
| 167 |
* @param string $api_key |
| 168 |
* @return void |
| 169 |
*/ |
| 170 |
function wplng_register_part_api_key( $api_key ) { |
| 171 |
?> |
| 172 |
<fieldset> |
| 173 |
<label for="wplng_api_key"><strong><?php esc_html_e( 'Set the wpLingua API key:', 'wplingua' ); ?></strong></label> |
| 174 |
<p><?php esc_html_e( 'If you already have an API key, enter it below. If you\'ve forgotten your site\'s API key, visit', 'wplingua' ); ?> <a href="https://wplingua.com/recovery/" target="_blank"><?php esc_html_e( 'the API key retrieval page', 'wplingua' ); ?></a>.</p> |
| 175 |
<br> |
| 176 |
<input type="text" name="wplng_api_key" id="wplng_api_key" value="<?php echo esc_attr( $api_key ); ?>"></input> |
| 177 |
|
| 178 |
<?php |
| 179 |
submit_button( |
| 180 |
__( 'Set API key', 'wplingua' ), |
| 181 |
'primary', |
| 182 |
'submit', |
| 183 |
false |
| 184 |
); |
| 185 |
?> |
| 186 |
</fieldset> |
| 187 |
<?php |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
/** |
| 192 |
* Print HTML subsection of Option page : wpLingua Register - Register free API Key |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
function wplng_register_part_free_api_key() { |
| 197 |
|
| 198 |
$email = sanitize_email( get_bloginfo( 'admin_email' ) ); |
| 199 |
$locale = strtolower( substr( get_locale(), 0, 2 ) ); |
| 200 |
|
| 201 |
if ( ! wplng_is_valid_language_id( $locale ) ) { |
| 202 |
$locale = 'en'; |
| 203 |
} |
| 204 |
|
| 205 |
?> |
| 206 |
<p for="wplng_api_key"><strong><?php esc_html_e( 'Register free wpLingua API key:', 'wplingua' ); ?></strong></p> |
| 207 |
<p><?php esc_html_e( 'Get a free wpLingua API key and make your website bilingual in a minute!', 'wplingua' ); ?></p> |
| 208 |
<hr> |
| 209 |
<br> |
| 210 |
<fieldset> |
| 211 |
<label for="wplng-website-url" class="wplng-fe-50"> |
| 212 |
<strong><?php esc_html_e( 'Website URL:', 'wplingua' ); ?> </strong> |
| 213 |
</label> |
| 214 |
<input type="url" name="wplng-website-url" id="wplng-website-url" class="wplng-fe-50" value="<?php echo esc_url( get_site_url() ); ?>"> |
| 215 |
</fieldset> |
| 216 |
<br> |
| 217 |
<fieldset> |
| 218 |
<label for="wplng-email" class="wplng-fe-50"> |
| 219 |
<strong><?php esc_html_e( 'Mail address:', 'wplingua' ); ?> </strong> |
| 220 |
</label> |
| 221 |
<input type="email" name="wplng-email" id="wplng-email" class="wplng-fe-50" value="<?php echo esc_attr( $email ); ?>"> |
| 222 |
</fieldset> |
| 223 |
<br> |
| 224 |
<fieldset> |
| 225 |
<label for="wplng-language-website" class="wplng-fe-50"> |
| 226 |
<strong><?php esc_html_e( 'Website language:', 'wplingua' ); ?> </strong> |
| 227 |
</label> |
| 228 |
<select name="wplng-language-website" id="wplng-language-website" class="wplng-fe-50"></select> |
| 229 |
</fieldset> |
| 230 |
<br> |
| 231 |
<fieldset> |
| 232 |
<label for="wplng-language-target" class="wplng-fe-50"> |
| 233 |
<strong><?php esc_html_e( 'Target language:', 'wplingua' ); ?> </strong> |
| 234 |
</label> |
| 235 |
<select name="wplng-language-target" id="wplng-language-target" class="wplng-fe-50"></select> |
| 236 |
</fieldset> |
| 237 |
<br> |
| 238 |
<fieldset> |
| 239 |
<input type="checkbox" name="wplng-accept-eula" id="wplng-accept-eula"> |
| 240 |
<label for="wplng-accept-eula"> |
| 241 |
<strong><?php esc_html_e( 'I have read and accept the', 'wplingua' ); ?> <a href="https://wplingua.com/terms/" target="_blank"><?php esc_html_e( 'API terms of use', 'wplingua' ); ?></a> </strong> |
| 242 |
</label> |
| 243 |
</fieldset> |
| 244 |
<fieldset style="display: none;"> |
| 245 |
<p><?php esc_html_e( 'Website Locale:', 'wplingua' ); ?> <span id="wplng-website-locale"><?php echo esc_html( $locale ); ?></span></p> |
| 246 |
<textarea name="wplng_request_free_key" id="wplng_request_free_key"></textarea> |
| 247 |
</fieldset> |
| 248 |
<button id="wplng-get-free-api-submit" class="button button-primary"> |
| 249 |
<?php esc_html_e( 'Get a free API key', 'wplingua' ); ?> |
| 250 |
</button> |
| 251 |
<?php |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/** |
| 256 |
* Print HTML subsection of Option page : wpLingua Register - Premium informations |
| 257 |
* |
| 258 |
* @return void |
| 259 |
*/ |
| 260 |
function wplng_register_part_premium() { |
| 261 |
?> |
| 262 |
<p><strong><?php esc_html_e( 'Get more target languages and advanced features:', 'wplingua' ); ?></strong></p> |
| 263 |
<p><?php esc_html_e( 'To translate your site into more languages and access advanced features, visit wpLingua website.', 'wplingua' ); ?></p> |
| 264 |
<ul style="list-style: inside; padding: 0 0 0 15px;"> |
| 265 |
<li><?php esc_html_e( 'Multilingual WooCommerce store', 'wplingua' ); ?></li> |
| 266 |
<li><?php esc_html_e( 'Allow search from all languages', 'wplingua' ); ?></li> |
| 267 |
<li><?php esc_html_e( 'Get more target languages', 'wplingua' ); ?></li> |
| 268 |
</ul> |
| 269 |
<br> |
| 270 |
<a class="button button-primary" href="https://wplingua.com/" target="_blank"><?php esc_html_e( 'Visit wpLingua website', 'wplingua' ); ?></a> |
| 271 |
<?php |
| 272 |
} |
| 273 |
|