PluginProbe
Polylang / 0.6
Polylang v0.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 0.6, at include/list-table.php

170 lines 5.6 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_List_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;action=edit&amp;lang='.$item['term_id']));
24 $delete_link = wp_nonce_url('?page=mlang&amp;action=delete&amp;noheader=true&amp;lang=' . $item['term_id'], 'delete-lang');
25 $actions = array(
26 'edit' => '<a href="' . $edit_link . '">' . __('Edit','polylang') . '</a>',
27 'delete' => '<a href="' . $delete_link .'">' . __('Delete','polylang') .'</a>'
28 );
29
30 return $item['name'].$this->row_actions($actions);
31 }
32
33 function column_cb($item){
34 return sprintf(
35 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
36 /*$1%s*/ esc_attr($this->_args['singular']),
37 /*$2%s*/ esc_attr($item['term_id'])
38 );
39 }
40
41 function get_columns(){
42 $columns = array(
43 // FIXME checkboxes are useles for now
44 // 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
45 'name' => __('Full name', 'polylang'),
46 'description' => __('Locale', 'polylang'),
47 'slug' => __('Code', 'polylang'),
48 'term_group' => __('Order', 'polylang'),
49 'flag' => __('Flag', 'polylang'),
50 'count' => __('Posts', 'polylang')
51 );
52 return $columns;
53 }
54
55 function get_sortable_columns() {
56 $sortable_columns = array(
57 'name' => array('name',true), // sorted by name by default
58 'description' => array('description',false),
59 'slug' => array('slug',false),
60 'term_group' => array('term_group',false),
61 'count' => array('count',false)
62 );
63 return $sortable_columns;
64 }
65
66 /*
67 function get_bulk_actions() {
68 return array('delete' => 'Delete');
69 }
70 */
71
72 function prepare_items($data = array()) {
73 $per_page = 5; // 5 languages per page
74 $columns = $this->get_columns();
75 $hidden = array();
76 $sortable = $this->get_sortable_columns();
77
78 $this->_column_headers = array($columns, $hidden, $sortable);
79
80 function usort_reorder($a,$b){
81 $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; // if no sort, default to name
82 $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; // if no order, default to asc
83 $result = strcmp($a[$orderby], $b[$orderby]); // determine sort order
84 return ($order==='asc') ? $result : -$result; // send final sort direction to usort
85 }
86 usort($data, 'usort_reorder');
87
88 $current_page = $this->get_pagenum();
89 $total_items = count($data);
90 $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
91 $this->items = $data;
92
93 $this->set_pagination_args( array(
94 'total_items' => $total_items, //WE have to calculate the total number of items
95 'per_page' => $per_page, //WE have to determine how many items to show on a page
96 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
97 ) );
98 }
99 }
100
101 class Polylang_String_Table extends WP_List_Table {
102 function __construct() {
103 parent::__construct( array(
104 'singular' => __('Strings translation','polylang'),
105 'plural' => __('Strings translations','polylang'),
106 'ajax'=> false)
107 );
108 }
109
110 function column_default($item, $column_name){
111 return $item[$column_name];
112 }
113
114 function column_translations($item){
115 $out = sprintf('<input type="hidden" name="string[%1$s]" value="%2$s" />', esc_attr($item['row']), esc_html($item['string']));
116
117 foreach($item['translations'] as $key=>$translation)
118 $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label><input name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" /></div>',
119 esc_attr($key), esc_attr($item['row']), esc_html($key), esc_html($translation));
120
121 return $out;
122 }
123
124 function get_columns(){
125 return array(
126 'name' => __('Name', 'polylang'),
127 'string' => __('String', 'polylang'),
128 'translations' => __('Translations', 'polylang'),
129 );
130 }
131
132 function get_sortable_columns() {
133 return array(
134 'name' => array('name',false),
135 'string' => array('string',false),
136 );
137 }
138
139 function prepare_items($data = array()) {
140 $per_page = 10; // 10 strings per page
141 $columns = $this->get_columns();
142 $hidden = array();
143 $sortable = $this->get_sortable_columns();
144
145 $this->_column_headers = array($columns, $hidden, $sortable);
146
147 function usort_reorder($a,$b){
148 $orderby = $_REQUEST['orderby'];
149 $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; // if no order, default to asc
150 $result = strcmp($a[$orderby], $b[$orderby]); // determine sort order
151
152 return ($order==='asc') ? $result : -$result; // send final sort direction to usort
153 }
154 if (!empty($_REQUEST['orderby'])) // no sort by default
155 usort($data, 'usort_reorder');
156
157 $current_page = $this->get_pagenum();
158 $total_items = count($data);
159 $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
160 $this->items = $data;
161
162 $this->set_pagination_args( array(
163 'total_items' => $total_items,
164 'per_page' => $per_page,
165 'total_pages' => ceil($total_items/$per_page)
166 ) );
167 }
168 }
169 ?>
170