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->movieqty = Settings::settingValue('..maxxxxprocessed') !== '' ? (int) Settings::settingValue('..maxxxxprocessed') : 100;
$this->showPasswords = Releases::showPasswords();
$this->echooutput = ($options['Echo'] && config('nntmux.echocli'));
$this->imgSavePath = NN_COVERS.'xxx'.DS;
$this->cookie = NN_TMP.'xxx.cookie';
}
/**
* 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 XXX releases with covers for xxx browse page.
*
*
* @param $page
* @param $cat
* @param $orderBy
* @param array $excludedcats
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed
* @throws \Exception
*/
public function getXXXRange($page, $cat, $orderBy, array $excludedcats = [])
{
$order = $this->getXXXOrder($orderBy);
$sql = Release::query()->selectRaw("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")
->select(
[
'xxx.*',
\Illuminate\Support\Facades\DB::raw('UNCOMPRESS(xxx.plot) AS plot'),
'r.movieinfo_id',
'g.name as group_name',
'rn.releases_id as nfoid',
]
)
->from('releases as r')
->leftJoin('groups as g', 'g.id', '=', 'r.groups_id')
->leftJoin('release_nfos as rn', 'rn.releases_id', '=', 'r.id')
->leftJoin('dnzb_failures as df', 'df.release_id', '=', 'r.id')
->leftJoin('categories as c', 'c.id', '=', 'r.categories_id')
->leftJoin('categories as cp', 'cp.id', '=', 'c.parentid')
->join('xxxinfo as xxx', 'xxx.id', '=', 'r.xxxinfo_id')
->where('r.nzbstatus', '=', 1)
->where('xxx.title', '!=', '');
Releases::showPasswords($sql, true);
if (\count($excludedcats) > 0) {
$sql->whereNotIn('r.categories_id', $excludedcats);
}
if (\count($cat) > 0 && $cat[0] !== -1) {
Category::getCategorySearch($cat, $sql, true);
}
$sql->groupBy('xxx.id')
->orderBy($order[0], $order[1]);
$return = Cache::get(md5($page.implode('.', $cat).implode('.', $excludedcats)));
if ($return !== null) {
return $return;
}
$return = $sql->paginate(config('nntmux.items_per_cover_page'));
$expiresAt = Carbon::now()->addSeconds(config('nntmux.cache_expiry_long'));
Cache::put(md5($page.implode('.', $cat).implode('.', $excludedcats)), $return, $expiresAt);
return $return;
}
/**
* Get the order type the user requested on the xxx 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;
}
/**
* 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
*/
public function getAllGenres($activeOnly = false): array
{
$ret = [];
if ($activeOnly) {
$res = Genre::query()->where(['disabled' => 0, 'type' => Category::XXX_ROOT])->orderBy('title')->get(['title']);
} else {
$res = Genre::query()->where(['type' => Category::XXX_ROOT])->orderBy('title')->get(['title']);
}
foreach ($res as $arr => $value) {
$ret[] = $value['title'];
}
return $ret;
}
/**
* @param bool $activeOnly
* @param null $gid
* @return mixed
*/
public function getGenres($activeOnly = false, $gid = null)
{
if ($activeOnly) {
return Genre::query()->where(['disabled' => 0, 'type' => Category::XXX_ROOT])->when($gid !== null, function ($query) use ($gid) {
return $query->where('id', $gid);
})->orderBy('title')->first(['title']);
}
return Genre::query()->where(['type' => Category::XXX_ROOT])->when($gid !== null, function ($query) use ($gid) {
return $query->where('id', $gid);
})->orderBy('title')->first(['title']);
}
/**
* 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 = Genre::query()->where('title', $arr)->first(['id']);
if ($res !== null) {
return $res['id'];
}
}
foreach ($arr as $key => $value) {
$res = Genre::query()->where('title', $value)->first(['id']);
if ($res !== null) {
$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 int|string
*/
private function insertGenre($genre)
{
$res = '';
if ($genre !== null) {
$res = Genre::query()->insert(['title' => $genre, 'type' => Category::XXX_ROOT, 'disabled' => 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 .= "