PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.7
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.7
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 / switcher-nav-menu.php

switcher-nav-menu.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.7, at inc/admin/switcher-nav-menu.php

366 lines 10.6 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 CSS and JS script for wpLingua nav menu option
11 *
12 * @param string $hook
13 * @return void
14 */
15 function wplng_switcher_nav_menu_inline_scripts( $hook ) {
16
17 if ( ! is_admin()
18 || $hook !== 'nav-menus.php'
19 || empty( wplng_get_api_key() )
20 ) {
21 return;
22 }
23
24 ?>
25 <style id="wplng-nav-menu-style">
26
27 #tabs-panel-wplingua-endpoints.tabs-panel {
28 max-height: unset;
29 }
30
31 #wplng_switcher_nav_menu .accordion-section-content .wplng-menu-header,
32 #wplng_switcher_nav_menu .accordion-section-content .inside {
33 margin-top: 0;
34 }
35
36 #tabs-panel-wplingua-endpoints label {
37 font-size: 14px;
38 margin-bottom: 6px;
39 display: block;
40 }
41
42 #tabs-panel-wplingua-endpoints select {
43 width: 100%;
44 max-width: 100%;
45 }
46
47 .menu-item:has(.wplng-menu-item-settings-switcher) p.field-url,
48 .menu-item:has(.wplng-menu-item-settings-switcher) p.description {
49 display: none;
50 }
51
52 .menu-item:has(.wplng-menu-item-settings-switcher) span.item-type {
53 display: none;
54 }
55
56 .menu-item:has(.wplng-menu-item-settings-switcher) span.item-controls::before {
57 content: "wpLingua";
58 display: inline-block;
59 padding: 12px 16px;
60 color: #646970;
61 font-size: 12px;
62 line-height: 1.5;
63 }
64
65 .wplng-menu-item-settings-switcher select {
66 width: 100%;
67 max-width: 100%;
68 margin: 10px 0;
69 }
70 </style>
71 <script id="wplng-nav-menu-script">
72 window.onload = function() {
73
74 /**
75 * wpLingua: Add new nav menu switcher
76 */
77
78 // Infinite nav menu switcher
79 // Update the edit fields event listen
80
81 let wplngNewValidate = document.getElementById('submit-posttype-wplingua-endpoints');
82 wplngNewValidate.addEventListener('click', wplngAlwaysValidate);
83
84 function wplngAlwaysValidate() {
85 wplngUpdateEditField();
86 setTimeout(() => {
87 document.getElementById('wplng-validate-id').checked = true;
88 }, 1500)
89 }
90
91 // Make link from option
92
93 let wplngNewNameFormat = document.getElementById('wplng-menu-name-format')
94 let wplngNewFlag = document.getElementById('wplng-menu-flag')
95 let wplngNewLayout = document.getElementById('wplng-menu-layout')
96
97 wplngNewNameFormat.addEventListener('change', wplngUpdateMenuSwitcherUrl);
98 wplngNewFlag.addEventListener('change', wplngUpdateMenuSwitcherUrl);
99 wplngNewLayout.addEventListener('change', wplngUpdateMenuSwitcherUrl);
100
101 function wplngUpdateMenuSwitcherUrl() {
102
103 let url = "#wplng";
104 url += "-n" + wplngNewNameFormat.value;
105 url += "-f" + wplngNewFlag.value;
106 url += "-l" + wplngNewLayout.value;
107
108 document.getElementById('wplng-menu-switcher-url').value = url;
109 }
110
111 wplngUpdateMenuSwitcherUrl();
112
113 /**
114 * wpLingua: Edit nav menu switcher
115 */
116
117 function wplngUpdateEditField() {
118
119 let wplngEditNameFormat = document.getElementsByClassName('wplng-menu-name-format-edit')
120 let wplngEditFlag = document.getElementsByClassName('wplng-menu-flag-edit')
121 let wplngEditLayout = document.getElementsByClassName('wplng-menu-layout-edit')
122
123 for (var i = 0; i < wplngEditNameFormat.length; i++) {
124 wplngEditNameFormat[i].addEventListener('change', wplngEditMenuSwitcherUrl);
125 }
126
127 for (var i = 0; i < wplngEditFlag.length; i++) {
128 wplngEditFlag[i].addEventListener('change', wplngEditMenuSwitcherUrl);
129 }
130
131 for (var i = 0; i < wplngEditLayout.length; i++) {
132 wplngEditLayout[i].addEventListener('change', wplngEditMenuSwitcherUrl);
133 }
134 }
135
136 function wplngEditMenuSwitcherUrl() {
137
138 let item = this.getAttribute("item");
139
140 let nameFormat = document.getElementById('wplng-menu-name-format-' + item).value;
141 let flag = document.getElementById('wplng-menu-flag-' + item).value;
142 let layout = document.getElementById('wplng-menu-layout-' + item).value;
143
144 let url = "#wplng";
145 url += "-n" + nameFormat;
146 url += "-f" + flag;
147 url += "-l" + layout;
148
149 document.getElementById('edit-menu-item-url-' + item).value = url;
150 }
151
152 wplngUpdateEditField();
153 }
154 </script>
155 <?php
156 }
157
158
159 /**
160 * Add wpLingua nav menu option meta ox
161 *
162 * @return void
163 */
164 function wp_nav_menu_switcher_box_add_register() {
165 add_meta_box(
166 'wplng_switcher_nav_menu',
167 __( 'wpLingua', 'wplingua' ),
168 'wp_nav_menu_switcher_box_add',
169 'nav-menus',
170 'side',
171 'default'
172 );
173 }
174
175
176 /**
177 * Print the HTML of the meta box used to add a language switcher in nav menu
178 *
179 * @return void
180 */
181 function wp_nav_menu_switcher_box_add() {
182
183 $valid_name_format = wplng_data_switcher_nav_menu_valid_name_format();
184 $valid_flags_style = wplng_data_switcher_nav_menu_valid_flags_style();
185 $valid_layout = wplng_data_switcher_nav_menu_valid_layout();
186
187 ?>
188 <div id="posttype-wplingua-endpoints" class="posttypediv">
189
190 <p class="wplng-menu-header"><?php esc_html_e( 'These options are used to add a language switcher in a menu. This language switcher automatically uses the menu design.', 'wplingua' ); ?></p>
191
192 <div id="tabs-panel-wplingua-endpoints" class="tabs-panel tabs-panel-active">
193 <ul class="categorychecklist form-no-clear">
194
195 <li>
196 <label for="wplng-menu-name-format">
197 <?php esc_html_e( 'Displayed names: ', 'wplingua' ); ?>
198 </label>
199 <select id="wplng-menu-name-format" name="wplng-menu-name-format">
200 <?php
201 foreach ( $valid_name_format as $key => $value ) {
202 echo '<option value="' . esc_attr( $key ) . '">';
203 echo esc_html( $value );
204 echo '</option>';
205 }
206 ?>
207 </select>
208 <hr>
209 </li>
210
211 <li>
212 <label for="wplng-menu-flag">
213 <?php esc_html_e( 'Displayed flag: ', 'wplingua' ); ?>
214 </label>
215 <select id="wplng-menu-flag" name="wplng-menu-flag">
216 <?php
217 foreach ( $valid_flags_style as $key => $value ) {
218 echo '<option value="' . esc_attr( $key ) . '">';
219 echo esc_html( $value );
220 echo '</option>';
221 }
222 ?>
223 </select>
224 <hr>
225 </li>
226
227 <li>
228 <label for="wplng-menu-layout">
229 <?php esc_html_e( 'Layout: ', 'wplingua' ); ?>
230 </label>
231 <select id="wplng-menu-layout" name="wplng-menu-layout">
232 <?php
233 foreach ( $valid_layout as $key => $value ) {
234 echo '<option value="' . esc_attr( $key ) . '">';
235 echo esc_html( $value );
236 echo '</option>';
237 }
238 ?>
239 </select>
240 </li>
241
242 <li style="display: none;">
243
244 <input type="checkbox" class="menu-item-checkbox" id="wplng-validate-id" name="menu-item[1][menu-item-validate]" value="1" onchange="alert('ok');" checked/>
245
246 <input type="hidden" class="menu-item-object-id" name="menu-item[1][menu-item-object-id]" value="wplingua" />
247 <input type="hidden" class="menu-item-object" name="menu-item[1][menu-item-object]" value="wplingua" />
248 <input type="hidden" class="menu-item-type" name="menu-item[1][menu-item-type]" value="custom" />
249 <input type="hidden" class="menu-item-title" name="menu-item[1][menu-item-title]" value="<?php esc_attr_e( 'Language switcher', 'wplingua' ); ?>" />
250 <input type="hidden" class="menu-item-classes" name="menu-item[1][menu-item-classes]" value="wplingua-menu-switcher-untreated"/>
251 <input type="hidden" class="menu-item-url" name="menu-item[1][menu-item-url]" value="" id="wplng-menu-switcher-url"/>
252 </li>
253
254 </ul>
255 </div>
256
257 <p class="button-controls" data-items-type="posttype-wplingua-endpoints">
258 <span class="add-to-menu">
259 <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'wplingua' ); ?>" name="add-post-type-menu-item" id="submit-posttype-wplingua-endpoints">
260 <span class="spinner"></span>
261 </span>
262 </p>
263
264 </div>
265 <?php
266 }
267
268
269 /**
270 * Print option in wpLingua nav menu
271 *
272 * @param string $item_id
273 * @param WP_Post $menu_item
274 * @return void
275 */
276 function wp_nav_menu_switcher_box_edit( $item_id, $menu_item ) {
277
278 if ( ! is_array( $menu_item->classes )
279 || ! in_array( 'wplingua-menu-switcher-untreated', $menu_item->classes, true )
280 || empty( $menu_item->url )
281 ) {
282 return;
283 }
284
285 $args = wplng_switcher_nav_menu_args_from_href( $menu_item->url );
286
287 if ( false === $args ) {
288 return;
289 }
290
291 $valid_name_format = wplng_data_switcher_nav_menu_valid_name_format();
292 $valid_flags_style = wplng_data_switcher_nav_menu_valid_flags_style();
293 $valid_layout = wplng_data_switcher_nav_menu_valid_layout();
294
295 ?>
296 <div class="wplng-menu-item-settings-switcher">
297 <label for="wplng-menu-name-format-<?php echo esc_attr( $item_id ); ?>">
298 <?php esc_html_e( 'Displayed names: ', 'wplingua' ); ?>
299 </label>
300 <select
301 class="wplng-menu-name-format-edit"
302 id="wplng-menu-name-format-<?php echo esc_attr( $item_id ); ?>"
303 name="wplng-menu-name-format-<?php echo esc_attr( $item_id ); ?>"
304 item="<?php echo esc_attr( $item_id ); ?>"
305 >
306 <?php
307 foreach ( $valid_name_format as $key => $value ) {
308 if ( $key === $args['name_format']['value'] ) {
309 echo '<option value="' . esc_attr( $key ) . '" selected>';
310 } else {
311 echo '<option value="' . esc_attr( $key ) . '">';
312 }
313 echo esc_html( $value );
314 echo '</option>';
315 }
316 ?>
317 </select>
318 <hr>
319 <label for="wplng-menu-flag-<?php echo esc_attr( $item_id ); ?>">
320 <?php esc_html_e( 'Displayed flag: ', 'wplingua' ); ?>
321 </label>
322 <select
323 class="wplng-menu-flag-edit"
324 id="wplng-menu-flag-<?php echo esc_attr( $item_id ); ?>"
325 name="wplng-menu-flag-<?php echo esc_attr( $item_id ); ?>"
326 item="<?php echo esc_attr( $item_id ); ?>"
327 >
328 <?php
329 foreach ( $valid_flags_style as $key => $value ) {
330 if ( $key === $args['flags_style']['value'] ) {
331 echo '<option value="' . esc_attr( $key ) . '" selected>';
332 } else {
333 echo '<option value="' . esc_attr( $key ) . '">';
334 }
335 echo esc_html( $value );
336 echo '</option>';
337 }
338 ?>
339 </select>
340 <hr>
341 <label for="wplng-menu-layout-<?php echo esc_attr( $item_id ); ?>">
342 <?php esc_html_e( 'Layout: ', 'wplingua' ); ?>
343 </label>
344 <select
345 class="wplng-menu-layout-edit"
346 id="wplng-menu-layout-<?php echo esc_attr( $item_id ); ?>"
347 name="wplng-menu-layout-<?php echo esc_attr( $item_id ); ?>"
348 item="<?php echo esc_attr( $item_id ); ?>"
349 >
350 <?php
351 foreach ( $valid_layout as $key => $value ) {
352 if ( $key === $args['layout']['value'] ) {
353 echo '<option value="' . esc_attr( $key ) . '" selected>';
354 } else {
355 echo '<option value="' . esc_attr( $key ) . '">';
356 }
357 echo esc_html( $value );
358 echo '</option>';
359 }
360 ?>
361 </select>
362 <hr>
363 </div>
364 <?php
365 }
366