示例#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();
      }

      
      
      
    }
    
  }
示例#2
0
  public function submit() {
    
    global $wpdb;
    
    $action = MasterPress::$action;
    
    if ($action == "create" || $action == "edit") {
      
      $field_set = new $this->model_class();
      // consume the post data
      
      $field_set->name = $_POST["name"];
      $field_set->singular_name = $_POST["singular_name"];
      $field_set->disabled = isset($_POST["disabled"]);
      $field_set->labels = $_POST["labels"];
      $field_set->visibility = MPC::post_val("visibility");
      $field_set->capabilities = self::handle_capabilities();
      $field_set->allow_multiple = isset($_POST["allow_multiple"]);
      $field_set->type = $this->db_type;
      $field_set->position = $_POST["position"];
      $field_set->icon = self::handle_icon("icon", "icon_select");
      $field_set->expanded = isset($_POST["expanded"]);
      $field_set->sidebar = isset($_POST["sidebar"]);
      $field_set->versions = $_POST["versions"];
      $field_set->visibility = $this->get_visibility_val();

      if ($action == "create") {
        $field_set->insert();
      } else if ($action == "edit") {
        $field_set->update(MasterPress::$id);
      }

      if ($field_set->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]);
        }

        // update other menu positions
        
        $op = MPC::post_val("other_position");
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }
        
        
      }        
      
      return $field_set;
      
    } else if ($action == "delete") { 

      $fg = MasterPress::$view->parent = call_user_func_array( array($this->model_class, "find_by_id"), array(MasterPress::$id));

      if ($fg) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $fg->delete_meta();
        }

      }
      
      $fg->delete();
      
      return true;

    } else if ($action == "delete-field") {

      $f = MPM_Field::find_by_id(MasterPress::$id);
      
      if ($f) {

        $field_data_action = $_POST["field_data"];
        
        if ($field_data_action == "delete") {
          $f->delete_meta();
        }

      }
      
      $f->delete();
      
      return true;
      
    } else if ($action == "create-field" || $action == "edit-field") {
      
      // FIELD OPERATIONS (NOT FIELD GROUPS!)
       
      $field = new MPM_Field();
      // consume the post data
      
      $field->field_set_id = $_POST["parent"];
      $field->name = $_POST["name"];
      $field->disabled = isset($_POST["disabled"]);
      $field->summary_options = $_POST["summary_options"];
      $field->required = isset($_POST["required"]);
      $field->labels = $_POST["labels"];
      $field->type = $_POST["type"]; 
      $field->icon = self::handle_icon("icon", "icon_select");
      $field->type_options = $_POST["type_options"];
      $field->position = $_POST["position"];
      $field->visibility = $this->get_visibility_val();
      $field->capabilities = self::handle_capabilities();

      if (MPC::is_create()) {
        $field->insert();
      } else if (MPC::is_edit()) {
        $field->update(MasterPress::$id);
      }

      if ($field->is_valid()) {

        if (MPC::is_edit()) {
          global $meow_provider;
          $meow_provider->migrate_field_meta($field, $_POST["name_original"]);
        }
        
        // update other menu positions
        
        $op = MPC::post_val("other_position");
        
        if (isset($op) && is_array($op)) {
          foreach ($op as $id => $position) {
            $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); 
          }
          
        }

        // clear the parent for the redirect
      
        MasterPress::$parent = null;

        
      }    
      
      
      return $field;
    } 
    
    
  }