diff -urpN fckeditor_old/fckeditor.admin.inc fckeditor/fckeditor.admin.inc --- fckeditor_old/fckeditor.admin.inc 2009-01-23 16:02:20.000000000 +0100 +++ fckeditor/fckeditor.admin.inc 2009-01-30 16:00:48.783900000 +0100 @@ -591,7 +591,8 @@ 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 css file set above at the Editor css') ), '#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')) ); diff -urpN fckeditor_old/fckeditor.module fckeditor/fckeditor.module --- fckeditor_old/fckeditor.module 2009-01-28 17:16:44.000000000 +0100 +++ fckeditor/fckeditor.module 2009-01-30 16:46:43.048100000 +0100 @@ -282,6 +282,16 @@ function fckeditor_menu() { 'type' => MENU_CALLBACK, ); + $items['fckeditor/styles/%element_id'] = array( + 'title' => 'FCKeditor XML Style', + 'description' => 'Styles for the FCKeditor.', + 'page callback' => 'fckeditor_xml_styles', + 'page arguments' => array(2), + 'file' => 'fckeditor.styles.inc', + 'access arguments' => array('access fckeditor'), + 'type' => MENU_CALLBACK, + ); + $items['admin/settings/fckeditor'] = array( 'title' => 'FCKeditor settings', 'description' => 'Configure the rich text editor.', @@ -754,6 +764,9 @@ 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') { + $js .= $js_id .".Config['StylesXmlPath'] = \"". url('fckeditor/styles/'.$textarea_id) ."\";\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'); @@ -817,6 +830,7 @@ function fckeditor_process_textarea($ele $conf['css_path'] = str_replace("%h%t", "%t", $conf['css_path']); $cssfiles[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $conf['css_path']); $js .= $js_id .".Config['EditorAreaCSS'] = '". implode(',', $cssfiles) ."';\n"; + drupal_add_css(str_replace(array('%h', '%t'), array($host, $themepath), $conf['css_path'])); break; case 'none': 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-01-30 16:48:02.139100000 +0100 @@ -0,0 +1,139 @@ +settings['css_mode'] == 'theme') { + $css = $themepath .'style.css'; + if (file_exists($css)) { + $css_path = $_SERVER['DOCUMENT_ROOT'].$host . $css; + } + } + else if ($profile->settings['css_mode'] == 'self') { + $css_path = $_SERVER['DOCUMENT_ROOT'].str_replace(array('%h', '%t'), array($host, $themepath), $profile->settings['css_path']); + } + $read_files = array(); + $css_file = _fckeditor_xml_styles_read_file($css_path, $host, $read_files, $theme_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) { + ereg('([^{]+){([^}]*)}',$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]); + 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'); + print ''; + print ''; + ksort($styles); + foreach($styles as $selector => $type) { + if($type == ID) { + $selector_parts = explode("#", $selector); + if(!empty($selector_parts[0])) { + print ''; + } + else { + print ''; + } + } + elseif($type == CSS_CLASS) { + $selector_parts = explode(".", $selector); + if(!empty($selector_parts[0])) { + print ''; + } + else { + print ''; + } + } + } + print ''; + exit; +} + +function _fckeditor_xml_styles_read_file($css_path, $host, $read_files, $theme_path) { + if(in_array($css_path, $read_files)) return ''; + if(file_exists($css_path)) + $css_file = file_get_contents($css_path); + else return ''; + + $read_files[] = $css_path; + + preg_match_all('/@import[\s]*("([^"]*)")?(\'([^\']*)\')?[\s]*;?/ms',$css_file,$css_sub_files,PREG_SET_ORDER); + //remove imports + $css_file = preg_replace('/@[a-zA-Z]*[\s]*("([^"]*)")?(\'([^\']*)\')?[\s]*;?/ms','',$css_file); + + foreach($css_sub_files as $css_sub_file) { + $css_file.= "\n"._fckeditor_xml_styles_read_file($_SERVER['DOCUMENT_ROOT'].$host.$theme_path.$css_sub_file[2], $host, $read_files, $theme_path); + } + return $css_file; +} \ No newline at end of file