Easy Digital Downloads
  • Package
  • Class
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Classes

  • EDD_API_Request_Log_Table
  • EDD_Customer_Reports_Table
  • EDD_Customers_Export
  • EDD_Download_History_Export
  • EDD_Download_Reports_Table
  • EDD_Export
  • EDD_File_Downloads_Log_Table
  • EDD_Gateway_Error_Log_Table
  • EDD_Payments_Export
  • EDD_Sales_Log_Table

Functions

  • edd_draw_chart_image
  • edd_estimated_monthly_stats
  • edd_generate_pdf
  • edd_get_report_dates
  • edd_log_default_views
  • edd_log_views
  • edd_logs_view_api_requests
  • edd_logs_view_file_downloads
  • edd_logs_view_gateway_errors
  • edd_logs_view_sales
  • edd_parse_report_dates
  • edd_report_views
  • edd_reporting_contextual_help
  • edd_reports_customers_table
  • edd_reports_default_views
  • edd_reports_downloads_table
  • edd_reports_earnings
  • edd_reports_graph
  • edd_reports_graph_controls
  • edd_reports_page
  • edd_reports_tab_export
  • edd_reports_tab_logs
  • edd_reports_tab_reports
  • edd_reports_taxes
  1 <?php
  2 /**
  3  * API Requests Log View Class
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin/Reports
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.5
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 // Load WP_List_Table if not loaded
 16 if ( ! class_exists( 'WP_List_Table' ) ) {
 17     require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
 18 }
 19 
 20 /**
 21  * EDD_API_Request_Log_Table List Table Class
 22  *
 23  * Renders the gateway errors list table
 24  *
 25  * @since 1.5
 26  */
 27 class EDD_API_Request_Log_Table extends WP_List_Table {
 28     /**
 29      * Number of items per page
 30      *
 31      * @var int
 32      * @since 1.5
 33      */
 34     public $per_page = 30;
 35 
 36     /**
 37      * Get things started
 38      *
 39      * @access public
 40      * @since 1.5
 41      * @see WP_List_Table::__construct()
 42      * @return void
 43      */
 44     public function __construct() {
 45         global $status, $page;
 46 
 47         // Set parent defaults
 48         parent::__construct( array(
 49             'singular'  => edd_get_label_singular(),    // Singular name of the listed records
 50             'plural'    => edd_get_label_plural(),      // Plural name of the listed records
 51             'ajax'      => false                        // Does this table support ajax?
 52         ) );
 53     }
 54 
 55     /**
 56      * Show the search field
 57      *
 58      * @since 1.5
 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         if ( ! empty( $_REQUEST['order'] ) )
 72             echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
 73         ?>
 74         <p class="search-box">
 75             <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
 76             <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
 77             <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?>
 78         </p>
 79         <?php
 80     }
 81 
 82     /**
 83      * Retrieve the table columns
 84      *
 85      * @access public
 86      * @since 1.5
 87      * @return array $columns Array of all the list table columns
 88      */
 89     public function get_columns() {
 90         $columns = array(
 91             'ID'         => __( 'Log ID', 'edd' ),
 92             'details'    => __( 'Request Details', 'edd' ),
 93             'ip'         => __( 'Request IP', 'edd' ),
 94             'date'       => __( 'Date', 'edd' )
 95         );
 96 
 97         return $columns;
 98     }
 99 
100     /**
101      * This function renders most of the columns in the list table.
102      *
103      * @access public
104      * @since 1.5
105      *
106      * @param array $item Contains all the data of the discount code
107      * @param string $column_name The name of the column
108      *
109      * @return string Column Name
110      */
111     public function column_default( $item, $column_name ) {
112         switch( $column_name ){
113             default:
114                 return $item[ $column_name ];
115         }
116     }
117 
118     /**
119      * Output Error Message column
120      *
121      * @access public
122      * @since 1.5
123      * @param array $item Contains all the data of the log
124      * @return void
125      */
126     public function column_details( $item ) {
127     ?>
128         <a href="#TB_inline?width=640&amp;inlineId=log-details-<?php echo $item['ID']; ?>" class="thickbox" title="<?php _e( 'View Request Details', 'edd' ); ?> "><?php _e( 'View Request', 'edd' ); ?></a>
129         <div id="log-details-<?php echo $item['ID']; ?>" style="display:none;">
130             <?php
131 
132             $request = get_post_field( 'post_excerpt', $item['ID'] );
133             $error   = get_post_field( 'post_content', $item['ID'] );
134             echo '<p><strong>' . __( 'API Request:', 'edd' ) . '</strong></p>';
135             echo '<div>' . $request . '</div>';
136             if( ! empty( $error ) ) {
137                 echo '<p><strong>' . __( 'Error', 'edd' ) . '</strong></p>';
138                 echo '<div>' . esc_html( $error ) . '</div>';
139             }
140             echo '<p><strong>' . __( 'API User:', 'edd' ) . '</strong></p>';
141             echo '<div>' . get_post_meta( $item['ID'], '_edd_log_user', true ) . '</div>';
142             echo '<p><strong>' . __( 'API Key:', 'edd' ) . '</strong></p>';
143             echo '<div>' . get_post_meta( $item['ID'], '_edd_log_api_key', true ) . '</div>';
144             echo '<p><strong>' . __( 'Request Date:', 'edd' ) . '</strong></p>';
145             echo '<div>' . get_post_field( 'post_date', $item['ID'] ) . '</div>';
146             ?>
147         </div>
148     <?php
149     }
150 
151     /**
152      * Retrieves the search query string
153      *
154      * @access public
155      * @since 1.5
156      * @return mixed String if search is present, false otherwise
157      */
158     public function get_search() {
159         return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
160     }
161 
162     /**
163      * Gets the meta query for the log query
164      *
165      * This is used to return log entries that match our search query
166      *
167      * @access public
168      * @since 1.5
169      * @return array $meta_query
170      */
171     function get_meta_query() {
172         $meta_query = array();
173 
174         $search = $this->get_search();
175 
176         if ( $search ) {
177             if ( filter_var( $search, FILTER_VALIDATE_IP ) ) {
178                 // This is an IP address search
179                 $key = '_edd_log_request_ip';
180             } else if ( is_email( $search ) ) {
181                 // This is an email search
182                 $key = '_edd_log_user';
183             } else {
184                 // Look for an API key
185                 $key = '_edd_log_api_key';
186             }
187 
188             // Setup the meta query
189             $meta_query[] = array(
190                 'key'     => $key,
191                 'value'   => $search,
192                 'compare' => '='
193             );
194         }
195 
196         return $meta_query;
197     }
198 
199     /**
200      * Retrieve the current page number
201      *
202      * @access public
203      * @since 1.5
204      * @return int Current page number
205      */
206     public function get_paged() {
207         return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
208     }
209 
210     /**
211      * Outputs the log views
212      *
213      * @access public
214      * @since 1.5
215      * @return void
216      */
217     function bulk_actions() {
218         // These aren't really bulk actions but this outputs the markup in the right place
219         edd_log_views();
220     }
221 
222     /**
223      * Gets the log entries for the current view
224      *
225      * @access public
226      * @since 1.5
227      * @global object $edd_logs EDD Logs Object
228      * @return array $logs_data Array of all the Log entires
229      */
230     public function get_logs() {
231         global $edd_logs;
232 
233         $logs_data = array();
234         $paged     = $this->get_paged();
235         $log_query = array(
236             'log_type'    => 'api_requests',
237             'paged'       => $paged,
238             'meta_query'  => $this->get_meta_query()
239         );
240 
241         $logs = $edd_logs->get_connected_logs( $log_query );
242 
243         if ( $logs ) {
244             foreach ( $logs as $log ) {
245 
246                 $logs_data[] = array(
247                     'ID'   => $log->ID,
248                     'ip'   => get_post_meta( $log->ID, '_edd_log_request_ip', true ),
249                     'date' => $log->post_date
250                 );
251             }
252         }
253 
254         return $logs_data;
255     }
256 
257     /**
258      * Setup the final data for the table
259      *
260      * @access public
261      * @since 1.5
262      * @global object $edd_logs EDD Logs Object
263      * @uses EDD_API_Request_Log_Table::get_columns()
264      * @uses WP_List_Table::get_sortable_columns()
265      * @uses EDD_API_Request_Log_Table::get_pagenum()
266      * @uses EDD_API_Request_Log_Table::get_logs()
267      * @uses EDD_API_Request_Log_Table::get_log_count()
268      * @return void
269      */
270     public function prepare_items() {
271         global $edd_logs;
272 
273         $columns               = $this->get_columns();
274         $hidden                = array(); // No hidden columns
275         $sortable              = $this->get_sortable_columns();
276         $this->_column_headers = array( $columns, $hidden, $sortable );
277         $current_page          = $this->get_pagenum();
278         $this->items           = $this->get_logs();
279         $total_items           = $edd_logs->get_log_count( 0, 'api_requests' );
280 
281         $this->set_pagination_args( array(
282                 'total_items'  => $total_items,
283                 'per_page'     => $this->per_page,
284                 'total_pages'  => ceil( $total_items / $this->per_page )
285             )
286         );
287     }
288 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0