adding actual useful feature

This commit is contained in:
x
2024-06-10 00:27:00 +02:00
committed by Abu Ottermann
parent 3077b2bede
commit 7990870f7c
4 changed files with 181 additions and 19 deletions

View File

@@ -0,0 +1,125 @@
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Video;
use App\Models\Banner;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Http\Requests;
use Cviebrock\EloquentTaggable\Services\TagService;
class TagviewController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($tag)
{
$tag = $video = Video::with('tags')->find($tag->id);
return $tag;
// $tag = Video::withAnyTags($tag)->first();
// return $tag;
// $video = Video::with('tags')->find($tag->id);
// return redirect('t/' . $tag->normalized . '/' . $video->id);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
public function showVideo($shortname, $id = null)
{
// return $shortname;
if (is_null($id)) {
$video = Video::getRandom($shortname, true);
if ($video instanceof HasMany) {
$video = $video->first();
}
else {
return redirect()->back()->with('error', 'tag is empty.');
}
return redirect('/t/' . $shortname . '/' . $video->id);
} else {
// Don't filter on specific video.
// TODO: Add warning page
$video = Video::withAnyTags($shortname)->find($id);
}
if (is_null($video)) {
return redirect()->back()->with('error', 'tag is empty.');
}
$sfw = $video->tags->contains(function($key, $tag) {
return $tag->normalized === 'sfw';
});
return view('video', [
'video' => $video,
'related' => $shortname,
'isTag' => true,
'sfw' => $sfw,
'banner' => Banner::getRandom($video->isSfw())]);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

View File

@@ -185,4 +185,9 @@ Route::group(["middleware" => "theme"], function() {
##Category View
Route::get('{shortname}', 'CategoryController@showVideo')->where('shortname', '[a-z][a-z0-9]+');
Route::get('{shortname}/{id}', 'CategoryController@showVideo')->where(['shortname' => '[a-z][a-z0-9]+', 'id' => '[0-9]+']);
##Tag View anybody?
Route::get('t/{tag}', 'TagviewController@showVideo')->where('tag', '[a-z][a-z0-9]+');
Route::get('t/{tag}/{id}', 'TagviewController@showVideo')->where(['tag' => '[a-z][a-z0-9]+', 'id' => '[0-9]+']);
});