, // Richard Bennett and Jeff Robbins /** * @file * Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal. */ /** * Implementation of hook_menu(). */ function tinymce_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'), 'callback' => 'tinymce_admin', 'access' => user_access('administer tinymce')); } return $items; } /** * Implementation of hook_help(). */ function tinymce_help($section) { switch ($section) { case 'admin/modules#description': return t('The TinyMCE Javascript HTML WYSIWYG editor.'); case 'admin/settings/tinymce#pages': return "node/*\nuser/*\ncomment/*"; case 'admin/settings/tinymce': return t('

TinyMCE adds what-you-see-is-what-you-get (WYSIWYG) html editing to textareas. Profiles can be defined based on user roles. 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. The default profile setting uses the "simple" TinyMCE theme which just shows the most minimal buttons set (bold, italic, underline, etc), but many other settings are available by switching to "advanced". And by default, textareas on affected pages will be automatically swapped out with the rich text editor. Users may disable the editor for any textarea without reloading the page. This setting can be reversed so that pages load with conventional textarea form fields. A link below each textarea allows TinyMCE to be turned on or off "on the fly".

Be aware that things can get confusing if a user is a member of roles defined in multiple profiles. In this case, the user will receive the profile for role with lowest role id they belong to. Did I mention it was confusing?

lastly, only users with the access tinymce permission will be able to use TinyMCE.

'); } } /** * Implementation of hook_perm(). */ function tinymce_perm() { return array('administer tinymce', 'access tinymce'); } /** * Implementation of hook_img_assist_head(). */ function tinymce_img_assist_head() { global $base_url; // The tinymce docs say to include tiny_mce_popup.js, but this was killing IE! $popup_path = $base_url .'/'. drupal_get_path('module', 'tinymce'). '/tinymce/jscripts/tiny_mce/tiny_mce_popup.js'; $img_assist_prop = $img_template = ''; if (module_exist('img_assist')) { $img_assist_prop = $base_url .'/'. drupal_get_path('module', 'img_assist'). '/properties.js'; $img_assist_prop = ''; $img_template = variable_get('img_assist_img_html', img_assist_help('img_assist/template')); $nl = "\n"; $img_template = preg_replace('/\n|\r|(\r\n)/m', '\\'. $nl, $img_template); } $clean_url = variable_get('clean_url', 0); $output = << var clean_url = $clean_url; var img_template = '$img_template'; function insertImage(form) { if (window.opener) { form['edit[filepath]'].value = window.opener.tinyMCE.convertURL(form['edit[filepath]'].value); form['edit[nodePath]'].value = window.opener.tinyMCE.convertURL(form['edit[nodePath]'].value); var img = generate_image_tag(form, 'html'); //img = img.replace(/\\r|\\n|\\t/g, ''); window.opener.tinyMCE.execInstanceCommand(myTextarea.name, 'mceInsertContent', false, img, true); } } EOD; return $output; } /** * Implementation of hook_img_assist_on_submit(). */ function tinymce_img_assist_on_submit() { return 'parent.insertImage(this.form);'; } /** * Implementation of hook_textarea(). */ function tinymce_textarea($op, $textarea_name) { static $is_running = FALSE; if (!user_access('access tinymce')) return NULL; global $user; global $base_url; static $profile_name; // Since tinymce_config() makes a db hit, only call it when we're pretty sure // we're gonna render tinymce. $valid_so_far = FALSE; if ($op == 'post') { if (!$profile_name) { $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)))); } $profile = tinymce_profile_load($profile_name); $init = tinymce_config($profile); $init['elements'] = 'edit['. $textarea_name .']'; $valid_so_far = TRUE; } if ($valid_so_far && _tinymce_page_match($profile)) { // Merge user-defined TinyMCE settings. $init = (array) theme('tinymce_theme', $init, $textarea_name, $init['theme'], $is_running); $settings = array(); foreach ($init as $k => $v) { $v = is_array($v) ? implode(',', $v) : $v; // Don't wrap the JS init in quotes for boolean values or functions. if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{') { $v = '"'. $v. '"'; } $settings[] = $k. ' : '. $v; } $tinymce_settings = implode(",\n ", $settings); if (module_exist('img_assist')) { $img_assist_js_on = $base_url .'/'. url('img_assist/add&editor=tinymce') .'&textarea='; $img_assist_js_off = $base_url .'/'. url('img_assist/add') .'&textarea='; $img_assist_on = $base_url .'/'. url('img_assist/add&editor=tinymce') .'&textarea=edit['. $textarea_name .']'; $img_assist_off = $base_url .'/'. url('img_assist/add') .'&textarea=edit['. $textarea_name .']'; } $enable = t('enable rich-text'); $disable = t('disable rich-text'); $tinymce_invoke = << tinyMCE.init({ $tinymce_settings }); EOD; $js_toggle = << function mceToggle(id, linkid) { element = document.getElementById(id); link = document.getElementById(linkid); img_assist = document.getElementById('img_assist-link-'+ id); if (tinyMCE.getEditorId(element.name) == null) { tinyMCE.addMCEControl(element, element.name); element.togg = 'on'; link.innerHTML = '$disable'; link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');"; if (img_assist) img_assist.href = "$img_assist_js_on"+ element.name; link.blur(); } else { tinyMCE.removeMCEControl(tinyMCE.getEditorId(element.name)); element.togg = 'off'; link.innerHTML = '$enable'; link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');"; if (img_assist) img_assist.href = "$img_assist_js_off"+ element.name; link.blur(); } } EOD; $status = isset($user->tinymce_status) ? $user->tinymce_status : variable_get('tinymce_default_state', 0); $link_text = $status == 1 ? $disable : $enable; $no_wysiwyg = t('Your current web browser does not support WYSIWYG editing.'); $wysiwyg_link = << img_assist = document.getElementById('img_assist-link-edit-$textarea_name'); if (img_assist) { img_assist.href = tinyMCE.getEditorId('edit-$textarea_name') == null ? "$img_assist_on" : "$img_assist_off"; } if (typeof(document.execCommand) == 'undefined') { img_assist.href = "$img_assist_off"; document.write('
$no_wysiwyg<\\/div>'); } else { document.write("
$link_text<\\/div><\\/a>"); } EOD; // We only load the TinyMCE js file once per request if (!$is_running) { $is_running = TRUE; if (is_dir(drupal_get_path('module', 'tinymce').'/imagemanager/')) { // if tinymce imagemanager is installed drupal_add_js(drupal_get_path('module', 'tinymce') .'/imagemanager/jscripts/mcimagemanager.js'); } // For some crazy reason IE will only load this JS file if the absolute reference is given to it. drupal_add_js($base_url. '/'. drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/tiny_mce.js'); drupal_set_html_head($js_toggle); // We have to do this becuase of some unfocused CSS in certain themes. See http://drupal.org/node/18879 for details drupal_set_html_head(''); } // Load a TinyMCE init for each textarea. if ($init) drupal_set_html_head($tinymce_invoke); return $wysiwyg_link; } } /** * Implementation of hook_user(). */ function tinymce_user($type, &$edit, &$user, $category = NULL) { if ($type == 'form' && $category == 'account' && user_access('access tinymce')) { $user_status = $edit['tinymce_status'] != NULL ? $edit['tinymce_status'] : ($user->tinymce_status != NULL ? $user->tinymce_status : variable_get('tinymce_default_state', 0)); $form = form_radios(t('Default status'), 'tinymce_status', $user_status, array(t('Off'), t('On')), t('Should rich-text editing be enabled or disabled by default in textarea fields?')); return array(array('title' => t('TinyMCE settings'), 'data' => $form)); } if ($type == 'validate') { return array('tinymce_status' => $edit['tinymce_status']); } } /** * @addtogroup themeable * @{ */ /** * Customize a TinyMCE theme. * * @param init * An array of settings TinyMCE should invoke a theme. You may override any * of the TinyMCE settings. Details here: * * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm * * @param textarea_name * The name of the textarea TinyMCE wants to enable. * * @param theme_name * The default tinymce theme name to be enabled for this textarea. The * sitewide default is 'simple', but the user may also override this. * * @param is_running * A boolean flag that identifies id TinyMCE is currently running for this * request life cycle. It can be ignored. */ function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) { switch ($textarea_name) { // Disable tinymce for these textareas case 'log': // Book log case 'img_assist_pages': case 'caption': // signature case 'pages': case 'settings][access_pages': //TinyMCE profile settings. unset($init); break; // Force the 'simple' theme for some of the smaller textareas. case 'signature': case 'site_mission': case 'site_footer': case 'settings][access_pages': $init['theme'] = 'simple'; foreach ($init as $k => $v) { if (strstr($k, 'theme_advanced_')) unset($init[$k]); } break; } // Add some extra features when using the advanced theme. switch ($theme_name) { case 'advanced': //$init['extended_valid_elements'] = array('a[href|target|name|title|onclick]'); break; } // Always return $init; !! return $init; } /** @} End of addtogroup themeable */ /** * Grab the themes available to TinyMCE. * * TinyMCE themes control the functionality and buttons that are available to a * user. Themes are only looked for within the default TinyMCE theme directory. * * NOTE: This function is not used in this release. We are only using advanced theme. * * @return * An array of theme names. */ function _tinymce_get_themes() { static $themes = array(); if (!$themes) { $theme_loc = drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/themes/'; if (is_dir($theme_loc) && $dh = opendir($theme_loc)) { while (($file = readdir($dh)) !== false) { if (!in_array($file, array('.', '..', 'CVS')) && is_dir($theme_loc . $file)) { $themes[$file] = $file; } } closedir($dh); asort($themes); } } return $themes; } /** * Return plugin metadata from the plugin registry. * * We also scrape each plugin's *.js file for the human friendly name and help * text URL of each plugin. * * @return * An array for each plugin. */ function _tinymce_get_buttons($skip_metadata = TRUE) { include_once(drupal_get_path('module', 'tinymce'). '/plugin_reg.php'); $plugins = _tinymce_plugins(); if ($skip_metadata == FALSE && is_array($plugins)) { foreach ($plugins as $name => $plugin) { $file = drupal_get_path('module', 'tinymce'). '/tinymce/jscripts/tiny_mce/plugins/'. $name .'/editor_plugin_src.js'; // Grab the plugin metadata by scanning the *.js file. if (file_exists($file)) { $lines = file($file, 'r'); $has_longname = FALSE; $has_infourl = FALSE; foreach ($lines as $line) { if ($has_longname && $has_infourl) break; if (strstr($line, 'longname')) { $start = strpos($line, "'") + 1; $end = strrpos($line, "'") - $start; $metadata[$name]['longname'] = substr($line, $start, $end); $has_longname = TRUE; } elseif (strstr($line, 'infourl')) { $start = strpos($line, "'") + 1; $end = strrpos($line, "'") - $start; $metadata[$name]['infourl'] = substr($line, $start, $end); $has_infourl = TRUE; } } } // Find out the buttons a plugin has. foreach ($plugin as $k => $v) { if (strstr($k, 'theme_advanced_buttons')) { $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['buttons'], $plugin[$k]); } } } return $metadata; } return $plugins; } /******************************************************************** * Module Functions :: Public ********************************************************************/ /** * Controller for tinymce administrative settings. */ function tinymce_admin($arg = NULL) { $edit = $_POST['edit']; $op = $_POST['op']; $op = $arg && !$op ? $arg : $op; switch ($op) { case 'add': $breadcrumb[] = array('path' => 'admin', 'title' => t('administer')); $breadcrumb[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce')); $breadcrumb[] = array('path' => 'admin/settings/tinymce/add', 'title' => t('Add new tinymce profile')); menu_set_location($breadcrumb); $output = tinymce_profile_form($edit); break; case 'edit': drupal_set_title(t('Edit tinymce profile')); $output = tinymce_profile_form(tinymce_profile_load(urldecode(arg(4)))); break; case 'delete': tinymce_profile_delete(urldecode(arg(4))); drupal_set_message(t('Deleted profile')); drupal_goto('admin/settings/tinymce'); break; case t('Create profile'); case t('Update profile'); if (tinymce_profile_validate($edit)) { tinymce_profile_save($edit); $edit['old_name'] ? drupal_set_message(t('Your tinymce profile has been updated.')) : drupal_set_message(t('Your tinymce profile has been created.')); drupal_goto('admin/settings/tinymce'); } else { $output = tinymce_profile_form($edit); } break; case t('Save settings'): variable_set('tinymce_default_state', $edit['tinymce_default_state']); drupal_set_message(t('Settings updated')); drupal_goto('admin/settings/tinymce'); break; default: drupal_set_title(t('TinyMCE settings (%revision)', array('%revision' => '$Revision$'))); //Check if TinyMCE is installed. $tinymce_loc = drupal_get_path('module', 'tinymce') .'/tinymce/'; if (!is_dir($tinymce_loc)) { drupal_set_message(t('Could not find the TinyMCE engine installed at %tinymce-directory. Please download TinyMCE, uncompress it and copy the folder into %tinymce-path.', array('%tinymce-path' => drupal_get_path('module', 'tinymce'), '%tinymce-directory' => $tinymce_loc)), 'error'); } $output = tinymce_profile_overview(); } print theme('page', $output); } /** * Return an array of initial tinymce config options from the current role. */ function tinymce_config($profile) { global $base_url; global $user; // Drupal theme path. $themepath = drupal_get_path('theme', init_theme()).'/'; $host = $base_url.'/'; $settings = $profile->settings; // Build a default list of TinyMCE settings. //dprint_r($settings); // Is tinymce on by default? $status = isset($user->tinymce_status) ? $user->tinymce_status : variable_get('tinymce_default_state', 0); $init['mode'] = $status == 1 ? 'exact' : 'none'; $init['theme'] = $settings['theme'] ? $settings['theme'] : 'simple'; $init['document_base_url'] = "$base_url/"; $init['verify_html'] = $settings['verify_html'] ? $settings['verify_html'] : 'false'; $init['preformatted'] = $settings['preformatted'] ? $settings['preformatted'] : 'false'; $init['convert_fonts_to_styles'] = $settings['convert_fonts_to_styles'] ? $settings['convert_fonts_to_styles'] : 'false'; 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'] : 'none'; $init['theme_advanced_resizing'] = $settings['resizing'] ? $settings['resizing'] : 'false'; $init['theme_advanced_blockformats'] = $settings['block_formats'] ? $settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6'; if (is_array($settings['plugins'])) { // 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 ($settings['plugins'][$rname][$v]) { if (!in_array($rname, $plugin_tracker)) $plugin_tracker[] = $rname; $init[$mce_key][] = $v; } } } } // 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) { if (!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 (!$init['theme_advanced_buttons1']) $init['theme_advanced_buttons1'] = array(); if (!$init['theme_advanced_buttons2']) $init['theme_advanced_buttons2'] = array(); if (!$init['theme_advanced_buttons3']) $init['theme_advanced_buttons3'] = array(); $min_btns = 5; // Minimum number of buttons per row. $num2 = count($init['theme_advanced_buttons2']); $num3 = count($init['theme_advanced_buttons3']); if ($num3 < $min_btns) { $init['theme_advanced_buttons2'] = array_merge($init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']); $init['theme_advanced_buttons3'] = array(); } if ($num2 < $min_btns) { $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']); $init['theme_advanced_buttons2'] = array(); } } } if ($edit['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; } } else if ($settings['css_setting'] == 'self') { $init['content_css'] = str_replace(array('%h', '%t'), array($host, $themepath), $settings['css_path']); } return $init; } /** * Remove a profile from the database. */ function tinymce_profile_delete($name) { db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $name); db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $name); } /** * Return an HTML form for profile configuration. */ function tinymce_profile_form($edit) { $edit = array2object($edit); // Only display the roles that currently don't have a tinymce profile. One // profile per role. $orig_roles = user_roles(FALSE, 'access tinymce'); $roles = $orig_roles; if (arg(3) == 'add') { $result = db_query('SELECT DISTINCT(rid) FROM {tinymce_role}'); while ($data = db_fetch_object($result)) { unset($roles[$data->rid]); } if (!$roles) { 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'); } else if (count($orig_roles) != count($roles)) { 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.')); } $btn = t('Create profile'); } else { $output = form_hidden('old_name', $edit->name); $btn = t('Update profile'); } $group = form_textfield(t('Profile name'), 'name', $edit->name, 40, 128, t('Enter a unique name for this profile. This name is only visible in the tinymce administration page.'), NULL, TRUE); $group .= form_checkboxes(t('Roles allowed to use this profile'), 'rids', array_keys((array) $edit->rids), $roles, t('Select at least one role. Listed are the roles with \'access tinymce\' permission.'), NULL, TRUE); // This line will come back when we resurrect the ability to use custom TinyMCE themes. //$group .= form_radios(t('Theme'), 'settings][theme', $edit->settings['theme'] ? $edit->settings['theme'] : 'simple', _tinymce_get_themes(), t('Select the tinymce theme. The advanced theme will display advanced options below.'), FALSE ,array('onclick'=>'tinymceThemeOptions(this.value);')); $group .= form_hidden('settings][theme', $edit->settings['theme'] ? $edit->settings['theme'] : 'advanced'); $group .= form_radios(t('Make tinymce visible on'), 'settings][access', $edit->settings['access'], array(t('all pages'), t('specific pages'))); $group .= form_textarea(t('Specific pages'), 'settings][access_pages', $edit->settings['access_pages'] ? $edit->settings['access_pages'] : tinymce_help('admin/settings/tinymce#pages'), 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are 'blog' for the blog page and 'blog/*' for every personal blog. '<front>' is the front page.")); $output .= form_group(t('Basic setup'), $group); $output .= t('

Options

'); $group = ''; $metadata = _tinymce_get_buttons(FALSE); // Generate the button list. foreach($metadata as $name => $meta) { if (is_array($meta['buttons'])) { foreach ($meta['buttons'] as $button) { if ($name != 'default') { $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/plugins/$name/images/$name.gif"; } else { $img_src = drupal_get_path('module', 'tinymce'). "/tinymce/jscripts/tiny_mce/themes/advanced/images/$button.gif"; } $b = file_exists($img_src) ? '' : $button; if ($name == 'default') { $title = $b; } else { $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name; if ($metadata[$name]['infourl']) { $title = ''. $title .''; } $title .= ' - '. $b; } $form_name = 'settings][plugins]['. $name. ']['. $button; $form_value = $edit->settings['plugins'][$name][$button]; $checkboxes[] = form_checkbox($title, $form_name, 1, $form_value, $description); } } else { $title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name; if ($metadata[$name]['infourl']) { $title = ''. $title .''; } $form_name = 'settings][plugins]['. $name. ']'; $form_value = $edit->settings['plugins'][$name]; $checkboxes[] = form_checkbox($title, $form_name, 1, $form_value, $description); } } // Split the checkboxes into 2 columns for a table view $split = ceil(count($checkboxes) / 2); $col[] = array_slice($checkboxes, 0, $split); $col[] = array_slice($checkboxes, $split); foreach ($col as $c) { $r[] = array('data' => implode('
', $c), 'valign' => 'top'); } $row[] = $r; $output .= form_group_collapsible(('Buttons'), theme('table', array(), $row, array('width' => '100%')), TRUE); $group = form_select(t('Toolbar location'), 'settings][toolbar_loc', $edit->settings['toolbar_loc'], array('bottom' => 'bottom', 'top' => 'top'), t('Show toolbar at the top or bottom of the editor area?')); $group .= form_select(t('Toolbar alignment'), 'settings][toolbar_align', $edit->settings['toolbar_align'], array('center' => 'center', 'left' => 'left', 'right' => 'right'), t('Align tool icons left, center, or right within the toolbar.')); $group .= form_select(t('Path location'), 'settings][path_loc', $edit->settings['path_loc'], array('none' => 'none', 'top' => 'top', 'bottom' => 'bottom'), t('Path to html elements (i.e. "body>table>tr>td"). Show at top, bottom, or not at all.')); $group .= form_select(t('Enable resizing button'), 'settings][resizing', $edit->settings['resizing'], array('false' => 'false', 'true' => 'true'), t(' This option gives you the ability to enable/disable the resizing button.')); $group .= form_textfield(t('Block formats'), 'settings][block_formats', $edit->settings['block_formats'] ? $edit->settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6', 40, 250, t('Comma separated list of HTML block formats. You can only remove elements, not add.')); $output .= form_group_collapsible(('Editor appearance'), $group, TRUE); $group = form_select(t('Verify HTML'), 'settings][verify_html', $edit->settings['verify_html'], array('true' => 'true', 'false' => 'false'), t('Should the HTML contents be verified or not? Verifying will strip <head> tags, so choose false if you will be editing full page HTML.')); $group .= form_select(t('Preformatted'), 'settings][preformatted', $edit->settings['preformatted'], array('false' => 'false', 'true' => 'true'), 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.')); $group .= form_select(t('Convert <font> tags to styles'), 'settings][convert_fonts_to_styles', $edit->settings['convert_fonts_to_styles'], array('true' => 'true', 'false' => 'false'), t('If you set this option to true, font size, font family, font color and font background color will be replaced by inline styles.')); $output .= form_group_collapsible(t('Cleanup/Output'), $group, TRUE); $group = form_select(t('Editor CSS'), 'settings][css_setting', $edit->settings['css_setting'] ? $edit->settings['css_setting'] : 'theme', array('theme' => 'use theme css', 'self' => 'define css', 'none' => 'tinyMCE default'), t('Defines the CSS to be used in the editor area.
use theme css - get css from current Drupal theme.
define css - enter path for css file below.
tinyMCE default - uses default CSS from editor.')); $group .= form_textfield(t('CSS path'), 'settings][css_path', $edit->settings['css_path'], 40, 255, t('Enter path to CSS file (example: "css/editor.css").
Macros: %h (host name: http://www.example.com/), %t (path to theme: theme/yourtheme/)
Be sure to select "define css" above.')); $group .= form_textfield(t('CSS classes'), 'settings][css_classes', $edit->settings['css_classes'], 40, 255, t('Adds CSS classes to the "styles" droplist. Format is "<title>=<class>;"
Example: "Header 1=header1;Header 2=header2;Header 3=header3;"
Leave blank to automatically import list of CSS classes from style sheet.')); $output .= form_group_collapsible(t('CSS'), $group, TRUE); $output .= form_submit($btn); return form($output); } /** * Load all profiles. Just load one profile if $name is passed in. */ function tinymce_profile_load($name = '') { static $profiles = array(); if (!$profiles) { $roles = user_roles(); $result = db_query('SELECT * FROM {tinymce_settings}'); while ($data = db_fetch_object($result)) { $data->settings = unserialize($data->settings); $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name); $role = array(); while ($r = db_fetch_object($result2)) { $role[$r->rid] = $roles[$r->rid]; } $data->rids = $role; $profiles[$data->name] = $data; } } return ($name ? $profiles[$name] : $profiles); } /** * Controller for tinymce profiles. */ function tinymce_profile_overview() { $output = ''; $profiles = tinymce_profile_load(); if ($profiles) { $output .= t('

Create new profile

', array('%create-profile-url' => url('admin/settings/tinymce/add'))); $roles = user_roles(); $header = array(t('Profile'), t('Roles'), t('Operations')); foreach ($profiles as $p) { $rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("
\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')); } $output .= theme('table', $header, $rows). '

 

'; } else { drupal_set_message(t('No profiles found. Click here to create a new profile.', array('%create-profile-url' => url('admin/settings/tinymce/add')))); } $group = form_radios(t('Default tinymce state'), 'tinymce_default_state', variable_get('tinymce_default_state', 0), array(t('Off'), t('On')), t('Should tinymce be enabled or disabled by default when it\'s first loaded from a textarea? Note: The user may override this setting in their profile.')); $output .= form_group(t('Default settings'), $group); $output .= form_submit(t('Save settings')); return form($output); } /** * Save a profile to the database. */ function tinymce_profile_save($edit) { db_query("DELETE FROM {tinymce_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']); db_query("DELETE FROM {tinymce_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']); db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit['settings'])); foreach ($edit['rids'] as $rid) { db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid); } } /** * Profile validation. */ function tinymce_profile_validate($edit) { $errors = array(); if (!$edit['name']) { $errors['name'] = t('You must give a profile name.'); } if (!$edit['rids']) { $errors['rids'] = t('You must select at least one role.'); } foreach ($errors as $name => $message) { form_set_error($name, $message); } return count($errors) == 0; } /******************************************************************** * Module Functions :: Private ********************************************************************/ /** * Determine if TinyMCE has permission to be used on the current page. * * @return * TRUE if can render, FALSE if not allowed. */ function _tinymce_page_match($edit) { //Kill TinyMCE if we're editing a textarea with PHP in it! if ($_POST['edit']['format'] == 2) { return FALSE; } else { // PHP input formats are #2 in the filters table. preg_match("|^node/(\d+)(/edit)$|", $_GET['q'], $match); if (intval($match[1]) > 0) { if (db_result(db_query('SELECT format FROM {node_revisions} WHERE nid = %d AND vid = %d AND format = 2', $match[1], $match[1]))) { return FALSE; } } } if ($edit->settings['access'] == 0) { return TRUE; } else { $page_match = FALSE; $pages = $edit->settings['access_pages'] ? $edit->settings['access_pages'] : tinymce_help('admin/settings/tinymce#pages'); if ($pages) { $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/'; $page_match = preg_match($regexp, $path); } return $page_match; } } ?>