class-api-requests-logs-list-table.php
8 years ago
class-gateway-error-logs-list-table.php
8 years ago
class-sales-logs-list-table.php
7 years ago
class-update-logs-list-table.php
8 years ago
logs.php
8 years ago
class-gateway-error-logs-list-table.php
273 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Gateway Error Log View Class. |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Admin/Reports |
| 7 | * @copyright Copyright (c) 2016, WordImpress |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | // Load WP_List_Table if not loaded. |
| 17 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 18 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Give_Gateway_Error_Log_Table Class. |
| 23 | * |
| 24 | * Renders the gateway errors list table. |
| 25 | * |
| 26 | * @access private |
| 27 | * @since 1.0 |
| 28 | */ |
| 29 | class Give_Gateway_Error_Log_Table extends WP_List_Table { |
| 30 | |
| 31 | /** |
| 32 | * Number of items per page. |
| 33 | * |
| 34 | * @var int |
| 35 | * @since 1.0 |
| 36 | */ |
| 37 | public $per_page = 30; |
| 38 | |
| 39 | /** |
| 40 | * Get things started. |
| 41 | * |
| 42 | * @since 1.0 |
| 43 | * @see WP_List_Table::__construct() |
| 44 | */ |
| 45 | public function __construct() { |
| 46 | // Set parent defaults. |
| 47 | parent::__construct( 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 | * This function renders most of the columns in the list table. |
| 56 | * |
| 57 | * @access public |
| 58 | * @since 1.0 |
| 59 | * |
| 60 | * @param array $item Contains all the data of the log item. |
| 61 | * @param string $column_name The name of the column. |
| 62 | * |
| 63 | * @return string Column Name. |
| 64 | */ |
| 65 | public function column_default( $item, $column_name ) { |
| 66 | |
| 67 | switch ( $column_name ) { |
| 68 | case 'ID' : |
| 69 | return $item['ID_label']; |
| 70 | case 'payment_id' : |
| 71 | return empty( $item['payment_id'] ) ? esc_html__( 'n/a', 'give' ) : sprintf( "<a href=\"%s\" target=\"_blank\">{$item['payment_id']}</a>", get_edit_post_link( $item['payment_id'] ) ); |
| 72 | case 'gateway' : |
| 73 | return empty( $item['gateway'] ) ? esc_html__( 'n/a', 'give' ) : $item['gateway']; |
| 74 | case 'error' : |
| 75 | return esc_html( $item['log_title'] ); |
| 76 | default: |
| 77 | return $item[ $column_name ]; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Output Error Message Column. |
| 83 | * |
| 84 | * @access public |
| 85 | * @since 1.0 |
| 86 | * |
| 87 | * @param array $item Contains all the data of the log. |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | public function column_message( $item ) { |
| 92 | ?> |
| 93 | <?php |
| 94 | echo Give()->tooltips->render_link( array( |
| 95 | 'label' => __( 'View Log Message', 'give' ), |
| 96 | 'tag_content' => '<span class="dashicons dashicons-visibility"></span>', |
| 97 | 'link' => "#TB_inline?width=640&inlineId=log-message-{$item['ID']}", |
| 98 | 'attributes' => array( |
| 99 | 'class' => 'thickbox give-error-log-details-link button button-small', |
| 100 | ), |
| 101 | ) ); |
| 102 | ?> |
| 103 | <div id="log-message-<?php echo $item['ID']; ?>" style="display:none;"> |
| 104 | <?php |
| 105 | |
| 106 | $serialized = strpos( $item['log_content'], '{"' ); |
| 107 | |
| 108 | // Check to see if the log message contains serialized information |
| 109 | if ( $serialized !== false ) { |
| 110 | $length = strlen( $item['log_content'] ) - $serialized; |
| 111 | $intro = substr( $item['log_content'], 0, - $length ); |
| 112 | $data = substr( $item['log_content'], $serialized, strlen( $item['log_content'] ) - 1 ); |
| 113 | |
| 114 | echo wpautop( $intro ); |
| 115 | echo wpautop( '<strong>' . esc_html__( 'Log data:', 'give' ) . '</strong>' ); |
| 116 | echo '<div style="word-wrap: break-word;">' . wpautop( $data ) . '</div>'; |
| 117 | } else { |
| 118 | // No serialized data found |
| 119 | echo wpautop( $item['log_content'] ); |
| 120 | } |
| 121 | ?> |
| 122 | </div> |
| 123 | <?php |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Retrieve the table columns. |
| 128 | * |
| 129 | * @access public |
| 130 | * @since 1.0 |
| 131 | * @return array $columns Array of all the list table columns. |
| 132 | */ |
| 133 | public function get_columns() { |
| 134 | $columns = array( |
| 135 | 'ID' => esc_html__( 'Log ID', 'give' ), |
| 136 | 'error' => esc_html__( 'Error', 'give' ), |
| 137 | 'gateway' => esc_html__( 'Gateway', 'give' ), |
| 138 | 'payment_id' => esc_html__( 'Donation ID', 'give' ), |
| 139 | 'date' => esc_html__( 'Date', 'give' ), |
| 140 | 'message' => esc_html__( 'Details', 'give' ), |
| 141 | ); |
| 142 | |
| 143 | return $columns; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Retrieve the current page number |
| 148 | * |
| 149 | * @access public |
| 150 | * @since 1.0 |
| 151 | * @return int Current page number |
| 152 | */ |
| 153 | public function get_paged() { |
| 154 | return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Outputs the log views |
| 159 | * |
| 160 | * @access public |
| 161 | * @since 1.0 |
| 162 | * @return void |
| 163 | */ |
| 164 | public function bulk_actions( $which = '' ) { |
| 165 | give_log_views(); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Gets the log entries for the current view. |
| 170 | * |
| 171 | * @access public |
| 172 | * @since 1.0 |
| 173 | * |
| 174 | * @return array $logs_data Array of all the Log entries. |
| 175 | */ |
| 176 | public function get_logs() { |
| 177 | // Prevent the queries from getting cached. |
| 178 | // Without this there are occasional memory issues for some installs. |
| 179 | wp_suspend_cache_addition( true ); |
| 180 | |
| 181 | $logs_data = array(); |
| 182 | $paged = $this->get_paged(); |
| 183 | $log_query = array( |
| 184 | 'log_type' => 'gateway_error', |
| 185 | 'paged' => $paged, |
| 186 | 'posts_per_page' => $this->per_page, |
| 187 | ); |
| 188 | |
| 189 | $logs = Give()->logs->get_connected_logs( $log_query ); |
| 190 | |
| 191 | if ( $logs ) { |
| 192 | foreach ( $logs as $log ) { |
| 193 | |
| 194 | $logs_data[] = array( |
| 195 | 'ID' => $log->ID, |
| 196 | 'ID_label' => '<span class=\'give-item-label give-item-label-gray\'>' . $log->ID . '</span>', |
| 197 | 'payment_id' => $log->log_parent, |
| 198 | 'error' => 'error', |
| 199 | 'gateway' => give_get_payment_gateway( $log->log_parent ), |
| 200 | 'date' => $log->log_date, |
| 201 | 'log_content' => $log->log_content, |
| 202 | 'log_title' => $log->log_title, |
| 203 | ); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return $logs_data; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Display Tablenav (extended). |
| 212 | * |
| 213 | * Display the table navigation above or below the table even when no items in the logs, |
| 214 | * so nav doesn't disappear. |
| 215 | * |
| 216 | * @see : https://github.com/WordImpress/Give/issues/564 |
| 217 | * |
| 218 | * @since 1.4.1 |
| 219 | * @access protected |
| 220 | * |
| 221 | * @param string $which |
| 222 | */ |
| 223 | protected function display_tablenav( $which ) { |
| 224 | if ( 'top' === $which ) { |
| 225 | wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
| 226 | } |
| 227 | ?> |
| 228 | <div class="tablenav <?php echo esc_attr( $which ); ?>"> |
| 229 | |
| 230 | <div class="alignleft actions bulkactions"> |
| 231 | <?php $this->bulk_actions( $which ); ?> |
| 232 | </div> |
| 233 | <?php |
| 234 | $this->extra_tablenav( $which ); |
| 235 | $this->pagination( $which ); |
| 236 | ?> |
| 237 | |
| 238 | <br class="clear"/> |
| 239 | </div> |
| 240 | <?php |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Setup the final data for the table |
| 245 | * |
| 246 | * @access public |
| 247 | * @since 1.0 |
| 248 | * |
| 249 | * @uses Give_Gateway_Error_Log_Table::get_columns() |
| 250 | * @uses WP_List_Table::get_sortable_columns() |
| 251 | * @uses Give_Gateway_Error_Log_Table::get_pagenum() |
| 252 | * @uses Give_Gateway_Error_Log_Table::get_logs() |
| 253 | * @uses Give_Gateway_Error_Log_Table::get_log_count() |
| 254 | * @return void |
| 255 | */ |
| 256 | public function prepare_items() { |
| 257 | |
| 258 | $columns = $this->get_columns(); |
| 259 | $hidden = array(); // No hidden columns |
| 260 | $sortable = $this->get_sortable_columns(); |
| 261 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| 262 | $this->items = $this->get_logs(); |
| 263 | $total_items = Give()->logs->get_log_count( 0, 'gateway_error' ); |
| 264 | |
| 265 | $this->set_pagination_args( array( |
| 266 | 'total_items' => $total_items, |
| 267 | 'per_page' => $this->per_page, |
| 268 | 'total_pages' => ceil( $total_items / $this->per_page ), |
| 269 | ) |
| 270 | ); |
| 271 | } |
| 272 | } |
| 273 |