datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
datatable.directory/app/Http/Controllers/Controller.php

88 lines
2.4 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests,
DispatchesJobs,
ValidatesRequests {
ValidatesRequests::validate as validate_orig;
ValidatesRequests::validateWithBag as validateWithBag_orig;
}
const BOT_USER_AGENTS = [
// generic
'crawler',
// cli / scripting
'httpie',
'curl',
'wget',
'lwp-request',
'python-requests',
'python-urllib',
'libwww',
'go-http-client',
// commercial
'googlebot',
'google (+',
'bingbot',
'slurp',
'duckduckbot',
'baiduspider',
'yandexbot',
'sogou',
'exabot',
'facebot',
'ia_archiver',
'linkdexbot',
'gigabot',
'adsbot',
// misc
'gigablast',
'phpcrawl',
'mj12bot',
'simplepie',
'sitelockspider',
'scoutjet',
'grub.org',
'mastodon', // mastodon fetching previews
];
protected function jsonResponse($data = [], $code=200)
{
return new JsonResponse($data, $code);
}
// Hacks to allow recursive nesting of validations in string and array format
public function makeValidator($data, $rules, $messages = array(), $customAttributes = array())
{
return \Validator::make($data, vali($rules), $messages, $customAttributes);
}
public function validate(Request $request, array $rules,
array $messages = [], array $customAttributes = [])
{
return objBag($this->validate_orig($request, vali($rules), $messages, $customAttributes));
}
public function validateWithBag($errorBag, Request $request, array $rules,
array $messages = [], array $customAttributes = [])
{
return objBag($this->validateWithBag_orig($errorBag, $request, vali($rules),
$messages, $customAttributes));
}
protected function backWithErrors($errors)
{
return back()->withInput()->withErrors($errors);
}
}