Files
newznab-tmux/app/Http/Controllers/SeriesController.php
T
2018-04-23 15:45:31 +02:00

148 lines
5.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Video;
use Blacklight\Releases;
use App\Models\UserSerie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class SeriesController extends BasePageController
{
/**
* @param string $id
* @param \Illuminate\Http\Request $request
*
* @throws \Exception
*/
public function index($id = '', Request $request)
{
$this->setPrefs();
$releases = new Releases(['Settings' => $this->settings]);
if ($id && ctype_digit($id)) {
$category = -1;
if ($request->has('t') && ctype_digit($request->input('t'))) {
$category = $request->input('t');
}
$catarray = [];
$catarray[] = $category;
$page = $request->has('page') ? $request->input('page') : 1;
$rel = $releases->tvSearch($page, ['id' => $id], '', '', '', 1000, '', $catarray, -1);
$show = Video::getByVideoID($request->input('id'));
if (! $show) {
$this->smarty->assign('nodata', 'No video information for this series.');
} elseif (! $rel) {
$this->smarty->assign('nodata', 'No releases for this series.');
} else {
$myshows = UserSerie::getShow(Auth::id(), $show['id']);
// Sort releases by season, episode, date posted.
$series = $episode = $posted = [];
foreach ($rel as $rlk => $rlv) {
$series[$rlk] = $rlv['series'];
$episode[$rlk] = $rlv['episode'];
$posted[$rlk] = $rlv['postdate'];
}
array_multisort($series, SORT_DESC, $episode, SORT_DESC, $posted, SORT_DESC, $rel);
$series = [];
foreach ($rel as $r) {
$series[$r['series']][$r['episode']][] = $r;
}
$this->smarty->assign('seasons', $series);
$this->smarty->assign('show', $show);
$this->smarty->assign('myshows', $myshows);
//get series name(s), description, country and genre
$seriestitles = $seriescountry = [];
$seriestitles[] = $show['title'];
if (! empty($show['summary'])) {
$seriessummary[] = $show['summary'];
}
if (! empty($show['countries_id'])) {
$seriescountry[] = $show['countries_id'];
}
$seriestitles = implode('/', array_map('trim', $seriestitles));
$this->smarty->assign('seriestitles', $seriestitles);
$this->smarty->assign('seriessummary', array_shift($seriessummary));
$this->smarty->assign('seriescountry', array_shift($seriescountry));
$title = 'Series';
$meta_title = 'View TV Series';
$meta_keywords = 'view,series,tv,show,description,details';
$meta_description = 'View TV Series';
if ($category !== -1) {
$catid = $category;
} else {
$catid = '';
}
$this->smarty->assign('category', $catid);
$this->smarty->assign('nodata', '');
}
$content = $this->smarty->fetch('viewseries.tpl');
$this->smarty->assign([
'title' => $title,
'content' => $content,
'meta_title' => $meta_title,
'meta_keywords' => $meta_keywords,
'meta_description' => $meta_description,
]);
$this->pagerender();
} else {
$letter = ($id && preg_match('/^(0\-9|[A-Z])$/i', $id)) ? $id : '0-9';
$showname = ($request->has('title') && ! empty($request->input('title'))) ? $request->input('title') : '';
if ($showname !== '' && ! $id) {
$letter = '';
}
$masterserieslist = Video::getSeriesList(Auth::id(), $letter, $showname);
$title = 'Series List';
$meta_title = 'View Series List';
$meta_keywords = 'view,series,tv,show,description,details';
$meta_description = 'View Series List';
$serieslist = [];
foreach ($masterserieslist as $s) {
if (preg_match('/^[0-9]/', $s['title'])) {
$thisrange = '0-9';
} else {
preg_match('/([A-Z]).*/i', $s['title'], $matches);
$thisrange = strtoupper($matches[1]);
}
$serieslist[$thisrange][] = $s;
}
ksort($serieslist);
$this->smarty->assign('serieslist', $serieslist);
$this->smarty->assign('seriesrange', range('A', 'Z'));
$this->smarty->assign('seriesletter', $letter);
$this->smarty->assign('showname', $showname);
$content = $this->smarty->fetch('viewserieslist.tpl');
$this->smarty->assign([
'title' => $title,
'content' => $content,
'meta_title' => $meta_title,
'meta_keywords' => $meta_keywords,
'meta_description' => $meta_description,
]);
$this->pagerender();
}
}
}