Preprocess variables for page.tpl.php

/**
 * Preprocess variables for page.tpl.php
 *
 * @see page.tpl.php
 */
function twitter_bootstrap_preprocess_page(&$variables) {

  // We want to allow the theme to use copies of the bootstrap framework that're
  // installed in sites/all/libraries. Start with a few vars for figuring out
  // the library location:
  $current_directory = getcwd();
  $base_path = base_path();
  $path_to_twitter_bootstrap = drupal_get_path('theme', 'twitter_bootstrap');
  // The fallback path to the bootstrap library is here, in the theme:
  $bootstrap_theme_path = $current_directory . $base_path . drupal_get_path('theme', 'twitter_bootstrap') . '/bootstrap';
  // But if the library module exists, we might find it elsewhere (and we'd
  // prefer to use that one):
  if (module_exists('libraries') && $path = libraries_get_path('bootstrap')) {
    // If the libraries module exists, here's one possiblity:
    $bootstrap_library_path = $current_directory . $base_path . $path;
  }
  // Decide which--if either--to use:
  if (isset($bootstrap_library_path) && is_dir($bootstrap_library_path)) {
    $bootstrap_path = $path;
  }
  elseif (is_dir($bootstrap_theme_path)) {
    $bootstrap_path = $path_to_twitter_bootstrap;
  }
  // If it's just not available, display a message to the user:
  else {
    drupal_set_message(t('The Bootstrap framework could not be found. In order to use the BH Bootstrap theme, you must download the framework from !bootstrap-url, and extract it to <em>sites/all/libraries/bootstrap</em> (if the !libraries-module is installed) or to %bootstrap-theme-path.', array('!bootstrap-url' => l(t('the Bootstrap project page'), 'http://twitter.github.com/bootstrap/'), '!libraries-module' => l(t('7.x-1.x version of the Libraries module'), 'http://drupal.org/project/libraries'), '%bootstrap-theme-path' => $path_to_twitter_bootstrap . '/bootstrap')), 'error');
  }

  // CSS
  drupal_add_css($bootstrap_path . '/css/bootstrap.css', array('media' => 'all'));
  drupal_add_css($bootstrap_path . '/css/bootstrap-responsive.css', array('media' => 'screen'));
  // JS
  drupal_add_js($bootstrap_path . '/js/bootstrap.min.js', array('scope' => 'footer'));

你可能感兴趣的:(Preprocess variables for page.tpl.php)