function quickbar_extras_preprocess_quickbar in Quickbar 7.2
Same name and namespace in other branches
- 6 modules/quickbar_extras/quickbar_extras.module \quickbar_extras_preprocess_quickbar()
Implements hook_preprocess_quickbar().
File
- modules/
quickbar_extras/ quickbar_extras.module, line 133
Code
function quickbar_extras_preprocess_quickbar(&$vars) {
global $user;
$role_weights = variable_get('quickbar_role_weights', '');
$settings = array();
if (is_array($role_weights)) {
// Sort roles
asort($role_weights);
// Get the user roles
$roles = user_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);
}
// 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]) && ($settings = variable_get('quickbar_extras_settings_' . $rid, array()))) {
break;
}
}
}
$menu_keys = array_keys($vars['tree'][0]['admin']);
if (!empty($settings['menu'])) {
$move_menus = array();
// We are first going to pull all of the menu ids out of the variable...
foreach ($settings['menu'] as $menu_id => $position) {
// ... if the current menu id being checked has a value of 'right'...
if ($position == 'right') {
// ... then we need to look in the menu items getting ready to be displayed...
foreach ($menu_keys as $menu_key) {
$menu_class = explode(' ', $menu_key);
$menu_id = str_replace('mlid_', '', $menu_id);
// ... if there is a match, add it to our move_menu array for further processing
if ($menu_class[0] == 'menu-' . $menu_id) {
$move_menus[] = $menu_key;
}
}
}
}
if (!empty($move_menus)) {
foreach ($move_menus as $move_menu) {
$vars['tree'][0]['right'][$move_menu] = $vars['tree'][0]['admin'][$move_menu];
unset($vars['tree'][0]['admin'][$move_menu]);
}
}
if (!empty($settings['show_username'])) {
global $user;
$username_prefix = isset($settings['show_username_prefix']) ? $settings['show_username_prefix'] : 'Hello, ';
$username_suffix = isset($settings['show_username_suffix']) ? $settings['show_username_suffix'] : '!';
if ($settings['show_username_link']) {
$vars['tree'][0]['right']['username'] = array(
'title' => $username_prefix . l($user->name, 'user/' . $user->uid, array(
'attributes' => array(
'class' => array(
'username-link',
),
),
)) . $username_suffix,
'html' => 1,
);
}
else {
$vars['tree'][0]['right']['username'] = array(
'title' => $username_prefix . $user->name . $username_suffix,
);
}
}
}
}