Permalink
Browse files

imported the code

  • Loading branch information...
pkrumins committed Feb 21, 2010
1 parent 3e3aad1 commit f8286565d41493657e19cacab5ba482faa4d6a2f
Showing with 52 additions and 1 deletion.
  1. +42 −0 index.php
  2. +4 −1 readme.txt
  3. +6 −0 website.conf
View
@@ -0,0 +1,42 @@
+<?php
+/*
+** Peteris Krumins
+** peteris.krumins@gmail.com
+**
+** A routing framework written in 2000.
+*/
+
+error_reporting(E_ALL);
+
+# check and parse the site configuration
+#
+if (!file_exists('website.conf')) {
+ die('site configuration file was not found');
+}
+
+$SiteConfig = parse_ini_file('website.conf', true);
+
+$parts = parse_url($_SERVER['REQUEST_URI']);
+$path = preg_replace('#^/+#', '', $parts['path']); // drop slashes from the beginning of the request path
+$path = preg_replace('#(//)+#', '', $path); // drop duplicate slashes
+$path = preg_replace('#/+$#', '', $path); // drop trailing slashes
+$path = split('/', $path);
+
+$VConfig['request_path'] = $path;
+
+$request_page = $VConfig['request_path'][0];
+
+if (isset($SiteConfig['pages'][$request_page])) {
+ $page = $request_page;
+}
+else if ($request_page == '') {
+ $page = 'default';
+}
+else {
+ $page = 'error';
+}
+
+require_once $SiteConfig['pages'][$page];
+
+?>
+
View
@@ -7,5 +7,8 @@ His blog is at http://www.catonmat.net -- good coders code, great reuse.
------------------------------------------------------------------------------
-will import it soon, just found its source.
+It uses website.conf INI file to store the possible request pages in the
+[pages] section.
+
+To use it, rewrite all requests to index.php.
View
@@ -0,0 +1,6 @@
+[pages]
+default = page-index.php
+about = page-about.php
+some_other_page = page-smth.php
+; ...
+error = page-error.php

0 comments on commit f828656

Please sign in to comment.