public function get($url) { $url_info = parse_url($url); $result = ''; if (!empty($url_info['host']) && !empty($this->providers[$url_info['host']])) { try { $response = $this->dataGrabber->getFromJson('http://' . $url_info['host'] . '/' . $this->providers[$url_info['host']] . '?url=' . urlencode($url) . '&format=json'); $result = $response && $response->thumbnail_url ? $response->thumbnail_url : ($response->thumbnail ? $response->thumbnail : ''); } catch (RemoteDataGrabberException $e) { throw new PreviewNotLinkException(); } } if (empty($result)) { throw new PreviewNotExecutableException(); } return $result; }
public function logout(Request $request, DataGrabberInterface $dataGrabber, $id) { $cookie = $request->cookie('x-access-token'); try { $this->authService->logout(); $logoutResult = (array) $dataGrabber->getFromJson(url(env('AUTH_LOGOUT')), [CURLOPT_COOKIE => 'x-access-token=' . $cookie]); } catch (AuthException $e) { $message = 'Internal logout error: ' . $e->getMessage(); return Response::json(['error' => [$message]], 500); } catch (RemoteDataGrabberException $e) { $message = 'Remote logout error: ' . $e->getMessage(); return Response::json(['error' => [$message]], 500); } setcookie('x-access-token', '', -1, '/'); return Response::json($logoutResult, 200, null, JSON_NUMERIC_CHECK); }
/** * Returns a view for a frame with the GitHub Gist widget * * @return Response */ public function getGistWidget(Request $request, DataGrabberInterface $grabber) { // Validating the input $validator = Validator::make(['link' => $request->get('link')], ['link' => ['required', 'regex:/(ftp|http|https):\\/\\/gist.github.com\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?/i']]); if ($validator->fails()) { return $this->returnWidgetError('Incorrect Gist path'); } // Trying to get a data from remote server $link = $request->get('link') . '.json'; try { $data = $grabber->getFromJson($link); } catch (RemoteDataGrabberException $e) { return $this->returnWidgetError('GitHub Gist is not found'); } // Successfull answer with gist return Response::view('widgets.gist', ['stylesheet_link' => $data->stylesheet, 'snippet' => $data->div, 'js_path' => $this->getJsPath()], 200); }
public function getLogout(Request $request, DataGrabberInterface $dataGrabber) { $cookie = $request->cookie('x-access-token'); $redirect = Redirect::to(url($this->redirectAfterLogout)); try { $this->authService->logout(); $logoutResult = (array) $dataGrabber->getFromJson(url(env('AUTH_LOGOUT')), [CURLOPT_COOKIE => 'x-access-token=' . $cookie]); } catch (AuthException $e) { $redirect = Redirect::to(url(env('AUTH_LOGOUT')))->withCookie('x-access-token', url(env('APP_PREFIX', '') . '/')); } catch (RemoteDataGrabberException $e) { $redirect = Redirect::to(url(env('AUTH_LOGOUT')))->withCookie('x-access-token', url(env('APP_PREFIX', '') . '/')); } Session::flush(); // I don't know if this is neccesary return $redirect; // Use in case of ajax query and redirecting from the front-end //return Response::json($logoutResult, 200, null, JSON_NUMERIC_CHECK); }