Skip to content

Instantly share code, notes, and snippets.

@sofadesign
Created April 27, 2010 17:31
Show Gist options
  • Save sofadesign/381034 to your computer and use it in GitHub Desktop.
Save sofadesign/381034 to your computer and use it in GitHub Desktop.
<?php
function before($route)
{
# Authentication if required
$uri = request_uri();
$is_admin = preg_match('%^/admin(/.+)?$%', $uri);
$auth_required = $is_admin && $uri != "/admin/login" && $uri != "/admin/logout";
if($auth_required) authentication_is_required();
# Layouts
$layout_name= $is_admin ? 'admin' : 'default';
$layout_path = "layouts/{$layout_name}.html.php";
layout($layout_path);
if(option('env') > ENV_DEVELOPMENT) error_layout($layout_path);
# other ui options
if($is_admin)
{
before_admin();
}
else
{
$is_file = preg_match('%^/(.+)/\d+/file/(\w+)?$%', $uri);
if(!$is_file) before_public();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment