function tinymce_config in TinyMCE 6.2
Same name and namespace in other branches
- 5.2 tinymce.module \tinymce_config()
- 5 tinymce.module \tinymce_config()
- 6 tinymce.module \tinymce_config()
Return an array of initial tinymce config options from the current role.
1 call to tinymce_config()
- tinymce_process_textarea in ./
tinymce.module - Attach tinymce to a textarea
File
- ./
tinymce.module, line 478 - Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal.
Code
function tinymce_config($profile) {
global $user;
// Drupal theme path.
$themepath = path_to_theme() . '/';
$host = base_path();
$settings = $profile->settings;
// Build a default list of TinyMCE settings.
// Is tinymce on by default?
$status = tinymce_user_get_status($user, $profile);
$init['mode'] = $status == 'true' ? 'exact' : 'none';
// $init['mode'] = "textareas";
$init['theme'] = $settings['theme'] ? $settings['theme'] : 'advanced';
$init['relative_urls'] = 'false';
$init['document_base_url'] = "{$host}";
$init['language'] = $settings['language'] ? $settings['language'] : 'en';
$init['safari_warning'] = $settings['safari_message'] ? $settings['safari_message'] : 'false';
$init['entity_encoding'] = 'raw';
$init['verify_html'] = $settings['verify_html'] ? $settings['verify_html'] : 'false';
$init['preformatted'] = $settings['preformatted'] ? $settings['preformatted'] : 'false';
$init['convert_fonts_to_spans'] = $settings['convert_fonts_to_spans'] ? $settings['convert_fonts_to_spans'] : 'false';
$init['remove_linebreaks'] = $settings['remove_linebreaks'] ? $settings['remove_linebreaks'] : 'true';
$init['apply_source_formatting'] = $settings['apply_source_formatting'] ? $settings['apply_source_formatting'] : 'true';
$init['theme_advanced_resize_horizontal'] = 'false';
$init['theme_advanced_resizing_use_cookie'] = 'false';
$tinymce_mod_path = drupal_get_path('module', 'tinymce');
if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/imagemanager/') && user_access('access tinymce imagemanager')) {
// we probably need more security than this
$init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
}
if (is_dir($tinymce_mod_path . '/tinymce/jscripts/tiny_mce/plugins/filemanager/') && user_access('access tinymce filemanager')) {
// we probably need more security than this
$init['file_browser_callback'] = "mcImageManager.filebrowserCallBack";
}
// Add support for IMCE if available.
if (module_exists('imce') && imce_access()) {
$init['file_browser_callback'] = 'mceImageBrowser';
}
if ($init['theme'] == 'advanced') {
$init['plugins'] = array();
$init['theme_advanced_toolbar_location'] = $settings['toolbar_loc'] ? $settings['toolbar_loc'] : 'bottom';
$init['theme_advanced_toolbar_align'] = $settings['toolbar_align'] ? $settings['toolbar_align'] : 'left';
$init['theme_advanced_path_location'] = $settings['path_loc'] ? $settings['path_loc'] : 'bottom';
$init['theme_advanced_resizing'] = $settings['resizing'] ? $settings['resizing'] : 'true';
$init['theme_advanced_blockformats'] = $settings['block_formats'] ? $settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6';
if (is_array($settings['buttons'])) {
// This gives us the $plugins variable.
$plugins = _tinymce_get_buttons();
// Find the enabled buttons and the mce row they belong on. Also map the
// plugin metadata for each button.
$plugin_tracker = array();
foreach ($plugins as $rname => $rplugin) {
// Plugin name
foreach ($rplugin as $mce_key => $mce_value) {
// TinyMCE key
foreach ($mce_value as $k => $v) {
// Buttons
if (isset($settings['buttons'][$rname . '-' . $v])) {
// Font isn't a true plugin, rather it's buttons made available by the advanced theme
if (!in_array($rname, $plugin_tracker) && $rname != 'font') {
$plugin_tracker[] = $rname;
}
$init[$mce_key][] = $v;
}
}
}
// Some advanced plugins only have an $rname and no buttons
if (isset($settings['buttons'][$rname])) {
if (!in_array($rname, $plugin_tracker)) {
$plugin_tracker[] = $rname;
}
}
}
// Add the rest of the TinyMCE config options to the $init array for each button.
if (is_array($plugin_tracker)) {
foreach ($plugin_tracker as $pname) {
if ($pname != 'default') {
$init['plugins'][] = $pname;
}
foreach ($plugins[$pname] as $mce_key => $mce_value) {
// Don't overwrite buttons or extended_valid_elements
if ($mce_key == 'extended_valid_elements') {
// $mce_value is an array for extended_valid_elements so just grab the first element in the array (never more than one)
$init[$mce_key][] = $mce_value[0];
}
elseif (!strstr($mce_key, 'theme_advanced_buttons')) {
$init[$mce_key] = $mce_value;
}
}
}
}
// Cleanup
foreach ($init as $mce_key => $mce_value) {
if (is_array($mce_value)) {
$mce_value = array_unique($mce_value);
}
$init[$mce_key] = $mce_value;
}
// Shuffle buttons around so that row 1 always has the most buttons,
// followed by row 2, etc. Note: These rows need to be set to NULL otherwise
// TinyMCE loads it's own buttons inherited from the theme.
if (!isset($init['theme_advanced_buttons1'])) {
$init['theme_advanced_buttons1'] = array();
}
if (!isset($init['theme_advanced_buttons2'])) {
$init['theme_advanced_buttons2'] = array();
}
if (!isset($init['theme_advanced_buttons3'])) {
$init['theme_advanced_buttons3'] = array();
}
// bweh - this isn't right!
// some buttons should go in a specific order:
// row 1
// - cut
// - copy
// - paste
// - pasteword
// - separator
// - undo
// - redo
// - separator
// - bold
// - italic
// - underline
// - separator
// row 2
// - formatselect
// - fontselect
// - fontsizeselect
// - separator
// - justifyleft
// - justifycenter
// - justifyright
// - justifyfull
// - separator
// - numlist
// - bullist
// - indent
// - outdent
$buttons = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
$init['theme_advanced_buttons1'] = array();
$init['theme_advanced_buttons2'] = array();
$init['theme_advanced_buttons3'] = array();
$row[] = array(
array(
'newdocument',
'save',
),
array(
'bold',
'italic',
'underline',
),
array(
'undo',
'redo',
),
array(
'cut',
'copy',
'paste',
'pasteword',
),
array(
'link',
'unlink',
),
array(
'image',
'charmap',
),
array(
'code',
),
);
$row[] = array(
array(
'formatselect',
'fontselect',
'fontsizeselect',
),
array(
'justifyleft',
'justifycenter',
'justifyright',
'justifyfull',
),
array(
'numlist',
'bullist',
'indent',
'outdent',
),
);
foreach ($row as $r_index => $r) {
$row_buttons = array();
foreach ($r as $rg_index => $rowgroup) {
$selected = array_intersect($rowgroup, $buttons);
if (count($selected) > 0) {
if (count($row_buttons) > 0) {
$row_buttons[] = "separator";
}
$row_buttons = array_merge($row_buttons, $selected);
}
$buttons = array_diff($buttons, $selected);
}
$init['theme_advanced_buttons' . ($r_index + 1)] = $row_buttons;
}
if (count($buttons) > 0) {
// some buttons are left -> append them to row 3
$init['theme_advanced_buttons3'] = array_merge($init['theme_advanced_buttons3'], $buttons);
}
$min_btns = 5;
// Minimum number of buttons per row.
$num1 = count($init['theme_advanced_buttons1']);
$num2 = count($init['theme_advanced_buttons2']);
$num3 = count($init['theme_advanced_buttons3']);
if ($num3 < $min_btns) {
$init['theme_advanced_buttons2'][] = 'separator';
$init['theme_advanced_buttons2'] = array_merge($init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
$init['theme_advanced_buttons3'] = array();
$num2 = count($init['theme_advanced_buttons2']);
}
if ($num2 < $min_btns) {
$init['theme_advanced_buttons1'][] = 'separator';
$init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
// Squish the rows together, since row 2 is empty
$init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
$init['theme_advanced_buttons3'] = array();
$num1 = count($init['theme_advanced_buttons1']);
}
if ($num1 < $min_btns) {
$init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
// Squish the rows together, since row 2 is empty
$init['theme_advanced_buttons2'] = $init['theme_advanced_buttons3'];
$init['theme_advanced_buttons3'] = array();
}
}
}
if ($settings['css_classes']) {
$init['theme_advanced_styles'] = $settings['css_classes'];
}
if ($settings['css_setting'] == 'theme') {
$css = $themepath . 'style.css';
if (file_exists($css)) {
$init['content_css'] = $host . $css;
}
}
elseif ($settings['css_setting'] == 'self') {
$init['content_css'] = str_replace(array(
'%h',
'%t',
), array(
$host,
$themepath,
), $settings['css_path']);
}
return $init;
}