| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Maintenance page preprocessing |
| 5 | */ |
| 6 | function fusion_core_preprocess_maintenance_page(&$vars) { |
| 7 | if (class_exists('Database', FALSE)) { |
| 8 | // set html vars (html.tpl.php is in maintenance-page.tpl.php) |
| 9 | fusion_core_preprocess_html($vars); |
| 10 | // set page vars |
| 11 | fusion_core_preprocess_page($vars); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * HTML preprocessing |
| 18 | */ |
| 19 | function fusion_core_preprocess_html(&$vars) { |
| 20 | global $theme_key, $user; |
| 21 | |
| 22 | // Add to array of helpful body classes. |
| 23 | if (isset($vars['node'])) { |
| 24 | // For full nodes. |
| 25 | $vars['classes_array'][] = ($vars['node']) ? 'full-node' : ''; |
| 26 | // For forums. |
| 27 | $vars['classes_array'][] = (($vars['node']->type == 'forum') || (arg(0) == 'forum')) ? 'forum' : ''; |
| 28 | } |
| 29 | else { |
| 30 | // Forums. |
| 31 | $vars['classes_array'][] = (arg(0) == 'forum') ? 'forum' : ''; |
| 32 | } |
| 33 | if (module_exists('panels') && function_exists('panels_get_current_page_display')) { |
| 34 | $vars['classes_array'][] = (panels_get_current_page_display()) ? 'panels' : ''; |
| 35 | } |
| 36 | $vars['classes_array'][] = theme_get_setting('sidebar_layout'); |
| 37 | $vars['classes_array'][] = (theme_get_setting('theme_font') != 'none') ? theme_get_setting('theme_font') : ''; |
| 38 | $vars['classes_array'][] = theme_get_setting('theme_font_size'); |
| 39 | $vars['classes_array'][] = (user_access('administer blocks', $user) && theme_get_setting('grid_mask')) ? 'grid-mask-enabled' : ''; |
| 40 | |
| 41 | // Add grid classes |
| 42 | $grid = fusion_core_grid_info(); |
| 43 | |
| 44 | // Fixed or fluid. |
| 45 | $vars['classes_array'][] = 'grid-type-' . $grid['type']; |
| 46 | |
| 47 | // Number of units in the grid (12, 16, etc.) |
| 48 | $vars['classes_array'][] = 'grid-width-' . sprintf("%02d", $grid['width']); |
| 49 | |
| 50 | // Fluid grid width in %. |
| 51 | $vars['classes_array'][] = ($grid['type'] == 'fluid') ? theme_get_setting('fluid_grid_width') : ''; |
| 52 | |
| 53 | // Remove any empty elements in the array. |
| 54 | $vars['classes_array'] = array_filter($vars['classes_array']); |
| 55 | |
| 56 | // Add a unique page id. |
| 57 | $vars['body_id'] = 'pid-' . drupal_clean_css_identifier(drupal_get_path_alias($_GET['q'])); |
| 58 | |
| 59 | // Add grid & local stylesheets, including versions inherited from parent themes |
| 60 | $themes = fusion_core_theme_paths($theme_key); |
| 61 | foreach ($themes as $name => $path) { |
| 62 | $file = theme_get_setting('theme_grid') . '.css'; |
| 63 | if (file_exists($path . '/css/' . $file)) { |
| 64 | drupal_add_css($path . '/css/' . $file, array('basename' => $name . '-' . $file, 'group' => CSS_THEME, 'preprocess' => TRUE)); |
| 65 | } |
| 66 | if (file_exists($path . '/css/local.css')) { |
| 67 | drupal_add_css($path . '/css/local.css', array('basename' => $name . '-local.css', 'group' => CSS_THEME, 'preprocess' => TRUE)); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * Page preprocessing |
| 75 | */ |
| 76 | function fusion_core_preprocess_page(&$vars) { |
| 77 | // Set grid width |
| 78 | $grid = fusion_core_grid_info(); |
| 79 | $vars['grid_width'] = $grid['name'] . $grid['width']; |
| 80 | |
| 81 | // Adjust width variables for nested grid groups |
| 82 | $grid_adjusted_groups = (theme_get_setting('grid_adjusted_groups')) ? theme_get_setting('grid_adjusted_groups') : array(); |
| 83 | foreach (array_keys($grid_adjusted_groups) as $group) { |
| 84 | $width = $grid['width']; |
| 85 | foreach ($grid_adjusted_groups[$group] as $region) { |
| 86 | $width = $width - $grid['regions'][$region]['width']; |
| 87 | } |
| 88 | if (!$grid['fixed'] && isset($grid['fluid_adjustments'][$group])) { |
| 89 | $vars[$group . '_width'] = '" style="width:' . $grid['fluid_adjustments'][$group] . '%"'; |
| 90 | } |
| 91 | else { |
| 92 | $vars[$group . '_width'] = $grid['name'] . $width; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Remove breadcrumbs if disabled |
| 97 | if (theme_get_setting('breadcrumb_display') == 0) { |
| 98 | $vars['breadcrumb'] = ''; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * Region preprocessing |
| 105 | */ |
| 106 | function fusion_core_preprocess_region(&$vars) { |
| 107 | static $grid; |
| 108 | |
| 109 | // Initialize grid info once per page |
| 110 | if (!isset($grid)) { |
| 111 | $grid = fusion_core_grid_info(); |
| 112 | } |
| 113 | |
| 114 | // Set region variables |
| 115 | $vars['region_style'] = $vars['fluid_width'] = ''; |
| 116 | $vars['region_name'] = str_replace('_', '-', $vars['region']); |
| 117 | $vars['classes_array'][] = $vars['region_name']; |
| 118 | if (in_array($vars['region'], array_keys($grid['regions']))) { |
| 119 | // Set region full-width or nested style |
| 120 | $vars['region_style'] = $grid['regions'][$vars['region']]['style']; |
| 121 | $vars['classes_array'][] = ($vars['region_style'] == 'nested') ? $vars['region_style'] : ''; |
| 122 | $vars['classes_array'][] = $grid['name'] . $grid['regions'][$vars['region']]['width']; |
| 123 | // Adjust & set region width |
| 124 | if (!$grid['fixed'] && isset($grid['fluid_adjustments'][$vars['region']])) { |
| 125 | $vars['fluid_width'] = ' style="width:' . $grid['fluid_adjustments'][$vars['region']] . '%"'; |
| 126 | } |
| 127 | } |
| 128 | // Sidebar regions receive common class, "sidebar". |
| 129 | $sidebar_regions = array('sidebar_first', 'sidebar_second'); |
| 130 | if (in_array($vars['region'], $sidebar_regions)) { |
| 131 | $vars['classes_array'][] = 'sidebar'; |
| 132 | } |
| 133 | |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /** |
| 138 | * Block preprocessing |
| 139 | */ |
| 140 | function fusion_core_preprocess_block(&$vars) { |
| 141 | global $theme_info, $user; |
| 142 | static $grid; |
| 143 | |
| 144 | // Exit if block is outside a defined region |
| 145 | if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | // Initialize grid info once per page |
| 150 | if (!isset($grid)) { |
| 151 | $grid = fusion_core_grid_info(); |
| 152 | } |
| 153 | |
| 154 | // Increment block count for current block's region, add first/last position class |
| 155 | $grid['regions'][$vars['block']->region]['count'] ++; |
| 156 | $region_count = $grid['regions'][$vars['block']->region]['count']; |
| 157 | $total_blocks = $grid['regions'][$vars['block']->region]['total']; |
| 158 | $vars['classes_array'][] = ($region_count == 1) ? 'first' : ''; |
| 159 | $vars['classes_array'][] = ($region_count == $total_blocks) ? 'last' : ''; |
| 160 | $vars['classes_array'][] = $vars['block_zebra']; |
| 161 | |
| 162 | // Set a default block width if not already set by Fusion Apply |
| 163 | $classes = implode(' ', $vars['classes_array']); |
| 164 | |
| 165 | // Special treatment for node_top and node_bottom regions. |
| 166 | // They are rendered inside of the $content region, so they need to be adjusted to fit the grid properly. |
| 167 | $assign_grid_units = ($vars['block']->region == 'node_top' || $vars['block']->region == 'node_bottom') ? FALSE : TRUE; |
| 168 | |
| 169 | if (strpos($classes, $grid['name']) === FALSE && $assign_grid_units) { |
| 170 | // Stack blocks vertically in sidebars by setting to full sidebar width |
| 171 | if ($vars['block']->region == 'sidebar_first') { |
| 172 | $width = $grid['fixed'] ? $grid['sidebar_first_width'] : $grid['width']; // Sidebar width or 100% (if fluid) |
| 173 | } |
| 174 | elseif ($vars['block']->region == 'sidebar_second') { |
| 175 | $width = $grid['fixed'] ? $grid['sidebar_second_width'] : $grid['width']; // Sidebar width or 100% (if fluid) |
| 176 | } |
| 177 | else { |
| 178 | // Default block width = region width divided by total blocks, adding any extra width to last block |
| 179 | $region_width = ($grid['fixed']) ? $grid['regions'][$vars['block']->region]['width'] : $grid['width']; // fluid grid regions = 100% |
| 180 | $width_adjust = (($region_count == $total_blocks) && ($region_width % $total_blocks)) ? $region_width % $total_blocks : 0; |
| 181 | $width = ($total_blocks) ? floor($region_width / $total_blocks) + $width_adjust : 0; |
| 182 | } |
| 183 | $vars['classes_array'][] = $grid['name'] . $width; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /** |
| 189 | * Node preprocessing |
| 190 | */ |
| 191 | function fusion_core_preprocess_node(&$vars) { |
| 192 | // Add to array of handy node classes |
| 193 | $vars['classes_array'][] = $vars['zebra']; // Node is odd or even |
| 194 | $vars['classes_array'][] = (!$vars['teaser']) ? 'full-node' : ''; // Node is teaser or full-node |
| 195 | |
| 196 | if ($vars['submitted'] && !$vars['teaser']) { |
| 197 | $vars['submitted'] = t('This page was last updated on !datetime', array( '!datetime' => format_date($vars['node']->changed, 'custom', 'F j, Y'))); |
| 198 | } |
| 199 | |
| 200 | $node_region_list = array('node_top', 'node_bottom'); |
| 201 | $node_region_blocks = array(); |
| 202 | foreach($node_region_list as $region) { |
| 203 | if ($list = fusion_core_block_list($region)) { |
| 204 | $node_region_blocks[$region] = _block_get_renderable_array($list); |
| 205 | } |
| 206 | $vars[$region] = isset($node_region_blocks[$region]) ? $node_region_blocks[$region] : array(); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | /** |
| 212 | * Comment preprocessing |
| 213 | */ |
| 214 | function fusion_core_preprocess_comment(&$vars) { |
| 215 | static $comment_odd = TRUE; // Comment is odd or even |
| 216 | |
| 217 | // Add to array of handy comment classes |
| 218 | $vars['classes_array'][] = $comment_odd ? 'odd' : 'even'; |
| 219 | $comment_odd = !$comment_odd; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /** |
| 224 | * Views preprocessing |
| 225 | * Add view type class (e.g., node, teaser, list, table) |
| 226 | */ |
| 227 | function fusion_core_preprocess_views_view(&$vars) { |
| 228 | $vars['css_name'] = $vars['css_name'] .' view-style-'. drupal_clean_css_identifier(strtolower($vars['view']->plugin_name)); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /** |
| 233 | * Search result preprocessing |
| 234 | */ |
| 235 | function fusion_core_preprocess_search_result(&$vars) { |
| 236 | static $search_zebra = 'even'; |
| 237 | |
| 238 | $search_zebra = ($search_zebra == 'even') ? 'odd' : 'even'; |
| 239 | $vars['search_zebra'] = $search_zebra; |
| 240 | $result = $vars['result']; |
| 241 | $vars['url'] = check_url($result['link']); |
| 242 | $vars['title'] = check_plain($result['title']); |
| 243 | |
| 244 | // Check for snippet existence. User search does not include snippets. |
| 245 | $vars['snippet'] = ''; |
| 246 | if (isset($result['snippet']) && theme_get_setting('search_snippet')) { |
| 247 | $vars['snippet'] = $result['snippet']; |
| 248 | } |
| 249 | |
| 250 | $info = array(); |
| 251 | if (!empty($result['type']) && theme_get_setting('search_info_type')) { |
| 252 | $info['type'] = check_plain($result['type']); |
| 253 | } |
| 254 | if (!empty($result['user']) && theme_get_setting('search_info_user')) { |
| 255 | $info['user'] = $result['user']; |
| 256 | } |
| 257 | if (!empty($result['date']) && theme_get_setting('search_info_date')) { |
| 258 | $info['date'] = format_date($result['date'], 'small'); |
| 259 | } |
| 260 | if (isset($result['extra']) && is_array($result['extra'])) { |
| 261 | // $info = array_merge($info, $result['extra']); Drupal bug? [extra] array not keyed with 'comment' & 'upload' |
| 262 | if (!empty($result['extra'][0]) && theme_get_setting('search_info_comment')) { |
| 263 | $info['comment'] = $result['extra'][0]; |
| 264 | } |
| 265 | if (!empty($result['extra'][1]) && theme_get_setting('search_info_upload')) { |
| 266 | $info['upload'] = $result['extra'][1]; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // Provide separated and grouped meta information. |
| 271 | $vars['info_split'] = $info; |
| 272 | $vars['info'] = implode(' - ', $info); |
| 273 | |
| 274 | // Provide alternate search result template. |
| 275 | $vars['template_files'][] = 'search-result-'. $vars['module']; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | /** |
| 280 | * Header region override |
| 281 | * Prints header blocks without region wrappers |
| 282 | */ |
| 283 | function fusion_core_region__header($vars) { |
| 284 | return $vars['content']; |
| 285 | } |
| 286 | |
| 287 | |
| 288 | /** |
| 289 | * File element override |
| 290 | * Sets form file input max width |
| 291 | */ |
| 292 | function fusion_core_file($vars) { |
| 293 | $vars['element']['#size'] = ($vars['element']['#size'] > 40) ? 40 : $vars['element']['#size']; |
| 294 | return theme_file($vars); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /** |
| 299 | * Custom theme functions |
| 300 | */ |
| 301 | function fusion_core_theme() { |
| 302 | return array( |
| 303 | 'grid_block' => array( |
| 304 | 'variables' => array('content' => NULL, 'id' => NULL), |
| 305 | ), |
| 306 | ); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Returns a list of blocks. |
| 311 | * Uses Drupal block interface and appends any blocks assigned by the Context module. |
| 312 | */ |
| 313 | function fusion_core_block_list($region) { |
| 314 | $drupal_list = array(); |
| 315 | if (module_exists('block')) { |
| 316 | $drupal_list = block_list($region); |
| 317 | } |
| 318 | if (module_exists('context') && $context = context_get_plugin('reaction', 'block')) { |
| 319 | $context_list = $context->block_list($region); |
| 320 | $drupal_list = array_merge($context_list, $drupal_list); |
| 321 | } |
| 322 | return $drupal_list; |
| 323 | } |
| 324 | |
| 325 | function fusion_core_grid_block($vars) { |
| 326 | $output = ''; |
| 327 | if ($vars['content']) { |
| 328 | $id = $vars['id']; |
| 329 | $output .= '<div id="' . $id . '" class="' . $id . ' block">' . "\n"; |
| 330 | $output .= '<div id="' . $id . '-inner" class="' . $id . '-inner gutter">' . "\n"; |
| 331 | $output .= $vars['content']; |
| 332 | $output .= '</div><!-- /' . $id . '-inner -->' . "\n"; |
| 333 | $output .= '</div><!-- /' . $id . ' -->' . "\n"; |
| 334 | } |
| 335 | return $output; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /** |
| 340 | * Generate initial grid info |
| 341 | */ |
| 342 | function fusion_core_grid_info() { |
| 343 | global $theme_key; |
| 344 | static $grid; |
| 345 | |
| 346 | if (!isset($grid)) { |
| 347 | $grid = array(); |
| 348 | $grid['name'] = substr(theme_get_setting('theme_grid'), 0, 7); |
| 349 | $grid['type'] = substr(theme_get_setting('theme_grid'), 7); |
| 350 | $grid['fixed'] = (substr(theme_get_setting('theme_grid'), 7) != 'fluid') ? TRUE : FALSE; |
| 351 | $grid['width'] = (int)substr($grid['name'], 4, 2); |
| 352 | $grid['sidebar_first_width'] = (fusion_core_block_list('sidebar_first')) ? theme_get_setting('sidebar_first_width') : 0; |
| 353 | $grid['sidebar_second_width'] = (fusion_core_block_list('sidebar_second')) ? theme_get_setting('sidebar_second_width') : 0; |
| 354 | $grid['regions'] = array(); |
| 355 | $regions = array_keys(system_region_list($theme_key, REGIONS_VISIBLE)); |
| 356 | $nested_regions = theme_get_setting('grid_nested_regions'); |
| 357 | $adjusted_regions = theme_get_setting('grid_adjusted_regions'); |
| 358 | foreach ($regions as $region) { |
| 359 | $region_style = 'full-width'; |
| 360 | $region_width = $grid['width']; |
| 361 | if ($region == 'sidebar_first' || $region == 'sidebar_second') { |
| 362 | $region_width = ($region == 'sidebar_first') ? $grid['sidebar_first_width'] : $grid['sidebar_second_width']; |
| 363 | } |
| 364 | if ($nested_regions && in_array($region, $nested_regions)) { |
| 365 | $region_style = 'nested'; |
| 366 | if ($adjusted_regions && in_array($region, array_keys($adjusted_regions))) { |
| 367 | foreach ($adjusted_regions[$region] as $adjacent_region) { |
| 368 | $region_width = $region_width - $grid[$adjacent_region . '_width']; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | $grid['regions'][$region] = array('width' => $region_width, 'style' => $region_style, 'total' => count(fusion_core_block_list($region)), 'count' => 0); |
| 373 | } |
| 374 | |
| 375 | // Adjustments for fluid width regions & groups |
| 376 | $grid['fluid_adjustments'] = array(); |
| 377 | // Regions |
| 378 | $adjusted_regions_fluid = (theme_get_setting('grid_adjusted_regions_fluid')) ? theme_get_setting('grid_adjusted_regions_fluid') : array(); |
| 379 | foreach (array_keys($adjusted_regions_fluid) as $adjusted_region) { |
| 380 | $width = $grid['width']; |
| 381 | foreach ($adjusted_regions_fluid[$adjusted_region] as $region) { |
| 382 | $width = $width - $grid['regions'][$region]['width']; // Subtract regions outside parent group to get correct parent width |
| 383 | } |
| 384 | $grid['fluid_adjustments'][$adjusted_region] = round(($grid['regions'][$adjusted_region]['width'] / $width) * 100, 2); |
| 385 | } |
| 386 | // Groups |
| 387 | $adjusted_groups_fluid = (theme_get_setting('grid_adjusted_groups_fluid')) ? theme_get_setting('grid_adjusted_groups_fluid') : array(); |
| 388 | foreach (array_keys($adjusted_groups_fluid) as $adjusted_group) { |
| 389 | $width = 100; |
| 390 | foreach ($adjusted_groups_fluid[$adjusted_group] as $region) { |
| 391 | $width = $width - $grid['fluid_adjustments'][$region]; // Subtract previously calculated sibling region fluid adjustments |
| 392 | } |
| 393 | $grid['fluid_adjustments'][$adjusted_group] = $width; // Group gets remaining width |
| 394 | } |
| 395 | } |
| 396 | return $grid; |
| 397 | } |
| 398 | |
| 399 | |
| 400 | /** |
| 401 | * Theme paths function |
| 402 | * Retrieves parent and current theme paths in parent-to-current order. |
| 403 | */ |
| 404 | function fusion_core_theme_paths($theme) { |
| 405 | $base_themes = system_find_base_themes(list_themes(), $theme); |
| 406 | foreach ($base_themes as $key => $base_theme) { |
| 407 | $base_themes[$key] = drupal_get_path('theme', $key); // Base theme paths |
| 408 | } |
| 409 | $base_themes[$theme] = drupal_get_path('theme', $theme); // Current theme path |
| 410 | return $base_themes; |
| 411 | } |