Files
XC_VM/src/Public/Controllers/Player/SeriesController.php
T
Divarion_D 9665a5a2ab refactor: expand Rector to Streaming / Public\Controllers / Ministra (stage 2)
Widen the Rector config to the remaining class-based trees (Streaming,
Public\Controllers, Ministra), keeping the templates, procedural
front-controllers (Public/stream, Public/admin, Ministra/portal.php) and the
streaming hot-path bootstraps out. Also document the recurring dropped-parens
bug + the review grep in the config header.

The resulting 107-file pass (94 Public\Controllers, 11 Streaming, 2 Ministra)
was reviewed against the suite + PHPStan + the usual scans:
- No dropped-parens bug this time (the assignment-in-condition pattern didn't
  occur in these files).
- 6 locally-called private static helpers became instance methods
  (behaviour-preserving; all called via $this->, no static call sites); one
  unused private param dropped (FanoutConfig::desired $rSnapshot, call site
  updated).
- De Morgan / ternary / dead-code simplifications; two `$x = getById()`
  truthy-assignments folded into the condition (no comparison, safe).

PHPStan level 5 clean; suite 721 tests / 0 errors.
2026-09-13 19:21:44 +03:00

129 lines
4.3 KiB
PHP

<?php
namespace XcVm\Public\Controllers\Player;
use XcVm\Core\Http\RequestManager;
use XcVm\Core\Util\ImageUtils;
/**
* SeriesController — series controller
*
* @package XC_VM_Public_Controllers_Player
* @author Divarion_D <https://github.com/Divarion-D>
* @copyright 2025-2026 Vateron Media
* @link https://github.com/Vateron-Media/XC_VM
* @license AGPL-3.0 https://www.gnu.org/licenses/agpl-3.0.html
*/
class SeriesController extends BasePlayerController {
public function index() {
global $db, $rUserInfo;
if (RequestManager::has('sort') && RequestManager::get('sort') == 'popular') {
$rPopular = (igbinary_unserialize(file_get_contents(CONTENT_PATH . 'tmdb_popular'))['series'] ?: []);
if (0 < count($rPopular) && 0 < count($rUserInfo['series_ids'])) {
$db->query('SELECT `id`, `title`, `year`, `rating`, `cover`, `backdrop_path` FROM `streams_series` WHERE `id` IN (' . implode(',', $rPopular) . ') AND `id` IN (' . implode(',', $rUserInfo['series_ids']) . ') ORDER BY FIELD(id, ' . implode(',', $rPopular) . ') ASC LIMIT 100;');
$rSeries = ['count' => $db->num_rows(), 'streams' => $db->get_rows()];
} else {
header('Location: series');
exit;
}
} else {
$rPopular = false;
$rPage = (intval(RequestManager::get('page') ?? 0) ?: 1);
$rLimit = 48;
$rSortArray = ['number' => 'Default', 'added' => 'Last Updated', 'release' => 'Air Date', 'name' => 'Title A-Z', 'top' => 'Rating'];
$rSortBy = (isset($rSortArray[RequestManager::get('sort') ?? '']) ? RequestManager::get('sort') : 'number');
$rPicking = [];
$rYearStart = (intval(RequestManager::get('year_s') ?? 0) ?: 1900);
$rYearEnd = (intval(RequestManager::get('year_e') ?? 0) ?: date('Y'));
if ($rYearStart < 1900 || date('Y') < $rYearStart) {
$rYearStart = 1900;
}
if ($rYearEnd < 1900 || date('Y') < $rYearEnd || $rYearEnd < $rYearStart) {
$rYearEnd = date('Y');
}
if (1900 < $rYearStart || $rYearEnd < date('Y')) {
$rPicking['year_range'] = [$rYearStart, $rYearEnd];
}
$rRatingStart = (intval(RequestManager::get('rating_s') ?? 0));
$rRatingEnd = (intval(RequestManager::get('rating_e') ?? 0) ?: 10);
if ($rRatingStart < 0 || 10 < $rRatingStart) {
$rRatingStart = 0;
}
if ($rRatingEnd < 0 || 10 < $rRatingEnd || $rRatingEnd < $rRatingStart) {
$rRatingEnd = 10;
}
if (0 < $rRatingStart || $rRatingEnd < 10) {
$rPicking['rating_range'] = [$rRatingStart, $rRatingEnd];
}
$rCategoryID = (intval(RequestManager::get('category') ?? 0) ?: null);
$rSearchBy = (RequestManager::get('search') ?? null);
if ($rSearchBy) {
$rPage = 1;
$rLimit = 100;
}
$rSeries = getUserSeries($rUserInfo, $rCategoryID, null, $rSortBy, $rSearchBy, $rPicking, ($rPage - 1) * $rLimit, $rLimit);
}
$rCover = '';
$rShuffle = $rSeries['streams'];
shuffle($rShuffle);
foreach ($rShuffle as $rStream) {
$rBackdrop = json_decode($rStream['backdrop_path'], true);
if (!empty($rBackdrop[0])) {
$rCover = ImageUtils::validateURL($rBackdrop[0]);
break;
}
}
if (!$rPopular && (!isset($rSearchBy) || !$rSearchBy)) {
$rCount = $rSeries['count'];
$rPages = ceil($rCount / $rLimit);
$rPagination = [];
foreach (range($rPage - 2, $rPage + 2) as $i) {
if (1 <= $i && $i <= $rPages) {
$rPagination[] = $i;
}
}
}
$GLOBALS['_TITLE'] = 'TV Series';
$GLOBALS['rYearStart'] = isset($rYearStart) ? $rYearStart : 1900;
$GLOBALS['rYearEnd'] = isset($rYearEnd) ? $rYearEnd : date('Y');
$GLOBALS['rRatingStart'] = isset($rRatingStart) ? $rRatingStart : 0;
$GLOBALS['rRatingEnd'] = isset($rRatingEnd) ? $rRatingEnd : 10;
$this->render('series', [
'rPopular' => $rPopular,
'rSeries' => $rSeries,
'rCover' => $rCover,
'rSortArray' => isset($rSortArray) ? $rSortArray : [],
'rSortBy' => isset($rSortBy) ? $rSortBy : null,
'rCategoryID' => isset($rCategoryID) ? $rCategoryID : null,
'rSearchBy' => isset($rSearchBy) ? $rSearchBy : null,
'rPage' => isset($rPage) ? $rPage : 1,
'rPages' => isset($rPages) ? $rPages : 1,
'rPagination' => isset($rPagination) ? $rPagination : [],
'rYearStart' => isset($rYearStart) ? $rYearStart : 1900,
'rYearEnd' => isset($rYearEnd) ? $rYearEnd : date('Y'),
'rRatingStart' => isset($rRatingStart) ? $rRatingStart : 0,
'rRatingEnd' => isset($rRatingEnd) ? $rRatingEnd : 10,
]);
}
}