function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') { global $charset; $regs = array(); // for use with ereg() if (!api_ereg(XHT_SUBS2, $subtext, $regs) && !api_ereg(XHT_SUBS1, $subtext, $regs)) { return $pre . $subtext . $post; } $type = $regs[1]; $text = $regs[2]; $result = ''; $subnum = FALSE; $subtext = isset($regs[3]) ? $regs[3] : ''; if ($this->xht_dbgn) { $subnum = ++$this->xht_dbgn; $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '+ ' . htmlspecialchars($text, ENT_QUOTES, $charset) . ' ' . XHT_RP . $this->_show_param() . " -->\n"; } if ($type == 'D') { // Assign the value to parameter [key] $this->xht_param[$text] = $subtext; // used to be: = $this->xht_substitute($subtext, $cur_elem); } elseif ($type == 'E') { $result = call_user_func($text, FALSE); // get cached result, if any if ($result === FALSE) { $result = $this->xht_substitute($subtext, $cur_elem); $result = call_user_func($text, $result); // allow to cache } } elseif ($type == 'R') { $rdepthn = 'rdepth' . ++$this->xht_param['rdepth']; $n = 0; $this->xht_param['number'] = '0'; if (is_array($a = $this->_lang($text, $cur_elem))) { foreach ($a as $key => $value) { $this->xht_param['number'] = (string) ++$n; $this->xht_param[$rdepthn] = (string) $n; $this->xht_param['key'] = $key; $this->xht_param['value'] = $value; $result .= $this->xht_substitute($subtext, $cur_elem); } } elseif (xht_is_assoclist($a)) { foreach (xht_explode_assoclist($a) as $key => $value) { $this->xht_param['number'] = (string) ++$n; $this->xht_param[$rdepthn] = (string) $n; $this->xht_param['key'] = $key; $this->xht_param['value'] = $value; $result .= $this->xht_substitute($subtext, $cur_elem); } } elseif (!is_object($this->xht_xmldoc)) { $result = '? R Error: no XML doc has been assigned to xht_xmldoc'; } else { $sub_elems = $this->xht_xmldoc->xmd_select_elements($text, $cur_elem); foreach ($sub_elems as $subElem) { $this->xht_param['number'] = (string) ++$n; $this->xht_param[$rdepthn] = (string) $n; $result .= $this->xht_substitute($subtext, $subElem); } } // removed 2004/10/05: template_array (security) // added 2005/03/08: associative list (lang arrays deprecated) $this->xht_param['rdepth']--; // As there is only one ['number'] or one set ['key'] + ['value'], // using them in nested repeats may not have the desired result. } elseif ($type == 'T') { if (api_ereg('^(=|==|<=|<|!=|<>|>|>=) +([^ ]+) +(.*)$', $subtext, $regs)) { // Comparand= parameter value if set, else languagevar value $cmp1 = isset($this->xht_param[$text]) ? $this->xht_param[$text] : $this->_lang($text, $cur_elem); $cmp3 = isset($this->xht_param[$cmp3 = $regs[2]]) ? $this->xht_param[$cmp3] : $this->_lang($cmp3, $cur_elem); $cmp = strcmp($cmp1, $cmp3); $op = ' ' . $regs[1] . ' '; if ($subnum) { $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . ' ' . htmlspecialchars($cmp1 . $op . $cmp3 . ' = ' . $cmp, ENT_QUOTES, $charset) . ' ' . XHT_RP . " -->\n"; } // debugging output if ($cmp < 0 && api_strpos(' <= < != <> ', $op) || $cmp == 0 && api_strpos(' = == <= >= ', $op) || $cmp > 0 && api_strpos(' != <> > >= ', $op)) { $result = $this->xht_substitute($regs[3], $cur_elem); } // else $result is empty } else { $result = $pre . $subtext . $post; } } else { if (api_strpos('CLPVX', $type) !== FALSE) { // used to be always $text = $this->xht_substitute($text, $cur_elem); } // nested escape if ($type == 'C') { // Call, e.g. {-C SUBTEMPLATE-} $result = $this->xht_fill_template($text, $cur_elem); } elseif ($type == 'H') { $result = htmlspecialchars($text, ENT_QUOTES, $charset); } elseif ($type == 'L') { $result = $this->_lang($text, $cur_elem); } elseif ($type == 'P') { $result = $this->xht_param[$text]; } elseif ($type == 'U') { $result = urlencode($text); } elseif ($type == 'W') { $result = xht_htmlwchars($text); } elseif (!is_object($this->xht_xmldoc)) { $result = '? V/X Error: no XML doc has been assigned to xht_xmldoc'; } else { if (api_ereg('^(.*)=/(.+)$', $text, $regs)) { $path = $regs[1]; $text = $regs[2]; if (api_substr($path, -1) == '/') { $path = api_substr($path, 0, -1); } if ($path) { $cur_elem = $this->xht_xmldoc->xmd_select_single_element($path, $cur_elem); } $cur_elem = call_user_func($this->xht_resource, $cur_elem); } $result = $type == 'V' ? $this->xht_xmldoc->xmd_value($text, $cur_elem) : $this->xht_xmldoc->xmd_html_value($text, $cur_elem, 'xht_htmlwchars'); } } if ($subnum) { $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '- ' . htmlspecialchars(api_strlen($result) <= 60 ? $result . ' ' : api_substr($result, 0, 57) . '...', ENT_QUOTES, $charset) . XHT_RP . " -->\n"; } return $result; }
function xmd_select_elements($xmPath, $parent = 0) { // XPath subset: e1/e2/.../en, also * and e[n] and *[n] (at 1 or -1) // /*/... starts from root, regardless of $parent // extensions: e= - or + (previous & next sibling) // e= -name or +name (sibling of specific name) // e= .. (stops at root, so too many doesn't matter) if (api_substr($xmPath, 0, 3) == '/*/') { $xmPath = api_substr($xmPath, 3); $parent = 0; } if ($parent < 0 || $parent > $this->_last) { return array(); } while (api_substr($xmPath, 0, 1) == '/') { $xmPath = api_substr($xmPath, 1); } while (api_substr($xmPath, -1) == '/') { $xmPath = api_substr($xmPath, 0, -1); } if ($xmPath == '' || $xmPath == '.') { return array($parent); } if ($xmPath == '..') { if ($parent > 0) { return array($this->parent[$parent]); } return array($parent); } if ($xmPath[0] == '-' || $xmPath[0] == '+') { $sib = $this->_sibnum($parent, api_substr($xmPath, 1), $xmPath[0]); if ($sib == -1) { return array(); } return array($sib); } $m = array(); if (api_ereg('^(.+)/([^/]+)$', $xmPath, $m)) { if (!($set = $this->xmd_select_elements($m[1], $parent))) { return $set; } // which is empty array if (count($set) == 1) { return $this->xmd_select_elements($m[2], $set[0]); } $bigset = array(); $m2 = $m[2]; foreach ($set as $e) { $bigset = array_merge($bigset, $this->xmd_select_elements($m2, $e)); } return $bigset; } $xmName = $xmPath; $xmNum = 0; $elems = array(); if (api_ereg('^(.+)\\[(-?[0-9]+)\\]$', $xmPath, $m)) { $xmName = $m[1]; $xmNum = (int) $m[2]; } foreach ($this->children[$parent] as $child) { if (!is_string($child)) { if ($xmName == '*' || $this->name[$child] == $xmName) { $elems[] = $child; } } } if ($xmNum == 0) { return $elems; } $xmNum = $xmNum > 0 ? $xmNum - 1 : count($elems) + $xmNum; return $xmNum < count($elems) ? array($elems[$xmNum]) : array(); }
<script> window.location.href='<?php echo $mainurl; ?> '; </script> <?php // sets the total weighting of the question $objQuestion->updateWeighting($questionWeighting); $objQuestion->save($exerciseId); $editQuestion = $questionId; unset($modifyAnswers); } } elseif (empty($reponse)) { $msgErr = get_lang('GiveText'); } elseif (!api_ereg('\\[.+\\]', $reponse)) { $msgErr = get_lang('DefineBlanks'); } else { // now we're going to give a weighting to each blank $setWeighting = 1; unset($submitAnswers); // removes character '::' possibly inserted by the user in the text $reponse = str_replace('::', '', $reponse); // we save the answer because it will be modified //$temp=$reponse; $temp = $reponse; /* // Deprecated code. // 1. find everything between the [tex] and [/tex] tags $startlocations=api_strpos($temp,'[tex]'); $endlocations=api_strpos($temp,'[/tex]');