Restyled by php-cs-fixer
This commit is contained in:
parent
ba9fa0f12a
commit
711ac93cb9
17 changed files with 74 additions and 47 deletions
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
class AdminBookmarksController extends Controller
|
class AdminBookmarksController extends Controller
|
||||||
{
|
{
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
$categories = BookmarkCategory::with('sites')->get();
|
$categories = BookmarkCategory::with('sites')->get();
|
||||||
return view('admin.bookmarks', compact('categories'));
|
return view('admin.bookmarks', compact('categories'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,19 @@
|
||||||
|
|
||||||
class AdminGuestbookController extends Controller
|
class AdminGuestbookController extends Controller
|
||||||
{
|
{
|
||||||
function getGuestbookUniqueAddr(): int {
|
public function getGuestbookUniqueAddr(): int
|
||||||
|
{
|
||||||
$uniqueIpsCount = DB::table('guestbook__entries')->distinct()->count('ip');
|
$uniqueIpsCount = DB::table('guestbook__entries')->distinct()->count('ip');
|
||||||
return $uniqueIpsCount;
|
return $uniqueIpsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGuestbookEntriesCount(): int {
|
public function getGuestbookEntriesCount(): int
|
||||||
|
{
|
||||||
$entryCount = DB::table('guestbook__entries')->count();
|
$entryCount = DB::table('guestbook__entries')->count();
|
||||||
return $entryCount;
|
return $entryCount;
|
||||||
}
|
}
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
$guestbook_unique_addr = $this->getGuestbookUniqueAddr();
|
$guestbook_unique_addr = $this->getGuestbookUniqueAddr();
|
||||||
$guestbook_entry_count = $this->getGuestbookEntriesCount();
|
$guestbook_entry_count = $this->getGuestbookEntriesCount();
|
||||||
$entries = GuestbookEntry::selectEntries();
|
$entries = GuestbookEntry::selectEntries();
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
class AdminImportController extends Controller
|
class AdminImportController extends Controller
|
||||||
{
|
{
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
return view('admin.import');
|
return view('admin.import');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +27,9 @@ public function submit(Request $request)
|
||||||
$data = json_decode($jsonContent, true);
|
$data = json_decode($jsonContent, true);
|
||||||
$tables = [];
|
$tables = [];
|
||||||
foreach($data as $item) {
|
foreach($data as $item) {
|
||||||
if ($item['type'] !== "table") continue;
|
if ($item['type'] !== "table") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$tables[$item['name']] = [
|
$tables[$item['name']] = [
|
||||||
'data' => $item['data'],
|
'data' => $item['data'],
|
||||||
'count' => count($item['data'])
|
'count' => count($item['data'])
|
||||||
|
@ -48,7 +51,8 @@ public function submit(Request $request)
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception Invalid table specified, to be replaced with custom exception
|
* @throws Exception Invalid table specified, to be replaced with custom exception
|
||||||
*/
|
*/
|
||||||
public function import(array $data, string $table_name): void {
|
public function import(array $data, string $table_name): void
|
||||||
|
{
|
||||||
switch ($table_name) {
|
switch ($table_name) {
|
||||||
case 'guestbook__entries':
|
case 'guestbook__entries':
|
||||||
GuestbookEntry::importGuestbookEntry($data);
|
GuestbookEntry::importGuestbookEntry($data);
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
class BookmarksController extends Controller
|
class BookmarksController extends Controller
|
||||||
{
|
{
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
$categories = BookmarkCategory::with('sites')->get();
|
$categories = BookmarkCategory::with('sites')->get();
|
||||||
return view('bookmarks', compact('categories'));
|
return view('bookmarks', compact('categories'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
class CalculatorsController extends Controller
|
class CalculatorsController extends Controller
|
||||||
{
|
{
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
return view('calculators');
|
return view('calculators');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
class ComputersController extends Controller
|
class ComputersController extends Controller
|
||||||
{
|
{
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
return view('computers');
|
return view('computers');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use UAParser\Parser;
|
use UAParser\Parser;
|
||||||
|
|
||||||
class GuestbookController extends Controller {
|
class GuestbookController extends Controller
|
||||||
public function show(): View {
|
{
|
||||||
|
public function show(): View
|
||||||
|
{
|
||||||
$entries = GuestbookEntry::selectEntries();
|
$entries = GuestbookEntry::selectEntries();
|
||||||
$parser = Parser::create();
|
$parser = Parser::create();
|
||||||
|
|
||||||
|
@ -26,7 +28,8 @@ public function show(): View {
|
||||||
* @return RedirectResponse
|
* @return RedirectResponse
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function addEntry(Request $request): RedirectResponse {
|
public function addEntry(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
'message' => 'required'
|
'message' => 'required'
|
||||||
|
@ -37,7 +40,8 @@ public function addEntry(Request $request): RedirectResponse {
|
||||||
return back()->with('success', 'Entry submitted successfully!');
|
return back()->with('success', 'Entry submitted successfully!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function banIP(string $addr) {
|
public function banIP(string $addr)
|
||||||
|
{
|
||||||
// TODO: Add banning system
|
// TODO: Add banning system
|
||||||
// $matching_bans = DB::select('SELECT reason FROM guestbook__bans WHERE ip_address = ?', array($request->ip()));
|
// $matching_bans = DB::select('SELECT reason FROM guestbook__bans WHERE ip_address = ?', array($request->ip()));
|
||||||
// if (!empty($matching_bans)) {
|
// if (!empty($matching_bans)) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ class HomeController extends Controller
|
||||||
* Returns age based on birthday date and current date (GMT)
|
* Returns age based on birthday date and current date (GMT)
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function returnAge(): int
|
public function returnAge(): int
|
||||||
{
|
{
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
$birthday = new DateTime("2005-06-07");
|
$birthday = new DateTime("2005-06-07");
|
||||||
|
@ -24,7 +24,8 @@ function returnAge(): int
|
||||||
* Shows home page
|
* Shows home page
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
return view('home', [
|
return view('home', [
|
||||||
'age' => $this->returnAge()
|
'age' => $this->returnAge()
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
class MusicController extends Controller
|
class MusicController extends Controller
|
||||||
{
|
{
|
||||||
public function getCurrentTrack() {
|
public function getCurrentTrack()
|
||||||
|
{
|
||||||
// If it's already cached just return that
|
// If it's already cached just return that
|
||||||
if (Cache::has('current_track')) {
|
if (Cache::has('current_track')) {
|
||||||
return Cache::get('current_track');
|
return Cache::get('current_track');
|
||||||
|
@ -34,7 +35,8 @@ public function getCurrentTrack() {
|
||||||
return $current_track;
|
return $current_track;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTopTracks() {
|
public function getTopTracks()
|
||||||
|
{
|
||||||
// If it's already cached just return that
|
// If it's already cached just return that
|
||||||
if (Cache::has('top_tracks')) {
|
if (Cache::has('top_tracks')) {
|
||||||
return Cache::get('top_tracks');
|
return Cache::get('top_tracks');
|
||||||
|
@ -61,7 +63,8 @@ public function getTopTracks() {
|
||||||
Cache::put('top_tracks', $topTracks, now()->addSeconds(15));
|
Cache::put('top_tracks', $topTracks, now()->addSeconds(15));
|
||||||
return $topTracks;
|
return $topTracks;
|
||||||
}
|
}
|
||||||
public function show() : View {
|
public function show(): View
|
||||||
|
{
|
||||||
return view('music')
|
return view('music')
|
||||||
->with('current_track', $this->getCurrentTrack())
|
->with('current_track', $this->getCurrentTrack())
|
||||||
->with('top_tracks', $this->getTopTracks());
|
->with('top_tracks', $this->getTopTracks());
|
||||||
|
|
|
@ -11,23 +11,27 @@ class BookmarkCategory extends Model
|
||||||
protected $table = "bookmark__categories";
|
protected $table = "bookmark__categories";
|
||||||
protected $fillable = ['name'];
|
protected $fillable = ['name'];
|
||||||
|
|
||||||
public function sites() {
|
public function sites()
|
||||||
|
{
|
||||||
return $this->hasMany(BookmarkSite::class, 'category');
|
return $this->hasMany(BookmarkSite::class, 'category');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function insertBookmarkCategory(string $name) {
|
public static function insertBookmarkCategory(string $name)
|
||||||
$newBookmarkCategory = new BookmarkCategory;
|
{
|
||||||
|
$newBookmarkCategory = new BookmarkCategory();
|
||||||
$newBookmarkCategory->name = $name;
|
$newBookmarkCategory->name = $name;
|
||||||
$newBookmarkCategory->save();
|
$newBookmarkCategory->save();
|
||||||
}
|
}
|
||||||
public static function selectBookmarks(int $id) {
|
public static function selectBookmarks(int $id)
|
||||||
|
{
|
||||||
$bookmarks = BookmarkSite::where('category', '=', $id)->firstOrFail();
|
$bookmarks = BookmarkSite::where('category', '=', $id)->firstOrFail();
|
||||||
return $bookmarks;
|
return $bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function importBookmarkCategory(array $data) {
|
public static function importBookmarkCategory(array $data)
|
||||||
|
{
|
||||||
foreach ($data as $category) {
|
foreach ($data as $category) {
|
||||||
$newBookmarkCategory = new BookmarkCategory;
|
$newBookmarkCategory = new BookmarkCategory();
|
||||||
$newBookmarkCategory->name = $category['name'];
|
$newBookmarkCategory->name = $category['name'];
|
||||||
$newBookmarkCategory->priority = intval($category['priority']);
|
$newBookmarkCategory->priority = intval($category['priority']);
|
||||||
$newBookmarkCategory->save();
|
$newBookmarkCategory->save();
|
||||||
|
|
|
@ -5,26 +5,30 @@
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class BookmarkSite extends Model {
|
class BookmarkSite extends Model
|
||||||
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
protected $table = "bookmark__sites";
|
protected $table = "bookmark__sites";
|
||||||
protected $fillable = ['name', 'description', 'url', 'category'];
|
protected $fillable = ['name', 'description', 'url', 'category'];
|
||||||
|
|
||||||
public function category() {
|
public function category()
|
||||||
|
{
|
||||||
return $this->belongsTo(BookmarkCategory::class, 'category');
|
return $this->belongsTo(BookmarkCategory::class, 'category');
|
||||||
}
|
}
|
||||||
public static function insertBookmark(string $name, string $url, int $category) {
|
public static function insertBookmark(string $name, string $url, int $category)
|
||||||
|
{
|
||||||
$category = BookmarkCategory::where('id', $category)->firstOrFail();
|
$category = BookmarkCategory::where('id', $category)->firstOrFail();
|
||||||
$newBookmark = new BookmarkSite;
|
$newBookmark = new BookmarkSite();
|
||||||
$newBookmark->name = $name;
|
$newBookmark->name = $name;
|
||||||
$newBookmark->url = $url;
|
$newBookmark->url = $url;
|
||||||
$newBookmark->category = $category->id;
|
$newBookmark->category = $category->id;
|
||||||
$newBookmark->save();
|
$newBookmark->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function importBookmark(array $data) {
|
public static function importBookmark(array $data)
|
||||||
|
{
|
||||||
foreach ($data as $site) {
|
foreach ($data as $site) {
|
||||||
$newBookmark = new BookmarkSite;
|
$newBookmark = new BookmarkSite();
|
||||||
$newBookmark->name = $site['name'];
|
$newBookmark->name = $site['name'];
|
||||||
$newBookmark->description = $site['description'];
|
$newBookmark->description = $site['description'];
|
||||||
$newBookmark->url = $site['url'];
|
$newBookmark->url = $site['url'];
|
||||||
|
|
|
@ -18,8 +18,9 @@ class GuestbookEntry extends Model
|
||||||
* @param Request $request The HTTP POST request
|
* @param Request $request The HTTP POST request
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function insertGuestbookEntry(Request $request) {
|
public static function insertGuestbookEntry(Request $request)
|
||||||
$newEntry = new GuestbookEntry;
|
{
|
||||||
|
$newEntry = new GuestbookEntry();
|
||||||
$newEntry->name = htmlspecialchars($request->get('name'));
|
$newEntry->name = htmlspecialchars($request->get('name'));
|
||||||
$newEntry->message = htmlspecialchars($request->get('message'));
|
$newEntry->message = htmlspecialchars($request->get('message'));
|
||||||
$newEntry->ip = $request->ip();
|
$newEntry->ip = $request->ip();
|
||||||
|
@ -28,15 +29,17 @@ public static function insertGuestbookEntry(Request $request) {
|
||||||
$newEntry->save();
|
$newEntry->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function selectEntries() {
|
public static function selectEntries()
|
||||||
|
{
|
||||||
$entries = GuestbookEntry::orderBy('created_at', 'desc')->get();
|
$entries = GuestbookEntry::orderBy('created_at', 'desc')->get();
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function importGuestbookEntry(array $data) {
|
public static function importGuestbookEntry(array $data)
|
||||||
|
{
|
||||||
foreach ($data as $entry) {
|
foreach ($data as $entry) {
|
||||||
$dt = new \DateTime('@' . $entry['timestamp']);
|
$dt = new \DateTime('@' . $entry['timestamp']);
|
||||||
$newEntry = new GuestbookEntry;
|
$newEntry = new GuestbookEntry();
|
||||||
$newEntry->name = $entry['name'];
|
$newEntry->name = $entry['name'];
|
||||||
$newEntry->ip = $entry['ip_address'];
|
$newEntry->ip = $entry['ip_address'];
|
||||||
$newEntry->agent = $entry['agent'];
|
$newEntry->agent = $entry['agent'];
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class () extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class () extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class () extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,10 +11,11 @@ class BookmarkCategoriesTableSeeder extends Seeder
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
*/
|
*/
|
||||||
public function run(): void {
|
public function run(): void
|
||||||
// BookmarkCategory::factory()->count(5)->create()->each(function ($category) {
|
{
|
||||||
// $category->sites()->saveMany(BookmarkSite::factory()->count(3)->make());
|
// BookmarkCategory::factory()->count(5)->create()->each(function ($category) {
|
||||||
// });
|
// $category->sites()->saveMany(BookmarkSite::factory()->count(3)->make());
|
||||||
|
// });
|
||||||
$category = new BookmarkCategory([
|
$category = new BookmarkCategory([
|
||||||
'name' => 'cool people',
|
'name' => 'cool people',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -41,4 +41,3 @@
|
||||||
Route::post('/admin/import', [AdminImportController::class, 'submit'])
|
Route::post('/admin/import', [AdminImportController::class, 'submit'])
|
||||||
->name('admin.import.submit')
|
->name('admin.import.submit')
|
||||||
->middleware('auth');
|
->middleware('auth');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue