public static function sendTorrent($fname, $isStart, $directory = null) { $hash = false; $torrent = is_object($fname) ? $fname : new \model\simple\Torrent($fname); if (!$torrent->errors()) { $raw_value = base64_encode($torrent->__toString()); $filename = is_object($fname) ? $torrent->getFileName() : $fname; if (strlen($raw_value) < self::RTORRENT_PACKET_LIMIT || is_null($filename)) { $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.raw_start' : 'load.raw'); $cmd->addParameter(""); $cmd->addParameter($raw_value, "base64"); if (!is_null($filename) && !true) { @unlink($filename); } } else { $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.start' : 'load.normal'); $cmd->addParameter(""); $cmd->addParameter($filename); } if (!is_null($filename) && rTorrentSettings::get(\config\Conf::$userscgi)->iVersion >= 0x805) { $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.custom.set") . "=x-filename," . rawurlencode(basename($filename))); } $req = new rXMLRPCRequest(\config\Conf::$userscgi); $req->addCommand($cmd); if (!is_null($directory)) { $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.directory.set=") . "\"" . $directory . "\""); } if ($req->run() && !$req->fault) { $hash = $req->val; } } return $hash; }
public function __construct($user, $cmd, $args = null) { //\trigger_error("ddd"); //throw new \Exception("ddd"); $this->user = $user; $this->command = rTorrentSettings::getCmd($this->user, $cmd); $this->params = array(); if ($args !== null) { if (is_array($args)) { foreach ($args as $prm) { $this->addParameter($prm); } } else { $this->addParameter($args); } } }