public function redirect($p)
 {
     $path = FabriqModules::new_model('pathmap', 'Paths');
     $path->get_by_path($p);
     if (count($path)) {
         switch ($path->modpage) {
             case 'module':
                 if (FabriqModules::enabled($path->controller)) {
                     $extra = explode('/', $path->extra);
                     if (count($extra) == 1) {
                         if ($extra[0] == '') {
                             unset($extra[0]);
                         }
                     }
                     PathMap::arg(0, $path->controller);
                     PathMap::arg(1, $path->action);
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                     FabriqStack::enqueue($path->controller, $path->action, 'module', $extra);
                     return true;
                 } else {
                     FabriqStack::error(404);
                 }
                 break;
             case 'page':
             default:
                 PathMap::arg(0, $path->controller);
                 PathMap::arg(1, $path->action);
                 FabriqStack::enqueue($path->controller, $path->action);
                 if ($path->extra != '') {
                     $extra = explode('/', $path->extra);
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         array_unshift($extra, $p[$path->wildcard]);
                     }
                     for ($i = 0; $i < count($extra); $i++) {
                         PathMap::arg($i + 2, $extra[$i]);
                     }
                 } else {
                     if ($path->wildcard) {
                         $p = explode('/', $_GET['q']);
                         PathMap::arg(2, $p[$path->wildcard]);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
 /**
  * Determines the path and enques what to render. This function
  * can be extended in the /app/PathMap.class.php file to add custom
  * functionality.
  */
 public static function map_path()
 {
     global $q;
     global $_FAPP;
     global $installed;
     $mapped = false;
     if ($installed && FabriqModules::enabled('pathmap')) {
         if (isset($_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_forcepwdreset']) && $_SESSION[Fabriq::siteTitle()]['FABMOD_USERS_forcepwdreset'] == 1) {
             if (!in_array('users', $q) && !in_array('changePassword', $q)) {
                 header('Location:' . call_user_func_array('BaseMapping::build_path', array_merge(array('users', 'changePassword'), $q)));
             }
         }
     }
     if (count($q) > 0) {
         if (trim($q[0]) != '' && (file_exists("app/controllers/{$q[0]}.controller.php") || file_exists('sites/' . FabriqStack::site() . "/app/controllers/{$q[0]}.controller.php"))) {
             $controller = $q[0];
             $mapped = true;
         }
         if (count($q) > 1) {
             if (!is_numeric($q[1])) {
                 $action = $q[1];
             } else {
                 $action = $_FAPP['adefault'];
             }
         } else {
             $action = $_FAPP['adefault'];
         }
         if ($mapped) {
             FabriqStack::enqueue($controller, $action);
         }
     }
     // try to map path with pathmap module if enabled and necessary
     if ($installed && FabriqModules::enabled('pathmap') && !$mapped) {
         $pathmap =& FabriqModules::module('pathmap');
         $mapped = $pathmap->redirect($_GET['q']);
     }
     // not installed, map to the install function
     if (!$installed) {
         PathMap::arg(0, 'fabriqinstall');
         PathMap::arg(1, 'install');
         FabriqStack::enqueue('fabriqinstall', 'install', 'module');
         $mapped = true;
     }
     // resolve controller and action if not already declared
     if (!$mapped) {
         if (count($q) == 0) {
             PathMap::arg(0, $_FAPP['cdefault']);
             PathMap::arg(1, $_FAPP['adefault']);
             FabriqStack::enqueue($_FAPP['cdefault'], $_FAPP['adefault']);
         } else {
             if ($q[0] != '' && !file_exists("app/controllers/{$q[0]}.controller.php") && !file_exists('sites/' . FabriqStack::site() . "/app/controllers/{$q[0]}.controller.php")) {
                 FabriqStack::error(404);
             }
         }
     }
 }