Exemple #1
0
function wikiplugin_tour($data, $params)
{
    if ($params['show_once'] && $params['show_once'] == 1) {
        if (empty($params['tour_id'])) {
            $tourId = "default";
        } else {
            $tourId = $params['tour_id'];
        }
        $cookie_id = 'tour' . md5($tourId);
        if ($_COOKIE[$cookie_id] == 'y') {
            return;
        }
        setcookie($cookie_id, 'y');
    }
    static $id = 0;
    $unique = 'wptour_' . ++$id;
    static $wp_tour = array('steps' => array());
    $params['template'] = "<div class='popover tour'>\n  <div class='arrow'></div>\n  <h3 class='popover-title'></h3>\n  <div class='popover-content'></div>\n  <div class='popover-navigation'>\n    <button class='btn btn-default' data-role='prev'>« " . tr('Prev') . "</button>\n    <button class='btn btn-default' data-role='next'>" . tr('Next') . " »</button>\n    <button class='btn btn-default' data-role='end'>" . tr('Close Tour') . "</button>\n  </div>\n</div>";
    $headerlib = TikiLib::lib('header');
    $headerlib->add_jsfile('vendor/sorich87/bootstrap-tour/build/js/bootstrap-tour.js')->add_cssfile('vendor/sorich87/bootstrap-tour/build/css/bootstrap-tour.css');
    $defaults = array();
    $plugininfo = wikiplugin_tour_info();
    foreach ($plugininfo['params'] as $key => $param) {
        $defaults["{$key}"] = $param['default'];
    }
    $params = array_merge($defaults, $params);
    // non changing init js in ransk 11 and 13 (the tour definition goes in 12)
    $headerlib->add_jq_onready('var tour;
', 11);
    if ($params['start'] === 'y') {
        $headerlib->add_jq_onready('
if (tour) {
	// Start the tour
	tour.restart();
} else {
	console.log("Warning: Tour not initialized, the last step needs to have parameter next set to -1");
}
', 13);
    }
    unset($params['start']);
    $html = '';
    if ($params['orphan'] == 1) {
        $params['orphan'] = true;
    } else {
        $params['orphan'] = false;
    }
    if (empty($params['element']) && !$params['orphan']) {
        $params['element'] = "#{$unique}";
        $html = '<span id="' . $unique . '"></span>';
    }
    $params['content'] = TikiLib::lib('parser')->parse_data($data);
    $wp_tour['steps'][] = array_filter($params);
    if ($params['next'] == -1 || $params['path']) {
        $js = '// Instance the tour
tour = new Tour(' . json_encode($wp_tour) . ');
';
        $headerlib->add_jq_onready($js, 12);
    }
    return $html;
}
Exemple #2
0
function wikiplugin_tour($data, $params)
{
    $defaults = array();
    $plugininfo = wikiplugin_tour_info();
    foreach ($plugininfo['params'] as $key => $param) {
        $defaults["{$key}"] = $param['default'];
    }
    $params = array_merge($defaults, $params);
    $cookie_id = 'tour' . md5($params['tour_id']);
    if (getCookie($cookie_id, 'tours') == 'y') {
        $dontStart = true;
    } else {
        $dontStart = false;
        if ($params['show_once'] === 'y') {
            setCookieSection($cookie_id, 'y', 'tours');
        }
    }
    static $id = 0;
    $unique = 'wptour_' . ++$id;
    static $wp_tour = array('steps' => array());
    if (!isset($wp_tour['start'])) {
        $wp_tour['start'] = $params['start'];
    }
    $headerlib = TikiLib::lib('header');
    $headerlib->add_jsfile('vendor/sorich87/bootstrap-tour/build/js/bootstrap-tour.js')->add_cssfile('vendor/sorich87/bootstrap-tour/build/css/bootstrap-tour.css');
    // non changing init js in ransk 11 and 13 (the tour definition goes in 12)
    $headerlib->add_jq_onready('var tour;
', 11);
    if ($wp_tour['start'] === 'y' && !$dontStart) {
        $headerlib->add_jq_onready('
if (tour) {
	// Start the tour
	tour.restart();
} else {
	console.log("Warning: Tour not initialized, the last step needs to have parameter next set to -1");
}
', 13);
    }
    unset($params['start']);
    unset($params['tour_id']);
    $html = '';
    $params['orphan'] = $params['orphan'] === 'y';
    $params['backdrop'] = $params['backdrop'] === 'y';
    if (empty($params['element']) && !$params['orphan']) {
        $params['element'] = "#{$unique}";
        $html = '<span id="' . $unique . '"></span>';
        if (!empty($params['show_restart_button'])) {
            $smarty = TikiLib::lib('smarty');
            $smarty->loadPlugin('smarty_function_button');
            $html .= smarty_function_button(['_text' => tra($params['show_restart_button']), '_id' => $unique . '_restart', 'href' => '#'], $smarty);
            $headerlib->add_jq_onready('$("#' . $unique . '_restart").click(function() {
	tour.goTo(0);
	tour.restart();
	return false;
});', 13);
        }
    }
    $params['content'] = TikiLib::lib('parser')->parse_data($data);
    $wp_tour['steps'][] = array_filter($params);
    if ($params['next'] == -1 || $params['path']) {
        $js = '// Instance the tour
tour = new Tour(' . json_encode($wp_tour) . ');
';
        $headerlib->add_jq_onready($js, 12);
    }
    return $html;
}