Remove nntmux/Category class and move its functions into Category model

This commit is contained in:
DariusIII
2018-01-11 11:03:12 +01:00
parent 5c1fd3558e
commit cdf881efde
59 changed files with 573 additions and 833 deletions
+1
View File
@@ -1,4 +1,5 @@
2018-01-11 DariusIII
* Chg: Remove nntmux/Category class and move its functions into Category model
* Fix: Fix missing Carbon class use statament
2018-01-10 DariusIII
* Chg: Add missing DatabaseSeeder class
+453
View File
@@ -8,6 +8,106 @@ use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
/**
* Category constants.
* Do NOT use the values, as they may change, always use the constant - that's what it's for.
*/
public const OTHER_MISC = '0010';
public const OTHER_HASHED = '0020';
public const GAME_NDS = '1010';
public const GAME_PSP = '1020';
public const GAME_WII = '1030';
public const GAME_XBOX = '1040';
public const GAME_XBOX360 = '1050';
public const GAME_WIIWARE = '1060';
public const GAME_XBOX360DLC = '1070';
public const GAME_PS3 = '1080';
public const GAME_OTHER = '1999';
public const GAME_3DS = '1110';
public const GAME_PSVITA = '1120';
public const GAME_WIIU = '1130';
public const GAME_XBOXONE = '1140';
public const GAME_PS4 = '1180';
public const MOVIE_FOREIGN = '2010';
public const MOVIE_OTHER = '2999';
public const MOVIE_SD = '2030';
public const MOVIE_HD = '2040';
public const MOVIE_UHD = '2045';
public const MOVIE_3D = '2050';
public const MOVIE_BLURAY = '2060';
public const MOVIE_DVD = '2070';
public const MOVIE_WEBDL = '2080';
public const MUSIC_MP3 = '3010';
public const MUSIC_VIDEO = '3020';
public const MUSIC_AUDIOBOOK = '3030';
public const MUSIC_LOSSLESS = '3040';
public const MUSIC_OTHER = '3999';
public const MUSIC_FOREIGN = '3060';
public const PC_0DAY = '4010';
public const PC_ISO = '4020';
public const PC_MAC = '4030';
public const PC_PHONE_OTHER = '4040';
public const PC_GAMES = '4050';
public const PC_PHONE_IOS = '4060';
public const PC_PHONE_ANDROID = '4070';
public const TV_WEBDL = '5010';
public const TV_FOREIGN = '5020';
public const TV_SD = '5030';
public const TV_HD = '5040';
public const TV_UHD = '5045';
public const TV_OTHER = '5999';
public const TV_SPORT = '5060';
public const TV_ANIME = '5070';
public const TV_DOCU = '5080';
public const XXX_DVD = '6010';
public const XXX_WMV = '6020';
public const XXX_XVID = '6030';
public const XXX_X264 = '6040';
public const XXX_CLIPHD = '6041';
public const XXX_CLIPSD = '6042';
public const XXX_UHD = '6045';
public const XXX_PACK = '6050';
public const XXX_IMAGESET = '6060';
public const XXX_OTHER = '6999';
public const XXX_SD = '6080';
public const XXX_WEBDL = '6090';
public const BOOKS_MAGAZINES = '7010';
public const BOOKS_EBOOK = '7020';
public const BOOKS_COMICS = '7030';
public const BOOKS_TECHNICAL = '7040';
public const BOOKS_FOREIGN = '7060';
public const BOOKS_UNKNOWN = '7999';
public const OTHER_ROOT = '0000';
public const GAME_ROOT = '1000';
public const MOVIE_ROOT = '2000';
public const MUSIC_ROOT = '3000';
public const PC_ROOT = '4000';
public const TV_ROOT = '5000';
public const XXX_ROOT = '6000';
public const BOOKS_ROOT = '7000';
public const STATUS_INACTIVE = 0;
public const STATUS_ACTIVE = 1;
public const STATUS_DISABLED = 2;
public const OTHERS_GROUP =
[
self::BOOKS_UNKNOWN,
self::GAME_OTHER,
self::MOVIE_OTHER,
self::MUSIC_OTHER,
self::PC_PHONE_OTHER,
self::TV_OTHER,
self::OTHER_HASHED,
self::XXX_OTHER,
self::OTHER_MISC,
];
/**
* Temporary category while we sort through the name.
* @var int
*/
protected $tmpCat = self::OTHER_MISC;
/**
* @var bool
*/
@@ -23,26 +123,41 @@ class Category extends Model
*/
protected $guarded = [];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function releases()
{
return $this->hasMany(Release::class, 'categories_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo(static::class, 'parentid');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany(static::class, 'parentid');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function userExcludedCategory()
{
return $this->hasMany(UserExcludedCategory::class, 'categories_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function roleExcludedCategory()
{
return $this->belongsTo(RoleExcludedCategory::class, 'categories_id');
@@ -73,4 +188,342 @@ class Category extends Model
return $recent;
}
/**
* Parse category search constraints.
*
* @param array $cat
*
* @return string $catsrch
*/
public static function getCategorySearch(array $cat = []): 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;
}
}
foreach ($cat as $category) {
if ($category !== -1 && self::isParent($category)) {
foreach (self::getChildren($category) as $child) {
$categories[] = $child['id'];
}
} elseif ($category > 0) {
$categories[] = $category;
}
}
$catCount = \count($categories);
switch ($catCount) {
//No category constraint
case 0:
$catsrch = ' AND 1=1 ';
break;
// One category constraint
case 1:
$catsrch = $categories[0] !== -1 ? ' AND r.categories_id = '.$categories[0] : '';
break;
// Multiple category constraints
default:
$catsrch = ' AND r.categories_id IN ('.implode(', ', $categories).') ';
break;
}
return $catsrch;
}
/**
* Returns a concatenated list of other categories.
*
* @return string
*/
public static function getCategoryOthersGroup(): string
{
return implode(
',',
self::OTHERS_GROUP
);
}
/**
* @param $category
*
* @return mixed
*/
public static function getCategoryValue($category)
{
return \constant('self::'.$category);
}
/**
* Check if category is parent.
*
* @param $cid
*
* @return bool
*/
public static function isParent($cid): bool
{
$ret = self::query()->where(['id' => $cid, 'parentid' => null])->first();
return $ret !== null;
}
/**
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public static function getFlat()
{
return self::query()->get();
}
/**
* Get children of a parent category.
*
*
* @param $cid
* @return mixed
*/
public static function getChildren($cid)
{
return self::find($cid)->children;
}
/**
* Get names of enabled parent categories.
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public static function getEnabledParentNames()
{
return self::query()
->where(['parentid' => null, 'status' => 1])
->get(['title']);
}
/**
* Returns category ID's for site disabled categories.
*
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public static function getDisabledIDs()
{
return self::query()
->where('status', '=', 2)
->orWhere(['status' => 2, 'parentid' => null])
->get(['id']);
}
/**
* Get a category row by its id.
*
*
* @param $id
* @return \Illuminate\Database\Eloquent\Model|null|static
*/
public static function getById($id)
{
return self::query()
->with('parent')
->where('id', $id)
->first();
}
/**
* Get multiple categories.
*
* @param array $ids
*
* @return array|bool
*/
public static function getByIds($ids)
{
if (\count($ids) > 0) {
$catIds = Cache::get('categoryids');
if ($catIds !== null) {
return $catIds;
}
$catIds = self::query()->whereIn('id', $ids)->get();
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
Cache::put('categoryids', $catIds, $expiresAt);
return $catIds;
}
return false;
}
/**
* Return the parent and category name from the supplied categoryID.
*
*
* @param $ID
* @return string
*/
public static function getNameByID($ID): string
{
$cat = self::query()->where('id', $ID)->first();
return $cat !== null ? $cat->parent->title.' -> '.$cat->title : '';
}
/**
* @param $title
* @param $parent
* @return bool|mixed
*/
public static function getIdByName($title, $parent)
{
$cat = self::query()->where('title', $title)->with('parent.'.$parent)->first(['id']);
return $cat !== null ? $cat->id : false;
}
/**
* Update a category.
*
*
* @param $id
* @param $status
* @param $desc->update
* @param $disablepreview
* @param $minsize
* @param $maxsize
* @return int
*/
public static function updateCategory($id, $status, $desc, $disablepreview, $minsize, $maxsize): int
{
return self::query()->where('id', $id)->update(
[
'disablepreview' => $disablepreview,
'status' => $status,
'minsizetoformrelease' => $minsize,
'maxsizetoformrelease' => $maxsize,
'description' => $desc,
]
);
}
/**
* @param array $excludedCats
*
* @param array $roleExcludedCats
*
* @return array
*/
public static function getForMenu(array $excludedCats = [], array $roleExcludedCats = []): array
{
$ret = [];
$sql = self::query()->where('status', '=', self::STATUS_ACTIVE);
if (\count($excludedCats) > 0 && \count($roleExcludedCats) === 0) {
$sql->whereNotIn('id', $excludedCats);
} elseif (\count($excludedCats) > 0 && \count($roleExcludedCats) > 0) {
$sql->whereNotIn('id', [$excludedCats, $roleExcludedCats]);
} elseif (\count($excludedCats) === 0 && \count($roleExcludedCats) > 0) {
$sql->whereNotIn('id', $roleExcludedCats);
}
$arrsql = Cache::get(md5(implode(',', $excludedCats).implode(',', $roleExcludedCats)));
if ($arrsql !== null) {
$arr = $arrsql;
} else {
$arr = $sql->get();
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
Cache::put(md5(implode(',', $excludedCats).implode(',', $roleExcludedCats)), $arr, $expiresAt);
}
foreach ($arr as $key => $val) {
if ($val['id'] === '0') {
$item = $arr[$key];
unset($arr[$key]);
$arr[] = $item;
break;
}
}
foreach ($arr as $a) {
if (empty($a['parentid'])) {
$ret[] = $a;
}
}
foreach ($ret as $key => $parent) {
$subcatlist = [];
$subcatnames = [];
foreach ($arr as $a) {
if ($a['parentid'] === $parent['id']) {
$subcatlist[] = $a;
$subcatnames[] = $a['title'];
}
}
if (\count($subcatlist) > 0) {
array_multisort($subcatnames, SORT_ASC, $subcatlist);
$ret[$key]['subcatlist'] = $subcatlist;
} else {
unset($ret[$key]);
}
}
return $ret;
}
/**
* Return a list of categories for use in a dropdown.
*
* @param bool $blnIncludeNoneSelected
*
* @return array
*/
public static function getForSelect($blnIncludeNoneSelected = true): array
{
$categories = self::getCategories();
$temp_array = [];
if ($blnIncludeNoneSelected) {
$temp_array[-1] = '--Please Select--';
}
foreach ($categories as $category) {
$temp_array[$category['id']] = $category['title'];
}
return $temp_array;
}
/**
* @param bool $activeOnly
* @param array $excludedCats
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection|static[]
*/
public static function getCategories($activeOnly = false, array $excludedCats = [])
{
$sql = self::query()
->select(['categories.id', 'cp.id as parentid', 'categories.status'])
->selectRaw("CONCAT(cp.title, ' > ',categories.title) AS title")
->leftJoin('categories as cp', 'cp.id', '=', 'categories.parentid')
->orderBy('categories.id');
if ($activeOnly) {
$sql->where('categories.status', '=', self::STATUS_ACTIVE);
}
if (\count($excludedCats) > 0) {
$sql->whereNotIn('categories.id', $excludedCats);
}
return $sql->get()->toArray();
}
}
-1
View File
@@ -2,7 +2,6 @@
namespace App\Models;
use nntmux\Category;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Model;
+1 -2
View File
@@ -2,12 +2,11 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\db\DB;
use nntmux\Category;
use nntmux\ColorCLI;
use nntmux\ConsoleTools;
$category = new Category();
$pdo = new DB();
$consoletools = new ConsoleTools();
$ran = false;
+1 -2
View File
@@ -4,11 +4,10 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\db\DB;
use nntmux\Console;
use nntmux\Category;
$category = new Category();
$pdo = new DB();
$console = new Console(['Echo' => true, 'Settings' => $pdo]);
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\db\DB;
use nntmux\Category;
use nntmux\ReleaseImage;
$pdo = new DB();
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\db\DB;
use nntmux\Category;
use nntmux\ColorCLI;
use nntmux\Categorize;
use nntmux\ConsoleTools;
+1 -1
View File
@@ -2,11 +2,11 @@
require_once dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\Nfo;
use nntmux\NZB;
use nntmux\NNTP;
use nntmux\db\DB;
use nntmux\Category;
use nntmux\ColorCLI;
use App\Models\Predb;
use nntmux\NameFixer;
+1 -1
View File
@@ -2,10 +2,10 @@
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\Category;
use nntmux\Tmux;
use nntmux\db\DB;
use nntmux\TmuxRun;
use nntmux\Category;
use nntmux\ColorCLI;
use nntmux\TmuxOutput;
use App\Models\Settings;
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use ApaiIO\ApaiIO;
use Carbon\Carbon;
@@ -154,7 +155,7 @@ class Books
$catsrch = '';
if (\count($cat) > 0 && $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
$maxage = '';
-473
View File
@@ -1,473 +0,0 @@
<?php
namespace nntmux;
use nntmux\db\DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use App\Models\Category as CategoryModel;
use Illuminate\Support\Facades\Cache as CacheFacade;
/**
* This class manages the site wide categories.
*/
class Category
{
/**
* Category constants.
* Do NOT use the values, as they may change, always use the constant - that's what it's for.
*/
public const OTHER_MISC = '0010';
public const OTHER_HASHED = '0020';
public const GAME_NDS = '1010';
public const GAME_PSP = '1020';
public const GAME_WII = '1030';
public const GAME_XBOX = '1040';
public const GAME_XBOX360 = '1050';
public const GAME_WIIWARE = '1060';
public const GAME_XBOX360DLC = '1070';
public const GAME_PS3 = '1080';
public const GAME_OTHER = '1999';
public const GAME_3DS = '1110';
public const GAME_PSVITA = '1120';
public const GAME_WIIU = '1130';
public const GAME_XBOXONE = '1140';
public const GAME_PS4 = '1180';
public const MOVIE_FOREIGN = '2010';
public const MOVIE_OTHER = '2999';
public const MOVIE_SD = '2030';
public const MOVIE_HD = '2040';
public const MOVIE_UHD = '2045';
public const MOVIE_3D = '2050';
public const MOVIE_BLURAY = '2060';
public const MOVIE_DVD = '2070';
public const MOVIE_WEBDL = '2080';
public const MUSIC_MP3 = '3010';
public const MUSIC_VIDEO = '3020';
public const MUSIC_AUDIOBOOK = '3030';
public const MUSIC_LOSSLESS = '3040';
public const MUSIC_OTHER = '3999';
public const MUSIC_FOREIGN = '3060';
public const PC_0DAY = '4010';
public const PC_ISO = '4020';
public const PC_MAC = '4030';
public const PC_PHONE_OTHER = '4040';
public const PC_GAMES = '4050';
public const PC_PHONE_IOS = '4060';
public const PC_PHONE_ANDROID = '4070';
public const TV_WEBDL = '5010';
public const TV_FOREIGN = '5020';
public const TV_SD = '5030';
public const TV_HD = '5040';
public const TV_UHD = '5045';
public const TV_OTHER = '5999';
public const TV_SPORT = '5060';
public const TV_ANIME = '5070';
public const TV_DOCU = '5080';
public const XXX_DVD = '6010';
public const XXX_WMV = '6020';
public const XXX_XVID = '6030';
public const XXX_X264 = '6040';
public const XXX_CLIPHD = '6041';
public const XXX_CLIPSD = '6042';
public const XXX_UHD = '6045';
public const XXX_PACK = '6050';
public const XXX_IMAGESET = '6060';
public const XXX_OTHER = '6999';
public const XXX_SD = '6080';
public const XXX_WEBDL = '6090';
public const BOOKS_MAGAZINES = '7010';
public const BOOKS_EBOOK = '7020';
public const BOOKS_COMICS = '7030';
public const BOOKS_TECHNICAL = '7040';
public const BOOKS_FOREIGN = '7060';
public const BOOKS_UNKNOWN = '7999';
public const OTHER_ROOT = '0000';
public const GAME_ROOT = '1000';
public const MOVIE_ROOT = '2000';
public const MUSIC_ROOT = '3000';
public const PC_ROOT = '4000';
public const TV_ROOT = '5000';
public const XXX_ROOT = '6000';
public const BOOKS_ROOT = '7000';
public const STATUS_INACTIVE = 0;
public const STATUS_ACTIVE = 1;
public const STATUS_DISABLED = 2;
public const OTHERS_GROUP =
[
self::BOOKS_UNKNOWN,
self::GAME_OTHER,
self::MOVIE_OTHER,
self::MUSIC_OTHER,
self::PC_PHONE_OTHER,
self::TV_OTHER,
self::OTHER_HASHED,
self::XXX_OTHER,
self::OTHER_MISC,
];
/**
* Temporary category while we sort through the name.
* @var int
*/
protected $tmpCat = self::OTHER_MISC;
/**
* @var \nntmux\db\DB
*/
public $pdo;
/**
* Construct.
*
* @param array $options Class instances.
* @throws \Exception
*/
public function __construct(array $options = [])
{
$defaults = [
'Settings' => null,
];
$options += $defaults;
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
}
/**
* Parse category search constraints.
*
* @param array $cat
*
* @return string $catsrch
*/
public function getCategorySearch(array $cat = []): 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;
}
}
foreach ($cat as $category) {
if ($category !== -1 && $this->isParent($category)) {
foreach ($this->getChildren($category) as $child) {
$categories[] = $child['id'];
}
} elseif ($category > 0) {
$categories[] = $category;
}
}
$catCount = \count($categories);
switch ($catCount) {
//No category constraint
case 0:
$catsrch = ' AND 1=1 ';
break;
// One category constraint
case 1:
$catsrch = $categories[0] !== -1 ? ' AND r.categories_id = '.$categories[0] : '';
break;
// Multiple category constraints
default:
$catsrch = ' AND r.categories_id IN ('.implode(', ', $categories).') ';
break;
}
return $catsrch;
}
/**
* Returns a concatenated list of other categories.
*
* @return string
*/
public static function getCategoryOthersGroup(): string
{
return implode(
',',
self::OTHERS_GROUP
);
}
/**
* @param $category
*
* @return mixed
*/
public static function getCategoryValue($category)
{
return \constant('self::'.$category);
}
/**
* Check if category is parent.
*
* @param $cid
*
* @return bool
*/
public function isParent($cid): bool
{
$ret = CategoryModel::query()->where(['id' => $cid, 'parentid' => null])->first();
return $ret !== null;
}
/**
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getFlat()
{
return CategoryModel::query()->get();
}
/**
* Get children of a parent category.
*
*
* @param $cid
* @return mixed
*/
public function getChildren($cid)
{
return CategoryModel::find($cid)->children;
}
/**
* Get names of enabled parent categories.
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getEnabledParentNames()
{
return CategoryModel::query()
->where(['parentid' => null, 'status' => 1])
->get(['title']);
}
/**
* Returns category ID's for site disabled categories.
*
*
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getDisabledIDs()
{
return CategoryModel::query()
->where('status', '=', 2)
->orWhere(['status' => 2, 'parentid' => null])
->get(['id']);
}
/**
* Get a category row by its id.
*
*
* @param $id
* @return \Illuminate\Database\Eloquent\Model|null|static
*/
public function getById($id)
{
return CategoryModel::query()
->with('parent')
->where('id', $id)
->first();
}
/**
* Get multiple categories.
*
* @param array $ids
*
* @return array|bool
*/
public function getByIds($ids)
{
if (\count($ids) > 0) {
$catIds = CacheFacade::get('categoryids');
if ($catIds !== null) {
return $catIds;
}
$catIds = CategoryModel::query()->whereIn('id', $ids)->get();
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
CacheFacade::put('categoryids', $catIds, $expiresAt);
return $catIds;
}
return false;
}
/**
* Return the parent and category name from the supplied categoryID.
*
*
* @param $ID
* @return string
*/
public function getNameByID($ID): string
{
$cat = CategoryModel::query()->where('id', $ID)->first();
return $cat !== null ? $cat->parent->title.' -> '.$cat->title : '';
}
/**
* @param $title
* @param $parent
* @return bool|mixed
*/
public function getIdByName($title, $parent)
{
$cat = CategoryModel::query()->where('title', $title)->with('parent.'.$parent)->first(['id']);
return $cat !== null ? $cat->id : false;
}
/**
* Update a category.
*
*
* @param $id
* @param $status
* @param $desc->update
* @param $disablepreview
* @param $minsize
* @param $maxsize
* @return int
*/
public function update($id, $status, $desc, $disablepreview, $minsize, $maxsize): int
{
return CategoryModel::query()->where('id', $id)->update(
[
'disablepreview' => $disablepreview,
'status' => $status,
'minsizetoformrelease' => $minsize,
'maxsizetoformrelease' => $maxsize,
'description' => $desc,
]
);
}
/**
* @param array $excludedCats
*
* @param array $roleExcludedCats
*
* @return array
*/
public function getForMenu(array $excludedCats = [], array $roleExcludedCats = []): array
{
$ret = [];
$excCatList = '';
if (\count($excludedCats) > 0 && \count($roleExcludedCats) === 0) {
$excCatList = ' AND id NOT IN ('.implode(',', $excludedCats).')';
} elseif (\count($excludedCats) > 0 && \count($roleExcludedCats) > 0) {
$excCatList = ' AND id NOT IN ('.implode(',', $excludedCats).','.implode(',', $roleExcludedCats).')';
} elseif (\count($excludedCats) === 0 && \count($roleExcludedCats) > 0) {
$excCatList = ' AND id NOT IN ('.implode(',', $roleExcludedCats).')';
}
$sql = sprintf('SELECT * FROM categories WHERE status = %d %s', self::STATUS_ACTIVE, $excCatList);
$arrsql = Cache::get(md5($sql));
if ($arrsql !== null) {
$arr = $arrsql;
} else {
$arr = $this->pdo->query($sql);
$expiresAt = Carbon::now()->addSeconds(NN_CACHE_EXPIRY_LONG);
Cache::put(md5($sql), $arr, $expiresAt);
}
foreach ($arr as $key => $val) {
if ($val['id'] === '0') {
$item = $arr[$key];
unset($arr[$key]);
$arr[] = $item;
break;
}
}
foreach ($arr as $a) {
if (empty($a['parentid'])) {
$ret[] = $a;
}
}
foreach ($ret as $key => $parent) {
$subcatlist = [];
$subcatnames = [];
foreach ($arr as $a) {
if ($a['parentid'] === $parent['id']) {
$subcatlist[] = $a;
$subcatnames[] = $a['title'];
}
}
if (\count($subcatlist) > 0) {
array_multisort($subcatnames, SORT_ASC, $subcatlist);
$ret[$key]['subcatlist'] = $subcatlist;
} else {
unset($ret[$key]);
}
}
return $ret;
}
/**
* Return a list of categories for use in a dropdown.
*
* @param bool $blnIncludeNoneSelected
*
* @return array
*/
public function getForSelect($blnIncludeNoneSelected = true): array
{
$categories = $this->getCategories();
$temp_array = [];
if ($blnIncludeNoneSelected) {
$temp_array[-1] = '--Please Select--';
}
foreach ($categories as $category) {
$temp_array[$category['id']] = $category['title'];
}
return $temp_array;
}
/**
* @param bool $activeOnly
* @param array $excludedCats
* @return string|static
*/
public function getCategories($activeOnly = false, array $excludedCats = [])
{
return $this->pdo->query(
"SELECT c.id, CONCAT(cp.title, ' > ',c.title) AS title, cp.id AS parentid, c.status
FROM categories c
INNER JOIN categories cp ON cp.id = c.parentid ".
(
$activeOnly ?
sprintf(
' WHERE c.status = %d %s ',
self::STATUS_ACTIVE,
(\count($excludedCats) > 0 ? ' AND c.id NOT IN ('.implode(',', $excludedCats).')' : '')
) : ''
).
' ORDER BY c.id'
);
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use ApaiIO\ApaiIO;
use GuzzleHttp\Client;
@@ -158,7 +159,7 @@ class Console
$catsrch = '';
if (\count($cat) > 0 && (int) $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
$exccatlist = '';
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use Carbon\Carbon;
use App\Models\Genre;
@@ -234,7 +235,7 @@ class Games
$catsrch = '';
if (\count($cat) > 0 && $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
if ($maxAge > 0) {
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use Carbon\Carbon;
use Tmdb\ApiToken;
@@ -234,7 +235,7 @@ class Movie
{
$catsrch = '';
if (\count($cat) > 0 && $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
$order = $this->getMovieOrder($orderBy);
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use ApaiIO\ApaiIO;
use Carbon\Carbon;
@@ -151,7 +152,7 @@ class Music
$catsrch = '';
if (\count($cat) > 0 && (int) $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
$exccatlist = '';
+9 -10
View File
@@ -8,7 +8,7 @@ use App\Models\Release;
use App\Models\Settings;
use nntmux\utility\Utility;
use Illuminate\Support\Facades\Cache;
use App\Models\Category as CategoryModel;
use App\Models\Category;
/**
* Class Releases.
@@ -72,7 +72,6 @@ class Releases
$this->groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo]));
$this->sphinxSearch = new SphinxSearch();
$this->releaseSearch = new ReleaseSearch($this->pdo);
$this->category = new Category(['Settings' => $this->pdo]);
$this->showPasswords = self::showPasswords();
}
@@ -99,7 +98,7 @@ class Releases
NZB::NZB_ADDED,
$this->showPasswords,
($groupName !== -1 ? sprintf(' AND g.name = %s', $this->pdo->escapeString($groupName)) : ''),
$this->category->getCategorySearch($cat),
Category::getCategorySearch($cat),
($maxAge > 0 ? (' AND r.postdate > NOW() - INTERVAL '.$maxAge.' DAY ') : ''),
(\count($excludedCats) ? (' AND r.categories_id NOT IN ('.implode(',', $excludedCats).')') : '')
);
@@ -162,7 +161,7 @@ class Releases
ORDER BY %8\$s %9\$s",
NZB::NZB_ADDED,
$this->showPasswords,
$this->category->getCategorySearch($cat),
Category::getCategorySearch($cat),
($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 ', $this->pdo->escapeString($groupName)) : ''),
@@ -396,7 +395,7 @@ class Releases
return $this->concatenatedCategoryIDsCache;
}
$result = CategoryModel::query()
$result = Category::query()
->whereNotNull('categories.parentid')
->whereNotNull('cp.id')
->selectRaw('CONCAT(cp.id, ", ", categories.id) AS category_ids')
@@ -700,7 +699,7 @@ class Releases
$catQuery = '';
if ($type === 'basic') {
$catQuery = $this->category->getCategorySearch($cat);
$catQuery = Category::getCategorySearch($cat);
} elseif ($type === 'advanced' && (int) $cat[0] !== -1) {
$catQuery = sprintf('AND r.categories_id = %d', $cat[0]);
}
@@ -875,7 +874,7 @@ class Releases
$this->showPasswords,
$showSql,
($name !== '' ? $this->releaseSearch->getSearchSQL(['searchname' => $name]) : ''),
$this->category->getCategorySearch($cat),
Category::getCategorySearch($cat),
($maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : ''),
($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : '')
);
@@ -952,7 +951,7 @@ class Releases
NZB::NZB_ADDED,
($aniDbID > -1 ? sprintf(' AND r.anidbid = %d ', $aniDbID) : ''),
($name !== '' ? $this->releaseSearch->getSearchSQL(['searchname' => $name]) : ''),
$this->category->getCategorySearch($cat),
Category::getCategorySearch($cat),
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '')
);
@@ -1021,7 +1020,7 @@ class Releases
$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->category->getCategorySearch($cat),
Category::getCategorySearch($cat),
($maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : ''),
($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : '')
);
@@ -1108,7 +1107,7 @@ class Releases
{
// Get the category for the parent of this release.
$currRow = Release::getCatByRelId($currentID);
$catRow = (new Category(['Settings' => $this->pdo]))->getById($currRow['categories_id']);
$catRow = Category::getById($currRow['categories_id']);
$parentCat = $catRow['parentid'];
$results = $this->search(
+2 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux;
use App\Models\Category;
use nntmux\db\DB;
use Carbon\Carbon;
use App\Models\Genre;
@@ -128,7 +129,7 @@ class XXX
{
$catsrch = '';
if (\count($cat) > 0 && $cat[0] !== -1) {
$catsrch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catsrch = Category::getCategorySearch($cat);
}
$order = $this->getXXXOrder($orderBy);
+1 -1
View File
@@ -21,8 +21,8 @@
namespace nntmux\http;
use App\Models\Category;
use nntmux\Groups;
use nntmux\Category;
use App\Models\AudioData;
use nntmux\utility\Utility;
+3 -3
View File
@@ -21,8 +21,8 @@
namespace nntmux\http;
use App\Models\Category;
use nntmux\db\DB;
use nntmux\Category;
use App\Models\Settings;
use nntmux\utility\Utility;
use App\Extensions\util\Versions;
@@ -33,7 +33,7 @@ use App\Extensions\util\Versions;
abstract class Capabilities
{
/**
* @var DB
* @var \nntmux\db\DB
*/
public $pdo;
@@ -157,7 +157,7 @@ abstract class Capabilities
'audio-search' => ['available' => 'no', 'supportedParams' => ''],
],
'categories' => $this->type === 'caps'
? (new Category(['Settings' => $this->pdo]))->getForMenu()
? Category::getForMenu()
: null,
];
}
+2 -2
View File
@@ -2,8 +2,8 @@
namespace nntmux\http;
use App\Models\Category;
use nntmux\NZB;
use nntmux\Category;
use nntmux\Releases;
/**
@@ -58,7 +58,7 @@ class RSS extends Capabilities
$userID
);
} elseif ((int) $cat[0] !== -1) {
$catSearch = (new Category(['Settings' => $this->pdo]))->getCategorySearch($cat);
$catSearch = Category::getCategorySearch($cat);
}
}
+1 -1
View File
@@ -21,7 +21,7 @@
namespace nntmux\http;
use nntmux\Category;
use App\Models\Category;
use nntmux\Utility\Utility;
/**
+1 -1
View File
@@ -2,6 +2,7 @@
namespace nntmux\processing;
use App\Models\Category;
use nntmux\Nfo;
use nntmux\XXX;
use nntmux\NNTP;
@@ -13,7 +14,6 @@ use nntmux\Music;
use nntmux\Groups;
use nntmux\Console;
use nntmux\Sharing;
use nntmux\Category;
use nntmux\NameFixer;
use App\Models\Release;
use App\Models\Settings;
+2 -3
View File
@@ -2,12 +2,12 @@
namespace nntmux\processing;
use App\Models\Category;
use nntmux\NZB;
use nntmux\NNTP;
use nntmux\db\DB;
use nntmux\Genres;
use nntmux\Groups;
use nntmux\Category;
use nntmux\ColorCLI;
use nntmux\Releases;
use App\Models\Predb;
@@ -1164,7 +1164,6 @@ class ProcessReleases
public function deleteReleases(): void
{
$startTime = time();
$category = new Category(['Settings' => $this->pdo]);
$genres = new Genres(['Settings' => $this->pdo]);
$passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0;
$disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0;
@@ -1251,7 +1250,7 @@ class ProcessReleases
}
// Disabled categories.
$disabledCategories = $category->getDisabledIDs();
$disabledCategories = Category::getDisabledIDs();
if (\count($disabledCategories) > 0) {
foreach ($disabledCategories as $disabledCategory) {
$releases = $this->pdo->queryDirect(
+8 -8
View File
@@ -2,9 +2,9 @@
namespace nntmux\processing\post;
use App\Models\Category;
use nntmux\NZB;
use nntmux\db\DB;
use nntmux\Category;
use nntmux\ColorCLI;
use App\Models\Settings;
use App\Models\AnidbEpisode;
@@ -12,10 +12,10 @@ use nntmux\db\populate\AniDB as PaDb;
class AniDB
{
const PROC_EXTFAIL = -1; // Release Anime title/episode # could not be extracted from searchname
const PROC_NOMATCH = -2; // AniDB ID was not found in anidb table using extracted title/episode #
protected const PROC_EXTFAIL = -1; // Release Anime title/episode # could not be extracted from searchname
protected const PROC_NOMATCH = -2; // AniDB ID was not found in anidb table using extracted title/episode #
const REGEX_NOFORN = 'English|Japanese|German|Danish|Flemish|Dutch|French|Swe(dish|sub)|Deutsch|Norwegian';
protected const REGEX_NOFORN = 'English|Japanese|German|Danish|Flemish|Dutch|French|Swe(dish|sub)|Deutsch|Norwegian';
/**
* @var bool Whether or not to echo messages to CLI
@@ -23,12 +23,12 @@ class AniDB
public $echooutput;
/**
* @var PaDb
* @var
*/
public $padb;
/**
* @var DB
* @var \nntmux\db\DB
*/
public $pdo;
@@ -166,7 +166,7 @@ class AniDB
)
) {
$matches['epno'] = (int) $matches['epno'];
if (in_array($matches['epno'], ['Movie', 'OVA'], false)) {
if (\in_array($matches['epno'], ['Movie', 'OVA'], false)) {
$matches['epno'] = 1;
}
} elseif (preg_match(
@@ -224,7 +224,7 @@ class AniDB
// clean up the release name to ensure we get a good chance at getting a valid title
$cleanArr = $this->extractTitleEpisode($release['searchname']);
if (is_array($cleanArr) && isset($cleanArr['title']) && is_numeric($cleanArr['epno'])) {
if (\is_array($cleanArr) && isset($cleanArr['title']) && is_numeric($cleanArr['epno'])) {
echo ColorCLI::header(PHP_EOL.'Looking Up: ').
ColorCLI::primary(' Title: '.$cleanArr['title'].PHP_EOL.
' Episode: '.$cleanArr['epno']);
+1 -1
View File
@@ -2,12 +2,12 @@
namespace nntmux\processing\post;
use App\Models\Category;
use nntmux\Nfo;
use nntmux\NZB;
use nntmux\NNTP;
use nntmux\db\DB;
use nntmux\Groups;
use nntmux\Category;
use nntmux\ColorCLI;
use nntmux\Releases;
use nntmux\NameFixer;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace nntmux\processing\tv;
use nntmux\Category;
use App\Models\Category;
use App\Models\Video;
use App\Models\TvInfo;
use App\Models\Release;
+2 -1
View File
@@ -18,7 +18,8 @@
* @author niel
* @copyright 2014 nZEDb
*/
use nntmux\Category;
use App\Models\Category;
/**
* Returns the value of the specified Category constant.
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use App\Models\Category;
use nntmux\Binaries;
use nntmux\Category;
$page = new AdminPage();
$bin = new Binaries(['Settings' => $page->pdo]);
+4 -4
View File
@@ -1,11 +1,11 @@
<?php
use App\Models\Category;
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Category;
$page = new AdminPage();
$category = new Category();
$id = 0;
// set the current action
@@ -13,7 +13,7 @@ $action = $_REQUEST['action'] ?? 'view';
switch ($action) {
case 'submit':
$ret = $category->update($_POST['id'], $_POST['status'], $_POST['description'],
$ret = Category::updateCategory($_POST['id'], $_POST['status'], $_POST['description'],
$_POST['disablepreview'], $_POST['minsizetoformrelease'], $_POST['maxsizetoformrelease']);
header('Location:'.WWW_TOP.'/category-list.php');
break;
@@ -22,7 +22,7 @@ switch ($action) {
if (isset($_GET['id'])) {
$page->title = 'Category Edit';
$id = $_GET['id'];
$cat = $category->getById($id);
$cat = Category::getById($id);
$page->smarty->assign('category', $cat);
}
break;
+3 -3
View File
@@ -1,16 +1,16 @@
<?php
use App\Models\Category;
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Category;
$page = new AdminPage();
$category = new Category();
$page->title = 'Category List';
$categorylist = $category->getFlat();
$categorylist = Category::getFlat();
$page->smarty->assign('categorylist', $categorylist);
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use App\Models\Category;
use nntmux\Regexes;
use nntmux\Category;
$page = new AdminPage();
$regexes = new Regexes(['Settings' => $page->pdo, 'Table_Name' => 'category_regexes']);
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use App\Models\Category;
use nntmux\Regexes;
use nntmux\Category;
$page = new AdminPage();
$regexes = new Regexes(['Settings' => $page->pdo, 'Table_Name' => 'collection_regexes']);
-56
View File
@@ -1,56 +0,0 @@
<?php
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Category;
use nntmux\ReleaseRegex;
$page = new AdminPage();
$category = new Category();
$reg = new ReleaseRegex();
$id = 0;
// set the current action
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
switch ($action) {
case 'submit':
if ($_POST['id'] == '') {
$reg->add($_POST);
} else {
$ret = $reg->update($_POST);
}
header('Location:'.WWW_TOP.'/regex-list.php');
break;
case 'addtest':
if (isset($_GET['regex']) && isset($_GET['groupname'])) {
$r = ['groupname'=>$_GET['groupname'], 'regex'=>$_GET['regex'], 'ordinal'=>'1', 'status'=>'1'];
$page->smarty->assign('regex', $r);
}
break;
case 'view':
default:
$page->title = 'Release Regex Add';
if (isset($_GET['id'])) {
$page->title = 'Release Regex Edit';
$id = $_GET['id'];
$r = $reg->getByID($id);
} else {
$r = [];
$r['status'] = 1;
}
$page->smarty->assign('regex', $r);
break;
}
$page->smarty->assign('status_ids', [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE]);
$page->smarty->assign('status_names', ['Yes', 'No']);
$page->smarty->assign('catlist', $category->getForSelect(true));
$page->content = $page->smarty->fetch('regex-edit.tpl');
$page->render();
-27
View File
@@ -1,27 +0,0 @@
<?php
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\ReleaseRegex;
$page = new AdminPage();
$reg = new ReleaseRegex();
$page->title = 'Release Regex List';
$reggrouplist = $reg->getGroupsForSelect();
$page->smarty->assign('reggrouplist', $reggrouplist);
$group = '.*';
if (isset($_REQUEST['group'])) {
$group = $_REQUEST['group'];
}
$page->smarty->assign('selectedgroup', $group);
$regexlist = $reg->get(false, $group, true);
$page->smarty->assign('regexlist', $regexlist);
$page->content = $page->smarty->fetch('regex-list.tpl');
$page->render();
-51
View File
@@ -1,51 +0,0 @@
<?php
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\ReleaseRegex;
$page = new AdminPage();
$page->title = 'Submit your regex expressions to newznab';
$regex = new ReleaseRegex();
$regexList = $regex->get(false, -1, true, true);
if (count($regexList)) {
$regexSerialize = serialize($regexList);
$regexFilename = 'releaseregex-'.time().'.regex';
// User wants to submit their regex's
if (isset($_POST['regex_submit_please'])) {
// Submit
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (newznab / compatible;)');
curl_setopt($ch, CURLOPT_URL, 'http://newznab.com/regex/uploadregex.php');
curl_setopt($ch, CURLOPT_POST, true);
$post = [
'regex' => $regexSerialize,
];
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
if ($response == 'OK') {
$page->smarty->assign('upload_status', 'OK');
} else {
$page->smarty->assign('upload_status', 'BAD');
}
}
} else {
$regexFilename = 'No user regexs found. Please add some.';
$regexList = ['Empty'];
$page->smarty->assign('regex_error', 1);
}
$page->smarty->assign('regex_filename', $regexFilename);
$page->smarty->assign('regex_contents', $regexList);
$page->content = $page->smarty->fetch('regex-submit.tpl');
$page->render();
-85
View File
@@ -1,85 +0,0 @@
<?php
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Groups;
use nntmux\Category;
use nntmux\ReleaseRegex;
$page = new AdminPage();
$reg = new ReleaseRegex();
$groups = new Groups();
$cat = new Category();
$id = 0;
// set the current action
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
$numarticlesdefault = 20000;
$groupList = $groups->getAll();
array_unshift($groupList, ['ID'=>0, 'name'=>'All Groups']);
$gid = $gnames = [];
$groupname = (isset($_REQUEST['groupname']) && ! empty($_REQUEST['groupname'])) ? $_REQUEST['groupname'] : '';
$groupID = isset($_REQUEST['groupID']) ? $_REQUEST['groupID'] : '0';
$regex = (isset($_REQUEST['regex']) && ! empty($_REQUEST['regex'])) ? $_REQUEST['regex'] : '/^(?P<name>.*)$/i';
$poster = (isset($_REQUEST['poster']) && ! empty($_REQUEST['poster'])) ? $_REQUEST['poster'] : '';
$unreleased = isset($_REQUEST['unreleased']) ? $_REQUEST['unreleased'] : '';
$matchagainstbins = isset($_REQUEST['matchagainstbins']) ? $_REQUEST['matchagainstbins'] : '';
$numarticles = (isset($_REQUEST['numarticles']) && ! empty($_REQUEST['numarticles'])) ? $_REQUEST['numarticles'] : $numarticlesdefault;
$clearexistingbins = isset($_REQUEST['clearexistingbins']) ? true : false;
foreach ($groupList as $grp) {
$gid[$grp['id']] = $grp['id'];
$gnames[$grp['id']] = $grp['name'];
}
$group = $groupname;
if ($group == '') {
if ($groupID == 0) {
$group = 0;
} else {
$group = $gnames[$groupID];
}
}
$page->smarty->assign('gid', $gid);
$page->smarty->assign('gnames', $gnames);
$page->smarty->assign('group', $group);
$page->smarty->assign('groupname', $groupname);
$page->smarty->assign('groupID', $groupID);
$page->smarty->assign('regex', $regex);
$page->smarty->assign('poster', $poster);
$page->smarty->assign('unreleased', $unreleased);
$page->smarty->assign('matchagainstbins', $matchagainstbins);
$page->smarty->assign('numarticles', $numarticles);
switch ($action) {
case 'test':
if (isset($_REQUEST['regex'])) {
$matches = $reg->testRegex($_REQUEST['regex'], $group, $poster, $unreleased, $matchagainstbins);
$offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
$page->smarty->assign('pagertotalitems', sizeof($matches));
$page->smarty->assign('pageroffset', $offset);
$page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
$page->smarty->assign('pagerquerybase', WWW_TOP."/regex-test.php?action=test&groupname={$groupname}&groupID={$groupID}&regex=".urlencode($regex).'&poster='.urlencode($poster)."&unreleased={$unreleased}&matchagainstbins={$matchagainstbins}&offset=");
$pager = $page->smarty->fetch('pager.tpl');
$page->smarty->assign('pager', $pager);
$matches = array_slice($matches, $offset, ITEMS_PER_PAGE);
$page->smarty->assign('matches', $matches);
}
break;
case 'fetch':
$result = $reg->fetchTestBinaries($group, $numarticles, $clearexistingbins);
$page->smarty->assign('error', implode('<br />', $result));
break;
}
$page->title = 'Release Regex Test';
$page->content = $page->smarty->fetch('regex-test.tpl');
$page->render();
+2 -3
View File
@@ -2,13 +2,12 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Category;
use App\Models\Category;
use nntmux\Releases;
use App\Models\Release;
$page = new AdminPage();
$releases = new Releases(['Settings' => $page->pdo]);
$category = new Category(['Settings' => $page->pdo]);
$id = 0;
// Set the current action.
@@ -50,7 +49,7 @@ switch ($action) {
$page->smarty->assign('yesno_ids', [1, 0]);
$page->smarty->assign('yesno_names', ['Yes', 'No']);
$page->smarty->assign('catlist', $category->getForSelect(false));
$page->smarty->assign('catlist', Category::getForSelect(false));
$page->content = $page->smarty->fetch('release-edit.tpl');
$page->render();
+1 -1
View File
@@ -2,8 +2,8 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use App\Models\Category;
use nntmux\Regexes;
use nntmux\Category;
$page = new AdminPage();
$regexes = new Regexes(['Settings' => $page->pdo, 'Table_Name' => 'release_naming_regexes']);
+2 -3
View File
@@ -2,11 +2,10 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use nntmux\Category;
use App\Models\Category;
use App\Models\UserRole;
use App\Models\RoleExcludedCategory;
$category = new Category();
$page = new AdminPage();
// Get the user roles.
@@ -80,7 +79,7 @@ switch ($_REQUEST['action'] ?? 'view') {
$page->smarty->assign('yesno_ids', [1, 0]);
$page->smarty->assign('yesno_names', ['Yes', 'No']);
$page->smarty->assign('catlist', $category->getForSelect(false));
$page->smarty->assign('catlist', Category::getForSelect(false));
$page->content = $page->smarty->fetch('role-edit.tpl');
$page->render();
+1 -2
View File
@@ -2,14 +2,13 @@
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'smarty.php';
use App\Models\Category;
use nntmux\Sites;
use nntmux\SABnzbd;
use nntmux\Category;
use App\Models\Settings;
use nntmux\utility\Utility;
use App\Models\Category as CategoryModel;
$category = new Category();
$page = new AdminPage();
$sites = new Sites();
$id = 0;
+2 -3
View File
@@ -1,7 +1,7 @@
<?php
use App\Models\Category;
use App\Models\User;
use nntmux\Category;
/**
* All admin pages implement this class. Enforces admin role for requesting user.
@@ -30,8 +30,7 @@ class AdminPage extends BasePage
$this->show403(true);
}
$category = new Category();
$this->smarty->assign('catClass', $category);
$this->smarty->assign('catClass', Category::class);
}
/**
+4 -5
View File
@@ -1,8 +1,8 @@
<?php
use App\Models\Category;
use App\Models\Menu;
use App\Models\User;
use nntmux\Category;
use nntmux\Contents;
use App\Models\Settings;
use App\Models\Forumpost;
@@ -47,15 +47,14 @@ class Page extends BasePage
$this->smarty->assign('useful_menu', $this->smarty->fetch('usefullinksmenu.tpl'));
$this->smarty->assign('article_menu', $this->smarty->fetch('articlesmenu.tpl'));
$category = new Category(['Settings' => $content->pdo]);
if (! empty($this->userdata)) {
$parentcatlist = $category->getForMenu($this->userdata['categoryexclusions'], $this->userdata['rolecategoryexclusions']);
$parentcatlist = Category::getForMenu($this->userdata['categoryexclusions'], $this->userdata['rolecategoryexclusions']);
} else {
$parentcatlist = $category->getForMenu();
$parentcatlist = Category::getForMenu();
}
$this->smarty->assign('parentcatlist', $parentcatlist);
$this->smarty->assign('catClass', $category);
$this->smarty->assign('catClass', Category::class);
$searchStr = '';
if ($this->page == 'search' && isset($_REQUEST['id'])) {
$searchStr = (string) $_REQUEST['id'];
+2 -3
View File
@@ -1,12 +1,11 @@
<?php
use nntmux\Category;
use App\Models\Category;
use nntmux\Releases;
use App\Models\Release;
$page = new AdminPage();
$releases = new Releases(['Settings' => $page->settings]);
$category = new Category(['Settings' => $page->settings]);
// Set the current action.
$action = $_REQUEST['action'] ?? '';
@@ -41,7 +40,7 @@ switch ($action) {
$page->smarty->assign('release', $rel);
$page->smarty->assign('success', $success);
$page->smarty->assign('from', $_POST['from'] ?? '');
$page->smarty->assign('catlist', $category->getForSelect(false));
$page->smarty->assign('catlist', Category::getForSelect(false));
$page->content = $page->smarty->fetch('ajax_release-edit.tpl');
echo $page->content;
+1 -1
View File
@@ -1,8 +1,8 @@
<?php
use App\Models\Category;
use nntmux\AniDB;
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
if (! User::isLoggedIn()) {
+3 -4
View File
@@ -1,17 +1,16 @@
<?php
use App\Models\Category;
use nntmux\Books;
use App\Models\User;
use nntmux\Category;
if (! User::isLoggedIn()) {
$page->show403();
}
$book = new Books(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
$boocats = $cat->getChildren(Category::BOOKS_ROOT);
$boocats = Category::getChildren(Category::BOOKS_ROOT);
$btmp = [];
foreach ($boocats as $bcat) {
$btmp[$bcat['id']] = $bcat;
@@ -66,7 +65,7 @@ $page->smarty->assign('pager', $pager);
if ((int) $category === -1) {
$page->smarty->assign('catname', 'All');
} else {
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+2 -3
View File
@@ -1,7 +1,7 @@
<?php
use App\Models\Category;
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
$releases = new Releases(['Settings' => $page->settings]);
@@ -50,8 +50,7 @@ $covgroup = '';
if ($category === -1 && (int) $grp === -1) {
$page->smarty->assign('catname', 'All');
} elseif ((int) $category !== -1 && (int) $grp === -1) {
$cat = new Category(['Settings' => $releases->pdo]);
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
if ($cdata['parentid'] === Category::GAME_ROOT || $cdata['id'] === Category::GAME_ROOT) {
+3 -4
View File
@@ -1,19 +1,18 @@
<?php
use App\Models\Category;
use nntmux\Genres;
use nntmux\Console;
use App\Models\User;
use nntmux\Category;
if (! User::isLoggedIn()) {
$page->show403();
}
$console = new Console(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
$gen = new Genres(['Settings' => $page->settings]);
$concats = $cat->getChildren(Category::GAME_ROOT);
$concats = Category::getChildren(Category::GAME_ROOT);
$ctmp = [];
foreach ($concats as $ccat) {
$ctmp[$ccat['id']] = $ccat;
@@ -77,7 +76,7 @@ $page->smarty->assign('pager', $pager);
if ((int) $category === -1) {
$page->smarty->assign('catname', 'All');
} else {
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+3 -4
View File
@@ -1,19 +1,18 @@
<?php
use App\Models\Category;
use nntmux\Games;
use nntmux\Genres;
use App\Models\User;
use nntmux\Category;
if (! User::isLoggedIn()) {
$page->show403();
}
$games = new Games(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
$gen = new Genres(['Settings' => $page->settings]);
$concats = $cat->getChildren(Category::PC_ROOT);
$concats = Category::getChildren(Category::PC_ROOT);
$ctmp = [];
foreach ($concats as $ccat) {
$ctmp[$ccat['id']] = $ccat;
@@ -85,7 +84,7 @@ $page->smarty->assign('pager', $pager);
if ($category == -1) {
$page->smarty->assign('catname', 'All');
} else {
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+3 -5
View File
@@ -1,17 +1,16 @@
<?php
use App\Models\Category;
use nntmux\Movie;
use App\Models\User;
use nntmux\Category;
$movie = new Movie(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
if (! User::isLoggedIn()) {
$page->show403();
}
$moviecats = $cat->getChildren(Category::MOVIE_ROOT);
$moviecats = Category::getChildren(Category::MOVIE_ROOT);
$mtmp = [];
foreach ($moviecats as $mcat) {
$mtmp[$mcat['id']] = $mcat;
@@ -90,8 +89,7 @@ $page->smarty->assign('pager', $pager);
if ($category == -1) {
$page->smarty->assign('catname', 'All');
} else {
$cat = new Category();
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+3 -4
View File
@@ -1,19 +1,18 @@
<?php
use App\Models\Category;
use nntmux\Music;
use nntmux\Genres;
use App\Models\User;
use nntmux\Category;
if (! User::isLoggedIn()) {
$page->show403();
}
$music = new Music(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
$gen = new Genres(['Settings' => $page->settings]);
$musiccats = $cat->getChildren(Category::MUSIC_ROOT);
$musiccats = Category::getChildren(Category::MUSIC_ROOT);
$mtmp = [];
foreach ($musiccats as $mcat) {
$mtmp[$mcat['id']] = $mcat;
@@ -77,7 +76,7 @@ $page->smarty->assign('pager', $pager);
if ($category == -1) {
$page->smarty->assign('catname', 'All');
} else {
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+11 -15
View File
@@ -1,8 +1,8 @@
<?php
use App\Models\Category;
use nntmux\Movie;
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
use nntmux\UserMovies;
use App\Models\Settings;
@@ -14,8 +14,8 @@ if (! User::isLoggedIn()) {
$um = new UserMovies(['Settings' => $page->settings]);
$mv = new Movie(['Settings' => $page->settings]);
$action = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$imdbid = isset($_REQUEST['subpage']) ? $_REQUEST['subpage'] : '';
$action = $_REQUEST['id'] ?? '';
$imdbid = $_REQUEST['subpage'] ?? '';
if (isset($_REQUEST['from'])) {
$page->smarty->assign('from', WWW_TOP.$_REQUEST['from']);
@@ -50,7 +50,7 @@ switch ($action) {
}
}
if ($action == 'doadd') {
if ($action === 'doadd') {
$category = (isset($_REQUEST['category']) && is_array($_REQUEST['category']) && ! empty($_REQUEST['category'])) ? $_REQUEST['category'] : [];
$um->addMovie(User::currentUserId(), $imdbid, $category);
if (isset($_REQUEST['from'])) {
@@ -59,12 +59,11 @@ switch ($action) {
header('Location:'.WWW_TOP.'/mymovies');
}
} else {
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::MOVIE_ROOT);
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
// If MOVIE WEB-DL categorization is disabled, don't include it as an option
if (Settings::settingValue('indexer.categorise.catwebdl') == 0 && $c['id'] == Category::MOVIE_WEBDL) {
if ((int) Settings::settingValue('indexer.categorise.catwebdl') === 0 && (int) $c['id'] === Category::MOVIE_WEBDL) {
continue;
}
$categories[$c['id']] = $c['title'];
@@ -87,7 +86,7 @@ switch ($action) {
$page->show404();
}
if ($action == 'doedit') {
if ($action === 'doedit') {
$category = (isset($_REQUEST['category']) && is_array($_REQUEST['category']) && ! empty($_REQUEST['category'])) ? $_REQUEST['category'] : [];
$um->updateMovie(User::currentUserId(), $imdbid, $category);
if (isset($_REQUEST['from'])) {
@@ -96,9 +95,8 @@ switch ($action) {
header('Location:'.WWW_TOP.'/mymovies');
}
} else {
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::MOVIE_ROOT);
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
@@ -128,9 +126,8 @@ switch ($action) {
$offset = (isset($_REQUEST['offset']) && ctype_digit($_REQUEST['offset'])) ? $_REQUEST['offset'] : 0;
$ordering = $releases->getBrowseOrdering();
$orderby = isset($_REQUEST['ob']) && in_array($_REQUEST['ob'], $ordering) ? $_REQUEST['ob'] : '';
$orderby = isset($_REQUEST['ob']) && \in_array($_REQUEST['ob'], $ordering, false) ? $_REQUEST['ob'] : '';
$results = [];
$results = $mv->getMovieRange($movies, $offset, ITEMS_PER_PAGE, $orderby, -1, $page->userdata['categoryexclusions']);
$page->smarty->assign('pagertotalitems', $browsecount);
@@ -163,8 +160,7 @@ switch ($action) {
$page->meta_keywords = 'search,add,to,cart,nzb,description,details';
$page->meta_description = 'Manage Your Movies';
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::MOVIE_ROOT);
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
@@ -174,7 +170,7 @@ switch ($action) {
$results = [];
foreach ($movies as $moviek => $movie) {
$showcats = explode('|', $movie['categories']);
if (is_array($showcats) && sizeof($showcats) > 0) {
if (is_array($showcats) && count($showcats) > 0) {
$catarr = [];
foreach ($showcats as $scat) {
if (! empty($scat)) {
+4 -7
View File
@@ -1,7 +1,7 @@
<?php
use App\Models\Category;
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
use App\Models\Video;
use nntmux\UserSeries;
@@ -58,8 +58,7 @@ switch ($action) {
header('Location:'.WWW_TOP.'/myshows');
}
} else {
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::TV_ROOT);
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
// If TV WEB-DL categorization is disabled, don't include it as an option
@@ -95,9 +94,8 @@ switch ($action) {
header('Location:'.WWW_TOP.'/myshows');
}
} else {
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::TV_ROOT);
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
@@ -161,8 +159,7 @@ switch ($action) {
$page->meta_keywords = 'search,add,to,cart,nzb,description,details';
$page->meta_description = 'Manage Your Shows';
$cat = new Category(['Settings' => $page->settings]);
$tmpcats = $cat->getChildren(Category::TV_ROOT);
$tmpcats = Category::getChildren(Category::TV_ROOT);
$categories = [];
foreach ($tmpcats as $c) {
$categories[$c['id']] = $c['title'];
+2 -3
View File
@@ -1,14 +1,13 @@
<?php
use App\Models\Category;
use nntmux\NZBGet;
use nntmux\SABnzbd;
use App\Models\User;
use nntmux\Category;
use App\Models\Settings;
use nntmux\utility\Utility;
use App\Models\UserExcludedCategory;
$category = new Category;
$sab = new SABnzbd($page);
$nzbGet = new NZBGet($page);
@@ -157,7 +156,7 @@ $page->meta_description = 'Edit User Profile for '.$data['username'];
$page->smarty->assign('cp_url_selected', $data['cp_url']);
$page->smarty->assign('cp_api_selected', $data['cp_api']);
$page->smarty->assign('catlist', $category->getForSelect(false));
$page->smarty->assign('catlist', Category::getForSelect(false));
$page->content = $page->smarty->fetch('profileedit.tpl');
$page->render();
+3 -4
View File
@@ -1,13 +1,12 @@
<?php
use App\Models\Category;
use App\Models\User;
use nntmux\Category;
use nntmux\http\RSS;
use App\Models\Settings;
use App\Models\UserRequest;
use nntmux\utility\Utility;
$category = new Category(['Settings' => $page->settings]);
$rss = new RSS(['Settings' => $page->settings]);
$offset = 0;
@@ -40,8 +39,8 @@ if (! isset($_GET['t']) && ! isset($_GET['show']) && ! isset($_GET['anidb'])) {
$page->smarty->assign(
[
'categorylist' => $category->getCategories(true, $page->userdata['categoryexclusions']),
'parentcategorylist' => $category->getForMenu($page->userdata['categoryexclusions']),
'categorylist' => Category::getCategories(true, $page->userdata['categoryexclusions']),
'parentcategorylist' => Category::getForMenu($page->userdata['categoryexclusions']),
]
);
+2 -2
View File
@@ -1,8 +1,8 @@
<?php
use App\Models\Category;
use nntmux\Groups;
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
use nntmux\ReleaseSearch;
@@ -203,7 +203,7 @@ $page->smarty->assign(
],
'results' => $results, 'sadvanced' => $searchType !== 'basic',
'grouplist' => $groups->getGroupsForSelect(),
'catlist' => (new Category(['Settings' => $page->settings]))->getForSelect(),
'catlist' => Category::getForSelect(),
'search_description' => $search_description,
'pager' => $page->smarty->fetch('pager.tpl'),
]
-2
View File
@@ -1,7 +1,6 @@
<?php
use App\Models\User;
use nntmux\Category;
use nntmux\Releases;
use App\Models\Video;
use nntmux\UserSeries;
@@ -11,7 +10,6 @@ if (! User::isLoggedIn()) {
}
$releases = new Releases(['Settings' => $page->settings]);
$cat = new Category(['Settings' => $page->settings]);
$us = new UserSeries();
if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
+3 -4
View File
@@ -1,17 +1,16 @@
<?php
use App\Models\Category;
use nntmux\XXX;
use App\Models\User;
use nntmux\Category;
if (! User::isLoggedIn()) {
$page->show403();
}
$movie = new XXX();
$cat = new Category();
$moviecats = $cat->getChildren(Category::XXX_ROOT);
$moviecats = Category::getChildren(Category::XXX_ROOT);
$mtmp = [];
foreach ($moviecats as $mcat) {
$mtmp[$mcat['id']] = $mcat;
@@ -66,7 +65,7 @@ $page->smarty->assign('pager', $pager);
if ((int) $category === -1) {
$page->smarty->assign('catname', 'All');
} else {
$cdata = $cat->getById($category);
$cdata = Category::getById($category);
if ($cdata) {
$page->smarty->assign('catname', $cdata->parent !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
} else {
+2 -1
View File
@@ -16,7 +16,8 @@
* @author niel
* @copyright 2016 nZEDb
*/
use nntmux\Category;
use App\Models\Category;
/**
* Returns the value of the specified Category constant.
+1 -1
View File
@@ -25,7 +25,7 @@
<td><a href="{$smarty.const.WWW_TOP}/category-edit.php?id={$category.id}">{$category.title}</a></td>
<td>
{if $category.parentid != null}
{$category->parent->title}
{Category::parent->title}
{else}
n/a
{/if}