= 3) { krsort($roles); $special_note .= "
'; } return t('Setup custom front pages for your site. Click on the option to expand the form and customise your settings.
Anonymous User = visitor not logged in | Authenticated User = visitor who is logged in
!special_note', array('!special_note' => $special_note)); } } /** * this function sets the necessary paths etc. so drupal * knows where to find the front_page */ function front_page_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/settings/front', 'title' => t('advanced front page settings'), 'description' => t('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.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'front_page_admin', 'access' => user_access('administer menu')); $items[] = array( 'path' => 'front_page', 'title' => t(''), 'callback' => 'front_page', 'access' => TRUE, 'type' => MENU_SUGGESTED_ITEM); $items[] = array( 'path' => 'admin/settings/front/uninstall', 'description' => t('This will uninstall the front page module.'), 'callback' => 'uninstall_front_page', 'type' => MENU_CALLBACK, 'access' => user_access('administer menu') ); } return $items; } /** * this function sets up the admin/build/front_page settings page * */ function front_page_admin() { // Load any existing settings and build the by redirect by role form $form['byrole'] = array('#type' => 'fieldset','#title' => t('Home pages'),'#description' => t('Designate a home page for each role. "Splash" pages will be used only when users are connecting from external sites. Spash pages must be in the form "node/x" where x is the id of a node, e.g., "node/21" (without the quotes). Only the body of the node will be displayed. Home pages are displayed when users follow internal home links, or for external links where there is no splash page designated, and may point to any page on the site.'),'#theme' => 'front_page_roles','#collapsible' => TRUE,'#tree' => TRUE); // build the form for roles $roles = user_roles(); foreach (element_children($roles) as $role) { $rolename = $roles[$role]; $form[$role] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Front Page for %rolename', array('%rolename' => $rolename))); $form[$role]['front_'. $role .'_text'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => variable_get('front_'. $role .'_text', ''), '#cols' => 60, '#rows' => 20, '#description' => t('Paste your HTML or TEXT here for visitors to your site who are already logged in.THEMED means your default layout, theme and stylesheet will be loaded with your custom front_page.
FULL allows you to have a completely different layout, style sheet etc.
REDIRECT will automatically redirect visitors already logged in to a specific page specified in the REDIRECT TO box.
SAME will display the same content as for Anonymous (not logged in) users.
THEMED means your default layout, theme and stylesheet will be loaded with your custom front_page.
FULL allows you to have a completely different layout, style sheet etc.
REDIRECT will automatically redirect visitors already logged in to a specific page specified in the REDIRECT TO box.
The length of time to check for when users see the special notice which will be displayed as a mission style notice on the front page.
'), ); $form['special_notice']['special_notice_text'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => variable_get('special_notice_text', ''), '#cols' => 60, '#rows' => 10, '#description' => t('Paste your HTML or TEXT here. It will be displayed as a mission style notice on the front page.')); $form['override'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Override your HOME breadcrumb links')); $form['override']['front_page_breadcrumb'] = array( '#type' => 'checkbox', '#title' => t('Redirect your site HOME links'), '#return_value' => 1, '#default_value' => variable_get('front_page_breadcrumb',0), '#description' => t('Check this box if you want to redirect users who click on any HOME links (including the HOME breadcrumb link). Useful if you have a splash page you don\'t want users brought back to when they click on HOME links from within your site.') ); $form['override']['front_page_breadcrumb_redirect'] = array( '#type' => 'textfield', '#title' => t('Redirect your site HOME links to'), '#default_value' => variable_get('front_page_breadcrumb_redirect', ''), '#cols' => 20, '#rows' => 1, '#description' => t('Specify where the user should be redirected to. An example would be node/12. Leave blank when you\'re not using HOME redirect.'), '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q=') ); $form['site'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#title' => t('Activate your front_page settings')); $form['site']['site_frontpage'] = array( '#type' => 'textfield', '#title' => t('Default front page'), '#default_value' => variable_get('site_frontpage', 'node'), '#size' => 40, '#description' => t('Change this setting to front_page to activate your front page settings.'), '#field_prefix' => url(NULL, NULL, NULL, TRUE) . (variable_get('clean_url', 0) ? '' : '?q=') ); $form['uninstall_front_page'] = array('#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Deactivate and uninstall the Front Page module')); $form['uninstall_front_page']['#description'] = t('
Follow the steps below to deactivate and remove the front_page.module from your Drupal installation.
STEP 1: !remove', array('!remove' => ''. t('Remove all front_page settings from the database') .'
PLEASE NOTE: REMOVING THE FRONT PAGE SETTINGS FROM YOUR DATABASE CANNOT BE UNDONE
YOUR DEFAULT SITE FRONT PAGE WILL REVERT BACK TO THE SYSTEM DEFAULT (NODE)
STEP 2: Once you have removed the front page settings from your database, you may safely delete the front_page.module and front_page.info files from your Drupal folder.
') ); return system_settings_form($form); } /** * this function uninstalls the front page module * */ function uninstall_front_page(){ $roles = ""; $roles = user_roles(); foreach (element_children($roles) as $role) { $rolename = $roles[$role]; variable_del('front_'. $role .'_text');// text settings variable_del('front_'. $role .'_type');// type variable_del('front_'. $role .'_redirect'); //redirect variable_del('front_'. $role .'_php');// php filter } variable_del('front_page_breadcrumb',''); // home breadcrumb override switch variable_del('front_page_breadcrumb_redirect','');// home override redirect variable_del('special_notice_time',''); // special notice time variable_del('special_notice_text','');// special notice text //reset some important site variables variable_set('site_frontpage', 'node'); //reset the default front page for the site back to node variable_set('uninstall_front_setting', '0'); drupal_set_message(t('All front page settings have been removed from your database. You may now disable the module below and then delete the front page files from your server.')); $module = 'front_page'; $status = '0'; module_disable($module); db_query("UPDATE {system} SET status = 0 WHERE name = '%s'", $module); drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED); drupal_goto('admin/settings/modules'); } function front_page() { /* Set a default value for landing zone if no front_page variables are filled. If the module is turned on * but empty in certain areas then a redirection loop will occur. This default prevents this */ $output = 'node'; /* Set the time to check against the last access of the user by the variable set in settings.*/ switch(variable_get('front_special_notice_time','')){ case 'one day' : $check_time = (time() - (24 * 60 * 60)); break; case 'one week' : $check_time =(time() - (7 * 24 * 60 * 60)); break; case 'one month' : $check_time =(time() - (30 * 24 * 60 * 60)); break; case 'three months' : $check_time =(time() - (90 * 24 * 60 * 60)); break; case 'six months' : $check_time =(time() - (180 * 24 * 60 * 60)); break; case 'one year' : $check_time =(time() - (360 * 24 * 60 * 60)); break; } //this checks to see if you are overriding HOME links on the site if (variable_get('front_page_breadcrumb',0)) { // This checks to see if the referer is an internal HOME link or not. $newhome = variable_get('front_page_breadcrumb_redirect','node'); $ref = $_SERVER["HTTP_REFERER"]; global $user, $base_url; $parsed_url=parse_url($base_url); $domain = $parsed_url['host']; if (stristr($ref, $domain)) { drupal_goto($path = $newhome, $query = NULL, $fragment = NULL); } } // the following is the code that loads the front_page settings global $user; /* * show this if the user is not logged in or if the authenticated user is to get the same output as * anonymous users */ $authenticated_user_text_setting = variable_get("front_2_text", ""); if (!$user->uid || variable_get("front_2_type", "same") == "same" || (empty($authenticated_user_text_setting))) { $output = variable_get("front_1_text", "drupal"); /* if PHP code execution is allowed then use eval */ if (variable_get('front_1_php', 0)) { $output = drupal_eval($output); } $fptype = variable_get("front_1_type", "drupal"); switch ($fptype) { case "themed": print theme('page', $output); return; case "full": print $output; return; case "redirect": $output = variable_get("front_1_redirect", "drupal"); break; } } /* this is where the new front page by role stuff happens */ else if ($user->uid ){ $roles=""; //make sure the roles variable is clear $roles = user_roles(); //load up the user roles for the site krsort($roles); //reverse the order of role types so it checks the highest or more recent role type first. foreach ($roles as $role_id => $role_name) { // run through each role type starting at the most recent working backwards if ((array_key_exists($role_id, $user->roles)) && (trim(variable_get("front_". $role_id ."_text", "")) != "")){ // if the current visitor has a role type that matches and if the front page setting for that role type is not empty. if ((variable_get("special_notice_text", "") != "") && ($user->access < $check_time)){ $output = '