mirror of
https://repo.getmonero.org/AnonDev/xmrmemes.git
synced 2024-10-01 05:25:34 -04:00
dbfda5cf9e
Add dark / light theme Add social sharing on meme pages Add approving / pending admin section Improve design Add pagination on profiles Make front end date time user friendly Finish rough draft of site And Much more... Still need to fix a few minor things before it goes live. Almost complete.
165 lines
4.1 KiB
PHP
165 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Meme;
|
|
use App\Models\User;
|
|
use App\Models\Address;
|
|
use Illuminate\Http\Request;
|
|
use chillerlan\QRCode\{QRCode, QROptions};
|
|
|
|
class MemeController extends Controller
|
|
{
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// $this->middleware('auth');
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'seo' => [
|
|
'title' => null,
|
|
'desc' => null,
|
|
'img' => null,
|
|
],
|
|
'memes' => Meme::with(['user', 'tips'])->orderByDesc('created_at')->paginate(20),
|
|
];
|
|
return view('homepage', ['data' => $data]);
|
|
}
|
|
|
|
public function leaderboard()
|
|
{
|
|
$users = User::with('tips')->has('memes')->get();
|
|
$users = $users->sortByDesc(function($user) {
|
|
return $user->tips_total;
|
|
});
|
|
|
|
$data = [
|
|
'users' => $users,
|
|
];
|
|
|
|
return view('leaderboard', ['data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('meme-create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validatedData = $request->validate([
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'caption' => ['string', 'max:255', 'nullable'],
|
|
'image' => ['required', 'image'],
|
|
]);
|
|
$user = \Auth::user();
|
|
$used_ids = Meme::pluck('address_id')->toArray();
|
|
$address = Address::whereNotIn('id', $used_ids)->first('id');
|
|
return Meme::create([
|
|
'user_id' => $user->id,
|
|
'address_id' => $address->id,
|
|
'title' => $request->input('title'),
|
|
'caption' => $request->input('caption'),
|
|
'image' => $request->file('image'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Models\Meme $meme
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$meme = Meme::where('id', $id)->with(['user', 'tips', 'address'])->firstOrFail();
|
|
|
|
$share = \Share::page(url()->current(), $meme->title, ['class' => 'fa-lg', 'target' => '_blank'])
|
|
->facebook()
|
|
->twitter()
|
|
->reddit()
|
|
->telegram()
|
|
->linkedin()
|
|
->whatsapp();
|
|
|
|
$data = [
|
|
'meme' => $meme,
|
|
'qr' => (new QRCode)->render($meme->address->address),
|
|
'share' => preg_replace("/<a(.*?)>/", "<a$1 target=\"_blank\">", $share),
|
|
];
|
|
|
|
return view('meme', ['data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\Meme $meme
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Meme $meme)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\Models\Meme $meme
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, Meme $meme)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function approve($id)
|
|
{
|
|
if (\Auth::user()->is_admin === 1) {
|
|
$meme = Meme::withoutGlobalScope('approved')->find($id);
|
|
$meme->is_approved = 1;
|
|
$meme->save();
|
|
return redirect()->away(url()->previous());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\Meme $meme
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
if (\Auth::user()->is_admin === 1) {
|
|
Meme::withoutGlobalScope('approved')->where('id', $id)->delete();
|
|
return redirect()->away(url()->previous());
|
|
}
|
|
}
|
|
}
|