/** * URL Generator for Smarty Templates * * Examples: * {link_to href="/news/show"} * * Type: function<br> * Name: a<br> * Purpose: Generates the proper URL from the href parameter given<br> * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_link_to($params, $smarty) { // method parameter "href" if (empty($params['href'])) { $errormessage = 'You are using the <font color="#FF0033">{link_to}</font> command, but the <font color="#FF0033">Parameter "href" is missing.</font>'; $errormessage .= ' Try to append the parameter in the following way: <font color="#66CC00">href="/news/show"</font>.'; trigger_error($errormessage); return; } else { // convert from internal slashed format to URL return Koch_Router::buildURL($params['href']); } }
/** * array_map callback function * * 1) convert short urls * 2) execute callback conditions of menu items * 3) use name as title, if title is not defined * * @param array $modulenavigation */ function applyCallbacks(array $modulenavigation) { /** * 1) Convert Short Urls * * This replaces the values of the 'url' key (array['url']), * because these might be shorthands, like "/index/show". */ $modulenavigation['url'] = Koch_Router::buildURL($modulenavigation['url']); /** * 2) Conditions of menu items * * If the condition of the menu item is not met, * then condition is set to false, otherwise true. */ if ($modulenavigation['condition'] !== null) { /** * the if statement evaluates the content of the key condition * and compares it to false, then reassigns the boolean value as * the condition value. * * for now you might define 'condition' => extension_loaded('apc') * * @todo check usage of closures */ if ($modulenavigation['condition'] === false) { $modulenavigation['condition'] = false; } else { $modulenavigation['condition'] = true; } } /** * 3) use name as title, if title is not defined */ if ($modulenavigation['title'] == '') { $modulenavigation['title'] = $modulenavigation['name']; } return $modulenavigation; }
/** * Redirect * * Redirects to the URL. * This redirects automatically, when headers are not already sent, * else it provides a link to the target URL for manual redirection. * * Time defines how long the redirect screen will be displayed. * Statuscode defines a http status code. The default value is 302. * Text is a messagestring for the htmlbody of the redirect screen. * * @param string Redirect to this URL * @param int seconds before redirecting (for the html tag "meta refresh") * @param int http status code, default: '303' => 'See other' * @param text text of redirect message * @param string redirect mode LOCATION, REFRESH, JS, HTML */ public static function redirect($url, $time = 0, $statusCode = 303, $message = null, $mode = null) { // convert from internal slashed format to external URL $url = Koch_Router::buildURL($url, false); $filename = ''; $linenum = ''; $redirect_html = ''; // redirect only, if headers are NOT already send if (headers_sent($filename, $linenum) === false) { // clear all output buffers #while(@ob_end_clean()); // redirect to ... self::setStatusCode($statusCode); // detect if redirect message contains a flashmessage type // fetch message from "type#message" $message = self::detectTypeAndSetFlashmessage($message); switch ($mode) { default: case 'LOCATION': header('LOCATION: ' . $url); #session_write_close(); // @todo figure out, if session closing is needed? exit; break; case 'REFRESH': header('Refresh: 0; URL="' . $url . '"'); #session_write_close(); // @todo figure out, if session closing is needed? break; case 'JS': $redirect_html = '<script type="text/javascript">window.location.href=' . $url . ';</script>'; break; case 'HTML': // redirect html content $redirect_html = '<html><head>'; $redirect_html .= '<meta http-equiv="refresh" content="' . $time . '; URL=' . $url . '" />'; $redirect_html .= '</head><body>' . $message . '</body></html>'; break; } if (empty($redirect_html) === false) { #self::addHeader('Location', $url); self::setContent($redirect_html, $time, htmlspecialchars($url, ENT_QUOTES, 'UTF-8')); } // Flush the content on the normal way! self::sendResponse(); } else { // headers already send! $msg = _('Header already send in file %s in line %s. Redirecting impossible.'); $msg .= _('You might click this link instead to redirect yourself to the <a href="%s">target url</a> an'); sprintf($msg, $filename, $linenum, $url); exit; } }