PluginProbe
Polylang / 1.1.6
Polylang v1.1.6
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 / include / list-table.php

list-table.php in Polylang 1.1.6, at include/list-table.php

191 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Thanks to Matt Van Andel (http://www.mattvanandel.com) for its plugin "Custom List Table Example" !
4
5 if(!class_exists('WP_List_Table')){
6 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); // since WP 3.1
7 }
8
9 class Polylang_Languages_Table extends WP_List_Table {
10 function __construct() {
11 parent::__construct(array(
12 'singular' => __('Language','polylang'),
13 'plural' => __('Languages','polylang'),
14 'ajax' => false
15 ));
16 }
17
18 function column_default($item, $column_name) {
19 return $item[$column_name];
20 }
21
22 function column_name($item) {
23 $edit_link = esc_url(admin_url('admin.php?page=mlang&amp;pll_action=edit&amp;lang=' . $item['term_id']));
24 $delete_link = wp_nonce_url('?page=mlang&amp;pll_action=delete&amp;noheader=true&amp;lang=' . $item['term_id'], 'delete-lang');
25 return $item['name'] . $this->row_actions(array(
26 'edit' => sprintf('<a href="%s">%s</a>', $edit_link, __('Edit','polylang')),
27 'delete' => sprintf('<a href="%s">%s</a>', $delete_link, __('Delete','polylang'))
28 ));
29 }
30
31 function get_columns() {
32 return array(
33 'name' => __('Full name', 'polylang'),
34 'description' => __('Locale', 'polylang'),
35 'slug' => __('Code', 'polylang'),
36 'term_group' => __('Order', 'polylang'),
37 'flag' => __('Flag', 'polylang'),
38 'count' => __('Posts', 'polylang')
39 );
40 }
41
42 function get_sortable_columns() {
43 return array(
44 'name' => array('name', true), // sorted by name by default
45 'description' => array('description', false),
46 'slug' => array('slug', false),
47 'term_group' => array('term_group', false),
48 'count' => array('count', false)
49 );
50 }
51
52 function prepare_items($data = array()) {
53 $per_page = $this->get_items_per_page('pll_lang_per_page');
54 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
55
56 function usort_reorder($a, $b){
57 $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name';
58 $result = strcmp($a[$orderby], $b[$orderby]); // determine sort order
59 return (empty($_REQUEST['order']) || $_REQUEST['order'] == 'asc') ? $result : -$result; // send final sort direction to usort
60 };
61
62 usort($data, 'usort_reorder');
63
64 $total_items = count($data);
65 $this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
66
67 $this->set_pagination_args(array(
68 'total_items' => $total_items,
69 'per_page' => $per_page,
70 'total_pages' => ceil($total_items/$per_page)
71 ));
72 }
73 } // class Polylang_Languages_Table
74
75 class Polylang_String_Table extends WP_List_Table {
76 private $groups;
77
78 function __construct($groups = array(), $group_selected) {
79 parent::__construct(array(
80 'singular' => __('Strings translation','polylang'),
81 'plural' => __('Strings translations','polylang'),
82 'ajax' => false
83 ));
84
85 $this->groups = &$groups;
86 $this->group_selected = $group_selected;
87 }
88
89 function column_default($item, $column_name) {
90 return $item[$column_name];
91 }
92
93 function column_cb($item){
94 return sprintf(
95 '<input type="checkbox" name="strings[]" value="%s" %s />',
96 esc_attr($item['row']),
97 empty($item['icl']) ? 'disabled' : ''
98 );
99 }
100
101 function column_string($item) {
102 return format_to_edit($item['string']); // don't interpret special chars for the string column
103 }
104
105 function column_translations($item) {
106 $out = '';
107 foreach($item['translations'] as $key => $translation) {
108 $input_type = $item['multiline'] ?
109 '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' :
110 '<input name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />';
111 $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n",
112 esc_attr($key),
113 esc_attr($item['row']),
114 esc_html($key),
115 format_to_edit($translation)); // don't interpret special chars
116 }
117 return $out;
118 }
119
120 function get_columns() {
121 return array(
122 'cb' => '<input type="checkbox" />', //checkbox
123 'context' => __('Group', 'polylang'),
124 'name' => __('Name', 'polylang'),
125 'string' => __('String', 'polylang'),
126 'translations' => __('Translations', 'polylang'),
127 );
128 }
129
130 function get_sortable_columns() {
131 return array(
132 'context' => array('context', false),
133 'name' => array('name', false),
134 'string' => array('string', false),
135 );
136 }
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 function get_bulk_actions() {
161 return array('delete' => __('Delete','polylang'));
162 }
163
164 function extra_tablenav($which) {
165 echo '<div class="alignleft actions">';
166
167 if ('top' == $which) {
168 echo '<select name="group">'."\n";
169 printf(
170 '<option value="-1"%s>%s</option>'."\n",
171 $this->group_selected == -1 ? ' selected="selected"' : '',
172 __('View all groups', 'polylang')
173 );
174
175 foreach ($this->groups as $group) {
176 printf(
177 '<option value="%s"%s>%s</option>'."\n",
178 esc_attr($group),
179 $this->group_selected == $group ? ' selected="selected"' : '',
180 esc_html($group)
181 );
182 }
183 echo '</select>'."\n";
184
185 submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
186 }
187
188 echo '</div>';
189 }
190 } // class Polylang_String_Table
191