You are here

function _ckeditor_add_css_from_theme in CKEditor - WYSIWYG HTML editor 7

1 call to _ckeditor_add_css_from_theme()
ckeditor_profile_settings_compile in includes/ckeditor.lib.inc
Compile settings of profile

File

includes/ckeditor.lib.inc, line 1133
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function _ckeditor_add_css_from_theme($current_theme, &$css_files) {
  global $language, $base_theme_info;
  $themes = list_themes();
  $theme_info = $themes[$current_theme];
  if (!empty($theme_info->base_theme)) {
    _ckeditor_add_css_from_theme($theme_info->base_theme, $css_files);
  }
  $query_string = '?' . variable_get('css_js_query_string', '0');
  $host = base_path();
  $themepath = drupal_get_path('theme', $current_theme) . '/';
  $module_drupal_local_path = ckeditor_module_path('local');
  $module_drupal_path = drupal_get_path('module', 'ckeditor');
  if (!empty($theme_info->stylesheets)) {
    $editorcss = "\"";
    foreach ($base_theme_info as $base) {

      // Grab stylesheets from base theme
      if (!empty($base->stylesheets)) {

        // may be empty when the base theme reference in the info file is invalid
        foreach ($base->stylesheets as $type => $stylesheets) {
          if ($type != "print") {
            foreach ($stylesheets as $name => $path) {
              if (file_exists($path)) {
                $css_files[$name] = $host . $path . $query_string;

                // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
                if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
                  $rtl_path = substr($path, 0, -4) . "-rtl.css";
                  if (file_exists($rtl_path)) {
                    $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
                  }
                }
              }
            }
          }
        }
      }
    }
    if (!empty($theme_info->stylesheets)) {

      // Grab stylesheets from current theme
      foreach ($theme_info->stylesheets as $type => $stylesheets) {
        if ($type != "print") {
          foreach ($stylesheets as $name => $path) {

            // Checks if less module exists...
            if (strstr($path, '.less') && module_exists('less')) {
              $path = 'sites/default/files/less/' . $path;

              // append the less file path
              $path = str_replace('.less', '', $path);

              // remove the .less
            }
            if (file_exists($path)) {
              $css_files[$name] = $host . $path . $query_string;

              // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
              if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
                $rtl_path = substr($path, 0, -4) . "-rtl.css";
                if (file_exists($rtl_path)) {
                  $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
                }
              }
            }
            elseif (!empty($css_files[$name])) {
              unset($css_files[$name]);
            }
          }
        }
      }
    }

    // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes)
    if (file_exists($themepath . 'css/local.css')) {
      $css_files[] = $host . $themepath . 'css/local.css' . $query_string;
    }
    if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) {
      $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string;
    }

    // Grab stylesheets from color module
    $color_paths = variable_get('color_' . $current_theme . '_stylesheets', array());
    if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
      if (!empty($color_paths[1])) {
        if (substr($color_paths[0], 0, 9) == 'public://') {
          $css_files[] = file_create_url($color_paths[1]) . $query_string;
        }
        else {
          $css_files[] = $host . $color_paths[1] . $query_string;
        }
      }
    }
    elseif (!empty($color_paths[0])) {
      if (substr($color_paths[0], 0, 9) == 'public://') {
        $css_files[] = file_create_url($color_paths[0]) . $query_string;
      }
      else {
        $css_files[] = $host . $color_paths[0] . $query_string;
      }
    }
  }
  else {
    if (!file_exists($themepath . 'ckeditor.css') && file_exists($themepath . 'style.css')) {
      $css_files[] = $host . $themepath . 'style.css' . $query_string;
    }
  }
  if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
    $css_files[] = $host . $module_drupal_path . '/css/ckeditor.css' . $query_string;
  }
  if (file_exists($themepath . 'ckeditor.css')) {
    $css_files[] = $host . $themepath . 'ckeditor.css' . $query_string;
  }
}