1
44

engine

  1. global $aliases;
  2.  
  3. $aliases = array();
  4.  
  5. @include 'aliases.inc';
  1. require_once 'requesturi.php';
  2. require_once 'translate.php';
  3. require_once 'head.php';
  4. require_once 'trace.php';
  5. require_once 'track.php';
  1. define('ACTIONS_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'actions');
  2. define('BLOCKS_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'blocks');
  3. define('VIEWS_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'views');
  4. define('LAYOUTS_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'layouts');
url
SYNOPSIS

url($action, $lang=false, $arg=false, $param=false)

DESCRIPTION
CODE
  1. function url($action, $lang=false, $arg=false, $param=false) {
  2.     global $base_path;
  3.  
  4.     $path = alias($action, $lang, $arg);
  5.  
  6.     if ($path === false) {
  7.         return false;
  8.     }
  9.  
  10.     $url = $base_path . '/' . $path;
  11.  
  12.     if ($param) {
  13.         if (is_array($param) and $lang and array_key_exists($lang, $param)) {
  14.             $param=$param[$lang];
  15.         }
  16.         if (is_array($param)) {
  17.             $p=array();
  18.             foreach ($param as $name => $value) {
  19.                 $p[]=urlencode($name) . '=' . urlencode($value);
  20.             }
  21.             $param=implode('&', $p);
  22.         }
  23.         $url .= '?' . $param;
  24.     }
  25.  
  26.     return $url;
  27. }
alias
SYNOPSIS

alias($action, $lang=false, $arg=false)

DESCRIPTION
CODE
  1. function alias($action, $lang=false, $arg=false) {
  2.     $path = $action ? detour($action, $lang) : '';
  3.  
  4.     if ($path === false) {
  5.         return false;
  6.     }
  7.  
  8.     if ($arg) {
  9.         if ($action) {
  10.             $path .= '/';
  11.         }
  12.         if (is_array($arg) and $lang and array_key_exists($lang, $arg)) {
  13.             $arg=$arg[$lang];
  14.         }
  15.         $path .= is_array($arg) ? implode('/', $arg) : $arg;
  16.     }
  17.  
  18.     return $lang ? $lang . '/' . $path : $path;
  19. }
detour
SYNOPSIS

detour($action, $lang=false)

DESCRIPTION
CODE
  1. function detour($action, $lang=false) {
  2.     global $aliases;
  3.  
  4.     if ($lang && array_key_exists($lang, $aliases)) {
  5.         if (($path = array_search($action, $aliases[$lang]))) {
  6.             return $path;
  7.         }
  8.     }
  9.     if (array_key_exists(0, $aliases)) {
  10.         if (($path = array_search($action, $aliases[0]))) {
  11.             return $path;
  12.         }
  13.     }
  14.  
  15.     return false;
  16. }
route
SYNOPSIS

route($query, $lang=false)

DESCRIPTION
CODE
  1. function route($query, $lang=false) {
  2.     global $aliases, $default_action, $home_action;
  3.  
  4.     $args = array();
  5.  
  6.     if (empty($query)) {
  7.         return array($home_action, false);
  8.     }
  9.  
  10.     $s = explode('/', $query);
  11.  
  12.     while (count($s) > 0) {
  13.         $p = implode('/', $s);
  14.         if ($lang && array_key_exists($lang, $aliases) && array_key_exists($p, $aliases[$lang])) {
  15.             return array($aliases[$lang][$p], $args);
  16.         }
  17.         if (array_key_exists(0, $aliases) && array_key_exists($p, $aliases[0])) {
  18.             return array($aliases[0][$p], $args);
  19.         }
  20.         array_unshift($args, array_pop($s));
  21.     }
  22.  
  23.     return $default_action ? array($default_action, $args) : false;
  24. }
dispatch
SYNOPSIS

dispatch($languages)

DESCRIPTION
CODE
  1. function dispatch($languages) {
  2.     global $base_path;
  3.     global $request_path, $request_query;
  4.     global $closing_time, $opening_time;
  5.     global $track_visitor, $track_visitor_agent;
  6.  
  7.     $req = $base_path ? substr(request_uri(), strlen($base_path)) : request_uri();
  8.  
  9.     if ($track_visitor) {
  10.         track($req, $track_visitor_agent);
  11.     }
  12.  
  13.     $url = @parse_url($req);
  14.     $path = isset($url['path']) ? trim(urldecode($url['path']), '/') : false;
  15.     $query = isset($url['query']) ? $url['query'] : false;
  16.  
  17.     $request_query=$query;
  18.  
  19.     if (empty($path)) {
  20.         $path = false;
  21.     }
  22.  
  23.     /* site language */
  24.     $p = $path ? explode('/', $path) : false;
  25.     $lang = $p ? $p[0] : false;
  26.  
  27.     if ($lang && in_array($lang, $languages, true)) {
  28.         array_shift($p);
  29.         $path = implode('/', $p);
  30.     }
  31.     else {
  32.         require_once 'locale.php';
  33.  
  34.         $lang=locale();
  35.  
  36.         if (!$lang or !in_array($lang, $languages, true)) {
  37.             $lang = $languages[0];
  38.         }
  39.     }
  40.  
  41.     $request_path=$path ? $lang . '/' . $path : $lang;
  42.  
  43.     $action=$args=$params=false;
  44.     if ($closing_time) {
  45.         $action='error/serviceunavailable';
  46.         $args=array($closing_time, $opening_time);
  47.     }
  48.     else {
  49.         $r = route($path, $lang);
  50.         if (!$r) {
  51.             $action='error/notfound';
  52.         }
  53.         else {
  54.             list($action, $args) = $r;
  55.  
  56.             if ($query) {
  57.                 parse_str($query, $params);
  58.             }
  59.         }
  60.     }
  61.  
  62.     $arglist = $args ? $params ? array_merge($args, $params) : $args : $params;
  63.  
  64.     run($action, $lang, $arglist);
  65. }
run
SYNOPSIS

run($action, $lang=false, $arglist=false)

DESCRIPTION
CODE
  1. function run($action, $lang=false, $arglist=false) {
  2.     global $theme, $author;
  3.  
  4.     head('lang', $lang);
  5.     head('title', translate('title', $lang));
  6.     head('description', translate('description', $lang));
  7.     head('keywords', translate('keywords', $lang));
  8.     head('author', $author);
  9.     head('favicon', 'favicon');
  10.     head('theme', $theme);
  11.  
  12.     $file = ACTIONS_DIR . DIRECTORY_SEPARATOR . $action . '.php';
  13.     if (!is_file($file)) {
  14.         $action = 'error/internalerror';
  15.         $file = ACTIONS_DIR . DIRECTORY_SEPARATOR . $action . '.php';
  16.         $arglist = false;
  17.     }
  18.     require_once $file;
  19.  
  20.     $func = basename($action);
  21.  
  22.     $farg = array();
  23.     if ($lang) {
  24.         $farg[] = $lang;
  25.     }
  26.     if ($arglist) {
  27.         $farg[] = $arglist;
  28.     }
  29.  
  30.     $output = call_user_func_array($func, $farg);
  31.  
  32.     if ($output) {
  33.         echo $output;
  34.     }
  35.  
  36.     exit;
  37. }
build
SYNOPSIS

build($block)

DESCRIPTION
CODE
  1. function build($block) {
  2.     $file = BLOCKS_DIR . DIRECTORY_SEPARATOR . $block . '.php';
  3.     require_once $file;
  4.     $func = basename($block);
  5.     $args=func_get_args();
  6.     array_shift($args);
  7.     return call_user_func_array($func, $args);
  8. }
view
SYNOPSIS

view($view, $lang=false, $vars=false)

DESCRIPTION
CODE
  1. function view($view, $lang=false, $vars=false) {
  2.     $file = $lang ? VIEWS_DIR . DIRECTORY_SEPARATOR . $lang . DIRECTORY_SEPARATOR . $view . '.phtml' : VIEWS_DIR . DIRECTORY_SEPARATOR . $view . '.phtml';
  3.     return render($file, $vars);
  4. }
layout
SYNOPSIS

layout($layout, $vars=false)

DESCRIPTION

layout returns the content generated by the head function and the contents of the array $vars placed according to the model $layout.

  1. layouts
    1. standard.phtml
    2. editing.phtml
    3. viewing.phtml
CODE
  1. function layout($layout, $vars=false) {
  2.     $head=view('head', false, head());
  3.     if ($vars) {
  4.         $vars['head'] = $head;
  5.     }
  6.     else {
  7.         $vars = array('head' => $head);
  8.     }
  9.     $trace=trace();
  10.     if ($trace) {
  11.         $vars['trace'] = $trace;
  12.     }
  13.     $file = LAYOUTS_DIR . DIRECTORY_SEPARATOR . $layout . '.phtml';
  14.     return render($file, $vars);
  15. }
render
SYNOPSIS

render($file, $vars=false)

DESCRIPTION
CODE
  1. function render($file, $vars=false) {
  2.     global $base_path, $base_url, $base_root;
  3.     global $request_path, $request_query;
  4.     global $sitename, $webmaster;
  5.     global $supported_languages, $system_languages;
  6.  
  7.     if ($vars) {
  8.         extract($vars);
  9.     }
  10.     ob_start();
  11.     require $file;
  12.     return ob_get_clean();
  13. }
redirect
SYNOPSIS

redirect($action, $lang=false, $arg=false, $code=false)

DESCRIPTION
CODE
  1. function redirect($action, $lang=false, $arg=false, $params=false, $code=false) {
  2.     global $base_url;
  3.  
  4.     $url=$base_url . url($action, $lang, $arg, $params);
  5.  
  6.     reload($url, $code);
  7. }
reload
SYNOPSIS

reload($url, $code=false)

DESCRIPTION
CODE
  1.         case 303:
  2.             header('HTTP/1.1 303 See Other');
  3.             break;
  4.         case 301:
  5.             header('HTTP/1.1 301 Moved Permanently');
  6.             break;
  7.         case 302:
  8.             header('HTTP/1.1 302 Found');
  9.             break;
  10.         case 307:
  11.             header('HTTP/1.1 307 Temporary Redirect');
  12.             break;
  13.     }
  14.  
  15.     header("Location: $url");
  16.  
  17.     exit;
  18. }
SEE ALSO

head, trace

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].