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); }
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 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); }
public function get($url) { try { $head = $this->dataGrabber->getHtmlHead($url); $result = preg_replace("/(.*)meta\\s*property=\"og:image\"\\s*content=\"(.+?)\"(.*)/s", '$2', $head); if (strlen($result) === strlen($head)) { // check <meta content="..." property="og:image"> $result = preg_replace("/(.*)meta\\s*content=\"(.+?)\"\\s*property=\"og:image\"(.*)/s", '$2', $head); } $result = strlen($result) !== strlen($head) ? $result : ''; } catch (RemoteDataGrabberException $e) { throw new PreviewNotLinkException(); } if (empty($result)) { throw new PreviewNotExecutableException(); } return $result; }
public function getPastebinWidget(Request $request, DataGrabberInterface $grabber) { $link = $request->get('link'); // Validating the input $validator = Validator::make(['link' => $link], ['link' => ['required', 'regex:/(ftp|http|https):\\/\\/pastebin.com\\/embed_iframe.php\\?i=[a-z0-9]+/i']]); if ($validator->fails()) { return $this->returnWidgetError('Incorrect Pastebin path'); } try { $data = $grabber->getRaw($link); } catch (RemoteDataGrabberException $e) { return $this->returnWidgetError('Pastebin snippet is not found'); } // Attaching a script for resize $doc = new DOMDocument('1.0'); $doc->loadHTML($data); $body = $doc->getElementsByTagName('body')->item(0); $script = $doc->createElement('script', ''); $scriptUrl = url($this->getJsPath() . '/vendor/jquery/iframeResizer.contentWindow.min.js'); $script->setAttribute('src', $scriptUrl); $body->appendChild($script); $htmlData = $doc->saveHTML(); return Response::make($htmlData, 200); }