From be6535c536471feae1c16299d3d8121c9feabd5b Mon Sep 17 00:00:00 2001 From: icewing Date: Tue, 11 Mar 2008 11:08:39 +0000 Subject: Marcus Povey * Added metadata/metastrings tag stuff. Lorks. git-svn-id: https://code.elgg.org/elgg/trunk@151 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 10 ++++++++++ engine/lib/metadata.php | 14 ++++++++++++-- engine/lib/metastrings.php | 34 ++++++++++++++++++++++++++++++++++ engine/schema/mysql.sql | 2 +- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 engine/lib/metastrings.php diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 3a950568f..3ff8c0e69 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -240,6 +240,11 @@ $time = time(); + // Add the metastring + $value = add_metastring($value); + if (!$value) return false; + + // If ok then add it return insert_data("INSERT into {$CONFIG->dbprefix}annotations (object_id, object_type, name, value, value_type, owner_id, created, access_id) VALUES ($object_id,'$object_type','$name','$value','$value_type', $owner_id, $time, $access_id)"); } @@ -269,6 +274,11 @@ $access = get_access_list(); + // Add the metastring + $value = add_metastring($value); + if (!$value) return false; + + // If ok then add it return update_data("UPDATE {$CONFIG->dbprefix}annotations set value='$value', value_type='$value_type', access_id=$access_id, owner_id=$owner_id where id=$annotation_id and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))"); } diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 56bb83990..105001535 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -136,8 +136,7 @@ return 'tag'; } - - + /** * Create a new metadata object, or update an existing one. * @@ -177,6 +176,11 @@ } else { + // Add the metastring + $value = add_metastring($value); + if (!$value) return false; + + // If ok then add it $id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (object_id, object_type, name, value, value_type, owner_id, created, access_id) VALUES ($object_id,'$object_type','$name','$value','$value_type', $owner_id, $time, $access_id)"); } @@ -209,6 +213,12 @@ $access = get_access_list(); + + // Add the metastring + $value = add_metastring($value); + if (!$value) return false; + + // If ok then add it return update_data("UPDATE {$CONFIG->dbprefix}metadata set value='$value', value_type='$value_type', access_id=$access_id, owner_id=$owner_id where id=$id and name='$name' and (access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))"); } diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php new file mode 100644 index 000000000..17c9a751b --- /dev/null +++ b/engine/lib/metastrings.php @@ -0,0 +1,34 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + + /** + * Add a metastring. + * It returns the id of the tag, whether by creating it or updating it. + * + * @param string $tag The value (whatever that is) to be stored + * @return mixed Integer tag or false. + */ + function add_metastring($tag) + { + global $CONFIG; + + $tag = sanitise_string($tag); + + $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where tag='$tag' limit 1"); + if ($row) + return $row->id; + + return insert_data("INSERT into {$CONFIG->dbprefix}metastrings (tag) values ('$tag')"); + } +?> \ No newline at end of file diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index af910dc6d..ce3778d71 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -230,7 +230,7 @@ CREATE TABLE `prefix_metadata` ( -- CREATE TABLE `prefix_metastrings` ( `id` int(11) NOT NULL auto_increment, - `tag` text NOT NULL, + `tag` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY (`tag`) -- cgit v1.2.3