Browse Source

Repurpose site_options table for misc values

It's what we were using it for anyway
spaghetti 8 years ago
parent
commit
592dc5dc47

+ 0
- 25
classes/siteoptions.class.php View File

@@ -1,25 +0,0 @@
1
-<?
2
-/*
3
- * Class to manage site options
4
- */
5
-class SiteOptions {
6
-
7
-  /*
8
-   * Get a site option
9
-   *
10
-   * @param string $Name The option name
11
-   * @param string $DefaultValue The value to default to if the name can't be found in the cache
12
-   */
13
-  public static function getSiteOption($Name, $DefaultValue) {
14
-    $Value = G::$Cache->get_value('site_option_' . $Name);
15
-
16
-    if ($Value === false) {
17
-      G::$DB->query("SELECT Value FROM site_options WHERE Name = '" . db_string($Name) . "'");
18
-      if (G::$DB->has_results()) {
19
-        list($Value) = G::$DB->next_record();
20
-        G::$Cache->cache_value('site_option_' . $Name, $Value);
21
-      }
22
-    }
23
-    return ($Value === false ? $DefaultValue : $Value);
24
-  }
25
-}

+ 3
- 3
gazelle.sql View File

@@ -798,11 +798,11 @@ CREATE TABLE `site_history` (
798 798
   PRIMARY KEY (`ID`)
799 799
 ) ENGINE=InnoDB CHARSET=utf8;
800 800
 
801
-CREATE TABLE `site_options` (
801
+CREATE TABLE `misc` (
802 802
   `ID` int(11) NOT NULL AUTO_INCREMENT,
803 803
   `Name` varchar(64) NOT NULL,
804
-  `Value` tinytext NOT NULL,
805
-  `Comment` text NOT NULL,
804
+  `First` text NOT NULL,
805
+  `Second` text NOT NULL,
806 806
   PRIMARY KEY (`ID`),
807 807
   UNIQUE KEY `Name` (`Name`),
808 808
   KEY `name_index` (`Name`)

+ 3
- 3
sections/contest/contest.php View File

@@ -2,9 +2,9 @@
2 2
 if (!($ContestSettings = $Cache->get_value("contest_settings"))) {
3 3
   $DB->query("
4 4
   SELECT
5
-    Value,
6
-    Comment
7
-  FROM site_options
5
+    First,
6
+    Second
7
+  FROM misc
8 8
   WHERE
9 9
     Name='ContestRules'
10 10
     OR Name='ContestTimes'

+ 4
- 4
sections/schedule/every/shop_freeleech.php View File

@@ -24,9 +24,9 @@ if ($DB->has_results()) {
24 24
   $Cache->delete_value('shop_freeleech_list');
25 25
 }
26 26
 
27
-// Also clear site_options for expired freeleech
27
+// Also clear misc table for expired freeleech
28 28
 $DB->query("
29
-  DELETE FROM site_options
30
-  WHERE Comment = 'freeleech'
31
-    AND CAST(Value AS UNSIGNED INTEGER) < " . date('U'));
29
+  DELETE FROM misc
30
+  WHERE Second = 'freeleech'
31
+    AND CAST(First AS UNSIGNED INTEGER) < " . date('U'));
32 32
 ?>

+ 9
- 9
sections/store/freeleechpool.php View File

@@ -24,15 +24,15 @@ if (isset($_POST['donation'])) {
24 24
         SET BonusPoints = BonusPoints - $Donation
25 25
         WHERE ID = $UserID");
26 26
       $DB->query("
27
-        UPDATE site_options
28
-        SET Value = Value + $Donation
27
+        UPDATE misc
28
+        SET First = First + $Donation
29 29
         WHERE Name = 'FreeleechPool'");
30 30
       $Cache->delete_value('user_info_heavy_'.$UserID);
31 31
 
32 32
       // Check to see if we're now over the target pool size
33 33
       $DB->query("
34
-        SELECT Value, Comment
35
-        FROM site_options
34
+        SELECT First, Second
35
+        FROM misc
36 36
         WHERE Name = 'FreeleechPool'");
37 37
       if ($DB->has_results()) {
38 38
         list($Pool, $Target) = $DB->next_record();
@@ -68,9 +68,9 @@ if (isset($_POST['donation'])) {
68 68
 
69 69
           $Target = rand(10000, 100000);
70 70
           $DB->query("
71
-            UPDATE site_options
72
-            SET Value = 0,
73
-                Comment = $Target
71
+            UPDATE misc
72
+            SET First = 0,
73
+                Second = $Target
74 74
             WHERE Name = 'FreeleechPool'");
75 75
         }
76 76
       }
@@ -96,8 +96,8 @@ if (isset($_POST['donation'])) {
96 96
 } else {
97 97
 
98 98
   $DB->query("
99
-    SELECT Value
100
-    FROM site_options
99
+    SELECT First
100
+    FROM misc
101 101
     WHERE Name = 'FreeleechPool'");
102 102
   if ($DB->has_results()) {
103 103
     list($Pool) = $DB->next_record();

+ 0
- 152
sections/tools/development/site_options.php View File

@@ -1,152 +0,0 @@
1
-<?
2
-if (!check_perms('admin_manage_permissions') && !check_perms('users_mod')) {
3
-    error(403);
4
-}
5
-
6
-if (!check_perms('admin_manage_permissions')) {
7
-  View::show_header('Site Options');
8
-  $DB->query("SELECT Name, Value, Comment FROM site_options");
9
-?>
10
-  <div class="header">
11
-    <h1>Site Options</h1>
12
-  </div>
13
-  <table width="100%">
14
-    <tr class="colhead">
15
-      <td>Name</td>
16
-      <td>Value</td>
17
-      <td>Comment</td>
18
-    </tr>
19
-<?
20
-  while (list($Name, $Value, $Comment) = $DB->next_record()) {
21
-?>
22
-    <tr class="row">
23
-      <td><?=$Name?></td>
24
-      <td><?=$Value?></td>
25
-      <td><?=$Comment?></td>
26
-    </tr>
27
-<?
28
-  }
29
-?>
30
-  </table>
31
-<?
32
-  View::show_footer();
33
-  die();
34
-}
35
-
36
-if (isset($_POST['submit'])) {
37
-    authorize();
38
-
39
-    if ($_POST['submit'] == 'Delete') {
40
-  $Name = db_string($_POST['name']);
41
-        $DB->query("DELETE FROM site_options WHERE Name = '" . $Name . "'");
42
-        $Cache->delete_value('site_option_' . $Name);
43
-    } else {
44
-        $Val->SetFields('name', '1', 'regex', 'The name must be separated by underscores. No spaces are allowed.', array('regex' => '/^[a-z][_a-z0-9]{0,63}$/i'));
45
-        $Val->SetFields('value', '1', 'string', 'You must specify a value for the option.');
46
-        $Val->SetFields('comment', '1', 'string', 'You must specify a comment for the option.');
47
-
48
-        $Error = $Val->ValidateForm($_POST);
49
-        if ($Error) {
50
-            error($Error);
51
-        }
52
-
53
-        $Name = db_string($_POST['name']);
54
-        $Value = db_string($_POST['value']);
55
-        $Comment = db_string($_POST['comment']);
56
-
57
-        if ($_POST['submit'] == 'Edit') {
58
-            $DB->query("SELECT Name FROM site_options WHERE ID = '" . db_string($_POST['id']) . "'");
59
-            list($OldName) = $DB->next_record();
60
-            $DB->query("
61
-                UPDATE site_options
62
-                SET
63
-                    Name = '$Name',
64
-                    Value = '$Value',
65
-                    Comment = '$Comment'
66
-                WHERE ID = '" . db_string($_POST['id']) . "'
67
-            ");
68
-            $Cache->delete_value('site_option_' . $OldName);
69
-        } else {
70
-            $DB->query("
71
-                INSERT INTO site_options (Name, Value, Comment)
72
-                VALUES ('$Name', '$Value', '$Comment')
73
-            ");
74
-        }
75
-
76
-        $Cache->delete_value('site_option_' . $Name);
77
-    }
78
-}
79
-
80
-$DB->query("
81
-    SELECT
82
-        ID,
83
-        Name,
84
-        Value,
85
-        Comment
86
-    FROM site_options
87
-    ORDER BY LOWER(Name) DESC
88
-");
89
-
90
-View::show_header('Site Options');
91
-?>
92
-
93
-<div class="header">
94
-  <h2>Site Options</h2>
95
-</div>
96
-<div class="box slight_margin">
97
-  <table>
98
-    <tr class="colhead">
99
-      <td>
100
-        <span class="tooltip" title="Words must be separated by underscores">Name</span>
101
-      </td>
102
-      <td>Value</td>
103
-      <td>Comment</td>
104
-      <td>Submit</td>
105
-    </tr>
106
-    <tr>
107
-      <form class="create_form" name="site_option" action="" method="post">
108
-        <input type="hidden" name="action" value="site_options" />
109
-        <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
110
-        <td>
111
-          <input type="text" size="40" name="name" />
112
-        </td>
113
-        <td>
114
-          <input type="text" size="20" name="value" />
115
-        </td>
116
-        <td>
117
-          <input type="text" size="75" name="comment" />
118
-        </td>
119
-        <td>
120
-          <input type="submit" name="submit" value="Create" />
121
-        </td>
122
-      </form>
123
-    </tr>
124
-<?
125
-while (list($ID, $Name, $Value, $Comment) = $DB->next_record()) {
126
-?>
127
-    <tr>
128
-      <form class="manage_form" name="site_option" action="" method="post">
129
-        <input type="hidden" name="id" value="<?=$ID?>" />
130
-        <input type="hidden" name="action" value="site_options" />
131
-        <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
132
-        <td>
133
-          <input type="text" size="40" name="name" value="<?=$Name?>" />
134
-        </td>
135
-        <td>
136
-          <input type="text" size="20" name="value" value="<?=$Value?>" />
137
-        </td>
138
-        <td>
139
-          <input type="text" size="75" name="comment" value="<?=$Comment?>" />
140
-        </td>
141
-        <td>
142
-          <input type="submit" name="submit" value="Edit" />
143
-          <input type="submit" name="submit" value="Delete" />
144
-        </td>
145
-      </form>
146
-    </tr>
147
-<?
148
-}
149
-?>
150
-  </table>
151
-</div>
152
-<? View::show_footer(); ?>

+ 2
- 2
sections/tools/index.php View File

@@ -434,8 +434,8 @@ switch ($_REQUEST['action']) {
434 434
     include(SERVER_ROOT.'/sections/tools/misc/manipulate_tree.php');
435 435
     break;
436 436
 
437
-  case 'site_options':
438
-    include(SERVER_ROOT.'/sections/tools/development/site_options.php');
437
+  case 'misc_values':
438
+    include(SERVER_ROOT.'/sections/tools/development/misc_values.php');
439 439
     break;
440 440
 
441 441
   case 'recommendations':

+ 4
- 4
sections/tools/managers/sitewide_freeleech.php View File

@@ -32,8 +32,8 @@ if (isset($_POST['type'])) {
32 32
         $DB->query($Query);
33 33
 
34 34
         $DB->query("
35
-          INSERT INTO site_options
36
-            (Name, Value, Comment)
35
+          INSERT INTO misc
36
+            (Name, First, Second)
37 37
           VALUES
38 38
             ('" . $Tag . "', '" . (time() + (60 * 60 * $Duration)) . "', 'freeleech')
39 39
           ON DUPLICATE KEY UPDATE
@@ -65,8 +65,8 @@ if (isset($_POST['type'])) {
65 65
       $Query .= " ON DUPLICATE KEY UPDATE ExpiryTime = ExpiryTime + INTERVAL " . $Duration . " HOUR";
66 66
       $DB->query($Query);
67 67
       $DB->query("
68
-        INSERT INTO site_options
69
-          (Name, Value, Comment)
68
+        INSERT INTO misc
69
+          (Name, First, Second)
70 70
         VALUES
71 71
           ('global', '" . (time() + (60 * 60 * $Duration)) . "', 'freeleech')
72 72
         ON DUPLICATE KEY UPDATE

+ 1
- 1
sections/tools/tools.php View File

@@ -223,7 +223,7 @@ View::show_header('Staff Tools');
223 223
   create_row("Rerender stylesheet gallery images", "tools.php?action=rerender_gallery", check_perms("site_debug") || check_perms("users_mod"));
224 224
   create_row("Schedule", "schedule.php?auth=$LoggedUser[AuthKey]", check_perms("site_debug"));
225 225
   create_row("Service stats", "tools.php?action=service_stats", check_perms("site_debug"));
226
-  create_row("Site options", "tools.php?action=site_options", check_perms('users_mod'));
226
+  create_row("Miscellaneous values", "tools.php?action=misc_values", check_perms('users_mod'));
227 227
   create_row("Tracker info", "tools.php?action=ocelot_info", check_perms("users_mod"));
228 228
   create_row("Update GeoIP", "tools.php?action=update_geoip", check_perms("admin_update_geoip"));
229 229
 

+ 3
- 3
sections/upload/upload_handle.php View File

@@ -541,9 +541,9 @@ if (!$Properties['GroupID']) {
541 541
 
542 542
 // Use this section to control freeleeches
543 543
 $DB->query("
544
-  SELECT Name, Value
545
-  FROM site_options
546
-  WHERE Comment = 'freeleech'");
544
+  SELECT First, Second
545
+  FROM misc
546
+  WHERE Second = 'freeleech'");
547 547
 if ($DB->has_results()) {
548 548
   $FreeLeechTags = $DB->to_array('Name');
549 549
   foreach ($FreeLeechTags as $Tag => $Exp) {

Loading…
Cancel
Save