'splash', 'title' => t('Splash'), 'description' => t('Splash page before the actual frontpage.'), 'callback' => 'splash_page', 'access' => user_access('access content'), 'type' => MENU_CALLBACK, ); // Admin $items[] = array( 'path' => 'admin/settings/splash', 'title' => t('Splash'), 'description' => t('Show a splash page before/over the actual frontpage.'), 'callback' => 'splash_menu_invoke_form', 'callback arguments' => array('splash_admin_when'), 'access' => user_access('administer splash'), ); $items[] = array( 'path' => 'admin/settings/splash/when', 'title' => t('When'), 'description' => t('Set WHEN the splash page is displayed.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, 'access' => user_access('administer splash'), 'callback' => 'splash_menu_invoke_form', 'callback arguments' => array('splash_admin_when'), ); $items[] = array( 'path' => 'admin/settings/splash/what', 'title' => t('What'), 'description' => t('Set WHAT is displayed as the splash page.'), 'type' => MENU_LOCAL_TASK, 'access' => user_access('administer splash'), 'callback' => 'splash_menu_invoke_form', 'callback arguments' => array('splash_admin_what'), ); $items[] = array( 'path' => 'admin/settings/splash/how', 'title' => t('How'), 'description' => t('Set HOW the splash page is displayed.'), 'type' => MENU_LOCAL_TASK, 'access' => user_access('administer splash'), 'callback' => 'splash_menu_invoke_form', 'callback arguments' => array('splash_admin_how'), ); } else { // Drupal 5's menu system requires hook_init in hook_menu. splash_menu_init(); } return $items; } function splash_menu_invoke_form($form) { require_once('splash.admin.inc'); return drupal_get_form($form); } /** * Invoked during hook_menu's non-caching stage. */ function splash_menu_init() { global $base_url; $splash = TRUE; $splash_what_content = variable_get('splash_what_content', ''); $splash_what_redirect = variable_get('splash_what_redirect', ''); $splash_when_frequency = variable_get('splash_when_frequency', 'never'); $splash_what_mode = variable_get('splash_what_mode', 'random'); $cookie_name = $splash_when['cookie'] ? $splash_when['cookie'] : 'splash_cookie'; $cookie_data = $_COOKIE[$cookie_name] ? (is_numeric($_COOKIE[$cookie_name]) ? array('time' => $_COOKIE[$cookie_name]) : (array) unserialize($_COOKIE[$cookie_name])) : array(); /*** THE WHEN ***/ // No WHAT if (empty($splash_what_content)) { $splash = FALSE; // Someone knew this special way to get around the splash :) } elseif ($_GET['splash'] == 'off') { $splash = FALSE; // Someone knew this special way to force splash display } elseif ($_GET['splash'] == 'on') { $splash = TRUE; // We are not on the front page (cannot use drupal_is_front_page here) } elseif ($_GET['q'] != drupal_get_normal_path(variable_get('site_frontpage', 'node'))) { $splash = FALSE; // We come from an internal page } elseif (($parsed_url = parse_url($base_url)) && stristr(referer_uri(), $parsed_url['host'])) { $splash = FALSE; // Front page is splash page?! } elseif ($splash_what_redirect && $_GET['q'] == drupal_get_normal_path($splash_what_redirect)) { $splash = FALSE; } else { // Frequency if ($splash) { // No cookie if (!$cookie_data['time']) { $splash = TRUE; } else { // Once if ($splash_when_frequency == 'once') { $splash = FALSE; // Every day } else if ($cookie_data['time'] && $splash_when_frequency == 'daily' && (time() - $cookie_data['time'] < 86400)) { $splash = FALSE; // Every week } else if ($cookie_data['time'] && $splash_when_frequency == 'weekly' && (time() - $cookie_data['time'] < 604800)) { $splash = FALSE; // Never } else if ($splash_when_frequency != 'always') { $splash = FALSE; } } } } // Show splash if ($splash) { /*** THE WHAT ***/ // Text if ($splash_what_mode == 'template' || $splash_what_mode == 'fullscreen') { $url = check_url('splash'); // Path or URL } else { $paths = preg_split('/[\n\r]+/', $splash_what_content); // Sequence if ($splash_what_mode == 'sequence') { $last_path = $cookie_data['sequence']; $last_index = array_search($last_path, $paths); if ($last_index !== FALSE && count($paths) > $last_index + 1) { $next_index = $last_index + 1; } else { $next_index = 0; } $cookie_data['sequence'] = $paths[$next_index]; // Random } else { $next_index = array_rand($paths); } $url = check_url($paths[$next_index]); } $cookie_data['time'] = time(); setcookie($cookie_name, serialize($cookie_data), time() + 604800, '/'); /*** THE HOW ***/ $splash_how_mode = variable_get('splash_how_mode', 'redirect'); $splash_how_size = variable_get('splash_how_size', ''); $size = !empty($splash_how_size) ? explode('x', $splash_how_size) : FALSE; // Thickbox if ($splash_how_mode == 'thickbox') { drupal_add_css(drupal_get_path('module', 'splash')."/thickbox/thickbox.css", 'module', 'screen'); drupal_set_html_head( "\n". "" ); drupal_add_js(drupal_get_path('module', 'splash').'/thickbox/thickbox.js'); $query = array(); $url_parts = parse_url($url); // Open external URLs and templated texts in iFrame if ($url_parts['scheme'] || $splash_how_mode == 'template') { $query[] = 'TB_iframe=true'; } // Set size if ($size) { $query[] = 'width='.$size[0].'&height='.$size[1]; } if (count($query)) { $url = url($url, implode('&', $query), NULL, TRUE); } drupal_add_js('$(document).ready(function(){ tb_show("", "'.$url.'") });', 'inline'); // New window } else if ($splash_how_mode == 'window') { $size_str = $size ? ', "width='.$size[0].',height='.$size[1].'"' : ''; drupal_add_js('window.onload = function() { window.open("'.$url.'", "splash"'.$size_str.'); }', 'inline'); // Redirect } else { drupal_goto($url); } } } function splash_help($section) { switch ($section) { case 'admin/settings/splash': return '
'. t('Install the !condition module to add additional conditions for displaying the splash page. Please note that the splash page is never displayed in the following conditions:
?nosplash
to the URL.'. t('What will be displayed as splash page? You can enter multiple internal paths or full URLs to pick from either in random or in sequence mode. Or enter some text and choose if should be displayed in the site template or full screen.').'
'; case 'admin/settings/splash/how': return ''. t('By default, the visitor is redirected to the splash page. In that case, please remember to include a link to the frontpage on the splash page. But you can also open the page in a new window (blocked by some browsers and plug-ins) or (if you have it installed) use the fancy !thickbox.', array('!thickbox' => l(t('ThickBox'), 'http://jquery.com/demo/thickbox/'))).'
'; } } function splash_page() { $splash_what_mode = variable_get('splash_what_mode', ''); $splash_what_content = variable_get('splash_what_content', ''); $splash_what_filter = variable_get('splash_what_filter', ''); $output = check_markup($splash_what_content, $splash_what_filter, FALSE); if ($splash_what_mode == 'fullscreen') { echo $output; exit; } else { return $output; } }