Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
6cd3d8c9bf
5 changed files with 954 additions and 855 deletions
  1. 59
    51
      classes/file_checker.class.php
  2. 602
    532
      classes/format.class.php
  3. 228
    213
      classes/forums.class.php
  4. 14
    12
      classes/g.class.php
  5. 51
    47
      classes/image.class.php

+ 59
- 51
classes/file_checker.class.php View File

@@ -1,78 +1,86 @@
1 1
 <?php
2 2
 $ComicsExtensions = array_fill_keys(array('cbr', 'cbz', 'gif', 'jpeg', 'jpg', 'pdf', 'png'), true);
3 3
 $MusicExtensions = array_fill_keys(
4
-  array(
4
+    array(
5 5
     'ac3', 'accurip', 'azw3', 'chm', 'cue', 'djv', 'djvu', 'doc', 'dts', 'epub', 'ffp',
6 6
     'flac', 'gif', 'htm', 'html', 'jpeg', 'jpg', 'lit', 'log', 'm3u', 'm3u8', 'm4a', 'm4b',
7 7
     'md5', 'mobi', 'mp3', 'mp4', 'nfo', 'pdf', 'pls', 'png', 'rtf', 'sfv', 'txt'),
8
-  true);
8
+    true
9
+);
9 10
 $Keywords = array(
10 11
   'ahashare.com', 'demonoid.com', 'demonoid.me', 'djtunes.com', 'h33t', 'housexclusive.net',
11 12
   'limetorrents.com', 'mixesdb.com', 'mixfiend.blogstop', 'mixtapetorrent.blogspot',
12 13
   'plixid.com', 'reggaeme.com' , 'scc.nfo', 'thepiratebay.org', 'torrentday');
13 14
 
14
-function check_file($Type, $Name) {
15
-  check_name($Name);
16
-  check_extensions($Type, $Name);
15
+function check_file($Type, $Name)
16
+{
17
+    check_name($Name);
18
+    check_extensions($Type, $Name);
17 19
 }
18 20
 
19
-function check_name($Name) {
20
-  global $Keywords;
21
-  $NameLC = strtolower($Name);
22
-  foreach ($Keywords as &$Value) {
23
-    if (strpos($NameLC, $Value) !== false) {
24
-      forbidden_error($Name);
21
+function check_name($Name)
22
+{
23
+    global $Keywords;
24
+    $NameLC = strtolower($Name);
25
+    foreach ($Keywords as &$Value) {
26
+        if (strpos($NameLC, $Value) !== false) {
27
+            forbidden_error($Name);
28
+        }
29
+    }
30
+    if (preg_match('/INCOMPLETE~\*/i', $Name)) {
31
+        forbidden_error($Name);
25 32
     }
26
-  }
27
-  if (preg_match('/INCOMPLETE~\*/i', $Name)) {
28
-    forbidden_error($Name);
29
-  }
30 33
 
31
-  /*
32
-   * These characters are invalid in NTFS on Windows systems:
33
-   *    : ? / < > \ * | "
34
-   *
35
-   * TODO: Add "/" to the blacklist. Adding "/" to the blacklist causes problems with nested dirs, apparently.
36
-   *
37
-   * Only the following characters need to be escaped (see the link below):
38
-   *    \ - ^ ]
39
-   *
40
-   * http://www.php.net/manual/en/regexp.reference.character-classes.php
41
-   */
42
-  $AllBlockedChars = ' : ? < > \ * | " ';
43
-  if (preg_match('/[\\:?<>*|"]/', $Name, $Matches)) {
44
-    character_error($Matches[0], $AllBlockedChars);
45
-  }
34
+    /*
35
+     * These characters are invalid in NTFS on Windows systems:
36
+     *    : ? / < > \ * | "
37
+     *
38
+     * TODO: Add "/" to the blacklist. Adding "/" to the blacklist causes problems with nested dirs, apparently.
39
+     *
40
+     * Only the following characters need to be escaped (see the link below):
41
+     *    \ - ^ ]
42
+     *
43
+     * http://www.php.net/manual/en/regexp.reference.character-classes.php
44
+     */
45
+    $AllBlockedChars = ' : ? < > \ * | " ';
46
+    if (preg_match('/[\\:?<>*|"]/', $Name, $Matches)) {
47
+        character_error($Matches[0], $AllBlockedChars);
48
+    }
46 49
 }
47 50
 
48
-function check_extensions($Type, $Name) {
49
-  global $MusicExtensions, $ComicsExtensions;
50
-  if ($Type == 'Music' || $Type == 'Audiobooks' || $Type == 'Comedy' || $Type == 'E-Books') {
51
-    if (!isset($MusicExtensions[get_file_extension($Name)])) {
52
-      invalid_error($Name);
53
-    }
54
-  } elseif ($Type == 'Comics') {
55
-    if (!isset($ComicsExtensions[get_file_extension($Name)])) {
56
-      invalid_error($Name);
51
+function check_extensions($Type, $Name)
52
+{
53
+    global $MusicExtensions, $ComicsExtensions;
54
+    if ($Type == 'Music' || $Type == 'Audiobooks' || $Type == 'Comedy' || $Type == 'E-Books') {
55
+        if (!isset($MusicExtensions[get_file_extension($Name)])) {
56
+            invalid_error($Name);
57
+        }
58
+    } elseif ($Type == 'Comics') {
59
+        if (!isset($ComicsExtensions[get_file_extension($Name)])) {
60
+            invalid_error($Name);
61
+        }
57 62
     }
58
-  }
59 63
 }
60 64
 
61
-function get_file_extension($FileName) {
62
-  return strtolower(substr(strrchr($FileName, '.'), 1));
65
+function get_file_extension($FileName)
66
+{
67
+    return strtolower(substr(strrchr($FileName, '.'), 1));
63 68
 }
64 69
 
65
-function invalid_error($Name) {
66
-  global $Err;
67
-  $Err = 'The torrent contained one or more invalid files (' . display_str($Name) . ')';
70
+function invalid_error($Name)
71
+{
72
+    global $Err;
73
+    $Err = 'The torrent contained one or more invalid files (' . display_str($Name) . ')';
68 74
 }
69 75
 
70
-function forbidden_error($Name) {
71
-  global $Err;
72
-  $Err = 'The torrent contained one or more forbidden files (' . display_str($Name) . ')';
76
+function forbidden_error($Name)
77
+{
78
+    global $Err;
79
+    $Err = 'The torrent contained one or more forbidden files (' . display_str($Name) . ')';
73 80
 }
74 81
 
75
-function character_error($Character, $AllBlockedChars) {
76
-  global $Err;
77
-  $Err = "One or more of the files or folders in the torrent has a name that contains the forbidden character '$Character'. Please rename the files as necessary and recreate the torrent.<br /><br />\nNote: The complete list of characters that are disallowed are shown below:<br />\n\t\t$AllBlockedChars";
82
+function character_error($Character, $AllBlockedChars)
83
+{
84
+    global $Err;
85
+    $Err = "One or more of the files or folders in the torrent has a name that contains the forbidden character '$Character'. Please rename the files as necessary and recreate the torrent.<br /><br />\nNote: The complete list of characters that are disallowed are shown below:<br />\n\t\t$AllBlockedChars";
78 86
 }

+ 602
- 532
classes/format.class.php
File diff suppressed because it is too large
View File


+ 228
- 213
classes/forums.class.php View File

@@ -1,17 +1,19 @@
1
-<?
2
-class Forums {
3
-  /**
4
-   * Get information on a thread.
5
-   *
6
-   * @param int $ThreadID the thread ID.
7
-   * @param boolean $Return indicates whether thread info should be returned.
8
-   * @param Boolean $SelectiveCache cache thread info.
9
-   * @return array holding thread information.
10
-   */
11
-  public static function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false) {
12
-    if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
13
-      $QueryID = G::$DB->get_query_id();
14
-      G::$DB->query("
1
+<?php
2
+class Forums
3
+{
4
+    /**
5
+     * Get information on a thread.
6
+     *
7
+     * @param int $ThreadID the thread ID.
8
+     * @param boolean $Return indicates whether thread info should be returned.
9
+     * @param Boolean $SelectiveCache cache thread info.
10
+     * @return array holding thread information.
11
+     */
12
+    public static function get_thread_info($ThreadID, $Return = true, $SelectiveCache = false)
13
+    {
14
+        if ((!$ThreadInfo = G::$Cache->get_value('thread_' . $ThreadID . '_info')) || !isset($ThreadInfo['Ranking'])) {
15
+            $QueryID = G::$DB->get_query_id();
16
+            G::$DB->query("
15 17
         SELECT
16 18
           t.Title,
17 19
           t.ForumID,
@@ -28,15 +30,15 @@ class Forums {
28 30
           LEFT JOIN forums_polls AS p ON p.TopicID = t.ID
29 31
         WHERE t.ID = ?
30 32
         GROUP BY fp.TopicID", $ThreadID);
31
-      if (!G::$DB->has_results()) {
32
-        G::$DB->set_query_id($QueryID);
33
-        return null;
34
-      }
35
-      $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
36
-      if ($ThreadInfo['StickyPostID']) {
37
-        $ThreadInfo['Posts']--;
38
-        G::$DB->query(
39
-          "SELECT
33
+            if (!G::$DB->has_results()) {
34
+                G::$DB->set_query_id($QueryID);
35
+                return null;
36
+            }
37
+            $ThreadInfo = G::$DB->next_record(MYSQLI_ASSOC, false);
38
+            if ($ThreadInfo['StickyPostID']) {
39
+                $ThreadInfo['Posts']--;
40
+                G::$DB->query(
41
+                    "SELECT
40 42
             p.ID,
41 43
             p.AuthorID,
42 44
             p.AddedTime,
@@ -47,53 +49,58 @@ class Forums {
47 49
             FROM forums_posts AS p
48 50
               LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
49 51
             WHERE p.TopicID = ?
50
-              AND p.ID = ?", $ThreadID, $ThreadInfo['StickyPostID']);
51
-        list ($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
52
-      }
53
-      G::$DB->set_query_id($QueryID);
54
-      if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
55
-        G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
56
-      }
57
-    }
58
-    if ($Return) {
59
-      return $ThreadInfo;
52
+              AND p.ID = ?",
53
+                    $ThreadID,
54
+                    $ThreadInfo['StickyPostID']
55
+                );
56
+                list($ThreadInfo['StickyPost']) = G::$DB->to_array(false, MYSQLI_ASSOC);
57
+            }
58
+            G::$DB->set_query_id($QueryID);
59
+            if (!$SelectiveCache || !$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
60
+                G::$Cache->cache_value('thread_' . $ThreadID . '_info', $ThreadInfo, 0);
61
+            }
62
+        }
63
+        if ($Return) {
64
+            return $ThreadInfo;
65
+        }
60 66
     }
61
-  }
62 67
 
63
-  /**
64
-   * Checks whether user has permissions on a forum.
65
-   *
66
-   * @param int $ForumID the forum ID.
67
-   * @param string $Perm the permissision to check, defaults to 'Read'
68
-   * @return boolean true if user has permission
69
-   */
70
-  public static function check_forumperm($ForumID, $Perm = 'Read') {
71
-    $Forums = self::get_forums();
72
-    if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
73
-      return true;
74
-    }
75
-    if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
76
-      return true;
77
-    }
78
-    if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
79
-      return false;
80
-    }
81
-    if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
82
-      return false;
68
+    /**
69
+     * Checks whether user has permissions on a forum.
70
+     *
71
+     * @param int $ForumID the forum ID.
72
+     * @param string $Perm the permissision to check, defaults to 'Read'
73
+     * @return boolean true if user has permission
74
+     */
75
+    public static function check_forumperm($ForumID, $Perm = 'Read')
76
+    {
77
+        $Forums = self::get_forums();
78
+        if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 1) {
79
+            return true;
80
+        }
81
+        if ($ForumID == DONOR_FORUM && Donations::has_donor_forum(G::$LoggedUser['ID'])) {
82
+            return true;
83
+        }
84
+        if ($Forums[$ForumID]['MinClass' . $Perm] > G::$LoggedUser['Class'] && (!isset(G::$LoggedUser['CustomForums'][$ForumID]) || G::$LoggedUser['CustomForums'][$ForumID] == 0)) {
85
+            return false;
86
+        }
87
+        if (isset(G::$LoggedUser['CustomForums'][$ForumID]) && G::$LoggedUser['CustomForums'][$ForumID] == 0) {
88
+            return false;
89
+        }
90
+        return true;
83 91
     }
84
-    return true;
85
-  }
86 92
 
87
-  /**
88
-   * Gets basic info on a forum.
89
-   *
90
-   * @param int $ForumID the forum ID.
91
-   */
92
-  public static function get_forum_info($ForumID) {
93
-    $Forum = G::$Cache->get_value("ForumInfo_$ForumID");
94
-    if (!$Forum) {
95
-      $QueryID = G::$DB->get_query_id();
96
-      G::$DB->query("
93
+    /**
94
+     * Gets basic info on a forum.
95
+     *
96
+     * @param int $ForumID the forum ID.
97
+     */
98
+    public static function get_forum_info($ForumID)
99
+    {
100
+        $Forum = G::$Cache->get_value("ForumInfo_$ForumID");
101
+        if (!$Forum) {
102
+            $QueryID = G::$DB->get_query_id();
103
+            G::$DB->query("
97 104
         SELECT
98 105
           Name,
99 106
           MinClassRead,
@@ -104,48 +111,50 @@ class Forums {
104 111
           LEFT JOIN forums_topics ON forums_topics.ForumID = forums.ID
105 112
         WHERE forums.ID = ?
106 113
         GROUP BY ForumID", $ForumID);
107
-      if (!G::$DB->has_results()) {
108
-        return false;
109
-      }
110
-      // Makes an array, with $Forum['Name'], etc.
111
-      $Forum = G::$DB->next_record(MYSQLI_ASSOC);
114
+            if (!G::$DB->has_results()) {
115
+                return false;
116
+            }
117
+            // Makes an array, with $Forum['Name'], etc.
118
+            $Forum = G::$DB->next_record(MYSQLI_ASSOC);
112 119
 
113
-      G::$DB->set_query_id($QueryID);
120
+            G::$DB->set_query_id($QueryID);
114 121
 
115
-      G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
122
+            G::$Cache->cache_value("ForumInfo_$ForumID", $Forum, 86400);
123
+        }
124
+        return $Forum;
116 125
     }
117
-    return $Forum;
118
-  }
119 126
 
120
-  /**
121
-   * Get the forum categories
122
-   * @return array ForumCategoryID => Name
123
-   */
124
-  public static function get_forum_categories() {
125
-    $ForumCats = G::$Cache->get_value('forums_categories');
126
-    if ($ForumCats === false) {
127
-      $QueryID = G::$DB->get_query_id();
128
-      G::$DB->query("
127
+    /**
128
+     * Get the forum categories
129
+     * @return array ForumCategoryID => Name
130
+     */
131
+    public static function get_forum_categories()
132
+    {
133
+        $ForumCats = G::$Cache->get_value('forums_categories');
134
+        if ($ForumCats === false) {
135
+            $QueryID = G::$DB->get_query_id();
136
+            G::$DB->query("
129 137
         SELECT ID, Name
130 138
         FROM forums_categories");
131
-      $ForumCats = [];
132
-      while (list ($ID, $Name) = G::$DB->next_record()) {
133
-        $ForumCats[$ID] = $Name;
134
-      }
135
-      G::$DB->set_query_id($QueryID);
136
-      G::$Cache->cache_value('forums_categories', $ForumCats, 0);
139
+            $ForumCats = [];
140
+            while (list($ID, $Name) = G::$DB->next_record()) {
141
+                $ForumCats[$ID] = $Name;
142
+            }
143
+            G::$DB->set_query_id($QueryID);
144
+            G::$Cache->cache_value('forums_categories', $ForumCats, 0);
145
+        }
146
+        return $ForumCats;
137 147
     }
138
-    return $ForumCats;
139
-  }
140 148
 
141
-  /**
142
-   * Get the forums
143
-   * @return array ForumID => (various information about the forum)
144
-   */
145
-  public static function get_forums() {
146
-    if (!$Forums = G::$Cache->get_value('forums_list')) {
147
-      $QueryID = G::$DB->get_query_id();
148
-      G::$DB->query("
149
+    /**
150
+     * Get the forums
151
+     * @return array ForumID => (various information about the forum)
152
+     */
153
+    public static function get_forums()
154
+    {
155
+        if (!$Forums = G::$Cache->get_value('forums_list')) {
156
+            $QueryID = G::$DB->get_query_id();
157
+            G::$DB->query("
149 158
         SELECT
150 159
           f.ID,
151 160
           f.CategoryID,
@@ -169,72 +178,75 @@ class Forums {
169 178
           LEFT JOIN forums_topics AS t ON t.ID = f.LastPostTopicID
170 179
         GROUP BY f.ID
171 180
         ORDER BY fc.Sort, fc.Name, f.CategoryID, f.Sort");
172
-      $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
181
+            $Forums = G::$DB->to_array('ID', MYSQLI_ASSOC, false);
173 182
 
174
-      G::$DB->query("
183
+            G::$DB->query("
175 184
         SELECT ForumID, ThreadID
176 185
         FROM forums_specific_rules");
177
-      $SpecificRules = [];
178
-      while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
179
-        $SpecificRules[$ForumID][] = $ThreadID;
180
-      }
181
-      G::$DB->set_query_id($QueryID);
182
-      foreach ($Forums as $ForumID => &$Forum) {
183
-        if (isset($SpecificRules[$ForumID])) {
184
-          $Forum['SpecificRules'] = $SpecificRules[$ForumID];
185
-        } else {
186
-          $Forum['SpecificRules'] = [];
186
+            $SpecificRules = [];
187
+            while (list($ForumID, $ThreadID) = G::$DB->next_record(MYSQLI_NUM, false)) {
188
+                $SpecificRules[$ForumID][] = $ThreadID;
189
+            }
190
+            G::$DB->set_query_id($QueryID);
191
+            foreach ($Forums as $ForumID => &$Forum) {
192
+                if (isset($SpecificRules[$ForumID])) {
193
+                    $Forum['SpecificRules'] = $SpecificRules[$ForumID];
194
+                } else {
195
+                    $Forum['SpecificRules'] = [];
196
+                }
197
+            }
198
+            G::$Cache->cache_value('forums_list', $Forums, 0);
187 199
         }
188
-      }
189
-      G::$Cache->cache_value('forums_list', $Forums, 0);
200
+        return $Forums;
190 201
     }
191
-    return $Forums;
192
-  }
193 202
 
194
-  /**
195
-   * Get all forums that the current user has special access to ("Extra forums" in the profile)
196
-   * @return array Array of ForumIDs
197
-   */
198
-  public static function get_permitted_forums() {
199
-    if (isset(G::$LoggedUser['CustomForums'])) {
200
-      return (array)array_keys(G::$LoggedUser['CustomForums'], 1);
201
-    } else {
202
-      return [];
203
+    /**
204
+     * Get all forums that the current user has special access to ("Extra forums" in the profile)
205
+     * @return array Array of ForumIDs
206
+     */
207
+    public static function get_permitted_forums()
208
+    {
209
+        if (isset(G::$LoggedUser['CustomForums'])) {
210
+            return (array)array_keys(G::$LoggedUser['CustomForums'], 1);
211
+        } else {
212
+            return [];
213
+        }
203 214
     }
204
-  }
205 215
 
206
-  /**
207
-   * Get all forums that the current user does not have access to ("Restricted forums" in the profile)
208
-   * @return array Array of ForumIDs
209
-   */
210
-  public static function get_restricted_forums() {
211
-    if (isset(G::$LoggedUser['CustomForums'])) {
212
-      return (array)array_keys(G::$LoggedUser['CustomForums'], 0);
213
-    } else {
214
-      return [];
216
+    /**
217
+     * Get all forums that the current user does not have access to ("Restricted forums" in the profile)
218
+     * @return array Array of ForumIDs
219
+     */
220
+    public static function get_restricted_forums()
221
+    {
222
+        if (isset(G::$LoggedUser['CustomForums'])) {
223
+            return (array)array_keys(G::$LoggedUser['CustomForums'], 0);
224
+        } else {
225
+            return [];
226
+        }
215 227
     }
216
-  }
217 228
 
218
-  /**
219
-   * Get the last read posts for the current user
220
-   * @param array $Forums Array of forums as returned by self::get_forums()
221
-   * @return array TopicID => array(TopicID, PostID, Page) where PostID is the ID of the last read post and Page is the page on which that post is
222
-   */
223
-  public static function get_last_read($Forums) {
224
-    if (isset(G::$LoggedUser['PostsPerPage'])) {
225
-      $PerPage = G::$LoggedUser['PostsPerPage'];
226
-    } else {
227
-      $PerPage = POSTS_PER_PAGE;
228
-    }
229
-    $TopicIDs = [];
230
-    foreach ($Forums as $Forum) {
231
-      if (!empty($Forum['LastPostTopicID'])) {
232
-        $TopicIDs[] = $Forum['LastPostTopicID'];
233
-      }
234
-    }
235
-    if (!empty($TopicIDs)) {
236
-      $QueryID = G::$DB->get_query_id();
237
-      G::$DB->query("
229
+    /**
230
+     * Get the last read posts for the current user
231
+     * @param array $Forums Array of forums as returned by self::get_forums()
232
+     * @return array TopicID => array(TopicID, PostID, Page) where PostID is the ID of the last read post and Page is the page on which that post is
233
+     */
234
+    public static function get_last_read($Forums)
235
+    {
236
+        if (isset(G::$LoggedUser['PostsPerPage'])) {
237
+            $PerPage = G::$LoggedUser['PostsPerPage'];
238
+        } else {
239
+            $PerPage = POSTS_PER_PAGE;
240
+        }
241
+        $TopicIDs = [];
242
+        foreach ($Forums as $Forum) {
243
+            if (!empty($Forum['LastPostTopicID'])) {
244
+                $TopicIDs[] = $Forum['LastPostTopicID'];
245
+            }
246
+        }
247
+        if (!empty($TopicIDs)) {
248
+            $QueryID = G::$DB->get_query_id();
249
+            G::$DB->query("
238 250
         SELECT
239 251
           l.TopicID,
240 252
           l.PostID,
@@ -250,70 +262,73 @@ class Forums {
250 262
         FROM forums_last_read_topics AS l
251 263
         WHERE l.TopicID IN(" . implode(',', $TopicIDs) . ") AND
252 264
           l.UserID = ?", $PerPage, G::$LoggedUser['ID']);
253
-      $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
254
-      G::$DB->set_query_id($QueryID);
255
-    } else {
256
-      $LastRead = [];
265
+            $LastRead = G::$DB->to_array('TopicID', MYSQLI_ASSOC);
266
+            G::$DB->set_query_id($QueryID);
267
+        } else {
268
+            $LastRead = [];
269
+        }
270
+        return $LastRead;
257 271
     }
258
-    return $LastRead;
259
-  }
260 272
 
261
-  /**
262
-   * Add a note to a topic.
263
-   * @param int $TopicID
264
-   * @param string $Note
265
-   * @param int|null $UserID
266
-   * @return boolean
267
-   */
268
-  public static function add_topic_note($TopicID, $Note, $UserID = null) {
269
-    if ($UserID === null) {
270
-      $UserID = G::$LoggedUser['ID'];
271
-    }
272
-    $QueryID = G::$DB->get_query_id();
273
-    G::$DB->query("
273
+    /**
274
+     * Add a note to a topic.
275
+     * @param int $TopicID
276
+     * @param string $Note
277
+     * @param int|null $UserID
278
+     * @return boolean
279
+     */
280
+    public static function add_topic_note($TopicID, $Note, $UserID = null)
281
+    {
282
+        if ($UserID === null) {
283
+            $UserID = G::$LoggedUser['ID'];
284
+        }
285
+        $QueryID = G::$DB->get_query_id();
286
+        G::$DB->query("
274 287
       INSERT INTO forums_topic_notes
275 288
         (TopicID, AuthorID, AddedTime, Body)
276 289
       VALUES
277 290
         (?, ?, NOW(), ?)", $TopicID, $UserID, $Note);
278
-    G::$DB->set_query_id($QueryID);
279
-    return (bool)G::$DB->affected_rows();
280
-  }
281
-
282
-  /**
283
-   * Determine if a thread is unread
284
-   * @param bool $Locked
285
-   * @param bool $Sticky
286
-   * @param int $LastPostID
287
-   * @param array $LastRead An array as returned by self::get_last_read
288
-   * @param int $LastTopicID TopicID of the thread where the most recent post was made
289
-   * @param string $LastTime Datetime of the last post
290
-   * @return bool
291
-   */
292
-  public static function is_unread($Locked, $Sticky, $LastPostID, $LastRead, $LastTopicID, $LastTime) {
293
-    return (!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime) > G::$LoggedUser['CatchupTime']);
294
-  }
295
-
296
-  /**
297
-   * Create the part of WHERE in the sql queries used to filter forums for a
298
-   * specific user (MinClassRead, restricted and permitted forums).
299
-   * @return string
300
-   */
301
-  public static function user_forums_sql() {
302
-    // I couldn't come up with a good name, please rename this if you can. -- Y
303
-    $RestrictedForums = self::get_restricted_forums();
304
-    $PermittedForums = self::get_permitted_forums();
305
-    if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
306
-      $PermittedForums[] = DONOR_FORUM;
291
+        G::$DB->set_query_id($QueryID);
292
+        return (bool)G::$DB->affected_rows();
307 293
     }
308
-    $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
309
-    if (count($RestrictedForums)) {
310
-      $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
294
+
295
+    /**
296
+     * Determine if a thread is unread
297
+     * @param bool $Locked
298
+     * @param bool $Sticky
299
+     * @param int $LastPostID
300
+     * @param array $LastRead An array as returned by self::get_last_read
301
+     * @param int $LastTopicID TopicID of the thread where the most recent post was made
302
+     * @param string $LastTime Datetime of the last post
303
+     * @return bool
304
+     */
305
+    public static function is_unread($Locked, $Sticky, $LastPostID, $LastRead, $LastTopicID, $LastTime)
306
+    {
307
+        return (!$Locked || $Sticky) && $LastPostID != 0 && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID) && strtotime($LastTime) > G::$LoggedUser['CatchupTime']);
311 308
     }
312
-    $SQL .= ')';
313
-    if (count($PermittedForums)) {
314
-      $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
309
+
310
+    /**
311
+     * Create the part of WHERE in the sql queries used to filter forums for a
312
+     * specific user (MinClassRead, restricted and permitted forums).
313
+     * @return string
314
+     */
315
+    public static function user_forums_sql()
316
+    {
317
+        // I couldn't come up with a good name, please rename this if you can. -- Y
318
+        $RestrictedForums = self::get_restricted_forums();
319
+        $PermittedForums = self::get_permitted_forums();
320
+        if (Donations::has_donor_forum(G::$LoggedUser['ID']) && !in_array(DONOR_FORUM, $PermittedForums)) {
321
+            $PermittedForums[] = DONOR_FORUM;
322
+        }
323
+        $SQL = "((f.MinClassRead <= '" . G::$LoggedUser['Class'] . "'";
324
+        if (count($RestrictedForums)) {
325
+            $SQL .= " AND f.ID NOT IN ('" . implode("', '", $RestrictedForums) . "')";
326
+        }
327
+        $SQL .= ')';
328
+        if (count($PermittedForums)) {
329
+            $SQL .= " OR f.ID IN ('" . implode("', '", $PermittedForums) . "')";
330
+        }
331
+        $SQL .= ')';
332
+        return $SQL;
315 333
     }
316
-    $SQL .= ')';
317
-    return $SQL;
318
-  }
319 334
 }

+ 14
- 12
classes/g.class.php View File

@@ -1,13 +1,15 @@
1
-<?
2
-class G {
3
-  public static $DB;
4
-  public static $Cache;
5
-  public static $LoggedUser;
1
+<?php
2
+class G
3
+{
4
+    public static $DB;
5
+    public static $Cache;
6
+    public static $LoggedUser;
6 7
 
7
-  public static function initialize() {
8
-    global $DB, $Cache, $LoggedUser;
9
-    self::$DB = $DB;
10
-    self::$Cache = $Cache;
11
-    self::$LoggedUser =& $LoggedUser;
12
-  }
13
-}
8
+    public static function initialize()
9
+    {
10
+        global $DB, $Cache, $LoggedUser;
11
+        self::$DB = $DB;
12
+        self::$Cache = $Cache;
13
+        self::$LoggedUser =& $LoggedUser;
14
+    }
15
+}

+ 51
- 47
classes/image.class.php View File

@@ -1,58 +1,62 @@
1
-<?
1
+<?php
2 2
 if (!extension_loaded('gd')) {
3
-  error('GD Extension not loaded.');
3
+    error('GD Extension not loaded.');
4 4
 }
5 5
 
6
-class IMAGE {
7
-  var $Image = false;
8
-  var $FontSize = 10;
9
-  var $Font = '';
10
-  var $TextAngle = 0;
11
-
12
-  function create($Width, $Height) {
13
-    $this->Image = imagecreate($Width, $Height);
14
-    $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
15
-    if (function_exists('imageantialias')) {
16
-      imageantialias($this->Image, true);
6
+class IMAGE
7
+{
8
+    public $Image = false;
9
+    public $FontSize = 10;
10
+    public $Font = '';
11
+    public $TextAngle = 0;
12
+
13
+    public function create($Width, $Height)
14
+    {
15
+        $this->Image = imagecreate($Width, $Height);
16
+        $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
17
+        if (function_exists('imageantialias')) {
18
+            imageantialias($this->Image, true);
19
+        }
17 20
     }
18
-  }
19
-
20
-  function color($Red, $Green, $Blue, $Alpha = 0) {
21
-    return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha);
22
-  }
23 21
 
24
-  function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1) {
25
-    if ($Thickness == 1) {
26
-      return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
22
+    public function color($Red, $Green, $Blue, $Alpha = 0)
23
+    {
24
+        return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha);
27 25
     }
28
-    $t = $Thickness / 2 - 0.5;
29
-    if ($x1 == $x2 || $y1 == $y2) {
30
-      return imagefilledrectangle($this->Image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
31
-    }
32
-    $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
33
-    $a = $t / sqrt(1 + pow($k, 2));
34
-    $Points = array(
35
-      round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
36
-      round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
37
-      round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
38
-      round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
39
-    );
40
-    imagefilledpolygon($this->Image, $Points, 4, $Color);
41
-    return imagepolygon($this->Image, $Points, 4, $Color);
42
-  }
43
-
44
-  function ellipse($x, $y, $Width, $Height, $Color) {
45
-    return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color);
46
-  }
47 26
 
48
-  function text($x, $y, $Color, $Text) {
49
-    return imagettftext ($this->Image, $this->FontSize, $this->TextAngle, $x, $y, $Color, $this->Font, $Text);
50
-  }
27
+    public function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1)
28
+    {
29
+        if ($Thickness == 1) {
30
+            return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
31
+        }
32
+        $t = $Thickness / 2 - 0.5;
33
+        if ($x1 == $x2 || $y1 == $y2) {
34
+            return imagefilledrectangle($this->Image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
35
+        }
36
+        $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
37
+        $a = $t / sqrt(1 + pow($k, 2));
38
+        $Points = array(
39
+        round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
40
+        round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
41
+        round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
42
+        round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
43
+        );
44
+        imagefilledpolygon($this->Image, $Points, 4, $Color);
45
+        return imagepolygon($this->Image, $Points, 4, $Color);
46
+    }
51 47
 
52
-  function make_png($FileName = null) {
53
-    return imagepng($this->Image, $FileName);
54
-  }
48
+    public function ellipse($x, $y, $Width, $Height, $Color)
49
+    {
50
+        return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color);
51
+    }
55 52
 
53
+    public function text($x, $y, $Color, $Text)
54
+    {
55
+        return imagettftext($this->Image, $this->FontSize, $this->TextAngle, $x, $y, $Color, $this->Font, $Text);
56
+    }
56 57
 
58
+    public function make_png($FileName = null)
59
+    {
60
+        return imagepng($this->Image, $FileName);
61
+    }
57 62
 }
58
-?>

Loading…
Cancel
Save