Browse Source

Don't abort page creation if magnet link fails to generate

spaghetti 7 years ago
parent
commit
bdbbbc17bb
3 changed files with 14 additions and 11 deletions
  1. 10
    7
      classes/bencodedecode.class.php
  2. 2
    2
      sections/torrents/browse.php
  3. 2
    2
      sections/torrents/takedelete.php

+ 10
- 7
classes/bencodedecode.class.php View File

18
    * @param bool $IsPath needs to be true if $Arg is a path
18
    * @param bool $IsPath needs to be true if $Arg is a path
19
    * @return decoded data with a suitable structure
19
    * @return decoded data with a suitable structure
20
    */
20
    */
21
-  function __construct($Arg = false, $IsPath = false) {
21
+  function __construct($Arg = false, $IsPath = false, $Strict = true) {
22
+    if (!$Strict) {
23
+      $this->ExitOnError = false;
24
+    }
22
     if ($Arg === false) {
25
     if ($Arg === false) {
23
       if (empty($this->Enc)) {
26
       if (empty($this->Enc)) {
24
         return false;
27
         return false;
169
       // The recursive nature of the class requires this to avoid duplicate error messages
172
       // The recursive nature of the class requires this to avoid duplicate error messages
170
       return false;
173
       return false;
171
     }
174
     }
172
-    if ($ErrMsg === false) {
173
-      printf("Malformed string. Invalid character at pos 0x%X: %s\n",
174
-          $this->Pos, str_replace(array("\r","\n"), array('',' '), htmlentities(substr($this->Data, $this->Pos, self::SnipLength))));
175
-    } else {
176
-      echo $ErrMsg;
177
-    }
178
     if ($this->ExitOnError) {
175
     if ($this->ExitOnError) {
176
+      if ($ErrMsg === false) {
177
+        printf("Malformed string. Invalid character at pos 0x%X: %s\n",
178
+            $this->Pos, str_replace(array("\r","\n"), array('',' '), htmlentities(substr($this->Data, $this->Pos, self::SnipLength))));
179
+      } else {
180
+        echo $ErrMsg;
181
+      }
179
       exit();
182
       exit();
180
     }
183
     }
181
     $ErrorPos = $this->Pos;
184
     $ErrorPos = $this->Pos;

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

596
       if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
596
       if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
597
         if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
597
         if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
598
           $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
598
           $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
599
-          $Tor = new BencodeTorrent($TorrentFile);
599
+          $Tor = new BencodeTorrent($TorrentFile, false, false);
600
           $TorrentFileName = $Tor->Dec['info']['name'];
600
           $TorrentFileName = $Tor->Dec['info']['name'];
601
           $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
601
           $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
602
         }
602
         }
674
     if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
674
     if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
675
       if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
675
       if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
676
         $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
676
         $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
677
-        $Tor = new BencodeTorrent($TorrentFile);
677
+        $Tor = new BencodeTorrent($TorrentFile, false, false);
678
         $TorrentFileName = $Tor->Dec['info']['name'];
678
         $TorrentFileName = $Tor->Dec['info']['name'];
679
         $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
679
         $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
680
       }
680
       }

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

26
     LEFT JOIN artists_group AS ag ON ag.ArtistID = ta.ArtistID
26
     LEFT JOIN artists_group AS ag ON ag.ArtistID = ta.ArtistID
27
     LEFT JOIN xbt_snatched AS x ON x.fid = t.ID
27
     LEFT JOIN xbt_snatched AS x ON x.fid = t.ID
28
   WHERE t.ID = '$TorrentID'");
28
   WHERE t.ID = '$TorrentID'");
29
-list($UserID, $GroupID, $Size, $InfoHash, $Name, $ArtistName, $Time, $Snatches) = $DB->next_record(MYSQLI_NUM, false);
29
+list($UploaderID, $GroupID, $Size, $InfoHash, $Name, $ArtistName, $Time, $Snatches) = $DB->next_record(MYSQLI_NUM, false);
30
 
30
 
31
-if ($LoggedUser['ID'] != $UserID && !check_perms('torrents_delete')) {
31
+if ($LoggedUser['ID'] != $UploaderID && !check_perms('torrents_delete')) {
32
   error(403);
32
   error(403);
33
 }
33
 }
34
 
34
 

Loading…
Cancel
Save