You are here

front_page.module in Front Page 6.2

File

front_page.module
View source
<?php

/**
 *
 * This module allows the site admin to set advanced front page settings.
 *
 * This version works with Drupal 6. Module information can be found at http://drupal.org/project/front.
 *
 * This module version was developed by timhilliard and various members of the drupal community.
 *
 * If you have any ideas/patches or requests, please post them at http://drupal.org/project/issues/front.
 *
 */

/**
 * Implementation of hook_help().
 */
function front_page_help($section) {
  switch ($section) {
    case 'admin/settings/front':
      return t('<p>Setup custom front pages for your site.</p>');
    case 'admin/settings/front/arrange':
      return t('<p>Arrange the order in which roles will be checked for custom front page settings. Roles will be processed from top to bottom. To enable other roles you must first enable them in the !link.</p>', array(
        '!link' => l(t('Settings tab'), 'admin/settings/front/settings'),
      ));
    case 'admin/settings/front/home-links':
      return t('<p>If a HOME link is set, the &lt;front&gt; placeholder will be replaced with this value instead of the standard front page.</p>');
  }
}

/**
 * Implementation of hook_menu().
 */
function front_page_menu() {
  $items['admin/settings/front'] = array(
    'title' => t('Front Page'),
    'description' => 'Specify a unique layout or splash page based on role type - override your HOME and breadcrumb links - display a custom mission style notice for users who haven\'t visited in a while - disable site and display a \'temporarily offline\' message.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'front_page_admin',
    ),
    'access arguments' => array(
      'administer front page',
    ),
    'file' => 'front_page.admin.inc',
  );
  $items['admin/settings/front/settings'] = array(
    'title' => t('Settings'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  $items['admin/settings/front/arrange'] = array(
    'title' => 'Arrange',
    'description' => 'Ability to re-arrange what order front page roles are processed.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'front_page_admin_arrange_form',
    ),
    'access arguments' => array(
      'administer front page',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'front_page.admin.inc',
    'weight' => 1,
  );
  $items['admin/settings/front/home-links'] = array(
    'title' => 'Home Links',
    'description' => 'Ability to re-write the home links on the site to another local path.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'front_page_admin_home_links',
    ),
    'access arguments' => array(
      'administer front page',
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'front_page.admin.inc',
    'weight' => 2,
  );
  $items['front_page'] = array(
    'title' => '',
    'page callback' => 'front_page',
    'access callback' => TRUE,
    'type' => MENU_SUGGESTED_ITEM,
  );
  $items['front_page/preview/%'] = array(
    'title' => '',
    'page callback' => 'front_page',
    'access callback' => TRUE,
    'type' => MENU_SUGGESTED_ITEM,
  );
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function front_page_perm() {
  return array(
    'administer front page',
  );
}

/**
 * Implementation of hook_init().
 */
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;
  }
}

/**
 * Function to handle the display of the front page themed and full types.
 */
function front_page() {

  // $_front_page variable should already have been loaded in front_page_init() function.
  global $_front_page;
  if ($_front_page) {
    switch ($_front_page['mode']) {
      case 'themed':
        return check_markup($_front_page['data'], $_front_page['filter_format']);
      case 'full':
        print check_markup($_front_page['data'], $_front_page['filter_format']);
        exit;
    }
  }

  // set page not found as there was no themed or full option set for the front page.
  drupal_not_found();
  exit;
}

/**
 * Function to parse a full URL including GET variables and fragment
 * to an array ready for drupal_goto(), url(), or l() functions.
 */
function front_page_parse_url($path) {
  $url['path'] = $path;
  $url['options'] = array();
  if (preg_match('@^(?P<path>[^?#]+)(\\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$@', $path, $match)) {
    $url['path'] = $match['path'];
    if (!empty($match['query'])) {
      foreach (explode('&', $match['query']) as $query_part) {
        list($key, $value) = explode('=', $query_part);
        $url['options']['query'][$key] = $value;
      }
    }
    if (!empty($match['fragment'])) {
      $url['options']['fragment'] = $match['fragment'];
    }
  }
  return $url;
}

/**
 * Function to return the first role enabled in front page, ordered by weight.
 */
function front_page_get_by_role($index = 0, $number = 1) {
  global $user;
  return db_fetch_array(db_query_range("SELECT * FROM {front_page} WHERE rid IN (" . implode(',', array_fill(0, count($user->roles), '%d')) . ") AND mode <> '' ORDER BY weight ASC, rid DESC", array_keys($user->roles), $index, $number));
}

/**
 * Function to return the first role enabled in front page, ordered by weight.
 */
function front_page_get_by_rid($rid) {
  return db_fetch_array(db_query("SELECT * FROM {front_page} WHERE rid = %d AND mode <> ''", $rid));
}

/**
 * Function to return all the roles in front page, ordered by weight.
 */
function front_page_get_all() {
  global $user;
  $roles = array();
  $result = db_query("SELECT * FROM {front_page} ORDER BY weight ASC, rid DESC", $rid);
  while ($role = db_fetch_array($result)) {
    $roles[$role['rid']] = $role;
  }
  return $roles;
}

/**
 * Implements hook_theme().
 */
function front_page_theme() {
  return array(
    'front_page_admin_arrange_form' => array(
      'file' => 'front_page.admin.inc',
      'render element' => 'form',
    ),
  );
}

// Define the custom_url_rewrite_outbound() function if not already defined.
if (!function_exists('custom_url_rewrite_outbound')) {
  function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
    front_page_url_outbound_alter($path, $options, $original_path);
  }
}

/**
 * Implementation of hook_url_outbound_alter().
 */
function front_page_url_outbound_alter(&$path, &$options, $original_path) {

  // check if path is set to 'front_page' as this is our virtual home
  // page and doesn't work properly unless used from home page.
  if ($path == 'front_page') {
    $original_path = $path = '';
  }
  $newpath = variable_get('front_page_home_link_path', '');
  if (($path == '<front>' || empty($path)) && !empty($newpath)) {
    $original_path = $path = $newpath;
  }
}

Functions

Namesort descending Description
front_page Function to handle the display of the front page themed and full types.
front_page_get_all Function to return all the roles in front page, ordered by weight.
front_page_get_by_rid Function to return the first role enabled in front page, ordered by weight.
front_page_get_by_role Function to return the first role enabled in front page, ordered by weight.
front_page_help Implementation of hook_help().
front_page_init Implementation of hook_init().
front_page_menu Implementation of hook_menu().
front_page_parse_url Function to parse a full URL including GET variables and fragment to an array ready for drupal_goto(), url(), or l() functions.
front_page_perm Implementation of hook_perm().
front_page_theme Implements hook_theme().
front_page_url_outbound_alter Implementation of hook_url_outbound_alter().