Exemplo n.º 1
0
function go_global_info()
{
    global $wpdb;
    global $current_user_id;
    global $current_points;
    global $current_currency;
    global $current_bonus_currency;
    global $current_penalty;
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    $current_points = go_return_points($current_user_id);
    $current_currency = go_return_currency($current_user_id);
    $current_bonus_currency = go_return_bonus_currency($current_user_id);
    $current_penalty = go_return_penalty($current_user_id);
    go_get_rank($current_user_id);
}
Exemplo n.º 2
0
function go_clipboard_collect_data()
{
    global $wpdb;
    $table_name_user_meta = $wpdb->prefix . 'usermeta';
    $table_name_go = $wpdb->prefix . 'go';
    $uid = $wpdb->get_results("SELECT user_id \n\t\tFROM {$table_name_user_meta} \n\t\tWHERE meta_key = '{$wpdb->prefix}capabilities' \n\t\tAND meta_value NOT LIKE '%administrator%'");
    $time = round(microtime(true));
    $array = get_option('go_graphing_data');
    foreach ($uid as $id) {
        foreach ($id as $value) {
            $bonus_currency = go_return_bonus_currency($value);
            $penalty = go_return_penalty($value);
            $currency = go_return_currency($value);
            $points = go_return_points($value);
            $third_stage = (int) $wpdb->get_var("select count(*) from " . $table_name_go . " where uid = {$value} and status = 3");
            $fourth_stage = (int) $wpdb->get_var("select count(*) from " . $table_name_go . " where uid = {$value} and status = 4");
            $array[$value][$time] = $bonus_currency . ',' . $penalty . ',' . $points . ',' . $third_stage . ',' . $fourth_stage . ',' . $currency;
        }
    }
    update_option('go_graphing_data', $array);
}
Exemplo n.º 3
0
function go_install_data()
{
    global $wpdb;
    $table_name_user_meta = $wpdb->prefix . "usermeta";
    $table_name_go_totals = $wpdb->prefix . "go_totals";
    $table_name_go = $wpdb->prefix . "go";
    global $default_role;
    $role = get_option('go_role', $default_role);
    $rank_prefix = get_option('go_level_names');
    if (empty($rank_prefix)) {
        $rank_prefix = 'Level';
    }
    $ranks = array('name' => array(), 'points' => array(), 'badges' => array());
    for ($i = 1; $i <= 20; $i++) {
        if ($i < 10) {
            $ranks['name'][] = "{$rank_prefix} 0{$i}";
        } else {
            $ranks['name'][] = "{$rank_prefix} {$i}";
        }
        if ($i == 1) {
            $ranks['points'][0] = 0;
        } else {
            $ranks['points'][] = 15 / 2 * ($i + 18) * ($i - 1);
        }
        $ranks['badges'][] = '';
    }
    $options_array = array('go_tasks_name' => 'Quest', 'go_tasks_plural_name' => 'Quests', 'go_first_stage_name' => 'Stage 1', 'go_second_stage_name' => 'Stage 2', 'go_third_stage_name' => 'Stage 3', 'go_fourth_stage_name' => 'Stage 4', 'go_fifth_stage_name' => 'Stage 5', 'go_abandon_stage_button' => 'Abandon', 'go_second_stage_button' => 'Accept', 'go_third_stage_button' => 'Complete', 'go_fourth_stage_button' => 'Master', 'go_fifth_stage_button' => 'Repeat Mastery', 'go_store_name' => 'Store', 'go_points_name' => 'Experience', 'go_points_prefix' => '', 'go_points_suffix' => 'XP', 'go_currency_name' => 'Gold', 'go_currency_prefix' => '', 'go_currency_suffix' => 'g', 'go_bonus_currency_name' => 'Honor', 'go_bonus_currency_prefix' => '', 'go_bonus_currency_suffix' => 'HP', 'go_penalty_name' => 'Damage', 'go_penalty_prefix' => '', 'go_penalty_suffix' => 'DP', 'go_minutes_name' => 'Minutes', 'go_minutes_prefix' => '', 'go_minutes_suffix' => 'm', 'go_level_names' => 'Level', 'go_level_plural_names' => 'Levels', 'go_organization_name' => 'Seating Chart', 'go_class_a_name' => 'Period', 'go_class_b_name' => 'Computer', 'go_focus_name' => 'Profession', 'go_stats_name' => 'Stats', 'go_inventory_name' => 'Inventory', 'go_badges_name' => 'Badges', 'go_leaderboard_name' => 'Leaderboard', 'go_presets' => $presets = array('name' => array('Tier 1', 'Tier 2', 'Tier 3', 'Tier 4', 'Tier 5'), 'points' => array(array(5, 5, 10, 30, 30), array(5, 5, 20, 60, 60), array(5, 5, 40, 120, 120), array(5, 5, 70, 210, 210), array(5, 5, 110, 330, 330)), 'currency' => array(array(0, 0, 3, 9, 9), array(0, 0, 6, 18, 18), array(0, 0, 12, 36, 36), array(0, 0, 21, 63, 63), array(0, 0, 33, 99, 99))), 'go_admin_bar_display_switch' => 'On', 'go_admin_bar_user_redirect' => 'On', 'go_admin_bar_add_switch' => '', 'go_admin_bar_add_minutes_switch' => '', 'go_ranks' => $ranks, 'go_class_a' => array('Period 1', 'Period 2', 'Period 3', 'Period 4', 'Period 5', 'Period 6', 'Period 7'), 'go_class_b' => array('Computer 01', 'Computer 02', 'Computer 03', 'Computer 04', 'Computer 05', 'Computer 06', 'Computer 07', 'Computer 08', 'Computer 09', 'Computer 10', 'Computer 11', 'Computer 12', 'Computer 13', 'Computer 14', 'Computer 15', 'Computer 16', 'Computer 17', 'Computer 18', 'Computer 19', 'Computer 20', 'Computer 21', 'Computer 22', 'Computer 23', 'Computer 24', 'Computer 25', 'Computer 26', 'Computer 27', 'Computer 28', 'Computer 29', 'Computer 30', 'Computer 31', 'Computer 32', 'Computer 33', 'Computer 34', 'Computer 35', 'Computer 36', 'Computer 37', 'Computer 38', 'Computer 39', 'Computer 40', 'Computer 41', 'Computer 42', 'Computer 43', 'Computer 44'), 'go_focus_switch' => '', 'go_focus' => array(''), 'go_admin_email' => '', 'go_video_width' => '', 'go_video_height' => '', 'go_store_receipt_switch' => '', 'go_full_student_name_switch' => '', 'go_multiplier_switch' => '', 'go_multiplier_threshold' => 10, 'go_penalty_switch' => '', 'go_penalty_threshold' => 5, 'go_multiplier_percentage' => 10, 'go_data_reset_switch' => '', 'go_analysis_script_day' => 'Friday');
    foreach ($options_array as $key => $value) {
        add_option($key, $value);
    }
    $uid = $wpdb->get_results("\n\t\tSELECT user_id\n\t\tFROM " . $table_name_user_meta . "\n\t\tWHERE meta_key =  '" . $wpdb->prefix . "capabilities'\n\t\tAND (meta_value LIKE  '%" . $role . "%' or meta_value like '%administrator%')\n\t");
    foreach ($uid as $id) {
        foreach ($id as $uids) {
            $check = (int) $wpdb->get_var("select uid from " . $table_name_go_totals . " where uid = {$uids} ");
            $total_points = (int) $wpdb->get_var("select sum(points) from " . $table_name_go . " where uid = {$uids} ");
            $total_currency = (int) $wpdb->get_var("select sum(currency) from " . $table_name_go . " where uid = {$uids} ");
            if ($check == 0) {
                $wpdb->insert($table_name_go_totals, array('uid' => $uids, 'points' => $total_points, 'currency' => $total_currency), array('%d'));
            } else {
                $wpdb->update($table_name_go_totals, array('uid' => $uids, 'points' => $total_points, 'currency' => $total_currency), array('uid' => $uids), array('%d'), array('%d'));
            }
            $badges_ids = get_user_meta($uids, 'go_badges', true);
            if (!$badges_ids) {
                update_user_meta($uids, 'go_badges', array());
            }
            $rank_check = get_user_meta($uids, 'go_rank');
            if (empty($rank_check) || $rank_check == '') {
                $ranks = get_option('go_ranks', false);
                $current_points = go_return_points($uids);
                while ($current_points >= current($ranks['points'])) {
                    next($ranks['points']);
                }
                $next_rank_points = current($ranks['points']);
                $next_rank = $ranks['name'][array_search($next_rank_points, $ranks['points'])];
                $rank_points = prev($ranks['points']);
                $new_rank = $ranks['name'][array_search($rank_points, $ranks['points'])];
                $new_rank_array = array(array($new_rank, $rank_points), array($next_rank, $next_rank_points));
                update_user_meta($uids, 'go_rank', $new_rank_array);
            }
        }
    }
}
Exemplo n.º 4
0
function go_clipboard_intable()
{
    global $wpdb;
    $class_a_choice = $_POST['go_clipboard_class_a_choice'];
    $table_name_user_meta = $wpdb->prefix . 'usermeta';
    $uid = $wpdb->get_results("SELECT user_id \n\t\tFROM {$table_name_user_meta} \n\t\tWHERE meta_key = '{$wpdb->prefix}capabilities' \n\t\tAND meta_value NOT LIKE '%administrator%'");
    foreach ($uid as $id) {
        $class_a = get_user_meta($id->user_id, 'go_classifications', true);
        if (!empty($class_a[$class_a_choice])) {
            $user_data_key = get_userdata($id->user_id);
            $user_login = $user_data_key->user_login;
            $user_display = $user_data_key->display_name;
            $user_first_name = $user_data_key->user_firstname;
            $user_last_name = $user_data_key->user_lastname;
            $user_url = $user_data_key->user_url;
            if (go_return_options('go_focus_switch') == 'On') {
                $user_focuses = go_display_user_focuses($id->user_id);
                $focus_name = get_option('go_focus_name');
                $focuses = get_option('go_focus');
                $focuses_list = "<option>{$user_focuses}</option><option " . (empty($user_focuses) || $user_focuses == "No {$focus_name}" ? "selected" : '') . ">No {$focus_name}</option>";
                foreach ($focuses as $focus) {
                    $focuses_list .= "<option value='" . esc_attr($focus) . "' >{$focus}</option>";
                }
            }
            $bonus_currency = go_return_bonus_currency($id->user_id);
            $penalty = go_return_penalty($id->user_id);
            $minutes = go_return_minutes($id->user_id);
            $currency = go_return_currency($id->user_id);
            $points = go_return_points($id->user_id);
            $badge_count = go_return_badge_count($id->user_id);
            go_get_rank($id->user_id);
            global $current_rank;
            echo "<tr id='user_{$id->user_id}'>\n\t\t\t\t\t<td><input class='go_checkbox' type='checkbox' name='go_selected' value='{$id->user_id}'/></td>\n\t\t\t\t\t<td><span><a href='#' onclick='go_admin_bar_stats_page_button(&quot;{$id->user_id}&quot;);'>{$user_login}</a></td>\n\t\t\t\t\t<td>{$class_a[$class_a_choice]}</td>\n\t\t\t\t\t<td><a href='{$user_url}' target='_blank'>{$user_last_name}, {$user_first_name}</a></td>\n\t\t\t\t\t<td>{$user_display}</td>\n\t\t\t\t\t<td>{$current_rank}</td>\n\t\t\t\t\t" . (go_return_options('go_focus_switch') == 'On' ? "<td><select class='go_focus' onchange='go_user_focus_change(&quot;{$id->user_id}&quot;, this);'>{$focuses_list}</select</td>" : '') . "\n\t\t\t\t\t<td class='user_points'>{$points}</td>\n\t\t\t\t\t<td class='user_currency'>{$currency}</td>\n\t\t\t\t\t<td class='user_bonus_currency'>{$bonus_currency}</td>\n\t\t\t\t\t<td class='user_penalty'>{$penalty}</td>\n\t\t\t\t\t<td class='user_minutes'>{$minutes}</td>\n\t\t\t\t\t<td class='user_badge_count'>{$badge_count}</td>\n\t\t\t\t  </tr>";
        }
    }
    die;
}
Exemplo n.º 5
0
function go_return_user_data($id, $counter, $sort)
{
    $points = go_return_points($id);
    $currency = go_return_currency($id);
    $bonus_currency = go_return_bonus_currency($id);
    $badge_count = go_return_badge_count($id);
    $user_data_key = get_userdata($id);
    $user_display = "<a href='#' onclick='go_admin_bar_stats_page_button(&quot;{$id}&quot;);'>{$user_data_key->display_name}</a>";
    switch ($sort) {
        case 'points':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$points}</div></li>";
            break;
        case 'currency':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$currency}</div></li>";
            break;
        case 'bonus_currency':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$bonus_currency}</div></li>";
            break;
        case 'badges':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$badge_count}</div></li>";
            break;
    }
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
function go_fix_levels()
{
    global $default_role;
    global $wpdb;
    $role = get_option('go_role', $default_role);
    $ranks = get_option('go_ranks');
    $uids = $wpdb->get_results("\n\t\tSELECT user_id\n\t\tFROM {$wpdb->usermeta}\n\t\tWHERE meta_key =  '{$wpdb->prefix}capabilities'\n\t\tAND (meta_value LIKE  '%{$role}%' or meta_value LIKE '%administrator%' )\n\t");
    foreach ($uids as $uid) {
        foreach ($uid as $user_id) {
            $current_points = go_return_points($user_id);
            current($ranks['points']);
            while ($current_points >= current($ranks['points'])) {
                next($ranks['points']);
                ini_set('max_execution_time', 300);
            }
            $next_rank_points = current($ranks['points']);
            $next_rank = $ranks['name'][key($ranks['points'])];
            $rank_points = prev($ranks['points']);
            $new_rank = $ranks['name'][key($ranks['points'])];
            $new_rank_array = array(array($new_rank, $rank_points), array($next_rank, $next_rank_points));
            update_user_meta($user_id, 'go_rank', $new_rank_array);
        }
    }
    die;
}
Exemplo n.º 8
0
function go_get_level_percentage($user_id)
{
    global $wpdb;
    $current_points = go_return_points($user_id);
    go_get_rank($user_id);
    global $current_currency;
    global $current_rank;
    global $next_rank_points;
    global $current_rank_points;
    $dom = $next_rank_points - $current_rank_points;
    if ($dom <= 0) {
        $dom = 1;
    }
    $percentage = ($current_points - $current_rank_points) / $dom * 100;
    if ($percentage <= 0) {
        $percentage = 0;
    } else {
        if ($percentage >= 100) {
            $percentage = 100;
        }
    }
    return $percentage;
}
Exemplo n.º 9
0
function go_the_lb_ajax()
{
    check_ajax_referer('go_lb_ajax_referall', 'nonce');
    global $wpdb;
    $table_name_go = "{$wpdb->prefix}go";
    $the_id = $_POST['the_item_id'];
    $the_post = get_post($the_id);
    $the_title = $the_post->post_title;
    $item_content = get_post_field('post_content', $the_id);
    $the_content = wpautop($item_content);
    $custom_fields = get_post_custom($the_id);
    if (isset($custom_fields['go_mta_penalty_switch'])) {
        $penalty = true;
    }
    $store_cost = !empty($custom_fields['go_mta_store_cost'][0]) ? unserialize($custom_fields['go_mta_store_cost'][0]) : null;
    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];
    }
    $store_filter = !empty($custom_fields['go_mta_store_filter'][0]) ? unserialize($custom_fields['go_mta_store_filter'][0]) : null;
    if (!empty($store_filter)) {
        $is_filtered = $store_filter[0];
        if ($is_filtered) {
            $req_rank = $store_filter[1];
            $bonus_filter = count($store_filter[2]) > 0 ? (int) $store_filter[2] : null;
            $penalty_filter = count($store_filter[3]) > 0 ? (int) $store_filter[3] : null;
        }
    }
    $store_limit = !empty($custom_fields['go_mta_store_limit'][0]) ? unserialize($custom_fields['go_mta_store_limit'][0]) : null;
    if (!empty($store_limit)) {
        $is_limited = $store_limit[0];
        if ($is_limited == 'true') {
            $purchase_limit = $store_limit[1];
        }
    }
    $user_id = get_current_user_id();
    $user_points = go_return_points($user_id);
    $user_bonus_currency = go_return_bonus_currency($user_id);
    $user_currency = go_return_currency($user_id);
    $user_penalties = go_return_penalty($user_id);
    $user_minutes = go_return_minutes($user_id);
    $purchase_count = $wpdb->get_var("SELECT SUM(count) FROM {$table_name_go} WHERE post_id={$the_id} AND uid={$user_id} LIMIT 1");
    $is_giftable = !empty($custom_fields['go_mta_store_giftable'][0]) ? $custom_fields['go_mta_store_giftable'][0] : '';
    $is_unpurchasable = !empty($custom_fields['go_mta_store_unpurchasable'][0]) ? $custom_fields['go_mta_store_unpurchasable'][0] : '';
    echo "<h2>{$the_title}</h2>";
    echo '<div id="go-lb-the-content">' . do_shortcode($the_content) . '</div>';
    if ($user_points >= $req_rank || $req_rank <= 0 || $penalty) {
        $lvl_color = "g";
        $output_level = $req_rank *= -1;
    } else {
        $lvl_color = "r";
    }
    if ($req_currency == 0) {
        $gold_color = "n";
    } elseif ($req_currency < 0) {
        $gold_color = "g";
        $output_currency = $req_currency *= -1;
    } else {
        $gold_color = "r";
    }
    if ($req_points == 0) {
        $points_color = "n";
    } elseif ($req_points < 0) {
        $points_color = "g";
        $output_points = $req_points *= -1;
    } else {
        $points_color = "r";
    }
    if ($req_bonus_currency == 0) {
        $bonus_currency_color = "n";
    } elseif ($req_bonus_currency < 0) {
        $bonus_currency_color = "g";
        $output_bonus_currency = $req_bonus_currency *= -1;
    } else {
        $bonus_currency_color = "r";
    }
    if ($req_penalty == 0) {
        $penalty_color = "n";
    } elseif ($req_penalty < 0) {
        $penalty_color = "r";
        $output_penalty = $req_penalty *= -1;
    } else {
        $penalty_color = "g";
    }
    if ($req_minutes == 0) {
        $minutes_color = "n";
    } elseif ($req_minutes < 0) {
        $minutes_color = "g";
        $output_minutes = $req_minutes *= -1;
    } else {
        $minutes_color = "r";
    }
    if ($lvl_color == "g" && $gold_color == "g" && $points_color == "g") {
        $buy_color = "gold";
    } else {
        $buy_color = "gold";
    }
    $user_focuses = array();
    if ($is_filtered === 'true' && !is_null($penalty_filter) && $user_penalties >= $penalty_filter) {
        $penalty_diff = $user_penalties - $penalty_filter;
        if ($penalty_diff > 0) {
            die("You have {$penalty_diff} too many " . go_return_options('go_penalty_name') . ".");
        } elseif ($penalty_diff == 0) {
            die("You need less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to buy this item.");
        }
    }
    // Get focus options associated with item
    $item_focus_array = !empty($custom_fields['go_mta_store_focus'][0]) ? unserialize($custom_fields['go_mta_store_focus'][0]) : null;
    // Check if item actually has focus
    $is_focused = (bool) filter_var($item_focus_array[0], FILTER_VALIDATE_BOOLEAN);
    if ($is_focused) {
        $item_focus = $item_focus_array[1];
    }
    // Check if user has a focus
    if (get_user_meta($user_id, 'go_focus', true) != null) {
        $user_focuses = (array) get_user_meta($user_id, 'go_focus', true);
    }
    // Check if item is locked by focus
    $locked_by_focus = !empty($custom_fields['go_mta_store_focus_lock'][0]) ? $custom_fields['go_mta_store_focus_lock'][0] : null;
    if (!empty($locked_by_focus)) {
        $focus_category_lock = true;
    }
    // Grab which focuses are chosen as the locks
    if (get_the_terms($the_id, 'store_focus_categories') && $focus_category_lock) {
        $categories = get_the_terms($the_id, 'store_focus_categories');
        $category_names = array();
        foreach ($categories as $category) {
            array_push($category_names, $category->name);
        }
    }
    // Check to see if the user has any of the focuses
    if (!empty($category_names) && $user_focuses) {
        $go_ahead = array_intersect($user_focuses, $category_names);
    }
    if ($is_focused && !empty($item_focus) && !empty($user_focuses) && in_array($item_focus, $user_focuses)) {
        die('You already have this ' . go_return_options('go_focus_name') . '!');
    }
    if (empty($go_ahead) && !empty($focus_category_lock)) {
        die('Item only available to those in ' . implode(', ', $category_names) . ' ' . strtolower(go_return_options('go_focus_name')));
    }
    if ($is_filtered === 'true' && !is_null($bonus_filter) && $user_bonus_currency < $bonus_filter) {
        die('You require more ' . go_return_options('go_bonus_currency_name') . ' to view this item.');
    }
    if (!empty($purchase_limit) && $purchase_count >= $purchase_limit) {
        die("You've reached the maximum purchase limit.");
    }
    if ($user_points < $req_rank) {
        die("You need to reach {$req_rank_key} to purchase this item.");
    }
    ?>
	<div id="golb-fr-price" class="golb-fr-boxes-<?php 
    echo $gold_color;
    ?>
" req="<?php 
    echo $req_currency;
    ?>
" cur="<?php 
    echo $user_currency;
    ?>
"><?php 
    echo go_return_options('go_currency_name') . ': ' . (empty($req_currency) ? 0 : ($req_currency < 0 ? $output_currency : $req_currency));
    ?>
</div>
	<div id="golb-fr-points" class="golb-fr-boxes-<?php 
    echo $points_color;
    ?>
" req="<?php 
    echo $req_points;
    ?>
" cur="<?php 
    echo $user_points;
    ?>
"><?php 
    echo go_return_options('go_points_name') . ': ' . (empty($req_points) ? 0 : ($req_points < 0 ? $output_points : $req_points));
    ?>
</div>
	<div id="golb-fr-bonus_currency" class="golb-fr-boxes-<?php 
    echo $bonus_currency_color;
    ?>
" req="<?php 
    echo $req_bonus_currency;
    ?>
" cur="<?php 
    echo $user_bonus_currency;
    ?>
"><?php 
    echo go_return_options('go_bonus_currency_name') . ': ' . (empty($req_bonus_currency) ? 0 : ($req_bonus_currency < 0 ? $output_bonus_currency : $req_bonus_currency));
    ?>
</div>
    <div id='golb-fr-penalty' class='golb-fr-boxes-<?php 
    echo $penalty_color;
    ?>
' req='<?php 
    echo $req_penalty;
    ?>
' cur='<?php 
    echo $user_penalties;
    ?>
'><?php 
    echo go_return_options('go_penalty_name') . ': ' . (empty($req_penalty) ? 0 : ($req_penalty < 0 ? $output_penalty : $req_penalty));
    ?>
</div>
    <div id="golb-fr-minutes" class="golb-fr-boxes-<?php 
    echo $minutes_color;
    ?>
" req="<?php 
    echo $req_minutes;
    ?>
" cur="<?php 
    echo $user_minutes;
    ?>
"><?php 
    echo go_return_options('go_minutes_name') . ': ' . (empty($req_minutes) ? 0 : ($req_minutes < 0 ? $output_minutes : $req_minutes));
    ?>
</div>
	<?php 
    if ($is_unpurchasable != 'on') {
        ?>
		<div id="golb-fr-qty" class="golb-fr-boxes-n">Qty: <input id="go_qty" style="width: 40px;font-size: 11px; margin-right:0px; margin-top: 0px; bottom: 3px; position: relative;" value="1" disabled="disabled" /></div>
		<div id="golb-fr-buy" class="golb-fr-boxes-<?php 
        echo $buy_color;
        ?>
" onclick="goBuytheItem( '<?php 
        echo $the_id;
        ?>
', '<?php 
        echo $buy_color;
        ?>
', '<?php 
        echo $purchase_count;
        ?>
' ); this.removeAttribute( 'onclick' );">Buy</div>
		<div id="golb-fr-purchase-limit" val="<?php 
        echo !empty($purchase_limit) ? $purchase_limit : 0;
        ?>
"><?php 
        echo !empty($purchase_limit) ? "Limit {$purchase_limit}" : 'No limit';
        ?>
</div>
		<div id="golb-purchased">
		<?
		if ( is_null( $purchase_count ) ) { 
			echo 'Quantity purchased: 0';
		} else {
			echo "Quantity purchased: {$purchase_count}";
		} 
	}
	 if ( ! empty( $item_focus ) && ! empty( $penalty ) && $is_giftable == 'on' ) {
	 ?>
 		<br />
		Gift this item <input type='checkbox' id='go_toggle_gift_fields'/>
        <div id="go_recipient_wrap" class="golb-fr-boxes-giftable">Gift To: <input id="go_recipient" type="text"/></div>
        <div id="go_search_results"></div> 
     <script>   
		var go_gift_check_box = jQuery( "#go_toggle_gift_fields" );
		var go_gift_text_box = jQuery( "#go_recipient_wrap" );
		go_gift_text_box.prop( "hidden", true );
		go_gift_check_box.click( function() {
			if ( jQuery( this ).is( ":checked" ) ) {
				go_gift_text_box.prop( "hidden", false );
			} else {
				go_gift_text_box.prop( "hidden", true );
				jQuery( '#go_search_results' ).hide();
				jQuery( "#go_recipient" ).val( '' );
			}
		});
	</script>
    
	<?php 
    }
    ?>
	</div>
	<?php 
    die;
}
Exemplo n.º 10
0
function go_the_lb_ajax()
{
    check_ajax_referer('go_lb_ajax_referall', 'nonce');
    global $wpdb;
    $table_name_go = $wpdb->prefix . "go";
    $the_id = $_POST["the_item_id"];
    $the_post = get_post($the_id);
    $the_title = $the_post->post_title;
    $item_content = get_post_field('post_content', $the_id);
    $the_content = wpautop($item_content);
    $custom_fields = get_post_custom($the_id);
    if (isset($custom_fields['go_mta_penalty_switch'])) {
        $penalty = true;
    }
    $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];
    }
    $store_filter = unserialize($custom_fields['go_mta_store_filter'][0]);
    $is_filtered = $store_filter[0];
    if ($is_filtered) {
        $req_rank = $store_filter[1];
        $bonus_filter = $store_filter[2] . length > 0 ? (int) $store_filter[2] : null;
        $penalty_filter = $store_filter[3] . length > 0 ? (int) $store_filter[3] : null;
    }
    $store_limit = unserialize($custom_fields['go_mta_store_limit'][0]);
    $is_limited = $store_limit[0];
    if ($is_limited == 'true') {
        $purchase_limit = $store_limit[1];
    }
    $user_id = get_current_user_id();
    $user_points = go_return_points($user_id);
    $user_bonus_currency = go_return_bonus_currency($user_id);
    $user_currency = go_return_currency($user_id);
    $user_penalties = go_return_penalty($user_id);
    $purchase_count = $wpdb->get_var("SELECT SUM(count) FROM {$table_name_go} WHERE post_id={$the_id} AND uid={$user_id} LIMIT 1");
    echo '<h2>' . $the_title . '</h2>';
    echo '<div id="go-lb-the-content">' . do_shortcode($the_content) . '</div>';
    if ($user_points >= $req_rank || $req_rank <= 0 || $penalty) {
        $lvl_color = "g";
    } else {
        $lvl_color = "r";
    }
    if ($user_currency >= $req_currency || $req_currency <= 0 || $penalty) {
        $gold_color = "g";
    } else {
        $gold_color = "r";
    }
    if ($user_points >= $req_points || $req_points <= 0 || $penalty) {
        $points_color = "g";
    } else {
        $points_color = "r";
    }
    if ($user_bonus_currency >= $req_bonus_currency || $req_bonus_currency <= 0 || $penalty) {
        $bonus_currency_color = "g";
    } else {
        $bonus_currency_color = "r";
    }
    if ($lvl_color == "g" && $gold_color == "g" && $points_color == "g") {
        $buy_color = "g";
    } else {
        $buy_color = "r";
    }
    $user_focuses = array();
    if ($is_filtered === 'true' && !is_null($penalty_filter) && $user_penalties >= $penalty_filter) {
        $penalty_diff = $user_penalties - $penalty_filter;
        if ($penalty_diff > 0) {
            die("You have {$penalty_diff} too many " . go_return_options('go_penalty_name') . ".");
        } else {
            if ($penalty_diff == 0) {
                die("You need less than {$penalty_filter} " . go_return_options('go_penalty_name') . " to buy this item.");
            }
        }
    }
    // Check if user has a focus
    if (get_user_meta($user_id, 'go_focus', true) != null) {
        $user_focuses = (array) get_user_meta($user_id, 'go_focus', true);
    }
    // Check if the item has a focus and the focus gateway is turned on
    if ($custom_fields['go_mta_focuses'][0] && $custom_fields['go_mta_focus_item_switch'][0] == 'on') {
        $item_focus = $custom_fields['go_mta_focuses'][0];
    }
    // If user has the focus and the item is a focus gateway echo this
    if ($item_focus && !empty($user_focuses) && in_array($item_focus, $user_focuses)) {
        die('You already have this ' . go_return_options('go_focus_name') . '!');
    }
    if ($is_filtered === 'true' && !is_null($bonus_filter) && $user_bonus_currency < $bonus_filter) {
        die('You require more ' . go_return_options('go_bonus_currency_name') . ' to view this item.');
    }
    if (!empty($purchase_limit) && $purchase_count >= $purchase_limit) {
        die("You've reached the maximum purchase limit.");
    }
    if ($user_points < $req_rank) {
        die("You need to reach {$req_rank_key} to purchase this item.");
    }
    ?>
	<div id="golb-fr-price" class="golb-fr-boxes-<?php 
    echo $gold_color;
    ?>
" req="<?php 
    echo $req_currency;
    ?>
" cur="<?php 
    echo $user_currency;
    ?>
"><?php 
    echo go_return_options('go_currency_name') . ': ' . $req_currency;
    ?>
</div>
	<div id="golb-fr-points" class="golb-fr-boxes-<?php 
    echo $points_color;
    ?>
" req="<?php 
    echo $req_points;
    ?>
" cur="<?php 
    echo $user_points;
    ?>
"><?php 
    echo go_return_options('go_points_name') . ': ' . $req_points;
    ?>
</div>
	<div id="golb-fr-bonus_currency" class="golb-fr-boxes-<?php 
    echo $bonus_currency_color;
    ?>
" req="<?php 
    echo $req_bonus_currency;
    ?>
" cur="<?php 
    echo $user_bonus_currency;
    ?>
"><?php 
    echo go_return_options('go_bonus_currency_name') . ': ' . $req_bonus_currency;
    ?>
</div>
	<div id="golb-fr-qty" class="golb-fr-boxes-g">Qty: <input id="go_qty" style="width: 40px;font-size: 11px; margin-right:0px; margin-top: 0px; bottom: 3px; position: relative;" value="1" disabled="disabled" /></div>
	<?php 
    if (!$item_focus && !$penalty) {
        ?>
        <div id="go_recipient_wrap" class="golb-fr-boxes-g">Recipient: <input id="go_recipient" type="text"/></div>
        <div id="go_search_results"></div>
	<?php 
    }
    ?>
	<div id="golb-fr-buy" class="golb-fr-boxes-<?php 
    echo $buy_color;
    ?>
" onclick="goBuytheItem('<?php 
    echo $the_id;
    ?>
', '<?php 
    echo $buy_color;
    ?>
', '<?php 
    echo $purchase_count;
    ?>
'); this.removeAttribute('onclick');">Buy</div>
	<div id="golb-fr-purchase-limit" val="<?php 
    echo $purchase_limit;
    ?>
"><?php 
    if ($purchase_limit == 0) {
        echo 'No limit';
    } else {
        echo 'Limit ' . $purchase_limit;
    }
    ?>
 </div>
	<div id="golb-purchased">
	<?php 
    if (is_null($purchase_count)) {
        echo 'Quantity purchased: 0';
    } else {
        echo "Quantity purchased: {$purchase_count}";
    }
    ?>
	</div>
	<?php 
    die;
}
Exemplo n.º 11
0
function go_return_user_data($id, $counter, $sort)
{
    $points = go_return_points($id);
    $currency = go_return_currency($id);
    $bonus_currency = go_return_bonus_currency($id);
    $badge_count = go_return_badge_count($id);
    $user_data_key = get_userdata($id);
    $user_display = "<a href='{$user_data_key->user_url}' target='_blank'>{$user_data_key->display_name}</a>";
    switch ($sort) {
        case 'points':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$points}</div></li>";
            break;
        case 'currency':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$currency}</div></li>";
            break;
        case 'bonus_currency':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$bonus_currency}</div></li>";
            break;
        case 'badges':
            echo "<li>{$counter} {$user_display} <div class='go_stats_amount'>{$badge_count}</div></li>";
            break;
    }
}