You are here

function front_page_init in Front Page 6.2

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

Implementation of hook_init().

File

./front_page.module, line 91

Code

function front_page_init() {
  global $_front_page, $conf;

  // If this function is called by PHP CLI (drush), do not do anything.
  if (function_exists('drush_main')) {
    return;
  }

  // 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/settings/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) {
    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;
  }
}