Beispiel #1
0
 public static function Factory($default_page = null, $requireLogin = true)
 {
     $prefs = UserPreferences::Instance(EGS_USERNAME);
     $default_page = $prefs->getPreferenceValue('default_page', 'shared');
     if ($default_page == null) {
         $ao = AccessObject::Instance();
         $default_page = 'module,' . $ao->getDefaultModule();
     }
     if (get_config('SETUP')) {
         if (defined('MODULE')) {
             $default_page = MODULE;
         }
     }
     $router = RouteParser::Instance();
     $modules = array();
     if (!$requireLogin || isLoggedIn()) {
         foreach ($router->getDispatch() as $key => $dispatch) {
             if (($key == 'group' || $key == 'module' || strstr($key, 'submodule')) && !empty($dispatch)) {
                 $modules[$key] = $dispatch;
             }
         }
         if (empty($modules)) {
             // Default page contains permission type and permission name
             // i.e. type is group or module
             $array = explode(',', $default_page);
             $modules[$array[0]] = $array[1];
         }
     } else {
         $modules['module'] = 'login';
     }
     $al =& AutoLoader::Instance();
     return $modules;
 }
Beispiel #2
0
 public function __construct()
 {
     $routes = RouteParser::getRoutes();
     $this->command = null;
     $uri = rtrim($_SERVER['REQUEST_URI'], '/');
     for ($i = 0; $i < sizeof($routes) && $this->command == null; $i++) {
         $this->command = $routes[$i]->tryMatch($uri);
     }
 }
Beispiel #3
0
 /**
  * Use environment information to determine the Controller to be used for execution
  */
 public static function Factory($controller)
 {
     $router = RouteParser::Instance();
     $_action = $router->Dispatch('action');
     if (!empty($_action) && $_action !== null) {
         if ($_action == 'new') {
             $action = '_new';
         } else {
             $action = $_action;
         }
         return $action;
     }
     return 'index';
 }
Beispiel #4
0
 /**
  * Uses global information ($_GET probably) to determine the Controller to instantiate and return
  * @return string	A (probably) extended form of the Controller class
  **/
 public static function Factory($requireLogin = true, $modulecomponents)
 {
     $router = RouteParser::Instance();
     if ($router->Dispatch('controller') !== null) {
         $classname = ucfirst(strtolower($router->Dispatch('controller'))) . 'Controller';
         if (is_array($modulecomponents)) {
             if (isset($modulecomponents[strtolower($classname)])) {
                 $controller = $classname;
                 return $controller;
             }
         } elseif (class_exists($classname)) {
             $controller = $classname;
             return $controller;
         }
     }
     if (defined('CONTROLLER')) {
         $controller = CONTROLLER;
     } else {
         $controller = 'IndexController';
     }
     return $controller;
 }
 /**
  * @test
  * @dataProvider parseData
  * @param string $input
  * @param Route $expected
  */
 public function parsesRoute($input, Route $expected)
 {
     $this->assertEquals($expected, RouteParser::parse($input));
 }
Beispiel #6
0
function isModuleAdmin($name = null)
{
    return true;
    $router = RouteParser::Instance();
    if (isset($name)) {
        $module = $name;
    } else {
        $module = $router->dispatch('module');
    }
    if (isset($_SESSION['module_admins'])) {
        $cache = $_SESSION['module_admins'];
    } else {
        $cache = array();
    }
    if (!isset($cache[$module])) {
        $access = AccessObject::Instance();
        $db = DB::Instance();
        $roles_string = implode(',', $access->roles);
        //		foreach ($access->roles as $role) {
        //			$roles_string.=$role.',';
        //		}
        //		$roles_string=rtrim($roles_string,',');
        $query = 'SELECT module_name FROM module_admins WHERE role_id IN (' . $roles_string . ') AND module_name=' . $db->qstr($module);
        debug('lib::isModuleAdmin ' . $query);
        $module = $db->GetOne($query);
        if (!empty($module) && $module !== FALSE) {
            $cache[$module] = TRUE;
        } else {
            foreach ($access->tree as $treenode) {
                if ($treenode['name'] == 'egs') {
                    $cache[$module] = TRUE;
                }
            }
            $cache[$module] = FALSE;
        }
    }
    $_SESSION['module_admins'][$module] = $cache[$module];
    return $cache[$module];
}
Beispiel #7
0
 /**
  * Adds a route to the collection.
  *
  * @param string $httpMethod
  * @param string $uri
  * @param mixed  $handler
  * @param string $name
  */
 public function addRoute($httpMethod, $uri, $handler, $name)
 {
     $routeData = $this->parser->parse($uri);
     $this->generator->addRoute($httpMethod, $routeData, $uri, $handler, $name);
 }
Beispiel #8
0
 public function setView()
 {
     $this->router = RouteParser::Instance();
     $this->router->ParseRoute(isset($_GET['url']) ? $_GET['url'] : '');
     if (!isset($this->login_required)) {
         $this->login_required = FALSE;
     }
     $this->modules = ModuleFactory::Factory(null, $this->login_required);
     $this->pid = $this->router->Dispatch('pid');
     $this->view = new View();
     $this->setContext();
     $this->view->set('help_link', $this->access->setHelpContext($this->pid));
     $this->view->set('modules', $this->modules);
     if (count($this->modules) > 0) {
         $modtype = 'module';
         foreach ($this->modules as $module) {
             $this->view->set($modtype, strtolower($module));
             $modtype = 'sub' . $modtype;
         }
     }
     if (isset($_GET['ajax'])) {
         $this->ajax = TRUE;
     }
     if (isset($_GET['json'])) {
         $this->json = TRUE;
     }
     // echo 'system::setView modules=<pre>'.print_r($this->modules,TRUE).'</pre><br>';
 }