aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/annotations.php27
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;