PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.1.1
CloudSecure WP Security v1.1.1
1.4.10 1.4.9 trunk 0.9.0 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.19 1.3.2 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8
cloudsecure-wp-security / modules / admin / login-log-table.php
cloudsecure-wp-security / modules / admin Last commit date
captcha.php 2 years ago common.php 2 years ago dashboard.php 2 years ago disable-author-query.php 2 years ago disable-login.php 2 years ago disable-restapi.php 2 years ago disable-xmlrpc.php 2 years ago login-log-table.php 2 years ago login-log.php 2 years ago login-notification.php 2 years ago rename-login-page.php 2 years ago restrict-admin-page.php 2 years ago server-error-notification.php 2 years ago server-error-table.php 2 years ago two-factor-authentication-registration.php 2 years ago two-factor-authentication.php 2 years ago unify-messages.php 2 years ago update-notice.php 2 years ago
login-log-table.php
276 lines
1 <?php
2
3 if ( ! class_exists( 'WP_List_Table' ) ) {
4 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5 }
6
7 class CloudSecureWP_Login_Log_Table extends WP_List_Table {
8 private $login_log;
9 private $per_page = 50;
10 private $conditions = array();
11 private $allowed_html;
12
13 function __construct( CloudSecureWP_Login_Log $login_log ) {
14 parent::__construct(
15 array(
16 'ajax' => false,
17 )
18 );
19 $this->login_log = $login_log;
20 }
21
22 /**
23 * 条件設定
24 *
25 * @param $conditions
26 * @return void
27 */
28 public function set_condition( array $conditions ): void {
29 $this->conditions = $conditions;
30 }
31
32 /**
33 * 絞込み条件保存
34 *
35 * @return void
36 */
37 public function save_conditions(): void {
38 $this->login_log->save_conditions( $this->conditions );
39 }
40
41 protected function pagination( $which ) {
42 if ( 'top' === $which ) {
43 return;
44 }
45 parent::pagination( 'top' );
46 }
47
48 protected function get_table_classes() {
49 $classes = parent::get_table_classes();
50 $classes[] = 'custom-table-class';
51 return $classes;
52 }
53
54 /**
55 * 条件取得
56 *
57 * @return array
58 */
59 public function get_conditions(): array {
60 $this->conditions = $this->login_log->get_conditions();
61 return $this->conditions;
62 }
63
64 function column_default( $item, $column ) {
65 $login_status_datas = $this->login_log->get_login_status_datas();
66 $methods = $this->login_log->get_methods();
67
68 switch ( $column ) {
69 case 'status':
70 return $login_status_datas[ $item[ $column ] ];
71 case 'method':
72 return $methods[ $item[ $column ] ];
73 case 'id':
74 case 'name':
75 case 'ip':
76 case 'login_at':
77 return $item[ $column ];
78 default:
79 return '';
80 }
81 }
82
83 function get_columns() {
84 $column_datas = $this->login_log->get_cloumns();
85
86 return array(
87 'login_at' => $column_datas['login_at'],
88 'status' => $column_datas['status'],
89 'ip' => $column_datas['ip'],
90 'method' => $column_datas['method'],
91 'name' => $column_datas['name'],
92 'id' => $column_datas['id'],
93 );
94 }
95
96 function get_hidden_columns() {
97 return array(
98 'id',
99 );
100 }
101
102 function get_sortable_columns() {
103 return array(
104 'login_at' => array( 'login_at', false ),
105 'status' => array( 'status', false ),
106 'ip' => array( 'ip', false ),
107 'method' => array( 'method', false ),
108 'name' => array( 'name', false ),
109 'id' => array( 'id', false ),
110 );
111 }
112
113 function usort_reorder( $a, $b ) {
114 $cloumns = $this->login_log->get_cloumns();
115 $orderby = 'login_at';
116
117 if ( array_key_exists( sanitize_text_field( $_GET['orderby'] ?? '' ), $cloumns ) ) {
118 $orderby = sanitize_text_field( $_GET['orderby'] );
119 }
120
121 $order = sanitize_text_field( $_GET['order'] ?? 'desc' );
122 if ( 'desc' !== $order ) {
123 $order = 'asc';
124 }
125
126 switch ( $orderby ) {
127 case 'id':
128 case 'status':
129 case 'method':
130 $result = ( (int) $a[ $orderby ] > (int) $b[ $orderby ] ? 1 : ( (int) $a[ $orderby ] < (int) $b[ $orderby ] ? -1 : 0 ) );
131 break;
132 case 'ip':
133 $a_ip = (int) sprintf( '%u', ip2long( $a[ $orderby ] ) );
134 $b_ip = (int) sprintf( '%u', ip2long( $b[ $orderby ] ) );
135 $result = ( $a_ip > $b_ip ? 1 : ( $a_ip < $b_ip ? -1 : 0 ) );
136 break;
137 default:
138 $result = strcmp( $a[ $orderby ], $b[ $orderby ] );
139 }
140
141 return ( $order === 'asc' ) ? $result : -$result;
142 }
143
144 function prepare_items() {
145 $columns = $this->get_columns();
146 $hidden = $this->get_hidden_columns();
147 $sortable = $this->get_sortable_columns();
148
149 $this->_column_headers = array( $columns, $hidden, $sortable );
150 $conditions = $this->get_conditions();
151
152 $login_log_rows = $this->login_log->get_login_history( $conditions );
153 $login_log_rows_count = count( $login_log_rows );
154
155 $current_page = $this->get_pagenum();
156 $max_page = (int) ceil( $login_log_rows_count / $this->per_page );
157
158 if ( $max_page < $current_page ) {
159 $current_page = $max_page;
160 }
161
162 $view_rows = array();
163 if ( 0 < $login_log_rows_count ) {
164 usort( $login_log_rows, array( &$this, 'usort_reorder' ) );
165 $view_rows = array_slice( $login_log_rows, ( ( $current_page - 1 ) * $this->per_page ), $this->per_page );
166 }
167 $this->items = $view_rows;
168
169 $this->set_pagination_args(
170 array(
171 'total_items' => $login_log_rows_count,
172 'per_page' => $this->per_page,
173 'total_pages' => ceil( $login_log_rows_count / $this->per_page ),
174 )
175 );
176 }
177
178 function extra_tablenav( $witch ) {
179 if ( 'top' === $witch ) {
180 $this->condition_view();
181 }
182 }
183
184
185 /**
186 * option 作成
187 *
188 * @param array $datas
189 * @param string $condition
190 * @return string
191 */
192 public function make_option( array $datas, string $condition ): string {
193 $options = '';
194 foreach ( $datas as $key => $val ) {
195
196 $selected = '';
197 if ( (string) $condition === (string) $key ) {
198 $selected = ' selected';
199 }
200 $options .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
201 }
202 return $options . "\n";
203 }
204
205 /**
206 * 絞込み条件
207 */
208 public function condition_view(): void {
209 $this->allowed_html = array(
210 'option' => array(
211 'value' => array(),
212 'selected' => array(),
213 ),
214 );
215
216 $login_status_datas = $this->login_log->get_login_status_datas();
217 $condition_status = $this->conditions['condition_status'] ?? '';
218 $status_options = $this->make_option( $login_status_datas, $condition_status );
219
220 $login_method_datas = $this->login_log->get_methods();
221 $condition_method = $this->conditions['condition_method'] ?? '';
222 $method_options = $this->make_option( $login_method_datas, $condition_method );
223
224 $condition_ip_other_than_t = '';
225 $condition_name_other_than_t = '';
226
227 $condition_ip = $this->conditions['condition_ip'] ?? '';
228 if ( '' !== $condition_ip ) {
229 $condition_ip_other_than = $this->conditions['condition_ip_other_than'] ?? '';
230 $condition_ip_other_than_t = $condition_ip_other_than === 't' ? 'checked' : '';
231 }
232
233 $condition_name = $this->conditions['condition_name'] ?? '';
234 if ( '' !== $condition_name ) {
235 $condition_name_other_than = $this->conditions['condition_name_other_than'] ?? '';
236 $condition_name_other_than_t = $condition_name_other_than === 't' ? 'checked' : '';
237 }
238 ?>
239 <div class="alignleft bulkactions login-log">
240 <div class="login-log-rows">
241 <div class="login-log-row">
242 <span>ログイン判定</span>
243 <select name="condition_status">
244 <option value="">--</option>
245 <?php echo wp_kses( $status_options, $this->allowed_html ); ?>
246 </select>
247 <div class="login-log-row-right">
248 <span>IPアドレス</span>
249 <input type="text" class="mr-12" name="condition_ip" placeholder="例)192.0.2.1" value="<?php echo esc_attr( $condition_ip ); ?>" maxlength="39"><br>
250 <input class="checkbox" id="condition_ip" type="checkbox" name="condition_ip_other_than" value="t" <?php echo esc_html( $condition_ip_other_than_t ); ?>><label for="condition_ip">を除く</label>
251 </div>
252 </div>
253 <div class="login-log-row">
254 <span>ログイン種別</span>
255 <select name="condition_method">
256 <option value="">--</option>
257 <?php echo wp_kses( $method_options, $this->allowed_html ); ?>
258 </select>
259 <div class="login-log-row-right">
260 <span>ユーザー名</span>
261 <input type="text" class="mr-12" name="condition_name" placeholder="例)user_name" value="<?php echo esc_attr( $condition_name ); ?>" maxlength="60"><br>
262 <input class="checkbox" id="condition_name" type="checkbox" name="condition_name_other_than" value="t" <?php echo esc_html( $condition_name_other_than_t ); ?>><label for="condition_name">を除く</label>
263 </div>
264 </div>
265 </div>
266 <div class="login-log-btns">
267 <?php wp_nonce_field( $this->login_log->get_feature_key() . '_csrf' ); ?>
268 <input type="submit" class="login-log-reset-btn" name="reset" value="クリア">
269 <input type="submit" class="login-log-done-btn" name="done" value="絞り込み">
270 </div>
271 </div>
272
273 <?php
274 }
275 }
276