Browse Source

Implement fetching OppaiCoin price data without login

Bypass login on /store.php if you GET api=1, and return price and
purchases data as JSON.
Maav 5 years ago
parent
commit
2faa14366d
1 changed files with 92 additions and 71 deletions
  1. 92
    71
      sections/store/index.php

+ 92
- 71
sections/store/index.php View File

@@ -1,78 +1,99 @@
1 1
 <?
2
-enforce_login();
2
+if (isset($_GET['api']) && $_GET['api'] == 1) {
3
+  $DB->query("
4
+    SELECT First, Second
5
+    FROM misc
6
+    WHERE Name='CoinBadge'");
7
+  if ($DB->has_results()) {
8
+    list($Purchases, $Price) = $DB->next_record();
9
+  } else {
10
+    $DB->query("
11
+      INSERT INTO misc
12
+             (Name,        First, Second)
13
+      VALUES ('CoinBadge', 0,     1000)");
14
+    list($Purchases, $Price) = [0, 1000];
15
+  }
16
+
17
+  $Response->purchases = $Purchases;
18
+  $Response->price = $Price;
19
+  echo json_encode($Response);
3 20
 
4
-if ($LoggedUser['DisablePoints']) {
5
-  View::show_header('Store'); ?>
6
-  <div class='thin'>
7
-    <h2 id='general'>Denied</h2>
8
-    <div class='box pad' style='padding: 10px 10px 10px 20px;'>
9
-    <p>You are not allowed to spend <?=BONUS_POINTS?>.</p>
10
-    </div>
11
-  </div>
12
-  <? View::show_footer();
13 21
 } else {
14
-  if (isset($_REQUEST['item'])) {
15
-    switch ($_REQUEST['item']) {
16
-      case 'upload_1GB':
17
-        include(SERVER_ROOT.'/sections/store/upload_1GB.php');
18
-        break;
19
-      case 'upload_10GB':
20
-        include(SERVER_ROOT.'/sections/store/upload_10GB.php');
21
-        break;
22
-      case 'upload_100GB':
23
-        include(SERVER_ROOT.'/sections/store/upload_100GB.php');
24
-        break;
25
-      case 'upload_1000GB':
26
-        include(SERVER_ROOT.'/sections/store/upload_1000GB.php');
27
-        break;
28
-      case '1k_points':
29
-        include(SERVER_ROOT.'/sections/store/1k_points.php');
30
-        break;
31
-      case '10k_points':
32
-        include(SERVER_ROOT.'/sections/store/10k_points.php');
33
-        break;
34
-      case '100k_points':
35
-        include(SERVER_ROOT.'/sections/store/100k_points.php');
36
-        break;
37
-      case '1m_points':
38
-        include(SERVER_ROOT.'/sections/store/1m_points.php');
39
-        break;
40
-      case 'token':
41
-        include(SERVER_ROOT.'/sections/store/token.php');
42
-        break;
43
-      case 'freeleechize':
44
-        include(SERVER_ROOT.'/sections/store/freeleechize.php');
45
-        break;
46
-      case 'freeleechpool':
47
-        include(SERVER_ROOT.'/sections/store/freeleechpool.php');
48
-        break;
49
-      case 'invite':
50
-        include(SERVER_ROOT.'/sections/store/invite.php');
51
-        break;
52
-      case 'title':
53
-        include(SERVER_ROOT.'/sections/store/title.php');
54
-        break;
55
-      case 'promotion':
56
-        include(SERVER_ROOT.'/sections/store/promotion.php');
57
-        break;
58
-      case 'become_admin':
59
-        include(SERVER_ROOT.'/sections/store/become_admin.php');
60
-        break;
61
-      case 'badge':
62
-        include(SERVER_ROOT.'/sections/store/badge.php');
63
-        break;
64
-      case 'coinbadge':
65
-        include(SERVER_ROOT.'/sections/store/coinbadge.php');
66
-        break;
67
-      case 'capture_user':
68
-        include(SERVER_ROOT.'/sections/store/capture_user.php');
69
-        break;
70
-      default:
71
-        error(404);
72
-        break;
73
-    }
22
+  enforce_login();
23
+
24
+  if ($LoggedUser['DisablePoints']) {
25
+    View::show_header('Store'); ?>
26
+    <div class='thin'>
27
+      <h2 id='general'>Denied</h2>
28
+      <div class='box pad' style='padding: 10px 10px 10px 20px;'>
29
+      <p>You are not allowed to spend <?=BONUS_POINTS?>.</p>
30
+      </div>
31
+    </div>
32
+    <? View::show_footer();
74 33
   } else {
75
-    include(SERVER_ROOT.'/sections/store/store.php');
34
+    if (isset($_REQUEST['item'])) {
35
+      switch ($_REQUEST['item']) {
36
+        case 'upload_1GB':
37
+          include(SERVER_ROOT.'/sections/store/upload_1GB.php');
38
+          break;
39
+        case 'upload_10GB':
40
+          include(SERVER_ROOT.'/sections/store/upload_10GB.php');
41
+          break;
42
+        case 'upload_100GB':
43
+          include(SERVER_ROOT.'/sections/store/upload_100GB.php');
44
+          break;
45
+        case 'upload_1000GB':
46
+          include(SERVER_ROOT.'/sections/store/upload_1000GB.php');
47
+          break;
48
+        case '1k_points':
49
+          include(SERVER_ROOT.'/sections/store/1k_points.php');
50
+          break;
51
+        case '10k_points':
52
+          include(SERVER_ROOT.'/sections/store/10k_points.php');
53
+          break;
54
+        case '100k_points':
55
+          include(SERVER_ROOT.'/sections/store/100k_points.php');
56
+          break;
57
+        case '1m_points':
58
+          include(SERVER_ROOT.'/sections/store/1m_points.php');
59
+          break;
60
+        case 'token':
61
+          include(SERVER_ROOT.'/sections/store/token.php');
62
+          break;
63
+        case 'freeleechize':
64
+          include(SERVER_ROOT.'/sections/store/freeleechize.php');
65
+          break;
66
+        case 'freeleechpool':
67
+          include(SERVER_ROOT.'/sections/store/freeleechpool.php');
68
+          break;
69
+        case 'invite':
70
+          include(SERVER_ROOT.'/sections/store/invite.php');
71
+          break;
72
+        case 'title':
73
+          include(SERVER_ROOT.'/sections/store/title.php');
74
+          break;
75
+        case 'promotion':
76
+          include(SERVER_ROOT.'/sections/store/promotion.php');
77
+          break;
78
+        case 'become_admin':
79
+          include(SERVER_ROOT.'/sections/store/become_admin.php');
80
+          break;
81
+        case 'badge':
82
+          include(SERVER_ROOT.'/sections/store/badge.php');
83
+          break;
84
+        case 'coinbadge':
85
+          include(SERVER_ROOT.'/sections/store/coinbadge.php');
86
+          break;
87
+        case 'capture_user':
88
+          include(SERVER_ROOT.'/sections/store/capture_user.php');
89
+          break;
90
+        default:
91
+          error(404);
92
+          break;
93
+      }
94
+    } else {
95
+      include(SERVER_ROOT.'/sections/store/store.php');
96
+    }
76 97
   }
77 98
 }
78 99
 ?>

Loading…
Cancel
Save