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