Ejemplo n.º 1
0
  public static function get_version() {
    
    global $wpdb;
    
    if (isset($_GET["id"])) {
      
      $id = $_GET["id"];
      $version = $wpdb->get_row("SELECT * FROM `".MPU::site_table("versions")."` WHERE `version_id` = $id");
      
      if ($version) {
        
        $ret = array("value" => MPU::db_decode($version->value));
        
        if (isset($_GET["fetch_template"], $_GET["model_id"])) {

          $set = MPM_FieldSet::find_by_id($_GET["model_id"]);
          
          if ($set) {
            $template = MPV_Meta::get_preview_set_template($set);
            
            $ret["template"] = $template;
          }
          
          
        }
        
        self::ajax_success( $ret );
        
      } else {
        self::ajax_error(__("The version could not be found", MASTERPRESS_DOMAIN));
      }
      
    } else {
      
      self::ajax_error(__("Cannot fetch version. No version id was supplied", MASTERPRESS_DOMAIN));
      
    }
    
  }
Ejemplo n.º 2
0
  public function load_prop($name, $value, $field) {

    if ($type_class = MPFT::type_class($field->type)) {
      return MPU::db_decode( call_user_func_array( array($type_class, "prop_from_load"), array($name, $value, $field)) );
    }
  
    return MPU::db_decode($value);
  }
Ejemplo n.º 3
0
  public function reassign_posts($new_post_type_name, $field_sets_action = "keep") {
    global $wpdb;
    
    $post_type_name = $this->name;
    
    
    if ($new_post_type_name) {

      // get the list of post ids for the existing type, which we'll need for later
      $post_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->posts WHERE post_type = '$post_type_name'");

      // update the posts
      $wpdb->query("UPDATE $wpdb->posts SET post_type = '$new_post_type_name' WHERE post_type = '$post_type_name'");
      
      if ($field_sets_action == "keep") {
        
        // update the link tables for this post type
        
        // need to check if there are any clashes for field sets named the same thing

        $sql = "SELECT id, name, visibility FROM ".MPU::table("field-sets")." WHERE type = 'p' AND ".MPM::visibility_rlike("post_types", $this->name);
        
        $post_type_sets = $wpdb->get_results($sql);
          
          
        $sql = "SELECT id, name, visibility FROM ".MPU::table("field-sets")." WHERE type = 'p' AND ".MPM::visibility_rlike("post_types", $this->name);
        
        $new_post_type_sets = $wpdb->get_results($sql);
        
        $clashes = array();
        
        foreach ($post_type_sets as $post_type_set) {
          foreach ($new_post_type_sets as $new_post_type_set) {
            if ($post_type_set->name == $new_post_type_set->name) {
              
              // a set with this name already exists, so we'll rename this one to "_2"
              
              $sql = "UPDATE ".MPU::table("field-sets")." SET name = CONCAT(name, '_2'), singular_name = CONCAT(singular_name, '_2') WHERE id = ".$post_type_set->id;
              
              $wpdb->query($sql);
              
              // now we need to update the meta keys for any meta values that were bound to this set
               
              // now get the fields inside this clashing set
              
              $field_ids = $wpdb->get_col("SELECT id FROM ".MPU::table("fields")." WHERE field_set_id = ".$post_type_set->id);
    
              if (count($field_ids)) {
      
                // get a list of meta values bound to the fields in this clashing set.
    
                $sql = "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE '%:field_id' AND meta_value IN (".implode(",", $field_ids).")";
                $rows = $wpdb->get_results($sql); 
                
                // this will need some serious testing!

                foreach ($rows as $row) {
                  list($set_name, $field_name, $prop_name) = MPFT::parse_meta_key($row->meta_key);
                  $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = REPLACE(meta_key, '".$set_name."', '".$set_name."_2') WHERE post_id = ".$row->post_id." AND ( meta_key = '".MPFT::meta_key($set_name, $field_name)."' OR meta_key LIKE '".MPFT::meta_key($set_name, $field_name).":%' ) ");
                }
      
                
              }
              
            }
          }
          
        }
        
        foreach ($post_type_sets as $set) {
          $visibility = MPU::db_decode($set->visibility);
          $visibility["post_types"] = $new_post_type_name;
          $sql = "UPDATE ".MPU::table("field-sets")." SET visibility = '".MPU::db_encode($visibility)."' WHERE id = ".$set->id;
          $wpdb->query($sql);
        }
          
      
        
        
      } else { 
        $this->delete_field_sets();
      }
      
      
    }

  }
Ejemplo n.º 4
0
 protected function data_from_row($row) {
   $data = array();
   
   foreach ($row as $key => $val) {
     $data[$key] = MPU::db_decode($val);
   }
   
   return $data;
 }