/** * Block preprocessing */ function fusion_core_preprocess_block(&$vars) { global $theme_info, $user; static $regions, $sidebar_first_width, $sidebar_last_width, $grid_name, $grid_width, $grid_fixed; // Initialize position to avoid notice if function returns. $vars['position'] = ''; // Do not process blocks outside defined regions if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) { return; } // Initialize block region grid info once per page if (!isset($regions)) { $grid_name = substr(theme_get_setting('theme_grid'), 0, 7); $grid_width = (int) substr($grid_name, 4, 2); $grid_fixed = substr(theme_get_setting('theme_grid'), 7) != 'fluid' ? 1 : 0; $sidebar_first_width = block_list('sidebar_first') ? theme_get_setting('sidebar_first_width') : 0; $sidebar_last_width = block_list('sidebar_last') ? theme_get_setting('sidebar_last_width') : 0; $regions = fusion_core_set_regions($grid_width, $sidebar_first_width, $sidebar_last_width); } // Increment block count for current block's region, add first/last position class $regions[$vars['block']->region]['count']++; $region_count = $regions[$vars['block']->region]['count']; $total_blocks = $regions[$vars['block']->region]['total']; $vars['position'] = $region_count == 1 ? 'first' : ''; $vars['position'] .= $region_count == $total_blocks ? ' last' : ''; // Set a default block width if not already set by Skinr if (!isset($vars['skinr']) || strpos($vars['skinr'], $grid_name) === false) { // Stack blocks vertically in sidebars by setting to full sidebar width if ($vars['block']->region == 'sidebar_first') { $width = $grid_fixed ? $sidebar_first_width : $grid_width; // Sidebar width or 100% (if fluid) } elseif ($vars['block']->region == 'sidebar_last') { $width = $grid_fixed ? $sidebar_last_width : $grid_width; // Sidebar width or 100% (if fluid) } else { // Default block width = region width divided by total blocks, adding any extra width to last block $region_width = $grid_fixed ? $regions[$vars['block']->region]['width'] : $grid_width; // fluid grid regions = 100% $width_adjust = $region_count == $total_blocks && $region_width % $total_blocks ? $region_width % $total_blocks : 0; $width = $total_blocks ? floor($region_width / $total_blocks) + $width_adjust : 0; } $vars['skinr'] = isset($vars['skinr']) ? $vars['skinr'] . ' ' . $grid_name . $width : $grid_name . $width; } if (isset($vars['skinr']) && strpos($vars['skinr'], 'superfish') !== false && ($vars['block']->module == 'menu' || $vars['block']->module == 'user' && $vars['block']->delta == 1)) { $superfish = ' sf-menu'; $superfish .= strpos($vars['skinr'], 'superfish-vertical') ? ' sf-vertical' : ''; $vars['block']->content = preg_replace('/<ul class="menu/i', '<ul class="menu' . $superfish, $vars['block']->content, 1); } // Add block edit links for admins if (user_access('administer blocks', $user) && theme_get_setting('block_config_link')) { $vars['edit_links'] = '<div class="fusion-edit">' . implode(' ', fusion_core_edit_links($vars['block'])) . '</div>'; } }
/** * Block preprocessing */ function fusion_core_preprocess_block(&$vars) { global $theme_info, $user; static $regions, $sidebar_first_width, $sidebar_last_width, $grid_name, $grid_width, $grid_fixed; // Initialize block region grid info once per page if (!isset($regions)) { $sidebar_first_width = $sidebar_last_width = 0; if (block_list('sidebar_first')) { $sidebar_first_width = isset($theme_info->info['settings']['sidebar-first-width']) ? $theme_info->info['settings']['sidebar-first-width'] : 3; $sidebar_first_width = theme_get_setting('sidebar_first_width') > 0 ? theme_get_setting('sidebar_first_width') : $sidebar_first_width; } if (block_list('sidebar_last')) { $sidebar_last_width = isset($theme_info->info['settings']['sidebar-last-width']) ? $theme_info->info['settings']['sidebar-last-width'] : 3; $sidebar_last_width = theme_get_setting('sidebar_last_width') > 0 ? theme_get_setting('sidebar_last_width') : $sidebar_last_width; } $grid_name = substr(theme_get_setting('theme_grid'), 0, 7); $grid_width = (int) substr($grid_name, 4, 2); $grid_fixed = substr(theme_get_setting('theme_grid'), 7) != 'fluid' ? 1 : 0; $regions = fusion_core_set_regions($grid_width, $sidebar_first_width, $sidebar_last_width); } // Increment block count for current block's region, add first/last position class $regions[$vars['block']->region]['count']++; $region_count = $regions[$vars['block']->region]['count']; $total_blocks = $regions[$vars['block']->region]['total']; $vars['position'] = $region_count == 1 ? 'first' : ''; $vars['position'] .= $region_count == $total_blocks ? ' last' : ''; // Set a default block width if not already set by Skinr if (!isset($vars['skinr']) || strpos($vars['skinr'], $grid_name) === false) { // Stack blocks vertically in sidebars by setting to full sidebar width if ($vars['block']->region == 'sidebar_first') { $width = $sidebar_first_width; } elseif ($vars['block']->region == 'sidebar_last') { $width = $sidebar_last_width; } else { // Default block width = region width divided by total blocks, adding any extra width to last block $region_width = $grid_fixed ? $regions[$vars['block']->region]['width'] : $grid_width; // fluid grid regions = 100% $width_adjust = $region_count == $total_blocks && $region_width % $total_blocks ? $region_width % $total_blocks : 0; $width = $total_blocks ? floor($region_width / $total_blocks) + $width_adjust : 0; } $vars['skinr'] .= ' ' . $grid_name . $width; } // Add block edit links for admins if (user_access('administer blocks', $user) && theme_get_setting('block_config_link')) { $vars['edit_links'] = '<div class="fusion-edit">' . implode(' ', fusion_core_edit_links($vars['block'])) . '</div>'; } }