get($object_type, $object_source, $object_division, $object_id, $meta_key, $meta_value); // don't populate unless individual rec if ($rec && count($rec) == 1) $this->populate($rec); else{ unset($rec); $rec->object_type = $object_type; $rec->object_source = $object_source; $rec->object_division = $object_division; $rec->object_id = $object_id; $rec->meta_key = $meta_key; $rec->meta_value = maybe_unserialize($meta_value); $this->populate($rec); } } function populate($rec){ $this->meta_id = $rec->meta_id; $this->object_type = $rec->object_type; $this->object_source = $rec->object_source; $this->object_division = $rec->object_division; $this->object_id = $rec->object_id; $this->meta_key = $rec->meta_key; $this->meta_value = maybe_unserialize($rec->meta_value); } // you have to populate the rec completely, including meta_value to get a specific rec function get($object_type = '', $object_source = '', $object_division, $object_id = '', $meta_key = '', $meta_value = ''){ global $bp, $wpdb; if (!$object_type){ $object_type = $this->object_type; $object_source = $this->object_source; $object_division = $this->object_division; $object_id = $this->object_id; $meta_key = $this->meta_key; $meta_value = maybe_serialize($this->meta_value); } $sql = $wpdb->prepare("SELECT * FROM {$bp->contents->meta->table_name} WHERE object_type = %s", $object_type); if ($object_source) $select_source = $wpdb->prepare(" AND object_source = %s", $object_source); if ($object_division) $select_division = $wpdb->prepare(" AND object_division = %s", $object_division); if ($object_id) $select_id = $wpdb->prepare(" AND object_id = %s", $object_id); if ($meta_key) $select_key = $wpdb->prepare(" AND meta_key = %s", $meta_key); if ($meta_value) $select_value = $wpdb->prepare(" AND meta_value = %s", $meta_value); $sql .= $select_source . $select_division . $select_id . $select_key . $select_value; $result = $wpdb->get_results($sql); if (empty($result)) return false; return $result; } function save(){ global $wpdb, $bp; if ($this->meta_id){ $sql = $wpdb->prepare( "UPDATE {$bp->contents->meta->table_name} SET object_type = %s, object_source = %s, object_division = %s, object_id = %s, meta_key = %s, meta_value = %s WHERE meta_id = %d", $this->object_type, $this->object_source, $this->object_division, $this->object_id, $this->meta_key, maybe_serialize($this->meta_value), $this->meta_id); } else{ $sql = $wpdb->prepare("INSERT INTO {$bp->contents->meta->table_name} ( object_type, object_source, object_division, object_id, meta_key, meta_value ) VALUES ( %s, %s, %s, %s, %s, %s )", $this->object_type, $this->object_source, $this->object_division, $this->object_id, $this->meta_key, maybe_serialize($this->meta_value)); } if ( false === $wpdb->query($sql) ) return false; if ( !$this->meta_id ) $this->meta_id = $wpdb->insert_id; return true; } function delete($id = ''){ global $wpdb, $bp; if (!$id) $id = $this->meta_id; $sql = $wpdb->prepare("DELETE FROM {$bp->contents->meta->table_name} WHERE meta_id = %d", $id); return $wpdb->query($sql); } } // OCI_Meta class OCI_Taxonomy_Meta extends OCI_Meta{ function oci_taxonomy_meta($taxonomy, $term_id, $item_id, $property, $value = ''){ $this->object_type = OCI_TAXONOMY_TERM; $this->object_source = $taxonomy; $this->object_division = $term; $this->object_id = $object; $this->meta_key = $property; $this->meta_value = $value; } } // OCI_Taxonomy ?>