From daa08c4e4c70247b98ff5fa1ea3d3a5b1a1039f1 Mon Sep 17 00:00:00 2001 From: gbateson Date: Fri, 18 Nov 2005 01:13:31 +0000 Subject: [PATCH] remove [] from clue button text in JCloze (HP default is [?], so additional [] are not needed) --- mod/hotpot/template/v6.php | 2660 ++++++++++++++++++------------------ 1 file changed, 1330 insertions(+), 1330 deletions(-) diff --git a/mod/hotpot/template/v6.php b/mod/hotpot/template/v6.php index 69be57029e3..ce1b545731e 100644 --- a/mod/hotpot/template/v6.php +++ b/mod/hotpot/template/v6.php @@ -1,1330 +1,1330 @@ -parent = &$parent; - - $get_js = optional_param('js', false); - $get_css = optional_param('css', false); - - if (!empty($get_css)) { - $this->css = ''; - $this->read_template('hp6.cs_', 'css'); - - } else if (!empty($get_js)) { - $this->js = ''; - $this->read_template($this->parent->draganddrop.$this->parent->quiztype.'6.js_', 'js'); - - } else { - $this->html = ''; - $this->read_template($this->parent->draganddrop.$this->parent->quiztype.'6.ht_', 'html'); - } - - // expand special strings, if any - $pattern = ''; - switch ($this->parent->quiztype) { - case 'jcloze': - $pattern = '/\[(PreloadImageList)\]/'; - break; - case 'jcross': - $pattern = '/\[(PreloadImageList|ShowHideClueList)\]/'; - break; - case 'jmatch': - $pattern = '/\[(PreloadImageList|QsToShow|FixedArray|DragArray)\]/'; - break; - case 'jmix': - $pattern = '/\[(PreloadImageList|SegmentArray|AnswerArray)\]/'; - break; - case 'jquiz': - $pattern = '/\[(PreloadImageList|QsToShow)\]/'; - break; - } - if (!empty($pattern)) { - $this->expand_strings('html', $pattern); - } - } - - // captions and messages - - function v6_expand_AlsoCorrect() { - return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',also-correct'); - } - function v6_expand_CapitalizeFirst() { - return $this->bool_value('hotpot-config-file,'.$this->parent->quiztype.',capitalize-first-letter'); - } - function v6_expand_CheckCaption() { - return $this->parent->xml_value('hotpot-config-file,global,check-caption'); - } - function v6_expand_CorrectIndicator() { - return $this->js_value('hotpot-config-file,global,correct-indicator'); - } - function v6_expand_Back() { - return $this->int_value('hotpot-config-file,global,include-back'); - } - function v6_expand_BackCaption() { - return $this->parent->xml_value('hotpot-config-file,global,back-caption'); - } - function v6_expand_ClickToAdd() { - return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',click-to-add'); - } - function v6_expand_ClueCaption() { - return $this->parent->xml_value('hotpot-config-file,global,clue-caption'); - } - function v6_expand_Clues() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-clues'); - } - function v6_expand_Contents() { - return $this->int_value('hotpot-config-file,global,include-contents'); - } - function v6_expand_ContentsCaption() { - return $this->parent->xml_value('hotpot-config-file,global,contents-caption'); - } - function v6_expand_GuessCorrect() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',guess-correct'); - } - function v6_expand_GuessIncorrect() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',guess-incorrect'); - } - function v6_expand_Hint() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-hint'); - } - function v6_expand_HintCaption() { - return $this->parent->xml_value('hotpot-config-file,global,hint-caption'); - } - function v6_expand_IncorrectIndicator() { - return $this->js_value('hotpot-config-file,global,incorrect-indicator'); - } - function v6_expand_LastQCaption() { - return $this->parent->xml_value('hotpot-config-file,global,last-q-caption'); - } - function v6_expand_NextCorrect() { - $value = $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-part'); - if (empty($value)) { // jquiz - $value = $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-letter'); - } - return $value; - } - function v6_expand_NextEx() { - return $this->int_value('hotpot-config-file,global,include-next-ex'); - } - function v6_expand_NextExCaption() { - return $this->parent->xml_value('hotpot-config-file,global,next-ex-caption'); - } - function v6_expand_NextQCaption() { - return $this->parent->xml_value('hotpot-config-file,global,next-q-caption'); - } - function v6_expand_OKCaption() { - return $this->parent->xml_value('hotpot-config-file,global,ok-caption'); - } - function v6_expand_Restart() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-restart'); - } - function v6_expand_RestartCaption() { - return $this->parent->xml_value('hotpot-config-file,global,restart-caption'); - } - function v6_expand_ShowAllQuestionsCaption() { - return $this->js_value('hotpot-config-file,global,show-all-questions-caption'); - } - function v6_expand_ShowOneByOneCaption() { - return $this->js_value('hotpot-config-file,global,show-one-by-one-caption'); - } - function v6_expand_TheseAnswersToo() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',also-correct'); - } - function v6_expand_ThisMuch() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',this-much-correct'); - } - function v6_expand_Undo() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-undo'); - } - function v6_expand_UndoCaption() { - return $this->parent->xml_value('hotpot-config-file,global,undo-caption'); - } - function v6_expand_YourScoreIs() { - return $this->js_value('hotpot-config-file,global,your-score-is'); - } - - // reading - - function v6_expand_Reading() { - return $this->int_value('data,reading,include-reading'); - } - function v6_expand_ReadingText() { - $title = $this->v6_expand_ReadingTitle(); - $value = $this->parent->xml_value('data,reading,reading-text'); - $value = empty($value) ? '' : ('
'.$value.'
'); - return $title.$value; - } - function v6_expand_ReadingTitle() { - $value = $this->parent->xml_value('data,reading,reading-title'); - return empty($value) ? '' : ('

'.$value.'

'); - } - - // timer - - function v6_expand_Timer() { - return $this->int_value('data,timer,include-timer'); - } - function v6_expand_JSTimer() { - return $this->read_template('hp6timer.js_'); - } - function v6_expand_Seconds() { - return $this->parent->xml_value('data,timer,seconds'); - } - - // send results - - function v6_expand_SendResults() { - return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',send-email'); - } - function v6_expand_JSSendResults() { - return $this->read_template('hp6sendresults.js_'); - } - function v6_expand_FormMailURL() { - return $this->parent->xml_value('hotpot-config-file,global,formmail-url'); - } - function v6_expand_EMail() { - return $this->parent->xml_value('hotpot-config-file,global,email'); - } - function v6_expand_NamePlease() { - return $this->js_value('hotpot-config-file,global,name-please'); - } - - // preload images - - function v6_expand_PreloadImages() { - $value = $this->v6_expand_PreloadImageList(); - return empty($value) ? false : true; - } - function v6_expand_PreloadImageList() { - - // check it has not been set already - if (!isset($this->PreloadImageList)) { - - // the list of image urls - $list = array(); - - // extract tags - $img_tag = htmlspecialchars('|<img.*?src="(.*?)".*?>|is'); - if (preg_match_all($img_tag, $this->parent->source, $matches)) { - $list = $matches[1]; - - // remove duplicates - $list = array_unique($list); - } - - // convert to comma delimited string - $this->PreloadImageList = empty($list) ? '' : "'".implode(',', $list)."'"; - } - return $this->PreloadImageList; - } - - // html files (all quiz types) - - function v6_expand_PlainTitle() { - return $this->parent->xml_value('data,title'); - } - function v6_expand_ExerciseSubtitle() { - return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',exercise-subtitle'); - } - function v6_expand_Instructions() { - return $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',instructions'); - } - function v6_expand_DublinCoreMetadata() { - $dc = ''."\n"; - if (is_string($this->parent->xml_value('rdf:RDF,rdf:Description'))) { - // do nothing (there is no more dc info) - } else { - $dc .= ''."\n"; - $dc .= ''."\n"; - } - return $dc; - } - function v6_expand_FullVersionInfo() { - global $CFG; - require_once($CFG->hotpotroot.DIRECTORY_SEPARATOR.'version.php'); // set $module - return $this->parent->xml_value('version').'.x (Moodle '.$CFG->release.', hotpot-module '.$this->parent->obj_value($module, 'release').')'; - } - function v6_expand_HeaderCode() { - return $this->parent->xml_value('hotpot-config-file,global,header-code'); - } - function v6_expand_StyleSheet() { - $this->read_template('hp6.cs_', 'css'); - return $this->css; - } - - // stylesheet (hp6.cs_) - - function v6_expand_PageBGColor() { - return $this->parent->xml_value('hotpot-config-file,global,page-bg-color'); - } - function v6_expand_GraphicURL() { - return $this->parent->xml_value('hotpot-config-file,global,graphic-url'); - } - function v6_expand_ExBGColor() { - return $this->parent->xml_value('hotpot-config-file,global,ex-bg-color'); - } - - function v6_expand_FontFace() { - return $this->parent->xml_value('hotpot-config-file,global,font-face'); - } - function v6_expand_FontSize() { - return $this->parent->xml_value('hotpot-config-file,global,font-size'); - } - function v6_expand_TextColor() { - return $this->parent->xml_value('hotpot-config-file,global,text-color'); - } - function v6_expand_TitleColor() { - return $this->parent->xml_value('hotpot-config-file,global,title-color'); - } - function v6_expand_LinkColor() { - return $this->parent->xml_value('hotpot-config-file,global,link-color'); - } - function v6_expand_VLinkColor() { - return $this->parent->xml_value('hotpot-config-file,global,vlink-color'); - } - - function v6_expand_NavTextColor() { - return $this->parent->xml_value('hotpot-config-file,global,page-bg-color'); - } - function v6_expand_NavBarColor() { - return $this->parent->xml_value('hotpot-config-file,global,nav-bar-color'); - } - function v6_expand_NavLightColor() { - $color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color'); - return $this->get_halfway_color($color, '#ffffff'); - } - function v6_expand_NavShadeColor() { - $color = $this->parent->xml_value('hotpot-config-file,global,nav-bar-color'); - return $this->get_halfway_color($color, '#000000'); - } - - function v6_expand_FuncLightColor() { // top-left of buttons - $color = $this->parent->xml_value('hotpot-config-file,global,ex-bg-color'); - return $this->get_halfway_color($color, '#ffffff'); - } - function v6_expand_FuncShadeColor() { // bottom right of buttons - $color = $this->parent->xml_value('hotpot-config-file,global,ex-bg-color'); - return $this->get_halfway_color($color, '#000000'); - } - - // navigation buttons - - function v6_expand_NavButtons() { - $back = $this->v6_expand_Back(); - $next_ex = $this->v6_expand_NextEx(); - $contents = $this->v6_expand_Contents(); - return (empty($back) && empty($next_ex) && empty($contents) ? false : true); - } - function v6_expand_NavBarJS() { - return $this->v6_expand_NavButtons(); - } - - // js files (all quiz types) - - function v6_expand_JSBrowserCheck() { - return $this->read_template('hp6browsercheck.js_'); - } - function v6_expand_JSButtons() { - return $this->read_template('hp6buttons.js_'); - } - function v6_expand_JSCard() { - return $this->read_template('hp6card.js_'); - } - function v6_expand_JSCheckShortAnswer() { - return $this->read_template('hp6checkshortanswer.js_'); - } - function v6_expand_JSHotPotNet() { - return $this->read_template('hp6hotpotnet.js_'); - } - function v6_expand_JSShowMessage() { - return $this->read_template('hp6showmessage.js_'); - } - function v6_expand_JSUtilities() { - return $this->read_template('hp6utilities.js_'); - } - - // js files - - function v6_expand_JSJCloze6() { - return $this->read_template('jcloze6.js_'); - } - function v6_expand_JSJCross6() { - return $this->read_template('jcross6.js_'); - } - function v6_expand_JSJMatch6() { - return $this->read_template('jmatch6.js_'); - } - function v6_expand_JSJMix6() { - return $this->read_template('jmix6.js_'); - } - function v6_expand_JSJQuiz6() { - return $this->read_template('jquiz6.js_'); - } - - // drag and drop - - function v6_expand_JSDJMatch6() { - return $this->read_template('djmatch6.js_'); - } - function v6_expand_JSDJMix6() { - return $this->read_template('djmix6.js_'); - } - - // what are these for? - - function v6_expand_JSFJMatch6() { - return $this->read_template('fjmatch6.js_'); - } - function v6_expand_JSFJMix6() { - return $this->read_template('fjmix6.js_'); - } - - // jmatch6.js_ - - function v6_expand_ShuffleQs() { - return $this->bool_value('hotpot-config-file,'.$this->parent->quiztype.',shuffle-questions'); - } - function v6_expand_QsToShow() { - $i = $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',show-limited-questions'); - if ($i) { - $i = $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',questions-to-show'); - } - if (empty($i)) { - $i = 0; - switch ($this->parent->quiztype) { - case 'jmatch': - $values = $this->parent->xml_values('data,matching-exercise,pair'); - $i = count($values); - break; - case 'jquiz': - while ($this->parent->xml_value('data,questions,question-record', "[$i]['#']['question'][0]['#']")) { - $i++; - } - break; - } // end switch - } - return $i; - } - function v6_expand_MatchDivItems() { - $str = ''; - - $this->get_jmatch_items($l_items=array(), $r_items = array()); - - $l_keys = $this->shuffle_jmatch_items($l_items); - $r_keys = $this->shuffle_jmatch_items($r_items); - - $options = ''; - foreach ($r_keys as $key) { - $options .= ''."\n"; - } - foreach ($l_keys as $key) { - $str .= ''.$l_items[$key]['text'][0]['#'].''; - $str .= ''; - $str .= ''; - } - return $str; - } - - // jmix6.js_ - - function v6_expand_Punctuation() { - $tags = 'data,jumbled-order-exercise'; - $chars = array_merge( - $this->jmix_Punctuation("$tags,main-order,segment"), - $this->jmix_Punctuation("$tags,alternate") - ); - $chars = array_unique($chars); - $chars = implode('', $chars); - $chars = $this->js_safe($chars, true); - return $chars; - } - function jmix_Punctuation($tags) { - $chars = array(); - - // all punctutation except '&#;' (because they are used in html entities) - $ENTITIES = $this->jmix_encode_punctuation('!"$%'."'".'()*+,-./:<=>?@[\]^_`{|}~'); - $pattern = "/&#x([0-9A-F]+);/i"; - $i = 0; - - // get next segment (or alternate answer) - while ($value = $this->parent->xml_value($tags, "[$i]['#']")) { - - // convert low-ascii punctuation to entities - $value = strtr($value, $ENTITIES); - - // extract all hex HTML entities - if (preg_match_all($pattern, $value, $matches)) { - - // loop through hex entities - $m_max = count($matches[0]); - for ($m=0; $m<$m_max; $m++) { - - // convert to hex number - eval('$hex=0x'.$matches[1][$m].';'); - - // is this a punctuation character? - if ( - ($hex>=0x0020 && $hex<=0x00BF) || // ascii punctuation - ($hex>=0x2000 && $hex<=0x206F) || // general punctuation - ($hex>=0x3000 && $hex<=0x303F) || // CJK punctuation - ($hex>=0xFE30 && $hex<=0xFE4F) || // CJK compatability - ($hex>=0xFE50 && $hex<=0xFE6F) || // small form variants - ($hex>=0xFF00 && $hex<=0xFF40) || // halfwidth and fullwidth forms (1) - ($hex>=0xFF5B && $hex<=0xFF65) || // halfwidth and fullwidth forms (2) - ($hex>=0xFFE0 && $hex<=0xFFEE) // halfwidth and fullwidth forms (3) - ) { - // add this character - $chars[] = $matches[0][$m]; - } - } - } - $i++; - } - - return $chars; - } - function v6_expand_OpenPunctuation() { - $tags = 'data,jumbled-order-exercise'; - $chars = array_merge( - $this->jmix_OpenPunctuation("$tags,main-order,segment"), - $this->jmix_OpenPunctuation("$tags,alternate") - ); - $chars = array_unique($chars); - $chars = implode('', $chars); - $chars = $this->js_safe($chars, true); - return $chars; - } - function jmix_OpenPunctuation($tags) { - $chars = array(); - - // unicode punctuation designations (pi="initial quote", ps="open") - // http://www.sql-und-xml.de/unicode-database/pi.html - // http://www.sql-und-xml.de/unicode-database/ps.html - $pi = '0022|0027|00AB|2018|201B|201C|201F|2039'; - $ps = '0028|005B|007B|0F3A|0F3C|169B|201A|201E|2045|207D|208D|2329|23B4|2768|276A|276C|276E|2770|2772|2774|27E6|27E8|27EA|2983|2985|2987|2989|298B|298D|298F|2991|2993|2995|2997|29D8|29DA|29FC|3008|300A|300C|300E|3010|3014|3016|3018|301A|301D|FD3E|FE35|FE37|FE39|FE3B|FE3D|FE3F|FE41|FE43|FE47|FE59|FE5B|FE5D|FF08|FF3B|FF5B|FF5F|FF62'; - $pattern = "/(&#x($pi|$ps);)/i"; - - $ENTITIES = $this->jmix_encode_punctuation('"'."'".'(<[{'); - - $i = 0; - while ($value = $this->parent->xml_value($tags, "[$i]['#']")) { - $value = strtr($value, $ENTITIES); - if (preg_match_all($pattern, $value, $matches)) { - $chars = array_merge($chars, $matches[0]); - } - $i++; - } - - return $chars; - } - function jmix_encode_punctuation($str) { - $ENTITIES = array(); - $i_max = strlen($str); - for ($i=0; $i<$i_max; $i++) { - $ENTITIES[$str{$i}] = '&#x'.sprintf('%04X', ord($str{$i})).';'; - } - return $ENTITIES; - } - function v6_expand_ExerciseTitle() { - return $this->parent->xml_value('data,title'); - } - - // Jmix specials - - function v6_expand_SegmentArray() { - $segments = $this->parent->xml_values('data,jumbled-order-exercise,main-order,segment'); - - $this->seed_random_number_generator(); - $keys = array_keys($segments); - shuffle($keys); - - $str = ''; - for($i=0; $ijs_safe($segments[$keys[$i]])."';\n"; - $str .= "Segments[$i][1] = ".($keys[$i]+1).";\n"; - $str .= "Segments[$i][2] = 0;\n"; - } - return $str; - } - function v6_expand_AnswerArray() { - - $segments = $this->parent->xml_values('data,jumbled-order-exercise,main-order,segment'); - $alternates = $this->parent->xml_values('data,jumbled-order-exercise,alternate'); - - $i = 0; - $pattern = ''; - $str = 'Answers['.$i++.'] = new Array('; - for($ii=0; $iiparent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',remaining-words'); - } - function v6_expand_TimesUp() { - return $this->parent->xml_value('hotpot-config-file,global,times-up'); - } - - // nav bar - - function v6_expand_NavBar($navbarid='') { - $this->navbarid = $navbarid; - - $tag = 'navbar'; - $this->read_template('hp6navbar.ht_', $tag); - - unset($this->navbarid); - - return $this->$tag; - } - function v6_expand_TopNavBar() { - return $this->v6_expand_NavBar('TopNavBar'); - } - function v6_expand_BottomNavBar() { - return $this->v6_expand_NavBar('BottomNavBar'); - } - - // hp6navbar.ht_ - - function v6_expand_NavBarID() { - // $this->navbarid is set in "$this->v6_expand_NavBar" - return empty($this->navbarid) ? '' : $this->navbarid; - } - function v6_expand_ContentsURL() { - $url = $this->parent->xml_value('hotpot-config-file,global,contents-url'); - if ($url) { - $url = hotpot_convert_navbutton_url($this->parent->get_baseurl(), $this->parent->reference, $url, $this->parent->course); - } - return $url; - } - function v6_expand_NextExURL() { - $url = $this->parent->xml_value('hotpot-config-file,'.$this->parent->quiztype.',next-ex-url'); - if ($url) { - $url = hotpot_convert_navbutton_url($this->parent->get_baseurl(), $this->parent->reference, $url, $this->parent->course); - } - return $url; - } - - // conditional blocks - - function v6_expand_ShowAnswer() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-show-answer'); - } - function v6_expand_Slide() { - return true; // whats's this (JMatch drag and drop) - } - - // specials (JMatch) - - function v6_expand_FixedArray() { - $str = ''; - $this->get_jmatch_items($l_items=array(), $r_items = array()); - foreach ($l_items as $i=>$item) { - $str .= "F[$i] = new Array();\n"; - $str .= "F[$i][0] = '".$this->js_safe($item['text'][0]['#'], true)."';\n"; - $str .= "F[$i][1] = ".($i+1).";\n"; - } - return $str; - } - function v6_expand_DragArray() { - $str = ''; - $this->get_jmatch_items($l_items=array(), $r_items = array()); - foreach ($r_items as $i=>$item) { - $str .= "D[$i] = new Array();\n"; - $str .= "D[$i][0] = '".$this->js_safe($item['text'][0]['#'], true)."';\n"; - $str .= "D[$i][1] = ".($i+1).";\n"; - $str .= "D[$i][2] = 0;\n"; - } - return $str; - } - - function get_jmatch_items(&$l_items, &$r_items) { - $i = 0; - while( - ($l_item = $this->parent->xml_value('data,matching-exercise,pair',"[$i]['#']['left-item'][0]['#']")) && - ($r_item = $this->parent->xml_value('data,matching-exercise,pair',"[$i]['#']['right-item'][0]['#']")) - ) { - $l_items[] = $l_item; - $r_items[] = $r_item; - $i++; - } - } - function shuffle_jmatch_items(&$items) { - // get moveable items - $moveable_keys = array(); - for($i=0; $iseed_random_number_generator(); - shuffle($moveable_keys); - - $keys = array(); - for($i=0, $ii=0; $iparent->quiztype) { - case 'jcloze': - $str .= "I = new Array();\n"; - $tags = 'data,gap-fill,question-record'; - while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { - $a = 0; - $aa = 0; - while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { - $text = $this->js_value($tags, $answer."['text'][0]['#']", true); - if ($text) { - if ($aa==0) { // first time only - $str .= "I[$q] = new Array();\n"; - $str .= "I[$q][1] = new Array();\n"; - } - $str .= "I[$q][1][$aa] = new Array();\n"; - $str .= "I[$q][1][$aa][0] = '$text';\n"; - $aa++; - } - $a++; - } - // add clue, if any answers were found - if ($aa) { - $clue = $this->js_value($tags, $question."['clue'][0]['#']", true); - $str .= "I[$q][2]='$clue';\n"; - } - $q++; - } - break; - case 'jquiz': - $str .= "I=new Array();\n"; - $tags = 'data,questions,question-record'; - while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { - - $question_type = $this->int_value($tags, $question."['question-type'][0]['#']"); - $weighting = $this->int_value($tags, $question."['weighting'][0]['#']"); - $clue = $this->js_value($tags, $question."['clue'][0]['#']", true); - - $answers = $question."['answers'][0]['#']"; - - $a = 0; - $aa = 0; - while (($answer = $answers."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { - $text = $this->js_value($tags, $answer."['text'][0]['#']", true); - $feedback = $this->js_value($tags, $answer."['feedback'][0]['#']", true); - $correct = $this->int_value($tags, $answer."['correct'][0]['#']"); - $percent = $this->int_value($tags, $answer."['percent-correct'][0]['#']"); - $include = $this->int_value($tags, $answer."['include-in-mc-options'][0]['#']"); - if ($text) { - if ($aa==0) { // first time only - $str .= "I[$q]=new Array();\n"; - $str .= "I[$q][0]=$weighting;\n"; - $str .= "I[$q][1]='$clue';\n"; - $str .= "I[$q][2]='".($question_type-1)."';\n"; - $str .= "I[$q][3]=new Array();\n"; - } - $str .= "I[$q][3][$aa]=new Array('$text','$feedback',$correct,$percent,$include);\n"; - $aa++; - } - $a++; - } - $q++; - } - break; - } - return $str; - } - - function v6_expand_ClozeBody() { - $str = ''; - - $dropdownlist = ''; - if ($this->v6_use_DropDownList()) { - $this->v6_set_WordList(); - foreach ($this->wordlist as $word) { - $dropdownlist .= ''; - } - } - - $q = 0; - $tags = 'data,gap-fill'; - - while ($text = $this->parent->xml_value($tags, "[0]['#'][$q]")) { - $str .= $text; - if (($question="[$q]['#']") && $this->parent->xml_value("$tags,question-record", $question)) { - $str .= ''; - if ($this->v6_use_DropDownList()) { - $str .= ''; - } else { - $str .= ''; - } - if ($this->v6_expand_Clues()) { - $caption = $this->v6_expand_ClueCaption(); - $str .= ''; - } - $str .= ''; - } - $q++; - } - - return $str; - } - - // JCloze quiztype - - function v6_expand_WordList() { - $str = ''; - if ($this->v6_include_WordList()) { - $this->v6_set_WordList(); - $str = implode('    ', $this->wordlist); - } - return $str; - } - function v6_include_WordList() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-word-list'); - } - function v6_use_DropDownList() { - return $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',use-drop-down-list'); - } - function v6_set_WordList() { - - if (isset($this->wordlist)) { - // do nothing - } else { - $this->wordlist = array(); - - // is the wordlist required - if ($this->v6_include_WordList() || $this->v6_use_DropDownList()) { - - $q = 0; - $tags = 'data,gap-fill,question-record'; - while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { - $a = 0; - $aa = 0; - while (($answer=$question."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { - $text = $this->parent->xml_value($tags, $answer."['text'][0]['#']"); - $correct = $this->int_value($tags, $answer."['correct'][0]['#']"); - if ($text && $correct) { // $correct is always true - $this->wordlist[] = $text; - $aa++; - } - $a++; - } - $q++; - } - $this->wordlist = array_unique($this->wordlist); - sort($this->wordlist); - } - } - } - function v6_expand_Keypad() { - $str = ''; - if ($this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-keypad')) { - - // these characters must always be in the keypad - $chars = array(); - $this->add_keypad_chars($chars, $this->parent->xml_value('hotpot-config-file,global,keypad-characters')); - - // append other characters used in the answers - $tags = ''; - switch ($this->parent->quiztype) { - case 'jcloze': - $tags = 'data,gap-fill,question-record'; - break; - case 'jquiz': - $tags = 'data,questions,question-record'; - break; - } - if ($tags) { - $q = 0; - while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { - - if ($this->parent->quiztype=='jquiz') { - $answers = $question."['answers'][0]['#']"; - } else { - $answers = $question; - } - - $a = 0; - while (($answer=$answers."['answer'][$a]['#']") && $this->parent->xml_value($tags, $answer)) { - $this->add_keypad_chars($chars, $this->parent->xml_value($tags, $answer."['text'][0]['#']")); - $a++; - } - $q++; - } - } - - // remove duplicate characters and sort - $chars = array_unique($chars); - usort($chars, "hotpot_sort_keypad_chars"); - - // create keypad buttons for each character - $str .= '
'; - foreach ($chars as $char) { - $str .= ""; - } - $str .= '
'; - } - return $str; - } - function add_keypad_chars(&$chars, $text) { - if (preg_match_all('|&[^;]+;|i', $text, $more_chars)) { - $chars = array_merge($chars, $more_chars[0]); - } - } - function v6_expand_Correct() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',guesses-correct'); - } - function v6_expand_Incorrect() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',guesses-incorrect'); - } - function v6_expand_GiveHint() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',next-correct-letter'); - } - function v6_expand_CaseSensitive() { - return $this->bool_value('hotpot-config-file,'.$this->parent->quiztype.',case-sensitive'); - } - - // JCross quiztype - - function v6_expand_CluesAcrossLabel() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',clues-across'); - } - function v6_expand_CluesDownLabel() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',clues-down'); - } - function v6_expand_EnterCaption() { - return $this->js_value('hotpot-config-file,'.$this->parent->quiztype.',enter-caption'); - } - function v6_expand_ShowHideClueList() { - $value = $this->int_value('hotpot-config-file,'.$this->parent->quiztype.',include-clue-list'); - return empty($value) ? ' style="display: none;"' : ''; - } - - // JCross specials - - function v6_expand_CluesDown() { - return $this->v6_expand_jcross_clues('D'); - } - function v6_expand_CluesAcross() { - return $this->v6_expand_jcross_clues('A'); - } - function v6_expand_jcross_clues($direction) { - // $direction: A(cross) or D(own) - $this->v6_get_jcross_grid($row=NULL, $r_max=0, $c_max=0); - $i = 0; // clue index; - $str = ''; - for($r=0; $r<=$r_max; $r++) { - for($c=0; $c<=$c_max; $c++) { - $aword = $this->get_jcross_aword($row, $r, $r_max, $c, $c_max); - $dword = $this->get_jcross_dword($row, $r, $r_max, $c, $c_max); - if ($aword || $dword) { - $i++; // increment clue index - - // get the definition for this word - $def = ''; - $word = ($direction=='A') ? $aword : $dword; - $clues = $this->parent->xml_values('data,crossword,clues,item'); - foreach ($clues as $clue) { - if ($clue['word'][0]['#']==$word) { - $def = $clue['def'][0]['#']; - $def = strtr($def, array('<'=>'<', '>'=>'>', "\n"=>'
')); - break; - } - } - - if (!empty($def)) { - $str .= ''.$i.'. '.$def.''; - } - } - } - } - return $str; - } - - // jcross6.js_ - - function v6_expand_LetterArray() { - $this->v6_get_jcross_grid($row=NULL, $r_max=0, $c_max=0); - $str = ''; - for($r=0; $r<=$r_max; $r++) { - $str .= "L[$r] = new Array("; - for($c=0; $c<=$c_max; $c++) { - $str .= ($c>0 ? ',' : '')."'".$this->js_safe($row[$r]['cell'][$c]['#'], true)."'"; - } - $str .= ");\n"; - } - return $str; - } - function v6_expand_GuessArray() { - $this->v6_get_jcross_grid($row=NULL, $r_max=0, $c_max=0); - $str = ''; - for($r=0; $r<=$r_max; $r++) { - $str .= "G[$r] = new Array('".str_repeat("','", $c_max)."');\n"; - } - return $str; - } - function v6_expand_ClueNumArray() { - $this->v6_get_jcross_grid($row=NULL, $r_max=0, $c_max=0); - $i = 0; // clue index - $str = ''; - for($r=0; $r<=$r_max; $r++) { - $str .= "CL[$r] = new Array("; - for($c=0; $c<=$c_max; $c++) { - if ($c>0) { - $str .= ','; - } - $aword = $this->get_jcross_aword($row, $r, $r_max, $c, $c_max); - $dword = $this->get_jcross_dword($row, $r, $r_max, $c, $c_max); - if (empty($aword) && empty($dword)) { - $str .= 0; - } else { - $i++; // increment the clue index - $str .= $i; - } - } - $str .= ");\n"; - } - return $str; - } - function v6_expand_GridBody() { - $this->v6_get_jcross_grid($row=NULL, $r_max=0, $c_max=0); - $i = 0; // clue index; - $str = ''; - for($r=0; $r<=$r_max; $r++) { - $str .= ''; - for($c=0; $c<=$c_max; $c++) { - if (empty($row[$r]['cell'][$c]['#'])) { - $str .= ' '; - } else { - $aword = $this->get_jcross_aword($row, $r, $r_max, $c, $c_max); - $dword = $this->get_jcross_dword($row, $r, $r_max, $c, $c_max); - if (empty($aword) && empty($dword)) { - $str .= ' '; - } else { - $i++; // increment clue index - $str .= ''.$i.'   '; - } - } - } - $str .= ''; - } - return $str; - } - function v6_get_jcross_grid(&$row, &$r_max, &$c_max) { - $row = $this->parent->xml_values('data,crossword,grid,row'); - $r_max = 0; - $c_max = 0; - if (isset($row) && is_array($row)) { - for($r=0; $rget_jcross_word($row, $r, $r_max, $c, $c_max, true); - } - return $str; - } - function get_jcross_aword(&$row, $r, $r_max, $c, $c_max) { - $str = ''; - if (($c==0 || empty($row[$r]['cell'][$c-1]['#'])) && $c<$c_max && !empty($row[$r]['cell'][$c+1]['#'])) { - $str = $this->get_jcross_word($row, $r, $r_max, $c, $c_max, false); - } - return $str; - } - function get_jcross_word(&$row, $r, $r_max, $c, $c_max, $go_down=false) { - $str = ''; - while ($r<=$r_max && $c<=$c_max && !empty($row[$r]['cell'][$c]['#'])) { - $str .= $row[$r]['cell'][$c]['#']; - if ($go_down) { - $r++; - } else { - $c++; - } - } - return $str; - } - - // specials (JQuiz) - - function v6_expand_QuestionOutput() { - $str = ''; - $str .= '
    '."\n"; - - $q = 0; - $tags = 'data,questions,question-record'; - while (($question="[$q]['#']") && $this->parent->xml_value($tags, $question)) { - - // get question - $question_text = $this->parent->xml_value($tags, $question."['question'][0]['#']"); - $question_type = $this->parent->xml_value($tags, $question."['question-type'][0]['#']"); - - // check we have a question - if ($question_text && $question_type) { - - $str .= '