diff options
| author | czaks <marcin@6irc.net> | 2016-05-08 02:50:44 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2016-05-08 02:50:44 +0200 |
| commit | a5e22f6d637365042c53f5e9552e8e8444549d6f (patch) | |
| tree | 78999bf985ff7d07b9b65426c226865561988b3f /inc/route.php | |
| parent | deef54fe13c181181b62f8e7e5ec8953e62a6f72 (diff) | |
split route and controller parts from smart build
Diffstat (limited to 'inc/route.php')
| -rw-r--r-- | inc/route.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/inc/route.php b/inc/route.php new file mode 100644 index 00000000..66602d77 --- /dev/null +++ b/inc/route.php @@ -0,0 +1,62 @@ +<?php + +// vichan's routing mechanism + +// don't bother with that unless you use smart build or advanced build +// you can use those parts for your own implementations though :^) + +defined('TINYBOARD') or exit; + +function route($path) { + $entrypoints = array(); + + $entrypoints['/%b/'] = 'sb_board'; + $entrypoints['/%b/'.$config['file_index']] = 'sb_board'; + $entrypoints['/%b/'.$config['file_page']] = 'sb_board'; + $entrypoints['/%b/%d.json'] = 'sb_api_board'; + if ($config['api']['enabled']) { + $entrypoints['/%b/threads.json'] = 'sb_api'; + $entrypoints['/%b/catalog.json'] = 'sb_api'; + } + + $entrypoints['/%b/'.$config['dir']['res'].$config['file_page']] = 'sb_thread_slugcheck'; + $entrypoints['/%b/'.$config['dir']['res'].$config['file_page50']] = 'sb_thread_slugcheck50'; + if ($config['slugify']) { + $entrypoints['/%b/'.$config['dir']['res'].$config['file_page_slug']] = 'sb_thread_slugcheck'; + $entrypoints['/%b/'.$config['dir']['res'].$config['file_page50_slug']] = 'sb_thread_slugcheck50'; + } + if ($config['api']['enabled']) { + $entrypoints['/%b/'.$config['dir']['res'].'%d.json'] = 'sb_thread'; + } + + $entrypoints['/*/'] = 'sb_ukko'; + $entrypoints['/*/index.html'] = 'sb_ukko'; + $entrypoints['/recent.html'] = 'sb_recent'; + $entrypoints['/%b/catalog.html'] = 'sb_catalog'; + $entrypoints['/sitemap.xml'] = 'sb_sitemap'; + + $reached = false; + + list($request) = explode('?', $path); + + foreach ($entrypoints as $id => $fun) { + $id = '@^' . preg_quote($id, '@') . '$@u'; + + $id = str_replace('%b', '('.$config['board_regex'].')', $id); + $id = str_replace('%d', '([0-9]+)', $id); + $id = str_replace('%s', '[a-zA-Z0-9-]+', $id); + + $matches = null; + + if (preg_match ($id, $request, $matches)) { + array_shift($matches); + + $reached = array($fun, $matches); + + break; + } + } + + return $reached; +} + |
