mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-7887 Multilang upgrade to new tags in Moodle 1.8
This commit is contained in:
parent
9016b062e7
commit
f16242ce61
@ -183,7 +183,8 @@
|
||||
'guestloginbutton' => 1,
|
||||
'style' => 'default',
|
||||
'template' => 'default',
|
||||
'theme' => 'standardwhite'));
|
||||
'theme' => 'standardwhite',
|
||||
'filter_multilang_converted' => 1));
|
||||
|
||||
notify($strdatabasesuccess, "green");
|
||||
} else {
|
||||
@ -501,6 +502,11 @@
|
||||
print_simple_box(get_string('cronwarning', 'admin')." ".$helpbutton, 'center', '60%');
|
||||
}
|
||||
|
||||
/// Print multilang upgrade notice if needed
|
||||
if (empty($CFG->filter_multilang_converted)) {
|
||||
print_simple_box(get_string('multilangupgradenotice', 'admin'), 'center', '60%');
|
||||
}
|
||||
|
||||
/// Alert if we are currently in maintenance mode
|
||||
if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
|
||||
print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center', '60%');
|
||||
|
112
admin/multilangupgrade.php
Normal file
112
admin/multilangupgrade.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php /// $Id$
|
||||
/// 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('multilangupgradeinfo', '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 '<strong>Progress:</strong>';
|
||||
$i = 0;
|
||||
$skiptables = array($CFG->prefix.'config');//, $CFG->prefix.'sessions2');
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (strpos($table, $CFG->prefix) !== 0
|
||||
or strpos($table, $CFG->prefix.'pma') === 0) { // Not our tables
|
||||
continue;
|
||||
}
|
||||
if (in_array($table, $skiptables)) { // Don't process these
|
||||
continue;
|
||||
}
|
||||
if ($columns = $db->MetaColumns($table, false)) {
|
||||
if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) {
|
||||
continue; // moodle tables have id
|
||||
}
|
||||
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 % 600 == 0) {
|
||||
echo '<br />';
|
||||
}
|
||||
if ($i % 10 == 0) {
|
||||
echo '.';
|
||||
}
|
||||
$i++;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set conversion flag - switches to new plugin automatically
|
||||
set_config('filter_multilang_converted', 1);
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
/// Rebuild course cache which might be incorrect now
|
||||
notify('Rebuilding course cache...', 'notifysuccess');
|
||||
rebuild_course_cache();
|
||||
notify('...finished', 'notifysuccess');
|
||||
|
||||
print_continue('index.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
die;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
?>
|
@ -16,5 +16,6 @@ $ADMIN->add('misc', new admin_externalpage('xmldbeditor', get_string('xmldbedito
|
||||
$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', !empty($CFG->filter_multilang_converted)));
|
||||
|
||||
?>
|
||||
|
@ -6,7 +6,7 @@ To Install it:
|
||||
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 @@ Definition of "lang block":
|
||||
|
||||
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 @@ One example in action:
|
||||
Ciao, Eloy :-)
|
||||
stronk7@moodle.org
|
||||
2005-11-16
|
||||
|
||||
Syntax was changed in 1.8, the conversion of existing text is done from admin/multilangupgrade.php
|
||||
Ciao, skodak :-)
|
||||
2006-12-11
|
14
filter/multilang/defaultsettings.php
Normal file
14
filter/multilang/defaultsettings.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// defaultsettings.php
|
||||
// deafault settings are done here, saves doing all this twice in
|
||||
// both the rendering routine and the config screen
|
||||
|
||||
if (!isset($forcereset)) {
|
||||
$forcereset = false;
|
||||
}
|
||||
|
||||
if (!isset($CFG->filter_multilang_force_old) or $forcereset) {
|
||||
set_config('filter_multilang_force_old', 0);
|
||||
}
|
||||
|
||||
?>
|
@ -23,29 +23,38 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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.
|
||||
//
|
||||
// Following new syntax is not compatible with old one:
|
||||
// <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
|
||||
|
||||
function multilang_filter($courseid, $text) {
|
||||
global $CFG;
|
||||
|
||||
// [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';
|
||||
|
||||
if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
|
||||
// new syntax
|
||||
$search = '/(<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)(\s*<span lang="[a-zA-Z0-9_-]+" class="multilang">.+?<\/span>)+/is';
|
||||
} else {
|
||||
// old syntax
|
||||
$search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.+?<\/(?:lang|span)>)+/is';
|
||||
}
|
||||
return preg_replace_callback($search, 'multilang_filter_impl', $text);
|
||||
}
|
||||
|
||||
function multilang_filter_impl($langblock) {
|
||||
global $CFG;
|
||||
|
||||
$mylang = str_replace('_utf8', '', current_language());
|
||||
static $parentcache;
|
||||
if (!isset($parentcache)) {
|
||||
@ -58,7 +67,14 @@ function multilang_filter_impl($langblock) {
|
||||
$parentlang = $parentcache[$mylang];
|
||||
}
|
||||
|
||||
$searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
|
||||
if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
|
||||
// new syntax
|
||||
$searchtosplit = '/<span lang="([a-zA-Z0-9_-]+)" class="multilang">(.+?)<\/span>/is';
|
||||
} else {
|
||||
// old syntax
|
||||
$searchtosplit = '/<(?:lang|span) lang="([a-zA-Z0-9_-]*)".*?>(.+?)<\/(?:lang|span)>/is';
|
||||
}
|
||||
|
||||
preg_match_all($searchtosplit, $langblock[0], $rawlanglist);
|
||||
|
||||
$langlist = array();
|
||||
|
14
filter/multilang/filterconfig.html
Normal file
14
filter/multilang/filterconfig.html
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// check the default settings
|
||||
require_once "defaultsettings.php";
|
||||
|
||||
?>
|
||||
|
||||
<table cellpadding="9" cellspacing="0">
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string('multilangforceold', 'admin'); ?></td>
|
||||
<td><?php choose_from_menu(array(get_String('no'), get_String('yes')), 'filter_multilang_force_old',
|
||||
$CFG->filter_multilang_force_old, ''); ?></td>
|
||||
<td />
|
||||
</tr>
|
||||
</table>
|
@ -336,6 +336,10 @@ $string['mediapluginwmv'] = 'Enable .wmv filter';
|
||||
$string['messaging'] = 'Enable messaging system';
|
||||
$string['misc'] = 'Miscellaneous';
|
||||
$string['modulesecurity'] = 'Module security';
|
||||
$string['multilangforceold'] = 'Force old multilang syntax: <span> without the class=\"multilang\" and <lang>';
|
||||
$string['multilangupgrade'] = 'Multilang upgrade';
|
||||
$string['multilangupgradeinfo'] = 'The multilang filter syntax was changed in 1.8, <lang> tag is not supported any more. <br /><br />Example: <span lang=\"en\" class=\"multilang\">Hello!</span><span lang=\"es\" class=\"multilang\">Hola!</span><br /><br /><strong>Do you want to upgrade the syntax in all existing texts now?</strong>';
|
||||
$string['multilangupgradenotice'] = 'Your site is probably using old multilang syntax, <a href=\"multilangupgrade.php\">multilang upgrade</a> is recommended.';
|
||||
$string['mustenablestats'] = 'Stats have not yet been enabled on this site.';
|
||||
$string['mymoodle'] = 'My Moodle';
|
||||
$string['mymoodleredirect'] = 'Force users to use My Moodle';
|
||||
|
Loading…
x
Reference in New Issue
Block a user