PluginProbe
Polylang / 1.7.3
Polylang v1.7.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / admin / table-string.php

table-string.php in Polylang 1.7.3, at admin/table-string.php

204 lines 5.1 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' ); // since WP 3.1
5 }
6
7 /*
8 * a class to create the strings translations table
9 * Thanks to Matt Van Andel (http://www.mattvanandel.com) for its plugin "Custom List Table Example" !
10 *
11 * @since 0.6
12 */
13 class PLL_Table_String extends WP_List_Table {
14 protected $languages, $groups, $group_selected;
15
16 /*
17 * constructor
18 *
19 * @since 0.6
20 *
21 * @param array $groups
22 * @param string $group_selected
23 */
24 function __construct($args) {
25 parent::__construct(array(
26 'plural' => 'Strings translations', // do not translate (used for css class)
27 'ajax' => false
28 ));
29
30 $this->languages = $args['languages'];
31 $this->groups = $args['groups'];
32 $this->group_selected = $args['selected'];
33 }
34
35 /*
36 * displays the item information in a column (default case)
37 *
38 * @since 0.6
39 *
40 * @param array $item
41 * @param string $column_name
42 * @return string
43 */
44 function column_default($item, $column_name) {
45 return $item[$column_name];
46 }
47
48 /*
49 * displays the checkbox in first column
50 *
51 * @since 1.1
52 *
53 * @param array $item
54 * @return string
55 */
56 function column_cb($item){
57 return sprintf(
58 '<input type="checkbox" name="strings[]" value="%s" %s />',
59 esc_attr($item['row']),
60 empty($item['icl']) ? 'disabled' : '' // only strings registered with WPML API can be removed
61 );
62 }
63
64 /*
65 * displays the string to translate
66 *
67 * @since 1.0
68 *
69 * @param array $item
70 * @return string
71 */
72 function column_string($item) {
73 return format_to_edit($item['string']); // don't interpret special chars for the string column
74 }
75
76 /*
77 * displays the translations to edit
78 *
79 * @since 0.6
80 *
81 * @param array $item
82 * @return string
83 */
84 function column_translations($item) {
85 $out = '';
86 foreach($item['translations'] as $key => $translation) {
87 $input_type = $item['multiline'] ?
88 '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' :
89 '<input type="text" name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />';
90 $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n",
91 esc_attr($key),
92 esc_attr($item['row']),
93 esc_html($this->languages[$key]),
94 format_to_edit($translation)); // don't interpret special chars
95 }
96 return $out;
97 }
98
99 /*
100 * gets the list of columns
101 *
102 * @since 0.6
103 *
104 * @return array the list of column titles
105 */
106 function get_columns() {
107 return array(
108 'cb' => '<input type="checkbox" />', //checkbox
109 'context' => __('Group', 'polylang'),
110 'name' => __('Name', 'polylang'),
111 'string' => __('String', 'polylang'),
112 'translations' => __('Translations', 'polylang'),
113 );
114 }
115
116 /*
117 * gets the list of sortable columns
118 *
119 * @since 0.6
120 *
121 * @return array
122 */
123 function get_sortable_columns() {
124 return array(
125 'context' => array('context', false),
126 'name' => array('name', false),
127 'string' => array('string', false),
128 );
129 }
130
131 /*
132 * prepares the list of items ofr displaying
133 *
134 * @since 0.6
135 *
136 * @param array $data
137 */
138 function prepare_items($data = array()) {
139 $per_page = $this->get_items_per_page('pll_strings_per_page');
140 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
141
142 function usort_reorder($a, $b){
143 $result = strcmp($a[$_REQUEST['orderby']], $b[$_REQUEST['orderby']]); // determine sort order
144 return (empty($_REQUEST['order']) || $_REQUEST['order'] == 'asc') ? $result : -$result; // send final sort direction to usort
145 };
146
147 if (!empty($_REQUEST['orderby'])) // no sort by default
148 usort($data, 'usort_reorder');
149
150 $total_items = count($data);
151 $this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
152
153 $this->set_pagination_args(array(
154 'total_items' => $total_items,
155 'per_page' => $per_page,
156 'total_pages' => ceil($total_items/$per_page)
157 ));
158 }
159
160 /*
161 * get the list of possible bulk actions
162 *
163 * @since 1.1
164 *
165 * @return array
166 */
167 function get_bulk_actions() {
168 return array('delete' => __('Delete','polylang'));
169 }
170
171 /*
172 * displays the dropdown list to filter strings per group
173 *
174 * @since 1.1
175 *
176 * @param string $which only 'top' is supported
177 */
178 function extra_tablenav($which) {
179 if ('top' != $which)
180 return;
181
182 echo '<div class="alignleft actions">';
183 echo '<select name="group">' . "\n";
184 printf(
185 '<option value="-1"%s>%s</option>' . "\n",
186 $this->group_selected == -1 ? ' selected="selected"' : '',
187 __('View all groups', 'polylang')
188 );
189
190 foreach ($this->groups as $group) {
191 printf(
192 '<option value="%s"%s>%s</option>' . "\n",
193 esc_attr(urlencode($group)),
194 $this->group_selected == $group ? ' selected="selected"' : '',
195 esc_html($group)
196 );
197 }
198 echo '</select>'."\n";
199
200 submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
201 echo '</div>';
202 }
203 }
204