1 | <?php |
||
2 | /******************************************************************************* |
||
3 | * karma.php |
||
4 | * ----------------------- |
||
5 | * begin : 2005-11-13 |
||
6 | * copyright : (C) 2005 Atari Legend |
||
7 | * email : [email protected] |
||
8 | * |
||
9 | * Id: karma.php,v 0.10 2005/11/13 23:30 Silver |
||
10 | * |
||
11 | ******************************************************************************** |
||
12 | |||
13 | ********************************************************************************* |
||
14 | *Exprimental Karma code |
||
15 | *********************************************************************************/ |
||
16 | |||
17 | // Allowed $karma_action values: |
||
18 | // |
||
19 | // $karma_action = "game_downloads" |
||
20 | // $karma_action = "game_comment" |
||
21 | // $karma_action = "game_submission" |
||
22 | // $karma_action = "weblink" |
||
23 | // $karma_action = "news_update" |
||
24 | // $karma_action = "game_review" |
||
25 | // $karma_action = demo_submission |
||
26 | |||
27 | function UserKarma($user_id, $karma_action) { |
||
28 | global $mysqli; |
||
29 | if (empty($user_id)) { |
||
30 | die("user_id wasn't passed properly"); |
||
0 ignored issues
–
show
|
|||
31 | } |
||
32 | if (empty($karma_action)) { |
||
33 | die("karma values wasn't passed properly"); |
||
0 ignored issues
–
show
|
|||
34 | } |
||
35 | |||
36 | $sql_karma = $mysqli->query("SELECT karma FROM users WHERE user_id = '$user_id'") or die("failed to query users"); |
||
0 ignored issues
–
show
|
|||
37 | list($karma_value) = $sql_karma->fetch_row(); |
||
38 | |||
39 | // For downloads |
||
40 | if ($karma_action == "game_downloads") { |
||
41 | $karma_value = $karma_value - 5; |
||
42 | } |
||
43 | |||
44 | // For game comments |
||
45 | if ($karma_action == "game_comment") { |
||
46 | $karma_value = $karma_value + 5; |
||
47 | } |
||
48 | |||
49 | // For game submissions |
||
50 | if ($karma_action == "game_submission") { |
||
51 | $karma_value = $karma_value + 10; |
||
52 | } |
||
53 | |||
54 | // For submitting weblinks |
||
55 | if ($karma_action == "weblink") { |
||
56 | $karma_value = $karma_value + 3; |
||
57 | } |
||
58 | |||
59 | // For submitting news |
||
60 | if ($karma_action == "news_update") { |
||
61 | $karma_value = $karma_value + 3; |
||
62 | } |
||
63 | |||
64 | // For submitting game_reviews |
||
65 | if ($karma_action == "game_review") { |
||
66 | $karma_value = $karma_value + 3; |
||
67 | } |
||
68 | |||
69 | // For submitting game_reviews |
||
70 | if ($karma_action == "demo_submission") { |
||
71 | $karma_value = $karma_value + 10; |
||
72 | } |
||
73 | |||
74 | $update_karma = $mysqli->query("UPDATE users SET karma='$karma_value' WHERE user_id = '$user_id'"); |
||
0 ignored issues
–
show
|
|||
75 | |||
76 | return; |
||
77 | } |
||
78 | |||
79 | function KarmaGood() { |
||
80 | global $mysqli; |
||
81 | $sql = $mysqli->query("SELECT karma,userid,user_id FROM users ORDER BY karma DESC LIMIT 17"); |
||
82 | while ($row = $sql->fetch_array(MYSQLI_BOTH)) { |
||
83 | $result[] = $row; |
||
84 | } |
||
85 | return $result; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
86 | } |
||
87 | |||
88 | function KarmaBad() { |
||
89 | global $mysqli; |
||
90 | $sql = $mysqli->query("SELECT karma,userid,user_id FROM users WHERE karma IS NOT NULL ORDER BY karma ASC LIMIT 17"); |
||
91 | while ($row = $sql->fetch_array(MYSQLI_BOTH)) { |
||
92 | $result[] = $row; |
||
93 | } |
||
94 | return $result; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
95 | } |
||
96 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.