| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_menu().
|
| 6 |
*/
|
| 7 |
function tinymce_autoconf_menu($may_cache) {
|
| 8 |
$items = array();
|
| 9 |
if ($may_cache) {
|
| 10 |
$items[] = array(
|
| 11 |
'path' => 'admin/settings/tinymce_autoconf',
|
| 12 |
'title' => t('TinyMCE -- create default profile'),
|
| 13 |
'callback' => 'drupal_get_form',
|
| 14 |
'callback arguments' => array('tinymce_autoconf_form', NULL),
|
| 15 |
'description' => t('Delivers a secure configuration of the TinyMCE module with a single mouse click.'),
|
| 16 |
'access' => user_access('administer tinymce'),
|
| 17 |
'type' => MENU_NORMAL_ITEM,
|
| 18 |
);
|
| 19 |
}
|
| 20 |
return $items;
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Creates the TinyMCE automatic configuration page
|
| 25 |
* It is one big button and a short description of the button. What could be simpler?
|
| 26 |
*/
|
| 27 |
function tinymce_autoconf_form() {
|
| 28 |
$form = array();
|
| 29 |
$form['submit'] = array(
|
| 30 |
'#type' => 'submit',
|
| 31 |
'#value' => t('Create/Restore TinyMCE defaults'),
|
| 32 |
'#prefix' => t('This will create a new secure configuration of the TinyMCE module, or restore a previously created one back to how it was originally.'),
|
| 33 |
'#suffix' => '<br/>'. t('The following actions will be performed:') . theme('item_list', array(
|
| 34 |
t('Gives authenticated users permission to use TinyMCE.'),
|
| 35 |
t('Creates/restores a default TinyMCE configuration.'),
|
| 36 |
t('Sets Filtered HTML as the default input format and configures it securely.'),
|
| 37 |
)),
|
| 38 |
);
|
| 39 |
return $form;
|
| 40 |
}
|
| 41 |
|
| 42 |
/**
|
| 43 |
* Ensures that a role has a permission.
|
| 44 |
* @param $rid ID of the role
|
| 45 |
* @param $perm Permission to ensure the role has
|
| 46 |
*/
|
| 47 |
function tinymce_autoconf_ensure_role_permission($rid, $perm) {
|
| 48 |
$result = db_query('SELECT perm FROM {permission} WHERE rid = %d', $rid);
|
| 49 |
if ($row = db_fetch_object($result)) {
|
| 50 |
$permissions = explode(', ', $row->perm);
|
| 51 |
}
|
| 52 |
else {
|
| 53 |
$permissions = array();
|
| 54 |
}
|
| 55 |
if (array_search($perm, $permissions) === FALSE) {
|
| 56 |
$permissions[] = $perm;
|
| 57 |
db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
|
| 58 |
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $permissions));
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Sets the roles that have access to a TinyMCE profile
|
| 64 |
* @param $profile Name of the TinyMCE profile
|
| 65 |
* @param $roles Array containing the role IDs to give access to
|
| 66 |
*/
|
| 67 |
function tinymce_autoconf_set_profile_roles($profile, $roles) {
|
| 68 |
db_query("DELETE FROM {tinymce_role} WHERE name = '%s'", $profile);
|
| 69 |
foreach ($roles as $rid) {
|
| 70 |
db_query("INSERT INTO {tinymce_role} VALUES ('%s', %d)", $profile, $rid);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Sets the settings for a TinyMCE profile
|
| 76 |
* @param $profile Name of the TinyMCE profile
|
| 77 |
* @param $settings Array containing the new profile settings
|
| 78 |
*/
|
| 79 |
function tinymce_autoconf_set_profile_settings($profile, $settings) {
|
| 80 |
db_query("DELETE FROM {tinymce_settings} WHERE name = '%s'", $profile);
|
| 81 |
db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $profile, serialize($settings));
|
| 82 |
}
|
| 83 |
|
| 84 |
/**
|
| 85 |
* Creates the TinyMCE automatic configuration page
|
| 86 |
* It is one big button and a short description of the button. What could be simpler?
|
| 87 |
*/
|
| 88 |
function tinymce_autoconf_form_submit($form_id, $form_values) {
|
| 89 |
// 1) Give the "authenticated user" role access rights to use TinyMCE
|
| 90 |
tinymce_autoconf_ensure_role_permission(DRUPAL_AUTHENTICATED_RID, 'access tinymce');
|
| 91 |
|
| 92 |
// 2) Create the TinyMCE profile "default" and give "authenticated user" access
|
| 93 |
tinymce_autoconf_set_profile_roles('default', array(DRUPAL_AUTHENTICATED_RID));
|
| 94 |
|
| 95 |
// 3) Set the settings for the TinyMCE profile "default"
|
| 96 |
tinymce_autoconf_set_profile_settings('default', array(
|
| 97 |
'name' => 'default',
|
| 98 |
'rids' => array(DRUPAL_AUTHENTICATED_RID),
|
| 99 |
'default' => 'true',
|
| 100 |
'user_choose' => 'true',
|
| 101 |
'show_toggle' => 'true',
|
| 102 |
'theme' => 'advanced',
|
| 103 |
'language' => 'en',
|
| 104 |
'safari_message' => 'false',
|
| 105 |
'access' => 1,
|
| 106 |
'access_pages' => implode("\n", array(
|
| 107 |
'node/*',
|
| 108 |
'user/*',
|
| 109 |
'comment/*',
|
| 110 |
)),
|
| 111 |
'buttons' => array(
|
| 112 |
'advhr-advhr' => 1,
|
| 113 |
'advimage' => 1,
|
| 114 |
'advlink' => 1,
|
| 115 |
'contextmenu' => 1,
|
| 116 |
'default-bold' => 1,
|
| 117 |
'default-italic' => 1,
|
| 118 |
'default-underline' => 1,
|
| 119 |
'default-strikethrough' => 1,
|
| 120 |
'default-justifyleft' => 1,
|
| 121 |
'default-justifycenter' => 1,
|
| 122 |
'default-justifyright' => 1,
|
| 123 |
'default-bullist' => 1,
|
| 124 |
'default-numlist' => 1,
|
| 125 |
'default-outdent' => 1,
|
| 126 |
'default-indent' => 1,
|
| 127 |
'default-link' => 1,
|
| 128 |
'default-unlink' => 1,
|
| 129 |
'default-image' => 1,
|
| 130 |
'default-cleanup' => 1,
|
| 131 |
'default-forecolor' => 1,
|
| 132 |
'default-backcolor' => 1,
|
| 133 |
'default-sup' => 1,
|
| 134 |
'default-sub' => 1,
|
| 135 |
'default-removeformat' => 1,
|
| 136 |
'default-charmap' => 1,
|
| 137 |
'emotions-emotions' => 1,
|
| 138 |
'font-fontselect' => 1,
|
| 139 |
'paste-pasteword' => 1,
|
| 140 |
'table-tablecontrols' => 1,
|
| 141 |
),
|
| 142 |
'toolbar_loc' => 'top',
|
| 143 |
'toolbar_align' => 'center',
|
| 144 |
'path_loc' => 'bottom',
|
| 145 |
'resizing' => 'true',
|
| 146 |
'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6',
|
| 147 |
'verify_html' => 'false',
|
| 148 |
'preformatted' => 'false',
|
| 149 |
'convert_fonts_to_spans' => 'false',
|
| 150 |
'remove_linebreaks' => 'false',
|
| 151 |
'apply_source_formatting' => 'true',
|
| 152 |
'css_setting' => 'theme',
|
| 153 |
'css_path' => '',
|
| 154 |
'css_classes' => '',
|
| 155 |
));
|
| 156 |
|
| 157 |
// 4) Set the settings for filtered HTML
|
| 158 |
variable_set('filter_default_format', 1);
|
| 159 |
variable_set('filter_html_1', 1);
|
| 160 |
variable_set('filter_url_length_1', 72);
|
| 161 |
variable_set('allowed_html_1', implode(' ', array(
|
| 162 |
'<a>',
|
| 163 |
'<b>',
|
| 164 |
'<address>',
|
| 165 |
'<blockquote>',
|
| 166 |
'<br>',
|
| 167 |
'<caption>',
|
| 168 |
'<center>',
|
| 169 |
'<code>',
|
| 170 |
'<dd>',
|
| 171 |
'<del>',
|
| 172 |
'<div>',
|
| 173 |
'<dl>',
|
| 174 |
'<dt>',
|
| 175 |
'<em>',
|
| 176 |
'<font>',
|
| 177 |
'<h2>',
|
| 178 |
'<h3>',
|
| 179 |
'<h4>',
|
| 180 |
'<h5>',
|
| 181 |
'<h6>',
|
| 182 |
'<hr>',
|
| 183 |
'<i>',
|
| 184 |
'<img>',
|
| 185 |
'<li>',
|
| 186 |
'<ol>',
|
| 187 |
'<p>',
|
| 188 |
'<pre>',
|
| 189 |
'<span>',
|
| 190 |
'<strong>',
|
| 191 |
'<sub>',
|
| 192 |
'<sup>',
|
| 193 |
'<table>',
|
| 194 |
'<tbody>',
|
| 195 |
'<td>',
|
| 196 |
'<tfoot>',
|
| 197 |
'<th>',
|
| 198 |
'<thead>',
|
| 199 |
'<tr>',
|
| 200 |
'<u>',
|
| 201 |
'<ul>',
|
| 202 |
'<tr>',
|
| 203 |
)));
|
| 204 |
variable_set('filter_html_help_1', 1);
|
| 205 |
variable_set('filter_html_nofollow_1', 0);
|
| 206 |
|
| 207 |
// 5) All done
|
| 208 |
drupal_set_message(t('TinyMCE has been configured.'));
|
| 209 |
}
|