Push passworded releases handling update ported from nZEDb.

This commit is contained in:
DariusIII
2015-06-14 16:50:21 +02:00
parent 953329a2f8
commit 35fa7f3ea9
9 changed files with 97 additions and 100 deletions
+14 -27
View File
@@ -151,34 +151,19 @@ class Books
return $res['num'];
}
public function getBookCount($cat, $maxage = -1, $excludedcats =[])
public function getBookCount($cat, $maxage = -1, $excludedcats = [])
{
$browseby = $this->getBrowseBy();
$catsrch = '';
if (count($cat) > 0 && $cat[0] != -1) {
$catsrch = (new \Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
}
if ($maxage > 0) {
$maxage = sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage);
} else {
$maxage = '';
}
$exccatlist = '';
if (count($excludedcats) > 0) {
$exccatlist = ' AND r.categoryid NOT IN (' . implode(',', $excludedcats) . ')';
}
$res = $this->pdo->queryOneRow(
sprintf(
"SELECT COUNT(DISTINCT r.bookinfoid) AS num FROM releases r "
. "INNER JOIN bookinfo boo ON boo.id = r.bookinfoid AND boo.title != '' and boo.cover = 1 "
. "WHERE r.nzbstatus = 1 AND r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') "
. "AND %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist
"SELECT COUNT(DISTINCT r.bookinfoid) AS num FROM releases r
INNER JOIN bookinfo boo ON boo.id = r.bookinfoid AND boo.title != '' and boo.cover = 1
WHERE r.nzbstatus = 1 AND r.passwordstatus %s
AND %s %s %s %s",
Releases::showPasswords($this->pdo),
$this->getBrowseBy(),
(count($cat) > 0 && $cat[0] != -1 ? (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat) : ''),
($maxage > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage) : ''),
(count($excludedcats) > 0 ? ' AND r.categoryid NOT IN (' . implode(',', $excludedcats) . ')' : '')
)
);
return $res['num'];
@@ -230,8 +215,10 @@ class Books
. "LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id "
. "INNER JOIN bookinfo boo ON boo.id = r.bookinfoid "
. "WHERE r.nzbstatus = 1 AND boo.cover = 1 AND boo.title != '' AND "
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s %s %s "
. "GROUP BY boo.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $maxage, $exccatlist, $order[0], $order[1]
. "r.passwordstatus %s AND %s %s %s %s "
. "GROUP BY boo.id ORDER BY %s %s" . $limit,
Releases::showPasswords($this->pdo),
$browseby, $catsrch, $maxage, $exccatlist, $order[0], $order[1]
);
return $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
+4 -4
View File
@@ -80,7 +80,7 @@ class Film
protected $yahooLimit = 0;
/**
* @var int
* @var string
*/
protected $showPasswords;
@@ -153,7 +153,7 @@ class Film
$this->imdburl = ($this->pdo->getSetting('imdburl') == 0 ? false : true);
$this->movieqty = ($this->pdo->getSetting('maximdbprocessed') != '') ? $this->pdo->getSetting('maximdbprocessed') : 100;
$this->searchEngines = true;
$this->showPasswords = ($this->pdo->getSetting('showpasswordedrelease') != '') ? $this->pdo->getSetting('showpasswordedrelease') : 0;
$this->showPasswords = Releases::showPasswords($this->pdo);
$this->debug = NN_DEBUG;
$this->echooutput = ($options['Echo'] && NN_ECHOCLI && $this->pdo->cli);
@@ -266,7 +266,7 @@ class Film
AND r.imdbid != '0000000'
AND m.cover = 1
AND m.title != ''
AND r.passwordstatus <= %d
AND r.passwordstatus %s
AND %s %s %s %s ",
$this->showPasswords,
$this->getBrowseBy(),
@@ -320,7 +320,7 @@ class Film
INNER JOIN movieinfo m ON m.imdbid = r.imdbid
WHERE r.nzbstatus = 1 AND r.imdbid != '0000000'
AND m.title != ''
AND r.passwordstatus <= %d AND %s %s %s %s
AND r.passwordstatus %s AND %s %s %s %s
GROUP BY m.imdbid ORDER BY %s %s %s",
$this->showPasswords,
$this->getBrowseBy(),
+4 -2
View File
@@ -172,9 +172,10 @@ class Games
WHERE r.nzbstatus = 1
AND con.title != ''
AND con.cover = 1
AND r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease')
AND r.passwordstatus %s
AND %s %s %s %s",
$this->getBrowseBy(),
Releases::showPasswords($this->pdo),
$catsrch,
($maxage > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage) : ''),
(count($excludedcats) > 0 ? " AND r.categoryid NOT IN (" . implode(",", $excludedcats) . ")" : '')
@@ -233,8 +234,9 @@ class Games
. "LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id "
. "INNER JOIN gamesinfo con ON con.id = r.gamesinfo_id "
. "WHERE r.nzbstatus = 1 AND con.title != '' AND "
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s %s %s "
. "r.passwordstatus %s AND %s %s %s %s "
. "GROUP BY con.id ORDER BY %s %s" . $limit,
Releases::showPasswords($this->pdo),
$browseby,
$catsrch,
$maxage,
+6 -4
View File
@@ -157,8 +157,9 @@ class Konsole
FROM releases r
INNER JOIN consoleinfo con ON con.id = r.consoleinfoid AND con.title != '' AND con.cover = 1
WHERE r.nzbstatus = 1
AND r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease')
AND r.passwordstatus %s
AND %s %s %s %s",
Releases::showPasswords($this->pdo),
$this->getBrowseBy(),
$catsrch,
($maxage > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage) : ''),
@@ -211,9 +212,10 @@ class Konsole
. "INNER JOIN consoleinfo con ON con.id = r.consoleinfoid "
. "INNER JOIN genres ON con.genreid = genres.id "
. "WHERE r.nzbstatus = 1 AND con.title != '' AND "
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s
%s "
. "GROUP BY con.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $exccatlist, $order[0], $order[1]
. "r.passwordstatus %s AND %s %s %s "
. "GROUP BY con.id ORDER BY %s %s" . $limit,
Releases::showPasswords($this->pdo),
$browseby, $catsrch, $exccatlist, $order[0], $order[1]
), true, NN_CACHE_EXPIRY_MEDIUM
);
}
+17 -24
View File
@@ -176,28 +176,19 @@ class Musik
*/
public function getMusicCount($cat, $maxage = -1, $excludedcats = [])
{
$browseby = $this->getBrowseBy();
$catsrch = '';
if (count($cat) > 0 && $cat[0] != -1) {
$catsrch = (new \Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
}
if ($maxage > 0) {
$maxage = sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage);
} else {
$maxage = '';
}
$exccatlist = "";
if (count($excludedcats) > 0) {
$exccatlist = " AND r.categoryid NOT IN (" . implode(",", $excludedcats) . ")";
}
$sql = sprintf("SELECT COUNT(DISTINCT r.musicinfoid) AS num FROM releases r INNER JOIN musicinfo m ON m.id = r.musicinfoid AND m.title != '' AND m.cover = 1 WHERE nzbstatus = 1 AND r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist);
$res = $this->pdo->queryOneRow($sql);
$res = $this->pdo->queryOneRow(
sprintf(
"SELECT COUNT(DISTINCT r.musicinfoid) AS num
FROM releases r
INNER JOIN musicinfo m ON m.id = r.musicinfoid AND m.title != '' AND m.cover = 1
WHERE nzbstatus = 1 AND r.passwordstatus %s AND %s %s %s %s",
Releases::showPasswords($this->pdo),
$this->getBrowseBy(),
(count($cat) > 0 && $cat[0] != -1 ? (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat) : ''),
($maxage > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxage) : ''),
(count($excludedcats) > 0 ? " AND r.categoryid NOT IN (" . implode(",", $excludedcats) . ")" : '')
)
);
return $res["num"];
}
@@ -252,8 +243,10 @@ class Musik
. "LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id "
. "INNER JOIN musicinfo m ON m.id = r.musicinfoid "
. "WHERE r.nzbstatus = 1 AND m.title != '' AND "
. "r.passwordstatus <= (SELECT value FROM settings WHERE setting='showpasswordedrelease') AND %s %s %s "
. "GROUP BY m.id ORDER BY %s %s" . $limit, $browseby, $catsrch, $exccatlist, $order[0], $order[1]),
. "r.passwordstatus %s AND %s %s %s "
. "GROUP BY m.id ORDER BY %s %s" . $limit,
Releases::showPasswords($this->pdo),
$browseby, $catsrch, $exccatlist, $order[0], $order[1]),
true, NN_CACHE_EXPIRY_MEDIUM
);
}
+35 -33
View File
@@ -11,9 +11,9 @@ use newznab\utility\Utility;
class Releases
{
// RAR/ZIP Passworded indicator.
const PASSWD_NONE = 0; // No password.
const PASSWD_POTENTIAL = 1; // Might have a password.
const BAD_FILE = 2; // Possibly broken RAR/ZIP.
const PASSWD_NONE = 0; // No password.
const PASSWD_POTENTIAL = 1; // Might have a password.
const BAD_FILE = 2; // Possibly broken RAR/ZIP.
const PASSWD_RAR = 10; // Definitely passworded.
/**
@@ -41,6 +41,11 @@ class Releases
*/
public $sphinxSearch;
/**
* @var string
*/
private $showPasswords;
/**
* @var array $options Class instances.
*/
@@ -58,6 +63,7 @@ class Releases
$this->passwordStatus = ($this->pdo->getSetting('checkpasswordedrar') == 1 ? -1 : 0);
$this->sphinxSearch = new SphinxSearch();
$this->releaseSearch = new ReleaseSearch($this->pdo, $this->sphinxSearch);
$this->showPasswords = self::showPasswords($this->pdo);
}
/**
@@ -168,7 +174,7 @@ class Releases
%s %s %s %s',
($groupName != '' ? 'INNER JOIN groups g ON g.id = r.groupid' : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
($groupName != '' ? sprintf(' AND g.name = %s', $this->pdo->escapeString($groupName)) : ''),
$this->categorySQL($cat),
($maxAge > 0 ? (' AND r.postdate > NOW() - INTERVAL ' . $maxAge . ' DAY ') : ''),
@@ -213,7 +219,7 @@ class Releases
%s %s %s %s
ORDER BY %s %s %s",
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
$this->categorySQL($cat),
($maxAge > 0 ? (" AND postdate > NOW() - INTERVAL " . $maxAge . ' DAY ') : ''),
(count($excludedCats) ? (' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')') : ''),
@@ -234,31 +240,27 @@ class Releases
/**
* Return site setting for hiding/showing passworded releases.
*
* @param Settings $pdo
*
* @return string
*/
public function showPasswords()
public static function showPasswords(Settings $pdo)
{
if (!is_null($this->passwordSettingBuffer)) {
return $this->passwordSettingBuffer;
}
$passwordStatus = ('= ' . Releases::PASSWD_NONE);
$setting = $this->pdo->query(
$setting = $pdo->query(
"SELECT value FROM settings WHERE setting = 'showpasswordedrelease'",
true, NN_CACHE_EXPIRY_LONG
);
if (isset($setting[0]['value']) && is_numeric($setting[0]['value'])) {
switch ($setting[0]['value']) {
case 1:
$passwordStatus = ('<= ' . Releases::PASSWD_POTENTIAL);
break;
case 10:
$passwordStatus = ('<= ' . Releases::PASSWD_RAR);
break;
}
switch ((isset($setting[0]['value']) && is_numeric($setting[0]['value']) ? $setting[0]['value'] : 10)) {
case 0: // Hide releases with a password or a potential password (Hide unprocessed releases).
return ('= ' . Releases::PASSWD_NONE);
case 1: // Show releases with no password or a potential password (Show unprocessed releases).
return ('<= ' . Releases::PASSWD_POTENTIAL);
case 2: // Hide releases with a password or a potential password (Show unprocessed releases).
return ('<= ' . Releases::PASSWD_NONE);
case 10: // Shows everything.
default:
return ('<= ' . Releases::PASSWD_RAR);
}
$this->passwordSettingBuffer = $passwordStatus;
return $passwordStatus;
}
/**
@@ -503,7 +505,7 @@ class Releases
ORDER BY postdate DESC %s",
$this->getConcatenatedCategoryIDs(),
$cartSearch,
$this->showPasswords(),
$this->showPasswords,
NZB::NZB_ADDED,
$catSearch,
($rageID > -1 ? sprintf(' AND r.rageid = %d %s ', $rageID, ($catSearch == '' ? $catLimit : '')) : ''),
@@ -547,7 +549,7 @@ class Releases
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
($airDate > -1 ? sprintf(' AND r.tvairdate >= DATE_SUB(CURDATE(), INTERVAL %d DAY) ', $airDate) : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
), true, NN_CACHE_EXPIRY_MEDIUM
);
@@ -584,7 +586,7 @@ class Releases
$this->uSQL($this->pdo->query(sprintf('SELECT imdbid, categoryid FROM usermovies WHERE userid = %d', $userID), true), 'imdbid'),
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
), true, NN_CACHE_EXPIRY_MEDIUM
);
@@ -628,7 +630,7 @@ class Releases
$this->uSQL($userShows, 'rageid'),
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : ''),
$orderBy[0],
$orderBy[1],
@@ -660,7 +662,7 @@ class Releases
$this->uSQL($userShows, 'rageid'),
(count($excludedCats) ? ' AND r.categoryid NOT IN (' . implode(',', $excludedCats) . ')' : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
)
);
@@ -991,7 +993,7 @@ class Releases
"%s
WHERE r.passwordstatus %s AND r.nzbstatus = %d %s %s %s %s %s %s %s %s %s %s %s",
$this->releaseSearch->getFullTextJoinString(),
$this->showPasswords(),
$this->showPasswords,
NZB::NZB_ADDED,
($maxAge > 0 ? sprintf(' AND r.postdate > (NOW() - INTERVAL %d DAY) ', $maxAge) : ''),
($groupName != -1 ? sprintf(' AND r.groupid = %d ', $this->groups->getIDByName($groupName)) : ''),
@@ -1065,7 +1067,7 @@ class Releases
AND r.passwordstatus %s %s %s %s %s %s %s",
($name !== '' ? $this->releaseSearch->getFullTextJoinString() : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
($rageId != -1 ? sprintf(' AND rageid = %d ', $rageId) : ''),
($series != '' ? sprintf(' AND UPPER(r.season) = UPPER(%s)', $this->pdo->escapeString(((is_numeric($series) && strlen($series) != 4) ? sprintf('S%02d', $series) : $series))) : ''),
($episode != '' ? sprintf(' AND r.episode %s', $this->pdo->likeString((is_numeric($episode) ? sprintf('E%02d', $episode) : $episode))) : ''),
@@ -1124,7 +1126,7 @@ class Releases
"%s
WHERE r.passwordstatus %s AND r.nzbstatus = %d %s %s %s %s %s",
($name !== '' ? $this->releaseSearch->getFullTextJoinString() : ''),
$this->showPasswords(),
$this->showPasswords,
NZB::NZB_ADDED,
($aniDbID > -1 ? sprintf(' AND anidbid = %d ', $aniDbID) : ''),
(is_numeric($episodeNumber) ? sprintf(" AND r.episode '%s' ", $this->pdo->likeString($episodeNumber)) : ''),
@@ -1184,7 +1186,7 @@ class Releases
%s %s %s %s",
($name !== '' ? $this->releaseSearch->getFullTextJoinString() : ''),
NZB::NZB_ADDED,
$this->showPasswords(),
$this->showPasswords,
($name !== '' ? $this->releaseSearch->getSearchSQL(['searchname' => $name]) : ''),
(($imDbId != '-1' && is_numeric($imDbId)) ? sprintf(' AND imdbid = %d ', str_pad($imDbId, 7, '0', STR_PAD_LEFT)) : ''),
$this->categorySQL($cat),
@@ -1381,7 +1383,7 @@ class Releases
WHERE r.categoryid BETWEEN 5000 AND 5999
AND r.passwordstatus %s
AND rageid = %d %s %s",
$this->showPasswords(),
$this->showPasswords,
$rageID,
$series,
$episode
+6 -3
View File
@@ -45,6 +45,9 @@ class XXX
protected $movieqty;
/**
* @var string
*/
protected $showPasswords;
protected $cookie;
@@ -65,7 +68,7 @@ class XXX
$this->releaseImage = ($options['ReleaseImage'] instanceof \ReleaseImage ? $options['ReleaseImage'] : new \ReleaseImage($this->pdo));
$this->movieqty = ($this->pdo->getSetting('maxxxxprocessed') != '') ? $this->pdo->getSetting('maxxxxprocessed') : 100;
$this->showPasswords = ($this->pdo->getSetting('showpasswordedrelease') != '') ? $this->pdo->getSetting('showpasswordedrelease') : 0;
$this->showPasswords = Releases::showPasswords($this->pdo);
$this->debug = NN_DEBUG;
$this->echooutput = ($options['Echo'] && NN_ECHOCLI);
$this->imgSavePath = NN_COVERS . 'xxx' . DS;
@@ -148,7 +151,7 @@ class XXX
INNER JOIN xxxinfo xxx ON xxx.id = r.xxxinfo_id
WHERE r.nzbstatus = 1
AND xxx.title != ''
AND r.passwordstatus <= %d
AND r.passwordstatus %s
AND %s %s %s %s ",
$this->showPasswords,
$this->getBrowseBy(),
@@ -204,7 +207,7 @@ class XXX
INNER JOIN xxxinfo xxx ON xxx.id = r.xxxinfo_id
WHERE r.nzbstatus = 1
AND xxx.title != ''
AND r.passwordstatus <= %d AND %s %s %s %s
AND r.passwordstatus %s AND %s %s %s %s
GROUP BY xxx.id ORDER BY %s %s %s",
$this->showPasswords,
$this->getBrowseBy(),
+7 -2
View File
@@ -45,7 +45,7 @@ switch($action)
if ($error == "")
{
$site = $ret;
$returnid = $site->id;
$returnid = $site['id'];
header("Location:".WWW_TOP."/site-edit.php?id=".$returnid);
}
else
@@ -104,7 +104,12 @@ $page->smarty->assign('registerstatus_ids', array(Settings::REGISTER_STATUS_API_
$page->smarty->assign('registerstatus_names', array('API Only', 'Open', 'Invite', 'Closed'));
$page->smarty->assign('passworded_ids', array(0,1,2));
$page->smarty->assign('passworded_names', array( 'Dont show passworded or potentially passworded', 'Dont show passworded', 'Show everything'));
$page->smarty->assign('passworded_names', [
'Hide passworded or potentially passworded (*yes)',
'Hide passworded or potentially passworded (*no)',
'Show non-passworded and potentially passworded (*no)',
'Show everything (*no)'
]);
$page->smarty->assign('sphinxrebuildfreqday_days', array('', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'));
@@ -849,7 +849,10 @@
<td><label for="showpasswordedrelease">Show Passworded Releases</label>:</td>
<td>
{html_options id="showpasswordedrelease" name='showpasswordedrelease' values=$passworded_ids output=$passworded_names selected=$fsite->showpasswordedrelease}
<div class="hint">Whether to show passworded or potentially passworded releases in browse, search, api and rss feeds. Potentially passworded means releases which contain .cab or .ace files which are typically password protected.</div>
<div class="hint">Whether to show passworded or potentially passworded releases in browse, search, api and rss
feeds. Potentially passworded means releases which contain .cab or .ace files which are
typically password protected. (*yes): Unprocessed releases are hidden. (*no): Unprocessed releases are displayed.
</div>
</td>
</tr>
</table>