wpml-tm-menus-management.php
28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
<?php
use WPML\API\Sanitize;
use WPML\Setup\Option;
use WPML\TM\API\Basket;
use WPML\TM\ATE\ClonedSites\Lock as AteApiLock;
use WPML\TM\Menu\TranslationBasket\Utility;
use WPML\TM\Menu\TranslationServices\Section;
use WPML\LIB\WP\User;
use function WPML\Container\make;
class WPML_TM_Menus_Management extends WPML_TM_Menus {
const SKIP_TM_WIZARD_META_KEY = 'wpml_skip_tm_wizard';
/** @var IWPML_Template_Service $template_service */
private $template_service;
private $active_languages;
private $translatable_types;
private $current_language;
private $filter_post_status;
private $filter_translation_type;
private $post_statuses;
private $selected_languages;
private $source_language;
/** @var \WPML_TM_Translation_Priorities */
private $translation_priorities;
private $dashboard_title_sort_link;
private $dashboard_date_sort_link;
private $documents;
private $selected_posts = array();
private $translation_filter;
private $found_documents;
/**
* @var \Mockery\MockInterface
*/
private $admin_sections;
public function __construct( IWPML_Template_Service $template_service ) {
$this->template_service = $template_service;
$this->admin_sections = WPML\Container\make( 'WPML_TM_Admin_Sections' );
$this->admin_sections->init_hooks();
parent::__construct();
}
protected function render_main() {
if ( ! AteApiLock::isLocked() ) {
?>
<div class="wrap">
<h1><?php echo esc_html__( 'Translation Management', 'wpml-translation-management' ); ?></h1>
<?php
do_action( 'icl_tm_messages' );
$this->build_tab_items();
$this->render_items();
?>
</div>
<?php
}
}
/**
* It builds all the sections.
*/
protected function build_tab_items() {
$this->tab_items = array();
$this->build_dashboard_item();
$this->build_basket_item();
/** @var \WPML_TM_Admin_Sections $admin_sections */
foreach ( $this->admin_sections->get_tab_items() as $slug => $tab_item ) {
$this->tab_items[ $slug ] = $tab_item;
}
$this->build_translation_jobs_item();
$this->build_tp_com_log_item();
$this->reorder_items();
}
/**
* It reorders all items based on their `order` key as well as the order (index) they were added.
*/
private function reorder_items() {
$order_of_sections = array();
$tab_items = $this->tab_items;
foreach ( $tab_items as $key => $value ) {
$order_of_sections[ $key ] = (int) $value['order'];
}
if ( array_multisort( $order_of_sections, SORT_ASC, $tab_items ) ) {
$this->tab_items = $tab_items;
}
}
private function build_dashboard_item() {
$this->tab_items['dashboard'] = [
'caption' => __( 'Dashboard', 'wpml-translation-management' ),
'current_user_can' => [ User::CAP_ADMINISTRATOR, User::CAP_MANAGE_TRANSLATIONS ],
'callback' => [ $this, 'build_content_dashboard' ],
'order' => 100,
];
}
public function build_content_dashboard() {
/** @var SitePress $sitepress */
global $sitepress;
$this->active_languages = $sitepress->get_active_languages();
$this->translatable_types = apply_filters( 'wpml_tm_dashboard_translatable_types', $sitepress->get_translatable_documents() );
$this->build_dashboard_data();
if ( $this->found_documents > $this->documents || $this->there_are_hidden_posts() ) {
$this->display_hidden_posts_message();
}
$this->build_dashboard_confirmation_messages_container();
$this->build_content_dashboard_remote_translations_controls();
$this->build_content_dashboard_filter();
$this->build_content_dashboard_results();
}
/**
* Used only by unit tests at the moment
*/
private function build_dashboard_data() {
$this->build_dashboard_filter_arguments();
$this->build_dashboard_documents();
}
private function build_dashboard_filter_arguments() {
global $sitepress, $iclTranslationManagement;
$this->current_language = $sitepress->get_current_language();
$this->source_language = TranslationProxy_Basket::get_source_language();
$this->translation_filter = \WPML\TM\TranslationDashboard\FiltersStorage::get();
if ( $this->source_language || ! isset( $this->translation_filter['from_lang'] ) ) {
if ( $this->source_language ) {
$this->translation_filter['from_lang'] = $this->source_language;
} else {
$this->translation_filter['from_lang'] = $this->current_language;
if ( $lang = Sanitize::stringProp( 'lang', $_GET ) ) {
$this->translation_filter['from_lang'] = $lang;
}
}
}
if ( ! isset( $this->translation_filter['to_lang'] ) ) {
$this->translation_filter['to_lang'] = '';
if ( $lang = Sanitize::stringProp( 'to_lang', $_GET ) ) {
$this->translation_filter['to_lang'] = $lang;
}
}
if ( $this->translation_filter['to_lang'] == $this->translation_filter['from_lang'] ) {
$this->translation_filter['to_lang'] = false;
}
if ( ! isset( $this->translation_filter['tstatus'] ) ) {
$this->translation_filter['tstatus'] = isset( $_GET['tstatus'] ) ? $_GET['tstatus'] : -1; // -1 == All documents
}
if ( ! isset( $this->translation_filter['sort_by'] ) || ! $this->translation_filter['sort_by'] ) {
$this->translation_filter['sort_by'] = 'date';
}
if ( ! isset( $this->translation_filter['sort_order'] ) || ! $this->translation_filter['sort_order'] ) {
$this->translation_filter['sort_order'] = 'DESC';
}
if ( ! isset( $this->translation_filter['type'] ) ) {
$this->translation_filter['type'] = ''; // All Types.
}
$sort_order_next = $this->translation_filter['sort_order'] == 'ASC' ? 'DESC' : 'ASC';
$nonce = wp_create_nonce( 'sort' );
$this->dashboard_title_sort_link = 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=dashboard&icl_tm_action=sort&sort_by=title&sort_order=' . $sort_order_next . '&nonce=' . $nonce;
$this->dashboard_date_sort_link = 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=dashboard&icl_tm_action=sort&sort_by=date&sort_order=' . $sort_order_next . '&nonce=' . $nonce;
$this->post_statuses = array(
'publish' => __( 'Published', 'wpml-translation-management' ),
'draft' => __( 'Draft', 'wpml-translation-management' ),
'pending' => __( 'Pending Review', 'wpml-translation-management' ),
'future' => __( 'Scheduled', 'wpml-translation-management' ),
'private' => __( 'Private', 'wpml-translation-management' ),
);
$this->post_statuses = apply_filters( 'wpml_tm_dashboard_post_statuses', $this->post_statuses );
$this->translation_priorities = new WPML_TM_Translation_Priorities();
// Get the document types that we can translate
/**
* attachments are excluded
*
* @since 2.6.0
*/
add_filter( 'wpml_tm_dashboard_translatable_types', array( $this, 'exclude_attachments' ) );
$this->post_types = $sitepress->get_translatable_documents();
$this->post_types = apply_filters( 'wpml_tm_dashboard_translatable_types', $this->post_types );
$this->build_external_types();
$this->selected_languages = array();
if ( ! empty( $iclTranslationManagement->dashboard_select ) ) {
$this->selected_posts = $iclTranslationManagement->dashboard_select['post'];
$this->selected_languages = $iclTranslationManagement->dashboard_select['translate_to'];
}
if ( isset( $this->translation_filter['icl_selected_posts'] ) ) {
parse_str( $this->translation_filter['icl_selected_posts'], $this->selected_posts );
}
$this->filter_post_status = isset( $this->translation_filter['status'] ) ? $this->translation_filter['status'] : false;
if ( isset( $_GET['type'] ) ) {
$this->translation_filter['type'] = $_GET['type'];
}
$paged = (int) filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT );
$this->translation_filter['page'] = $paged ? $paged - 1 : 0;
$this->filter_translation_type = isset( $this->translation_filter['type'] ) ? $this->translation_filter['type'] : false;
}
private function build_dashboard_confirmation_messages_container() {
echo '<div id="wpml-tm-dashboard-sent-content-messages-container"></div>';
}
private function build_dashboard_documents() {
global $wpdb, $sitepress;
$wpml_tm_dashboard_pagination = new WPML_TM_Dashboard_Pagination();
$wpml_tm_dashboard_pagination->add_hooks();
$tm_dashboard = new WPML_TM_Dashboard( $wpdb, $sitepress );
$this->translation_filter['limit_no'] = $this->dashboard_pagination ? $this->dashboard_pagination->get_items_per_page() : 20;
$dashboard_data = $tm_dashboard->get_documents( $this->translation_filter );
$this->documents = $dashboard_data['documents'];
$this->found_documents = $dashboard_data['found_documents'];
}
/**
* @return bool
*/
private function there_are_hidden_posts() {
return -1 === $this->found_documents;
}
private function display_hidden_posts_message() {
?>
<div class="notice notice-warning otgs-notice-icon inline">
<p>
<?php
echo sprintf(
esc_html__( 'To see more items, use the filter and narrow down the search. %s', 'wpml-translation-management' ),
'<a href="https://wpml.org/documentation/translating-your-contents/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmltm" target="_blank">' . esc_html__( 'Help', 'wpml-translation-management' ) . '</a>'
)
?>
</p>
</div>
<?php
}
private function build_content_dashboard_remote_translations_controls() {
// shows only when translation polling is on and there are translations in progress
$this->build_content_dashboard_fetch_translations_box();
$active_service = icl_do_not_promote() ? false : TranslationProxy::get_current_service();
$service_dashboard_info = TranslationProxy::get_service_dashboard_info();
if ( $active_service && $service_dashboard_info ) {
?>
<div class="icl_cyan_box">
<h3>
<?php
echo $active_service->name . ' ' . __(
'account status',
'wpml-translation-management'
)
?>
</h3>
<?php echo $service_dashboard_info; ?>
</div>
<?php
}
}
private function build_content_dashboard_results() {
?>
<form method="post" id="icl_tm_dashboard_form">
<?php
// #############################################
// Display the items for translation in a table.
// #############################################
$this->build_content_dashboard_documents();
$this->heading( __( '2. Select translation options', 'wpml-translation-management' ) );
$this->build_content_dashboard_documents_options();
do_action( 'wpml_tm_dashboard_promo' );
?>
</form>
<?php
}
private function build_content_dashboard_documents() {
?>
<input type="hidden" name="icl_tm_action" value="add_jobs"/>
<input type="hidden" name="translate_from" value="<?php echo esc_attr( $this->translation_filter['from_lang'] ); ?>"/>
<table class="widefat fixed striped" id="icl-tm-translation-dashboard">
<thead>
<?php $this->build_content_dashboard_documents_head_footer_cells(); ?>
</thead>
<tfoot>
<?php $this->build_content_dashboard_documents_head_footer_cells(); ?>
</tfoot>
<tbody>
<?php
$this->build_content_dashboard_documents_body();
?>
</tbody>
</table>
<div class="tablenav clearfix">
<div class="alignleft">
<strong><?php echo esc_html__( 'Word count estimate:', 'wpml-translation-management' ); ?></strong>
<?php printf( esc_html__( '%s words', 'wpml-translation-management' ), '<span id="icl-tm-estimated-words-count">0</span>' ); ?>
<span id="icl-tm-doc-wrap" style="display: none">
<?php printf( esc_html__( 'in %s document(s)', 'wpml-translation-management' ), '<span id="icl-tm-sel-doc-count">0</span>' ); ?>
</span>
<?php do_action( 'wpml_tm_dashboard_word_count_estimation' ); ?>
</div>
<?php
if ( $this->dashboard_pagination ) {
do_action( 'wpml_tm_dashboard_pagination', $this->dashboard_pagination->get_items_per_page(), $this->found_documents );
}
?>
</div>
<?php
do_action( 'wpml_tm_after_translation_dashboard_documents' );
}
private function build_content_dashboard_documents_options() {
echo '<div class="tm-dashboard-translation-options"></div>';
}
private function build_content_dashboard_documents_head_footer_cells() {
global $sitepress;
?>
<tr>
<td scope="col" class="manage-column column-cb check-column">
<?php
$check_all_checked = checked( true, isset( $_GET['post_id'] ), false );
?>
<input type="checkbox" <?php echo $check_all_checked; ?>/>
</td>
<th scope="col" class="manage-column column-title">
<?php
$dashboard_title_sort_caption = __( 'Title', 'wpml-translation-management' );
$this->build_content_dashboard_documents_sorting_link( $this->dashboard_title_sort_link, $dashboard_title_sort_caption, 'p.post_title' );
?>
</th>
<th scope="col" class="manage-column wpml-column-type">
<?php echo esc_html__( 'Type', 'wpml-translation-management' ); ?>
</th>
<?php
$active_languages = $sitepress->get_active_languages();
$lang_count = count( $active_languages );
$lang_col_width = ( $lang_count - 1 ) * 32 . 'px';
if ( $lang_count > 10 ) {
$lang_col_width = '30%';
}
?>
<th scope="col" class="manage-column column-active-languages wpml-col-languages" style="width: <?php echo esc_attr( $lang_col_width ); ?>">
<?php
if ( $this->translation_filter['to_lang'] && array_key_exists( $this->translation_filter['to_lang'], $active_languages ) ) {
$lang = $active_languages[ $this->translation_filter['to_lang'] ];
?>
<span title="<?php echo esc_attr( $lang['display_name'] ); ?>">
<?php echo $sitepress->get_flag_image( $lang['code'], [ 16, 12 ], $this->translation_filter['to_lang'] ) ?>
</span>
<?php
} else {
foreach ( $active_languages as $lang ) {
if ( $lang['code'] === $this->translation_filter['from_lang'] ) {
continue;
}
?>
<span title="<?php echo esc_attr( $lang['display_name'] ); ?>">
<?php echo $sitepress->get_flag_image( $lang['code'], [ 16, 12 ], $lang['code'] ) ?>
</span>
<?php
}
}
?>
</th>
<th scope="col" class="manage-column column-date">
<?php
$dashboard_date_sort_label = __( 'Date', 'wpml-translation-management' );
$this->build_content_dashboard_documents_sorting_link( $this->dashboard_date_sort_link, $dashboard_date_sort_label, 'p.post_date' );
?>
</th>
<th scope="col" class="manage-column column-actions">
<?php echo esc_html__( 'Actions', 'wpml-translation-management' ); ?>
</th>
</tr>
<?php
}
private function build_content_dashboard_documents_body() {
global $sitepress;
if ( ! $this->documents ) {
?>
<tr>
<td scope="col" colspan="6" align="center">
<span class="no-documents-found"><?php echo esc_html__( 'No documents found', 'wpml-translation-management' ); ?></span>
</td>
</tr>
<?php
} else {
$records_factory = new WPML_TM_Word_Count_Records_Factory();
$single_process_factory = new WPML_TM_Word_Count_Single_Process_Factory();
$translatable_element_provider = new WPML_TM_Translatable_Element_Provider(
$records_factory->create(),
$single_process_factory->create(),
class_exists( 'WPML_ST_Package_Factory' ) ? new WPML_ST_Package_Factory() : null
);
wp_nonce_field( 'save_translator_note_nonce', '_icl_nonce_stn_' );
$active_languages = $this->translation_filter['to_lang']
? array( $this->translation_filter['to_lang'] => $this->active_languages[ $this->translation_filter['to_lang'] ] )
: $this->active_languages;
foreach ( $this->documents as $doc ) {
$selected = is_array( $this->selected_posts ) && in_array( $doc->ID, $this->selected_posts );
$doc_row = new WPML_TM_Dashboard_Document_Row(
$doc,
$this->post_types,
$this->post_statuses,
$active_languages,
$selected,
$sitepress,
$translatable_element_provider
);
$doc_row->display();
}
}
}
private function build_content_dashboard_documents_sorting_link( $url, $label, $filter_argument ) {
$caption = $label;
if ( $this->translation_filter['sort_by'] === $filter_argument ) {
$caption .= ' ';
$caption .= $this->translation_filter['sort_order'] === 'ASC' ? '↑' : '↓';
}
?>
<a href="<?php echo esc_url( $url ); ?>">
<?php echo $caption; ?>
</a>
<?php
}
private function build_basket_item() {
$basket_items_count = TranslationProxy_Basket::get_basket_items_count( true );
if ( $basket_items_count > 0 ) {
$this->tab_items['basket'] = [
'caption' => $this->build_basket_item_caption( $basket_items_count ),
'current_user_can' => [ User::CAP_ADMINISTRATOR, User::CAP_MANAGE_TRANSLATIONS ],
'callback' => [ $this, 'build_content_basket' ],
'order' => 101,
];
}
}
/**
* @param int $basket_items_count
*
* @return string
*/
private function build_basket_item_caption( $basket_items_count = 0 ) {
if ( isset( $_GET['clear_basket'] ) && $_GET['clear_basket'] ) {
$basket_items_count = 0;
} else {
if ( ! is_numeric( $basket_items_count ) ) {
$basket_items_count = TranslationProxy_Basket::get_basket_items_count( true );
}
if ( isset( $_GET['action'], $_GET['id'] ) && $_GET['action'] === 'delete' && $_GET['id'] ) {
-- $basket_items_count;
}
}
$basket_items_count_caption = esc_html__( 'Translation Basket', 'wpml-translation-management' );
if ( $basket_items_count > 0 ) {
$basket_item_count_badge = '<span id="wpml-basket-items"><span id="basket-item-count">' . $basket_items_count . '</span></span>';
$basket_items_count_caption .= $basket_item_count_badge;
}
return $basket_items_count_caption;
}
public function build_content_basket() {
$basket_table = new SitePress_Table_Basket();
do_action( 'wpml_tm_before_basket_items_display' );
$basket_table->prepare_items();
$action_url = esc_attr( 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=' . $_GET['sm'] );
$this->heading( __( '1. Review documents for translation', 'wpml-translation-management' ) );
?>
<form method="post" id="translation-jobs-basket-form" class="js-translation-jobs-basket-form"
data-message="
<?php
echo esc_attr__(
'You are about to delete selected items from the basket. Are you sure you want to do that?',
'wpml-translation-management'
)
?>
"
name="translation-jobs-basket" action="<?php echo $action_url; ?>">
<?php
$basket_table->display();
?>
</form>
<?php
$this->build_translation_options();
}
private function build_translation_options() {
global $sitepress, $wpdb;
$basket_items_number = TranslationProxy_Basket::get_basket_items_count( true );
if ( $basket_items_number > 0 ) {
$deadline_estimate_factory = new WPML_TM_Jobs_Deadline_Estimate_Factory();
$deadline_estimate_date = $deadline_estimate_factory->create()->get(
TranslationProxy_Basket::get_basket(),
array(
'translator_id' => TranslationProxy_Service::get_wpml_translator_id(),
'service' => TranslationProxy::get_current_service_id(),
)
);
$basket_name_max_length = TranslationProxy::get_current_service_batch_name_max_length();
$source_language = TranslationProxy_Basket::get_source_language();
$basket = new WPML_Translation_Basket( $wpdb );
$basket_name_placeholder = sprintf(
__( '%1$s|WPML|%2$s', 'wpml-translation-management' ),
htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ),
$source_language
);
$basket_name_placeholder = $basket->get_unique_basket_name( $basket_name_placeholder, $basket_name_max_length );
$utility = make( Utility::class );
$target_languages = $utility->getTargetLanguages();
$isTheOnlyAvailableTranslator = $utility->isTheOnlyAvailableTranslatorForTargetLanguages( $target_languages );
$translators_dropdowns = wpml_collect( $target_languages )->pluck( 'code', 'code' )
->map( [ $this, 'get_translators_dropdown' ] );
$tooltip_content = esc_html__( 'This deadline is what WPML suggests according to the amount of work that you already sent to this translator. You can modify this date to set the deadline manually.', 'wpml-translation-management' );
$translation_service_enabled = $this->is_translation_service_enabled();
$model = array(
'strings' => array(
'heading_basket_name' => __( '2. Set a batch name and deadline', 'wpml-translation-management' ),
'heading_translators' => __( '3. Choose translator or Translation Service', 'wpml-translation-management' ),
'batch_name_label' => __( 'Batch name:', 'wpml-translation-management' ),
'batch_name_desc' => __( 'Give a name to the batch. If omitted, the default name will be applied.', 'wpml-translation-management' ),
'column_language' => __( 'Language pair', 'wpml-translation-management' ),
'column_translator' => __( 'Translator', 'wpml-translation-management' ),
'pro_translation_tip' => __( 'Did you know that you can also set Translation Services and professional translators will handle your translation?', 'wpml-translation-management' ),
'batch_deadline_label' => __( 'Suggested deadline:', 'wpml-translation-management' ),
'batch_deadline_tooltip' => $tooltip_content,
'button_send_all' => __( 'Send all items for translation', 'wpml-translation-management' ),
),
'source_language' => $sitepress->get_language_details( $source_language ),
'source_language_flag' => $sitepress->get_flag_img( $source_language ),
'basket_name_max_length' => $basket_name_max_length,
'basket_name_placeholder' => $basket_name_placeholder,
'target_languages' => $target_languages,
'dropdowns_translators' => $translators_dropdowns,
'pro_translation_link' => '<br /><a href="' . admin_url( 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=translators' ) . '">'
. __( 'Check available Translation Services', 'wpml-translation-management' ) . '</a>',
'deadline_estimation_date' => $deadline_estimate_date,
'extra_basket_fields' => TranslationProxy_Basket::get_basket_extra_fields_section(),
'nonces' => array(
'_icl_nonce_send_basket_items' => wp_create_nonce( 'send_basket_items_nonce' ),
'_icl_nonce_send_basket_item' => wp_create_nonce( 'send_basket_item_nonce' ),
'_icl_nonce_send_basket_commit' => wp_create_nonce( 'send_basket_commit_nonce' ),
'_icl_nonce_check_basket_name' => wp_create_nonce( 'check_basket_name_nonce' ),
'_icl_nonce_refresh_deadline' => wp_create_nonce( 'wpml-tm-jobs-deadline-estimate-ajax-action' ),
'_icl_nonce_rollback_basket' => wp_create_nonce( 'rollback_basket_nonce' ),
),
'translation_service_enabled' => $translation_service_enabled,
'current_user_only_translator' => $isTheOnlyAvailableTranslator,
);
echo $this->template_service->show( $model, 'basket/options.twig' );
}
do_action( 'wpml_translation_basket_page_after' );
}
public function get_translators_dropdown( $lang_code ) {
$selected_translator = TranslationProxy_Service::get_wpml_translator_id();
$args = array(
'from' => TranslationProxy_Basket::get_source_language(),
'to' => $lang_code,
'name' => 'translator[' . $lang_code . ']',
'selected' => $selected_translator,
'services' => array( 'local', TranslationProxy::get_current_service_id() ),
'echo' => false,
);
return wpml_tm_get_translators_dropdown()->render( $args );
}
private function build_translation_jobs_item() {
$jobs_repository = wpml_tm_get_jobs_repository();
$jobs_count = $jobs_repository->get_count( new WPML_TM_Jobs_Search_Params() );
if ( $jobs_count ) {
$this->tab_items['jobs'] = [
'caption' => __( 'Jobs', 'wpml-translation-management' ),
'current_user_can' => [ User::CAP_ADMINISTRATOR, User::CAP_MANAGE_TRANSLATIONS ],
'callback' => [ $this, 'build_content_translation_jobs' ],
'order' => 100000,
'visible' => ! Option::shouldTranslateEverything(),
];
}
}
public function build_content_translation_jobs() {
echo "<div id='wpml-remote-jobs-container'></div>";
}
private function build_tp_com_log_item() {
if ( isset( $_GET['sm'] ) && 'com-log' === $_GET['sm'] ) {
$this->tab_items['com-log'] = array(
'caption' => __( 'Communication Log', 'wpml-translation-management' ),
'current_user_can' => 'manage_options',
'callback' => array( $this, 'build_tp_com_log' ),
'order' => 1000000,
);
}
}
public function build_tp_com_log() {
if ( isset( $_POST['tp-com-clear-log'] ) ) {
WPML_TranslationProxy_Com_Log::clear_log();
}
if ( isset( $_POST['tp-com-disable-log'] ) ) {
WPML_TranslationProxy_Com_Log::set_logging_state( false );
}
if ( isset( $_POST['tp-com-enable-log'] ) ) {
WPML_TranslationProxy_Com_Log::set_logging_state( true );
}
$action_url = esc_attr( 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=' . $_GET['sm'] );
$com_log = WPML_TranslationProxy_Com_Log::get_log();
?>
<form method="post" id="tp-com-log-form" name="tp-com-log-form" action="<?php echo $action_url; ?>">
<?php if ( WPML_TranslationProxy_Com_Log::is_logging_enabled() ) : ?>
<?php echo esc_html__( "This is a log of the communication between your site and the translation system. It doesn't include any private information and allows WPML support to help with problems related to sending content to translation.", 'wpml-translation-management' ); ?>
<br />
<br />
<?php if ( $com_log != '' ) : ?>
<textarea wrap="off" readonly="readonly" rows="16" style="font-size:10px; width:100%"><?php echo $com_log; ?></textarea>
<br />
<br />
<input class="button-secondary" type="submit" name="tp-com-clear-log" value="<?php echo esc_attr__( 'Clear log', 'wpml-translation-management' ); ?>">
<?php else : ?>
<strong><?php echo esc_html__( 'The communication log is empty.', 'wpml-translation-management' ); ?></strong>
<br />
<br />
<?php endif; ?>
<input class="button-secondary" type="submit" name="tp-com-disable-log" value="<?php echo esc_attr__( 'Disable logging', 'wpml-translation-management' ); ?>">
<?php else : ?>
<?php echo esc_html__( 'Communication logging is currently disabled. To allow WPML support to help you with issues related to sending content to translation, you need to enable the communication logging.', 'wpml-translation-management' ); ?>
<br />
<br />
<input class="button-secondary" type="submit" name="tp-com-enable-log" value="<?php echo esc_attr__( 'Enable logging', 'wpml-translation-management' ); ?>">
<?php endif; ?>
</form>
<?php
}
public function get_dashboard_documents() {
return $this->documents;
}
public function build_content_dashboard_filter() {
global $wpdb;
$dashboard_filter = new WPML_TM_Dashboard_Display_Filter(
$this->active_languages,
$this->source_language,
$this->translation_filter,
$this->post_types,
$this->post_statuses,
$this->translation_priorities->get_values(),
$wpdb
);
$dashboard_filter->display();
}
private function build_external_types() {
$this->post_types = apply_filters( 'wpml_get_translatable_types', $this->post_types );
foreach ( $this->post_types as $id => $type_info ) {
if ( isset( $type_info->prefix ) ) {
// this is an external type returned by wpml_get_translatable_types
$new_type = new stdClass();
$new_type->labels = new stdClass();
$new_type->labels->singular_name = isset( $type_info->labels->singular_name ) ? $type_info->labels->singular_name : $type_info->label;
$new_type->labels->name = isset( $type_info->labels->name ) ? $type_info->labels->name : $type_info->label;
$new_type->prefix = $type_info->prefix;
$new_type->external_type = 1;
$this->post_types[ $id ] = $new_type;
}
}
}
/**
* @param array $post_types
*
* @since 2.6.0
*
* @return array
*/
public function exclude_attachments( $post_types ) {
unset( $post_types['attachment'] );
return $post_types;
}
protected function get_page_slug() {
return WPML_Translation_Management::PAGE_SLUG_MANAGEMENT;
}
protected function get_default_tab() {
return 'dashboard';
}
/**
* @return bool|\TranslationProxy_Service|\WP_Error
*/
private function is_translation_service_enabled() {
$translation_service_enabled = TranslationProxy::get_current_service();
if ( is_wp_error( $translation_service_enabled ) ) {
$translation_service_enabled = false;
}
return $translation_service_enabled;
}
}