/** * Construct */ function __construct() { // Default settings $defaults = array('setup' => 'off', 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => array('purchase' => __('Payment for tickets to %link_with_title%', 'mycred'), 'refund' => __('Ticket refund for %link_with_title%', 'mycred')), 'refund' => 0, 'labels' => array('header' => __('Pay using your %_plural% balance', 'mycred'), 'button' => __('Pay Now', 'mycred'), 'link' => __('Pay', 'mycred'), 'checkout' => __('%plural% Cost', 'mycred')), 'messages' => array('success' => __('Thank you for your payment!', 'mycred'), 'error' => __("I'm sorry but you can not pay for these tickets using %_plural%", 'mycred'))); // Settings $settings = get_option('mycred_eventsmanager_gateway_prefs'); $this->prefs = mycred_apply_defaults($defaults, $settings); $this->mycred_type = $this->prefs['type']; // Load myCRED $this->core = mycred($this->mycred_type); // Apply Whitelabeling $this->label = mycred_label(); $this->title = strip_tags($this->label); $this->status_txt = 'Paid using ' . strip_tags($this->label); parent::__construct(); if (!$this->is_active()) { return; } // Currency add_filter('em_get_currencies', array($this, 'add_currency')); if ($this->single_currency()) { add_filter('em_get_currency_formatted', array($this, 'format_price'), 10, 4); } // Adjust Ticket Columns add_filter('em_booking_form_tickets_cols', array($this, 'ticket_columns'), 10, 2); add_action('em_booking_form_tickets_col_mycred', array($this, 'ticket_col'), 10, 2); add_filter('em_bookings_table_cols_col_action', array($this, 'bookings_table_actions'), 10, 2); add_action('em_cart_form_after_totals', array($this, 'checkout_total')); // Refund if ($this->prefs['refund'] != 0) { add_filter('em_booking_set_status', array($this, 'refunds'), 10, 2); } }
function the_quiz_button($button, $quiz_id) { global $post; $quiz_id = get_the_ID(); $user_id = get_current_user_id(); $flag = 1; if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { $pid = get_post_meta($quiz_id, 'vibe_quiz_product', true); if (isset($pid) && is_numeric($pid) && get_post_type($pid) == 'product') { $product_taken = wc_customer_bought_product('', $user_id, $pid); if (!$product_taken) { $pid = get_permalink($pid); $check = vibe_get_option('direct_checkout'); $check = intval($check); if (isset($check) && $check) { $pid .= '?redirect'; } $flag = 0; $html = '<a href="' . $pid . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>'; } else { $flag = 1; } } } if (in_array('paid-memberships-pro/paid-memberships-pro.php', apply_filters('active_plugins', get_option('active_plugins'))) && is_user_logged_in()) { $membership_ids = vibe_sanitize(get_post_meta($quiz_id, 'vibe_quiz_membership', false)); if (!pmpro_hasMembershipLevel($membership_ids, $user_id) && isset($membership_ids) && count($membership_ids) >= 1) { $membership_taken = get_user_meta($user_id, $quiz_id, true); if (!$membership_taken) { $pmpro_levels_page_id = get_option('pmpro_levels_page_id'); $link = get_permalink($pmpro_levels_page_id); $html = '<a href="' . $link . '"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '</a>'; $flag = 0; } else { $flag = 1; } } } if (in_array('wplms-mycred-addon/wplms-mycred-addon.php', apply_filters('active_plugins', get_option('active_plugins')))) { $points = get_post_meta($quiz_id, 'vibe_quiz_mycred_points', true); $mycred = mycred(); $balance = $mycred->get_users_cred($user_id); if ($balance < $points) { $flag = 0; $html = '<a href="#"class="button create-group-button full"> ' . __('Take this Quiz', 'vibe') . '<span>' . __('<br/>Not enough points.', 'vibe') . '</span></a>'; } if (!$mycred->has_entry('purchase_quiz', $quiz_id, $user_id)) { $flag = 1; $deduct = -1 * $points; $mycred->update_users_balance($user_id, $deduct); $mycred->add_to_log('purchase_quiz', $user_id, $deduct, __('Student subscibed to quiz', 'wplms-mycred'), $quiz_id); } else { $flag = 1; } } if (!$flag) { return $html; } return $button; }
/** * Construct */ function __construct($args = array(), $service_prefs = NULL) { if (!empty($args)) { foreach ($args as $key => $value) { $this->{$key} = $value; } } // Grab myCRED Settings $this->core = mycred(); // Grab settings if ($service_prefs !== NULL) { // Assign prefs if set if (isset($service_prefs[$this->id])) { $this->prefs = $service_prefs[$this->id]; } // Defaults must be set if (!isset($this->defaults) || empty($this->defaults)) { $this->defaults = array(); } } // Apply default settings if needed if (!empty($this->defaults)) { $this->prefs = wp_parse_args($this->prefs, $this->defaults); } }
/** * Construct */ function __construct($args = array(), $hook_prefs = NULL, $type = 'mycred_default') { if (!empty($args)) { foreach ($args as $key => $value) { $this->{$key} = $value; } } // Grab myCRED Settings $this->core = mycred($type); if (!empty($type)) { $this->core->cred_id = sanitize_text_field($type); $this->mycred_type = $this->core->cred_id; } if ($this->mycred_type != 'mycred_default') { $this->is_main_type = false; } // Grab settings if ($hook_prefs !== NULL) { // Assign prefs if set if (isset($hook_prefs[$this->id])) { $this->prefs = $hook_prefs[$this->id]; } // Defaults must be set if (!isset($this->defaults)) { $this->defaults = array(); } } // Apply default settings if needed if (!empty($this->defaults)) { $this->prefs = mycred_apply_defaults($this->defaults, $this->prefs); } }
/** * Construct */ function __construct() { // Default settings $defaults = array('labels' => array('gateway' => $this->label, 'payment' => $this->label . ' ' . __('Payments', 'mycred'), 'button' => __('Pay Now', 'mycred')), 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => __('Payment for Event Registration', 'mycred'), 'messages' => array('solvent' => 'Click "Pay Now" to pay using your %plural%.', 'insolvent' => 'Unfortunately you do not have enough %plural% to pay for this event.', 'visitors' => 'Payments using %_plural% is only available for registered members.')); // Settings $settings = get_option('mycred_espresso_gateway_prefs'); $this->prefs = mycred_apply_defaults($defaults, $settings); $this->mycred_type = $this->prefs['type']; // Load myCRED $this->core = mycred($this->mycred_type); }
/** * Construct */ function __construct() { parent::__construct('myCRED_Sell_Content_Module', array('module_name' => 'sell_content', 'register' => false, 'defaults' => array('post_types' => 'post,page', 'type' => 'mycred_default', 'pay' => 'none', 'pay_percent' => 100, 'templates' => array('members' => '<p>Buy this %post_type% for only %price% %buy_button%</p>', 'visitors' => '<p><a href="%login_url_here%">Login</a> to buy access to this %post_type%.</p>', 'cantafford' => "<p>You do not have enough %plural% to buy access to this %post_type%.</p>\n<p><strong>Price</strong>: %price%</p>"), 'defaults' => array('price' => 10, 'overwrite_price' => 0, 'button_label' => __('Buy Now', 'mycred'), 'overwrite_buttonlabel' => 0, 'expire' => 0), 'logs' => array('buy' => 'Purchase of %link_with_title%', 'sell' => 'Sale of %link_with_title%')), 'add_to_core' => true)); // Adjust Module to the selected point type $this->mycred_type = 'mycred_default'; if (isset($this->sell_content['type'])) { $this->mycred_type = $this->sell_content['type']; } $this->core = mycred($this->mycred_type); add_filter('mycred_email_before_send', array($this, 'email_notices'), 10, 2); }
function mycred_bbp_add_balance_in_profile() { $user_id = bbp_get_displayed_user_id(); $mycred = mycred(); if ($mycred->exclude_user($user_id)) { return; } $balance = $mycred->get_users_cred($user_id, $mycred->mycred_type); $layout = $mycred->plural() . ': ' . $mycred->format_creds($balance); $layout = apply_filters('mycred_bbp_authors_profile_balance', $layout, $balance, $user_id); echo apply_filters('mycred_bbp_profile_balance', '<div class="users-mycred-balance">' . $layout . '</div>', $user_id, $balance); }
function mycred_render_shortcode_load_coupon($atts, $content = NULL) { if (!is_user_logged_in()) { return $content; } $mycred = mycred(); if (!isset($mycred->coupons)) { return '<p><strong>Coupon Add-on settings are missing! Please visit the myCRED > Settings page to save your settings before using this shortcode.</strong></p>'; } // Prep $output = ' <div class="mycred-coupon-form">'; $user_id = get_current_user_id(); // No show for excluded users if ($mycred->exclude_user($user_id)) { return ''; } // On submits if (isset($_POST['mycred_coupon_load']['token']) && wp_verify_nonce($_POST['mycred_coupon_load']['token'], 'mycred-load-coupon' . $user_id)) { $coupon = mycred_get_coupon_post($_POST['mycred_coupon_load']['couponkey']); $load = mycred_use_coupon($_POST['mycred_coupon_load']['couponkey'], $user_id); // Coupon does not exist if ($load === 'missing') { $output .= '<p class="mycred-coupon-status">' . $mycred->coupons['invalid'] . '</p>'; } elseif ($load === 'expired') { $output .= '<p class="mycred-coupon-status">' . $mycred->coupons['expired'] . '</p>'; } elseif ($load === 'max') { $output .= '<p class="mycred-coupon-status">' . $mycred->coupons['user_limit'] . '</p>'; } elseif ($load === 'min_balance') { $min = get_post_meta($coupon->ID, 'min', true); $template = str_replace('%min%', $min, $mycred->coupons['min']); $output .= '<p class="mycred-coupon-status">' . $template . '</p>'; } elseif ($load === 'max_balance') { $max = get_post_meta($coupon->ID, 'max', true); $template = str_replace('%max%', $max, $mycred->coupons['max']); $output .= '<p class="mycred-coupon-status">' . $template . '</p>'; } else { $output .= '<p class="mycred-coupon-status">' . $mycred->coupons['success'] . '</p>'; } } $output .= ' <form action="" method="post"> <p> <label for="mycred-coupon-code">' . __('Coupon', 'mycred') . '</label><br /> <input type="text" name="mycred_coupon_load[couponkey]" id="mycred-coupon-couponkey" value="" /> <input type="hidden" name="mycred_coupon_load[token]" value="' . wp_create_nonce('mycred-load-coupon' . $user_id) . '" /> <input type="submit" class="btn btn-primary btn-large button button-large button-primary" value="' . __('Apply Coupon', 'mycred') . '" /> </p> </form> </div>'; return apply_filters('mycred_load_coupon', $output, $atts, $content); }
/** * Construct */ function __construct() { // Default settings $defaults = array('setup' => 'off', 'type' => 'mycred_default', 'rate' => 100, 'share' => 0, 'log' => array('purchase' => __('Payment for tickets to %link_with_title%', 'mycred'), 'refund' => __('Ticket refund for %link_with_title%', 'mycred')), 'refund' => 0, 'labels' => array('header' => __('Pay using your %_plural% balance', 'mycred'), 'button' => __('Pay Now', 'mycred'), 'link' => __('Pay', 'mycred')), 'messages' => array('success' => __('Thank you for your payment!', 'mycred'), 'error' => __("I'm sorry but you can not pay for these tickets using %_plural%", 'mycred'))); // Settings $settings = get_option('mycred_eventsmanager_gateway_prefs'); $this->prefs = mycred_apply_defaults($defaults, $settings); $this->mycred_type = $this->prefs['type']; // Load myCRED $this->core = mycred($this->mycred_type); // Apply Whitelabeling $this->label = mycred_label(); }
/** * Widget Output */ public function widget($args, $instance) { extract($args, EXTR_SKIP); // Prep $title = $instance['title']; $mycred = mycred(); if (!isset($mycred->transfers)) { return '<p>' . __('The myCRED Transfer add-on has not yet been setup!', 'mycred') . '</p>'; } $pref = $mycred->transfers; global $mycred_load_transfer; // Members if (is_user_logged_in()) { // Excluded users $user_id = get_current_user_id(); if ($mycred->exclude_user($user_id)) { return; } echo $before_widget; // Title if (!empty($title)) { echo $before_title; echo $mycred->template_tags_general($title); echo $after_title; } // Prep shortcode $attr = array('show_balance' => $instance['show_balance'], 'show_limit' => $instance['show_limit']); if (isset($instance['button']) && !empty($instance['button'])) { $attr['button'] = $instance['button']; } echo mycred_transfer_render($attr, ''); $mycred_load_transfer = true; echo $after_widget; } else { $mycred_load = false; // If login message is set if (!empty($pref['templates']['login'])) { echo $before_widget; if (!empty($instance['title'])) { echo $before_title; echo $mycred->template_tags_general($title); echo $after_title; } // Show login message echo '<p>' . $mycred->template_tags_general($pref['templates']['login']) . '</p>'; echo $after_widget; } return; } }
public function __toString() { $mycred = mycred(); $count = 1; $output = '<ul class="wl-leaderboard">'; foreach ($this->data as $position => $data) { $avatar = get_avatar($data->user_id, 24); $output .= "<li>{$avatar}<span><strong>{$data->user_login}</strong> avec " . $mycred->format_creds($data->total) . '</span>'; $output .= "<span class=\"pull\">{$count}</span>"; $output .= '</li>'; $count++; } $output .= '</ul>'; return $output; }
/** * Construct */ function __construct($module_id = '', $args = array(), $type = 'mycred_default') { // Module ID is required if (empty($module_id)) { wp_die('myCRED_Module() Error. A Module ID is required!'); } $this->module_id = $module_id; $this->core = mycred($type); if (!empty($type)) { $this->core->cred_id = sanitize_text_field($type); $this->mycred_type = $this->core->cred_id; } if ($this->mycred_type != 'mycred_default') { $this->is_main_type = false; } $this->point_types = mycred_get_types(); // Default arguments $defaults = array('module_name' => '', 'option_id' => '', 'defaults' => array(), 'labels' => array('menu' => '', 'page_title' => ''), 'register' => true, 'screen_id' => '', 'add_to_core' => false, 'accordion' => false, 'cap' => 'plugin', 'menu_pos' => 10); $args = wp_parse_args($args, $defaults); $this->module_name = $args['module_name']; $this->option_id = $args['option_id']; if (!$this->is_main_type) { $this->option_id .= '_' . $this->mycred_type; } $this->settings_name = 'myCRED-' . $this->module_name; if (!$this->is_main_type) { $this->settings_name .= '-' . $this->mycred_type; } $this->labels = $args['labels']; $this->register = $args['register']; $this->screen_id = $args['screen_id']; if (!$this->is_main_type && !empty($this->screen_id)) { $this->screen_id = 'myCRED_' . $this->mycred_type . substr($this->screen_id, 6); } $this->add_to_core = $args['add_to_core']; $this->accordion = $args['accordion']; $this->cap = $args['cap']; $this->menu_pos = $args['menu_pos']; $this->default_prefs = $args['defaults']; $this->current_user_id = get_current_user_id(); $this->now = current_time('timestamp'); $this->set_settings(); }
public function widget($args, $instance) { if (!$instance['show_visitors'] && !is_user_logged_in()) { return; } $leaderboard = WL_Leaderboard::current($instance['number']); $mycred = mycred(); // Start constructing Widget $output = $args['before_widget']; // Title (if not empty) if (!empty($instance['title'])) { $output .= $args['before_title']; // Allow general template tags in the title $output .= $mycred->template_tags_general($instance['title']); $output .= $args['after_title']; } $output .= $leaderboard; $output .= $args['after_widget']; echo $output; }
/** * Get Spending * @version 1.0 */ function get_spending() { global $wpdb; if ($this->args['ctypes'] == 'all') { $point_types = $this->ctypes; } else { $point_types = array($this->args['ctypes'] => $this->ctypes[$this->args['ctypes']]); } $series = $ctypes = $categories = array(); $num = 0; if (count($point_types) > 0) { foreach ($point_types as $type_id => $label) { $num++; $count = $wpdb->get_var("SELECT COUNT( * ) FROM {$this->core->log_table} WHERE ctype = '{$type_id}';"); if ($count === NULL) { $count = $num; } $ctypes[$count] = $type_id; } ksort($ctypes, SORT_NUMERIC); } foreach ($ctypes as $count => $type_id) { $values = array(); foreach ($this->dates as $date) { $query = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT SUM( creds ) \n\t\t\t\t\t\tFROM {$this->core->log_table} \n\t\t\t\t\t\tWHERE creds < 0 \n\t\t\t\t\t\tAND ctype = %s \n\t\t\t\t\t\tAND time BETWEEN %d AND %d;", $type_id, $date['from'], $date['until'])); if ($query === NULL) { $query = 0; } $values[] = abs($query); if (!in_array($date['label'], $categories)) { $categories[] = esc_attr($date['label']); } } $mycred = mycred($type_id); $series[] = "{ label : '" . esc_js($mycred->plural()) . "', fillColor : '" . str_replace(',1)', ',0.3)', $this->colors[$type_id]) . "', strokeColor : '" . $this->colors[$type_id] . "', pointColor : '" . $this->colors[$type_id] . "', data : [" . implode(', ', $values) . "] }"; } return array('categories' => $categories, 'series' => $series); }
/** * Construct * @since 1.6 * @version 1.0 */ public function __construct() { // Get all types $this->point_types = mycred_get_types(); // Get the used type (if used) $type = 'mycred_default'; $currency = affiliate_wp()->settings->get('currency', 'mycred_default'); if (array_key_exists($currency, $this->point_types)) { $type = $currency; } // Load myCRED $this->mycred = mycred($type); }
/** * Request Related Template Tags * @since 1.1 * @version 1.2.1 */ public function template_tags_request($content, $request) { $type = $this->core; if ($request['type'] != 'mycred_default') { $type = mycred($request['type']); } $user_id = $request['user_id']; $new_balance = $type->get_users_balance($user_id, $request['type']); $content = str_replace('%new_balance%', $new_balance, $content); $content = str_replace('%new_balance_f%', $type->format_creds($new_balance), $content); if ($request['amount'] > 0) { $old_balance = $type->number($new_balance - $request['amount']); } else { $old_balance = $type->number($new_balance + $request['amount']); } $content = str_replace('%old_balance%', $old_balance, $content); $content = str_replace('%old_balance_f%', $type->format_creds($old_balance), $content); $content = str_replace('%amount%', $request['amount'], $content); $content = str_replace('%entry%', $request['entry'], $content); $content = str_replace('%data%', $request['data'], $content); $content = str_replace('%blog_name%', get_option('blogname'), $content); $content = str_replace('%blog_url%', get_option('home'), $content); $content = str_replace('%blog_info%', get_option('blogdescription'), $content); $content = str_replace('%admin_email%', get_option('admin_email'), $content); $content = str_replace('%num_members%', $this->core->count_members(), $content); // Badges related if (function_exists('mycred_ref_has_badge') && isset($request['badges'])) { $titles = array(); $images = array(); foreach ($request['badges'] as $level => $badge_id) { $badge_id = absint($badge_id); $title = sprintf(_x('%s - Level %d', 'Badge Title - Level 1,2,3..', 'mycred'), get_the_title($badge_id), $level); $titles[] = $title; // Level image first $level_image = get_post_meta($badge_id, 'level_image' . $level, true); // Default to main image if ($level_image == '') { $level_image = get_post_meta($badge_id, 'main_image', true); } if ($level_image == '') { $images[] = '<img src="' . $level_image . '" alt="' . $title . '" />'; } } $title = implode(', ', $titles); $content = str_replace('%badge_title%', $title, $content); $image = implode(' ', $images); $content = str_replace('%badge_image%', $image, $content); } return $content; }
/** * 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 }
/** * Setup Step 2 - Presentation * In this step we get to name our creds along with settup how creds are shown around * the website. * @since 0.1 * @version 1.2 */ protected function setup_step2() { if (!$this->step) { return; } $mycred = mycred(); // Capabilities $edit_plugin = isset($_POST['myCRED-cap-plugin']) ? sanitize_text_field($_POST['myCRED-cap-plugin']) : 'manage_options'; $edit_creds = isset($_POST['myCRED-cap-creds']) ? sanitize_text_field($_POST['myCRED-cap-creds']) : 'export'; // Max $max = isset($_POST['myCRED-max']) ? $mycred->number($_POST['myCRED-max']) : $mycred->number(0); // Excludes $exclude_plugin_editors = isset($_POST['myCRED-exclude-plugin-editors']) ? 1 : 0; $exclude_cred_editors = isset($_POST['myCRED-exclude-cred-editors']) ? 1 : 0; $exclude_list = isset($_POST['myCRED-exclude-list']) ? $_POST['myCRED-exclude-list'] : ''; $delete_user = isset($_POST['delete_user']) ? 1 : 0; ?> <form method="post" action="" class="setup step3"> <input type="hidden" name="step" value="3" /> <input type="hidden" name="token" value="<?php echo wp_create_nonce('myCRED-setup-step3'); ?> " /> <h2><?php _e('Security', 'mycred'); ?> </h2> <ol class="inline"> <li> <label for="myCRED-cap-plugin"><?php _e('Edit Settings Capability', 'mycred'); ?> </label> <h2><input type="text" name="myCRED-cap-plugin" id="myCRED-cap-plugin" value="<?php echo $edit_plugin; ?> " /></h2> </li> <li> <label for="myCRED-cap-creds"><?php echo $mycred->template_tags_general(__('Edit Users %plural% Capability', 'mycred')); ?> </label> <h2><input type="text" name="myCRED-cap-creds" id="myCRED-cap-creds" value="<?php echo $edit_creds; ?> " /></h2> </li> <li class="block"> <label for="myCRED-max"><?php echo $mycred->template_tags_general(__('Maximum %plural% payouts', 'mycred')); ?> </label> <div class="h2"><input type="text" name="myCRED-max" id="myCRED-max" value="<?php echo $max; ?> " size="8" /></div> <div class="description"><?php _e('As an added security, you can set the maximum amount a user can gain or loose in a single instance. If used, make sure this is the maximum amount a user would be able to transfer, buy, or spend in your store. Use zero to disable.', 'mycred'); ?> </div> </li> </ol> <h2><?php _e('Excludes', 'mycred'); ?> </h2> <ol> <li> <input type="checkbox" name="myCRED-exclude-plugin-editors" id="myCRED-exclude-plugin"<?php checked($exclude_plugin_editors, 1); ?> value="1" class="checkbox" /> <label for="myCRED-exclude-plugin"><?php _e('Exclude those who can "Edit Settings".', 'mycred'); ?> </label> </li> <li style="width: 100%;"> <input type="checkbox" name="myCRED-exclude-cred-editors" id="myCRED-exclude-caps"<?php checked($exclude_cred_editors, 1); ?> value="1" class="checkbox" /> <label for="myCRED-exclude-caps"><?php echo $mycred->template_tags_general(__('Exclude those who can "Edit Users %plural%".', 'mycred')); ?> </label> </li> <li> <label for="myCRED-exclude-list"><?php _e('Exclude the following user IDs:', 'mycred'); ?> </label> <h2><input type="text" name="myCRED-exclude-list" id="myCRED-exclude-list" value="<?php echo $exclude_list; ?> " /></h2> </li> </ol> <h2><?php _e('User Deletions', 'mycred'); ?> </h2> <ol> <li> <input type="checkbox" name="myCRED-delete-user" id="myCRED-delete-user"<?php checked($delete_user, 1); ?> value="1" class="checkbox" /> <label for="myCRED-delete-user"><?php _e('Delete log entries when user is deleted.', 'mycred'); ?> </label> </li> </ol> <p class="action-row"><input type="submit" class="button button-primary button-large" name="being-setup" value="<?php _e('Next', 'mycred'); ?> " /></p> </form> <?php }
function mycred_count_users_with_rank($rank_id = NULL) { if ($rank_id === NULL) { return 0; } $type = get_post_meta($rank_id, 'ctype', true); if ($type == '') { return 0; } $mycred = mycred($type); $rank_meta_key = 'mycred_rank'; if ($mycred->is_multisite && $GLOBALS['blog_id'] > 1 && !$mycred->use_master_template) { $rank_meta_key .= '_' . $GLOBALS['blog_id']; } if ($type != 'mycred_default') { $rank_meta_key .= $type; } global $wpdb; $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT( user_id ) FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %d;", $rank_meta_key, $rank_id)); if ($count === NULL) { $count = 0; } return $count; }
function mycred_use_coupon($code = '', $user_id = 0) { // Missing required information if (empty($code) || $user_id === 0) { return 'missing'; } // Get coupon by code (post title) $coupon = mycred_get_coupon_post($code); // Coupon does not exist if ($coupon === NULL) { return 'missing'; } // Check Expiration $now = current_time('timestamp'); $expires = mycred_get_coupon_expire_date($coupon->ID, true); if (!empty($expires) && $expires !== 0 && $expires <= $now) { wp_trash_post($coupon->ID); return 'expired'; } // Get Global Count $global_count = mycred_get_global_coupon_count($coupon->ID); // We start with enforcing the global count $global_max = mycred_get_coupon_global_max($coupon->ID); if ($global_count >= $global_max) { wp_trash_post($coupon->ID); return 'expired'; } $type = get_post_meta($coupon->ID, 'type', true); if ($type == '') { $type = 'mycred_default'; } $mycred = mycred($type); // Get User max $user_count = mycred_get_users_coupon_count($code, $user_id); // Next we enforce the user max $user_max = mycred_get_coupon_user_max($coupon->ID); if ($user_count >= $user_max) { return 'max'; } // Min balance requirement $users_balance = $mycred->get_users_cred($user_id, $type); $min_balance = mycred_get_coupon_min_balance($coupon->ID); if ($min_balance > $mycred->zero() && $users_balance < $min_balance) { return 'min_balance'; } // Max balance requirement $max_balance = mycred_get_coupon_max_balance($coupon->ID); if ($max_balance > $mycred->zero() && $users_balance >= $max_balance) { return 'max_balance'; } // Ready to use coupon! $value = mycred_get_coupon_value($coupon->ID); $value = $mycred->number($value); // Get Coupon log template if (!isset($mycred->core['coupons']['log'])) { $mycred->core['coupons']['log'] = 'Coupon redemption'; } // Apply Coupon $mycred->add_creds('coupon', $user_id, $value, $mycred->core['coupons']['log'], $coupon->ID, $code, $type); do_action('mycred_use_coupon', $user_id, $coupon); // Increment global counter $global_count++; update_post_meta($coupon->ID, 'global_count', $global_count); // If the updated counter reaches the max, trash the coupon now if ($global_count >= $global_max) { wp_trash_post($coupon->ID); } return $mycred->number($users_balance + $value); }
/** @see WP_Widget::widget -- do not rename this */ function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $width = $instance['width']; $num = $instance['num']; $user_id = get_current_user_id(); echo '<div class="' . $width . '"> <div class="dash-widget">' . $before_widget; if ($title) { echo $before_title . $title . $after_title; } global $wpdb; $table = $wpdb->prefix . 'myCRED_log'; $query = $wpdb->prepare("\n SELECT creds,ref,time as t\n FROM {$table} AS mycred\n WHERE mycred.user_id = %d\n ORDER BY mycred.time DESC\n LIMIT 0,%d", $user_id, $num); $spends = $wpdb->get_results($query); $mycred = mycred(); $current_balance = $mycred->get_users_cred($user_id); $total = array(); if (is_array($spends)) { foreach ($spends as $k => $spend) { $sales_pie[$spend->ref] += round($spend->creds, 0); $sales[$spend->t] += $spend->creds; } } else { $points = array(); } $i = 0; if (is_array($sales)) { foreach ($sales as $key => $value) { $i++; if ($i == 1) { $total[$key] = $current_balance; } else { if ($i <= count($sales)) { $total[$key] = $total[$prev_key[$i - 1]] - $sales[$prev_key[$i - 1]]; } } $prev_key[$i] = $key; } } if (isset($sales) && is_array($sales)) { ksort($sales); foreach ($sales as $key => $value) { $points_array[$key] = array('date' => date('d-M-y', $key), 'sales' => $value, 'total' => $total[$key]); } } echo '<div id="mycred_points_data" class="morris"></div>'; echo '<div class="row"> <div class="col-md-6"> <label class="sales_labels">' . __('Action', 'wplms-dashboard') . '<strong>' . __('Variation', 'wplms-dashboard') . ' </strong></label> <div class="course_list">'; $sales_pie_array = array(); if (isset($sales_pie) && is_array($sales_pie) && count($sales_pie)) { echo '<ul class="course_sales_list">'; foreach ($sales_pie as $ctitle => $sales) { $ctitle = str_replace('_', ' ', $ctitle); echo '<li>' . $ctitle . '<strong>' . ($sales < 0 ? '(-)' . $sales * -1 : $sales) . '</strong></li>'; $sales_pie_array[] = array('label' => $ctitle, 'value' => $sales < 0 ? $sales * -1 : $sales); } echo '</ul>'; } else { echo '<div class="message"><p>' . __('No data found', 'wplms-dashboard') . '</p></div>'; } echo '</div></div><div class="col-md-6"> <div id="mycred_points_breakup" class="morris"></div> </div></div>'; echo '</div></div>'; echo '<script> var mycred_points_data=['; $first = 0; if (isset($points_array) && is_array($points_array)) { foreach ($points_array as $data) { if ($first) { echo ','; } $first = 1; echo str_replace('"', '\'', json_encode($data, JSON_NUMERIC_CHECK)); } } echo ']; var mycred_points_breakup =['; $first = 0; if (isset($sales_pie_array) && is_Array($sales_pie_array)) { foreach ($sales_pie_array as $data) { if ($first) { echo ','; } $first = 1; echo str_replace('"', '\'', json_encode($data, JSON_NUMERIC_CHECK)); } } echo ']; </script>'; }
/** * Construct */ public function __construct($args = array(), $array = false) { if (empty($args)) { return false; } global $wpdb; $select = $where = $sortby = $limits = ''; $prep = $wheres = array(); // Load General Settings if (isset($args['ctype'])) { $type = $args['ctype']; } else { $type = 'mycred_default'; } $this->core = mycred($type); if ($this->core->format['decimals'] > 0) { $format = '%f'; } else { $format = '%d'; } // Prep Defaults $defaults = array('user_id' => NULL, 'ctype' => 'mycred_default', 'number' => 25, 'time' => NULL, 'ref' => NULL, 'ref_id' => NULL, 'amount' => NULL, 's' => NULL, 'data' => NULL, 'orderby' => 'time', 'offset' => '', 'order' => 'DESC', 'ids' => false, 'cache' => '', 'paged' => $this->get_pagenum()); $this->args = wp_parse_args($args, $defaults); // Difference between default and given args $this->diff = array_diff_assoc($this->args, $defaults); if (isset($this->diff['number'])) { unset($this->diff['number']); } $data = false; if ($this->args['cache'] != '') { $cache_id = substr($this->args['cache'], 0, 23); if (is_multisite()) { $data = get_site_transient('mycred_log_query_' . $cache_id); } else { $data = get_transient('mycred_log_query_' . $cache_id); } } if ($data === false) { // Type $wheres[] = 'ctype = %s'; $prep[] = $this->args['ctype']; // User ID if ($this->args['user_id'] !== NULL && $this->args['user_id'] != '') { $user_id = $this->get_user_id($this->args['user_id']); if ($user_id !== false) { $wheres[] = 'user_id = %d'; $prep[] = $user_id; } } // Reference if ($this->args['ref'] !== NULL && $this->args['ref'] != '') { $refs = explode(',', $this->args['ref']); $ref_count = count($refs); if ($ref_count > 1) { $ref_count = $ref_count - 1; $wheres[] = 'ref IN (%s' . str_repeat(',%s', $ref_count) . ')'; foreach ($refs as $ref) { $prep[] = sanitize_text_field($ref); } } else { $wheres[] = 'ref = %s'; $prep[] = sanitize_text_field($refs[0]); } } // Reference ID if ($this->args['ref_id'] !== NULL && $this->args['ref_id'] != '') { $ref_ids = explode(',', $this->args['ref_id']); if (count($ref_ids) > 1) { $ref_id_count = count($ref_ids) - 1; $wheres[] = 'ref_id IN (%d' . str_repeat(',%d', $ref_id_count) . ')'; foreach ($ref_ids as $ref_id) { $prep[] = (int) sanitize_text_field($ref_id); } } else { $wheres[] = 'ref_id = %d'; $prep[] = (int) sanitize_text_field($this->args['ref_id']); } } // Amount if ($this->args['amount'] !== NULL && $this->args['amount'] != '') { // Advanced query if (is_array($this->args['amount'])) { // Range if (isset($this->args['amount']['start']) && isset($this->args['amount']['end'])) { $wheres[] = 'creds BETWEEN ' . $format . ' AND ' . $format; $prep[] = $this->core->number(sanitize_text_field($this->args['amount']['start'])); $prep[] = $this->core->number(sanitize_text_field($this->args['amount']['end'])); } elseif (isset($this->args['amount']['num']) && isset($this->args['amount']['compare'])) { $compare = urldecode($this->args['amount']['compare']); $wheres[] = 'creds ' . trim($compare) . ' ' . $format; $prep[] = $this->core->number(sanitize_text_field($this->args['amount']['num'])); } } else { $amounts = explode(',', $this->args['amount']); $amount_count = count($amounts); if ($amount_count > 1) { $amount_count = $amount_count - 1; $wheres[] = 'amount IN (' . $format . str_repeat(',' . $format, $ref_id_count) . ')'; foreach ($amount_count as $amount) { $prep[] = $this->core->number(sanitize_text_field($amount)); } } else { $wheres[] = 'creds = ' . $format; $prep[] = $this->core->number(sanitize_text_field($amounts[0])); } } } // Time if ($this->args['time'] !== NULL && $this->args['time'] != '') { $now = date_i18n('U'); $today = strtotime(date_i18n('Y/m/d') . ' midnight'); $todays_date = date_i18n('d'); // Show todays entries if ($this->args['time'] == 'today') { $wheres[] = "time BETWEEN {$today} AND {$now}"; } elseif ($this->args['time'] == 'yesterday') { $yesterday = strtotime('-1 day midnight'); $wheres[] = "time BETWEEN {$yesterday} AND {$today}"; } elseif ($this->args['time'] == 'thisweek') { $weekday = date_i18n('w'); // New week started today so show only todays if (get_option('start_of_week') == $weekday) { $wheres[] = "time BETWEEN {$today} AND {$now}"; } else { $week_start = strtotime('-' . ($weekday + 1) . ' days midnight'); $wheres[] = "time BETWEEN {$week_start} AND {$now}"; } } elseif ($this->args['time'] == 'thismonth') { $start_of_month = strtotime(date_i18n('Y/m/01') . ' midnight'); $wheres[] = "time BETWEEN {$start_of_month} AND {$now}"; } else { $times = explode(',', $this->args['time']); if (count($times) == 2) { $from = sanitize_key($times[0]); $to = sanitize_key($times[1]); $wheres[] = "time BETWEEN {$from} AND {$to}"; } } } // Entry Search if ($this->args['s'] !== NULL && $this->args['s'] != '') { $search_query = sanitize_text_field($this->args['s']); if (is_int($search_query)) { $search_query = (string) $search_query; } $wheres[] = "entry LIKE %s"; $prep[] = "%{$search_query}%"; } // Data if ($this->args['data'] !== NULL && $this->args['data'] != '') { $data_query = sanitize_text_field($this->args['data']); if (is_int($data_query)) { $data_query = (string) $data_query; } $wheres[] = "data LIKE %s"; $prep[] = $data_query; } // Order by if ($this->args['orderby'] != '') { // Make sure $sortby is valid $sortbys = array('id', 'ref', 'ref_id', 'user_id', 'creds', 'ctype', 'entry', 'data', 'time'); $allowed = apply_filters('mycred_allowed_sortby', $sortbys); if (in_array($this->args['orderby'], $allowed)) { $sortby = "ORDER BY " . $this->args['orderby'] . " " . $this->args['order']; } } // Number of results $number = $this->args['number']; if ($number < -1) { $number = abs($number); } elseif ($number == 0 || $number == -1) { $number = NULL; } // Limits if ($number !== NULL) { $page = 1; if ($this->args['paged'] !== NULL) { $page = absint($this->args['paged']); if (!$page) { $page = 1; } } if ($this->args['offset'] == '') { $pgstrt = ($page - 1) * $number . ', '; } else { $offset = absint($this->args['offset']); $pgstrt = $offset . ', '; } $limits = 'LIMIT ' . $pgstrt . $number; } else { $limits = ''; } // Prep return if ($this->args['ids'] === true) { $select = 'id'; } else { $select = '*'; } $found_rows = ''; if ($limits != '') { $found_rows = 'SQL_CALC_FOUND_ROWS'; } // Filter $select = apply_filters('mycred_query_log_select', $select, $this->args, $this->core); $sortby = apply_filters('mycred_query_log_sortby', $sortby, $this->args, $this->core); $limits = apply_filters('mycred_query_log_limits', $limits, $this->args, $this->core); $wheres = apply_filters('mycred_query_log_wheres', $wheres, $this->args, $this->core); $prep = apply_filters('mycred_query_log_prep', $prep, $this->args, $this->core); $where = 'WHERE ' . implode(' AND ', $wheres); // Run $this->request = $wpdb->prepare("SELECT {$found_rows} {$select} FROM {$this->core->log_table} {$where} {$sortby} {$limits}", $prep); $this->prep = $prep; $this->results = $wpdb->get_results($this->request, $array ? ARRAY_A : OBJECT); if ($limits != '') { $this->num_rows = $wpdb->get_var('SELECT FOUND_ROWS()'); } else { $this->num_rows = count($this->results); } if ($limits != '') { $this->max_num_pages = ceil($this->num_rows / $number); } if ($this->args['cache'] != '') { if (is_multisite()) { set_site_transient('mycred_log_query_' . $cache_id, $this->results, DAY_IN_SECONDS * 1); } else { set_transient('mycred_log_query_' . $cache_id, $this->results, DAY_IN_SECONDS * 1); } } $this->total_rows = $wpdb->get_var("SELECT COUNT( * ) FROM {$this->core->log_table}"); } else { $this->request = 'transient'; $this->results = $data; $this->prep = ''; $this->num_rows = count($data); } $this->headers = $this->table_headers(); }
/** * Buy Handler * @since 0.1 * @version 1.2 */ public function buy() { if (!isset($this->prefs['account']) || empty($this->prefs['account'])) { wp_die(__('Please setup this gateway before attempting to make a purchase!', 'mycred')); } // Location $location = 'https://www.moneybookers.com/app/payment.pl'; // Type $type = $this->get_point_type(); $mycred = mycred($type); // Amount $amount = $mycred->number($_REQUEST['amount']); $amount = abs($amount); // Get Cost $cost = $this->get_cost($amount, $type); $to = $this->get_to(); $from = get_current_user_id(); // Revisiting pending payment if (isset($_REQUEST['revisit'])) { $this->transaction_id = strtoupper($_REQUEST['revisit']); } else { $post_id = $this->add_pending_payment(array($to, $from, $amount, $cost, $this->prefs['currency'], $type)); $this->transaction_id = get_the_title($post_id); } // Thank you page $thankyou_url = $this->get_thankyou(); // Cancel page $cancel_url = $this->get_cancelled($this->transaction_id); // Start constructing merchant details $hidden_fields = array('pay_to_email' => $this->prefs['account'], 'transaction_id' => $this->transaction_id, 'return_url' => $thankyou_url, 'cancel_url' => $cancel_url, 'status_url' => $this->callback_url(), 'return_url_text' => __('Return to ', 'mycred') . get_bloginfo('name'), 'hide_login' => 1); // Customize Checkout Page if (isset($this->prefs['account_title']) && !empty($this->prefs['account_title'])) { $hidden_fields = array_merge_recursive($hidden_fields, array('recipient_description' => $mycred->template_tags_general($this->prefs['account_title']))); } if (isset($this->prefs['account_logo']) && !empty($this->prefs['account_logo'])) { $hidden_fields = array_merge_recursive($hidden_fields, array('logo_url' => $this->prefs['account_logo'])); } if (isset($this->prefs['confirmation_note']) && !empty($this->prefs['confirmation_note'])) { $hidden_fields = array_merge_recursive($hidden_fields, array('confirmation_note' => $mycred->template_tags_general($this->prefs['confirmation_note']))); } // If we want an email receipt for purchases if (isset($this->prefs['email_receipt']) && !empty($this->prefs['email_receipt'])) { $hidden_fields = array_merge_recursive($hidden_fields, array('status_url2' => $this->prefs['account'])); } // Item Name $item_name = str_replace('%number%', $amount, $this->prefs['item_name']); $item_name = $mycred->template_tags_general($item_name); // Hidden form fields $sale_details = array('merchant_fields' => 'sales_data', 'sales_data' => $this->transaction_id, 'amount' => $cost, 'currency' => $this->prefs['currency'], 'detail1_description' => __('Product:', 'mycred'), 'detail1_text' => $item_name); $hidden_fields = array_merge_recursive($hidden_fields, $sale_details); // Gifting if ($to != $from) { $user = get_userdata($to); $gift_details = array('detail2_description' => __('Gift to:', 'mycred'), 'detail2_text' => $user->display_name . ' ' . __('(author)', 'mycred')); $hidden_fields = array_merge_recursive($hidden_fields, $gift_details); unset($user); } // Generate processing page $this->get_page_header(__('Processing payment …', 'mycred')); $this->get_page_redirect($hidden_fields, $location); $this->get_page_footer(); exit; }
function mycred_woo_payout_rewards($order_id) { // Get Order $order = new WC_Order($order_id); // If we paid with myCRED we do not award points by default if ($order->payment_method == 'mycred' && apply_filters('mycred_woo_reward_mycred_payment', false) === false) { return; } // Get items $items = $order->get_items(); // Get point types $types = mycred_get_types(); // Loop foreach ($types as $type => $label) { // Load type $mycred = mycred($type); // Check for exclusions if ($mycred->exclude_user($order->user_id)) { continue; } // Calculate reward $reward = $mycred->zero(); foreach ($items as $item) { $prefs = (array) get_post_meta($item['product_id'], 'mycred_reward', true); if (isset($prefs[$type]) && $prefs[$type] != '') { $reward = $reward + $prefs[$type] * $item['qty']; } } // Award if ($reward != $mycred->zero()) { // Let others play with the reference and log entry $reference = apply_filters('mycred_woo_reward_reference', 'reward', $order_id, $type); $log = apply_filters('mycred_woo_reward_log', '%plural% reward for store purchase', $order_id, $type); // Execute $mycred->add_creds($reference, $order->user_id, $reward, $log, $order_id, array('ref_type' => 'post'), $type); } } }
/** * Admin Footer * Inserts the Inline Edit Form modal. * @since 1.2 * @version 1.3.1 */ public function admin_footer() { // Security if (!$this->core->can_edit_creds()) { return; } $screen = get_current_screen(); if ($screen->id == 'users') { if ($this->core->can_edit_creds() && !$this->core->can_edit_plugin()) { $req = '(<strong>' . __('required', 'mycred') . '</strong>)'; } else { $req = '(' . __('optional', 'mycred') . ')'; } ob_start(); ?> <div id="edit-mycred-balance" style="display: none;"> <div class="mycred-adjustment-form"> <p class="row inline" style="width: 20%"><label><?php _e('ID', 'mycred'); ?> :</label><span id="mycred-userid"></span></p> <p class="row inline" style="width: 40%"><label><?php _e('User', 'mycred'); ?> :</label><span id="mycred-username"></span></p> <p class="row inline" style="width: 40%"><label><?php _e('Current Balance', 'mycred'); ?> :</label> <span id="mycred-current"></span></p> <div class="clear"></div> <input type="hidden" name="mycred_update_users_balance[token]" id="mycred-update-users-balance-token" value="<?php echo wp_create_nonce('mycred-update-users-balance'); ?> " /> <input type="hidden" name="mycred_update_users_balance[type]" id="mycred-update-users-balance-type" value="" /> <p class="row"><label for="mycred-update-users-balance-amount"><?php _e('Amount', 'mycred'); ?> :</label><input type="text" name="mycred_update_users_balance[amount]" id="mycred-update-users-balance-amount" value="" /><br /><span class="description"><?php _e('A positive or negative value', 'mycred'); ?> .</span></p> <p class="row"><label for="mycred-update-users-balance-entry"><?php _e('Log Entry', 'mycred'); ?> :</label><input type="text" name="mycred_update_users_balance[entry]" id="mycred-update-users-balance-entry" value="" /><br /><span class="description"><?php echo $req; ?> </span></p> <p class="row"><input type="button" name="mycred-update-users-balance-submit" id="mycred-update-users-balance-submit" value="<?php _e('Update Balance', 'mycred'); ?> " class="button button-primary button-large" /></p> <div class="clear"></div> </div> <div class="clear"></div> </div> <?php $content = ob_get_contents(); ob_end_clean(); echo apply_filters('mycred_admin_inline_editor', $content); } elseif ($screen->id == 'user-edit' || $screen->id == 'profile' || $screen->id == 'users_page_bp-profile-edit') { global $bp; if ($this->using_bp && version_compare($bp->version, '2.1', '>=')) { $types = mycred_get_types(); $user_id = get_current_user_id(); if (isset($_GET['user_id'])) { $user_id = (int) $_GET['user_id']; } $tabs = array(); foreach ($types as $type => $label) { $mycred = mycred($type); if ($mycred->exclude_user($user_id)) { continue; } $classes = 'nav-tab'; if (isset($_GET['ctype']) && $_GET['ctype'] == $type) { $classes .= ' nav-tab-active'; } $tabs[] = array('label' => $mycred->plural(), 'url' => esc_url(add_query_arg(array('page' => 'mycred-edit-balance', 'user_id' => $user_id, 'ctype' => $type), admin_url('users.php'))), 'classes' => $classes); } $user = get_userdata($user_id); $tabs = apply_filters('mycred_edit_profile_tabs_bp', $tabs, $user); $output = ''; foreach ($tabs as $tab) { $output .= '<a class="' . $tab['classes'] . '" href="' . $tab['url'] . '">' . esc_attr($tab['label']) . '</a>'; } ob_start(); ?> <script type="text/javascript"> jQuery(document).ready(function($) { $( 'h2#profile-nav' ).append( '<?php echo $output; ?> ' ); }); </script> <?php $content = ob_get_contents(); ob_end_clean(); echo apply_filters('mycred_admin_bp_nav', $content); } } }
function mycred_catch_exchange_requests() { if (!isset($_POST['mycred_exchange']['nonce']) || !wp_verify_nonce($_POST['mycred_exchange']['nonce'], 'mycred-exchange')) { return; } // Decode token $token = mycred_verify_token($_POST['mycred_exchange']['token'], 5); if ($token === false) { return; } global $mycred_exchange; list($from, $to, $user_id, $rate, $min) = $token; // Check point types $types = mycred_get_types(); if (!array_key_exists($from, $types) || !array_key_exists($to, $types)) { $mycred_exchange = array('success' => false, 'message' => __('Point types not found.', 'mycred')); return; } $user_id = get_current_user_id(); // Check for exclusion $mycred_from = mycred($from); if ($mycred_from->exclude_user($user_id)) { $mycred_exchange = array('success' => false, 'message' => sprintf(__('You are excluded from using %s.', 'mycred'), $mycred_from->plural())); return; } // Check balance $balance = $mycred_from->get_users_balance($user_id, $from); if ($balance < $mycred_from->number($min)) { $mycred_exchange = array('success' => false, 'message' => __('Your balance is too low to use this feature.', 'mycred')); return; } // Check for exclusion $mycred_to = mycred($to); if ($mycred_to->exclude_user($user_id)) { $mycred_exchange = array('success' => false, 'message' => sprintf(__('You are excluded from using %s.', 'mycred'), $mycred_to->plural())); return; } // Prep Amount $amount = abs($_POST['mycred_exchange']['amount']); $amount = $mycred_from->number($amount); // Make sure we are sending more then minimum if ($amount < $min) { $mycred_exchange = array('success' => false, 'message' => sprintf(__('You must exchange at least %s!', 'mycred'), $mycred_from->format_creds($min))); return; } // Make sure we have enough points if ($amount > $balance) { $mycred_exchange = array('success' => false, 'message' => __('Insufficient Funds. Please try a lower amount.', 'mycred')); return; } // Let others decline $reply = apply_filters('mycred_decline_exchange', false, compact('from', 'to', 'user_id', 'rate', 'min', 'amount')); if ($reply === false) { $mycred_from->add_creds('exchange', $user_id, 0 - $amount, sprintf(__('Exchange from %s', 'mycred'), $mycred_from->plural()), 0, array('from' => $from, 'rate' => $rate, 'min' => $min), $from); $exchanged = $mycred_to->number($amount * $rate); $mycred_to->add_creds('exchange', $user_id, $exchanged, sprintf(__('Exchange to %s', 'mycred'), $mycred_to->plural()), 0, array('to' => $to, 'rate' => $rate, 'min' => $min), $to); $mycred_exchange = array('success' => true, 'message' => sprintf(__('You have successfully exchanged %s into %s.', 'mycred'), $mycred_from->format_creds($amount), $mycred_to->format_creds($exchanged))); } else { $mycred_exchange = array('success' => false, 'message' => $reply); return; } }
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; }
/** * Show Balance in Header * @since 0.1 * @version 1.4.1 */ public function show_balance($dump = NULL, $context = 'header') { // Prep $output = ''; $user_id = bp_displayed_user_id(); // Check for exclusion if ($this->core->exclude_user($user_id)) { return; } // Check visibility settings if (!$this->buddypress['visibility']['balance'] && !bp_is_my_profile() && !mycred_is_admin()) { return; } // Parse template $template = $this->buddypress['balance_template']; // Loop though all post types $mycred_types = mycred_get_types(); if (!empty($mycred_types)) { $_template = $template; foreach ($mycred_types as $type => $label) { $template = $_template; // Load myCRED with this points type $mycred = mycred($type); // Check if user is excluded from this type if ($mycred->exclude_user($user_id)) { continue; } // Get users balance $balance = $mycred->get_users_cred($user_id, $type); // Output $template = str_replace('%label%', $label, $template); $template = $mycred->template_tags_general($template); $output .= '<div class="mycred-balance mycred-' . $type . '">' . $template . ' ' . $mycred->format_creds($balance) . '</div>'; } } echo apply_filters('mycred_bp_profile_header', $output, $this->buddypress['balance_template'], $this); }
/** * * @version 1.0 */ function widget() { if ($this->args['ctypes'] == 'all') { $label = __('Total amount in circulation', 'mycred'); } else { $label = sprintf(__('Total amount of %s in circulation', 'mycred'), $this->ctypes[$this->args['ctypes']]); } $circulation = $this->get_data(); $gains_loses = $this->gains_and_loses(); ?> <div id="mycred-stats-overview" class="clear clearfix"> <div id="mycred-stats-<?php echo $this->id; ?> " class="left-column"> <canvas id="total-circulation-<?php echo $this->id; ?> -chart"></canvas> </div> <h1><?php echo $label; ?> : <?php echo $this->format_number($circulation['total']); ?> </h1> <?php if ($this->args['ctypes'] == 'all') { ?> <ul id="total-per-point-type"><li><?php echo implode('</li><li>', $circulation['totals']); ?> </li></ul> <?php } else { $circulation = array('series' => array()); $mycred = mycred($this->args['ctypes']); $gains = $this->get_total($this->args['ctypes']); $loses = $this->get_total($this->args['ctypes'], false); $total = $gains + abs($loses); $gains_p = number_format($gains / $total * 100, 0); $gains_l = number_format(100 - $gains_p, 0); $color = $gain_color = $this->colors[$this->args['ctypes']]; $circulation['series'][] = "{ value: {$gains_p}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__('Total gains (%)', 'mycred') . "' }"; $color = $lose_color = mycred_inverse_rgb_color($this->colors[$this->args['ctypes']]); $circulation['series'][] = "{ value: {$gains_l}, color: '" . $color . "', highlight: '" . $color . "', label: '" . esc_attr__('Total loses (%)', 'mycred') . "' }"; // ?> <ul id="total-per-point-type"><li><?php printf(__('Total Gained: %s', 'mycred'), '<span style="color:' . $gain_color . '">' . $mycred->format_creds($gains) . '</span>'); ?> </li><li><?php printf(__('Total Spent: %s', 'mycred'), '<span style="color:' . $lose_color . '">' . $mycred->format_creds($loses) . '</span>'); ?> </li></ul> <?php } ?> <div class="table"> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="rowtitle"></th> <th class="doublecell" colspan="2"><?php _e('Today', 'mycred'); ?> </th> <th class="doublecell" colspan="2"><?php _e('This Week', 'mycred'); ?> </th> <th class="doublecell" colspan="2"><?php _e('This Month', 'mycred'); ?> </th> <th class="doublecell" colspan="2"><?php _e('This Year', 'mycred'); ?> </th> </tr> <tr class="subheader"> <th class="rowtitle"></th> <th class="cell"><?php _e('Gained', 'mycred'); ?> </th> <th class="cell"><?php _e('Lost', 'mycred'); ?> </th> <th class="cell"><?php _e('Gained', 'mycred'); ?> </th> <th class="cell"><?php _e('Lost', 'mycred'); ?> </th> <th class="cell"><?php _e('Gained', 'mycred'); ?> </th> <th class="cell"><?php _e('Lost', 'mycred'); ?> </th> <th class="cell"><?php _e('Gained', 'mycred'); ?> </th> <th class="cell last"><?php _e('Lost', 'mycred'); ?> </th> </tr> </thead> <tbody> <?php foreach ($gains_loses as $type_id => $dates) { $mycred = mycred($type_id); ?> <tr style="color: <?php echo $this->colors[$type_id]; ?> ;"> <td class="rowtitle"><?php echo $this->ctypes[$type_id]; ?> </td> <?php $page_id = 'myCRED'; if ($type_id != 'mycred_default') { $page_id .= '_' . $type_id; } $base_url = add_query_arg(array('page' => $page_id), admin_url('admin.php')); foreach ($dates as $key => $item) { $url = add_query_arg(array('show' => $key), $base_url); echo '<td class="cell"><a href="' . $url . '">' . $mycred->format_number($item['gains']) . '</a></td>'; $url = add_query_arg(array('show' => $key, 'num' => 0, 'compare' => urlencode('<')), $base_url); echo '<td class="cell"><a href="' . $url . '">' . $mycred->format_number($item['loses']) . '</a></td>'; } } ?> </tbody> </table> <?php echo $this->action_buttons(); ?> </div> <div class="clear clearfix"></div> </div> <script type="text/javascript"> jQuery(function($) { var <?php echo $this->id; ?> = $( '#total-circulation-<?php echo $this->id; ?> -chart' ).get(0).getContext( '2d' ); <?php echo $this->id; ?> .canvas.width = 240; <?php echo $this->id; ?> .canvas.height = 240; var <?php echo $this->id; ?> chart = new Chart( <?php echo $this->id; ?> ).Doughnut([ <?php echo implode(',', $circulation['series']); ?> ],{ segmentStrokeColor : '#F1F1F1', segmentStrokeWidth : 3, percentageInnerCutout : 60 }); }); </script> <?php }
/** * Construct */ function __construct($key = NULL) { $this->handle_magic(); $this->core = mycred(); $this->key = $key; $this->method = $_SERVER['REQUEST_METHOD']; $this->uri = explode('/', $_SERVER['REQUEST_URI']); $this->format = ''; $this->parse_call(); $this->get_host_IP(); // Let others play do_action_ref_array('mycred_remote', array(&$this)); }