From 83e12e913f30a7b2c4b5676f972f145b78c2852e Mon Sep 17 00:00:00 2001
From: Alex Skrypnyk <alex.designworks@gmail.com>
Date: Tue, 20 Dec 2011 14:07:49 +1100
Subject: [PATCH 7/7] by alex.designworks: Added fullscreen template functionality. Allows specify path to PHP-based template for splash screen.
 by alex.designworks: Fixed coding and comments formatting.

---
 splash.admin.inc |  186 +++++++++++++-----------
 splash.install   |   38 +++---
 splash.module    |  416 ++++++++++++++++++++++++++++++------------------------
 3 files changed, 355 insertions(+), 285 deletions(-)

diff --git a/splash.admin.inc b/splash.admin.inc
index 8c09923..d6f11a6 100644
--- a/splash.admin.inc
+++ b/splash.admin.inc
@@ -1,91 +1,95 @@
 <?php
 
+/**
+ * @file
+ * Administrative interface.
+ */
 function splash_admin_when() {
-	$splash_when = variable_get('splash_when', array());
+  $splash_when = variable_get('splash_when', array());
 
-	$form['general'] = array(
-		'#type' => 'fieldset',
-		'#title' => t('Settings'),
-	);	
+  $form['general'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Settings'),
+  );
   $form['general']['frequency'] = array(
-	  '#type' => 'select', 
-	  '#title' => t('Display with frequency'), 
-	  '#default_value' => $splash_when['frequency'],
-	  '#options' => array(
-	  	''				=> t('Never (off)'),
-		  'always'	=> t('Always'),
-		  'once'		=> t('Once'),
-		  'daily'		=> t('Daily'),
-		  'weekly'	=> t('Weekly'),
-		), 
-	  '#description' => t('How often should visitors see the splash page?'),
-	);
-	$form['general']['cookie'] = array(
-		'#type' => 'checkbox',
-		'#title' => t('Force display on next visit'), 
-		'#description' => t('Reset the name of the cookie to force the display of the splash on next visit.  This is useful to preview changes to the splash content in development.'),
-		'#default_value' => 0,
-	);
-	
-	if (module_exists('condition')) {
-		$form = array_merge($form, module_invoke('condition', 'selection_form', $splash_when['conditions']));
-	}
-	
-	$form = system_settings_form($form);
-	
-	unset($form['#submit']);
-	
-	return $form;
+    '#type' => 'select',
+    '#title' => t('Display with frequency'),
+    '#default_value' => $splash_when['frequency'],
+    '#options' => array(
+      '' => t('Never (off)'),
+      'always' => t('Always'),
+      'once' => t('Once'),
+      'daily' => t('Daily'),
+      'weekly' => t('Weekly'),
+    ),
+    '#description' => t('How often should visitors see the splash page?'),
+  );
+  $form['general']['cookie'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Force display on next visit'),
+    '#description' => t('Reset the name of the cookie to force the display of the splash on next visit.  This is useful to preview changes to the splash content in development.'),
+    '#default_value' => 0,
+  );
+
+  if (module_exists('condition')) {
+    $form = array_merge($form, module_invoke('condition', 'selection_form', $splash_when['conditions']));
+  }
+
+  $form = system_settings_form($form);
+
+  unset($form['#submit']);
+
+  return $form;
 }
 
 function splash_admin_when_submit($form, &$form_state) {
-	
+
   if ($op == t('Reset to defaults')) {
-	  variable_del('splash_when');
-	  
+    variable_del('splash_when');
+
     drupal_set_message(t('The configuration options have been reset to their default values.'));
   }
-  
   else {
-	  $splash_when = variable_get('splash_when', array());
-		$splash_when['frequency'] = $form_state['values']['frequency'];
-		
-		if ($form_state['values']['cookie']) {
-			$splash_when['cookie'] = 'splash_cookie_'.time();
-		}
-		
-		if (module_exists('condition')) {
-			$splash_when['conditions'] = $form_state['values']['conditions'];
-		}
-		
-		variable_set('splash_when', $splash_when);
-		  
+    $splash_when = variable_get('splash_when', array());
+    $splash_when['frequency'] = $form_state['values']['frequency'];
+
+    if ($form_state['values']['cookie']) {
+      $splash_when['cookie'] = 'splash_cookie_' . time();
+    }
+
+    if (module_exists('condition')) {
+      $splash_when['conditions'] = $form_state['values']['conditions'];
+    }
+
+    variable_set('splash_when', $splash_when);
+
     drupal_set_message(t('The configuration options have been saved.'));
   }
-  
+
   cache_clear_all();
   drupal_rebuild_theme_registry();
 }
 
 function splash_admin_what() {
-	$splash_what = variable_get('splash_what', array());
+  $splash_what = variable_get('splash_what', array());
 
-	$form['splash_what'] = array(
-		'#tree' => TRUE,
-	);
+  $form['splash_what'] = array(
+    '#tree' => TRUE,
+  );
   $form['splash_what']['mode'] = array(
     '#type' => 'select',
     '#title' => t('Content mode'),
     '#options' => array(
-    	'' => t('Pick random path or URL from the list'),
-    	'sequence' => t('Pick next path or URL from the list'),
-    	'template' => t('Display entered text in the site template'),
-    	'fullscreen' => t('Display entered text/HTML full screen'),
+      '' => t('Pick random path or URL from the list'),
+      'sequence' => t('Pick next path or URL from the list'),
+      'template' => t('Display entered text in the site template'),
+      'fullscreen' => t('Display entered text/HTML full screen'),
+      'fullscreen_path' => t('Display text/HTML from specified path'),
     ),
     '#default_value' => $splash_what['mode'],
     '#description' => t('Determines how the content field below will be used.'),
   );
-  
+
   $form['splash_what']['content'] = array(
     '#type' => 'textarea',
     '#title' => t('Content'),
@@ -95,26 +99,43 @@ function splash_admin_what() {
 
   $form['splash_what']['filter'] = filter_form($splash_what['format']);
   $form['splash_what']['format'] = array(
-  	'#type' => 'value',
-  	'#value' => $splash_what['format'],
-  );  
-	
+    '#type' => 'value',
+    '#value' => $splash_what['format'],
+  );
+
+  $form['splash_what']['bypass'] = array(
+    '#title' => t('Bypass key'),
+    '#type' => 'textfield',
+    '#default_value' => isset($splash_what['bypass']) && !empty($splash_what['bypass']) ? $splash_what['bypass'] : 'splash',
+    '#description' => t('Word that is used as a key in query to skip splash screen. Defaults to "splash".'),
+    '#required' => TRUE,
+  );
+
+  $form['splash_what']['bypass_words'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Bypass words'),
+    '#default_value' => isset($splash_what['bypass_words']) && !empty($splash_what['bypass_words']) ? implode("\n", $splash_what['bypass_words']) : array('off'),
+    '#description' => t('List of words that used as values in query to skip splash screen (one on each line).'),
+  );
+
   $form['#submit'][] = 'splash_admin_what_submit';
-  
+
   return system_settings_form($form);
 }
 
 function splash_admin_what_submit($form, &$form_state) {
-	$form_state['values']['splash_what']['format'] = $form_state['values']['format'];
+  $form_state['values']['splash_what']['format'] = $form_state['values']['format'];
+  // Save bypass words as array.
+  $form_state['values']['splash_what']['bypass_words'] = explode("\n", str_replace("\r", "", $form_state['values']['splash_what']['bypass_words']));
 }
 
 function splash_admin_how() {
-	$splash_how = variable_get('splash_how', array());
-	
-	$options = array(
-		'redirect' => t('Redirect'),
-		'window' => t('Open in new window'),
-	);
+  $splash_how = variable_get('splash_how', array());
+
+  $options = array(
+    'redirect' => t('Redirect'),
+    'window' => t('Open in new window'),
+  );
   if (module_exists('thickbox')) {
     $options['thickbox'] = t('Open in ThickBox');
   }
@@ -124,10 +145,10 @@ function splash_admin_how() {
   if (module_exists('lightbox2')) {
     $options['lightbox2'] = t('Open in Lightbox2');
   }
-	
-	$form['splash_how'] = array(
-		'#tree' => TRUE,
-	);
+
+  $form['splash_how'] = array(
+    '#tree' => TRUE,
+  );
   $form['splash_how']['mode'] = array(
     '#type' => 'radios',
     '#required' => TRUE,
@@ -142,15 +163,12 @@ function splash_admin_how() {
     '#default_value' => $splash_how['size'],
     '#description' => t('Size (<code>WIDTHxHEIGHT</code>, e.g. 400x300) of the window or ThickBox.'),
   );
-	
-	return system_settings_form($form);
+
+  return system_settings_form($form);
 }
 
 function splash_admin_how_validate($form, &$form_state) {
-	
-	if (!empty($form_state['values']['splash_how']['size']) && !preg_match('/^[1-9][0-9]*x[1-9][0-9]*$/i', $form_state['values']['splash_how']['size'])) {
-		form_set_error('size', t('Invalid Window/Box size. Use <code>WIDTHxHEIGHT</code>, e.g. 400x300.'));
-	} 
+  if (!empty($form_state['values']['splash_how']['size']) && !preg_match('/^[1-9][0-9]*x[1-9][0-9]*$/i', $form_state['values']['splash_how']['size'])) {
+    form_set_error('size', t('Invalid Window/Box size. Use <code>WIDTHxHEIGHT</code>, e.g. 400x300.'));
+  }
 }
-
-?>
\ No newline at end of file
diff --git a/splash.install b/splash.install
index 83636f0..7390389 100644
--- a/splash.install
+++ b/splash.install
@@ -1,29 +1,29 @@
 <?php
-
+/**
+ * @file
+ */
 function splash_update_6200() {
-	$ret = array();
-	
-	// Old variables
-  $redirect		= variable_get('splash_redirect', NULL);
-  $cookie			= variable_get('splash_cookie', NULL);
-  $frequency	= variable_get('splash_frequency', NULL);
-  $code				= variable_get('splash_code', NULL);
-  
-  // New variables
+  $ret = array();
+
+  // Old variables.
+  $redirect = variable_get('splash_redirect', NULL);
+  $cookie = variable_get('splash_cookie', NULL);
+  $frequency = variable_get('splash_frequency', NULL);
+  $code = variable_get('splash_code', NULL);
+
+  // New variables.
   variable_set('splash_when', array(
-  	'frequency' => (!is_string($frequency) || strlen($frequency) == 0) ? 'always' : $frequency,
-  	'cookie' => (!is_string($cookie) || strlen($frequency) == 0) ? 'splash_cookie' : $cookie,
+    'frequency' => (!is_string($frequency) || strlen($frequency) == 0) ? 'always' : $frequency,
+    'cookie' => (!is_string($cookie) || strlen($frequency) == 0) ? 'splash_cookie' : $cookie,
   ));
   variable_set('splash_what', array(
-  	'content' => (!is_string($redirect) || strlen($redirect) == 0) ? '' : $redirect,
+    'content' => (!is_string($redirect) || strlen($redirect) == 0) ? '' : $redirect,
   ));
 
-  // Code has been moved to Conditions module
+  // Code has been moved to Conditions module.
   if (is_string($code) && strlen($code) > 0) {
-	  drupal_set_message(t('Splash - Install the conditions module to trigger the display by the PHP code you had set: %code', array('%code' => $code)));
+    drupal_set_message(t('Splash - Install the conditions module to trigger the display by the PHP code you had set: %code', array('%code' => $code)));
   }
-	
-	return $ret;
-}
 
-?>
\ No newline at end of file
+  return $ret;
+}
diff --git a/splash.module b/splash.module
index 0df1656..21afdf6 100644
--- a/splash.module
+++ b/splash.module
@@ -1,236 +1,288 @@
 <?php
-
 /**
- * Permissions
+ * @file
+ * Main module file.
+ */
+/**
+ * Implements hook_perm().
  */
 function splash_perm() {
   return array('administer splash');
 }
 
+/**
+ * Implements hook_menu().
+ */
 function splash_menu() {
   $items = array();
-  
-  // Splash (for texts)
+
+  // Splash (for texts).
   $items['splash'] = array(
     'title' => 'Splash',
     'page callback' => 'splash_page',
-    'access arguments' => array('access content'),
+    'access callback' => TRUE,
+    //'access arguments' => TRUE, //array('access content'),
     'type' => MENU_CALLBACK,
   );
-  
-  // Admin
+
+  // 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',
-	);
+    '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,
-	);
+    '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,
-	);
+    '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,
-	);
+    '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() {
+/**
+ * Implements hook_boot().
+ */
+function splash_boot() {
   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 = TRUE;
+  $splash_when = variable_get('splash_when', array());
   $splash_what = variable_get('splash_what', array());
+  // Cookie name is used to allow resetting cookies.
+  // Unique cookies will be identify and reset, if required.
   $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 ***/
-  
+
+
+  // THE WHEN
+  include_once(str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']) . 'includes/common.inc');
+  include_once(str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']) . 'includes/path.inc');
+  include_once(str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']) . 'modules/filter/filter.module');
+
+  $bypass = isset($splash_what['bypass']) && !empty($splash_what['bypass']) ? $splash_what['bypass'] : 'splash';
+  $bypass_words = isset($splash_what['bypass_words']) && !empty($splash_what['bypass_words']) ? $splash_what['bypass_words'] : array('off');
+
   // 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;
+    $splash = FALSE;
+    $reason = 'No WHAT';
+    // Someone knew this special way to get around the splash :)
+  }
+  elseif (isset($_GET[$bypass]) && in_array(strtolower($_GET[$bypass]), $bypass_words)) {
+    $splash = FALSE;
+    $reason = 'Someone knew this special way to get around the splash';
+    // Someone knew this special way to force splash display.
+  }
+  elseif (isset($_GET[$bypass]) && $_GET[$bypass] == '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;
+    // We are not on the front page (cannot use drupal_is_front_page here).
+  }
+  elseif (isset($_GET['q']) && ($_GET['q'] != '') && ($_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';
-			  }
-		  }
-	  }
+    // Front page is splash page?!
   }
-  
-  //dsm($reason);
+  elseif (isset($splash_what['redirect']) && $splash_what['redirect'] && $_GET['q'] == drupal_get_normal_path($splash_what['redirect'])) {
+    $splash = FALSE;
+    $reason = 'Front page is (already) a 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 (empty($cookie_data)) {
+        $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';
+          // Always.
+        }
+        else if ($splash_when['frequency'] == 'always') {
+          $splash = TRUE;
+          $reason = 'Always';
+          // Never.
+        }
+        else {
+          $splash = FALSE;
+          $reason = 'Never';
+        }
+      }
+    }
+  }
+
 
   // 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);
-  	}
+    // 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');
+
+      // Fullscreen or fullscreen_path.
+    }
+    else if ($splash_what['mode'] == 'fullscreen' || $splash_what['mode'] == 'fullscreen_path') {
+      // Because hook_boot() is called before DRUPAL_BOOTSTRAP_LANGUAGE
+      // we need to initialize it here only because we are calling our
+      // implementation of hook_page() directly.
+      drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE);
+      splash_page();
+      // Redirect.
+    }
+    else {
+      drupal_goto($url);
+    }
   }
 }
 
+/**
+ * Implemnts hook_help().
+ */
 function splash_help($path, $arg) {
   switch ($path) {
     case 'admin/settings/splash':
-      return '<p>'. 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: <ul><li>The requested page is not the front page.</li><li>The visitor returns to the frontpage from another page on the same site.</li><li>The splash page is the same as the front page.</li><li>The visitors added <code>?nosplash</code> to the URL.</li></ul>', array('!condition' => l(t('Condition'), 'http://drupal.org/project/condition'))).'</p>';
+      return '<p>' . 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: <ul><li>The requested page is not the front page.</li><li>The visitor returns to the frontpage from another page on the same site.</li><li>The splash page is the same as the front page.</li><li>The visitors added <code>?nosplash</code> to the URL.</li></ul>', array('!condition' => l(t('Condition'), 'http://drupal.org/project/condition'))) . '</p>';
     case 'admin/settings/splash/what':
-      return '<p>'. 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.').'</p>';
+      return '<p>' . 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.') . '</p>';
     case 'admin/settings/splash/how':
-      return '<p>'. 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/'))).'</p>';
+      return '<p>' . 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/'))) . '</p>';
   }
 }
 
+/**
+ * Implements hook_page().
+ */
 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;
+  $splash_what = variable_get('splash_what', array());
+  switch ($splash_what['mode']) {
+    case 'fullscreen':
+      // Render page from entered values.
+      $output = check_markup($splash_what['content'], $splash_what['format'], FALSE);
+      print $output;
+      exit();
+      break;
+    case 'fullscreen_path':
+      // Render page from template specified in the path.
+      include_once($splash_what['content']);
+      exit();
+      break;
+    default:
+      $output = check_markup($splash_what['content'], $splash_what['format'], FALSE);
+      return $output;
   }
 }
-
-?>
\ No newline at end of file
-- 
1.7.4.msysgit.0

