function bootstrap_tour_run_tour in Bootstrap Tour 7
Same name and namespace in other branches
- 7.2 bootstrap_tour.module \bootstrap_tour_run_tour()
Helper function to actually run a tour. Can be called from anywhere.
1 call to bootstrap_tour_run_tour()
- bootstrap_tour_page_build in ./
bootstrap_tour.module - 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 6
Code
function bootstrap_tour_run_tour($name, $force = FALSE) {
$tour = bootstrap_tour_load($name);
if (empty($tour) || !empty($tour->disabled)) {
return;
}
if (!empty($tour->roles)) {
// Compare the tour's roles to the user's roles and if there aren't any overlaps and
// the user isn't user 1, cancel running the tour.
global $user;
$tour_roles = explode(',', $tour->roles);
$user_roles = array_keys($user->roles);
$compare = array_intersect($tour_roles, $user_roles);
if ($user->uid != 1 && empty($compare)) {
return;
}
}
if (!empty($tour->steps) && !is_array($tour->steps)) {
$tour->steps = unserialize($tour->steps);
}
if (count($tour->steps) > 1) {
// Set this as the current tour in the session.
$_SESSION['tour'] = $name;
}
$first_path = $tour->steps[0]['path'];
if ($first_path == current_path() || $first_path == request_path() || $first_path == '<front>' && request_path() == '') {
if (empty($_GET['step']) || $_GET['step'] == 0) {
// We're starting the tour over.
if (!empty($_SESSION['nexttour'])) {
unset($_SESSION['nexttour']);
}
}
}
drupal_alter('bootstrap_tour', $tour);
$step_path = '';
foreach ($tour->steps as $key => &$step) {
// If a path isn't specified, then use the path from the previous step.
if ($step['path']) {
$step_path = $step['path'];
}
else {
$step['path'] = $step_path;
}
// Determine we are on the first step of the tour.
if ($key == 0 && ($step['path'] == current_path() || $step['path'] == request_path() || $step['path'] == '<front>' && request_path() == '')) {
if (!empty($_GET['tour']) && (empty($_GET['step']) || $_GET['step'] == 0)) {
$tour->isFirstStep = TRUE;
}
}
// Filter user supplied content.
$step['title'] = check_plain($step['title']);
$step['content'] = check_markup($step['content'], $step['format']);
}
$tour->force = $force;
$tour->cleanUrls = variable_get('clean_url', 0);
drupal_add_js(array(
'bootstrapTour' => array(
'tour' => $tour,
),
), 'setting');
if (module_exists('libraries') && ($library = libraries_detect('bootstrap_tour')) && !empty($library['installed'])) {
libraries_load('bootstrap_tour');
}
else {
// Grab the Bootstrap Tour JS from CDNJS if the library isn't installed.
global $base_url;
$base = parse_url($base_url);
drupal_add_css($base['scheme'] . '://cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.6.1/css/bootstrap-tour.min.css', 'external');
drupal_add_js($base['scheme'] . '://cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.6.1/js/bootstrap-tour.min.js', 'external');
}
drupal_add_js(drupal_get_path('module', 'bootstrap_tour') . '/js/bootstrap-tour.js');
drupal_add_css(drupal_get_path('module', 'bootstrap_tour') . '/css/bootstrap-tour.css');
}