</tr>
<tr>
<td align="right" valign="top">editorspelling:</td>
- <td valign="top"><select name="spelling"<?php
+ <td valign="top"><select onchange="change_state()" id="spelling" name="spelling"<?php
if (empty($CFG->aspellpath)) {
echo " disabled=\"disabled\"";
$CFG->editorspelling = false;
?>>
<option value="1"<?php print(!$CFG->editorspelling)?"":" selected=\"selected\"";?>><?php print_string("yes");?></option>
<option value="0"<?php print(!$CFG->editorspelling)?" selected=\"selected\"":"";?>><?php print_string("no");?></option>
- </select></td>
+ </select>
+ <select id="dictionary" name="dictionary"<?php
+ if (empty($CFG->aspellpath)) {
+ echo " disabled=\"disabled\"";
+ $CFG->editordictionary = false;
+ }
+ ?>>
+ <?php
+ if (is_array($dicts)) {
+ foreach ($dicts as $dict) {
+ echo "<option value=\"$dict\"";
+ if (!empty($CFG->editordictionary)) {
+ print ($CFG->editordictionary != $dict) ? "" : " selected=\"selected\"";
+ }
+ echo ">$dict</option>\n";
+ }
+ } else if (is_string($dicts)) {
+ echo '<option value="">'. $dicts .'</option>' . "\n";
+ }
+ ?>
+ </select>
+ </td>
<td valign="top"><?php print_string("edhelpenablespelling");?></td>
</tr>
<tr><td colspan="3"><br /><?php print_string("edhelpfontlist");?></td></tr>
<td valign="top" align="right">editorhidebuttons:</td>
<td colspan="2">
<?php
- $buttons = explode(chr(32), $CFG->editorhidebuttons);
+ $buttons = array();
+ if (!empty($CFG->editorhidebuttons)) {
+ $buttons = explode(chr(32), $CFG->editorhidebuttons);
+ }
?>
<table border="0" cellpadding="2" cellspacing="1">
<tr>
<input type="submit" name="resettodefaults" value="<?php print_string('editorresettodefaults') ?>" />
</center>
</form>
+<script language="javascript" type="text/javascript">
+<!--
+
+function change_state () {
+
+ var choice = document.forms[0].spelling;
+ var speller = choice.options[choice.selectedIndex].value;
+
+ if (speller != 1) {
+ document.forms[0].dictionary.disabled = true;
+ } else {
+ document.forms[0].dictionary.disabled = false;
+ }
+}
+
+document.onload = change_state();
+-->
+</script>
// Generate edit form
$fontlist = editor_convert_to_array($CFG->editorfontlist);
+ $dicts = editor_get_dictionaries();
$stradmin = get_string("administration");
$strconfiguration = get_string("configuration");
$updatedata['editorkillword'] = !empty($data->killword) ? $data->killword : "true";
$updatedata['editorspelling'] = !empty($data->spelling) ? $data->spelling : 0;
$updatedata['editorfontlist'] = $fontlist;
+ $updatedata['editordictionary'] = !empty($data->dictionary) ? $data->dictionary : '';
$hidebuttons = '';
if (!empty($data->buttons) && is_array($data->buttons)) {
foreach ($data->buttons as $key => $value) {
$hidebuttons .= $key . " ";
}
-
- $updatedata['editorhidebuttons'] = trim($hidebuttons);
}
+ $updatedata['editorhidebuttons'] = trim($hidebuttons);
foreach ($updatedata as $name => $value) {
if (!(set_config($name, $value))) {
$updatedata['editorspelling'] = $defaults['editorspelling'];
$updatedata['editorfontlist'] = $defaults['editorfontlist'];
$updatedata['editorhidebuttons'] = $defaults['editorhidebuttons'];
+ $updatedata['editordictionary'] = '';
foreach ($updatedata as $name => $value) {
if (!(set_config($name, $value))) {
}
return true;
}
+
+function editor_get_dictionaries () {
+/// Get all installed dictionaries in the system
+
+ error_reporting(E_ALL); // for debug, final version shouldn't have this...
+ clearstatcache();
+
+ $strerror = '';
+
+ if (!function_exists('popen')) {
+ return $strerror = "Popen function disabled!";
+ exit;
+ }
+
+ global $CFG;
+
+ $cmd = $CFG->aspellpath;
+ $output = '';
+ $dictionaries = array();
+ $dicts = array();
+
+ if(!($handle = @popen($cmd .' dump dicts', 'r'))) {
+ return $strerror = "Couldn't create handle!";
+ exit;
+ }
+
+ while(!feof($handle)) {
+ $output .= fread($handle, 1024);
+ }
+ @pclose($handle);
+
+ $dictionaries = explode(chr(10), $output);
+
+ // Get rid of possible empty values
+ if (is_array($dictionaries)) {
+
+ $cnt = count($dictionaries);
+
+ for ($i = 0; $i < $cnt; $i++) {
+ if (!empty($dictionaries[$i])) {
+ $dicts[] = $dictionaries[$i];
+ }
+ }
+ }
+
+ if (count($dicts) >= 1) {
+ return $dicts;
+ }
+
+ $strerror = "Error! Check your aspell installation!";
+ return $strerror;
+
+}
+
?>
exit;
}
-$aspell_opts = "-a -H --lang=$lang --encoding=utf-8";
-$tempfiledir = "./";
-$input_separator = "A";
+$aspell_opts = '-a -H --lang='. $lang .' --encoding=utf-8';
+$tempfiledir = './';
+$input_separator = 'A';
function check_language($cmd) {
/// return users current language if its
/// language is not in the list. If english dictionary
/// isn't found, then false is returned.
+ global $CFG;
+
error_reporting(E_ALL); // for debug, final version shouldn't have this...
clearstatcache();
$current_lang = current_language();
if(in_array($current_lang,$dicts)) {
return $current_lang;
}
+ }
- if(in_array("en", $dicts)) {
- return "en";
- }
+ if (!empty($CFG->editordictionary)) {
+ return $CFG->editordictionary;
}
+
return false;
+
}
// set the JavaScript variable to the submitted text.