Example #1
0
 /**
  * Set the authentication rules for this application
  */
 public static function setAuthentication()
 {
     $application = Nomad_Application::getInstance(FALSE);
     $gatekeeper = $application->Nomad_GateKeeper;
     $gatekeeper->denyGlobally();
     $gatekeeper->addAllowGate("ErrorController", self::$_ALL_USERS);
     $gatekeeper->addAllowGates(array("DefaultController" => self::$_ALL_USERS, "DocumentationController" => self::$_ALL_USERS, "MoviesController" => self::$_ALL_USERS, "AdminController::listusersPage" => self::SITE_ADMINISTRATOR, "AdminController::indexPage" => self::$_ALL_USERS, "BoxesController::indexPage" => self::$_ALL_USERS, "ContainerController" => self::$_ALL_USERS, "TestingController" => self::$_ALL_USERS, "FunwithformsController" => self::$_ALL_USERS));
 }
Example #2
0
 /**
  * @param $name
  * @param $params
  */
 public function __construct($name, $params)
 {
     $this->_controller = strtolower(Nomad_Application::getInstance()->getRoute()->getRequest()->getController());
     $this->_page = strtolower(Nomad_Application::getInstance()->getRoute()->getRequest()->getPage());
     $this->_currentPage = '/' . $this->_controller . '/' . $this->_page;
     parent::__construct($name, 'nav', $params);
     $this->_addItems($this, $name, $params);
 }
Example #3
0
 /**
  * @param Nomad_View    $view
  * @param Nomad_Request $request
  */
 public function __construct(Nomad_View $view, Nomad_Request $request)
 {
     $this->request = $request;
     $this->view = $view;
     //Check permissions on the controller level (if Nomad_GateKeeper is present)
     $application = Nomad_Application::getInstance();
     if (isset($application->Nomad_GateKeeper)) {
         $controllerName = $request->getController() . 'Controller';
         $pageName = $request->getPage() . 'Page';
         if (!Nomad_GateKeeper::getNomad_GateKeeper()->checkPermissions($controllerName, $pageName)) {
             $application->halt(403);
         }
     }
 }
Example #4
0
<?php

/**
 * Bootstrap.php
 * Creates, sets up then runs the Nomad Application
 *
 * @author Mark Hillebert
 * @package The Nomad Project
 */
header('Content-Type: text/html; charset=utf-8');
$application = Nomad_Application::getInstance();
/** setup for Nomad_Session use */
//Nomad_Session::getInstance();
$application->registerPlugin('NomadTimer');
$application->registerPlugin('Nomad_GateKeeper');
/** Set up the authorization using a custom service (/services/authlist.php) */
authlist::setAuthentication();
/** Setup Main Navigation */
$application->view->mainNavigation = NavigationMenus::createMainNavigation();
/** Setup theme changing links */
$application->view->themeLinks = NavigationMenus::themeLinks();
$params = $application->getRoute()->getRequest()->getParams();
$currentTheme = Nomad_Session::getInstance()->currentTheme;
if (isset($currentTheme)) {
    $application->view->useTheme($currentTheme);
}
if (count($params) > 0) {
    Nomad_Session::getInstance()->currentTheme = ucfirst($params[0]);
    $application->view->useTheme(ucfirst($params[0]));
}
$application->run();
Example #5
0
 /**
  * provides access to the application as a singleton pattern
  */
 public static function getInstance()
 {
     if (is_null(self::$_application)) {
         $c = __CLASS__;
         self::$_application = new $c();
     }
     return self::$_application;
 }
 /**
  * Theme switching links
  * @return Nomad_Navigation
  */
 public static function themeLinks()
 {
     $routedUrl = Nomad_Application::getInstance()->getRoute()->getCurrentUrlRoute();
     $theme = new Nomad_Navigation('theme_links', array('children' => array(['href' => DS . $routedUrl . DS . 'gypsy', 'label' => 'Default'], ['href' => DS . $routedUrl . DS . 'pinkypie', 'label' => 'Pinky Pie']), 'attributes' => array('class' => 'column sixteen'), 'innerText' => '(Url Parameter Demo) Change Themes: '));
     return $theme;
 }
Example #7
0
 /**
  * Redirects to a new internal controller/page.
  *
  * NOTE: THIS DOES NOT BREAK THE FLOW!
  *
  * @param array|string $locationArray ["controllerName", "pageName"] | "ControllerName"
  * @param bool $breakFlow
  * @throws Nomad_RedirectBreak_Exception
  */
 public function redirect($locationArray, $breakFlow = TRUE)
 {
     if (is_array($locationArray)) {
         $controllerName = $locationArray[0] . 'Controller';
         $pageName = isset($locationArray[1]) ? $locationArray[1] : "index";
     } else {
         $controllerName = $locationArray;
         $pageName = 'index';
     }
     $app = Nomad_Application::getInstance();
     $route = $app->getRoute();
     $request = $route->getRequest();
     $request->setController($controllerName);
     $request->setPage($pageName);
     $this->_controllerName = $route->getControllerMethodName();
     $this->_pageName = $route->getPage();
     $this->_controllerPath = strtolower($route->getController());
     // get any view variables set and pass them to the new view
     $oldViewVars = get_object_vars($app->view);
     $page = $route->getPage();
     $viewPath = APPLICATION_ROOT . DS . 'application' . DS . 'views' . DS . strtolower($route->getController()) . DS . $page . ".phtml";
     $app->view = new Nomad_View($viewPath);
     $app->view->setTitle(ucfirst($page));
     //re-apply the old variables back to the new view.
     foreach ($oldViewVars as $key => $value) {
         $app->view->{$key} = $value;
     }
     $this->setRedirectStatus(TRUE);
     $this->setBreakFlowStatus($breakFlow);
     if ($this->getBreakFlowStatus()) {
         /**
          * Break the flow if redirectBreak is set to true (default).
          * This exception should be caught only to stop the flow, and not acted on.
          */
         throw new Nomad_RedirectBreak_Exception();
     }
 }
Example #8
0
 /**
  * @param $class
  * @param null $function
  * @throws Nomad_Exception
  * @return bool
  */
 public function checkPermissions($class = NULL, $function = NULL)
 {
     if (isset($class)) {
         /**  if class is set then method MUST be set also.*/
         if (!isset($function)) {
             throw new Nomad_Exception("Nomad_GateKeeper needs both the class and the method passed, or neither.");
         }
     }
     /**NOT GONNA DOT THIS DIRTY HACK TO GET THE CALLING FUNCTION (although it works)**/
     //else{
     //    $calling = debug_backtrace(NULL,2);
     //    $method = $calling[1]['function'];
     //    $class = $calling[1]['class'];
     //}
     $currentRole = $this->getRole();
     if (isset($this->_resourcesTree[$class])) {
         if (array_key_exists($function, $this->_resourcesTree[$class])) {
             //individual functions were assigned permissions
             if ($this->_hasIntersection($currentRole, $this->_resourcesTree[$class][$function])) {
                 return TRUE;
             }
         } else {
             if ($this->_is_assoc($this->_resourcesTree[$class])) {
                 /**
                  * The Page/Function was not found in the resources tree, although other Page(s)/Function(s) were set.
                  * Return the default allow/deny
                  */
                 return $this->_allowed;
             }
             //entire class was assigned permissions
             if ($this->_hasIntersection($currentRole, $this->_resourcesTree[$class])) {
                 return TRUE;
             }
         }
     }
     if (!$this->_allowed) {
         Nomad_Application::getInstance()->halt(403);
     }
     return $this->_allowed;
 }
 public function indexPage()
 {
     Nomad_Application::getInstance()->halt(404);
 }