You are here

function fckeditor_admin_profile_form_validate in FCKeditor - WYSIWYG HTML editor 6.2

Profile validation.

1 call to fckeditor_admin_profile_form_validate()
fckeditor_admin_profile_clone_form_validate in ./fckeditor.admin.inc

File

./fckeditor.admin.inc, line 884
FCKeditor - The text editor for Internet - http://www.fckeditor.net Copyright (C) 2003-2008 Frederico Caldeira Knabben

Code

function fckeditor_admin_profile_form_validate($form, &$form_state) {
  $edit =& $form_state['values'];

  //include mode and all other fields are empty, invalid
  if ($edit['excl_mode'] == 1 && empty($edit['excl'])) {
    form_set_error('excl_mode', t('Include mode selected, but no paths given. Enter at least one path where FCKeditor should appear.'));
  }
  else {
    fckeditor_admin_profile_validate_fieldpaths('excl', $edit['excl']);
  }
  fckeditor_admin_profile_validate_fieldpaths('simple_incl', $edit['simple_incl']);
  if (!preg_match('/^\\d+$/', trim($edit['min_rows']))) {
    form_set_error('min_rows', t('Minimum rows must be a valid number.'));
  }
  if ($edit['default'] == 't' && $edit['popup'] == 't') {
    form_set_error('popup', t('If FCKeditor is enabled by default, popup window must be disabled.'));
  }
  if ($edit['show_toggle'] == 't' && $edit['popup'] == 't') {
    form_set_error('popup', t('If toggle is enabled, popup window must be disabled.'));
  }
  if (!$edit['name']) {
    form_set_error('name', t('You must give a profile name.'));
  }
  elseif ($edit['name'] == 'FCKeditor 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 = fckeditor_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 valid width.') . ' ' . t('Example') . ': 400 ' . t('or') . ' 100%.');
  }
  if (!empty($edit['css_path'])) {
    if ($edit['css_mode'] != 'self') {
      form_set_error('css_path', t('CSS path is not empty.') . ' ' . t('Please set the %settingname option to %settingoption mode.', array(
        '%settingname' => t('Editor CSS'),
        '%settingoption' => t('Define CSS'),
      )));
    }
    elseif (FALSE !== strpos($edit['css_path'], '"')) {
      form_set_error('css_path', t('Double quotes are not allowed in CSS path.'));
    }
    elseif (substr($edit['css_path'], 0, 1) == "'" && substr($edit['css_path'], -1) == "'") {
      form_set_error('css_path', t('Enter valid path, do not surround it with quotes.'));
    }
  }
  if (!empty($edit['styles_path'])) {
    if ($edit['css_style'] != 'self') {
      form_set_error('styles_path', t('Path to predefined styles is not empty.') . ' ' . t('Please set the %settingname option to %settingoption mode.', array(
        '%settingname' => t('Predefined styles'),
        '%settingoption' => t('Define path to fckstyles.xml'),
      )));
    }
    elseif (FALSE !== strpos($edit['styles_path'], '"')) {
      form_set_error('styles_path', t('Double quotes are not allowed in path.'));
    }
    elseif (substr($edit['styles_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
      form_set_error('styles_path', t('Enter valid path, do not surround it with quotes.'));
    }
  }
  if (!empty($edit['templatefile_path'])) {
    if ($edit['templatefile_mode'] != 'self') {
      form_set_error('templatefile_path', t('Path to predefined templates is not empty.') . ' ' . t('Please set the %settingname option to %settingoption mode.', array(
        '%settingname' => t('Predefined templates'),
        '%settingoption' => t('Define path to fcktemplates.xml'),
      )));
    }
    elseif (FALSE !== strpos($edit['templatefile_path'], '"')) {
      form_set_error('templatefile_path', t('Double quotes are not allowed in path.'));
    }
    elseif (substr($edit['templatefile_path'], 0, 1) == "'" && substr($edit['styles_path'], -1) == "'") {
      form_set_error('templatefile_path', t('Enter valid 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 valid, semicolon separated, list of HTML font formats (no semicolon at the end of list expected).'));
    }
  }
  if (variable_get('file_downloads', '') !== FILE_DOWNLOADS_PRIVATE) {
    if (!empty($edit['UserFilesAbsolutePath']) && empty($edit['UserFilesPath'])) {
      form_set_error('UserFilesPath', t('Path to uploaded files is required.'));
    }
    if (!empty($edit['UserFilesPath']) && empty($edit['UserFilesAbsolutePath'])) {
      form_set_error('UserFilesPath', t('Absolute path to uploaded files is required.'));
    }
  }
}