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

169 lines 5.5 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 = 10; // 10 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 = '';
116 foreach($item['translations'] as $key=>$translation)
117 $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>',
118 esc_attr($key), esc_attr($item['row']), esc_html($key), esc_html($translation));
119
120 return $out;
121 }
122
123 function get_columns(){
124 return array(
125 'name' => __('Name', 'polylang'),
126 'string' => __('String', 'polylang'),
127 'translations' => __('Translations', 'polylang'),
128 );
129 }
130
131 function get_sortable_columns() {
132 return array(
133 'name' => array('name',false),
134 'string' => array('string',false),
135 );
136 }
137
138 function prepare_items($data = array()) {
139 $per_page = 10; // 10 strings per page
140 $columns = $this->get_columns();
141 $hidden = array();
142 $sortable = $this->get_sortable_columns();
143
144 $this->_column_headers = array($columns, $hidden, $sortable);
145
146 function usort_reorder($a,$b){
147 $orderby = $_REQUEST['orderby'];
148 $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; // if no order, default to asc
149 $result = strcmp($a[$orderby], $b[$orderby]); // determine sort order
150
151 return ($order==='asc') ? $result : -$result; // send final sort direction to usort
152 }
153 if (!empty($_REQUEST['orderby'])) // no sort by default
154 usort($data, 'usort_reorder');
155
156 $current_page = $this->get_pagenum();
157 $total_items = count($data);
158 $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
159 $this->items = $data;
160
161 $this->set_pagination_args( array(
162 'total_items' => $total_items,
163 'per_page' => $per_page,
164 'total_pages' => ceil($total_items/$per_page)
165 ) );
166 }
167 }
168 ?>
169