comment() публичный Метод

Getter and setter of torrent comment
public comment ( $comment = null ) : string | null
Результат string | null comment or null if not set
Пример #1
0
 $path_edit = trim($request['path_edit']);
 $piece_size = $request['piece_size'];
 $callback_log = create_function('$msg', '$fp=fopen("php://stdout","w"); fputs($fp, $msg."\\n"); fclose($fp);');
 $callback_err = create_function('$msg', '$fp=fopen("php://stderr","w"); fputs($fp, $msg."\\n"); fclose($fp);');
 if (count($announce_list) > 0) {
     $torrent = new Torrent($path_edit, $announce_list[0][0], $piece_size, $callback_log, $callback_err);
     if ($trackersCount > 1) {
         $torrent->announce_list($announce_list);
     }
 } else {
     $torrent = new Torrent($path_edit, array(), $piece_size, $callback_log, $callback_err);
 }
 if (isset($request['comment'])) {
     $comment = trim($request['comment']);
     if (strlen($comment)) {
         $torrent->comment($comment);
     }
 }
 if ($request['private']) {
     $torrent->is_private(true);
 }
 $fname = rTask::formatPath($taskNo) . '/result.torrent';
 $torrent->save($fname);
 if ($request['start_seeding']) {
     $fname = getUniqueUploadedFilename($torrent->info['name'] . '.torrent');
     $path_edit = trim($request['path_edit']);
     if (is_dir($path_edit)) {
         $path_edit = addslash($path_edit);
     }
     if (rTorrentSettings::get()->correctDirectory($path_edit)) {
         $path_edit = dirname($path_edit);
Пример #2
0
 public static function run_ex($hash, $fname)
 {
     $torrent = new Torrent($fname);
     if (!$torrent->errors()) {
         foreach (self::$TRACKERS as $key => $value) {
             if (preg_match($key, $torrent->comment())) {
                 return call_user_func($value, $torrent->comment(), $hash, $torrent);
             }
         }
     }
     return self::STE_NOT_NEED;
 }
Пример #3
0
 public function download()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_tracker');
     $torrent_id = $this->getState('torrent.id');
     $db = $this->getDbo();
     $user = JFactory::getUser();
     $config = new JConfig();
     if ($user->get('guest') && $params->get('allow_guest') == 0 || !TrackerHelper::user_permissions('download_torrents', $user->id)) {
         echo "<script> alert(\"" . JText::_("COM_TRACKER_USER_CANNOT_DOWNLOAD_TORRENT") . "\"); window.history.go(-1);</script>\n";
         return;
     }
     # Get the total number of records
     $query = $db->getQuery(true);
     $query->select('count(*)');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $total = $db->loadResult();
     if (!$total) {
         echo "<script> alert('" . JText::_('COM_TRACKER_INVALID_TORRENT') . "'); window.history.go(-1);</script>\n";
         return;
     }
     // All OK so far, let's continue
     # Get the torrent
     $query->clear();
     $query->select('*');
     $query->from('#__tracker_torrents');
     $query->where('fid = ' . (int) $torrent_id);
     $db->setQuery($query);
     $row = $db->loadObjectList();
     $row = $row[0];
     $torrentfile = $row->fid . "_" . $row->filename;
     if (!is_file(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_DOESNT_EXIST') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     if (!is_readable(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile)) {
         echo "<script> alert(\"" . JText::_('COM_TRACKER_FILE_ISNT_READABLE') . "\"); window.history.go(-1);</script>\n";
         exit;
     }
     clearstatcache();
     # Get the xbt tracker config
     $query->clear();
     $query->select('name, value');
     $query->from('xbt_config');
     $db->setQuery($query);
     $tracker = $db->loadObjectList('name');
     // ###############################################################################################################################
     // New Torrent pass version use
     // ###############################################################################################################################
     $uid = $user->id;
     $torrent_pass_private_key = $tracker['torrent_pass_private_key']->value;
     # Get the user torrent pass version
     $query->clear();
     $query->select('torrent_pass_version');
     $query->from('#__tracker_users');
     $query->where('id = ' . $user->id);
     $db->setQuery($query);
     $torrent_pass_version = $db->loadResult();
     $torrent = new Torrent(JPATH_SITE . DS . $params->get('torrent_dir') . $torrentfile);
     // ###############################################################################################################################
     // reset announce trackers
     $torrent->announce(false);
     // Private Torrents
     if ($params->get('make_private') == 1 && !$torrent->is_private()) {
         $torrent->is_private(true);
     }
     // Generate the new torrent passkey from the newly modified torrent
     $torrent_pass = sprintf('%08x%s', $user->id, substr(sha1(sprintf('%s %d %d %s', $torrent_pass_private_key, $torrent_pass_version, $user->id, pack('H*', $torrent->hash_info()))), 0, 24));
     // Check if we have several trackers
     if ($params->get('trackers_address') == '') {
         $announceurl = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
         // adds the default "site" tracker
         $torrent->announce($announceurl);
     } else {
         $trackers_address = explode(",", $params->get('trackers_address'));
         $trackers_address = str_replace(" ", "", $trackers_address);
         for ($i = 0; $i < count($trackers_address); $i++) {
             $other_trackers = 'http://' . $trackers_address[$i] . ':' . $tracker['listen_port']->value . '/' . $torrent_pass . '/announce';
             $torrent->announce($other_trackers);
         }
     }
     // Put some comment in the torrent
     $torrent->comment('Torrent downloaded from ' . $config->sitename);
     // If we have tags enabled, put the site name in a Tag and send the torrent filename
     if ($params->get('tag_in_torrent') == 1) {
         $torrent->send('[' . $config->sitename . ']' . $row->name . '.torrent');
     } else {
         $torrent->send();
     }
 }
Пример #4
0
function rtAddTorrent($fname, $isStart, $directory, $label, $dbg = false)
{
    if ($isStart) {
        $method = 'load_start_verbose';
    } else {
        $method = 'load_verbose';
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "1" . $fname);
    }
    $torrent = new Torrent($fname);
    if ($dbg) {
        rtDbg(__FUNCTION__, "2");
    }
    if ($torrent->errors()) {
        if ($dbg) {
            rtDbg(__FUNCTION__, "fail to create Torrent() object");
        }
        return false;
    }
    if ($directory && strlen($directory) > 0) {
        $directory = rtMakeStrParam("d.set_directory=\"" . $directory . "\"");
    } else {
        $directory = "";
    }
    $comment = $torrent->comment();
    if ($comment && strlen($comment) > 0) {
        if (isInvalidUTF8($comment)) {
            $comment = win2utf($comment);
        }
        if (strlen($comment) > 0) {
            $comment = rtMakeStrParam("d.set_custom2=VRS24mrker" . rawurlencode($comment));
            if (strlen($comment) > 4096) {
                $comment = '';
            }
        }
    } else {
        $comment = "";
    }
    if ($label && strlen($label) > 0) {
        $label = rtMakeStrParam("d.set_custom1=\"" . rawurlencode($label) . "\"");
    } else {
        $label = "";
    }
    $addition = "";
    global $saveUploadedTorrents;
    $delete_tied = $saveUploadedTorrents ? "" : rtMakeStrParam("d.delete_tied=");
    $content = '<?xml version="1.0" encoding="UTF-8"?>' . '<methodCall>' . '<methodName>' . $method . '</methodName>' . '<params>' . '<param><value><string>' . $fname . '</string></value></param>' . $directory . $comment . $label . $addition . $delete_tied . '</params></methodCall>';
    //if( $dbg ) rtDbg( __FUNCTION__, $content );
    $res = rXMLRPCRequest::send($content);
    if ($dbg && !empty($res)) {
        rtDbg(__FUNCTION__, $res);
    }
    if (!$res || ($res = '')) {
        return false;
    } else {
        return $torrent->hash_info();
    }
}
Пример #5
0
require_once 'Torrent.class.php';
// create torrent
$torrent = new Torrent('./torrents', 'http://torrent.tracker/annonce');
if (!($error = $torrent->error())) {
    $torrent->save('test.torrent');
    // save to disk
} else {
    echo '<br>DEBUG: ', $error;
    // error method return the last error message
}
// print torrent info
$torrent = new Torrent('./test.torrent');
echo '<pre>private: ', $torrent->is_private() ? 'yes' : 'no', '<br>annonce: ';
var_dump($torrent->announce());
echo '<br>name: ', $torrent->name(), '<br>comment: ', $torrent->comment(), '<br>piece_length: ', $torrent->piece_length(), '<br>size: ', $torrent->size(2), '<br>hash info: ', $torrent->hash_info(), '<br>stats: ';
var_dump($torrent->scrape());
echo '<br>content: ';
var_dump($torrent->content());
echo '<br>source: ', $torrent;
// modify torrent
$torrent->announce('http://alternate-torrent.tracker/annonce');
// add a tracker
$torrent->announce(false);
// reset announce trackers
$torrent->announce(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce'));
// set tracker(s), it also works with a 'one tracker' array...
$torrent->announce(array(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce'), 'http://another-torrent.tracker/annonce'));
// set tiered trackers
$torrent->comment('hello world');
$torrent->name('test torrent');
Пример #6
0
 public static function run($hash, $state = null, $time = null, $successful_time = null)
 {
     global $saveUploadedTorrents;
     if (is_null($state)) {
         self::getState($hash, $state, $time, $successful_time);
     }
     if ($state == self::STE_INPROGRESS && time() - $time > self::MAX_LOCK_TIME) {
         $state = 0;
     }
     if ($state != self::STE_INPROGRESS) {
         $state = self::STE_INPROGRESS;
         if (!self::setState($hash, $state)) {
             return false;
         }
         $fname = rTorrentSettings::get()->session . $hash . ".torrent";
         if (is_readable($fname)) {
             $torrent = new Torrent($fname);
             if (!$torrent->errors()) {
                 if (preg_match('`^http://(?P<tracker>rutracker)\\.org/forum/viewtopic\\.php\\?t=(?P<id>\\d+)$`', $torrent->comment(), $matches) || preg_match('`^http://(?P<tracker>kinozal)\\.tv/details\\.php\\?id=(?P<id>\\d+)$`', $torrent->comment(), $matches)) {
                     if ($matches["tracker"] == "rutracker") {
                         $client = self::makeClient($torrent->comment());
                         if ($client->status == 200 && preg_match("`ajax.form_token\\s*=\\s*'(?P<form_token>[^']+)';.*topic_id\\s*:\\s*(?P<topic_id>\\d+),\\s*t_hash\\s*:\\s*'(?P<t_hash>[^']+)'`s", $client->results, $matches1)) {
                             $client->setcookies();
                             $client->fetch("http://rutracker.org/forum/ajax.php", "POST", "application/x-www-form-urlencoded; charset=UTF-8", "action=get_info_hash" . "&topic_id=" . $matches1["topic_id"] . "&t_hash=" . $matches1["t_hash"] . "&form_token=" . $matches1["form_token"]);
                             if ($client->status == 200) {
                                 $ret = json_decode($client->results, true);
                                 if ($ret && array_key_exists("ih_hex", $ret) && strtoupper($ret["ih_hex"]) == $hash) {
                                     self::setState($hash, self::STE_UPTODATE);
                                     return true;
                                 }
                             }
                         }
                         $client->setcookies();
                         $client->fetchComplex("http://dl.rutracker.org/forum/dl.php?t=" . $matches["id"]);
                     } else {
                         if ($matches["tracker"] == "kinozal") {
                             $client = self::makeClient("http://kinozal.tv/get_srv_details.php?action=2&id=" . $matches["id"]);
                             if ($client->status == 200 && preg_match('`<li>.*(?P<hash>[0-9A-Fa-f]{40})</li>`', $client->results, $matches1)) {
                                 if (strtoupper($matches1["hash"]) == $hash) {
                                     self::setState($hash, self::STE_UPTODATE);
                                     return true;
                                 }
                             }
                             $client->setcookies();
                             $client->fetchComplex("http://dl.kinozal.tv/download.php?id=" . $matches["id"]);
                         } else {
                             self::setState($hash, self::STE_NOT_NEED);
                             return true;
                         }
                     }
                     if ($client->status == 200) {
                         $torrent = new Torrent($client->results);
                         if (!$torrent->errors()) {
                             if ($torrent->hash_info() != $hash) {
                                 $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_directory_base", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_throttle_name", $hash), new rXMLRPCCommand("d.get_connection_seed", $hash), new rXMLRPCCommand("d.is_open", $hash), new rXMLRPCCommand("d.is_active", $hash), new rXMLRPCCommand("d.get_state", $hash), new rXMLRPCCommand("d.stop", $hash), new rXMLRPCCommand("d.close", $hash)));
                                 if ($req->success()) {
                                     $addition = array(getCmd("d.set_connection_seed=") . $req->val[3], getCmd("d.set_custom") . "=chk-state," . self::STE_UPDATED, getCmd("d.set_custom") . "=chk-time," . time(), getCmd("d.set_custom") . "=chk-stime," . time());
                                     $isStart = $req->val[4] != 0 && $req->val[5] != 0 && $req->val[6] != 0;
                                     if (!empty($req->val[2])) {
                                         $addition[] = getCmd("d.set_throttle_name=") . $req->val[2];
                                     }
                                     if (preg_match('/rat_(\\d+)/', $req->val[3], $ratio)) {
                                         $addition[] = getCmd("view.set_visible=") . "rat_" . $ratio;
                                     }
                                     $label = rawurldecode($req->val[1]);
                                     if (rTorrent::sendTorrent($torrent, $isStart, false, $req->val[0], $label, $saveUploadedTorrents, false, true, $addition)) {
                                         $req = new rXMLRPCRequest(new rXMLRPCCommand("d.erase", $hash));
                                         if ($req->success()) {
                                             $state = null;
                                         }
                                     }
                                 }
                             } else {
                                 $state = self::STE_UPTODATE;
                             }
                         } else {
                             $state = self::STE_DELETED;
                         }
                     } else {
                         $state = $client->status < 0 ? self::STE_CANT_REACH_TRACKER : self::STE_DELETED;
                     }
                 } else {
                     $state = self::STE_NOT_NEED;
                 }
             }
         }
         if ($state == self::STE_INPROGRESS) {
             $state == self::STE_ERROR;
         }
         if (!is_null($state)) {
             self::setState($hash, $state);
         }
     }
     return $state != self::STE_CANT_REACH_TRACKER;
 }