| Commit | Line | Data |
|---|---|---|
| 1b120ffb JS |
1 | <?php |
| 2 | // $Id$ | |
| 3 | /** | |
| 4 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net | |
| 5 | * Copyright (C) 2003-2008 Frederico Caldeira Knabben | |
| 6 | * | |
| 7 | * == BEGIN LICENSE == | |
| 8 | * | |
| 9 | * Licensed under the terms of any of the following licenses at your | |
| 10 | * choice: | |
| 11 | * | |
| 12 | * - GNU General Public License Version 2 or later (the "GPL") | |
| 13 | * http://www.gnu.org/licenses/gpl.html | |
| 14 | * | |
| 15 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") | |
| 16 | * http://www.gnu.org/licenses/lgpl.html | |
| 17 | * | |
| 18 | * - Mozilla Public License Version 1.1 or later (the "MPL") | |
| 19 | * http://www.mozilla.org/MPL/MPL-1.1.html | |
| 20 | * | |
| 21 | * == END LICENSE == | |
| 22 | * | |
| 23 | * @file | |
| 24 | * FCKeditor Module for Drupal 6.x | |
| 25 | * | |
| 26 | * This module allows Drupal to replace textarea fields with FCKeditor. | |
| 27 | * | |
| 28 | * This HTML text editor brings to the web many of the powerful functionalities | |
| 29 | * of known desktop editors like Word. It's really lightweight and doesn't | |
| 30 | * require any kind of installation on the client computer. | |
| 31 | */ | |
| 32 | ||
| 33 | /** | |
| 34 | * Main administrative page | |
| 35 | */ | |
| 36 | function fckeditor_admin_main() { | |
| a2c15b72 | 37 | $editor_path = fckeditor_path(TRUE); |
| 29d8625e | 38 | $fckconfig_file = $editor_path .'/fckconfig.js'; |
| a2c15b72 | 39 | if (!file_exists($fckconfig_file)) { |
| 42225b39 | 40 | drupal_set_message(t('Checking for %filename.', array('%filename' => $fckconfig_file))); |
| e905551c | 41 | drupal_set_message(t('The FCKeditor component is not installed correctly. Please go to the <a href="!fckeditorlink">FCKeditor homepage</a> to download the latest version. After that you must extract the files to %fckeditorpath and make sure that the directory %fckeditorsubdir and the file %fckeditorfile exist. Refer to the <a href="!readme">readme.txt</a> for more information.', array('!fckeditorlink' => url('http://www.fckeditor.net/download'), '!readme' => url('admin/help/fckeditor'), '%fckeditorpath' => $editor_path, '%fckeditorsubdir' => $editor_path .'/editor', '%fckeditorfile' => $editor_path .'/fckeditor.js')), 'error'); |
| 42225b39 | 42 | drupal_set_message(t('If you have FCKeditor already installed please edit <a href="!editg">FCKeditor Global Profile</a> and update FCKeditor path.', array('!editg' => url('admin/settings/fckeditor/editg'))), 'warning'); |
| 1b120ffb JS |
43 | return FALSE; |
| 44 | } | |
| a2c15b72 | 45 | |
| 1b120ffb JS |
46 | $access_fckeditor_roles = user_roles(FALSE, 'access fckeditor'); |
| 47 | if (!$access_fckeditor_roles) { | |
| 42225b39 | 48 | drupal_set_message(t('There is currently no role with the "access fckeditor" permission. Visit <a href="!acl">permissions</a> administration section.', array('!acl' => url('admin/user/permissions'))), 'warning'); |
| a2c15b72 | 49 | } |
| 1b120ffb JS |
50 | else { |
| 51 | $result = db_query_range("SELECT name FROM {fckeditor_settings} WHERE name<>'FCKeditor Global Profile'", 0, 1); | |
| 52 | $has_profiles = FALSE; | |
| 53 | //find profile other than Global | |
| 54 | if (($obj = db_fetch_object($result))) { | |
| 55 | $has_profiles = TRUE; | |
| 56 | } | |
| 57 | ||
| 58 | //find roles with profiles | |
| 59 | $result = db_query("SELECT rid FROM {fckeditor_role}"); | |
| 60 | $rids = array(); | |
| 61 | while (($obj = db_fetch_object($result))) { | |
| 62 | $rids[] = $obj->rid; | |
| 63 | } | |
| a2c15b72 | 64 | $rids = array_unique($rids); |
| 1b120ffb | 65 | if (!$has_profiles) { |
| 42225b39 | 66 | drupal_set_message(t('No FCKeditor profiles found. At this moment, nobody is able to use FCKeditor. Create new profile below.'), 'error'); |
| 1b120ffb JS |
67 | } |
| 68 | else { | |
| 69 | //not all roles with access fckeditor has their FCKeditor profile assigned | |
| 70 | $diff = array_diff(array_keys($access_fckeditor_roles), $rids); | |
| 71 | if ($diff) { | |
| 72 | $list = "<ul>"; | |
| 73 | foreach ($diff as $rid) { | |
| 74 | $list .= "<li>". $access_fckeditor_roles[$rid] ."</li>"; | |
| 75 | } | |
| 76 | $list .= "</ul>"; | |
| 42225b39 | 77 | drupal_set_message(t('Not all roles with <a href="!access">access fckeditor</a> permission are associated with FCKeditor profiles. As a result, users having the following roles may be unable to use FCKeditor: !list Create new or edit FCKeditor profiles below and in the <em>Basic setup</em> section, check "Roles allowed to use this profile".', array('!access' => url('admin/user/permissions'), '!list' => $list)), 'warning'); |
| 1b120ffb | 78 | } |
| a2c15b72 | 79 | } |
| 1b120ffb | 80 | } |
| a2c15b72 | 81 | |
| 1b120ffb JS |
82 | return fckeditor_profile_overview(); |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * Controller for fckeditor profiles. | |
| 87 | */ | |
| 88 | function fckeditor_profile_overview() { | |
| 89 | $output = ''; | |
| 90 | ||
| 91 | $profiles = fckeditor_profile_load(); | |
| 92 | if ($profiles) { | |
| 93 | $access_fckeditor_roles = user_roles(FALSE, 'access fckeditor'); | |
| 94 | $header = array(t('Profile'), t('Roles'), t('Operations')); | |
| 95 | foreach ($profiles as $p) { | |
| 96 | $rids = $p->rids; | |
| 97 | if ($p->name !== "FCKeditor Global Profile") { | |
| 98 | foreach (array_keys($p->rids) as $rid) { | |
| 99 | if (!isset($access_fckeditor_roles[$rid])) { | |
| 100 | unset($rids[$rid]); | |
| 101 | } | |
| a2c15b72 | 102 | } |
| 4255581d | 103 | $rows[] = array( |
| a2c15b72 | 104 | array('data' => $p->name, 'valign' => 'top'), |
| 105 | array('data' => implode("<br />\n", $rids)), | |
| 106 | array('data' => | |
| 107 | l(t('edit'), 'admin/settings/fckeditor/edit/'. urlencode($p->name)) .' '. | |
| 108 | l(t('clone'), 'admin/settings/fckeditor/clone/'. urlencode($p->name)) .' '. | |
| 4255581d WW |
109 | l(t('delete'), 'admin/settings/fckeditor/delete/'. urlencode($p->name)), 'valign' => 'top' |
| 110 | ) | |
| 111 | ); | |
| 1b120ffb JS |
112 | } |
| 113 | } | |
| 201b993d | 114 | $output .= '<h3>'. t('Profiles') .'</h3>'; |
| 1b120ffb JS |
115 | $output .= theme('table', $header, $rows); |
| 116 | $output .= '<p>'. l(t('Create new profile'), 'admin/settings/fckeditor/add') .'</p>'; | |
| 117 | } | |
| 118 | else { | |
| 42225b39 | 119 | drupal_set_message(t('No profiles found. Click here to <a href="!create">create a new profile</a>.', array('!create' => url('admin/settings/fckeditor/add')))); |
| 1b120ffb JS |
120 | } |
| 121 | ||
| 122 | $rows = array(); | |
| 123 | if (!isset($profiles['FCKeditor Global Profile'])) { | |
| 42225b39 | 124 | drupal_set_message(t('Global profile not found. Click here to <a href="!create">create the global profile</a>.', array('!create' => url('admin/settings/fckeditor/addg')))); |
| 1b120ffb JS |
125 | } |
| 126 | else { | |
| 42225b39 | 127 | $output .= "<h3>". t("Global settings") ."</h3>"; |
| 4255581d | 128 | $rows[] = array( |
| a2c15b72 | 129 | array('data' => t('FCKeditor Global Profile'), 'valign' => 'top'), |
| 4255581d WW |
130 | array('data' => l(t('edit'), 'admin/settings/fckeditor/editg') ." ". l(t('delete'), 'admin/settings/fckeditor/delete/FCKeditor Global Profile'), 'valign' => 'top') |
| 131 | ); | |
| 1b120ffb JS |
132 | $output .= theme('table', array(t('Profile'), t('Operations')), $rows); |
| 133 | } | |
| 134 | return $output; | |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 4255581d WW |
138 | * Clone profile |
| 139 | */ | |
| 140 | function fckeditor_admin_profile_clone_form($form_state, $oldprofile) { | |
| 141 | return fckeditor_admin_profile_form($form_state, $oldprofile); | |
| 142 | } | |
| 143 | ||
| 144 | function fckeditor_admin_profile_clone_form_validate($form_state, $oldprofile) { | |
| 145 | fckeditor_admin_profile_form_validate($form_state, $oldprofile); | |
| 146 | } | |
| 147 | ||
| 148 | function fckeditor_admin_profile_clone_form_submit($form, &$form_state) { | |
| 149 | $edit =& $form_state['values']; | |
| a2c15b72 | 150 | drupal_set_message(t('Your FCKeditor profile has been created.')); |
| 4255581d | 151 | $settings = fckeditor_admin_values_to_settings($edit); |
| 4059f348 | 152 | db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings); |
| 4255581d WW |
153 | fckeditor_rebuild_selectors($edit['name']); |
| 154 | if (!empty($edit['rids'])) { | |
| 155 | foreach (array_keys($edit['rids']) as $rid) { | |
| 156 | if ($edit['rids'][$rid]!=0) { | |
| 4059f348 | 157 | db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid); |
| 4255581d WW |
158 | } |
| 159 | } | |
| 160 | } | |
| 161 | $form_state['redirect'] = 'admin/settings/fckeditor'; | |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 1b120ffb JS |
165 | * Form builder for a normal profile |
| 166 | */ | |
| f60bb09c JS |
167 | function fckeditor_admin_profile_form($form_state, $profile = NULL) { |
| 168 | if ($profile != NULL) { | |
| 1b120ffb JS |
169 | $form['_profile'] = array( |
| 170 | '#type' => 'value', | |
| 171 | '#value' => $profile, | |
| 172 | ); | |
| 173 | } | |
| 174 | else { | |
| 175 | $profile = new stdClass(); | |
| 176 | } | |
| a2c15b72 | 177 | |
| 1b120ffb | 178 | module_load_include('lib.inc', 'fckeditor'); |
| a2c15b72 | 179 | |
| 1b120ffb JS |
180 | $toolbar_options = fckeditor_load_toolbar_options(); |
| 181 | $skin_options = fckeditor_load_skin_options(); | |
| 182 | $lang_options = fckeditor_load_lang_options(); | |
| 183 | ||
| 184 | // Only display the roles that currently don't have a fckeditor profile. One | |
| 185 | // profile per role. | |
| 186 | $orig_roles = user_roles(FALSE, 'access fckeditor'); | |
| 187 | $roles = $orig_roles; | |
| 188 | ||
| 189 | if (!empty($profile->rids) && !user_roles(FALSE, 'access fckeditor')) { | |
| 42225b39 | 190 | drupal_set_message(t('You haven\'t assigned "access fckeditor" <a href="!permissions">permissions</a> yet. It is recommended to assign the "access fckeditor" <a href="!permissions">permissions</a> before updating FCKeditor profiles.', array('!permissions' => url('admin/user/permissions'))), 'warning'); |
| 1b120ffb JS |
191 | } |
| 192 | ||
| 193 | if (empty($profile->name)) { | |
| 4059f348 | 194 | $result = db_query("SELECT DISTINCT(rid) FROM {fckeditor_role}"); |
| 1b120ffb JS |
195 | while (($data = db_fetch_object($result))) { |
| 196 | if ((empty($profile->rids) || !in_array($data->rid, array_keys((array) $profile->rids))) && !form_get_errors()) { | |
| 197 | unset($roles[$data->rid]); | |
| 198 | } | |
| 199 | } | |
| 200 | if (count($orig_roles) != count($roles)) { | |
| 201 | drupal_set_message(t('Not all user roles are shown since they already have fckeditor profiles. You must first unassign profiles in order to add them to a new one.')); | |
| 202 | } | |
| 1b120ffb JS |
203 | } |
| 204 | ||
| 205 | $form['basic'] = array( | |
| 201b993d | 206 | '#type' => 'fieldset', |
| 207 | '#title' => t('Basic setup'), | |
| 208 | '#collapsible' => TRUE, | |
| 209 | '#collapsed' => TRUE | |
| 1b120ffb JS |
210 | ); |
| 211 | ||
| 4255581d WW |
212 | if (arg(3) == 'clone') { |
| 213 | //load all profiles to check their names | |
| 214 | $profiles = fckeditor_profile_load(); | |
| 215 | $oldname = $profile->name; | |
| 216 | $maxsize=128; //default max name length | |
| a2c15b72 | 217 | |
| 4255581d WW |
218 | $res=array(); |
| 219 | $pat = "/^(?<name>.*?)_(?<n>[0-9]*)$/"; | |
| 220 | if (preg_match_all($pat, $oldname, $res)) { // oldname like 'name_nr' | |
| 221 | $name=$res['name'][0]; | |
| 222 | $num=$res['n'][0]+1; | |
| 223 | } | |
| 224 | else{ | |
| 225 | $name=$oldname; | |
| 226 | $num=2; | |
| 227 | } | |
| a2c15b72 | 228 | |
| 4255581d WW |
229 | $newname=substr($name, 0, $maxsize-3) .'_'. $num; // +limit |
| 230 | while (isset($profiles[$newname])) { //find next free number | |
| 231 | $num++; | |
| 232 | $newname=substr($name, 0, $maxsize-3) .'_'. $num; | |
| 233 | ||
| a2c15b72 | 234 | } |
| 4255581d WW |
235 | //dont clone rids |
| 236 | $profile->settings['rids']=array(); | |
| 237 | $profile->rids=array(); | |
| 238 | } | |
| f60bb09c JS |
239 | else { |
| 240 | $newname = $profile->name; | |
| 4255581d | 241 | } |
| a2c15b72 | 242 | |
| 1b120ffb | 243 | $form['basic']['name'] = array( |
| 201b993d | 244 | '#type' => 'textfield', |
| 245 | '#title' => t('Profile name'), | |
| 246 | '#default_value' => !empty($profile->name) ? $newname : '', | |
| 247 | '#size' => 40, | |
| 248 | '#maxlength' => 128, | |
| 249 | '#description' => t('Enter a name for this profile. This name is only visible within the fckeditor administration page.'), | |
| 250 | '#required' => TRUE | |
| 1b120ffb JS |
251 | ); |
| 252 | ||
| 253 | $form['basic']['rids'] = array( | |
| 201b993d | 254 | '#type' => 'checkboxes', |
| 255 | '#title' => t('Roles allowed to use this profile'), | |
| 256 | '#default_value' => !empty($profile->rids) ? array_keys((array) $profile->rids) : array(), | |
| 257 | '#options' => $roles, | |
| 258 | '#description' => t('Only roles with "access fckeditor" permission will be shown here. If no role is available, make sure that you have assigned the "access fckeditor" <a href="!permission">permission</a>.', array('!permission' => url('admin/user/permissions'))), | |
| 259 | '#required' => TRUE | |
| 1b120ffb | 260 | ); |
| 43e129e1 | 261 | |
| 1b120ffb | 262 | $form['basic']['allow_user_conf'] = array( |
| 7730222a | 263 | '#type' => 'radios', |
| 201b993d | 264 | '#title' => t('Allow users to customize FCKeditor appearance'), |
| 265 | '#default_value' => !empty($profile->settings['allow_user_conf']) ? $profile->settings['allow_user_conf'] : 'f', | |
| 266 | '#options' => array( | |
| 7730222a WW |
267 | 'f' => t('No'), |
| 268 | 't' => t('Yes') | |
| 201b993d | 269 | ), |
| 270 | '#description' => t('If allowed, users will be able to override the "Editor appearance" by visiting their profile page.'), | |
| 1b120ffb JS |
271 | ); |
| 272 | ||
| c46c807b WW |
273 | $form['security'] = array( |
| 274 | '#type' => 'fieldset', | |
| 275 | '#title' => t('Security'), | |
| af43ec91 | 276 | '#description' => '<p>'. t("When Drupal saves user data input through a textarea, it's saved in the database in unmodified form. That's why all untrusted textarea input should be run through an input format filter before outputting it to the screen.") .'</p>'.'<p>'. t("Drupal will not, however, filter data for content editors editing a textarea. Normally, there is no security risk because the unmodified code is displayed as text and will not be rendered as HTML. But with FCKeditor installed, this is not the case, and content editors are subject to having raw, untrusted code running inside their browsers.") .'</p>'.'<p>'. t("To address this issue, you should select a security filters below to prevent FCKeditor from rendering malicious code. Note that if a textarea's input format is set to \"Full HTML\" (or if the input format of the node doesn't include the filter), FCKeditor will properly ignore the setting below and will not run the code through the security filter.") .'</p>'.'<p>'. t("If any textareas on your site are accessible to unwanted users, we recommend checking the \"HTML Filter\". You may have other modules installed that provide other kinds of security filters and you may use those as long as you trust them to properly filter out malicious code. Note that not all the filters below are security filters and will provide no protection.") .'</p>', |
| c46c807b WW |
277 | '#collapsible' => TRUE, |
| 278 | '#collapsed' => TRUE | |
| 279 | ); | |
| 43e129e1 | 280 | |
| c46c807b WW |
281 | $all = filter_list_all(); |
| 282 | ||
| 283 | $form['security']['filters'] = array( | |
| 284 | '#type' => 'fieldset', | |
| 285 | '#title' => t('Security filters'), | |
| 286 | '#description' => t('Please choose carefully all filters that protect your content (probably not all filters listed below are security filters).'), | |
| 287 | '#tree' => TRUE, | |
| 288 | ); | |
| 43e129e1 | 289 | |
| c46c807b | 290 | //don't bother administrator with filters that definitely are not security filters |
| 88275757 | 291 | $modules_with_filters_to_skip = array('amazon_filter', 'asy', 'bbcode', 'biblio', 'blockquote', 'bookpost', 'chessboard', 'citation_filter', 'codefilter', 'collapse_text', 'contextlinks', 'coolfilter', 'dialectic', 'dript', 'dme', 'drutex', 'embedfilter', 'ext_link_page', 'extlink', 'elf', 'flickr', 'flickrstickr', 'footnotes', 'formdefaults', 'freelinking', 'gallery', 'geogebra', 'geshifilter', 'gotwo', 'googtube', 'gotcha', 'gtspam', 'hidden_content', 'img_assist', 'image_filter', 'inlinetags', 'insert_view', 'insertframe', 'insertnode', 'interwiki', 'jlightbox', 'jsmath', 'language_sections', 'link_node', 'lootz', 'markdown', 'marksmarty', 'mobile_codes', 'mykml', 'nofollowlist', 'oagwt', 'paging', 'pathfilter', 'pearwiki_filter', 'php', 'pirate', 'reptag', 'scrippet', 'scripturefilter', 'signwriter', 'slideshowpro', 'smartlinebreakconverter', 'smartypants', 'smileys', 'spamspan', 'spam_tokens', 'spoiler', 'table_altrow', 'tablemanager', 'tableofcontents', 'textile', 'tooltips', 'twikifilter', 'typogrify', 'unwrap', 'urlclass', 'urlicon', 'url_replace_filter', 'username_highlighter', 'video_filter', 'quote'); |
| c46c807b WW |
292 | |
| 293 | if (!isset($profile->settings['ss'])) { | |
| 294 | $profile->settings['filters']['filter/0'] = 1; | |
| 295 | } | |
| 296 | ||
| 297 | foreach ($all as $id => $filter) { | |
| 298 | if (in_array(strtolower($filter->module), $modules_with_filters_to_skip)) { | |
| 299 | continue; | |
| 300 | } | |
| 301 | //skip line break converter and email -> link | |
| 302 | if ($filter->module == 'filter' && in_array($filter->delta, array(1, 2))) { | |
| 303 | continue; | |
| 304 | } | |
| 305 | $form['security']['filters'][$id] = array( | |
| 306 | '#type' => 'checkbox', | |
| 307 | '#title' => $filter->name, | |
| 308 | '#default_value' => !empty($profile->settings['filters'][$id]), | |
| 309 | '#description' => module_invoke($filter->module, 'filter', 'description', $filter->delta), | |
| 310 | ); | |
| 311 | } | |
| 312 | ||
| 313 | $form['security']['ss'] = array( | |
| 314 | '#type' => 'radios', | |
| 315 | '#title' => t('Security settings'), | |
| 316 | '#default_value' => isset($profile->settings['ss']) ? $profile->settings['ss'] : '2', | |
| 317 | '#options' => array( | |
| 318 | '2' => t('Always run security filters for FCKeditor.'), | |
| 319 | '1' => t('Run security filters only when FCKeditor is set to start automatically.'), | |
| 320 | ), | |
| 321 | '#description' => t('There are two ways of starting FCKeditor: automatically and manually (via toggle or in a popup). If you decide to apply security filters only when FCKeditor starts automatically, you\'ll not be protected when toggling manually from plain textarea to FCKeditor or when using FCKeditor in a popup mode. So choose this option only, if you can detect various attacks (mainly XSS) by yourself just by looking at the HTML code.'), | |
| 322 | ); | |
| 43e129e1 | 323 | |
| 1b120ffb | 324 | $form['fckeditor_exclude_settings'] = array( |
| 201b993d | 325 | '#type' => 'fieldset', |
| 326 | '#title' => t('Visibility settings'), | |
| 327 | '#collapsible' => TRUE, | |
| 328 | '#collapsed' => TRUE, | |
| 5b402531 | 329 | '#description' => t('The following settings are combined with the visibility settings of the global profile.'), |
| 1b120ffb JS |
330 | ); |
| 331 | ||
| 332 | $form['fckeditor_exclude_settings']['min_rows'] = array( | |
| 201b993d | 333 | '#type' => 'textfield', |
| 334 | '#title' => t('Minimum rows'), | |
| 335 | '#default_value' => !empty($profile->settings['min_rows']) ? $profile->settings['min_rows'] : '5', | |
| 336 | '#description' => t("FCKeditor will be triggered if the textarea has more rows than entered here. Enter '1' if you do not want to use this feature."), | |
| 1b120ffb JS |
337 | ); |
| 338 | ||
| 339 | $form['fckeditor_exclude_settings']['excl_mode'] = array( | |
| 7730222a | 340 | '#type' => 'radios', |
| 201b993d | 341 | '#title' => t('Use inclusion or exclusion mode'), |
| 342 | '#default_value' => (empty($profile->settings['excl_mode']) || in_array($profile->settings['excl_mode'], array(0, 2))) ? 0 : 1, | |
| 343 | '#options' => array( | |
| 344 | '0' => t('Exclude'), | |
| 345 | '1' => t('Include') | |
| 346 | ), | |
| 347 | '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), | |
| 1b120ffb JS |
348 | ); |
| 349 | ||
| 350 | /** | |
| 351 | * get excluded fields - so we can have normal textareas too | |
| 352 | * split the phrase by any number of commas or space characters, | |
| 353 | * which include " ", \r, \t, \n and \f | |
| 354 | */ | |
| 355 | $form['fckeditor_exclude_settings']['excl'] = array( | |
| 201b993d | 356 | '#type' => 'textarea', |
| 357 | '#title' => t('Fields to exclude/include'), | |
| 358 | '#cols' => 60, | |
| 359 | '#rows' => 5, | |
| 360 | '#prefix' => '<div style="margin-left:20px">', | |
| 361 | '#suffix' => '</div>', | |
| 362 | '#default_value' => !empty($profile->settings['excl']) ? $profile->settings['excl'] : '', | |
| 95e32685 | 363 | '#description' => t('Enter the paths to the textarea fields on which you want to enable or disable FCKeditor.') .' '. t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Short instruction is available below.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))) .' <ul><li>'. t('Path structure: <strong>content_type@path.element_id</strong>') .'</li><li>'. t('The following wildcards are available: "*", "?".') .'</li><li>'. t('Content type is optional. You may even specify only path or field id.') .'</li><li>'. t('Examples:') .'<ul><li><em>blog@*.edit-body</em> - '. t('matches all fields of type "blog" called edit-body, on any page.') .'<li><em>node/add/*.edit-user-*</em> - '. t('matches fields starting with "edit-user-" on pages starting with "node/add/') .'</li></ul></li></ul>', |
| 5c21faac | 364 | '#wysiwyg' => FALSE, |
| 1b120ffb | 365 | ); |
| a2c15b72 | 366 | |
| 1b120ffb | 367 | $form['fckeditor_exclude_settings']['simple_incl'] = array( |
| 201b993d | 368 | '#type' => 'textarea', |
| 369 | '#title' => t('Force simplified toolbar on the following fields'), | |
| 370 | '#cols' => 60, | |
| 371 | '#rows' => 5, | |
| 372 | '#default_value' => !empty($profile->settings['simple_incl']) ? $profile->settings['simple_incl'] : '', | |
| 582314ab | 373 | '#description' => t('Enter the paths to the textarea fields on which you want to force the simplified toolbar (!name).', array('!name' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)) .' '. t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Take a look at the exclusion settings (above) for short instruction.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))), |
| 5c21faac | 374 | '#wysiwyg' => FALSE, |
| 1b120ffb JS |
375 | ); |
| 376 | ||
| 377 | $form['appearance'] = array( | |
| 201b993d | 378 | '#type' => 'fieldset', |
| 379 | '#title' => t('Editor appearance'), | |
| 380 | '#collapsible' => TRUE, | |
| 381 | '#collapsed' => TRUE, | |
| 1b120ffb JS |
382 | ); |
| 383 | ||
| 384 | $form['appearance']['default'] = array( | |
| 7730222a | 385 | '#type' => 'radios', |
| 201b993d | 386 | '#title' => t('Default state'), |
| 387 | '#default_value' => !empty($profile->settings['default']) ? $profile->settings['default'] : 't', | |
| 388 | '#options' => array( | |
| 389 | 't' => t('Enabled'), | |
| 390 | 'f' => t('Disabled') | |
| 391 | ), | |
| 392 | '#description' => t('Default editor state. If disabled, rich text editor may still be enabled using toggle or popup window.'), | |
| 1b120ffb JS |
393 | ); |
| 394 | ||
| 395 | $form['appearance']['show_toggle'] = array( | |
| 7730222a | 396 | '#type' => 'radios', |
| 201b993d | 397 | '#title' => t('Show disable/enable rich text editor toggle'), |
| 398 | '#default_value' => !empty($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : 't', | |
| 399 | '#options' => array( | |
| 7730222a WW |
400 | 't' => t('Show'), |
| 401 | 'f' => t('Hide') | |
| 201b993d | 402 | ), |
| 403 | '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea. Works only if FCKeditor is not running in a popup window (see below).'), | |
| 1b120ffb | 404 | ); |
| a2c15b72 | 405 | |
| 1b120ffb | 406 | $form['appearance']['popup'] = array( |
| 7730222a | 407 | '#type' => 'radios', |
| 201b993d | 408 | '#title' => t('Use FCKeditor in a popup window'), |
| 409 | '#default_value' => !empty($profile->settings['popup']) ? $profile->settings['popup'] : 'f', | |
| 410 | '#options' => array( | |
| 7730222a WW |
411 | 'f' => t('No'), |
| 412 | 't' => t('Yes') | |
| 201b993d | 413 | ), |
| 414 | '#description' => t('If this option is enabled a link to a popup window will be used instead of a textarea replace.'), | |
| 1b120ffb JS |
415 | ); |
| 416 | ||
| 417 | $form['appearance']['skin'] = array( | |
| 201b993d | 418 | '#type' => 'select', |
| 419 | '#title' => t('Skin'), | |
| 420 | '#default_value' => !empty($profile->settings['skin']) ? $profile->settings['skin'] : 'default', | |
| 421 | '#options' => $skin_options, | |
| 422 | '#description' => t('Choose a default skin.'), | |
| 1b120ffb JS |
423 | ); |
| 424 | ||
| 425 | $form['appearance']['toolbar'] = array( | |
| 201b993d | 426 | '#type' => 'select', |
| 427 | '#title' => t('Toolbar'), | |
| 428 | '#default_value' => !empty($profile->settings['toolbar']) ? $profile->settings['toolbar'] : 'default', | |
| 429 | '#options' => $toolbar_options, | |
| 430 | '#description' => t('Choose a default toolbar set. To define new toolbar, edit "fckeditor.config.js" located in "!module_path".', array('!module_path' => drupal_get_path('module', 'fckeditor'))), | |
| 1b120ffb JS |
431 | ); |
| 432 | ||
| 433 | $form['appearance']['expand'] = array( | |
| 7730222a | 434 | '#type' => 'radios', |
| 201b993d | 435 | '#title' => t('Start the toolbar expanded'), |
| 436 | '#default_value' => !empty($profile->settings['expand']) ? $profile->settings['expand'] : 't', | |
| 437 | '#options' => array( | |
| 7730222a WW |
438 | 't' => t('Expanded'), |
| 439 | 'f' => t('Collapsed') | |
| 201b993d | 440 | ), |
| 441 | '#description' => t('The toolbar start expanded or collapsed.'), | |
| 1b120ffb JS |
442 | ); |
| 443 | ||
| 444 | $form['appearance']['width'] = array( | |
| 201b993d | 445 | '#type' => 'textfield', |
| 446 | '#title' => t('Width'), | |
| 447 | '#default_value' => !empty($profile->settings['width']) ? $profile->settings['width'] : '100%', | |
| 448 | '#description' => t("Width in pixels or percent. Example: 400 or 100%."), | |
| 449 | '#size' => 40, | |
| 450 | '#maxlength' => 128, | |
| 1b120ffb JS |
451 | ); |
| 452 | ||
| 453 | $form['appearance']['lang'] = array( | |
| 201b993d | 454 | '#type' => 'select', |
| 455 | '#title' => t('Language'), | |
| 456 | '#default_value' => !empty($profile->settings['lang']) ? $profile->settings['lang'] : 'en', | |
| 457 | '#options' => $lang_options, | |
| 458 | '#description' => t('The language for the FCKeditor interface.') | |
| 1b120ffb JS |
459 | ); |
| 460 | ||
| 461 | $form['appearance']['auto_lang'] = array( | |
| 7730222a | 462 | '#type' => 'radios', |
| 201b993d | 463 | '#title' => t('Auto-detect language'), |
| 464 | '#default_value' => !empty($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't', | |
| 465 | '#options' => array( | |
| 7730222a WW |
466 | 't' => t('Enabled'), |
| 467 | 'f' => t('Disabled') | |
| 201b993d | 468 | ), |
| 469 | '#description' => t('Use auto detect user language feature.') | |
| 1b120ffb | 470 | ); |
| a2c15b72 | 471 | |
| 1b120ffb JS |
472 | /* |
| 473 | $form['appearance']['appearance_conf'] = array( | |
| 201b993d | 474 | '#type' => 'select', |
| 475 | '#title' => t('Ignore this section, use default settings defined in config files'), | |
| 476 | '#default_value' => $profile->settings['appearance_conf'] ? $profile->settings['appearance_conf'] : 'f', | |
| 477 | '#options' => array( | |
| 478 | 'f' => t('false'), | |
| 479 | 't' => t('true') | |
| 480 | ), | |
| 481 | '#description' => t('Although it is less handy, defining settings only in config files (<code>fckconfig.js</code> and <code>fckeditor.config.js</code>) will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in <code>Editor appearance</code> will have no affect on FCKeditor\'s behaviour.'), | |
| 1b120ffb JS |
482 | ); |
| 483 | */ | |
| 484 | ||
| 485 | $form['output'] = array( | |
| 201b993d | 486 | '#type' => 'fieldset', |
| 487 | '#title' => t('Cleanup and output'), | |
| 488 | '#collapsible' => TRUE, | |
| 489 | '#collapsed' => TRUE, | |
| 1b120ffb JS |
490 | ); |
| 491 | ||
| 492 | $form['output']['enter_mode'] = array( | |
| 201b993d | 493 | '#type' => 'select', |
| 494 | '#title' => t('Enter mode'), | |
| 495 | '#default_value' => !empty($profile->settings['enter_mode']) ? $profile->settings['enter_mode'] : 'p', | |
| 496 | '#options' => array( | |
| 497 | 'p' => '<p>', | |
| 498 | 'br' => '<br>', | |
| 499 | 'div' => '<div>' | |
| 500 | ), | |
| 501 | '#description' => t('Set which tag FCKeditor should use when [Enter] key is pressed.') | |
| 1b120ffb JS |
502 | ); |
| 503 | ||
| 504 | $form['output']['shift_enter_mode'] = array( | |
| 201b993d | 505 | '#type' => 'select', |
| 506 | '#title' => t('Shift + Enter mode'), | |
| 507 | '#default_value' => !empty($profile->settings['shift_enter_mode']) ? $profile->settings['shift_enter_mode'] : 'br', | |
| 508 | '#options' => array( | |
| 509 | 'p' => '<p>', | |
| 510 | 'br' => '<br>', | |
| 511 | 'div' => '<div>' | |
| 512 | ), | |
| 513 | '#description' => t('Set which tag FCKeditor should use when [Shift] + [Enter] is pressed.') | |
| 1b120ffb JS |
514 | ); |
| 515 | ||
| 516 | $form['output']['font_format'] = array( | |
| 201b993d | 517 | '#type' => 'textfield', |
| 518 | '#title' => t('Font formats'), | |
| 519 | '#default_value' => !empty($profile->settings['font_format']) ? $profile->settings['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6', | |
| 520 | '#size' => 40, | |
| 521 | '#maxlength' => 250, | |
| 522 | '#description' => t('Semicolon separated list of HTML font formats. Allowed values are: p;div;pre;address;h1;h2;h3;h4;h5;h6'), | |
| 1b120ffb JS |
523 | ); |
| 524 | ||
| 525 | $form['output']['format_source'] = array( | |
| 7730222a | 526 | '#type' => 'radios', |
| 201b993d | 527 | '#title' => t('Apply source formatting'), |
| 528 | '#default_value' => !empty($profile->settings['format_source']) ? $profile->settings['format_source'] : 't', | |
| 529 | '#options' => array( | |
| 7730222a WW |
530 | 't' => t('Yes'), |
| 531 | 'f' => t('No') | |
| 201b993d | 532 | ), |
| 533 | '#description' => t('When set to "true" the editor will format the XHTML when switching from WYSIWYG view to Source view, by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), | |
| 1b120ffb JS |
534 | ); |
| 535 | ||
| 536 | $form['output']['format_output'] = array( | |
| 7730222a | 537 | '#type' => 'radios', |
| 201b993d | 538 | '#title' => t('Format output'), |
| 539 | '#default_value' => !empty($profile->settings['format_output']) ? $profile->settings['format_output'] : 't', | |
| 540 | '#options' => array( | |
| 7730222a WW |
541 | 't' => t('Yes'), |
| 542 | 'f' => t('No') | |
| 201b993d | 543 | ), |
| 544 | '#description' => t('When set to "true" the editor will format the XHTML output by inserting line breaks on some tags endings and indenting paragraphs, tables and lists.'), | |
| 1b120ffb JS |
545 | ); |
| 546 | ||
| 547 | /* | |
| 548 | $form['output']['output_conf'] = array( | |
| 201b993d | 549 | '#type' => 'select', |
| 550 | '#title' => t('Ignore this section, use default settings defined in config files'), | |
| 551 | '#default_value' => $profile->settings['output_conf'] ? $profile->settings['output_conf'] : 'f', | |
| 552 | '#options' => array( | |
| 553 | 'f' => t('False'), | |
| 554 | 't' => t('True') | |
| 555 | ), | |
| 556 | '#description' => t('Although it is less handy, defining settings only in config files ("fckconfig.js" and "fckeditor.config.js") will slightly leverage your traffic and improve load time of your site. <br/>Warning: if set to true, all changes made in "Cleanup and output" will have no affect on FCKeditor\'s behaviour.'), | |
| 1b120ffb JS |
557 | ); |
| 558 | */ | |
| 559 | ||
| 560 | $form['css'] = array( | |
| 201b993d | 561 | '#type' => 'fieldset', |
| 562 | '#title' => t('CSS'), | |
| 563 | '#collapsible' => TRUE, | |
| 564 | '#collapsed' => TRUE | |
| 1b120ffb JS |
565 | ); |
| 566 | ||
| 567 | $form['css']['css_mode'] = array( | |
| 201b993d | 568 | '#type' => 'select', |
| 569 | '#title' => t('Editor CSS'), | |
| 570 | '#default_value' => !empty($profile->settings['css_mode']) ? $profile->settings['css_mode'] : 'theme', | |
| 571 | '#options' => array( | |
| 572 | 'theme' => t('Use theme css'), | |
| 573 | 'self' => t('Define css'), | |
| 574 | 'none' => t('FCKeditor default') | |
| 575 | ), | |
| 576 | '#description' => t('Defines the CSS to be used in the editor area.<br />Use theme css - load style.css from current site theme.<br/>Define css - enter path for css file below.<br />FCKeditor default - uses default CSS from editor.') | |
| 1b120ffb JS |
577 | ); |
| 578 | ||
| 579 | $form['css']['css_path'] = array( | |
| 201b993d | 580 | '#type' => 'textfield', |
| 581 | '#title' => t('CSS path'), | |
| 582 | '#default_value' => !empty($profile->settings['css_path']) ? $profile->settings['css_path'] : "", | |
| 583 | '#size' => 40, | |
| 584 | '#maxlength' => 255, | |
| 585 | '#description' => t('Enter path to CSS file (Example: "css/editor.css") or a list of css files seperated by a comma (Example: "/themes/garland/style.css,http://example.com/style.css"). Make sure to select "Define css" above.<br />Available placeholders:<br /><strong>%h</strong> - host name (!host).<br /><strong>%t</strong> - path to theme (!theme).', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/')) | |
| 1b120ffb JS |
586 | ); |
| 587 | ||
| 588 | $form['css']['css_style'] = array( | |
| 201b993d | 589 | '#type' => 'select', |
| 590 | '#title' => t('Predefined styles'), | |
| 591 | '#default_value' => !empty($profile->settings['css_style']) ? $profile->settings['css_style'] : 'theme', | |
| 592 | '#options' => array( | |
| 593 | 'theme' => t('Use theme fckstyles.xml'), | |
| 594 | 'self' => t('Define path to fckstyles.xml'), | |
| 595 | 'default' => t('FCKeditor default') | |
| 596 | ), | |
| 597 | '#description' => t('Define the location of "fckstyles.xml" file. It is used by the "Style" dropdown list available in the default toolbar. Copy "!fckstyles.xml" inside your theme directory ("!theme") and adjust it to your needs.', array('!fckstyles.xml' => fckeditor_path(TRUE) .'/fckstyles.xml', '!theme' => path_to_theme() .'/fckstyles.xml')) | |
| 1b120ffb JS |
598 | ); |
| 599 | ||
| 600 | $form['css']['styles_path'] = array( | |
| 201b993d | 601 | '#type' => 'textfield', |
| 602 | '#title' => t('Predefined styles path'), | |
| 603 | '#default_value' => !empty($profile->settings['styles_path']) ? $profile->settings['styles_path'] : "", | |
| 604 | '#size' => 40, | |
| 605 | '#maxlength' => 255, | |
| 606 | '#description' => t('Enter path to XML file with predefined styles (Example: "/fckstyles.xml"). Be sure to select "define path to fckstyles.xml" above.<br />Available placeholders:<br /><strong>%h</strong> - host name (!host).<br /><strong>%t</strong> - path to theme (!theme).<br /><strong>%m</strong> - path to FCKeditor module (!module).', array('!host' => base_path(), '!theme' => base_path() . path_to_theme() .'/', '!module' => drupal_get_path('module', 'fckeditor'))) | |
| 1b120ffb JS |
607 | ); |
| 608 | ||
| 609 | $form['fckeditor_upload_settings'] = array( | |
| 201b993d | 610 | '#type' => 'fieldset', |
| 611 | '#title' => t('File browser settings'), | |
| 612 | '#collapsible' => TRUE, | |
| 613 | '#collapsed' => TRUE, | |
| 43e129e1 | 614 | '#description' => t('Set file browser settings. A file browser will allow you to explore the files contained on the server and embed them as links, images or flash movies. Besides the built-in FCKeditor file browser, you can also use a contributed module like <a href="!imce">IMCE</a>, <a href="!ib">Image Browser</a> or <a href="!webfm">Web File Manager</a>. The quick upload setting controls whether images, flash movies and files can be uploaded using the upload tab of the respective dialogs. Please note that these options require manual configuration, check <a href="!readme">readme.txt</a> for more information.', array('!imce' => url('http://drupal.org/project/imce'), '!ib' => url('http://drupal.org/project/imagebrowser'), '!webfm' => url('http://drupal.org/project/webfm'), '!readme' => url('admin/help/fckeditor'))) |
| a2c15b72 | 615 | ); |
| 616 | ||
| 1b120ffb JS |
617 | $filebrowsers = array( |
| 618 | 'none' => t('None'), | |
| 619 | 'builtin' => t('Built-in filebrowser'), | |
| 620 | ); | |
| a2c15b72 | 621 | |
| 1b120ffb JS |
622 | if (module_exists('imce')) { |
| 623 | $filebrowsers['imce'] = t('IMCE'); | |
| 624 | } | |
| a2c15b72 | 625 | |
| 12ac377f WW |
626 | if (module_exists('imagebrowser')) { |
| 627 | $filebrowsers['ib'] = t('Image Browser'); | |
| 628 | } | |
| 629 | ||
| 43e129e1 WW |
630 | if (module_exists('webfm_popup')) { |
| 631 | $filebrowsers['webfm'] = t('Web File Manager'); | |
| 632 | } | |
| 633 | ||
| 1b120ffb JS |
634 | $form['fckeditor_upload_settings']['filebrowser'] = array( |
| 635 | '#type' => 'select', | |
| 1b120ffb JS |
636 | '#title' => t('File browser type'), |
| 637 | '#default_value' => !empty($profile->settings['filebrowser']) ? $profile->settings['filebrowser'] : 'none', | |
| 201b993d | 638 | '#options' => $filebrowsers, |
| 1b120ffb JS |
639 | '#description' => t('Select the file browser that you would like to use to upload files, images and flash movies.'), |
| 640 | ); | |
| a2c15b72 | 641 | |
| 1b120ffb | 642 | $form['fckeditor_upload_settings']['quickupload'] = array( |
| 7730222a | 643 | '#type' => 'radios', |
| 1b120ffb JS |
644 | '#title' => t('Allow quick uploads'), |
| 645 | '#default_value' => !empty($profile->settings['quickupload']) ? $profile->settings['quickupload'] : 'f', | |
| 201b993d | 646 | '#options' => array( |
| 7730222a WW |
647 | 'f' => t('No'), |
| 648 | 't' => t('Yes') | |
| 201b993d | 649 | ), |
| 12ac377f | 650 | '#description' => t('The quick upload functionality can be disabled and enabled independently of the file browser. It will always use the settings below. To enable quick uploads you must follow the same configuration procedure as when enabling the built-in file browser.'), |
| 1b120ffb | 651 | ); |
| a2c15b72 | 652 | |
| 64e4e195 WW |
653 | $current_user_files_path = empty($profile->settings['UserFilesPath']) ? "" : strtr($profile->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%n" => "UNAME")); |
| 654 | $current_user_files_absolute_path = empty($profile->settings['UserFilesAbsolutePath']) ? "" : strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => "UID", "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'], "%n" => "UNAME")); | |
| 1b120ffb JS |
655 | |
| 656 | $form['fckeditor_upload_settings']['UserFilesPath'] = array( | |
| 657 | '#type' => 'textfield', | |
| 658 | '#title' => t('Path to uploaded files'), | |
| 659 | '#default_value' => !empty($profile->settings['UserFilesPath']) ? $profile->settings['UserFilesPath'] : "%b%f/", | |
| 660 | '#size' => 40, | |
| 661 | '#maxlength' => 255, | |
| 42225b39 | 662 | '#description' => t('Path to uploaded files relative to the document root.<br />Available placeholders:<br/><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br /><strong>%n</strong> - Username.<br />Current path: !path', array('!path' => $current_user_files_path, '!files' => file_directory_path(), '!base' => base_path())), |
| 1b120ffb | 663 | ); |
| a2c15b72 | 664 | |
| 1b120ffb JS |
665 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath'] = array( |
| 666 | '#type' => 'textfield', | |
| 667 | '#title' => t('Absolute path to uploaded files'), | |
| 668 | '#default_value' => !empty($profile->settings['UserFilesAbsolutePath']) ? $profile->settings['UserFilesAbsolutePath'] : "%d%b%f/", | |
| 669 | '#size' => 40, | |
| 670 | '#maxlength' => 255, | |
| 42225b39 | 671 | '#description' => t('The path to the local directory (in the server) which points to the path defined above. If empty, FCKeditor will try to discover the right path.<br />Available placeholders:<br/><strong>%d</strong> - server path to document root (!root).<br /><strong>%b</strong> - base URL path of the Drupal installation (!base).<br/><strong>%f</strong> - Drupal file system path where the files are stored (!files).<br /><strong>%u</strong> - User ID.<br /><strong>%n</strong> - Username.<br />Current path: !path', array('!path' => $current_user_files_absolute_path, '!files' => file_directory_path(), '!base' => base_path(), '!root' => $_SERVER['DOCUMENT_ROOT'])), |
| 1b120ffb JS |
672 | ); |
| 673 | ||
| 674 | if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { | |
| b94b689f | 675 | $form['fckeditor_upload_settings']['UserFilesPath']['#description'] = t('Setting relative path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically. To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!url' => url('admin/settings/fckeditor/editg'))); |
| 1b120ffb | 676 | $form['fckeditor_upload_settings']['UserFilesPath']['#disabled'] = TRUE; |
| b94b689f | 677 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#description'] = t('Setting path to uploaded files has been disabled because private downloads are enabled and this path is calculated automatically.To change the location of uploaded files in the private file system, edit the <a href="!url">FCKeditor Global Profile</a>.', array('!global' => url('admin/settings/fckeditor/editg'))); |
| 1b120ffb JS |
678 | $form['fckeditor_upload_settings']['UserFilesAbsolutePath']['#disabled'] = TRUE; |
| 679 | } | |
| a2c15b72 | 680 | |
| 1b120ffb | 681 | $form['advanced'] = array( |
| 201b993d | 682 | '#type' => 'fieldset', |
| 683 | '#title' => t('Advanced options'), | |
| 684 | '#collapsible' => TRUE, | |
| 685 | '#collapsed' => TRUE, | |
| 1b120ffb | 686 | ); |
| ac9e6b9f WW |
687 | $form['advanced']['theme_config_js'] = array( |
| 688 | '#type' => 'radios', | |
| 689 | '#title' => t('Load fckeditor.config.js from theme path'), | |
| 690 | '#default_value' => !empty($profile->settings['theme_config_js']) ? $profile->settings['theme_config_js'] : 'f', | |
| 691 | '#options' => array( | |
| 692 | 't' => t('Yes'), | |
| 693 | 'f' => t('No') | |
| 694 | ), | |
| 695 | '#description' => t('When set to "true" the editor will try to load the fckeditor.config.js file from theme directory.'), | |
| 696 | ); | |
| 1b120ffb | 697 | $form['advanced']['js_conf'] = array( |
| 201b993d | 698 | '#type' => 'textarea', |
| 699 | '#title' => t('Custom javascript configuration'), | |
| 700 | '#default_value' => !empty($profile->settings['js_conf']) ? $profile->settings['js_conf'] : "", | |
| 701 | '#cols' => 60, | |
| 702 | '#rows' => 5, | |
| dec7b1d3 | 703 | '#description' => t('To change FCKeditor configuration globally, you should modify the config file: "!fckeditor_config". Sometimes it is required to change the FCKeditor configuration for a single profile only. Use this box to define settings that are unique for this profile. Available options are listed in the <a href="!docs">FCKeditor documentation</a>. Add the following code snippet to disable some advanced tabs in dialog windows of FCKeditor: <pre>@code</pre><strong>Warning</strong>: If you make something wrong here, FCKeditor may fail to load.', array('!fckeditor_config' => drupal_get_path('module', 'fckeditor') ."/fckeditor.config.js", '!docs' => 'http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options', '@code' => "LinkDlgHideTarget = true;\nLinkDlgHideAdvanced = true;\nImageDlgHideLink = true;\nImageDlgHideAdvanced = true;\nFlashDlgHideAdvanced = true;")), |
| 5c21faac | 704 | '#wysiwyg' => FALSE, |
| 42225b39 | 705 | ); |
| 1b120ffb JS |
706 | |
| 707 | $form['submit'] = array( | |
| 708 | '#type' => 'submit', | |
| 42225b39 | 709 | '#value' => t('Save') |
| 1b120ffb JS |
710 | ); |
| 711 | ||
| 712 | return $form; | |
| 713 | } | |
| 714 | ||
| 715 | /** | |
| 716 | * Profile validation. | |
| 717 | */ | |
| e5c55219 | 718 | function fckeditor_admin_profile_form_validate($form, &$form_state) { |
| 1b120ffb JS |
719 | $edit =& $form_state['values']; |
| 720 | ||
| 721 | //include mode and all other fields are empty, invalid | |
| 722 | if ($edit['excl_mode'] == 1 && empty($edit['excl'])) { | |
| 723 | form_set_error('excl_mode', t('Include mode selected, but no paths given. Enter at least one path where FCKeditor should appear.')); | |
| 724 | } | |
| 725 | else { | |
| 726 | fckeditor_admin_profile_validate_fieldpaths('excl', $edit['excl']); | |
| 727 | } | |
| a2c15b72 | 728 | |
| 1b120ffb | 729 | fckeditor_admin_profile_validate_fieldpaths('simple_incl', $edit['simple_incl']); |
| a2c15b72 | 730 | |
| 1b120ffb | 731 | if (!preg_match('/^\d+$/', trim($edit['min_rows']))) { |
| 42225b39 | 732 | form_set_error('min_rows', t('Minimum rows must be a valid number.')); |
| 1b120ffb JS |
733 | } |
| 734 | ||
| 735 | if ($edit['default'] == 't' && $edit['popup'] == 't') { | |
| 736 | form_set_error('popup', t('If FCKeditor is enabled by default, popup window must be disabled.')); | |
| 737 | } | |
| 738 | ||
| 739 | if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') { | |
| 740 | form_set_error('popup', t('If toggle is enabled, popup window must be disabled.')); | |
| 741 | } | |
| 742 | ||
| 743 | if (!$edit['name']) { | |
| 744 | form_set_error('name', t('You must give a profile name.')); | |
| 745 | } | |
| 746 | elseif ($edit['name'] == 'FCKeditor Global Profile') { | |
| 747 | form_set_error('name', t('This profile name is reserved. Please choose a different name.')); | |
| 748 | } | |
| 749 | elseif (!isset($edit['_profile']) || ($edit['_profile']->name != $edit['name'])) { | |
| 750 | $result = fckeditor_profile_load($edit['name']); | |
| 751 | if (!empty($result)) { | |
| 42225b39 | 752 | form_set_error('name', t('The profile name must be unique. A profile with this name already exists.')); |
| 1b120ffb JS |
753 | } |
| 754 | } | |
| 755 | ||
| 756 | if (!preg_match('/^\d+%?$/', $edit['width'])) { | |
| 42225b39 | 757 | form_set_error('width', t('Enter valid width. Example: 400 or 100%.')); |
| 1b120ffb JS |
758 | } |
| 759 | ||
| 760 | if (!empty($edit['css_path'])) { | |
| 761 | if ($edit['css_mode'] != 'self') { | |
| 762 | form_set_error('css_path', t('CSS path is not empty. Please set the "Editor CSS" option to "define css" mode.')); | |
| 763 | } | |
| 764 | else if (FALSE !== strpos($edit['css_path'], '"')) { | |
| 765 | form_set_error('css_path', t('Double quotes are not allowed in CSS path.')); | |
| 766 | } | |
| a2c15b72 | 767 | |
| 1b120ffb JS |
768 | else if (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") { |
| 769 | form_set_error('css_path', t('Enter valid path, do not surround it with quotes.')); | |
| 770 | } | |
| 771 | } | |
| 772 | ||
| 773 | if (!empty($edit['styles_path'])) { | |
| 774 | if ($edit['css_style'] != 'self') { | |
| 775 | form_set_error('styles_path', t('Path to predefined styles is not empty. Please set the "Predefined styles" option to "define path to fckstyles.xml" mode.')); | |
| 776 | } | |
| 777 | else if (FALSE !== strpos($edit['styles_path'], '"')) { | |
| 778 | form_set_error('styles_path', t('Double quotes are not allowed in path.')); | |
| 779 | } | |
| 780 | else if (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") { | |
| 781 | form_set_error('styles_path', t('Enter valid path, do not surround it with quotes.')); | |
| 782 | } | |
| 783 | } | |
| 784 | ||
| 785 | if (!empty($edit['font_format'])) { | |
| 786 | if (!preg_match("/^((p|div|pre|address|h1|h2|h3|h4|h5|h6);)*(p|div|pre|address|h1|h2|h3|h4|h5|h6)$/", $edit['font_format'])) { | |
| 787 | form_set_error('font_format', t('Enter valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).')); | |
| 788 | } | |
| 789 | } | |
| 790 | ||
| 791 | if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE) { | |
| b94b689f | 792 | if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) { |
| 1b120ffb JS |
793 | form_set_error('UserFilesPath', t('Path to uploaded files is required.')); |
| 794 | } | |
| b94b689f | 795 | if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) { |
| 1b120ffb JS |
796 | form_set_error('UserFilesPath', t('Absolute path to uploaded files is required.')); |
| 797 | } | |
| 798 | } | |
| 799 | } | |
| 800 | ||
| 801 | function fckeditor_admin_profile_form_submit($form, &$form_state) { | |
| 802 | $edit =& $form_state['values']; | |
| a2c15b72 | 803 | |
| 1b120ffb | 804 | if (isset($edit['_profile'])) { |
| 4059f348 WW |
805 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $edit['_profile']->name); |
| 806 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $edit['_profile']->name); | |
| 1b120ffb | 807 | drupal_set_message(t('Your FCKeditor profile has been updated.')); |
| f60bb09c JS |
808 | } |
| 809 | else { | |
| 1b120ffb JS |
810 | drupal_set_message(t('Your FCKeditor profile has been created.')); |
| 811 | } | |
| a2c15b72 | 812 | |
| 1b120ffb | 813 | $settings = fckeditor_admin_values_to_settings($edit); |
| 4059f348 | 814 | db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings); |
| 1b120ffb JS |
815 | fckeditor_rebuild_selectors($edit['name']); |
| 816 | if (!empty($edit['rids'])) { | |
| 817 | foreach (array_keys($edit['rids']) as $rid) { | |
| 1357af1b | 818 | if ($edit['rids'][$rid]!=0) { |
| 4059f348 | 819 | db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)", $edit['name'], $rid); |
| 1357af1b | 820 | } |
| 1b120ffb JS |
821 | } |
| 822 | } | |
| a2c15b72 | 823 | |
| 1b120ffb JS |
824 | $form_state['redirect'] = 'admin/settings/fckeditor'; |
| 825 | } | |
| 826 | ||
| 827 | function fckeditor_admin_global_profile_form($form_state, $mode = 'add') { | |
| 29d8625e | 828 | module_load_include('lib.inc', 'fckeditor'); |
| 1b120ffb JS |
829 | if ($mode == 'edit') { |
| 830 | $profile = fckeditor_profile_load('FCKeditor Global Profile'); | |
| a2c15b72 | 831 | |
| 1b120ffb JS |
832 | $form['_profile'] = array( |
| 833 | '#type' => 'value', | |
| 834 | '#value' => $profile, | |
| 835 | ); | |
| 836 | } | |
| 837 | else { | |
| 838 | $profile = new stdClass(); | |
| 839 | } | |
| 840 | ||
| 841 | if ($mode == 'add') { | |
| 842 | $data = fckeditor_profile_load('FCKeditor Global Profile'); | |
| 843 | if (!empty($data)) { | |
| 844 | drupal_set_message(t('Global profile already exist. Only one global profile is allowed.'), 'error'); | |
| 845 | drupal_not_found(); | |
| 846 | } | |
| 847 | ||
| 848 | $btn = t('Create global profile'); | |
| 849 | } | |
| 850 | else { | |
| 851 | $btn = t('Update global profile'); | |
| 852 | } | |
| 853 | ||
| 854 | $form['common'] = array( | |
| 201b993d | 855 | '#type' => 'fieldset', |
| 856 | '#title' => t('Main setup'), | |
| 857 | '#collapsible' => TRUE, | |
| 858 | '#collapsed' => TRUE | |
| 1b120ffb JS |
859 | ); |
| 860 | ||
| 861 | $roles = fckeditor_sorted_roles(); | |
| 862 | $rids = $rtext = array(); | |
| 863 | foreach ($roles as $rid => $name) { | |
| 864 | $rids[] = $rid; | |
| 865 | $rtext[] = '<strong>'. $rid .' - </strong>'. $name; | |
| 866 | } | |
| 201b993d | 867 | $form['common']['rank'] = array( |
| 868 | '#type' => 'textfield', | |
| 869 | '#title' => t('Role precedence'), | |
| 870 | '#default_value' => implode('>', $rids), | |
| 871 | '#description' => t('A user having <strong>multiple roles</strong> gets the permissions of the highest one. Sort role IDs according to their <strong>precedence from higher to lower</strong> by putting > in between.'), | |
| 1b120ffb JS |
872 | ); |
| 873 | if ($rids) { | |
| 42225b39 | 874 | $form['common']['rank']['#description'] .= '<br />'. t('Here is the id-name pairs of roles having access to FCKeditor:') .'<div>'. implode('<br />', $rtext) .'</div>'; |
| 1b120ffb JS |
875 | } |
| 876 | else { | |
| 42225b39 | 877 | $form['common']['rank']['#description'] .= '<br />'. t('You haven\'t assigned the "access fckeditor" <a href="!permissions">permissions</a> yet.', array('!permissions' => url('admin/user/permissions'))); |
| 1b120ffb | 878 | } |
| a2c15b72 | 879 | |
| 1b120ffb | 880 | $form['fckeditor_exclude_settings'] = array( |
| 201b993d | 881 | '#type' => 'fieldset', |
| 882 | '#title' => t('Visibility settings'), | |
| 883 | '#collapsible' => TRUE, | |
| 884 | '#collapsed' => TRUE, | |
| 5b402531 | 885 | '#description' => t('The following settings are combined with the visibility settings of the specific profile.'), |
| 1b120ffb JS |
886 | ); |
| 887 | ||
| 888 | $form['fckeditor_exclude_settings']['excl_mode'] = array( | |
| 7730222a | 889 | '#type' => 'radios', |
| 201b993d | 890 | '#title' => t('Use inclusion or exclusion mode'), |
| 891 | '#default_value' => (empty($profile->settings['excl_mode']) || in_array($profile->settings['excl_mode'], array(0, 2))) ? 0 : 1, | |
| 892 | '#options' => array( | |
| 893 | '0' => t('Exclude'), | |
| 894 | '1' => t('Include') | |
| 895 | ), | |
| 896 | '#description' => t('Choose the way of disabling/enabling FCKeditor on selected fields/paths (see below). Use exclude to disable FCKeditor on selected fields/paths. Use include if you want to load FCKeditor only on selected paths/fields.'), | |
| 1b120ffb JS |
897 | ); |
| 898 | /** | |
| 899 | * get excluded fields - so we can have normal textareas too | |
| 900 | * split the phrase by any number of commas or space characters, | |
| 901 | * which include " ", \r, \t, \n and \f | |
| 902 | */ | |
| 903 | $form['fckeditor_exclude_settings']['excl'] = array( | |
| 201b993d | 904 | '#type' => 'textarea', |
| 905 | '#title' => t('Fields to exclude/include'), | |
| 906 | '#cols' => 60, | |
| 907 | '#rows' => 5, | |
| 908 | '#prefix' => '<div style="margin-left:20px">', | |
| 909 | '#suffix' => '</div>', | |
| 910 | '#default_value' => !empty($profile->settings['excl']) ? $profile->settings['excl'] : '', | |
| 95e32685 | 911 | '#description' => t('Enter the paths to the textarea fields on which you want to enable or disable FCKeditor.') .' '. t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Short instruction is available below.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))) .' <ul><li>'. t('Path structure: <strong>content_type@path.element_id</strong>') .'</li><li>'. t('The following wildcards are available: "*", "?".') .'</li><li>'. t('Content type is optional. You may even specify only path or field id.') .'</li><li>'. t('Examples:') .'<ul><li><em>blog@*.edit-body</em> - '. t('matches all fields of type "blog" called edit-body, on any page.') .'<li><em>node/add/*.edit-user-*</em> - '. t('matches fields starting with "edit-user-" on pages starting with "node/add/') .'</li></ul></li></ul>', |
| 5c21faac | 912 | '#wysiwyg' => FALSE, |
| 1b120ffb | 913 | ); |
| a2c15b72 | 914 | |
| 1b120ffb | 915 | $form['fckeditor_exclude_settings']['simple_incl'] = array( |
| 201b993d | 916 | '#type' => 'textarea', |
| 917 | '#title' => t('Force simplified toolbar on the following fields'), | |
| 918 | '#cols' => 60, | |
| 919 | '#rows' => 5, | |
| 920 | '#default_value' => !empty($profile->settings['simple_incl']) ? $profile->settings['simple_incl'] : '', | |
| 582314ab | 921 | '#description' => t('Enter the paths to the textarea fields on which you want to force the simplified toolbar (!name).', array('!name' => FCKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME)) .' '. t('Please see the <a href="!helppagelink">help page</a> for more information about defining field names. Take a look at the exclusion settings (above) for short instruction.', array('!helppagelink' => url('admin/help/fckeditor', array('fragment' => 'fieldinclexcl')))), |
| 5c21faac | 922 | '#wysiwyg' => FALSE, |
| 1b120ffb | 923 | ); |
| a2c15b72 | 924 | |
| 29d8625e | 925 | $form['fckeditor_advanced_settings'] = array( |
| 201b993d | 926 | '#type' => 'fieldset', |
| 927 | '#title' => t('Advanced settings'), | |
| 928 | '#collapsible' => TRUE, | |
| 929 | '#collapsed' => TRUE, | |
| 29d8625e | 930 | ); |
| a2c15b72 | 931 | |
| 29d8625e WW |
932 | $module_drupal_path = drupal_get_path('module', 'fckeditor'); |
| 933 | ||
| 934 | $form['fckeditor_advanced_settings']['fckeditor_path'] = array( | |
| 201b993d | 935 | '#type' => 'textfield', |
| 936 | '#title' => t('Path to FCKeditor'), | |
| b94b689f | 937 | '#default_value' => !empty($profile->settings['fckeditor_path']) ? $profile->settings['fckeditor_path'] : '%m/fckeditor', |
| 201b993d | 938 | '#size' => 40, |
| 939 | '#maxlength' => 128, | |
| 940 | '#description' => t('Path to FCKeditor (the HTML editor, downloaded from <a href="!fckeditornet">www.fckeditor.net</a>) relative to the document root.<br />Available placeholders:<br /><strong>%b</strong> - base URL path of the Drupal installation (!base).<br /><strong>%m</strong> - base URL path where FCKeditor module is stored (!files).<br />Current path: !path', array('!path' => fckeditor_path(FALSE), '!base' => base_path(), '!files' => base_path() . $module_drupal_path , '!fckeditornet' => 'http://www.fckeditor.net/download')), | |
| 941 | '#required' => TRUE | |
| a2c15b72 | 942 | ); |
| 29d8625e WW |
943 | |
| 944 | $form['fckeditor_advanced_settings']['fckeditor_local_path'] = array( | |
| 201b993d | 945 | '#type' => 'textfield', |
| 946 | '#title' => t('Local path to FCKeditor'), | |
| 947 | '#default_value' => isset($profile->settings['fckeditor_local_path'])?$profile->settings['fckeditor_local_path']:'', | |
| 948 | '#size' => 40, | |
| 949 | '#maxlength' => 128, | |
| 950 | '#description' => t('The path to the local directory (on the server) which points to the path defined above. Enter either an absolute server path or path relative to "index.php". If empty, FCKeditor module will try to find the right path.<br />Current path: !path', array('!path' => fckeditor_path(TRUE))), | |
| a2c15b72 | 951 | ); |
| 952 | ||
| 44173850 | 953 | $form['fckeditor_advanced_settings']['show_fieldnamehint'] = array( |
| 7730222a | 954 | '#type' => 'radios', |
| 201b993d | 955 | '#title' => t('Show field name hint below each rich text editor'), |
| 956 | '#default_value' => !empty($profile->settings['show_fieldnamehint']) ? $profile->settings['show_fieldnamehint'] : 't', | |
| 957 | '#options' => array( | |
| 7730222a WW |
958 | 't' => t('Yes'), |
| 959 | 'f' => t('No') | |
| 201b993d | 960 | ), |
| 961 | '#description' => t('This only applies for users with "administer fckeditor" permissions.'), | |
| a2c15b72 | 962 | ); |
| 963 | ||
| b94b689f WW |
964 | if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { |
| 965 | $current_private_dir = !isset($edit->settings['private_dir']) ? "" : $edit->settings['private_dir']; | |
| 966 | $form['fckeditor_advanced_settings']['private_dir'] = array( | |
| 967 | '#type' => 'textfield', | |
| 968 | '#title' => t('Location of files uploaded with FCKeditor in the private folder'), | |
| 969 | '#default_value' => $current_private_dir, | |
| 970 | '#size' => 40, | |
| 971 | '#maxlength' => 255, | |
| 95e32685 | 972 | '#description' => t('The path relative to the location of the private directory where FCKeditor should store uploaded files.') .'<br />'. t('<strong>Warning:</strong> FCKeditor does not implement any kind of access protection on files available in this location. All files stored in the directory defined above might be accessible by unathenticated users if there is no information about the file in the Drupal\'s database.') .'<br />'. t('System path to the private folder is: !system_path.', array('!system_path' => realpath(file_directory_path()) . DIRECTORY_SEPARATOR)) .'<br />'. t('Available wildcard characters:<br/><strong>%u</strong> - User ID.') .'<br />'. t('Current path: !path', array('!path' => $current_private_dir .' ('. file_create_path($current_private_dir) .')')), |
| b94b689f WW |
973 | ); |
| 974 | } | |
| 43e129e1 | 975 | |
| 1b120ffb | 976 | $form['submit'] = array( |
| 201b993d | 977 | '#type' => 'submit', |
| 978 | '#value' => $btn | |
| 1b120ffb JS |
979 | ); |
| 980 | ||
| 981 | return $form; | |
| 982 | } | |
| 983 | ||
| e5c55219 | 984 | function fckeditor_admin_global_profile_form_validate($form, &$form_state) { |
| 1b120ffb JS |
985 | $edit =& $form_state['values']; |
| 986 | ||
| 987 | //include mode and all other fields are empty, invalid | |
| 988 | if ($edit['excl_mode'] == 1 && empty($edit['excl'])) { | |
| 989 | form_set_error('excl_mode', t('Include mode selected, but no paths given. Enter at least one path where FCKeditor should appear.')); | |
| 990 | } | |
| 991 | else { | |
| 992 | fckeditor_admin_profile_validate_fieldpaths('excl', $edit['excl']); | |
| 993 | } | |
| a2c15b72 | 994 | |
| 1b120ffb JS |
995 | fckeditor_admin_profile_validate_fieldpaths('simple_incl', $edit['simple_incl']); |
| 996 | } | |
| 997 | ||
| 998 | function fckeditor_admin_global_profile_form_submit($form, &$form_state) { | |
| 29d8625e | 999 | module_load_include('lib.inc', 'fckeditor'); |
| 1b120ffb JS |
1000 | $edit =& $form_state['values']; |
| 1001 | $edit['name'] = 'FCKeditor Global Profile'; | |
| a2c15b72 | 1002 | |
| 1b120ffb JS |
1003 | if (isset($edit['rank'])) { |
| 1004 | $edit['rank'] = explode('>', str_replace(' ', '', $edit['rank'])); | |
| 1005 | } | |
| a2c15b72 | 1006 | |
| 1b120ffb | 1007 | if (isset($edit['_profile'])) { |
| 4059f348 WW |
1008 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $edit['_profile']->name); |
| 1009 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $edit['_profile']->name); | |
| 1b120ffb | 1010 | } |
| a2c15b72 | 1011 | |
| 29d8625e | 1012 | //strip whitespaces |
| 29d8625e WW |
1013 | if (empty($edit['fckeditor_local_path'])) { |
| 1014 | $edit['fckeditor_local_path'] = ''; | |
| 1015 | } | |
| b94b689f WW |
1016 | else { |
| 1017 | $edit['fckeditor_local_path'] = trim($edit['fckeditor_local_path']); | |
| 1018 | } | |
| a2c15b72 | 1019 | |
| 29d8625e | 1020 | //strip slash from the end |
| b94b689f WW |
1021 | if (empty($edit['fckeditor_path'])) { |
| 1022 | $edit['fckeditor_path'] = ''; | |
| 1023 | } | |
| 29d8625e WW |
1024 | $edit['fckeditor_path'] = trim(rtrim($edit['fckeditor_path'], "/")); |
| 1025 | if ($edit['fckeditor_path'] && 0 !== strpos($edit['fckeditor_path'], "/") && 0 !== strpos($edit['fckeditor_path'], "%")) { | |
| 1026 | //ensure that slash is at the beginning | |
| 1027 | $edit['fckeditor_path'] = "/". $edit['fckeditor_path']; | |
| 1028 | } | |
| 1029 | //no slash at the end | |
| 1030 | $edit['fckeditor_local_path'] = trim(rtrim($edit['fckeditor_local_path'], "/")); | |
| a2c15b72 | 1031 | |
| 1b120ffb | 1032 | $settings = fckeditor_admin_values_to_settings($edit); |
| 4059f348 | 1033 | db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", $edit['name'], $settings); |
| 1b120ffb | 1034 | fckeditor_rebuild_selectors($edit['name']); |
| a2c15b72 | 1035 | |
| 1b120ffb JS |
1036 | drupal_set_message(t('FCKeditor global profile has been saved.')); |
| 1037 | $form_state['redirect'] = 'admin/settings/fckeditor'; | |
| 1038 | } | |
| 1039 | ||
| 1040 | /** | |
| 1041 | * Converts an array of form values to a serialized array that does not | |
| 1042 | * contain Drupal Form API values | |
| 1043 | */ | |
| 1044 | function fckeditor_admin_values_to_settings($values) { | |
| 1045 | unset($values['name'], $values['rids'], $values['_profile'], $values['op'], $values['submit'], $values['form_build_id'], $values['form_token'], $values['form_id']); | |
| a2c15b72 | 1046 | return serialize($values); |
| 1b120ffb JS |
1047 | } |
| 1048 | ||
| 1049 | function fckeditor_admin_profile_validate_fieldpaths($fieldname, $paths) { | |
| 1050 | $myerrors = array(); | |
| a2c15b72 | 1051 | |
| 1b120ffb | 1052 | $rules = preg_split('/[\s,]+/', $paths); |
| a2c15b72 | 1053 | |
| 1b120ffb JS |
1054 | foreach ($rules as $rule) { |
| 1055 | $rule = trim($rule); | |
| 1056 | if (!empty($rule) && strpos($rule, '.') === FALSE && strpos($rule, '/') === FALSE && strpos($rule, '-') === FALSE) { | |
| 1057 | $myerrors[] = t('Rule %rule is ambiguous: please append .* if %rule is a path or prepend *. if %rule is a field', array('%rule' => $rule)); | |
| 1058 | } | |
| 1059 | } | |
| a2c15b72 | 1060 | |
| 1b120ffb JS |
1061 | if (!empty($myerrors)) { |
| 1062 | form_set_error($fieldname, implode('<br/>', $myerrors)); | |
| 1063 | } | |
| 1064 | } | |
| 1065 | ||
| 1066 | function fckeditor_admin_profile_delete_form($form_state, $profile) { | |
| 1067 | $form = array(); | |
| a2c15b72 | 1068 | |
| 1b120ffb JS |
1069 | $form['_profile'] = array( |
| 1070 | '#type' => 'value', | |
| 1071 | '#value' => $profile, | |
| 1072 | ); | |
| 42225b39 | 1073 | |
| 1b120ffb JS |
1074 | $form['question'] = array( |
| 1075 | '#type' => 'item', | |
| 42225b39 | 1076 | '#value' => t('Are you sure that you want to delete the FCKeditor profile %profile?', array('%profile' => $profile->name)), |
| 1b120ffb | 1077 | ); |
| a2c15b72 | 1078 | |
| 1b120ffb JS |
1079 | $form['delete'] = array( |
| 1080 | '#type' => 'submit', | |
| 1081 | '#id' => 'delete', | |
| 42225b39 | 1082 | '#value' => t('Delete'), |
| 1b120ffb | 1083 | ); |
| a2c15b72 | 1084 | |
| 1b120ffb JS |
1085 | $form['back'] = array( |
| 1086 | '#type' => 'submit', | |
| 1087 | '#id' => 'back', | |
| 1088 | '#value' => t('Cancel'), | |
| 1089 | ); | |
| a2c15b72 | 1090 | |
| 1b120ffb JS |
1091 | return $form; |
| 1092 | } | |
| 1093 | ||
| 1094 | function fckeditor_admin_profile_delete_form_submit($form, &$form_state) { | |
| 1095 | $v =& $form_state['values']; | |
| a2c15b72 | 1096 | |
| 1b120ffb | 1097 | if ($form_state['clicked_button']['#id'] == 'delete') { |
| f60bb09c | 1098 | fckeditor_profile_delete($v['_profile']->name); |
| 42225b39 | 1099 | drupal_set_message(t('Deleted FCKeditor profile.')); |
| 1b120ffb | 1100 | } |
| a2c15b72 | 1101 | |
| 1b120ffb JS |
1102 | $form_state['redirect'] = 'admin/settings/fckeditor'; |
| 1103 | } | |
| 1104 | ||
| 1105 | /** | |
| 1106 | * Rebuilds the regular expression that is used to match the inclusion/exclusion rules | |
| 1107 | * and the simplified toolbar rules | |
| 1108 | * | |
| 1109 | * @param string $name Name of the profile to process. If omitted, all profiles are rebuilt | |
| 1110 | */ | |
| 1111 | function fckeditor_rebuild_selectors($name = NULL) { | |
| 1112 | if ($name == NULL) { | |
| 4059f348 | 1113 | $result = db_query("SELECT * FROM {fckeditor_settings}"); |
| 1b120ffb JS |
1114 | } |
| 1115 | else { | |
| 4059f348 | 1116 | $result = db_query("SELECT * FROM {fckeditor_settings} WHERE name = '%s'", $name); |
| 1b120ffb | 1117 | } |
| a2c15b72 | 1118 | |
| 1b120ffb JS |
1119 | while (($data = db_fetch_object($result))) { |
| 1120 | if ($data->settings) { | |
| 1121 | $settings = unserialize($data->settings); | |
| a2c15b72 | 1122 | |
| 1b120ffb JS |
1123 | foreach (array('excl', 'simple_incl') as $var) { |
| 1124 | $settings[$var .'_regex'] = ''; | |
| 1125 | $rules = preg_split('/[\s,]+/', $settings[$var]); | |
| 1126 | $regex = array(); | |
| a2c15b72 | 1127 | |
| 1b120ffb JS |
1128 | if (!empty($rules)) { |
| 1129 | foreach ($rules as $rule) { | |
| 1130 | if (!empty($rule)) { | |
| 1131 | $rule = fckeditor_parse_rule($rule); | |
| 1132 | $regex[] = '(?:'. fckeditor_rule_to_regex($rule) .')'; | |
| 1133 | } | |
| 1134 | } | |
| a2c15b72 | 1135 | |
| 1b120ffb JS |
1136 | if (!empty($regex)) { |
| 1137 | $settings[$var .'_regex'] = '#'. implode('|', $regex) .'#'; | |
| 1138 | } | |
| 1139 | } | |
| 1140 | } | |
| a2c15b72 | 1141 | |
| 1b120ffb JS |
1142 | db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name); |
| 1143 | } | |
| 1144 | } | |
| 1145 | } | |
| 1146 | ||
| ed7a9537 | 1147 | function fckeditor_rule_create($nodetype = '*', $path = '*', $fieldname = '*') { |
| 1b120ffb | 1148 | $rule = new stdClass(); |
| ed7a9537 | 1149 | $rule->nodetype = $nodetype; |
| 1b120ffb JS |
1150 | $rule->path = $path; |
| 1151 | $rule->field = $fieldname; | |
| a2c15b72 | 1152 | |
| 1b120ffb JS |
1153 | return $rule; |
| 1154 | } | |
| 1155 | ||
| 1156 | function fckeditor_parse_rule($rule) { | |
| 1157 | $ruleobj = new stdClass(); | |
| a2c15b72 | 1158 | |
| ed7a9537 | 1159 | $atpos = strpos($rule, '@'); |
| 27c847ec | 1160 | if ($atpos !== FALSE) { |
| ed7a9537 JS |
1161 | $ruleobj->nodetype = substr($rule, 0, $atpos); |
| 1162 | $rule = substr($rule, $atpos + 1); | |
| 27c847ec JS |
1163 | } |
| 1164 | else { | |
| ed7a9537 JS |
1165 | $ruleobj->nodetype = '*'; |
| 1166 | } | |
| a2c15b72 | 1167 | |
| 1b120ffb JS |
1168 | $dotpos = strpos($rule, '.'); |
| 1169 | if ($dotpos === FALSE) { | |
| 1170 | if (strpos($rule, '/') === FALSE && strpos($rule, '-') !== FALSE) { | |
| 1171 | // assume it's a field | |
| 1172 | $ruleobj->path = '*'; | |
| 1173 | $ruleobj->field = $rule; | |
| 1174 | } | |
| 1175 | elseif (strpos($rule, '/') !== FALSE) { | |
| 1176 | // assume it's a path | |
| 1177 | $ruleobj->path = $rule; | |
| 1178 | $ruleobj->field = '*'; | |
| 1179 | } | |
| 1180 | else { | |
| 1181 | return NULL; | |
| 1182 | } | |
| 1183 | } | |
| ed7a9537 JS |
1184 | else { |
| 1185 | $ruleobj->path = substr($rule, 0, $dotpos); | |
| 1186 | $ruleobj->field = str_replace('\.', '.', substr($rule, $dotpos + 1)); | |
| 1187 | } | |
| a2c15b72 | 1188 | |
| 1b120ffb JS |
1189 | return $ruleobj; |
| 1190 | } | |
| 1191 | ||
| 1192 | function fckeditor_rule_to_regex($rule) { | |
| 1193 | static $replace = array('\*' => '.*', '\?' => '.'); | |
| a2c15b72 | 1194 | |
| 1b120ffb | 1195 | $field = str_replace('.', '\.', $rule->field); |
| ed7a9537 | 1196 | $regex = '^'. preg_quote($rule->nodetype, '#') .'@'. preg_quote($rule->path, '#') .'\.'. preg_quote($field, '#') .'$'; |
| 1b120ffb | 1197 | $regex = strtr($regex, $replace); |
| a2c15b72 | 1198 | |
| 1b120ffb JS |
1199 | return $regex; |
| 1200 | } | |
| 1201 | ||
| 1202 | function fckeditor_rule_to_string($rule) { | |
| 1203 | $field = str_replace('.', '\.', $rule->field); | |
| ed7a9537 JS |
1204 | $rulestr = ''; |
| 1205 | if ($rule->nodetype != '*') { | |
| 27c847ec | 1206 | $rulestr .= $rule->nodetype .'@'; |
| ed7a9537 | 1207 | } |
| 27c847ec | 1208 | return $rulestr . $rule->path .'.'. $field; |
| 1b120ffb JS |
1209 | } |
| 1210 | ||
| 1211 | /** | |
| 1212 | * Remove a profile from the database. | |
| 1213 | */ | |
| 1214 | function fckeditor_profile_delete($name) { | |
| 4059f348 WW |
1215 | db_query("DELETE FROM {fckeditor_settings} WHERE name = '%s'", $name); |
| 1216 | db_query("DELETE FROM {fckeditor_role} WHERE name = '%s'", $name); | |
| 29d8625e | 1217 | } |