Example #1
0
 public static function doRouting()
 {
     // Set the locale
     self::setLocale();
     // Check if we have a route and it's not empty
     if (isset($_GET[self::$trigger]) && !empty($_GET[self::$trigger])) {
         // Cleanup the route using our regex (only alphanumeric and url safe chars (.,-_/) are allowed)
         self::$current_route = preg_replace('/[^[:alnum:]\\.\\-\\_\\/]/', '', $_GET[self::$trigger]);
         // See if we have an filename ending (.html, etc.)
         if (self::$ending !== '') {
             // Calculate the offset for the length of the filename ending
             $offset = @strrpos(self::$current_route, self::$ending, -strlen(self::$ending));
             // Check if offset is present
             if ($offset !== FALSE) {
                 // So we remove the ending using the calculated offset to include the files we need
                 self::$tpl = substr_replace(self::$current_route, '', $offset, strlen(self::$ending)) . '.tpl';
                 self::$conf = substr_replace(self::$current_route, '', $offset, strlen(self::$ending)) . '.conf';
                 self::$md = substr_replace(self::$current_route, '', $offset, strlen(self::$ending)) . '.md';
             } else {
                 // Show 404
                 self::error404();
                 return;
             }
         } else {
             // We don't have a filename ending, thus we can assign the route's name to files we need
             self::$tpl = self::$current_route . '.tpl';
             self::$conf = self::$current_route . '.conf';
             self::$md = self::$current_route . '.md';
         }
         // Check for needed files we include later
         if (!file_exists('templates/' . self::$view_dir . self::$tpl) || !is_readable('templates/' . self::$view_dir . self::$tpl) || !is_file('templates/' . self::$view_dir . self::$tpl)) {
             // ...and if not show up the 404
             self::error404();
             return;
         }
     } else {
         // Set the current route to the default
         self::$current_route = self::$default_route . self::$ending;
         // Since we have no route, try to show up the default one
         self::$tpl = self::$default_route . '.tpl';
         self::$conf = self::$default_route . '.conf';
         self::$md = self::$default_route . '.md';
         // Again, check for needed files we include later
         if (!file_exists('templates/' . self::$view_dir . self::$tpl) || !is_readable('templates/' . self::$view_dir . self::$tpl) || !is_file('templates/' . self::$view_dir . self::$tpl)) {
             // ...and if not shopw up the 404 (again)
             self::error404();
             return;
         }
     }
     // Assign all needed files to our main template
     self::$smarty->assign('viewFile', self::$view_dir . self::$tpl);
     self::$smarty->assign('markdownFile', self::$md_dir . self::$md);
     self::$smarty->assign('currentRoute', self::$current_route);
     self::$smarty->assign('configFile', self::$conf);
     // Show the main template
     self::$smarty->display('main.tpl');
 }