PluginProbe
Bogo / 3.9.3
Bogo v3.9.3
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / admin / includes / terms-translation.php

terms-translation.php in Bogo 3.9.3, at admin/includes/terms-translation.php

230 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! class_exists( 'WP_List_Table' ) ) {
4 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5 }
6
7 class Bogo_Terms_Translation_List_Table extends WP_List_Table {
8 private $locale_to_edit = null;
9
10 public static function define_columns() {
11 $columns = array(
12 'original' => __( 'Original', 'bogo' ),
13 'translation' => __( 'Translation', 'bogo' ),
14 'context' => __( 'Context', 'bogo' ),
15 );
16
17 return $columns;
18 }
19
20 public function prepare_items() {
21 $this->locale_to_edit = trim( $_GET['locale'] ?? '' );
22
23 if ( ! bogo_is_available_locale( $this->locale_to_edit ) ) {
24 return;
25 }
26
27 $items = bogo_terms_translation( $this->locale_to_edit );
28
29 foreach ( $items as $key => $item ) {
30 $cap = isset( $item['cap'] )
31 ? $item['cap']
32 : 'bogo_edit_terms_translation';
33
34 if ( ! current_user_can( $cap ) ) {
35 unset( $items[$key] );
36 }
37 }
38
39 if ( ! empty( $_REQUEST['s'] ) ) {
40 $keywords = preg_split( '/[\s]+/', $_REQUEST['s'] );
41
42 foreach ( $items as $key => $item ) {
43 $haystack = $item['original'] . ' ' . $item['translated'];
44
45 foreach ( $keywords as $needle ) {
46 if ( false === stripos( $haystack, $needle ) ) {
47 unset( $items[$key] );
48 break;
49 }
50 }
51 }
52 }
53
54 $items = array_filter( $items );
55 $items = array_values( $items );
56
57 $per_page = $this->get_items_per_page( 'bogo_texts_per_page' );
58 $offset = ( $this->get_pagenum() - 1 ) * $per_page;
59
60 $this->items = array_slice( $items, $offset, $per_page );
61
62 $total_items = count( $items );
63 $total_pages = ceil( $total_items / $per_page );
64
65 $this->set_pagination_args( array(
66 'total_items' => $total_items,
67 'total_pages' => $total_pages,
68 'per_page' => $per_page,
69 ) );
70 }
71
72 public function get_columns() {
73 return get_column_headers( get_current_screen() );
74 }
75
76 public function column_original( $item ) {
77 return esc_html( $item['original'] );
78 }
79
80 public function column_translation( $item ) {
81 return sprintf(
82 '<input %1$s />',
83 bogo_format_atts( array(
84 'type' => 'text',
85 'name' => $item['name'],
86 'id' => $item['name'],
87 'value' => $item['translated'],
88 'class' => 'translation-text large-text',
89 ) )
90 );
91 }
92
93 public function column_context( $item ) {
94 return esc_html( $item['context'] );
95 }
96
97 protected function display_tablenav( $which ) {
98 echo sprintf( '<div class="tablenav %1$s">', esc_attr( $which ) );
99 $this->extra_tablenav( $which );
100 $this->pagination( $which );
101 echo '<br class="clear" />';
102 echo '</div>';
103 }
104
105 protected function extra_tablenav( $which ) {
106 if ( 'top' === $which ) {
107 $options = array(
108 sprintf(
109 '<option value="">%1$s</option>',
110 __( '-- Select Language to Edit --', 'bogo' )
111 )
112 );
113
114 $available_locales = bogo_available_locales( array(
115 'current_user_can_access' => true,
116 ) );
117
118 foreach ( $available_locales as $locale ) {
119 if ( bogo_is_default_locale( $locale ) ) {
120 continue;
121 }
122
123 $options[] = sprintf(
124 '<option %1$s>%2$s</option>',
125 bogo_format_atts( array(
126 'value' => $locale,
127 'selected' => $locale === $this->locale_to_edit,
128 ) ),
129 bogo_get_language( $locale )
130 );
131 }
132
133 echo '<div class="alignleft">';
134 echo '<select name="locale" id="select-locale">';
135
136 echo wp_kses( implode( $options ), 'bogo_form_inside' );
137
138 echo '</select>';
139 echo '</div>';
140 }
141
142 if ( 'bottom' === $which ) {
143 echo '<div class="alignleft">';
144 submit_button();
145 echo '</div>';
146 }
147 }
148 }
149
150
151 function bogo_terms_translation( $locale_to_edit ) {
152 static $items = array();
153 static $locale = null;
154
155 if (
156 ! empty( $items ) and
157 $locale === $locale_to_edit
158 ) {
159 return $items;
160 }
161
162 $locale = $locale_to_edit;
163
164 if ( ! Bogo_POMO::import( $locale ) ) {
165 Bogo_POMO::reset();
166 }
167
168 if ( ! bogo_is_available_locale( $locale ) ) {
169 return $items;
170 }
171
172 $blogname = get_option( 'blogname' );
173
174 if ( $blogname ) {
175 $items[] = array(
176 'name' => 'blogname',
177 'original' => $blogname,
178 'translated' => bogo_translate(
179 'blogname', 'blogname', $blogname
180 ),
181 'context' => __( 'Site Title', 'bogo' ),
182 'cap' => 'manage_options',
183 );
184 }
185
186 $blogdescription = get_option( 'blogdescription' );
187
188 if ( $blogdescription ) {
189 $items[] = array(
190 'name' => 'blogdescription',
191 'original' => $blogdescription,
192 'translated' => bogo_translate(
193 'blogdescription', 'blogdescription', $blogdescription
194 ),
195 'context' => __( 'Tagline', 'bogo' ),
196 'cap' => 'manage_options',
197 );
198 }
199
200 remove_filter( 'get_term', 'bogo_get_term_filter' );
201
202 foreach ( (array) get_taxonomies( array(), 'objects' ) as $taxonomy ) {
203 $tax_labels = get_taxonomy_labels( $taxonomy );
204 $terms = get_terms( array(
205 'taxonomy' => $taxonomy->name,
206 'orderby' => 'slug',
207 'hide_empty' => false,
208 ) );
209
210 foreach ( (array) $terms as $term ) {
211 $name = sprintf( '%s:%d', $taxonomy->name, $term->term_id );
212 $items[] = array(
213 'name' => $name,
214 'original' => $term->name,
215 'translated' => bogo_translate(
216 $name, $taxonomy->name, $term->name
217 ),
218 'context' => $tax_labels->name,
219 'cap' => $taxonomy->cap->edit_terms,
220 );
221 }
222 }
223
224 add_filter( 'get_term', 'bogo_get_term_filter', 10, 2 );
225
226 $items = apply_filters( 'bogo_terms_translation', $items, $locale );
227
228 return $items;
229 }
230