PluginProbe
Redirection / 2.3.16
Redirection v2.3.16
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.16, at models/pager.php

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