Exemplo n.º 1
0
 /**
  * Do Payout
  * Runs though all user compounded interest and pays.
  * @since 1.2
  * @version 1.2.1
  */
 public function do_interest_batch($batch)
 {
     if (!empty($batch) && is_array($batch)) {
         set_time_limit($this->prefs['run_time']);
         foreach ($batch as $user_id) {
             $user_id = intval($user_id);
             // Get past interest
             $past_interest = mycred_get_user_meta($user_id, $this->core->get_cred_id() . '_comp', '', true);
             if (empty($past_interest) || $past_interest == 0) {
                 continue;
             }
             // Pay / Charge
             $this->core->add_creds('payout', $user_id, $past_interest, $this->prefs['log']);
             // Reset past interest
             mycred_update_user_meta($user_id, $this->core->get_cred_id() . '_comp', '', 0);
         }
     }
 }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
 /**
  * Accepting Invites
  * @since 0.1
  * @version 1.2
  */
 public function accept_invite($invited_user_id, $inviters = array())
 {
     if (empty($inviters)) {
         return;
     }
     // Invite Anyone will pass on an array of user IDs of those who have invited this user which we need to loop though
     foreach ((array) $inviters as $inviter_id) {
         // Limit Check
         if ($this->prefs['accept_invite']['limit'] != 0) {
             $key = 'mycred_invite_anyone';
             if (!$this->is_main_type) {
                 $key .= '_' . $this->mycred_type;
             }
             $user_log = mycred_get_user_meta($inviter_id, $key, '', true);
             if (empty($user_log['accepted'])) {
                 $user_log['accepted'] = 0;
             }
             // Continue to next inviter if limit is reached
             if ($user_log['accepted'] >= $this->prefs['accept_invite']['limit']) {
                 continue;
             }
         }
         // Award Points
         $run = true;
         if (function_exists('buddypress') && apply_filters('bp_core_signup_send_activation_key', true)) {
             $run = false;
             // Get pending list
             $pending = get_transient('mycred-pending-bp-signups');
             if ($pending === false) {
                 $pending = array();
             }
             // Add to pending list if not there already
             if (!isset($pending[$invited_user_id])) {
                 $pending[$invited_user_id] = $inviter_id;
                 delete_transient('mycred-pending-bp-signups');
                 set_transient('mycred-pending-bp-signups', $pending, 7 * DAY_IN_SECONDS);
             }
         }
         if ($run) {
             $this->core->add_creds('accepting_an_invite', $inviter_id, $this->prefs['accept_invite']['creds'], $this->prefs['accept_invite']['log'], $invited_user_id, array('ref_type' => 'user'), $this->mycred_type);
         }
         // Update Limit
         if ($this->prefs['accept_invite']['limit'] != 0) {
             $user_log['accepted'] = $user_log['accepted'] + 1;
             mycred_update_user_meta($inviter_id, $key, '', $user_log);
         }
     }
 }
        /**
         * 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 
        }
        /**
         * Subscription Shortcode
         * @since 1.4.6
         * @version 1.0
         */
        public function render_subscription_shortcode($attr, $content = NULL)
        {
            extract(shortcode_atts(array('success' => __('Settings saved.', 'mycred')), $attr));
            if (!is_user_logged_in()) {
                return $content;
            }
            $user_id = get_current_user_id();
            $unsubscriptions = mycred_get_user_meta($user_id, 'mycred_email_unsubscriptions', '', true);
            if ($unsubscriptions == '') {
                $unsubscriptions = array();
            }
            // Save
            $saved = false;
            if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'mycred-unsubscribe' && wp_verify_nonce($_REQUEST['token'], 'update-mycred-email-subscriptions')) {
                if (isset($_POST['mycred_email_unsubscribe']) && !empty($_POST['mycred_email_unsubscribe'])) {
                    $new_selection = $_POST['mycred_email_unsubscribe'];
                } else {
                    $new_selection = array();
                }
                mycred_update_user_meta($user_id, 'mycred_email_unsubscriptions', '', $new_selection);
                $unsubscriptions = $new_selection;
                $saved = true;
            }
            global $wpdb;
            $email_notices = $wpdb->get_results($wpdb->prepare("\n\t\t\t\tSELECT * \n\t\t\t\tFROM {$wpdb->posts} notices\n\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} prefs \n\t\t\t\t\tON ( notices.ID = prefs.post_id AND prefs.meta_key = 'mycred_email_settings' )\n\n\t\t\t\tWHERE notices.post_type = 'mycred_email_notice' \n\t\t\t\t\tAND notices.post_status = 'publish'\n\t\t\t\t\tAND ( prefs.meta_value LIKE %s OR prefs.meta_value LIKE %s );", '%s:9:"recipient";s:4:"user";%', '%s:9:"recipient";s:4:"both";%'));
            ob_start();
            if ($saved) {
                echo '<p class="updated-email-subscriptions">' . $success . '</p>';
            }
            $url = add_query_arg(array('do' => 'mycred-unsubscribe', 'user' => get_current_user_id(), 'token' => wp_create_nonce('update-mycred-email-subscriptions')));
            ?>
<form action="<?php 
            echo esc_url($url);
            ?>
" id="mycred-email-subscriptions" method="post">
	<table class="table">
		<thead>
			<tr>
				<th class="check"><?php 
            _e('Unsubscribe', 'mycred');
            ?>
</th>
				<th class="notice-title"><?php 
            _e('Email Notice', 'mycred');
            ?>
</th>
			</tr>
		</thead>
		<tbody>

		<?php 
            if (!empty($email_notices)) {
                ?>
		
			<?php 
                foreach ($email_notices as $notice) {
                    $settings = $this->get_email_settings($notice->ID);
                    ?>

			<?php 
                    if ($settings['label'] == '') {
                        continue;
                    }
                    ?>

			<tr>
				<td class="check"><input type="checkbox" name="mycred_email_unsubscribe[]"<?php 
                    if (in_array($notice->ID, $unsubscriptions)) {
                        echo ' checked="checked"';
                    }
                    ?>
 value="<?php 
                    echo $notice->ID;
                    ?>
" /></td>
				<td class="notice-title"><?php 
                    echo $settings['label'];
                    ?>
</td>
			</tr>

			<?php 
                }
                ?>
		
		<?php 
            } else {
                ?>

			<tr>
				<td colspan="2"><?php 
                _e('There are no email notifications yet.', 'mycred');
                ?>
</td>
			</tr>

		<?php 
            }
            ?>

		</tbody>
	</table>
	<input type="submit" class="btn btn-primary button button-primary pull-right" value="<?php 
            _e('Save Changes', 'mycred');
            ?>
" />
</form>
<?php 
            $content = ob_get_contents();
            ob_end_clean();
            return apply_filters('mycred_render_email_subscriptions', $content, $attr);
        }
Exemplo n.º 6
0
 /**
  * Get Users Limit
  * @since 1.4
  * @version 1.0
  */
 public function get_users_limit($user_id, $limit)
 {
     $key = 'mycred_bbp_limits_' . $limit;
     if (!$this->is_main_type) {
         $key .= '_' . $this->mycred_type;
     }
     return (array) mycred_get_user_meta($user_id, $key, '', true);
 }
 function mycred_user_got_promoted($user_id = NULL, $rank_id = NULL)
 {
     $type = get_post_meta($rank_id, 'ctype', true);
     if ($type == '') {
         $type = 'mycred_default';
         update_post_meta($rank_id, 'ctype', $type);
     }
     $end = '';
     if ($type != 'mycred_default') {
         $end = $type;
     }
     $current_rank_id = mycred_get_user_meta($user_id, 'mycred_rank', $end, true);
     // No promotion
     if ($current_rank_id == $rank_id) {
         return false;
     }
     // User did not have a rank before but will have now, that is assumed to be a promotion
     if (empty($current_rank_id) && !empty($rank_id)) {
         return true;
     }
     // Get minimums
     if (!mycred_override_settings()) {
         $current_min = get_post_meta($current_rank_id, 'mycred_rank_min', true);
         $new_min = get_post_meta($rank_id, 'mycred_rank_min', true);
     } else {
         $original_blog_id = get_current_blog_id();
         switch_to_blog(1);
         $current_min = get_post_meta($current_rank_id, 'mycred_rank_min', true);
         $new_min = get_post_meta($rank_id, 'mycred_rank_min', true);
         switch_to_blog($original_blog_id);
     }
     // Compare
     if ($new_min > $current_min) {
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
 function mycred_check_if_user_gets_badge($user_id = NULL, $request = array(), $badge_ids = array())
 {
     if ($user_id === NULL || empty($badge_ids)) {
         return;
     }
     global $wpdb;
     foreach ($badge_ids as $badge_id) {
         // See if user already has badge
         if (mycred_get_user_meta($user_id, 'mycred_badge' . $badge_id, '', true) != '') {
             continue;
         }
         $requirements = mycred_get_badge_requirements($badge_id);
         $needs = $requirements[0];
         $mycred = mycred($needs['type']);
         $mycred_log = $mycred->log_table;
         if ($needs['by'] == 'count') {
             $select = 'COUNT( * )';
             $amount = $needs['amount'];
         } else {
             $select = 'SUM( creds )';
             $amount = $mycred->number($needs['amount']);
         }
         $result = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT {$select} \n\t\t\tFROM {$mycred_log} \n\t\t\tWHERE user_id = %d \n\t\t\t\tAND ctype = %s \n\t\t\t\tAND ref = %s;", $user_id, $needs['type'], $needs['reference']));
         // If this function is used by the mycred_add filter, we need to take into
         // account the instance that we are currently being hooked into as the log entry
         // will be added after this code has executed.
         // In case we sum up, add the points the user will gain to the result
         if (!isset($request['done']) && $needs['by'] == 'sum') {
             $result = $result + $request['amount'];
         } elseif (!isset($request['done']) && $needs['by'] == 'count') {
             $result = $result + 1;
         }
         if ($needs['by'] != 'count') {
             $result = $mycred->number($result);
         }
         // Got it!
         if ($result >= $amount) {
             mycred_update_user_meta($user_id, 'mycred_badge' . $badge_id, '', apply_filters('mycred_badge_user_value', 1, $user_id, $badge_id));
         }
     }
 }
 /**
  * Get Cost
  * @since 1.3.2
  * @version 1.1
  */
 function get_cost($amount = 0, $type = 'mycred_default', $raw = false)
 {
     // Apply minimum
     if ($amount < $this->core->buy_creds['minimum']) {
         $amount = $this->core->buy_creds['minimum'];
     }
     // Calculate cost here so we can use any exchange rate
     if (isset($this->prefs['exchange'][$type])) {
         // Check for user override
         $override = mycred_get_user_meta($this->current_user_id, 'mycred_buycred_rates_' . $type, '', true);
         if (isset($override[$this->id]) && $override[$this->id] != '') {
             $rate = $override[$this->id];
         } else {
             $rate = $this->prefs['exchange'][$type];
         }
         if (isfloat($rate)) {
             $rate = (double) $rate;
         } else {
             $rate = (int) $rate;
         }
         $mycred = mycred($type);
         $cost = $mycred->number($amount) * $rate;
     } else {
         $cost = $amount;
     }
     // Return a properly formated cost so PayPal is happy
     if (!$raw) {
         $cost = number_format($cost, 2, '.', '');
     }
     return apply_filters('mycred_buycred_get_cost', $cost, $amount, $type, $this->prefs, $this->core->buy_creds);
 }
Exemplo n.º 10
0
 /**
  * Make Purchase AJAX
  * @since 1.1
  * @version 1.3
  */
 public function make_purchase_ajax()
 {
     // We must be logged in
     if (!is_user_logged_in()) {
         die;
     }
     // Security
     check_ajax_referer('mycred-buy-content-ajax', 'token');
     // Prep
     $post_id = $_POST['postid'];
     $user_id = get_current_user_id();
     $action = 'buy-content-ajax';
     $sell_content = $this->sell_content;
     $prefs = $this->get_sale_prefs($post_id);
     if (!$this->user_paid($user_id, $post_id) && $this->user_can_buy($user_id, $prefs['price'])) {
         $post = get_post($post_id);
         // Charge
         $this->core->add_creds('buy_content', $user_id, 0 - $prefs['price'], $sell_content['logs']['buy'], $post_id, array('ref_type' => 'post', 'purchase_id' => 'TXID' . date_i18n('U'), 'seller' => $post->post_author), $this->mycred_type);
         $request = compact('action', 'post_id', 'user_id', 'author', 'post_type', 'sell_content', 'prefs');
         do_action('mycred_sell_content_purchase_ready', $request);
         // Pay
         if ($sell_content['pay'] == 'author') {
             // Check if author has a custom share
             $users_share = mycred_get_user_meta($post->post_author, 'mycred_sell_content_share_' . $this->mycred_type, '', true);
             if ($users_share == '') {
                 $users_share = $sell_content['pay_percent'];
             }
             if (isfloat($users_share)) {
                 $users_share = (double) $users_share;
             } else {
                 $users_share = (int) $users_share;
             }
             $payout = $users_share / 100 * $prefs['price'];
             $this->core->add_creds('buy_content', $post->post_author, $payout, $sell_content['logs']['sell'], $post_id, array('ref_type' => 'post', 'purchase_id' => 'TXID' . date_i18n('U'), 'buyer' => $user_id), $this->mycred_type);
         }
         // $match[1] = start tag, $match[2] = settings, $match[3] = content, $match[4] = end tag
         preg_match("'(\\[mycred_sell_this_ajax(.{1,})\\])(.*?)(\\[\\/mycred_sell_this_ajax\\])'si", $post->post_content, $match);
         // Filter content before returning
         $content = apply_filters('the_content', $match[3]);
         $content = str_replace(']]>', ']]&gt;', $content);
         $content = do_shortcode($content);
     } else {
         $content = '<p>' . __('You can not buy this content.', 'mycred') . '</p>';
     }
     die($content);
 }
 function mycred_get_users_transfer_history($user_id, $type = 'mycred_default', $key = NULL)
 {
     if ($key === NULL) {
         $key = 'mycred_transactions';
     }
     if ($type != 'mycred_default' && $type != '') {
         $key .= '_' . $type;
     }
     $default = array('frame' => '', 'amount' => 0);
     return mycred_apply_defaults($default, mycred_get_user_meta($user_id, $key, '', true));
 }
        /**
         * User Override
         * @since 1.5.2
         * @version 1.0
         */
        function user_override($user = NULL, $type = 'mycred_default')
        {
            $users_rate = mycred_get_user_meta($user->ID, 'mycred_banking_rate_' . $type);
            $excluded = $this->exclude_user($user->ID);
            ?>

<h3><?php 
            _e('Compound Interest', 'mycred');
            ?>
</h3>

<?php 
            if ($excluded == 'list') {
                ?>

<table class="form-table">
	<tr>
		<td colspan="2"><?php 
                _e('This user is excluded from receiving interest on this balance.', 'mycred');
                ?>
</td>
	</tr>
	<tr>
		<td colspan="2"><?php 
                submit_button(__('Remove from Excluded List', 'mycred'), 'primary medium', 'mycred_include_users_interest_rate', false);
                ?>
</td>
	</tr>
</table>

<?php 
            } elseif ($excluded == 'role') {
                ?>

<table class="form-table">
	<tr>
		<td colspan="2"><?php 
                _e('This user role is excluded from receiving interest on this balance.', 'mycred');
                ?>
</td>
	</tr>
</table>

<?php 
            } else {
                ?>

<table class="form-table">
	<tr>
		<th scope="row"><?php 
                _e('Interest Rate', 'mycred');
                ?>
</th>
		<td>
			<input type="text" name="mycred_adjust_users_interest_rate" id="mycred-adjust-users-interest-rate" value="<?php 
                echo $users_rate;
                ?>
" placeholder="<?php 
                echo $this->prefs['rate']['amount'];
                ?>
" size="8" /> %<br />
			<span class="description"><?php 
                _e('Leave empty to use the default value.', 'mycred');
                ?>
</span>
		</td>
	</tr>
	<tr>
		<th scope="row"></th>
		<td>
			<?php 
                submit_button(__('Save Interest Rate', 'mycred'), 'primary medium', 'mycred_adjust_users_interest_rate_run', false);
                ?>
 
			<?php 
                submit_button(__('Exclude from receiving interest', 'mycred'), 'primary medium', 'mycred_exclude_users_interest_rate', false);
                ?>
		</td>
	</tr>
</table>
<?php 
            }
        }
Exemplo n.º 13
0
        /**
         * import function.
         */
        function import($file)
        {
            global $wpdb, $mycred;
            $this->imported = $this->skipped = 0;
            if (!is_file($file)) {
                echo '<p><strong>' . __('Sorry, there has been an error.', 'mycred') . '</strong><br />';
                echo __('The file does not exist, please try again.', 'mycred') . '</p>';
                $this->footer();
                die;
            }
            ini_set('auto_detect_line_endings', '1');
            if (($handle = fopen($file, "r")) !== FALSE) {
                $header = fgetcsv($handle, 0, $this->delimiter);
                $no_of_columns = sizeof($header);
                if ($no_of_columns == 3 || $no_of_columns == 4) {
                    $loop = 0;
                    $mycred_types = mycred_get_types();
                    while (($row = fgetcsv($handle, 0, $this->delimiter)) !== FALSE) {
                        $log_entry = '';
                        if ($no_of_columns == 3) {
                            list($id, $balance, $point_type) = $row;
                        } else {
                            list($id, $balance, $point_type, $log_entry) = $row;
                        }
                        $user = false;
                        if (is_numeric($id)) {
                            $user = get_userdata($id);
                        }
                        if ($user === false) {
                            $user = get_user_by('email', $id);
                        }
                        if ($user === false) {
                            $user = get_user_by('login', $id);
                        }
                        if ($user === false) {
                            $this->skipped++;
                            continue;
                        }
                        if (!isset($mycred_types[$point_type])) {
                            if ($point_type != '') {
                                $log_entry = $point_type;
                            }
                        }
                        if ($point_type == '') {
                            $point_type = 'mycred_default';
                        }
                        $method = trim($_POST['method']);
                        if ($method == 'add') {
                            $current_balance = mycred_get_user_meta($user->ID, $point_type, '', true);
                            $balance = $current_balance + $balance;
                        }
                        mycred_update_user_meta($user->ID, $point_type, '', $balance);
                        if (!empty($log_entry)) {
                            $wpdb->insert($mycred->log_table, array('ref' => 'import', 'ref_id' => NULL, 'user_id' => $user->ID, 'creds' => $mycred->number($balance), 'ctype' => $point_type, 'time' => date_i18n('U'), 'entry' => sanitize_text_field($log_entry), 'data' => ''));
                        }
                        $loop++;
                        $this->imported++;
                    }
                } else {
                    echo '<p><strong>' . __('Sorry, there has been an error.', 'mycred') . '</strong><br />';
                    echo __('The CSV is invalid.', 'mycred') . '</p>';
                    $this->footer();
                    die;
                }
                fclose($handle);
            }
            // Show Result
            echo '<div class="updated settings-error below-h2"><p>
				' . sprintf(__('Import complete - A total of <strong>%d</strong> balances were successfully imported. <strong>%d</strong> was skipped.', 'mycred'), $this->imported, $this->skipped) . '
			</p></div>';
            $this->import_end();
        }
Exemplo n.º 14
0
 /**
  * Update Daily Limit
  * Updates a given users daily limit.
  * @since 1.3.3
  * @version 1.1
  */
 public function update_daily_limit($user_id, $id)
 {
     // No limit used
     if ($this->prefs[$id]['limit'] == 0) {
         return;
     }
     $today = date_i18n('Y-m-d');
     $key = 'mycred_simplepress_limits_' . $id;
     if (!$this->is_main_type) {
         $key .= '_' . $this->mycred_type;
     }
     $current = mycred_get_user_meta($user_id, $key, '', true);
     if (empty($current) || !array_key_exists($today, (array) $current)) {
         $current[$today] = 0;
     }
     $current[$today] = $current[$today] + 1;
     mycred_update_user_meta($user_id, $key, '', $current);
 }
Exemplo n.º 15
0
 /**
  * Get users balance
  * Returns the users balance unformated.
  *
  * @param $user_id (int), required user id
  * @param $type (string), optional cred type to check for
  * @returns zero if user id is not set or if no creds were found, else returns amount
  * @since 0.1
  * @version 1.4
  */
 public function get_users_balance($user_id = NULL, $type = NULL)
 {
     if ($user_id === NULL) {
         return $this->zero();
     }
     $types = mycred_get_types();
     if ($type === NULL || !array_key_exists($type, $types)) {
         $type = $this->get_cred_id();
     }
     $balance = mycred_get_user_meta($user_id, $type, '', true);
     if ($balance == '') {
         $balance = $this->zero();
     }
     // Let others play
     $balance = apply_filters('mycred_get_users_cred', $balance, $this, $user_id, $type);
     return $this->number($balance);
 }
 function mycred_check_if_user_gets_badge($user_id = NULL, $badge_ids = array(), $save = true)
 {
     if ($user_id === NULL || empty($badge_ids)) {
         return;
     }
     global $wpdb;
     $ids = array();
     foreach ($badge_ids as $badge_id) {
         $level = false;
         $requirements = mycred_get_badge_requirements($badge_id);
         foreach ($requirements as $req_level => $needs) {
             if ($needs['type'] == '') {
                 $needs['type'] = 'mycred_default';
             }
             $mycred = mycred($needs['type']);
             // Count occurences
             if ($needs['by'] == 'count') {
                 $select = 'COUNT( * )';
                 $amount = absint($needs['amount']);
             } else {
                 $select = 'SUM( creds )';
                 $amount = $mycred->number($needs['amount']);
             }
             $result = $wpdb->get_var(apply_filters('mycred_if_user_gets_badge_sql', $wpdb->prepare("\n\t\t\t\t\tSELECT {$select} \n\t\t\t\t\tFROM {$mycred->log_table} \n\t\t\t\t\tWHERE user_id = %d \n\t\t\t\t\t\tAND ctype = %s \n\t\t\t\t\t\tAND ref = %s;", $user_id, $needs['type'], $needs['reference']), $user_id, $badge_id, $req_level, $needs));
             if ($result === NULL) {
                 $result = 0;
             }
             if ($needs['by'] != 'count') {
                 $result = $mycred->number($result);
             } else {
                 $result = absint($result);
             }
             $level = NULL;
             if ($result >= $amount) {
                 $level = absint($req_level);
             }
             $current = mycred_get_user_meta($user_id, 'mycred_badge' . $badge_id, '', true);
             if ($current == '') {
                 $current = -1;
             }
             // If a level has been reached assign it now unless the user has this level already
             if ($level !== NULL && $current < $level) {
                 if ($save) {
                     mycred_update_user_meta($user_id, 'mycred_badge' . $badge_id, '', apply_filters('mycred_badge_user_value', $level, $user_id, $badge_id));
                 }
                 $ids[$badge_id] = $level;
             }
         }
     }
     return $ids;
 }
 /**
  * Get Ref ID
  * Returns a given users referral ID.
  * @since 1.4
  * @version 1.0
  */
 public function get_ref_id($user_id)
 {
     // Link format
     switch ($this->prefs['setup']['links']) {
         case 'username':
             $user = get_userdata($user_id);
             if ($user === false) {
                 $ref_id = 0;
             } else {
                 $ref_id = urlencode($user->user_login);
             }
             break;
         case 'numeric':
             $ref_id = mycred_get_user_meta($user_id, 'mycred_affiliate_link', '', true);
             if (empty($ref_id)) {
                 $counter = absint(get_option('mycred_affiliate_counter', 0));
                 $number = $counter + 1;
                 update_option('mycred_affiliate_counter', $number);
                 mycred_update_user_meta($user_id, 'mycred_affiliate_link', '', $number);
                 $ref_id = $number;
             }
             break;
     }
     return apply_filters('mycred_affiliate_get_ref_id', $ref_id, $user_id, $this);
 }
Exemplo n.º 18
0
 function mycred_user_got_promoted($user_id = NULL, $rank_id = NULL)
 {
     $current_rank_id = mycred_get_user_meta($user_id, 'mycred_rank', '', true);
     if ($current_rank_id == $rank_id) {
         return false;
     }
     if (empty($current_rank_id) && !empty($rank_id)) {
         return true;
     }
     if (!mycred_override_settings()) {
         $current_min = get_post_meta($current_rank_id, 'mycred_rank_min', true);
         $new_min = get_post_meta($rank_id, 'mycred_rank_min', true);
     } else {
         $original_blog_id = get_current_blog_id();
         switch_to_blog(1);
         $current_min = get_post_meta($current_rank_id, 'mycred_rank_min', true);
         $new_min = get_post_meta($rank_id, 'mycred_rank_min', true);
         switch_to_blog($original_blog_id);
     }
     if ($new_min > $current_min) {
         return true;
     }
     return false;
 }