|
|
|
@ -34,13 +34,7 @@ class TableController extends Controller |
|
|
|
|
$revision = $tableModel->revision; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$cookieName = "view!$user->name!$table"; |
|
|
|
|
if (!$request->cookie($cookieName, false)) { |
|
|
|
|
|
|
|
|
|
$tableModel->countVisit(); |
|
|
|
|
|
|
|
|
|
\Cookie::queue($cookieName, true, 86400); |
|
|
|
|
} |
|
|
|
|
$this->countTableVisit($request, $tableModel); |
|
|
|
|
|
|
|
|
|
return view('table.view', [ |
|
|
|
|
'table' => $tableModel, |
|
|
|
@ -191,4 +185,23 @@ class TableController extends Controller |
|
|
|
|
|
|
|
|
|
return redirect(route('table.view', ['user' => $u, 'table' => $input->name])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Check unique visit, filter bots / scripts, and increment visits count. |
|
|
|
|
* |
|
|
|
|
* @param Request $request |
|
|
|
|
* @param Table $table |
|
|
|
|
*/ |
|
|
|
|
private function countTableVisit(Request $request, Table $table) |
|
|
|
|
{ |
|
|
|
|
$cookieName = "view_$table->id"; |
|
|
|
|
if (!$request->cookie($cookieName, false)) { |
|
|
|
|
$ua = $request->userAgent(); |
|
|
|
|
// Filter out suspicious user agents |
|
|
|
|
if (! str_contains(strtolower($ua), Controller::BOT_USER_AGENTS)) { |
|
|
|
|
$table->countVisit(); |
|
|
|
|
\Cookie::queue($cookieName, true, 24*60); // in minutes |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|