From 01693c67dbb7ed686b6fa03faba875eb11fea160 Mon Sep 17 00:00:00 2001 From: icewing Date: Thu, 1 May 2008 12:12:59 +0000 Subject: Marcus Povey * Fixed regression on custom class loader git-svn-id: https://code.elgg.org/elgg/trunk@590 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 2 +- engine/lib/entities.php | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/engine/lib/database.php b/engine/lib/database.php index 0979592c0..0f4bc89b9 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -355,7 +355,7 @@ * @param string $string The string to sanitise * @return string Sanitised string */ - function sanitise_string($string) { + function sanitise_string($string) {return $string; return mysql_real_escape_string(trim($string)); } diff --git a/engine/lib/entities.php b/engine/lib/entities.php index c62eb8ea7..a4df6fa02 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -595,7 +595,7 @@ * * TODO: Move to a nicer place? * - * @param string $subtype_id + * @param int $subtype_id */ function get_subtype_from_id($subtype_id) { @@ -631,6 +631,25 @@ return NULL; } + /** + * This function tests to see if a subtype has a registered class handler by its id. + * + * @param int $subtype_id The subtype + * @return a class name or null + */ + function get_subtype_class_from_id($subtype_id) + { + global $CONFIG; + + $subtype = (int)$subtype_id; + + $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id"); + if ($result) + return $result->class; + + return NULL; + } + /** * This function will register a new subtype, returning its ID as required. * @@ -641,18 +660,17 @@ function add_subtype($type, $subtype, $class = "") { global $CONFIG; - $type = sanitise_string($type); $subtype = sanitise_string($subtype); $class = sanitise_string($class); - + // Short circuit if no subtype is given - if ($subtype == "") + if ($subtype2 == "") return 0; - + $id = get_subtype_id($type, $subtype); - if (!$id) + if ($id==0) return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes (type, subtype, class) values ('$type','$subtype','$class')"); return $id; @@ -748,14 +766,16 @@ if (!($row instanceof stdClass)) return $row; // See if there are any registered subtype handler classes for this type and subtype - $classname = get_subtype_class($row->type, $row->subtype); + + $classname = get_subtype_class_from_id($row->subtype); if ($classname!="") { $tmp = new $classname($row); if (!($tmp instanceof ElggEntity)) throw new ClassException("$classname is not an ElggEntity."); - + + return $tmp; } else { @@ -842,6 +862,7 @@ if (!$count) { $query .= " order by $order_by"; if ($limit) $query .= " limit $offset, $limit"; // Add order and limit + $dt = get_data($query, "entity_row_to_elggstar"); return $dt; } else { -- cgit v1.2.3