View source
<?php
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 <front> placeholder will be replaced with this value instead of the standard front page.</p>');
}
}
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;
}
function front_page_perm() {
return array(
'administer front page',
);
}
function front_page_init() {
global $_front_page, $conf;
if (function_exists('drush_main')) {
return;
}
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';
$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']);
$conf['site_frontpage'] = $_GET['q'];
break;
}
$GLOBALS['conf']['cache'] = FALSE;
}
}
function front_page() {
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;
}
}
drupal_not_found();
exit;
}
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 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 front_page_get_by_rid($rid) {
return db_fetch_array(db_query("SELECT * FROM {front_page} WHERE rid = %d AND mode <> ''", $rid));
}
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;
}
function front_page_theme() {
return array(
'front_page_admin_arrange_form' => array(
'file' => 'front_page.admin.inc',
'render element' => 'form',
),
);
}
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);
}
}
function front_page_url_outbound_alter(&$path, &$options, $original_path) {
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;
}
}