forked from TheMacLab/game-on
/
go_ranks.php
128 lines (116 loc) · 3.65 KB
/
go_ranks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
This is the file that displays a page on the admin side of wordpress for the list of rankings.
Allows administrator to edit points required for each ranking and to delete certain rankings/add others.
*/
function go_update_ranks ($user_id, $total_points) {
global $wpdb;
global $current_rank;
go_get_rank($user_id);
global $current_rank_points;
global $next_rank;
global $next_rank_points;
global $current_points;
$ranks = get_option('go_ranks');
$name_array = $ranks['name'];
$points_array = $ranks['points'];
if ($next_rank != '') {
if ($total_points >= $next_rank_points) {
while (current($points_array) != $next_rank_points) {
next($points_array);
}
while ($total_points >= current($points_array)) {
$current_key = key($points_array);
$new_rank = $name_array[$current_key];
$new_rank_points = $points_array[$current_key];
$new_next_rank = $name_array[$current_key + 1];
$new_next_rank_points = $points_array[$current_key + 1];
if ($ranks['badges'][$current_key]) {
$badge_id = $ranks['badges'][$current_key];
do_shortcode("[go_award_badge id='{$badge_id}' repeat='off' uid='{$user_id}']");
}
next($points_array);
}
$new_rank = array(
array($new_rank, $new_rank_points),
array($new_next_rank, $new_next_rank_points)
);
$update = true;
}
if (!empty($points_array)) {
reset($points_array);
}
if ($total_points < $current_rank_points) {
while (current($points_array) != $current_rank_points) {
next($points_array);
}
while ($total_points < current($points_array)) {
$current_key = key($points_array);
$new_rank = $name_array[$current_key - 1];
$new_rank_points = $points_array[$current_key - 1];
$new_next_rank = $name_array[$current_key];
$new_next_rank_points = $points_array[$current_key];
if($ranks['badges'][$current_key]){
go_remove_badge($user_id, $ranks['badges'][$current_key]);
}
prev($points_array);
}
$new_rank = array(
array($new_rank, $new_rank_points),
array($new_next_rank, $new_next_rank_points)
);
$update = true;
}
}
if ($update) {
update_user_meta($user_id, 'go_rank', $new_rank);
go_get_rank($user_id);
global $current_rank;
global $current_rank_points;
global $next_rank;
global $next_rank_points;
global $counter;
$counter++;
$space = $counter*85;
echo '
<div id="go_notification_level" class="go_notification" style="top: '.($space - 17).'px; color: #FFD700; width: 300px; height: 81.6px; font-size: 52px;"> '.$current_rank.'!</div>
<script type="text/javascript" language="javascript">
go_notification(3000, jQuery("#go_notification_level"));
jQuery("#go_admin_bar_rank").html("'.$current_rank.'");
</script>';
}
}
function go_get_rank ($user_id) {
global $wpdb;
$rank = get_user_meta($user_id, 'go_rank');
global $current_rank;
global $current_rank_points;
global $next_rank;
global $next_rank_points;
$current_rank = $rank[0][0][0];
$current_rank_points = $rank[0][0][1];
$next_rank = $rank[0][1][0];
$next_rank_points = $rank[0][1][1];
}
function go_get_all_ranks () {
$all_ranks = get_option('go_ranks');
$all_ranks_sorted = array();
foreach ($all_ranks as $level => $points) {
$all_ranks_sorted[] = array('name' => $level , 'value' => $points);
}
return $all_ranks_sorted;
}
function go_clean_ranks () {
$all_ranks = get_option('go_ranks');
$all_ranks_sorted = array();
foreach ($all_ranks as $level => $points) {
echo '<option value="'.$points.'">'.$level.'</option>';
}
}
function go_get_rank_key ($points) {
global $wpdb;
$ranks = get_option('go_ranks',false);
$key = array_search($points, $ranks['points']);
return $key;
}
?>