From 1e80b51172443daaee579eb44f81cf3e0b965393 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 19 Aug 2011 11:17:32 +0200 Subject: [PATCH] fixed checking --- pmwiki_recipes/exercises.php | 37 +++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/pmwiki_recipes/exercises.php b/pmwiki_recipes/exercises.php index ed7fb7c..29d17ee 100644 --- a/pmwiki_recipes/exercises.php +++ b/pmwiki_recipes/exercises.php @@ -42,7 +42,7 @@ SDV($HandleActions['Exercises'], 'Exercises'); SDV($HandleAuth['Exercises'],'read'); function Exercises($pagename, $auth){ - global $ScriptUrl; + global $ScriptUrl, $FarmD; $type = $_GET["type"]; $counter = (int) $_GET["counter"]; $difficulty = (int) $_GET["difficulty"]; @@ -179,12 +179,12 @@ function Exercises($pagename, $auth){ $text = $content["text"]; $lines = explode("\n",$text); - $pickedline = $lines[rand(0,count($lines)-1)]; + $pickedline = $lines[array_rand($lines)]; unset($lines[array_search($pickedline,$lines)]); - // remove markups + //should be better parsed! e.g. remove markups //pregreplace("/(:.*:)/","",$pickedline); while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { - $pickedline = $lines[rand(0,count($lines)-1)]; + $pickedline = $lines[array_rand($lines)]; //pregreplace("/(:.*:)/","",$pickedline); unset($lines[array_search($pickedline,$lines)]); } @@ -192,16 +192,16 @@ function Exercises($pagename, $auth){ $answers[] = $pickedline; for ($i=1;$i<$n;$i++) { - $otherpage = $pages[rand(0,count($pages)-1)]; + $otherpage = $pages[array_rand($lines)]; $otherpage = $pages[array_rand($pages)]; unset($pages[array_search($otherpage,$pages)]); $content = ReadPage($otherpage,READPAGE_CURRENT); $text = $content["text"]; $lines = explode("\n",$text); - $pickedline = $lines[rand(0,count($lines)-1)]; + $pickedline = $lines[array_rand($lines)]; unset($lines[array_search($pickedline,$lines)]); while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { - $pickedline = $lines[rand(0,count($lines)-1)]; + $pickedline = $lines[array_rand($lines)]; unset($lines[array_search($pickedline,$lines)]); } $answers[] = $pickedline; @@ -213,10 +213,13 @@ function Exercises($pagename, $auth){ shuffle($answers); for ($i=0;$i<$n;$i++) { - $hashedanswer = md5($answers[$i]); + if ($answers[$i]==$actualanswer) + $hashedanswer = md5($sourcepage); + else + $hashedanswer = md5($answers[$i]); + // hashing the answer, NOT the page, but only used to hide so should not be problematic $result .="\n* [[$pagename?action=ExercisesCheck&".$counterparam ."type=$type&source=$sourcepage&answer=$hashedanswer|$i]] [@".$answers[$i]."@] "; - //should be better parsed! } $result .="\n\nClick on the answer."; @@ -229,7 +232,7 @@ function Exercises($pagename, $auth){ $pickedline = $lines[array_rand($lines)]; unset($lines[array_search($pickedline,$lines)]); while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { - $pickedline = $lines[rand(0,count($lines)-1)]; + $pickedline = $lines[array_rand($lines)]; unset($lines[array_search($pickedline,$lines)]); } $answers[] = $sourcepage; @@ -310,6 +313,9 @@ function ExercisesCheck($pagename, $auth){ $pages = ListPages("/$group\./e"); } + $result = ""; + $verbatimresult = ""; + switch ($type) { case "pagelink": $content = ReadPage($sourcepage,READPAGE_CURRENT); @@ -329,7 +335,11 @@ function ExercisesCheck($pagename, $auth){ } else { $result .="No, [[$sourcepage]] is not linked to [[$answer]] "; $result .="but $formattedlinks are. "; - if ($counter > 0) $result .="\nIt means you are losing your $counter points."; + if ($counter > 0){ + $result .="\nIt means you are losing your $counter points."; + // $halloffame = ExercisesResults(); + // to add to $verbatimresult to motivate playing again + } $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; } break; @@ -350,6 +360,7 @@ function ExercisesCheck($pagename, $auth){ } break; case "pagehasexpression": + // XXX does not work if ( md5($sourcepage) === $answer ) { $result .="Excellent! [[$sourcepage]] indeed has that expression."; if ( $counter > 0) { @@ -381,13 +392,13 @@ function ExercisesCheck($pagename, $auth){ $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; } break; - + default: $result .= "Exercise type unknown, this most likely indicate that the checking for the solution has not yet been implemented, please consider notifying the author. For now try [[$pagename?action=Exercises&type=random|a random type of exercise]]."; } $result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%"; $renderedresult = MarkupToHTML($pagename, $result); - print $renderedresult; + print $renderedresult.$verbatimresult; if ( ( isset($Author) ) && ( $counter > $score_lower_threshold ) ) { $score = "$counter,$Author,$type,".time()."\n"; $write_result = file_put_contents($activityfile,$score, FILE_APPEND | LOCK_EX);