Exemplo n.º 1
0
  public static function dispatch() {
    
    // check that we're inside MasterPress (this also prevents MasterPress ajax from the normal dispatch too)
    
    if (isset($_REQUEST["page"]) && substr($_REQUEST["page"], 0, 11) == "masterpress") {
      // dispatch the menu to the correct controller / action

      // infer the controller, falling back to masterplan if the page is blank (shouldn't happen)
    
      if ($_REQUEST["page"] == "masterpress") {
        MasterPress::$controller_key = "masterplan";
      } else {
        MasterPress::$controller_key = str_replace("masterpress-", "", $_REQUEST["page"]); 
      }
    
      // include the controller
      MPC::incl(MasterPress::$controller_key);
    
      // infer the controller class, by converting to Title Case, and prefixing with "MPC_"
      $controller_class = MasterPress::controller_class(MasterPress::$controller_key);

      MasterPress::$controller = new $controller_class();

      MasterPress::$suffix = "-".MasterPress::$controller_key;

      MasterPress::$view = new stdClass();
       
      MasterPress::$action = "";
      
      if (isset($_GET['action'])) {
        MasterPress::$action = $_GET['action'];
      }
    
      if (MasterPress::$action == "") {
        MasterPress::$action = "manage";
      }
      
      if (isset($_REQUEST["parent"])) {
        MasterPress::$parent = $_REQUEST["parent"];
      }

      if (isset($_REQUEST["gparent"])) {
        MasterPress::$gparent = $_REQUEST["gparent"];
      }
    
      if (isset($_REQUEST["id"])) {
        MasterPress::$id = $_REQUEST["id"];
      }
      
      if (isset($_REQUEST["from"])) {
        MasterPress::$from = $_REQUEST["from"];
      }
    
      if (MasterPress::$action != "manage") { // no need for nonce checks on the manage (menu) pages
        $nonce = $_REQUEST['_wpnonce'];
        
        if ( !wp_verify_nonce($nonce, MasterPress::$action) ) { 
          // if nonce verification fails, simply go back to "manage", which is a non-destructive action
          MasterPress::$action = "manage";
        } 
      }

      
      $method = str_replace("-", "_", MasterPress::$action);
      
      if (method_exists(MasterPress::$controller, $method)) {
        MasterPress::$controller->$method();
      }

      
      
      
    }
    
  }