/** * Decode multipass token and log user */ public function takeCapture() { if (!Input::has('legend') || !Input::has('zoom') || !Input::has('lat') || !Input::has('lng')) { App::abort(500, 'Missing parameters'); } $phantomjs = getenv('PHANTOM_PATH'); $filename = storage_path() . '/captures/capture_' . str_random(12) . '.jpg'; $legend = Input::get('legend'); $zoom = Input::get('zoom'); $lat = Input::get('lat'); $lng = Input::get('lng'); $siteURL = getenv('SITE_URL'); Log::info('Temp file name:' . $filename); App::finish(function ($request, $response) use($filename) { if (file_exists($filename)) { unlink($filename); Log::info('Temp file removed'); } }); $command = $phantomjs . ' ' . public_path() . '/js/capture.js ' . $filename . ' ' . $legend . ' ' . $zoom . ' ' . $lat . ' ' . $lng . ' ' . $siteURL; Log::info('Comand:' . $command); shell_exec($command); if (file_exists($filename)) { $file = 'atlas_capture.jpg'; return Response::download($filename, $file); } else { App::abort(500, 'Capture error'); } }
static function _break() { self::$finish = true; throw new AppBreakException(); }
function _redirect($url, $params_or_http_code = array()) { if (App::$controller) { App::$controller->layout = false; } App::$finish = true; $http_code = 302; if (is_array($params_or_http_code)) { $url = _url($url, $params_or_http_code); } else { $url = _url($url); $http_code = intval($params_or_http_code); } @header("Location: {$url}", true, $http_code); throw new AppRedirectException($url, $http_code); // App::_break(); }
/** * 输出调试信息 * * @param mixed $obj * @param string $title * @return void */ public static function dump($obj, $title = 'DUMP', $type = 'dump') { switch ($type) { case 'print': $content = print_r($obj, true); break; default: ob_start(); var_dump($obj); $content = ob_get_contents() . "\n"; ob_end_clean(); } App::finish($content, false, $title); }
function _redirect($url, $params_or_http_code = array()) { App::$controller->layout = false; App::$finish = true; $http_code = 302; if (is_array($params_or_http_code)) { $url = _url($url, $params_or_http_code); } else { $url = _url($url); $http_code = intval($params_or_http_code); } header("Location: {$url}", true, $http_code); App::_break(); }
function _redirect($url, $params = array()) { App::$controller->layout = false; App::$finish = true; $url = _url($url, $params); header("Location: {$url}"); App::_break(); }
return Redirect::secure(Request::path(), 301); // permanent redirect } } Cookie::setDefaultPathAndDomain(Config::get("cookies.path"), Config::get("cookies.domain")); }); App::after(function ($request, $response) { if (Config::get("ssl.enabled") && Request::secure()) { if (method_exists($response, "header")) { $response->header("Strict-Transport-Security", "max-age=5256000"); } } }); App::finish(function () { // now that the response has been sent to the user fire an event so that code that is now listening for this event can execute // depending on the server configuration the response might still not have been sent though as the server software may wait // until the php process finishes before sending the response. Event::fire("app.finish"); }); /* |-------------------------------------------------------------------------- | Authentication Filters |-------------------------------------------------------------------------- */ // redirect to login page if not logged in Route::filter('auth', function () { if (is_null(Auth::getUser()) || Auth::getUserState() !== 0) { if (Request::wantsJson()) { return Response::make("", 401); // unauthorized } else { return Redirect::to("/admin/login")->with("authRequestFromFilter", true);
return Response::view('errors.default', array('exception' => $exception), $code); } } else { // Display a JSON error $error_json = new stdClass(); $error_json->error = new stdClass(); // TODO: Set error type based on status code switch ($code) { case 500: $error_json->error->type = 'api_error'; break; default: $error_json->error->type = 'invalid_request_error'; break; } $error_json->error->message = $exception->getMessage(); // Create response $response = Response::json($error_json); $response->setStatusCode($code); // Make sure cross origin requests are allowed $response->header('Access-Control-Allow-Origin', '*'); return $response; } }); App::finish(function ($request, $response) { $tracker_id = \Config::get('tracker.id'); if (!empty($tracker_id)) { $tracker = \App::make('Tdt\\Core\\Analytics\\TrackerInterface'); $tracker->track($request, $tracker_id); } });