adding actual useful feature
This commit is contained in:
125
app/Http/Controllers/TagviewController.php
Normal file
125
app/Http/Controllers/TagviewController.php
Normal 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)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@@ -185,4 +185,9 @@ Route::group(["middleware" => "theme"], function() {
|
|||||||
##Category View
|
##Category View
|
||||||
Route::get('{shortname}', 'CategoryController@showVideo')->where('shortname', '[a-z][a-z0-9]+');
|
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]+']);
|
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]+']);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -67,31 +67,43 @@ class Video extends Model
|
|||||||
return $this->belongsToMany(User::class, 'favorites', 'video_id', 'user_id');
|
return $this->belongsToMany(User::class, 'favorites', 'video_id', 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFirstId($related = null) {
|
public static function getFirstId($related = null, $isTag = false) {
|
||||||
if ($related) {
|
if ($related) {
|
||||||
return $related->videos()->filtered()->orderBy('id', 'ASC')->first()->id;
|
if (!$isTag) {
|
||||||
|
return $related->videos()->filtered()->orderBy('id', 'ASC')->first()->id;
|
||||||
|
}
|
||||||
|
return Video::withAnyTags($related)->filtered()->orderBy('id', 'ASC')->first()->id;
|
||||||
}
|
}
|
||||||
return static::filtered()->orderBy('id', 'ASC')->first()->id;
|
return static::filtered()->orderBy('id', 'ASC')->first()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLastId($related = null) {
|
public static function getLastId($related = null, $isTag = false) {
|
||||||
if ($related) {
|
if ($related) {
|
||||||
return $related->videos()->filtered()->orderBy('id', 'DESC')->first()->id;
|
if (!$isTag) {
|
||||||
|
return $related->videos()->filtered()->orderBy('id', 'DESC')->first()->id;
|
||||||
|
}
|
||||||
|
return Video::withAnyTags($related)->filtered()->orderBy('id', 'DESC')->first()->id;
|
||||||
}
|
}
|
||||||
return static::select('id')->filtered()->orderBy('id', 'DESC')->first()->id;
|
return static::select('id')->filtered()->orderBy('id', 'DESC')->first()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNext($related = null) {
|
public function getNext($related = null, $isTag = false) {
|
||||||
if ($related) {
|
if ($related) {
|
||||||
return $related->videos()->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
|
if (!$isTag) {
|
||||||
|
return $related->videos()->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
|
||||||
|
}
|
||||||
|
return Video::withAnyTags($related)->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
|
||||||
} else {
|
} else {
|
||||||
return static::filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
|
return static::filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPrev($related = null) {
|
public function getPrev($related = null, $isTag = false) {
|
||||||
if ($related) {
|
if ($related) {
|
||||||
return $related->videos()->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
|
if (!$isTag) {
|
||||||
|
return $related->videos()->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
|
||||||
|
}
|
||||||
|
return Video::withAnyTags($related)->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
|
||||||
} else {
|
} else {
|
||||||
return static::filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
|
return static::filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
|
||||||
}
|
}
|
||||||
@@ -220,14 +232,24 @@ public function blurryThumb() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRandom($related = null) {
|
public static function getRandom($related = null, $tag = false) {
|
||||||
if ($related) {
|
if ($related) {
|
||||||
$id = $related->videos()->filtered()->countScoped()->count() - 1;
|
if (!$tag) {
|
||||||
|
$id = $related->videos()->filtered()->countScoped()->count() - 1;
|
||||||
|
if ($id < 0) {
|
||||||
|
return redirect()->back()->with('error', 'no videos found');
|
||||||
|
}
|
||||||
|
$id = mt_rand(0, $id);
|
||||||
|
return $related->videos()->filtered()->skip($id);
|
||||||
|
}
|
||||||
|
// jetzt sind wir im tag
|
||||||
|
$id = Video::withAnyTags($related)->filtered()->countScoped()->count()-1;
|
||||||
if ($id < 0) {
|
if ($id < 0) {
|
||||||
return redirect()->back()->with('error', 'no videos found');
|
return redirect()->back()->with('error', 'no videos found');
|
||||||
}
|
}
|
||||||
$id = mt_rand(0, $id);
|
$id = mt_rand(0,$id);
|
||||||
return $related->videos()->filtered()->skip($id);
|
return Video::withAnyTags($related)->filtered()->skip($id);
|
||||||
|
|
||||||
}
|
}
|
||||||
$id = static::filtered()->countScoped()->count() - 1;
|
$id = static::filtered()->countScoped()->count() - 1;
|
||||||
if ($id < 0) {
|
if ($id < 0) {
|
||||||
@@ -237,6 +259,16 @@ public function blurryThumb() {
|
|||||||
return static::filtered()->skip($id);
|
return static::filtered()->skip($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getSingleRandom($related = null) {
|
||||||
|
$query = $related ? $related->videos()->filtered() : static::filtered();
|
||||||
|
$count = $query->countScoped()->count();
|
||||||
|
if ($count < 1) {
|
||||||
|
return null; // Return null if no videos found
|
||||||
|
}
|
||||||
|
return $query->inRandomOrder()->first();
|
||||||
|
}
|
||||||
|
|
||||||
public function isSfw() {
|
public function isSfw() {
|
||||||
return !$this->tags->contains(function ($key, $tag) {
|
return !$this->tags->contains(function ($key, $tag) {
|
||||||
return $tag->normalized === 'nsfw';
|
return $tag->normalized === 'nsfw';
|
||||||
|
@@ -33,20 +33,20 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="text-center" style="position: unset;">
|
<div class="text-center" style="position: unset;">
|
||||||
@if($related)
|
@if($related)
|
||||||
@if(($prev = $video->getPrev($related)) === null)
|
@if(($prev = $video->getPrev($related,$isTag)) === null)
|
||||||
<a class="first" href="#" style="visibility: hidden;">← first</a>
|
<a class="first" href="#" style="visibility: hidden;">← first</a>
|
||||||
<a id="prev" href="#" style="visibility: hidden;">← prev</a> |
|
<a id="prev" href="#" style="visibility: hidden;">← prev</a> |
|
||||||
@else
|
@else
|
||||||
<a class="first" href="{{url($related->baseurl(), $video->getFirstId($related))}}">← first</a>
|
<a class="first" href="{{url($isTag ? '/t/' . $related : $related->baseurl(), $video->getFirstId($related,$isTag))}}">← first</a>
|
||||||
<a id="prev" href="{{url($related->baseurl(), [$prev->id])}}">← prev</a> |
|
<a id="prev" href="{{url($isTag ? '/t/' . $related : $related->baseurl(), [$prev->id])}}">← prev</a> |
|
||||||
@endif
|
@endif
|
||||||
<a href="{{url($related->baseurl())}}">{!!$related->displayName()!!}</a>
|
<a href="{{url($isTag ? '/t/' . $related : $related->baseurl())}}">{!!$isTag ? $related:$related->displayName()!!}</a>
|
||||||
@if(($next = $video->getNext($related)) === null)
|
@if(($next = $video->getNext($related,$isTag)) === null)
|
||||||
| <a id="next" href="#" style="visibility: hidden;">next →</a>
|
| <a id="next" href="#" style="visibility: hidden;">next →</a>
|
||||||
<a class="last" href="#" style="visibility: hidden;">last →</a>
|
<a class="last" href="#" style="visibility: hidden;">last →</a>
|
||||||
@else
|
@else
|
||||||
| <a id="next" href="{{url($related->baseurl(), [$next->id])}}">next →</a>
|
| <a id="next" href="{{url($isTag ? '/t/' . $related : $related->baseurl(), [$next->id])}}">next →</a>
|
||||||
<a class="last" href="{{url($related->baseurl(), $video->getLastId($related))}}">last →</a>
|
<a class="last" href="{{url($isTag ? '/t/' . $related : $related->baseurl(), $video->getLastId($related,$isTag))}}">last →</a>
|
||||||
@endif
|
@endif
|
||||||
@else
|
@else
|
||||||
@if(($prev = $video->getPrev()) === null)
|
@if(($prev = $video->getPrev()) === null)
|
||||||
|
Reference in New Issue
Block a user