diff --git a/editors/ckeditor.inc b/editors/ckeditor.inc index de9f65b..3cf14b0 100644 --- a/editors/ckeditor.inc +++ b/editors/ckeditor.inc @@ -386,8 +386,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') { - $css = wysiwyg_get_css(); - $settings['contentsCss'] = reset($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)))); @@ -395,7 +395,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 68c2f98..199faf6 100644 --- a/editors/fckeditor.inc +++ b/editors/fckeditor.inc @@ -197,7 +197,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 5aae0ed..0c3404a 100644 --- a/editors/openwysiwyg.inc +++ b/editors/openwysiwyg.inc @@ -124,8 +124,8 @@ function wysiwyg_openwysiwyg_settings($editor, $config, $theme) { if (isset($config['css_setting'])) { if ($config['css_setting'] == 'theme') { - $css = wysiwyg_get_css(); - $settings['CSSFile'] = reset($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)))); diff --git a/editors/tinymce.inc b/editors/tinymce.inc index 81bc2b6..6dc96bf 100644 --- a/editors/tinymce.inc +++ b/editors/tinymce.inc @@ -367,7 +367,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 d317d26..2da5252 100644 --- a/editors/wymeditor.inc +++ b/editors/wymeditor.inc @@ -202,8 +202,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 db952b6..1eb26d7 100644 --- a/editors/yui.inc +++ b/editors/yui.inc @@ -238,7 +238,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 5b24943..00a4650 100644 --- a/wysiwyg.admin.inc +++ b/wysiwyg.admin.inc @@ -27,6 +27,7 @@ function wysiwyg_profile_form($form, &$form_state, $profile) { 'language' => 'en', 'buttons' => array(), 'css_setting' => 'theme', + 'css_theme' => variable_get('node_admin_theme') ? variable_get('admin_theme') : variable_get('theme_default', 'bartik'), 'css_path' => NULL, ); $profile = (object) $profile; @@ -171,7 +172,31 @@ function wysiwyg_profile_form($form, &$form_state, $profile) { '#title' => t('Editor CSS'), '#default_value' => $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('Active theme'), + 'wysiwyg_theme_admin' => t('Admin theme'), + 'wysiwyg_theme_default' => t('Default theme'), + // Set an optgroup 'Other'. + t('Other') => array(), + ); + foreach ($themes as $theme) { + if ($theme->status) { + $theme_list[t('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 02756ce..0c9a09e 100644 --- a/wysiwyg.module +++ b/wysiwyg.module @@ -680,27 +680,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['type'] != 'inline' && $info['media'] != 'print') { - $files[] = file_create_url($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; + } + } + } + } + // 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][] = file_create_url($path); + } + + return $files[$theme]; } /**