//removes everything after yEnc in subject $partless = preg_replace('/(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?(\\(\\d+\\/\\d+\\))?$/', 'yEnc', $firstname['0']); $partless = preg_replace('/yEnc.*?$/i', 'yEnc', $partless); $subject = utf8_encode(trim($partless)); // Make a fake message object to use to check the blacklist. $msg = array("Subject" => $subject, "From" => $fromname, "Message-ID" => ""); // Groups. $groupArr = []; foreach ($file->groups->group as $group) { $group = (string) $group; if (array_key_exists($group, $siteGroups)) { $groupName = $group; $groupID = $siteGroups[$group]; } $groupArr[] = $group; if ($binaries->isBlacklisted($msg, $group)) { $isBlackListed = true; } } if ($groupID != -1 && !$isBlackListed) { if ($usenzbname) { $usename = str_replace(array('.nzb.gz', '.nzb'), '', basename($nzbFile)); } if (count($file->segments->segment) > 0) { foreach ($file->segments->segment as $segment) { $size = $segment->attributes()->bytes; $totalsize = $totalsize + $size; } } } else { if ($isBlackListed) {
/** * @param object $nzbXML Reference of simpleXmlObject with NZB contents. * @param bool|string $useNzbName Use the NZB file name as release name? * @return bool * * @access protected */ protected function scanNZBFile(&$nzbXML, $useNzbName = false) { $totalFiles = $totalSize = $groupID = 0; $isBlackListed = $groupName = $firstName = $posterName = $postDate = false; // Go through the NZB, get the details, look if it's blacklisted, look if we have the groups. foreach ($nzbXML->file as $file) { $totalFiles++; $groupID = -1; // Get the nzb info. if ($firstName === false) { $firstName = (string) $file->attributes()->subject; } if ($posterName === false) { $posterName = (string) $file->attributes()->poster; } if ($postDate === false) { $postDate = date("Y-m-d H:i:s", (string) $file->attributes()->date); } // Make a fake message array to use to check the blacklist. $msg = ["Subject" => (string) $file->attributes()->subject, "From" => (string) $file->attributes()->poster, "Message-ID" => ""]; // Get the group names, group_id, check if it's blacklisted. $groupArr = []; foreach ($file->groups->group as $group) { $group = (string) $group; // If group_id is -1 try to get a group_id. if ($groupID === -1) { if (array_key_exists($group, $this->allGroups)) { $groupID = $this->allGroups[$group]; if (!$groupName) { $groupName = $group; } } else { $groupID = $this->groups->add(['name' => $group, 'description' => 'Added by NZBimport script.', 'backfill_target' => 0, 'first_record' => 0, 'last_record' => 0, 'active' => 0, 'backfill' => 0]); $this->allGroups[$group] = $groupID; $this->echoOut("Adding missing group: ({$group})"); } } // Add all the found groups to an array. $groupArr[] = $group; // Check if this NZB is blacklisted. if ($this->binaries->isBlacklisted($msg, $group)) { $isBlackListed = true; break; } } // If we found a group and it's not blacklisted. if ($groupID !== -1 && !$isBlackListed) { // Get the size of the release. if (count($file->segments->segment) > 0) { foreach ($file->segments->segment as $segment) { $totalSize += (int) $segment->attributes()->bytes; } } } else { if ($isBlackListed) { $errorMessage = "Subject is blacklisted: " . utf8_encode(trim($firstName)); } else { $errorMessage = "No group found for " . $firstName . " (one of " . implode(', ', $groupArr) . " are missing"; } $this->echoOut($errorMessage); return false; } } // Try to insert the NZB details into the DB. return $this->insertNZB(['subject' => $firstName, 'useFName' => $useNzbName, 'postDate' => empty($postDate) ? date("Y-m-d H:i:s") : $postDate, 'from' => empty($posterName) ? '' : $posterName, 'groupid' => $groupID, 'groupName' => $groupName, 'totalFiles' => $totalFiles, 'totalSize' => $totalSize]); }