diff -urpN fckeditor_old/fckeditor.admin.inc fckeditor/fckeditor.admin.inc --- fckeditor_old/fckeditor.admin.inc 2009-03-24 17:11:30.000000000 +0100 +++ fckeditor/fckeditor.admin.inc 2009-05-15 10:07:00.966200000 +0200 @@ -591,7 +591,9 @@ function fckeditor_admin_profile_form($f '#options' => array( 'theme' => t('Use theme fckstyles.xml'), 'self' => t('Define path to fckstyles.xml'), - 'default' => t('FCKeditor default') + 'default' => t('FCKeditor default'), + 'module' => t('Use fckstyles generated based on the stylesheets of your theme. Will create a file if it doesn\'t exist yet.'), + 'module_regenerate' => t('Use fckstyles generated based on the stylesheets of your theme. Will regenerate the fckstyles file.') ), '#description' => t('Define the location of "fckstyles.xml" file. It is used by the "Style" dropdown list available in the default toolbar. Copy "!fckstyles.xml" inside your theme directory ("!theme") and adjust it to your needs.', array('!fckstyles.xml' => fckeditor_path(TRUE) .'/fckstyles.xml', '!theme' => path_to_theme() .'/fckstyles.xml')) ); @@ -798,6 +800,19 @@ function fckeditor_admin_profile_form_va } function fckeditor_admin_profile_form_submit($form, &$form_state) { + if ($form_state['values']['css_style'] == 'module_regenerate' || $form_state['values']['css_style'] == 'module') { + $styles_xml_path = file_create_path('fckeditor'); + + if (!file_exists($styles_xml_path .'/fckeditor.styles.xml') || $form_state['values']['css_style'] == 'module_regenerate') { + include_once(drupal_get_path('module', 'fckeditor') .'/fckeditor.styles.inc'); + $styles_xml = fckeditor_xml_styles($form_state['values']); + file_check_directory($styles_xml_path, FILE_CREATE_DIRECTORY); + file_save_data($styles_xml, $styles_xml_path .'/fckeditor.styles.xml', FILE_EXISTS_REPLACE); + drupal_set_message(t('XML Styles file saved in: @styles', array('@styles' => $styles_xml_path .'/fckeditor.styles.xml'))); + $form_state['values']['css_style'] = 'module'; + } + } + $edit =& $form_state['values']; if (isset($edit['_profile'])) { diff -urpN fckeditor_old/fckeditor.module fckeditor/fckeditor.module --- fckeditor_old/fckeditor.module 2009-05-14 12:48:22.000000000 +0200 +++ fckeditor/fckeditor.module 2009-05-15 10:06:57.378200000 +0200 @@ -774,6 +774,10 @@ function fckeditor_process_textarea($ele $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']); $js .= $js_id .".Config['StylesXmlPath'] = \"". str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']) ."\";\n"; } + else if ($conf['css_style'] == 'module') { + $styles_xml_path = file_create_path('fckeditor'); + $js .= $js_id .".Config['StylesXmlPath'] = \"". url($styles_xml_path .'/fckeditor.styles.xml') ."\";\n"; + } // add custom stylesheet if configured // lets hope it exists but we'll leave that to the site admin $cssfiles = array($module_full_path .'/fckeditor.css'); diff -urpN fckeditor_old/fckeditor.styles.inc fckeditor/fckeditor.styles.inc --- fckeditor_old/fckeditor.styles.inc 1970-01-01 01:00:00.000000000 +0100 +++ fckeditor/fckeditor.styles.inc 2009-05-15 10:07:03.758600000 +0200 @@ -0,0 +1,173 @@ +stylesheets)) { + foreach ($base_theme_info as $base) { + foreach ($base->stylesheets as $type => $stylesheets) { + if ($type != "print") { + foreach ($stylesheets as $name => $path) { + if (file_exists($path)) { + $css_file .= file_get_contents($path); + } + } + } + } + } + } + if (!empty($theme_info->stylesheets)) { + foreach ($theme_info->stylesheets as $type => $stylesheets) { + if ($type != "print") { + foreach ($stylesheets as $name => $path) { + if (file_exists($path)) { + $css_file .= file_get_contents($path); + } + } + } + } + } + + //remove comments + $css_file = preg_replace('|/\*.*?\*/|ms', '', $css_file); + + //break up css statements + preg_match_all('/[^{]+{([^}]*)}/ms', $css_file, $css_statements, PREG_SET_ORDER); + /* + Array + ( + [0] => Array + ( + [0] => * { font-size: 100.01%; } + [1] => font-size: 100.01%; + ) + ) + */ + + $styles = array(); + + //loop through the css statements + foreach ($css_statements as $css_statement) { + preg_match_all('/([^{]+){([^}]*)}/ms', $css_statement[0], $css_parts); + /* + Array + ( + [0] => * { font-size: 100.01%; } + [1] => * + [2] => font-size: 100.01%; + ) + */ + + //loop through the selectors + $selectors = explode(',', $css_parts[1][0]); + foreach ($selectors as $selector) { + //only works on css selectors consisting of a single class or a single html tag + if (preg_match('/^([\s])*([a-zA-Z0-9\-]*[\.#]{1}[a-zA-Z0-9\-]+)([\s])*$/', $selector) > 0) { + //remove white space from selector + $selector = preg_replace('/\s/', '', $selector); + + //remove new lines and extra whitespaces from the css + $css_parts[2] = trim(preg_replace('/([\s])+/', ' ', $css_parts[2])); + + //contains a class + if (strstr($selector, ".") !== FALSE) { + $styles[$selector] = CSS_CLASS;//(isset($classes[$selector]) ? $classes[$selector] : '') .$cssParts[2]; + } + //contains an id + else { + $styles[$selector] = CSS_ID;//(isset($ids[$selector]) ? $ids[$selector] : '').$cssParts[2]; + } + } + } + } + + //create xml + /* + + + + + */ + + //header('Content-Type: text/xml'); + $xml = ''; + $xml .= ''; + $styles_parsed = array(); + foreach ($styles as $selector => $type) { + if($type == ID) { + $selector_parts = explode("#", $selector); + if (in_array($selector_parts[0], array('body'))) continue; + if (!empty($selector_parts[0])) { + $styles_parsed[$selector_parts[1]] = ' + + '; + } + else { + $styles_parsed[$selector_parts[1]] = ' + + '; + } + } + elseif ($type == CSS_CLASS) { + $selector_parts = explode(".", $selector); + if (in_array($selector_parts[0], array('body'))) continue; + if (!empty($selector_parts[0])) { + $styles_parsed[$selector_parts[1]] = ' + + '; + } + else { + $styles_parsed[$selector_parts[1]] = ' + + '; + } + } + } + ksort($styles_parsed); + $xml .= implode('', $styles_parsed); + $xml .= ''; + return $xml; +} \ No newline at end of file