diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-06 11:41:42 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-06 11:41:42 +0000 |
commit | 58ee726ca707c67ad3b821c148ca6f82f79ac176 (patch) | |
tree | 17838606f154727ca53975163348229c47f77265 | |
parent | b99ecb331413aa8bc26f53f901a8791a7a8ee4c1 (diff) | |
download | elgg-58ee726ca707c67ad3b821c148ca6f82f79ac176.tar.gz elgg-58ee726ca707c67ad3b821c148ca6f82f79ac176.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* 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
-rw-r--r-- | engine/lib/annotations.php | 27 |
1 files changed, 25 insertions, 2 deletions
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 @@ -167,6 +167,27 @@ } /** + * 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. * * @param int $object_id @@ -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; |