Beispiel #1
0
        /**
         * My History Page
         * @since 0.1
         * @version 1.2.1
         */
        public function my_history_page()
        {
            // Security
            if (!is_user_logged_in()) {
                wp_die(__('Access Denied', 'mycred'));
            }
            $settings_key = 'mycred_epp_' . $_GET['page'];
            if (!$this->is_main_type) {
                $settings_key .= '_' . $this->mycred_type;
            }
            $per_page = mycred_get_user_meta($this->current_user_id, $settings_key, '', true);
            if ($per_page == '') {
                $per_page = 10;
            }
            $args = array('user_id' => $this->current_user_id, 'number' => $per_page);
            if (isset($_GET['type']) && !empty($_GET['type'])) {
                $args['ctype'] = $_GET['type'];
            } else {
                $args['ctype'] = $this->mycred_type;
            }
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                $args['s'] = sanitize_text_field($_GET['s']);
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                $args['ref'] = sanitize_text_field($_GET['ref']);
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                $args['time'] = absint($_GET['show']);
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                $args['order'] = sanitize_text_field($_GET['order']);
            }
            if (isset($_GET['start']) && isset($_GET['end'])) {
                $args['amount'] = array('start' => sanitize_text_field($_GET['start']), 'end' => sanitize_text_field($_GET['end']));
            } elseif (isset($_GET['num']) && isset($_GET['compare'])) {
                $args['amount'] = array('num' => sanitize_text_field($_GET['num']), 'compare' => $_GET['compare']);
            } elseif (isset($_GET['amount'])) {
                $args['amount'] = sanitize_text_field($_GET['amount']);
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                $args['paged'] = absint($_GET['paged']);
            }
            $log = new myCRED_Query_Log($args);
            unset($log->headers['column-username']);
            ?>
<div class="wrap" id="myCRED-wrap">
	<h2><?php 
            $this->page_title(sprintf(__('My %s History', 'mycred'), $this->core->plural()));
            ?>
</h2>

	<?php 
            $log->filter_dates(admin_url('users.php?page=' . $_GET['page']));
            ?>

	<?php 
            do_action('mycred_top_my_log_page', $this);
            ?>

	<?php 
            $log->exporter(__('Export', 'mycred'), true);
            ?>

	<form method="get" action="" name="mycred-mylog-form" novalidate>
<?php 
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                echo '<input type="hidden" name="s" value="' . $_GET['s'] . '" />';
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                echo '<input type="hidden" name="ref" value="' . $_GET['ref'] . '" />';
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                echo '<input type="hidden" name="show" value="' . $_GET['show'] . '" />';
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                echo '<input type="hidden" name="order" value="' . $_GET['order'] . '" />';
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                echo '<input type="hidden" name="paged" value="' . $_GET['paged'] . '" />';
            }
            $log->search();
            ?>
		<input type="hidden" name="page" value="<?php 
            echo $_GET['page'];
            ?>
" />

		<?php 
            do_action('mycred_above_my_log_table', $this);
            ?>

		<div class="tablenav top">

			<?php 
            $log->table_nav('top', true);
            ?>

		</div>

		<?php 
            $log->display();
            ?>

		<div class="tablenav bottom">

			<?php 
            $log->table_nav('bottom', true);
            ?>

		</div>

		<?php 
            do_action('mycred_bellow_my_log_table', $this);
            ?>

	</form>

	<?php 
            do_action('mycred_bottom_my_log_page', $this);
            ?>

</div>
<?php 
            $log->reset_query();
        }
        /**
         * Custom Log Page
         * @since 1.4
         * @version 1.3.1
         */
        public function purchase_log_page()
        {
            $type = substr($_GET['page'], 25);
            if ($type == 'mycred_default') {
                $mycred = $this->core;
            } else {
                $mycred = mycred($type);
            }
            // Security
            if (!$mycred->can_edit_creds()) {
                wp_die(__('Access Denied', 'mycred'));
            }
            $per_page = mycred_get_user_meta(get_current_user_id(), 'mycred_payments_' . $type, '', true);
            if (empty($per_page) || $per_page < 1) {
                $per_page = 10;
            }
            // Get references
            $references = apply_filters('mycred_buycred_log_refs', array('buy_creds_with_paypal_standard', 'buy_creds_with_skrill', 'buy_creds_with_zombaio', 'buy_creds_with_netbilling', 'buy_creds_with_bitpay'), $this, $type);
            // Prep
            $args = array('number' => $per_page, 'ctype' => $type, 'ref' => implode(',', $references));
            if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
                $args['user_id'] = $_GET['user_id'];
            }
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                $args['s'] = $_GET['s'];
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                $args['ref'] = $_GET['ref'];
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                $args['time'] = $_GET['show'];
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                $args['order'] = $_GET['order'];
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                $args['paged'] = $_GET['paged'];
            }
            if (isset($_GET['start']) && isset($_GET['end'])) {
                $args['amount'] = array('start' => $_GET['start'], 'end' => $_GET['end']);
            } elseif (isset($_GET['num']) && isset($_GET['compare'])) {
                $args['amount'] = array('num' => $_GET['num'], 'compare' => $_GET['compare']);
            } elseif (isset($_GET['amount'])) {
                $args['amount'] = $_GET['amount'];
            }
            $log = new myCRED_Query_Log($args);
            $log->headers = apply_filters('mycred_buycred_log_columns', array('column-gateway' => __('Gateway', 'mycred'), 'column-username' => __('Buyer', 'mycred'), 'column-date' => __('Date', 'mycred'), 'column-amount' => $mycred->plural(), 'column-payed' => __('Payed', 'mycred'), 'column-tranid' => __('Transaction ID', 'mycred')));
            $filter_url = admin_url('admin.php?page=myCRED_page_gateways_log_' . $type);
            ?>
<div class="wrap list" id="myCRED-wrap">
	<h2><?php 
            _e('<strong>buy</strong>CRED Purchase Log', 'mycred');
            ?>
 <a href="<?php 
            echo admin_url('admin.php?page=myCRED_page_gateways');
            ?>
" class="click-to-toggle add-new-h2"><?php 
            _e('Gateway Settings', 'mycred');
            ?>
</a> <a href="<?php 
            echo $this->get_settings_url('buycred_module');
            ?>
" class="click-to-toggle add-new-h2"><?php 
            _e('buyCRED Settings', 'mycred');
            ?>
</a></h2>
	<?php 
            $log->filter_dates(esc_url($filter_url));
            ?>

	<div class="clear"></div>
	<form method="get" action="">
<?php 
            if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
                echo '<input type="hidden" name="user_id" value="' . esc_attr($_GET['user_id']) . '" />';
            }
            if (isset($_GET['s']) && !empty($_GET['s'])) {
                echo '<input type="hidden" name="s" value="' . esc_attr($_GET['s']) . '" />';
            }
            if (isset($_GET['ref']) && !empty($_GET['ref'])) {
                echo '<input type="hidden" name="ref" value="' . esc_attr($_GET['ref']) . '" />';
            }
            if (isset($_GET['show']) && !empty($_GET['show'])) {
                echo '<input type="hidden" name="show" value="' . esc_attr($_GET['show']) . '" />';
            }
            if (isset($_GET['order']) && !empty($_GET['order'])) {
                echo '<input type="hidden" name="order" value="' . esc_attr($_GET['order']) . '" />';
            }
            if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                echo '<input type="hidden" name="paged" value="' . esc_attr($_GET['paged']) . '" />';
            }
            $log->search();
            ?>

		<input type="hidden" name="page" value="<?php 
            echo esc_attr($_GET['page']);
            ?>
" />
		<?php 
            do_action('mycred_above_payment_log_table', $this);
            ?>

		<div class="tablenav top">
<?php 
            $log->filter_options(false, $references);
            $log->navigation('top');
            ?>
		</div>
		<table class="table wp-list-table widefat mycred-table log-entries" cellspacing="0">
			<thead>
				<tr>
<?php 
            foreach ($log->headers as $col_id => $col_title) {
                echo '<th scope="col" id="' . str_replace('column-', '', $col_id) . '" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
            }
            ?>
				</tr>
			</thead>
			<tfoot>
				<tr>
<?php 
            foreach ($log->headers as $col_id => $col_title) {
                echo '<th scope="col" class="manage-column ' . $col_id . '">' . $col_title . '</th>';
            }
            ?>
				</tr>
			</tfoot>
			<tbody id="the-list">
<?php 
            // If we have results
            if ($log->have_entries()) {
                // Prep
                $date_format = get_option('date_format') . ' ' . get_option('time_format');
                $entry_data = '';
                $alt = 0;
                // Loop results
                foreach ($log->results as $log_entry) {
                    // Highlight alternate rows
                    $alt = $alt + 1;
                    if ($alt % 2 == 0) {
                        $class = ' alt';
                    } else {
                        $class = '';
                    }
                    // Prep Sales data for use in columns
                    $sales_data = $this->get_sales_data_from_log_data($log_entry->data);
                    list($buyer_id, $payer_id, $amount, $cost, $currency, $token, $other) = $sales_data;
                    // Default Currency
                    if (empty($currency)) {
                        $currency = 'USD';
                    }
                    $gateway_name = str_replace('buy_creds_with_', '', $log_entry->ref);
                    if (!array_key_exists(str_replace('_', '-', $gateway_name), $this->installed)) {
                        $style = ' style="color:silver;"';
                    } elseif (!$this->is_active(str_replace('_', '-', $gateway_name))) {
                        $style = ' style="color:gray;"';
                    } elseif (substr($log_entry->entry, 0, 4) == 'TEST') {
                        $style = ' style="color:orange;"';
                    } else {
                        $style = '';
                    }
                    echo '<tr class="myCRED-log-row' . $class . '" id="mycred-log-entry-' . $log_entry->id . '">';
                    // Run though columns
                    foreach ($log->headers as $column_id => $column_name) {
                        echo '<td class="' . $column_id . '"' . $style . '>';
                        switch ($column_id) {
                            // Used gateway
                            case 'column-gateway':
                                $gateway = str_replace(array('-', '_'), ' ', $gateway_name);
                                echo ucwords($gateway);
                                break;
                                // Username Column
                            // Username Column
                            case 'column-username':
                                $user = get_userdata($log_entry->user_id);
                                if ($user === false) {
                                    echo 'ID: ' . $log_entry->user_id;
                                } else {
                                    echo $user->display_name . ' <em><small>(ID: ' . $log_entry->user_id . ')</small></em>';
                                }
                                break;
                                // Date & Time Column
                            // Date & Time Column
                            case 'column-date':
                                echo date_i18n($date_format, $log_entry->time);
                                break;
                                // Amount Column
                            // Amount Column
                            case 'column-amount':
                                echo $mycred->format_creds($log_entry->creds);
                                break;
                                // Amount Paid
                            // Amount Paid
                            case 'column-payed':
                                if (empty($cost)) {
                                    echo 'n/a';
                                } else {
                                    echo number_format($cost, 2) . ' ' . $currency;
                                }
                                break;
                                // Transaction ID
                            // Transaction ID
                            case 'column-tranid':
                                $transaction_id = $log_entry->time . $log_entry->user_id;
                                $saved_data = maybe_unserialize($log_entry->data);
                                if (isset($saved_data['txn_id'])) {
                                    $transaction_id = $saved_data['txn_id'];
                                } elseif (isset($saved_data['transaction_id'])) {
                                    $transaction_id = $saved_data['transaction_id'];
                                }
                                echo $transaction_id;
                                break;
                            default:
                                do_action('mycred_payment_log_' . $column_id, $log_entry);
                                do_action('mycred_payment_log_' . $column_id . '_' . $type, $log_entry);
                                break;
                        }
                        echo '</td>';
                    }
                    echo '</tr>';
                }
            } else {
                echo '<tr><td colspan="' . count($log->headers) . '" class="no-entries">' . __('No purchases found', 'mycred') . '</td></tr>';
            }
            ?>
			</tbody>
		</table>
		<div class="tablenav bottom">

			<?php 
            $log->table_nav('bottom', false);
            ?>

		</div>
		<?php 
            do_action('mycred_below_payment_log_table', $this);
            ?>

	</form>
</div>
<?php 
        }