public function performRedirect(Request $request, $short_url, $secret_key = false) { $link = Link::where('short_url', $short_url)->first(); if ($link == null) { return abort(404); } $link_secret_key = $link->secret_key; if ($link->is_disabled == 1) { return view('error', ['message' => 'Sorry, but this link has been disabled by an administrator.']); } if ($link_secret_key) { if (!$secret_key) { // if we do not receieve a secret key // when we are expecting one, return a 404 return abort(404); } else { if ($link_secret_key != $secret_key) { // a secret key is provided, but it is incorrect return abort(404); } } } $long_url = $link->long_url; $clicks = intval($link->clicks); if (is_int($clicks)) { $clicks += 1; } $link->clicks = $clicks; $link->save(); LinkHelper::processPostClick($link); return redirect()->to($long_url); }
/** * Show the admin panel, and process admin AJAX requests. * * @return Response */ public function displayAdminPage(Request $request) { if (!$this->isLoggedIn()) { return abort(404); } $username = session('username'); $role = session('role'); $admin_users = null; $admin_links = null; if ($this->currIsAdmin()) { $admin_users = User::paginate(15); $admin_links = Link::paginate(15); } $user = UserHelper::getUserByUsername($username); if (!$user) { return redirect(route('index'))->with('error', 'Invalid or disabled account.'); } $user_links = Link::where('creator', $username)->paginate(15); return view('admin', ['role' => $role, 'admin_users' => $admin_users, 'admin_links' => $admin_links, 'user_links' => $user_links, 'api_key' => $user->api_key, 'api_active' => $user->api_active, 'api_quota' => $user->api_quota]); }
public static function findSuitableEnding() { /** * Provided an in-use link ending (string), * find the next available base-32/62 ending. * @return string */ $base = env('POLR_BASE'); $link = Link::where('is_custom', 0)->orderBy('created_at', 'desc')->first(); if ($link == null) { $base10_val = 0; $base_x_val = 0; } else { $latest_link_ending = $link->short_url; $base10_val = BaseHelper::toBase10($latest_link_ending, $base); $base10_val++; } $base_x_val = null; while (LinkHelper::linkExists($base_x_val) || $base_x_val == null) { $base_x_val = BaseHelper::toBase($base10_val, $base); $base10_val++; } return $base_x_val; }
public function links($id) { $links = Link::where('lesson_id', '=', $id)->get(); return $links; }
/** * @param $hash * @return bool */ protected function hashExists($hash) { return (bool) $this->link->where('hash', $hash)->count(); }