forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-7887 Multilang upgrade to new tags in Moodle 1.8
- Loading branch information
skodak
committed
Dec 12, 2006
1 parent
9016b06
commit f16242c
Showing
8 changed files
with
185 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 :-) | ||
[email protected] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters