MDL-15304
Handle empty names for labels (if only HTML tags in label text)
This commit is contained in:
+18
-10
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user