Updated with 5.5 changes
[project/tinymce.git] / tinymce.module
1 <?php
2 // $Id$
3 // A collaborative project by Matt Westgate <drupal at asitis dot org>,
4 // Richard Bennett <richard.b@ at ritechnologies dot com> and Jeff Robbins <robbins at jjeff dot com>
5
6 /**
7 * @file
8 * Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal.
9 */
10
11 /**
12 * Implementation of hook_menu().
13 */
14 function tinymce_menu($may_cache) {
15 $items = array();
16 if ($may_cache) {
17 $items[] = array('path' => 'admin/settings/tinymce', 'title' => t('TinyMCE'),
18 'callback' => 'tinymce_admin',
19 'description' => t('Configure the rich editor.'),
20 'access' => user_access('administer tinymce'));
21 }
22 return $items;
23 }
24
25 /**
26 * Implementation of hook_help().
27 */
28 function tinymce_help($section) {
29 switch ($section) {
30 case 'admin/settings/tinymce#pages':
31 return "node/*\nuser/*\ncomment/*";
32 case 'admin/settings/tinymce':
33 case 'admin/help#tinymce' :
34 return t('<p style="font-size:x-small">$Revision$ $Date$</p>' .
35 '<p>TinyMCE adds what-you-see-is-what-you-get (WYSIWYG) html editing to textareas. This editor can be enabled/disabled without reloading the page by clicking a link below each textarea.</p>
36 <p>Profiles can be defined based on user roles. A TinyMCE profile can define which pages receive this TinyMCE capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions.</p>
37 <p>Lastly, only users with the <code>access tinymce</code> <a href="!url">permission</a> will be able to use TinyMCE.</p>', array('!url' => url('admin/user/access'))
38 );
39 }
40 }
41
42 /**
43 * Implementation of hook_perm().
44 */
45 function tinymce_perm() {
46 $array = array('administer tinymce', 'access tinymce');
47 $tinymce_mod_path = drupal_get_path('module', 'tinymce');
48
49 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/')) {
50 $array[] = 'access tinymce imagemanager';
51 }
52 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/')) {
53 $array[] = 'access tinymce filemanager';
54 }
55
56 return $array;
57 }
58
59 /**
60 * Implementation of hook_elements().
61 */
62 function tinymce_elements() {
63 $type = array();
64
65 if (user_access('access tinymce')) {
66 // Let TinyMCE potentially process each textarea.
67 $type['textarea'] = array('#process' => array('tinymce_process_textarea' => array()));
68 }
69
70 return $type;
71 }
72
73 /**
74 * Attach tinymce to a textarea
75 */
76 function tinymce_process_textarea($element) {
77 static $is_running = FALSE;
78 global $user;
79 static $profile_name;
80
81 //$element is an array of attributes for the textarea but there is no just 'name' value, so we extract this from the #id field
82 $textarea_name = substr($element['#id'], strpos($element['#id'], '-') + 1);
83
84 // Since tinymce_config() makes a db hit, only call it when we're pretty sure
85 // we're gonna render tinymce.
86 if (!$profile_name) {
87 $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($user->roles))));
88 if (!$profile_name) {
89 return $element;
90 }
91 }
92 $profile = tinymce_profile_load($profile_name);
93 $init = tinymce_config($profile);
94 $init['elements'] = 'edit-'. $textarea_name;
95
96 if (_tinymce_page_match($profile)) {
97 // Merge user-defined TinyMCE settings.
98 $init = (array) theme('tinymce_theme', $init, $textarea_name, $init['theme'], $is_running);
99
100 // If $init array is empty no need to execute rest of code since there are no textareas to theme with TinyMCE
101 if (count($init) < 1) {
102 return $element;
103 }
104
105 $settings = array();
106 foreach ($init as $k => $v) {
107 $v = is_array($v) ? implode(',', $v) : $v;
108 // Don't wrap the JS init in quotes for boolean values or functions.
109 if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{') {
110 $v = '"'. $v. '"';
111 }
112 $settings[] = $k. ' : '. $v;
113 }
114 $tinymce_settings = implode(",\n ", $settings);
115
116 $enable = t('enable rich-text');
117 $disable = t('disable rich-text');
118
119 $tinymce_invoke = <<<EOD
120
121 tinyMCE.init({
122 $tinymce_settings
123 });
124
125 EOD;
126
127 $tinymce_gz_invoke = <<<EOD
128
129 tinyMCE_GZ.init({
130 $tinymce_settings
131 });
132
133 EOD;
134
135 $js_toggle = <<<EOD
136
137 function mceToggle(id, linkid) {
138 element = document.getElementById(id);
139 link = document.getElementById(linkid);
140 img_assist = document.getElementById('img_assist-link-'+ id);
141
142 if (tinyMCE.getEditorId(element.id) == null) {
143 tinyMCE.addMCEControl(element, element.id);
144 element.togg = 'on';
145 link.innerHTML = '$disable';
146 link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
147 if (img_assist)
148 img_assist.innerHTML = '';
149 link.blur();
150 }
151 else {
152 tinyMCE.removeMCEControl(tinyMCE.getEditorId(element.id));
153 element.togg = 'off';
154 link.innerHTML = '$enable';
155 link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";
156 if (img_assist)
157 img_assist.innerHTML = img_assist_default_link;
158 link.blur();
159 }
160 }
161
162 EOD;
163
164 $status = tinymce_user_get_status($user, $profile);
165
166 // note we test for string == true because we save our settings as strings
167 $link_text = $status == 'true' ? $disable : $enable;
168 $img_assist_link = ($status == 'true') ? 'yes' : 'no';
169 $no_wysiwyg = t('Your current web browser does not support WYSIWYG editing.');
170 $wysiwyg_link = <<<EOD
171 <script type="text/javascript">
172 img_assist = document.getElementById('img_assist-link-edit-$textarea_name');
173 if (img_assist) {
174 var img_assist_default_link = img_assist.innerHTML;
175 if ('$img_assist_link' == 'yes') {
176 img_assist.innerHTML = tinyMCE.getEditorId('edit-$textarea_name') == null ? '' : img_assist_default_link;
177 }
178 else {
179 img_assist.innerHTML = tinyMCE.getEditorId('edit-$textarea_name') == null ? img_assist_default_link : '';
180 }
181 }
182 if (typeof(document.execCommand) == 'undefined') {
183 img_assist.innerHTML = img_assist_default_link;
184 document.write('<div style="font-size:x-small">$no_wysiwyg</div>');
185 }
186 else {
187 document.write("<div><a href=\"javascript:mceToggle('edit-$textarea_name', 'wysiwyg4$textarea_name');\" id=\"wysiwyg4$textarea_name\">$link_text</a></div>");
188 }
189 </script>
190 EOD;
191
192 // We only load the TinyMCE js file once per request
193 if (!$is_running) {
194 $is_running = TRUE;
195 $tinymce_mod_path = drupal_get_path('module', 'tinymce');
196
197 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/') && user_access('access tinymce imagemanager') ) {
198 // if tinymce imagemanager is installed
199 drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/jscripts/mcimagemanager.js');
200 }
201
202 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/') && user_access('access tinymce filemanager') ) {
203 // if tinymce filemanager is installed
204 drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/jscripts/mcfilemanager.js');
205 }
206
207 // TinyMCE Compressor 1.0.9 and greater
208 if (file_exists($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.js')) {
209 drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.js');
210 drupal_add_js($tinymce_gz_invoke, 'inline');
211 }
212 // TinyMCE Compressor (versions < 1.0.9)
213 elseif (file_exists($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php')) {
214 drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php');
215 }
216 else {
217 // For some crazy reason IE will only load this JS file if the absolute reference is given to it.
218 drupal_add_js($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/tiny_mce.js');
219 }
220 drupal_add_js($js_toggle, 'inline');
221 // We have to do this becuase of some unfocused CSS in certain themes. See http://drupal.org/node/18879 for details
222 drupal_set_html_head('<style type="text/css" media="all">.mceEditor img { display: inline; }</style>');
223 }
224 // Load a TinyMCE init for each textarea.
225 if ($init) drupal_add_js($tinymce_invoke, 'inline');
226
227 //settings are saved as strings, not booleans
228 if ($profile->settings['show_toggle'] == 'true') {
229 // Make sure to append to #suffix so it isn't completely overwritten
230 $element['#suffix'] .= $wysiwyg_link;
231 }
232 // Set resizable to false to avoid drupal.js resizable function from taking control of the textarea
233 $element['#resizable'] = FALSE;
234 }
235
236 return $element;
237 }
238
239 /**
240 * Implementation of hook_user().
241 */
242 function tinymce_user($type, &$edit, &$user, $category = NULL) {
243 if ($type == 'form' && $category == 'account' && user_access('access tinymce')) {
244 $profile = tinymce_user_get_profile($user);
245
246 // because the settings are saved as strings we need to test for the string 'true'
247 if ($profile->settings['user_choose'] == 'true') {
248 $form['tinymce'] = array(
249 '#type' => 'fieldset',
250 '#title' => t('TinyMCE rich-text settings'),
251 '#weight' => 10,
252 '#collapsible' => TRUE,
253 '#collapsed' => TRUE
254 );
255
256 $form['tinymce']['tinymce_status'] = array(
257 '#type' => 'select',
258 '#title' => t('Default state'),
259 '#default_value' => isset($user->tinymce_status) ? $user->tinymce_status : (isset($profile->settings['default']) ? $profile->settings['default'] : 'false'),
260 '#options' => array('false' => t('disabled'), 'true' => t('enabled')),
261 '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields?')
262 );
263
264 return array('tinymce' => $form);
265 }
266 }
267 if ($type == 'validate') {
268 return array('tinymce_status' => $edit['tinymce_status']);
269 }
270 }
271
272 /**
273 * @addtogroup themeable
274 * @{
275 */
276
277 /**
278 * Customize a TinyMCE theme.
279 *
280 * @param init
281 * An array of settings TinyMCE should invoke a theme. You may override any
282 * of the TinyMCE settings. Details here:
283 *
284 * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm
285 *
286 * @param textarea_name
287 * The name of the textarea TinyMCE wants to enable.
288 *
289 * @param theme_name
290 * The default tinymce theme name to be enabled for this textarea. The
291 * sitewide default is 'simple', but the user may also override this.
292 *
293 * @param is_running
294 * A boolean flag that identifies id TinyMCE is currently running for this
295 * request life cycle. It can be ignored.
296 */
297 function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
298 switch ($textarea_name) {
299 // Disable tinymce for these textareas
300 case 'log': // book and page log
301 case 'img_assist_pages':
302 case 'caption': // signature
303 case 'pages':
304 case 'access_pages': //TinyMCE profile settings.
305 case 'user_mail_welcome_body': // user config settings
306 case 'user_mail_approval_body': // user config settings
307 case 'user_mail_pass_body': // user config settings
308 case 'synonyms': // taxonomy terms
309 case 'description': // taxonomy terms
310 unset($init);
311 break;
312
313 // Force the 'simple' theme for some of the smaller textareas.
314 case 'signature':
315 case 'site_mission':
316 case 'site_footer':
317 case 'site_offline_message':
318 case 'page_help':
319 case 'user_registration_help':
320 case 'user_picture_guidelines':
321 $init['theme'] = 'simple';
322 foreach ($init as $k => $v) {
323 if (strstr($k, 'theme_advanced_')) unset($init[$k]);
324 }
325 break;
326 }
327
328 /* Example, add some extra features when using the advanced theme.
329
330 // If $init is available, we can extend it
331 if (isset($init)) {
332 switch ($theme_name) {
333 case 'advanced':
334 $init['extended_valid_elements'] = array('a[href|target|name|title|onclick]');
335 break;
336 }
337 }
338
339 */
340
341 // Always return $init
342 return $init;
343 }
344
345 /** @} End of addtogroup themeable */
346
347 /**
348 * Grab the themes available to TinyMCE.
349 *
350 * TinyMCE themes control the functionality and buttons that are available to a
351 * user. Themes are only looked for within the default TinyMCE theme directory.
352 *
353 * NOTE: This function is not used in this release. We are only using advanced theme.
354 *
355 * @return
356 * An array of theme names.
357 */
358 function _tinymce_get_themes() {
359 static $themes = array();
360
361 if (!$themes) {
362 $theme_loc = drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/themes/';
363 if (is_dir($theme_loc) && $dh = opendir($theme_loc)) {
364 while (($file = readdir($dh)) !== false) {
365 if (!in_array($file, array('.', '..', 'CVS')) && is_dir($theme_loc . $file)) {
366 $themes[$file] = $file;
367 }
368 }
369 closedir($dh);
370 asort($themes);
371 }
372 }
373
374 return $themes;
375 }
376
377 /**
378 * Return plugin metadata from the plugin registry.
379 *
380 * We also scrape each plugin's *.js file for the human friendly name and help
381 * text URL of each plugin.
382 *
383 * @return
384 * An array for each plugin.
385 */
386 function _tinymce_get_buttons($skip_metadata = TRUE) {
387 include_once(drupal_get_path('module', 'tinymce'). '/plugin_reg.php');
388 $plugins = _tinymce_plugins();
389
390 if ($skip_metadata == FALSE && is_array($plugins)) {
391 foreach ($plugins as $name => $plugin) {
392 $file = drupal_get_path('module', 'tinymce'). '/tinymce/jscripts/tiny_mce/plugins/'. $name .'/editor_plugin_src.js';
393 // Grab the plugin metadata by scanning the *.js file.
394 if (file_exists($file)) {
395 $lines = file($file);
396 $has_longname = FALSE;
397 $has_infourl = FALSE;
398 foreach ($lines as $line) {
399 if ($has_longname && $has_infourl) break;
400 if (strstr($line, 'longname')) {
401 $start = strpos($line, "'") + 1;
402 $end = strrpos($line, "'") - $start;
403 $metadata[$name]['longname'] = substr($line, $start, $end);
404 $has_longname = TRUE;
405 }
406 elseif (strstr($line, 'infourl')) {
407 $start = strpos($line, "'") + 1;
408 $end = strrpos($line, "'") - $start;
409 $metadata[$name]['infourl'] = substr($line, $start, $end);
410 $has_infourl = TRUE;
411 }
412 }
413 }
414
415 // Find out the buttons a plugin has.
416 foreach ($plugin as $k => $v) {
417 if (strstr($k, 'theme_advanced_buttons')) {
418 $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['buttons'], $plugin[$k]);
419 }
420 }
421 }
422 return $metadata;
423 }
424
425 return $plugins;
426 }
427 /********************************************************************
428 * Module Functions :: Public
429 ********************************************************************/
430
431 /**
432 * Controller for tinymce administrative settings.
433 */
434 function tinymce_admin($arg = NULL) {
435
436 $edit = $_POST;
437 $op = $_POST['op'];
438
439 $op = $arg && !$op ? $arg : $op;
440
441 switch ($op) {
442 case 'add':
443 $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
444 $breadcrumb[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'));
445 $breadcrumb[] = array('path' => 'admin/settings/tinymce/add', 'title' => t('Add new TinyMCE profile'));
446 menu_set_location($breadcrumb);
447 $output = tinymce_profile_form($edit);
448 break;
449
450 case 'edit':
451 drupal_set_title(t('Edit tinymce profile'));
452 $output = tinymce_profile_form(tinymce_profile_load(urldecode(arg(4))));
453 break;
454
455 case 'delete':
456 tinymce_profile_delete(urldecode(arg(4)));
457 drupal_set_message(t('Deleted profile'));
458 drupal_goto('admin/settings/tinymce');
459 break;
460
461 case t('Create profile');
462 case t('Update profile');
463 if (tinymce_profile_validate($edit)) {
464 tinymce_profile_save($edit);
465 $edit['old_name'] ? drupal_set_message(t('Your TinyMCE profile has been updated.')) : drupal_set_message(t('Your TinyMCE profile has been created.'));
466 drupal_goto('admin/settings/tinymce');
467 }
468 else {
469 $output = tinymce_profile_form($edit);
470 }
471 break;
472
473 default:
474 drupal_set_title(t('TinyMCE settings'));
475 //Check if TinyMCE is installed.
476 $tinymce_loc = drupal_get_path('module', 'tinymce') .'/tinymce/';
477 if (!is_dir($tinymce_loc)) {
478 drupal_set_message(t('Could not find the TinyMCE engine installed at <strong>!tinymce-directory</strong>. Please <a href="http://tinymce.moxiecode.com/">download TinyMCE</a>, uncompress it and copy the folder into !tinymce-path.', array('!tinymce-path' => drupal_get_path('module', 'tinymce'), '!tinymce-directory' => $tinymce_loc)), 'error');
479 }
480 $output = tinymce_profile_overview();
481 }
482
483 return $output;
484 }
485
486 /**
487 * Return an array of initial tinymce config options from the current role.
488 */
489 function tinymce_config($profile) {
490 global $user;
491
492 // Drupal theme path.
493 $themepath = path_to_theme() . '/';
494 $host = base_path();
495
496 $settings = $profile->settings;
497
498 // Build a default list of TinyMCE settings.
499
500 // Is tinymce on by default?
501 $status = tinymce_user_get_status($user, $profile);
502
503 $init['mode'] = $status == 'true' ? 'exact' : 'none';
504 $init['theme'] = $settings['theme'] ? $settings['theme'] : 'advanced';
505 $init['relative_urls'] = 'false';
506 $init['document_base_url'] = "$host";
507 $init['language'] = $settings['language'] ? $settings['language'] : 'en';
508 $init['safari_warning'] = $settings['safari_message'] ? $settings['safari_message'] : 'false';
509 $init['entity_encoding'] = 'raw';
510 $init['verify_html'] = $settings['verify_html'] ? $settings['verify_html'] : 'false';
511 $init['preformatted'] = $settings['preformatted'] ? $settings['preformatted'] : 'false';
512 $init['convert_fonts_to_spans'] = $settings['convert_fonts_to_spans'] ? $settings['convert_fonts_to_spans'] : 'false';
513 $init['remove_linebreaks'] = $settings['remove_linebreaks'] ? $settings['remove_linebreaks'] : 'true';
514 $init['apply_source_formatting'] = $settings['apply_source_formatting'] ? $settings['apply_source_formatting'] : 'true';
515 $init['theme_advanced_resize_horizontal'] = 'false';
516 $init['theme_advanced_resizing_use_cookie'] = 'false';
517
518
519 $tinymce_mod_path = drupal_get_path('module', 'tinymce');
520 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/') && user_access('access tinymce imagemanager')) {
521 // we probably need more security than this
522 $init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
523 }
524 if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/') && user_access('access tinymce filemanager')) {
525 // we probably need more security than this
526 $init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
527 }
528
529 if ($init['theme'] == 'advanced') {
530 $init['plugins'] = array();
531 $init['theme_advanced_toolbar_location'] = $settings['toolbar_loc'] ? $settings['toolbar_loc'] : 'bottom';
532 $init['theme_advanced_toolbar_align'] = $settings['toolbar_align'] ? $settings['toolbar_align'] : 'left';
533 $init['theme_advanced_path_location'] = $settings['path_loc'] ? $settings['path_loc'] : 'bottom';
534 $init['theme_advanced_resizing'] = $settings['resizing'] ? $settings['resizing'] : 'true';
535 $init['theme_advanced_blockformats'] = $settings['block_formats'] ? $settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6';
536
537 if (is_array($settings['buttons'])) {
538 // This gives us the $plugins variable.
539 $plugins = _tinymce_get_buttons();
540
541 // Find the enabled buttons and the mce row they belong on. Also map the
542 // plugin metadata for each button.
543 $plugin_tracker = array();
544 foreach ($plugins as $rname => $rplugin) { // Plugin name
545 foreach ($rplugin as $mce_key => $mce_value) { // TinyMCE key
546 foreach ($mce_value as $k => $v) { // Buttons
547 if ($settings['buttons'][$rname . '-' . $v]) {
548 // Font isn't a true plugin, rather it's buttons made available by the advanced theme
549 if (!in_array($rname, $plugin_tracker) && $rname != 'font') $plugin_tracker[] = $rname;
550 $init[$mce_key][] = $v;
551 }
552 }
553 }
554 // Some advanced plugins only have an $rname and no buttons
555 if ($settings['buttons'][$rname]) {
556 if (!in_array($rname, $plugin_tracker)) $plugin_tracker[] = $rname;
557 }
558 }
559
560 // Add the rest of the TinyMCE config options to the $init array for each button.
561 if (is_array($plugin_tracker)) {
562 foreach ($plugin_tracker as $pname) {
563 if ($pname != 'default') $init['plugins'][] = $pname;
564 foreach ($plugins[$pname] as $mce_key => $mce_value) {
565 // Don't overwrite buttons or extended_valid_elements
566 if ($mce_key == 'extended_valid_elements') {
567 // $mce_value is an array for extended_valid_elements so just grab the first element in the array (never more than one)
568 $init[$mce_key][] = $mce_value[0];
569 }
570 else if (!strstr($mce_key, 'theme_advanced_buttons')) {
571 $init[$mce_key] = $mce_value;
572 }
573 }
574 }
575 }
576
577 // Cleanup
578 foreach ($init as $mce_key => $mce_value) {
579 if (is_array($mce_value)) $mce_value = array_unique($mce_value);
580 $init[$mce_key] = $mce_value;
581 }
582
583 // Shuffle buttons around so that row 1 always has the most buttons,
584 // followed by row 2, etc. Note: These rows need to be set to NULL otherwise
585 // TinyMCE loads it's own buttons inherited from the theme.
586 if (!$init['theme_advanced_buttons1']) $init['theme_advanced_buttons1'] = array();
587 if (!$init['theme_advanced_buttons2']) $init['theme_advanced_buttons2'] = array();
588 if (!$init['theme_advanced_buttons3']) $init['theme_advanced_buttons3'] = array();
589
590 $min_btns = 5; // Minimum number of buttons per row.
591 $num1 = count($init['theme_advanced_buttons1']);
592 $num2 = count($init['theme_advanced_buttons2']);
593 $num3 = count($init['theme_advanced_buttons3']);
594
595 if ($num3 < $min_btns) {
596 $init['theme_advanced_buttons2'] = array_merge($init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
597 $init['theme_advanced_buttons3'] = array();
598 $num2 = count($init['theme_advanced_buttons2']);
599 }
600 if ($num2 < $min_btns) {
601 $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
602 // Squish the rows together, since row 2 is empty
603 $init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
604 $init['theme_advanced_buttons3'] = array();
605 $num1 = count($init['theme_advanced_buttons1']);
606 }
607 if ($num1 < $min_btns) {
608 $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
609 // Squish the rows together, since row 2 is empty
610 $init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
611 $init['theme_advanced_buttons3'] = array();
612 }
613
614 }
615 }
616
617 if ($settings['css_classes']) $init['theme_advanced_styles'] = $settings['css_classes'];
618
619 if ($settings['css_setting'] == 'theme') {
620 $css = $themepath . 'style.css';
621 if (file_exists($css)) {
622 $init['content_css'] = $host . $css;
623 }
624 }
625 else if ($settings['css_setting'] == 'self') {
626 $init['content_css'] = str_replace(array('%h', '%t'), array($host, $themepath), $settings['css_path']);
627 }
628
629 return $init;
630 }
631
632 /**
633 * Remove a profile from the database.
634 */
635 function tinymce_profile_delete($name) {
636 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $name);
637 db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $name);
638 }
639
640 /**
641 * Return an HTML form for profile configuration.
642 */
643 function tinymce_profile_form_build($edit) {
644 $edit = (object) $edit;
645
646 // Only display the roles that currently don't have a tinymce profile. One
647 // profile per role.
648 $orig_roles = user_roles(FALSE, 'access tinymce');
649 $roles = $orig_roles;
650 if (arg(3) == 'add') {
651 $result = db_query('SELECT DISTINCT(rid) FROM {tinymce_role}');
652 while ($data = db_fetch_object($result)) {
653 if (!in_array($data->rid, array_keys((array) $edit->rids)) && !form_get_errors()){
654 unset($roles[$data->rid]);
655 }
656 }
657 if (!$orig_roles) {
658 drupal_set_message(t('You must <a href="!access-control-url">assign</a> at least one role with the \'access tinymce\' permission before creating a profile.', array('!access-control-url' => url('admin/user/access'))), 'error');
659 }
660 else if (!$roles) {
661 drupal_set_message(t('You will not be allowed to create a new profile since all user roles have already been assigned profiles. Either remove an existing tinymce profile from at least one role or assign another role the \'access tinymce\' permission.'), 'error');
662 }
663 else if (count($orig_roles) != count($roles)) {
664 drupal_set_message(t('Not all user roles are shown since they already have tinymce profiles. You must first unassign profiles in order to add them to a new one.'));
665 }
666 $btn = t('Create profile');
667 }
668 else {
669 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name);
670 $btn = t('Update profile');
671 }
672
673 $form['basic'] = array(
674 '#type' => 'fieldset',
675 '#title' => t('Basic setup'),
676 '#collapsible' => TRUE,
677 '#collapsed' => TRUE
678 );
679
680 $form['basic']['name'] = array(
681 '#type' => 'textfield',
682 '#title' => t('Profile name'),
683 '#default_value' => $edit->name,
684 '#size' => 40,
685 '#maxlength' => 128,
686 '#description' => t('Enter a name for this profile. This name is only visible within the tinymce administration page.'),
687 '#required' => TRUE
688 );
689
690 $form['basic']['rids'] = array(
691 '#type' => 'checkboxes',
692 '#title' => t('Roles allowed to use this profile'),
693 '#default_value' => array_keys((array) $edit->rids),
694 '#options' => $roles,
695 '#description' => t('Check at least one role. Only roles with \'access tinymce\' permission will be shown here.'),
696 '#required' => TRUE
697 );
698
699 $form['basic']['default'] = array(
700 '#type' => 'select',
701 '#title' => t('Default state'),
702 '#default_value' => $edit->settings['default'] ? $edit->settings['default'] : 'false',
703 '#options' => array('false' => t('disabled'), 'true' => t('enabled')),
704 '#description' => t('Default editor state for users in this profile. Users will be able to override this state if the next option is enabled.'),
705 );
706
707 $form['basic']['user_choose'] = array(
708 '#type' => 'select',
709 '#title' => t('Allow users to choose default'),
710 '#default_value' => $edit->settings['user_choose'] ? $edit->settings['user_choose'] : 'false',
711 '#options' => array('false' => t('false'), 'true' => t('true')),
712 '#description' => t('If allowed, users will be able to choose their own TinyMCE default state by visiting their profile page.'),
713 );
714
715 $form['basic']['show_toggle'] = array(
716 '#type' => 'select',
717 '#title' => t('Show disable/enable rich text editor toggle'),
718 '#default_value' => $edit->settings['show_toggle'] ? $edit->settings['show_toggle'] : 'true',
719 '#options' => array('false' => t('false'), 'true' => t('true')),
720 '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. If false, editor defaults to the global default or user default (see above).'),
721 );
722
723 // This line upgrades previous versions of TinyMCE for user who previously selected a theme other than advanced.
724 if ($edit->settings['theme'] != 'advanced') $edit->settings['theme'] = 'advanced';
725
726 $form['basic']['theme'] = array(
727 '#type' => 'hidden',
728 '#value' => $edit->settings['theme'] ? $edit->settings['theme'] : 'advanced'
729 );
730
731 $form['basic']['language'] = array(
732 '#type' => 'select',
733 '#title' => t('Language'),
734 '#default_value' => $edit->settings['language'] ? $edit->settings['language'] : 'en',
735 '#options' => drupal_map_assoc(array('ar', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fr', 'fr_ca', 'he', 'hu', 'is', 'it', 'ja', 'ko', 'nb', 'nl', 'nn', 'pl', 'pt', 'pt_br', 'ru', 'ru_KOI8-R', 'ru_UTF-8', 'si', 'sk', 'sv', 'th', 'zh_cn', 'zh_tw', 'zh_tw_utf8')),
736 '#description' => t('The language for the TinyMCE interface. Language codes based on the <a href="http://www.loc.gov/standards/iso639-2/englangn.html">ISO-639-2</a> format.')
737 );
738
739 $form['basic']['safari_message'] = array(
740 '#type' => 'select',
741 '#title' => t('Safari browser warning'),
742 '#default_value' => $edit->settings['safari_message'] ? $edit->settings['safari_message'] : 'false',
743 '#options' => array('false' => t('false'), 'true' => t('true')),
744 '#description' => t('TinyMCE support for the Safari web browser is experimental and a warning message is displayed when that browser is detected. You can disable this message here.')
745 );
746
747 $form['visibility'] = array(
748 '#type' => 'fieldset',
749 '#title' => t('Visibility'),
750 '#collapsible' => TRUE,
751 '#collapsed' => TRUE
752 );
753
754 $access = user_access('use PHP for block visibility');
755
756 // If the visibility is set to PHP mode but the user doesn't have this block permission, don't allow them to edit nor see this PHP code
757 if ($edit->settings['access'] == 2 && !$access) {
758 $form['visibility'] = array();
759 $form['visibility']['access'] = array(
760 '#type' => 'value',
761 '#value' => 2
762 );
763 $form['visibility']['access_pages'] = array(
764 '#type' => 'value',
765 '#value' => $edit->settings['access_pages']
766 );
767 }
768 else {
769 $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.'));
770 $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '!blog' for the blog page and !blog-wildcard for every personal blog. !front is the front page.", array('!blog' => theme('placeholder', 'blog'), '!blog-wildcard' => theme('placeholder', 'blog/*'), '!front' => theme('placeholder', '<front>')));
771
772 if ($access) {
773 $options[] = t('Show if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
774 $description .= t('If the PHP-mode is chosen, enter PHP code between !php. Note that executing incorrect PHP-code can break your Drupal site.', array('!php' => theme('placeholder', '<?php ?>')));
775 }
776 $form['visibility']['access'] = array(
777 '#type' => 'radios',
778 '#title' => t('Show tinymce on specific pages'),
779 '#default_value' => isset($edit->settings['access']) ? $edit->settings['access'] : 1,
780 '#options' => $options
781 );
782 $form['visibility']['access_pages'] = array(
783 '#type' => 'textarea',
784 '#title' => t('Pages'),
785 '#default_value' => isset($edit->settings['access_pages']) ? $edit->settings['access_pages'] : tinymce_help('admin/settings/tinymce#pages'),
786 '#description' => $description
787 );
788 }
789
790 $form['buttons'] = array(
791 '#type' => 'fieldset',
792 '#title' => t('Buttons and plugins'),
793 '#collapsible' => TRUE,
794 '#collapsed' => TRUE,
795 '#tree' => TRUE,
796 '#theme' => 'tinymce_profile_form_buttons'
797 );
798
799 $metadata = _tinymce_get_buttons(FALSE);
800 // Generate the button list.
801 foreach($metadata as $name => $meta) {
802 if (is_array($meta['buttons'])) {
803 foreach ($meta['buttons'] as $button) {
804 if ($name != 'default') {
805 $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/plugins/$name/images/$name.gif";
806
807 //correct for plugins that have more than one button
808 if (!file_exists($img_src)) {
809 $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/plugins/$name/images/$button.gif";
810 }
811 }
812 else {
813 $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/themes/advanced/images/$button.gif";
814 }
815
816 $b = file_exists($img_src) ? '<img src="'. base_path() . $img_src .'" title="'. $button .'" style="border: 1px solid grey; vertical-align: middle;" />' : $button;
817
818 if ($name == 'default') {
819 $title = $b;
820 }
821 else {
822 $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name;
823 if ($metadata[$name]['infourl']) {
824 $title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
825 }
826 $title = $b . ' &#8211; '. $title;
827 }
828 $form_value = $edit->settings['buttons'][$name . '-' . $button];
829 $form['buttons'][$name . '-' . $button] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
830 }
831 }
832 else {
833 $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name;
834 if ($metadata[$name]['infourl']) {
835 $title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
836 }
837 $form_value = $edit->settings['buttons'][$name];
838 $form['buttons'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
839 }
840 }
841
842 $form['appearance'] = array(
843 '#type' => 'fieldset',
844 '#title' => t('Editor appearance'),
845 '#collapsible' => TRUE,
846 '#collapsed' => TRUE
847 );
848
849 $form['appearance']['toolbar_loc'] = array(
850 '#type' => 'select',
851 '#title' => t('Toolbar location'),
852 '#default_value' => $edit->settings['toolbar_loc'],
853 '#options' => array('bottom' => t('bottom'), 'top' => t('top')),
854 '#description' => t('Show toolbar at the top or bottom of the editor area?')
855 );
856
857 $form['appearance']['toolbar_align'] = array(
858 '#type' => 'select',
859 '#title' => t('Toolbar alignment'),
860 '#default_value' => $edit->settings['toolbar_align'],
861 '#options' => array('center' => t('center'), 'left' => t('left'), 'right' => t('right')),
862 '#description' => t('Align tool icons left, center, or right within the toolbar.')
863 );
864
865 $form['appearance']['path_loc'] = array(
866 '#type' => 'select',
867 '#title' => t('Path location'),
868 '#default_value' => $edit->settings['path_loc'] ? $edit->settings['path_loc'] : 'bottom',
869 '#options' => array('none' => t('none'), 'top' => t('top'), 'bottom' => t('bottom')),
870 '#description' => t('Path to html elements (i.e. "body>table>tr>td"). Show at top, bottom, or not at all.')
871 );
872
873 $form['appearance']['resizing'] = array(
874 '#type' => 'select',
875 '#title' => t('Enable resizing button'),
876 '#default_value' => isset($edit->settings['resizing']) ? $edit->settings['resizing'] : 'true',
877 '#options' => array('false' => t('false'), 'true' => t('true')),
878 '#description' => t(' This option gives you the ability to enable/disable the resizing button. If enabled the <strong>Path location toolbar</strong> must be set to "top" or "bottom" in order to display the resize icon.')
879 );
880
881 $form['appearance']['block_formats'] = array(
882 '#type' => 'textfield',
883 '#title' => t('Block formats'),
884 '#default_value' => $edit->settings['block_formats'] ? $edit->settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6',
885 '#size' => 40,
886 '#maxlength' => 250,
887 '#description' => t('Comma separated list of HTML block formats. You can only remove elements, not add.')
888 );
889
890 $form['output'] = array(
891 '#type' => 'fieldset',
892 '#title' => t('Cleanup and output'),
893 '#collapsible' => TRUE,
894 '#collapsed' => TRUE
895 );
896
897 $form['output']['verify_html'] = array(
898 '#type' => 'select',
899 '#title' => t('Verify HTML'),
900 '#default_value' => $edit->settings['verify_html'],
901 '#options' => array('false' => t('false'), 'true' => t('true')),
902 '#description' => t('Should the HTML contents be verified or not? Verifying will strip &lt;head&gt tags, so choose false if you will be editing full page HTML.')
903 );
904
905 $form['output']['preformatted'] = array(
906 '#type' => 'select',
907 '#title' => t('Preformatted'),
908 '#default_value' => $edit->settings['preformatted'],
909 '#options' => array('false' => t('false'), 'true' => t('true')),
910 '#description' => t('If this option is set to true, the editor will insert TAB characters on tab and preserve other whitespace characters just like a PRE HTML element does.')
911 );
912
913 $form['output']['convert_fonts_to_spans'] = array(
914 '#type' => 'select',
915 '#title' => t('Convert &lt;font&gt; tags to styles'),
916 '#default_value' => $edit->settings['convert_fonts_to_spans'],
917 '#options' => array('true' => t('true'), 'false' => t('false')),
918 '#description' => t('If you set this option to true, font size, font family, font color and font background color will be replaced by inline styles.')
919 );
920
921 $form['output']['remove_linebreaks'] = array(
922 '#type' => 'select',
923 '#title' => t('Remove linebreaks'),
924 '#default_value' => $edit->settings['remove_linebreaks'],
925 '#options' => array('true' => 'true', 'false' => 'false'),
926 '#description' => t('Set this option to false to prevent TinyMCE from removing linebreaks from existing nodes. True avoids conflicts with some filters.')
927 );
928
929 $form['output']['apply_source_formatting'] = array(
930 '#type' => 'select',
931 '#title' => t('Apply source formatting'),
932 '#default_value' => $edit->settings['apply_source_formatting'],
933 '#options' => array('true' => 'true', 'false' => 'false'),
934 '#description' => t('This option makes TinyMCE apply source formatting. Set this to true for a cleaner HTML source. Choose false to avoid conflicts with some filters.')
935 );
936
937 $form['css'] = array(
938 '#type' => 'fieldset',
939 '#title' => t('CSS'),
940 '#collapsible' => TRUE,
941 '#collapsed' => TRUE
942 );
943
944 $form['css']['css_setting'] = array(
945 '#type' => 'select',
946 '#title' => t('Editor CSS'),
947 '#default_value' => $edit->settings['css_setting'] ? $edit->settings['css_setting'] : 'theme',
948 '#options' => array('theme' => t('use theme css'), 'self' => t('define css'), 'none' => t('tinyMCE default')),
949 '#description' => t('Defines the CSS to be used in the editor area.<br />use theme css - load style.css from current site theme.<br/>define css - enter path for css file below.<br />tinyMCE default - uses default CSS from editor.')
950 );
951
952 $form['css']['css_path'] = array(
953 '#type' => 'textfield',
954 '#title' => t('CSS path'),
955 '#default_value' => $edit->settings['css_path'],
956 '#size' => 40,
957 '#maxlength' => 255,
958 '#description' => t('Enter path to CSS file (<em>example: "css/editor.css"</em>) or a list of css files seperated by a comma (<em>example: /themes/garland/style.css,http://domain.com/customMCE.css</em>).<br />Macros: %h (host name: http://www.example.com/), %t (path to theme: theme/yourtheme/)<br />Be sure to select "define css" above.')
959 );
960
961 $form['css']['css_classes'] = array(
962 '#type' => 'textfield',
963 '#title' => t('CSS classes'),
964 '#default_value' => $edit->settings['css_classes'],
965 '#size' => 40,
966 '#maxlength' => 255,
967 '#description' => t('Adds CSS classes to the "styles" droplist. Format is: &lt;title&gt;=&lt;class&gt;;<br/> Example: Header 1=header1;Header 2=header2;Header 3=header3 (note: no trailing \';\')<br />Leave blank to automatically import list of CSS classes from style sheet.')
968 );
969
970 $form['submit'] = array(
971 '#type' => 'submit',
972 '#value' => $btn
973 );
974
975 return $form;
976 }
977
978 /**
979 * Return an HTML form for profile configuration.
980 */
981 function tinymce_profile_form($edit) {
982
983 $output .= drupal_get_form('tinymce_profile_form_build', $edit);
984
985 return $output;
986 }
987
988 /**
989 * Layout for the buttons in the tinymce profile form
990 */
991 function theme_tinymce_profile_form_buttons($form) {
992 $buttons = array();
993
994 // Flatten forms array
995 foreach (element_children($form) as $key) {
996 $buttons[] = drupal_render($form[$key]);
997 }
998
999 //split checkboxes into rows with 3 columns
1000 $total = count($buttons);
1001 $rows = array();
1002 for ($i = 0; $i < $total; $i++) {
1003 $row = array();
1004 $row[] = array('data' => $buttons[$i]);
1005 $row[] = array('data' => $buttons[++$i]);
1006 $row[] = array('data' => $buttons[++$i]);
1007 $rows[] = $row;
1008 }
1009
1010 $output = theme('table', array(), $rows, array('width' => '100%'));
1011
1012 return $output;
1013 }
1014
1015 /**
1016 * Load all profiles. Just load one profile if $name is passed in.
1017 */
1018 function tinymce_profile_load($name = '') {
1019 static $profiles = array();
1020
1021 if (!$profiles) {
1022 $roles = user_roles();
1023 $result = db_query('SELECT * FROM {tinymce_settings}');
1024 while ($data = db_fetch_object($result)) {
1025 $data->settings = unserialize($data->settings);
1026 $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name);
1027 $role = array();
1028 while ($r = db_fetch_object($result2)) {
1029 $role[$r->rid] = $roles[$r->rid];
1030 }
1031 $data->rids = $role;
1032
1033 $profiles[$data->name] = $data;
1034 }
1035 }
1036
1037 return ($name ? $profiles[$name] : $profiles);
1038 }
1039
1040 /**
1041 * Controller for tinymce profiles.
1042 */
1043 function tinymce_profile_overview() {
1044 $output = '';
1045
1046 $profiles = tinymce_profile_load();
1047 if ($profiles) {
1048 $roles = user_roles();
1049 $header = array(t('Profile'), t('Roles'), t('Operations'));
1050 foreach ($profiles as $p) {
1051 $rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("<br />\n", $p->rids)), array('data' => l(t('edit'), 'admin/settings/tinymce/edit/'. urlencode($p->name)) . ' '. l(t('delete'), 'admin/settings/tinymce/delete/'. urlencode($p->name)), 'valign' => 'top'));
1052 }
1053 $output .= theme('table', $header, $rows);
1054 $output .= t('<p><a href="!create-profile-url">Create new profile</a></p>', array('!create-profile-url' => url('admin/settings/tinymce/add')));
1055 }
1056 else {
1057 drupal_set_message(t('No profiles found. Click here to <a href="!create-profile-url">create a new profile</a>.', array('!create-profile-url' => url('admin/settings/tinymce/add'))));
1058 }
1059
1060 return $output;
1061 }
1062
1063 /**
1064 * Save a profile to the database.
1065 */
1066 function tinymce_profile_save($edit) {
1067 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
1068 db_query("DELETE FROM {tinymce_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
1069 db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
1070 foreach ($edit['rids'] as $rid => $value) {
1071 db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
1072 }
1073
1074 // if users can't set their own defaults, make sure to remove $user->tinymce_status so their default doesn't override the main default
1075 if ($edit['user_choose'] == 'false') {
1076 global $user;
1077 user_save($user, array('tinymce_status' => NULL));
1078 }
1079 }
1080
1081 /**
1082 * Profile validation.
1083 */
1084 function tinymce_profile_validate($edit) {
1085 $errors = array();
1086
1087 if (!$edit['name']) {
1088 $errors['name'] = t('You must give a profile name.');
1089 }
1090
1091 if (!$edit['rids']) {
1092 $errors['rids'] = t('You must select at least one role.');
1093 }
1094
1095 foreach ($errors as $name => $message) {
1096 form_set_error($name, $message);
1097 }
1098
1099 return count($errors) == 0;
1100 }
1101
1102 /********************************************************************
1103 * Module Functions :: Private
1104 ********************************************************************/
1105
1106 /**
1107 * Determine if TinyMCE has permission to be used on the current page.
1108 *
1109 * @return
1110 * TRUE if can render, FALSE if not allowed.
1111 */
1112 function _tinymce_page_match($edit) {
1113 $page_match = FALSE;
1114
1115 // Kill TinyMCE if we're editing a textarea with PHP in it!
1116 // PHP input formats are #2 in the filters table.
1117 if (is_numeric(arg(1)) && arg(2) == 'edit') {
1118 $node = node_load(arg(1));
1119 if ($node->format == 2) {
1120 return FALSE;
1121 }
1122 }
1123
1124 if ($edit->settings['access_pages']) {
1125 // If the PHP option wasn't selected
1126 if ($edit->settings['access'] < 2) {
1127 $path = drupal_get_path_alias($_GET['q']);
1128 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($edit->settings['access_pages'], '/')) .')$/';
1129 $page_match = !($edit->settings['access'] xor preg_match($regexp, $path));
1130 }
1131 else {
1132 $page_match = drupal_eval($edit->settings['access_pages']);
1133 }
1134 }
1135 // No pages were specified to block so show on all
1136 else {
1137 $page_match = TRUE;
1138 }
1139
1140 return $page_match;
1141 }
1142
1143 function tinymce_user_get_profile($account) {
1144 $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($account->roles))));
1145 if ($profile_name){
1146 return tinymce_profile_load($profile_name);
1147 }
1148 else {
1149 return FALSE;
1150 }
1151 }
1152
1153 function tinymce_user_get_status($user, $profile){
1154 $settings = $profile->settings;
1155
1156 if ($settings['user_choose']) {
1157 $status = isset($user->tinymce_status) ? $user->tinymce_status : (isset($settings['default']) ? $settings['default'] : 'false');
1158 }
1159 else {
1160 $status = isset($settings['default']) ? $settings['default'] : 'false';
1161 }
1162
1163 return $status;
1164 }