',
- '',
- '
',
- '',
- '',
- '',
- '',
- '',
- '',
- '| ',
- ' | ',
- '',
- '',
- '',
- '',
- '',
- '',
- )));
- variable_set('filter_html_help_1', 1);
- variable_set('filter_html_nofollow_1', 0);
-
- // 5) All done
- drupal_set_message(t('TinyMCE has been configured.'));
-}
+/**
+ * Implementation of hook_menu().
+ */
+function tinymce_autoconf_menu($may_cache) {
+ $items = array();
+ if ($may_cache) {
+ $items[] = array(
+ 'path' => 'admin/settings/tinymce_autoconf',
+ 'title' => t('TinyMCE: create default profiles'),
+ 'callback' => 'drupal_get_form',
+ 'callback arguments' => array('tinymce_autoconf_form', NULL),
+ 'description' => t('Automatically creates 3 TinyMCE profiles: comments, basic, advanced.'),
+ 'access' => user_access('administer tinymce'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ }
+ return $items;
+}
+
+/**
+ * Creates the TinyMCE automatic configuration page
+ */
+function tinymce_autoconf_form() {
+ $form = array();
+
+ $form['description'] = array(
+ '#value' => t('This will automatically create 3 TinyMCE profiles: comments, basic, and
+ advanced.
+
+ Warning - Any existing TinyMCE profiles named "Comments", "Basic", and "Advanced" will be
+ overwritten by this module. Use with care.
+
+ This also creates a "code" style for the font-style select box. In order to utilize
+ this style, you must have this (or similar) CSS somewhere in your stylesheet:
+
+.code {
+ background-color:#CCCCCC;
+ border:1px solid #DDDDDD;
+ display:block;
+ font-family:\'lucida console\',courier,monospace;
+ overflow:auto;
+ padding:2em;
+ white-space:pre;
+ width: 100%;
+}
+
+
+ The majority of the settings for these profile were developed by Boris Mann of Raincity Studios.
'),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Create/Restore TinyMCE profiles'),
+ );
+ return $form;
+}
+
+/**
+ * Ensures that a role has a permission.
+ * @param $rid ID of the role
+ * @param $perm Permission to ensure the role has
+ */
+function tinymce_autoconf_ensure_role_permission($rid, $perm) {
+ $result = db_query('SELECT perm FROM {permission} WHERE rid = %d', $rid);
+ if ($row = db_fetch_object($result)) {
+ $permissions = explode(', ', $row->perm);
+ }
+ else {
+ $permissions = array();
+ }
+ if (array_search($perm, $permissions) === FALSE) {
+ $permissions[] = $perm;
+ db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
+ db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $permissions));
+ }
+}
+
+/**
+ * Sets the roles that have access to a TinyMCE profile
+ * @param $profile Name of the TinyMCE profile
+ * @param $roles Array containing the role IDs to give access to
+ */
+function tinymce_autoconf_set_profile_roles($profile, $roles) {
+ db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $profile);
+ foreach ($roles as $rid) {
+ db_query("INSERT INTO {tinymce_role} VALUES ('%s', %d)", $profile, $rid);
+ }
+}
+
+
+/**
+ * Do the configuration...
+ */
+function tinymce_autoconf_form_submit($form_id, $form_values) {
+ // 1) Give the "authenticated user" role access rights to use TinyMCE
+ tinymce_autoconf_ensure_role_permission(DRUPAL_AUTHENTICATED_RID, 'access tinymce');
+
+ // 2) Create the TinyMCE profile "default" and give "authenticated user" access
+ tinymce_autoconf_set_profile_roles('default', array(DRUPAL_AUTHENTICATED_RID));
+
+ // 3) Remove default line break filter for the Full HTML format
+ // NOTE: voodoo magic -- have to know that Full HTML = 3, and that line break delta = 2
+ // Should probably define constants for this in crud.inc
+ install_remove_filter(3, 'filter', 2);
+
+ // 4) Set the settings for filtered HTML
+ variable_set('filter_default_format', 1);
+ variable_set('filter_html_1', 1);
+ variable_set('filter_url_length_1', 72);
+ variable_set('allowed_html_1', implode(' ', array(
+ '',
+ '',
+ '',
+ '',
+ ' ',
+ '',
+ '',
+ '',
+ '- ',
+ '
',
+ '',
+ ' ',
+ '- ',
+ '',
+ '',
+ '
',
+ '',
+ '',
+ '',
+ '',
+ ' ',
+ '',
+ ' ',
+ '- ',
+ '
',
+ '',
+ ' ',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '| ',
+ ' | ',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ )));
+ variable_set('filter_html_help_1', 1);
+ variable_set('filter_html_nofollow_1', 0);
+
+ // 5) TinyMCE
+ $comment_settings = array(
+ 'name' => 'Comments',
+ 'old_name' => 'Comments',
+ 'default' => 'true',
+ 'user_choose' => 'false',
+ 'show_toggle' => 'false',
+ 'theme' => 'advanced',
+ 'language' => 'en',
+ 'safari_message' => 'false',
+ 'access' => '1',
+ 'access_pages' => "node/*\ncomment/*",
+ 'buttons' => array(
+ 'autosave' => '1',
+ 'default-bold' => '1',
+ 'default-italic' => '1',
+ 'default-underline' => '1',
+ 'default-strikethrough' => '1',
+ 'default-link' => '1',
+ 'default-unlink' => '1',
+ 'emotions-emotions' => '1',
+ 'font-styleselect' => '1',
+ ),
+ 'toolbar_loc' => 'top',
+ 'toolbar_align' => 'center',
+ 'path_loc' => 'bottom',
+ 'resizing' => 'true',
+ 'block_formats' => 'p,address,pre,h1,h2,h3,h4,h5,h6',
+ 'verify_html' => 'true',
+ 'preformatted' => 'false',
+ 'convert_fonts_to_styles' => 'true',
+ 'css_setting' => 'theme',
+ 'css_path' => '',
+ 'css_classes' => 'Code=code',
+ );
+
+ // We'll install the Comments profile and associate it with the anonymous and authenticated users
+ install_tinymce_create_profile('Comments', $comment_settings );
+
+ // Let's start off with the same base
+ $basic_settings = $comment_settings;
+
+ // now we just override the changes
+ $basic_settings['name'] = 'Basic';
+ $basic_settings['old_name'] = 'Basic';
+ $basic_settings['user_choose'] = 'true';
+
+ // we'll start with the same button set and merge in new ones
+ $basic_settings['buttons'] = array_merge(
+ $comment_settings['buttons'],
+ array(
+ 'default-justifyleft' => '1',
+ 'default-justifycenter' => '1',
+ 'default-justifyright' => '1',
+ 'default-bullist' => '1',
+ 'default-numlist' => '1',
+ 'default-indent' => '1',
+ 'default-outdent' => '1',
+ 'default-hr' => '1',
+ 'default-image' => '1',
+ 'spellchecker-spellchecker' => '1',
+ 'drupalbreak-drupalbreak' => '1',
+ 'drupalimage-drupalimage' => '1'
+ )
+ );
+ $basic_settings['toolbar_align'] = 'left';
+
+ // Now we create the Basic profile and assign it to the Contributor role
+ install_tinymce_create_profile('Basic', $basic_settings );
+
+ // Let's do the same with Advanced, start it off with Basic settings
+ $advanced_settings = $basic_settings;
+
+ // Now we just override the changes -- main difference is a Tables button and showing the toggle to disable rich text
+ $advanced_settings['name'] = 'Advanced';
+ $advanced_settings['old_name'] = 'Advanced';
+ $advanced_settings['show_toggle'] = 'true';
+
+ // Only addition is ability to work with tables
+ $advanced_settings['buttons']['table-tablecontrols'] = '1';
+
+ // Now we create the Advanced profile and assign it to the Site Admin role
+ install_tinymce_create_profile('Advanced', $advanced_settings );
+
+ drupal_set_message(t('The TinyMCE profiles have been created/restored.'));
+}
+
+/**
+ * Remove the specified filter from the specified format
+ * @param $format_id The ID of the format to remove the filter from
+ * @param $module The module this filter belongs to
+ * @param $delta The delta of this filter
+ *
+ * NOTE: the module name + the delta is what uniquely identifies a filter
+ */
+function install_remove_filter($format_id, $module, $delta) {
+ db_query("DELETE FROM {filters} WHERE format = %d AND module = '%s' AND delta = %d", $format_id, $module, $delta);
+}
+
+/**
+ * Create a new TinyMCE profile and set the settings
+ * @param $name A text string identifying the profile
+ * @param $settings An associative array containing key value pairs
+ */
+function install_tinymce_create_profile($name, $settings) {
+ db_query("DELETE FROM {tinymce_settings} WHERE name='%s'", $name);
+ db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $name, serialize($settings));
+}
\ No newline at end of file
| |