class-api-requests-logs-list-table.php
6 years ago
class-gateway-error-logs-list-table.php
6 years ago
class-spam-logs-list-table.php
6 years ago
class-update-logs-list-table.php
6 years ago
logs.php
6 years ago
class-spam-logs-list-table.php
326 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Spam Log View Class |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Admin/Reports |
| 7 | * @copyright Copyright (c) 2020, GiveWP |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 2.5.14 |
| 10 | */ |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | // Load WP_List_Table if not loaded |
| 18 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 19 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Give_Spam_Log_Table List Table Class |
| 24 | * |
| 25 | * Renders the gateway errors list table |
| 26 | * |
| 27 | * @since 2.5.14 |
| 28 | */ |
| 29 | class Give_Spam_Log_Table extends WP_List_Table { |
| 30 | /** |
| 31 | * Number of items per page |
| 32 | * |
| 33 | * @var int |
| 34 | * @since 2.5.14 |
| 35 | */ |
| 36 | public $per_page = 30; |
| 37 | |
| 38 | /** |
| 39 | * Get things started |
| 40 | * |
| 41 | * @since 2.5.14 |
| 42 | * @see WP_List_Table::__construct() |
| 43 | */ |
| 44 | public function __construct() { |
| 45 | // Set parent defaults |
| 46 | parent::__construct( |
| 47 | array( |
| 48 | 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
| 49 | 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
| 50 | 'ajax' => false, // Does this table support ajax? |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Show the search field |
| 57 | * |
| 58 | * @since 2.5.14 |
| 59 | * @access public |
| 60 | * |
| 61 | * @param string $text Label for the search box |
| 62 | * @param string $input_id ID of the search box |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function search_box( $text, $input_id ) { |
| 67 | $input_id = "{$input_id}-search-input"; |
| 68 | |
| 69 | if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 70 | echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
| 71 | } |
| 72 | if ( ! empty( $_REQUEST['order'] ) ) { |
| 73 | echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
| 74 | } |
| 75 | ?> |
| 76 | <p class="search-box" role="search"> |
| 77 | <label class="screen-reader-text" for="<?php echo $input_id; ?>"><?php echo $text; ?>:</label> |
| 78 | <input type="search" id="<?php echo $input_id; ?>" name="s" value="<?php _admin_search_query(); ?>"/> |
| 79 | <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?> |
| 80 | </p> |
| 81 | <?php |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Retrieve the table columns |
| 86 | * |
| 87 | * @access public |
| 88 | * @return array $columns Array of all the list table columns |
| 89 | * @since 2.5.14 |
| 90 | */ |
| 91 | public function get_columns() { |
| 92 | return array( |
| 93 | 'ID' => __( 'Log ID', 'give' ), |
| 94 | 'error' => __( 'Error', 'give' ), |
| 95 | 'date' => __( 'Date', 'give' ), |
| 96 | 'details' => __( 'Log Details', 'give' ), |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * This function renders most of the columns in the list table. |
| 102 | * |
| 103 | * @access public |
| 104 | * |
| 105 | * @param array $item Contains all the data of the discount code |
| 106 | * @param string $column_name The name of the column |
| 107 | * |
| 108 | * @return string Column Name |
| 109 | * @since 2.5.14 |
| 110 | */ |
| 111 | public function column_default( $item, $column_name ) { |
| 112 | switch ( $column_name ) { |
| 113 | case 'error': |
| 114 | $action = 'akismet_deblacklist_spammed_email'; |
| 115 | $donor_email = Give()->logmeta_db->get_meta( $item['ID'], 'donor_email', true ); |
| 116 | |
| 117 | return str_replace( |
| 118 | '#noncelink', |
| 119 | add_query_arg( |
| 120 | array( |
| 121 | 'give-action' => $action, |
| 122 | 'email' => $donor_email, |
| 123 | 'log' => $item['ID'], |
| 124 | '_wpnonce' => wp_create_nonce( "give_{$action}_{$donor_email}" ), |
| 125 | ), |
| 126 | admin_url() |
| 127 | ), |
| 128 | $item[ $column_name ] |
| 129 | ); |
| 130 | |
| 131 | default: |
| 132 | return esc_attr( $item[ $column_name ] ); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Output Error Message column |
| 138 | * |
| 139 | * @access public |
| 140 | * |
| 141 | * @param array $item Contains all the data of the log |
| 142 | * |
| 143 | * @return void |
| 144 | * @since 2.5.14 |
| 145 | */ |
| 146 | public function column_details( $item ) { |
| 147 | echo Give()->tooltips->render_link( |
| 148 | array( |
| 149 | 'label' => __( 'View Log Details', 'give' ), |
| 150 | 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', |
| 151 | 'link' => "#TB_inline?width=640&inlineId=log-details-{$item['ID']}", |
| 152 | 'attributes' => array( |
| 153 | 'class' => 'thickbox give-error-log-details-link button button-small', |
| 154 | ), |
| 155 | ) |
| 156 | ); |
| 157 | ?> |
| 158 | <div id="log-details-<?php echo $item['ID']; ?>" style="display:none;"> |
| 159 | <?php echo $item['log_content']; ?> |
| 160 | </div> |
| 161 | <?php |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Display Tablenav (extended) |
| 166 | * |
| 167 | * Display the table navigation above or below the table even when no items in the logs, so nav doesn't disappear |
| 168 | * |
| 169 | * @see : https://github.com/impress-org/give/issues/564 |
| 170 | * |
| 171 | * @since 2.5.14 |
| 172 | * @access protected |
| 173 | * |
| 174 | * @param string $which |
| 175 | */ |
| 176 | protected function display_tablenav( $which ) { |
| 177 | if ( 'top' === $which ) { |
| 178 | wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
| 179 | } |
| 180 | ?> |
| 181 | <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 182 | |
| 183 | <div class="alignleft actions bulkactions"> |
| 184 | <?php $this->bulk_actions( $which ); ?> |
| 185 | </div> |
| 186 | <?php |
| 187 | $this->extra_tablenav( $which ); |
| 188 | $this->pagination( $which ); |
| 189 | ?> |
| 190 | |
| 191 | <br class="clear"/> |
| 192 | </div> |
| 193 | <?php |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Retrieves the search query string |
| 198 | * |
| 199 | * @access public |
| 200 | * @since 2.5.14 |
| 201 | * |
| 202 | * @return string|bool String if search is present, false otherwise |
| 203 | */ |
| 204 | public function get_search() { |
| 205 | return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Retrieve the current page number |
| 210 | * |
| 211 | * @access public |
| 212 | * @return int Current page number |
| 213 | * @since 2.5.14 |
| 214 | */ |
| 215 | public function get_paged() { |
| 216 | return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Gets the meta query for the log query |
| 221 | * |
| 222 | * This is used to return log entries that match our search query |
| 223 | * |
| 224 | * @access public |
| 225 | * @since 2.5.14 |
| 226 | * |
| 227 | * @return array $meta_query |
| 228 | */ |
| 229 | public function get_meta_query() { |
| 230 | |
| 231 | $meta_query = array( 'relation' => 'OR' ); |
| 232 | $search = $this->get_search(); |
| 233 | |
| 234 | if ( $search ) { |
| 235 | $meta_query[] = array( |
| 236 | 'key' => 'donor_email', |
| 237 | 'value' => $search, |
| 238 | ); |
| 239 | } |
| 240 | |
| 241 | return $meta_query; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Gets the log entries for the current view |
| 246 | * |
| 247 | * @access public |
| 248 | * @return array $logs_data Array of all the Log entires |
| 249 | * @since 2.5.14 |
| 250 | */ |
| 251 | public function get_logs() { |
| 252 | $logs_data = array(); |
| 253 | $paged = $this->get_paged(); |
| 254 | $log_query = array( |
| 255 | 'log_type' => 'spam', |
| 256 | 'paged' => $paged, |
| 257 | 'meta_query' => $this->get_meta_query(), |
| 258 | 'posts_per_page' => $this->per_page, |
| 259 | ); |
| 260 | |
| 261 | $logs = Give()->logs->get_connected_logs( $log_query ); |
| 262 | |
| 263 | if ( $logs ) { |
| 264 | foreach ( $logs as $log ) { |
| 265 | |
| 266 | $logs_data[] = array( |
| 267 | 'ID' => $log->ID, |
| 268 | 'date' => $log->log_date, |
| 269 | 'log_content' => wp_kses( |
| 270 | $log->log_content, |
| 271 | array( |
| 272 | 'p' => array(), |
| 273 | 'pre' => array(), |
| 274 | 'strong' => array(), |
| 275 | ) |
| 276 | ), |
| 277 | 'error' => wp_kses( |
| 278 | $log->log_title, |
| 279 | array( |
| 280 | 'p' => array(), |
| 281 | 'strong' => array(), |
| 282 | 'a' => array( |
| 283 | 'href' => array(), |
| 284 | 'title' => array(), |
| 285 | 'target' => array(), |
| 286 | ), |
| 287 | ) |
| 288 | ), |
| 289 | ); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return $logs_data; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Setup the final data for the table |
| 298 | * |
| 299 | * @access public |
| 300 | * @return void |
| 301 | * @uses Give_Spam_Log_Table::get_columns() |
| 302 | * @uses WP_List_Table::get_sortable_columns() |
| 303 | * @uses Give_Spam_Log_Table::get_pagenum() |
| 304 | * @uses Give_Spam_Log_Table::get_logs() |
| 305 | * @uses Give_Spam_Log_Table::get_log_count() |
| 306 | * |
| 307 | * @since 2.5.14 |
| 308 | */ |
| 309 | public function prepare_items() { |
| 310 | $columns = $this->get_columns(); |
| 311 | $hidden = array(); // No hidden columns |
| 312 | $sortable = $this->get_sortable_columns(); |
| 313 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| 314 | $this->items = $this->get_logs(); |
| 315 | $total_items = Give()->logs->get_log_count( 0, 'spam', $this->get_meta_query() ); |
| 316 | |
| 317 | $this->set_pagination_args( |
| 318 | array( |
| 319 | 'total_items' => $total_items, |
| 320 | 'per_page' => $this->per_page, |
| 321 | 'total_pages' => ceil( $total_items / $this->per_page ), |
| 322 | ) |
| 323 | ); |
| 324 | } |
| 325 | } |
| 326 |