Builds the "stylesSet" configuration part of the CKEditor JS settings.
string $styles: The "styles" setting.
array|FALSE An array containing the "stylesSet" configuration, or FALSE when the syntax is invalid.
getConfig()
protected function generateStylesSetSetting($styles) {
$styles_set = array();
// Early-return when empty.
$styles = trim($styles);
if (empty($styles)) {
return $styles_set;
}
$styles = str_replace(array(
"\r\n",
"\r",
), "\n", $styles);
foreach (explode("\n", $styles) as $style) {
$style = trim($style);
// Ignore empty lines in between non-empty lines.
if (empty($style)) {
continue;
}
// Validate syntax: element.class[.class...]|label pattern expected.
if (!preg_match('@^ *[a-zA-Z0-9]+ *(\\.[a-zA-Z0-9_-]+ *)+\\| *.+ *$@', $style)) {
return FALSE;
}
// Parse.
list($selector, $label) = explode('|', $style);
$classes = explode('.', $selector);
$element = array_shift($classes);
// Build the data structure CKEditor's stylescombo plugin expects.
// @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Styles
$styles_set[] = array(
'name' => trim($label),
'element' => trim($element),
'attributes' => array(
'class' => implode(' ', array_map('trim', $classes)),
),
);
}
return $styles_set;
}