/** * Reset some variables for the current release. */ protected function _resetReleaseStatus() { // Only process for samples, previews and images if not disabled. $this->_foundVideo = $this->_processVideo ? false : true; $this->_foundMediaInfo = $this->_processMediaInfo ? false : true; $this->_foundAudioInfo = $this->_processAudioInfo ? false : true; $this->_foundAudioSample = $this->_processAudioSample ? false : true; $this->_foundJPGSample = $this->_processJPGSample ? false : true; $this->_foundSample = $this->_processThumbnails ? false : true; $this->_foundSample = $this->_release['disablepreview'] == 1 ? true : false; $this->_foundPAR2Info = false; $this->_passwordStatus = [Releases::PASSWD_NONE]; $this->_releaseHasPassword = false; $this->_releaseGroupName = $this->_groups->getByNameByID($this->_release['group_id']); $this->_releaseHasNoNFO = false; // Make sure we don't already have an nfo. if ($this->_release['nfostatus'] != 1) { $this->_releaseHasNoNFO = true; } $this->_NZBHasCompressedFile = false; $this->_sampleMessageIDs = $this->_JPGMessageIDs = $this->_MediaInfoMessageIDs = []; $this->_AudioInfoMessageIDs = $this->_RARFileMessageIDs = []; $this->_AudioInfoExtension = ''; $this->_addedFileInfo = 0; $this->_totalFileInfo = 0; $this->_compressedFilesChecked = 0; }
/** * Function for searching on the site (by subject, searchname or advanced). * * @param string $searchName * @param string $usenetName * @param string $posterName * @param string $groupName * @param int $sizeFrom * @param int $sizeTo * @param int $hasNfo * @param int $hasComments * @param int $daysNew * @param int $daysOld * @param int $offset * @param int $limit * @param string $orderBy * @param int $maxAge * @param integer[] $excludedCats * @param string $type * @param array $cat * * @return array */ public function search($searchName, $usenetName, $posterName, $groupName, $sizeFrom, $sizeTo, $hasNfo, $hasComments, $daysNew, $daysOld, $offset = 0, $limit = 1000, $orderBy = '', $maxAge = -1, $excludedCats = [], $type = 'basic', $cat = [-1]) { $sizeRange = [1 => 1, 2 => 2.5, 3 => 5, 4 => 10, 5 => 20, 6 => 30, 7 => 40, 8 => 80, 9 => 160, 10 => 320, 11 => 640]; if ($orderBy == '') { $orderBy = []; $orderBy[0] = 'postdate '; $orderBy[1] = 'desc '; } else { $orderBy = $this->getBrowseOrder($orderBy); } $searchOptions = []; if ($searchName != -1) { $searchOptions['searchname'] = $searchName; } if ($usenetName != -1) { $searchOptions['name'] = $usenetName; } if ($posterName != -1) { $searchOptions['fromname'] = $posterName; } $whereSql = sprintf("%s\n\t\t\tWHERE r.passwordstatus %s AND r.nzbstatus = %d %s %s %s %s %s %s %s %s %s %s %s", $this->releaseSearch->getFullTextJoinString(), $this->showPasswords(), NZB::NZB_ADDED, $maxAge > 0 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $maxAge) : '', $groupName != -1 ? sprintf(' AND r.group_id = %d ', $this->groups->getIDByName($groupName)) : '', array_key_exists($sizeFrom, $sizeRange) ? ' AND r.size > ' . (string) (104857600 * (int) $sizeRange[$sizeFrom]) . ' ' : '', array_key_exists($sizeTo, $sizeRange) ? ' AND r.size < ' . (string) (104857600 * (int) $sizeRange[$sizeTo]) . ' ' : '', $hasNfo != 0 ? ' AND r.nfostatus = 1 ' : '', $hasComments != 0 ? ' AND r.comments > 0 ' : '', $type !== 'advanced' ? $this->categorySQL($cat) : ($cat[0] != '-1' ? sprintf(' AND (r.categoryid = %d) ', $cat[0]) : ''), $daysNew != -1 ? sprintf(' AND r.postdate < (NOW() - INTERVAL %d DAY) ', $daysNew) : '', $daysOld != -1 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $daysOld) : '', count($excludedCats) > 0 ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : '', count($searchOptions) > 0 ? $this->releaseSearch->getSearchSQL($searchOptions) : ''); $baseSql = sprintf("SELECT r.*,\n\t\t\t\tCONCAT(cp.title, ' > ', c.title) AS category_name,\n\t\t\t\tCONCAT(cp.id, ',', c.id) AS category_ids,\n\t\t\t\tgroups.name AS group_name,\n\t\t\t\trn.id AS nfoid,\n\t\t\t\tre.releaseid AS reid,\n\t\t\t\tcp.id AS categoryparentid\n\t\t\tFROM releases r\n\t\t\tLEFT OUTER JOIN video_data re ON re.releaseid = r.id\n\t\t\tLEFT OUTER JOIN release_nfos rn ON rn.releaseid = r.id\n\t\t\tINNER JOIN groups ON groups.id = r.group_id\n\t\t\tINNER JOIN category c ON c.id = r.categoryid\n\t\t\tINNER JOIN category cp ON cp.id = c.parentid\n\t\t\t%s", $whereSql); $sql = sprintf("SELECT * FROM (\n\t\t\t\t%s\n\t\t\t) r\n\t\t\tORDER BY r.%s %s\n\t\t\tLIMIT %d OFFSET %d", $baseSql, $orderBy[0], $orderBy[1], $limit, $offset); $releases = $this->pdo->query($sql); if ($releases && count($releases)) { $releases[0]['_totalrows'] = $this->getPagerCount($baseSql); } return $releases; }
/** * Delete unwanted releases based on admin settings. * This deletes releases based on group. * * @param int|string $groupID (optional) * * @void * @access public */ public function deletedReleasesByGroup($groupID = '') { $startTime = time(); $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; if ($this->echoCLI) { echo $this->pdo->log->header("Process Releases -> Delete releases smaller/larger than minimum size/file count from group/site setting."); } if ($groupID == '') { $groupIDs = $this->groups->getActiveIDs(); } else { $groupIDs = [['id' => $groupID]]; } $maxSizeSetting = $this->pdo->getSetting('maxsizetoformrelease'); $minSizeSetting = $this->pdo->getSetting('minsizetoformrelease'); $minFilesSetting = $this->pdo->getSetting('minfilestoformrelease'); foreach ($groupIDs as $groupID) { $releases = $this->pdo->queryDirect(sprintf("\n\t\t\t\t\tSELECT SQL_NO_CACHE r.guid, r.id\n\t\t\t\t\tFROM releases r\n\t\t\t\t\tINNER JOIN groups g ON g.id = r.group_id\n\t\t\t\t\tWHERE r.group_id = %d\n\t\t\t\t\tAND greatest(IFNULL(g.minsizetoformrelease, 0), %d) > 0\n\t\t\t\t\tAND r.size < greatest(IFNULL(g.minsizetoformrelease, 0), %d)", $groupID['id'], $minSizeSetting, $minSizeSetting)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $minSizeDeleted++; } } if ($maxSizeSetting > 0) { $releases = $this->pdo->queryDirect(sprintf(' SELECT SQL_NO_CACHE id, guid FROM releases WHERE group_id = %d AND size > %d', $groupID['id'], $maxSizeSetting)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $maxSizeDeleted++; } } } $releases = $this->pdo->queryDirect(sprintf("\n\t\t\t\t\tSELECT SQL_NO_CACHE r.id, r.guid\n\t\t\t\t\tFROM releases r\n\t\t\t\t\tINNER JOIN groups g ON g.id = r.group_id\n\t\t\t\t\tWHERE r.group_id = %d\n\t\t\t\t\tAND greatest(IFNULL(g.minfilestoformrelease, 0), %d) > 0\n\t\t\t\t\tAND r.totalpart < greatest(IFNULL(g.minfilestoformrelease, 0), %d)", $groupID['id'], $minFilesSetting, $minFilesSetting)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage); $minFilesDeleted++; } } } if ($this->echoCLI) { $this->pdo->log->doEcho($this->pdo->log->primary('Deleted ' . ($minSizeDeleted + $maxSizeDeleted + $minFilesDeleted) . ' releases: ' . PHP_EOL . $minSizeDeleted . ' smaller than, ' . $maxSizeDeleted . ' bigger than, ' . $minFilesDeleted . ' with less files than site/groups setting in: ' . $this->consoleTools->convertTime(time() - $startTime)), true); } }
/** * Backfill all the groups up to user specified time/date. * * @param string $groupName * @param string|int $articles * @param string $type * * @return void */ public function backfillAllGroups($groupName = '', $articles = '', $type = '') { $res = []; if ($groupName !== '') { $grp = $this->_groups->getByName($groupName); if ($grp) { $res = [$grp]; } } else { if ($type === 'normal' || $type === '') { $res = $this->_groups->getActiveBackfill(); } else { if ($type === 'date') { $res = $this->_groups->getActiveByDateBackfill(); } } } $groupCount = count($res); if ($groupCount > 0) { $counter = 1; $allTime = microtime(true); $dMessage = 'Backfilling: ' . $groupCount . ' group(s) - Using compression? ' . ($this->_compressedHeaders ? 'Yes' : 'No'); if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header($dMessage), true); } $this->_binaries = new Binaries(['NNTP' => $this->_nntp, 'Echo' => $this->_echoCLI, 'Settings' => $this->pdo, 'Groups' => $this->_groups]); if ($articles !== '' && !is_numeric($articles)) { $articles = 20000; } // Loop through groups. foreach ($res as $groupArr) { if ($groupName === '') { $dMessage = "Starting group " . $counter . ' of ' . $groupCount; if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { $this->pdo->log->doEcho($this->pdo->log->header($dMessage), true); } } $this->backfillGroup($groupArr, $groupCount - $counter, $articles); $counter++; } $dMessage = 'Backfilling completed in ' . number_format(microtime(true) - $allTime, 2) . " seconds."; if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_INFO); } if ($this->_echoCLI) { $this->pdo->log->doEcho($this->pdo->log->primary($dMessage)); } } else { $dMessage = "No groups specified. Ensure groups are added to nZEDb's database for updating."; if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, $dMessage, Logger::LOG_FATAL); } if ($this->_echoCLI) { $this->pdo->log->doEcho($this->pdo->log->warning($dMessage), true); } } }
if (is_numeric($options[2])) { (new RequestIDLocal(['Echo' => true]))->lookupRequestIDs(['GroupID' => $options[2], 'limit' => 5000]); } break; /* Update a single group's article headers. * * $options[2] => (string) Group name. */ /* Update a single group's article headers. * * $options[2] => (string) Group name. */ case 'update_group_headers': $pdo = new Settings(); $nntp = nntp($pdo); $groups = new Groups(['Settings' => $pdo]); $groupMySQL = $groups->getByName($options[2]); (new Binaries(['NNTP' => $nntp, 'Groups' => $groups, 'Settings' => $pdo]))->updateGroup($groupMySQL); break; // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on // Do a single group (update_binaries/backFill/update_releases/postprocess). // $options[2] => (int)groupID, group to work on case 'update_per_group': if (is_numeric($options[2])) { $pdo = new Settings(); // Get the group info from MySQL. $groupMySQL = $pdo->queryOneRow(sprintf('SELECT * FROM groups WHERE id = %d', $options[2])); if ($groupMySQL === false) { exit('ERROR: Group not found with ID ' . $options[2] . PHP_EOL); }
<?php /* Argument 1 is optional string, group name. Or numeric, number of header max to download. * Argument 2 is optional int, max number of headers to download. */ require_once dirname(__FILE__) . '/config.php'; use nzedb\Binaries; use nzedb\Groups; use nzedb\NNTP; use nzedb\db\Settings; $pdo = new Settings(); // Create the connection here and pass $nntp = new NNTP(['Settings' => $pdo]); if ($nntp->doConnect() !== true) { exit($pdo->log->error("Unable to connect to usenet.")); } $binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]); if (isset($argv[1]) && !is_numeric($argv[1])) { $groupName = $argv[1]; echo $pdo->log->header("Updating group: {$groupName}"); $grp = new Groups(['Settings' => $pdo]); $group = $grp->getByName($groupName); if (is_array($group)) { $binaries->updateGroup($group, isset($argv[2]) && is_numeric($argv[2]) && $argv[2] > 0 ? $argv[2] : 0); } } else { $binaries->updateAllGroups(isset($argv[1]) && is_numeric($argv[1]) && $argv[1] > 0 ? $argv[1] : 0); }
<?php require_once './config.php'; use nzedb\Groups; $page = new AdminPage(); $groups = new Groups(['Settings' => $page->settings]); $gname = ""; if (isset($_REQUEST['groupname']) && !empty($_REQUEST['groupname'])) { $gname = $_REQUEST['groupname']; } $groupcount = $groups->getCountInactive($gname); $offset = isset($_REQUEST["offset"]) ? $_REQUEST["offset"] : 0; $groupname = isset($_REQUEST['groupname']) && !empty($_REQUEST['groupname']) ? $_REQUEST['groupname'] : ''; $page->smarty->assign('groupname', $groupname); $page->smarty->assign('pagertotalitems', $groupcount); $page->smarty->assign('pageroffset', $offset); $page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE); $groupsearch = $gname != "" ? 'groupname=' . $gname . '&' : ''; $page->smarty->assign('pagerquerybase', WWW_TOP . "/group-list-inactive.php?" . $groupsearch . "offset="); $pager = $page->smarty->fetch("pager.tpl"); $page->smarty->assign('pager', $pager); $grouplist = $groups->getRangeInactive($offset, ITEMS_PER_PAGE, $gname); $page->smarty->assign('grouplist', $grouplist); $page->title = "Group List"; $page->content = $page->smarty->fetch('group-list.tpl'); $page->render();
/** * Attempt to find NFO files inside the NZB's of releases. * * @param object $nntp Instance of class NNTP. * @param string $groupID (optional) Group ID. * @param string $guidChar (optional) First character of the release GUID (used for multi-processing). * @param int $processImdb (optional) Attempt to find IMDB id's in the NZB? * @param int $processTvrage (optional) Attempt to find TvRage id's in the NZB? * * @return int How many NFO's were processed? * * @access public */ public function processNfoFiles($nntp, $groupID = '', $guidChar = '', $processImdb = 1, $processTvrage = 1) { $ret = 0; $guidCharQuery = $guidChar === '' ? '' : 'AND r.guid ' . $this->pdo->likeString($guidChar, false, true); $groupIDQuery = $groupID === '' ? '' : 'AND r.group_id = ' . $groupID; $optionsQuery = self::NfoQueryString($this->pdo); $res = $this->pdo->query(sprintf(' SELECT r.id, r.guid, r.group_id, r.name FROM releases r WHERE 1=1 %s %s %s ORDER BY r.nfostatus ASC, r.postdate DESC LIMIT %d', $optionsQuery, $guidCharQuery, $groupIDQuery, $this->nzbs)); $nfoCount = count($res); if ($nfoCount > 0) { $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . ($guidChar === '' ? '' : '[' . $guidChar . '] ') . ($groupID === '' ? '' : '[' . $groupID . '] ') . 'Processing ' . $nfoCount . ' NFO(s), starting at ' . $this->nzbs . ' * = hidden NFO, + = NFO, - = no NFO, f = download failed.')); if ($this->echo) { // Get count of releases per nfo status $nfoStats = $this->pdo->queryDirect(sprintf(' SELECT r.nfostatus AS status, COUNT(*) AS count FROM releases r WHERE 1=1 %s %s %s GROUP BY r.nfostatus ORDER BY r.nfostatus ASC', $optionsQuery, $guidCharQuery, $groupIDQuery)); if ($nfoStats instanceof \Traversable) { $outString = PHP_EOL . 'Available to process'; foreach ($nfoStats as $row) { $outString .= ', ' . $row['status'] . ' = ' . number_format($row['count']); } $this->pdo->log->doEcho($this->pdo->log->header($outString . '.')); } } $groups = new Groups(['Settings' => $this->pdo]); $nzbContents = new NZBContents(['Echo' => $this->echo, 'NNTP' => $nntp, 'Nfo' => $this, 'Settings' => $this->pdo, 'PostProcess' => new PostProcess(['Echo' => $this->echo, 'Nfo' => $this, 'Settings' => $this->pdo])]); $movie = new Movie(['Echo' => $this->echo, 'Settings' => $this->pdo]); foreach ($res as $arr) { $fetchedBinary = $nzbContents->getNFOfromNZB($arr['guid'], $arr['id'], $arr['group_id'], $groups->getByNameByID($arr['group_id'])); if ($fetchedBinary !== false) { // Insert nfo into database. $cp = 'COMPRESS(%s)'; $nc = $this->pdo->escapeString($fetchedBinary); $ckreleaseid = $this->pdo->queryOneRow(sprintf('SELECT releaseid FROM release_nfos WHERE releaseid = %d', $arr['id'])); if (!isset($ckreleaseid['releaseid'])) { $this->pdo->queryInsert(sprintf('INSERT INTO release_nfos (nfo, releaseid) VALUES (' . $cp . ', %d)', $nc, $arr['id'])); } $this->pdo->queryExec(sprintf('UPDATE releases SET nfostatus = %d WHERE id = %d', self::NFO_FOUND, $arr['id'])); $ret++; $movie->doMovieUpdate($fetchedBinary, 'nfo', $arr['id'], $processImdb); // If set scan for tvrage info. Disabled for now while TvRage is down. TODO: Add Other Scraper Checks if ($processTvrage == 1) { /*$tvRage = new TvRage(['Echo' => $this->echo, 'Settings' => $this->pdo]); $showId = $this->parseShowId($fetchedBinary); if ($showId !== false) { $show = $tvRage->parseNameEpSeason($arr['name']); if (is_array($show) && $show['name'] != '') { // Update release with season, ep, and air date info (if available) from release title. $tvRage->updateEpInfo($show, $arr['id']); $rid = $tvRage->getByRageID($rageId); if (!$rid) { $tvrShow = $tvRage->getRageInfoFromService($rageId); $tvRage->updateRageInfo($rageId, $show, $tvrShow, $arr['id']); } } }*/ } } } } // Remove nfo that we cant fetch after 5 attempts. $releases = $this->pdo->queryDirect(sprintf('SELECT r.id FROM releases r WHERE r.nzbstatus = %d AND r.nfostatus < %d AND r.nfostatus > %d %s %s', NZB::NZB_ADDED, $this->maxRetries, self::NFO_FAILED, $groupIDQuery, $guidCharQuery)); if ($releases instanceof \Traversable) { foreach ($releases as $release) { // remove any release_nfos for failed $this->pdo->queryExec(sprintf(' DELETE FROM release_nfos WHERE nfo IS NULL AND releaseid = %d', $release['id'])); // set release.nfostatus to failed $this->pdo->queryExec(sprintf(' UPDATE releases r SET r.nfostatus = %d WHERE r.id = %d', self::NFO_FAILED, $release['id'])); } } if ($this->echo) { if ($nfoCount > 0) { echo PHP_EOL; } if ($ret > 0) { $this->pdo->log->doEcho($ret . ' NFO file(s) found/processed.', true); } } return $ret; }
function preName($argv, $argc) { global $pdo; $groups = new Groups(['Settings' => $pdo]); $category = new Categorize(['Settings' => $pdo]); $internal = $external = $pre = 0; $show = 2; if ($argv[$argc - 1] === 'show') { $show = 1; } else { if ($argv[$argc - 1] === 'bad') { $show = 3; } } $counter = 0; $pdo->log = new ColorCLI(); $full = $all = $usepre = false; $what = $where = ''; if ($argv[1] === 'full') { $full = true; } else { if ($argv[1] === 'all') { $all = true; } else { if ($argv[1] === 'preid') { $usepre = true; } else { if (is_numeric($argv[1])) { $what = ' AND adddate > NOW() - INTERVAL ' . $argv[1] . ' HOUR'; } } } } if ($usepre === true) { $where = ''; $why = ' WHERE preid = 0 AND nzbstatus = 1'; } else { if (isset($argv[1]) && is_numeric($argv[1])) { $where = ''; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && is_numeric($argv[2]) && $full === true) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) { $where = ' AND group_id IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) { $where = ' AND group_id IN ' . $argv[2]; $why = ' WHERE nzbstatus = 1'; } else { if (isset($argv[2]) && is_numeric($argv[2]) && $all === true) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 and preid = 0'; } else { if (isset($argv[2]) && is_numeric($argv[2])) { $where = ' AND group_id = ' . $argv[2]; $why = ' WHERE nzbstatus = 1 AND isrenamed = 0'; } else { if ($full === true) { $why = ' WHERE nzbstatus = 1 AND (isrenamed = 0 OR categoryid between 7000 AND 7999)'; } else { if ($all === true) { $why = ' WHERE nzbstatus = 1'; } else { $why = ' WHERE 1=1'; } } } } } } } } } resetSearchnames(); echo $pdo->log->header("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where . ";\n"); $res = $pdo->queryDirect("SELECT id, name, searchname, fromname, size, group_id, categoryid FROM releases" . $why . $what . $where); $total = $res->rowCount(); if ($total > 0) { $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); foreach ($res as $row) { $groupname = $groups->getByNameByID($row['group_id']); $cleanerName = releaseCleaner($row['name'], $row['fromname'], $row['size'], $groupname, $usepre); $preid = 0; $predb = $predbfile = $increment = false; if (!is_array($cleanerName)) { $cleanName = trim((string) $cleanerName); $propername = $increment = true; if ($cleanName != '' && $cleanerName != false) { $run = $pdo->queryOneRow("SELECT id FROM predb WHERE title = " . $pdo->escapeString($cleanName)); if (isset($run['id'])) { $preid = $run['id']; $predb = true; } } } else { $cleanName = trim($cleanerName["cleansubject"]); $propername = $cleanerName["properlynamed"]; if (isset($cleanerName["increment"])) { $increment = $cleanerName["increment"]; } if (isset($cleanerName["predb"])) { $preid = $cleanerName["predb"]; $predb = true; } } if ($cleanName != '') { if (preg_match('/alt\\.binaries\\.e\\-?book(\\.[a-z]+)?/', $groupname)) { if (preg_match('/^[0-9]{1,6}-[0-9]{1,6}-[0-9]{1,6}$/', $cleanName, $match)) { $rf = new ReleaseFiles($pdo); $files = $rf->get($row['id']); foreach ($files as $f) { if (preg_match('/^(?P<title>.+?)(\\[\\w\\[\\]\\(\\). -]+)?\\.(pdf|htm(l)?|epub|mobi|azw|tif|doc(x)?|lit|txt|rtf|opf|fb2|prc|djvu|cb[rz])/', $f["name"], $match)) { $cleanName = $match['title']; break; } } } } //try to match clean name against predb filename $prefile = $pdo->queryOneRow("SELECT id, title FROM predb WHERE filename = " . $pdo->escapeString($cleanName)); if (isset($prefile['id'])) { $preid = $prefile['id']; $cleanName = $prefile['title']; $predbfile = true; $propername = true; } if ($cleanName != $row['name'] && $cleanName != $row['searchname']) { if (strlen(utf8_decode($cleanName)) <= 3) { } else { $determinedcat = $category->determineCategory($row["group_id"], $cleanName); if ($propername == true) { $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, " . "iscategorized = 1, isrenamed = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id'])); } else { $pdo->queryExec(sprintf("UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, " . "iscategorized = 1, searchname = %s, categoryid = %d, preid = " . $preid . " WHERE id = %d", $pdo->escapeString($cleanName), $determinedcat, $row['id'])); } if ($increment === true) { $internal++; } else { if ($predb === true) { $pre++; } else { if ($predbfile === true) { $pre++; } else { if ($propername === true) { $external++; } } } } if ($show === 1) { $oldcatname = $category->getNameByID($row["categoryid"]); $newcatname = $category->getNameByID($determinedcat); NameFixer::echoChangedReleaseName(['new_name' => $cleanName, 'old_name' => $row["searchname"], 'new_category' => $newcatname, 'old_category' => $oldcatname, 'group' => $groupname, 'release_id' => $row["id"], 'method' => 'misc/testing/Various/renametopre.php']); } } } else { if ($show === 3 && preg_match('/^\\[?\\d*\\].+?yEnc/i', $row['name'])) { echo $pdo->log->primary($row['name']); } } } if ($cleanName == $row['name']) { $pdo->queryExec(sprintf("UPDATE releases SET isrenamed = 1, iscategorized = 1 WHERE id = %d", $row['id'])); } if ($show === 2 && $usepre === false) { $consoletools->overWritePrimary("Renamed Releases: [Internal=" . number_format($internal) . "][External=" . number_format($external) . "][Predb=" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total)); } else { if ($show === 2 && $usepre === true) { $consoletools->overWritePrimary("Renamed Releases: [" . number_format($pre) . "] " . $consoletools->percentString(++$counter, $total)); } } } } echo $pdo->log->header("\n" . number_format($pre) . " renamed using preDB Match\n" . number_format($external) . " renamed using ReleaseCleaning.php\n" . number_format($internal) . " using renametopre.php\nout of " . number_format($total) . " releases.\n"); if (isset($argv[1]) && is_numeric($argv[1]) && !isset($argv[2])) { echo $pdo->log->header("Categorizing all releases using searchname from the last {$argv[1]} hours. This can take a while, be patient."); } else { if (isset($argv[1]) && $argv[1] !== "all" && isset($argv[2]) && !is_numeric($argv[2]) && !preg_match('/\\([\\d, ]+\\)/', $argv[2])) { echo $pdo->log->header("Categorizing all non-categorized releases in other->misc using searchname. This can take a while, be patient."); } else { if (isset($argv[1]) && isset($argv[2]) && (is_numeric($argv[2]) || preg_match('/\\([\\d, ]+\\)/', $argv[2]))) { echo $pdo->log->header("Categorizing all non-categorized releases in {$argv[2]} using searchname. This can take a while, be patient."); } else { echo $pdo->log->header("Categorizing all releases using searchname. This can take a while, be patient."); } } } $timestart = TIME(); if (isset($argv[1]) && is_numeric($argv[1])) { $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $full === true) { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true); } else { if (isset($argv[2]) && preg_match('/\\([\\d, ]+\\)/', $argv[2]) && $all === true) { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true); } else { if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "full") { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where) . " AND iscategorized = 0 ", true); } else { if (isset($argv[2]) && is_numeric($argv[2]) && $argv[1] == "all") { $relcount = catRelease("searchname", str_replace(" AND", "WHERE", $where), true); } else { if (isset($argv[1]) && $argv[1] == "full") { $relcount = catRelease("searchname", "WHERE categoryID = 0010 OR iscategorized = 0", true); } else { if (isset($argv[1]) && $argv[1] == "all") { $relcount = catRelease("searchname", "", true); } else { if (isset($argv[1]) && $argv[1] == "preid") { $relcount = catRelease("searchname", "WHERE preid = 0 AND nzbstatus = 1", true); } else { $relcount = catRelease("searchname", "WHERE (iscategorized = 0 OR categoryID = 0010) AND adddate > NOW() - INTERVAL " . $argv[1] . " HOUR", true); } } } } } } } } $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $time = $consoletools->convertTime(TIME() - $timestart); echo $pdo->log->header("Finished categorizing " . number_format($relcount) . " releases in " . $time . " seconds, using the usenet subject.\n"); resetSearchnames(); }
/** * Returns unix time for an article number. * * @param int $post The article number to get the time from. * @param array $groupData Usenet group info from NNTP selectGroup method. * * @return int Timestamp. */ public function postdate($post, array $groupData) { // Set table names $groupID = $this->_groups->getIDByName($groupData['group']); $group = []; if ($groupID !== '') { $group = $this->_groups->getCBPTableNames($this->_tablePerGroup, $groupID); } $currentPost = $post; $attempts = $date = 0; do { // Try to get the article date locally first. if ($groupID !== '') { // Try to get locally. $local = $this->_pdo->queryOneRow(sprintf(' SELECT c.date AS date FROM %s c INNER JOIN %s b ON(c.id=b.collection_id) INNER JOIN %s p ON(b.id=p.binaryid) WHERE p.number = %s %s LIMIT 1', $group['cname'], $group['bname'], $group['pname'], $currentPost, $this->_tablePerGroup === false ? sprintf('AND c.group_id = %d', $groupID) : '')); if ($local !== false) { $date = $local['date']; break; } } // If we could not find it locally, try usenet. $header = $this->_nntp->getXOVER($currentPost); if (!$this->_nntp->isError($header)) { // Check if the date is set. if (isset($header[0]['Date']) && strlen($header[0]['Date']) > 0) { $date = $header[0]['Date']; break; } } // Try to get a different article number. if (abs($currentPost - $groupData['first']) > abs($groupData['last'] - $currentPost)) { $tempPost = round($currentPost / (mt_rand(1005, 1012) / 1000), 0, PHP_ROUND_HALF_UP); if ($tempPost < $groupData['first']) { $tempPost = $groupData['first']; } } else { $tempPost = round(mt_rand(1005, 1012) / 1000 * $currentPost, 0, PHP_ROUND_HALF_UP); if ($tempPost > $groupData['last']) { $tempPost = $groupData['last']; } } // If we got the same article number as last time, give up. if ($tempPost === $currentPost) { break; } $currentPost = $tempPost; if ($this->_debug) { $this->_colorCLI->doEcho($this->_colorCLI->debug('Postdate retried ' . $attempts . " time(s).")); } } while ($attempts++ <= 20); // If we didn't get a date, set it to now. if (!$date) { $date = time(); } else { $date = strtotime($date); } if ($this->_debug) { $this->_debugging->log(get_class(), __FUNCTION__, 'Article (' . $post . "'s) date is (" . $date . ') (' . $this->daysOld($date) . " days old)", Logger::LOG_INFO); } return $date; }
<?php require_once './config.php'; use nzedb\Groups; $page = new AdminPage(); $groups = new Groups(['Settings' => $page->settings]); $groupName = isset($_REQUEST['groupname']) && !empty($_REQUEST['groupname']) ? $_REQUEST['groupname'] : ''; $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0; $page->smarty->assign(['groupname' => $groupName, 'pagertotalitems' => $groups->getCount($groupName), 'pageroffset' => $offset, 'pageritemsperpage' => ITEMS_PER_PAGE, 'pagerquerybase' => WWW_TOP . "/group-list.php?" . ($groupName != '' ? "groupname={$groupName}&" : '') . 'offset=', 'pagerquerysuffix' => '', 'grouplist' => $groups->getRange($offset, ITEMS_PER_PAGE, $groupName)]); $page->smarty->assign('pager', $page->smarty->fetch('pager.tpl')); $page->title = 'Group List'; $page->content = $page->smarty->fetch('group-list.tpl'); $page->render();
<?php require_once './config.php'; use nzedb\Groups; $page = new AdminPage(); $groups = new Groups(['Settings' => $page->settings]); $id = 0; // Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; switch ($action) { case 'submit': if ($_POST["id"] == "") { // Add a new group. $groups->add($_POST); } else { // Update an existing group. $groups->update($_POST); } header("Location:" . WWW_TOP . "/group-list.php"); break; case 'view': default: if (isset($_GET["id"])) { $page->title = "Newsgroup Edit"; $id = $_GET["id"]; $group = $groups->getByID($id); } else { $page->title = "Newsgroup Add"; $group = ['id' => '', 'name' => '', 'description' => '', 'minfilestoformrelease' => 0, 'active' => 0, 'backfill' => 0, 'minsizetoformrelease' => 0, 'first_record' => 0, 'last_record' => 0, 'backfill_target' => 0]; } $page->smarty->assign('group', $group);
<?php use nzedb\Category; use nzedb\Groups; use nzedb\ReleaseSearch; use nzedb\Releases; if (!$page->users->isLoggedIn()) { $page->show403(); } $groups = new Groups(['Settings' => $page->settings]); $releases = new Releases(['Groups' => $groups, 'Settings' => $page->settings]); $page->meta_title = "Search Nzbs"; $page->meta_keywords = "search,nzb,description,details"; $page->meta_description = "Search for Nzbs"; $results = []; $searchType = "basic"; if (isset($_REQUEST["search_type"]) && $_REQUEST["search_type"] == "adv") { $searchType = "advanced"; } $ordering = $releases->getBrowseOrdering(); $orderBy = isset($_REQUEST["ob"]) && in_array($_REQUEST['ob'], $ordering) ? $_REQUEST["ob"] : ''; $offset = isset($_REQUEST["offset"]) && ctype_digit($_REQUEST['offset']) ? $_REQUEST["offset"] : 0; $page->smarty->assign(['subject' => '', 'search' => '', 'category' => [0], 'pagertotalitems' => 0, 'pageritemsperpage' => 1, 'pageroffset' => 1, 'covgroup' => '']); if ((isset($_REQUEST["id"]) || isset($_REQUEST["subject"])) && !isset($_REQUEST["searchadvr"]) && $searchType == "basic") { $searchString = ''; switch (true) { case isset($_REQUEST["subject"]): $searchString = (string) $_REQUEST["subject"]; $page->smarty->assign('subject', $searchString); break; case isset($_REQUEST["id"]):
/** * Test a single release naming regex for a group name. * * @param string $groupName * @param string $regex * @param int $displayLimit * @param int $queryLimit * * @return array */ public function testReleaseNamingRegex($groupName, $regex, $displayLimit, $queryLimit) { $groups = new Groups(['Settings' => $this->pdo]); $groupID = $groups->getIDByName($groupName); if (!$groupID) { return []; } $rows = $this->pdo->query(sprintf('SELECT name, searchname, id FROM releases WHERE group_id = %d LIMIT %d', $groupID, $queryLimit)); $data = []; if ($rows) { $limit = 1; foreach ($rows as $row) { $match = $this->_matchRegex($regex, $row['name']); if ($match) { $data[$row['id']] = ['subject' => $row['name'], 'old_name' => $row['searchname'], 'new_name' => $match]; if ($limit++ > $displayLimit) { break; } } } } return $data; }
/** * Attempt to get a better name from a par2 file and categorize the release. * * @note Called from NZBContents.php * * @param string $messageID MessageID from NZB file. * @param int $relID ID of the release. * @param int $groupID Group ID of the release. * @param \nzedb\NNTP $nntp Class NNTP * @param int $show Only show result or apply iy. * * @return bool */ public function parsePAR2($messageID, $relID, $groupID, &$nntp, $show) { if ($messageID === '') { return false; } $query = $this->pdo->queryOneRow(sprintf(' SELECT id, group_id, categoryid, name, searchname, UNIX_TIMESTAMP(postdate) AS post_date, id AS releaseid FROM releases WHERE isrenamed = 0 AND id = %d', $relID)); if ($query === false) { return false; } // Only get a new name if the category is OTHER. $foundName = true; if (!in_array((int) $query['categoryid'], [Category::CAT_BOOKS_OTHER, Category::CAT_GAME_OTHER, Category::CAT_MOVIE_OTHER, Category::CAT_MUSIC_OTHER, Category::CAT_PC_PHONE_OTHER, Category::CAT_TV_OTHER, Category::CAT_OTHER_HASHED, Category::CAT_XXX_OTHER, Category::CAT_MISC])) { $foundName = false; } // Get the PAR2 file. $par2 = $nntp->getMessages($this->groups->getByNameByID($groupID), $messageID, $this->alternateNNTP); if ($nntp->isError($par2)) { return false; } // Put the PAR2 into Par2Info, check if there's an error. $this->_par2Info->setData($par2); if ($this->_par2Info->error) { return false; } // Get the file list from Par2Info. $files = $this->_par2Info->getFileList(); if ($files !== false && count($files) > 0) { $filesAdded = 0; // Loop through the files. foreach ($files as $file) { if (!isset($file['name'])) { continue; } // If we found a name and added 10 files, stop. if ($foundName === true && $filesAdded > 10) { break; } if ($this->addpar2) { // Add to release files. if ($filesAdded < 11 && $this->pdo->queryOneRow(sprintf(' SELECT id FROM release_files WHERE releaseid = %d AND name = %s', $relID, $this->pdo->escapeString($file['name']))) === false) { // Try to add the files to the DB. if ($this->releaseFiles->add($relID, $file['name'], $file['size'], $query['post_date'], 0)) { $filesAdded++; } } } else { $filesAdded++; } // Try to get a new name. if ($foundName === false) { $query['textstring'] = $file['name']; if ($this->nameFixer->checkName($query, 1, 'PAR2, ', 1, $show) === true) { $foundName = true; } } } // If we found some files. if ($filesAdded > 0) { $this->debugging->log('PostProcess', 'parsePAR2', 'Added ' . $filesAdded . ' release_files from PAR2 for ' . $query['searchname'], Logger::LOG_INFO); // Update the file count with the new file count + old file count. $this->pdo->queryExec(sprintf(' UPDATE releases SET rarinnerfilecount = rarinnerfilecount + %d WHERE id = %d', $filesAdded, $relID)); } if ($foundName === true) { return true; } } return false; }
/** * Update the release with the new information. * * @param array $release * @param string $name * @param string $method * @param boolean $echo * @param string $type * @param int $nameStatus * @param int $show * @param int $preId */ public function updateRelease($release, $name, $method, $echo, $type, $nameStatus, $show, $preId = 0) { if ($this->relid !== $release['releaseid']) { $releaseCleaning = new ReleaseCleaning($this->pdo); $newName = $releaseCleaning->fixerCleaner($name); if (strtolower($newName) != strtolower($release["searchname"])) { $this->matched = true; $this->relid = $release["releaseid"]; $determinedCategory = $this->category->determineCategory($release['group_id'], $newName); if ($type === "PAR2, ") { $newName = ucwords($newName); if (preg_match('/(.+?)\\.[a-z0-9]{2,3}(PAR2)?$/i', $name, $match)) { $newName = $match[1]; } } $this->fixed++; $newName = explode("\\", $newName); $newName = preg_replace(['/^[-=_\\.:\\s]+/', '/[-=_\\.:\\s]+$/'], '', $newName[0]); if ($this->echooutput === true && $show === 1) { $groupName = $this->_groups->getByNameByID($release['group_id']); $oldCatName = $this->category->getNameByID($release['categoryid']); $newCatName = $this->category->getNameByID($determinedCategory); if ($type === "PAR2, ") { echo PHP_EOL; } echo $this->pdo->log->headerOver("\nNew name: ") . $this->pdo->log->primary(substr($newName, 0, 255)) . $this->pdo->log->headerOver("Old name: ") . $this->pdo->log->primary($release["searchname"]) . $this->pdo->log->headerOver("Use name: ") . $this->pdo->log->primary($release["name"]) . $this->pdo->log->headerOver("New cat: ") . $this->pdo->log->primary($newCatName) . $this->pdo->log->headerOver("Old cat: ") . $this->pdo->log->primary($oldCatName) . $this->pdo->log->headerOver("Group: ") . $this->pdo->log->primary($groupName) . $this->pdo->log->headerOver("Method: ") . $this->pdo->log->primary($type . $method) . $this->pdo->log->headerOver("ReleaseID: ") . $this->pdo->log->primary($release["releaseid"]); if (isset($release['filename']) && $release['filename'] != "") { echo $this->pdo->log->headerOver("Filename: ") . $this->pdo->log->primary($release["filename"]); } if ($type !== "PAR2, ") { echo "\n"; } } $newTitle = $this->pdo->escapeString(substr($newName, 0, 255)); if ($echo == true) { if ($nameStatus == 1) { $status = ''; switch ($type) { case "NFO, ": $status = "isrenamed = 1, iscategorized = 1, proc_nfo = 1,"; break; case "PAR2, ": $status = "isrenamed = 1, iscategorized = 1, proc_par2 = 1,"; break; case "Filenames, ": case "file matched source: ": $status = "isrenamed = 1, iscategorized = 1, proc_files = 1,"; break; case "SHA1, ": case "MD5, ": $status = "isrenamed = 1, iscategorized = 1, dehashstatus = 1,"; break; case "PreDB FT Exact, ": $status = "isrenamed = 1, iscategorized = 1,"; break; case "sorter ": $status = "isrenamed = 1, iscategorized = 1, proc_sorter = 1,"; break; } $this->pdo->queryExec(sprintf(' UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, preid = %d, searchname = %s, %s categoryid = %d WHERE id = %d', $preId, $newTitle, $status, $determinedCategory, $release['releaseid'])); $this->sphinx->updateRelease($release['releaseid'], $this->pdo); } else { $newTitle = $this->pdo->escapeString(substr($newName, 0, 255)); $this->pdo->queryExec(sprintf(' UPDATE releases SET videos_id = 0, tv_episodes_id = 0, imdbid = NULL, musicinfoid = NULL, consoleinfoid = NULL, bookinfoid = NULL, anidbid = NULL, preid = %d, searchname = %s, iscategorized = 1, categoryid = %d WHERE id = %d', $preId, $newTitle, $determinedCategory, $release['releaseid'])); $this->sphinx->updateRelease($release['releaseid'], $this->pdo); } } } } $this->done = true; }
<?php require_once './config.php'; use nzedb\Groups; $page = new AdminPage(); $msgs = $error = false; // Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; switch ($action) { case 'submit': if (isset($_POST['groupfilter'])) { $groups = new Groups(); $msgs = $groups->addBulk($_POST['groupfilter'], $_POST['active'], $_POST['backfill']); if (is_string($msgs)) { $error = true; } } break; case 'view': default: $msgs = false; break; } $page->smarty->assign('error', $error); $page->smarty->assign('groupmsglist', $msgs); $page->smarty->assign('yesno_ids', [1, 0]); $page->smarty->assign('yesno_names', ['Yes', 'No']); $page->title = 'Bulk Add Newsgroups'; $page->content = $page->smarty->fetch('group-bulk.tpl'); $page->render();
<?php require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php'); use nzedb\ConsoleTools; use nzedb\Groups; use nzedb\db\Settings; $pdo = new Settings(); if (!isset($argv[1]) || $argv[1] != 'true') { exit($pdo->log->error("\nThis script will move all collections, binaries, parts into tables per group.\n\n" . "php {$argv['0']} true ...: To process all parts and leave the parts/binaries/collections tables intact.\n" . "php {$argv['0']} true truncate ...: To process all parts and truncate parts/binaries/collections tables after completed.\n")); } $start = time(); $consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]); $groups = new Groups(['Settings' => $pdo]); $actgroups = $pdo->query("SELECT DISTINCT group_id from collections"); echo $pdo->log->info("Creating new collections, binaries, and parts tables for each group that has collections."); foreach ($actgroups as $group) { $pdo->queryExec("DROP TABLE IF EXISTS collections_" . $group['group_id']); $pdo->queryExec("DROP TABLE IF EXISTS binaries_" . $group['group_id']); $pdo->queryExec("DROP TABLE IF EXISTS parts_" . $group['group_id']); if ($groups->createNewTPGTables($group['group_id']) === false) { exit($pdo->log->error("\nThere is a problem creating new parts/files tables for group {$group['name']}.\n")); } } $collections_rows = $pdo->queryDirect("SELECT group_id FROM collections GROUP BY group_id"); echo $pdo->log->info("Counting parts, this could table a few minutes."); $parts_count = $pdo->queryOneRow("SELECT COUNT(*) AS cnt FROM parts"); $i = 0; if ($collections_rows instanceof \Traversable) { foreach ($collections_rows as $row) { $groupName = $groups->getByNameByID($row['group_id']); echo $pdo->log->header("Processing {$groupName}");
<?php require_once dirname(__FILE__) . '/../../../www/config.php'; use nzedb\ConsoleTools; use nzedb\Groups; use nzedb\db\Settings; /* This script will allow you to move from single collections/binaries/parts tables to TPG without having to run reset_truncate. Please STOP all update scripts before running this script. Use the following options to run: php convert_to_tpg.php true Convert c/b/p to tpg leaving current collections/binaries/parts tables in-tact. php convert_to_tgp.php true delete Convert c/b/p to tpg and TRUNCATE current collections/binaries/parts tables. */ $debug = false; $pdo = new Settings(); $groups = new Groups(['Settings' => $pdo]); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $DoPartRepair = $pdo->getSetting('partrepair') == '0' ? false : true; if (!isset($argv[1]) || $argv[1] != 'true') { exit($pdo->log->error("\nMandatory argument missing\n\n" . "This script will allow you to move from single collections/binaries/parts tables to TPG without having to run reset_truncate.\n" . "Please STOP all update scripts before running this script.\n\n" . "Use the following options to run:\n" . "php {$argv['0']} true ...: Convert c/b/p to tpg leaving current collections/binaries/parts tables in-tact.\n" . "php {$argv['0']} true delete ...: Convert c/b/p to tpg and TRUNCATE current collections/binaries/parts tables.\n")); } $clen = $pdo->queryOneRow('SELECT COUNT(*) AS total FROM collections;'); $cdone = 0; $ccount = 1; $gdone = 1; $actgroups = $groups->getActive(); $glen = count($actgroups); $newtables = $glen * 3; $begintime = time(); echo "Creating new collections, binaries, and parts tables for each active group...\n"; foreach ($actgroups as $group) {
<?php use nzedb\Groups; if (!$page->users->isLoggedIn()) { $page->show403(); } $groups = new Groups(['Settings' => $page->settings]); $grouplist = $groups->getAll(); $page->smarty->assign('results', $grouplist); $page->meta_title = "Browse Groups"; $page->meta_keywords = "browse,groups,description,details"; $page->meta_description = "Browse groups"; $page->content = $page->smarty->fetch('browsegroup.tpl'); $page->render();
/** * @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", (int) $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, 'group_id' => $groupID, 'groupName' => $groupName, 'totalFiles' => $totalFiles, 'totalSize' => $totalSize]); }