/**
  * 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);
 }
Beispiel #2
0
<?php

include_once 'includes/globalConfig.php';
Dune::setDatabaseCredentials($twlProjectCredentials);
function isfloat($f)
{
    return $f == (string) (double) $f;
}
print isfloat(false) . '<br>';
print isfloat(true) . '<br>';
print isfloat("") . '<br>';
print isfloat("abc") . '<br>';
print isfloat(2) . '<br>';
print isfloat("2") . '<br>';
print isfloat(2.3) . '<br>';
print isfloat("2.3") . '<br>';
 /**
  * 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);
 }
 /**
  * Save User Override
  * @since 1.5.2
  * @version 1.0.1
  */
 function save_user_override()
 {
     // Save interest rate
     if (isset($_POST['mycred_adjust_users_interest_rate_run']) && isset($_POST['mycred_adjust_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $rate = $_POST['mycred_adjust_users_interest_rate'];
         if ($rate != '') {
             if (isfloat($rate)) {
                 $rate = (double) $rate;
             } else {
                 $rate = (int) $rate;
             }
             mycred_update_user_meta($user_id, 'mycred_banking_rate_' . $ctype, '', $rate);
         } else {
             mycred_delete_user_meta($user_id, 'mycred_banking_rate_' . $ctype);
         }
         wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_rate')));
         exit;
     } elseif (isset($_POST['mycred_exclude_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $excluded = explode(',', $this->prefs['exclude_ids']);
         $clean_ids = array();
         if (!empty($excluded)) {
             foreach ($excluded as $id) {
                 if ($id == 0) {
                     continue;
                 }
                 $clean_ids[] = (int) trim($id);
             }
         }
         if (!in_array($user_id, $clean_ids) && $user_id != 0) {
             $clean_ids[] = $user_id;
         }
         $option_id = 'mycred_pref_bank';
         if (!$this->is_main_type) {
             $option_id .= '_' . $ctype;
         }
         $data = mycred_get_option($option_id);
         $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids);
         mycred_update_option($option_id, $data);
         wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_excluded')));
         exit;
     } elseif (isset($_POST['mycred_include_users_interest_rate'])) {
         $ctype = sanitize_key($_GET['ctype']);
         $user_id = absint($_GET['user_id']);
         $excluded = explode(',', $this->prefs['exclude_ids']);
         if (!empty($excluded)) {
             $clean_ids = array();
             foreach ($excluded as $id) {
                 $clean_id = (int) trim($id);
                 if ($clean_id != $user_id && $user_id != 0) {
                     $clean_ids[] = $clean_id;
                 }
             }
             $option_id = 'mycred_pref_bank';
             if (!$this->is_main_type) {
                 $option_id .= '_' . $ctype;
             }
             $data = mycred_get_option($option_id);
             $data['service_prefs'][$this->id]['exclude_ids'] = implode(',', $clean_ids);
             mycred_update_option($option_id, $data);
             wp_safe_redirect(add_query_arg(array('result' => 'banking_interest_included')));
             exit;
         }
     }
 }