View source
<?php
function front_page_help($section) {
switch ($section) {
case 'admin/config/front/settings':
return t('<p>Setup custom front pages for your site.</p>');
case 'admin/config/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/config/front/settings'),
));
case 'admin/config/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/config/front'] = array(
'title' => 'Front Page',
'description' => 'Configure front page.',
'position' => 'right',
'weight' => -15,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'administer front page',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/front/settings'] = array(
'title' => 'Settings',
'description' => 'Administer custom front page settings.',
'weight' => 0,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'front_page_admin',
),
'access arguments' => array(
'administer front page',
),
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
'file' => 'front_page.admin.inc',
);
$items['admin/config/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 | MENU_NORMAL_ITEM,
'file' => 'front_page.admin.inc',
'weight' => 1,
);
$items['admin/config/front/home-links'] = array(
'title' => 'Home links',
'description' => 'Allows you to change the location of the <front> placeholder.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'front_page_admin_home_links',
),
'access arguments' => array(
'administer front page',
),
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
'file' => 'front_page.admin.inc',
'weight' => 2,
);
$items['front_page'] = array(
'title' => '',
'page callback' => 'front_page',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
function front_page_permission() {
return array(
'administer front page' => array(
'title' => t('Administer front page'),
'description' => t('Allow users to make changes to the front page settings.'),
),
);
}
function front_page_init() {
if (drupal_is_cli() || drupal_installation_attempted()) {
return;
}
if (variable_get('maintenance_mode', 0)) {
return;
}
if (!empty($_SERVER['SCRIPT_FILENAME']) && realpath(DRUPAL_ROOT . '/index.php') != realpath($_SERVER['SCRIPT_FILENAME'])) {
return;
}
global $_front_page, $conf;
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) {
drupal_alter('front_page', $_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'];
}
}
if (module_exists('token')) {
$url['path'] = token_replace($url['path']);
}
return $url;
}
function front_page_get_by_role($index = 0, $number = 1) {
global $user;
$roles = array();
foreach (array_keys($user->roles) as $rid) {
$roles[] = front_page_get_by_rid($rid);
}
$roles = array_filter($roles);
if (empty($roles)) {
return FALSE;
}
uasort($roles, '_front_page_sort');
return reset($roles);
}
function front_page_get_by_rid($rid) {
$role = _front_page_get_by_rid_with_default($rid);
return !empty($role['mode']) ? $role : FALSE;
}
function front_page_get_all() {
$roles = array();
foreach (user_roles() as $rid => $role) {
$roles[$rid] = _front_page_get_by_rid_with_default($rid);
}
uasort($roles, '_front_page_sort');
return $roles;
}
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;
}
}
function front_page_theme() {
return array(
'front_page_admin_arrange_form' => array(
'file' => 'front_page.admin.inc',
'render element' => 'form',
),
);
}
function front_page_user_role_delete($role) {
variable_del("front_page_role_{$role->rid}");
}
function _front_page_get_by_rid_with_default($rid) {
return variable_get("front_page_role_{$rid}", array(
'rid' => $rid,
'mode' => '',
'data' => '',
'filter_format' => '',
'weight' => 0,
));
}
function _front_page_sort($a, $b) {
$a_value = is_array($a) && isset($a['weight']) ? $a['weight'] : 0;
$b_value = is_array($b) && isset($b['weight']) ? $b['weight'] : 0;
if ($a_value != $b_value) {
return $a_value < $b_value ? -1 : 1;
}
$a_value = is_array($a) && isset($a['rid']) ? $a['rid'] : 0;
$b_value = is_array($b) && isset($b['rid']) ? $b['rid'] : 0;
if ($a_value != $b_value) {
return $a_value > $b_value ? -1 : 1;
}
return 0;
}