### Eclipse Workspace Patch 1.0
#P moodle
Index: admin/settings/misc.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/misc.php,v
retrieving revision 1.9
diff -u -r1.9 misc.php
--- admin/settings/misc.php	30 Oct 2006 21:01:47 -0000	1.9
+++ admin/settings/misc.php	11 Dec 2006 22:43:04 -0000
@@ -16,5 +16,6 @@
 $ADMIN->add('misc', new admin_externalpage('oacleanup', 'Online Assignment Cleanup', $CFG->wwwroot.'/'.$CFG->admin.'/oacleanup.php', 'moodle/site:config', true));
 $ADMIN->add('misc', new admin_externalpage('upgradeforumread', 'Upgrade forum', $CFG->wwwroot.'/'.$CFG->admin.'/upgradeforumread.php', 'moodle/site:config', true));
 $ADMIN->add('misc', new admin_externalpage('upgradelogs', 'Upgrade logs', $CFG->wwwroot.'/'.$CFG->admin.'/upgradelogs.php', 'moodle/site:config', true));
+$ADMIN->add('misc', new admin_externalpage('multilangupgrade', get_string('multilangupgrade', 'admin'), $CFG->wwwroot.'/'.$CFG->admin.'/multilangupgrade.php', 'moodle/site:config', true));
 
 ?>
Index: filter/multilang/README.txt
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/multilang/README.txt,v
retrieving revision 1.5
diff -u -r1.5 README.txt
--- filter/multilang/README.txt	14 Aug 2006 07:46:03 -0000	1.5
+++ filter/multilang/README.txt	11 Dec 2006 22:43:04 -0000
@@ -6,7 +6,7 @@
 To Use it:
     - Create your contents in multiple languages.
     - Enclose every language content between:
-        <span lang="XX">your_content_here</span>
+        <span lang="XX" class="multilang">your_content_here</span><span lang="YY" class="multilang">your_content_other_lang</span>
     - Test it (by changing your language).
 
 How it works:
@@ -23,9 +23,9 @@
 
 One example in action:
     - This text:
-        <span lang="en">Hello!</span><span lang="es">Hola!</span>
+        <span lang="en" class="multilang">Hello!</span><span lang="es" class="multilang">Hola!</span>
         This text is common for every language because it's out from any lang block.
-        <span lang="en">Bye!</span><span lang="it">Ciao!</span>
+        <span lang="en" class="multilang">Bye!</span><span lang="it" class="multilang">Ciao!</span>
 
     - Will print, if current language is English:
         Hello!
@@ -41,3 +41,7 @@
 Ciao, Eloy :-)
 stronk7@moodle.org
 2005-11-16
+
+Ciao, skodak :-)
+Syntax chnged in 1.8, old filter was renamed to 'multilangold'.
+2006-12-11
\ No newline at end of file
Index: filter/multilang/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/multilang/filter.php,v
retrieving revision 1.16
diff -u -r1.16 filter.php
--- filter/multilang/filter.php	15 Sep 2006 08:23:40 -0000	1.16
+++ filter/multilang/filter.php	11 Dec 2006 22:43:04 -0000
@@ -23,25 +23,26 @@
 ///////////////////////////////////////////////////////////////////////////
 
 // Given XML multilinguage text, return relevant text according to
-// current language.  i.e.=
-//   - look for lang sections in the code.
+// current language:
+//   - look for multilang blocks in the text.
 //   - if there exists texts in the currently active language, print them.
 //   - else, if there exists texts in the current parent language, print them.
 //   - else, print the first language in the text.
 // Please note that English texts are not used as default anymore!
 //
-// This is an improved version of the original multilang filter by Gaetan Frenoy. 
-// It should be 100% compatible with the original one. Some new features are:
-//   - Supports a new "short" syntax to make things easier. Simply use:
-//         <span lang="XX">
-//   - Needs less resources and executes faster.
-//   - Allows any type of content to be used. No restrictions at all!
+// This version is based on original multilang filter by Gaetan Frenoy,
+// rewritten by Eloy and skodak.
+//
+// This version is not backwards compatible with old multilang syntax.
+// Syntax is:
+//   <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
 
 function multilang_filter($courseid, $text) {
 
     // [pj] I don't know about you but I find this new implementation funny :P
     // [skodak] I was laughing while rewriting it ;-)
-    $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>\s*)+/is';
+
+    $search = '/(<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)(\s*<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)*/is';
     return preg_replace_callback($search, 'multilang_filter_impl', $text);
 }
 
@@ -58,7 +59,7 @@
         $parentlang = $parentcache[$mylang];
     }
 
-    $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    $searchtosplit = '/<span lang="([a-zA-Z0-9_-]+)" class="multilang">(.+?)<\/span>/is';
     preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
 
     $langlist = array();
Index: filter/multilangold/filter.php
===================================================================
RCS file: filter/multilangold/filter.php
diff -N filter/multilangold/filter.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ filter/multilangold/filter.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,84 @@
+<?php //$Id: filter.php,v 1.16 2006/09/15 08:23:40 moodler Exp $
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// This program is part of Moodle - Modular Object-Oriented Dynamic      //
+// Learning Environment - http://moodle.org                              //
+//                                                                       //
+// Copyright (C) 2004  Gaetan Frenoy <gaetan@frenoy.net>                 //
+//                     Eloy Lafuente <stronk7@moodle.org>                //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+// Given XML multilinguage text, return relevant text according to
+// current language.  i.e.=
+//   - look for lang sections in the code.
+//   - if there exists texts in the currently active language, print them.
+//   - else, if there exists texts in the current parent language, print them.
+//   - else, print the first language in the text.
+// Please note that English texts are not used as default anymore!
+//
+// This is an improved version of the original multilang filter by Gaetan Frenoy. 
+// It should be 100% compatible with the original one. Some new features are:
+//   - Supports a new "short" syntax to make things easier. Simply use:
+//         <span lang="XX">
+//   - Needs less resources and executes faster.
+//   - Allows any type of content to be used. No restrictions at all!
+
+//NOTICE - this is the original pre 1.8 multilang filter, not recommended anymore
+//       - please convert the existing data and use the new multilang filter and syntax
+
+
+function multilangold_filter($courseid, $text) {
+
+    // [pj] I don't know about you but I find this new implementation funny :P
+    // [skodak] I was laughing while rewriting it ;-)
+    $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>\s*)+/is';
+    return preg_replace_callback($search, 'multilangold_filter_impl', $text);
+}
+
+function multilangold_filter_impl($langblock) {
+    $mylang = str_replace('_utf8', '', current_language());
+    static $parentcache;
+    if (!isset($parentcache)) {
+        $parentcache = array();
+    }
+    if (!array_key_exists($mylang, $parentcache)) {
+        $parentlang = str_replace('_utf8', '', get_string('parentlanguage'));
+        $parentcache[$mylang] = $parentlang;
+    } else {
+        $parentlang = $parentcache[$mylang];
+    }
+
+    $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
+
+    $langlist = array();
+    foreach ($rawlanglist[1] as $index=>$lang) {
+        $lang = str_replace('_utf8', '', str_replace('-','_',strtolower($lang))); // normalize languages
+        $langlist[$lang] = $rawlanglist[2][$index];
+    }
+
+    if (array_key_exists($mylang, $langlist)) {
+        return $langlist[$mylang];
+    } else if (array_key_exists($parentlang, $langlist)) {
+        return $langlist[$parentlang];
+    } else {
+        $first = array_shift($langlist);
+        return $first;
+    }
+}
+
+?>
Index: filter/multilangold/README.txt
===================================================================
RCS file: filter/multilangold/README.txt
diff -N filter/multilangold/README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ filter/multilangold/README.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,46 @@
+$Id: README.txt,v 1.5 2006/08/14 07:46:03 skodak Exp $
+
+NOTICE - this is the original pre 1.8 multilang filter, not recommended anymore
+       - please convert the existing data and use the new multilang filter and syntax
+
+To Install it:
+    - Enable if from "Administration/Filters".
+  
+To Use it:
+    - Create your contents in multiple languages.
+    - Enclose every language content between:
+        <span lang="XX">your_content_here</span>
+    - Test it (by changing your language).
+
+How it works:
+    - look for "lang blocks" in the code.
+    - for each "lang block":
+        - if there are texts in the currently active language, print them.
+        - else, if there exists texts in the current parent language, print them.
+        - else, print the first language found in the text.
+    - text out of "lang blocks" will be showed always.
+
+Definition of "lang block":
+    Is a collection of lang tags separated only by whitespace chars (space,
+    tab, linefeed or return chars).
+
+One example in action:
+    - This text:
+        <span lang="en">Hello!</span><span lang="es">Hola!</span>
+        This text is common for every language because it's out from any lang block.
+        <span lang="en">Bye!</span><span lang="it">Ciao!</span>
+
+    - Will print, if current language is English:
+        Hello!
+        This text is common for every language because it's out from any lang block.
+        Bye!
+
+    - And, in Spanish, it will print:
+        Hola!
+        This text is common for every language because it's out from any lang block.
+        Bye!
+
+
+Ciao, Eloy :-)
+stronk7@moodle.org
+2005-11-16
Index: admin/multilangupgrade.php
===================================================================
RCS file: admin/multilangupgrade.php
diff -N admin/multilangupgrade.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ admin/multilangupgrade.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,104 @@
+<?php /// $Id: replace.php,v 1.6 2006/09/25 20:22:56 skodak Exp $
+      /// Search and replace strings throughout all texts in the whole database
+
+require_once('../config.php');
+require_once($CFG->dirroot.'/course/lib.php');
+require_once($CFG->libdir.'/adminlib.php');
+$adminroot = admin_get_root();
+admin_externalpage_setup('multilangupgrade', $adminroot);
+
+$go = optional_param('go', 0, PARAM_BOOL);
+
+require_login();
+
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
+
+###################################################################
+admin_externalpage_print_header($adminroot);
+
+print_heading(get_string('multilangupgrade', 'admin'));
+
+$strmultilangupgrade = get_String('mulilangupgradeinfo', 'admin');
+
+if (!$go or !data_submitted() or !confirm_sesskey()) {   /// Print a form
+    $optionsyes = array('go'=>1, 'sesskey'=>sesskey());
+    notice_yesno($strmultilangupgrade, 'multilangupgrade.php', 'index.php', $optionsyes, null, 'post', 'get');
+    admin_externalpage_print_footer($adminroot);
+    die;
+}
+
+
+if (!$tables = $db->Metatables() ) {    // No tables yet at all.
+    error("no tables");
+}
+
+print_simple_box_start('center');
+
+/// Turn off time limits, sometimes upgrades can be slow.
+
+@set_time_limit(0);
+@ob_implicit_flush(true);
+while(@ob_end_flush());
+
+echo 'Progress:<br />';
+$i = 0;
+foreach ($tables as $table) {
+    $skiptables = array($CFG->prefix.'config', $CFG->prefix.'sessions2');
+    if (strpos($table, $CFG->prefix) !== 0) { // Not our table
+        continue;
+    }
+    if (in_array($table, $skiptables)) {      // Don't process these
+        continue;
+    }
+    if ($columns = $db->MetaColumns($table, false)) {
+        foreach ($columns as $column => $data) {
+            if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
+                // first find candidate records
+                $rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
+                if ($rs and $rs->RecordCount() > 0) {
+                    while (!$rs->EOF) {
+                        $text = $rs->fields[$column];
+                        $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
+                        $newtext = preg_replace_callback($search, 'multilangupgrade_impl', $text);
+                        if ($newtext != $text) {
+                            $newtext = addslashes($newtext);
+                            execute_sql("UPDATE $table SET $column='$newtext' WHERE id=".$rs->fields['id'], false);
+                        }
+                        if ($i % 10 == 0) {
+                            echo '.';
+                        } 
+                        if ($i % 600 == 0) {
+                            echo '<br />';
+                        } 
+                        $i++;
+                        $rs->MoveNext();
+                    }
+                }
+
+
+            }
+        }
+    }
+}
+
+print_simple_box_end();
+
+/// Rebuild course cache which might be incorrect now
+notify('Rebuilding course cache...');
+rebuild_course_cache();
+notify('...finished');
+
+print_continue('index.php');
+
+admin_externalpage_print_footer($adminroot);
+
+function multilangupgrade_impl($langblock) {
+    $searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
+    preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
+    $return = '';
+    foreach ($rawlanglist[1] as $index=>$lang) {
+        $return .= '<span lang="'.$lang.'" class="multilang">'.$rawlanglist[2][$index].'</span>';
+    }
+    return $return;
+}
+?>
