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>
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><p>lastly, only users with the <code>access tinymce</code> permission will be able to use TinyMCE.</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 = $img_template = '';
55 if (module_exist('img_assist')) {
56 $img_assist_prop = $base_url .
'/'.
drupal_get_path('module', 'img_assist').
'/properties.js';
57 $img_assist_prop = '<script language="javascript" src="'.
$img_assist_prop .
'"></script>';
59 $img_template = variable_get('img_assist_img_html', img_assist_help('img_assist/template'));
61 $img_template = preg_replace('/\n|\r|(\r\n)/m', '\\'.
$nl, $img_template);
63 $clean_url = variable_get('clean_url', 0);
67 <script language
="javascript">
68 var clean_url
= $clean_url;
69 var img_template
= '$img_template';
71 function insertImage(form
) {
73 form
['edit[filepath]'].value
= window.opener.tinyMCE.
convertURL(form
['edit[filepath]'].value
);
74 form
['edit[nodePath]'].value
= window.opener.tinyMCE.
convertURL(form
['edit[nodePath]'].value
);
76 var img
= generate_image_tag(form
, 'html');
77 //img = img.replace(/\\r|\\n|\\t/g, '');
79 window.opener.tinyMCE.
execInstanceCommand(myTextarea.name
, 'mceInsertContent', false
, img
, true
);
89 * Implementation of hook_img_assist_on_submit().
91 function tinymce_img_assist_on_submit() {
92 return 'parent.insertImage(this.form);';
96 * Implementation of hook_elements().
98 function tinymce_elements() {
99 $type['textarea'] = array('#process' => 'tinymce_process_textarea');
104 * Attach tinymce to a textarea
106 function tinymce_process_textarea($element) {
107 static
$is_running = FALSE
;
108 if (!user_access('access tinymce')) return NULL
;
112 static
$profile_name;
114 //$element is an array of attributes for the textarea but there is no just 'name' value, so we extract this from the #id field
115 $textarea_name = substr($element['#id'], strpos($element['#id'], '-') + 1);
117 // Since tinymce_config() makes a db hit, only call it when we're pretty sure
118 // we're gonna render tinymce.
119 if (!$profile_name) {
120 $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
))));
122 $profile = tinymce_profile_load($profile_name);
123 $init = tinymce_config($profile);
124 $init['elements'] = 'edit['.
$textarea_name .
']';
126 if (_tinymce_page_match($profile)) {
127 // Merge user-defined TinyMCE settings.
128 $init = (array) theme('tinymce_theme', $init, $textarea_name, $init['theme'], $is_running);
130 // If $init array is empty no need to execute rest of code since there are no textareas to theme with TinyMCE
131 if (count($init) < 1) {
136 foreach ($init as
$k => $v) {
137 $v = is_array($v) ?
implode(',', $v) : $v;
138 // Don't wrap the JS init in quotes for boolean values or functions.
139 if (strtolower($v) != 'true' && strtolower($v) != 'false' && $v[0] != '{') {
142 $settings[] = $k.
' : '.
$v;
144 $tinymce_settings = implode(",\n ", $settings);
146 if (module_exist('img_assist')) {
147 $img_assist_js_on = $base_url .
'/'.
url('img_assist/add&editor=tinymce') .
'&textarea=';
148 $img_assist_js_off = $base_url .
'/'.
url('img_assist/add') .
'&textarea=';
149 $img_assist_on = $base_url .
'/'.
url('img_assist/add&editor=tinymce') .
'&textarea=edit['.
$textarea_name .
']';
150 $img_assist_off = $base_url .
'/'.
url('img_assist/add') .
'&textarea=edit['.
$textarea_name .
']';
153 $enable = t('enable rich-text');
154 $disable = t('disable rich-text');
156 $tinymce_invoke = <<<EOD
157 <script language
="javascript" type
="text/javascript">
165 <script language
="javascript" type
="text/javascript">
166 function mceToggle(id
, linkid
) {
167 element
= document.
getElementById(id
);
168 link = document.
getElementById(linkid
);
169 img_assist
= document.
getElementById('img_assist-link-'+ id
);
171 if (tinyMCE.
getEditorId(element.name
) == null
) {
172 tinyMCE.
addMCEControl(element
, element.name
);
174 link.innerHTML
= '$disable';
175 link.href
= "javascript:mceToggle('" +id
+ "', '" +linkid
+ "');";
177 img_assist.href
= "$img_assist_js_on"+ element.name
;
181 tinyMCE.
removeMCEControl(tinyMCE.
getEditorId(element.name
));
182 element.togg
= 'off';
183 link.innerHTML
= '$enable';
184 link.href
= "javascript:mceToggle('" +id
+ "', '" +linkid
+ "');";
186 img_assist.href
= "$img_assist_js_off"+ element.name
;
193 $status = isset($user->tinymce_status
) ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0);
194 $link_text = $status == 1 ?
$disable : $enable;
195 $no_wysiwyg = t('Your current web browser does not support WYSIWYG editing.');
196 $wysiwyg_link = <<<EOD
197 <script language
="javascript" type
="text/javascript">
198 img_assist
= document.
getElementById('img_assist-link-edit-$textarea_name');
200 img_assist.href
= tinyMCE.
getEditorId('edit-$textarea_name') == null ?
"$img_assist_on" : "$img_assist_off";
202 if (typeof(document.execCommand
) == 'undefined') {
203 img_assist.href
= "$img_assist_off";
204 document.
write('<div style="font-size:x-small">$no_wysiwyg<\\/div>');
207 document.
write("<div><a href=\"javascript:mceToggle('edit-$textarea_name', 'wysiwyg4$textarea_name');\" id=\"wysiwyg4$textarea_name\">$link_text<\\/div><\\/a>");
212 // We only load the TinyMCE js file once per request
215 $tinymce_mod_path = drupal_get_path('module', 'tinymce');
216 if (is_dir($tinymce_mod_path.
'/imagemanager/')) {
217 // if tinymce imagemanager is installed
218 drupal_add_js(drupal_get_path('module', 'tinymce') .
'/imagemanager/jscripts/mcimagemanager.js');
220 // TinyMCE Compressor
221 if (file_exists($tinymce_mod_path.
'tinymce/jscripts/tiny_mce/tiny_mce_gzip.php')) {
222 drupal_add_js($base_url.
'/'.
$tinymce_mod_path .
'/tinymce/jscripts/tiny_mce/tiny_mce_gzip.php');
225 // For some crazy reason IE will only load this JS file if the absolute reference is given to it.
226 drupal_add_js($base_url.
'/'.
$tinymce_mod_path .
'/tinymce/jscripts/tiny_mce/tiny_mce.js');
228 drupal_set_html_head($js_toggle);
229 // We have to do this becuase of some unfocused CSS in certain themes. See http://drupal.org/node/18879 for details
230 drupal_set_html_head('<style type="text/css" media="all">.mceEditor img { display: inline; }</style>');
232 // Load a TinyMCE init for each textarea.
233 if ($init) drupal_set_html_head($tinymce_invoke);
235 // Make sure to append to #suffix so it isn't completely overwritten
236 $element['#suffix'] .
= $wysiwyg_link;
243 * Implementation of hook_user().
245 function tinymce_user($type, &$edit, &$user, $category = NULL
) {
246 if ($type == 'form' && $category == 'account' && user_access('access tinymce')) {
247 $user_status = $edit['tinymce_status'] != NULL ?
$edit['tinymce_status'] : ($user->tinymce_status
!= NULL ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0));
248 $form['tinymce'] = array('#type' => 'fieldset', '#title' => t('TinyMCE settings'), '#weight' => 5, '#collapsible' => TRUE
, '#collapsed' => TRUE
);
249 $form['tinymce']['tinymce_status'] = array('#type' => 'radios', '#title' => t('Default status'), '#default_value' => $user_status, '#options' => array(t('Off'), t('On')), '#description' => t('Should rich-text editing be enabled or disabled by default in textarea fields?'));
250 return array('tinymce' => $form);
252 if ($type == 'validate') {
253 return array('tinymce_status' => $edit['tinymce_status']);
258 * @addtogroup themeable
263 * Customize a TinyMCE theme.
266 * An array of settings TinyMCE should invoke a theme. You may override any
267 * of the TinyMCE settings. Details here:
269 * http://tinymce.moxiecode.com/wrapper.php?url=tinymce/docs/using.htm
271 * @param textarea_name
272 * The name of the textarea TinyMCE wants to enable.
275 * The default tinymce theme name to be enabled for this textarea. The
276 * sitewide default is 'simple', but the user may also override this.
279 * A boolean flag that identifies id TinyMCE is currently running for this
280 * request life cycle. It can be ignored.
282 function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
283 switch ($textarea_name) {
284 // Disable tinymce for these textareas
285 case
'log': // Book log
286 case
'img_assist_pages':
287 case
'caption': // signature
289 case
'access_pages': //TinyMCE profile settings.
293 // Force the 'simple' theme for some of the smaller textareas.
298 $init['theme'] = 'simple';
299 foreach ($init as
$k => $v) {
300 if (strstr($k, 'theme_advanced_')) unset($init[$k]);
305 // Add some extra features when using the advanced theme.
306 switch ($theme_name) {
308 //$init['extended_valid_elements'] = array('a[href|target|name|title|onclick]');
312 // Always return $init; !!
316 /** @} End of addtogroup themeable */
319 * Grab the themes available to TinyMCE.
321 * TinyMCE themes control the functionality and buttons that are available to a
322 * user. Themes are only looked for within the default TinyMCE theme directory.
324 * NOTE: This function is not used in this release. We are only using advanced theme.
327 * An array of theme names.
329 function _tinymce_get_themes() {
330 static
$themes = array();
333 $theme_loc = drupal_get_path('module', 'tinymce') .
'/tinymce/jscripts/tiny_mce/themes/';
334 if (is_dir($theme_loc) && $dh = opendir($theme_loc)) {
335 while (($file = readdir($dh)) !== false
) {
336 if (!in_array($file, array('.', '..', 'CVS')) && is_dir($theme_loc .
$file)) {
337 $themes[$file] = $file;
349 * Return plugin metadata from the plugin registry.
351 * We also scrape each plugin's *.js file for the human friendly name and help
352 * text URL of each plugin.
355 * An array for each plugin.
357 function _tinymce_get_buttons($skip_metadata = TRUE
) {
358 include_once(drupal_get_path('module', 'tinymce').
'/plugin_reg.php');
359 $plugins = _tinymce_plugins();
360 if ($skip_metadata == FALSE
&& is_array($plugins)) {
361 foreach ($plugins as
$name => $plugin) {
362 $file = drupal_get_path('module', 'tinymce').
'/tinymce/jscripts/tiny_mce/plugins/'.
$name .
'/editor_plugin_src.js';
363 // Grab the plugin metadata by scanning the *.js file.
364 if (file_exists($file)) {
365 $lines = file($file);
366 $has_longname = FALSE
;
367 $has_infourl = FALSE
;
368 foreach ($lines as
$line) {
369 if ($has_longname && $has_infourl) break;
370 if (strstr($line, 'longname')) {
371 $start = strpos($line, "'") + 1;
372 $end = strrpos($line, "'") - $start;
373 $metadata[$name]['longname'] = substr($line, $start, $end);
374 $has_longname = TRUE
;
376 elseif (strstr($line, 'infourl')) {
377 $start = strpos($line, "'") + 1;
378 $end = strrpos($line, "'") - $start;
379 $metadata[$name]['infourl'] = substr($line, $start, $end);
385 // Find out the buttons a plugin has.
386 foreach ($plugin as
$k => $v) {
387 if (strstr($k, 'theme_advanced_buttons')) {
388 $metadata[$name]['buttons'] = array_merge((array) $metadata[$name]['buttons'], $plugin[$k]);
397 /********************************************************************
398 * Module Functions :: Public
399 ********************************************************************/
402 * Controller for tinymce administrative settings.
404 function tinymce_admin($arg = NULL
) {
405 $edit = $_POST['edit'];
408 $op = $arg && !$op ?
$arg : $op;
412 $breadcrumb[] = array('path' => 'admin', 'title' => t('administer'));
413 $breadcrumb[] = array('path' => 'admin/settings/tinymce', 'title' => t('tinymce'));
414 $breadcrumb[] = array('path' => 'admin/settings/tinymce/add', 'title' => t('Add new tinymce profile'));
415 menu_set_location($breadcrumb);
416 $output = tinymce_profile_form($edit);
420 drupal_set_title(t('Edit tinymce profile'));
421 $output = tinymce_profile_form(tinymce_profile_load(urldecode(arg(4))));
425 tinymce_profile_delete(urldecode(arg(4)));
426 drupal_set_message(t('Deleted profile'));
427 drupal_goto('admin/settings/tinymce');
430 case
t('Create profile');
431 case
t('Update profile');
432 if (tinymce_profile_validate($edit)) {
433 tinymce_profile_save($edit);
434 $edit['old_name'] ?
drupal_set_message(t('Your tinymce profile has been updated.')) : drupal_set_message(t('Your tinymce profile has been created.'));
435 drupal_goto('admin/settings/tinymce');
438 $output = tinymce_profile_form($edit);
442 case
t('Save settings'):
443 variable_set('tinymce_default_state', $edit['tinymce_default_state']);
444 drupal_set_message(t('Settings updated'));
445 drupal_goto('admin/settings/tinymce');
449 drupal_set_title(t('TinyMCE settings (%revision)', array('%revision' => '$Revision$')));
450 //Check if TinyMCE is installed.
451 $tinymce_loc = drupal_get_path('module', 'tinymce') .
'/tinymce/';
452 if (!is_dir($tinymce_loc)) {
453 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');
455 $output = tinymce_profile_overview();
458 print theme('page', $output);
462 * Return an array of initial tinymce config options from the current role.
464 function tinymce_config($profile) {
467 // Drupal theme path.
468 $themepath = drupal_get_path('theme', init_theme()).
'/';
469 $host = $base_url.
'/';
471 $settings = $profile->settings
;
473 // Build a default list of TinyMCE settings.
475 // Is tinymce on by default?
476 $status = isset($user->tinymce_status
) ?
$user->tinymce_status
: variable_get('tinymce_default_state', 0);
477 $init['mode'] = $status == 1 ?
'exact' : 'none';
478 $init['theme'] = $settings['theme'] ?
$settings['theme'] : 'simple';
479 $init['document_base_url'] = "$base_url/";
481 $init['verify_html'] = $settings['verify_html'] ?
$settings['verify_html'] : 'false';
482 $init['preformatted'] = $settings['preformatted'] ?
$settings['preformatted'] : 'false';
483 $init['convert_fonts_to_styles'] = $settings['convert_fonts_to_styles'] ?
$settings['convert_fonts_to_styles'] : 'false';
484 if ($init['theme'] == 'advanced') {
485 $init['plugins'] = array();
486 $init['theme_advanced_toolbar_location'] = $settings['toolbar_loc'] ?
$settings['toolbar_loc'] : 'bottom';
487 $init['theme_advanced_toolbar_align'] = $settings['toolbar_align'] ?
$settings['toolbar_align'] : 'left';
488 $init['theme_advanced_path_location'] = $settings['path_loc'] ?
$settings['path_loc'] : 'none';
489 $init['theme_advanced_resizing'] = $settings['resizing'] ?
$settings['resizing'] : 'false';
490 $init['theme_advanced_blockformats'] = $settings['block_formats'] ?
$settings['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6';
492 if (is_array($settings['buttons'])) {
493 // This gives us the $plugins variable.
494 $plugins = _tinymce_get_buttons();
496 // Find the enabled buttons and the mce row they belong on. Also map the
497 // plugin metadata for each button.
498 $plugin_tracker = array();
499 foreach ($plugins as
$rname => $rplugin) { // Plugin name
500 foreach ($rplugin as
$mce_key => $mce_value) { // TinyMCE key
501 foreach ($mce_value as
$k => $v) { // Buttons
502 if ($settings['buttons'][$rname .
'-' .
$v]) {
503 if (!in_array($rname, $plugin_tracker)) $plugin_tracker[] = $rname;
504 $init[$mce_key][] = $v;
510 // Add the rest of the TinyMCE config options to the $init array for each button.
511 if (is_array($plugin_tracker)) {
512 foreach ($plugin_tracker as
$pname) {
513 if ($pname != 'default') $init['plugins'][] = $pname;
514 foreach ($plugins[$pname] as
$mce_key => $mce_value) {
515 if (!strstr($mce_key, 'theme_advanced_buttons')) {
516 $init[$mce_key] = $mce_value;
523 foreach ($init as
$mce_key => $mce_value) {
524 if (is_array($mce_value)) $mce_value = array_unique($mce_value);
525 $init[$mce_key] = $mce_value;
528 // Shuffle buttons around so that row 1 always has the most buttons,
529 // followed by row 2, etc. Note: These rows need to be set to NULL otherwise
530 // TinyMCE loads it's own buttons inherited from the theme.
531 if (!$init['theme_advanced_buttons1']) $init['theme_advanced_buttons1'] = array();
532 if (!$init['theme_advanced_buttons2']) $init['theme_advanced_buttons2'] = array();
533 if (!$init['theme_advanced_buttons3']) $init['theme_advanced_buttons3'] = array();
535 $min_btns = 5; // Minimum number of buttons per row.
536 $num2 = count($init['theme_advanced_buttons2']);
537 $num3 = count($init['theme_advanced_buttons3']);
539 if ($num3 < $min_btns) {
540 $init['theme_advanced_buttons2'] = array_merge($init['theme_advanced_buttons2'], $init['theme_advanced_buttons3']);
541 $init['theme_advanced_buttons3'] = array();
543 if ($num2 < $min_btns) {
544 $init['theme_advanced_buttons1'] = array_merge($init['theme_advanced_buttons1'], $init['theme_advanced_buttons2']);
545 $init['theme_advanced_buttons2'] = array();
550 if ($edit['css_classes']) $init['theme_advanced_styles'] = $settings['css_classes'];
552 if ($settings['css_setting'] == 'theme') {
553 $css = $themepath .
'style.css';
554 if (file_exists($css)) {
555 $init['content_css'] = $host .
$css;
558 else if ($settings['css_setting'] == 'self') {
559 $init['content_css'] = str_replace(array('%h', '%t'), array($host, $themepath), $settings['css_path']);
566 * Remove a profile from the database.
568 function tinymce_profile_delete($name) {
569 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $name);
570 db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $name);
574 * Return an HTML form for profile configuration.
576 function tinymce_profile_form($edit) {
577 $edit = array2object($edit);
579 // Only display the roles that currently don't have a tinymce profile. One
581 $orig_roles = user_roles(FALSE
, 'access tinymce');
582 $roles = $orig_roles;
583 if (arg(3) == 'add') {
584 $result = db_query('SELECT DISTINCT(rid) FROM {tinymce_role}');
585 while ($data = db_fetch_object($result)) {
586 unset($roles[$data->rid
]);
589 drupal_set_message(t('You must assign at least one role with the \'access tinymce\' permission before creating a profile.'), 'error');
592 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');
594 else if (count($orig_roles) != count($roles)) {
595 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.'));
597 $btn = t('Create profile');
600 $form['old_name'] = array('#type' => 'hidden', '#value' => $edit->name
);
601 $btn = t('Update profile');
604 $form['basic'] = array('#type' => 'fieldset', '#title' => t('Basic setup'), '#collapsible' => TRUE
, '#collapsed' => TRUE
);
605 $form['basic']['name'] = array('#type' => 'textfield', '#title' => t('Profile name'), '#default_value' => $edit->name
, '#size' => 40, '#maxlength' => 128, '#description' => t('Enter a unique name for this profile. This name is only visible in the tinymce administration page.'), '#required' => TRUE
);
606 $form['basic']['rids'] = array('#type' => 'checkboxes', '#title' => t('Roles allowed to use this profile'), '#default_value' => array_keys((array) $edit->rids
), '#options' => $roles, '#description' => t('Select at least one role. Listed are the roles with \'access tinymce\' permission.'), '#required' => TRUE
);
607 $form['basic']['theme'] = array('#type' => 'hidden', '#value' => $edit->settings
['theme'] ?
$edit->settings
['theme'] : 'advanced');
608 $form['basic']['access'] = array('#type' => 'radios', '#title' => t('Make tinymce visible on'), '#default_value' => $edit->settings
['access'], '#options' => array(t('all pages'), t('specific pages')));
609 $form['basic']['access_pages'] = array('#type' => 'textarea', '#title' => t('Specific pages'), '#default_value' => $edit->settings
['access_pages'] ?
$edit->settings
['access_pages'] : tinymce_help('admin/settings/tinymce#pages'), '#cols' => 40, '#rows' => 5, '#description' => 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."));
611 $form['buttons'] = array('#type' => 'fieldset', '#title' => t('Buttons'), '#collapsible' => TRUE
, '#collapsed' => TRUE
, '#tree' => TRUE
, '#theme' => 'tinymce_profile_form_buttons');
613 $metadata = _tinymce_get_buttons(FALSE
);
614 // Generate the button list.
615 foreach($metadata as
$name => $meta) {
616 if (is_array($meta['buttons'])) {
617 foreach ($meta['buttons'] as
$button) {
618 if ($name != 'default') {
619 $img_src = drupal_get_path('module', 'tinymce').
"/tinymce/jscripts/tiny_mce/plugins/$name/images/$name.gif";
621 //correct for plugins that have more than one button
622 if (!file_exists($img_src)) {
623 $img_src = drupal_get_path('module', 'tinymce').
"/tinymce/jscripts/tiny_mce/plugins/$name/images/$button.gif";
627 $img_src = drupal_get_path('module', 'tinymce').
"/tinymce/jscripts/tiny_mce/themes/advanced/images/$button.gif";
629 $b = file_exists($img_src) ?
'<img src="'.
$img_src .
'" title="'.
$button .
'" style="border: 1px solid grey; vertical-align: middle;" />' : $button;
631 if ($name == 'default') {
635 $title = $metadata[$name]['longname'] ?
$metadata[$name]['longname'] : $name;
636 if ($metadata[$name]['infourl']) {
637 $title = '<a href="'.
$metadata[$name]['infourl'] .
'" target="_blank">'.
$title .
'</a>';
639 $title = $b .
' – '.
$title;
641 $form_value = $edit->settings
['buttons'][$name .
'-' .
$button];
642 $form['buttons'][$name .
'-' .
$button] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value, '#description' => $description);
646 $title = $metadata[$name]['longname'] ?
$metadata[$name]['longname'] : $name;
647 if ($metadata[$name]['infourl']) {
648 $title = '<a href="'.
$metadata[$name]['infourl'] .
'" target="_blank">'.
$title .
'</a>';
650 $form_value = $edit->settings
['buttons'][$name];
651 $form['buttons'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value, '#description' => $description);
655 $form['appearance'] = array('#type' => 'fieldset', '#title' => t('Editor appearance'), '#collapsible' => TRUE
, '#collapsed' => TRUE
);
656 $form['appearance']['toolbar_loc'] = array('#type' => 'select', '#title' => t('Toolbar location'), '#default_value' => $edit->settings
['toolbar_loc'], '#options' => array('bottom' => 'bottom', 'top' => 'top'), '#description' => t('Show toolbar at the top or bottom of the editor area?'));
657 $form['appearance']['toolbar_align'] = array('#type' => 'select', '#title' => t('Toolbar alignment'), '#default_value' => $edit->settings
['toolbar_align'], '#options' => array('center' => 'center', 'left' => 'left', 'right' => 'right'), '#description' => t('Align tool icons left, center, or right within the toolbar.'));
658 $form['appearance']['path_loc'] = array('#type' => 'select', '#title' => t('Path location'), '#default_value' => $edit->settings
['path_loc'], '#options' => array('none' => 'none', 'top' => 'top', 'bottom' => 'bottom'), '#description' => t('Path to html elements (i.e. "body>table>tr>td"). Show at top, bottom, or not at all.'));
659 $form['appearance']['resizing'] = array('#type' => 'select', '#title' => t('Enable resizing button'), '#default_value' => $edit->settings
['resizing'], '#options' => array('false' => 'false', 'true' => 'true'), '#description' => t(' This option gives you the ability to enable/disable the resizing button.'));
660 $form['appearance']['block_formats'] = array('#type' => 'textfield', '#title' => t('Block formats'), '#default_value' => $edit->settings
['block_formats'] ?
$edit->settings
['block_formats'] : 'p,address,pre,h1,h2,h3,h4,h5,h6', '#size' => 40, '#maxlength' => 250, '#description' => t('Comma separated list of HTML block formats. You can only remove elements, not add.'));
662 $form['output'] = array('#type' => 'fieldset', '#title' => t('Cleanup/Output'), '#collapsible' => TRUE
, '#collapsed' => TRUE
);
663 $form['output']['verify_html'] = array('#type' => 'select', '#title' => t('Verify HTML'), '#default_value' => $edit->settings
['verify_html'], '#options' => array('true' => 'true', 'false' => 'false'), '#description' => 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.'));
664 $form['output']['preformatted'] = array('#type' => 'select', '#title' => t('Preformatted'), '#default_value' => $edit->settings
['preformatted'], '#options' => array('false' => 'false', 'true' => 'true'), '#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.'));
665 $form['output']['convert_fonts_to_styles'] = array('#type' => 'select', '#title' => t('Convert <font> tags to styles'), '#default_value' => $edit->settings
['convert_fonts_to_styles'], '#options' => array('true' => 'true', 'false' => 'false'), '#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.'));
667 $form['css'] = array('#type' => 'fieldset', '#title' => t('CSS'), '#collapsible' => TRUE
, '#collapsed' => TRUE
);
668 $form['css']['css_setting'] = array('#type' => 'select', '#title' => t('Editor CSS'), '#default_value' => $edit->settings
['css_setting'] ?
$edit->settings
['css_setting'] : 'theme', '#options' => array('theme' => 'use theme css', 'self' => 'define css', 'none' => 'tinyMCE default'), '#description' => 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.'));
669 $form['css']['css_path'] = array('#type' => 'textfield', '#title' => t('CSS path'), '#default_value' => $edit->settings
['css_path'], '#size' => 40, '#maxlength' => 255, '#description' => t('Enter path to CSS file (example: "css/editor.css").<br />Macros: %h (host name: http://www.example.com/), %t (path to theme: theme/yourtheme/)<br />Be sure to select "define css" above.'));
670 $form['css']['css_classes'] = array('#type' => 'textfield', '#title' => t('CSS classes'), '#default_value' => $edit->settings
['css_classes'], '#size' => 40, '#maxlength' => 255, '#description' => 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.'));
672 $form['submit'] = array('#type' => 'submit', '#value' => $btn);
674 $output .
= drupal_get_form('tinymce_profile_form', $form);
680 * Layout for the buttons in the tinymce profile form
682 function theme_tinymce_profile_form_buttons($form) {
685 // Flatten forms array
686 foreach (element_children($form) as
$key) {
687 $buttons[] = form_render($form[$key]);
690 //split checkboxes into rows with 3 columns
691 $total = count($buttons);
693 for ($i = 0; $i < $total; $i++) {
695 $row[] = array('data' => $buttons[$i]);
696 $row[] = array('data' => $buttons[++$i]);
697 $row[] = array('data' => $buttons[++$i]);
701 $output = theme('table', array(), $rows, array('width' => '100%'));
707 * Load all profiles. Just load one profile if $name is passed in.
709 function tinymce_profile_load($name = '') {
710 static
$profiles = array();
713 $roles = user_roles();
714 $result = db_query('SELECT * FROM {tinymce_settings}');
715 while ($data = db_fetch_object($result)) {
716 $data->settings
= unserialize($data->settings
);
717 $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name
);
719 while ($r = db_fetch_object($result2)) {
720 $role[$r->rid
] = $roles[$r->rid
];
724 $profiles[$data->name
] = $data;
728 return ($name ?
$profiles[$name] : $profiles);
732 * Controller for tinymce profiles.
734 function tinymce_profile_overview() {
737 $profiles = tinymce_profile_load();
739 $output .
= t('<p><a href="%create-profile-url">Create new profile</a></p>', array('%create-profile-url' => url('admin/settings/tinymce/add')));
740 $roles = user_roles();
741 $header = array(t('Profile'), t('Roles'), t('Operations'));
742 foreach ($profiles as
$p) {
743 $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'));
745 $output .
= theme('table', $header, $rows).
'<p> </p>';
748 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'))));
751 $form['settings'] = array('#type' => 'fieldset', '#title' => t('Default settings'), '#collapsible' => TRUE
);
752 $form['settings']['tinymce_default_state'] = array('#type' => 'radios', '#title' => t('Default tinymce state'), '#default_value' => variable_get('tinymce_default_state', 0), '#options' => array(t('Off'), t('On')), '#description' => 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.'));
753 $form['settings']['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
755 $output .
= drupal_get_form('settings', $form);
761 * Save a profile to the database.
763 function tinymce_profile_save($edit) {
764 db_query("DELETE FROM {tinymce_settings} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
765 db_query("DELETE FROM {tinymce_role} WHERE name = '%s' or name = '%s'", $edit['name'], $edit['old_name']);
766 db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], serialize($edit));
767 foreach ($edit['rids'] as
$rid => $value) {
768 //if this rid has been checked, insert it
770 db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid);
776 * Profile validation.
778 function tinymce_profile_validate($edit) {
781 if (!$edit['name']) {
782 $errors['name'] = t('You must give a profile name.');
785 if (!$edit['rids']) {
786 $errors['rids'] = t('You must select at least one role.');
789 foreach ($errors as
$name => $message) {
790 form_set_error($name, $message);
793 return count($errors) == 0;
796 /********************************************************************
797 * Module Functions :: Private
798 ********************************************************************/
801 * Determine if TinyMCE has permission to be used on the current page.
804 * TRUE if can render, FALSE if not allowed.
806 function _tinymce_page_match($edit) {
807 //Kill TinyMCE if we're editing a textarea with PHP in it!
808 if ($_POST['edit']['format'] == 2) {
812 // PHP input formats are #2 in the filters table.
813 preg_match("|^node/(\d+)(/edit)$|", $_GET['q'], $match);
814 if (intval($match[1]) > 0) {
815 if (db_result(db_query('SELECT format FROM {node_revisions} WHERE nid = %d AND vid = %d AND format = 2', $match[1], $match[1]))) {
821 if ($edit->settings
['access'] == 0) {
826 $pages = $edit->settings
['access_pages'] ?
$edit->settings
['access_pages'] : tinymce_help('admin/settings/tinymce#pages');
828 $path = drupal_get_path_alias($_GET['q']);
829 $regexp = '/^('.
preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'.
variable_get('site_frontpage', 'node') .
'\2'), preg_quote($pages, '/')) .
')$/';
830 $page_match = preg_match($regexp, $path);