From 20355e5ac22092c55286e9c0bf056d673d3196f2 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 4 Apr 2007 03:35:23 +0000 Subject: [PATCH] MDL-9138; Edited lib/xmlize.php to return false when the passed file doesn't return any entries (when it's not valid XML or is empty). Also made it much clearer that glossary/import requires an XML file, not just any old file. --- lang/en_utf8/glossary.php | 2 ++ lib/xmlize.php | 7 ++++++- mod/glossary/import.php | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lang/en_utf8/glossary.php b/lang/en_utf8/glossary.php index bc7f66cfd7..4fba94447c 100644 --- a/lang/en_utf8/glossary.php +++ b/lang/en_utf8/glossary.php @@ -92,6 +92,7 @@ $string['entryleveldefaultsettings'] = 'Entry Level Default Settings'; $string['entrysaved'] = 'This entry has been saved'; $string['entryupdated'] = 'This entry has been updated'; $string['entryusedynalink'] = 'This entry should be automatically linked'; +$string['errorparsingxml'] = 'Errors occurred while parsing the file. Make sure it is valid XML syntax.'; $string['explainaddentry'] = 'Add a new entry to the current glossary.
Concept and definition are mandatory fields.'; $string['explainall'] = 'Shows ALL entries on one page'; $string['explainalphabet'] = 'Browse the glossary using this index'; @@ -125,6 +126,7 @@ $string['importcategories'] = 'Import categories'; $string['importedcategories'] = 'Imported categories'; $string['importedentries'] = 'Imported entries'; $string['importentries'] = 'Import entries'; +$string['importentriesfromxml'] = 'Import entries from XML file'; $string['isglobal'] = 'Is this glossary global?'; $string['linkcategory'] = 'Automatically link this category'; $string['linking'] = 'Auto-linking'; diff --git a/lib/xmlize.php b/lib/xmlize.php index 8493d2c1db..34f29dfcf1 100644 --- a/lib/xmlize.php +++ b/lib/xmlize.php @@ -54,6 +54,11 @@ function xmlize($data, $WHITE=1, $encoding='UTF-8') { xml_parser_free($parser); $i = 0; + + if (empty($vals)) { + // XML file is invalid or empty, return false + return false; + } $tagname = $vals[$i]['tag']; if ( isset ($vals[$i]['attributes'] ) ) @@ -186,4 +191,4 @@ function traverse_xmlize($array, $arrName = 'array', $level = 0) { } -?> \ No newline at end of file +?> diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 281be0a0d1..0a83eef4d2 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -43,7 +43,7 @@ $strsearchconcept = get_string("searchconcept", "glossary"); $strsearchindefinition = get_string("searchindefinition", "glossary"); $strsearch = get_string("search"); - $strimportentries = get_string('importentries', 'glossary'); + $strimportentries = get_string('importentriesfromxml', 'glossary'); print_header_simple(format_string($glossary->name), "", "id\">$strglossaries -> " . @@ -363,7 +363,7 @@ } print_box_end(); } else { - notify("Error while trying to read the file."); + notice(get_string('errorparsingxml', 'glossary')); } /// Finish the page -- 2.39.5