From 39065cc82c617b0fb35c6e05c9f8fbade512f203 Mon Sep 17 00:00:00 2001 From: icewing Date: Wed, 5 Mar 2008 14:42:35 +0000 Subject: Types forced on $object->value git-svn-id: https://code.elgg.org/elgg/trunk@77 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'engine/lib/annotations.php') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 1a559b872..d1cf9905f 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -25,14 +25,19 @@ private $attributes; /** - * Construct a new site object, optionally from a given id value. + * Construct a new site object, optionally from a given id value or db row. * - * @param int $id + * @param mixed $id */ function __construct($id = null) { if (!empty($id)) { - if ($annotation = get_annotation($id)) { + if ($id instanceof stdClass) + $annotation = $id; + else + $annotation = get_annotation($id); + + if ($annotation) { $objarray = (array) $annotation; foreach($objarray as $key => $value) { $this->attributes[$key] = $value; @@ -43,6 +48,21 @@ function __get($name) { if (isset($attributes[$name])) { + + // Sanitise outputs if required + if ($name=='value') + { + switch ($attributes['value_type']) + { + case 'integer' : return (int)$attributes['value']; + case 'tag' : + case 'text' : + case 'file' : return sanitise_string($attributes['value']); + + default : throw new InstallationException("Type {$attributes['value_type']} is not supported. This indicates an error in your installation, most likely caused by an incomplete upgrade."); + } + } + return $attributes[$name]; } return null; -- cgit v1.2.3