PluginProbe
Polylang / 1.0.1
Polylang v1.0.1
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.0.1, at include/list-table.php

145 lines 4.8 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;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 return $item['name'] . $this->row_actions($actions);
30 }
31
32 function get_columns() {
33 return array(
34 'name' => __('Full name', 'polylang'),
35 'description' => __('Locale', 'polylang'),
36 'slug' => __('Code', 'polylang'),
37 'term_group' => __('Order', 'polylang'),
38 'flag' => __('Flag', 'polylang'),
39 'count' => __('Posts', 'polylang')
40 );
41 }
42
43 function get_sortable_columns() {
44 return array(
45 'name' => array('name', true), // sorted by name by default
46 'description' => array('description', false),
47 'slug' => array('slug', false),
48 'term_group' => array('term_group', false),
49 'count' => array('count', false)
50 );
51 }
52
53 function prepare_items($data = array()) {
54 $per_page = $this->get_items_per_page('pll_lang_per_page');
55 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
56
57 function usort_reorder($a, $b){
58 $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name';
59 $result = strcmp($a[$orderby], $b[$orderby]); // determine sort order
60 return (empty($_REQUEST['order']) || $_REQUEST['order'] == 'asc') ? $result : -$result; // send final sort direction to usort
61 };
62
63 usort($data, 'usort_reorder');
64
65 $total_items = count($data);
66 $this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
67
68 $this->set_pagination_args(array(
69 'total_items' => $total_items,
70 'per_page' => $per_page,
71 'total_pages' => ceil($total_items/$per_page)
72 ));
73 }
74 } // class Polylang_Languages_Table
75
76 class Polylang_String_Table extends WP_List_Table {
77 function __construct() {
78 parent::__construct(array(
79 'singular' => __('Strings translation','polylang'),
80 'plural' => __('Strings translations','polylang'),
81 'ajax' => false
82 ));
83 }
84
85 function column_default($item, $column_name) {
86 return $item[$column_name];
87 }
88
89 function column_string($item) {
90 return format_to_edit($item['string']); // don't interpret special chars for the string column
91 }
92
93 function column_translations($item) {
94 $out = '';
95 foreach($item['translations'] as $key => $translation) {
96 $input_type = $item['multiline'] ?
97 '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' :
98 '<input name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />';
99 $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n",
100 esc_attr($key),
101 esc_attr($item['row']),
102 esc_html($key),
103 format_to_edit($translation)); // don't interpret special chars
104 }
105 return $out;
106 }
107
108 function get_columns() {
109 return array(
110 'name' => __('Name', 'polylang'),
111 'string' => __('String', 'polylang'),
112 'translations' => __('Translations', 'polylang'),
113 );
114 }
115
116 function get_sortable_columns() {
117 return array(
118 'name' => array('name', false),
119 'string' => array('string', false),
120 );
121 }
122
123 function prepare_items($data = array()) {
124 $per_page = $this->get_items_per_page('pll_strings_per_page');
125 $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
126
127 function usort_reorder($a, $b){
128 $result = strcmp($a[$_REQUEST['orderby']], $b[$_REQUEST['orderby']]); // determine sort order
129 return (empty($_REQUEST['order']) || $_REQUEST['order'] == 'asc') ? $result : -$result; // send final sort direction to usort
130 };
131
132 if (!empty($_REQUEST['orderby'])) // no sort by default
133 usort($data, 'usort_reorder');
134
135 $total_items = count($data);
136 $this->items = array_slice($data, ($this->get_pagenum() - 1) * $per_page, $per_page);
137
138 $this->set_pagination_args(array(
139 'total_items' => $total_items,
140 'per_page' => $per_page,
141 'total_pages' => ceil($total_items/$per_page)
142 ));
143 }
144 } // class Polylang_String_Table
145