Browse Source

Fix: Backward compatibility with Moodle 2.0 and textlib

MOODLE_20_STABLE
root 12 years ago
parent
commit
138c3226e2
  1. 18
      attempt.php
  2. 84
      cross/cross_class.php
  3. 10
      cross/crossdb_class.php
  4. 2
      cross/play.php
  5. 40
      cryptex/cryptexdb_class.php
  6. 12
      cryptex/play.php
  7. 4
      exporthtml_hangman.php
  8. 2
      exporthtml_millionaire.php
  9. 24
      hangman/play.php
  10. 78
      locallib.php
  11. 6
      millionaire/play.php
  12. 10
      sudoku/play.php
  13. 4
      version.php

18
attempt.php

@ -223,17 +223,17 @@
function game_cross_unpackpuzzle( $g)
{
$ret = "";
$len = textlib::strlen( $g);
$len = game_strlen( $g);
while( $len)
{
for( $i=0; $i < $len; $i++)
{
$c = textlib::substr( $g, $i, 1);
$c = game_substr( $g, $i, 1);
if( $c >= '1' and $c <= '9'){
if( $i > 0){
//found escape character
if( textlib::substr( $g, $i-1, 1) == '/'){
$g = textlib::substr( $g, 0, $i-1).textlib::substr( $g, $i);
if( game_substr( $g, $i-1, 1) == '/'){
$g = game_substr( $g, 0, $i-1).game_substr( $g, $i);
$i--;
$len--;
continue;
@ -247,16 +247,16 @@ function game_cross_unpackpuzzle( $g)
//found the start of a number
for( $j=$i+1; $j < $len; $j++)
{
$c = textlib::substr( $g, $j, 1);
$c = game_substr( $g, $j, 1);
if( $c < '0' or $c > '9'){
break;
}
}
$count = textlib::substr( $g, $i, $j-$i);
$ret .= textlib::substr( $g, 0, $i) . str_repeat( '_', $count);
$count = game_substr( $g, $i, $j-$i);
$ret .= game_substr( $g, 0, $i) . str_repeat( '_', $count);
$g = textlib::substr( $g, $j);
$len = textlib::strlen( $g);
$g = game_substr( $g, $j);
$len = game_strlen( $g);
}else
{

84
cross/cross_class.php

@ -60,7 +60,7 @@ class Cross
$maxlen = 0;
foreach( $this->m_input_answers as $word => $answer)
{
$len = textlib::strlen( $word);
$len = game_strlen( $word);
if( $len > $maxlen){
$maxlen = $len;
}
@ -82,7 +82,7 @@ class Cross
$this->m_words = array();
foreach( $this->m_input_answers as $word => $answer)
{
$len =textlib::strlen( $word);
$len = game_strlen( $word);
if( $len <= $this->m_N20max){
$this->m_words[] = game_upper( $word);
@ -259,7 +259,7 @@ class Cross
$sum_rep = 0;
foreach( $cross_word as $word){
$word = textlib::substr( $word, 1, -1);
$word = game_substr( $word, 1, -1);
if( array_key_exists( $word, $this->m_reps))
$sum_rep += $this->m_reps[ $word] - $this->m_average_reps;
@ -293,7 +293,7 @@ class Cross
$row = floor( $pos / $N22);
$dir = $cross_dir[ $i];
$len = textlib::strlen($cross_word[ $i])-3;
$len = game_strlen($cross_word[ $i])-3;
if( $bPrint)
echo "col=$col row=$row dir=$dir word=".$cross_word[ $i]."<br>";
@ -415,7 +415,7 @@ class Cross
$ret = "<table border=0 cellpadding=2 cellspacing=1><tr>";
for ($n = 0;; $n ++) {
$c = textlib::substr( $puzzle, $n, 1);
$c = game_substr( $puzzle, $n, 1);
if (($m = $n % $N22) == 0 or $m == $N21 or $n < $N22 or $n > $N2200) {
$ret .= "<td class=marc> </td>";
@ -424,10 +424,10 @@ class Cross
} elseif ($c == '.') {
$ret .= "<td class=blanc> </td>";
} else {
if ((textlib::substr( $puzzle, $n - 1, 1) > '0' or
textlib::substr( $puzzle, $n + 1, 1) > '0') and
(textlib::substr( $puzzle, $n - $N22, 1) > '0'
or textlib::substr( $puzzle, $n + $N22, 1) > '0')) {
if ((game_substr( $puzzle, $n - 1, 1) > '0' or
game_substr( $puzzle, $n + 1, 1) > '0') and
(game_substr( $puzzle, $n - $N22, 1) > '0'
or game_substr( $puzzle, $n + $N22, 1) > '0')) {
$ret .= "<td align=center class=connector>$c</td>";
} else {
$ret .= "<td align=center class=filled>$c</td>";
@ -468,23 +468,23 @@ class Cross
$new_dir = 'h';
}
$regex = textlib::substr( $puzzle, $pos, 1);
$regex = game_substr( $puzzle, $pos, 1);
if ( ($regex == '0' or $regex == '.') and (! $val_blanc)){
return false;
}
if ((textlib::substr( $puzzle, $pos - $inc, 1) > '0')){
if ((game_substr( $puzzle, $pos - $inc, 1) > '0')){
return false;
}
if ((textlib::substr( $puzzle, $pos + $inc, 1) > '0')){
if ((game_substr( $puzzle, $pos + $inc, 1) > '0')){
return false;
}
$left = $right = 0;
for ($limit_a = $pos - $inc; ($w = textlib::substr( $puzzle, $limit_a, 1)) !== '0'; $limit_a -= $inc)
for ($limit_a = $pos - $inc; ($w = game_substr( $puzzle, $limit_a, 1)) !== '0'; $limit_a -= $inc)
{
if ($w == '.' and ((textlib::substr( $puzzle, $limit_a - $oinc, 1) > '0') or (textlib::substr( $puzzle, $limit_a + $oinc, 1) > '0'))){
if ($w == '.' and ((game_substr( $puzzle, $limit_a - $oinc, 1) > '0') or (game_substr( $puzzle, $limit_a + $oinc, 1) > '0'))){
break;
}
@ -496,9 +496,9 @@ class Cross
$regex = $w . $regex;
}
for ($limit_b = $pos + $inc; ($w = textlib::substr( $puzzle, $limit_b, 1)) !== '0'; $limit_b += $inc)
for ($limit_b = $pos + $inc; ($w = game_substr( $puzzle, $limit_b, 1)) !== '0'; $limit_b += $inc)
{
if ($w== '.' and ((textlib::substr( $puzzle, $limit_b - $oinc, 1) > '0') or (textlib::substr( $puzzle, $limit_b + $oinc, 1) > '0'))){
if ($w== '.' and ((game_substr( $puzzle, $limit_b - $oinc, 1) > '0') or (game_substr( $puzzle, $limit_b + $oinc, 1) > '0'))){
break;
}
@ -510,7 +510,7 @@ class Cross
$regex .= $w;
}
if (($len_regex = textlib::strlen($regex)) < 2){
if (($len_regex = game_strlen($regex)) < 2){
return false;
}
@ -523,36 +523,36 @@ class Cross
for($pos_c = $ini; $pos_c <= $fin; $pos_c++, $pos_p += $inc)
{
if (textlib::substr( $puzzle, $pos_p - $inc, 1) > '0'){
if (game_substr( $puzzle, $pos_p - $inc, 1) > '0'){
continue;
}
$w = textlib::substr($regex, $pos_c, $lens);
$w = game_substr($regex, $pos_c, $lens);
if( !$this->my_preg_match( $w, $words, $word))
continue;
$larr0 = $pos_p + ((textlib::strlen( $word) - 2) * $inc);
$larr0 = $pos_p + ((game_strlen( $word) - 2) * $inc);
if ($larr0 >= $N2222){
continue;
}
if (textlib::substr( $puzzle, $larr0, 1) > '0'){
if (game_substr( $puzzle, $larr0, 1) > '0'){
continue;
}
$words = str_replace( $word, ';', $words);
$len = textlib::strlen( $word) ;
$len = game_strlen( $word) ;
for ($n = 1, $pp = $pos_p; $n < $len - 1; $n++, $pp += $inc)
{
$this->setchar( $puzzle, $pp, textlib::substr( $word , $n, 1));
$this->setchar( $puzzle, $pp, game_substr( $word , $n, 1));
if ($pp == $pos)
continue;
$c = textlib::substr( $puzzle, $pp, 1);
$c = game_substr( $puzzle, $pp, 1);
$poss[] = array($pp, $new_dir, ord( $c));
}
@ -573,17 +573,17 @@ class Cross
function my_preg_match( $w, $words, &$word)
{
$a = explode( ";", $words);
$len_w = textlib::strlen( $w);
$len_w = game_strlen( $w);
foreach( $a as $test)
{
if( textlib::strlen( $test) != $len_w)
if( game_strlen( $test) != $len_w)
continue;
for( $i=0; $i <$len_w; $i++)
{
if( textlib::substr( $w, $i, 1) == '.')
if( game_substr( $w, $i, 1) == '.')
continue;
if( textlib::substr( $w, $i, 1) != textlib::substr( $test, $i, 1) )
if( game_substr( $w, $i, 1) != game_substr( $test, $i, 1) )
break;
}
if( $i < $len_w)
@ -601,9 +601,9 @@ class Cross
$ret = "";
if( $pos > 0)
$ret .= textlib::substr( $s, 0, $pos);
$ret .= game_substr( $s, 0, $pos);
$s = $ret . $char . textlib::substr( $s, $pos+1, textlib::strlen( $s)-$pos-1);
$s = $ret . $char . game_substr( $s, $pos+1, game_strlen( $s)-$pos-1);
}
function showhtml_base( $crossm, $crossd, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game)
@ -640,7 +640,7 @@ class Cross
$i++;
$sWordLength .= ",".textlib::strlen( $rec->answertext);
$sWordLength .= ",".game_strlen( $rec->answertext);
if( $rec->questionid != 0)
{
$q = game_filterquestion(str_replace( '\"', '"', $rec->questiontext), $rec->questionid, $context->id, $game->course);
@ -705,7 +705,7 @@ class Cross
{
for( $i=0; $i < count( $value); $i++)
{
$this->m_LegendH[ $key.textlib::substr( $letters, $i, 1)] = $value[ $i];
$this->m_LegendH[ $key.game_substr( $letters, $i, 1)] = $value[ $i];
}
}
}
@ -719,7 +719,7 @@ class Cross
{
for( $i=0; $i < count( $value); $i++)
{
$this->m_LegendV[ $key.textlib::substr( $letters, $i, 1)] = $value[ $i];
$this->m_LegendV[ $key.game_substr( $letters, $i, 1)] = $value[ $i];
}
}
}
@ -727,16 +727,16 @@ class Cross
ksort( $this->m_LegendH);
ksort( $this->m_LegendV);
$sRet .= "WordLength = new Array( ".textlib::substr( $sWordLength, 1).");\n";
$sRet .= "Clue = new Array( ".textlib::substr( $sClue, 1).");\n";
$sRet .= "WordLength = new Array( ".game_substr( $sWordLength, 1).");\n";
$sRet .= "Clue = new Array( ".game_substr( $sClue, 1).");\n";
$sguess = str_replace( ' ', '_', $sguess);
$sRet .= "Guess = new Array( ".textlib::substr( $sguess, 1).");\n";
$sRet .= "Solutions = new Array( ".textlib::substr( $ssolutions, 1).");\n";
$sRet .= "Guess = new Array( ".game_substr( $sguess, 1).");\n";
$sRet .= "Solutions = new Array( ".game_substr( $ssolutions, 1).");\n";
if( $showhtmlsolutions){
$sRet .= "HtmlSolutions = new Array( ".textlib::substr( $shtmlsolutions, 1).");\n";
$sRet .= "HtmlSolutions = new Array( ".game_substr( $shtmlsolutions, 1).");\n";
}
$sRet .= "WordX = new Array( ".textlib::substr( $sWordX, 1).");\n";
$sRet .= "WordY = new Array( ".textlib::substr( $sWordY, 1).");\n";
$sRet .= "WordX = new Array( ".game_substr( $sWordX, 1).");\n";
$sRet .= "WordY = new Array( ".game_substr( $sWordY, 1).");\n";
$sRet .= "LastHorizontalWord = $LastHorizontalWord;\n";
return $sRet;
@ -744,11 +744,11 @@ class Cross
function cmp($a, $b) {
return textlib::strlen($b) - textlib::strlen($a);
return game_strlen($b) - game_strlen($a);
}
function cmp_magic($a, $b) {
return (textlib::strlen($a) + mt_rand(0, 3)) - (textlib::strlen($b) - mt_rand(0, 1));
return (game_strlen($a) + mt_rand(0, 3)) - (game_strlen($b) - mt_rand(0, 1));
}
}

10
cross/crossdb_class.php

@ -182,28 +182,28 @@ function game_cross_computecheck( $correctletters, $wrongletters, $restletters,
global $DB, $USER;
$word = $rec->answertext;
$len = textlib::strlen( $word);
$len = game_strlen( $word);
if( $loadfromdb)
$guess = $rec->studentanswer;
else
$guess = textlib::substr( $g, $pos, $len);
$guess = game_substr( $g, $pos, $len);
$len_guess = textlib::strlen( $guess);;
$len_guess = game_strlen( $guess);;
$pos += $len;
$is_empty = true;
for($i = 0; $i < $len; $i++)
{
if( $i < $len_guess)
$letterguess = textlib::substr( $guess, $i, 1);
$letterguess = game_substr( $guess, $i, 1);
else
$letterguess = " ";
if( $letterguess != ' ')
$is_empty = false;
$letterword= textlib::substr( $word, $i, 1);
$letterword= game_substr( $word, $i, 1);
if( $letterword != $letterguess)
{
if( ($letterguess != ' ' and $letterguess != '_')){

2
cross/play.php

@ -45,7 +45,7 @@ function game_cross_new( $game, $attemptid, &$crossm)
$reps = array();
foreach( $recs as $rec){
if( $game->param7 == false){
if( textlib::strpos( $rec->answertext, ' ')){
if( game_strpos( $rec->answertext, ' ')){
continue; //spaces not allowed
}
}

40
cryptex/cryptexdb_class.php

@ -39,11 +39,11 @@ class CryptexDB extends CrossDB
{
$pos = $rec->col - 1 + ($rec->row-1) * $cols;
$s = $rec->answertext;
$len = textlib::strlen( $s);
$len = game_strlen( $s);
$a = array();
for( $i=0; $i < $len; $i++){
$a[] = textlib::substr( $s, $i, 1);
$a[] = game_substr( $s, $i, 1);
}
for( $i=0; $i < $len; $i++){
@ -57,10 +57,10 @@ class CryptexDB extends CrossDB
}
}
$len = textlib::strlen( $letters);
$len = game_strlen( $letters);
$spaces = 0;
for( $i=0; $i < $len; $i++){
if( textlib::substr( $letters, $i, 1) == '.'){
if( game_substr( $letters, $i, 1) == '.'){
$spaces++;
}
}
@ -82,7 +82,7 @@ class CryptexDB extends CrossDB
$ret_letters = "";
for( $row=0; $row < $crossm->rows; $row++){
$ret_letters .= textlib::substr( $letters, $cols * $row, ($cols-1));
$ret_letters .= game_substr( $letters, $cols * $row, ($cols-1));
}
@ -97,8 +97,8 @@ class CryptexDB extends CrossDB
echo "<tr>";
for( $col=0; $col < $cols; $col++){
$pos = $cols * $row+$col;
$c = textlib::substr( $letters, $pos, 1);
$m = textlib::substr( $mask, $pos, 1);
$c = game_substr( $letters, $pos, 1);
$m = game_substr( $mask, $pos, 1);
if( $showsolution and $m > '0'){
echo "<td align=center><b><FONT color=red>".$c."</font></td>";
@ -116,9 +116,9 @@ class CryptexDB extends CrossDB
function insertchar( &$letters, $cols, $rows, $char, &$spaces)
{
$len = textlib::strlen( $letters);
$len = game_strlen( $letters);
for( $i=0; $i < $len; $i++){
if( textlib::substr( $letters, $i, 1) == '.'){
if( game_substr( $letters, $i, 1) == '.'){
$this->setchar( $letters, $i, $char);
$spaces--;
return;
@ -128,17 +128,17 @@ class CryptexDB extends CrossDB
function insertchars( &$letters, $cols, $rows, $char, &$spaces)
{
$len = textlib::strlen( $letters);
$len = game_strlen( $letters);
for( $i=0; $i < $len; $i++){
if( textlib::substr( $letters, $i, 1) == '.' and textlib::substr( $letters, $i+1, 1) == '.' ){
$this->setchar( $letters, $i, textlib::substr( $char, 0, 1));
$this->setchar( $letters, $i+1, textlib::substr( $char, 1, 1));
if( game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i+1, 1) == '.' ){
$this->setchar( $letters, $i, game_substr( $char, 0, 1));
$this->setchar( $letters, $i+1, game_substr( $char, 1, 1));
$spaces-=2;
return true;
}
if( textlib::substr( $letters, $i, 1) == '.' and textlib::substr( $letters, $i+$cols+1, 1) == '.' ){
$this->setchar( $letters, $i, textlib::substr( $char, 0, 1));
$this->setchar( $letters, $i + $cols+1, textlib::substr( $char, 1, 1));
if( game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i+$cols+1, 1) == '.' ){
$this->setchar( $letters, $i, game_substr( $char, 0, 1));
$this->setchar( $letters, $i + $cols+1, game_substr( $char, 1, 1));
$spaces-=2;
return true;
}
@ -150,10 +150,10 @@ class CryptexDB extends CrossDB
function gethash( $word)
{
$x = 37;
$len = count( textlib::strlen( $word));
$len = count( game_strlen( $word));
for($i=0; $i < $len; $i++){
$x = $x xor ord( textlib::substr( $word, $i, 1));
$x = $x xor ord( game_substr( $word, $i, 1));
}
return $x;
@ -180,14 +180,14 @@ class CryptexDB extends CrossDB
$word = $rec->answertext;
$pos = $crossm->cols * ($rec->row-1)+($rec->col-1);
$len = textlib::strlen( $word);
$len = game_strlen( $word);
$found = ($rec->answertext == $rec->studentanswer);
for( $i=0; $i < $len; $i++)
{
$c = ( $found ? '1' : '2');
if( textlib::substr( $mask, $pos, 1) != '1'){
if( game_substr( $mask, $pos, 1) != '1'){
game_setchar( $mask, $pos, $c);
}

12
cryptex/play.php

@ -42,7 +42,7 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $
$reps = array();
foreach( $recs as $rec){
if( $game->param7 == false){
if( textlib::strpos( $rec->answertext, ' ')){
if( game_strpos( $rec->answertext, ' ')){
continue; //spaces not allowed
}
}
@ -100,13 +100,13 @@ function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $co
$answer1 = trim( game_upper( $query->answertext));
$answer2 = trim( game_upper( $answer));
$len1 = textlib::strlen( $answer1);
$len2 = textlib::strlen( $answer2);
$len1 = game_strlen( $answer1);
$len2 = game_strlen( $answer2);
$equal = ( $len1 == $len2);
if( $equal){
for( $i=0; $i < $len1; $i++)
{
if( textlib::substr( $answer1, $i, 1) != textlib::substr( $answer2, $i, 1))
if( game_substr( $answer1, $i, 1) != game_substr( $answer2, $i, 1))
{
$equal = true;
break;
@ -159,14 +159,14 @@ function game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, $updatea
else
$textdir = '';
$len = textlib::strlen( $mask);
$len = game_strlen( $mask);
//count1 means there is a guested letter
//count2 means there is a letter that not guessed
$count1 = $count2 = 0;
for($i=0; $i < $len; $i++)
{
$c = textlib::substr( $mask, $i, 1);
$c = game_substr( $mask, $i, 1);
if( $c == '1'){
$count1++;
}else if( $c == '2')

4
exporthtml_hangman.php

@ -103,12 +103,12 @@ var used_letters = "";
var wrong_guesses = 0;
var used_letters_all = "";
var all_letters = new Array(<?php
$len = textlib::strlen( $allletters);
$len = game_strlen( $allletters);
for( $i=0; $i < $len; $i++)
{
if( $i > 0)
echo ',';
echo '"'.textlib::substr( $allletters, $i, 1).'"';
echo '"'.game_substr( $allletters, $i, 1).'"';
}
?>);

2
exporthtml_millionaire.php

@ -500,7 +500,7 @@ var Base64 = {
$letters = get_string( 'lettersall', 'game');
for($i=1 ; $i <= $maxquestions; $i++)
{
$s = textlib::substr( $letters, $i-1, 1);
$s = game_substr( $letters, $i-1, 1);
echo "<tr>\n";
echo "<td style='background:$colorback;color:$color1'>";
echo "<input style=\"background:$colorback;color:$color1;\" type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";

24
hangman/play.php

@ -154,10 +154,10 @@ function game_hangman_continue( $id, $game, $attempt, $hangman, $newletter, $act
$letters = '';
if( $game->param1){
$letters .= textlib::substr( $min->answer, 0, 1);
$letters .= game_substr3( $min->answer, 0, 1);
}
if( $game->param2){
$letters .= textlib::substr( $min->answer, -1, 1);
$letters .= game_substr3( $min->answer, -1, 1);
}
$newrec->letters = $letters;
@ -285,7 +285,7 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
$letters = $hangman->letters;
if( $newletter != NULL)
{
if( textlib::strpos( $letters,$newletter) === false){
if( game_strpos( $letters,$newletter) === false){
$letters .= $newletter;
}
}
@ -320,21 +320,21 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
$word_line = $word_line2 = "";
$len = textlib::strlen( $word);
$len = game_strlen( $word);
$done = 1;
$answer = '';
$correct = 0;
for ($x=0; $x < $len; $x++)
{
$char = textlib::substr( $word, $x, 1);
$char = game_substr3( $word, $x, 1);
if( $showsolution){
$word_line2 .= ( $char == " " ? '&nbsp; ' : $char);
$done = 0;
}
if ( textlib::strpos($letters, $char) === false){
if ( game_strpos($letters, $char) === false){
$word_line.="_<font size=\"1\">&nbsp;</font>\r\n";
$done = 0;
$answer .= '_';
@ -346,14 +346,14 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
}
}
$len_alpha = textlib::strlen($alpha);
$len_alpha = game_strlen($alpha);
$fontsize = 5;
for ($c=0; $c < $len_alpha; $c++)
{
$char = textlib::substr( $alpha, $c, 1);
$char = game_substr3( $alpha, $c, 1);
if ( textlib::strpos($letters, $char) === false)
if ( game_strpos($letters, $char) === false)
{
//User doesn't select this character
$params = 'id='.$id.'&amp;newletter='.urlencode( $char);
@ -366,7 +366,7 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
continue;
}
if ( textlib::strpos($word, $char) === false)
if ( game_strpos($word, $char) === false)
{
$links .= "\r\n<font size=\"$fontsize\" color=\"red\">$char </font>";
$wrong++;
@ -399,7 +399,7 @@ function hangman_showpage(&$done, &$correct, &$wrong, $max, &$word_line, &$word_
}
$query->percent = ($correct -$wrong/$max) / textlib::strlen( $word);
$query->percent = ($correct -$wrong/$max) / game_strlen( $word);
if( $query->percent < 0){
$query->percent = 0;
}
@ -454,7 +454,7 @@ function hangman_onincorrect( $id, $word_line, $word, $game, $attempt, $hangman,
if( $game->param6){
//show the correct answer
if( textlib::strpos($word, ' ') != false)
if( game_strpos($word, ' ') != false)
echo '<br/>'.get_string( 'hangman_correct_phrase', 'game');
else
echo '<br/>'.get_string( 'hangman_correct_word', 'game');

78
locallib.php

@ -30,10 +30,28 @@ define( "CONST_GAME_TRIES_REPETITION", "3");
/**#@-*/
function game_get_moodle_version()
{
global $DB;
static $s_moodle_version = null;
if( $s_moodle_version != null)
return $s_moodle_version;
$rec = $DB->get_record_select( 'config', "name='release'");
if( $rec == false)
return $s_moodle_version='';
else
{
$a = explode( '.', $rec->value);
return $s_moodle_version = sprintf( '%02u.%02u', $a[ 0], $a[ 1]);
}
}
function game_upper( $str, $lang='')
{
$str = textlib::strtoupper( $str);
$str = game_strtoupper( $str);
$strings = get_string_manager()->load_component_strings( 'game', ($lang == '' ? 'en' : $lang));
if( !isset( $strings[ 'convertfrom']))
@ -43,9 +61,9 @@ function game_upper( $str, $lang='')
$from = $strings[ 'convertfrom'];
$to = $strings[ 'convertto'];
$len = textlib::strlen( $from);
$len = game_strlen( $from);
for($i=0; $i < $len; $i++){
$str = str_replace( textlib::substr( $from, $i, 1), textlib::substr( $to, $i, 1), $str);
$str = str_replace( game_substr( $from, $i, 1), game_substr( $to, $i, 1), $str);
}
return $str;
@ -483,13 +501,12 @@ function game_getallletters( $word, $lang='')
return '';
}
function hangman_existall( $str, $strfind)
{
$n = textlib::strlen( $str);
$n = game_strlen( $str);
for( $i=0; $i < $n; $i++)
{
$pos = textlib::strpos( $strfind, textlib::substr( $str, $i, 1));
$pos = game_strpos( $strfind, game_substr( $str, $i, 1));
if( $pos === false)
return false;
}
@ -620,10 +637,10 @@ function game_questions_shortanswer_question_fraction( $table, $fields, $select)
$ret = "";
if( $pos > 0){
$ret .= textlib::substr( $s, 0, $pos);
$ret .= game_substr( $s, 0, $pos);
}
$s = $ret . $char . textlib::substr( $s, $pos+1);
$s = $ret . $char . game_substr( $s, $pos+1);
}
@ -1925,3 +1942,48 @@ function game_can_start_new_attempt( $game)
else
return true;
}
function game_strlen( $str)
{
if( game_get_moodle_version() < '02.05')
return textlib_get_instance()->strlen( $str);
else
return textlib::strlen( $str);
}
function game_substr()
{
$num = func_num_args();
$a = func_get_args();
if( $num == 3)
{
if( game_get_moodle_version() < '02.05')
return textlib_get_instance()->substr( $a[ 0], $a[ 1], $a[ 2]);
else
return textlib::ubstr( $a[ 0], $a[ 1], $a[ 2]);
}else if( $num == 2)
{
if( game_get_moodle_version() < '02.05')
return textlib_get_instance()->substr( $a[ 0], $a[ 1]);
else
return textlib::ubstr( $a[ 0], $a[ 1]);
}else
die( 'Substr requires 2 or 3 parameters');
}
function game_strtoupper( $str)
{
if( game_get_moodle_version() < '02.05')
return textlib_get_instance()->qstrtoupper( $str);
else
return textlib::strtoupper( $str);
}
function game_strpos( $haystack, $needle, $offset = 0)
{
if( game_get_moodle_version() < '02.05')
return textlib_get_instance()->strpos( $haystack, $needle, $offset);
else
return textlib::strtoupper( $haystack, $needle, $offset);
}

6
millionaire/play.php

@ -223,7 +223,7 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
for( $i=1; $i <= count( $aAnswer); $i++)
{
$name = "btAnswer".$i;
$s = textlib::substr( $letters, $i-1, 1);
$s = game_substr( $letters, $i-1, 1);
$disabled = ( $state == 15 ? "disabled=1" : "");
@ -560,10 +560,10 @@ function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $conte
$info = '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';
for( $i=0; $i < $n; $i++){
$info .= "<br>". textlib::substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$aPercent[ $i]. ' %';
$info .= "<br>". game_substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$aPercent[ $i]. ' %';
}
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, textlib::substr( $info, 4), $context);
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, game_substr( $info, 4), $context);
}

10
sudoku/play.php

@ -184,10 +184,10 @@ function game_sudoku_getclosed( $data)
{
$a = array();
$n = textlib::strlen( $data);
$n = game_strlen( $data);
for( $i=1; $i <= $n; $i++)
{
$c = textlib::substr( $data, $i-1, 1);
$c = game_substr( $data, $i-1, 1);
if( $c >= "1" and $c <= "9")
$a[ $i] = $i;
}
@ -608,7 +608,7 @@ function game_sudoku_check_number( $id, $game, $attempt, $sudoku, $pos, $num, $c
{
global $DB;
$correct = textlib::substr( $sudoku->data, $pos-1, 1);
$correct = game_substr( $sudoku->data, $pos-1, 1);
if( $correct != $num)
{
@ -616,8 +616,8 @@ function game_sudoku_check_number( $id, $game, $attempt, $sudoku, $pos, $num, $c
return;
}
$leng = textlib::strlen( $sudoku->guess);
$lend = textlib::strlen( $sudoku->data);
$leng = game_strlen( $sudoku->guess);
$lend = game_strlen( $sudoku->data);
if( $leng < $lend){
$sudoku->guess .= str_repeat( ' ', $lend - $leng);
}

4
version.php

@ -11,7 +11,7 @@
defined('MOODLE_INTERNAL') || die();
$module->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$module->version = 2013082201; // The current module version (Date: YYYYMMDDXX)
$module->version = 2013082401; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2010112400; // Requires Moodle 2.0
$module->cron = 0; // Period for cron to check this module (secs)
$module->release = '3.8.22';
$module->release = '3.8.24';

Loading…
Cancel
Save