diff --git a/Changelog b/Changelog index 17531fe5e..0239b6528 100755 --- a/Changelog +++ b/Changelog @@ -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 diff --git a/app/Models/Category.php b/app/Models/Category.php index 418c01869..fda3615b3 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -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(); + } } diff --git a/app/Models/Video.php b/app/Models/Video.php index b837f82d5..8b9ab3208 100644 --- a/app/Models/Video.php +++ b/app/Models/Video.php @@ -2,7 +2,6 @@ namespace App\Models; -use nntmux\Category; use Illuminate\Support\Carbon; use Illuminate\Database\Eloquent\Model; diff --git a/misc/testing/DB/reset_postprocessing.php b/misc/testing/DB/reset_postprocessing.php index 16cd948c0..efdbf09d1 100755 --- a/misc/testing/DB/reset_postprocessing.php +++ b/misc/testing/DB/reset_postprocessing.php @@ -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; diff --git a/misc/testing/PostProc/getConsole.php b/misc/testing/PostProc/getConsole.php index 54a37e60d..d632ec6a1 100644 --- a/misc/testing/PostProc/getConsole.php +++ b/misc/testing/PostProc/getConsole.php @@ -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]); diff --git a/misc/testing/PostProc/getXXXSamples.php b/misc/testing/PostProc/getXXXSamples.php index e2d414beb..74268b967 100644 --- a/misc/testing/PostProc/getXXXSamples.php +++ b/misc/testing/PostProc/getXXXSamples.php @@ -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(); diff --git a/misc/testing/Releases/recategorize.php b/misc/testing/Releases/recategorize.php index cafdc5993..d99139b91 100644 --- a/misc/testing/Releases/recategorize.php +++ b/misc/testing/Releases/recategorize.php @@ -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; diff --git a/misc/update/tmux/bin/groupfixrelnames.php b/misc/update/tmux/bin/groupfixrelnames.php index 6cb378ce5..be174e286 100644 --- a/misc/update/tmux/bin/groupfixrelnames.php +++ b/misc/update/tmux/bin/groupfixrelnames.php @@ -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; diff --git a/misc/update/tmux/monitor.php b/misc/update/tmux/monitor.php index 7d960bec0..a42af27ad 100644 --- a/misc/update/tmux/monitor.php +++ b/misc/update/tmux/monitor.php @@ -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; diff --git a/nntmux/Books.php b/nntmux/Books.php index 09c21da3b..28e31e153 100755 --- a/nntmux/Books.php +++ b/nntmux/Books.php @@ -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 = ''; diff --git a/nntmux/Category.php b/nntmux/Category.php deleted file mode 100755 index 3823afad7..000000000 --- a/nntmux/Category.php +++ /dev/null @@ -1,473 +0,0 @@ - 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' - ); - } -} diff --git a/nntmux/Console.php b/nntmux/Console.php index d62326c9b..a3bbf2084 100755 --- a/nntmux/Console.php +++ b/nntmux/Console.php @@ -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 = ''; diff --git a/nntmux/Games.php b/nntmux/Games.php index 35d9309e2..7ab1962ce 100755 --- a/nntmux/Games.php +++ b/nntmux/Games.php @@ -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) { diff --git a/nntmux/Movie.php b/nntmux/Movie.php index d28921556..bd229f0cf 100755 --- a/nntmux/Movie.php +++ b/nntmux/Movie.php @@ -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); diff --git a/nntmux/Music.php b/nntmux/Music.php index c34b5435c..bcec8007e 100755 --- a/nntmux/Music.php +++ b/nntmux/Music.php @@ -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 = ''; diff --git a/nntmux/Releases.php b/nntmux/Releases.php index 2a7c37841..28ae5a32e 100755 --- a/nntmux/Releases.php +++ b/nntmux/Releases.php @@ -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( diff --git a/nntmux/XXX.php b/nntmux/XXX.php index f98dad8d1..8ae37c8ed 100755 --- a/nntmux/XXX.php +++ b/nntmux/XXX.php @@ -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); diff --git a/nntmux/http/API.php b/nntmux/http/API.php index faa2d4680..671af6385 100755 --- a/nntmux/http/API.php +++ b/nntmux/http/API.php @@ -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; diff --git a/nntmux/http/Capabilities.php b/nntmux/http/Capabilities.php index bf354aac8..b2e684714 100755 --- a/nntmux/http/Capabilities.php +++ b/nntmux/http/Capabilities.php @@ -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, ]; } diff --git a/nntmux/http/RSS.php b/nntmux/http/RSS.php index 273a69969..08d43da21 100755 --- a/nntmux/http/RSS.php +++ b/nntmux/http/RSS.php @@ -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); } } diff --git a/nntmux/http/XML_Response.php b/nntmux/http/XML_Response.php index a31c52102..481aa15de 100755 --- a/nntmux/http/XML_Response.php +++ b/nntmux/http/XML_Response.php @@ -21,7 +21,7 @@ namespace nntmux\http; -use nntmux\Category; +use App\Models\Category; use nntmux\Utility\Utility; /** diff --git a/nntmux/processing/PostProcess.php b/nntmux/processing/PostProcess.php index d4346674c..2e5669df6 100755 --- a/nntmux/processing/PostProcess.php +++ b/nntmux/processing/PostProcess.php @@ -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; diff --git a/nntmux/processing/ProcessReleases.php b/nntmux/processing/ProcessReleases.php index 823bbc7a3..add1da16f 100755 --- a/nntmux/processing/ProcessReleases.php +++ b/nntmux/processing/ProcessReleases.php @@ -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( diff --git a/nntmux/processing/post/AniDB.php b/nntmux/processing/post/AniDB.php index 456459840..194384ef0 100755 --- a/nntmux/processing/post/AniDB.php +++ b/nntmux/processing/post/AniDB.php @@ -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']); diff --git a/nntmux/processing/post/ProcessAdditional.php b/nntmux/processing/post/ProcessAdditional.php index 0e7ecb0d8..268256dc9 100755 --- a/nntmux/processing/post/ProcessAdditional.php +++ b/nntmux/processing/post/ProcessAdditional.php @@ -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; diff --git a/nntmux/processing/tv/TV.php b/nntmux/processing/tv/TV.php index 1fd42117a..27bb59d5a 100755 --- a/nntmux/processing/tv/TV.php +++ b/nntmux/processing/tv/TV.php @@ -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; diff --git a/nntmux/utility/SmartyUtils.php b/nntmux/utility/SmartyUtils.php index 622025d73..1d8262f76 100755 --- a/nntmux/utility/SmartyUtils.php +++ b/nntmux/utility/SmartyUtils.php @@ -18,7 +18,8 @@ * @author niel * @copyright 2014 nZEDb */ -use nntmux\Category; + +use App\Models\Category; /** * Returns the value of the specified Category constant. diff --git a/public/admin/binaryblacklist-edit.php b/public/admin/binaryblacklist-edit.php index 52ddf6771..42e2e1a99 100644 --- a/public/admin/binaryblacklist-edit.php +++ b/public/admin/binaryblacklist-edit.php @@ -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]); diff --git a/public/admin/category-edit.php b/public/admin/category-edit.php index 7596495e5..f09165aa4 100644 --- a/public/admin/category-edit.php +++ b/public/admin/category-edit.php @@ -1,11 +1,11 @@ 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; diff --git a/public/admin/category-list.php b/public/admin/category-list.php index 35b21a23a..2bc3dafd4 100644 --- a/public/admin/category-list.php +++ b/public/admin/category-list.php @@ -1,16 +1,16 @@ title = 'Category List'; -$categorylist = $category->getFlat(); +$categorylist = Category::getFlat(); $page->smarty->assign('categorylist', $categorylist); diff --git a/public/admin/category_regexes-edit.php b/public/admin/category_regexes-edit.php index 22086aeb3..0dbdb54e8 100644 --- a/public/admin/category_regexes-edit.php +++ b/public/admin/category_regexes-edit.php @@ -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']); diff --git a/public/admin/collection_regexes-edit.php b/public/admin/collection_regexes-edit.php index 52a17792b..566bc6633 100644 --- a/public/admin/collection_regexes-edit.php +++ b/public/admin/collection_regexes-edit.php @@ -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']); diff --git a/public/admin/regex-edit.php b/public/admin/regex-edit.php deleted file mode 100644 index 777694f0a..000000000 --- a/public/admin/regex-edit.php +++ /dev/null @@ -1,56 +0,0 @@ -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(); diff --git a/public/admin/regex-list.php b/public/admin/regex-list.php deleted file mode 100644 index 610eddace..000000000 --- a/public/admin/regex-list.php +++ /dev/null @@ -1,27 +0,0 @@ -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(); diff --git a/public/admin/regex-submit.php b/public/admin/regex-submit.php deleted file mode 100644 index c11dff809..000000000 --- a/public/admin/regex-submit.php +++ /dev/null @@ -1,51 +0,0 @@ -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(); diff --git a/public/admin/regex-test.php b/public/admin/regex-test.php deleted file mode 100644 index 525a9c836..000000000 --- a/public/admin/regex-test.php +++ /dev/null @@ -1,85 +0,0 @@ -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.*)$/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}®ex=".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('
', $result)); - - break; -} - -$page->title = 'Release Regex Test'; - -$page->content = $page->smarty->fetch('regex-test.tpl'); -$page->render(); diff --git a/public/admin/release-edit.php b/public/admin/release-edit.php index 825ec8135..1418fbeb0 100644 --- a/public/admin/release-edit.php +++ b/public/admin/release-edit.php @@ -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(); diff --git a/public/admin/release_naming_regexes-edit.php b/public/admin/release_naming_regexes-edit.php index ce6b96943..7851da62b 100644 --- a/public/admin/release_naming_regexes-edit.php +++ b/public/admin/release_naming_regexes-edit.php @@ -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']); diff --git a/public/admin/role-edit.php b/public/admin/role-edit.php index 6fddf7b08..9b44fde68 100644 --- a/public/admin/role-edit.php +++ b/public/admin/role-edit.php @@ -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(); diff --git a/public/admin/site-edit.php b/public/admin/site-edit.php index d654518cf..83e9af379 100644 --- a/public/admin/site-edit.php +++ b/public/admin/site-edit.php @@ -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; diff --git a/public/pages/AdminPage.php b/public/pages/AdminPage.php index e2405d73d..4e5c39c4c 100644 --- a/public/pages/AdminPage.php +++ b/public/pages/AdminPage.php @@ -1,7 +1,7 @@ show403(true); } - $category = new Category(); - $this->smarty->assign('catClass', $category); + $this->smarty->assign('catClass', Category::class); } /** diff --git a/public/pages/Page.php b/public/pages/Page.php index cc8b02f27..b15f662b4 100644 --- a/public/pages/Page.php +++ b/public/pages/Page.php @@ -1,8 +1,8 @@ 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']; diff --git a/public/pages/ajax_release-admin.php b/public/pages/ajax_release-admin.php index 378097697..667d30688 100644 --- a/public/pages/ajax_release-admin.php +++ b/public/pages/ajax_release-admin.php @@ -1,12 +1,11 @@ $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; diff --git a/public/pages/anime.php b/public/pages/anime.php index 7b3f32eb0..fee885387 100755 --- a/public/pages/anime.php +++ b/public/pages/anime.php @@ -1,8 +1,8 @@ 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 { diff --git a/public/pages/browse.php b/public/pages/browse.php index 0b6c3032e..129c0d63e 100644 --- a/public/pages/browse.php +++ b/public/pages/browse.php @@ -1,7 +1,7 @@ $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) { diff --git a/public/pages/console.php b/public/pages/console.php index 835d965ab..dac263139 100644 --- a/public/pages/console.php +++ b/public/pages/console.php @@ -1,19 +1,18 @@ 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 { diff --git a/public/pages/games.php b/public/pages/games.php index d3250cd4c..99ce8ad38 100644 --- a/public/pages/games.php +++ b/public/pages/games.php @@ -1,19 +1,18 @@ 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 { diff --git a/public/pages/movies.php b/public/pages/movies.php index 8ca26687e..affe458f3 100644 --- a/public/pages/movies.php +++ b/public/pages/movies.php @@ -1,17 +1,16 @@ $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 { diff --git a/public/pages/music.php b/public/pages/music.php index b14f74313..77ecda492 100644 --- a/public/pages/music.php +++ b/public/pages/music.php @@ -1,19 +1,18 @@ 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 { diff --git a/public/pages/mymovies.php b/public/pages/mymovies.php index c4c980df4..8ecc8c2d7 100755 --- a/public/pages/mymovies.php +++ b/public/pages/mymovies.php @@ -1,8 +1,8 @@ $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)) { diff --git a/public/pages/myshows.php b/public/pages/myshows.php index 595a41bd1..054678988 100755 --- a/public/pages/myshows.php +++ b/public/pages/myshows.php @@ -1,7 +1,7 @@ $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']; diff --git a/public/pages/profileedit.php b/public/pages/profileedit.php index af3d145cf..b4105dea9 100644 --- a/public/pages/profileedit.php +++ b/public/pages/profileedit.php @@ -1,14 +1,13 @@ 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(); diff --git a/public/pages/rss.php b/public/pages/rss.php index d708a60aa..f0faed2e5 100755 --- a/public/pages/rss.php +++ b/public/pages/rss.php @@ -1,13 +1,12 @@ $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']), ] ); diff --git a/public/pages/search.php b/public/pages/search.php index 030c7d4f0..01430d520 100644 --- a/public/pages/search.php +++ b/public/pages/search.php @@ -1,8 +1,8 @@ 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'), ] diff --git a/public/pages/series.php b/public/pages/series.php index 751cf410a..fed9c5f17 100644 --- a/public/pages/series.php +++ b/public/pages/series.php @@ -1,7 +1,6 @@ $page->settings]); -$cat = new Category(['Settings' => $page->settings]); $us = new UserSeries(); if (isset($_GET['id']) && ctype_digit($_GET['id'])) { diff --git a/public/pages/xxx.php b/public/pages/xxx.php index 1b9f541f6..a43b4fbbb 100644 --- a/public/pages/xxx.php +++ b/public/pages/xxx.php @@ -1,17 +1,16 @@ 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 { diff --git a/public/plugins/function.getcatval.php b/public/plugins/function.getcatval.php index 09e37c1e7..10d93d80d 100755 --- a/public/plugins/function.getcatval.php +++ b/public/plugins/function.getcatval.php @@ -16,7 +16,8 @@ * @author niel * @copyright 2016 nZEDb */ -use nntmux\Category; + +use App\Models\Category; /** * Returns the value of the specified Category constant. diff --git a/public/themes/admin/category-list.tpl b/public/themes/admin/category-list.tpl index 5ccb20a6b..b04751f34 100644 --- a/public/themes/admin/category-list.tpl +++ b/public/themes/admin/category-list.tpl @@ -25,7 +25,7 @@ {$category.title} {if $category.parentid != null} - {$category->parent->title} + {Category::parent->title} {else} n/a {/if}