You are here

function wysiwyg_ckeditor_settings_parse_styles in Wysiwyg 7.2

Same name and namespace in other branches
  1. 6.2 editors/ckeditor.inc \wysiwyg_ckeditor_settings_parse_styles()

Parses stylesSet settings string into a stylesSet JavaScript settings array.

@todo This should be a plugin setting, but Wysiwyg does not support plugin-specific settings yet.

Parameters

string $css_classes: A string containing CSS class definitions to add to the Style dropdown list, separated by newlines.

Return value

array|false An array containing the parsed stylesSet definition, or FALSE on parse error.

See also

wysiwyg_ckeditor_settings_form()

wysiwyg_ckeditor_settings_form_validate_css_classes()

2 calls to wysiwyg_ckeditor_settings_parse_styles()
wysiwyg_ckeditor_settings in editors/ckeditor.inc
Return runtime editor settings for a given wysiwyg profile.
wysiwyg_ckeditor_settings_form_validate_stylessets in editors/ckeditor.inc
#element_validate handler for CSS classes element altered by wysiwyg_ckeditor_settings_form().

File

editors/ckeditor.inc, line 679
Editor integration functions for CKEditor.

Code

function wysiwyg_ckeditor_settings_parse_styles($css_classes) {
  $set = array();
  $input = trim($css_classes);
  if (empty($input)) {
    return $set;
  }

  // Handle both Unix and Windows line-endings.
  foreach (explode("\n", str_replace("\r", '', $input)) as $line) {
    $line = trim($line);

    // [label]=[element].[class][.[class]][...] pattern expected.
    if (!preg_match('@^.+= *[a-zA-Z0-9]+(\\.[a-zA-Z0-9_ -]+)*$@', $line)) {
      return FALSE;
    }
    list($label, $selector) = explode('=', $line, 2);
    $classes = explode('.', $selector);
    $element = array_shift($classes);
    $style = array();
    $style['name'] = trim($label);
    $style['element'] = trim($element);
    if (!empty($classes)) {
      $style['attributes']['class'] = implode(' ', array_map('trim', $classes));
    }
    $set[] = $style;
  }
  return $set;
}