protected function makeResponse($response, $internal = true) { if ($this->isServer and ($response === false or $response === E_UNAUTH) and !$this->user(false)) { return Redirect::to(route('vanemart::login') . '?back=' . urlencode(\URI::full()))->with('passthru', 1); } else { return parent::makeResponse($response, $internal); } }
function current() { if (isset($this->current)) { return $this->current; } else { $url = Menu::expand($this->url); return trim(strtok(\URI::full(), '?'), '/') === trim($url, '/'); } }
function get_index($id = null) { if ($model = static::find($id)) { if ($this->in('redir', 1) and strtok(\URI::full(), '?') !== $model->url() and strtok(null) == '') { return Redirect::to($model->url(), 301); } else { $this->title = $model->to_array(); return $this->ajax($model); } } }
public function action_image($galleryID, $imageID) { if (Auth::guest()) { Session::put('lastURL', URI::full()); return Redirect::to('login'); } $image = Images::get($imageID); if ($image != null) { Images::incrementViews($imageID); $liked = Likes::has($imageID, Auth::user()->id); return View::make('home.image')->with('image', $image)->with('galleryID', $galleryID)->with('liked', $liked); } else { return "Image does not exists!"; } }
$cachedResponse = Cache::get(md5(URI::full())); if ($cachedResponse && Config::get('cache.timeout')) { return $cachedResponse; } }); // Prepara la respuesta antes de ser enviada Route::filter('prepareResponse', function ($response) { $cache_timeout = Config::get('cache.timeout'); if ($cache_timeout) { $response->header('cache-control', 'max-age=' . $cache_timeout * 60 . ', public'); } else { $response->header('cache-control', 'public'); } if (gettype($response->content) != 'array') { // TODO: Implementar distintas formas de retornar la data $response->header('Content-Type', 'application/json'); $response->content = Apihelper::wrapCallback(json_encode(array('error' => true, 'message' => $response->content))); } else { $response->header('Content-Type', 'application/json'); $response->content = Apihelper::wrapCallback(json_encode($response->content)); } }); // Agrega la respuesta al cache Route::filter('cacheResponse', function ($response) { $cache_timeout = Config::get('cache.timeout'); if ($cache_timeout) { if (!Cache::get(md5(URI::full()))) { Cache::put(md5(URI::full()), $response, $cache_timeout); } } });
<?php //Route::controller(Controller::detect()); Route::get('(:bundle)', function () { return '欢迎使用管理后台'; }); Route::get('(:bundle)/pannel', function () { return '欢迎使用管理后台控制面板' . URI::full() . 'cc' . Request::ip(); });
}); Route::filter('block_tutorial', function () { $session_tutorial = Session::get('halt_tutorial_except', 0); $session_exam = Session::get('examid', 0); if ($session_exam && !Sentry::getUser()->inGroup(Sentry::findGroupByName('admin'))) { return "SYSTEM RESOURCES ARE INACCESSIBLE WHILE DOING A EXAM"; } }); Route::filter('exam_check', function () { if (!Session::get('examid')) { return Redirect::to(URL::previous()); } }); Route::filter('cache', function ($response = null) { if (Setting::get('system.cache') != 0) { $uri = URI::full() == '/' ? 'home' : Str::slug(URI::full()); $cached_filename = "response-{$uri_}" . Sentry::getUser()->id; if (is_null($response)) { return Cache::get($cached_filename); } else { if ($response->status == 200) { $cache_time = Setting::get('system.cache'); // 30 minutes if ($cache_time > 0) { Cache::put($cached_filename, $response, $cache_time); } } } } }); //TODO:create a filter
$allowed = true; break; } } if (!$allowed || count($pieces) == 0) { return Response::code(403); } $path = implode(DS, $pieces); if (!File::exists(J_PATH . $path) || is_dir(J_PATH . $path)) { return Response::code(404); } $im = new Image(J_PATH . $path); $im->resize((int) Request::get("width"), (int) Request::get("height"), Request::get("method", "fit"), Request::get("background", 0xffffff)); $im->header(); }); Router::register("*", "(:all)", function () { Response::code(404); if (Request::isLocal()) { echo "URI: " . URI::full() . "<br>\n"; echo "Path Info: " . Request::pathInfo() . "\n"; } return; }); if (URI::isManager()) { Structure::routes(); } Request::$route = Router::route(Request::method(), URI::current()); Event::fire(J_EVENT_RESPONSE_START); echo Request::$route->call(); Event::fire(J_EVENT_RESPONSE_END); //echo "<br><br>" . round(elapsed_time() * 1000000) / 1000 . "ms";
| You can even respond to more than one URI: | | Route::post(array('hello', 'world'), function() | { | return 'Hello World!'; | }); | | It's easy to allow URI wildcards using (:num) or (:any): | | Route::put('hello/(:any)', function($name) | { | return "Welcome, $name."; | }); | */ Log::info(sprintf("%s %s %s Seg[%d]: %s %s %s", Request::method(), URI::full(), Request::ip(), Router::$segments, URI::segment(1, '-'), URI::segment(2, '-'), URI::segment(3, '-'))); // start page Route::get('/', 'sapoc@index'); // login/logout Route::get('login', 'sapoc@login'); Route::post('login', 'sapoc@auth'); Route::get('logout', function () { Auth::logout(); return Redirect::to('/'); }); // register Route::get('verify', 'sapoc@verify'); Route::post('verify', 'sapoc@send_verification'); //Route::get('register', 'user@register'); Route::get('register', 'sapoc@register'); Route::post('register', 'sapoc@create_user');
| | Filter::register('filter', function() | { | return 'Filtered!'; | }); | | Next, attach the filter to a route: | | Router::register('GET /', array('before' => 'filter', function() | { | return 'Hello World!'; | })); | */ Route::filter('cache', function ($response = NULL) { $cname = 'response:' . Str::slug(URI::full()); if (!$response) { return Cache::get($cname); } else { if ($response->status == 200) { $ctime = floor(pow(current(sys_getloadavg()) + 1, 5)); # cache for between 1 and 32 minutes Cache::put($cname, $response, $ctime); } } }); Route::filter('before', function () { // Do stuff before every request to your application... }); Route::filter('after', function ($response) { // Encode objects/arrays/booleans to JSON