Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
a1be208a9e

+ 18
- 16
classes/revisionhistory.class.php View File

1
-<?
2
-class RevisionHistory {
3
-  /**
4
-   * Read the revision history of an artist or torrent page
5
-   * @param string $Page artists or torrents
6
-   * @param in $PageID
7
-   * @return array
8
-   */
9
-  public static function get_revision_history($Page, $PageID) {
10
-    $Table = ($Page == 'artists') ? 'wiki_artists' : 'wiki_torrents';
11
-    $QueryID = G::$DB->get_query_id();
12
-    G::$DB->query("
1
+<?php
2
+class RevisionHistory
3
+{
4
+    /**
5
+     * Read the revision history of an artist or torrent page
6
+     * @param string $Page artists or torrents
7
+     * @param in $PageID
8
+     * @return array
9
+     */
10
+    public static function get_revision_history($Page, $PageID)
11
+    {
12
+        $Table = ($Page == 'artists') ? 'wiki_artists' : 'wiki_torrents';
13
+        $QueryID = G::$DB->get_query_id();
14
+        G::$DB->query("
13
       SELECT
15
       SELECT
14
         RevisionID,
16
         RevisionID,
15
         Summary,
17
         Summary,
18
       FROM $Table
20
       FROM $Table
19
       WHERE PageID = $PageID
21
       WHERE PageID = $PageID
20
       ORDER BY RevisionID DESC");
22
       ORDER BY RevisionID DESC");
21
-    $Ret = G::$DB->to_array();
22
-    G::$DB->set_query_id($QueryID);
23
-    return $Ret;
24
-  }
23
+        $Ret = G::$DB->to_array();
24
+        G::$DB->set_query_id($QueryID);
25
+        return $Ret;
26
+    }
25
 }
27
 }

+ 26
- 24
classes/revisionhistoryview.class.php View File

1
-<?
2
-class RevisionHistoryView {
3
-  /**
4
-   * Render the revision history
5
-   * @param array $RevisionHistory see RevisionHistory::get_revision_history
6
-   * @param string $BaseURL
7
-   */
8
-  public static function render_revision_history($RevisionHistory, $BaseURL) {
9
-?>
1
+<?php
2
+class RevisionHistoryView
3
+{
4
+    /**
5
+     * Render the revision history
6
+     * @param array $RevisionHistory see RevisionHistory::get_revision_history
7
+     * @param string $BaseURL
8
+     */
9
+    public static function render_revision_history($RevisionHistory, $BaseURL)
10
+    {
11
+        ?>
10
   <table cellpadding="6" cellspacing="1" border="0" width="100%" class="box">
12
   <table cellpadding="6" cellspacing="1" border="0" width="100%" class="box">
11
     <tr class="colhead">
13
     <tr class="colhead">
12
       <td>Revision</td>
14
       <td>Revision</td>
13
       <td>Date</td>
15
       <td>Date</td>
14
-<? if (check_perms('users_mod')) { ?>
16
+        <?php if (check_perms('users_mod')) { ?>
15
       <td>User</td>
17
       <td>User</td>
16
-<? } ?>
18
+        <?php } ?>
17
       <td>Summary</td>
19
       <td>Summary</td>
18
     </tr>
20
     </tr>
19
-<?
20
-    foreach ($RevisionHistory as $Entry) {
21
-      list($RevisionID, $Summary, $Time, $UserID) = $Entry;
22
-?>
21
+        <?php
22
+        foreach ($RevisionHistory as $Entry) {
23
+            list($RevisionID, $Summary, $Time, $UserID) = $Entry; ?>
23
     <tr class="row">
24
     <tr class="row">
24
       <td>
25
       <td>
25
-        <?= "<a href=\"$BaseURL&amp;revisionid=$RevisionID\">#$RevisionID</a>" ?>
26
+            <?= "<a href=\"$BaseURL&amp;revisionid=$RevisionID\">#$RevisionID</a>" ?>
26
       </td>
27
       </td>
27
       <td>
28
       <td>
28
-        <?=$Time?>
29
+            <?=$Time?>
29
       </td>
30
       </td>
30
-<? if (check_perms('users_mod')) { ?>
31
+            <?php if (check_perms('users_mod')) { ?>
31
       <td>
32
       <td>
32
-        <?=Users::format_username($UserID, false, false, false)?>
33
+                <?=Users::format_username($UserID, false, false, false)?>
33
       </td>
34
       </td>
34
-<? } ?>
35
+            <?php } ?>
35
       <td>
36
       <td>
36
-        <?=($Summary ? $Summary : '(empty)')?>
37
+            <?=($Summary ? $Summary : '(empty)')?>
37
       </td>
38
       </td>
38
     </tr>
39
     </tr>
39
-<?    } ?>
40
+            <?php
41
+        } ?>
40
   </table>
42
   </table>
41
-<?
42
-  }
43
+        <?php
44
+    }
43
 }
45
 }

+ 38
- 33
classes/rules.class.php View File

1
 <?php
1
 <?php
2
-class Rules {
2
+class Rules
3
+{
3
 
4
 
4
   /**
5
   /**
5
    * Displays the site's "Golden Rules".
6
    * Displays the site's "Golden Rules".
6
    *
7
    *
7
    */
8
    */
8
-  public static function display_golden_rules() {
9
-    ?>
9
+    public static function display_golden_rules()
10
+    {
11
+        ?>
10
     <ol>
12
     <ol>
11
       <li>Staff can do anything to anyone for any reason (or no reason). If you take issue with a decision, you must do so privately with the staff member who issued the decision or with an administrator of the site.</li>
13
       <li>Staff can do anything to anyone for any reason (or no reason). If you take issue with a decision, you must do so privately with the staff member who issued the decision or with an administrator of the site.</li>
12
       <li>One account per person per lifetime.</li>
14
       <li>One account per person per lifetime.</li>
16
       <li>Attempting to find a bug in the site code is allowed and sometimes even rewarded. Follow proper disclosure procedures by contacting staff about the issue well before disclosing it publicly. Do not misuse any bugs you may discover. Do not attempt to portray abuse as a bug in the hopes of a reward.</li>
18
       <li>Attempting to find a bug in the site code is allowed and sometimes even rewarded. Follow proper disclosure procedures by contacting staff about the issue well before disclosing it publicly. Do not misuse any bugs you may discover. Do not attempt to portray abuse as a bug in the hopes of a reward.</li>
17
       <li>Don't reveal the criteria for hidden badges or events.</li>
19
       <li>Don't reveal the criteria for hidden badges or events.</li>
18
     </ol>
20
     </ol>
19
-<?
20
-  }
21
-
22
-  /**
23
-   * Displays the site's rules for tags.
24
-   *
25
-   * @param boolean $OnUpload - whether it's being displayed on a torrent upload form
26
-   */
27
-  public static function display_site_tag_rules($OnUpload = false) {
28
-    ?>
21
+        <?php
22
+    }
23
+
24
+    /**
25
+     * Displays the site's rules for tags.
26
+     *
27
+     * @param boolean $OnUpload - whether it's being displayed on a torrent upload form
28
+     */
29
+    public static function display_site_tag_rules($OnUpload = false)
30
+    {
31
+        ?>
29
     <ul>
32
     <ul>
30
       <li>Tags should be comma-separated, and you should use a period (".") to separate words inside a tag &mdash; e.g. "<strong class="important_text_alt">big.breasts</strong>".</li>
33
       <li>Tags should be comma-separated, and you should use a period (".") to separate words inside a tag &mdash; e.g. "<strong class="important_text_alt">big.breasts</strong>".</li>
31
 
34
 
60
 
63
 
61
       <li><strong>You should be able to build up a list of tags using only the official tags <?=($OnUpload ? 'to the left of the text box' : 'on <a href="upload.php">the torrent upload page</a>')?>.</strong> If you are in any doubt about whether or not a tag is acceptable, do not add it.</li>
64
       <li><strong>You should be able to build up a list of tags using only the official tags <?=($OnUpload ? 'to the left of the text box' : 'on <a href="upload.php">the torrent upload page</a>')?>.</strong> If you are in any doubt about whether or not a tag is acceptable, do not add it.</li>
62
     </ul>
65
     </ul>
63
-<?
64
-  }
65
-
66
-  /**
67
-   * Displays the site's rules for the forum
68
-   *
69
-   */
70
-  public static function display_forum_rules() {
71
-    ?>
66
+        <?php
67
+    }
68
+
69
+    /**
70
+     * Displays the site's rules for the forum
71
+     *
72
+     */
73
+    public static function display_forum_rules()
74
+    {
75
+        ?>
72
     <ol>
76
     <ol>
73
       <li>Many forums have their own set of rules. Make sure you read and take note of these rules before you attempt to post in one of these forums.</li>
77
       <li>Many forums have their own set of rules. Make sure you read and take note of these rules before you attempt to post in one of these forums.</li>
74
       <li>No commercial advertising or referral schemes. This includes any scheme in which the poster gets personal gain from users clicking a link. You will be immediately banned for this, no questions asked.</li>
78
       <li>No commercial advertising or referral schemes. This includes any scheme in which the poster gets personal gain from users clicking a link. You will be immediately banned for this, no questions asked.</li>
85
       <li>No language other than English (and Japanese, when relevant) is permitted in the forums.</li>
89
       <li>No language other than English (and Japanese, when relevant) is permitted in the forums.</li>
86
       <li>Some things that <em>are</em> allowed include mature and graphic content, political and religious discussions, and insults. You are welcome to express whatever inflammatory opinions you want as long as you don't go overboard with it.</li>
90
       <li>Some things that <em>are</em> allowed include mature and graphic content, political and religious discussions, and insults. You are welcome to express whatever inflammatory opinions you want as long as you don't go overboard with it.</li>
87
     </ol>
91
     </ol>
88
-<?
89
-  }
90
-
91
-  /**
92
-   * Displays the site's rules for conversing on its IRC network
93
-   *
94
-   */
95
-  public static function display_irc_chat_rules() {
96
-    ?>
92
+        <?php
93
+    }
94
+
95
+    /**
96
+     * Displays the site's rules for conversing on its IRC network
97
+     *
98
+     */
99
+    public static function display_irc_chat_rules()
100
+    {
101
+        ?>
97
     <ol>
102
     <ol>
98
       <li>Staff have the final decision. If a staff member says stop and you continue, expect repercussions.</li>
103
       <li>Staff have the final decision. If a staff member says stop and you continue, expect repercussions.</li>
99
       <li>Do not leave Caps Lock enabled all the time. It gets annoying, and you will likely get yourself kicked.</li>
104
       <li>Do not leave Caps Lock enabled all the time. It gets annoying, and you will likely get yourself kicked.</li>
110
       <li>Unofficial channels are <em>not</em> policed by staff. Any content or discussion that goes on in unofficial channels shoud be treated as part of an unrelated public irc network.</li>
115
       <li>Unofficial channels are <em>not</em> policed by staff. Any content or discussion that goes on in unofficial channels shoud be treated as part of an unrelated public irc network.</li>
111
       <li><strong>Read the channel topic before asking questions.</strong></li>
116
       <li><strong>Read the channel topic before asking questions.</strong></li>
112
     </ol>
117
     </ol>
113
-<?
114
-  }
118
+        <?php
119
+    }
115
 }
120
 }

+ 184
- 176
classes/script_start.php View File

12
 require 'config.php'; //The config contains all site wide configuration information
12
 require 'config.php'; //The config contains all site wide configuration information
13
 
13
 
14
 // Check for common setup pitfalls
14
 // Check for common setup pitfalls
15
-if (!ini_get('short_open_tag')) { die('short_open_tag must be On in php.ini'); }
16
-if (!extension_loaded('apcu')) { die('APCu extension not loaded'); }
15
+if (!ini_get('short_open_tag')) {
16
+    die('short_open_tag must be On in php.ini');
17
+}
18
+if (!extension_loaded('apcu')) {
19
+    die('APCu extension not loaded');
20
+}
17
 
21
 
18
 // Deal with dumbasses
22
 // Deal with dumbasses
19
 if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) {
23
 if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) {
20
-  die('d14:failure reason40:Invalid .torrent, try downloading again.e');
24
+    die('d14:failure reason40:Invalid .torrent, try downloading again.e');
21
 }
25
 }
22
 
26
 
23
 require(SERVER_ROOT.'/classes/proxies.class.php');
27
 require(SERVER_ROOT.'/classes/proxies.class.php');
25
 // Get the user's actual IP address if they're proxied.
29
 // Get the user's actual IP address if they're proxied.
26
 // Or if cloudflare is used
30
 // Or if cloudflare is used
27
 if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
31
 if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
28
-  $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
32
+    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
29
 }
33
 }
30
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
34
 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
31
     && proxyCheck($_SERVER['REMOTE_ADDR'])
35
     && proxyCheck($_SERVER['REMOTE_ADDR'])
32
-    && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'],
36
+    && filter_var(
37
+        $_SERVER['HTTP_X_FORWARDED_FOR'],
33
         FILTER_VALIDATE_IP,
38
         FILTER_VALIDATE_IP,
34
-        FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
35
-  $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
39
+        FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
40
+    )) {
41
+    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
36
 }
42
 }
37
 
43
 
38
 if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) {
44
 if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) {
39
-  // Skip this block if running from cli or if the browser is old and shitty
40
-  // This should really be done in nginx config TODO: Remove
41
-  if ($_SERVER['HTTP_HOST'] == 'www.'.SITE_DOMAIN) {
42
-    header('Location: https://'.SITE_DOMAIN.$_SERVER['REQUEST_URI']); die();
43
-  }
45
+    // Skip this block if running from cli or if the browser is old and shitty
46
+    // This should really be done in nginx config TODO: Remove
47
+    if ($_SERVER['HTTP_HOST'] == 'www.'.SITE_DOMAIN) {
48
+        header('Location: https://'.SITE_DOMAIN.$_SERVER['REQUEST_URI']);
49
+        die();
50
+    }
44
 }
51
 }
45
 
52
 
46
 
53
 
47
 
54
 
48
 $ScriptStartTime = microtime(true); //To track how long a page takes to create
55
 $ScriptStartTime = microtime(true); //To track how long a page takes to create
49
 if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
56
 if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
50
-  $RUsage = getrusage();
51
-  $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
57
+    $RUsage = getrusage();
58
+    $CPUTimeStart = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'];
52
 }
59
 }
53
 ob_start(); //Start a buffer, mainly in case there is a mysql error
60
 ob_start(); //Start a buffer, mainly in case there is a mysql error
54
 
61
 
97
 // Permissions
104
 // Permissions
98
 
105
 
99
 if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
106
 if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
100
-  $SessionID = $_COOKIE['session'];
101
-  $LoggedUser['ID'] = (int)$_COOKIE['userid'];
107
+    $SessionID = $_COOKIE['session'];
108
+    $LoggedUser['ID'] = (int)$_COOKIE['userid'];
102
 
109
 
103
-  $UserID = $LoggedUser['ID']; //TODO: UserID should not be LoggedUser
110
+    $UserID = $LoggedUser['ID']; //TODO: UserID should not be LoggedUser
104
 
111
 
105
-  if (!$LoggedUser['ID'] || !$SessionID) {
106
-    logout();
107
-  }
112
+    if (!$LoggedUser['ID'] || !$SessionID) {
113
+        logout();
114
+    }
108
 
115
 
109
-  $UserSessions = $Cache->get_value("users_sessions_$UserID");
110
-  if (!is_array($UserSessions)) {
111
-    $DB->query(
112
-     "SELECT
116
+    $UserSessions = $Cache->get_value("users_sessions_$UserID");
117
+    if (!is_array($UserSessions)) {
118
+        $DB->query(
119
+            "SELECT
113
         SessionID,
120
         SessionID,
114
         Browser,
121
         Browser,
115
         OperatingSystem,
122
         OperatingSystem,
118
       FROM users_sessions
125
       FROM users_sessions
119
       WHERE UserID = '$UserID'
126
       WHERE UserID = '$UserID'
120
         AND Active = 1
127
         AND Active = 1
121
-      ORDER BY LastUpdate DESC");
122
-    $UserSessions = $DB->to_array('SessionID',MYSQLI_ASSOC);
123
-    $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
124
-  }
128
+      ORDER BY LastUpdate DESC"
129
+        );
130
+        $UserSessions = $DB->to_array('SessionID', MYSQLI_ASSOC);
131
+        $Cache->cache_value("users_sessions_$UserID", $UserSessions, 0);
132
+    }
125
 
133
 
126
-  if (!array_key_exists($SessionID, $UserSessions)) {
127
-    logout();
128
-  }
134
+    if (!array_key_exists($SessionID, $UserSessions)) {
135
+        logout();
136
+    }
129
 
137
 
130
-  // Check if user is enabled
131
-  $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
132
-  if ($Enabled === false) {
133
-    $DB->query("
138
+    // Check if user is enabled
139
+    $Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
140
+    if ($Enabled === false) {
141
+        $DB->query("
134
       SELECT Enabled
142
       SELECT Enabled
135
       FROM users_main
143
       FROM users_main
136
       WHERE ID = '$LoggedUser[ID]'");
144
       WHERE ID = '$LoggedUser[ID]'");
137
-    list($Enabled) = $DB->next_record();
138
-    $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
139
-  }
140
-  if ($Enabled == 2) {
141
-    logout();
142
-  }
145
+        list($Enabled) = $DB->next_record();
146
+        $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
147
+    }
148
+    if ($Enabled == 2) {
149
+        logout();
150
+    }
143
 
151
 
144
-  // Up/Down stats
145
-  $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
146
-  if (!is_array($UserStats)) {
147
-    $DB->query("
152
+    // Up/Down stats
153
+    $UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
154
+    if (!is_array($UserStats)) {
155
+        $DB->query("
148
       SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio
156
       SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio
149
       FROM users_main
157
       FROM users_main
150
       WHERE ID = '$LoggedUser[ID]'");
158
       WHERE ID = '$LoggedUser[ID]'");
151
-    $UserStats = $DB->next_record(MYSQLI_ASSOC);
152
-    $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
153
-  }
159
+        $UserStats = $DB->next_record(MYSQLI_ASSOC);
160
+        $Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
161
+    }
154
 
162
 
155
-  // Get info such as username
156
-  $LightInfo = Users::user_info($LoggedUser['ID']);
157
-  $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
163
+    // Get info such as username
164
+    $LightInfo = Users::user_info($LoggedUser['ID']);
165
+    $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
158
 
166
 
159
-  // Create LoggedUser array
160
-  $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
167
+    // Create LoggedUser array
168
+    $LoggedUser = array_merge($HeavyInfo, $LightInfo, $UserStats);
161
 
169
 
162
-  $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
170
+    $LoggedUser['RSS_Auth'] = md5($LoggedUser['ID'] . RSS_HASH . $LoggedUser['torrent_pass']);
163
 
171
 
164
-  // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
165
-  $LoggedUser['RatioWatch'] = (
166
-    $LoggedUser['RatioWatchEnds']
172
+    // $LoggedUser['RatioWatch'] as a bool to disable things for users on Ratio Watch
173
+    $LoggedUser['RatioWatch'] = (
174
+        $LoggedUser['RatioWatchEnds']
167
     && time() < strtotime($LoggedUser['RatioWatchEnds'])
175
     && time() < strtotime($LoggedUser['RatioWatchEnds'])
168
     && ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
176
     && ($LoggedUser['BytesDownloaded'] * $LoggedUser['RequiredRatio']) > $LoggedUser['BytesUploaded']
169
-  );
177
+    );
170
 
178
 
171
-  // Load in the permissions
172
-  $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
173
-  $LoggedUser['Permissions']['MaxCollages'] += Donations::get_personal_collages($LoggedUser['ID']);
179
+    // Load in the permissions
180
+    $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
181
+    $LoggedUser['Permissions']['MaxCollages'] += Donations::get_personal_collages($LoggedUser['ID']);
174
 
182
 
175
-  // Change necessary triggers in external components
176
-  $Cache->CanClear = check_perms('admin_clear_cache');
183
+    // Change necessary triggers in external components
184
+    $Cache->CanClear = check_perms('admin_clear_cache');
177
 
185
 
178
-  // Because we <3 our staff
179
-  if (check_perms('site_disable_ip_history')) {
180
-    $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
181
-  }
186
+    // Because we <3 our staff
187
+    if (check_perms('site_disable_ip_history')) {
188
+        $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
189
+    }
182
 
190
 
183
-  // Update LastUpdate every 10 minutes
184
-  if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
185
-    $DB->query("
191
+    // Update LastUpdate every 10 minutes
192
+    if (strtotime($UserSessions[$SessionID]['LastUpdate']) + 600 < time()) {
193
+        $DB->query("
186
       UPDATE users_main
194
       UPDATE users_main
187
       SET LastAccess = NOW()
195
       SET LastAccess = NOW()
188
       WHERE ID = '$LoggedUser[ID]'");
196
       WHERE ID = '$LoggedUser[ID]'");
189
-    $SessionQuery =
190
-     "UPDATE users_sessions
197
+        $SessionQuery =
198
+        "UPDATE users_sessions
191
       SET ";
199
       SET ";
192
-    // Only update IP if we have an encryption key in memory
193
-    if (apcu_exists('DBKEY')) {
194
-      $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
195
-    }
196
-    $SessionQuery .=
197
-       "Browser = '$Browser',
200
+        // Only update IP if we have an encryption key in memory
201
+        if (apcu_exists('DBKEY')) {
202
+            $SessionQuery .= "IP = '".Crypto::encrypt($_SERVER['REMOTE_ADDR'])."', ";
203
+        }
204
+        $SessionQuery .=
205
+         "Browser = '$Browser',
198
         OperatingSystem = '$OperatingSystem',
206
         OperatingSystem = '$OperatingSystem',
199
         LastUpdate = NOW()
207
         LastUpdate = NOW()
200
       WHERE UserID = '$LoggedUser[ID]'
208
       WHERE UserID = '$LoggedUser[ID]'
201
         AND SessionID = '".db_string($SessionID)."'";
209
         AND SessionID = '".db_string($SessionID)."'";
202
-    $DB->query($SessionQuery);
203
-    $Cache->begin_transaction("users_sessions_$UserID");
204
-    $Cache->delete_row($SessionID);
205
-    $UsersSessionCache = array(
210
+        $DB->query($SessionQuery);
211
+        $Cache->begin_transaction("users_sessions_$UserID");
212
+        $Cache->delete_row($SessionID);
213
+        $UsersSessionCache = array(
206
         'SessionID' => $SessionID,
214
         'SessionID' => $SessionID,
207
         'Browser' => $Browser,
215
         'Browser' => $Browser,
208
         'OperatingSystem' => $OperatingSystem,
216
         'OperatingSystem' => $OperatingSystem,
209
         'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
217
         'IP' => (apcu_exists('DBKEY') ? Crypto::encrypt($_SERVER['REMOTE_ADDR']) : $UserSessions[$SessionID]['IP']),
210
         'LastUpdate' => sqltime() );
218
         'LastUpdate' => sqltime() );
211
-    $Cache->insert_front($SessionID, $UsersSessionCache);
212
-    $Cache->commit_transaction(0);
213
-  }
214
-
215
-  // Notifications
216
-  if (isset($LoggedUser['Permissions']['site_torrents_notify'])) {
217
-    $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
218
-    if (!is_array($LoggedUser['Notify'])) {
219
-      $DB->query("
219
+        $Cache->insert_front($SessionID, $UsersSessionCache);
220
+        $Cache->commit_transaction(0);
221
+    }
222
+
223
+    // Notifications
224
+    if (isset($LoggedUser['Permissions']['site_torrents_notify'])) {
225
+        $LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
226
+        if (!is_array($LoggedUser['Notify'])) {
227
+            $DB->query("
220
         SELECT ID, Label
228
         SELECT ID, Label
221
         FROM users_notify_filters
229
         FROM users_notify_filters
222
         WHERE UserID = '$LoggedUser[ID]'");
230
         WHERE UserID = '$LoggedUser[ID]'");
223
-      $LoggedUser['Notify'] = $DB->to_array('ID');
224
-      $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
231
+            $LoggedUser['Notify'] = $DB->to_array('ID');
232
+            $Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
233
+        }
225
     }
234
     }
226
-  }
227
-
228
-  // We've never had to disable the wiki privs of anyone.
229
-  if ($LoggedUser['DisableWiki']) {
230
-    unset($LoggedUser['Permissions']['site_edit_wiki']);
231
-  }
232
 
235
 
233
-  // IP changed
236
+    // We've never had to disable the wiki privs of anyone.
237
+    if ($LoggedUser['DisableWiki']) {
238
+        unset($LoggedUser['Permissions']['site_edit_wiki']);
239
+    }
234
 
240
 
235
-  if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
241
+    // IP changed
236
 
242
 
237
-    if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
238
-      error('Your IP address has been banned.');
239
-    }
243
+    if (apcu_exists('DBKEY') && Crypto::decrypt($LoggedUser['IP']) != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
244
+        if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
245
+            error('Your IP address has been banned.');
246
+        }
240
 
247
 
241
-    $CurIP = db_string($LoggedUser['IP']);
242
-    $NewIP = db_string($_SERVER['REMOTE_ADDR']);
243
-    $DB->query("
248
+        $CurIP = db_string($LoggedUser['IP']);
249
+        $NewIP = db_string($_SERVER['REMOTE_ADDR']);
250
+        $DB->query("
244
       SELECT IP
251
       SELECT IP
245
       FROM users_history_ips
252
       FROM users_history_ips
246
       WHERE EndTime IS NULL
253
       WHERE EndTime IS NULL
247
         AND UserID = '$LoggedUser[ID]'");
254
         AND UserID = '$LoggedUser[ID]'");
248
-    while (list($EncIP) = $DB->next_record()) {
249
-      if (Crypto::decrypt($EncIP) == $CurIP) {
250
-        $CurIP = $EncIP;
251
-        // CurIP is now the encrypted IP that was already in the database (for matching)
252
-        break;
253
-      }
254
-    }
255
-    $DB->query("
255
+        while (list($EncIP) = $DB->next_record()) {
256
+            if (Crypto::decrypt($EncIP) == $CurIP) {
257
+                $CurIP = $EncIP;
258
+                // CurIP is now the encrypted IP that was already in the database (for matching)
259
+                break;
260
+            }
261
+        }
262
+        $DB->query("
256
       UPDATE users_history_ips
263
       UPDATE users_history_ips
257
       SET EndTime = NOW()
264
       SET EndTime = NOW()
258
       WHERE EndTime IS NULL
265
       WHERE EndTime IS NULL
259
         AND UserID = '$LoggedUser[ID]'
266
         AND UserID = '$LoggedUser[ID]'
260
         AND IP = '$CurIP'");
267
         AND IP = '$CurIP'");
261
-    $DB->query("
268
+        $DB->query("
262
       INSERT IGNORE INTO users_history_ips
269
       INSERT IGNORE INTO users_history_ips
263
         (UserID, IP, StartTime)
270
         (UserID, IP, StartTime)
264
       VALUES
271
       VALUES
265
         ('$LoggedUser[ID]', '".Crypto::encrypt($NewIP)."', NOW())");
272
         ('$LoggedUser[ID]', '".Crypto::encrypt($NewIP)."', NOW())");
266
 
273
 
267
-    $ipcc = Tools::geoip($NewIP);
268
-    $DB->query("
274
+        $ipcc = Tools::geoip($NewIP);
275
+        $DB->query("
269
       UPDATE users_main
276
       UPDATE users_main
270
       SET IP = '".Crypto::encrypt($NewIP)."', ipcc = '$ipcc'
277
       SET IP = '".Crypto::encrypt($NewIP)."', ipcc = '$ipcc'
271
       WHERE ID = '$LoggedUser[ID]'");
278
       WHERE ID = '$LoggedUser[ID]'");
272
-    $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
273
-    $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
274
-    $Cache->commit_transaction(0);
275
-
276
-
277
-  }
279
+        $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
280
+        $Cache->update_row(false, array('IP' => Crypto::encrypt($_SERVER['REMOTE_ADDR'])));
281
+        $Cache->commit_transaction(0);
282
+    }
278
 
283
 
279
 
284
 
280
-  // Get stylesheets
281
-  $Stylesheets = $Cache->get_value('stylesheets');
282
-  if (!is_array($Stylesheets)) {
283
-    $DB->query('
285
+    // Get stylesheets
286
+    $Stylesheets = $Cache->get_value('stylesheets');
287
+    if (!is_array($Stylesheets)) {
288
+        $DB->query('
284
       SELECT
289
       SELECT
285
         ID,
290
         ID,
286
         LOWER(REPLACE(Name, " ", "_")) AS Name,
291
         LOWER(REPLACE(Name, " ", "_")) AS Name,
288
         LOWER(REPLACE(Additions, " ", "_")) AS Additions,
293
         LOWER(REPLACE(Additions, " ", "_")) AS Additions,
289
         Additions AS ProperAdditions
294
         Additions AS ProperAdditions
290
       FROM stylesheets');
295
       FROM stylesheets');
291
-    $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
292
-    $Cache->cache_value('stylesheets', $Stylesheets, 0);
293
-  }
296
+        $Stylesheets = $DB->to_array('ID', MYSQLI_BOTH);
297
+        $Cache->cache_value('stylesheets', $Stylesheets, 0);
298
+    }
294
 
299
 
295
-  //A9 TODO: Clean up this messy solution
296
-  $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
300
+    //A9 TODO: Clean up this messy solution
301
+    $LoggedUser['StyleName'] = $Stylesheets[$LoggedUser['StyleID']]['Name'];
297
 
302
 
298
-  if (empty($LoggedUser['Username'])) {
299
-    logout(); // Ghost
300
-  }
303
+    if (empty($LoggedUser['Username'])) {
304
+        logout(); // Ghost
305
+    }
301
 }
306
 }
302
 G::initialize();
307
 G::initialize();
303
 $Debug->set_flag('end user handling');
308
 $Debug->set_flag('end user handling');
307
 /**
312
 /**
308
  * Log out the current session
313
  * Log out the current session
309
  */
314
  */
310
-function logout() {
311
-  global $SessionID;
312
-  setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
313
-  setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
314
-  setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
315
-  if ($SessionID) {
316
-
317
-    G::$DB->query("
315
+function logout()
316
+{
317
+    global $SessionID;
318
+    setcookie('session', '', time() - 60 * 60 * 24 * 365, '/', '', false);
319
+    setcookie('userid', '', time() - 60 * 60 * 24 * 365, '/', '', false);
320
+    setcookie('keeplogged', '', time() - 60 * 60 * 24 * 365, '/', '', false);
321
+    if ($SessionID) {
322
+        G::$DB->query("
318
       DELETE FROM users_sessions
323
       DELETE FROM users_sessions
319
       WHERE UserID = '" . G::$LoggedUser['ID'] . "'
324
       WHERE UserID = '" . G::$LoggedUser['ID'] . "'
320
         AND SessionID = '".db_string($SessionID)."'");
325
         AND SessionID = '".db_string($SessionID)."'");
321
 
326
 
322
-    G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
323
-    G::$Cache->delete_row($SessionID);
324
-    G::$Cache->commit_transaction(0);
325
-  }
326
-  G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
327
-  G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
328
-  G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
327
+        G::$Cache->begin_transaction('users_sessions_' . G::$LoggedUser['ID']);
328
+        G::$Cache->delete_row($SessionID);
329
+        G::$Cache->commit_transaction(0);
330
+    }
331
+    G::$Cache->delete_value('user_info_' . G::$LoggedUser['ID']);
332
+    G::$Cache->delete_value('user_stats_' . G::$LoggedUser['ID']);
333
+    G::$Cache->delete_value('user_info_heavy_' . G::$LoggedUser['ID']);
329
 
334
 
330
-  header('Location: login.php');
335
+    header('Location: login.php');
331
 
336
 
332
-  die();
337
+    die();
333
 }
338
 }
334
 
339
 
335
-function logout_all_sessions() {
336
-  $UserID = G::$LoggedUser['ID'];
340
+function logout_all_sessions()
341
+{
342
+    $UserID = G::$LoggedUser['ID'];
337
 
343
 
338
-  G::$DB->query("
344
+    G::$DB->query("
339
     DELETE FROM users_sessions
345
     DELETE FROM users_sessions
340
     WHERE UserID = '$UserID'");
346
     WHERE UserID = '$UserID'");
341
 
347
 
342
-  G::$Cache->delete_value('users_sessions_' . $UserID);
343
-  logout();
348
+    G::$Cache->delete_value('users_sessions_' . $UserID);
349
+    logout();
344
 }
350
 }
345
 
351
 
346
-function enforce_login() {
347
-  global $SessionID;
348
-  if (!$SessionID || !G::$LoggedUser) {
349
-    setcookie('redirect', $_SERVER['REQUEST_URI'], time() + 60 * 30, '/', '', false);
350
-    logout();
351
-  }
352
+function enforce_login()
353
+{
354
+    global $SessionID;
355
+    if (!$SessionID || !G::$LoggedUser) {
356
+        setcookie('redirect', $_SERVER['REQUEST_URI'], time() + 60 * 30, '/', '', false);
357
+        logout();
358
+    }
352
 }
359
 }
353
 
360
 
354
 /**
361
 /**
358
  * @param Are we using ajax?
365
  * @param Are we using ajax?
359
  * @return authorisation status. Prints an error message to LAB_CHAN on IRC on failure.
366
  * @return authorisation status. Prints an error message to LAB_CHAN on IRC on failure.
360
  */
367
  */
361
-function authorize($Ajax = false) {
362
-  if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != G::$LoggedUser['AuthKey']) {
363
-    send_irc("PRIVMSG ".LAB_CHAN." :".G::$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER']) ? " coming from ".$_SERVER['HTTP_REFERER'] : ""));
364
-    error('Invalid authorization key. Go back, refresh, and try again.', $Ajax);
365
-    return false;
366
-  }
367
-  return true;
368
+function authorize($Ajax = false)
369
+{
370
+    if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != G::$LoggedUser['AuthKey']) {
371
+        send_irc("PRIVMSG ".LAB_CHAN." :".G::$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER']) ? " coming from ".$_SERVER['HTTP_REFERER'] : ""));
372
+        error('Invalid authorization key. Go back, refresh, and try again.', $Ajax);
373
+        return false;
374
+    }
375
+    return true;
368
 }
376
 }
369
 
377
 
370
 $Debug->set_flag('ending function definitions');
378
 $Debug->set_flag('ending function definitions');
371
 //Include /sections/*/index.php
379
 //Include /sections/*/index.php
372
 $Document = basename(parse_url($_SERVER['SCRIPT_FILENAME'], PHP_URL_PATH), '.php');
380
 $Document = basename(parse_url($_SERVER['SCRIPT_FILENAME'], PHP_URL_PATH), '.php');
373
 if (!preg_match('/^[a-z0-9]+$/i', $Document)) {
381
 if (!preg_match('/^[a-z0-9]+$/i', $Document)) {
374
-  error(404);
382
+    error(404);
375
 }
383
 }
376
 
384
 
377
 $StripPostKeys = array_fill_keys(array('password', 'cur_pass', 'new_pass_1', 'new_pass_2', 'verifypassword', 'confirm_password', 'ChangePassword', 'Password'), true);
385
 $StripPostKeys = array_fill_keys(array('password', 'cur_pass', 'new_pass_1', 'new_pass_2', 'verifypassword', 'confirm_password', 'ChangePassword', 'Password'), true);
388
 $AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
396
 $AllowedPages = ['staffpm', 'ajax', 'locked', 'logout', 'login'];
389
 
397
 
390
 if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
398
 if (isset(G::$LoggedUser['LockedAccount']) && !in_array($Document, $AllowedPages)) {
391
-  require(SERVER_ROOT . '/sections/locked/index.php');
399
+    require(SERVER_ROOT . '/sections/locked/index.php');
392
 } else {
400
 } else {
393
-  require(SERVER_ROOT . '/sections/' . $Document . '/index.php');
401
+    require(SERVER_ROOT . '/sections/' . $Document . '/index.php');
394
 }
402
 }
395
 
403
 
396
 $Debug->set_flag('completed module execution');
404
 $Debug->set_flag('completed module execution');
401
 Old versions of Internet Explorer choke when downloading binary files over HTTPS with disabled cache.
409
 Old versions of Internet Explorer choke when downloading binary files over HTTPS with disabled cache.
402
 Define the following constant in files that handle file downloads */
410
 Define the following constant in files that handle file downloads */
403
 if (!defined('SKIP_NO_CACHE_HEADERS')) {
411
 if (!defined('SKIP_NO_CACHE_HEADERS')) {
404
-  header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
405
-  header('Pragma: no-cache');
412
+    header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
413
+    header('Pragma: no-cache');
406
 }
414
 }
407
 
415
 
408
 //Flush to user
416
 //Flush to user

+ 170
- 159
classes/sitehistory.class.php View File

1
-<?
1
+<?php
2
 
2
 
3
-class SiteHistory {
4
-  private static $Categories = array(1 => "Code", "Event", "Milestone", "Policy", "Release", "Staff Change");
5
-  private static $SubCategories = array(1 => "Announcement", "Blog Post", "Change Log", "Forum Post", "Wiki", "Other", "External Source");
6
-  private static $Tags = array(
3
+class SiteHistory
4
+{
5
+    private static $Categories = array(1 => "Code", "Event", "Milestone", "Policy", "Release", "Staff Change");
6
+    private static $SubCategories = array(1 => "Announcement", "Blog Post", "Change Log", "Forum Post", "Wiki", "Other", "External Source");
7
+    private static $Tags = array(
7
                 "api",
8
                 "api",
8
                 "celebration",
9
                 "celebration",
9
                 "class.primary",
10
                 "class.primary",
64
                 "whitelist",
65
                 "whitelist",
65
                 "wiki");
66
                 "wiki");
66
 
67
 
67
-  public static function get_months() {
68
-    $Results = G::$Cache->get_value("site_history_months");
69
-    if (!$Results) {
70
-      $QueryID = G::$DB->get_query_id();
71
-      G::$DB->query("
68
+    public static function get_months()
69
+    {
70
+        $Results = G::$Cache->get_value("site_history_months");
71
+        if (!$Results) {
72
+            $QueryID = G::$DB->get_query_id();
73
+            G::$DB->query("
72
           SELECT DISTINCT
74
           SELECT DISTINCT
73
             YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
75
             YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
74
           FROM site_history
76
           FROM site_history
75
           ORDER BY Date DESC");
77
           ORDER BY Date DESC");
76
-      $Results = G::$DB->to_array();
77
-      G::$DB->set_query_id($QueryID);
78
-      G::$Cache->cache_value("site_history_months", $Results, 0);
78
+            $Results = G::$DB->to_array();
79
+            G::$DB->set_query_id($QueryID);
80
+            G::$Cache->cache_value("site_history_months", $Results, 0);
81
+        }
82
+        return $Results;
79
     }
83
     }
80
-    return $Results;
81
-  }
82
 
84
 
83
-  public static function get_event($ID) {
84
-    if (!empty($ID)) {
85
-      $QueryID = G::$DB->get_query_id();
86
-      G::$DB->query("
85
+    public static function get_event($ID)
86
+    {
87
+        if (!empty($ID)) {
88
+            $QueryID = G::$DB->get_query_id();
89
+            G::$DB->query("
87
           SELECT
90
           SELECT
88
             ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
91
             ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
89
           FROM site_history
92
           FROM site_history
90
           WHERE ID = '$ID'
93
           WHERE ID = '$ID'
91
           ORDER BY Date DESC");
94
           ORDER BY Date DESC");
92
-      $Event = G::$DB->next_record();
93
-      G::$DB->set_query_id($QueryID);
94
-      return $Event;
95
+            $Event = G::$DB->next_record();
96
+            G::$DB->set_query_id($QueryID);
97
+            return $Event;
98
+        }
95
     }
99
     }
96
-  }
97
 
100
 
98
-  public static function get_latest_events($Limit) {
99
-    self::get_events(null, null, null, null, null, null, $Limit);
100
-  }
101
-
102
-  public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit) {
103
-    $Month = (int)$Month;
104
-    $Year = (int)$Year;
105
-    $Title = db_string($Title);
106
-    $Category = (int)$Category;
107
-    $SubCategory = (int)$SubCategory;
108
-    $Tags = db_string($Tags);
109
-    $Limit = (int)$Limit;
110
-    $Where = [];
111
-    if (!empty($Month)) {
112
-      $Where[] = " MONTH(Date) = '$Month' ";
113
-    }
114
-    if (!empty($Year)) {
115
-      $Where[] = " YEAR(Date) = '$Year' ";
116
-    }
117
-    if (!empty($Title)) {
118
-      $Where[] = " Title LIKE '%$Title%' ";
119
-    }
120
-    if (!empty($Category)) {
121
-      $Where[] = " Category = '$Category '";
122
-    }
123
-    if (!empty($SubCategory)) {
124
-      $Where[] = " SubCategory = '$SubCategory '";
125
-    }
126
-    if (!empty($Tags)) {
127
-      $Tags = explode(',', $Tags);
128
-      $Or = '(';
129
-      foreach ($Tags as $Tag) {
130
-        $Tag = trim($Tag);
131
-        $Or .= " Tags LIKE '%$Tag%' OR ";
132
-      }
133
-      if (strlen($Or) > 1) {
134
-        $Or = rtrim($Or, 'OR ');
135
-        $Or .= ')';
136
-        $Where[] = $Or;
137
-      }
138
-    }
139
-    if (!empty($Limit)) {
140
-      $Limit = " LIMIT $Limit";
141
-    } else {
142
-      $Limit = '';
143
-    }
144
-    if (count($Where) > 0) {
145
-      $Query = ' WHERE ' . implode('AND', $Where);
146
-    } else {
147
-      $Query = '';
101
+    public static function get_latest_events($Limit)
102
+    {
103
+        self::get_events(null, null, null, null, null, null, $Limit);
148
     }
104
     }
149
 
105
 
150
-    $QueryID = G::$DB->get_query_id();
151
-    G::$DB->query("
106
+    public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit)
107
+    {
108
+        $Month = (int)$Month;
109
+        $Year = (int)$Year;
110
+        $Title = db_string($Title);
111
+        $Category = (int)$Category;
112
+        $SubCategory = (int)$SubCategory;
113
+        $Tags = db_string($Tags);
114
+        $Limit = (int)$Limit;
115
+        $Where = [];
116
+        if (!empty($Month)) {
117
+            $Where[] = " MONTH(Date) = '$Month' ";
118
+        }
119
+        if (!empty($Year)) {
120
+            $Where[] = " YEAR(Date) = '$Year' ";
121
+        }
122
+        if (!empty($Title)) {
123
+            $Where[] = " Title LIKE '%$Title%' ";
124
+        }
125
+        if (!empty($Category)) {
126
+            $Where[] = " Category = '$Category '";
127
+        }
128
+        if (!empty($SubCategory)) {
129
+            $Where[] = " SubCategory = '$SubCategory '";
130
+        }
131
+        if (!empty($Tags)) {
132
+            $Tags = explode(',', $Tags);
133
+            $Or = '(';
134
+            foreach ($Tags as $Tag) {
135
+                $Tag = trim($Tag);
136
+                $Or .= " Tags LIKE '%$Tag%' OR ";
137
+            }
138
+            if (strlen($Or) > 1) {
139
+                $Or = rtrim($Or, 'OR ');
140
+                $Or .= ')';
141
+                $Where[] = $Or;
142
+            }
143
+        }
144
+        if (!empty($Limit)) {
145
+            $Limit = " LIMIT $Limit";
146
+        } else {
147
+            $Limit = '';
148
+        }
149
+        if (count($Where) > 0) {
150
+            $Query = ' WHERE ' . implode('AND', $Where);
151
+        } else {
152
+            $Query = '';
153
+        }
154
+
155
+        $QueryID = G::$DB->get_query_id();
156
+        G::$DB->query("
152
         SELECT
157
         SELECT
153
           ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
158
           ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
154
         FROM site_history
159
         FROM site_history
155
         $Query
160
         $Query
156
         ORDER BY Date DESC
161
         ORDER BY Date DESC
157
         $Limit");
162
         $Limit");
158
-    $Events = G::$DB->to_array();
159
-    G::$DB->set_query_id($QueryID);
160
-    return $Events;
161
-  }
162
-
163
-  public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
164
-    if (empty($Date)) {
165
-      $Date = sqltime();
166
-    } else {
167
-      list($Y, $M, $D) = explode('-', $Date);
168
-      if (!checkdate($M, $D, $Y)) {
169
-        error("Error");
170
-      }
171
-    }
172
-    $Title = db_string($Title);
173
-    $Link = db_string($Link);
174
-    $Category = (int)$Category;
175
-    $SubCategory = (int)$SubCategory;
176
-    $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
177
-    $ExplodedTags = explode(',', $Tags);
178
-    foreach ($ExplodedTags as $Tag) {
179
-      if (!in_array($Tag, self::get_tags())) {
180
-        error("Invalid tag");
181
-      }
163
+        $Events = G::$DB->to_array();
164
+        G::$DB->set_query_id($QueryID);
165
+        return $Events;
182
     }
166
     }
183
-    $Body = db_string($Body);
184
-    $UserID = (int)$UserID;
185
 
167
 
186
-    if (empty($Title) || empty($Category) || empty($SubCategory)) {
187
-      error("Error");
188
-    }
168
+    public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
169
+    {
170
+        if (empty($Date)) {
171
+            $Date = sqltime();
172
+        } else {
173
+            list($Y, $M, $D) = explode('-', $Date);
174
+            if (!checkdate($M, $D, $Y)) {
175
+                error("Error");
176
+            }
177
+        }
178
+        $Title = db_string($Title);
179
+        $Link = db_string($Link);
180
+        $Category = (int)$Category;
181
+        $SubCategory = (int)$SubCategory;
182
+        $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
183
+        $ExplodedTags = explode(',', $Tags);
184
+        foreach ($ExplodedTags as $Tag) {
185
+            if (!in_array($Tag, self::get_tags())) {
186
+                error("Invalid tag");
187
+            }
188
+        }
189
+        $Body = db_string($Body);
190
+        $UserID = (int)$UserID;
189
 
191
 
190
-    $QueryID = G::$DB->get_query_id();
191
-    G::$DB->query("
192
+        if (empty($Title) || empty($Category) || empty($SubCategory)) {
193
+            error("Error");
194
+        }
195
+
196
+        $QueryID = G::$DB->get_query_id();
197
+        G::$DB->query("
192
         INSERT INTO site_history
198
         INSERT INTO site_history
193
           (Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
199
           (Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
194
         VALUES
200
         VALUES
195
           ('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
201
           ('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
196
-    G::$DB->set_query_id($QueryID);
197
-    G::$Cache->delete_value("site_history_months");
198
-  }
199
-
200
-  public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
201
-    if (empty($Date)) {
202
-      $Date = sqltime();
203
-    } else {
204
-      $Date = db_string($Date);
205
-      list($Y, $M, $D) = explode('-', $Date);
206
-      if (!checkdate($M, $D, $Y)) {
207
-        error("Error");
208
-      }
209
-    }
210
-    $ID = (int)$ID;
211
-    $Title = db_string($Title);
212
-    $Link = db_string($Link);
213
-    $Category = (int)$Category;
214
-    $SubCategory = (int)$SubCategory;
215
-    $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
216
-    $ExplodedTags = explode(",", $Tags);
217
-    foreach ($ExplodedTags as $Tag) {
218
-      if (!in_array($Tag, self::get_tags())) {
219
-        error("Invalid tag");
220
-      }
202
+        G::$DB->set_query_id($QueryID);
203
+        G::$Cache->delete_value("site_history_months");
221
     }
204
     }
222
-    $Body = db_string($Body);
223
-    $UserID = (int)$UserID;
224
 
205
 
225
-    if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
226
-      error("Error");
227
-    }
206
+    public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
207
+    {
208
+        if (empty($Date)) {
209
+            $Date = sqltime();
210
+        } else {
211
+            $Date = db_string($Date);
212
+            list($Y, $M, $D) = explode('-', $Date);
213
+            if (!checkdate($M, $D, $Y)) {
214
+                error("Error");
215
+            }
216
+        }
217
+        $ID = (int)$ID;
218
+        $Title = db_string($Title);
219
+        $Link = db_string($Link);
220
+        $Category = (int)$Category;
221
+        $SubCategory = (int)$SubCategory;
222
+        $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
223
+        $ExplodedTags = explode(",", $Tags);
224
+        foreach ($ExplodedTags as $Tag) {
225
+            if (!in_array($Tag, self::get_tags())) {
226
+                error("Invalid tag");
227
+            }
228
+        }
229
+        $Body = db_string($Body);
230
+        $UserID = (int)$UserID;
231
+
232
+        if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
233
+            error("Error");
234
+        }
228
 
235
 
229
-    $QueryID = G::$DB->get_query_id();
230
-    G::$DB->query("
236
+        $QueryID = G::$DB->get_query_id();
237
+        G::$DB->query("
231
         UPDATE site_history
238
         UPDATE site_history
232
         SET
239
         SET
233
           Title = '$Title',
240
           Title = '$Title',
239
           AddedBy = '$UserID',
246
           AddedBy = '$UserID',
240
           Date = '$Date'
247
           Date = '$Date'
241
         WHERE ID = '$ID'");
248
         WHERE ID = '$ID'");
242
-    G::$DB->set_query_id($QueryID);
243
-    G::$Cache->delete_value("site_history_months");
244
-  }
245
-
246
-  public static function delete_event($ID) {
247
-    if (!is_numeric($ID)) {
248
-      error(404);
249
+        G::$DB->set_query_id($QueryID);
250
+        G::$Cache->delete_value("site_history_months");
249
     }
251
     }
250
-    $QueryID = G::$DB->get_query_id();
251
-    G::$DB->query("
252
+
253
+    public static function delete_event($ID)
254
+    {
255
+        if (!is_numeric($ID)) {
256
+            error(404);
257
+        }
258
+        $QueryID = G::$DB->get_query_id();
259
+        G::$DB->query("
252
         DELETE FROM site_history
260
         DELETE FROM site_history
253
         WHERE ID = '$ID'");
261
         WHERE ID = '$ID'");
254
-    G::$DB->set_query_id($QueryID);
255
-    G::$Cache->delete_value("site_history_months");
256
-  }
262
+        G::$DB->set_query_id($QueryID);
263
+        G::$Cache->delete_value("site_history_months");
264
+    }
257
 
265
 
258
-  public static function get_categories() {
259
-    return self::$Categories;
260
-  }
266
+    public static function get_categories()
267
+    {
268
+        return self::$Categories;
269
+    }
261
 
270
 
262
-  public static function get_sub_categories() {
263
-    return self::$SubCategories;
264
-  }
271
+    public static function get_sub_categories()
272
+    {
273
+        return self::$SubCategories;
274
+    }
265
 
275
 
266
-  public static function get_tags() {
267
-    return self::$Tags;
268
-  }
276
+    public static function get_tags()
277
+    {
278
+        return self::$Tags;
279
+    }
269
 }
280
 }

Loading…
Cancel
Save