wpml-package-translation-html-packages.class.php
5.87 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
<?php
class WPML_Package_Translation_HTML_Packages {
var $load_priority = 101;
public function __construct() {
add_action( 'WPML_PT_HTML', array( $this, 'loaded' ), $this->load_priority );
}
public function loaded() {
$this->set_admin_hooks();
}
private function set_admin_hooks() {
if ( is_admin() ) {
add_action( 'wpml_pt_package_table_columns', array( $this, 'render_package_table_columns' ), 10, 1 );
add_action( 'wpml_pt_package_table_options', array( $this, 'package_translation_menu_options' ), 10, 1 );
add_action( 'wpml_pt_package_table_body', array( $this, 'package_translation_menu_body' ), 10, 1 );
add_action( 'wpml_pt_package_status', array( $this, 'render_string_package_status' ), 10, 3 );
}
}
public static function package_translation_menu() {
$packages = apply_filters( 'wpml_pt_all_packages', array() );
$package_kinds = array();
if ( $packages ) {
foreach ( $packages as $package ) {
$kind_slugs = array_keys( $package_kinds );
if ( ! in_array( $package->kind_slug, $kind_slugs ) ) {
$package_kinds[ $package->kind_slug ] = $package->kind;
}
}
}
$table_title = __( 'Package Management', 'wpml-string-translation' );
$package_kind_label = __( 'Display packages for this kind:', 'wpml-string-translation' );
$package_kind_options[- 1] = __( 'Display packages for this kind:', 'wpml-string-translation' );
foreach ( $package_kinds as $kind_slug => $kind ) {
$package_kind_options[ $kind_slug ] = $kind;
}
?>
<h2><?php echo $table_title; ?></h2>
<p>
<label for="package_kind_filter"><?php echo $package_kind_label; ?></label>
<select id="package_kind_filter">
<?php do_action( 'wpml_pt_package_table_options', $package_kind_options ); ?>
</select>
</p>
<table id="icl_package_translations" class="widefat" cellspacing="0">
<thead>
<?php do_action( 'wpml_pt_package_table_columns', 'thead' ); ?>
</thead>
<tfoot>
<?php do_action( 'wpml_pt_package_table_columns', 'tfoot' ); ?>
</tfoot>
<tbody>
<?php do_action( 'wpml_pt_package_table_body', $packages ); ?>
</tbody>
</table>
<br/>
<input id="delete_packages" type="button" class="button-primary" value="<?php echo __( 'Delete Selected Packages', 'wpml-string-translation' ); ?>" disabled="disabled"/>
<span class="spinner"></span>
<span style="display:none" class="js-delete-confirm-message"><?php echo __( "Are you sure you want to delete these packages?\nTheir strings and translations will be deleted too.", 'wpml-string-translation' ); ?></span>
<?php
wp_nonce_field( 'wpml_package_nonce', 'wpml_package_nonce' );
}
public function package_translation_menu_options( $package_kind_options ) {
foreach ( $package_kind_options as $option_value => $option_label ) {
?>
<option value="<?php echo esc_attr( $option_value ); ?>"><?php echo $option_label; ?></option>
<?php
}
}
/**
* @param array<\WPML_Package> $packages
*/
public function package_translation_menu_body( $packages ) {
if ( ! $packages ) {
$this->package_translation_menu_no_packages();
} else {
$this->package_translation_menu_items( $packages );
}
}
public function render_package_table_columns( $position ) {
?>
<tr>
<th scope="col" class="manage-column column-cb check-column">
<label for="select_all_package_<?php echo $position; ?>" style="display: none;">
<?php _e( 'Select All', 'wpml-string-translation' ); ?>
</label>
<input id="select_all_package_<?php echo $position; ?>" class="js_package_all_cb" type="checkbox"/>
</th>
<th scope="col"><?php echo __( 'Kind', 'wpml-string-translation' ); ?></th>
<th scope="col"><?php echo __( 'Name', 'wpml-string-translation' ); ?></th>
<th scope="col"><?php echo __( 'Info', 'wpml-string-translation' ); ?></th>
</tr>
<?php
}
public function render_string_package_status( $string_count, $translation_in_progress, $default_package_language ) {
$package_statuses[] = sprintf( __( 'Contains %s strings', 'wpml-string-translation' ), $string_count );
if ( $translation_in_progress ) {
$package_statuses[] = '(' . __( 'Translation is in progress', 'wpml-string-translation' ) . ')';
}
$package_statuses[] = __( 'Default package language', 'wpml-string-translation' ) . ': ' . $default_package_language;
echo implode( ' - ', $package_statuses );
}
private function package_translation_menu_no_packages() {
?>
<tr>
<td colspan="6" align="center">
<strong><?php echo __( 'No packages found', 'wpml-string-translation' ); ?></strong>
</td>
</tr>
<?php
}
/**
* @param array<\WPML_Package> $packages
*/
private function package_translation_menu_items( $packages ) {
global $wpdb, $sitepress;
foreach ( $packages as $package ) {
$package_language_code = $package->get_package_language();
$package_language = $sitepress->get_display_language_name( $package_language_code );
$tm = new WPML_Package_TM( $package );
$translation_in_progress = $tm->is_translation_in_progress();
$package_id = $package->ID;
$string_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}icl_strings WHERE string_package_id=%d", $package_id ) );
$disabled = disabled( $translation_in_progress, true, false );
?>
<tr id="row_<?php echo $package_id; ?>" class="js_package js_package_<?php echo esc_attr( $package->kind_slug ); ?>">
<td>
<input id="package_<?php echo $package_id; ?>" class="js_package_row_cb" type="checkbox" value="<?php echo $package_id; ?>" <?php echo $disabled; ?>/>
</td>
<td class="js-package-kind">
<?php echo $package->kind; ?>
</td>
<td>
<label for="package_<?php echo $package_id; ?>"><?php echo esc_html( $package->title ); ?></label>
</td>
<td>
<?php
do_action( 'wpml_pt_package_status', $string_count, $translation_in_progress, $package_language );
?>
</td>
</tr>
<?php
}
}
}