'Splash', 'page callback' => 'splash_page', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Admin $items['admin/settings/splash'] = array( 'title' => 'Splash', 'description' => t('Show a splash page before/over the actual frontpage.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('splash_admin_when'), 'access arguments' => array('administer splash'), 'file' => 'splash.admin.inc', ); $items['admin/settings/splash/when'] = array( 'title' => 'When', 'description' => t('Set WHEN the splash page is displayed.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'access arguments' => array('administer splash'), 'weight' => -10, ); $items['admin/settings/splash/what'] = array( 'title' => 'What', 'description' => t('Set WHAT is displayed as the splash page.'), 'page arguments' => array('splash_admin_what'), 'access arguments' => array('administer splash'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/splash/how'] = array( 'title' => 'How', 'description' => t('Set HOW the splash page is displayed.'), 'page arguments' => array('splash_admin_how'), 'access arguments' => array('administer splash'), 'type' => MENU_LOCAL_TASK, ); return $items; } function splash_init() { global $base_url; if (function_exists('drush_verify_cli') && call_user_func('drush_verify_cli')) { return; } $splash = TRUE; $splash_when = variable_get('splash_when', array()); $splash_what = variable_get('splash_what', array()); $cookie_name = (!empty($splash_when['cookie'])) ? $splash_when['cookie'] : 'splash_cookie'; $cookie_data = (!empty($_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; $reason = 'No WHAT'; // Someone knew this special way to get around the splash :) } elseif ($_GET['splash'] == 'off') { $splash = FALSE; $reason = 'Someone knew this special way to get around the splash'; // Someone knew this special way to force splash display } elseif ($_GET['splash'] == 'on') { $splash = TRUE; $reason = 'Someone knew this special way to force splash display'; // 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; $reason = 'We are not on the front page'; // We come from an internal page } elseif (($parsed_url = parse_url($base_url)) && stristr(referer_uri(), $parsed_url['host'])) { $splash = FALSE; $reason = 'We come from an internal page'; // Front page is splash page?! } elseif ($splash_what['redirect'] && $_GET['q'] == drupal_get_normal_path($splash_what['redirect'])) { $splash = FALSE; $reason = 'Front page is splash page'; } else { // Conditions if (module_exists('condition') && is_array($splash_when['conditions'])) { $splash = condition_selection_validate($splash_when['conditions']); $reason = ($splash) ? 'Conditions true' : 'Conditions false'; } // Frequency if ($splash) { // No cookie if (!$cookie_data['time']) { $splash = TRUE; $reason = 'No cookie'; } else { // Once if ($splash_when['frequency'] == 'once') { $splash = FALSE; $reason = 'Once'; // Every day } else if ($cookie_data['time'] && $splash_when['frequency'] == 'daily' && (time() - $cookie_data['time'] < 86400)) { $splash = FALSE; $reason = 'Every day'; // Every week } else if ($cookie_data['time'] && $splash_when['frequency'] == 'weekly' && (time() - $cookie_data['time'] < 604800)) { $splash = FALSE; $reason = 'Every week'; // Never } else if ($splash_when['frequency'] != 'always') { $splash = FALSE; $reason = 'Never'; } } } } //dsm($reason); // 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() + 31556926, '/'); /*** THE HOW ***/ $splash_how = variable_get('splash_how', array()); $size = $splash_how['size'] ? explode('x', $splash_how['size']) : FALSE; // Thickbox if (module_exists('thickbox') && ($splash_how['mode'] == 'thickbox')) { //_thickbox_doheader(); $query = array(); $url_parts = parse_url($url); // Open external URLs and templated texts in iFrame if ($url_parts['scheme'] || $splash_what['mode'] == 'template') { $query[] = 'TB_iframe=true'; } // Set size if ($size) { $query[] = 'width='.$size[0].'&height='.$size[1]; } if (count($query)) { $url = url($url, array('query' => implode('&', $query))); } 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($path, $arg) { switch ($path) { 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:

', array('!condition' => l(t('Condition'), 'http://drupal.org/project/condition'))).'

'; case 'admin/settings/splash/what': return '

'. 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 = variable_get('splash_what', array()); $output = check_markup($splash_what['content'], $splash_what['format'], FALSE); if ($splash_what['mode'] == 'fullscreen') { echo $output; exit; } else { return $output; } } ?>