You are here

function front_page_init in Front Page 7.2

Same name and namespace in other branches
  1. 6.2 front_page.module \front_page_init()

Implements hook_init().

File

./front_page.module, line 99

Code

function front_page_init() {

  // Make sure front page module is not run when using cli (drush).
  // Make sur front page module does not run when installing Drupal either.
  if (drupal_is_cli() || drupal_installation_attempted()) {
    return;
  }

  // Don't run when site is in maintenance mode
  if (variable_get('maintenance_mode', 0)) {
    return;
  }

  // Ignore non index.php requests (like cron)
  if (!empty($_SERVER['SCRIPT_FILENAME']) && realpath(DRUPAL_ROOT . '/index.php') != realpath($_SERVER['SCRIPT_FILENAME'])) {
    return;
  }
  global $_front_page, $conf;

  // let administrator know that there is a config error.
  if (variable_get('site_frontpage', '') == 'front_page' && user_access('administer menu')) {
    drupal_set_message(t('There is a configuration error. The home page should not be set to the path "front_page". Please change this !link', array(
      '!link' => l(t('here'), 'admin/config/system/site-information'),
    )), 'error');
  }
  if (variable_get('front_page_enable', 0) && drupal_is_front_page()) {
    $_front_page = front_page_get_by_role();
  }
  if (user_access('administer menu') && preg_match('@^front_page/preview/([0-9]+)$@', $_GET['q'], $match)) {
    $_front_page = front_page_get_by_rid($match[1]);
  }
  if ($_front_page) {

    // Let other hooks modify
    drupal_alter('front_page', $_front_page);
    switch ($_front_page['mode']) {
      case 'themed':
      case 'full':
        $_GET['q'] = 'front_page';

        // need to set variable site_frontpage to current path so that it thinks it is the front page.
        $conf['site_frontpage'] = $_GET['q'];
        break;
      case 'redirect':
        $url = front_page_parse_url($_front_page['data']);
        drupal_goto($url['path'], $url['options']);
        break;
      case 'alias':
        $url = front_page_parse_url($_front_page['data']);
        $_GET['q'] = drupal_get_normal_path($url['path']);

        // need to set variable site_frontpage to current path so that it thinks it is the front page.
        $conf['site_frontpage'] = $_GET['q'];
        break;
    }

    // turn caching off for this page as it is dependant on role.
    $GLOBALS['conf']['cache'] = FALSE;
  }
}