You are here

function availability_calendars_init in Availability Calendars 6

Same name and namespace in other branches
  1. 6.2 availability_calendars.module \availability_calendars_init()
  2. 7.2 availability_calendars.module \availability_calendars_init()

Implementation of hook_init(). Currently just adds our css/js files to pages.

File

./availability_calendars.module, line 16
Availability Calendars Module.

Code

function availability_calendars_init() {

  // css is added to all pages, since blocks will need to make use of it
  // base css
  drupal_add_css(drupal_get_path('module', 'availability_calendars') . '/availability_calendars.css');

  // current theme info
  $theme_data = _system_theme_data();

  // array containing info about all themes
  $theme_key = array_pop(explode('/', path_to_theme()));

  // get the currently enabled theme's namespace, can't find a better way to do this
  $theme = $theme_data[$theme_key];

  // object containing all info about current theme
  $theme_bases = $theme->base_themes;

  // array of current theme's base themes
  // themes we will perform specific theming on
  $core_themes = array(
    'garland',
    'bluemarine',
    'chameleon',
    'marvin',
    'pushbutton',
  );
  $base_themes = array(
    'fusion_core',
    'tao',
    'zen',
    'ninesixty',
  );

  // check to see if we are using a core theme
  if (in_array($theme_key, array_merge($core_themes, $base_themes))) {
    $add_css = TRUE;
  }

  // check whether the theme being used is a subtheme of one of our themed base themes
  foreach ($base_themes as $key) {
    if (is_array($theme_bases)) {
      if (array_key_exists($key, $theme_bases)) {
        $theme_key = $key;

        // if the current theme is a subtheme of one of our base themes then use the base theme's namespace instead of our enabled theme's
        $add_css = TRUE;
        break;
      }
    }
  }
  if ($add_css) {
    drupal_add_css(drupal_get_path('module', 'availability_calendars') . '/css/' . $theme_key . '.css');
  }
}