|
|
@ -42,7 +42,7 @@ SDV($HandleActions['Exercises'], 'Exercises'); |
|
|
|
SDV($HandleAuth['Exercises'],'read'); |
|
|
|
SDV($HandleAuth['Exercises'],'read'); |
|
|
|
|
|
|
|
|
|
|
|
function Exercises($pagename, $auth){ |
|
|
|
function Exercises($pagename, $auth){ |
|
|
|
global $ScriptUrl; |
|
|
|
global $ScriptUrl, $FarmD; |
|
|
|
$type = $_GET["type"]; |
|
|
|
$type = $_GET["type"]; |
|
|
|
$counter = (int) $_GET["counter"]; |
|
|
|
$counter = (int) $_GET["counter"]; |
|
|
|
$difficulty = (int) $_GET["difficulty"]; |
|
|
|
$difficulty = (int) $_GET["difficulty"]; |
|
|
@ -179,12 +179,12 @@ function Exercises($pagename, $auth){ |
|
|
|
$text = $content["text"]; |
|
|
|
$text = $content["text"]; |
|
|
|
$lines = explode("\n",$text); |
|
|
|
$lines = explode("\n",$text); |
|
|
|
|
|
|
|
|
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
$pickedline = $lines[array_rand($lines)]; |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
// remove markups |
|
|
|
//should be better parsed! e.g. remove markups |
|
|
|
//pregreplace("/(:.*:)/","",$pickedline); |
|
|
|
//pregreplace("/(:.*:)/","",$pickedline); |
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
$pickedline = $lines[array_rand($lines)]; |
|
|
|
//pregreplace("/(:.*:)/","",$pickedline); |
|
|
|
//pregreplace("/(:.*:)/","",$pickedline); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
} |
|
|
|
} |
|
|
@ -192,16 +192,16 @@ function Exercises($pagename, $auth){ |
|
|
|
$answers[] = $pickedline; |
|
|
|
$answers[] = $pickedline; |
|
|
|
|
|
|
|
|
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
for ($i=1;$i<$n;$i++) { |
|
|
|
$otherpage = $pages[rand(0,count($pages)-1)]; |
|
|
|
$otherpage = $pages[array_rand($lines)]; |
|
|
|
$otherpage = $pages[array_rand($pages)]; |
|
|
|
$otherpage = $pages[array_rand($pages)]; |
|
|
|
unset($pages[array_search($otherpage,$pages)]); |
|
|
|
unset($pages[array_search($otherpage,$pages)]); |
|
|
|
$content = ReadPage($otherpage,READPAGE_CURRENT); |
|
|
|
$content = ReadPage($otherpage,READPAGE_CURRENT); |
|
|
|
$text = $content["text"]; |
|
|
|
$text = $content["text"]; |
|
|
|
$lines = explode("\n",$text); |
|
|
|
$lines = explode("\n",$text); |
|
|
|
$pickedline = $lines[rand(0,count($lines)-1)]; |
|
|
|
$pickedline = $lines[array_rand($lines)]; |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
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)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
} |
|
|
|
} |
|
|
|
$answers[] = $pickedline; |
|
|
|
$answers[] = $pickedline; |
|
|
@ -213,10 +213,13 @@ function Exercises($pagename, $auth){ |
|
|
|
shuffle($answers); |
|
|
|
shuffle($answers); |
|
|
|
|
|
|
|
|
|
|
|
for ($i=0;$i<$n;$i++) { |
|
|
|
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 |
|
|
|
$result .="\n* [[$pagename?action=ExercisesCheck&".$counterparam |
|
|
|
."type=$type&source=$sourcepage&answer=$hashedanswer|$i]] [@".$answers[$i]."@] "; |
|
|
|
."type=$type&source=$sourcepage&answer=$hashedanswer|$i]] [@".$answers[$i]."@] "; |
|
|
|
//should be better parsed! |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
$result .="\n\nClick on the answer."; |
|
|
|
$result .="\n\nClick on the answer."; |
|
|
|
|
|
|
|
|
|
|
@ -229,7 +232,7 @@ function Exercises($pagename, $auth){ |
|
|
|
$pickedline = $lines[array_rand($lines)]; |
|
|
|
$pickedline = $lines[array_rand($lines)]; |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
while (( strlen($pickedline) < $minlinelength ) && ( count($lines) > 0 ) ) { |
|
|
|
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)]); |
|
|
|
unset($lines[array_search($pickedline,$lines)]); |
|
|
|
} |
|
|
|
} |
|
|
|
$answers[] = $sourcepage; |
|
|
|
$answers[] = $sourcepage; |
|
|
@ -310,6 +313,9 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
$pages = ListPages("/$group\./e"); |
|
|
|
$pages = ListPages("/$group\./e"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = ""; |
|
|
|
|
|
|
|
$verbatimresult = ""; |
|
|
|
|
|
|
|
|
|
|
|
switch ($type) { |
|
|
|
switch ($type) { |
|
|
|
case "pagelink": |
|
|
|
case "pagelink": |
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT); |
|
|
|
$content = ReadPage($sourcepage,READPAGE_CURRENT); |
|
|
@ -329,7 +335,11 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$result .="No, [[$sourcepage]] is not linked to [[$answer]] "; |
|
|
|
$result .="No, [[$sourcepage]] is not linked to [[$answer]] "; |
|
|
|
$result .="but $formattedlinks are. "; |
|
|
|
$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]]. "; |
|
|
|
$result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -350,6 +360,7 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "pagehasexpression": |
|
|
|
case "pagehasexpression": |
|
|
|
|
|
|
|
// XXX does not work |
|
|
|
if ( md5($sourcepage) === $answer ) { |
|
|
|
if ( md5($sourcepage) === $answer ) { |
|
|
|
$result .="Excellent! [[$sourcepage]] indeed has that expression."; |
|
|
|
$result .="Excellent! [[$sourcepage]] indeed has that expression."; |
|
|
|
if ( $counter > 0) { |
|
|
|
if ( $counter > 0) { |
|
|
@ -387,7 +398,7 @@ function ExercisesCheck($pagename, $auth){ |
|
|
|
} |
|
|
|
} |
|
|
|
$result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%"; |
|
|
|
$result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%"; |
|
|
|
$renderedresult = MarkupToHTML($pagename, $result); |
|
|
|
$renderedresult = MarkupToHTML($pagename, $result); |
|
|
|
print $renderedresult; |
|
|
|
print $renderedresult.$verbatimresult; |
|
|
|
if ( ( isset($Author) ) && ( $counter > $score_lower_threshold ) ) { |
|
|
|
if ( ( isset($Author) ) && ( $counter > $score_lower_threshold ) ) { |
|
|
|
$score = "$counter,$Author,$type,".time()."\n"; |
|
|
|
$score = "$counter,$Author,$type,".time()."\n"; |
|
|
|
$write_result = file_put_contents($activityfile,$score, FILE_APPEND | LOCK_EX); |
|
|
|
$write_result = file_put_contents($activityfile,$score, FILE_APPEND | LOCK_EX); |
|
|
|