/** * Initiate class vars when writing NZB's. * * @param int $groupID * * @access public */ public function initiateForWrite($groupID) { $this->groupid = $groupID; // Set table names if ($this->tablePerGroup === true) { if ($this->groupid == '') { exit("{$this->groupid} is missing\n"); } $bName = 'binaries_' . $this->groupid; $pName = 'parts_' . $this->groupid; } else { $bName = 'binaries'; $pName = 'parts'; } $this->_binariesQuery = sprintf('SELECT %s.*, UNIX_TIMESTAMP(%s.date) AS udate, groups.name AS groupname FROM %s INNER JOIN groups ON %s.groupid = groups.id WHERE %s.releaseid = ', $bName, $bName, $bName, $bName, $bName); $this->_partsQuery = 'SELECT DISTINCT(messageid), size, partnumber FROM ' . $pName . ' WHERE binaryid = %d ORDER BY partnumber'; $this->_nzbHeadString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n<!-- NZB Generated by: newznab " . $this->pdo->version() . ' ' . htmlspecialchars(date('F j, Y, g:i a O'), ENT_QUOTES, 'utf-8') . " -->\n<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n<head>\n <meta type=\"category\">%s</meta>\n <meta type=\"name\">%s</meta>\n</head>\n\n"; }
public function encodePost($message, $reftime = Null, $debug = False, $prvkey = Null, $passphrase = Null, $encrypt = True, $msgtype = SpotNab::FETCH_COMMENT_TYPE, $user = Null, $email = Null, $group = Null) { /* Assembles and encodes a message ready to be posted onto a usenet server. false is returned if the function fails, If a reftime is specified, it is presumed that it will be in an integer format and it will be localtime If the debug is set to true, then a third part of the article is returned containing header information that would look as though _get_header() returned it */ // Assumed to be in Y-m-d H:i:s format or int // convert local time into UTC $reftime = $this->local2utc($reftime, "YmdHis"); $s = new Settings(); $msgid = sprintf('<%s.%s.%d@%s>', $this->getRandomStr(30), $msgtype, time(), SpotNab::SEGID_DOMAIN); if (!is_string($message)) { // If message is not already in string format, then // it's in it's assembled mixed array format... we // need to convert it to json before proceeding $message = json_encode($message, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); if ($message === false) { // Fail return false; } } // nntp posting expects an array as follows: // array( // [0] => 'Message Header' // [1] => 'Message Body' // ); if ($encrypt) { // Encrypt Message $message = $this->encrypt($message, $prvkey, $passphrase); if ($message === false) { // fail return false; } } else { // Convert to base64 $message = base64_encode($message); } // Compress Messsage $message = @gzcompress($message, 9); // Yenc Binary Content $message = $this->_nntp->encodeYenc2($message, md5($message)); // // Prepare Header // // Checksum id $checksum = sha1($message); // Prepare Subject $subject = sprintf("%s-%s", $checksum, $reftime); if ($user === Null) { $user = trim($this->_post_user); } if ($email === Null) { $email = trim($this->_post_email); } if ($group === Null) { $group = trim($this->_post_group); } $header = "Subject: " . $subject . "\r\n"; $header .= "Newsgroups: " . $group . "\r\n"; $header .= "Message-ID: {$msgid}\r\n"; $header .= "X-Newsreader: NewzNab v" . $s->version() . "\r\n"; $header .= "X-No-Archive: yes\r\n"; $header .= "From: " . $user . " <" . $email . ">\r\n"; // Binary Content $header .= 'Content-Type: text/plain; charset=ISO-8859-1' . "\r\n"; $header .= 'Content-Transfer-Encoding: 8bit' . "\r\n"; // Assemble Article in structure NNTP expects $article = [$header, $message]; if ($debug) { // Append some debug data to the article $article[] = ['Number' => 1234, 'Subject' => $subject, 'From' => sprintf('%s <%s>', $user, $email), 'Date' => date(DATE_RFC822, strtotime($this->utc2local($reftime))), 'Message-ID' => $msgid, 'Bytes' => strlen($message), 'Lines' => '1', 'Epoch' => strtotime($this->utc2local($reftime)), 'Group' => $group]; } return $article; }