From 58ee726ca707c67ad3b821c148ca6f82f79ac176 Mon Sep 17 00:00:00 2001 From: icewing Date: Thu, 6 Mar 2008 11:41:42 +0000 Subject: Marcus Povey * Very crude type detection for annotation tags, defaults to 'tag' git-svn-id: https://code.elgg.org/elgg/trunk@91 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'engine') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 130cf12a2..d728dfa9a 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -166,6 +166,27 @@ return get_data($query); } + /** + * Detect the value_type for a given value. + * Currently this is very crude. + * + * TODO: Make better! + * + * @param mixed $value + * @param string $value_type If specified, overrides the detection. + * @return string + */ + function detect_annotation_valuetype($value, $value_type = "") + { + if ($value_type!="") + return $value_type; + + // This is crude + if (is_int($value)) return 'integer'; + + return 'tag'; + } + /** * Create a new annotation. * @@ -185,10 +206,12 @@ $object_type = sanitise_string(trim($object_type)); $name = sanitise_string(trim($name)); $value = sanitise_string(trim($value)); - $value_type = sanitise_string(trim($value_type)); + $value_type = detect_annotation_valuetype($value, sanitise_string(trim($value_type))); $owner_id = (int)$owner_id; $access_id = (int)$access_id; + + 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, $access_id)"); } @@ -209,7 +232,7 @@ $annotation_id = (int)$annotation_id; $name = sanitise_string(trim($name)); $value = sanitise_string(trim($value)); - $value_type = sanitise_string(trim($value_type)); + $value_type = detect_annotation_valuetype($value, sanitise_string(trim($value_type))); $owner_id = (int)$owner_id; $access_id = (int)$access_id; -- cgit v1.2.3