]> git.mjollnir.org Git - moodle.git/commitdiff
Enhancing editor settings.
authorjulmis <julmis>
Sat, 22 Jan 2005 10:58:25 +0000 (10:58 +0000)
committerjulmis <julmis>
Sat, 22 Jan 2005 10:58:25 +0000 (10:58 +0000)
admin/editor.html
admin/editor.php
lib/speller/server-scripts/spellchecker.php

index 1b8508e798f3d5428d1ba1190d587183a2b7d5f1..f0cb124cb3922ab47bd267b3deb4446c1478d98b 100644 (file)
@@ -40,7 +40,7 @@
 </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>
index 33502699fc8ad5e5a6b9d12f61b1350bdf2dcfde..d50b394bb2023540a58e1239f5aa3ed9d3f9c06b 100644 (file)
@@ -31,6 +31,7 @@
         // Generate edit form
 
         $fontlist = editor_convert_to_array($CFG->editorfontlist);
+        $dicts    = editor_get_dictionaries();
 
         $stradmin = get_string("administration");
         $strconfiguration = get_string("configuration");
@@ -106,15 +107,15 @@ function editor_update_config ($data) {
     $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))) {
@@ -140,6 +141,7 @@ function reset_to_defaults () {
     $updatedata['editorspelling'] = $defaults['editorspelling'];
     $updatedata['editorfontlist'] = $defaults['editorfontlist'];
     $updatedata['editorhidebuttons'] = $defaults['editorhidebuttons'];
+    $updatedata['editordictionary'] = '';
 
     foreach ($updatedata as $name => $value) {
         if (!(set_config($name, $value))) {
@@ -148,4 +150,58 @@ function reset_to_defaults () {
     }
     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;
+
+}
+
 ?>
index 184adcf90a9c4633efc09a923b4cb615055fa53c..0ad2bebdeb81c14dce6c0989a8e46a8b510b0390 100644 (file)
@@ -19,9 +19,9 @@ if(!($lang = check_language($aspell_prog))) {
     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
@@ -30,6 +30,8 @@ function check_language($cmd) {
 /// 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();
@@ -51,12 +53,14 @@ function check_language($cmd) {
         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.