root/devel/mod/tinymce/tinymce_js.php

Revision 1403, 4.5 kB (checked in by rho, 1 year ago)

Improved spell language selection based on user settings

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

  • Property svn:eol-style set to native
Line 
1 <?php
2 // $parameter[0] is an optional array of textbox ids to add to the elements list
3 // for when this is called explicitly as run('tinymce:include')
4
5     // Language setting
6
7     global $CFG, $USER;
8     global $page_owner;
9
10     if (run('userdetails:editor', $USER->ident) == "yes") {
11
12         if (empty($USER->locale) || $USER->locale == 'default') {
13             // Userlocale not set, use default
14             if (substr($CFG->defaultlocale, 2, 1) == "_")
15             {
16                 $lang = substr($CFG->defaultlocale, 0, 2);
17             } else {
18                 $lang = $CFG->defaultlocale;
19             }
20         } else {
21             // Userlocale set
22             if (substr($USER->locale, 2, 1) == "_")
23             {
24                 $lang = substr($USER->locale, 0, 2);
25             } else {
26                 $lang = $USER->locale;
27             }
28         }
29
30         // Lose the trailing slash
31         $url = substr($CFG->wwwroot, 0, -1);
32
33         global $metatags;
34         
35         // gzip thingy should only assemble plugins we're actually using
36         $plugins = 'spellchecker,emotions,contextmenu,preview,style,searchreplace,safari';
37         //plugins : 'style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,spellchecker',
38         
39         // in blog weblogs:edit $parameter is an integer.
40         // in weblogs:posts:view:individual $parameter is an object.
41         // tinymce:include wants an array.
42         if (!empty($parameter) && is_array($parameter) && !empty($parameter[0]) && is_array($parameter[0])) {
43             $elements = $parameter[0];
44         } else {
45             $elements = array("new_weblog_post","new_weblog_comment");
46         }
47         $elementstring = implode(",", $elements);
48         
49         // auto select spellchecker language based on $lang
50         $available_langs = array('English=en','Dutch=nl','German=de',
51                                  'Spanish=es','Danish=dk','Swedish=sv',         
52                                  'French=fr','Japanese=jp');
53         $spell_langs = array();
54         $spell_found = false;
55
56         foreach ($available_langs as $slang) {
57             $lang_code = substr($slang,strlen($slang)-2,2);
58
59             if ($lang_code == $lang) {
60                 $spell_langs[] = '+' . $slang;
61                 $spell_found = true;
62             } else {
63                 $spell_langs[] = $slang;
64             }
65         }
66
67         $spellcheck_languages = implode(',', $spell_langs);
68
69         // Set default first language if lang not found in spell langs
70         if (!$spell_found) {
71             $spellcheck_languages = '+' . $spellcheck_languages;
72         }
73
74         $metatags .= <<< END
75     <script language="javascript" type="text/javascript" src="$url/mod/tinymce/lib/jscripts/tiny_mce/tiny_mce_gzip.js"></script>
76
77     <script language="javascript" type="text/javascript">
78     tinyMCE_GZ.init({
79         plugins : '$plugins',
80         themes : 'advanced',
81         language : '$lang',
82         disk_cache : true,
83         debug : false
84     });
85     </script>
86
87     <script language="javascript" type="text/javascript">
88     tinyMCE.init({
89         language : "$lang",
90         mode : "exact",
91         plugins : "$plugins",
92         convert_urls : false,
93         relative_urls : false,
94         elements : "$elementstring",
95         theme : "advanced",
96         theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,image,undo,redo,link,unlink,code,spellchecker,emotions",
97         theme_advanced_buttons2 : "preview,styleprops,search,replace",
98         theme_advanced_buttons3 : "",
99         theme_advanced_toolbar_location : "top",
100         theme_advanced_toolbar_align : "left",
101         theme_advanced_path_location : "bottom",
102         plugin_preview_width : "500",
103         plugin_preview_height : "600",
104         extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
105         remove_linebreaks: true,
106         theme_advanced_source_editor_width : "400",
107         theme_advanced_source_editor_height : "400",
108         spellchecker_languages : "$spellcheck_languages",
109         document_base_url : "$url",
110         fullscreen_settings : {
111             theme_advanced_path_location : "top"
112         }
113         });
114     </script>\n
115 END;
116     }
117 ?>
118
Note: See TracBrowser for help on using the browser.