You are here

function ckeditor_admin_profile_form_validate in CKEditor - WYSIWYG HTML editor 7

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

Form validation for a profile.

1 call to ckeditor_admin_profile_form_validate()
ckeditor_admin_profile_clone_form_validate in includes/ckeditor.admin.inc
Form validation for a clone profile

File

includes/ckeditor.admin.inc, line 1567
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_validate($form, &$form_state) {
  $edit =& $form_state['values'];

  /*
   if ($edit['default'] == 't' && $edit['popup'] == 't') {
   form_set_error('popup', t('If CKEditor is enabled by default, the popup window must be disabled.'));
   }

   if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
   form_set_error('popup', t('If toggle is enabled, the popup window must be disabled.'));
   }
  */
  if (!$edit['name']) {
    form_set_error('name', t('You must give a profile name.'));
  }
  elseif (!preg_match('/^[A-Za-z0-9_]+$/', $edit['name'])) {
    form_set_error('name', t('Enter a valid profile name. Only alphanumeric and underscore characters are allowed.'));
  }
  elseif ($edit['name'] == 'CKEditor Global Profile') {
    form_set_error('name', t('This profile name is reserved. Please choose a different name.'));
  }
  elseif (!isset($edit['_profile']) || $edit['_profile']->name != $edit['name']) {
    $result = ckeditor_profile_load($edit['name']);
    if (!empty($result)) {
      form_set_error('name', t('The profile name must be unique. A profile with this name already exists.'));
    }
  }
  if (!preg_match('/^\\d+%?$/', $edit['width'])) {
    form_set_error('width', t('Enter a valid width value. Examples: 400, 100%.'));
  }
  if (!empty($edit['css_path'])) {
    if ($edit['css_mode'] != 'self') {
      form_set_error('css_path', t('The CSS path is not empty. Please set the <strong>Editor CSS</strong> option to the <strong>Define CSS</strong> mode.'));
    }
    elseif (FALSE !== strpos($edit['css_path'], '"')) {
      form_set_error('css_path', t('Double quotes are not allowed in the CSS path.'));
    }
    elseif (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
      form_set_error('css_path', t('Enter a valid CSS path, do not surround it with quotes.'));
    }
  }
  if (!empty($edit['styles_path'])) {
    if ($edit['css_style'] != 'self') {
      form_set_error('styles_path', t('The path to predefined styles is not empty. Please set the <strong>Predefined styles</strong> option to the <strong>Define path to ckeditor.styles.js</strong> mode.'));
    }
    elseif (FALSE !== strpos($edit['styles_path'], '"')) {
      form_set_error('styles_path', t('Double quotes are not allowed in the styles path.'));
    }
    elseif (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
      form_set_error('styles_path', t('Enter a valid styles path, do not surround it with quotes.'));
    }
  }
  if (!empty($edit['config_js_path'])) {
    if ($edit['config_js'] != 'self') {
      form_set_error('config_js_path', t('The Config JS path is not empty. Please set the <strong>Config JS</strong> option to the <strong>Define path to ckeditor.config.js</strong> mode.'));
    }
    elseif (FALSE !== strpos($edit['config_js_path'], '"')) {
      form_set_error('config_js_path', t('Double quotes are not allowed in the Config JS path.'));
    }
    elseif (substr($edit['config_js_path'], 0, 1) == "'" && substr($edit['config_js_path'], -1) == "'") {
      form_set_error('config_js_path', t('Enter a valid Config JS path, do not surround it with quotes.'));
    }
  }
  if (!empty($edit['font_format'])) {
    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'])) {
      form_set_error('font_format', t('Enter a valid, semicolon-separated list of HTML font formats (no semicolon at the end of the list is expected).'));
    }
  }

  // @todo DOWNLOAD API
  if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) {
    form_set_error('UserFilesPath', t('The path to uploaded files is required.'));
  }
  if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) {
    form_set_error('UserFilesPath', t('An absolute path to uploaded files is required.'));
  }
  if (ckeditor_get_version(TRUE) == 3) {
    $load_methods = _ckeditor_load_methods();
    if (!isset($load_methods[$edit['ckeditor_load_method']])) {
      form_set_error('ckeditor_load_method', t('Set a valid loading method.'));
    }
    if (!preg_match('#\\d+#', $edit['ckeditor_load_time_out'])) {
      form_set_error('ckeditor_load_time_out', t('Enter a valid loading timeout in seconds.'));
    }
  }
  $toolbar = $edit['toolbar'];
  $toolbar = str_replace("'", '"', $toolbar);
  $toolbar = preg_replace('/(\\w*)\\s*\\:/', '"${1}":', $toolbar);
  if (strpos($toolbar, 'CodeSnippet') !== false && empty($edit['loadPlugins']['codesnippet'])) {
    form_set_error('loadPlugins][codesnippet', t('The Code Snippet plugin must be enabled if the CodeSnippet button is enabled in the toolbar.'));
  }
  if (strpos($toolbar, 'Mathjax') !== false && empty($edit['loadPlugins']['mathjax'])) {
    form_set_error('loadPlugins][mathjax', t('The Mathjax plugin must be enabled if the Mathjax button is enabled in the toolbar.'));
  }
  if (!json_decode($toolbar)) {
    form_set_error('toolbar', t('Enter a valid toolbar configuration.'));
  }
}