From 376ca347caab29dce18d7b54fe1f922e992b6e6d Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 18 Jun 2008 15:31:47 +0000 Subject: [PATCH] MDL-15304 Handle empty names for labels (if only HTML tags in label text) --- mod/label/lib.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mod/label/lib.php b/mod/label/lib.php index 9d36666f6f..6e07786b6d 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -5,18 +5,30 @@ define("LABEL_MAX_NAME_LENGTH", 50); +function get_label_name($label) { + $textlib = textlib_get_instance(); + + $name = addslashes(strip_tags(format_string(stripslashes($label->content),true))); + if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { + $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; + } + + if (empty($name)) { + // arbitrary name + $name = "label{$label->instance}"; + } + + return $name; +} + function label_add_instance($label) { global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will create a new instance and return the id number /// of the new instance. - $textlib = textlib_get_instance(); - $label->name = strip_tags(format_string($label->content)); - if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { - $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; - } + $label->name = get_label_name($label); $label->timemodified = time(); return $DB->insert_record("label", $label); @@ -28,12 +40,8 @@ function label_update_instance($label) { /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will update an existing instance with new data. - $textlib = textlib_get_instance(); - $label->name = strip_tags(format_string($label->content)); - if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { - $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; - } + $label->name = get_label_name($label); $label->timemodified = time(); $label->id = $label->instance; -- 2.39.5