За последние 24 часа нас посетили 17985 программистов и 1624 робота. Сейчас ищут 846 программистов ...

Помогите с class_torrent.php

Тема в разделе "Прочие вопросы по PHP", создана пользователем Ruffneck, 14 фев 2014.

  1. Ruffneck

    Ruffneck Новичок

    С нами с:
    14 фев 2014
    Сообщения:
    4
    Симпатии:
    0
    есть 2 скрипта upload.php и class_torrent.php

    постооянно выскакивает ошибка An error has occured!: Could not find info dictionary

    upload.php

    Код (Text):
    1. <?php
    2. /**
    3. *
    4. * @ iDezender 7.0
    5. * @ Developed by Qarizma
    6. *
    7. * @ Visit our website:
    8. * @ www.iRadikal.com
    9. * @ For cheap decoding service :)
    10. * @ And for the ionCube Decoder!
    11. *
    12. */
    13. function TS_Match($string, $find) {
    14.         return (strpos( $string, $find ) === false ? false : true);
    15.     }
    16.  
    17.     function TS_Global($name = '') {
    18.         return (isset( $_GET['' . $name] ) ? (!is_array( $_GET['' . $name] ) ? trim( $_GET['' . $name] ) : $_GET['' . $name]) : (isset( $_POST['' . $name] ) ? (!is_array( $_POST['' . $name] ) ? trim( $_POST['' . $name] ) : $_POST['' . $name]) : ''));
    19.     }
    20.    
    21.     function show_upload_errors()
    22.     {
    23.         global $UploadErrors;
    24.         global $lang;
    25.         global $BASEURL;
    26.         global $pic_base_url;
    27.  
    28.         if (0 < count( $UploadErrors ))
    29.         {
    30.             $Errors = '';
    31.             foreach ($UploadErrors as $Error) {
    32.                 $Errors .= '<img src="' . $pic_base_url . 'error.gif" border="0" alt="" title="" /> ' . $Error . '<br />';
    33.             }
    34.  
    35.             echo show_notice( $Errors, 1, $lang->upload['error'] );
    36.             unset( $Errors );
    37.         }
    38.  
    39.     }
    40.  
    41.     define( 'TU_VERSION', '3.0.7 by xam' );
    42.     define( 'THIS_SCRIPT', 'upload.php' );
    43.     require( './global.php' );
    44.    
    45.   require_once INC_PATH . '/class_language.php';
    46.   $lang = new trackerlanguage ();
    47.   $lang->set_path (INC_PATH . '/languages');
    48.   if ((empty ($_COOKIE['ts_language']) OR !file_exists (INC_PATH . '/languages/' . $_COOKIE['ts_language'])))
    49.   {
    50.     $lang->set_language ($defaultlanguage);
    51.   }
    52.   else
    53.   {
    54.     $lang->set_language ($_COOKIE['ts_language']);
    55.   }
    56.   $lang->load ('global');
    57.  
    58.     if (!isset( $CURUSER )) {
    59.         print_no_permission(  );
    60.     }
    61.  
    62.     @ini_set( 'upload_max_filesize', (1000 < $max_torrent_size ? $max_torrent_size : 10485760) );
    63.     @ini_set( 'memory_limit', '20000M' );
    64.     $lang->load( 'upload' );
    65.    
    66.     require_once( INC_PATH . '/editor.php' );
    67.    
    68.     $is_mod = is_mod($usergroups);
    69.  
    70.     $announce_urls = array ();
    71.     $announce_urls[] = 'http://' . $_SERVER['HTTP_HOST'] . '/announce.php';
    72.     $externalscrape = 'yes';
    73.     $use_torrent_details = 'no';
    74.     $xbt_active = 'no';
    75.     $search_before_upload = 'no';
    76.    
    77.     $ModerateTorrent = ($usergroups['canupload'] == 'moderate' ? true : false);
    78.     $CanUploadExternalTorrent = (( $usergroups['canexternal'] == 'yes' AND $externalscrape == 'yes' ) ? true : false);
    79.     $AnnounceURL = trim( ($xbt_active == 'yes' ? $xbt_announce_url . '/' . $CURUSER['passkey'] . '/announce' : $announce_urls['0'] . '?passkey=' . $CURUSER['passkey']) );
    80.     $postoptions = '';
    81.     $postoptionstitle = '';
    82.     $UploadErrors = array(  );
    83.  
    84.     if (( isset( $_GET['id'] ) AND is_valid_id( $_GET['id'] ) ))
    85.     {
    86.         if ($EditTorrentID = intval( TS_Global( 'id' ) ))
    87.         {
    88.             $Query = $db->sql_query( 'SELECT * FROM torrents WHERE id = ' . $db->sqlesc( $EditTorrentID ) );
    89.  
    90.             if ($db->num_rows( $Query )) {
    91.                 $EditTorrent = mysqli_fetch_assoc( $Query );
    92.  
    93.                 if (( $EditTorrent['owner'] != $CURUSER['id'] AND !$is_mod ))
    94.                 {
    95.                     print_no_permission( true );
    96.                 }
    97.  
    98.                 $name = $EditTorrent['name'];
    99.                 $descr = $EditTorrent['descr'];
    100.                 $IsExternalTorrent = (( $EditTorrent['ts_external'] == 'yes' AND $CanUploadExternalTorrent ) ? true : false);
    101.                 $category = intval( $EditTorrent['category'] );
    102.                 $t_image_url = $EditTorrent['t_image'];
    103.                 $t_link = $EditTorrent['t_link'];
    104.  
    105.                 if (( $t_link AND preg_match( '@http:\/\/www.imdb.com\/title\/(.*)\/@isU', $t_link, $result ) ))
    106.                 {
    107.                     $t_link = $result['0'];
    108.                     unset( $result );
    109.                 }
    110.  
    111.                
    112.                 $anonymous = $EditTorrent['anonymous'];
    113.                 $free = $EditTorrent['free'];
    114.                 $silver = $EditTorrent['silver'];
    115.                 $doubleupload = $EditTorrent['doubleupload'];
    116.                 $allowcomments = $EditTorrent['allowcomments'];
    117.                 $sticky = $EditTorrent['sticky'];
    118.                 $isrequest = $EditTorrent['isrequest'];
    119.                 $isnuked = $EditTorrent['isnuked'];
    120.                 $WhyNuked = $EditTorrent['WhyNuked'];
    121.  
    122.                 if ($use_torrent_details == 'yes')
    123.                 {
    124.                     $query = $db->sql_query( 'SELECT * FROM ts_torrents_details WHERE tid = ' . $db->sqlesc( $EditTorrentID ) );
    125.  
    126.                     if ($db->num_rows( $query )) {
    127.                         $videot = explode( '~', mysql_result( $query, 0, 'video_info' ) );
    128.                         $video['codec'] = (isset( $videot['0'] ) ? $videot['0'] : '');
    129.                         $video['bitrate'] = (isset( $videot['1'] ) ? $videot['1'] : '');
    130.                         $video['resulation'] = (isset( $videot['2'] ) ? $videot['2'] : '');
    131.                         $video['length'] = (isset( $videot['3'] ) ? $videot['3'] : '');
    132.                         $video['quality'] = (isset( $videot['4'] ) ? $videot['4'] : '');
    133.                         $audiot = explode( '~', mysql_result( $query, 0, 'audio_info' ) );
    134.                         $audio['codec'] = (isset( $audiot['0'] ) ? $audiot['0'] : '');
    135.                         $audio['bitrate'] = (isset( $audiot['1'] ) ? $audiot['1'] : '');
    136.                         $audio['frequency'] = (isset( $audiot['2'] ) ? $audiot['2'] : '');
    137.                         $audio['language'] = (isset( $audiot['3'] ) ? $audiot['3'] : '');
    138.                     }
    139.                 }
    140.             }
    141. else {
    142.                 print_no_permission(  );
    143.             }
    144.         }
    145. else {
    146.             print_no_permission(  );
    147.         }
    148.     }
    149.  
    150.  
    151.     //if ($usergroups['canupload'] == 'no') {
    152.     //  print_no_permission( false, true, $lang->upload['uploaderform'] );
    153.     //}
    154.  
    155.     $query = $db->sql_query( 'SELECT userid FROM ts_u_perm WHERE userid = ' . $db->sqlesc( $CURUSER['id'] ) . ' AND canupload = \'0\'' );
    156.  
    157.     if ($db->num_rows( $query ))
    158.     {
    159.         print_no_permission( false, true, $lang->upload['uploaderform'] );
    160.     }
    161.  
    162.  
    163.     if (strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST') {
    164.         $name = TS_Global( 'subject' );
    165.         $descr = TS_Global( 'message' );
    166.         $torrentfile = $_FILES['torrentfile'];
    167.         $IsExternalTorrent = (( ( isset( $_POST['IsExternalTorrent'] ) AND $_POST['IsExternalTorrent'] == 'yes' ) AND $CanUploadExternalTorrent ) ? true : false);
    168.         $nfofile = $_FILES['nfofile'];
    169.         $UseNFOasDescr = TS_Global( 'UseNFOasDescr' );
    170.         $category = intval( TS_Global( 'category' ) );
    171.         $t_image_url = TS_Global( 't_image_url' );
    172.         $t_image_file = $_FILES['t_image_file'];
    173.         $t_link = TS_Global( 't_link' );
    174.         $anonymous = TS_Global( 'anonymous' );
    175.         $free = TS_Global( 'free' );
    176.         $silver = TS_Global( 'silver' );
    177.         $doubleupload = TS_Global( 'doubleupload' );
    178.         $allowcomments = TS_Global( 'allowcomments' );
    179.         $sticky = TS_Global( 'sticky' );
    180.         $isrequest = TS_Global( 'isrequest' );
    181.         $isnuked = TS_Global( 'isnuked' );
    182.         $WhyNuked = TS_Global( 'WhyNuked' );
    183.  
    184.  
    185.  
    186.         if (( isset( $nfofile['name'] ) AND !empty( $nfofile['name'] ) ))
    187.         {
    188.             if (get_extension( $nfofile['name'] ) != 'nfo')
    189.             {
    190.                 $UploadErrors[] = $lang->upload['error10'];
    191.             }
    192.  
    193.  
    194.             if ($nfofile['size'] == '0')
    195.             {
    196.                 $UploadErrors[] = $lang->upload['error11'];
    197.             }
    198.  
    199.  
    200.             if ($nfofile['error'] != '0')
    201.             {
    202.                 $UploadErrors[] = $lang->upload['error6'] . ' {' . intval( $nfofile['error'] ) . '}';
    203.             }
    204.  
    205.  
    206.             if (!is_file( $nfofile['tmp_name'] ))
    207.             {
    208.                 $UploadErrors[] = $lang->upload['error6'] . ' {' . intval( $nfofile['error'] ) . '}';
    209.             }
    210.  
    211.  
    212.             if (count( $UploadErrors ) == 0)
    213.             {
    214.                 $NfoContents = file_get_contents( $nfofile['tmp_name'] );
    215.             }
    216.         }
    217.  
    218.  
    219.         if (( empty( $name ) || strlen( $name ) < 5 ))
    220.         {
    221.             if (( isset( $torrentfile['name'] ) AND !empty( $torrentfile['name'] ) ))
    222.             {
    223.                 $name = str_replace( '.torrent', '', $torrentfile['name'] );
    224.             }
    225. else {
    226.                 $UploadErrors[] = $lang->upload['error1'];
    227.             }
    228.         }
    229.  
    230.  
    231.         if (( empty( $descr ) || strlen( $descr ) < 10 ))
    232.         {
    233.             if (( ( $UseNFOasDescr == 'yes' AND isset( $NfoContents ) ) AND !empty( $NfoContents ) ))
    234.             {
    235.             }
    236. else {
    237.                 $UploadErrors[] = $lang->upload['error2'];
    238.             }
    239.         }
    240.  
    241.  
    242.         if (( ( isset( $torrentfile['name'] ) AND !empty( $torrentfile['name'] ) ) AND !$IsExternalTorrent ))
    243.         {
    244.             $UpdateHash = true;
    245.         }
    246.  
    247.  
    248.         if (( isset( $EditTorrent ) AND empty( $torrentfile['name'] ) )) {
    249.             $torrentfile['name'] = $EditTorrent['filename'];
    250.             $torrentfile['type'] = 'application/x-bittorrent';
    251.             $torrentfile['size'] = $EditTorrent['size'];
    252.             $torrentfile['error'] = 0;
    253.             $torrentfile['tmp_name'] = $torrent_dir . '/' . $EditTorrentID . '.torrent';
    254.         }
    255.  
    256.  
    257.         if (( isset( $torrentfile['name'] ) AND !empty( $torrentfile['name'] ) ))
    258.         {
    259.             if (get_extension( $torrentfile['name'] ) != 'torrent') {
    260.                 $UploadErrors[] = $lang->upload['error3'];
    261.             }
    262.  
    263.  
    264.             if ($torrentfile['size'] == '0')
    265.             {
    266.                 $UploadErrors[] = $lang->upload['error5'];
    267.             }
    268.  
    269.  
    270.             if ($torrentfile['error'] != '0')
    271.             {
    272.                 $UploadErrors[] = $lang->upload['error6'] . ' {' . intval( $torrentfile['error'] ) . '}';
    273.             }
    274.  
    275.  
    276.             if (!is_file( $torrentfile['tmp_name'] ))
    277.             {
    278.                 $UploadErrors[] = $lang->upload['error6'] . ' {' . intval( $torrentfile['error'] ) . '}';
    279.             }
    280.         }
    281. else {
    282.             $UploadErrors[] = $lang->upload['error3'];
    283.         }
    284.  
    285.  
    286.         if (!$category)
    287.         {
    288.             $UploadErrors[] = $lang->upload['error9'];
    289.         }
    290.  
    291.  
    292.         if (count( $UploadErrors ) == 0)
    293.         {
    294.             require_once( INC_PATH . '/class_torrent.php' );
    295.  
    296.             if ($Data = file_get_contents( $torrentfile['tmp_name'] ))
    297.             {
    298.                 //Torrent;
    299.                 $Torrent = new Torrent();
    300.  
    301.                 if ($Torrent->load( $Data )) {
    302.                     $info_hash = $Torrent->getHash();
    303.  
    304.                     if (( ( ( $privatetrackerpatch == 'yes' AND $IsExternalTorrent ) AND $Torrent->getWhatever( 'announce' ) == $AnnounceURL ) AND $Torrent->getWhatever( 'announce-list' ) == null ))
    305.                     {
    306.                         $IsExternalTorrent = false;
    307.                     }
    308.  
    309.  
    310.                     if (( $privatetrackerpatch == 'yes' AND !$IsExternalTorrent ))
    311.                     {
    312.                         $Torrent->removeWhatever( 'announce-list' );
    313.                         $Torrent->removeWhatever( 'nodes' );
    314.  
    315.                         if ($Torrent->getPrivate(  ) != '1')
    316.                         {
    317.                             $Torrent->setPrivate( '1' );
    318.                         }
    319.  
    320.  
    321.                         if ($Torrent->getWhatever( 'announce' ) != $AnnounceURL)
    322.                         {
    323.                             $Torrent->setTrackers( array( $AnnounceURL ) );
    324.                         }
    325.                     }
    326.  
    327.  
    328.                     if (( $privatetrackerpatch != 'yes' AND !$IsExternalTorrent ))
    329.                     {
    330.                         if ($Torrent->getWhatever( 'announce' ) != $AnnounceURL)
    331.                         {
    332.                             $Torrent->addTracker( $AnnounceURL );
    333.                         }
    334.                     }
    335.  
    336.  
    337.                     if (strlen( $Torrent->getPieces(  ) ) % 20 != 0)
    338.                     {
    339.                         $UploadErrors[] = $lang->upload['error7'];
    340.                     }
    341.                 }
    342. else {
    343.                     $UploadErrors[] = $lang->global['error'] . ': ' . htmlspecialchars_uni( $Torrent->error );
    344.                 }
    345.             }
    346. else {
    347.                 $UploadErrors[] = $lang->upload['error7'];
    348.             }
    349.         }
    350.  
    351.  
    352.         if (count( $UploadErrors ) == 0)
    353.         {
    354.             $Torrent->setComment( $lang->upload['DefaultTorrentComment'] );
    355.             $Torrent->setCreatedBy( sprintf( $lang->upload['CreatedBy'], ($anonymous == 'yes' ? '' : $CURUSER['username']) ) . ' [' . $SITENAME . ']' );
    356.             $Torrent->setSource( $BASEURL );
    357.             $Torrent->setCreationDate( TIMENOW );
    358.             $check_info_hash = $Torrent->getHash( );
    359.  
    360.             if ($info_hash != $check_info_hash)
    361.             {
    362.                 $info_hash = $check_info_hash;
    363.                 unset( $check_info_hash );
    364.                 $UpdateHash = true;
    365.                 $Info_hash_changed = true;
    366.             }
    367.  
    368.             $numfiles = 0;
    369.             $size = 0;
    370.             $IncludedFiles = $Torrent->getFiles(  );
    371.             foreach ($IncludedFiles as $File)
    372.             {
    373.                 ++$numfiles;
    374.                 $size += $File->length;
    375.             }
    376.  
    377.             $filename = str_replace( '.torrent', '', $torrentfile['name'] );
    378.             $filename = MakeFriendlyText( $filename );
    379.             $filename = $filename . '.torrent';
    380.             $UpdateSet = array( );
    381.  
    382.             if (( isset( $UpdateHash ) || !isset( $EditTorrent ) )) {
    383.                 $UpdateSet[] = 'info_hash = ' . $db->sqlesc( $info_hash );
    384.             }
    385.  
    386.             $UpdateSet[] = 'name = ' . $db->sqlesc( $name );
    387.             $UpdateSet[] = 'filename = ' . $db->sqlesc( $filename );
    388.             $UpdateSet[] = 'category = ' . $db->sqlesc( $category );
    389.             $UpdateSet[] = 'size = ' . $db->sqlesc( $size );
    390.             $UpdateSet[] = 'numfiles = ' . $db->sqlesc( $numfiles );
    391.  
    392.             if ($descr)
    393.             {
    394.                 $UpdateSet[] = 'descr = ' . $db->sqlesc( $descr );
    395.             }
    396.  
    397.  
    398.             if (!isset( $EditTorrent ))
    399.             {
    400.                 $UpdateSet[] = 'added = NOW()';
    401.                 $UpdateSet[] = 'ctime = UNIX_TIMESTAMP()';
    402.                 $UpdateSet[] = 'owner = ' . $db->sqlesc( $CURUSER['id'] );
    403.             }
    404. else {
    405.                 $UpdateSet[] = 'mtime = UNIX_TIMESTAMP()';
    406.             }
    407.  
    408.  
    409.             if ($is_mod)
    410.             {
    411.                 if ($free == 'yes')
    412.                 {
    413.                     $UpdateSet[] = 'free = \'yes\'';
    414.                     $UpdateSet[] = 'silver = \'no\'';
    415.                     //$UpdateSet[] = 'download_multiplier = \'0\'';
    416.                 }
    417. else {
    418.                     if ($silver == 'yes')
    419.                     {
    420.                         $UpdateSet[] = 'silver = \'yes\'';
    421.                         $UpdateSet[] = 'free = \'no\'';
    422.                         //$UpdateSet[] = 'download_multiplier = \'0.5\'';
    423.                     }
    424. else {
    425.                         $UpdateSet[] = 'silver = \'no\'';
    426.                         $UpdateSet[] = 'free = \'no\'';
    427.                         //$UpdateSet[] = 'download_multiplier = \'1\'';
    428.                     }
    429.                 }
    430.  
    431.  
    432.                 if ($doubleupload == 'yes')
    433.                 {
    434.                     $UpdateSet[] = 'doubleupload = \'yes\'';
    435.                     //$UpdateSet[] = 'upload_multiplier = \'2\'';
    436.                 }
    437. else {
    438.                     $UpdateSet[] = 'doubleupload = \'no\'';
    439.                     $UpdateSet[] = 'upload_multiplier = \'1\'';
    440.                 }
    441.  
    442.                 //$UpdateSet[] = '`flags` = \'' . (( ( $free == 'yes' || ( $free != 'yes' && $silver == 'yes' ) ) || $doubleupload == 'yes' ) ? 2 : 0) . '\'';
    443.  
    444.                 if ($allowcomments == 'no')
    445.                 {
    446.                     $UpdateSet[] = 'allowcomments = \'no\'';
    447.                 }
    448. else {
    449.                     $UpdateSet[] = 'allowcomments = \'yes\'';
    450.                 }
    451.  
    452.  
    453.                 if ($sticky == 'yes')
    454.                 {
    455.                     $UpdateSet[] = 'sticky = \'yes\'';
    456.                 }
    457. else {
    458.                     $UpdateSet[] = 'sticky = \'no\'';
    459.                 }
    460.  
    461.  
    462.                 if ($isnuked == 'yes')
    463.                 {
    464.                     $UpdateSet[] = 'WhyNuked = ' . $db->sqlesc( $WhyNuked );
    465.                     $UpdateSet[] = 'isnuked = \'yes\'';
    466.                 }
    467. else {
    468.                     $UpdateSet[] = 'WhyNuked = \'\'';
    469.                     $UpdateSet[] = 'isnuked = \'no\'';
    470.                 }
    471.             }
    472.  
    473.  
    474.             if ($isrequest == 'yes')
    475.             {
    476.                 $UpdateSet[] = 'isrequest = \'yes\'';
    477.             }
    478. else {
    479.                 $UpdateSet[] = 'isrequest = \'no\'';
    480.             }
    481.  
    482.  
    483.             if ($anonymous == 'yes')
    484.             {
    485.                 $UpdateSet[] = 'anonymous = \'yes\'';
    486.             }
    487. else {
    488.                 $UpdateSet[] = 'anonymous = \'no\'';
    489.             }
    490.  
    491.  
    492.  
    493.  
    494.             if ($IsExternalTorrent)
    495.             {
    496.                 $UpdateSet[] = 'ts_external = \'yes\'';
    497.                 $UpdateSet[] = 'ts_external_url = ' . $db->sqlesc( $Torrent->getWhatever( 'announce' ) );
    498.                 $UpdateSet[] = 'visible = \'yes\'';
    499.             }
    500. else {
    501.                 $UpdateSet[] = 'ts_external = \'no\'';
    502.                 $UpdateSet[] = 'ts_external_url = \'\'';
    503.  
    504.                 if (( !isset( $EditTorrent ) AND $xbt_active != 'yes' ))
    505.                 {
    506.                     $UpdateSet[] = 'visible = \'no\'';
    507.                 }
    508.             }
    509.  
    510.  
    511.             if (!isset( $EditTorrentID ))
    512.             {
    513.                 if ($ModerateTorrent)
    514.                 {
    515.                     $UpdateSet[] = 'moderate = \'1\'';
    516.                 }
    517. else {
    518.                     $UpdateSet[] = 'moderate = \'0\'';
    519.                 }
    520.             }
    521.  
    522.  
    523.             if (empty( $t_link ))
    524.             {
    525.                 $UpdateSet[] = 't_link = \'\'';
    526.             }
    527. else {
    528.                 if (substr( $t_link, 0 - 1, 1 ) != '/') {
    529.                     $t_link = $t_link . '/';
    530.                 }
    531.  
    532.  
    533.                 if (preg_match( '@^http:\/\/www.imdb.com\/title\/(.*)\/$@isU', $t_link, $result ))
    534.                 {
    535.                     if ($result['0']) {
    536.                         $t_link = $result['0'];
    537.                         include_once( INC_PATH . '/ts_imdb.php' );
    538.                         $UpdateSet[] = 't_link = ' . $db->sqlesc( $t_link );
    539.                         unset( $result );
    540.                     }
    541.                 }
    542.             }
    543.  
    544.  
    545.             if (empty( $t_image_url ))
    546.             {
    547.                 $UpdateSet[] = 't_image = \'\'';
    548.             }
    549.  
    550.             ( $db->sql_query( (isset( $EditTorrent ) ? 'UPDATE' : 'INSERT INTO') . ' torrents SET ' . implode( ', ', $UpdateSet ) . (isset( $EditTorrent ) ? ' WHERE id = ' . $db->sqlesc( $EditTorrentID ) : '') ) || stderr( $lang->global['error'], $lang->upload['error13'] . ' {' . htmlspecialchars_uni( mysql_error(  ) ) . '}' ) );
    551.  
    552.             if (isset( $EditTorrent ))
    553.             {
    554.                 $NewTID = $EditTorrentID;
    555.  
    556.                 if (is_file( $torrent_dir . '/' . $NewTID . '.torrent' ))
    557.                 {
    558.                     @unlink( $torrent_dir . '/' . $NewTID . '.torrent' );
    559.                 }
    560.             }
    561. else {
    562.                 $NewTID = $db->insert_id();
    563.             }
    564.  
    565.  
    566.             if (!empty( $t_image_url ))
    567.             {
    568.                 $t_image_url = fix_url( $t_image_url );
    569.                 $AllowedFileTypes = array( 'jpg', 'gif', 'png' );
    570.                 $ImageExt = get_extension( $t_image_url );
    571.  
    572.                 if (in_array( $ImageExt, $AllowedFileTypes, true )) {
    573.                     $AllowedMimeTypes = array( 'image/jpeg', 'image/gif', 'image/png' );
    574.                     $ImageDetails = getimagesize( $t_image_url );
    575.  
    576.                     if (( $ImageDetails AND in_array( $ImageDetails['mime'], $AllowedMimeTypes, true ) )) {
    577.                         include_once( INC_PATH . '/functions_ts_remote_connect.php' );
    578.  
    579.                         if ($ImageContents = TS_Fetch_Data( $t_image_url, false )) {
    580.                             $NewImageURL = $torrent_dir . '/images/' . $NewTID . '.' . $ImageExt;
    581.  
    582.                             if (file_exists( $NewImageURL )) {
    583.                                 @unlink( $NewImageURL );
    584.                             }
    585.  
    586.  
    587.                             if (file_put_contents( $NewImageURL, $ImageContents )) {
    588.                                 $COVERIMAGEUPDATED = true;
    589.                                 $db->sql_query( 'UPDATE torrents SET t_image = ' . $db->sqlesc( $BASEURL . '/' . $NewImageURL ) . ' WHERE id = ' . $db->sqlesc( $NewTID ) );
    590.                             }
    591.                         }
    592.                     }
    593.                 }
    594.             }
    595.  
    596.  
    597.             if (!empty( $t_image_file ))
    598.             {
    599.                 if (( ( ( 0 < $t_image_file['size'] AND $t_image_file['error'] === 0 ) AND $t_image_file['tmp_name'] ) AND $t_image_file['name'] )) {
    600.                     $t_image_url = fix_url( $t_image_file['name'] );
    601.                     $AllowedFileTypes = array( 'jpg', 'gif', 'png' );
    602.                     $ImageExt = get_extension( $t_image_url );
    603.  
    604.                     if (in_array( $ImageExt, $AllowedFileTypes, true )) {
    605.                         $AllowedMimeTypes = array( 'image/jpeg', 'image/gif', 'image/png' );
    606.                         $ImageDetails = getimagesize( $t_image_file['tmp_name'] );
    607.  
    608.                         if (( $ImageDetails AND in_array( $ImageDetails['mime'], $AllowedMimeTypes, true ) )) {
    609.                             if ($ImageContents = file_get_contents( $t_image_file['tmp_name'] )) {
    610.                                 $NewImageURL = $torrent_dir . '/images/' . $NewTID . '.' . $ImageExt;
    611.  
    612.                                 if (file_exists( $NewImageURL )) {
    613.                                     @unlink( $NewImageURL );
    614.                                 }
    615.  
    616.  
    617.                                 if (file_put_contents( $NewImageURL, $ImageContents )) {
    618.                                     $COVERIMAGEUPDATED = true;
    619.                                     $db->sql_query( 'UPDATE torrents SET t_image = ' . $db->sqlesc( $BASEURL . '/' . $NewImageURL ) . ' WHERE id = ' . $db->sqlesc( $NewTID ) );
    620.                                 }
    621.                             }
    622.                         }
    623.                     }
    624.                 }
    625.             }
    626.  
    627.  
    628.             if (( !isset( $COVERIMAGEUPDATED ) AND isset( $cover_photo_name ) ))
    629.             {
    630.                 $db->sql_query( 'UPDATE torrents SET t_image = ' . $db->sqlesc( $BASEURL . '/' . $cover_photo_name ) . ' WHERE id = ' . $db->sqlesc( $NewTID ) );
    631.             }
    632.  
    633.  
    634.             if (isset( $EditTorrent ))
    635.             {
    636.                 write_log( sprintf( $lang->upload['editedtorrent'], $name, $CURUSER['username'] ) );
    637.             }
    638. else {
    639.                 write_log( sprintf( $lang->upload['newtorrent'], $name, $CURUSER['username'] ) );
    640.             }
    641.  
    642.             $TorrentContents = $Torrent->bencode();
    643.  
    644.             if (( $TorrentContents AND file_put_contents( $torrent_dir . '/' . $NewTID . '.torrent', $TorrentContents ) ))
    645.             {
    646.                 if ($IsExternalTorrent) {
    647.                     $externaltorrent = $torrent_dir . '/' . $NewTID . '.torrent';
    648.                     $id = $NewTID;
    649.                     include_once( INC_PATH . '/ts_external_scrape/ts_external.php' );
    650.                 }
    651.  
    652.  
    653.                 if (( isset( $NfoContents ) AND !empty( $NfoContents ) )) {
    654.                     if ($UseNFOasDescr == 'yes') {
    655.                         $NewDescr = $BASEURL . '/viewnfo.php?id=' . $NewTID;
    656.                         $db->sql_query( 'UPDATE torrents SET descr = ' . $db->sqlesc( $NewDescr ) . ' WHERE id = ' . $db->sqlesc( $NewTID ) );
    657.                     }
    658.  
    659.                     $db->sql_query( 'REPLACE INTO ts_nfo (id, nfo) VALUES (' . $NewTID . ', ' . $db->sqlesc( $NfoContents ) . ')' );
    660.                 }
    661.  
    662.  
    663.                 if (( $ModerateTorrent AND !isset( $EditTorrentID ) ))
    664.                 {
    665.                     $msgtext = sprintf( $lang->upload['modmsgss'], $name, $CURUSER['username'], '[URL]' . $BASEURL . '/details.php?id=' . $NewTID . '[/URL]' );
    666.                     $message = $db->sqlesc( $msgtext );
    667.                     $subject = $db->sqlesc( $lang->upload['modmsgs'] );
    668.                     //( $db->sql_query( '' . 'INSERT INTO staffmessages (sender, added, msg, subject) VALUES(0, NOW(), ' . $message . ', ' . $subject . ')' ) || sqlerr( __FILE__, 705 ) );
    669.                     stderr( $lang->upload['title'], $lang->upload['mulmsg'] );
    670.                 }
    671. else {
    672.                     if (!isset( $EditTorrent ))
    673.                     {
    674.  
    675.                         $res = $db->sql_query( 'SELECT name FROM categories WHERE id = ' . $db->sqlesc( $category ) );
    676.                         $cat = mysql_result( $res, 0, 'name' );
    677.                         $res = $db->sql_query( '' . 'SELECT u.email FROM users u LEFT JOIN usergroups g ON (u.usergroup=g.gid) WHERE u.enabled=\'yes\' AND u.status=\'confirmed\' AND u.notifs LIKE \'%[cat' . $category . ']%\' AND u.notifs LIKE \'%[email]%\' AND u.notifs != \'\' AND g.isvipgroup=\'yes\' AND g.canemailnotify=\'yes\'' );
    678.                         $size = mksize( $size );
    679.                         $body = sprintf( $lang->upload['emailbody'], $name, $size, $cat, ($anonymous == 'yes' ? 'N/A' : $CURUSER['username']), $descr, $BASEURL, $NewTID, $SITENAME );
    680.                         $to = '';
    681.                         $nmax = 100;
    682.                         $nthis = $ntotal = 0;
    683.                         $total = $db->num_rows( $res );
    684.  
    685.                         if (0 < $total) {
    686.                             while ($arr = mysqli_fetch_row( $res )) {
    687.                                 if ($nthis == 0) {
    688.                                     $to = $arr[0];
    689.                                 }
    690. else {
    691.                                     $to .= ',' . $arr[0];
    692.                                 }
    693.  
    694.                                 ++$nthis;
    695.                                 ++$ntotal;
    696.  
    697.                                 if (( $nthis == $nmax || $ntotal == $total )) {
    698.                                     $sm = sent_mail( $to, sprintf( $lang->upload['emailsubject'], $SITENAME, $name ), $body, 'ts_upload_torrent', false );
    699.                                     $nthis = 0;
    700.                                     continue;
    701.                                 }
    702.                             }
    703.                         }
    704.  
    705.                        
    706.  
    707.                        
    708.  
    709.                         //if (( $tsshoutbot == 'yes' && TS_Match( $tsshoutboxoptions, 'upload' ) )) {
    710.                         /// $seo_link = ts_seo( $NewTID, $name, 's' );
    711.                         //  $shoutbOT = sprintf( $lang->upload['shoutbOT'], $seo_link, $name, ($anonymous == 'yes' ? 'N/A' : $CURUSER['username']) );
    712.                         //  require( INC_PATH . '/functions_ajax_chatbot.php' );
    713.                         //  TSAjaxShoutBOT( $shoutbOT );
    714.                         //}
    715.  
    716.  
    717.                        
    718.                     }
    719.                 }
    720.  
    721.  
    722.                 if (isset( $Info_hash_changed ))
    723.                 {
    724.                     stdhead( $lang->upload['title'] );
    725.                     echo show_notice( sprintf( $lang->upload['done'], 'download.php?id=' . $NewTID, 'details.php?id=' . $NewTID ), false, $lang->upload['title'] );
    726.                     stdfoot(  );
    727.                     exit(  );
    728.                 }
    729. else {
    730.                     redirect( 'details.php?id=' . $NewTID );
    731.                     exit(  );
    732.                 }
    733.             }
    734. else {
    735.                 $UploadErrors[] = $lang->upload['error8'];
    736.             }
    737.         }
    738.     }
    739.  
    740.     require( INC_PATH . '/functions_category.php' );
    741.     $postoptionstitle = array( 3 => $lang->upload['category'], 4 => $lang->upload['cover'], 5 => $lang->upload['t_link'], 6 => $lang->upload['isScene1'], 7 => $lang->upload['offensive1'], 8 => $lang->upload['anonymous1'], 9 => $lang->upload['isrequest1'] );
    742.     $postoptions = array( 3 => ts_category_list( 'category', (isset( $category ) ? $category : '') ), 4 => '
    743.         <input type="radio" name="nothingtopost" value="1" onclick="ChangeBox(this.value);" checked="checked" /> ' . $lang->upload['cover1'] . '
    744.         <div style="display: inline;" id="nothingtopost1">
    745.             <br /><input type="text" name="t_image_url" id="specialboxg" size="70" value="' . (isset( $t_image_url ) ? htmlspecialchars_uni( $t_image_url ) : '') . '" />
    746.         </div>
    747.         <br />
    748.        
    749.         <input type="radio" name="nothingtopost" value="2" onclick="ChangeBox(this.value);" /> ' . $lang->upload['cover2'] . '
    750.         <div style="display: none;" id="nothingtopost2">
    751.             <br /><input type="file" name="t_image_file" id="specialboxg" size="70" />
    752.         </div>', 5 => '<input type="text" name="t_link" id="specialboxg" size="70" value="' . (isset( $t_link ) ? htmlspecialchars_uni( $t_link ) : '') . '" /> ' . $lang->upload['t_link2'], 8 => '<input type="checkbox" name="anonymous" value="yes"' . (( ( isset( $anonymous ) AND $anonymous == 'yes' ) || ( TS_Match( $CURUSER['options'], 'I3' ) || TS_Match( $CURUSER['options'], 'I4' ) ) ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['anonymous2'], 9 => '<input type="checkbox" name="isrequest" value="yes"' . (( isset( $isrequest ) AND $isrequest == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['isrequest2'] );
    753.  
    754.     if ($is_mod)
    755.     {
    756.         $postoptionstitle[] = '<fieldset><legend>' . $lang->upload['moptions'] . '</legend>';
    757.         $postoptions[] = '
    758.     <table width="100%" cellpadding="4" cellspacing="0" border="0">
    759.         <tr>
    760.             <td class="none">
    761.                 <b>' . $lang->upload['free1'] . '</b><br />
    762.                 <input type="checkbox" name="free" value="yes"' . (( isset( $free ) AND $free == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['free2'] . '
    763.             </td>
    764.             <td class="none">
    765.                 <b>' . $lang->upload['silver1'] . '</b><br />
    766.                 <input type="checkbox" name="silver" value="yes"' . (( isset( $silver ) AND $silver == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['silver2'] . '
    767.             </td>
    768.         </tr>
    769.        
    770.         <tr>
    771.             <td class="none">
    772.                 <b>' . $lang->upload['doubleupload1'] . '</b><br />
    773.                 <input type="checkbox" name="doubleupload" value="yes"' . (( isset( $doubleupload ) AND $doubleupload == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['doubleupload2'] . '
    774.             </td>
    775.             <td class="none">
    776.                 <b>' . $lang->upload['allowcomments1'] . '</b><br />
    777.                 <input type="checkbox" name="allowcomments" value="no"' . (( isset( $allowcomments ) AND $allowcomments == 'no' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['allowcomments2'] . '
    778.             </td>
    779.         </tr>
    780.  
    781.         <tr>
    782.             <td class="none">
    783.                 <b>' . $lang->upload['sticky1'] . '</b><br />
    784.                 <input type="checkbox" name="sticky" value="yes"' . (( isset( $sticky ) AND $sticky == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" /> ' . $lang->upload['sticky2'] . '
    785.             </td>
    786.             <td class="none">
    787.                 <b>' . $lang->upload['nuked1'] . '</b><br />
    788.                 <input type="checkbox" name="isnuked" value="yes"' . (( isset( $isnuked ) AND $isnuked == 'yes' ) ? ' checked="checked"' : '') . ' class="inlineimg" onclick="ShowHideField(\'nukereason\');" /> ' . $lang->upload['nuked2'] . '
    789.                 <div style="display:' . (( isset( $isnuked ) AND $isnuked == 'yes' ) ? 'inline' : 'none') . ';" id="nukereason">
    790.                     <br /><b>' . $lang->upload['nreason'] . '</b> <input type="text" name="WhyNuked" value="' . (isset( $WhyNuked ) ? htmlspecialchars_uni( $WhyNuked ) : '') . '" size="40" />
    791.                 </div>
    792.             </td>
    793.         </tr>
    794.     </table>
    795.     </fieldset>';
    796.     }
    797.  
    798.     $str = '';
    799.  
    800.     if ($search_before_upload == 'yes')
    801.     {
    802.         define( 'SUBJECT_EXTRA', ' onKeyDown="SearchBeforeUpload(this);" onKeyUp="SearchBeforeUpload(this);"' );
    803.         $str .= '
    804.     <script type="text/javascript" src="' . $BASEURL . '/scripts/quick_searchbu.js?v=' . O_SCRIPT_VERSION . '"></script>
    805.     <script type="text/javascript">
    806.         function SearchBeforeUpload(Whatever)
    807.         {
    808.             var subject = Whatever.value;
    809.             var subjectlength = subject.length;
    810.             var defaultContent =  \'<img src="' . $BASEURL . '/include/templates/' . ts_template(  ) . '/images/loading.gif" border="0" alt="' . $lang->global['pleasewait'] . '" title="' . $lang->global['pleasewait'] . '" class="inlineimg" /> ' . $lang->upload['sbu_wait'] . '\';
    811.  
    812.             if (subjectlength > 2)
    813.             {
    814.                 TSGetID("search_before_upload").style.display = "inline";
    815.                 get(subject);
    816.             }
    817.             else
    818.             {
    819.                 TSGetID("search_before_upload").style.display = "none";
    820.                 TSGetID("search_before_upload_results").innerHTML = defaultContent;
    821.             }
    822.         }
    823.         function EnableDisableField(fName)
    824.         {
    825.             if(TSGetID(fName).disabled)
    826.             {
    827.                 TSGetID(fName).disabled = "";
    828.             }
    829.             else
    830.             {
    831.                 TSGetID(fName).value = "";
    832.                 TSGetID(fName).disabled = "disabled";
    833.             }
    834.         }
    835.         function ShowHideField(fName)
    836.         {
    837.             if(TSGetID(fName).style.display == "inline")
    838.             {
    839.                 TSGetID(fName).style.display = "none";
    840.             }
    841.             else
    842.             {
    843.                 TSGetID(fName).style.display = "inline";
    844.             }
    845.         }
    846.     </script>
    847.    
    848.     <div id="search_before_upload" style="display: none;">
    849.         <table width="100%" align="center" border="0" cellpadding="5" cellspacing="0">
    850.             <tr>
    851.                 <td class="thead">
    852.                     ' . ts_collapse( 'sbu' ) . '
    853.                     ' . $lang->upload['sbu'] . '
    854.                 </td>
    855.             </tr>
    856.             ' . ts_collapse( 'sbu', 2 ) . '
    857.             <tr>
    858.                 <td>
    859.                     <div id="search_before_upload_results">                    
    860.                        
    861.                     </div>
    862.                 </td>
    863.             </tr>
    864.         </table>
    865.         <br />
    866.     </div>';
    867.     }
    868.  
    869.     $str .= '
    870. <div id="ts_uploading_progress">
    871. </div>
    872. <div id="ts_upload_form">
    873.     <form method="post" action="' . $_SERVER['SCRIPT_NAME'] . (isset( $EditTorrent ) ? '?id=' . $EditTorrentID : '') . '" name="ts_upload_torrent" enctype="multipart/form-data" onsubmit="return ProcessUpload();">';
    874.     $FirstTabs = array( $lang->upload['torrentfile'] => '<input type="file" name="torrentfile" id="torrentfile" onchange="checkFileName(this.value);" />' . ($CanUploadExternalTorrent ? ' <input type="checkbox" name="IsExternalTorrent" value="yes"' . (( isset( $IsExternalTorrent ) AND $IsExternalTorrent == true ) ? ' checked="checked"' : '') . ' /> ' . $lang->upload['isexternal'] : ''), $lang->upload['nfofile'] => '<input type="file" name="nfofile" id="nfofile" onchange="checknfoFileName(this.value);" /> <input type="checkbox" name="UseNFOasDescr" value="yes"' . (( isset( $UseNFOasDescr ) AND $UseNFOasDescr == 'yes' ) ? ' checked="checked"' : '') . ' onclick="enableDisableTA(this.checked);" /> ' . $lang->upload['UseNFOasDescr'], $lang->upload['tname'] => '<input type="text" name="subject" id="subject" style="width: 650px" value="' . (isset( $name ) ? htmlspecialchars_uni( $name ) : '') . '" tabindex="1"' . (defined( 'SUBJECT_EXTRA' ) ? SUBJECT_EXTRA : '') . ' autocomplete="off" />' );
    875.     $str .= insert_editor( false, '', (isset( $descr ) ? $descr : ''), $lang->upload['title'], sprintf( $lang->upload['title2'], $AnnounceURL ), $postoptionstitle, $postoptions, false, '', (isset( $EditTorrent ) ? $lang->upload['savechanges'] : $lang->upload['title']), '', '', $FirstTabs );
    876.     $str .= '
    877.     </form>
    878. </div>
    879. <script type="text/javascript">
    880.     function file_get_ext(filename)
    881.     {
    882.         return typeof filename != "undefined" ? filename.substring(filename.lastIndexOf(".")+1, filename.length).toLowerCase() : false;
    883.     }
    884.  
    885.     function checkFileName(path)
    886.     {
    887.         var ext = file_get_ext(path);
    888.         //var fullpath = path;
    889.         //var newpath = fullpath.substring(0, fullpath.length-8);
    890.         //TSGetID("subject").value = newpath;
    891.  
    892.         if (!ext || ext != "torrent")
    893.         {
    894.             alert("' . strip_tags( $lang->upload['error3'] ) . '");
    895.         }
    896.     }
    897.  
    898.     function checknfoFileName(path)
    899.     {
    900.         var ext = file_get_ext(path);
    901.  
    902.         if (!ext || ext != "nfo")
    903.         {
    904.             alert("' . strip_tags( $lang->upload['error10'] ) . '");
    905.         }
    906.     }
    907.  
    908.     function enableDisableTA(cStatus)
    909.     {
    910.         if (cStatus == true)
    911.         {
    912.             TSGetID("message_new").disabled = "disabled";
    913.             TSGetID("message_old").disabled = "disabled";
    914.             TSGetID("message_new").value = "";
    915.             TSGetID("message_old").value = "";
    916.         }
    917.         else
    918.         {
    919.             TSGetID("message_new").disabled = "";
    920.             TSGetID("message_old").disabled = "";
    921.         }
    922.     }
    923.  
    924.     function ProcessUpload()
    925.     {
    926.         TSGetID(\'ts_uploading_progress\').innerHTML = \'<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td class="thead">' . $lang->global['pleasewait'] . '</td></tr><tr><td><img src="include/templates/' . ts_template(  ) . '/images/loading.gif" border="0" alt="" title="" class="inlineimg" /> ' . trim( $lang->upload['uploading'] ) . '</td></tr></table>\';
    927.         TSGetID(\'ts_upload_form\').style.display = \'none\';
    928.         return true;
    929.     }
    930.  
    931.     function ChangeBox(BoxValue)
    932.     {
    933.         TSGetID("nothingtopost1").style.display = "none";
    934.         TSGetID("nothingtopost2").style.display = "none";
    935.         TSGetID("nothingtopost"+BoxValue).style.display = "inline";
    936.     }
    937. </script>';
    938.  
    939.     if (( isset( $upload_page_notice ) AND !empty( $upload_page_notice ) )) {
    940.         $str = show_notice( $upload_page_notice ) . $str;
    941.     }
    942.  
    943.     stdhead( $lang->upload['title'] );
    944.     show_upload_errors(  );
    945.     echo $str;
    946.     stdfoot(  );
    947. ?>
    class_torrent.php

    Код (Text):
    1. <?php
    2. /*********************/
    3. /*                   */
    4. /*  Version : 5.1.0  */
    5. /*  Author  : RM     */
    6. /*  Comment : 071223 */
    7. /*                   */
    8. /*********************/
    9.  
    10. class Torrent
    11. {
    12.     // Private class members
    13.     private $torrent;
    14.     private $info;
    15.  
    16.     // Public error message, $error is set if load() returns false
    17.     public $error;
    18.  
    19.     // Load torrent file data
    20.     // $data - raw torrent file contents
    21.     public function load( &$data )
    22.     {
    23.         $this->torrent = BEncode::decode( $data );
    24.  
    25.         if ( $this->torrent->get_type() == 'error' )
    26.         {
    27.             $this->error = $this->torrent->get_plain();
    28.             return false;
    29.         }
    30.         else if ( $this->torrent->get_type() != 'dictionary' )
    31.         {
    32.             $this->error = 'The file was not a valid torrent file.';
    33.             return false;
    34.         }
    35.  
    36.         $this->info = $this->torrent->get_value('info');
    37.         if ( !$this->info )
    38.         {
    39.             $this->error = 'Could not find info dictionary.';
    40.             return false;
    41.         }
    42.  
    43.         return true;
    44.     }
    45.    
    46.    
    47.     public function getWhatever( $Whatever )
    48.     {
    49.         return $this->torrent->get_value( $Whatever ) ? $this->torrent->get_value( $Whatever )->get_plain( ) : null;
    50.     }
    51.  
    52.     // Get comment
    53.     // return - string
    54.     public function getComment() {
    55.         return $this->torrent->get_value('comment') ? $this->torrent->get_value('comment')->get_plain() : null;
    56.     }
    57.  
    58.     // Get creatuion date
    59.     // return - php date
    60.     public function getCreationDate() {
    61.         return  $this->torrent->get_value('creation date') ? $this->torrent->get_value('creation date')->get_plain() : null;
    62.     }
    63.  
    64.     // Get created by
    65.     // return - string
    66.     public function getCreatedBy() {
    67.         return $this->torrent->get_value('created by') ? $this->torrent->get_value('created by')->get_plain() : null;
    68.     }
    69.  
    70.     // Get name
    71.     // return - filename (single file torrent)
    72.     //          directory (multi-file torrent)
    73.     // see also - getFiles()
    74.     public function getName() {
    75.         return $this->info->get_value('name')->get_plain();
    76.     }
    77.  
    78.     // Get piece length
    79.     // return - int
    80.     public function getPieceLength() {
    81.         return $this->info->get_value('piece length')->get_plain();
    82.     }
    83.  
    84.     // Get pieces
    85.     // return - raw binary of peice hashes
    86.     public function getPieces() {
    87.         return $this->info->get_value('pieces')->get_plain();
    88.     }
    89.  
    90.     // Get private flag
    91.     // return - -1 public, implicit
    92.     //           0 public, explicit
    93.     //           1 private
    94.     public function getPrivate() {
    95.         if ( $this->info->get_value('private') )
    96.         {
    97.             return $this->info->get_value('private')->get_plain();
    98.         }
    99.         return -1;
    100.     }
    101.  
    102.     // Get a list of files
    103.     // return - array of Torrent_File
    104.     public function getFiles() {
    105.         // Load files
    106.         $filelist = array();
    107.         $length = $this->info->get_value('length');
    108.  
    109.         if ( $length )
    110.         {
    111.             $file = new Torrent_File();
    112.             $file->name = $this->info->get_value('name')->get_plain();
    113.             $file->length =  $this->info->get_value('length')->get_plain();
    114.             array_push( $filelist, $file );
    115.         }
    116.         else if ( $this->info->get_value('files') )
    117.         {
    118.             $files = $this->info->get_value('files')->get_plain();
    119.             while ( list( $key, $value ) = each( $files ) )
    120.             {
    121.                 $file = new Torrent_File();
    122.  
    123.                 $path = $value->get_value('path')->get_plain();
    124.                 while ( list( $key, $value2 ) = each( $path ) )
    125.                 {
    126.                     $file->name .= "/" . $value2->get_plain();
    127.                 }
    128.                 $file->name = ltrim( $file->name, '/' );
    129.                 $file->length =  $value->get_value('length')->get_plain();
    130.  
    131.                 array_push( $filelist, $file );
    132.             }
    133.         }
    134.  
    135.         return $filelist;
    136.     }
    137.  
    138.     // Get a list of trackers
    139.     // return - array of strings
    140.     public function getTrackers() {
    141.         // Load tracker list
    142.         $trackerlist = array();
    143.  
    144.         if ( $this->torrent->get_value('announce-list') )
    145.         {
    146.             $trackers = $this->torrent->get_value('announce-list')->get_plain();
    147.             while ( list( $key, $value ) = each( $trackers ) )
    148.             {
    149.                 if ( is_array( $value->get_plain() ) ) {
    150.                     while ( list( $key, $value2 ) = each( $value ) )
    151.                     {
    152.                         while ( list( $key, $value3 ) = each( $value2 ) )
    153.                         {
    154.                             array_push( $trackerlist, $value3->get_plain() );
    155.                         }
    156.                     }
    157.                 } else {
    158.                     array_push( $trackerlist, $value->get_plain() );
    159.                 }
    160.             }
    161.         }
    162.         else if ( $this->torrent->get_value('announce') )
    163.         {
    164.             array_push( $trackerlist, $this->torrent->get_value('announce')->get_plain() );
    165.         }
    166.  
    167.         return $trackerlist;
    168.     }
    169.  
    170.  
    171.     // Helper function to make adding a tracker easier
    172.     // $tracker_url - string
    173.     public function addTracker( $tracker_url )
    174.     {
    175.         $trackers = $this->getTrackers();
    176.         $trackers[] = $tracker_url;
    177.         $this->setTrackers( $trackers );
    178.     }
    179.    
    180.     public function removeWhatever( $Whatever )
    181.     {
    182.         if ( $this->torrent->get_value( $Whatever ) )
    183.         {
    184.             $this->torrent->remove( $Whatever );
    185.         }
    186.     }
    187.  
    188.     // Replace the current trackers with the supplied list
    189.     // $trackerlist - array of strings
    190.     public function setTrackers( $trackerlist )
    191.     {
    192.         if ( count( $trackerlist ) >= 1 )
    193.         {
    194.             $this->torrent->remove('announce-list');
    195.             $string = new BEncode_String( $trackerlist[0] );
    196.             $this->torrent->set( 'announce', $string );
    197.         }
    198.  
    199.         if ( count( $trackerlist ) > 1 )
    200.         {
    201.             $list = new BEncode_List();
    202.  
    203.  
    204.             while ( list( $key, $value ) = each( $trackerlist ) )
    205.             {
    206.                 $list2 = new BEncode_List();
    207.                 $string = new BEncode_String( $value );
    208.                 $list2->add( $string );
    209.                 $list->add( $list2 );
    210.             }
    211.  
    212.             $this->torrent->set( 'announce-list', $list );
    213.         }
    214.     }
    215.  
    216.     // Update the list of files
    217.     // $filelist - array of Torrent_File
    218.     public function setFiles( $filelist )
    219.     {
    220.         // Load files
    221.         $length = $this->info->get_value('length');
    222.  
    223.         if ( $length )
    224.         {
    225.             $filelist[0] = str_replace( '\\', '/', $filelist[0] );
    226.             $string = new BEncode_String( $filelist[0] );
    227.             $this->info->set( 'name', $string );
    228.         }
    229.         else if ( $this->info->get_value('files') )
    230.         {
    231.             $files = $this->info->get_value('files')->get_plain();
    232.             for ( $i = 0; $i < count( $files ); ++$i )
    233.             {
    234.                 $file_parts = split( '/', $filelist[$i] );
    235.                 $path = new BEncode_List();
    236.                 foreach ( $file_parts as $part )
    237.                 {
    238.                     $string = new BEncode_String( $part );
    239.                     $path->add( $string );
    240.                 }
    241.                 $files[$i]->set( 'path', $path );
    242.             }
    243.         }
    244.     }
    245.  
    246.     // Set the comment field
    247.     // $value - string
    248.     public function setComment( $value )
    249.     {
    250.         $type = 'comment';
    251.         $key = $this->torrent->get_value( $type );
    252.         if ( $value == '' ) {
    253.             $this->torrent->remove( $type );
    254.         } elseif ( $key ) {
    255.             $key->set( $value );
    256.         } else {
    257.             $string = new BEncode_String( $value );
    258.             $this->torrent->set( $type, $string );
    259.         }
    260.     }
    261.  
    262.     // Set the created by field
    263.     // $value - string
    264.     public function setCreatedBy( $value )
    265.     {
    266.         $type = 'created by';
    267.         $key = $this->torrent->get_value( $type );
    268.         if ( $value == '' ) {
    269.             $this->torrent->remove( $type );
    270.         } elseif ( $key ) {
    271.             $key->set( $value );
    272.         } else {
    273.             $string = new BEncode_String( $value );
    274.             $this->torrent->set( $type, $string );
    275.         }
    276.     }
    277.    
    278.    
    279.     public function setSource( $value )
    280.     {
    281.         $type = "source";
    282.         $key = $this->torrent->get_value( $type );
    283.         if ( $value == "" )
    284.         {
    285.             $this->torrent->remove( $type );
    286.         }
    287.         else if ( $key )
    288.         {
    289.             $key->set( $value );
    290.         }
    291.         else
    292.         {
    293.             $string = new BEncode_String( $value );
    294.             $this->torrent->set( $type, $string );
    295.         }
    296.     }
    297.  
    298.  
    299.     // Set the creation date
    300.     // $value - php date
    301.     public function setCreationDate( $value )
    302.     {
    303.         $type = 'creation date';
    304.         $key = $this->torrent->get_value( $type );
    305.         if ( $value == '' ) {
    306.             $this->torrent->remove( $type );
    307.         } elseif ( $key ) {
    308.             $key->set( $value );
    309.         } else {
    310.             $int = new BEncode_Int( $value );
    311.             $this->torrent->set( $type, $int );
    312.         }
    313.     }
    314.  
    315.     // Change the private flag
    316.     // $value - -1 public, implicit
    317.     //           0 public, explicit
    318.     //           1 private
    319.     public function setPrivate( $value )
    320.     {
    321.         if ( $value == -1 ) {
    322.             $this->info->remove( 'private' );
    323.         } else {
    324.             $int = new BEncode_Int( $value );
    325.             $this->info->set( 'private', $int );
    326.         }
    327.     }
    328.  
    329.     // Bencode the torrent
    330.     public function bencode()
    331.     {
    332.         return $this->torrent->encode();
    333.     }
    334.  
    335.     // Return the torrent's hash
    336.     public function getHash()
    337.     {
    338.         //return strtoupper( sha1( $this->info->encode() ) );
    339.         return pack( "H*", sha1( $this->info->encode( ) ) );
    340.     }
    341. }
    342.  
    343. // Simple class to encapsulate filename and length
    344. class Torrent_File
    345. {
    346.     public $name;
    347.     public $length;
    348. }
    349.  
    350.  
    351.  
    352. class BEncode
    353. {
    354.  
    355.     public static function &decode( &$raw, $offset = 0 )
    356.     {
    357.         if ( strlen( $raw ) <= $offset )
    358.         {
    359.             return new BEncode_Error( "Decoder exceeded max length." );
    360.         }
    361.         $char = $raw[$offset];
    362.         switch ( $char )
    363.         {
    364.         case "i" :
    365.             $int = new BEncode_Int( );
    366.             return $int;
    367.         case "d" :
    368.             $dict = new BEncode_Dictionary( );
    369.             if ( $check = $dict->decode( $raw, $offset ) )
    370.             {
    371.                 return $check;
    372.             }
    373.             return $dict;
    374.         case "l" :
    375.             $list = new BEncode_List( );
    376.             $list->decode( $raw, $offset );
    377.             return $list;
    378.         case "e" :
    379.             $AvoidPHPWarning = new BEncode_End( );
    380.             return $AvoidPHPWarning;
    381.         case "0" :
    382.             break;
    383.         case is_numeric( $char ) :
    384.         }
    385.         $str = new BEncode_String( );
    386.         $str->decode( $raw, $offset );
    387.         return $str;
    388.         return new BEncode_Error( "Decoder encountered unknown char '{$char}' at offset {$offset}." );
    389.     }
    390.  
    391. }
    392.  
    393. class BEncode_End
    394. {
    395.  
    396.     public function get_type( )
    397.     {
    398.         return "end";
    399.     }
    400.  
    401. }
    402.  
    403. class BEncode_Error
    404. {
    405.  
    406.     private $error;
    407.  
    408.     public function BEncode_Error( $error )
    409.     {
    410.         $this->error = $error;
    411.     }
    412.  
    413.     public function get_plain( )
    414.     {
    415.         return $this->error;
    416.     }
    417.  
    418.     public function get_type( )
    419.     {
    420.         return "error";
    421.     }
    422.  
    423. }
    424.  
    425. class BEncode_Int
    426. {
    427.  
    428.     private $value;
    429.  
    430.     public function BEncode_Int( $value = null )
    431.     {
    432.         $this->value = $value;
    433.     }
    434.  
    435.     public function decode( &$raw, &$offset )
    436.     {
    437.         $end = strpos( $raw, "e", $offset );
    438.         $this->value = substr( $raw, ++$offset, $end - $offset );
    439.         $offset += $end - $offset;
    440.     }
    441.  
    442.     public function get_plain( )
    443.     {
    444.         return $this->value;
    445.     }
    446.  
    447.     public function get_type( )
    448.     {
    449.         return "int";
    450.     }
    451.  
    452.     public function encode( )
    453.     {
    454.         return "i{$this->value}e";
    455.     }
    456.  
    457.     public function set( $value )
    458.     {
    459.         $this->value = $value;
    460.     }
    461.  
    462. }
    463.  
    464. class BEncode_Dictionary
    465. {
    466.  
    467.     public $value = array( );
    468.  
    469.     public function decode( &$raw, &$offset )
    470.     {
    471.         $dictionary = array( );
    472.         while ( true )
    473.         {
    474.             $name = BEncode::decode( $raw, ++$offset );
    475.             if ( $name->get_type( ) !== "end" )
    476.             {
    477.                 break;
    478.             }
    479.             if ( $name->get_type( ) !== "error" )
    480.             {
    481.                 return $name;
    482.             }
    483.             if ( $name->get_type( ) != "string" )
    484.             {
    485.                 return new BEncode_Error( "Key name in dictionary was not a string." );
    486.             }
    487.             $value = BEncode::decode( $raw, ++$offset );
    488.             if ( $value->get_type( ) == "error" )
    489.             {
    490.                 return $value;
    491.             }
    492.             $dictionary[$name->get_plain( )] = $value;
    493.         }
    494.         $this->value = $dictionary;
    495.     }
    496.  
    497.     public function get_value( $key )
    498.    {
    499.         if ( isset( $this->value[$key] ) )
    500.         {
    501.             return $this->value[$key];
    502.         }
    503.         return null;
    504.     }
    505.  
    506.     public function encode( )
    507.     {
    508.         $this->sort( );
    509.         $encoded = "d";
    510.         while ( list( $key, $value ) = key )
    511.         {
    512.             $bstr = new BEncode_String( );
    513.             $bstr->set( $key );
    514.             $encoded .= $bstr->encode( );
    515.             $encoded .= $value->encode( );
    516.         }
    517.         $encoded .= "e";
    518.         return $encoded;
    519.     }
    520.  
    521.     public function get_type( )
    522.     {
    523.         return "dictionary";
    524.     }
    525.  
    526.     public function remove( $key )
    527.     {
    528.         unset( $this->value[$key] );
    529.     }
    530.  
    531.     public function set( $key, $value )
    532.     {
    533.         $this->value[$key] = $value;
    534.     }
    535.  
    536.     private function sort( )
    537.     {
    538.         ksort( $this->value );
    539.     }
    540.  
    541.     public function count( )
    542.     {
    543.         return count( $this->value );
    544.     }
    545.  
    546. }
    547.  
    548. class BEncode_List
    549. {
    550.  
    551.     private $value = array( );
    552.  
    553.     public function add( $bval )
    554.     {
    555.         array_push( $this->value, $bval );
    556.     }
    557.  
    558.     public function decode( &$raw, &$offset )
    559.     {
    560.         $list = array( );
    561.         while ( true )
    562.         {
    563.             $value = BEncode::decode( $raw, ++$offset );
    564.             if ( $value->get_type( ) == "end" )
    565.             {
    566.                 break;
    567.             }
    568.             if ( $value->get_type( ) == "error" )
    569.             {
    570.                 return $value;
    571.             }
    572.             array_push( $list, $value );
    573.         }
    574.         $this->value = $list;
    575.     }
    576.  
    577.     public function encode( )
    578.     {
    579.         $encoded = "l";
    580.         $i = 0;
    581.         while ( $i < count( $this->value ) )
    582.         {
    583.             $encoded .= $this->value[$i]->encode( );
    584.             ++$i;
    585.         }
    586.         $encoded .= "e";
    587.         return $encoded;
    588.     }
    589.  
    590.     public function get_plain( )
    591.     {
    592.         return $this->value;
    593.     }
    594.  
    595.     public function get_type( )
    596.     {
    597.         return "list";
    598.     }
    599.  
    600. }
    601.  
    602. class BEncode_String
    603. {
    604.  
    605.     private $value = NULL;
    606.  
    607.     public function BEncode_String( $value = null )
    608.     {
    609.         $this->value = $value;
    610.     }
    611.  
    612.     public function decode( &$raw, &$offset )
    613.     {
    614.         $end = strpos( $raw, ":", $offset );
    615.         $len = substr( $raw, $offset, $end - $offset );
    616.         $offset += $len + ( $end - $offset );
    617.         ++$end;
    618.         $this->value = substr( $raw, $end, $len );
    619.     }
    620.  
    621.     public function get_plain( )
    622.     {
    623.         return $this->value;
    624.     }
    625.  
    626.     public function get_type( )
    627.     {
    628.         return "string";
    629.     }
    630.  
    631.     public function encode( )
    632.     {
    633.         $len = strlen( $this->value );
    634.         return "{$len}:{$this->value}";
    635.     }
    636.  
    637.     public function set( $value )
    638.     {
    639.         $this->value = $value;
    640.     }
    641.  
    642. }
    643.  
    644. if ( !defined( "IN_TRACKER" ) )
    645. {
    646.     exit( "<font face='verdana' size='2' color='darkred'><b>Error!</b> Direct initialization of this file is not allowed.</font>" );
    647. }
    648. ?>
     
  2. Your

    Your Старожил

    С нами с:
    2 июл 2011
    Сообщения:
    4.074
    Симпатии:
    7
    С английским совсем тяжко?
    Воспользуйся переводчиком))
    Кода очень моного, копаться лень.
     
  3. Ruffneck

    Ruffneck Новичок

    С нами с:
    14 фев 2014
    Сообщения:
    4
    Симпатии:
    0
    пхп функции разве можно переводить ?:(
     
  4. Fell-x27

    Fell-x27 Суперстар
    Команда форума Модератор

    С нами с:
    25 июл 2013
    Сообщения:
    12.156
    Симпатии:
    1.771
    Адрес:
    :сердА
    Это перевести не пробовал? А еще там должно быть написано, в каком файле ошибка и в какой строке.
     
  5. Ruffneck

    Ruffneck Новичок

    С нами с:
    14 фев 2014
    Сообщения:
    4
    Симпатии:
    0
    не пишет в каком файле и строке !

    Код (Text):
    1. $this->info = $this->torrent->get_value('info');
    2.         if ( !$this->info )
    3.         {
    4.             $this->error = 'Could not find info dictionary.';
    5.             return false;
    6.         }
     
  6. Ke1eth

    Ke1eth Активный пользователь

    С нами с:
    16 мар 2012
    Сообщения:
    1.073
    Симпатии:
    11
    Адрес:
    заблудилса
    Код (PHP):
    1. $this->info = $this->torrent->get_value('info'); 
    Вот тут и разбирайся, почему info пустое получается.
     
  7. Ruffneck

    Ruffneck Новичок

    С нами с:
    14 фев 2014
    Сообщения:
    4
    Симпатии:
    0
    если бы я знал пхп я бы не просил помощи !:(