diff options
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/inc/functions.php b/inc/functions.php new file mode 100644 index 0000000..4e98342 --- /dev/null +++ b/inc/functions.php @@ -0,0 +1,67 @@ +<?php +function eml_tpl ($options) { + return tpl($options, 'eml.tpl'); +} +function tpl ($options, $file) { + $tpl_htm = file_get_contents(INCLUDE_PATH.$file); + $tpl_htm = preg_replace_callback('/\[tpl:([^\]]*)\]/i', + function ($matches) use (&$options) { + if (!isset($options[$matches[1]])) return ''; + return $options[$matches[1]]; + }, $tpl_htm); + $tpl_htm = preg_replace_callback('/\[include:([^\]]*)\]/i', + function ($matches) { + ob_start(); + if (include INCLUDE_PATH.$matches[1]) { + $r = ob_get_clean(); + ob_end_clean(); + return $r; + } else { + ob_end_clean(); + return ''; + } + }, $tpl_htm); + $tpl_htm = preg_replace_callback('/\[config:([^\]]*)\]/i', + function ($matches) { + global $b_config; + if (!isset($b_config[$matches[1]])) return ''; + return $b_config[$matches[1]]; + }, $tpl_htm); + $tpl_htm = preg_replace_callback('/\[user:([^\]]*)\]/i', + function ($matches) { + global $b_user; + if (!isset($b_user[$matches[1]])) return ''; + return $b_user[$matches[1]]; + }, $tpl_htm); + return $tpl_htm; +} + +function fatal ($msg, $link, $label) { + if ($link === null) $link = 'javascript:history.go(-1);'; + if ($label === null) $label = '← Got It'; + die(tpl(array('message' => $msg, 'link' => $link, 'label' => $label), 'fatal.tpl')); +} + +function gohome () { + global $b_config; + redirect($b_config['base_url']); +} + +function goin () { + l_redirect('dash/'); +} + +function loggedin () { + goin(); +} + +function l_redirect ($page) { + global $b_config; + redirect($b_config['base_url'].$page); +} + +function redirect ($url) { + header('Location: '.$url); + fatal('Redirecting...', $url); +} +?> |
