You are here

function ckeditor_admin_profile_form in CKEditor - WYSIWYG HTML editor 7

Same name and namespace in other branches
  1. 6 includes/ckeditor.admin.inc \ckeditor_admin_profile_form()

Form builder for a profile

1 call to ckeditor_admin_profile_form()
ckeditor_admin_profile_clone_form in includes/ckeditor.admin.inc
Form builder for a clone profile
1 string reference to 'ckeditor_admin_profile_form'
ckeditor_menu in ./ckeditor.module
Implementation of hook_menu().

File

includes/ckeditor.admin.inc, line 658
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function ckeditor_admin_profile_form($form, $form_state, $task, $profile = NULL) {
  global $theme;
  if ($profile != NULL) {
    $form['_profile'] = array(
      '#type' => 'value',
      '#value' => $profile,
    );
  }
  else {
    $profile = new stdClass();
  }
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  $editor_path = ckeditor_path('relative');
  $editor_local_path = ckeditor_path('local');
  $editor_url_path = ckeditor_path('url');
  $module_drupal_path = ckeditor_module_path('relative');
  $module_drupal_url_path = ckeditor_module_path('url');
  drupal_add_js(array(
    'ckeditor_version' => ckeditor_get_version(),
  ), 'setting');
  $lang_options = ckeditor_load_lang_options();

  // Attach the administration CSS.
  $form['#attached'] = array(
    'css' => array(
      drupal_get_path('module', 'ckeditor') . '/css/ckeditor.admin.css',
    ),
  );
  $form['basic'] = array(
    '#type' => 'fieldset',
    '#title' => t('Basic setup'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  switch ($task) {
    case 'clone':

      //load all profiles to check their names
      $profiles = ckeditor_profile_load();
      $oldname = $profile->name;
      $maxsize = 128;

      //default max name length
      $res = array();
      $pat = "/^(.*?)_([0-9]+)\$/";
      if (preg_match($pat, $oldname, $res)) {

        // oldname like 'name_nr'
        $name = $res[1];
        $num = $res[2] + 1;
      }
      else {
        $name = $oldname;
        $num = 2;
      }
      $newname = substr($name, 0, $maxsize - 3) . '_' . $num;

      // +limit
      while (isset($profiles[$newname])) {

        //find next free number
        $num++;
        $newname = substr($name, 0, $maxsize - 3) . '_' . $num;
      }
      break;
    case 'edit':
      $newname = $profile->name;
      break;
  }
  $global_profile = ckeditor_profile_load('CKEditor Global Profile');
  $toolbar_wizard = !empty($global_profile->settings['toolbar_wizard']) ? $global_profile->settings['toolbar_wizard'] : 't';
  drupal_add_js(array(
    'ckeditor_toolbar_wizard' => $toolbar_wizard,
  ), 'setting');
  $form['basic']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile name'),
    '#default_value' => !empty($profile->name) ? $newname : '',
    '#size' => 40,
    '#maxlength' => 128,
    '#description' => t('Enter a name for this profile. This name is only visible within the CKEditor administration page.'),
    '#required' => TRUE,
  );
  $orig_formats = filter_formats();
  if ($task == 'edit' && !empty($profile->name)) {
    $used_formats = db_select('ckeditor_input_format', 'f')
      ->fields('f', array(
      "format",
    ))
      ->distinct()
      ->condition("f.name", array(
      $profile->name,
    ), 'NOT IN')
      ->execute()
      ->fetchAllAssoc('format');
  }
  else {
    $profile->input_formats = array();
    $used_formats = db_select('ckeditor_input_format', 'f')
      ->fields('f', array(
      "format",
    ))
      ->distinct()
      ->execute()
      ->fetchAllAssoc('format');
  }
  $formats = array();
  $input_format_config_links = array();
  foreach ($orig_formats as $format) {
    if ($task == 'edit' && !empty($profile->input_formats) && array_key_exists($format->format, $profile->input_formats) || !array_key_exists($format->format, $used_formats)) {
      $formats[$format->format] = $format->name;
      $input_format_config_links[$format->format] = array(
        "name" => $format->name,
        "config_url" => url("admin/config/content/formats/" . $format->format),
      );
    }
  }
  $form['basic']['input_formats'] = array(
    '#id' => 'input-formats',
    '#type' => 'checkboxes',
    '#title' => t('Text formats'),
    '#default_value' => !empty($profile->input_formats) ? array_keys((array) $profile->input_formats) : array(),
    '#options' => $formats,
    '#description' => t('Choose the text formats where you want to load CKEditor.'),
  );
  $form['security'] = array(
    '#type' => 'fieldset',
    '#title' => t('Security'),
    '#description' => '<p>' . t('The CKEditor security system protects you from executing malicious code that is already in your database. In plain textareas database content is harmless because it is not executed, but the CKEditor WYSIWYG editor interprets HTML like a web browser and thus the content needs to be filtered before it is loaded.') . '</p>',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['security']['filters'] = array(
    '#id' => 'security-filters',
    '#type' => 'container',
  );
  $form['security']['filters']['__header'] = array(
    '#type' => 'item',
    '#title' => t('Security filters'),
    '#description' => t('Below is a list of security filters along with their status for each text format.<br /><br />The following statuses are available: !img_enabled - the filter is configured for a given text format and will be run on the content during the filtering process. !img_disabled - the filter is disabled for a given text format and will not be run on the content during the filtering process.<br /><br />In order to modify the security filters settings for each of the text formats, you need to visit the text format configuration sections as listed below: !elem_format_config', array(
      '!img_enabled' => '</br><img src="' . $module_drupal_path . '/images/tick.png"/>',
      '!img_disabled' => '</br><img src="' . $module_drupal_path . '/images/delete.png"/>',
      '!elem_format_config' => '<ul class="text-formats-config"></ul>',
    )),
    '#weight' => -10,
  );

  //get text formats filters
  $input_format_filters = array();
  foreach ($formats as $key => $value) {
    $input_format_filters[$key] = array();
    $filters = filter_list_format($key);
    foreach ($filters as $filter_name => $filter_settings) {
      if ($filter_settings->status == 1) {
        $input_format_filters[$key][$filter_name] = TRUE;
      }
    }
  }
  drupal_add_js(array(
    'text_format_filters' => $input_format_filters,
    'text_formats_config_links' => $input_format_config_links,
  ), 'setting');
  $security_filters = ckeditor_security_filters();
  _ckeditor_admin_profile_form_security_filters($form, $profile, $security_filters);
  $form['security']['ss'] = array(
    '#type' => 'radios',
    '#title' => t('Security settings'),
    '#default_value' => isset($profile->settings['ss']) ? $profile->settings['ss'] : '2',
    '#options' => array(
      '2' => t('Always run security filters for CKEditor.'),
      '1' => t('Run security filters only when CKEditor is set to start automatically.'),
    ),
    '#description' => t('There are two ways of starting CKEditor: automatically and manually (via toggle). If you decide to apply security filters only when CKEditor starts automatically, you will not be protected when toggling manually from plain textarea to CKEditor. Choose this option only if you can detect various attacks (mainly XSS) by yourself just by looking at the HTML code.'),
  );
  $form['appearance'] = array(
    '#type' => 'fieldset',
    '#title' => t('Editor appearance'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $ui_colors = array(
    "default" => t('CKEditor default'),
    "custom" => t('Select manually'),
  );
  if (function_exists('color_get_palette')) {

    // apparently $theme is not initialized (?)
    if (empty($theme)) {
      init_theme();
    }
    $palette = @color_get_palette($theme, FALSE);

    //[#652274]
    $color_palette['default'] = '#D3D3D3';
    if (!empty($palette)) {
      if (!empty($palette['base'])) {
        $color_palette['color_base'] = $palette['base'];
        $ui_colors["color_base"] = t('Color module: base');
      }
      if (!empty($palette['top'])) {
        $color_palette['color_top'] = $palette['top'];
        $ui_colors["color_top"] = t('Color module: top');
      }
      if (!empty($palette['bottom'])) {
        $color_palette['color_bottom'] = $palette['bottom'];
        $ui_colors["color_bottom"] = t('Color module: bottom');
      }
    }
    drupal_add_js(array(
      'ckeditor_uicolor' => $color_palette,
    ), 'setting');
  }
  if ($editor_path == '<URL>') {
    drupal_add_js($editor_url_path . '/ckeditor.js', 'external');
  }
  else {
    drupal_add_js('window.CKEDITOR_BASEPATH = "' . $editor_path . '/"', array(
      'type' => 'inline',
      'weight' => -100,
    ));
    drupal_add_js($editor_url_path . '/ckeditor.js', array(
      'type' => 'file',
      'preprocess' => FALSE,
    ));
  }
  if (!empty($profile->settings['config_js']) && $profile->settings['config_js'] == 'self') {
    $themepath = drupal_get_path('theme', variable_get('theme_default', $theme)) . '/';
    $config_js_path = trim(str_replace("%h%t", "%t", $profile->settings['config_js_path']));
    $config_js_path = str_replace(array(
      '%h',
      '%t',
    ), array(
      base_path(),
      base_path() . $themepath,
    ), $config_js_path);
    if (!empty($config_js_path)) {
      drupal_add_js($config_js_path, 'external');
    }
    else {
      drupal_add_js($module_drupal_url_path . '/ckeditor.config.js', 'file');
    }
  }
  elseif (!empty($profile->settings['config_js']) && $profile->settings['config_js'] == 'theme') {
    $themepath = drupal_get_path('theme', variable_get('theme_default', $theme)) . '/';
    drupal_add_js(base_path() . $themepath . 'ckeditor.config.js', 'external');
  }
  else {
    drupal_add_js($module_drupal_url_path . '/ckeditor.config.js', 'file');
  }
  drupal_add_js($module_drupal_url_path . '/includes/ckeditor.admin.js', 'file');
  if ($toolbar_wizard == 't') {
    drupal_add_library('system', 'ui.widget');
    drupal_add_library('system', 'ui.sortable');
    drupal_add_js($module_drupal_url_path . '/includes/jqueryUI/sort.js', 'file');
  }
  $form['appearance']['toolbar'] = array(
    '#type' => 'textarea',
    '#title' => t('Toolbar'),
    '#default_value' => !empty($profile->settings['toolbar']) ? $profile->settings['toolbar'] : '',
    '#description' => t('Load sample toolbar: !toolbars', array(
      "!toolbars" => '<a href="#" id="cke_toolbar_DrupalBasic" class="cke_load_toolbar">' . t('Basic') . '</a> | <a href="#" id="cke_toolbar_DrupalAdvanced" class="cke_load_toolbar">' . t('Advanced') . '</a> | <a href="#" id="cke_toolbar_DrupalFull" class="cke_load_toolbar">' . t('Full') . '</a>',
    )),
    '#wysiwyg' => FALSE,
    '#rows' => 15,
  );
  if ($toolbar_wizard == 't') {
    $form['appearance']['toolbar_wizzard_used'] = array(
      '#markup' => '<div>' . t('Current toolbar') . '</div><div class="sortableList" id="groupLayout"></div><br/>',
      '#description' => t('Currently used buttons'),
    );
    drupal_add_js(array(
      'cke_toolbar_buttons_all' => ckeditor_toolbar_buttons_all(),
    ), 'setting');
    $form['appearance']['toolbar_wizzard_all'] = array(
      '#markup' => '<div>' . t('Available buttons') . '</div><div id="allButtons" class="sortableList"></div><br/>',
      '#description' => t('All available buttons'),
    );
  }
  $form['appearance']['expand'] = array(
    '#type' => 'radios',
    '#title' => t('Toolbar state on startup'),
    '#default_value' => !empty($profile->settings['expand']) ? $profile->settings['expand'] : 't',
    '#options' => array(
      't' => t('Expanded'),
      'f' => t('Collapsed'),
    ),
    '#description' => t('The toolbar will start in an expanded or collapsed state.'),
  );
  $form['appearance']['default'] = array(
    '#type' => 'radios',
    '#title' => t('Default editor state'),
    '#default_value' => !empty($profile->settings['default']) ? $profile->settings['default'] : 't',
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
    '#description' => t('Default editor state. If disabled, the rich text editor may still be enabled by using toggle.'),
  );
  $form['appearance']['show_toggle'] = array(
    '#type' => 'radios',
    '#title' => t('Show the disable/enable rich text editor toggle'),
    '#default_value' => !empty($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : 't',
    '#options' => array(
      't' => t('Show'),
      'f' => t('Hide'),
    ),
    '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea.'),
  );
  $form['appearance']['uicolor'] = array(
    '#type' => 'select',
    '#title' => t('User interface color'),
    '#default_value' => !empty($profile->settings['uicolor']) ? $profile->settings['uicolor'] : 'default',
    '#options' => $ui_colors,
  );
  if (!isset($global_profile->settings['skin']) || !file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin'])) {
    $global_profile->settings['skin'] = ckeditor_default_skin();
  }
  $skinframe_url = url('admin/config/content/ckeditor/skinframe', array(
    'query' => array(
      'token' => drupal_get_token('ckeditorSkinframeCall'),
      'skin' => $global_profile->settings['skin'],
      'uicolor' => !empty($profile->settings['uicolor_user']) && $profile->settings['uicolor'] == 'custom' ? ltrim($profile->settings['uicolor_user'], '#') : 'D3D3D3',
    ),
  ));
  $form['appearance']['skinframe'] = array(
    '#markup' => '<iframe frameborder="0" id="skinframe" marginheight="0" marginwidth="0" src="' . $skinframe_url . '" style="height:430px;width:700px;"></iframe><br/>',
    '#description' => '',
  );
  $form['appearance']['uicolor_user'] = array(
    '#type' => 'hidden',
    '#default_value' => !empty($profile->settings['uicolor_user']) ? $profile->settings['uicolor_user'] : 'default',
  );
  $plugin_list = ckeditor_load_plugins();
  $plugins = array();
  if (isset($profile->settings['loadPlugins'])) {
    foreach ($plugin_list as $key => $val) {
      $plugins[$key] = $val['desc'];
    }
  }
  else {
    $default_plugins = array();
    foreach ($plugin_list as $key => $val) {
      $plugins[$key] = $val['desc'];
      if (isset($val['default']) && $val['default'] == 't') {
        $default_plugins[] = $key;
      }
    }
  }
  $form['appearance']['loadPlugins'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Plugins'),
    '#default_value' => isset($profile->settings['loadPlugins']) ? array_keys((array) $profile->settings['loadPlugins']) : $default_plugins,
    '#options' => $plugins,
    '#description' => t('Choose the plugins that you want to enable in CKEditor.'),
  );
  if ($editor_local_path != '<URL>' && file_exists($editor_local_path . '/plugins/divarea/plugin.js')) {
    $form['appearance']['use_divarea'] = array(
      '#type' => 'radios',
      '#title' => t('"Div-based" editor'),
      '#default_value' => !empty($profile->settings['use_divarea']) ? $profile->settings['use_divarea'] : 'f',
      '#options' => array(
        't' => t('Enabled'),
        'f' => t('Disabled'),
      ),
      '#description' => t("Loading editor into <code>div</code> instead of <code>iframe</code>."),
    );
  }
  $form['appearance']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Editor width'),
    '#default_value' => !empty($profile->settings['width']) ? $profile->settings['width'] : '100%',
    '#description' => t("Editor interface width in pixels or percent. Examples: 400, 100%."),
    '#size' => 40,
    '#maxlength' => 128,
  );
  $form['appearance']['lang'] = array(
    '#type' => 'select',
    '#title' => t('Language'),
    '#default_value' => !empty($profile->settings['lang']) ? $profile->settings['lang'] : 'en',
    '#options' => $lang_options,
    '#description' => t('The language for the CKEditor user interface.'),
  );
  $form['appearance']['auto_lang'] = array(
    '#type' => 'radios',
    '#title' => t('Auto-detect language'),
    '#default_value' => !empty($profile->settings['auto_lang']) ? $profile->settings['auto_lang'] : 't',
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
    '#description' => t('Automatically detect the user language.'),
  );
  $form['appearance']['language_direction'] = array(
    '#type' => 'select',
    '#title' => t('Language direction'),
    '#default_value' => !empty($profile->settings['language_direction']) ? $profile->settings['language_direction'] : 'default',
    '#options' => array(
      'default' => t('Get from current locale (default)'),
      'ltr' => t('Left-To-Right'),
      // language like English
      'rtl' => t('Right-To-Left'),
    ),
    '#description' => t('Choose the language direction used in the editing area. Even when CKEditor automatically detects the user language and adjusts its user interface, the editing area is not automatically changed into the LTR or RTL mode. To be able to type LTR (like English) and RTL (like Arabic, Hebrew, Persian) content at the same time, please make sure that the <strong>!bidiltr</strong> and <strong>!bidirtl</strong> buttons are enabled in the toolbar.', array(
      '!bidiltr' => 'BidiLtr',
      '!bidirtl' => 'BidiRtl',
    )),
  );
  $form['acf'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced content filter'),
    '#description' => t('Configure input data filtering in CKEditor. See !link for more information about ACF.', array(
      '!link' => l(t('this blog post'), 'http://ckeditor.com/blog/Upgrading-to-CKEditor-4.1'),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['acf']['allowed_content'] = array(
    '#type' => 'radios',
    '#title' => t('Advanced content filter'),
    '#description' => t('<strong>Example:</strong> if only Bold and Link buttons are enabled, only !strong and !a tags will be allowed. Any !b tags will automatically be converted into !strong. The !img tag will not be allowed, unless the Image button is added to the toolbar.', array(
      '!strong' => '<code>&lt;strong&gt;</code>',
      '!a' => '<code>&lt;a&gt;</code>',
      '!img' => '<code>&lt;img&gt;</code>',
      '!b' => '<code>&lt;b&gt;</code>',
    )) . '<br /><br />' . t('<strong>Warning:</strong> CKEditor will not use the set of tags associated with text format. Only the buttons enabled in the toolbar and optional plugins will determine which tags/attributes/styles are handled by CKEditor. Enabling ACF in CKEditor does not affect server-side filtering done by Drupal in any way.'),
    '#default_value' => !empty($profile->settings['allowed_content']) ? $profile->settings['allowed_content'] : 't',
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
  );
  $form['acf']['allowed_content']['t']['#description'] = t('CKEditor will only allow tags/attributes/styles provided by CKEditor features. Disallowed content will be removed directly by CKEditor. When configured properly, it helps to ensure a true WYSIWYG experience.');
  $form['acf']['allowed_content']['f']['#description'] = t('CKEditor will not filter any tags and as a result, the user will be able to insert any content into the editor. The content will only be filtered by server-side filters associated with input formats.');
  $form['acf']['extraAllowedContent'] = array(
    '#type' => 'textarea',
    '#title' => t('Extra allowed content'),
    '#default_value' => !empty($profile->settings['extraAllowedContent']) ? $profile->settings['extraAllowedContent'] : "",
    '#cols' => 60,
    '#rows' => 5,
    '#description' => t('Set additional allowed content rules for CKEditor. Separate rules with a semicolon. See !docs for more information.', array(
      '!docs' => l(t('CKEditor documentation'), 'http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent'),
    )) . '<p>' . t('<strong>Example:</strong> !rules', array(
      '!rules' => "<code>object[width,height];param[name,value];embed[*];</code>",
    )) . '</p>',
    '#wysiwyg' => FALSE,
  );
  $form['output'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cleanup and output'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['output']['enter_mode'] = array(
    '#type' => 'select',
    '#title' => t('Enter mode'),
    '#default_value' => !empty($profile->settings['enter_mode']) ? $profile->settings['enter_mode'] : 'p',
    '#options' => array(
      'p' => '<p>',
      'br' => '<br>',
      'div' => '<div>',
    ),
    '#description' => t('Set which tag should be used by CKEditor when the <em>Enter</em> key is pressed.'),
  );
  $form['output']['shift_enter_mode'] = array(
    '#type' => 'select',
    '#title' => t('Shift+Enter mode'),
    '#default_value' => !empty($profile->settings['shift_enter_mode']) ? $profile->settings['shift_enter_mode'] : 'br',
    '#options' => array(
      'p' => '<p>',
      'br' => '<br>',
      'div' => '<div>',
    ),
    '#description' => t('Set which tag should be used by CKEditor when the <em>Shift+Enter</em> key combination is pressed.'),
  );
  $form['output']['font_format'] = array(
    '#type' => 'textfield',
    '#title' => t('Font formats'),
    '#default_value' => !empty($profile->settings['font_format']) ? $profile->settings['font_format'] : 'p;div;pre;address;h1;h2;h3;h4;h5;h6',
    '#size' => 40,
    '#maxlength' => 250,
    '#description' => t('Semicolon-separated list of HTML font formats. Allowed values are: !allowed_values', array(
      '!allowed_values' => '<code>p;div;pre;address;h1;h2;h3;h4;h5;h6</code>',
    )),
  );
  if (!empty($profile->settings['formatting']['custom_formatting_options'])) {
    foreach ($profile->settings['formatting']['custom_formatting_options'] as $k => $v) {
      if ($v === 0) {
        unset($profile->settings['formatting']['custom_formatting_options'][$k]);
      }
    }
  }
  $form['output']['custom_formatting'] = array(
    '#type' => 'radios',
    '#title' => t('Use custom formatting options'),
    '#default_value' => !empty($profile->settings['custom_formatting']) ? $profile->settings['custom_formatting'] : 'f',
    '#options' => array(
      't' => t('Yes'),
      'f' => t('No'),
    ),
  );
  $form['output']['formatting'] = array(
    '#type' => 'fieldset',
    '#title' => t('Custom formatting options'),
    '#tree' => TRUE,
  );
  $form['output']['formatting']['custom_formatting_options'] = array(
    '#type' => 'checkboxes',
    '#default_value' => isset($profile->settings['formatting']['custom_formatting_options']) ? array_keys((array) $profile->settings['formatting']['custom_formatting_options']) : array(
      'indent' => 'indent',
      'breakBeforeOpen' => 'breakBeforeOpen',
      'breakAfterOpen' => 'breakAfterOpen',
      'breakAfterClose' => 'breakAfterClose',
    ),
    '#options' => array(
      'indent' => t('Indent the element contents.'),
      'breakBeforeOpen' => t('Break line before the opening tag.'),
      'breakAfterOpen' => t('Break line after the opening tag.'),
      'breakBeforeClose' => t('Break line before the closing tag.'),
      'breakAfterClose' => t('Break line after the closing tag.'),
      'pre_indent' => t('Indent the <code>&lt;pre&gt;</code> element contents.'),
    ),
  );
  $form['css'] = array(
    '#type' => 'fieldset',
    '#title' => t('CSS'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $current_theme = variable_get('theme_default', $theme);
  $theme_path = drupal_get_path('theme', $current_theme);
  $form['css']['css_mode'] = array(
    '#type' => 'select',
    '#title' => t('Editor CSS'),
    '#default_value' => !empty($profile->settings['css_mode']) ? $profile->settings['css_mode'] : 'theme',
    '#options' => array(
      'theme' => t('Use theme CSS'),
      'self' => t('Define CSS'),
      'none' => t('CKEditor default'),
    ),
    '#description' => t('Defines the CSS to be used in the editor area.!title_theme_css &ndash; load the !style_css file from the current site theme.!title_define_css &ndash; enter the CSS file path below.!title_ckeditor_default &ndash; use the default editor CSS.', array(
      '!title_theme_css' => '<br /><strong>' . t('Use theme CSS') . '</strong>',
      '!title_define_css' => '<br /><strong>' . t('Define CSS') . '</strong>',
      '!title_ckeditor_default' => '<br /><strong>' . t('CKEditor default') . '</strong>',
      '!style_css' => '<code>style.css</code>',
    )),
  );
  $form['css']['css_path'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS file path'),
    '#default_value' => !empty($profile->settings['css_path']) ? $profile->settings['css_path'] : "",
    '#size' => 40,
    '#maxlength' => 255,
    '#description' => t('Enter the path to the CSS file (Example: !example1) or a list of CSS files separated with a comma (Example: !example2). Make sure you select the !title_define_css option above.', array(
      '!example1' => '<code>"css/editor.css"</code>',
      '!example2' => '<code>"/themes/garland/style.css,http://example.com/style.css"</code>',
      '!title_define_css' => '<strong>' . t('Define CSS') . '</strong>',
    )) . '<br />' . t('Available placeholders:!h &ndash; host name (!host).!t &ndash; path to theme (!theme).', array(
      '!h' => '<br /><code>%h</code>',
      '!t' => '<br /><code>%t</code>',
      '!host' => '<code>' . base_path() . '</code>',
      '!theme' => '<code>' . base_path() . $theme_path . '/</code>',
    )),
  );
  $form['css']['css_style'] = array(
    '#type' => 'select',
    '#title' => t('Predefined styles'),
    '#default_value' => !empty($profile->settings['css_style']) ? $profile->settings['css_style'] : 'theme',
    '#options' => array(
      'theme' => t('Use theme ckeditor.styles.js'),
      'self' => t('Define path to ckeditor.styles.js'),
      'default' => t('CKEditor default'),
    ),
    '#description' => t('Define the location of the !ckeditor_styles_js_file file. It is used by the <strong>Style</strong> drop-down list available in the default toolbar. Copy the !ckeditor_styles_js_path file into your theme directory (!theme) and adjust it to your needs.', array(
      '!ckeditor_styles_js_file' => '<code>ckeditor.styles.js</code>',
      '!ckeditor_styles_js_path' => '<code>' . drupal_get_path('module', 'ckeditor') . '/ckeditor.styles.js</code>',
      '!theme' => '<code>' . $theme_path . '/ckeditor.styles.js' . '</code>',
    )),
  );
  $form['css']['styles_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Predefined styles path'),
    '#default_value' => !empty($profile->settings['styles_path']) ? $profile->settings['styles_path'] : "",
    '#size' => 40,
    '#maxlength' => 255,
    '#description' => t('Enter the path to a file with predefined styles (Example: !example1). Make sure you select the !style_define_path option above.', array(
      '!style_define_path' => '<strong>' . t('Define path to ckeditor.styles.js') . '</strong>',
      '!ckeditor_styles_js_file' => '<code>ckeditor.styles.js</code>',
      '!example1' => '<code>/ckeditor.styles.js</code>',
    )) . '<br />' . t('Available placeholders:!h &ndash; host name (!host).!t &ndash; path to theme (!theme).!m &ndash; path to the CKEditor module (!module).', array(
      '!h' => '<br /><code>%h</code>',
      '!t' => '<br /><code>%t</code>',
      '!m' => '<br /><code>%m</code>',
      '!host' => '<code>' . base_path() . '</code>',
      '!theme' => '<code>' . base_path() . $theme_path . '/</code>',
      '!module' => '<code>' . drupal_get_path('module', 'ckeditor') . '</code>',
    )),
  );
  $form['ckeditor_upload_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('File browser settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Set the file browser settings. A file browser will allow you to browse the files stored on the server and embed them as links, images, or Flash movies. CKEditor is compatible with such Drupal modules as !imce or !elfinder. CKEditor can be also integrated with !ckfinder, an advanced Ajax file manager.', array(
      '!imce' => l(t('IMCE'), 'http://drupal.org/project/imce'),
      '!elfinder' => l(t('elFinder'), 'http://drupal.org/project/elfinder'),
      '!ckfinder' => l(t('CKFinder'), 'http://cksource.com/ckfinder'),
    )),
  );
  $filebrowsers = array(
    'none' => t('None'),
    'ckfinder' => t('CKFinder'),
  );
  $filebrowsers_dialogs = array(
    '' => t('Same as in the Link dialog window'),
    'ckfinder' => t('CKFinder'),
  );
  if (module_exists('imce')) {
    $filebrowsers['imce'] = t('IMCE');
    $filebrowsers_dialogs['imce'] = t('IMCE');
  }
  if (module_exists('elfinder')) {
    $filebrowsers['elfinder'] = t('elFinder');
    $filebrowsers_dialogs['elfinder'] = t('elFinder');
  }

  /* MODULES NOT PORTED TO D7
      if (module_exists('tinybrowser')) {
      $filebrowsers['tinybrowser'] = t('TinyBrowser');
      $filebrowsers_dialogs['tinybrowser'] = t('TinyBrowser');
      }

      if (module_exists('imagebrowser')) {
      $filebrowsers['ib'] = t('Image Browser');
      $filebrowsers_dialogs['ib'] = t('Image Browser');
      }

      if (module_exists('webfm_popup')) {
      $filebrowsers['webfm'] = t('Web File Manager');
      $filebrowsers_dialogs['webfm'] = t('Web File Manager');
      }
     */
  $form['ckeditor_upload_settings']['filebrowser'] = array(
    '#type' => 'select',
    '#title' => t('File browser type (Link dialog window)'),
    '#default_value' => !empty($profile->settings['filebrowser']) ? $profile->settings['filebrowser'] : 'none',
    '#options' => $filebrowsers,
    '#description' => t('Select the file browser that you would like to use to upload files.'),
  );
  $form['ckeditor_upload_settings']['filebrowser_image'] = array(
    '#type' => 'select',
    '#title' => t('File browser type (Image dialog window)'),
    '#default_value' => !empty($profile->settings['filebrowser_image']) ? $profile->settings['filebrowser_image'] : 'none',
    '#options' => $filebrowsers_dialogs,
    '#description' => t('Select the file browser that you would like to use to upload images.'),
  );
  $form['ckeditor_upload_settings']['filebrowser_flash'] = array(
    '#type' => 'select',
    '#title' => t('File browser type (Flash dialog window)'),
    '#default_value' => !empty($profile->settings['filebrowser_flash']) ? $profile->settings['filebrowser_flash'] : 'none',
    '#options' => $filebrowsers_dialogs,
    '#description' => t('Select the file browser that you would like to use to upload Flash movies.'),
  );
  if (variable_get('file_default_scheme', '') != 'private') {
    $current_user_files_path = empty($profile->settings['UserFilesPath']) ? "%b%f/" : $profile->settings['UserFilesPath'];
    $current_user_files_path = strtr($current_user_files_path, array(
      "%f" => variable_get('file_public_path', conf_path() . '/files'),
      "%u" => "UID",
      "%b" => base_path(),
      "%n" => "UNAME",
    ));
    $current_user_files_absolute_path = empty($profile->settings['UserFilesAbsolutePath']) ? "%d%b%f/" : $profile->settings['UserFilesAbsolutePath'];
    $current_user_files_absolute_path = strtr($current_user_files_absolute_path, array(
      "%f" => variable_get('file_public_path', conf_path() . '/files'),
      "%u" => "UID",
      "%b" => base_path(),
      "%d" => ckeditor_get_document_root_full_path(),
      "%n" => "UNAME",
    ));
    $form['ckeditor_upload_settings']['UserFilesPath'] = array(
      '#type' => 'textfield',
      '#prefix' => '<fieldset><legend>' . t('CKFinder settings') . '</legend>',
      '#title' => t('Path to uploaded files'),
      '#default_value' => !empty($profile->settings['UserFilesPath']) ? $profile->settings['UserFilesPath'] : "%b%f/",
      '#size' => 40,
      '#maxlength' => 255,
      '#description' => t('Path to uploaded files relative to the document root.') . '<br />' . t('Available placeholders:!b &ndash; the base URL path of the Drupal installation (!base).!f &ndash; the Drupal file system path where the files are stored (!files).!u &ndash; User ID.!n &ndash; Username.', array(
        '!n' => '<br /><code>%n</code>',
        '!u' => '<br /><code>%u</code>',
        '!f' => '<br/><code>%f</code>',
        '!b' => '<br/><code>%b</code>',
        '!files' => '<code>' . variable_get('file_public_path', conf_path() . '/files') . '</code>',
        '!base' => '<code>' . base_path() . '</code>',
      )) . '<br />' . t('Current path: !path', array(
        '!path' => '<code>' . $current_user_files_path . '</code>',
      )),
    );
    $form['ckeditor_upload_settings']['UserFilesAbsolutePath'] = array(
      '#type' => 'textfield',
      '#title' => t('Absolute path to uploaded files'),
      '#default_value' => !empty($profile->settings['UserFilesAbsolutePath']) ? $profile->settings['UserFilesAbsolutePath'] : "%d%b%f/",
      '#size' => 40,
      '#maxlength' => 255,
      '#suffix' => '</fieldset>',
      '#description' => t('The path to the local directory (on the server) which points to the path defined above. If left empty, CKEditor will try to discover the right path.') . '<br />' . t('Available placeholders:!d &ndash; the server path to the document root (!root).!b &ndash; the base URL path of the Drupal installation (!base).!f &ndash; the Drupal file system path where the files are stored (!files).!u &ndash; User ID.!n &ndash; Username.', array(
        '!u' => '<br /><code>%u</code>',
        '!n' => '<br /><code>%n</code>',
        '!d' => '<br/><code>%d</code>',
        '!b' => '<br /><code>%b</code>',
        '!f' => '<br/><code>%f</code>',
        '!files' => '<code>' . variable_get('file_public_path', conf_path() . '/files') . '</code>',
        '!base' => '<code>' . base_path() . '</code>',
        '!root' => '<code>' . ckeditor_get_document_root_full_path() . '</code>',
      )) . '<br />' . t('Current path: !path', array(
        '!path' => '<code>' . $current_user_files_absolute_path . '</code>',
      )),
    );
  }
  if (variable_get('file_default_scheme', '') == 'private') {
    $form['ckeditor_upload_settings']['private_path_descrption'] = array(
      '#markup' => '<div>' . t('Setting a relative path to uploaded files was disabled because private downloads are enabled and thus this path is calculated automatically. To change the location of uploaded files in the private file system, edit the <strong>!url</strong>.', array(
        '!url' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg'),
      )) . '</div>',
    );
  }
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (ckeditor_get_version(TRUE) == 3) {
    $form['advanced']['ckeditor_load_method'] = array(
      '#type' => 'select',
      '#title' => t('Loading method'),
      '#default_value' => !empty($profile->settings['ckeditor_load_method']) ? $profile->settings['ckeditor_load_method'] : 'ckeditor.js',
      '#options' => _ckeditor_load_methods(),
      '#description' => t('Select the loading method of CKEditor. If the !ckeditor_basic_js file is used, only a small file is loaded initially and the rest of the editor is loaded later (see <strong>Loading timeout</strong>). This might be useful if CKEditor is disabled by default.', array(
        '!ckeditor_basic_js' => '<code>ckeditor_basic.js</code>',
      )),
    );
    $form['advanced']['ckeditor_load_time_out'] = array(
      '#type' => 'textfield',
      '#title' => t('Loading timeout'),
      '#default_value' => !empty($profile->settings['ckeditor_load_time_out']) ? $profile->settings['ckeditor_load_time_out'] : "0",
      '#size' => 40,
      '#maxlength' => 255,
      '#description' => t('The time to wait (in seconds) to load the full editor code after the page is loaded, if the !ckeditor_basic_js file is used. If set to zero, the editor is loaded on demand.', array(
        '!ckeditor_basic_js' => '<code>ckeditor_basic.js</code>',
      )),
    );
  }
  $form['advanced']['forcePasteAsPlainText'] = array(
    '#type' => 'select',
    '#title' => t('Force pasting as plain text'),
    '#default_value' => !empty($profile->settings['forcePasteAsPlainText']) ? $profile->settings['forcePasteAsPlainText'] : "f",
    '#options' => array(
      't' => t('Enabled'),
      'f' => t('Disabled'),
    ),
    '#description' => t('If enabled, HTML content will be automatically changed to plain text when pasting.'),
  );
  $form['advanced']['html_entities'] = array(
    '#type' => 'radios',
    '#title' => t('HTML Entities'),
    '#default_value' => !empty($profile->settings['html_entities']) ? $profile->settings['html_entities'] : 'f',
    '#description' => t('Convert all applicable characters to HTML entities.'),
    '#options' => array(
      'f' => t('No'),
      't' => t('Yes'),
    ),
  );
  $form['advanced']['scayt_autoStartup'] = array(
    '#type' => 'radios',
    '#title' => t('Spellchecker'),
    '#default_value' => !empty($profile->settings['scayt_autoStartup']) ? $profile->settings['scayt_autoStartup'] : 'f',
    '#description' => t('If enabled, turns on SCAYT (Spell Check As You Type) automatically after loading the editor.'),
    '#options' => array(
      'f' => t('No'),
      't' => t('Yes'),
    ),
  );
  $form['advanced']['disableNativeSpellChecker'] = array(
    '#type' => 'radios',
    '#title' => t('Disable native browser spell checker'),
    '#default_value' => !empty($profile->settings['disableNativeSpellChecker']) ? $profile->settings['disableNativeSpellChecker'] : 'f',
    '#description' => t('If set to yes the native browser spell check functionality is disabled.'),
    '#options' => array(
      'f' => t('No'),
      't' => t('Yes'),
    ),
  );
  $form['advanced']['config_js'] = array(
    '#type' => 'select',
    '#title' => t('!ckeditor_config_js', array(
      '!ckeditor_config_js' => 'Config JS',
    )),
    '#default_value' => !empty($profile->settings['config_js']) ? $profile->settings['config_js'] : 'none',
    '#options' => array(
      'none' => t('CKEditor default'),
      'theme' => t('Use theme ckeditor.config.js'),
      'self' => t('Define path to ckeditor.config.js'),
    ),
    '#description' => t('Define where to load the !ckeditor_config_js file from.!title_theme_config_js &ndash; load the !ckeditor_config_js file from the current site theme.!title_define_ckeditor_js &ndash; enter the !ckeditor_config_js file path below.!title_ckeditor_default_js &ndash; use the default editor !ckeditor_config_js.', array(
      '!ckeditor_config_js' => '<code>ckeditor.config.js</code>',
      '!title_theme_config_js' => '<br /><strong>' . t('Use theme ckeditor.config.js') . '</strong>',
      '!title_define_ckeditor_js' => '<br /><strong>' . t('Define path to ckeditor.config.js') . '</strong>',
      '!title_ckeditor_default_js' => '<br /><strong>' . t('CKEditor default') . '</strong>',
    )),
  );
  $form['advanced']['config_js_path'] = array(
    '#type' => 'textfield',
    '#title' => t('ckeditor.config.js file path'),
    '#default_value' => !empty($profile->settings['config_js_path']) ? $profile->settings['config_js_path'] : "",
    '#size' => 40,
    '#maxlength' => 255,
    '#hidden' => empty($profile->settings['config_js_path']),
    '#states' => array(
      'visible' => array(
        ':input[name="config_js"]' => array(
          'value' => 'self',
        ),
      ),
    ),
    '#description' => t('Enter the path to the ckeditor.config.js file (Example: !example1). Make sure you select the !title_define_js option above.', array(
      '!example1' => '<code>"js/config.js"</code>',
      '!title_define_js' => '<strong>' . t('Define path to ckeditor.config.js') . '</strong>',
    )) . '<br />' . t('Available placeholders:!h &ndash; host name (!host).!t &ndash; path to theme (!theme).', array(
      '!h' => '<br /><code>%h</code>',
      '!t' => '<br /><code>%t</code>',
      '!host' => '<code>' . base_path() . '</code>',
      '!theme' => '<code>' . base_path() . $theme_path . '/</code>',
    )),
  );
  $form['advanced']['js_conf'] = array(
    '#type' => 'textarea',
    '#title' => t('Custom JavaScript configuration'),
    '#default_value' => !empty($profile->settings['js_conf']) ? $profile->settings['js_conf'] : "",
    '#cols' => 60,
    '#rows' => 5,
    '#description' => t('In order to change CKEditor configuration globally, you should modify the !ckeditor_config configuration file. Sometimes it is required to change the CKEditor configuration for a single profile only. Use this box to define settings that are unique for this profile. Available options are listed in the !docs. Add the following code snippet to change the fonts available in the CKEditor <strong>Font</strong> and <strong>Size</strong> drop-down lists: <pre>@code</pre><strong>Warning</strong>: If you make a mistake here, CKEditor may not load correctly.', array(
      '!ckeditor_config' => '<code>' . drupal_get_path('module', 'ckeditor') . "/ckeditor.config.js</code>",
      '!docs' => l(t('CKEditor documentation'), 'http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html'),
      '@code' => "config.font_names = 'Arial;Times New Roman;Verdana';\nconfig.fontSize_sizes = '16/16px;24/24px;48/48px;';",
    )),
    '#wysiwyg' => FALSE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}