From e564571835157bbed16326ced3b32725365990ee Mon Sep 17 00:00:00 2001 From: gbateson Date: Tue, 1 Sep 2009 01:05:41 +0000 Subject: [PATCH] MDL-20184 more efficient and accurate detection of missing nodes in xml tree when importing Hot Potatoes XML files to Moodle question bank / quiz module --- question/format/hotpot/format.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/question/format/hotpot/format.php b/question/format/hotpot/format.php index 83f0a5bd50..8464ccfb5b 100644 --- a/question/format/hotpot/format.php +++ b/question/format/hotpot/format.php @@ -522,8 +522,29 @@ class hotpot_xml_tree { } function xml_value($tags, $more_tags="[0]['#']") { - $tags = empty($tags) ? '' : "['".str_replace(",", "'][0]['#']['", $tags)."']"; - eval('$value = &$this->xml'.$this->xml_root.$tags.$more_tags.';'); + $value = null; + if (isset($this->xml) && is_array($this->xml)) { + + $all_tags = $this->xml_root; + if ($tags) { + $all_tags .= "['".str_replace(",", "'][0]['#']['", $tags)."']"; + } + $all_tags .= $more_tags; + + $pos = strrpos($all_tags, '['); + if ($pos===false) { + $most_tags = ''; // shouldn't happen !! + } else { + $most_tags = substr($all_tags, 0, $pos); + } + + eval('if (isset($this->xml'.$most_tags.') && is_array($this->xml'.$most_tags.') && isset($this->xml'.$all_tags.')) {' + .'$value = &$this->xml'.$all_tags.';' + .'} else {' + .'$value = null;' + .'}' + ); + } if (is_string($value)) { -- 2.39.5