Browse Source

Web seeds will come with OPS's bencode libraries

pjc 5 years ago
parent
commit
fb441f833f

+ 1
- 0
classes/bencode.class.php View File

1
 <?php
1
 <?php
2
+
2
 /**
3
 /**
3
  * If we're running a 32bit PHP version, we use small objects to store ints.
4
  * If we're running a 32bit PHP version, we use small objects to store ints.
4
  * Overhead from the function calls is small enough to not worry about
5
  * Overhead from the function calls is small enough to not worry about

+ 3
- 4
classes/bencodedecode.class.php View File

1
 <?php
1
 <?php
2
-
3
 /**
2
 /**
4
  * The decode class is simple and straightforward. The only thing to
3
  * The decode class is simple and straightforward. The only thing to
5
  * note is that empty dictionaries are represented by boolean trues
4
  * note is that empty dictionaries are represented by boolean trues
93
       case 'i':
92
       case 'i':
94
         $this->Pos++;
93
         $this->Pos++;
95
         $Value = substr($this->Data, $this->Pos, strpos($this->Data, 'e', $this->Pos) - $this->Pos);
94
         $Value = substr($this->Data, $this->Pos, strpos($this->Data, 'e', $this->Pos) - $this->Pos);
96
-        if (!ctype_digit($Value) && !($Value[0] === '-' && ctype_digit(substr($Value, 1)))) {
95
+        if (!ctype_digit($Value) && !($Value[0] == '-' && ctype_digit(substr($Value, 1)))) {
97
             return $this->error();
96
             return $this->error();
98
         }
97
         }
99
         $this->Pos += strlen($Value) + 1;
98
         $this->Pos += strlen($Value) + 1;
102
       case 'l':
101
       case 'l':
103
         $Value = [];
102
         $Value = [];
104
         $this->Pos++;
103
         $this->Pos++;
105
-        while ($this->Data[$this->Pos] !== 'e') {
104
+        while ($this->Data[$this->Pos] != 'e') {
106
             if ($this->Pos >= $this->Length) {
105
             if ($this->Pos >= $this->Length) {
107
                 return $this->error();
106
                 return $this->error();
108
             }
107
             }
114
       case 'd':
113
       case 'd':
115
         $Value = [];
114
         $Value = [];
116
         $this->Pos++;
115
         $this->Pos++;
117
-        while ($this->Data[$this->Pos] !== 'e') {
116
+        while ($this->Data[$this->Pos] != 'e') {
118
             $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
117
             $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
119
             if (!ctype_digit($Length)) {
118
             if (!ctype_digit($Length)) {
120
                 return $this->error();
119
                 return $this->error();

+ 2
- 20
classes/bencodetorrent.class.php View File

1
 <?php
1
 <?php
2
-
3
 /**
2
 /**
4
  * Torrent class that contains some convenient functions related to torrent meta data
3
  * Torrent class that contains some convenient functions related to torrent meta data
5
  */
4
  */
93
         if (empty($this->Dec)) {
92
         if (empty($this->Dec)) {
94
             return false;
93
             return false;
95
         }
94
         }
96
-        return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) === 1;
95
+        return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) == 1;
97
     }
96
     }
98
-    
99
     /**
97
     /**
100
      * Add the "private" flag to the torrent
98
      * Add the "private" flag to the torrent
101
      *
99
      *
125
         if (empty($this->Dec)) {
123
         if (empty($this->Dec)) {
126
             return false;
124
             return false;
127
         }
125
         }
128
-        if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] === $Sources[0] || $this->Dec['info']['source'] === $Sources[1])) {
126
+        if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
129
             return false;
127
             return false;
130
         }
128
         }
131
         $this->Dec['info']['source'] = $Sources[0];
129
         $this->Dec['info']['source'] = $Sources[0];
169
         }
167
         }
170
         return $r.'e'.substr($Data, 1);
168
         return $r.'e'.substr($Data, 1);
171
     }
169
     }
172
-
173
-    /**
174
-     * Add list of web seeds to a torrent
175
-     */
176
-    public static function add_web_seeds($Data, $Urls)
177
-    {
178
-        $r = 'd8:url-listl';
179
-        for ($i = 0; $i < count($Urls); $i++) {
180
-            $r .= 'l';
181
-            for ($j = 0; $j < count($Urls[$i]); $j++) {
182
-                $r .= strlen($Urls[$i][$j]).':'.$Urls[$i][$j];
183
-            }
184
-            $r .= 'e';
185
-        }
186
-        return $r.'e'.substr($Data, 1);
187
-    }
188
 }
170
 }

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

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

+ 2
- 2
classes/torrents.class.php View File

2
 
2
 
3
 class Torrents
3
 class Torrents
4
 {
4
 {
5
-  const FILELIST_DELIM = 0xF7; // Hex for &divide; Must be the same as phrase_boundary in sphinx.conf!
5
+    const FILELIST_DELIM = 0xF7; // Hex for &divide; Must be the same as phrase_boundary in sphinx.conf!
6
   const SNATCHED_UPDATE_INTERVAL = 3600; // How often we want to update users' snatch lists
6
   const SNATCHED_UPDATE_INTERVAL = 3600; // How often we want to update users' snatch lists
7
   const SNATCHED_UPDATE_AFTERDL = 300; // How long after a torrent download we want to update a user's snatch lists
7
   const SNATCHED_UPDATE_AFTERDL = 300; // How long after a torrent download we want to update a user's snatch lists
8
 
8
 
1230
         return $EditionName;
1230
         return $EditionName;
1231
     }
1231
     }
1232
 
1232
 
1233
-    //Used to get reports info on a unison cache in both browsing pages and torrent pages.
1233
+    // Used to get reports info on a unison cache in both browsing pages and torrent pages.
1234
     public static function get_reports($TorrentID)
1234
     public static function get_reports($TorrentID)
1235
     {
1235
     {
1236
         $Reports = G::$Cache->get_value("reports_torrent_$TorrentID");
1236
         $Reports = G::$Cache->get_value("reports_torrent_$TorrentID");

+ 7
- 28
classes/torrentsdl.class.php View File

1
 <?php
1
 <?php
2
-
3
 /**
2
 /**
4
  * Class for functions related to the features involving torrent downloads
3
  * Class for functions related to the features involving torrent downloads
5
  */
4
  */
19
     private $User;
18
     private $User;
20
     private $AnnounceURL;
19
     private $AnnounceURL;
21
     private $AnnounceList;
20
     private $AnnounceList;
22
-    private $WebSeeds;
23
 
21
 
24
     /**
22
     /**
25
      * Create a Zip object and store the query results
23
      * Create a Zip object and store the query results
31
     public function __construct(&$QueryResult, $Title)
29
     public function __construct(&$QueryResult, $Title)
32
     {
30
     {
33
         G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
31
         G::$Cache->InternalCache = false; // The internal cache is almost completely useless for this
34
-        Zip::unlimit(); // Need more memory and longer timeout
35
-        $this->QueryResult = $QueryResult;
32
+    Zip::unlimit(); // Need more memory and longer timeout
33
+    $this->QueryResult = $QueryResult;
36
         $this->Title = $Title;
34
         $this->Title = $Title;
37
         $this->User = G::$LoggedUser;
35
         $this->User = G::$LoggedUser;
38
-        $this->AnnounceURL = ANNOUNCE_URLS[0][0].'/'.G::$LoggedUser['torrent_pass'].'/announce';
39
-
36
+        $this->AnnounceURL = ANNOUNCE_URLS[0][0]."/".G::$LoggedUser['torrent_pass']."/announce";
40
         function add_passkey($Ann)
37
         function add_passkey($Ann)
41
         {
38
         {
42
-            return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann.'/'.G::$LoggedUser['torrent_pass'].'/announce';
39
+            return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann."/".G::$LoggedUser['torrent_pass']."/announce";
43
         }
40
         }
44
-
45
         $this->AnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
41
         $this->AnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
46
-        #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
47
-        $this->WebSeeds = [];
42
+        #$this->AnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
48
         $this->Zip = new Zip(Misc::file_string($Title));
43
         $this->Zip = new Zip(Misc::file_string($Title));
49
     }
44
     }
50
 
45
 
241
      * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format)
236
      * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format)
242
      * @return bencoded string
237
      * @return bencoded string
243
      */
238
      */
244
-    public static function get_file(&$TorrentData, $AnnounceURL, $AnnounceList = [], $WebSeeds = [])
239
+    public static function get_file(&$TorrentData, $AnnounceURL, $AnnounceList = [])
245
     {
240
     {
246
         if (Misc::is_new_torrent($TorrentData)) {
241
         if (Misc::is_new_torrent($TorrentData)) {
247
             $Bencode = BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL);
242
             $Bencode = BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL);
248
-
249
-            # Announce list
250
             if (!empty($AnnounceList)) {
243
             if (!empty($AnnounceList)) {
251
                 $Bencode = BencodeTorrent::add_announce_list($Bencode, $AnnounceList);
244
                 $Bencode = BencodeTorrent::add_announce_list($Bencode, $AnnounceList);
252
             }
245
             }
253
-
254
-            # Web seeds
255
-            if (!empty($WebSeeds)) {
256
-                $Bencode = BencodeTorrent::add_web_seeds($Bencode, $WebSeeds);
257
-            }
258
             return $Bencode;
246
             return $Bencode;
259
         }
247
         }
260
-
261
         $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
248
         $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
262
         $Tor->set_announce_url($AnnounceURL);
249
         $Tor->set_announce_url($AnnounceURL);
263
         unset($Tor->Val['announce-list']);
250
         unset($Tor->Val['announce-list']);
264
-
265
-        # Announce list
266
         if (!empty($AnnounceList)) {
251
         if (!empty($AnnounceList)) {
267
             $Tor->set_announce_list($AnnounceList);
252
             $Tor->set_announce_list($AnnounceList);
268
         }
253
         }
269
-
270
-        # Web seeds
271
-        if (!empty($WebSeeds)) {
272
-            $Tor->add_web_seeds($WebSeeds);
273
-        }
274
-        
275
-        #unset($Tor->Val['url-list']);
254
+        unset($Tor->Val['url-list']);
276
         unset($Tor->Val['libtorrent_resume']);
255
         unset($Tor->Val['libtorrent_resume']);
277
         return $Tor->enc();
256
         return $Tor->enc();
278
     }
257
     }

+ 2
- 2
sections/requests/new_edit.php View File

121
       <!-- Main table -->
121
       <!-- Main table -->
122
       <table class="layout">
122
       <table class="layout">
123
         <tr>
123
         <tr>
124
-          <td colspan="2" class="center">Please make sure your request follows <a href="rules.php?p=requests">the
125
-              request rules</a>!</td>
124
+          <td colspan="2" class="center">Please make sure your request follows the
125
+            <a href="rules.php?p=requests">request rules</a>!</td>
126
         </tr>
126
         </tr>
127
         <?php  if ($NewRequest || $CanEdit) { ?>
127
         <?php  if ($NewRequest || $CanEdit) { ?>
128
 
128
 

+ 2
- 2
sections/torrents/browse.php View File

250
             <td class="nobr ft_ripspecifics">
250
             <td class="nobr ft_ripspecifics">
251
 
251
 
252
               <select name="media" class="ft_media fti_advanced">
252
               <select name="media" class="ft_media fti_advanced">
253
-                <option value="">DNA/RNA/Proteins</option>
253
+                <option value="">Sequencing</option>
254
                 <?php  foreach ($Media as $MediaName) { ?>
254
                 <?php  foreach ($Media as $MediaName) { ?>
255
                 <option value="<?=display_str($MediaName); ?>"
255
                 <option value="<?=display_str($MediaName); ?>"
256
                 <?Format::selected('media', $MediaName)?>><?=display_str($MediaName); ?>
256
                 <?Format::selected('media', $MediaName)?>><?=display_str($MediaName); ?>
318
                 <option value="">Assembly Level</option>
318
                 <option value="">Assembly Level</option>
319
                 <?php  foreach ($Resolutions as $Resolution) { ?>
319
                 <?php  foreach ($Resolutions as $Resolution) { ?>
320
                 <option value="<?=display_str($Resolution); ?>"
320
                 <option value="<?=display_str($Resolution); ?>"
321
-                <?Format::selected('resolution', $Resolution)?>><?=display_str($Resolution); ?>"
321
+                <?Format::selected('resolution', $Resolution)?>><?=display_str($Resolution); ?>
322
                 </option>
322
                 </option>
323
                 <?php  } ?>
323
                 <?php  } ?>
324
               </select>
324
               </select>

+ 4
- 3
sections/torrents/details.php View File

1
 <?php
1
 <?php
2
+
2
 function compare($X, $Y)
3
 function compare($X, $Y)
3
 {
4
 {
4
     return($Y['name'] < $X['name']);
5
     return($Y['name'] < $X['name']);
964
       </div>
965
       </div>
965
     </div>
966
     </div>
966
 
967
 
967
-        <!-- Mirrors -->
968
-        <div class="box torrent_mirrors_box <?php if (!count($Mirrors)) {
968
+    <!-- Mirrors -->
969
+    <div class="box torrent_mirrors_box <?php if (!count($Mirrors)) {
969
     echo 'dead';
970
     echo 'dead';
970
 } ?>">
971
 } ?>">
971
       <div class="head"><a href="#">&uarr;</a>&nbsp;<strong>
972
       <div class="head"><a href="#">&uarr;</a>&nbsp;<strong>
972
-      Mirrors (<?= count($Mirrors) ?>)</strong>
973
+          Mirrors (<?= count($Mirrors) ?>)</strong>
973
         <?php
974
         <?php
974
     if (count($Mirrors) > 0) {
975
     if (count($Mirrors) > 0) {
975
         ?>
976
         ?>

+ 26
- 36
sections/torrents/download.php View File

13
     $UserInfo = $Cache->get_value('user_'.$_REQUEST['torrent_pass']);
13
     $UserInfo = $Cache->get_value('user_'.$_REQUEST['torrent_pass']);
14
     if (!is_array($UserInfo)) {
14
     if (!is_array($UserInfo)) {
15
         $DB->query("
15
         $DB->query("
16
-        SELECT ID, la.UserID
17
-          FROM users_main AS m
16
+      SELECT ID, la.UserID
17
+      FROM users_main AS m
18
         INNER JOIN users_info AS i ON i.UserID = m.ID
18
         INNER JOIN users_info AS i ON i.UserID = m.ID
19
         LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
19
         LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
20
-          WHERE m.torrent_pass = '".db_string($_REQUEST['torrent_pass'])."'
21
-          AND m.Enabled = '1'");
20
+      WHERE m.torrent_pass = '".db_string($_REQUEST['torrent_pass'])."'
21
+        AND m.Enabled = '1'");
22
         $UserInfo = $DB->next_record();
22
         $UserInfo = $DB->next_record();
23
         $Cache->cache_value('user_'.$_REQUEST['torrent_pass'], $UserInfo, 3600);
23
         $Cache->cache_value('user_'.$_REQUEST['torrent_pass'], $UserInfo, 3600);
24
     }
24
     }
25
-
26
     $UserInfo = array($UserInfo);
25
     $UserInfo = array($UserInfo);
27
     list($UserID, $Locked) = array_shift($UserInfo);
26
     list($UserID, $Locked) = array_shift($UserInfo);
28
     if (!$UserID) {
27
     if (!$UserID) {
29
         error(0);
28
         error(0);
30
     }
29
     }
31
-
32
     $TorrentPass = $_REQUEST['torrent_pass'];
30
     $TorrentPass = $_REQUEST['torrent_pass'];
33
     $AuthKey = $_REQUEST['authkey'];
31
     $AuthKey = $_REQUEST['authkey'];
34
 
32
 
35
-    if ($Locked === $UserID) {
33
+    if ($Locked == $UserID) {
36
         header('HTTP/1.1 403 Forbidden');
34
         header('HTTP/1.1 403 Forbidden');
37
         die();
35
         die();
38
     }
36
     }
39
 }
37
 }
40
 
38
 
41
 $TorrentID = $_REQUEST['id'];
39
 $TorrentID = $_REQUEST['id'];
40
+
42
 if (!is_number($TorrentID)) {
41
 if (!is_number($TorrentID)) {
43
     error(0);
42
     error(0);
44
 }
43
 }
45
 
44
 
46
 /*
45
 /*
47
- * uTorrent Remote and various scripts redownload .torrent files periodically.
48
- * To prevent this retardation from blowing bandwidth etc., let's block it
49
- * if the .torrent file has been downloaded four times before
50
-*/
46
+  uTorrent Remote and various scripts redownload .torrent files periodically.
47
+  To prevent this retardation from blowing bandwidth etc., let's block it
48
+  if the .torrent file has been downloaded four times before
49
+ */
51
 $ScriptUAs = array('BTWebClient*', 'Python-urllib*', 'python-requests*');
50
 $ScriptUAs = array('BTWebClient*', 'Python-urllib*', 'python-requests*');
52
 if (Misc::in_array_partial($_SERVER['HTTP_USER_AGENT'], $ScriptUAs)) {
51
 if (Misc::in_array_partial($_SERVER['HTTP_USER_AGENT'], $ScriptUAs)) {
53
     $DB->query("
52
     $DB->query("
56
     WHERE UserID = $UserID
55
     WHERE UserID = $UserID
57
       AND TorrentID = $TorrentID
56
       AND TorrentID = $TorrentID
58
     LIMIT 4");
57
     LIMIT 4");
59
-
60
     if ($DB->record_count() === 4) {
58
     if ($DB->record_count() === 4) {
61
         error('You have already downloaded this torrent file four times. If you need to download it again, please do so from your browser.', true);
59
         error('You have already downloaded this torrent file four times. If you need to download it again, please do so from your browser.', true);
62
         die();
60
         die();
75
       COALESCE(NULLIF(tg.Name,''), NULLIF(tg.NameRJ,''), tg.NameJP) AS Name,
73
       COALESCE(NULLIF(tg.Name,''), NULLIF(tg.NameRJ,''), tg.NameJP) AS Name,
76
       tg.WikiImage,
74
       tg.WikiImage,
77
       tg.CategoryID,
75
       tg.CategoryID,
78
-      tm.Resource,
79
       t.Size,
76
       t.Size,
80
       t.FreeTorrent,
77
       t.FreeTorrent,
81
       HEX(t.info_hash)
78
       HEX(t.info_hash)
82
     FROM torrents AS t
79
     FROM torrents AS t
83
       INNER JOIN torrents_group AS tg ON tg.ID = t.GroupID
80
       INNER JOIN torrents_group AS tg ON tg.ID = t.GroupID
84
-      LEFT JOIN torrents_mirrors AS tm ON tm.ID = t.GroupID
85
     WHERE t.ID = '".db_string($TorrentID)."'");
81
     WHERE t.ID = '".db_string($TorrentID)."'");
86
-
87
     if (!$DB->has_results()) {
82
     if (!$DB->has_results()) {
88
         error(404);
83
         error(404);
89
     }
84
     }
90
-
91
     $Info = array($DB->next_record(MYSQLI_NUM, array(4, 5, 6, 10)));
85
     $Info = array($DB->next_record(MYSQLI_NUM, array(4, 5, 6, 10)));
92
     $Artists = Artists::get_artist($Info[0][4], false);
86
     $Artists = Artists::get_artist($Info[0][4], false);
93
     $Info['Artists'] = Artists::display_artists($Artists, false, true);
87
     $Info['Artists'] = Artists::display_artists($Artists, false, true);
94
     $Info['PlainArtists'] = Artists::display_artists($Artists, false, true, false);
88
     $Info['PlainArtists'] = Artists::display_artists($Artists, false, true, false);
95
     $Cache->cache_value("torrent_download_$TorrentID", $Info, 0);
89
     $Cache->cache_value("torrent_download_$TorrentID", $Info, 0);
96
 }
90
 }
97
-
98
 if (!is_array($Info[0])) {
91
 if (!is_array($Info[0])) {
99
     error(404);
92
     error(404);
100
 }
93
 }
101
-
102
-list($Media, $Format, $Encoding, $Year, $GroupID, $Name, $Image, $CategoryID, $Resources, $Size, $FreeTorrent, $InfoHash) = array_shift($Info); // Used for generating the filename
94
+list($Media, $Format, $Encoding, $Year, $GroupID, $Name, $Image, $CategoryID, $Size, $FreeTorrent, $InfoHash) = array_shift($Info); // used for generating the filename
103
 $Artists = $Info['Artists'];
95
 $Artists = $Info['Artists'];
104
 
96
 
105
 // If he's trying use a token on this, we need to make sure he has one,
97
 // If he's trying use a token on this, we need to make sure he has one,
106
 // deduct it, add this to the FLs table, and update his cache key.
98
 // deduct it, add this to the FLs table, and update his cache key.
107
-// todo: Make sure strict equality works
108
 if ($_REQUEST['usetoken'] && $FreeTorrent == '0') {
99
 if ($_REQUEST['usetoken'] && $FreeTorrent == '0') {
109
     if (isset($LoggedUser)) {
100
     if (isset($LoggedUser)) {
110
         $FLTokens = $LoggedUser['FLTokens'];
101
         $FLTokens = $LoggedUser['FLTokens'];
135
 
126
 
136
         if (!Torrents::has_token($TorrentID)) {
127
         if (!Torrents::has_token($TorrentID)) {
137
             $DB->query("
128
             $DB->query("
138
-            INSERT INTO users_freeleeches (UserID, TorrentID, Time)
139
-            VALUES ($UserID, $TorrentID, NOW())
140
-            ON DUPLICATE KEY UPDATE
141
-              Time = VALUES(Time),
142
-              Expired = FALSE,
143
-              Uses = Uses + 1");
129
+        INSERT INTO users_freeleeches (UserID, TorrentID, Time)
130
+        VALUES ($UserID, $TorrentID, NOW())
131
+        ON DUPLICATE KEY UPDATE
132
+          Time = VALUES(Time),
133
+          Expired = FALSE,
134
+          Uses = Uses + 1");
144
             $DB->query("
135
             $DB->query("
145
-            UPDATE users_main
146
-            SET FLTokens = FLTokens - 1
147
-            WHERE ID = $UserID");
136
+        UPDATE users_main
137
+        SET FLTokens = FLTokens - 1
138
+        WHERE ID = $UserID");
148
 
139
 
149
             // Fix for downloadthemall messing with the cached token count
140
             // Fix for downloadthemall messing with the cached token count
150
             $UInfo = Users::user_heavy_info($UserID);
141
             $UInfo = Users::user_heavy_info($UserID);
159
     }
150
     }
160
 }
151
 }
161
 
152
 
162
-// Stupid Recent Snatches on User Page
153
+// Stupid Recent Snatches On User Page
163
 if ($Image != '') {
154
 if ($Image != '') {
164
     $RecentSnatches = $Cache->get_value("recent_snatches_$UserID");
155
     $RecentSnatches = $Cache->get_value("recent_snatches_$UserID");
165
     if (!empty($RecentSnatches)) {
156
     if (!empty($RecentSnatches)) {
191
 header('Content-Type: application/x-bittorrent; charset=utf-8');
182
 header('Content-Type: application/x-bittorrent; charset=utf-8');
192
 header('Content-disposition: attachment; filename="'.$FileName.'"');
183
 header('Content-disposition: attachment; filename="'.$FileName.'"');
193
 
184
 
194
-function add_passkey($Ann)
185
+function add_passkey($ann)
195
 {
186
 {
196
     global $TorrentPass;
187
     global $TorrentPass;
197
-    return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann.'/'.$TorrentPass.'/announce';
188
+    return (is_array($ann)) ? array_map("add_passkey", $ann) : $ann."/".$TorrentPass."/announce";
198
 }
189
 }
199
-
200
-$UserAnnounceURL = ANNOUNCE_URLS[0][0].'/'.$TorrentPass.'/announce';
190
+$UserAnnounceURL = ANNOUNCE_URLS[0][0]."/".$TorrentPass."/announce";
201
 $UserAnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
191
 $UserAnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
202
-#$UserAnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
192
+#$UserAnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map("add_passkey", ANNOUNCE_URLS);
203
 
193
 
204
-echo TorrentsDL::get_file($Contents, $UserAnnounceURL, $UserAnnounceList, $Resources);
194
+echo TorrentsDL::get_file($Contents, $UserAnnounceURL, $UserAnnounceList);
205
 
195
 
206
 define('SKIP_NO_CACHE_HEADERS', 1);
196
 define('SKIP_NO_CACHE_HEADERS', 1);

Loading…
Cancel
Save