Browse Source

Put magnet links behind a user setting

spaghetti 8 years ago
parent
commit
785d4c17f6

+ 13
- 5
sections/artist/artist.php View File

@@ -279,16 +279,20 @@ foreach ($TorrentList as $Group) {
279 279
 
280 280
       $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : '';
281 281
       $TorrentDL = "torrents.php?action=download&id=".$TorrentID."&authkey=".$LoggedUser['AuthKey']."&torrent_pass=".$LoggedUser['torrent_pass'];
282
-      $TorrentMG = "magnet:?xt=urn:btih:".$Torrent['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Torrent['Size'];
282
+      if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
283
+        $TorrentMG = "magnet:?xt=urn:btih:".$Torrent['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Torrent['Size'];
284
+      }
283 285
 ?>
284 286
     <tr class="torrent_row groupid_<?=$GroupID?> group_torrent discog<?=$SnatchedTorrentClass . $SnatchedGroupClass . $HideTorrents?>">
285 287
       <td colspan="2">
286 288
           <span>
287 289
           [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download">DL</a>
290
+<?  if (isset($TorrentMG)) { ?>
288 291
           | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
289
-<? if (Torrents::can_use_token($Torrent)) { ?>
292
+<?  }
293
+    if (Torrents::can_use_token($Torrent)) { ?>
290 294
           | <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
291
-<?    } ?>
295
+<?  } ?>
292 296
           | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
293 297
         </span>
294 298
         &nbsp;&nbsp;&raquo;&nbsp; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Torrent)?></a>
@@ -349,7 +353,9 @@ foreach ($TorrentList as $Group) {
349 353
     $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : '';
350 354
 
351 355
     $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
352
-    $TorrentMG = "magnet:?xt=urn:btih:".$Torrent['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Torrent['Size'];
356
+    if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
357
+      $TorrentMG = "magnet:?xt=urn:btih:".$Torrent['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Torrent['Size'];
358
+    }
353 359
 
354 360
 ?>
355 361
     <tr class="torrent<?=$SnatchedTorrentClass . $SnatchedGroupClass?>">
@@ -360,8 +366,10 @@ foreach ($TorrentList as $Group) {
360 366
           <div class="float_right">
361 367
             <span>
362 368
             [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download">DL</a>
369
+<?  if (isset($TorrentMG)) { ?>
363 370
             | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
364
-<? if (Torrents::can_use_token($Torrent)) { ?>
371
+<?  }
372
+    if (Torrents::can_use_token($Torrent)) { ?>
365 373
             | <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
366 374
 <?    } ?>
367 375
             | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]

+ 24
- 14
sections/torrents/browse.php View File

@@ -596,21 +596,26 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
596 596
 
597 597
       $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
598 598
       $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
599
-      if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
600
-        $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
601
-        $Tor = new BencodeTorrent($TorrentFile);
602
-        $TorrentFileName = $Tor->Dec['info']['name'];
603
-        $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
599
+
600
+      if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
601
+        if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
602
+          $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
603
+          $Tor = new BencodeTorrent($TorrentFile);
604
+          $TorrentFileName = $Tor->Dec['info']['name'];
605
+          $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
606
+        }
607
+        $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
604 608
       }
605
-      $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
606 609
 
607 610
 ?>
608 611
   <tr class="group_torrent groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass . (!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1 ? ' hidden' : '')?>">
609 612
     <td colspan="3">
610 613
       <span>
611 614
         [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download"><?=$Data['HasFile'] ? 'DL' : 'Missing'?></a>
615
+<?      if (isset($TorrentMG)) { ?>
612 616
         | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
613
-<?      if (Torrents::can_use_token($Data)) { ?>
617
+<?      }
618
+        if (Torrents::can_use_token($Data)) { ?>
614 619
         | <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
615 620
 <?      } ?>
616 621
         | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
@@ -668,13 +673,16 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
668 673
     }
669 674
     $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
670 675
     $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
671
-    if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
672
-      $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
673
-      $Tor = new BencodeTorrent($TorrentFile);
674
-      $TorrentFileName = $Tor->Dec['info']['name'];
675
-      $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
676
+
677
+    if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
678
+      if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
679
+        $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
680
+        $Tor = new BencodeTorrent($TorrentFile);
681
+        $TorrentFileName = $Tor->Dec['info']['name'];
682
+        $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
683
+      }
684
+      $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
676 685
     }
677
-    $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
678 686
 ?>
679 687
   <tr class="torrent<?=$SnatchedTorrentClass . $SnatchedGroupClass?>">
680 688
 <?    if ($GroupResults) { ?>
@@ -688,8 +696,10 @@ $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGr
688 696
         <div class="float_right">
689 697
           <span>
690 698
           [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download">DL</a>
699
+<?    if (isset($TorrentMG)) { ?>
691 700
           | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
692
-<?    if (Torrents::can_use_token($Data)) { ?>
701
+<?    }
702
+      if (Torrents::can_use_token($Data)) { ?>
693 703
           | <a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
694 704
 <?    } ?>
695 705
           | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]

+ 11
- 7
sections/torrents/details.php View File

@@ -532,20 +532,24 @@ foreach ($TorrentList as $Torrent) {
532 532
   if (!empty($BadFiles)) { $ExtraInfo.=$AddExtra. Format::torrent_label('Bad File Names'); $AddExtra=' / '; }
533 533
 
534 534
   $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
535
-  if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
536
-    $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
537
-    $Tor = new BencodeTorrent($TorrentFile);
538
-    $TorrentFileName = $Tor->Dec['info']['name'];
539
-    $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
535
+  if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
536
+    if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
537
+      $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
538
+      $Tor = new BencodeTorrent($TorrentFile);
539
+      $TorrentFileName = $Tor->Dec['info']['name'];
540
+      $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
541
+    }
542
+    $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$InfoHash."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Size;
540 543
   }
541
-  $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$InfoHash."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Size;
542 544
 ?>
543 545
 
544 546
       <tr class="torrent_row groupid_<?=$GroupID?> group_torrent<?=($IsSnatched ? ' snatched_torrent' : '')?>" style="font-weight: normal;" id="torrent<?=$TorrentID?>">
545 547
         <td>
546 548
           <span>[ <a href="<?=$TorrentDL?>" class="tooltip" title="Download"><?=($HasFile ? 'DL' : 'Missing')?></a>
549
+<?  if (isset($TorrentMG)) { ?>
547 550
             | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
548
-<?  if (Torrents::can_use_token($Torrent)) { ?>
551
+<?  }
552
+    if (Torrents::can_use_token($Torrent)) { ?>
549 553
             | <a href="torrents.php?action=download&amp;id=<?=$TorrentID ?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1" class="tooltip" title="Use a FL Token" onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
550 554
 <?  } ?>
551 555
             | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a>

+ 7
- 0
sections/user/edit.php View File

@@ -250,6 +250,13 @@ echo $Val->GenerateJS('userform');
250 250
           <label for="showsnatched">Enable snatched torrents indicator</label>
251 251
         </td>
252 252
       </tr>
253
+      <tr id="tor_magnet_tr">
254
+        <td class="label tooltip" title="Magnet links should only be used on clients with DHT disabled globally"><strong>Magnet links</strong></td>
255
+        <td>
256
+          <input type="checkbox" name="showmagnets" id="showmagnets"<?=!empty($SiteOptions['ShowMagnets']) ? ' checked="checked"' : '' ?> />
257
+          <label for="showmagnets">Show magnet links</label>
258
+        </td>
259
+      </tr>
253 260
 <? /* ?>
254 261
       <tr>
255 262
         <td class="label"><strong>Collage album art view</strong></td>

+ 1
- 0
sections/user/take_edit.php View File

@@ -271,6 +271,7 @@ $Options['DisablePMAvatars']    = (!empty($_POST['disablepmavatars']) ? 1 : 0);
271 271
 $Options['NotifyOnQuote']       = (!empty($_POST['notifications_Quotes_popup']) ? 1 : 0);
272 272
 $Options['ListUnreadPMsFirst']  = (!empty($_POST['list_unread_pms_first']) ? 1 : 0);
273 273
 $Options['ShowSnatched']        = (!empty($_POST['showsnatched']) ? 1 : 0);
274
+$Options['ShowMagnets']         = (!empty($_POST['showmagnets']) ? 1 : 0);
274 275
 $Options['DisableAutoSave']     = (!empty($_POST['disableautosave']) ? 1 : 0);
275 276
 $Options['NoVoteLinks']         = (!empty($_POST['novotelinks']) ? 1 : 0);
276 277
 $Options['CoverArt']            = (int)!empty($_POST['coverart']);

Loading…
Cancel
Save