public static function createTorrent($torrent, $hash)
{
global $saveUploadedTorrents;
$torrent = new Torrent($torrent);
if ($torrent->errors()) {
return self::STE_DELETED;
}
if ($torrent->hash_info() == $hash) {
return self::STE_UPTODATE;
}
$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()) {
return null;
}
}
}
return self::STE_ERROR;
}