22
33namespace Manuel ;
44
5- if ( ! defined ( 'ABSPATH ' ) ) {
5+ if (! defined ('ABSPATH ' ) ) {
66 exit ; // Exit if accessed directly.
77}
88
9- // Fetch statistics from the database.
10- $ manuel_settings = new Manuel_Settings ( '1.0 ' );
11- $ stats = $ manuel_settings ->get_manuel_cron ()->get_stats ();
9+ if (!class_exists ('WP_List_Table ' )) {
10+ require_once (ABSPATH . 'wp-admin/includes/class-wp-list-table.php ' );
11+ }
12+
13+ class Manuel_Links_Stats extends \WP_List_Table {
14+ public function __construct ()
15+ {
16+ parent ::__construct ([
17+ 'singular ' => __ ('Stat ' , 'manuel ' ),
18+ 'plural ' => __ ('Stats ' , 'manuel ' ),
19+ 'ajax ' => false
20+ ]);
21+ }
22+
23+ public function get_columns () {
24+ return [
25+ 'cb ' => '<input type="checkbox" /> ' , // Render a checkbox.
26+ 'post_title ' => __ ('Post Title ' , 'manuel ' ),
27+ 'original_link ' => __ ('Original Link ' , 'manuel ' ),
28+ 'anchor_text ' => __ ('Anchor Text ' , 'manuel ' ),
29+ 'time_removed ' => __ ('Time Removed ' , 'manuel ' )
30+ ];
31+ }
32+
33+ public function column_cb ($ item ) {
34+ return sprintf ('<input type="checkbox" name="bulk-delete[]" value="%s" /> ' , $ item ['ID ' ]);
35+ }
36+
37+ public function prepare_items () {
38+ $ columns = $ this ->get_columns ();
39+ $ hidden = array ();
40+ $ sortable = array ();
41+
42+ $ this ->_column_headers = array ($ columns , $ hidden , $ sortable );
43+
44+ $ manuel_settings = new Manuel_Settings ('1.0 ' );
45+ $ data = $ manuel_settings ->get_manuel_cron ()->get_stats ();
46+
47+ $ perPage = 20 ;
48+ $ currentPage = $ this ->get_pagenum ();
49+ $ totalItems = count ($ data );
50+
51+ $ this ->set_pagination_args ([
52+ 'total_items ' => $ totalItems ,
53+ 'per_page ' => $ perPage
54+ ]);
55+
56+ $ data = array_slice ($ data , (($ currentPage -1 )*$ perPage ), $ perPage );
57+
58+ $ this ->items = $ data ;
59+ }
60+
61+ public function column_default ($ item , $ column_name ) {
62+ switch ($ column_name ) {
63+ case 'post_id ' :
64+ case 'post_title ' :
65+ case 'anchor_text ' :
66+ case 'time_removed ' :
67+ return esc_html ($ item [$ column_name ]);
68+ case 'original_link ' :
69+ return '<a href=" ' . esc_url ($ item [$ column_name ]) . '"> ' . esc_url ($ item [$ column_name ]) . '</a> ' ;
70+ default :
71+ return print_r ($ item , true );
72+ }
73+ }
74+
75+ public function column_post_title ($ item ) {
76+ $ actions = [
77+ 'edit ' => sprintf ('<a href="%s">%s</a> ' , get_edit_post_link ($ item ['post_id ' ]), __ ('Edit ' , 'manuel ' )),
78+ 'trash ' => sprintf ('<a href="%s">%s</a> ' , get_delete_post_link ($ item ['post_id ' ]), __ ('Trash ' , 'manuel ' )),
79+ 'view ' => sprintf ('<a href="%s">%s</a> ' , get_permalink ($ item ['post_id ' ]), __ ('View ' , 'manuel ' ))
80+ ];
81+
82+ return sprintf ('%1$s %2$s ' , $ item ['post_title ' ], $ this ->row_actions ($ actions ));
83+ }
84+
85+ public function extra_tablenav ($ which ) {
86+ if ($ which === 'top ' ) {
87+ ?>
88+ <div class="alignleft actions bulkactions">
89+ <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
90+ <select name="action" id="bulk-action-selector-top">
91+ <option value="-1">Bulk Actions</option>
92+ <option value="trash">Move to Trash</option>
93+ </select>
94+ <input type="submit" id="doaction" class="button action" value ="Apply">
95+ </div>
96+ <div class="alignleft actions">
97+ <label class="screen-reader-text" for="post-search-input">Search Posts:</label>
98+ <input type="search" id="post-search-input" name="s" value="">
99+ <input type="submit" id="search-submit" class="button" value="Search Posts">
100+ </div>
101+ <?php
102+ }
103+ if ($ which === 'bottom ' ){
104+ ?>
105+ <div class="alignleft actions bulkactions">
106+ <label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
107+ <select name="action2" id="bulk-action-selector-bottom">
108+ <option value="-1">Bulk Actions</option>
109+ <option value="trash">Move to Trash</option>
110+ </select>
111+ <input type="submit" id="doaction2" class="button action" value="Apply">
112+ </div>
113+ <?php
114+ }
115+ }
116+ }
117+
118+ $ linksTable = new Manuel_Links_Stats ();
12119?>
13120
14121<div class="wrap">
15- <h1><?php esc_html_e ( 'Manuel Stats ' , 'manuel ' ); ?> </h1>
16-
17- <table class="widefat">
18- <thead>
19- <tr>
20- <th><?php esc_html_e ( 'Post ID ' , 'manuel ' ); ?> </th>
21- <th><?php esc_html_e ( 'Post Title ' , 'manuel ' ); ?> </th>
22- <th><?php esc_html_e ( 'Original Link ' , 'manuel ' ); ?> </th>
23- <th><?php esc_html_e ( 'Anchor Text ' , 'manuel ' ); ?> </th>
24- <th><?php esc_html_e ( 'Time Removed ' , 'manuel ' ); ?> </th>
25- </tr>
26- </thead>
27- <tbody>
28- <?php foreach ( $ stats as $ stat ) : ?>
29- <tr>
30- <td><?php echo esc_html ( $ stat ['post_id ' ] ); ?> </td>
31- <td><?php echo esc_html ( $ stat ['post_title ' ] ); ?> </td>
32- <td><a href="<?php echo esc_url ( $ stat ['original_link ' ] ); ?> "><?php echo esc_url ( $ stat ['original_link ' ] ); ?> </a></td>
33- <td><?php echo esc_html ( $ stat ['anchor_text ' ] ); ?> </td>
34- <td><?php echo esc_html ( $ stat ['time_removed ' ] ); ?> </td>
35- </tr>
36- <?php endforeach ; ?>
37- </tbody>
38- </table>
39- </div>
122+ <h2><?php esc_html_e ('Manuel Links Stats ' , 'manuel ' ) ?> </h2>
123+ <form method="post">
124+ <?php
125+ $ linksTable ->prepare_items ();
126+ $ linksTable ->display ();
127+ ?>
128+ </form>
129+ </div>
0 commit comments