You are here

function quickbar_init in Quickbar 7

Same name and namespace in other branches
  1. 6 quickbar.module \quickbar_init()
  2. 7.2 quickbar.module \quickbar_init()

Implements hook_init().

File

./quickbar.module, line 6

Code

function quickbar_init() {

  // Make sure quickbar should be used.
  if (quickbar_is_enabled()) {

    // Declare initial variables.
    global $user;

    // Get the user roles
    $roles = user_roles();
    if (is_array($roles)) {

      // Sort roles
      asort($roles);

      // Get some variables we might use
      $use_machine_names = variable_get('quickbar_use_machine_names', 0);
      if ($use_machine_names) {
        $machine_roles = _quickbar_role_machine_names($roles);
      }
      $role_weights = variable_get('quickbar_role_weights', array());
      $menus = variable_get('quickbar_role_menus', array());

      // Loop through the roles looking for a role that matches the current users
      // role and also has a menu associated with it.
      foreach ($role_weights as $rid => $weight) {
        $user_role_index = $use_machine_names ? array_search($machine_roles[$rid], $roles) : $rid;
        if (!empty($user->roles[$user_role_index]) && isset($menus[$rid])) {
          $settings = variable_get('quickbar_settings_' . $rid, _quickbar_default_settings());
          $path = drupal_get_path('module', 'quickbar');
          drupal_add_js($path . '/js/quickbar.js');
          drupal_add_js(array(
            'quickbar' => array(
              'secondary_menu_visibility' => $settings['secondary_menu_visibility'],
            ),
          ), 'setting');
          drupal_add_css($path . '/theme/quickbar.css');

          // Add the iconset
          if ($settings['iconset'] != '_none') {
            $iconsets = module_invoke_all('quickbar_iconset_info');
            drupal_add_css($iconsets[$settings['iconset']]['css']);
          }
          break;
        }
      }
    }
  }
}