pjc 5 years ago
parent
commit
b9f44e087b

+ 3
- 1
classes/bencodetorrent.class.php View File

@@ -1,5 +1,7 @@
1 1
 <?php
2 2
 
3
+# todo: Replace this with https://github.com/OPSnet/bencode-torrent
4
+
3 5
 /**
4 6
  * Torrent class that contains some convenient functions related to torrent meta data
5 7
  */
@@ -34,7 +36,7 @@ class BencodeTorrent extends BencodeDecode
34 36
             if (isset($InfoDict['path.utf-8']['files'][0])) {
35 37
                 $this->PathKey = 'path.utf-8';
36 38
             }
37
-            
39
+
38 40
             foreach ($InfoDict['files'] as $File) {
39 41
                 $TmpPath = [];
40 42
                 foreach ($File[$this->PathKey] as $SubPath) {

+ 111
- 91
classes/commentsview.class.php View File

@@ -1,96 +1,116 @@
1
-<?
2
-class CommentsView {
3
-  /**
4
-   * Render a thread of comments
5
-   * @param array $Thread An array as returned by Comments::load
6
-   * @param int $LastRead PostID of the last read post
7
-   * @param string $Baselink Link to the site these comments are on
8
-   */
9
-  public static function render_comments($Thread, $LastRead, $Baselink) {
10
-    foreach ($Thread as $Post) {
11
-      list($PostID, $AuthorID, $AddedTime, $CommentBody, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
12
-      self::render_comment($AuthorID, $PostID, $CommentBody, $AddedTime, $EditedUserID, $EditedTime, $Baselink . "&amp;postid=$PostID#post$PostID", ($PostID > $LastRead));
1
+<?php
2
+
3
+class CommentsView
4
+{
5
+    /**
6
+     * Render a thread of comments
7
+     * @param array $Thread An array as returned by Comments::load
8
+     * @param int $LastRead PostID of the last read post
9
+     * @param string $Baselink Link to the site these comments are on
10
+     */
11
+    public static function render_comments($Thread, $LastRead, $Baselink)
12
+    {
13
+        foreach ($Thread as $Post) {
14
+            list($PostID, $AuthorID, $AddedTime, $CommentBody, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
15
+            self::render_comment($AuthorID, $PostID, $CommentBody, $AddedTime, $EditedUserID, $EditedTime, $Baselink . "&amp;postid=$PostID#post$PostID", ($PostID > $LastRead));
16
+        }
13 17
     }
14
-  }
15 18
 
16
-  /**
17
-   * Render one comment
18
-   * @param int $AuthorID
19
-   * @param int $PostID
20
-   * @param string $Body
21
-   * @param string $AddedTime
22
-   * @param int $EditedUserID
23
-   * @param string $EditedTime
24
-   * @param string $Link The link to the post elsewhere on the site
25
-   * @param string $Header The header used in the post
26
-   * @param bool $Tools Whether or not to show [Edit], [Report] etc.
27
-   * 
28
-   * todo: Find a better way to pass the page (artist, collages, requests, torrents) to this function than extracting it from $Link
29
-   */
30
-  static function render_comment($AuthorID, $PostID, $Body, $AddedTime, $EditedUserID, $EditedTime, $Link, $Unread = false, $Header = '', $Tools = true) {
31
-    $UserInfo = Users::user_info($AuthorID);
32
-    $Header = Users::format_username($AuthorID, true, true, true, true, true) . time_diff($AddedTime) . $Header;
33
-?>
34
-    <table class="forum_post box vertical_margin<?=(!Users::has_avatars_enabled() ? ' noavatar' : '') . ($Unread ? ' forum_unread' : '')?>" id="post<?=$PostID?>">
35
-      <colgroup>
36
-<?    if (Users::has_avatars_enabled()) { ?>
37
-        <col class="col_avatar" />
38
-<?    } ?>
39
-        <col class="col_post_body" />
40
-      </colgroup>
41
-      <tr class="colhead_dark">
42
-        <td colspan="<?=(Users::has_avatars_enabled() ? 2 : 1)?>">
43
-          <div class="float_left"><a class="post_id" href="<?=$Link?>">#<?=$PostID?></a>
44
-            <?=$Header?>
45
-<?    if ($Tools) { ?>
46
-            - <a href="#quickpost" onclick="Quote('<?=$PostID?>','<?=$UserInfo['Username']?>', true);" class="brackets">Quote</a>
47
-<?      if ($AuthorID == G::$LoggedUser['ID'] || check_perms('site_moderate_forums')) { ?>
48
-            - <a href="#post<?=$PostID?>" onclick="Edit_Form('<?=$PostID?>','');" class="brackets">Edit</a>
49
-<?      }
19
+    /**
20
+     * Render one comment
21
+     * @param int $AuthorID
22
+     * @param int $PostID
23
+     * @param string $Body
24
+     * @param string $AddedTime
25
+     * @param int $EditedUserID
26
+     * @param string $EditedTime
27
+     * @param string $Link The link to the post elsewhere on the site
28
+     * @param string $Header The header used in the post
29
+     * @param bool $Tools Whether or not to show [Edit], [Report] etc.
30
+     *
31
+     * todo: Find a better way to pass the page (artist, collages, requests, torrents) to this function than extracting it from $Link
32
+     */
33
+    public static function render_comment($AuthorID, $PostID, $Body, $AddedTime, $EditedUserID, $EditedTime, $Link, $Unread = false, $Header = '', $Tools = true)
34
+    {
35
+        $UserInfo = Users::user_info($AuthorID);
36
+        $Header = Users::format_username($AuthorID, true, true, true, true, true) . time_diff($AddedTime) . $Header; ?>
37
+<table
38
+  class="forum_post box vertical_margin<?=(!Users::has_avatars_enabled() ? ' noavatar' : '') . ($Unread ? ' forum_unread' : '')?>"
39
+  id="post<?=$PostID?>">
40
+  <colgroup>
41
+    <?php if (Users::has_avatars_enabled()) { ?>
42
+    <col class="col_avatar" />
43
+    <?php } ?>
44
+    <col class="col_post_body" />
45
+  </colgroup>
46
+  <tr class="colhead_dark">
47
+    <td colspan="<?=(Users::has_avatars_enabled() ? 2 : 1)?>">
48
+      <div class="float_left"><a class="post_id"
49
+          href="<?=$Link?>">#<?=$PostID?></a>
50
+        <?=$Header?>
51
+        <?php if ($Tools) { ?>
52
+        - <a href="#quickpost"
53
+          onclick="Quote('<?=$PostID?>','<?=$UserInfo['Username']?>', true);"
54
+          class="brackets">Quote</a>
55
+        <?php if ($AuthorID == G::$LoggedUser['ID'] || check_perms('site_moderate_forums')) { ?>
56
+        - <a href="#post<?=$PostID?>"
57
+          onclick="Edit_Form('<?=$PostID?>','');"
58
+          class="brackets">Edit</a>
59
+        <?php }
50 60
       if (check_perms('site_moderate_forums')) { ?>
51
-            - <a href="#post<?=$PostID?>" onclick="Delete('<?=$PostID?>');" class="brackets">Delete</a>
52
-<?      } ?>
53
-          </div>
54
-          <div id="bar<?=$PostID?>" class="float_right">
55
-            <a href="reports.php?action=report&amp;type=comment&amp;id=<?=$PostID?>" class="brackets">Report</a>
56
-<?
61
+        - <a href="#post<?=$PostID?>"
62
+          onclick="Delete('<?=$PostID?>');"
63
+          class="brackets">Delete</a>
64
+        <?php } ?>
65
+      </div>
66
+      <div id="bar<?=$PostID?>" class="float_right">
67
+        <a href="reports.php?action=report&amp;type=comment&amp;id=<?=$PostID?>"
68
+          class="brackets">Report</a>
69
+        <?php
57 70
       if (check_perms('users_warn') && $AuthorID != G::$LoggedUser['ID'] && G::$LoggedUser['Class'] >= $UserInfo['Class']) {
58
-?>
59
-            <form class="manage_form hidden" name="user" id="warn<?=$PostID?>" action="comments.php" method="post">
60
-              <input type="hidden" name="action" value="warn" />
61
-              <input type="hidden" name="postid" value="<?=$PostID?>" />
62
-            </form>
63
-            - <a href="#" onclick="$('#warn<?=$PostID?>').raw().submit(); return false;" class="brackets">Warn</a>
64
-<?      } ?>
65
-            &nbsp;
66
-            <a href="#">&uarr;</a>
67
-<?    } ?>
68
-          </div>
69
-        </td>
70
-      </tr>
71
-      <tr>
72
-<?    if (Users::has_avatars_enabled()) { ?>
73
-        <td class="avatar" valign="top">
74
-        <?=Users::show_avatar($UserInfo['Avatar'], $AuthorID, $UserInfo['Username'], G::$LoggedUser['DisableAvatars'])?>
75
-        </td>
76
-<?    } ?>
77
-        <td class="body" valign="top">
78
-          <div id="content<?=$PostID?>">
79
-            <?=Text::full_format($Body)?>
80
-<?    if ($EditedUserID) { ?>
81
-            <br />
82
-            <br />
83
-            <div class="last_edited">
84
-<?      if (check_perms('site_admin_forums')) { ?>
85
-              <a href="#content<?=$PostID?>" onclick="LoadEdit('<?=substr($Link, 0, strcspn($Link, '.'))?>', <?=$PostID?>, 1); return false;">&laquo;</a>
86
-<?      } ?>
87
-              Last edited by
88
-              <?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime, 2, true, true)?>
89
-<?    } ?>
90
-            </div>
91
-          </div>
92
-        </td>
93
-      </tr>
94
-    </table>
95
-<?  }
71
+          ?>
72
+        <form class="manage_form hidden" name="user"
73
+          id="warn<?=$PostID?>" action="comments.php" method="post">
74
+          <input type="hidden" name="action" value="warn" />
75
+          <input type="hidden" name="postid" value="<?=$PostID?>" />
76
+        </form>
77
+        - <a href="#"
78
+          onclick="$('#warn<?=$PostID?>').raw().submit(); return false;"
79
+          class="brackets">Warn</a>
80
+        <?php
81
+      } ?>
82
+        &nbsp;
83
+        <a href="#">&uarr;</a>
84
+        <?php } ?>
85
+      </div>
86
+    </td>
87
+  </tr>
88
+  <tr>
89
+    <?php if (Users::has_avatars_enabled()) { ?>
90
+    <td class="avatar" valign="top">
91
+      <?=Users::show_avatar($UserInfo['Avatar'], $AuthorID, $UserInfo['Username'], G::$LoggedUser['DisableAvatars'])?>
92
+    </td>
93
+    <?php } ?>
94
+    <td class="body" valign="top">
95
+      <div id="content<?=$PostID?>">
96
+        <?=Text::full_format($Body)?>
97
+        <?php if ($EditedUserID) { ?>
98
+        <br />
99
+        <br />
100
+        <div class="last_edited">
101
+          <?php if (check_perms('site_admin_forums')) { ?>
102
+          <a href="#content<?=$PostID?>"
103
+            onclick="LoadEdit('<?=substr($Link, 0, strcspn($Link, '.'))?>', <?=$PostID?>, 1); return false;">&laquo;</a>
104
+          <?php } ?>
105
+          Last edited by
106
+          <?=Users::format_username($EditedUserID, false, false, false) ?>
107
+          <?=time_diff($EditedTime, 2, true, true)?>
108
+          <?php } ?>
109
+        </div>
110
+      </div>
111
+    </td>
112
+  </tr>
113
+</table>
114
+<?php
115
+    }
96 116
 }

+ 215
- 202
classes/donationsview.class.php View File

@@ -1,214 +1,227 @@
1
-<?
1
+<?php
2 2
 
3
-class DonationsView {
4
-  public static function render_mod_donations($UserID) {
5
-?>
6
-    <table class="layout box" id="donation_box">
7
-      <tr class="colhead">
8
-        <td colspan="2">
9
-          Donor System (add points)
10
-        </td>
11
-      </tr>
12
-      <tr>
13
-        <td class="label">Value:</td>
14
-        <td>
15
-          <input type="text" name="donation_value" onkeypress="return isNumberKey(event);" />
16
-          <select name="donation_currency">
17
-            <option value="EUR">EUR</option>
18
-            <option value="USD">USD</option>
19
-            <option value="BTC">BTC</option>
20
-          </select>
21
-        </td>
22
-      </tr>
23
-      <tr>
24
-        <td class="label">Reason:</td>
25
-        <td><input type="text" class="wide_input_text" name="donation_reason" /></td>
26
-      </tr>
27
-      <tr>
28
-        <td align="right" colspan="2">
29
-          <input type="submit" name="donor_points_submit" value="Add donor points" />
30
-        </td>
31
-      </tr>
32
-    </table>
3
+class DonationsView
4
+{
5
+    public static function render_mod_donations($UserID)
6
+    {
7
+        ?>
8
+<table class="layout box" id="donation_box">
9
+  <tr class="colhead">
10
+    <td colspan="2">
11
+      Donor System (add points)
12
+    </td>
13
+  </tr>
14
+  <tr>
15
+    <td class="label">Value:</td>
16
+    <td>
17
+      <input type="text" name="donation_value" onkeypress="return isNumberKey(event);" />
18
+      <select name="donation_currency">
19
+        <option value="EUR">EUR</option>
20
+        <option value="USD">USD</option>
21
+        <option value="BTC">BTC</option>
22
+      </select>
23
+    </td>
24
+  </tr>
25
+  <tr>
26
+    <td class="label">Reason:</td>
27
+    <td><input type="text" class="wide_input_text" name="donation_reason" /></td>
28
+  </tr>
29
+  <tr>
30
+    <td align="right" colspan="2">
31
+      <input type="submit" name="donor_points_submit" value="Add donor points" />
32
+    </td>
33
+  </tr>
34
+</table>
33 35
 
34
-    <table class="layout box" id="donor_points_box">
35
-      <tr class="colhead">
36
-        <td colspan="3" class="tooltip" title='Use this tool only when manually correcting values. If crediting donations normally, use the "Donor System (add points)" tool'>
37
-          Donor System (modify values)
38
-        </td>
39
-      </tr>
40
-      <tr>
41
-        <td class="label tooltip" title="Active points determine a user's Donor Rank and do expire.">Active points:</td>
42
-        <td><input type="text" name="donor_rank" onkeypress="return isNumberKey(event);" value="<?=Donations::get_rank($UserID)?>" /></td>
43
-      </tr>
44
-      <tr>
45
-        <td class="label tooltip" title="Total points represent a user's overall total and never expire. Total points determines a user's Special Rank and Donor Leaderboard placement.">Total points:</td>
46
-        <td><input type="text" name="total_donor_rank" onkeypress="return isNumberKey(event);" value="<?=Donations::get_total_rank($UserID)?>" /></td>
47
-      </tr>
48
-      <tr>
49
-        <td class="label">Reason:</td>
50
-        <td><input type="text" class="wide_input_text" name="reason" /></td>
51
-      </tr>
52
-      <tr>
53
-        <td align="right" colspan="2">
54
-          <input type="submit" name="donor_values_submit" value="Change point values" />
55
-        </td>
56
-      </tr>
57
-    </table>
58
-<?
59
-  }
36
+<table class="layout box" id="donor_points_box">
37
+  <tr class="colhead">
38
+    <td colspan="3" class="tooltip"
39
+      title='Use this tool only when manually correcting values. If crediting donations normally, use the "Donor System (add points)" tool'>
40
+      Donor System (modify values)
41
+    </td>
42
+  </tr>
43
+  <tr>
44
+    <td class="label tooltip" title="Active points determine a user's Donor Rank and do expire.">Active points:</td>
45
+    <td><input type="text" name="donor_rank" onkeypress="return isNumberKey(event);"
46
+        value="<?=Donations::get_rank($UserID)?>" /></td>
47
+  </tr>
48
+  <tr>
49
+    <td class="label tooltip"
50
+      title="Total points represent a user's overall total and never expire. Total points determines a user's Special Rank and Donor Leaderboard placement.">
51
+      Total points:</td>
52
+    <td><input type="text" name="total_donor_rank" onkeypress="return isNumberKey(event);"
53
+        value="<?=Donations::get_total_rank($UserID)?>" /></td>
54
+  </tr>
55
+  <tr>
56
+    <td class="label">Reason:</td>
57
+    <td><input type="text" class="wide_input_text" name="reason" /></td>
58
+  </tr>
59
+  <tr>
60
+    <td align="right" colspan="2">
61
+      <input type="submit" name="donor_values_submit" value="Change point values" />
62
+    </td>
63
+  </tr>
64
+</table>
65
+<?php
66
+    }
60 67
 
61
-  public static function render_donor_stats($UserID) {
62
-    $OwnProfile = G::$LoggedUser['ID'] == $UserID;
63
-    if (check_perms("users_mod") || $OwnProfile || Donations::is_visible($UserID)) {
64
-?>
65
-      <div class="box box_info box_userinfo_donor_stats">
66
-        <div class="head colhead_dark">Donor Statistics</div>
67
-        <ul class="stats nobullet">
68
-<?
68
+    public static function render_donor_stats($UserID)
69
+    {
70
+        $OwnProfile = G::$LoggedUser['ID'] === $UserID;
71
+        if (check_perms("users_mod") || $OwnProfile || Donations::is_visible($UserID)) {
72
+            ?>
73
+<div class="box box_info box_userinfo_donor_stats">
74
+  <div class="head colhead_dark">Donor Statistics</div>
75
+  <ul class="stats nobullet">
76
+    <?php
69 77
       if (Donations::is_donor($UserID)) {
70
-        if (check_perms('users_mod') || $OwnProfile) {
71
-?>
72
-          <li>
73
-            Total donor points: <?=Donations::get_total_rank($UserID)?>
74
-          </li>
75
-<?        } ?>
76
-          <li>
77
-            Current donor rank: <?=self::render_rank(Donations::get_rank($UserID), Donations::get_special_rank($UserID), true)?>
78
-          </li>
79
-          <li>
80
-            Leaderboard position: <?=Donations::get_leaderboard_position($UserID)?>
81
-          </li>
82
-          <li>
83
-            Last donated: <?=time_diff(Donations::get_donation_time($UserID))?>
84
-          </li>
85
-          <li>
86
-            Rank expires: <?=(Donations::get_rank_expiration($UserID))?>
87
-          </li>
88
-<?      } else { ?>
89
-          <li>
90
-            This user hasn't donated.
91
-          </li>
92
-<?      } ?>
93
-        </ul>
94
-      </div>
95
-<?
78
+          if (check_perms('users_mod') || $OwnProfile) {
79
+              ?>
80
+    <li>
81
+      Total donor points: <?=Donations::get_total_rank($UserID)?>
82
+    </li>
83
+    <?php
84
+          } ?>
85
+    <li>
86
+      Current donor rank: <?=self::render_rank(Donations::get_rank($UserID), Donations::get_special_rank($UserID), true)?>
87
+    </li>
88
+    <li>
89
+      Leaderboard position: <?=Donations::get_leaderboard_position($UserID)?>
90
+    </li>
91
+    <li>
92
+      Last donated: <?=time_diff(Donations::get_donation_time($UserID))?>
93
+    </li>
94
+    <li>
95
+      Rank expires: <?=(Donations::get_rank_expiration($UserID))?>
96
+    </li>
97
+    <?php
98
+      } else { ?>
99
+    <li>
100
+      This user hasn't donated.
101
+    </li>
102
+    <?php      } ?>
103
+  </ul>
104
+</div>
105
+<?php
106
+        }
96 107
     }
97
-  }
98 108
 
99
-  public static function render_profile_rewards($EnabledRewards, $ProfileRewards) {
100
-    for ($i = 1; $i <= 4; $i++) {
101
-      if ($EnabledRewards['HasProfileInfo' . $i] && $ProfileRewards['ProfileInfo' . $i]) {
102
-?>
103
-      <div class="box">
104
-        <div class="head">
105
-          <span><?=!empty($ProfileRewards['ProfileInfoTitle' . $i]) ? display_str($ProfileRewards['ProfileInfoTitle' . $i]) : "Extra Profile " . ($i + 1)?></span>
106
-          <span class="float_right"><a data-toggle-target="#profilediv_<?=$i?>" data-toggle-replace="Show" class="brackets">Hide</a></span>
107
-        </div>
108
-        <div class="pad profileinfo" id="profilediv_<?=$i?>">
109
-<?          echo Text::full_format($ProfileRewards['ProfileInfo' . $i]); ?>
110
-        </div>
111
-      </div>
112
-<?
113
-      }
109
+    public static function render_profile_rewards($EnabledRewards, $ProfileRewards)
110
+    {
111
+        for ($i = 1; $i <= 4; $i++) {
112
+            if ($EnabledRewards['HasProfileInfo' . $i] && $ProfileRewards['ProfileInfo' . $i]) {
113
+                ?>
114
+<div class="box">
115
+  <div class="head">
116
+    <span><?=!empty($ProfileRewards['ProfileInfoTitle' . $i]) ? display_str($ProfileRewards['ProfileInfoTitle' . $i]) : "Extra Profile " . ($i + 1)?></span>
117
+    <span class="float_right"><a
118
+        data-toggle-target="#profilediv_<?=$i?>"
119
+        data-toggle-replace="Show" class="brackets">Hide</a></span>
120
+  </div>
121
+  <div class="pad profileinfo" id="profilediv_<?=$i?>">
122
+    <?php          echo Text::full_format($ProfileRewards['ProfileInfo' . $i]); ?>
123
+  </div>
124
+</div>
125
+<?php
126
+            }
127
+        }
114 128
     }
115
-  }
116 129
 
117
-  public static function render_donation_history($DonationHistory) {
118
-    if (empty($DonationHistory)) {
119
-      return;
120
-    }
121
-?>
122
-    <div class="box box2" id="donation_history_box">
123
-      <div class="head">
124
-        Donation History <a data-toggle-target="#donation_history" class="brackets" style="float_right">Toggle</a>
125
-      </div>
126
-      <div class="hidden" id="donation_history">
127
-        <table cellpadding="6" cellspacing="1" border="0" class="border" width="100%">
128
-          <tbody>
129
-          <tr class="colhead_dark">
130
-            <td>
131
-              <strong>Source</strong>
132
-            </td>
133
-            <td>
134
-              <strong>Date</strong>
135
-            </td>
136
-            <td>
137
-              <strong>Amount (EUR)</strong>
138
-            </td>
139
-            <td>
140
-              <strong>Added Points</strong>
141
-            </td>
142
-            <td>
143
-              <strong>Total Points</strong>
144
-            </td>
145
-            <td>
146
-              <strong>Email</strong>
147
-            </td>
148
-            <td style="width: 30%;">
149
-              <strong>Reason</strong>
150
-            </td>
151
-          </tr>
152
-<?    foreach ($DonationHistory as $Donation) { ?>
153
-          <tr class="row">
154
-            <td>
155
-              <?=display_str($Donation['Source'])?> (<?=Users::format_username($Donation['AddedBy'])?>)
156
-            </td>
157
-            <td>
158
-              <?=$Donation['Time']?>
159
-            </td>
160
-            <td>
161
-              <?=$Donation['Amount']?>
162
-            </td>
163
-            <td>
164
-              <?=$Donation['Rank']?>
165
-            </td>
166
-            <td>
167
-              <?=$Donation['TotalRank']?>
168
-            </td>
169
-            <td>
170
-              <?=display_str($Donation['Email'])?>
171
-            </td>
172
-            <td>
173
-              <?=display_str($Donation['Reason'])?>
174
-            </td>
175
-          </tr>
176
-<?
130
+    public static function render_donation_history($DonationHistory)
131
+    {
132
+        if (empty($DonationHistory)) {
133
+            return;
134
+        } ?>
135
+<div class="box box2" id="donation_history_box">
136
+  <div class="head">
137
+    Donation History <a data-toggle-target="#donation_history" class="brackets" style="float_right">Toggle</a>
138
+  </div>
139
+  <div class="hidden" id="donation_history">
140
+    <table cellpadding="6" cellspacing="1" border="0" class="border" width="100%">
141
+      <tbody>
142
+        <tr class="colhead_dark">
143
+          <td>
144
+            <strong>Source</strong>
145
+          </td>
146
+          <td>
147
+            <strong>Date</strong>
148
+          </td>
149
+          <td>
150
+            <strong>Amount (EUR)</strong>
151
+          </td>
152
+          <td>
153
+            <strong>Added Points</strong>
154
+          </td>
155
+          <td>
156
+            <strong>Total Points</strong>
157
+          </td>
158
+          <td>
159
+            <strong>Email</strong>
160
+          </td>
161
+          <td style="width: 30%;">
162
+            <strong>Reason</strong>
163
+          </td>
164
+        </tr>
165
+        <?php    foreach ($DonationHistory as $Donation) { ?>
166
+        <tr class="row">
167
+          <td>
168
+            <?=display_str($Donation['Source'])?>
169
+            (<?=Users::format_username($Donation['AddedBy'])?>)
170
+          </td>
171
+          <td>
172
+            <?=$Donation['Time']?>
173
+          </td>
174
+          <td>
175
+            <?=$Donation['Amount']?>
176
+          </td>
177
+          <td>
178
+            <?=$Donation['Rank']?>
179
+          </td>
180
+          <td>
181
+            <?=$Donation['TotalRank']?>
182
+          </td>
183
+          <td>
184
+            <?=display_str($Donation['Email'])?>
185
+          </td>
186
+          <td>
187
+            <?=display_str($Donation['Reason'])?>
188
+          </td>
189
+        </tr>
190
+        <?php
191
+    } ?>
192
+      </tbody>
193
+    </table>
194
+  </div>
195
+</div>
196
+<?php
177 197
     }
178
-?>
179
-          </tbody>
180
-        </table>
181
-      </div>
182
-    </div>
183
-<?
184
-  }
185 198
 
186
-  public static function render_rank($Rank, $SpecialRank, $ShowOverflow = false) {
187
-    if ($SpecialRank == 3) {
188
-      $Display = '∞ [Diamond]';
189
-    } else {
190
-      $CurrentRank = $Rank >= MAX_RANK ? MAX_RANK : $Rank;
191
-      $Overflow = $Rank - $CurrentRank;
192
-      $Display = $CurrentRank;
193
-      if ($Display == 5 || $Display == 6) {
194
-        $Display--;
195
-      }
196
-      if ($ShowOverflow && $Overflow) {
197
-        $Display .= " (+$Overflow)";
198
-      }
199
-      if ($Rank >= 6) {
200
-        $Display .= ' [Gold]';
201
-      } elseif ($Rank >= 4) {
202
-        $Display .= ' [Silver]';
203
-      } elseif ($Rank >= 3) {
204
-        $Display .= ' [Bronze]';
205
-      } elseif ($Rank >= 2) {
206
-        $Display .= ' [Copper]';
207
-      } elseif ($Rank >= 1) {
208
-        $Display .= ' [Red]';
209
-      }
199
+    public static function render_rank($Rank, $SpecialRank, $ShowOverflow = false)
200
+    {
201
+        if ($SpecialRank === 3) {
202
+            $Display = '∞ [Diamond]';
203
+        } else {
204
+            $CurrentRank = $Rank >= MAX_RANK ? MAX_RANK : $Rank;
205
+            $Overflow = $Rank - $CurrentRank;
206
+            $Display = $CurrentRank;
207
+            if ($Display === 5 || $Display === 6) {
208
+                $Display--;
209
+            }
210
+            if ($ShowOverflow && $Overflow) {
211
+                $Display .= " (+$Overflow)";
212
+            }
213
+            if ($Rank >= 6) {
214
+                $Display .= ' [Gold]';
215
+            } elseif ($Rank >= 4) {
216
+                $Display .= ' [Silver]';
217
+            } elseif ($Rank >= 3) {
218
+                $Display .= ' [Bronze]';
219
+            } elseif ($Rank >= 2) {
220
+                $Display .= ' [Copper]';
221
+            } elseif ($Rank >= 1) {
222
+                $Display .= ' [Red]';
223
+            }
224
+        }
225
+        echo $Display;
210 226
     }
211
-    echo $Display;
212
-  }
213
-
214 227
 }

+ 77
- 45
classes/format.class.php View File

@@ -2,39 +2,38 @@
2 2
 
3 3
 class Format
4 4
 {
5
-
6
-  /**
7
-   * Torrent Labels
8
-   * Map a common display string to a CSS class
9
-   * Indexes are lower case
10
-   * Note the "tl_" prefix for "torrent label"
11
-   *
12
-   * There are five basic types:
13
-   * * tl_free (leech status)
14
-   * * tl_snatched
15
-   * * tl_reported
16
-   * * tl_approved
17
-   * * tl_notice (default)
18
-   *
19
-   * @var array Strings
20
-   */
5
+    /**
6
+     * Torrent Labels
7
+     * Map a common display string to a CSS class
8
+     * Indexes are lower case
9
+     * Note the "tl_" prefix for "torrent label"
10
+     *
11
+     * There are five basic types:
12
+     * * tl_free (leech status)
13
+     * * tl_snatched
14
+     * * tl_reported
15
+     * * tl_approved
16
+     * * tl_notice (default)
17
+     *
18
+     * @var array Strings
19
+     */
21 20
     private static $TorrentLabels = array(
22
-    'default'  => 'tl_notice',
23
-    'snatched' => 'tl_snatched',
24
-    'seeding'  => 'tl_seeding',
25
-    'leeching' => 'tl_leeching',
21
+        'default'  => 'tl_notice',
22
+        'snatched' => 'tl_snatched',
23
+        'seeding'  => 'tl_seeding',
24
+        'leeching' => 'tl_leeching',
26 25
 
27
-    'freeleech'          => 'tl_free',
28
-    'neutral leech'      => 'tl_free tl_neutral',
29
-    'personal freeleech' => 'tl_free tl_personal',
26
+        'freeleech'          => 'tl_free',
27
+        'neutral leech'      => 'tl_free tl_neutral',
28
+        'personal freeleech' => 'tl_free tl_personal',
30 29
 
31
-    'reported'       => 'tl_reported',
32
-    'bad tags'       => 'tl_reported tl_bad_tags',
33
-    'bad folders'    => 'tl_reported tl_bad_folders',
34
-    'bad file names' => 'tl_reported tl_bad_file_names',
30
+        'reported'       => 'tl_reported',
31
+        'bad tags'       => 'tl_reported tl_bad_tags',
32
+        'bad folders'    => 'tl_reported tl_bad_folders',
33
+        'bad file names' => 'tl_reported tl_bad_file_names',
35 34
 
36
-    'uncensored' => 'tl_notice'
37
-  );
35
+        'uncensored' => 'tl_notice'
36
+    );
38 37
 
39 38
     /**
40 39
      * Shorten a string
@@ -82,36 +81,47 @@ class Format
82 81
         if ($Ratio < 0.1) {
83 82
             return 'r00';
84 83
         }
84
+
85 85
         if ($Ratio < 0.2) {
86 86
             return 'r01';
87 87
         }
88
+
88 89
         if ($Ratio < 0.3) {
89 90
             return 'r02';
90 91
         }
92
+
91 93
         if ($Ratio < 0.4) {
92 94
             return 'r03';
93 95
         }
96
+
94 97
         if ($Ratio < 0.5) {
95 98
             return 'r04';
96 99
         }
100
+
97 101
         if ($Ratio < 0.6) {
98 102
             return 'r05';
99 103
         }
104
+
100 105
         if ($Ratio < 0.7) {
101 106
             return 'r06';
102 107
         }
108
+
103 109
         if ($Ratio < 0.8) {
104 110
             return 'r07';
105 111
         }
112
+
106 113
         if ($Ratio < 0.9) {
107 114
             return 'r08';
108 115
         }
116
+
109 117
         if ($Ratio < 1) {
110 118
             return 'r09';
111 119
         }
120
+
112 121
         if ($Ratio < 2) {
113 122
             return 'r10';
114 123
         }
124
+
115 125
         if ($Ratio < 5) {
116 126
             return 'r20';
117 127
         }
@@ -133,9 +143,11 @@ class Format
133 143
         if ($Ratio === false) {
134 144
             return '&ndash;';
135 145
         }
146
+
136 147
         if ($Ratio === '∞') {
137 148
             return '<span class="tooltip r99" title="Infinite">∞</span>';
138 149
         }
150
+
139 151
         if ($Color) {
140 152
             $Ratio = sprintf(
141 153
                 '<span class="tooltip %s" title="%s">%s</span>',
@@ -144,7 +156,6 @@ class Format
144 156
                 $Ratio
145 157
             );
146 158
         }
147
-
148 159
         return $Ratio;
149 160
     }
150 161
 
@@ -160,6 +171,7 @@ class Format
160 171
         if ($Divisor === 0 && $Dividend === 0) {
161 172
             return false;
162 173
         }
174
+
163 175
         if ($Divisor === 0) {
164 176
             return '∞';
165 177
         }
@@ -180,9 +192,11 @@ class Format
180 192
             $Separator = $Escape ? '&amp;' : '&';
181 193
             $QueryItems = null;
182 194
             parse_str($_SERVER['QUERY_STRING'], $QueryItems);
195
+
183 196
             foreach ($Exclude as $Key) {
184 197
                 unset($QueryItems[$Key]);
185 198
             }
199
+
186 200
             if ($Sort) {
187 201
                 ksort($QueryItems);
188 202
             }
@@ -217,6 +231,7 @@ class Format
217 231
                 error(0);
218 232
             }
219 233
             $Page = $_GET['page'];
234
+
220 235
             if ($Page <= 0) {
221 236
                 $Page = 1;
222 237
             }
@@ -262,6 +277,7 @@ class Format
262 277
         $Location = "$Document.php";
263 278
         $StartPage = ceil($StartPage);
264 279
         $TotalPages = 0;
280
+
265 281
         if ($TotalRecords > 0) {
266 282
             $StartPage = min($StartPage, ceil($TotalRecords / $ItemsPerPage));
267 283
 
@@ -305,6 +321,7 @@ class Format
305 321
                     if ($i !== $StartPage) {
306 322
                         $Pages .= "<a href=\"$Location?page=$i$QueryString$Anchor\">";
307 323
                     }
324
+
308 325
                     $Pages .= '<strong>';
309 326
                     if ($i * $ItemsPerPage > $TotalRecords) {
310 327
                         $Pages .= ((($i - 1) * $ItemsPerPage) + 1)."-$TotalRecords";
@@ -316,6 +333,7 @@ class Format
316 333
                     if ($i !== $StartPage) {
317 334
                         $Pages .= '</a>';
318 335
                     }
336
+
319 337
                     if ($i < $StopPage) {
320 338
                         $Pages .= ' | ';
321 339
                     }
@@ -329,6 +347,7 @@ class Format
329 347
                 $Pages .= "<a href=\"$Location?page=$TotalPages$QueryString$Anchor\"><strong> Last »</strong></a>";
330 348
             }
331 349
         }
350
+
332 351
         if ($TotalPages > 1) {
333 352
             return $Pages;
334 353
         }
@@ -347,8 +366,10 @@ class Format
347 366
     {
348 367
         $Units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
349 368
         $Size = (double)$Size;
369
+
350 370
         for ($Steps = 0; abs($Size) >= 1024 && $Steps < count($Units); $Size /= 1024, $Steps++) {
351 371
         }
372
+
352 373
         if (func_num_args() === 1 && $Steps >= 4) {
353 374
             $Levels++;
354 375
         }
@@ -369,15 +390,15 @@ class Format
369 390
             $Number = $Number / 1000;
370 391
         }
371 392
         switch ($Steps) {
372
-      case 0: return round($Number); break;
373
-      case 1: return round($Number, 2).'k'; break;
374
-      case 2: return round($Number, 2).'M'; break;
375
-      case 3: return round($Number, 2).'G'; break;
376
-      case 4: return round($Number, 2).'T'; break;
377
-      case 5: return round($Number, 2).'P'; break;
378
-      default:
379
-        return round($Number, 2).'E + '.$Steps * 3;
380
-    }
393
+          case 0: return round($Number); break;
394
+          case 1: return round($Number, 2).'k'; break;
395
+          case 2: return round($Number, 2).'M'; break;
396
+          case 3: return round($Number, 2).'G'; break;
397
+          case 4: return round($Number, 2).'T'; break;
398
+          case 5: return round($Number, 2).'P'; break;
399
+          default:
400
+            return round($Number, 2).'E + '.$Steps * 3;
401
+        }
381 402
     }
382 403
 
383 404
     /**
@@ -393,13 +414,14 @@ class Format
393 414
         if (empty($Unit)) {
394 415
             return $Value ? round($Value) : 0;
395 416
         }
417
+
396 418
         switch (strtolower($Unit[0])) {
397
-      case 'k': return round($Value * 1024);
398
-      case 'm': return round($Value * 1048576);
399
-      case 'g': return round($Value * 1073741824);
400
-      case 't': return round($Value * 1099511627776);
401
-      default: return 0;
402
-    }
419
+          case 'k': return round($Value * 1024);
420
+          case 'm': return round($Value * 1048576);
421
+          case 'g': return round($Value * 1073741824);
422
+          case 't': return round($Value * 1099511627776);
423
+          default: return 0;
424
+        }
403 425
     }
404 426
 
405 427
     /**
@@ -447,6 +469,7 @@ class Format
447 469
         if (empty($Array)) {
448 470
             $Array = $_GET;
449 471
         }
472
+
450 473
         if (isset($Array[$Name]) && $Array[$Name] !== '') {
451 474
             if ($Array[$Name] === $Value) {
452 475
                 echo " $Attribute=\"$Attribute\"";
@@ -473,6 +496,7 @@ class Format
473 496
         if ($UserIDKey && isset($_REQUEST[$UserIDKey]) && G::$LoggedUser['ID'] != $_REQUEST[$UserIDKey]) {
474 497
             return '';
475 498
         }
499
+
476 500
         $Pass = true;
477 501
         if (!is_array($Tests)) {
478 502
             // Scalars are nice and easy
@@ -489,6 +513,7 @@ class Format
489 513
             // Loop to the end of the array or until we find a matching test
490 514
             foreach ($Tests as $Test) {
491 515
                 $Pass = true;
516
+
492 517
                 // If $Pass remains true after this test, it's a match
493 518
                 foreach ($Test as $Type => $Part) {
494 519
                     if (!isset($Target[$Type]) || $Target[$Type] !== $Part) {
@@ -496,14 +521,17 @@ class Format
496 521
                         break;
497 522
                     }
498 523
                 }
524
+
499 525
                 if ($Pass) {
500 526
                     break;
501 527
                 }
502 528
             }
503 529
         }
530
+
504 531
         if (!$Pass) {
505 532
             return '';
506 533
         }
534
+
507 535
         if ($AddAttribute) {
508 536
             return " class=\"$ClassName\"";
509 537
         }
@@ -522,12 +550,15 @@ class Format
522 550
             if (self::is_utf8($Str)) {
523 551
                 $Encoding = 'UTF-8';
524 552
             }
553
+
525 554
             if (empty($Encoding)) {
526 555
                 $Encoding = mb_detect_encoding($Str, 'UTF-8, ISO-8859-1');
527 556
             }
557
+
528 558
             if (empty($Encoding)) {
529 559
                 $Encoding = 'ISO-8859-1';
530 560
             }
561
+
531 562
             if ($Encoding === 'UTF-8') {
532 563
                 return $Str;
533 564
             } else {
@@ -592,6 +623,7 @@ class Format
592 623
         if (empty($Class)) {
593 624
             $Class = self::find_torrent_label_class($Text);
594 625
         }
626
+        
595 627
         return sprintf(
596 628
             '<strong class="torrent_label tooltip %1$s" title="%2$s" style="white-space: nowrap;">%2$s</strong>',
597 629
             display_str($Class),

+ 11
- 7
classes/image.class.php View File

@@ -15,6 +15,7 @@ class IMAGE
15 15
     {
16 16
         $this->Image = imagecreate($Width, $Height);
17 17
         $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
18
+
18 19
         if (function_exists('imageantialias')) {
19 20
             imageantialias($this->Image, true);
20 21
         }
@@ -27,21 +28,24 @@ class IMAGE
27 28
 
28 29
     public function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1)
29 30
     {
30
-        if ($Thickness == 1) {
31
+        if ($Thickness === 1) {
31 32
             return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
32 33
         }
33 34
         $t = $Thickness / 2 - 0.5;
34
-        if ($x1 == $x2 || $y1 == $y2) {
35
+
36
+        if ($x1 === $x2 || $y1 === $y2) {
35 37
             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);
36 38
         }
37 39
         $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
38 40
         $a = $t / sqrt(1 + pow($k, 2));
41
+
39 42
         $Points = array(
40
-      round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
41
-      round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
42
-      round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
43
-      round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
44
-    );
43
+            round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
44
+            round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
45
+            round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
46
+            round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
47
+        );
48
+
45 49
         imagefilledpolygon($this->Image, $Points, 4, $Color);
46 50
         return imagepolygon($this->Image, $Points, 4, $Color);
47 51
     }

+ 10
- 0
classes/irc.class.php View File

@@ -1,4 +1,5 @@
1 1
 <?php
2
+
2 3
 class IRC_DB extends DB_MYSQL
3 4
 {
4 5
     public function halt($Msg)
@@ -35,6 +36,7 @@ abstract class IRC_BOT
35 36
       if (isset($_SERVER['HOME']) && is_dir($_SERVER['HOME']) && getcwd() !== $_SERVER['HOME']) {
36 37
           chdir($_SERVER['HOME']);
37 38
       }
39
+
38 40
       ob_end_clean();
39 41
       restore_error_handler(); // Avoid PHP error logging
40 42
       set_time_limit(0);
@@ -56,11 +58,14 @@ abstract class IRC_BOT
56 58
         } else {
57 59
             $IrcAddress = 'tcp://' . BOT_SERVER . ':' . BOT_PORT;
58 60
         }
61
+
59 62
         while (!$this->Socket = stream_socket_client($IrcAddress, $ErrNr, $ErrStr)) {
60 63
             sleep(15);
61 64
         }
65
+
62 66
         stream_set_blocking($this->Socket, 0);
63 67
         $this->Connecting = false;
68
+
64 69
         if ($Reconnect) {
65 70
             $this->post_connect();
66 71
         }
@@ -147,6 +152,7 @@ abstract class IRC_BOT
147 152
         // This is used to prevent messages from getting truncated
148 153
         $Text = wordwrap($Text, 460, "\n", true);
149 154
         $TextArray = explode("\n", $Text);
155
+
150 156
         foreach ($TextArray as $Text) {
151 157
             $this->send_raw("PRIVMSG $Channel :$Text");
152 158
         }
@@ -181,12 +187,15 @@ abstract class IRC_BOT
181 187
     {
182 188
         G::$Cache->InternalCache = false;
183 189
         stream_set_timeout($this->Socket, 10000000000);
190
+
184 191
         while ($this->State === 1) {
185 192
             $NullSock = null;
186 193
             $Sockets = array($this->Socket, $this->ListenSocket);
194
+
187 195
             if (stream_select($Sockets, $NullSock, $NullSock, null) === false) {
188 196
                 die();
189 197
             }
198
+
190 199
             foreach ($Sockets as $Socket) {
191 200
                 if ($Socket === $this->Socket) {
192 201
                     $this->irc_events();
@@ -195,6 +204,7 @@ abstract class IRC_BOT
195 204
                     $this->listener_events();
196 205
                 }
197 206
             }
207
+            
198 208
             G::$DB->LinkID = false;
199 209
             G::$DB->Queries = [];
200 210
         }

+ 7
- 7
classes/lockedaccounts.class.php View File

@@ -1,4 +1,4 @@
1
-<?
1
+<?php
2 2
 
3 3
 /**
4 4
  * Class to manage locked accounts
@@ -17,8 +17,7 @@ class LockedAccounts
17 17
      */
18 18
     public static function lock_account($UserID, $Type, $Message, $Reason, $LockedByUserID)
19 19
     {
20
-
21
-        if ($LockedByUserID == 0) {
20
+        if ($LockedByUserID === 0) {
22 21
             $Username = "System";
23 22
         } else {
24 23
             G::$DB->query("SELECT Username FROM users_main WHERE ID = '" . $LockedByUserID . "'");
@@ -26,8 +25,9 @@ class LockedAccounts
26 25
         }
27 26
 
28 27
         G::$DB->query("
29
-                INSERT INTO locked_accounts (UserID, Type)
30
-                VALUES ('" . $UserID . "', " . $Type . ")");
28
+        INSERT INTO locked_accounts (UserID, Type)
29
+          VALUES ('" . $UserID . "', " . $Type . ")");
30
+          
31 31
         Tools::update_user_notes($UserID, sqltime() . " - " . db_string($Message) . " by $Username\nReason: " . db_string($Reason) . "\n\n");
32 32
         G::$Cache->delete_value('user_info_' . $UserID);
33 33
     }
@@ -43,7 +43,7 @@ class LockedAccounts
43 43
      */
44 44
     public static function unlock_account($UserID, $Type, $Message, $Reason, $UnlockedByUserID)
45 45
     {
46
-        if ($UnlockedByUserID == 0) {
46
+        if ($UnlockedByUserID === 0) {
47 47
             $Username = "System";
48 48
         } else {
49 49
             G::$DB->query("SELECT Username FROM users_main WHERE ID = '" . $UnlockedByUserID . "'");
@@ -52,7 +52,7 @@ class LockedAccounts
52 52
 
53 53
         G::$DB->query("DELETE FROM locked_accounts WHERE UserID = '$UserID' AND Type = '". $Type ."'");
54 54
 
55
-        if (G::$DB->affected_rows() == 1) {
55
+        if (G::$DB->affected_rows() === 1) {
56 56
             G::$Cache->delete_value("user_info_" . $UserID);
57 57
             Tools::update_user_notes($UserID, sqltime() . " - " . db_string($Message) . " by $Username\nReason: " . db_string($Reason) . "\n\n");
58 58
         }

+ 45
- 40
classes/mass_user_torrents_editor.class.php View File

@@ -13,49 +13,54 @@
13 13
  *
14 14
  * It could also be used for other types like collages.
15 15
  */
16
-abstract class MASS_USER_TORRENTS_EDITOR {
17
-  /**
18
-   * The affected DB table
19
-   * @var string $Table
20
-   */
21
-  protected $Table;
16
+abstract class MASS_USER_TORRENTS_EDITOR
17
+{
18
+    /**
19
+     * The affected DB table
20
+     * @var string $Table
21
+     */
22
+    protected $Table;
22 23
 
23
-  /**
24
-   * Set the Table
25
-   * @param string $Table
26
-   */
27
-  final public function set_table($Table) {
28
-    $this->Table = db_string($Table);
29
-  }
24
+    /**
25
+     * Set the Table
26
+     * @param string $Table
27
+     */
28
+    final public function set_table($Table)
29
+    {
30
+        $this->Table = db_string($Table);
31
+    }
30 32
 
31
-  /**
32
-   * Get the Table
33
-   * @return string $Table
34
-   */
35
-  final public function get_table() {
36
-    return $this->Table;
37
-  }
33
+    /**
34
+     * Get the Table
35
+     * @return string $Table
36
+     */
37
+    final public function get_table()
38
+    {
39
+        return $this->Table;
40
+    }
38 41
 
39
-  /**
40
-   * The extending class must provide a method to send a query and clear the cache
41
-   */
42
-  abstract protected function query_and_clear_cache($sql);
42
+    /**
43
+     * The extending class must provide a method to send a query and clear the cache
44
+     */
45
+    abstract protected function query_and_clear_cache($sql);
43 46
 
44
-  /**
45
-   * A method to insert many rows into a single table
46
-   * Not required in subsequent classes
47
-   */
48
-  public function mass_add() {}
47
+    /**
48
+     * A method to insert many rows into a single table
49
+     * Not required in subsequent classes
50
+     */
51
+    public function mass_add()
52
+    {
53
+    }
49 54
 
50
-  /**
51
-   * A method to remove many rows from a table
52
-   * The extending class must have a mass_remove method
53
-   */
54
-  abstract public function mass_remove();
55
+    /**
56
+     * A method to remove many rows from a table
57
+     * The extending class must have a mass_remove method
58
+     */
59
+    abstract public function mass_remove();
55 60
 
56
-  /**
57
-   * A method to update many rows in a table
58
-   * The extending class must have a mass_update method
59
-   */
60
-  abstract public function mass_update();
61
-}
61
+    /**
62
+     * A method to update many rows in a table
63
+     * The extending class must have a mass_update method
64
+     */
65
+    abstract public function mass_update();
66
+}

+ 3
- 0
classes/sphinxqlresult.class.php View File

@@ -57,6 +57,7 @@ class SphinxqlResult
57 57
         while ($Row = $this->fetch_array()) {
58 58
             $Return[] = $Row[$Key];
59 59
         }
60
+
60 61
         $this->data_seek(0);
61 62
         return $Return;
62 63
     }
@@ -78,6 +79,7 @@ class SphinxqlResult
78 79
                 $Return[] = $Row;
79 80
             }
80 81
         }
82
+
81 83
         $this->data_seek(0);
82 84
         return $Return;
83 85
     }
@@ -95,6 +97,7 @@ class SphinxqlResult
95 97
         while ($Row = $this->fetch_array()) {
96 98
             $Return[$Row[$Key1]] = $Row[$Key2];
97 99
         }
100
+        
98 101
         $this->data_seek(0);
99 102
         return $Return;
100 103
     }

+ 282
- 262
classes/subscriptions.class.php View File

@@ -1,43 +1,46 @@
1
-<?
2
-class Subscriptions {
3
-  /**
4
-   * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
5
-   * @param string $Body
6
-   * @param int $PostID
7
-   * @param string $Page
8
-   * @param int $PageID
9
-   */
10
-  public static function quote_notify($Body, $PostID, $Page, $PageID) {
11
-    $QueryID = G::$DB->get_query_id();
12
-    /*
13
-     * Explanation of the parameters PageID and Page: Page contains where
14
-     * this quote comes from and can be forums, artist, collages, requests
15
-     * or torrents. The PageID contains the additional value that is
16
-     * necessary for the users_notify_quoted table. The PageIDs for the
17
-     * different Page are: forums: TopicID artist: ArtistID collages:
18
-     * CollageID requests: RequestID torrents: GroupID
1
+<?php
2
+
3
+class Subscriptions
4
+{
5
+    /**
6
+     * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
7
+     * @param string $Body
8
+     * @param int $PostID
9
+     * @param string $Page
10
+     * @param int $PageID
19 11
      */
20
-    $Matches = [];
21
-    preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
12
+    public static function quote_notify($Body, $PostID, $Page, $PageID)
13
+    {
14
+        $QueryID = G::$DB->get_query_id();
15
+        /*
16
+         * Explanation of the parameters PageID and Page: Page contains where
17
+         * this quote comes from and can be forums, artist, collages, requests
18
+         * or torrents. The PageID contains the additional value that is
19
+         * necessary for the users_notify_quoted table. The PageIDs for the
20
+         * different Page are: forums: TopicID artist: ArtistID collages:
21
+         * CollageID requests: RequestID torrents: GroupID
22
+         */
23
+        $Matches = [];
24
+        preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
22 25
 
23
-    if (count($Matches)) {
24
-      $Usernames = [];
25
-      $Level = 0;
26
-      foreach ($Matches as $M) {
27
-        if ($M[0] != '[/quote]') {
28
-          if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
29
-            $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
30
-          }
31
-          ++$Level;
32
-        } else {
33
-          --$Level;
26
+        if (count($Matches)) {
27
+            $Usernames = [];
28
+            $Level = 0;
29
+            foreach ($Matches as $M) {
30
+                if ($M[0] != '[/quote]') {
31
+                    if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
32
+                        $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
33
+                    }
34
+                    ++$Level;
35
+                } else {
36
+                    --$Level;
37
+                }
38
+            }
34 39
         }
35
-      }
36
-    }
37
-    // remove any dupes in the array (the fast way)
38
-    $Usernames = array_flip(array_flip($Usernames));
40
+        // remove any dupes in the array (the fast way)
41
+        $Usernames = array_flip(array_flip($Usernames));
39 42
 
40
-    G::$DB->query("
43
+        G::$DB->query("
41 44
       SELECT m.ID
42 45
       FROM users_main AS m
43 46
         LEFT JOIN users_info AS i ON i.UserID = m.ID
@@ -45,152 +48,163 @@ class Subscriptions {
45 48
         AND i.NotifyOnQuote = '1'
46 49
         AND i.UserID != " . G::$LoggedUser['ID']);
47 50
 
48
-    $Results = G::$DB->to_array();
49
-    foreach ($Results as $Result) {
50
-      $UserID = db_string($Result['ID']);
51
-      $QuoterID = db_string(G::$LoggedUser['ID']);
52
-      $Page = db_string($Page);
53
-      $PageID = db_string($PageID);
54
-      $PostID = db_string($PostID);
51
+        $Results = G::$DB->to_array();
52
+        foreach ($Results as $Result) {
53
+            $UserID = db_string($Result['ID']);
54
+            $QuoterID = db_string(G::$LoggedUser['ID']);
55
+            $Page = db_string($Page);
56
+            $PageID = db_string($PageID);
57
+            $PostID = db_string($PostID);
55 58
 
56
-      G::$DB->query("
59
+            G::$DB->query(
60
+          "
57 61
         INSERT IGNORE INTO users_notify_quoted
58 62
           (UserID, QuoterID, Page, PageID, PostID, Date)
59 63
         VALUES
60 64
           (    ?,               ?,               ?,      ?,       ?,   NOW())",
61
-          $Result['ID'], G::$LoggedUser['ID'], $Page, $PageID, $PostID);
62
-      G::$Cache->delete_value("notify_quoted_$UserID");
63
-      if ($Page == 'forums') {
64
-        $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
65
-      } else {
66
-        $URL = site_url() . "comments.php?action=jump&postid=$PostID";
67
-      }
65
+          $Result['ID'],
66
+          G::$LoggedUser['ID'],
67
+          $Page,
68
+          $PageID,
69
+          $PostID
70
+      );
71
+            G::$Cache->delete_value("notify_quoted_$UserID");
72
+            if ($Page == 'forums') {
73
+                $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
74
+            } else {
75
+                $URL = site_url() . "comments.php?action=jump&postid=$PostID";
76
+            }
77
+        }
78
+        G::$DB->set_query_id($QueryID);
68 79
     }
69
-    G::$DB->set_query_id($QueryID);
70
-  }
71 80
 
72
-  /**
73
-   * (Un)subscribe from a forum thread.
74
-   * If UserID == 0, G::$LoggedUser[ID] is used
75
-   * @param int $TopicID
76
-   * @param int $UserID
77
-   */
78
-  public static function subscribe($TopicID, $UserID = 0) {
79
-    if ($UserID == 0) {
80
-      $UserID = G::$LoggedUser['ID'];
81
-    }
82
-    $QueryID = G::$DB->get_query_id();
83
-    $UserSubscriptions = self::get_subscriptions();
84
-    $Key = self::has_subscribed($TopicID);
85
-    if ($Key !== false) {
86
-      G::$DB->query('
81
+    /**
82
+     * (Un)subscribe from a forum thread.
83
+     * If UserID == 0, G::$LoggedUser[ID] is used
84
+     * @param int $TopicID
85
+     * @param int $UserID
86
+     */
87
+    public static function subscribe($TopicID, $UserID = 0)
88
+    {
89
+        if ($UserID == 0) {
90
+            $UserID = G::$LoggedUser['ID'];
91
+        }
92
+        $QueryID = G::$DB->get_query_id();
93
+        $UserSubscriptions = self::get_subscriptions();
94
+        $Key = self::has_subscribed($TopicID);
95
+        if ($Key !== false) {
96
+            G::$DB->query('
87 97
         DELETE FROM users_subscriptions
88 98
         WHERE UserID = ' . db_string($UserID) . '
89 99
           AND TopicID = ' . db_string($TopicID));
90
-      unset($UserSubscriptions[$Key]);
91
-    } else {
92
-      G::$DB->query("
100
+            unset($UserSubscriptions[$Key]);
101
+        } else {
102
+            G::$DB->query("
93 103
         INSERT IGNORE INTO users_subscriptions (UserID, TopicID)
94 104
         VALUES ($UserID, " . db_string($TopicID) . ")");
95
-      array_push($UserSubscriptions, $TopicID);
105
+            array_push($UserSubscriptions, $TopicID);
106
+        }
107
+        G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
108
+        G::$Cache->delete_value("subscriptions_user_new_$UserID");
109
+        G::$DB->set_query_id($QueryID);
96 110
     }
97
-    G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
98
-    G::$Cache->delete_value("subscriptions_user_new_$UserID");
99
-    G::$DB->set_query_id($QueryID);
100
-  }
101 111
 
102
-  /**
103
-   * (Un)subscribe from comments.
104
-   * If UserID == 0, G::$LoggedUser[ID] is used
105
-   * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
106
-   * @param int $PageID ArtistID, CollageID, RequestID or GroupID
107
-   * @param int $UserID
108
-   */
109
-  public static function subscribe_comments($Page, $PageID, $UserID = 0) {
110
-    if ($UserID == 0) {
111
-      $UserID = G::$LoggedUser['ID'];
112
-    }
113
-    $QueryID = G::$DB->get_query_id();
114
-    $UserCommentSubscriptions = self::get_comment_subscriptions();
115
-    $Key = self::has_subscribed_comments($Page, $PageID);
116
-    if ($Key !== false) {
117
-      G::$DB->query("
112
+    /**
113
+     * (Un)subscribe from comments.
114
+     * If UserID == 0, G::$LoggedUser[ID] is used
115
+     * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
116
+     * @param int $PageID ArtistID, CollageID, RequestID or GroupID
117
+     * @param int $UserID
118
+     */
119
+    public static function subscribe_comments($Page, $PageID, $UserID = 0)
120
+    {
121
+        if ($UserID == 0) {
122
+            $UserID = G::$LoggedUser['ID'];
123
+        }
124
+        $QueryID = G::$DB->get_query_id();
125
+        $UserCommentSubscriptions = self::get_comment_subscriptions();
126
+        $Key = self::has_subscribed_comments($Page, $PageID);
127
+        if ($Key !== false) {
128
+            G::$DB->query("
118 129
         DELETE FROM users_subscriptions_comments
119 130
         WHERE UserID = " . db_string($UserID) . "
120 131
           AND Page = '" . db_string($Page) . "'
121 132
           AND PageID = " . db_string($PageID));
122
-      unset($UserCommentSubscriptions[$Key]);
123
-    } else {
124
-      G::$DB->query("
133
+            unset($UserCommentSubscriptions[$Key]);
134
+        } else {
135
+            G::$DB->query("
125 136
         INSERT IGNORE INTO users_subscriptions_comments
126 137
           (UserID, Page, PageID)
127 138
         VALUES
128 139
           ($UserID, '" . db_string($Page) . "', " . db_string($PageID) . ")");
129
-      array_push($UserCommentSubscriptions, array($Page, $PageID));
140
+            array_push($UserCommentSubscriptions, array($Page, $PageID));
141
+        }
142
+        G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
143
+        G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
144
+        G::$DB->set_query_id($QueryID);
130 145
     }
131
-    G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
132
-    G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
133
-    G::$DB->set_query_id($QueryID);
134
-  }
135 146
 
136
-  /**
137
-   * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
138
-   * If UserID == 0, G::$LoggedUser[ID] is used
139
-   * @param int $UserID
140
-   * @return array Array of TopicIDs
141
-   */
142
-  public static function get_subscriptions($UserID = 0) {
143
-    if ($UserID == 0) {
144
-      $UserID = G::$LoggedUser['ID'];
145
-    }
146
-    $QueryID = G::$DB->get_query_id();
147
-    $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
148
-    if ($UserSubscriptions === false) {
149
-      G::$DB->query('
147
+    /**
148
+     * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
149
+     * If UserID == 0, G::$LoggedUser[ID] is used
150
+     * @param int $UserID
151
+     * @return array Array of TopicIDs
152
+     */
153
+    public static function get_subscriptions($UserID = 0)
154
+    {
155
+        if ($UserID == 0) {
156
+            $UserID = G::$LoggedUser['ID'];
157
+        }
158
+        $QueryID = G::$DB->get_query_id();
159
+        $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
160
+        if ($UserSubscriptions === false) {
161
+            G::$DB->query('
150 162
         SELECT TopicID
151 163
         FROM users_subscriptions
152 164
         WHERE UserID = ' . db_string($UserID));
153
-      $UserSubscriptions = G::$DB->collect(0);
154
-      G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
165
+            $UserSubscriptions = G::$DB->collect(0);
166
+            G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
167
+        }
168
+        G::$DB->set_query_id($QueryID);
169
+        return $UserSubscriptions;
155 170
     }
156
-    G::$DB->set_query_id($QueryID);
157
-    return $UserSubscriptions;
158
-  }
159 171
 
160
-  /**
161
-   * Same as self::get_subscriptions, but for comment subscriptions
162
-   * @param int $UserID
163
-   * @return array Array of ($Page, $PageID)
164
-   */
165
-  public static function get_comment_subscriptions($UserID = 0) {
166
-    if ($UserID == 0) {
167
-      $UserID = G::$LoggedUser['ID'];
168
-    }
169
-    $QueryID = G::$DB->get_query_id();
170
-    $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
171
-    if ($UserCommentSubscriptions === false) {
172
-      G::$DB->query('
172
+    /**
173
+     * Same as self::get_subscriptions, but for comment subscriptions
174
+     * @param int $UserID
175
+     * @return array Array of ($Page, $PageID)
176
+     */
177
+    public static function get_comment_subscriptions($UserID = 0)
178
+    {
179
+        if ($UserID == 0) {
180
+            $UserID = G::$LoggedUser['ID'];
181
+        }
182
+        $QueryID = G::$DB->get_query_id();
183
+        $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
184
+        if ($UserCommentSubscriptions === false) {
185
+            G::$DB->query('
173 186
         SELECT Page, PageID
174 187
         FROM users_subscriptions_comments
175 188
         WHERE UserID = ' . db_string($UserID));
176
-      $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
177
-      G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
189
+            $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
190
+            G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
191
+        }
192
+        G::$DB->set_query_id($QueryID);
193
+        return $UserCommentSubscriptions;
178 194
     }
179
-    G::$DB->set_query_id($QueryID);
180
-    return $UserCommentSubscriptions;
181
-  }
182 195
 
183
-  /**
184
-   * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
185
-   * @return int Number of unread subscribed threads/comments
186
-   */
187
-  public static function has_new_subscriptions() {
188
-    $QueryID = G::$DB->get_query_id();
196
+    /**
197
+     * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
198
+     * @return int Number of unread subscribed threads/comments
199
+     */
200
+    public static function has_new_subscriptions()
201
+    {
202
+        $QueryID = G::$DB->get_query_id();
189 203
 
190
-    $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
191
-    if ($NewSubscriptions === false) {
192
-      // forum subscriptions
193
-      G::$DB->query("
204
+        $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
205
+        if ($NewSubscriptions === false) {
206
+            // forum subscriptions
207
+            G::$DB->query("
194 208
           SELECT COUNT(1)
195 209
           FROM users_subscriptions AS s
196 210
             LEFT JOIN forums_last_read_topics AS l ON l.UserID = s.UserID AND l.TopicID = s.TopicID
@@ -199,10 +213,10 @@ class Subscriptions {
199 213
           WHERE " . Forums::user_forums_sql() . "
200 214
             AND IF(t.IsLocked = '1' AND t.IsSticky = '0'" . ", t.LastPostID, IF(l.PostID IS NULL, 0, l.PostID)) < t.LastPostID
201 215
             AND s.UserID = " . G::$LoggedUser['ID']);
202
-      list($NewForumSubscriptions) = G::$DB->next_record();
216
+            list($NewForumSubscriptions) = G::$DB->next_record();
203 217
 
204
-      // comment subscriptions
205
-      G::$DB->query("
218
+            // comment subscriptions
219
+            G::$DB->query("
206 220
           SELECT COUNT(1)
207 221
           FROM users_subscriptions_comments AS s
208 222
             LEFT JOIN users_comments_last_read AS lr ON lr.UserID = s.UserID AND lr.Page = s.Page AND lr.PageID = s.PageID
@@ -211,23 +225,24 @@ class Subscriptions {
211 225
           WHERE s.UserID = " . G::$LoggedUser['ID'] . "
212 226
             AND (s.Page != 'collages' OR co.Deleted = '0')
213 227
             AND IF(lr.PostID IS NULL, 0, lr.PostID) < c.ID");
214
-      list($NewCommentSubscriptions) = G::$DB->next_record();
228
+            list($NewCommentSubscriptions) = G::$DB->next_record();
215 229
 
216
-      $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
217
-      G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
230
+            $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
231
+            G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
232
+        }
233
+        G::$DB->set_query_id($QueryID);
234
+        return (int)$NewSubscriptions;
218 235
     }
219
-    G::$DB->set_query_id($QueryID);
220
-    return (int)$NewSubscriptions;
221
-  }
222 236
 
223
-  /**
224
-   * Returns whether or not the current user has new quote notifications.
225
-   * @return int Number of unread quote notifications
226
-   */
227
-  public static function has_new_quote_notifications() {
228
-    $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
229
-    if ($QuoteNotificationsCount === false) {
230
-      $sql = "
237
+    /**
238
+     * Returns whether or not the current user has new quote notifications.
239
+     * @return int Number of unread quote notifications
240
+     */
241
+    public static function has_new_quote_notifications()
242
+    {
243
+        $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
244
+        if ($QuoteNotificationsCount === false) {
245
+            $sql = "
231 246
         SELECT COUNT(1)
232 247
         FROM users_notify_quoted AS q
233 248
           LEFT JOIN forums_topics AS t ON t.ID = q.PageID
@@ -237,166 +252,171 @@ class Subscriptions {
237 252
           AND q.UnRead
238 253
           AND (q.Page != 'forums' OR " . Forums::user_forums_sql() . ")
239 254
           AND (q.Page != 'collages' OR c.Deleted = '0')";
240
-      $QueryID = G::$DB->get_query_id();
241
-      G::$DB->query($sql);
242
-      list($QuoteNotificationsCount) = G::$DB->next_record();
243
-      G::$DB->set_query_id($QueryID);
244
-      G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
255
+            $QueryID = G::$DB->get_query_id();
256
+            G::$DB->query($sql);
257
+            list($QuoteNotificationsCount) = G::$DB->next_record();
258
+            G::$DB->set_query_id($QueryID);
259
+            G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
260
+        }
261
+        return (int)$QuoteNotificationsCount;
245 262
     }
246
-    return (int)$QuoteNotificationsCount;
247
-  }
248 263
 
249
-  /**
250
-   * Returns the key which holds this $TopicID in the subscription array.
251
-   * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
252
-   * @param int $TopicID
253
-   * @return bool|int
254
-   */
255
-  public static function has_subscribed($TopicID) {
256
-    $UserSubscriptions = self::get_subscriptions();
257
-    return array_search($TopicID, $UserSubscriptions);
258
-  }
264
+    /**
265
+     * Returns the key which holds this $TopicID in the subscription array.
266
+     * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
267
+     * @param int $TopicID
268
+     * @return bool|int
269
+     */
270
+    public static function has_subscribed($TopicID)
271
+    {
272
+        $UserSubscriptions = self::get_subscriptions();
273
+        return array_search($TopicID, $UserSubscriptions);
274
+    }
259 275
 
260
-  /**
261
-   * Same as has_subscribed, but for comment subscriptions.
262
-   * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
263
-   * @param int $PageID
264
-   * @return bool|int
265
-   */
266
-  public static function has_subscribed_comments($Page, $PageID) {
267
-    $UserCommentSubscriptions = self::get_comment_subscriptions();
268
-    return array_search(array($Page, $PageID), $UserCommentSubscriptions);
269
-  }
276
+    /**
277
+     * Same as has_subscribed, but for comment subscriptions.
278
+     * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
279
+     * @param int $PageID
280
+     * @return bool|int
281
+     */
282
+    public static function has_subscribed_comments($Page, $PageID)
283
+    {
284
+        $UserCommentSubscriptions = self::get_comment_subscriptions();
285
+        return array_search(array($Page, $PageID), $UserCommentSubscriptions);
286
+    }
270 287
 
271
-  /**
272
-   * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
273
-   * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
274
-   * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
275
-   */
276
-  public static function flush_subscriptions($Page, $PageID) {
277
-    $QueryID = G::$DB->get_query_id();
278
-    if ($Page == 'forums') {
279
-      G::$DB->query("
288
+    /**
289
+     * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
290
+     * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
291
+     * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
292
+     */
293
+    public static function flush_subscriptions($Page, $PageID)
294
+    {
295
+        $QueryID = G::$DB->get_query_id();
296
+        if ($Page == 'forums') {
297
+            G::$DB->query("
280 298
         SELECT UserID
281 299
         FROM users_subscriptions
282 300
         WHERE TopicID = '$PageID'");
283
-    } else {
284
-      G::$DB->query("
301
+        } else {
302
+            G::$DB->query("
285 303
         SELECT UserID
286 304
         FROM users_subscriptions_comments
287 305
         WHERE Page = '$Page'
288 306
           AND PageID = '$PageID'");
307
+        }
308
+        $Subscribers = G::$DB->collect('UserID');
309
+        foreach ($Subscribers as $Subscriber) {
310
+            G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
311
+        }
312
+        G::$DB->set_query_id($QueryID);
289 313
     }
290
-    $Subscribers = G::$DB->collect('UserID');
291
-    foreach ($Subscribers as $Subscriber) {
292
-      G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
293
-    }
294
-    G::$DB->set_query_id($QueryID);
295
-  }
296 314
 
297
-  /**
298
-   * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
299
-   * Passing $NewPageID = null will delete the subscriptions.
300
-   * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
301
-   * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
302
-   * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
303
-   */
304
-  public static function move_subscriptions($Page, $OldPageID, $NewPageID) {
305
-    self::flush_subscriptions($Page, $OldPageID);
306
-    $QueryID = G::$DB->get_query_id();
307
-    if ($Page == 'forums') {
308
-      if ($NewPageID !== null) {
309
-        G::$DB->query("
315
+    /**
316
+     * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
317
+     * Passing $NewPageID = null will delete the subscriptions.
318
+     * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
319
+     * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
320
+     * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
321
+     */
322
+    public static function move_subscriptions($Page, $OldPageID, $NewPageID)
323
+    {
324
+        self::flush_subscriptions($Page, $OldPageID);
325
+        $QueryID = G::$DB->get_query_id();
326
+        if ($Page == 'forums') {
327
+            if ($NewPageID !== null) {
328
+                G::$DB->query("
310 329
           UPDATE IGNORE users_subscriptions
311 330
           SET TopicID = '$NewPageID'
312 331
           WHERE TopicID = '$OldPageID'");
313
-        // explanation see below
314
-        G::$DB->query("
332
+                // explanation see below
333
+                G::$DB->query("
315 334
           UPDATE IGNORE forums_last_read_topics
316 335
           SET TopicID = $NewPageID
317 336
           WHERE TopicID = $OldPageID");
318
-        G::$DB->query("
337
+                G::$DB->query("
319 338
           SELECT UserID, MIN(PostID)
320 339
           FROM forums_last_read_topics
321 340
           WHERE TopicID IN ($OldPageID, $NewPageID)
322 341
           GROUP BY UserID
323 342
           HAVING COUNT(1) = 2");
324
-        $Results = G::$DB->to_array(false, MYSQLI_NUM);
325
-        foreach ($Results as $Result) {
326
-          G::$DB->query("
343
+                $Results = G::$DB->to_array(false, MYSQLI_NUM);
344
+                foreach ($Results as $Result) {
345
+                    G::$DB->query("
327 346
             UPDATE forums_last_read_topics
328 347
             SET PostID = $Result[1]
329 348
             WHERE TopicID = $NewPageID
330 349
               AND UserID = $Result[0]");
331
-        }
332
-      }
333
-      G::$DB->query("
350
+                }
351
+            }
352
+            G::$DB->query("
334 353
         DELETE FROM users_subscriptions
335 354
         WHERE TopicID = '$OldPageID'");
336
-      G::$DB->query("
355
+            G::$DB->query("
337 356
         DELETE FROM forums_last_read_topics
338 357
         WHERE TopicID = $OldPageID");
339
-    } else {
340
-      if ($NewPageID !== null) {
341
-        G::$DB->query("
358
+        } else {
359
+            if ($NewPageID !== null) {
360
+                G::$DB->query("
342 361
           UPDATE IGNORE users_subscriptions_comments
343 362
           SET PageID = '$NewPageID'
344 363
           WHERE Page = '$Page'
345 364
             AND PageID = '$OldPageID'");
346
-        // last read handling
347
-        // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
348
-        G::$DB->query("
365
+                // last read handling
366
+                // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
367
+                G::$DB->query("
349 368
           UPDATE IGNORE users_comments_last_read
350 369
           SET PageID = '$NewPageID'
351 370
           WHERE Page = '$Page'
352 371
             AND PageID = $OldPageID");
353
-        // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
354
-        G::$DB->query("
372
+                // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
373
+                G::$DB->query("
355 374
           SELECT UserID, MIN(PostID)
356 375
           FROM users_comments_last_read
357 376
           WHERE Page = '$Page'
358 377
             AND PageID IN ($OldPageID, $NewPageID)
359 378
           GROUP BY UserID
360 379
           HAVING COUNT(1) = 2");
361
-        $Results = G::$DB->to_array(false, MYSQLI_NUM);
362
-        // 3) update rows for those people found in 2) to the earlier post
363
-        foreach ($Results as $Result) {
364
-          G::$DB->query("
380
+                $Results = G::$DB->to_array(false, MYSQLI_NUM);
381
+                // 3) update rows for those people found in 2) to the earlier post
382
+                foreach ($Results as $Result) {
383
+                    G::$DB->query("
365 384
             UPDATE users_comments_last_read
366 385
             SET PostID = $Result[1]
367 386
             WHERE Page = '$Page'
368 387
               AND PageID = $NewPageID
369 388
               AND UserID = $Result[0]");
370
-        }
371
-      }
372
-      G::$DB->query("
389
+                }
390
+            }
391
+            G::$DB->query("
373 392
         DELETE FROM users_subscriptions_comments
374 393
         WHERE Page = '$Page'
375 394
           AND PageID = '$OldPageID'");
376
-      G::$DB->query("
395
+            G::$DB->query("
377 396
         DELETE FROM users_comments_last_read
378 397
         WHERE Page = '$Page'
379 398
           AND PageID = '$OldPageID'");
399
+        }
400
+        G::$DB->set_query_id($QueryID);
380 401
     }
381
-    G::$DB->set_query_id($QueryID);
382
-  }
383 402
 
384
-  /**
385
-   * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
386
-   * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
387
-   * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
388
-   */
389
-  public static function flush_quote_notifications($Page, $PageID) {
390
-    $QueryID = G::$DB->get_query_id();
391
-    G::$DB->query("
403
+    /**
404
+     * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
405
+     * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
406
+     * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
407
+     */
408
+    public static function flush_quote_notifications($Page, $PageID)
409
+    {
410
+        $QueryID = G::$DB->get_query_id();
411
+        G::$DB->query("
392 412
       SELECT UserID
393 413
       FROM users_notify_quoted
394 414
       WHERE Page = '$Page'
395 415
         AND PageID = $PageID");
396
-    $Subscribers = G::$DB->collect('UserID');
397
-    foreach ($Subscribers as $Subscriber) {
398
-      G::$Cache->delete_value("notify_quoted_$Subscriber");
416
+        $Subscribers = G::$DB->collect('UserID');
417
+        foreach ($Subscribers as $Subscriber) {
418
+            G::$Cache->delete_value("notify_quoted_$Subscriber");
419
+        }
420
+        G::$DB->set_query_id($QueryID);
399 421
     }
400
-    G::$DB->set_query_id($QueryID);
401
-  }
402 422
 }

+ 20
- 18
classes/textarea_preview.class.php View File

@@ -43,6 +43,7 @@ class TEXTAREA_PREVIEW_SUPER
43 43
         if (self::$Textareas === 0) {
44 44
             return;
45 45
         }
46
+
46 47
         if (self::$Exectuted === false && $all) {
47 48
             View::parse('generic/textarea/script.phtml');
48 49
         }
@@ -70,6 +71,7 @@ class TEXTAREA_PREVIEW_SUPER
70 71
             }
71 72
             $script[] = sprintf('[%s]', $a);
72 73
         }
74
+
73 75
         if (!empty($script)) {
74 76
             View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
75 77
         }
@@ -155,16 +157,16 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
155 157
      * It's important to have the right IDs as they make the JS function properly.
156 158
      */
157 159
     public function __construct(
158
-      $Name,
159
-      $ID = '',
160
-      $Value = '',
161
-      $Cols = 50,
162
-      $Rows = 10,
163
-      $Preview = true,
164
-      $Buttons = true,
165
-      $Buffer = false,
166
-      array $ExtraAttributes = []
167
-  ) {
160
+        $Name,
161
+        $ID = '',
162
+        $Value = '',
163
+        $Cols = 50,
164
+        $Rows = 10,
165
+        $Preview = true,
166
+        $Buttons = true,
167
+        $Buffer = false,
168
+        array $ExtraAttributes = []
169
+    ) {
168 170
         $this->id = parent::$Textareas;
169 171
         parent::$Textareas += 1;
170 172
         array_push(parent::$_ID, $ID);
@@ -184,14 +186,14 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
184 186
         }
185 187
 
186 188
         $this->buffer = View::parse('generic/textarea/textarea.phtml', array(
187
-      'ID' => $ID,
188
-      'NID' => $this->id,
189
-      'Name' => &$Name,
190
-      'Value' => &$Value,
191
-      'Cols' => &$Cols,
192
-      'Rows' => &$Rows,
193
-      'Attributes' => &$Attributes
194
-    ), $Buffer);
189
+            'ID' => $ID,
190
+            'NID' => $this->id,
191
+            'Name' => &$Name,
192
+            'Value' => &$Value,
193
+            'Cols' => &$Cols,
194
+            'Rows' => &$Rows,
195
+            'Attributes' => &$Attributes
196
+        ), $Buffer);
195 197
 
196 198
         if ($Buttons === true) {
197 199
             $this->buttons();

+ 0
- 3
classes/top10view.class.php View File

@@ -5,7 +5,6 @@ class Top10View
5 5
     public static function render_linkbox($Selected)
6 6
     {
7 7
         ?>
8
-
9 8
 <div class="linkbox">
10 9
   <a href="top10.php?type=torrents" class="brackets"><?=self::get_selected_link("Torrents", $Selected === "torrents")?></a>
11 10
   <a href="top10.php?type=users" class="brackets"><?=self::get_selected_link("Users", $Selected === "users")?></a>
@@ -14,7 +13,6 @@ class Top10View
14 13
   <a href="top10.php?type=donors" class="brackets"><?=self::get_selected_link("Donors", $Selected === "donors")?></a>
15 14
   <?php } ?>
16 15
 </div>
17
-
18 16
 <?php
19 17
     }
20 18
 
@@ -45,7 +43,6 @@ class Top10View
45 43
     {
46 44
         if (!empty($Image)) {
47 45
             $Name = display_str($Name); ?>
48
-
49 46
 <li>
50 47
   <a
51 48
     href="<?=$Url?><?=$Name?>">

+ 224
- 212
classes/torrent_32bit.class.php View File

@@ -1,4 +1,7 @@
1
-<?
1
+<?php
2
+
3
+# todo: Replace this with https://github.com/OPSnet/bencode-torrent
4
+
2 5
 /*******************************************************************************
3 6
 |~~~~ Gazelle bencode parser                                               ~~~~|
4 7
 --------------------------------------------------------------------------------
@@ -72,248 +75,257 @@ coded up in around 4 minutes for STC when we discovered this problem, then
72 75
 discovered that floats aren't accurate enough to use. :(
73 76
 
74 77
 *******************************************************************************/
75
-class BENCODE2 {
76
-  var $Val; // Decoded array
77
-  var $Pos = 1; // Pointer that indicates our position in the string
78
-  var $Str = ''; // Torrent string
79
-
80
-  function __construct($Val, $IsParsed = false) {
81
-    if (!$IsParsed) {
82
-      $this->Str = $Val;
83
-      $this->dec();
84
-    } else {
85
-      $this->Val = $Val;
86
-    }
87
-  }
88
-
89
-  // Decode an element based on the type
90
-  function decode($Type, $Key) {
91
-    if (ctype_digit($Type)) { // Element is a string
92
-      // Get length of string
93
-      $StrLen = $Type;
94
-      while ($this->Str[$this->Pos + 1] != ':') {
95
-        $this->Pos++;
96
-        $StrLen.=$this->Str[$this->Pos];
78
+class BENCODE2
79
+{
80
+    public $Val; // Decoded array
81
+  public $Pos = 1; // Pointer that indicates our position in the string
82
+  public $Str = ''; // Torrent string
83
+
84
+  public function __construct($Val, $IsParsed = false)
85
+  {
86
+      if (!$IsParsed) {
87
+          $this->Str = $Val;
88
+          $this->dec();
89
+      } else {
90
+          $this->Val = $Val;
97 91
       }
98
-      $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
99
-
100
-      $this->Pos += $StrLen;
101
-      $this->Pos += 2;
102
-
103
-    } elseif ($Type == 'i') { // Element is an int
104
-      $this->Pos++;
105
-
106
-      // Find end of integer (first occurance of 'e' after position)
107
-      $End = strpos($this->Str, 'e', $this->Pos);
108
-
109
-      // Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int)
110
-      $this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos);
111
-      $this->Pos = $End + 1;
112
-
113
-    } elseif ($Type == 'l') { // Element is a list
114
-      $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
115
-      $this->Pos += $this->Val[$Key]->Pos;
116
-
117
-    } elseif ($Type == 'd') { // Element is a dictionary
118
-      $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
119
-      $this->Pos += $this->Val[$Key]->Pos;
120
-      // Sort by key to respect spec
121
-      ksort($this->Val[$Key]->Val);
92
+  }
122 93
 
123
-    } else {
124
-      die('Invalid torrent file');
94
+    // Decode an element based on the type
95
+    public function decode($Type, $Key)
96
+    {
97
+        if (ctype_digit($Type)) { // Element is a string
98
+            // Get length of string
99
+            $StrLen = $Type;
100
+            while ($this->Str[$this->Pos + 1] != ':') {
101
+                $this->Pos++;
102
+                $StrLen.=$this->Str[$this->Pos];
103
+            }
104
+            $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
105
+
106
+            $this->Pos += $StrLen;
107
+            $this->Pos += 2;
108
+        } elseif ($Type == 'i') { // Element is an int
109
+            $this->Pos++;
110
+
111
+            // Find end of integer (first occurance of 'e' after position)
112
+            $End = strpos($this->Str, 'e', $this->Pos);
113
+
114
+            // Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int)
115
+            $this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos);
116
+            $this->Pos = $End + 1;
117
+        } elseif ($Type == 'l') { // Element is a list
118
+            $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
119
+            $this->Pos += $this->Val[$Key]->Pos;
120
+        } elseif ($Type == 'd') { // Element is a dictionary
121
+            $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
122
+            $this->Pos += $this->Val[$Key]->Pos;
123
+            // Sort by key to respect spec
124
+            ksort($this->Val[$Key]->Val);
125
+        } else {
126
+            die('Invalid torrent file');
127
+        }
125 128
     }
126
-  }
127 129
 
128
-  function encode($Val) {
129
-    if (is_string($Val)) {
130
-      if (substr($Val, 0, 7) == '[*INT*]') {
131
-        return 'i'.substr($Val,7).'e';
132
-      } else {
133
-        return strlen($Val).':'.$Val;
134
-      }
135
-    } elseif (is_object($Val)) {
136
-      return $Val->enc();
137
-    } else {
138
-      return 'fail';
130
+    public function encode($Val)
131
+    {
132
+        if (is_string($Val)) {
133
+            if (substr($Val, 0, 7) == '[*INT*]') {
134
+                return 'i'.substr($Val, 7).'e';
135
+            } else {
136
+                return strlen($Val).':'.$Val;
137
+            }
138
+        } elseif (is_object($Val)) {
139
+            return $Val->enc();
140
+        } else {
141
+            return 'fail';
142
+        }
139 143
     }
140
-  }
141 144
 }
142 145
 
143
-class BENCODE_LIST extends BENCODE2 {
144
-  function enc() {
145
-    $Str = 'l';
146
-    foreach ($this->Val as $Value) {
147
-      $Str.=$this->encode($Value);
146
+class BENCODE_LIST extends BENCODE2
147
+{
148
+    public function enc()
149
+    {
150
+        $Str = 'l';
151
+        foreach ($this->Val as $Value) {
152
+            $Str.=$this->encode($Value);
153
+        }
154
+        return $Str.'e';
148 155
     }
149
-    return $Str.'e';
150
-  }
151 156
 
152
-  // Decode a list
153
-  function dec() {
154
-    $Key = 0; // Array index
155
-    $Length = strlen($this->Str);
156
-    while ($this->Pos<$Length) {
157
-      $Type = $this->Str[$this->Pos];
158
-      // $Type now indicates what type of element we're dealing with
159
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
160
-
161
-      if ($Type == 'e') { // End of list
162
-        $this->Pos += 1;
163
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
164
-        return;
165
-      }
166
-
167
-      // Decode the bencoded element.
168
-      // This function changes $this->Pos and $this->Val, so you don't have to.
169
-      $this->decode($Type, $Key);
170
-      ++ $Key;
157
+    // Decode a list
158
+    public function dec()
159
+    {
160
+        $Key = 0; // Array index
161
+        $Length = strlen($this->Str);
162
+        while ($this->Pos<$Length) {
163
+            $Type = $this->Str[$this->Pos];
164
+            // $Type now indicates what type of element we're dealing with
165
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
166
+
167
+            if ($Type == 'e') { // End of list
168
+                $this->Pos += 1;
169
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
170
+                return;
171
+            }
172
+
173
+            // Decode the bencoded element.
174
+            // This function changes $this->Pos and $this->Val, so you don't have to.
175
+            $this->decode($Type, $Key);
176
+            ++ $Key;
177
+        }
178
+        return true;
171 179
     }
172
-    return true;
173
-  }
174 180
 }
175 181
 
176
-class BENCODE_DICT extends BENCODE2 {
177
-  function enc() {
178
-    $Str = 'd';
179
-    foreach ($this->Val as $Key => $Value) {
180
-      $Str.=strlen($Key).':'.$Key.$this->encode($Value);
182
+class BENCODE_DICT extends BENCODE2
183
+{
184
+    public function enc()
185
+    {
186
+        $Str = 'd';
187
+        foreach ($this->Val as $Key => $Value) {
188
+            $Str.=strlen($Key).':'.$Key.$this->encode($Value);
189
+        }
190
+        return $Str.'e';
181 191
     }
182
-    return $Str.'e';
183
-  }
184
-
185
-  // Decode a dictionary
186
-  function dec() {
187
-    $Length = strlen($this->Str);
188
-    while ($this->Pos < $Length) {
189
-
190
-      if ($this->Str[$this->Pos] == 'e') { // End of dictionary
191
-        $this->Pos += 1;
192
-        unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
193
-        return;
194
-      }
195
-
196
-      // Get the dictionary key
197
-      // Length of the key, in bytes
198
-      $KeyLen = $this->Str[$this->Pos];
199
-
200
-      // Allow for multi-digit lengths
201
-      while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
202
-        $this->Pos++;
203
-        $KeyLen.=$this->Str[$this->Pos];
204
-      }
205
-      // $this->Pos is now on the last letter of the key length
206
-      // Adding 2 brings it past that character and the ':' to the beginning of the string
207
-      $this->Pos+=2;
208
-
209
-      // Get the name of the key
210
-      $Key = substr($this->Str, $this->Pos, $KeyLen);
211
-
212
-      // Move the position past the key to the beginning of the element
213
-      $this->Pos += $KeyLen;
214
-      $Type = $this->Str[$this->Pos];
215
-      // $Type now indicates what type of element we're dealing with
216
-      // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
217
-
218
-      // Decode the bencoded element.
219
-      // This function changes $this->Pos and $this->Val, so you don't have to.
220
-      $this->decode($Type, $Key);
221
-
222 192
 
193
+    // Decode a dictionary
194
+    public function dec()
195
+    {
196
+        $Length = strlen($this->Str);
197
+        while ($this->Pos < $Length) {
198
+            if ($this->Str[$this->Pos] == 'e') { // End of dictionary
199
+                $this->Pos += 1;
200
+                unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
201
+                return;
202
+            }
203
+
204
+            // Get the dictionary key
205
+            // Length of the key, in bytes
206
+            $KeyLen = $this->Str[$this->Pos];
207
+
208
+            // Allow for multi-digit lengths
209
+            while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
210
+                $this->Pos++;
211
+                $KeyLen.=$this->Str[$this->Pos];
212
+            }
213
+            // $this->Pos is now on the last letter of the key length
214
+            // Adding 2 brings it past that character and the ':' to the beginning of the string
215
+            $this->Pos+=2;
216
+
217
+            // Get the name of the key
218
+            $Key = substr($this->Str, $this->Pos, $KeyLen);
219
+
220
+            // Move the position past the key to the beginning of the element
221
+            $this->Pos += $KeyLen;
222
+            $Type = $this->Str[$this->Pos];
223
+            // $Type now indicates what type of element we're dealing with
224
+            // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
225
+
226
+            // Decode the bencoded element.
227
+            // This function changes $this->Pos and $this->Val, so you don't have to.
228
+            $this->decode($Type, $Key);
229
+        }
230
+        return true;
223 231
     }
224
-    return true;
225
-  }
226 232
 }
227 233
 
228 234
 
229
-class TORRENT extends BENCODE_DICT {
230
-  function dump() {
231
-    // Convenience function used for testing and figuring out how we store the data
232
-    print_r($this->Val);
233
-  }
234
-
235
-  function dump_data() {
236
-    // Function which serializes $this->Val for storage
237
-    return base64_encode(serialize($this->Val));
238
-  }
235
+class TORRENT extends BENCODE_DICT
236
+{
237
+    public function dump()
238
+    {
239
+        // Convenience function used for testing and figuring out how we store the data
240
+        print_r($this->Val);
241
+    }
239 242
 
240
-  function set_announce_url($Announce) {
241
-    $this->Val['announce'] = $Announce;
242
-    ksort($this->Val);
243
-  }
243
+    public function dump_data()
244
+    {
245
+        // Function which serializes $this->Val for storage
246
+        return base64_encode(serialize($this->Val));
247
+    }
244 248
 
245
-  // Returns an array of:
246
-  //  * the files in the torrent
247
-  //  * the total size of files described therein
248
-  function file_list() {
249
-    $FileList = [];
250
-    if (!isset($this->Val['info']->Val['files'])) { // Single file mode
251
-      $TotalSize = substr($this->Val['info']->Val['length'],7);
252
-      $FileList[] = array($TotalSize, $this->get_name());
253
-    } else { // Multiple file mode
254
-      $FileNames = [];
255
-      $FileSizes = [];
256
-      $TotalSize = 0;
257
-      $Files = $this->Val['info']->Val['files']->Val;
258
-      if (isset($Files[0]->Val['path.utf-8'])) {
259
-        $PathKey = 'path.utf-8';
260
-      } else {
261
-        $PathKey = 'path';
262
-      }
263
-      foreach ($Files as $File) {
264
-        $FileSize = substr($File->Val['length'], 7);
265
-        $TotalSize += $FileSize;
249
+    public function set_announce_url($Announce)
250
+    {
251
+        $this->Val['announce'] = $Announce;
252
+        ksort($this->Val);
253
+    }
266 254
 
267
-        $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
268
-        $FileSizes[] = $FileSize;
269
-        $FileNames[] = $FileName;
270
-      }
271
-      natcasesort($FileNames);
272
-      foreach ($FileNames as $Index => $FileName) {
273
-        $FileList[] = array($FileSizes[$Index], $FileName);
274
-      }
255
+    // Returns an array of:
256
+    //  * the files in the torrent
257
+    //  * the total size of files described therein
258
+    public function file_list()
259
+    {
260
+        $FileList = [];
261
+        if (!isset($this->Val['info']->Val['files'])) { // Single file mode
262
+            $TotalSize = substr($this->Val['info']->Val['length'], 7);
263
+            $FileList[] = array($TotalSize, $this->get_name());
264
+        } else { // Multiple file mode
265
+            $FileNames = [];
266
+            $FileSizes = [];
267
+            $TotalSize = 0;
268
+            $Files = $this->Val['info']->Val['files']->Val;
269
+            if (isset($Files[0]->Val['path.utf-8'])) {
270
+                $PathKey = 'path.utf-8';
271
+            } else {
272
+                $PathKey = 'path';
273
+            }
274
+            foreach ($Files as $File) {
275
+                $FileSize = substr($File->Val['length'], 7);
276
+                $TotalSize += $FileSize;
277
+
278
+                $FileName = ltrim(implode('/', $File->Val[$PathKey]->Val), '/');
279
+                $FileSizes[] = $FileSize;
280
+                $FileNames[] = $FileName;
281
+            }
282
+            natcasesort($FileNames);
283
+            foreach ($FileNames as $Index => $FileName) {
284
+                $FileList[] = array($FileSizes[$Index], $FileName);
285
+            }
286
+        }
287
+        return array($TotalSize, $FileList);
275 288
     }
276
-    return array($TotalSize, $FileList);
277
-  }
278 289
 
279
-  function get_name() {
280
-    if (isset($this->Val['info']->Val['name.utf-8'])) {
281
-      return $this->Val['info']->Val['name.utf-8'];
282
-    } else {
283
-      return $this->Val['info']->Val['name'];
290
+    public function get_name()
291
+    {
292
+        if (isset($this->Val['info']->Val['name.utf-8'])) {
293
+            return $this->Val['info']->Val['name.utf-8'];
294
+        } else {
295
+            return $this->Val['info']->Val['name'];
296
+        }
284 297
     }
285
-  }
286 298
 
287
-  function make_private() {
288
-    //----- The following properties do not affect the infohash:
299
+    public function make_private()
300
+    {
301
+        //----- The following properties do not affect the infohash:
289 302
 
290
-    // anounce-list is an unofficial extension to the protocol
291
-    // that allows for multiple trackers per torrent
292
-    unset($this->Val['announce-list']);
303
+        // anounce-list is an unofficial extension to the protocol
304
+        // that allows for multiple trackers per torrent
305
+        unset($this->Val['announce-list']);
293 306
 
294
-    // Bitcomet & Azureus cache peers in here
295
-    unset($this->Val['nodes']);
307
+        // Bitcomet & Azureus cache peers in here
308
+        unset($this->Val['nodes']);
296 309
 
297
-    // Azureus stores the dht_backup_enable flag here
298
-    unset($this->Val['azureus_properties']);
310
+        // Azureus stores the dht_backup_enable flag here
311
+        unset($this->Val['azureus_properties']);
299 312
 
300
-    // Remove web-seeds
301
-    unset($this->Val['url-list']);
313
+        // Remove web-seeds
314
+        unset($this->Val['url-list']);
302 315
 
303
-    // Remove libtorrent resume info
304
-    unset($this->Val['libtorrent_resume']);
316
+        // Remove libtorrent resume info
317
+        unset($this->Val['libtorrent_resume']);
305 318
 
306
-    //----- End properties that do not affect the infohash
319
+        //----- End properties that do not affect the infohash
307 320
 
308
-    if (!empty($this->Val['info']->Val['private']) && $this->Val['info']->Val['private'] == '[*INT*]1') {
309
-      return true;
310
-    } else {
311
-      // Torrent is not private!
312
-      // add private tracker flag and sort info dictionary
313
-      $this->Val['info']->Val['private'] = '[*INT*]1';
314
-      ksort($this->Val['info']->Val);
315
-      return false;
321
+        if (!empty($this->Val['info']->Val['private']) && $this->Val['info']->Val['private'] == '[*INT*]1') {
322
+            return true;
323
+        } else {
324
+            // Torrent is not private!
325
+            // add private tracker flag and sort info dictionary
326
+            $this->Val['info']->Val['private'] = '[*INT*]1';
327
+            ksort($this->Val['info']->Val);
328
+            return false;
329
+        }
316 330
     }
317
-  }
318 331
 }
319
-?>

+ 14
- 11
classes/useragent.class.php View File

@@ -3,7 +3,7 @@
3 3
 class UserAgent
4 4
 {
5 5
     private static $Browsers = array(
6
-    //Less popular
6
+    // Less popular
7 7
     'Shiira'     => 'Shiira',
8 8
     'Songbird'   => 'Songbird',
9 9
     'SeaMonkey'  => 'SeaMonkey',
@@ -18,25 +18,25 @@ class UserAgent
18 18
     'libcurl'    => 'cURL',
19 19
     'midori'     => 'Midori',
20 20
     'Blackberry' => 'BlackBerry Browser',
21
-    //Big names
21
+    // Big names
22 22
     'Firefox' => 'Firefox',
23 23
     'OPR'     => 'Opera Blink', # Opera 15+ (the version running Blink)
24 24
     'Opera'   => 'Opera',
25 25
     'Chrome'  => 'Chrome',
26 26
     'Safari'  => 'Safari',
27
-    //Put Chrome Frame above IE
27
+    // Put Chrome Frame above IE
28 28
     'chromeframe' => 'Chrome Frame',
29 29
     'x-clock'     => 'Chrome Frame',
30 30
     'MSIE'        => 'Internet Explorer',
31 31
     'Trident'     => 'Internet Explorer',
32
-    //Firefox versions
32
+    // Firefox versions
33 33
     'Shiretoko'    => 'Firefox (Experimental)',
34 34
     'Minefield'    => 'Firefox (Experimental)',
35 35
     'GranParadiso' => 'Firefox (Experimental)',
36 36
     'Namoroka'     => 'Firefox (Experimental)',
37 37
     'AppleWebKit'  => 'WebKit',
38 38
     'Mozilla'      => 'Mozilla'
39
-    //Weird shit
39
+    // Weird shit
40 40
     /*
41 41
     'WWW-Mechanize' => 'Perl',
42 42
     'Wget'          => 'Wget',
@@ -48,7 +48,7 @@ class UserAgent
48 48
   );
49 49
 
50 50
     private static $OperatingSystems = array(
51
-    //Mobile
51
+    // Mobile
52 52
     'SymbianOS'    => 'Symbian',
53 53
     'blackberry'   => 'BlackBerry',
54 54
     'iphone'       => 'iPhone',
@@ -58,7 +58,7 @@ class UserAgent
58 58
     'mot-razr'     => 'Motorola Razr',
59 59
   //'tablet PC'    => 'Windows RT',
60 60
   //'ARM; Trident' => 'Windows RT',
61
-    //Windows
61
+    // Windows
62 62
     'Windows NT 10.0' => 'Windows 10',
63 63
     'Windows NT 6.4'  => 'Windows 10',
64 64
     'Windows NT 6.3'  => 'Windows 8.1',
@@ -88,11 +88,11 @@ class UserAgent
88 88
     'win16'           => 'Windows 3.1',
89 89
   //'windows'         => 'Windows',
90 90
     'cros'            => 'Chrome OS',
91
-    //OS X
91
+    // OS X
92 92
     'os x'      => 'Mac OS X',
93 93
     'macintosh' => 'Mac OS X',
94 94
     'darwin'    => 'Mac OS X',
95
-    //Less popular
95
+    // Less popular
96 96
     'ubuntu'  => 'Ubuntu',
97 97
     'debian'  => 'Debian',
98 98
     'fedora'  => 'Fedora',
@@ -105,7 +105,7 @@ class UserAgent
105 105
     'unix'    => 'Unix',
106 106
     'Sun OS'  => 'Sun',
107 107
     'Sun'     => 'Sun',
108
-    //Weird shit
108
+    // Weird shit
109 109
     /*
110 110
     'WWW-Mechanize' => 'Perl',
111 111
     'Wget'          => 'Wget',
@@ -114,7 +114,7 @@ class UserAgent
114 114
     'Java'          => 'Java',
115 115
     'RSS'           => 'RSS Downloader',
116 116
     */
117
-    //Catch-all
117
+    // Catch-all
118 118
     'win' => 'Windows',
119 119
     'mac' => 'Mac OS X'
120 120
   );
@@ -124,6 +124,7 @@ class UserAgent
124 124
         if (empty($UserAgentString)) {
125 125
             return 'Hidden';
126 126
         }
127
+
127 128
         foreach (self::$OperatingSystems as $String => $OperatingSystem) {
128 129
             if (stripos($UserAgentString, $String) !== false) {
129 130
                 return $OperatingSystem;
@@ -150,6 +151,7 @@ class UserAgent
150 151
         if (empty($UserAgentString)) {
151 152
             return 'Hidden';
152 153
         }
154
+
153 155
         $Return = 'Unknown';
154 156
         foreach (self::$Browsers as $String => $Browser) {
155 157
             if (strpos($UserAgentString, $String) !== false) {
@@ -157,6 +159,7 @@ class UserAgent
157 159
                 break;
158 160
             }
159 161
         }
162
+        
160 163
         if (self::mobile($UserAgentString)) {
161 164
             $Return .= ' Mobile';
162 165
         }

Loading…
Cancel
Save