PluginProbe
Redirection / 2.3.13
Redirection v2.3.13
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / models / pager.php

pager.php in Redirection 2.3.13, at models/pager.php

727 lines 22.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( !class_exists( 'WP_List_Table' ) )
4 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
6 class Redirection_Table extends WP_List_Table {
7 private $groups;
8 private $total_items;
9
10 function __construct( array $groups, Red_Group $current_group = null ) {
11 $this->groups = $groups;
12 $this->current_group = $current_group;
13
14 //Set parent defaults
15 parent::__construct( array(
16 'singular' => 'item', //singular name of the listed records
17 'plural' => 'items', //plural name of the listed records
18 'ajax' => false //does this table support ajax?
19 ) );
20 }
21
22 function get_columns(){
23 $columns = array(
24 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
25 'type' => __( 'Type', 'redirection' ),
26 'url' => __( 'URL', 'redirection' ),
27 'hits' => __( 'Hits', 'redirection' ),
28 'last_access' => __( 'Last Access', 'redirection' ),
29 );
30
31 return $columns;
32 }
33
34 function column_type( $item ) {
35 return esc_html( $item->type() );
36 }
37
38 function column_last_access( $item ) {
39 if ( $item->last_access == 0 )
40 return '&mdash;';
41 return date_i18n( get_option( 'date_format' ), $item->last_access );
42 }
43
44 function column_hits( $item ) {
45 return esc_html( number_format_i18n( $item->last_count, 0 ) );
46 }
47
48 function column_url( $item ) {
49 $actions = array(
50 'edit' => sprintf( '<a class="red-ajax" data-action="%s" data-nonce="%s" data-id="%s" href="#">'.__( 'Edit', 'redirection' ).'</a>', 'red_redirect_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
51 'delete' => sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Delete', 'redirection' ).'</a>', 'delete', $item->get_id() ),
52 );
53
54 $before = $after = '';
55 if ( $item->is_enabled() )
56 $actions['disable'] = sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Disable', 'redirection' ).'</a>', 'disable', $item->get_id() );
57 else {
58 $actions['enable'] = sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Enable', 'redirection' ).'</a>', 'enable', $item->get_id() );
59 $before = '<span class="red-disabled">';
60 $after = '</span>';
61 }
62
63 $title = $item->url;
64 if ( $item->title )
65 $title = $item->title;
66
67 return sprintf( '%1$s %2$s', $before.'<a href="'.esc_url( $item->url ).'">'.esc_html( $title ).'</a>'.$after, $this->row_actions( $actions ) );
68 }
69
70 function column_cb($item){
71 return sprintf(
72 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
73 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
74 /*$2%s*/ $item->id //The value of the checkbox should be the record's id
75 );
76 }
77
78 function get_row( $item ) {
79 ob_start();
80
81 $this->single_row( $item );
82 $output = ob_get_contents();
83
84 ob_end_clean();
85
86 return $output;
87 }
88
89 function get_sortable_columns() {
90 $sortable_columns = array(
91 'url' => array( 'url', false),
92 );
93 return $sortable_columns;
94 }
95
96 function get_bulk_actions() {
97 $actions = array(
98 'delete' => __( 'Delete', 'redirection' ),
99 'enable' => __( 'Enable', 'redirection' ),
100 'disable' => __( 'Disable', 'redirection' ),
101 'reset' => __( 'Reset Hits', 'redirection' ),
102 );
103
104 return $actions;
105 }
106
107 function process_bulk_action() {
108 if ( !isset( $_POST['item'] ) )
109 return;
110
111 if ( in_array( $this->current_action(), array( 'reset', 'enable', 'disable', 'delete' ) ) ) {
112 $redirections = array();
113
114 foreach( (array)$_POST['item'] AS $id ) {
115 $redirect = Red_Item::get_by_id( intval( $id ) );
116 if ( $redirect )
117 $redirections[] = $redirect;
118 }
119
120 array_map( array( &$this, 'process_action_items' ), $redirections );
121
122 Red_Module::flush( $this->current_group->module_id );
123 }
124 }
125
126 function process_action_items( $item ) {
127 if ( $this->current_action() == 'reset' )
128 $item->reset();
129 elseif ( $this->current_action() == 'enable' )
130 $item->enable();
131 elseif ( $this->current_action() == 'disable' )
132 $item->disable();
133 elseif ( $this->current_action() == 'delete' )
134 $item->delete();
135 }
136
137 function extra_tablenav( $which ) {
138 if ( $which == 'bottom' )
139 return;
140
141 ?>
142 <div class="alignleft actions">
143 <select name="id">
144 <?php foreach ( $this->groups AS $module_name => $groups ) : ?>
145 <optgroup label="<?php echo esc_attr( $module_name ); ?>">
146 <?php foreach ( $groups AS $group_name => $group ) : ?>
147 <option value="<?php echo esc_attr( $group_name ); ?>"<?php selected( $group_name, $this->current_group->get_id() ); ?>>
148 <?php echo esc_html( $group ); ?>
149 </option>
150 <?php endforeach; ?>
151 </optgroup>
152 <?php endforeach; ?>
153 </select>
154
155 <?php submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) ); ?>
156 </div>
157 <?php
158 }
159
160 function prepare_items( $type = '', $id = 0 ) {
161 global $wpdb, $current_user;
162
163 $screen = get_current_screen();
164
165 $per_page = 25;
166 if ( $screen && $screen->get_option( 'per_page', 'option' ) ) {
167 $per_page = intval( get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true ) );
168 if ( $per_page === 0 )
169 $per_page = 25;
170 }
171
172 $columns = $this->get_columns();
173 $sortable = $this->get_sortable_columns();
174
175 $this->_column_headers = array( $columns, array(), $sortable );
176
177 // Process any stuff
178 $this->process_bulk_action();
179
180 $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
181 $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
182
183 if ( !in_array( $orderby, array_keys( $sortable ) ) )
184 $orderby = 'id';
185
186 if ( !in_array( $order, array( 'asc', 'desc' ) ) )
187 $order = 'desc';
188
189 $where = array();
190 if ( isset( $_GET['s'] ) )
191 $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
192
193 if ( isset( $_REQUEST['id'] ) )
194 $where[] = $wpdb->prepare( "group_id=%d", intval( $_REQUEST['id'] ) );
195
196 $where_cond = "";
197 if ( count( $where ) > 0 )
198 $where_cond = " WHERE ".implode( ' AND ', $where );
199
200 $table = $wpdb->prefix.'redirection_items';
201 $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
202 $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
203
204 $this->items = array();
205 foreach ( (array)$rows AS $row ) {
206 $this->items[] = new Red_Item( $row );
207 }
208
209 $this->set_pagination_args( array(
210 'total_items' => $this->total_items,
211 'per_page' => $per_page,
212 'total_pages' => ceil( $this->total_items / $per_page )
213 ) );
214 }
215 }
216
217 class Redirection_Group_Table extends WP_List_Table {
218 private $modules;
219 private $current_module;
220
221 function __construct( $modules, $current_module ) {
222 $this->modules = $modules;
223 $this->current_module = $current_module;
224
225 //Set parent defaults
226 parent::__construct( array(
227 'singular' => 'item', //singular name of the listed records
228 'plural' => 'items', //plural name of the listed records
229 'ajax' => false //does this table support ajax?
230 ) );
231 }
232
233 function get_columns(){
234 $columns = array(
235 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
236 'name' => __( 'Name', 'redirection' ),
237 'redirects' => __( 'Redirects', 'redirection' ),
238 );
239
240 return $columns;
241 }
242
243 function column_name( $item ) {
244 $actions = array(
245 'edit' => sprintf( '<a class="red-ajax" data-action="%s" data-nonce="%s" data-id="%s" href="#">'.__( 'Edit', 'redirection' ).'</a>', 'red_group_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
246 'delete' => sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Delete', 'redirection' ).'</a>', 'delete', $item->get_id() ),
247 'view' => '<a href="tools.php?page=redirection.php&amp;id='.$item->get_id().'">'.__( 'View Redirects', 'redirection' ).'</a>',
248 );
249
250 $after = $before = '';
251 if ( $item->is_disabled() ) {
252 $before = '<span class="red-disabled">';
253 $after = '</span>';
254 }
255
256 return sprintf( '%1$s %2$s', $before.esc_html( $item->get_name() ).$after, $this->row_actions( $actions ) );
257 }
258
259 function column_redirects( $item ) {
260 return esc_html( $item->get_item_count() );
261 }
262
263 function column_cb($item){
264 return sprintf(
265 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
266 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
267 /*$2%s*/ $item->id //The value of the checkbox should be the record's id
268 );
269 }
270
271 function get_sortable_columns() {
272 $sortable_columns = array(
273 'name' => array( 'name', false ),
274 );
275
276 return $sortable_columns;
277 }
278
279 function get_bulk_actions() {
280 $actions = array(
281 'delete' => __( 'Delete', 'redirection' ),
282 );
283
284 return $actions;
285 }
286
287 function process_bulk_action() {
288 if ( !isset( $_POST['item'] ) )
289 return;
290
291 if ( in_array( $this->current_action(), array( 'delete' ) ) ) {
292 $groups = array();
293
294 foreach( (array)$_POST['item'] AS $id ) {
295 $redirect = Red_Group::get( intval( $id ) );
296 if ( $redirect )
297 $groups[] = $redirect;
298 }
299
300 array_map( array( &$this, 'delete_item' ), $groups );
301 }
302 }
303
304 function delete_item( $item ) {
305 $item->delete();
306 }
307
308 function extra_tablenav( $which ) {
309 if ( $which == 'bottom' )
310 return;
311
312 ?>
313 <div class="alignleft actions">
314 <select name="id">
315 <?php foreach ( $this->modules AS $module_name => $module ) : ?>
316 <option value="<?php echo esc_attr( $module_name ); ?>"<?php selected( $module_name, $this->current_module ); ?>>
317 <?php echo esc_html( $module ); ?>
318 </option>
319 <?php endforeach; ?>
320 </select>
321
322 <?php submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) ); ?>
323 </div>
324 <?php
325 }
326
327 function prepare_items( $type = '', $id = 0 ) {
328 global $wpdb, $current_user;
329
330 $screen = get_current_screen();
331 $per_page = get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true );
332
333 $per_page = $per_page ? $per_page : 25;
334 $columns = $this->get_columns();
335 $sortable = $this->get_sortable_columns();
336
337 $this->_column_headers = array( $columns, array(), $sortable );
338
339 // Process any stuff
340 $this->process_bulk_action();
341
342 $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
343 $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
344
345 if ( !in_array( $orderby, array_keys( $sortable ) ) )
346 $orderby = $wpdb->prefix.'redirection_groups.name';
347
348 if ( !in_array( $order, array( 'asc', 'desc' ) ) )
349 $order = 'desc';
350
351 $where = array();
352 if ( isset( $_GET['s'] ) )
353 $where[] = $wpdb->prepare( 'name LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
354
355 if ( isset( $_REQUEST['id'] ) )
356 $where[] = $wpdb->prepare( "module_id=%d", intval( $_REQUEST['id'] ) );
357
358 $where_cond = "";
359 if ( count( $where ) > 0 )
360 $where_cond = " WHERE ".implode( ' AND ', $where );
361
362 $table = $wpdb->prefix.'redirection_groups';
363 $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
364 $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
365
366 $this->items = array();
367 foreach ( (array)$rows AS $row ) {
368 $this->items[] = new Red_Group( $row );
369 }
370
371 $this->set_pagination_args( array(
372 'total_items' => $this->total_items,
373 'per_page' => $per_page,
374 'total_pages' => ceil( $this->total_items / $per_page )
375 ) );
376 }
377 }
378
379 class Redirection_Log_Table extends WP_List_Table {
380 const REFERRER_MAX = 120;
381 const TARGET_MAX = 80;
382 private $lookup;
383
384 function __construct( $options ) {
385 $this->lookup = $options['lookup'];
386
387 //Set parent defaults
388 parent::__construct( array(
389 'singular' => 'item', //singular name of the listed records
390 'plural' => 'items', //plural name of the listed records
391 'ajax' => false //does this table support ajax?
392 ) );
393 }
394
395 function column_created( $item ) {
396 $actions = array();
397
398 if ( $item->sent_to == '' ) {
399 $actions['add'] = '<a href="'.esc_url( $item->url ).'" class="add-log">'.__( 'Add redirect', 'redirection' ).'</a>';
400 }
401
402 return sprintf( '%1$s %2$s', date_i18n( get_option( 'date_format' ), $item->created ).' '.gmdate( get_option( 'time_format' ), $item->created ), $this->row_actions( $actions ) );
403 }
404
405 function column_ip( $item ) {
406 return '<a href="'.esc_attr( $this->lookup ).esc_attr( $item->ip ).'">'.esc_html( $item->ip ).'</a>';
407 }
408
409 function column_url( $item ) {
410 $actions = array(
411 'target' => esc_html( substr( $item->sent_to, 0, self::TARGET_MAX ) ),
412 );
413
414 return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->url ).'">'.esc_html( $item->show_url( $item->url ) ).'</a>', $this->row_actions( $actions ) );
415 }
416
417 function column_referrer( $item ) {
418 $actions = array(
419 'agent' => esc_html( substr( $item->agent, 0, self::REFERRER_MAX ) ),
420 );
421
422 return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
423 }
424
425 function column_cb($item){
426 return sprintf(
427 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
428 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
429 /*$2%s*/ $item->id //The value of the checkbox should be the record's id
430 );
431 }
432
433 function get_columns(){
434 $columns = array(
435 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
436 'created' => __( 'Date', 'redirection' ),
437 'url' => __( 'Source URL', 'redirection' ),
438 'referrer' => __( 'Referrer', 'redirection' ),
439 'ip' => __( 'IP', 'redirection' ),
440 );
441 return $columns;
442 }
443
444 function get_sortable_columns() {
445 $sortable_columns = array(
446 'created' => array( 'id', true ),
447 'url' => array( 'url', false),
448 'referrer' => array( 'referrer', false ),
449 'ip' => array( 'item_id', false ),
450 );
451 return $sortable_columns;
452 }
453
454 function get_bulk_actions() {
455 $actions = array(
456 'delete' => __( 'Delete', 'redirection' )
457 );
458 return $actions;
459 }
460
461 function process_bulk_action() {
462 if ( 'delete' === $this->current_action() ) {
463 foreach( $_POST['item'] AS $id ) {
464 RE_Log::delete( intval( $id ) );
465 }
466 }
467 }
468
469 function prepare_items( $type = '', $id = 0 ) {
470 global $wpdb, $current_user;
471
472 $screen = get_current_screen();
473 $per_page = get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true );
474
475 $per_page = $per_page ? $per_page : 25;
476 $columns = $this->get_columns();
477 $sortable = $this->get_sortable_columns();
478
479 $this->_column_headers = array( $columns, array(), $sortable );
480
481 // Process any stuff
482 $this->process_bulk_action();
483
484 $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
485 $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
486
487 if ( !in_array( $orderby, array_keys( $sortable ) ) )
488 $orderby = 'id';
489
490 if ( !in_array( $order, array( 'asc', 'desc' ) ) )
491 $order = 'desc';
492
493 $where = array();
494 if ( isset( $_GET['s'] ) )
495 $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
496
497 $where_cond = "";
498 if ( count( $where ) > 0 )
499 $where_cond = " WHERE ".implode( ' AND ', $where );
500
501 $table = $wpdb->prefix.'redirection_logs';
502 $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
503 $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
504
505 $this->items = array();
506 foreach ( (array)$rows AS $row ) {
507 $this->items[] = new RE_Log( $row );
508 }
509
510 $this->set_pagination_args( array(
511 'total_items' => $total_items,
512 'per_page' => $per_page,
513 'total_pages' => ceil( $total_items / $per_page )
514 ) );
515 }
516 }
517
518 class Redirection_404_Table extends WP_List_Table {
519 private $lookup;
520
521 function __construct( $options ) {
522 $this->lookup = $options['lookup'];
523
524 //Set parent defaults
525 parent::__construct( array(
526 'singular' => 'item', //singular name of the listed records
527 'plural' => 'items', //plural name of the listed records
528 'ajax' => false //does this table support ajax?
529 ) );
530 }
531
532 function column_created( $item ) {
533 $actions['add'] = '<a href="'.esc_url( $item->url ).'" class="add-log">'.__( 'Add redirect', 'redirection' ).'</a>';
534
535 return sprintf( '%1$s%2$s', date_i18n( get_option( 'date_format' ), $item->created ).'<br/>'.gmdate( get_option( 'time_format' ), $item->created ), $this->row_actions( $actions ) );
536 }
537
538 function column_ip( $item ) {
539 $actions['add'] = '<a href="'.admin_url( 'tools.php?page=redirection.php&sub=404s&ip='.esc_attr( long2ip( $item->ip ) ) ).'">'.__( 'Show only this IP', 'redirection' ).'</a>';
540
541 return sprintf( '%1$s %2$s', '<a href="'.esc_attr( $this->lookup ).esc_attr( long2ip( $item->ip ) ).'">'.long2ip( $item->ip ).'</a>', $this->row_actions( $actions ) );
542 }
543
544 function column_url( $item ) {
545 return '<a href="'.esc_url( $item->url ).'">'.esc_html( $item->show_url( $item->url ) ).'</a>';
546 }
547
548 function column_referrer( $item ) {
549 $actions = array(
550 'agent' => esc_html( $item->agent ),
551 );
552
553 return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
554 }
555
556 function column_cb($item){
557 return sprintf(
558 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
559 /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
560 /*$2%s*/ $item->id //The value of the checkbox should be the record's id
561 );
562 }
563
564 function get_columns(){
565 $columns = array(
566 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
567 'created' => __( 'Date', 'redirection' ),
568 'url' => __( 'Source URL', 'redirection' ),
569 'referrer' => __( 'Referrer', 'redirection' ),
570 'ip' => __( 'IP', 'redirection' ),
571 );
572 return $columns;
573 }
574
575 function get_sortable_columns() {
576 $sortable_columns = array(
577 'created' => array( 'id', true ),
578 'url' => array( 'url', false),
579 'referrer' => array( 'referrer', false ),
580 );
581 return $sortable_columns;
582 }
583
584 function get_bulk_actions() {
585 $actions = array(
586 'delete' => __( 'Delete', 'redirection' )
587 );
588 return $actions;
589 }
590
591 function process_bulk_action() {
592 if ( 'delete' === $this->current_action() ) {
593 foreach( $_POST['item'] AS $id ) {
594 RE_404::delete( intval( $id ) );
595 }
596 }
597 }
598
599 function prepare_items( $restrict_by_ip = false ) {
600 global $wpdb, $current_user;
601
602 $screen = get_current_screen();
603 $per_page = get_user_meta( $current_user->ID, $screen->get_option( 'per_page', 'option' ), true );
604
605 $per_page = $per_page ? $per_page : 25;
606 $columns = $this->get_columns();
607 $sortable = $this->get_sortable_columns();
608
609 $this->_column_headers = array( $columns, array(), $sortable );
610
611 // Process any stuff
612 $this->process_bulk_action();
613
614 $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
615 $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
616
617 if ( !in_array( $orderby, array_keys( $sortable ) ) )
618 $orderby = 'id';
619
620 if ( !in_array( $order, array( 'asc', 'desc' ) ) )
621 $order = 'desc';
622
623 $where = array();
624 if ( isset( $_GET['s'] ) )
625 $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_GET['s'] ).'%' );
626
627 if ( $restrict_by_ip !== false )
628 $where[] = $wpdb->prepare( 'ip=INET_ATON(%s)', $restrict_by_ip );
629
630 $where_cond = "";
631 if ( count( $where ) > 0 )
632 $where_cond = " WHERE ".implode( ' AND ', $where );
633
634 $table = $wpdb->prefix.'redirection_404';
635 $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
636 $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
637
638 $this->items = array();
639 foreach ( (array)$rows AS $row ) {
640 $this->items[] = new RE_Log( $row );
641 }
642
643 $this->set_pagination_args( array(
644 'total_items' => $total_items,
645 'per_page' => $per_page,
646 'total_pages' => ceil( $total_items / $per_page )
647 ) );
648 }
649 }
650
651 class Redirection_Module_Table extends WP_List_Table {
652 private $token = false;
653
654 function __construct( $token ) {
655 $this->token = $token;
656
657 //Set parent defaults
658 parent::__construct( array(
659 'singular' => 'item', //singular name of the listed records
660 'plural' => 'items', //plural name of the listed records
661 'ajax' => false //does this table support ajax?
662 ) );
663 }
664
665 function get_columns() {
666 $columns = array(
667 'moduletype' => __( 'Type', 'redirection' ),
668 'name' => __( 'Name', 'redirection' ),
669 'groups' => __( 'Groups', 'redirection' ),
670 'hits' => __( 'Hits', 'redirection' ),
671 );
672
673 return $columns;
674 }
675
676 function column_groups( $item ) {
677 return esc_html( $item->groups() );
678 }
679
680 function column_hits( $item ) {
681 return esc_html( number_format_i18n( $item->hits(), 0 ) );
682 }
683
684 function column_moduletype( $item ) {
685 return esc_html( $item->get_type_string() );
686 }
687
688 function column_name( $item ) {
689 $actions['edit'] = sprintf( '<a href="#" class="red-ajax" data-action="%s" data-nonce="%s" data-id="%s">'.__( 'Edit', 'redirection' ).'</a>', 'red_module_edit', wp_create_nonce( 'red_edit-'.$item->get_id() ), $item->get_id() );
690
691 if ( $this->token ) {
692 if ( $item->get_type() === 'wp' ) {
693 $actions['rss'] = sprintf( '<a href="%s">RSS</a>', '?page=redirection.php&amp;token='.$this->token.'&amp;sub=rss&amp;module='.intval( $item->get_id() ) );
694 }
695
696 $actions['htaccess'] = sprintf( '<a href="%s">.htaccess</a>', '?page=redirection.php&amp;token='.$this->token.'&amp;sub=apache&amp;module='.intval( $item->get_id() ) );
697 $actions['csv'] = sprintf( '<a href="%s">CSV</a>', '?page=redirection.php&amp;token='.$this->token.'&amp;sub=csv&amp;module='.intval( $item->get_id() ) );
698 }
699
700 return '<a href="#" data-action="%s" data-nonce="%s" data-id="%s">'.esc_html( $item->get_name() ).'</a>'.$this->row_actions( $actions );
701 }
702
703 function prepare_items( $type = '', $id = 0 ) {
704 global $wpdb;
705
706 $table = $wpdb->prefix.'redirection_modules';
707 $rows = $wpdb->get_results( "SELECT * FROM {$table}" );
708 $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" );
709
710 $columns = $this->get_columns();
711 $sortable = $this->get_sortable_columns();
712
713 $this->_column_headers = array( $columns, array(), $sortable );
714
715 $this->items = array();
716 foreach ( (array)$rows AS $row ) {
717 $this->items[] = Red_Module::new_item( $row );
718 }
719
720 $this->set_pagination_args( array(
721 'total_items' => $this->total_items,
722 'per_page' => 100,
723 'total_pages' => ceil( $this->total_items / 100 )
724 ) );
725 }
726 }
727