PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.12.2
Translate and Go multilingual – Automatic AI translation – wpLingua v2.12.2
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 / dom / mode-list.php

mode-list.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.12.2, at inc/dom/mode-list.php

411 lines 11.3 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 * Modify dom for the list mode
11 *
12 * @param array $translations
13 * @return object $dom
14 */
15 function wplng_dom_mode_list( $dom, $args ) {
16
17 wplng_args_setup( $args );
18
19 if ( $args['mode'] !== 'list'
20 || $args['load'] === 'progress'
21 || ! current_user_can( 'edit_posts' )
22 ) {
23 return $dom;
24 }
25
26 /**
27 * Add body class : wplingua-list
28 */
29
30 foreach ( $dom->find( 'body[class]' ) as $element ) {
31 $element->class = $element->class . ' wplingua-list';
32 }
33
34 /**
35 * Add list assets
36 */
37
38 $asset_url = add_query_arg(
39 'ver',
40 WPLNG_PLUGIN_VERSION,
41 plugins_url() . '/wplingua/assets/css/list.css'
42 );
43
44 $asset = '<link';
45 $asset .= ' rel="stylesheet"';
46 $asset .= ' id="wplingua-list-css"';
47 $asset .= ' href="' . esc_url( $asset_url ) . '"';
48 $asset .= ' type="text/css"';
49 $asset .= '/>';
50
51 foreach ( $dom->find( 'head' ) as $element ) {
52 $element->innertext = $element->innertext . $asset;
53 }
54
55 /**
56 * Switcher
57 */
58
59 $language_website = wplng_get_language_by_id( $args['language_source'] );
60 $language_current_id = $args['language_target'];
61 $languages_target = wplng_get_languages_target();
62
63 if ( empty( $languages_target ) ) {
64 return '';
65 }
66
67 $class = wplng_get_switcher_class(
68 array(
69 'theme' => 'grey-simple-smooth',
70 'style' => 'dropdown',
71 'flags' => 'rectangular',
72 'title' => 'name',
73 )
74 );
75
76 // Create the switcher HTML
77
78 $html_switcher = '<div id="wplng-modal-list-switcher">';
79 $html_switcher .= '<div class="' . esc_attr( 'wplng-switcher ' . $class ) . '">';
80 $html_switcher .= '<div class="switcher-content">';
81
82 $html_switcher .= '<div class="wplng-languages">';
83
84 // Create link for each target languages
85 foreach ( $languages_target as $language_target ) {
86
87 $url = wplng_get_url_current_for_language( $language_target['id'] );
88
89 if ( $language_target['id'] === $language_current_id ) {
90 continue;
91 }
92
93 $html_switcher .= '<a';
94 $html_switcher .= ' class="wplng-language"';
95 $html_switcher .= ' href="' . esc_url( $url ) . '"';
96 $html_switcher .= '>';
97
98 if ( ! empty( $language_target['flag'] ) ) {
99 $html_switcher .= '<img';
100 $html_switcher .= ' src="' . esc_url( $language_target['flag'] ) . '"';
101 $html_switcher .= ' alt="' . esc_attr( $language_target['name'] ) . '"';
102 $html_switcher .= '>';
103 }
104
105 $html_switcher .= '<span class="language-name">';
106 $html_switcher .= esc_html( $language_target['name'] );
107 $html_switcher .= '</span>';
108
109 $html_switcher .= '</a>';
110 }
111
112 $html_switcher .= '</div>'; // End .wplng-languages
113
114 // Create link for current language
115 if ( $language_website['id'] !== $language_current_id ) {
116
117 foreach ( $languages_target as $language_target ) {
118
119 if ( $language_target['id'] !== $language_current_id ) {
120 continue;
121 }
122
123 $url = wplng_get_url_current_for_language( $language_target['id'] );
124
125 $html_switcher .= '<a';
126 $html_switcher .= ' class="wplng-language wplng-language-current"';
127 $html_switcher .= ' href="' . esc_url( $url ) . '"';
128 $html_switcher .= ' onclick="event.preventDefault();"';
129 $html_switcher .= '>';
130
131 if ( ! empty( $language_target['flag'] ) ) {
132 $html_switcher .= '<img';
133 $html_switcher .= ' src="' . esc_url( $language_target['flag'] ) . '"';
134 $html_switcher .= ' alt="' . esc_attr( $language_target['name'] ) . '"';
135 $html_switcher .= '>';
136 }
137
138 $html_switcher .= '<span class="language-name">';
139 $html_switcher .= esc_html( $language_target['name'] );
140 $html_switcher .= '</span>';
141
142 $html_switcher .= '</a>';
143
144 break;
145 }
146 }
147
148 $html_switcher .= '</div>'; // End .switcher-content
149 $html_switcher .= '</div>'; // End .wplng-switcher
150 $html_switcher .= '</div>'; // End #wplng-modal-list-switcher
151
152 /**
153 * Return button
154 */
155
156 $return_button = '<a';
157 $return_button .= ' href="' . esc_url( $args['url_current'] ) . '"';
158 $return_button .= ' title="' . esc_attr__( 'Return on page', 'wplingua' ) . '"';
159 $return_button .= ' class="wplng-button-icon wplng-button-return"';
160 $return_button .= '>';
161 $return_button .= '<span class="dashicons dashicons-no"></span>';
162 $return_button .= '</a>';
163
164 /**
165 * Filter : Search
166 */
167
168 $filter_search = '<div class="wplng-filter">';
169 $filter_search .= '<label for="wplng-filter-search">';
170 $filter_search .= '<span class="dashicons dashicons-search"></span> ';
171 $filter_search .= esc_html__( 'Search', 'wplingua' );
172 $filter_search .= '</label>';
173 $filter_search .= '<input type="text" id="wplng-filter-search">';
174 $filter_search .= '</div>'; // End .wplng-filter
175
176 /**
177 * Filter : Status
178 */
179
180 $filter_status = '<div class="wplng-filter">';
181 $filter_status .= '<label for="wplng-filter-status">';
182 $filter_status .= '<span class="dashicons dashicons-yes"></span> ';
183 $filter_status .= esc_html__( 'Status', 'wplingua' );
184 $filter_status .= '</label>';
185 $filter_status .= '<div class="wplng-filter-select">';
186 $filter_status .= '<select id="wplng-filter-status">';
187
188 $filter_status .= '<option value="all">';
189 $filter_status .= esc_html__( 'All', 'wplingua' );
190 $filter_status .= '</option>';
191
192 $filter_status .= '<option value="reviewed">';
193 $filter_status .= esc_html__( 'Reviewed', 'wplingua' );
194 $filter_status .= '</option>';
195
196 $filter_status .= '<option value="unreviewed">';
197 $filter_status .= esc_html__( 'Unreviewed', 'wplingua' );
198 $filter_status .= '</option>';
199
200 $filter_status .= '</select>';
201 $filter_status .= '</div>'; // End .wplng-filter-select
202 $filter_status .= '</div>'; // End .wplng-filter
203
204 /**
205 * Filter : Order
206 */
207
208 $filter_order = '<div class="wplng-filter">';
209 $filter_order .= '<label for="wplng-filter-order">';
210 $filter_order .= '<span class="dashicons dashicons-randomize"></span> ';
211 $filter_order .= esc_html__( 'Order', 'wplingua' );
212 $filter_order .= '</label>';
213 $filter_order .= '<div class="wplng-filter-select">';
214 $filter_order .= '<select id="wplng-filter-order">';
215
216 $filter_order .= '<option value="occurrence">';
217 $filter_order .= esc_html__( 'Occurrence order', 'wplingua' );
218 $filter_order .= '</option>';
219
220 $filter_order .= '<option value="alphabetical-sources">';
221 $filter_order .= esc_html__( 'Alphabetical - sources', 'wplingua' );
222 $filter_order .= '</option>';
223
224 $filter_order .= '<option value="alphabetical-translations">';
225 $filter_order .= esc_html__( 'Alphabetical - translations', 'wplingua' );
226 $filter_order .= '</option>';
227
228 $filter_order .= '</select>';
229 $filter_order .= '</div>'; // End .wplng-filter-select
230 $filter_order .= '</div>'; // End .wplng-filter
231
232 /**
233 * Modal
234 */
235
236 $html = '<div id="wplng-modal-container">';
237 $html .= '<div id="wplng-modal">';
238
239 /**
240 * Modal header
241 */
242
243 $html .= '<div id="wplng-modal-header">';
244
245 $html .= '<div id="wplng-modal-header-main">';
246
247 $html .= '<div id="wplng-modal-header-title">';
248 $html .= '<span class="dashicons dashicons-translation wplng-modal-header-icon"></span> ';
249 $html .= '<span id="wplng-modal-title-text">';
250 $html .= esc_html__( 'All translations on page', 'wplingua' );
251 $html .= '</span>'; // End #wplng-modal-title-text
252 $html .= '</div>'; // End #wplng-modal-title
253
254 $html .= '<div id="wplng-modal-header-control">';
255 $html .= $html_switcher;
256 $html .= $return_button;
257 $html .= '</div>'; // End #wplng-modal-header-control
258
259 $html .= '</div>'; // End #wplng-modal-header-main
260
261 $html .= '<div id="wplng-modal-filter">';
262 $html .= $filter_search;
263 $html .= $filter_status;
264 $html .= $filter_order;
265 $html .= '</div>'; // End #wplng-modal-filter
266
267 $html .= '</div>'; // End #wplng-modal-header
268
269 /**
270 * Extract SEO title and description
271 */
272
273 $translations = $args['translations'];
274 $seo_title = '';
275 $seo_description = '';
276 $translation_seo_title = array();
277 $translation_seo_description = array();
278
279 foreach ( $dom->find( 'title' ) as $element ) {
280 $seo_title = wplng_text_esc( $element->innertext );
281 break;
282 }
283
284 foreach ( $dom->find( 'meta[name="description"]' ) as $element ) {
285 if ( isset( $element->attr['content'] ) ) {
286 $seo_description = wplng_text_esc( $element->attr['content'] );
287 break;
288 }
289 }
290
291 foreach ( $translations as $key => $translation ) {
292
293 if ( empty( $translation['post_id'] )
294 || empty( $translation['source'] )
295 || empty( $translation['translation'] )
296 ) {
297 continue;
298 }
299
300 if ( $seo_title === $translation['translation'] ) {
301 $translation_seo_title = $translation;
302 $translation_seo_title['tag'] = __( 'SEO - Title:', 'wplingua' );
303 unset( $translations[ $key ] );
304 } elseif ( $seo_description === $translation['translation'] ) {
305 $translation_seo_description = $translation;
306 $translation_seo_description['tag'] = __( 'SEO - Description:', 'wplingua' );
307 unset( $translations[ $key ] );
308 }
309 }
310
311 if ( ! empty( $translation_seo_description ) ) {
312 $translations = array_merge(
313 array( $translation_seo_description ),
314 $translations
315 );
316 }
317
318 if ( ! empty( $translation_seo_title ) ) {
319 $translations = array_merge(
320 array( $translation_seo_title ),
321 $translations
322 );
323 }
324
325 /**
326 * Make the Modal items
327 */
328
329 $html .= '<div id="wplng-modal-items">';
330
331 $html .= '<p id="wplng-modal-no-item-found" style="display: none;">';
332 $html .= esc_html( 'No translation found.', 'wplingua' );
333 $html .= '</p>'; // End #wplng-modal-no-item-found
334
335 foreach ( $translations as $key => $translation ) {
336
337 if ( empty( $translation['post_id'] )
338 || empty( $translation['source'] )
339 || empty( $translation['translation'] )
340 ) {
341 continue;
342 }
343
344 $class = 'wplng-modal-item';
345
346 if ( ! empty( $translation['review'] ) ) {
347 $class .= ' wplng-is-review';
348 }
349
350 $html .= '<div class="' . esc_attr( $class ) . '"';
351 $html .= ' data-wplng-post="' . esc_attr( $translation['post_id'] ) . '"';
352 $html .= ' data-wplng-order="' . esc_attr( $key ) . '"';
353 $html .= '>';
354
355 if ( ! empty( $translation['tag'] ) ) {
356 $html .= '<div class="wplng-item-tag">';
357 $html .= esc_html( $translation['tag'] );
358 $html .= '</div>'; // End .wplng-item-tag
359 }
360
361 $html .= '<div class="wplng-item-main">';
362
363 $html .= '<div class="wplng-item-text">';
364 $html .= '<div class="wplng-item-source">';
365 $html .= esc_html( $translation['source'] );
366 $html .= '</div>'; // End .wplng-item-source
367 $html .= '<div class="wplng-item-translation">';
368 $html .= esc_html( $translation['translation'] );
369 $html .= '</div>'; // End .wplng-item-translation
370 $html .= '</div>'; // End .wplng-item-text
371 $html .= '<div class="wplng-item-edit">';
372
373 $html .= '<a';
374 $html .= ' title="' . esc_attr__( 'Edit this translation', 'wplingua' ) . '"';
375 $html .= ' data-wplng-post="' . esc_attr( $translation['post_id'] ) . '"';
376 $html .= ' class="wplng-button-icon wplng-edit-link"';
377 $html .= '>';
378 $html .= '<span class="dashicons dashicons-edit"></span></a>';
379 $html .= '</a>';
380
381 $html .= '</div>'; // End .wplng-item-edit
382 $html .= '</div>'; // End .wplng-item-main
383 $html .= '</div>'; // ENd .wplng-modal-item
384 }
385
386 $html .= '</div>'; // End #wplng-modal-items
387 $html .= '</div>'; // End #wplng-modal
388
389 $html .= '<button';
390 $html .= ' id="wplng-scroll-to-top"';
391 $html .= ' title="' . esc_attr__( 'Go to top', 'wplingua' ) . '"';
392 $html .= ' style="display: none;"';
393 $html .= '>';
394 $html .= '<span class="dashicons dashicons-arrow-up-alt2"></span>';
395 $html .= '</button>';
396
397 $html .= '</div>'; // End #wplng-modal-container
398
399 /**
400 * Place the translation edit modale
401 */
402
403 $html .= wplng_translation_edit_modal_get_html();
404
405 foreach ( $dom->find( 'body' ) as $body ) {
406 $body->innertext = $body->innertext . $html;
407 }
408
409 return $dom;
410 }
411