mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-31 10:18:55 +00:00
Further update to getCategorySearch
This commit is contained in:
@@ -107,7 +107,7 @@ class Books
|
||||
$browseby = $this->getBrowseBy();
|
||||
$catsrch = '';
|
||||
if (\count($cat) > 0 && $cat[0] !== -1) {
|
||||
$catsrch = Category::getCategorySearch($cat);
|
||||
$catsrch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
$exccatlist = '';
|
||||
if (\count($excludedCats) > 0) {
|
||||
|
||||
@@ -140,7 +140,7 @@ class Console
|
||||
$browseBy = $this->getBrowseBy();
|
||||
$catsrch = '';
|
||||
if (\count($cat) > 0 && (int) $cat[0] !== -1) {
|
||||
$catsrch = Category::getCategorySearch($cat);
|
||||
$catsrch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
$exccatlist = '';
|
||||
if (\count($excludedCats) > 0) {
|
||||
|
||||
@@ -171,7 +171,7 @@ class Games
|
||||
$browseBy = $this->getBrowseBy();
|
||||
$catsrch = '';
|
||||
if (\count($cat) > 0 && $cat[0] !== -1) {
|
||||
$catsrch = Category::getCategorySearch($cat);
|
||||
$catsrch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
if ($maxAge > 0) {
|
||||
$maxAge = sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge);
|
||||
|
||||
@@ -187,10 +187,7 @@ class Movie
|
||||
->where('movieinfo.imdbid', '!=', '0000000')
|
||||
->when($maxAge > 0, fn ($query) => $query->whereRaw('r.postdate > NOW() - INTERVAL ? DAY', [$maxAge]))
|
||||
->when(! empty($excludedCats), fn ($query) => $query->whereNotIn('r.categories_id', $excludedCats))
|
||||
->when(! empty($categorySearch), fn ($query) => $query->whereRaw(
|
||||
// Check if $categorySearch starts with AND or OR and clean it up
|
||||
preg_match('/^\s*(AND|OR)\s+/i', $categorySearch) ? preg_replace('/^\s*(AND|OR)\s+/i', '', $categorySearch) : $categorySearch
|
||||
))
|
||||
->when(! empty($categorySearch), fn ($query) => $query->whereRaw($categorySearch))
|
||||
->groupBy('movieinfo.imdbid')
|
||||
->orderBy($order[0], $order[1])
|
||||
->offset($start)
|
||||
|
||||
@@ -130,7 +130,7 @@ class Music
|
||||
$browseby = $this->getBrowseBy();
|
||||
$catsrch = '';
|
||||
if (\count($cat) > 0 && (int) $cat[0] !== -1) {
|
||||
$catsrch = Category::getCategorySearch($cat);
|
||||
$catsrch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
$exccatlist = '';
|
||||
if (\count($excludedCats) > 0) {
|
||||
|
||||
@@ -82,7 +82,7 @@ class Releases extends Release
|
||||
ORDER BY %8\$s %9\$s",
|
||||
NZB::NZB_ADDED,
|
||||
$this->showPasswords(),
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
($maxAge > 0 ? (' AND postdate > NOW() - INTERVAL '.$maxAge.' DAY ') : ''),
|
||||
(\count($excludedCats) ? (' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')') : ''),
|
||||
((int) $groupName !== -1 ? sprintf(' AND g.name = %s ', escapeString($groupName)) : ''),
|
||||
@@ -124,7 +124,7 @@ class Releases extends Release
|
||||
NZB::NZB_ADDED,
|
||||
$this->showPasswords(),
|
||||
($groupName !== -1 ? sprintf(' AND g.name = %s', escapeString($groupName)) : ''),
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
($maxAge > 0 ? (' AND r.postdate > NOW() - INTERVAL '.$maxAge.' DAY ') : ''),
|
||||
(\count($excludedCats) ? (' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')') : '')
|
||||
));
|
||||
@@ -474,7 +474,7 @@ class Releases extends Release
|
||||
|
||||
$catQuery = '';
|
||||
if ($type === 'basic') {
|
||||
$catQuery = Category::getCategorySearch($cat);
|
||||
$catQuery = Category::getCategorySearch($cat, true);
|
||||
} elseif ($type === 'advanced' && (int) $cat[0] !== -1) {
|
||||
$catQuery = sprintf('AND r.categories_id = %d', $cat[0]);
|
||||
}
|
||||
@@ -560,7 +560,7 @@ class Releases extends Release
|
||||
}
|
||||
}
|
||||
|
||||
$catQuery = Category::getCategorySearch($cat);
|
||||
$catQuery = Category::getCategorySearch($cat, true);
|
||||
|
||||
$whereSql = sprintf(
|
||||
'WHERE r.passwordstatus %s AND r.nzbstatus = %d %s %s %s %s %s %s',
|
||||
@@ -712,7 +712,7 @@ class Releases extends Release
|
||||
$this->showPasswords(),
|
||||
$showSql,
|
||||
(! empty($name) && ! empty($searchResult)) ? 'AND r.id IN ('.implode(',', $searchResult).')' : '',
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
$maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : '',
|
||||
$minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : '',
|
||||
! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
|
||||
@@ -852,7 +852,7 @@ class Releases extends Release
|
||||
$this->showPasswords(),
|
||||
$showSql,
|
||||
(! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
($maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : ''),
|
||||
($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : ''),
|
||||
! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : ''
|
||||
@@ -929,7 +929,7 @@ class Releases extends Release
|
||||
($aniDbID > -1 ? sprintf(' AND r.anidbid = %d ', $aniDbID) : ''),
|
||||
(! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''),
|
||||
! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
|
||||
);
|
||||
$baseSql = sprintf(
|
||||
@@ -1002,7 +1002,7 @@ class Releases extends Release
|
||||
($tmDbId !== -1 && is_numeric($tmDbId)) ? sprintf(' AND m.tmdbid = %d ', $tmDbId) : '',
|
||||
($traktId !== -1 && is_numeric($traktId)) ? sprintf(' AND m.traktid = %d ', $traktId) : '',
|
||||
! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '',
|
||||
Category::getCategorySearch($cat),
|
||||
Category::getCategorySearch($cat, true),
|
||||
$maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '',
|
||||
$minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : ''
|
||||
);
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class XXX
|
||||
{
|
||||
$catSrch = '';
|
||||
if (\count($cat) > 0 && $cat[0] !== -1) {
|
||||
$catSrch = Category::getCategorySearch($cat);
|
||||
$catSrch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
$order = $this->getXXXOrder($orderBy);
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
|
||||
|
||||
@@ -44,7 +44,7 @@ class RSS extends ApiController
|
||||
$userID
|
||||
);
|
||||
} elseif ((int) $cat[0] !== -1) {
|
||||
$catSearch = Category::getCategorySearch($cat);
|
||||
$catSearch = Category::getCategorySearch($cat, true);
|
||||
}
|
||||
}
|
||||
$sql =
|
||||
|
||||
+24
-15
@@ -304,18 +304,17 @@ class Category extends Model
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getCategorySearch(array $cat = []): string
|
||||
public static function getCategorySearch(array $cat = [], bool $useRaw = false): array|string
|
||||
{
|
||||
$categories = [];
|
||||
|
||||
// If multiple categories were sent in a single array position, slice and add them
|
||||
if (strpos($cat[0], ',') !== false) {
|
||||
$tmpcats = explode(',', $cat[0]);
|
||||
// Reset the category to the first comma separated value in the string
|
||||
$cat[0] = $tmpcats[0];
|
||||
// Add the remaining categories in the string to the original array
|
||||
foreach (array_slice($tmpcats, 1) as $tmpcat) {
|
||||
$cat[] = $tmpcat;
|
||||
// If multiple categories were sent in a single array position, split them
|
||||
if (isset($cat[0]) && str_contains($cat[0], ',')) {
|
||||
$tempCategories = explode(',', $cat[0]);
|
||||
// Reset the first category and add the remaining ones
|
||||
$cat[0] = $tempCategories[0];
|
||||
foreach (array_slice($tempCategories, 1) as $tempCategory) {
|
||||
$cat[] = $tempCategory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,14 +327,24 @@ class Category extends Model
|
||||
}
|
||||
}
|
||||
|
||||
// Return based on whether it's for raw SQL or Laravel query builder
|
||||
$catCount = count($categories);
|
||||
$catSearch = match ($catCount) {
|
||||
0 => 'AND 1=1',
|
||||
1 => $categories[0] !== -1 ? ' AND r.categories_id = '.$categories[0] : '',
|
||||
default => ' AND r.categories_id IN ('.implode(', ', $categories).') ',
|
||||
};
|
||||
|
||||
return $catSearch;
|
||||
if ($useRaw) {
|
||||
// Raw MySQL query string
|
||||
return match ($catCount) {
|
||||
0 => '1=1', // Always true condition
|
||||
1 => $categories[0] !== -1 ? 'AND r.categories_id = '.$categories[0] : '1=1', // Single category case
|
||||
default => 'AND r.categories_id IN ('.implode(', ', $categories).')', // Multiple categories
|
||||
};
|
||||
}
|
||||
|
||||
// Laravel Query Builder array
|
||||
return match ($catCount) {
|
||||
0 => ['1=1'], // Always true condition
|
||||
1 => [$categories[0] !== -1 ? 'r.categories_id = ?' : '1=1', $categories[0]],
|
||||
default => 'r.categories_id IN ('.implode(', ', $categories).')',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user