From ab99b86308c88cd21d10b190e3a9b2a0bd240a2b Mon Sep 17 00:00:00 2001 From: Vasilis Daloukas Date: Wed, 15 Jul 2015 20:15:18 +0300 Subject: [PATCH] New: User defined language at hangman and crossword --- cross/play.php | 6 +++--- hangman/play.php | 2 +- lang/en/game.php | 1 + locallib.php | 33 +++++++++++++++++++++------------ mod_form.php | 5 +++++ version.php | 4 ++-- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cross/play.php b/cross/play.php index 1504b8c..fc4c9a2 100755 --- a/cross/play.php +++ b/cross/play.php @@ -457,7 +457,7 @@ function WordEntryKeyPress(event) // Returns true if the string passed in contains any characters prone to evil. function ContainsBadChars(theirWord) -{ +{return false; for (var i = 0; i < theirWord.length; i++) if (BadChars.indexOf(theirWord.charAt(i)) >= 0) return true; return false; @@ -693,7 +693,7 @@ function PackPuzzle( sData) s = s2.concat( s.substr( j)); } - return s; + return encodeURIComponent( s); } // Called when the "check server" link is clicked. @@ -735,7 +735,7 @@ function CheckServerClick( endofgame) } sData += UserEntry; } - + sData = PackPuzzle( sData); if( endofgame) diff --git a/hangman/play.php b/hangman/play.php index e06b835..d30dbe6 100755 --- a/hangman/play.php +++ b/hangman/play.php @@ -51,7 +51,7 @@ function game_hangman_continue( $id, $game, $attempt, $hangman, $newletter, $act $answer2 = str_replace( '-', '', $answer2); } - $allletters = game_getallletters( $answer2, $game->language); + $allletters = game_getallletters( $answer2, $game->language, $game->userlanguage); if( $allletters == ''){ continue; diff --git a/lang/en/game.php b/lang/en/game.php index 9adf047..65c5bcb 100755 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -241,6 +241,7 @@ $string[ 'hangman_showcorrectanswer'] = 'Show the correct answer after the end'; $string[ 'hangman_showfirst'] = 'Show first letter of hangman'; $string[ 'hangman_showlast'] = 'Show last letter of hangman'; $string[ 'hangman_showquestion'] = 'Show the questions ?'; +$string[ 'language_user_defined'] = 'User defined language'; $string[ 'hiddenpicture_across'] = 'Cells horizontal'; $string[ 'hiddenpicture_down'] = 'Cells down'; $string[ 'hiddenpicture_height'] = 'Set height of picture to (in pixels)'; diff --git a/locallib.php b/locallib.php index f878b75..53826d8 100755 --- a/locallib.php +++ b/locallib.php @@ -508,25 +508,34 @@ function game_detectlanguage( $word){ //The words maybe are in two languages e.g. greek or english //so I try to find the correct one. -function game_getallletters( $word, $lang='') +function game_getallletters( $word, $lang='', $userlanguage='') { for(;;) { - $strings = get_string_manager()->load_component_strings( 'game', ($lang == '' ? 'en' : $lang)); - if( isset( $strings[ 'lettersall'])) + if( $lang == 'user') { - $letters = $strings[ 'lettersall']; - $word2 = game_upper( $word, $lang); - if( hangman_existall( $word2, $letters)) + $letters = $userlanguage; + if( hangman_existall( $word, $letters)) return $letters; - } + else + return ''; + }else + { + $strings = get_string_manager()->load_component_strings( 'game', ($lang == '' ? 'en' : $lang)); + if( isset( $strings[ 'lettersall'])) + { + $letters = $strings[ 'lettersall']; + $word2 = game_upper( $word, $lang); + if( hangman_existall( $word2, $letters)) + return $letters; + } - if( $lang == '') - break; - else - $lang = ''; + if( $lang == '') + break; + else + $lang = ''; + } } - return ''; } diff --git a/mod_form.php b/mod_form.php index ff4668e..083be71 100755 --- a/mod_form.php +++ b/mod_form.php @@ -232,8 +232,13 @@ class mod_game_mod_form extends moodleform_mod { $a = array(); $a = get_string_manager()->get_list_of_translations(); $a[ ''] = '----------'; + $a[ 'user'] = get_string('language_user_defined', 'game'); ksort( $a); $mform->addElement('select', 'language', get_string('hangman_language','game'), $a); + + $mform->addElement('text', 'userlanguage', get_string('language_user_defined','game')); + $mform->setType('userlanguage', PARAM_TEXT); + $mform->disabledIf('userlanguage', 'language', 'neq', 'user'); } //--------------------------------------------------------------------------- diff --git a/version.php b/version.php index b6873ad..022ae53 100755 --- a/version.php +++ b/version.php @@ -22,10 +22,10 @@ if( !isset( $plugin)) $useplugin = 2; $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics) -$plugin->version = 2015071502; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2015071503; // The current module version (Date: YYYYMMDDXX) $plugin->requires = 2010112400; // Requires Moodle 2.0 $plugin->cron = 0; // Period for cron to check this module (secs) -$plugin->release = '3.30.15.2'; +$plugin->release = '3.30.15.3'; if( $useplugin != 2) $module = $plugin;