function releases_rt() { $pdo = new nzedb\db\DB(); $rows = $pdo->queryExec('SELECT id, guid, name, searchname, fromname FROM releases'); if ($rows !== false && $rows->rowCount()) { $sphinx = new SphinxSearch(); $total = $rows->rowCount(); $string = 'REPLACE INTO releases_rt (id, guid, name, searchname, fromname) VALUES '; $tempString = ''; $i = 0; echo '[Starting to populate sphinx RT indexes with ' . $total . ' releases.] '; foreach ($rows as $row) { $i++; $tempString .= sprintf('(%d, %s, %s, %s, %s),', $row['id'], $sphinx->sphinxQL->escapeString($row['guid']), $sphinx->sphinxQL->escapeString($row['name']), $sphinx->sphinxQL->escapeString($row['searchname']), $sphinx->sphinxQL->escapeString($row['fromname'])); if ($i === 1000 || $i >= $total) { $sphinx->sphinxQL->queryExec($string . rtrim($tempString, ',')); $tempString = ''; $total -= $i; $i = 0; echo '.'; } } echo ' [Done.]' . PHP_EOL; } else { echo 'No releases in your DB or an error occurred. This will need to be resolved before you can use the search.' . PHP_EOL; } }
/** * Get a group ID for a group name. * * @param string $groupName * * @return mixed * * @access protected */ protected function _getGroupID($groupName) { if (!isset($this->_groupList[$groupName])) { $group = $this->_pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $this->_pdo->escapeString($groupName))); $this->_groupList[$groupName] = $group['id']; } return $this->_groupList[$groupName]; }
/** * Safe backfill using posts. Going back to a date specified by the user on the site settings. * This does 1 group for x amount of parts until it reaches the date. * * @param string $articles * * @return void */ public function safeBackfill($articles = '') { $groupname = $this->pdo->queryOneRow(sprintf(' SELECT name FROM groups WHERE first_record_postdate BETWEEN %s AND NOW() AND backfill = 1 ORDER BY name ASC', $this->pdo->escapeString($this->_safeBackFillDate))); if (!$groupname) { $dMessage = 'No groups to backfill, they are all at the target date ' . $this->_safeBackFillDate . ", or you have not enabled them to be backfilled in the groups page.\n"; if ($this->_debug) { $this->_debugging->log('Backfill', "safeBackfill", $dMessage, Logger::LOG_FATAL); } exit($dMessage); } else { $this->backfillAllGroups($groupname['name'], $articles); } }
/** * Return a single PRE for a release. * * @param int $preID * * @return array */ public function getOne($preID) { return $this->pdo->queryOneRow(sprintf('SELECT * FROM predb WHERE id = %d', $preID)); }
if (isset($_GET['category'])) { $pdo = new nzedb\db\DB(); $preData = $pdo->query(sprintf('SELECT * FROM predb p WHERE p.category %s %s %s %s LIMIT %d OFFSET %d', $newer, $older, $nuked, $pdo->likeString($_GET['category']), $limit, $offset)); } break; case 'a': case 'all': $pdo = new nzedb\db\DB(); $preData = $pdo->query(sprintf('SELECT * FROM predb p WHERE 1=1 %s %s %s ORDER BY p.predate DESC LIMIT %d OFFSET %d', $newer, $older, $nuked, $limit, $offset)); break; } } else { if (isset($_POST['data'])) { $reqData = @unserialize($_POST['data']); if ($reqData !== false && is_array($reqData) && isset($reqData[0]['ident'])) { $pdo = new nzedb\db\DB(); $preData = array(); foreach ($reqData as $request) { $result = $pdo->queryOneRow(sprintf(' SELECT p.*, g.name AS groupname FROM predb p INNER JOIN groups g ON g.id = p.group_id WHERE requestid = %d AND g.name = %s LIMIT 1', $request['reqid'], $pdo->escapeString($request['group']))); if ($result !== false) { $result['ident'] = $request['ident']; $preData[] = $result; } }
/** * Optimize a RT index. * @param string $indexName */ public function optimizeRTIndex($indexName) { if (!is_null($this->sphinxQL)) { $this->sphinxQL->queryExec(sprintf('OPTIMIZE INDEX %s', $indexName)); } }
<?php if (!isset($argv[1])) { exit('This script will set where backfill starts based on your oldest release in a group or groups,' . ' so you do not have to re-download and process all the headers you already downloaded.' . PHP_EOL . 'This is good if you imported NZBs or reset a group for example.' . PHP_EOL . 'To start the script, type in a group name or all for all the backfill enabled groups.' . PHP_EOL); } require_once dirname(__FILE__) . '/../../../www/config.php'; $pdo = new nzedb\db\DB(); if ($argv[1] === 'all') { $groups = $pdo->query('SELECT * FROM groups WHERE backfill = 1'); } else { $groups = $pdo->query(sprintf('SELECT * FROM groups WHERE name = %s', $pdo->escapeString($argv[1]))); } if (count($groups) === 0) { if ($argv[1] === 'all') { exit('ERROR! No groups were found with backfill enabled!' . PHP_EOL); } else { exit('ERROR! Group (' . $argv[1] . ') not found!' . PHP_EOL); } } $nntp = new NNTP(['Settings' => $pdo]); $nntp->doConnect() or exit('Could not connect to Usenet!' . PHP_EOL); $binaries = new Binaries(['NNTP' => $nntp, 'Settings' => $pdo]); foreach ($groups as $group) { $groupNNTP = $nntp->selectGroup($group['name']); if ($nntp->isError($groupNNTP)) { echo 'ERROR! Could not fetch information from NNTP for group (' . $group['name'] . ')' . PHP_EOL; continue; } $postDate = $pdo->queryOneRow(sprintf('SELECT UNIX_TIMESTAMP(postdate) AS postdate FROM releases WHERE group_id = %d ORDER BY postdate ASC LIMIT 1', $group['id'])); if ($postDate === false) { echo 'ERROR! Could not find any existing releases for group (' . $group['name'] . ')' . PHP_EOL;
SELECT title, groupname, reqid FROM predb WHERE reqid = %d AND groupname = %s LIMIT 1', $request['reqid'], $db->escapeString($request['group']))); if ($result !== false) { $result['ident'] = $request['ident']; $preData[] = $result; } } } } else { if (isset($_GET['reqid']) && isset($_GET['group']) && is_numeric($_GET['reqid'])) { require dirname(__FILE__) . '/../settings.php'; require dirname(__FILE__) . '/../Classes/DB.php'; $db = new nzedb\db\DB(); $preData = $db->queryOneRow(sprintf(' SELECT title, groupname, reqid FROM predb WHERE reqid = %d AND groupname = %s LIMIT 1', $_GET['reqid'], $db->escapeString(trim($_GET['group'])))); if ($preData !== false) { $preData['ident'] = 0; $preData = array($preData); } } } header('Content-type: text/xml'); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<requests>\n"; if ($preData !== false) {
public function info($message) { if (PEAR_LOG_DEBUG) { echo $this->color->info($message); } } } $nntp = new NNTPTest(new NNTPDebug(isset($argv[1]) ? true : false)); if ($nntp->doConnect() !== true) { exit('Error connecting to usenet!' . PHP_EOL); } $n = PHP_EOL; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// Put your test code under here. //////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $db = new nzedb\db\DB(); $groups = $db->query('SELECT name FROM groups WHERE name NOT like \'alt.binaries.%\' AND active = 1'); $groupList = array(); foreach ($groups as $group) { $groupList += $nntp->getGroups($group['name']); } $groupList += $nntp->getGroups('alt.binaries.*'); $groups = $db->queryDirect('SELECT name FROM groups WHERE active = 1'); $activeGroups = array(); if ($groups instanceof Traversable) { foreach ($groups as $group) { if (isset($groupList[$group['name']])) { $activeGroups[$group['name']] = $groupList[$group['name']]; } } }
<?php require dirname(__FILE__) . '/../../www/config.php'; if (nZEDb_RELEASE_SEARCH_TYPE != ReleaseSearch::SPHINX) { exit('Error, nZEDb_RELEASE_SEARCH_TYPE in www/settings.php must be set to SPHINX!' . PHP_EOL); } if (!isset($argv[1]) || !isset($argv[2]) || !is_numeric($argv[2])) { exit('Argument 1 must the hostname or IP to the Sphinx searchd server, Argument 2 must be the port to the Sphinx searchd server.' . PHP_EOL); } $pdo = new nzedb\db\DB(); $sphinxConnection = sprintf('%s:%d', $argv[1], $argv[2]); $tables = []; $tables['releases_se'] = sprintf("CREATE TABLE releases_se\n(\n\tid BIGINT UNSIGNED NOT NULL,\n\tweight INTEGER NOT NULL,\n\tquery VARCHAR(1024) NOT NULL,\n\tguid VARCHAR(40) NOT NULL,\n\tname VARCHAR(255) NOT NULL DEFAULT '',\n\tsearchname VARCHAR(255) NOT NULL DEFAULT '',\n\tfromname VARCHAR(255) NULL,\n\tINDEX(query)\n) ENGINE=SPHINX CONNECTION=\"sphinx://%s/releases_rt\"", $sphinxConnection); foreach ($tables as $table => $query) { $pdo->queryExec(sprintf('DROP TABLE IF EXISTS %s', $table)); $pdo->queryExec($query); } echo 'All done! If you messed up your sphinx connection info, you can rerun this script.' . PHP_EOL;
<?php define('pre_settings', true); define('m2v_settings', true); require 'settings.php'; require_once 'Classes/DB.php'; $db = new nzedb\db\DB(); for (;;) { $db->ping(true); $rss_data = getUrl(M2VRU_RSS_LINK); if (!$rss_data) { echo "Error downloading '" . M2VRU_RSS_LINK . "'\n"; sleep_printout(M2V_SLEEP_TIME); continue; } $rss_data = @simplexml_load_string($rss_data); if (!$rss_data) { echo "Error parsing XML data from M2V RSS.\n"; sleep_printout(M2V_SLEEP_TIME); continue; } echo "Downloaded RSS data from M2V.\n"; $items = 0; foreach ($rss_data->channel->item as $item) { if ($item->title == "m2v.ru") { continue; } if ($db->queryOneRow("SELECT id FROM predb WHERE filename != '' AND title = " . $db->escapeString($item->title))) { continue; } $item_data = getUrl($item->link);
protected function _updateString($sqlKey, &$oldValue, &$newValue, $escape = true) { return empty($oldValue) && !empty($newValue) ? $sqlKey . ' = ' . ($escape ? $this->_db->escapeString($newValue) : $newValue) . ', ' : ''; }