3 // A collaborative project by Matt Westgate <drupal at asitis dot org>
4 // and Richard Bennett <richard.b@gritechnologies.com>
8 * Integrate the TinyMCE editor (http://tinymce.moxiecode.com/) into Drupal.
12 * Implementation of hook_menu().
14 function tinymce_menu($may_cache) {
17 $items[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'),
18 'callback' => 'tinymce_admin',
19 'access' => user_access('administer tinymce'));
25 * Implementation of hook_help().
27 function tinymce_help($section) {
29 case
'admin/modules#description':
30 return t('The TinyMCE Javascript HTML WYSIWYG editor.');
32 case
'admin/settings/tinymce#pages':
33 return "node/*\nuser/*\ncomment/*";
35 case
'admin/settings/tinymce':
36 return t('<p>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".</p><p>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?</p>');
41 * Implementation of hook_perm().
43 function tinymce_perm() {
44 return array('administer tinymce', 'access tinymce');
48 * Implementation of hook_img_assist_head().
50 function tinymce_img_assist_head() {
52 // The tinymce docs say to include tiny_mce_popup.js, but this was killing IE!
53 $popup_path = $base_url .
'/'.
drupal_get_path('module', 'tinymce').
'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js';
54 $img_assist_prop = $base_url .
'/'.
drupal_get_path('module', 'img_assist').
'/properties.js';
55 $clean_url = variable_get('clean_url', 0);
56 $img_template = variable_get('img_assist_img_html', img_assist_help('img_assist/template'));
57 $img_template = str_replace("\r\n", "\n", $img_template);
58 $img_template = str_replace("\n", '\n', addslashes($img_template));
61 <script language
="javascript" src
="$img_assist_prop"></script
>
62 <script language
="javascript">
63 var clean_url
= $clean_url;
64 var img_template
= "$img_template";
66 function insertImage(form
) {
68 form
['edit[thumbpath]'].value
= window.opener.tinyMCE.
convertURL(form
['edit[thumbpath]'].value
);
69 form
['edit[filepath]'].value
= window.opener.tinyMCE.
convertURL(form
['edit[filepath]'].value
);
70 form
['edit[nodePath]'].value
= window.opener.tinyMCE.
convertURL(form
['edit[nodePath]'].value
);
72 var img
= generate_image_tag(form
, 'html');
73 //img = img.replace(/\\r|\\n|\\t/g, '');
75 window.opener.tinyMCE.
execInstanceCommand(myTextarea.name
, 'mceInsertContent', false
, img
, true
);
85 * Implementation of hook_img_assist_on_submit().
87 function tinymce_img_assist_on_submit() {
88 return 'parent.insertImage(this.form);';
92 * Implementation of hook_textarea().
94 function tinymce_textarea($op, $textarea_name) {
95 static
$is_running = FALSE
;
96 if (!user_access('access tinymce')) return NULL
;
100 static
$profile_name;
102 // Since tinymce_config() makes a db hit, only call it when we're pretty sure
103 // we're gonna render tinymce.
104 $valid_so_far = FALSE
;
106 if (!$profile_name) {
107 $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
))));
109 $profile = tinymce_profile_load($profile_name);
110 $init = tinymce_config($profile);
111 $init['elements'] = 'edit['.
$textarea_name .
']';
112 $valid_so_far = TRUE
;
115 if ($valid_so_far && _tinymce_page_match($profile)) {
116 // Merge user-defined TinyMCE settings.
117 $init = (array) theme('tinymce_theme', $init, $textarea_name, $init['theme'], $is_running);
119 foreach ($init as
$k => $v) {
120 if (strtolower($v) != 'true' && strtolower($v) != 'false') {
123 $settings[] = $k.
' : '.
$v;
125 $tinymce_settings = implode(",\n ", $settings);
127 if (function_exists('img_assist_help')) {
128 $img_assist_js_on = $base_url .
'/'.
url('img_assist/add&editor=tinymce') .
'&textarea=';
129 $img_assist_js_off = $base_url .
'/'.
url('img_assist/add') .
'&textarea=';
130 $img_assist_on = $base_url .
'/'.
url('img_assist/add&editor=tinymce') .
'&textarea=edit['.
$textarea_name .
']';
131 $img_assist_off = $base_url .
'/'.
url('img_assist/add') .
'&textarea=edit['.
$textarea_name .
']';
134 $enable = t('enable rich-text');
135 $disable = t('disable rich-text');
137 $tinymce_invoke = <<<EOD
138 <script language
="javascript" type
="text/javascript">
146 <script language
="javascript" type
="text/javascript">
147 function mceToggle(id
, linkid
) {
148 element
= document.
getElementById(id
);
149 link = document.
getElementById(linkid
);
150 img_assist
= document.
getElementById('img_assist-link-'+ id
);
152 if (tinyMCE.
getEditorId(element.name
) == null
) {
153 tinyMCE.
addMCEControl(element
, element.name
);
155 link.innerHTML
= '$disable';
156 link.href
= "javascript:mceToggle('" +id
+ "', '" +linkid
+ "');";
158 img_assist.href
= "$img_assist_js_on"+ element.name
;
162 tinyMCE.
removeMCEControl(tinyMCE.
getEditorId(element.name
));
163 element.togg
= 'off';
164 link.innerHTML
= '$enable';
165 link.href
= "javascript:mceToggle('" +id
+ "', '" +linkid
+ "');";
167 img_assist.href
= "$img_assist_js_off"+ element.name
;
174 $status = isset($user->tinymce_status
) ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0);
175 $link_text = $status == 1 ?
$disable : $enable;
176 $no_wysiwyg = t('Your current web browser does not support WYSIWYG editing.');
177 $wysiwyg_link = <<<EOD
178 <script language
="javascript" type
="text/javascript">
179 img_assist
= document.
getElementById('img_assist-link-edit-$textarea_name');
181 img_assist.href
= tinyMCE.
getEditorId('edit-$textarea_name') == null ?
"$img_assist_on" : "$img_assist_off";
183 if (typeof(document.execCommand
) == 'undefined') {
184 img_assist.href
= "$img_assist_off";
185 document.
write('<div style="font-size:x-small">$no_wysiwyg</div>');
188 document.
write("<div><a href=\"javascript:mceToggle('edit-$textarea_name', 'wysiwyg4$textarea_name');\" id=\"wysiwyg4$textarea_name\">$link_text</div></a>");
193 // We only load the TinyMCE js file once per request
194 if (!$is_running && !empty($init)) {
196 // For some crazy reason IE will only load this JS file if the absolute reference is given to it.
197 drupal_set_html_head('<script language="javascript" type="text/javascript" src="'.
$base_url .
'/'.
drupal_get_path('module', 'tinymce') .
'/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>');
198 drupal_set_html_head($js_toggle);
199 // We have to do this becuase of some unfocused CSS in certain themes. See http://drupal.org/node/18879 for details
200 drupal_set_html_head('<style type="text/css" media="all">.mceEditor img { display: inline; }</style>');
202 // Load a TinyMCE init for each textarea.
203 drupal_set_html_head($tinymce_invoke);
205 return $wysiwyg_link;
210 * Implementation of hook_user().
212 function tinymce_user($type, &$edit, &$user, $category = NULL
) {
213 if ($type == 'form' && $category == 'account' && user_access('access tinymce')) {
214 $user_status = $edit['tinymce_status'] != NULL ?
$edit['tinymce_status'] : ($user->tinymce_status
!= NULL ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0));
215 $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?'));
216 return array(array('title' => t('TinyMCE settings'), 'data' => $form));
218 if ($type == 'validate') {
219 return array('tinymce_status' => $edit['tinymce_status']);
225 * @addtogroup themeable
230 * Customize a TinyMCE theme.
233 * An array of settings TinyMCE should invoke a theme. You may override any
234 * of the TinyMCE settings. Details here:
236 * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm
238 * @param textarea_name
239 * The name of the textarea TinyMCE wants to enable.
242 * The default tinymce theme name to be enabled for this textarea. The
243 * sitewide default is 'simple', but the user may also override this.
246 * A boolean flag that identifies id TinyMCE is currently running for this
247 * request life cycle. It can be ignored.
249 function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
250 switch ($textarea_name) {
251 // Disable tinymce for these textareas
253 case
'img_assist_pages':
258 // Force the 'simple' theme for some of the smaller textareas.
262 case
'settings][access_pages':
263 $init['theme'] = 'simple';
264 unset($init['theme_advanced_toolbar_location']);
265 unset($init['theme_advanced_toolbar_align']);
266 unset($init['theme_advanced_path_location']);
267 unset($init['theme_advanced_blockformats']);
268 unset($init['theme_advanced_styles']);
272 // Add some extra features when using the advanced theme.
273 switch ($theme_name) {
275 $init['extended_valid_elements'] = 'a[href|target|name|title|onclick]';
276 $init['theme_advanced_buttons3_add_before'] = 'tablecontrols,separator';
277 $init['plugins'] = file_exists(drupal_get_path('module', 'tinymce').
'/tinymce/jscripts/tiny_mce/plugins/drupalimage') ?
'drupalimage,table,emotions,print' : 'table,emotions,print';
278 $init['theme_advanced_buttons3_add'] = 'drupalimage,emotions,separator,print';
282 // Always return $init; !!
286 /** @} End of addtogroup themeable */
289 * Grab the themes available to TinyMCE.
291 * TinyMCE themes control the functionality and buttons that are available to a
292 * user. Themes are only looked for within the default TinyMCE theme directory.
295 * An array of theme names.
297 function _tinymce_get_themes() {
298 static
$themes = array();
301 $theme_loc = drupal_get_path('module', 'tinymce') .
'/tinymce/jscripts/tiny_mce/themes/';
302 if (is_dir($theme_loc) && $dh = opendir($theme_loc)) {
303 while (($file = readdir($dh)) !== false
) {
304 if (!in_array($file, array('.', '..', 'CVS')) && is_dir($theme_loc .
$file)) {
305 $themes[$file] = $file;
316 /********************************************************************
317 * Module Functions :: Public
318 ********************************************************************/
321 * Controller for tinymce administrative settings.
323 function tinymce_admin($arg = NULL
) {
324 $edit = $_POST['edit'];
327 $op = $arg && !$op ?
$arg : $op;
331 $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
332 $breadcrumb[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'));
333 $breadcrumb[] = array('path' => 'admin/settings/tinymce/add', 'title' => t('Add new tinymce profile'));
334 menu_set_location($breadcrumb);
335 $output = tinymce_profile_form($edit);
339 drupal_set_title(t('Edit tinymce profile'));
340 $output = tinymce_profile_form(tinymce_profile_load(urldecode(arg(4))));
344 tinymce_profile_delete(urldecode(arg(4)));
345 drupal_set_message(t('Deleted profile'));
346 drupal_goto('admin/settings/tinymce');
349 case
t('Create profile');
350 case
t('Update profile');
351 if (tinymce_profile_validate($edit)) {
352 tinymce_profile_save($edit);
353 $edit['old_name'] ?
drupal_set_message(t('Your tinymce profile has been updated.')) : drupal_set_message(t('Your tinymce profile has been created.'));
354 drupal_goto('admin/settings/tinymce');
357 $output = tinymce_profile_form($edit);
361 case
t('Save settings'):
362 variable_set('tinymce_default_state', $edit['tinymce_default_state']);
363 drupal_set_message(t('Settings updated'));
364 drupal_goto('admin/settings/tinymce');
368 drupal_set_title(t('TinyMCE settings (%revision)', array('%revision' => '$Revision$')));
369 //Check if TinyMCE is installed.
370 $tinymce_loc = drupal_get_path('module', 'tinymce') .
'/tinymce/';
371 if (!is_dir($tinymce_loc)) {
372 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');
374 $output = tinymce_profile_overview();
377 print theme('page', $output);
381 * Return an array of initial tinymce config options from the current role.
383 function tinymce_config($profile) {
387 $settings = $profile->settings
;
389 // Build a default list of TinyMCE settings.
391 // Is tinymce on by default?
392 $status = isset($user->tinymce_status
) ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0);
393 $init['mode'] = $status == 1 ?
'exact' : 'none';
394 $init['theme'] = $settings['theme'] ?
$settings['theme'] : 'simple';
395 $init['document_base_url'] = "$base_url/";
397 $init['verify_html'] = $settings['verify_html'] ?
$settings['verify_html'] : 'false';
398 $init['auto_cleanup_word'] = $settings['msword'] ?
$settings['msword'] : 'false';
399 $init['preformatted'] = $settings['preformatted'] ?
$settings['preformatted'] : 'false';
400 $init['force_br_newlines'] = $settings['force_br'] ?
$settings['force_br'] : 'false';
401 $init['force_p_newlines'] = $settings['force_p'] ?
$settings['force_p'] : 'false';
402 if ($init['theme'] == 'advanced') {
403 $init['theme_advanced_toolbar_location'] = $settings['toolbar_loc'] ?
$settings['toolbar_loc'] : 'bottom';
404 $init['theme_advanced_toolbar_align'] = $settings['toolbar_align'] ?
$settings['toolbar_align'] : 'left';
405 $init['theme_advanced_path_location'] = $settings['path_loc'] ?
$settings['path_loc'] : 'none';
406 $init['theme_advanced_blockformats'] = $settings['block_formats'] ?
$settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6';
409 if ($edit['css_classes']) $init['theme_advanced_styles'] = $settings['css_classes'];
410 if ($settings['width']) $init['width'] = $settings['width'];
411 if ($settings['height']) $init['height'] = $settings['height'];
413 if ($settings['css_setting'] == 'theme') {
414 $css = drupal_get_path('theme', init_theme()) .
'/style.css';
415 if (file_exists($css)) {
416 $init['content_css'] = $base_url .
'/'.
$css;
418 else if ($settings['css_setting'] == 'self') {
419 $init['content_css'] = $edit['css_path'];
427 * Remove a profile from the database.
429 function tinymce_profile_delete($name) {
430 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $name);
431 db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $name);
435 * Return an HTML form for profile configuration.
437 function tinymce_profile_form($edit) {
438 $edit = array2object($edit);
440 // Only display the roles that currently don't have a tinymce profile. One
442 $orig_roles = user_roles();
443 $roles = $orig_roles;
444 if (arg(3) == 'add') {
445 $result = db_query('SELECT DISTINCT(rid) FROM {tinymce_role}');
446 while ($data = db_fetch_object($result)) {
447 unset($roles[$data->rid
]);
450 drupal_set_message(t('You will not be allowed to create a new profile since all user roles have already been assigned profiles. First remove an existing tinymce profile from at least one role in order to create a new profile.'), 'error');
452 else if (count($orig_roles) != count($roles)) {
453 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.'));
455 $btn = t('Create profile');
458 $output = form_hidden('old_name', $edit->name
);
459 $btn = t('Update profile');
462 $group = form_textfield(t('Profile name'), 'name', $edit->name
, 40, 128, t('Enter an unique name for this profile. This name is only visible in the tinymce administration page.'), NULL
, TRUE
);
463 $group .
= form_checkboxes(t('Roles allowed to use this profile'), 'rids', array_keys((array) $edit->rids
), $roles, t('Select at least one role.'), NULL
, TRUE
);
464 $group .
= form_radios(t('Theme'), 'settings][theme', $edit->settings
['theme'] ?
$edit->settings
['theme'] : 'simple', _tinymce_get_themes(), t('Select the tinymce theme. The <em>advanced</em> theme will display advanced options below.'), FALSE
,array('onclick'=>'tinymceThemeOptions(this.value);'));
465 $group .
= form_radios(t('Make tinymce visible on'), 'settings][access', $edit->settings
['access'], array(t('specific pages'), t('all textareas')));
466 $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 '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page."));
467 $output .
= form_group(t('Basic setup'), $group);
469 $output .
= t('<h3>Options</h3>');
472 $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?'));
473 $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.'));
474 $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.'));
475 $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.'));
476 $dsp = $edit->settings
['theme'] == 'advanced' ?
'block' : 'none';
477 $output .
= '<div id="advancedThemeSettings" style="display:'.
$dsp .
';">'.
form_group(('Advanced theme options'), $group).
'</div>';
479 $group = form_textfield(t('Editor width'), 'settings][width', $edit->settings
['width'], 3, 5, t('Set width of editor. Leave blank to use size of textarea being replaced.'));
480 $group .
= form_textfield(t('Editor height'), 'settings][height', $edit->settings
['height'], 3, 5, t('Set height of editor. Leave blank to use size of textarea being replaced.'));
481 $output .
= form_group(t('Editor display'), $group);
483 $group = form_select(t('Auto cleanup Word'), 'settings][msword', $edit->settings
['msword'], array('true' => 'true', 'false' => 'false'), t('Automatically cleanup MS Office/Word HTML will be executed automatically on paste operations. (Only works in Internet Explorer)'));
484 $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.'));
485 $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.'));
486 $output .
= form_group(t('On save'), $group);
488 $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.<br />use theme css - get css from current Drupal theme.<br/>define css - enter path for css file below.<br />tinyMCE default - uses default CSS from editor.'));
489 $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"). Select "define css" above.'));
490 $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>;"<br/> Example: "Header 1=header1;Header 2=header2;Header 3=header3;"<br />Leave blank to automatically import list of CSS classes from style sheet.'));
491 $output .
= form_group(t('CSS'), $group);
493 $group .
= form_select(t('Force BR new lines'), 'settings][force_br', $edit->settings
['force_br'] ?
$edit->settings
['force_br'] : 'false', array('true' => 'true', 'false' => 'false'), t('Use BR tags for new lines rather than P.'));
494 $group .
= form_select(t('Force P new lines'), 'settings][force_p', $edit->settings
['force_p'] ?
$edit->settings
['force_p'] : 'true', array('true' => 'true', 'false' => 'false'), t('When enabled, Mozilla/Firefox will generate P elements on Enter/Return key and BR elements on Shift+Enter/Return..'));
495 $output .
= form_group(t('Formatting'), $group);
496 $output .
= form_submit($btn);
499 <script type
='text/javascript'>
500 function tinymceThemeOptions(theme
) {
501 document.
getElementById('advancedThemeSettings').style.display
= theme
== 'advanced' ?
'block' : 'none';
505 drupal_set_html_head($js);
507 return form($output);
513 function tinymce_profile_load($name = '') {
514 static
$profiles = array();
517 $roles = user_roles();
518 $result = db_query('SELECT * FROM {tinymce_settings}');
519 while ($data = db_fetch_object($result)) {
520 $data->settings
= unserialize($data->settings
);
521 $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name
);
523 while ($r = db_fetch_object($result2)) {
524 $role[$r->rid
] = $roles[$r->rid
];
528 $profiles[$data->name
] = $data;
532 return ($name ?
$profiles[$name] : $profiles);
536 * Controller for tinymce profiles.
538 function tinymce_profile_overview() {
540 $output .
= t('<p><a href="%create-profile-url">Create new profile</a></p>', array('%create-profile-url' => url('admin/settings/tinymce/add')));
542 $profiles = tinymce_profile_load();
544 $roles = user_roles();
545 $header = array(t('Profile'), t('Roles'), t('Operations'));
546 foreach ($profiles as
$p) {
547 $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'));
549 $output .
= theme('table', $header, $rows).
'<p> </p>';
552 $output .
= t('<p>No profiles found.</p>');
555 $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.'));
556 $output .
= form_group(t('Default settings'), $group);
557 $output .
= form_submit(t('Save settings'));
559 return form($output);
563 * Save a profile to the database.
565 function tinymce_profile_save($edit) {
566 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
567 db_query("DELETE FROM {tinymce_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
568 db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit['settings']));
569 foreach ($edit['rids'] as
$rid) {
570 db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
575 * Profile validation.
577 function tinymce_profile_validate($edit) {
580 if (!$edit['name']) {
581 $errors['name'] = t('You must give a profile name.');
584 if (!$edit['rids']) {
585 $errors['rids'] = t('You must select at least one role.');
588 foreach ($errors as
$name => $message) {
589 form_set_error($name, $message);
592 return count($errors) == 0;
595 /********************************************************************
596 * Module Functions :: Private
597 ********************************************************************/
600 * Determine if TinyMCE has permission to be used on the current page.
603 * TRUE if can render, FALSE if not allowed.
605 function _tinymce_page_match($edit) {
606 //Kill TinyMCE if we're editing a textarea with PHP in it!
607 if ($_POST['edit']['format'] == 2) {
611 // PHP input formats are #2 in the filters table.
612 preg_match("|^node/(\d+)(/edit)$|", $_GET['q'], $match);
613 if (intval($match[1]) > 0) {
614 if (db_result(db_query('SELECT format FROM {node} WHERE nid = %d AND format = 2', $match[1]))) {
620 if ($edit->settings
['access'] == 1) {
625 $pages = $edit->settings
['access_pages'] ?
$edit->settings
['access_pages'] : tinymce_help('admin/settings/tinymce#pages');
627 $path = drupal_get_path_alias($_GET['q']);
628 $regexp = '/^('.
preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'.
variable_get('site_frontpage', 'node') .
'\2'), preg_quote($pages, '/')) .
')$/';
629 $page_match = preg_match($regexp, $path);