diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc index fcf168e..4813767 100644 --- a/editors/ckeditor.inc +++ b/editors/ckeditor.inc @@ -236,7 +236,8 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { // Versions below 3.0.1 could only handle one stylesheet. if (version_compare($editor['installed version'], '3.0.1.4391', '<')) { if ($config['css_setting'] == 'theme') { - $settings['contentsCss'] = reset(wysiwyg_get_css()); + $css_theme = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : ''); + $settings['contentsCss'] = reset($css_theme); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['contentsCss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); @@ -244,7 +245,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) { } else { if ($config['css_setting'] == 'theme') { - $settings['contentsCss'] = wysiwyg_get_css(); + $settings['contentsCss'] = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : ''); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['contentsCss'] = explode(',', strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL))))); diff --git a/editors/fckeditor.inc b/editors/fckeditor.inc index 27bcb7b..f1f7c77 100644 --- a/editors/fckeditor.inc +++ b/editors/fckeditor.inc @@ -129,7 +129,7 @@ function wysiwyg_fckeditor_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { - $settings['EditorAreaCSS'] = implode(',', wysiwyg_get_css()); + $settings['EditorAreaCSS'] = implode(',', wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : '')); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['EditorAreaCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); diff --git a/editors/openwysiwyg.inc b/editors/openwysiwyg.inc index b3ad84d..fe6bb15 100644 --- a/editors/openwysiwyg.inc +++ b/editors/openwysiwyg.inc @@ -100,7 +100,8 @@ function wysiwyg_openwysiwyg_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { - $settings['CSSFile'] = reset(wysiwyg_get_css()); + $css_theme = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : ''); + $settings['CSSFile'] = reset($css_theme); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['CSSFile'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); @@ -126,7 +127,7 @@ function wysiwyg_openwysiwyg_settings($editor, $config, $theme) { } } - // @todo + // @todo // if (isset($config['block_formats'])) { // $settings['DropDowns']['headings']['elements'] = explode(',', $config['block_formats']); // } diff --git a/editors/tinymce.inc b/editors/tinymce.inc index f3a92dd..47ca93c 100644 --- a/editors/tinymce.inc +++ b/editors/tinymce.inc @@ -223,7 +223,7 @@ function wysiwyg_tinymce_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { - $settings['content_css'] = implode(',', wysiwyg_get_css()); + $settings['content_css'] = implode(',', wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : '')); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); diff --git a/editors/wymeditor.inc b/editors/wymeditor.inc index 5f44d64..1bc0a9f 100644 --- a/editors/wymeditor.inc +++ b/editors/wymeditor.inc @@ -172,8 +172,8 @@ function wysiwyg_wymeditor_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { // WYMeditor only supports one CSS file currently. - $css = wysiwyg_get_css(); - $settings['stylesheet'] = reset($css); + $css_theme = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : ''); + $settings['stylesheet'] = reset($css_theme); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['stylesheet'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); diff --git a/editors/yui.inc b/editors/yui.inc index 36d0a59..f1eb81b 100644 --- a/editors/yui.inc +++ b/editors/yui.inc @@ -208,7 +208,7 @@ function wysiwyg_yui_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { - $settings['extracss'] = wysiwyg_get_css(); + $settings['extracss'] = wysiwyg_get_css(isset($config['css_theme']) ? $config['css_theme'] : ''); } elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) { $settings['extracss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))); diff --git a/wysiwyg.admin.inc b/wysiwyg.admin.inc index 497e5d4..3725d9b 100644 --- a/wysiwyg.admin.inc +++ b/wysiwyg.admin.inc @@ -40,6 +40,7 @@ function wysiwyg_profile_form($form, &$form_state, $profile) { 'apply_source_formatting' => FALSE, 'paste_auto_cleanup_on_paste' => FALSE, 'css_setting' => 'theme', + 'css_theme' => variable_get('node_admin_theme') ? variable_get('admin_theme') : variable_get('theme_default', 'bartik'), 'css_path' => NULL, 'css_classes' => NULL, ); @@ -271,7 +272,30 @@ function wysiwyg_profile_form($form, &$form_state, $profile) { '#title' => t('Editor CSS'), '#default_value' => $profile->settings['css_setting'], '#options' => array('theme' => t('Use theme CSS'), 'self' => t('Define CSS'), 'none' => t('Editor default CSS')), - '#description' => t('Defines the CSS to be used in the editor area.
Use theme CSS - loads stylesheets from current site theme.
Define CSS - enter path for stylesheet files below.
Editor default CSS - uses default stylesheets from editor.'), + '#description' => t('Defines the CSS to be used in the editor area.
Use theme CSS - loads stylesheets from the theme specified below.
Define CSS - enter path for stylesheet files below.
Editor default CSS - uses default stylesheets from editor.'), + ); + + $themes = list_themes(); + $theme_list = array( + '' => t('Node admin theme'), + 'wysiwyg_theme_admin' => t('Admin theme'), + 'wysiwyg_theme_default' => t('Default theme'), + 'Other' => array(), + ); + foreach ($themes as $theme) { + if ($theme->status) { + $theme_list['Other'][$theme->name] = $theme->info['name']; + } + } + $form['css']['css_theme'] = array( + '#type' => 'select', + '#title' => t('Theme'), + '#default_value' => $profile->settings['css_theme'], + '#description' => t("Select which theme's CSS to apply to the editor.
Note: This is only applied when 'Editor CSS' field above is set to 'Use theme CSS'"), + '#options' => $theme_list, + '#states' => array( + 'visible' => array('select[name="css_setting"]' => array('value' => 'theme')), + ), ); $form['css']['css_path'] = array( diff --git a/wysiwyg.module b/wysiwyg.module index 22130ea..6d89f9f 100644 --- a/wysiwyg.module +++ b/wysiwyg.module @@ -638,32 +638,77 @@ function wysiwyg_get_editor_config($profile, $theme) { * This assumes that the content editing area only needs stylesheets defined * for the scope 'theme'. * + * @param $theme + * (optional) The theme to retrieve stylesheets for. Defaults to '' which is + * the current node admin theme. + * * @return * An array containing CSS files, including proper base path. */ -function wysiwyg_get_css() { - static $files; +function wysiwyg_get_css($theme = '') { + $files = drupal_static(__FUNCTION__, array()); - if (isset($files)) { - return $files; + $themes = list_themes(); + if (empty($theme)) { + $theme = variable_get('node_admin_theme') ? variable_get('admin_theme') : variable_get('theme_default', 'bartik'); + } + elseif ($theme == 'wysiwyg_theme_admin' && $admin_theme = variable_get('admin_theme')) { + $theme = $admin_theme; } - // In node form previews, the theme has not been initialized yet. - if (!empty($_POST)) { - drupal_theme_initialize(); + if (!$theme || !isset($themes[$theme])) { + $theme = variable_get('theme_default', 'bartik'); } - $files = array(); - foreach (drupal_add_css() as $filepath => $info) { - if ($info['group'] >= CSS_THEME && $info['media'] != 'print') { - if ($info['type'] == 'external') { - $files[] = $filepath; + if (isset($files[$theme])) { + return $files[$theme]; + } + + $files[$theme] = array(); + $stylesheets = array(); + $themes = list_themes(); + + // Add any base theme css. + if (isset($themes[$theme]->info['base theme'])) { + if (!empty($themes[$themes[$theme]->info['base theme']]->stylesheets)) { + foreach ($themes[$themes[$theme]->info['base theme']]->stylesheets as $media => $media_stylesheet) { + if ($media !== 'print') { + foreach ($media_stylesheet as $stylesheet) { + $stylesheets[] = $stylesheet; + } + } } - elseif (file_exists($filepath)) { - $files[] = base_path() . $filepath; + } + // Add any base theme css set in the 'css' key. + if (!empty($themes[$themes[$theme]->info['base theme']]->info['css'])) { + $theme_path = drupal_get_path('theme', $themes[$theme]->info['base theme']); + foreach($themes[$themes[$theme]->info['base theme']]->info['css'] as $stylesheet => $info) { + $stylesheets[] = $theme_path . '/css/' . $stylesheet; } } } - return $files; + + // Add themes css. + if (isset($themes[$theme]->stylesheets)) { + foreach ($themes[$theme]->stylesheets as $media => $media_stylesheet) { + if ($media !== 'print') { + foreach ($media_stylesheet as $stylesheet) { + $stylesheets[] = $stylesheet; + } + } + } + } + // Add any theme css set in the 'css' key. + if (!empty($themes[$theme]->info['css'])) { + foreach($themes[$theme]->info['css'] as $stylesheet => $info) { + $stylesheets[] = drupal_get_path('theme', $theme) . '/css/' . $stylesheet; + } + } + + foreach ($stylesheets as $path) { + $files[$theme][] = base_path() . $path; + } + + return $files[$theme]; } /**