function go_clipboard_add() { $ids = $_POST['ids']; $points = $_POST['points']; $currency = $_POST['currency']; $bonus_currency = $_POST['bonus_currency']; $penalty = $_POST['penalty']; $reason = $_POST['reason']; $badge_ID = $_POST['badge_ID']; foreach ($ids as $key => $value) { if ($reason != '') { if ($points != '') { go_add_currency($value, $reason, 6, $points, 0, false); } if ($currency != '') { go_add_currency($value, $reason, 6, 0, $currency, false); } if ($bonus_currency != '') { go_add_bonus_currency($value, $bonus_currency, $reason); } if ($penalty != '') { go_add_penalty($value, $penalty, $reason); } if ($badge_ID != '') { do_shortcode('[go_award_badge id="' . $badge_ID . '" repeat = "off" uid="' . $value . '"]'); } go_message_user($value, $reason); } } die; }
function go_clipboard_add() { $ids = $_POST['ids']; $points = $_POST['points']; $currency = $_POST['currency']; $bonus_currency = $_POST['bonus_currency']; $penalty = $_POST['penalty']; $minutes = $_POST['minutes']; $reason = $_POST['reason']; $badge_ID = $_POST['badge_ID']; foreach ($ids as $key => $value) { if ($reason != '') { if ($points != '') { go_add_currency($value, $reason, 6, $points, 0, false); } if ($currency != '') { go_add_currency($value, $reason, 6, 0, $currency, false); } if ($bonus_currency != '') { go_add_bonus_currency($value, $bonus_currency, $reason); } if ($penalty != '') { go_add_penalty($value, $penalty, $reason); } if ($minutes != '') { go_add_minutes($value, $minutes, $reason); } if ($badge_ID != '') { do_shortcode("[go_award_badge id='{$badge_ID}' repeat = 'off' uid='{$value}']"); } go_message_user($value, $reason); } } die; }
function go_buy_item() { global $wpdb; $go_table_name = $wpdb->prefix . "go"; $post_id = $_POST["the_id"]; $qty = $_POST['qty']; $current_purchase_count = $_POST['purchase_count']; if (isset($_POST['recipient']) && !empty($_POST['recipient']) && $_POST['recipient'] != '') { $recipient = $_POST['recipient']; $recipient_id = $wpdb->get_var('SELECT id FROM ' . $wpdb->users . ' WHERE display_name="' . $recipient . '"'); $recipient_purchase_count = $wpdb->get_var("SELECT count FROM {$table_name_go} WHERE post_id={$post_id} AND uid={$recipient_id} LIMIT 1"); } $user_id = get_current_user_id(); $custom_fields = get_post_custom($post_id); $sending_receipt = $custom_fields['go_mta_store_receipt'][0]; $store_cost = unserialize($custom_fields['go_mta_store_cost'][0]); if (!empty($store_cost)) { $req_currency = $store_cost[0]; $req_points = $store_cost[1]; $req_bonus_currency = $store_cost[2]; $req_penalty = $store_cost[3]; $req_minutes = $store_cost[4]; } $penalty = $custom_fields['go_mta_penalty_switch']; $store_limit = unserialize($custom_fields['go_mta_store_limit'][0]); $is_limited = (bool) $store_limit[0]; if ($is_limited) { $limit = (int) $store_limit[1]; } $store_filter = unserialize($custom_fields['go_mta_store_filter'][0]); $is_filtered = (bool) $store_filter[0]; if ($is_filtered) { $req_rank = $store_filter[1]; $bonus_filter = $store_filter[2]; } $store_exchange = unserialize($custom_fields['go_mta_store_exchange'][0]); $is_exchangeable = (bool) $store_exchange[0]; if ($is_exchangeable) { $exchange_currency = $store_exchange[1]; $exchange_points = $store_exchange[2]; $exchange_bonus_currency = $store_exchange[3]; } $item_url = $custom_fields['go_mta_store_item_url'][0]; $badge_id = $custom_fields['go_mta_badge_id'][0]; $store_focus = $custom_fields['go_mta_store_focus'][0]; $is_focused = (bool) $store_focus[0]; if ($is_focused) { $item_focus = $store_focus[1]; } $repeat = 'off'; $cur_currency = go_return_currency($user_id); $cur_points = go_return_points($user_id); $cur_bonus_currency = go_return_bonus_currency($user_id); $cur_penalty = go_return_penalty($user_id); $cur_minutes = go_return_minutes($user_id); $enough_currency = check_values($req_currency, $cur_currency); $enough_points = check_values($req_points, $cur_points); $enough_bonus_currency = check_values($req_bonus_currency, $cur_bonus_currency); $enough_penalty = check_values($req_penalty, $cur_penalty); $enough_minutes = check_values($req_minutes, $cur_minutes); $within_limit = true; if (!empty($limit)) { $qty_diff = $limit - $current_purchase_count - $qty; if ($qty_diff < 0) { $within_limit = false; } } if (($enough_currency && $enough_bonus_currency && $enough_points && $enough_minutes || $penalty) && $within_limit) { if ($is_focused && !empty($item_focus)) { $user_focuses = (array) get_user_meta($user_id, 'go_focus', true); $user_focuses[] = $item_focus; update_user_meta($user_id, 'go_focus', $user_focuses); } if ($recipient_id) { go_message_user($recipient_id, get_userdata($user_id)->display_name . " has purchased {$qty} <a href='javascript:;' onclick='go_lb_opener({$post_id})'>" . get_the_title($post_id) . "</a> for you."); if ($exchange_currency || $exchange_points || $exchange_bonus_currency) { go_add_post($recipient_id, $post_id, -1, $exchange_points, $exchange_currency, $exchange_bonus_currency, null, null, $repeat); go_add_bonus_currency($recipient_id, $exchange_bonus_currency, get_userdata($user_id)->display_name . " purchase of {$qty} " . get_the_title($post_id) . "."); } else { go_add_post($recipient_id, $post_id, -1, 0, 0, 0, null, $repeat); } go_add_post($user_id, $post_id, -1, -$req_points, -$req_currency, -$req_bonus_currency, -$req_minutes, null, $repeat); $wpdb->query($wpdb->prepare("UPDATE {$go_table_name} SET reason = 'Gifted' WHERE uid = %d AND status = %d AND gifted = %d AND post_id = %d ORDER BY timestamp DESC, reason DESC, id DESC LIMIT 1", $user_id, -1, 0, $post_id)); } else { go_add_post($user_id, $post_id, -1, -$req_points, -$req_currency, -$req_bonus_currency, -$req_minutes, null, $repeat); if (!empty($req_penalty)) { go_add_penalty($user_id, -$req_penalty, get_the_title($post_id)); } } if (!empty($badge_id)) { if ($recipient_id) { do_shortcode('[go_award_badge id="' . $badge_id . '" repeat = "off" uid="' . $recipient_id . '"]'); } else { do_shortcode('[go_award_badge id="' . $badge_id . '" repeat = "off" uid="' . $user_id . '"]'); } } if (!empty($item_url) && isset($item_url)) { $item_hyperlink = '<a target="_blank" href="' . $item_url . '">Grab your loot!</a>'; echo $item_hyperlink; } else { echo "Purchased"; } if ($sending_receipt === 'true') { $receipt = go_mail_item_reciept($user_id, $post_id, $req_currency, $req_points, $req_bonus_currency, $req_minutes, $qty, $recipient_id); if (!empty($receipt)) { echo $receipt; } } } else { $currency_name = go_return_options('go_currency_name'); $points_name = go_return_options('go_points_name'); $bonus_currency_name = go_return_options('go_bonus_currency_name'); $minutes_name = go_return_options('go_minutes_name'); $enough_array = array($currency_name => $enough_currency, $points_name => $enough_points, $bonus_currency_name => $enough_bonus_currency, $minutes_name => $enough_minutes); $errors = array(); foreach ($enough_array as $key => $enough) { if (!$enough) { $errors[] = $key; } } if (!empty($errors)) { $errors = implode(', ', $errors); echo 'Need more ' . substr($errors, 0, strlen($errors)); } if ($is_limited && !$within_limit) { $qty_diff *= -1; echo "You've attempted to purchase " . ($qty_diff == 1 ? '1 item' : "{$qty_diff} items") . " greater than the purchase limit."; } } die; }
function go_stats_move_stage() { global $wpdb; $go_table_name = "{$wpdb->prefix}go"; if (!empty($_POST['user_id'])) { $user_id = $_POST['user_id']; } else { $user_id = get_current_user_id(); } $current_rank = get_user_meta($user_id, 'go_rank', true); $task_id = $_POST['task_id']; $status = $_POST['status']; $count = $_POST['count']; $message = $_POST['message']; $custom_fields = get_post_custom($task_id); $rewards = unserialize($custom_fields['go_presets'][0]); $current_status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); $page_id = $wpdb->get_var($wpdb->prepare("SELECT page_id FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); $changed = array('type' => 'json', 'points' => 0, 'currency' => 0, 'bonus_currency' => 0); if ($status == 1) { $current_rewards = $wpdb->get_results($wpdb->prepare("SELECT points, currency, bonus_currency FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); go_task_abandon($user_id, $task_id, $current_rewards[0]->points, $current_rewards[0]->currency, $current_rewards[0]->bonus_currency); $changed['points'] = -$current_rewards[0]->points; $changed['currency'] = -$current_rewards[0]->currency; $changed['bonus_currency'] = -$current_rewards[0]->bonus_currency; $current_points = go_return_points($user_id); $updated_rank = get_user_meta($user_id, 'go_rank', true); if ($current_rank[0][0] != $updated_rank[0][0]) { $changed['current_points'] = $current_points; $changed['rank'] = $updated_rank[0][0]; $changed['rank_points'] = $updated_rank[0][1]; $changed['next_rank_points'] = $updated_rank[1][1]; } $changed['abandon'] = 'true'; } else { for ($count; $count > 0; $count--) { go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, 'on', -1, null, null, null, null); $changed['points'] += -$rewards['points'][$current_status]; $changed['currency'] += -$rewards['currency'][$current_status]; $changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status]; } while ($current_status != $status) { if ($current_status > $status) { $current_status--; go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, null, null, null, null, null, null); $changed['points'] += -$rewards['points'][$current_status]; $changed['currency'] += -$rewards['currency'][$current_status]; $changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status]; } elseif ($current_status < $status) { $current_status++; $current_count = $wpdb->get_var($wpdb->prepare("SELECT count FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); if ($current_status == 5 && $current_count == 0) { go_add_post($user_id, $task_id, $current_status - 1, $rewards['points'][$current_status - 1], $rewards['currency'][$current_status - 1], $rewards['bonus_currency'][$current_status - 1], null, $page_id, 'on', 1, null, null, null, null); $changed['points'] += $rewards['points'][$current_status - 1]; $changed['currency'] += $rewards['currency'][$current_status - 1]; $changed['bonus_currency'] += $rewards['bonus_currency'][$current_status - 1]; } elseif ($current_status < 5) { go_add_post($user_id, $task_id, $current_status, $rewards['points'][$current_status - 1], $rewards['currency'][$current_status - 1], $rewards['bonus_currency'][$current_status - 1], null, $page_id, null, null, null, null, null, null); $changed['points'] += $rewards['points'][$current_status - 1]; $changed['currency'] += $rewards['currency'][$current_status - 1]; $changed['bonus_currency'] += $rewards['bonus_currency'][$current_status - 1]; } } } if ($message === 'See me') { go_message_user($user_id, $message . ' about, <a href="' . get_permalink($task_id) . '" style="display: inline-block; text-decoration: underline; padding: 0px; margin: 0px;">' . get_the_title($task_id) . '</a>, please.'); } else { go_message_user($user_id, 'RE: <a href="' . get_permalink($task_id) . '">' . get_the_title($task_id) . '</a> ' . $message); } $current_points = go_return_points($user_id); $updated_rank = get_user_meta($user_id, 'go_rank', true); if ($current_rank[0][0] != $updated_rank[0][0]) { $changed['current_points'] = $current_points; $changed['rank'] = $updated_rank[0][0]; $changed['rank_points'] = $updated_rank[0][1]; $changed['next_rank_points'] = $updated_rank[1][1]; } } echo json_encode($changed); die; }
function go_stats_move_stage() { global $wpdb; $go_table_name = "{$wpdb->prefix}go"; if (!empty($_POST['user_id'])) { $user_id = $_POST['user_id']; } else { $user_id = get_current_user_id(); } $current_rank = get_user_meta($user_id, 'go_rank', true); $task_id = $_POST['task_id']; $status = $_POST['status']; $count = $_POST['count']; $message = $_POST['message']; $custom_fields = get_post_custom($task_id); $date_picker = !empty($custom_fields['go_mta_date_picker'][0]) && unserialize($custom_fields['go_mta_date_picker'][0]) ? array_filter(unserialize($custom_fields['go_mta_date_picker'][0])) : null; $rewards = unserialize($custom_fields['go_presets'][0]); $current_status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); $page_id = $wpdb->get_var($wpdb->prepare("SELECT page_id FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); $changed = array('type' => 'json', 'points' => 0, 'currency' => 0, 'bonus_currency' => 0); if (!empty($date_picker)) { $dates = $date_picker['date']; $percentages = $date_picker['percent']; $unix_today = strtotime(date('Y-m-d')); $past_dates = array(); foreach ($dates as $key => $date) { if ($unix_today >= strtotime($date)) { $past_dates[$key] = abs($unix_today - strtotime($date)); } } if (!empty($past_dates)) { asort($past_dates); $update_percent = (double) ($percentages[key($past_dates)] / 100); } else { $update_percent = 1; } } else { $update_percent = 1; } if ($status == 1) { $current_rewards = $wpdb->get_results($wpdb->prepare("SELECT points, currency, bonus_currency FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); go_task_abandon($user_id, $task_id, $current_rewards[0]->points, $current_rewards[0]->currency, $current_rewards[0]->bonus_currency * $update_percent); $changed['points'] = -$current_rewards[0]->points; $changed['currency'] = -$current_rewards[0]->currency; $changed['bonus_currency'] = -$current_rewards[0]->bonus_currency; $current_points = go_return_points($user_id); $updated_rank = get_user_meta($user_id, 'go_rank', true); if ($current_rank[0][0] != $updated_rank[0][0]) { $changed['current_points'] = $current_points; $changed['rank'] = $updated_rank[0][0]; $changed['rank_points'] = $updated_rank[0][1]; $changed['next_rank_points'] = $updated_rank[1][1]; } $changed['abandon'] = 'true'; if ($message === 'See me') { go_message_user($user_id, $message . ' about, <a href="' . get_permalink($task_id) . '" style="display: inline-block; text-decoration: underline; padding: 0px; margin: 0px;">' . get_the_title($task_id) . '</a>, please.'); } else { go_message_user($user_id, 'RE: <a href="' . get_permalink($task_id) . '">' . get_the_title($task_id) . '</a> ' . $message); } } else { for ($count; $count > 0; $count--) { go_add_post($user_id, $task_id, $current_status, floor(-$rewards['points'][$current_status] * $update_percent), floor(-$rewards['currency'][$current_status] * $update_percent), floor(-$rewards['bonus_currency'][$current_status] * $update_percent), null, $page_id, 'on', -1, null, null, null, null); $changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent); $changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent); $changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent); } while ($current_status != $status) { if ($current_status > $status) { $current_status--; go_add_post($user_id, $task_id, $current_status, floor(-$rewards['points'][$current_status] * $update_percent), floor(-$rewards['currency'][$current_status] * $update_percent), floor(-$rewards['bonus_currency'][$current_status] * $update_percent), null, $page_id, null, null, null, null, null, null); $changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent); $changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent); $changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent); } elseif ($current_status < $status) { $current_status++; $current_count = $wpdb->get_var($wpdb->prepare("SELECT count FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id)); if ($current_status == 5 && $current_count == 0) { go_add_post($user_id, $task_id, $current_status - 1, floor($rewards['points'][$current_status - 1] * $update_percent), floor($rewards['currency'][$current_status - 1] * $update_percent), floor($rewards['bonus_currency'][$current_status - 1] * $update_percent), null, $page_id, 'on', 1, null, null, null, null); $changed['points'] += floor($rewards['points'][$current_status - 1] * $update_percent); $changed['currency'] += floor($rewards['currency'][$current_status - 1] * $update_percent); $changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status - 1] * $update_percent); } elseif ($current_status < 5) { go_add_post($user_id, $task_id, $current_status, floor($rewards['points'][$current_status - 1] * $update_percent), floor($rewards['currency'][$current_status - 1] * $update_percent), floor($rewards['bonus_currency'][$current_status - 1] * $update_percent), null, $page_id, null, null, null, null, null, null); $changed['points'] += floor($rewards['points'][$current_status - 1] * $update_percent); $changed['currency'] += floor($rewards['currency'][$current_status - 1] * $update_percent); $changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status - 1] * $update_percent); } } } if ($message === 'See me') { go_message_user($user_id, $message . ' about, <a href="' . get_permalink($task_id) . '" style="display: inline-block; text-decoration: underline; padding: 0px; margin: 0px;">' . get_the_title($task_id) . '</a>, please.'); } else { go_message_user($user_id, 'RE: <a href="' . get_permalink($task_id) . '">' . get_the_title($task_id) . '</a> ' . $message); } $current_points = go_return_points($user_id); $updated_rank = get_user_meta($user_id, 'go_rank', true); if ($current_rank[0][0] != $updated_rank[0][0]) { $changed['current_points'] = $current_points; $changed['rank'] = $updated_rank[0][0]; $changed['rank_points'] = $updated_rank[0][1]; $changed['next_rank_points'] = $updated_rank[1][1]; } } echo json_encode($changed); die; }