summaryrefslogtreecommitdiff
path: root/inc/route.php
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2016-09-25 16:34:47 +0900
committerBenjamin Southall <applemansigloo@gmail.com>2016-09-25 16:34:47 +0900
commita3b9c4405c6d4cca2a70dbb400e3ba3f65e7ea04 (patch)
tree5a2ebdb801748586e3fde7c12cbeda169b2c3e31 /inc/route.php
parent9436524a306c8e3d6d8a6ed195e2a3c56d5cde39 (diff)
parenta4b619ae5eaab5755dc215a496854dee8f7ce395 (diff)
Merged lainchan with vichan master at 25/9/2016 a4b619ae5eaab5755dc215a496854dee8f7ce395 @czaks czaks committed on GitHub 2 days ago
Diffstat (limited to 'inc/route.php')
-rw-r--r--inc/route.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/inc/route.php b/inc/route.php
new file mode 100644
index 00000000..2a5c1732
--- /dev/null
+++ b/inc/route.php
@@ -0,0 +1,65 @@
+<?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) { global $config;
+ $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['/%b/index.rss'] = 'sb_catalog';
+ $entrypoints['/sitemap.xml'] = 'sb_sitemap';
+
+ $entrypoints = array_merge($entrypoints, $config['controller_entrypoints']);
+
+ $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;
+}
+