PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 1.0.5
Translate and Go multilingual – Automatic AI translation – wpLingua v1.0.5
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / admin / option-page-switcher.php

option-page-switcher.php in Translate and Go multilingual – Automatic AI translation – wpLingua 1.0.5, at inc/admin/option-page-switcher.php

302 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Switcher
11 *
12 * @return void
13 */
14 function wplng_option_page_switcher() {
15
16 $insert = wplng_get_switcher_insert();
17 $theme = wplng_get_switcher_theme();
18 $style = wplng_get_switcher_style();
19 $name_format = wplng_get_switcher_name_format();
20 $flags_style = wplng_get_switcher_flags_style();
21 $custom_css = get_option( 'wplng_custom_css' );
22
23 if ( empty( $custom_css ) || ! is_string( $custom_css ) ) {
24 $custom_css = '';
25 } else {
26 $custom_css = wp_strip_all_tags( $custom_css );
27 }
28
29 ?>
30 <div class="wrap">
31
32 <h1 class="wp-heading-inline"><span class="dashicons dashicons-translation"></span> <?php esc_html_e( 'wpLingua - Switcher settings', 'wplingua' ); ?></h1>
33
34 <hr class="wp-header-end">
35
36 <form method="post" action="options.php">
37 <?php
38 settings_fields( 'wplng_switcher' );
39 do_settings_sections( 'wplng_switcher' );
40 ?>
41 <table class="form-table wplng-form-table">
42
43 <tr>
44 <th scope="row"><?php esc_html_e( 'Switcher preview', 'wplingua' ); ?></th>
45 <td id="wplng-switcher-preview-container">
46 <div class="wplng-switcher-preview">
47 <?php
48 echo wplng_get_switcher_html(
49 array( 'class' => 'switcher-preview' )
50 );
51 ?>
52 </div>
53 </td>
54 </tr>
55
56 <tr>
57 <th scope="row"><?php esc_html_e( 'Switcher design', 'wplingua' ); ?></th>
58 <td>
59 <fieldset>
60
61 <label for="wplng_style" class="wplng-fe-50">
62 <strong><?php esc_html_e( 'Switcher style: ', 'wplingua' ); ?></strong>
63 </label>
64
65 <select id="wplng_style" name="wplng_style" class="wplng-fe-50">
66 <?php
67
68 $style_options = wplng_data_switcher_valid_style();
69
70 foreach ( $style_options as $option_value => $option_name ) {
71 if ( $style === $option_value ) {
72 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
73 } else {
74 echo '<option value="' . esc_attr( $option_value ) . '">';
75 }
76 echo esc_html( $option_name );
77 echo '</option>';
78 }
79
80 ?>
81 </select>
82
83 </fieldset>
84
85 <br>
86
87 <fieldset>
88 <label for="wplng_name_format" class="wplng-fe-50">
89 <strong><?php esc_html_e( 'Displayed name: ', 'wplingua' ); ?></strong>
90 </label>
91 <select id="wplng_name_format" name="wplng_name_format" class="wplng-fe-50">
92 <?php
93
94 $name_format_options = wplng_data_switcher_valid_name_format();
95
96 foreach ( $name_format_options as $option_value => $option_name ) {
97 if ( $name_format === $option_value ) {
98 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
99 } else {
100 echo '<option value="' . esc_attr( $option_value ) . '">';
101 }
102 echo esc_html( $option_name );
103 echo '</option>';
104 }
105
106 ?>
107 </select>
108 </fieldset>
109
110 <br>
111
112 <fieldset>
113 <label for="wplng_flags_style" class="wplng-fe-50">
114 <strong><?php esc_html_e( 'Flag style: ', 'wplingua' ); ?></strong>
115 </label>
116 <select id="wplng_flags_style" name="wplng_flags_style" class="wplng-fe-50">
117 <?php
118
119 $flags_style_options = wplng_data_switcher_valid_flags_style();
120
121 foreach ( $flags_style_options as $option_value => $option_name ) {
122 if ( $flags_style === $option_value ) {
123 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
124 } else {
125 echo '<option value="' . esc_attr( $option_value ) . '">';
126 }
127 echo esc_html( $option_name );
128 echo '</option>';
129 }
130
131 ?>
132 </select>
133 </fieldset>
134
135 <br>
136
137 <fieldset>
138 <label for="wplng_theme" class="wplng-fe-50">
139 <strong><?php esc_html_e( 'Switcher theme: ', 'wplingua' ); ?></strong>
140 </label>
141
142 <select id="wplng_theme" name="wplng_theme" class="wplng-fe-50">
143 <?php
144
145 $theme_options = wplng_data_switcher_valid_theme();
146
147 foreach ( $theme_options as $option_value => $option_name ) {
148 if ( $theme === $option_value ) {
149 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
150 } else {
151 echo '<option value="' . esc_attr( $option_value ) . '">';
152 }
153 echo esc_html( $option_name );
154 echo '</option>';
155 }
156
157 ?>
158 </select>
159 </fieldset>
160 </td>
161 </tr>
162
163 <tr>
164 <th scope="row"><?php esc_html_e( 'Custom CSS', 'wplingua' ); ?></th>
165 <td>
166 <fieldset>
167 <label for="wplng_custom_css">
168 <strong><?php esc_html_e( 'Set custom CSS:', 'wplingua' ); ?></strong>
169 </label>
170 <textarea name="wplng_custom_css" id="wplng_custom_css"><?php echo esc_textarea( $custom_css ); ?></textarea>
171 </fieldset>
172 </td>
173 </tr>
174
175 <tr>
176 <th scope="row"><?php esc_html_e( 'Switcher insertion', 'wplingua' ); ?></th>
177 <td>
178 <fieldset>
179
180 <label for="wplng_insert" class="wplng-fe-50">
181 <strong><?php _e( 'Automatic insert: ', 'wplingua' ); ?></strong>
182 </label>
183
184 <select id="wplng_insert" name="wplng_insert" class="wplng-fe-50">
185 <?php
186
187 $insert_options = wplng_data_switcher_valid_insert();
188
189 foreach ( $insert_options as $option_value => $option_name ) {
190 if ( $insert === $option_value ) {
191 echo '<option value="' . esc_attr( $option_value ) . '" selected>';
192 } else {
193 echo '<option value="' . esc_attr( $option_value ) . '">';
194 }
195 echo esc_html( $option_name );
196 echo '</option>';
197 }
198
199 ?>
200 </select>
201
202 </fieldset>
203 <br>
204 <p>
205 <strong class="wplng-fe-50"><?php esc_html_e( 'Shortcode switcher: ', 'wplingua' ); ?></strong>
206 <code class="wplng-fe-50">[wplng_switcher]</code>
207 </p>
208
209 </td>
210 </tr>
211
212 </table>
213 <?php submit_button(); ?>
214 </form>
215 </div>
216 <?php
217 }
218
219
220 /**
221 * Print HTML subsection of Option page : wpLingua Switcher - Flags style
222 *
223 * @param string $old_flags_style Flag URL
224 * @param string $new_flags_style Flag URL
225 * @return void
226 */
227 function wplng_options_switcher_update_flags_style( $old_flags_style, $new_flags_style ) {
228
229 if ( $old_flags_style === $new_flags_style ) {
230 return;
231 }
232
233 if ( 'none' === $new_flags_style ) {
234 $new_flags_style = 'rectangular';
235 }
236
237 if ( 'none' === $old_flags_style ) {
238 $old_flags_style = 'rectangular';
239 }
240
241 /**
242 * Replace flag URL for website language
243 */
244
245 $website_flag = wplng_get_language_website_flag();
246
247 $website_flag = str_replace(
248 '/wplingua/assets/images/' . $old_flags_style . '/',
249 '/wplingua/assets/images/' . $new_flags_style . '/',
250 $website_flag
251 );
252
253 $website_flag = sanitize_url( $website_flag );
254
255 update_option( 'wplng_website_flag', $website_flag );
256
257 /**
258 * Replace flag URL for target languages
259 */
260
261 $target_languages_json = get_option( 'wplng_target_languages' );
262
263 if ( empty( $target_languages_json ) ) {
264 return;
265 }
266
267 $target_languages = json_decode(
268 $target_languages_json,
269 true
270 );
271
272 if ( empty( $target_languages ) || ! is_array( $target_languages ) ) {
273 return;
274 }
275
276 foreach ( $target_languages as $key => $target_language ) {
277 if ( ! empty( $target_language['flag'] )
278 && is_string( $target_language['flag'] )
279 ) {
280
281 $old_src = sanitize_url( $target_language['flag'] );
282
283 $new_src = str_replace(
284 '/' . $old_flags_style . '/',
285 '/' . $new_flags_style . '/',
286 $old_src
287 );
288
289 $new_src = sanitize_url( $new_src );
290
291 $target_languages[ $key ]['flag'] = $new_src;
292 }
293 }
294
295 $target_languages_json = wp_json_encode(
296 $target_languages,
297 JSON_UNESCAPED_SLASHES
298 );
299
300 update_option( 'wplng_target_languages', $target_languages_json );
301 }
302