false,
'ReleaseImage' => null,
'Settings' => null,
];
$options += $defaults;
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage($this->pdo));
$this->movieqty = (Settings::settingValue('..maxxxxprocessed') !== '') ? Settings::settingValue('..maxxxxprocessed') : 100;
$this->showPasswords = Releases::showPasswords();
$this->debug = NN_DEBUG;
$this->echooutput = ($options['Echo'] && NN_ECHOCLI);
$this->imgSavePath = NN_COVERS.'xxx'.DS;
$this->cookie = NN_TMP.'xxx.cookie';
$this->catWhere = 'AND categories_id IN ('.
Category::XXX_DVD.', '.
Category::XXX_WMV.', '.
Category::XXX_XVID.', '.
Category::XXX_X264.', '.
Category::XXX_SD.', '.
Category::XXX_CLIPHD.', '.
Category::XXX_CLIPSD.', '.
Category::XXX_WEBDL.') ';
if (NN_DEBUG || NN_LOGGING) {
$this->debug = true;
try {
$this->debugging = new Logger();
} catch (LoggerException $error) {
$this->debug = false;
}
}
}
/**
* Get info for a xxx id.
*
* @param $xxxid
* @return \Illuminate\Database\Query\Builder|static
*/
public function getXXXInfo($xxxid)
{
return XxxInfo::query()->where('id', $xxxid)->selectRaw(' *, UNCOMPRESS(plot) as plot')->first();
}
/**
* Get movie releases with covers for xxx browse page.
*
* @param $cat
* @param $start
* @param $num
* @param $orderBy
* @param $maxAge
* @param array $excludedCats
*
* @return array
*/
public function getXXXRange($cat, $start, $num, $orderBy, $maxAge = -1, array $excludedCats = []): array
{
$catsrch = '';
if (count($cat) > 0 && $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
}
$order = $this->getXXXOrder($orderBy);
$xxxmovies = $this->pdo->queryCalc(
sprintf(
"
SELECT SQL_CALC_FOUND_ROWS
xxx.id,
GROUP_CONCAT(r.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_id
FROM xxxinfo xxx
LEFT JOIN releases r ON xxx.id = r.xxxinfo_id
WHERE r.nzbstatus = 1
AND xxx.title != ''
AND r.passwordstatus %s
%s %s %s %s
GROUP BY xxx.id
ORDER BY %s %s %s",
$this->showPasswords,
$this->getBrowseBy(),
$catsrch,
(
$maxAge > 0
? 'AND r.postdate > NOW() - INTERVAL '.$maxAge.'DAY '
: ''
),
(count($excludedCats) > 0 ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
$order[0],
$order[1],
($start === false ? '' : ' LIMIT '.$num.' OFFSET '.$start)
),
true,
NN_CACHE_EXPIRY_MEDIUM
);
$xxxIDs = $releaseIDs = false;
if (is_array($xxxmovies['result'])) {
foreach ($xxxmovies['result'] as $xxx => $id) {
$xxxIDs[] = $id['id'];
$releaseIDs[] = $id['grp_release_id'];
}
}
$sql = sprintf(
"
SELECT
GROUP_CONCAT(r.id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_id,
GROUP_CONCAT(r.rarinnerfilecount ORDER BY r.postdate DESC SEPARATOR ',') AS grp_rarinnerfilecount,
GROUP_CONCAT(r.haspreview ORDER BY r.postdate DESC SEPARATOR ',') AS grp_haspreview,
GROUP_CONCAT(r.passwordstatus ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_password,
GROUP_CONCAT(r.guid ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_guid,
GROUP_CONCAT(rn.releases_id ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_nfoid,
GROUP_CONCAT(g.name ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_grpname,
GROUP_CONCAT(r.searchname ORDER BY r.postdate DESC SEPARATOR '#') AS grp_release_name,
GROUP_CONCAT(r.postdate ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_postdate,
GROUP_CONCAT(r.size ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_size,
GROUP_CONCAT(r.totalpart ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_totalparts,
GROUP_CONCAT(r.comments ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_comments,
GROUP_CONCAT(r.grabs ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_grabs,
GROUP_CONCAT(df.failed ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_failed,
GROUP_CONCAT(cp.title, ' > ', c.title ORDER BY r.postdate DESC SEPARATOR ',') AS grp_release_catname,
xxx.*, UNCOMPRESS(xxx.plot) AS plot,
g.name AS group_name,
rn.releases_id AS nfoid
FROM releases r
LEFT OUTER JOIN groups g ON g.id = r.groups_id
LEFT OUTER JOIN release_nfos rn ON rn.releases_id = r.id
LEFT OUTER JOIN dnzb_failures df ON df.release_id = r.id
LEFT OUTER JOIN categories c ON c.id = r.categories_id
LEFT OUTER JOIN categories cp ON cp.id = c.parentid
INNER JOIN xxxinfo xxx ON xxx.id = r.xxxinfo_id
WHERE r.nzbstatus = 1
AND xxx.id IN (%s)
AND xxx.title != ''
AND r.passwordstatus %s
%s %s %s %s
GROUP BY xxx.id
ORDER BY %s %s",
(is_array($xxxIDs) ? implode(',', $xxxIDs) : -1),
$this->showPasswords,
$this->getBrowseBy(),
$catsrch,
(
$maxAge > 0
? 'AND r.postdate > NOW() - INTERVAL '.$maxAge.'DAY '
: ''
),
(count($excludedCats) > 0 ? ' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')' : ''),
$order[0],
$order[1]
);
$return = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM);
if (! empty($return)) {
$return[0]['_totalcount'] = $xxxmovies['total'] ?? 0;
}
return $return;
}
/**
* Get the order type the user requested on the movies page.
*
* @param $orderBy
*
* @return array
*/
protected function getXXXOrder($orderBy): array
{
$orderArr = explode('_', (($orderBy === '') ? 'MAX(r.postdate)' : $orderBy));
switch ($orderArr[0]) {
case 'title':
$orderField = 'xxx.title';
break;
case 'posted':
default:
$orderField = 'MAX(r.postdate)';
break;
}
return [$orderField, isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1]) ? $orderArr[1] : 'desc'];
}
/**
* Order types for xxx page.
*
* @return array
*/
public function getXXXOrdering(): array
{
return ['title_asc', 'title_desc', 'name_asc', 'name_desc', 'size_asc', 'size_desc', 'posted_asc', 'posted_desc', 'cat_asc', 'cat_desc'];
}
/**
* @return string
*/
protected function getBrowseBy(): string
{
$browseBy = ' ';
$browseByArr = ['title', 'director', 'actors', 'genre', 'id'];
foreach ($browseByArr as $bb) {
if (isset($_REQUEST[$bb]) && ! empty($_REQUEST[$bb])) {
$bbv = stripslashes($_REQUEST[$bb]);
if ($bb === 'genre') {
$bbv = $this->getGenreID($bbv);
}
if ($bb === 'id') {
$browseBy .= 'AND xxx.'.$bb.'='.$bbv;
} else {
$browseBy .= 'AND xxx.'.$bb.' '.$this->pdo->likeString($bbv, true, true);
}
}
}
return $browseBy;
}
/**
* Create click-able links to actors/genres/directors/etc..
*
* @param $data
* @param $field
*
* @return string
*/
public function makeFieldLinks($data, $field): string
{
if (empty($data[$field])) {
return '';
}
$tmpArr = explode(',', $data[$field]);
$newArr = [];
$i = 0;
foreach ($tmpArr as $ta) {
if (trim($ta) === '') {
continue;
}
if ($field === 'genre') {
$ta = $this->getGenres(true, $ta);
$ta = $ta['title'];
}
if ($i > 7) {
break;
} //only use first 8
$newArr[] = ''.$ta.'';
$i++;
}
return implode(', ', $newArr);
}
/**
* Update XXX Information from getXXXCovers.php in misc/testing/PostProc.
*
* @param string $id
* @param string $title
* @param string $tagLine
* @param string $plot
* @param string $genre
* @param string $director
* @param string $actors
* @param string $extras
* @param string $productInfo
* @param string $trailers
* @param string $directUrl
* @param string $classUsed
* @param string $cover
* @param string $backdrop
*/
public function update(
$id = '',
$title = '',
$tagLine = '',
$plot = '',
$genre = '',
$director = '',
$actors = '',
$extras = '',
$productInfo = '',
$trailers = '',
$directUrl = '',
$classUsed = '',
$cover = '',
$backdrop = ''
): void {
if (! empty($id)) {
XxxInfo::query()->where('id', $id)->update(
[
'title' => $title,
'tagline' => $tagLine,
'plot' => "\x1f\x8b\x08\x00".gzcompress($plot),
'genre' => substr($genre, 0, 64),
'director' => $director,
'actors' => $actors,
'extras' => $extras,
'productinfo' => $productInfo,
'trailers'=> $trailers,
'directurl' => $directUrl,
'classused' => $classUsed,
'cover' => empty($cover) ? 0 : $cover,
'backdrop' => empty($backdrop) ? 0 : $backdrop,
]
);
}
}
/**
* Get all genres for search-filter.tpl.
*
* @param bool $activeOnly
*
* @return array|null
*/
public function getAllGenres($activeOnly = false): ?array
{
$ret = null;
if ($activeOnly) {
$res = $this->pdo->query(
'SELECT title FROM genres WHERE disabled = 0 AND type = '.
Category::XXX_ROOT.' ORDER BY title'
);
} else {
$res = $this->pdo->query(
'SELECT title FROM genres WHERE disabled = 1 AND type = '.
Category::XXX_ROOT.' ORDER BY title'
);
}
foreach ($res as $arr => $value) {
$ret[] = $value['title'];
}
return $ret;
}
/**
* Get Genres for activeonly and/or an ID.
*
* @param bool $activeOnly
* @param null|string $gid
*
* @return array|bool
*/
public function getGenres($activeOnly = false, $gid = null)
{
if ($gid !== null) {
$gid = ' AND id = '.$this->pdo->escapeString($gid).' ORDER BY title';
} else {
$gid = ' ORDER BY title';
}
if ($activeOnly) {
return $this->pdo->queryOneRow('SELECT title FROM genres WHERE disabled = 0 AND type = '.Category::XXX_ROOT.$gid);
}
return $this->pdo->queryOneRow('SELECT title FROM genres WHERE disabled = 1 AND type = '.Category::XXX_ROOT.$gid);
}
/**
* Get Genre id's Of the title.
*
* @param $arr - Array or String
*
* @return string - If array .. 1,2,3,4 if string .. 1
*/
protected function getGenreID($arr): string
{
$ret = null;
if (! is_array($arr)) {
$res = $this->pdo->queryOneRow('SELECT id FROM genres WHERE title = '.$this->pdo->escapeString($arr));
if ($res !== false) {
return $res['id'];
}
}
foreach ($arr as $key => $value) {
$res = $this->pdo->queryOneRow('SELECT id FROM genres WHERE title = '.$this->pdo->escapeString($value));
if ($res !== false) {
$ret .= ','.$res['id'];
} else {
$ret .= ','.$this->insertGenre($value);
}
}
$ret = ltrim($ret, ',');
return $ret;
}
/**
* Inserts Genre and returns last affected row (Genre ID).
*
* @param $genre
*
* @return bool
*/
private function insertGenre($genre): bool
{
$res = '';
if ($genre !== null) {
$res = $this->pdo->queryInsert(sprintf('INSERT INTO genres (title, type, disabled) VALUES (%s ,%d ,%d)', $this->pdo->escapeString($genre), Category::XXX_ROOT, 0));
}
return $res;
}
/**
* Inserts Trailer Code by Class.
*
* @param $whichclass
* @param $res
*
* @return string
*/
public function insertSwf($whichclass, $res): string
{
$ret = '';
if ($whichclass === 'ade') {
if (! empty($res)) {
$trailers = unserialize($res, 'ade');
$ret .= "';
return $ret;
}
}
if ($whichclass === 'pop') {
if (! empty($res)) {
$trailers = unserialize($res, 'pop');
$ret .= "