function bootstrap_tour_page_build in Bootstrap Tour 7
Same name and namespace in other branches
- 7.2 bootstrap_tour.module \bootstrap_tour_page_build()
Implementation of hook_init(). Load all the tours and figure out if any are set to auto-run and start on the current page. If so, go ahead and run that one.
File
- ./
bootstrap_tour.module, line 92
Code
function bootstrap_tour_page_build(&$page) {
// Try and detect if we are in an AJAX request and bail if so.
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
return;
}
$tours = bootstrap_tour_load_all();
// Force a tour to run if the tour name is in the session vars.
$current_name = !empty($_SESSION['tour']) ? $_SESSION['tour'] : NULL;
// We can also jump to a new tour by specifying ?tour=tourname in the query
// string, but only if it's the first step OR in the tour we were already
// on. This is to prevent weird behavior if we switch domains on the same
// site - ie. we shouldn't be able to start a new tour mid-stream.
if (!empty($_GET['tour']) && ($_GET['tour'] == $current_name || empty($_GET['step']))) {
$current_name = $_GET['tour'];
}
if (!empty($current_name)) {
foreach ($tours as $tour) {
if ($tour->name == $current_name) {
bootstrap_tour_run_tour($tour->name, TRUE);
return;
}
}
}
// Force the next tour to run if the tour name is in the session vars.
if (!empty($_SESSION['nexttour'])) {
foreach ($tours as $tour) {
if ($_SESSION['nexttour'] == $tour->name) {
bootstrap_tour_run_tour($tour->name, TRUE);
return;
}
}
}
// Otherwise, only run the tour if it's set to auto-run and we're on the path of one of the steps.
foreach ($tours as $tour) {
if (!empty($tour->steps) && $tour->autorun) {
if (!is_array($tour->steps)) {
$tour->steps = unserialize($tour->steps);
}
$path = $tour->steps[0]['path'];
if ($path == current_path() || $path == request_path() || $path == '<front>' && request_path() == '') {
bootstrap_tour_run_tour($tour->name);
}
}
}
}