diff --git a/system/includes/dispatch.php b/system/includes/dispatch.php index 81df1d4..9b269c5 100644 --- a/system/includes/dispatch.php +++ b/system/includes/dispatch.php @@ -272,53 +272,51 @@ function content($value = null) { } function render($view, $locals = null, $layout = null) { + $login = login(); + if(!$login) { + $c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI'])); + $dir = 'cache/page'; + $cachefile = $dir. '/' . $c . '.cache'; + if(is_dir($dir) === false) { + mkdir($dir, 0777, true); + } + } - if(!login()) { - $c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI'])); - $dir = 'cache/page'; - $cachefile = $dir. '/' . $c . '.cache'; - if(is_dir($dir) === false) { - mkdir($dir, 0777, true); - } - } + if (is_array($locals) && count($locals)) { + extract($locals, EXTR_SKIP); + } - if (is_array($locals) && count($locals)) { - extract($locals, EXTR_SKIP); - } + if (($view_root = config('views.root')) == null) + error(500, "[views.root] is not set"); - if (($view_root = config('views.root')) == null) - error(500, "[views.root] is not set"); + ob_start(); + include "{$view_root}/{$view}.html.php"; + content(trim(ob_get_clean())); - ob_start(); - include "{$view_root}/{$view}.html.php"; - content(trim(ob_get_clean())); + if ($layout !== false) { - if ($layout !== false) { + if ($layout == null) { + $layout = config('views.layout'); + $layout = ($layout == null) ? 'layout' : $layout; + } - if ($layout == null) { - $layout = config('views.layout'); - $layout = ($layout == null) ? 'layout' : $layout; - } + $layout = "{$view_root}/{$layout}.html.php"; - $layout = "{$view_root}/{$layout}.html.php"; + header('Content-type: text/html; charset=utf-8'); - header('Content-type: text/html; charset=utf-8'); + ob_start(); + require $layout; - ob_start(); - require $layout; - - if(!login()) { - if (!file_exists($cachefile)) { - file_put_contents($cachefile, ob_get_contents()); - } + if(!$login) { + if (!file_exists($cachefile)) { + file_put_contents($cachefile, ob_get_contents()); + } } - echo trim(ob_get_clean()); - - } else { - echo content(); - } - + echo trim(ob_get_clean()); + } else { + echo content(); + } } function json($obj, $code = 200) {