Ejemplo n.º 1
0
 function versions() {
   
   global $wpdb, $meow_provider;
   
   $versions = array();
   
   if ($this->object) {
     $sql = "SELECT v.*, u.* FROM `".MPU::site_table("versions")."` v LEFT OUTER JOIN $wpdb->users u ON u.ID = v.user_id WHERE v.object_id = ".$this->object->id()." AND v.field_set_name = '".$this->name."' AND v.object_type = '".$meow_provider->type_key($this->object)."' ORDER BY version_id DESC";
     $versions = $wpdb->get_results($sql);
   }
   
   return $versions;
 }
Ejemplo n.º 2
0
	public function legacy_dir_migrate() {
		
		global $wpdb, $wf, $blog_id;
			
		$ud = wp_upload_dir(); 

		$affected_rows = 0;
		
		$tables = array( $wpdb->postmeta, $wpdb->usermeta, MPU::site_table("termmeta"));
		
		if (MASTERPRESS_MULTI) {

			foreach ($tables as $table) {
				// hard-code blogs.dir here, as it's the only setup that was supported anyway (any others would have failed with masterpress 1.0)
				$sql = "UPDATE $table SET meta_value = REPLACE(meta_value, '/blogs.dir/$blog_id/mp/uploads/', '/blogs.dir/$blog_id/mp/files/' ) WHERE meta_value LIKE '%/blogs.dir/$blog_id/mp/uploads/%' ";

				$affected_rows += $wpdb->query( $sql );
			
				// there's no need to update the /sites/files type URLs, as no install could have ever had these working
			}

			if (is_main_site()) {
				foreach ($tables as $table) { 
					$sql = "UPDATE $table SET meta_value = REPLACE(meta_value, '" . WP_CONTENT_URL . "/mp/uploads', '" . $ud["baseurl"] . "/mp/files" . "' ) WHERE meta_value LIKE '%/mp/uploads/%' ";
					$affected_rows += $wpdb->query( $sql );
				}
			}
			
		
		} else {
			
			foreach ($tables as $table) { 
				$sql = "UPDATE $table SET meta_value = REPLACE(meta_value, '" . WP_CONTENT_URL . "/mp/uploads', '" . $ud["baseurl"] . "/mp/files" . "' ) WHERE meta_value LIKE '%/mp/uploads/%' ";
				$affected_rows += $wpdb->query( $sql );
			}

		}
		

		update_option("mp_legacy_dir", "0");
		
		MPV::success( sprintf( __("%d database records were migrated to the new content path", MASTERPRESS_DOMAIN), $affected_rows ) );
		
		$this->manage();

	}
Ejemplo n.º 3
0
  public static function add_term_meta($term_id, $meta_key, $meta_value, $taxonomy = NULL) {
    global $wpdb, $wf;
    
    $taxonomy = self::infer_taxonomy_name($taxonomy);
    
    $result = $wpdb->insert( 
      MPU::site_table("termmeta"), 
      array(
        "term_id" => $term_id,
        "meta_key" => $meta_key,
        "meta_value" => $meta_value,
        "taxonomy" => $taxonomy
      ),
      array("%d", "%s", "%s", "%s")
    );
    
    if ($result) {
      return $wpdb->insert_id;
    }
    
    return false;

  }
Ejemplo n.º 4
0
  public function create_version($object_id, $object_type, $object_type_meta = "", $dirty = array(), $versions_count = array()) {
    
    global $wf, $wpdb, $current_user;
    
    $initial = !is_array($dirty) && $dirty == "initial";
    
    if ($object_type == "post") {
      $object = $wf->post($object_id);
    } else if ($object_type == "term") {
      $object = $wf->term_by_id($object_id, $object_type_meta);
    } else if ($object_type == "user") {
      $object = $wf->user($object_id);
    } else if ($object_type == "site") {
      $object = $wf->site($object_id);
    }
    
    if (isset($object) && !is_woof_silent($object)) {
      
      $sets_to_record = array();

      $sets = array();
      
      foreach ($versions_count as $set => $count) {
        
        if ($count != 0) {

          // don't record if version recording is off (zero value)
        
          $sql = "SELECT * FROM ".MPU::site_table('versions')." WHERE object_id = $object_id AND object_type = '$object_type' "; 
        
          if ($object_type_meta != "") {
            $sql .= " AND object_type_meta = '$object_type_meta' ";
          }

          $sql .= " AND field_set_name = '".$set."'";

          $vr = $wpdb->get_results($sql);

          $record = false;
          
          if ($initial) {
            if (count($vr) == 0) {
              $record = true;
            }
          }
          
          if (is_array($dirty) && isset($dirty[$set])) {
            $record = true;
          }
          
          if ($record) {
            $sets_to_record[$set] = count($vr) - $count; // store the number of versions to delete (the -1 is because we ALSO store the current version)
          }
        
          
        }
        
      }
      
      
      if (!count($sets_to_record)) {
        return array(); // no need to do anything
      }
      
      $data = $this->get_meta($object);
      
      
      foreach ($data as $set => $fields) {
              
        if (isset($sets_to_record[$set])) {
        
          $json = json_encode($fields);

          if (! ( $initial && $json && $json == "[]" ) ) {
            
            $wpdb->insert( MPU::site_table("versions"), array(
                "date" => date("Y-m-d H:i:s"),
                "user_id" => $wf->the_user()->id,
                "object_id" => $object_id,
                "object_type" => $object_type,
                "object_type_meta" => $object_type_meta,
                "field_set_count" => count($fields),
                "field_set_name" => $set,
                "value" => "json:".$json
              )
            );
          
          
            if ($sets_to_record[$set] > 0) {
              // delete older versions of the content
            
              $sql = "SELECT version_id FROM ".MPU::site_table('versions')." WHERE object_id = $object_id AND object_type = '$object_type' "; 
              if ($object_type_meta != "") {
                $sql .= " AND object_type_meta = '$object_type_meta' ";
              }
              $sql .= " AND field_set_name = '".$set."' ORDER BY version_id LIMIT ".$sets_to_record[$set];
          
              $versions_to_delete = $wpdb->get_col($sql);
            
              if (count($versions_to_delete)) {
                $wpdb->query("DELETE FROM ".MPU::site_table('versions')." WHERE version_id IN (".implode(",", $versions_to_delete).")");
              }
            }
          
          }
        
        
        }

      
      }
      
      $this->uncache_data();
      
      return true;
      
    }
    
  }
Ejemplo n.º 5
0
 public function delete_meta() {
   global $wpdb;
   $wpdb->query("DELETE FROM ".MPU::site_table("termmeta")." WHERE `taxonomy` = '".$this->name."'");
 }