| 1 |
<?php
|
| 2 |
//$Id: splash.module,v 1.16 2009/09/01 15:31:55 seanr Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Permissions
|
| 6 |
*/
|
| 7 |
function splash_perm() {
|
| 8 |
return array('administer splash');
|
| 9 |
}
|
| 10 |
|
| 11 |
function splash_menu() {
|
| 12 |
$items = array();
|
| 13 |
|
| 14 |
// Splash (for texts)
|
| 15 |
$items['splash'] = array(
|
| 16 |
'title' => 'Splash',
|
| 17 |
'page callback' => 'splash_page',
|
| 18 |
'access arguments' => array('access content'),
|
| 19 |
'type' => MENU_CALLBACK,
|
| 20 |
);
|
| 21 |
|
| 22 |
// Admin
|
| 23 |
$items['admin/settings/splash'] = array(
|
| 24 |
'title' => 'Splash',
|
| 25 |
'description' => t('Show a splash page before/over the actual frontpage.'),
|
| 26 |
'page callback' => 'drupal_get_form',
|
| 27 |
'page arguments' => array('splash_admin_when'),
|
| 28 |
'access arguments' => array('administer splash'),
|
| 29 |
'file' => 'splash.admin.inc',
|
| 30 |
);
|
| 31 |
$items['admin/settings/splash/when'] = array(
|
| 32 |
'title' => 'When',
|
| 33 |
'description' => t('Set WHEN the splash page is displayed.'),
|
| 34 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 35 |
'access arguments' => array('administer splash'),
|
| 36 |
'weight' => -10,
|
| 37 |
);
|
| 38 |
$items['admin/settings/splash/what'] = array(
|
| 39 |
'title' => 'What',
|
| 40 |
'description' => t('Set WHAT is displayed as the splash page.'),
|
| 41 |
'page arguments' => array('splash_admin_what'),
|
| 42 |
'access arguments' => array('administer splash'),
|
| 43 |
'type' => MENU_LOCAL_TASK,
|
| 44 |
);
|
| 45 |
$items['admin/settings/splash/how'] = array(
|
| 46 |
'title' => 'How',
|
| 47 |
'description' => t('Set HOW the splash page is displayed.'),
|
| 48 |
'page arguments' => array('splash_admin_how'),
|
| 49 |
'access arguments' => array('administer splash'),
|
| 50 |
'type' => MENU_LOCAL_TASK,
|
| 51 |
);
|
| 52 |
|
| 53 |
return $items;
|
| 54 |
}
|
| 55 |
|
| 56 |
function splash_init() {
|
| 57 |
global $base_url;
|
| 58 |
|
| 59 |
if (function_exists('drush_verify_cli') && call_user_func('drush_verify_cli')) {
|
| 60 |
return;
|
| 61 |
}
|
| 62 |
|
| 63 |
$splash = TRUE;
|
| 64 |
$splash_when = variable_get('splash_when', array());
|
| 65 |
$splash_what = variable_get('splash_what', array());
|
| 66 |
$cookie_name = (!empty($splash_when['cookie'])) ? $splash_when['cookie'] : 'splash_cookie';
|
| 67 |
$cookie_data = (!empty($_COOKIE[$cookie_name])) ? (is_numeric($_COOKIE[$cookie_name]) ? array('time' => $_COOKIE[$cookie_name]) : (array) unserialize($_COOKIE[$cookie_name])) : array();
|
| 68 |
|
| 69 |
/*** THE WHEN ***/
|
| 70 |
|
| 71 |
// No WHAT
|
| 72 |
if (empty($splash_what['content'])) {
|
| 73 |
$splash = FALSE;
|
| 74 |
$reason = 'No WHAT';
|
| 75 |
// Someone knew this special way to get around the splash :)
|
| 76 |
} elseif ($_GET['splash'] == 'off') {
|
| 77 |
$splash = FALSE;
|
| 78 |
$reason = 'Someone knew this special way to get around the splash';
|
| 79 |
// Someone knew this special way to force splash display
|
| 80 |
} elseif ($_GET['splash'] == 'on') {
|
| 81 |
$splash = TRUE;
|
| 82 |
$reason = 'Someone knew this special way to force splash display';
|
| 83 |
// We are not on the front page (cannot use drupal_is_front_page here)
|
| 84 |
} elseif ($_GET['q'] != drupal_get_normal_path(variable_get('site_frontpage', 'node'))) {
|
| 85 |
$splash = FALSE;
|
| 86 |
$reason = 'We are not on the front page';
|
| 87 |
// We come from an internal page
|
| 88 |
} elseif (($parsed_url = parse_url($base_url)) && stristr(referer_uri(), $parsed_url['host'])) {
|
| 89 |
$splash = FALSE;
|
| 90 |
$reason = 'We come from an internal page';
|
| 91 |
// Front page is splash page?!
|
| 92 |
} elseif ($splash_what['redirect'] && $_GET['q'] == drupal_get_normal_path($splash_what['redirect'])) {
|
| 93 |
$splash = FALSE;
|
| 94 |
$reason = 'Front page is splash page';
|
| 95 |
} else {
|
| 96 |
|
| 97 |
// Conditions
|
| 98 |
if (module_exists('condition') && is_array($splash_when['conditions'])) {
|
| 99 |
$splash = condition_selection_validate($splash_when['conditions']);
|
| 100 |
$reason = ($splash) ? 'Conditions true' : 'Conditions false';
|
| 101 |
}
|
| 102 |
|
| 103 |
// Frequency
|
| 104 |
if ($splash) {
|
| 105 |
|
| 106 |
// No cookie
|
| 107 |
if (!$cookie_data['time']) {
|
| 108 |
$splash = TRUE;
|
| 109 |
$reason = 'No cookie';
|
| 110 |
|
| 111 |
} else {
|
| 112 |
|
| 113 |
// Once
|
| 114 |
if ($splash_when['frequency'] == 'once') {
|
| 115 |
$splash = FALSE;
|
| 116 |
$reason = 'Once';
|
| 117 |
// Every day
|
| 118 |
} else if ($cookie_data['time'] && $splash_when['frequency'] == 'daily' && (time() - $cookie_data['time'] < 86400)) {
|
| 119 |
$splash = FALSE;
|
| 120 |
$reason = 'Every day';
|
| 121 |
// Every week
|
| 122 |
} else if ($cookie_data['time'] && $splash_when['frequency'] == 'weekly' && (time() - $cookie_data['time'] < 604800)) {
|
| 123 |
$splash = FALSE;
|
| 124 |
$reason = 'Every week';
|
| 125 |
// Never
|
| 126 |
} else if ($splash_when['frequency'] != 'always') {
|
| 127 |
$splash = FALSE;
|
| 128 |
$reason = 'Never';
|
| 129 |
}
|
| 130 |
}
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
| 134 |
//dsm($reason);
|
| 135 |
|
| 136 |
// Show splash
|
| 137 |
if ($splash) {
|
| 138 |
|
| 139 |
/*** THE WHAT ***/
|
| 140 |
|
| 141 |
// Text
|
| 142 |
if ($splash_what['mode'] == 'template' || $splash_what['mode'] == 'fullscreen') {
|
| 143 |
$url = check_url('splash');
|
| 144 |
|
| 145 |
// Path or URL
|
| 146 |
} else {
|
| 147 |
$paths = preg_split('/[\n\r]+/', $splash_what['content']);
|
| 148 |
|
| 149 |
// Sequence
|
| 150 |
if ($splash_what['mode'] == 'sequence') {
|
| 151 |
$last_path = $cookie_data['sequence'];
|
| 152 |
$last_index = array_search($last_path, $paths);
|
| 153 |
|
| 154 |
if ($last_index !== FALSE && count($paths) > $last_index + 1) {
|
| 155 |
$next_index = $last_index + 1;
|
| 156 |
|
| 157 |
} else {
|
| 158 |
$next_index = 0;
|
| 159 |
}
|
| 160 |
|
| 161 |
$cookie_data['sequence'] = $paths[$next_index];
|
| 162 |
|
| 163 |
// Random
|
| 164 |
} else {
|
| 165 |
$next_index = array_rand($paths);
|
| 166 |
}
|
| 167 |
|
| 168 |
$url = check_url($paths[$next_index]);
|
| 169 |
}
|
| 170 |
|
| 171 |
$cookie_data['time'] = time();
|
| 172 |
setcookie($cookie_name, serialize($cookie_data), time() + 31556926, '/');
|
| 173 |
|
| 174 |
/*** THE HOW ***/
|
| 175 |
$splash_how = variable_get('splash_how', array());
|
| 176 |
$size = $splash_how['size'] ? explode('x', $splash_how['size']) : FALSE;
|
| 177 |
|
| 178 |
// Thickbox
|
| 179 |
if (module_exists('thickbox') && ($splash_how['mode'] == 'thickbox')) {
|
| 180 |
//_thickbox_doheader();
|
| 181 |
|
| 182 |
$query = array();
|
| 183 |
$url_parts = parse_url($url);
|
| 184 |
|
| 185 |
// Open external URLs and templated texts in iFrame
|
| 186 |
if ($url_parts['scheme'] || $splash_what['mode'] == 'template') {
|
| 187 |
$query[] = 'TB_iframe=true';
|
| 188 |
}
|
| 189 |
|
| 190 |
// Set size
|
| 191 |
if ($size) {
|
| 192 |
$query[] = 'width='.$size[0].'&height='.$size[1];
|
| 193 |
}
|
| 194 |
|
| 195 |
if (count($query)) {
|
| 196 |
$url = url($url, array('query' => implode('&', $query)));
|
| 197 |
}
|
| 198 |
|
| 199 |
drupal_add_js('$(document).ready(function(){ tb_show("", "'.$url.'") });', 'inline');
|
| 200 |
|
| 201 |
// New window
|
| 202 |
} else if ($splash_how['mode'] == 'window') {
|
| 203 |
$size_str = $size ? ', "width='.$size[0].',height='.$size[1].'"' : '';
|
| 204 |
drupal_add_js('window.onload = function() { window.open("'.$url.'", "splash"'.$size_str.'); }', 'inline');
|
| 205 |
|
| 206 |
// Redirect
|
| 207 |
} else {
|
| 208 |
drupal_goto($url);
|
| 209 |
}
|
| 210 |
}
|
| 211 |
}
|
| 212 |
|
| 213 |
function splash_help($path, $arg) {
|
| 214 |
switch ($path) {
|
| 215 |
case 'admin/settings/splash':
|
| 216 |
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>';
|
| 217 |
case 'admin/settings/splash/what':
|
| 218 |
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>';
|
| 219 |
case 'admin/settings/splash/how':
|
| 220 |
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>';
|
| 221 |
}
|
| 222 |
}
|
| 223 |
|
| 224 |
function splash_page() {
|
| 225 |
$splash_what = variable_get('splash_what', array());
|
| 226 |
$output = check_markup($splash_what['content'], $splash_what['format'], FALSE);
|
| 227 |
|
| 228 |
if ($splash_what['mode'] == 'fullscreen') {
|
| 229 |
echo $output;
|
| 230 |
exit;
|
| 231 |
|
| 232 |
} else {
|
| 233 |
return $output;
|
| 234 |
}
|
| 235 |
}
|
| 236 |
|
| 237 |
?>
|