function smarty_block_add_help($params, $content, $smarty, &$repeat)
{
    global $prefs;
    global $help_sections;
    if (!isset($content)) {
        return;
    }
    if ($prefs['javascript_enabled'] != 'y') {
        return $content;
    }
    if (isset($params['title'])) {
        $section['title'] = $params['title'];
    }
    if (isset($params['id'])) {
        $section['id'] = $params['id'];
    } else {
        $section['id'] = $params['id'] = 'help_section_' . count($help_sections);
    }
    $section['content'] = $content;
    $help_sections[$params['id']] = $section;
    if (!isset($params['show']) or $params['show'] == 'y') {
        global $headerlib;
        $smarty->loadPlugin('smarty_block_self_link');
        $self_link_params['_alt'] = tra('Click for Help');
        $self_link_params['_icon'] = 'help';
        $self_link_params['_ajax'] = 'n';
        $title = tra('Help');
        $headerlib->add_js('
var openEditHelp = function() {
	var opts, edithelp_pos = getCookie("edithelp_position");
	opts = { width: 460, height: 500, title: "' . $title . '", autoOpen: false, beforeclose: function(event, ui) {
		var off = $(this).offsetParent().offset();
   		setCookie("edithelp_position", parseInt(off.left,10) + "," + parseInt(off.top,10) + "," + $(this).offsetParent().width() + "," + $(this).offsetParent().height());
	}};
	if (edithelp_pos) {edithelp_pos = edithelp_pos.split(",");}
	if (edithelp_pos && edithelp_pos.length) {
		opts["position"] = [parseInt(edithelp_pos[0],10), parseInt(edithelp_pos[1],10)];
		opts["width"] = parseInt(edithelp_pos[2],10);
		opts["height"] = parseInt(edithelp_pos[3],10);
	}
	try {
		if ($("#help_sections").dialog) {
			$("#help_sections").dialog("destroy");
		}
	} catch( e ) {
		// IE throws errors destroying a non-existant dialog
	}
	$("#help_sections").dialog(opts).dialog("open");
	
};');
        $self_link_params['_onclick'] = 'openEditHelp();return false;';
        return smarty_block_self_link($self_link_params, "", $smarty);
    } else {
        return;
    }
}
Beispiel #2
0
 function renderInnerOutput($context = array())
 {
     $att_id = $this->getValue();
     if (empty($att_id)) {
         return '';
     }
     if ($context['list_mode'] === 'csv') {
         global $base_url;
         return $base_url . 'tiki-download_item_attachment.php?attId=' . $att_id;
         // should something to do with export_attachment() happen here?
     }
     $attachment = TikiLib::lib('trk')->get_item_attachment($att_id);
     $smarty = TikiLib::lib('smarty');
     $smarty->loadPlugin('smarty_block_self_link');
     $smarty->loadPlugin('smarty_function_icon');
     $link = smarty_block_self_link(array('_script' => 'tiki-download_item_attachment.php', 'attId' => $att_id), smarty_function_icon(array('_id' => 'disk', 'alt' => tra('Download')), $smarty) . ' ' . $attachment['filename'], $smarty);
     return $link;
 }
function smarty_function_interactivetranslation($params, $smarty)
{
    global $headerlib, $smarty;
    $strings = get_collected_strings();
    if (count($strings) == 0) {
        return;
    }
    usort($strings, 'sort_strings_by_length');
    $strings = json_encode($strings);
    // add wrench icon link
    $smarty->loadPlugin('smarty_block_self_link');
    $help .= smarty_block_self_link(array('_icon' => 'wrench', '_script' => 'tiki-edit_languages.php', '_title' => tra('Click here to go to Edit Languages')), '', $smarty);
    $jq = <<<JS
\tvar data = {$strings};
JS;
    $headerlib->add_jq_onready($jq);
    $headerlib->add_jq_onready(file_get_contents('lib/language/js/interactive_translation.js'));
    return $smarty->fetch('interactive_translation_box.tpl');
}
Beispiel #4
0
function smarty_block_add_help($params, $content, $smarty, &$repeat)
{
    global $prefs;
    global $help_sections;
    if (!isset($content)) {
        return;
    }
    if ($prefs['javascript_enabled'] != 'y') {
        return $content;
    }
    if (isset($params['title'])) {
        $section['title'] = $params['title'];
    }
    if (isset($params['id'])) {
        $section['id'] = $params['id'];
    } else {
        $section['id'] = $params['id'] = 'help_section_' . count($help_sections);
    }
    $section['content'] = $content;
    $help_sections[$params['id']] = $section;
    if (!isset($params['show']) or $params['show'] == 'y') {
        $smarty->loadPlugin('smarty_block_self_link');
        $smarty->loadPlugin('smarty_function_icon');
        $self_link_params['_alt'] = tra('Click for Help');
        $self_link_params['_ajax'] = 'n';
        $self_link_params['_anchor'] = $section['id'];
        $self_link_params['_title'] = $section['title'];
        $self_link_params['_class'] = 'help';
        $self_link_params['_onclick'] = '$.openEditHelp(' . (count($help_sections) - 1) . ');return false;';
        $link = '';
        if (empty($params['icononly']) || $params['icononly'] === 'n') {
            $link = $section['title'] . '&nbsp;';
        }
        $link .= smarty_function_icon(array('_id' => 'help'), $smarty);
        return smarty_block_self_link($self_link_params, $link, $smarty);
    } else {
        return;
    }
}
Beispiel #5
0
function smarty_function_button($params, $smarty)
{
    if (!is_array($params) || !isset($params['_text'])) {
        return;
    }
    global $tikilib, $prefs, $auto_query_args;
    $class = null;
    $smarty->loadPlugin('smarty_block_self_link');
    $selected = false;
    if (!empty($params['_selected'])) {
        // Filter the condition
        if (preg_match('/[a-zA-Z0-9 =<>!]+/', $params['_selected'])) {
            $error_report = error_reporting(~E_ALL);
            $return = eval('$selected =' . $params['_selected'] . ";");
            error_reporting($error_report);
            if ($return !== FALSE) {
                if ($selected) {
                    if (!empty($params['_selected_class'])) {
                        $params['_class'] = $params['_selected_class'];
                    } else {
                        $params['_class'] = 'selected';
                    }
                    if (!empty($params['_selected_text'])) {
                        $params['_text'] = $params['_selected_text'];
                    }
                    if (!empty($params['_selected_title'])) {
                        $params['_title'] = $params['_selected_title'];
                    }
                    if (!empty($params['_selected_icon'])) {
                        $params['_icon'] = $params['_selected_icon'];
                    }
                    if (!empty($params['_selected_icon_name'])) {
                        $params['_icon_name'] = $params['_selected_icon_name'];
                    }
                }
            }
        }
    }
    $disabled = false;
    if (!empty($params['_disabled'])) {
        // Filter the condition
        if (preg_match('/[a-zA-Z0-9 =<>!]+/', $params['_disabled'])) {
            $error_report = error_reporting(~E_ALL);
            $return = eval('$disabled =' . $params['_disabled'] . ";");
            error_reporting($error_report);
            if ($return !== FALSE) {
                if ($disabled) {
                    if (!empty($params['_disabled_class'])) {
                        $params['_class'] = $params['_disabled_class'];
                    } else {
                        $params['_class'] = 'disabled';
                    }
                    if (!empty($params['_disabled_text'])) {
                        $params['_text'] = $params['_disabled_text'];
                    }
                    if (!empty($params['_disabled_title'])) {
                        $params['_title'] = $params['_disabled_title'];
                    }
                    if (!empty($params['_disabled_icon'])) {
                        $params['_icon'] = $params['_disabled_icon'];
                    }
                    if (!empty($params['_disabled_icon_name'])) {
                        $params['_icon_name'] = $params['_disabled_icon_name'];
                    }
                }
            }
        }
        unset($params['_disabled']);
    }
    //apply class only to the button
    if (!empty($params['_class'])) {
        $class = $params['_class'];
    }
    if (!empty($params['_id'])) {
        $id = ' id="' . $params['_id'] . '"';
    } else {
        $id = '';
    }
    unset($params['_class']);
    if (!$disabled) {
        $flip_id = '';
        if (!empty($params['_flip_id'])) {
            $params['_onclick'] = "javascript:flip('" . $params['_flip_id'] . "');flip('" . $params['_flip_id'] . "_close','inline');return false;";
            if (!empty($params['_escape']) && $params['_escape'] === 'y') {
                $params['_onclick'] = addslashes($params['_onclick']);
            }
            if (!isset($params['_flip_hide_text']) || $params['_flip_hide_text'] != 'n') {
                $cookie_key = 'show_' . $params['_flip_id'];
                $params['_text'] .= '<span id="' . $params['_flip_id'] . '_close" style="display:' . (isset($_SESSION['tiki_cookie_jar'][$cookie_key]) && $_SESSION['tiki_cookie_jar'][$cookie_key] == 'y' || isset($params['_flip_default_open']) && $params['_flip_default_open'] == 'y' ? 'inline' : 'none') . ';"> (' . tra('Hide') . ')</span>';
            }
        }
        $auto_query_args_orig = $auto_query_args;
        if (!empty($params['_auto_args'])) {
            if ($params['_auto_args'] != '*') {
                if (!isset($auto_query_args)) {
                    $auto_query_args = null;
                }
                $auto_query_args = explode(',', $params['_auto_args']);
            }
        } else {
            $params['_noauto'] = 'y';
        }
        // Remove params that does not start with a '_', since we don't want them to modify the URL except when in auto_query_args
        if (!isset($params['_keepall']) || $params['_keepall'] != 'y') {
            foreach ($params as $k => $v) {
                if ($k[0] != '_' && $k != 'href' && (empty($auto_query_args) || !in_array($k, $auto_query_args))) {
                    unset($params[$k]);
                }
            }
        }
        $url_args = array();
        if (!empty($params['href'])) {
            // Handle anchors
            if (strpos($params['href'], '#')) {
                list($params['href'], $params['_anchor']) = explode('#', $params['href'], 2);
            }
            // Handle script and URL arguments
            if (($pos = strpos($params['href'], '?')) !== false) {
                $params['_script'] = substr($params['href'], 0, $pos);
                TikiLib::parse_str($tikilib->htmldecode(substr($params['href'], $pos + 1)), $url_args);
                $params = array_merge($params, $url_args);
            } else {
                $params['_script'] = $params['href'];
            }
            unset($params['href']);
        }
        $html = smarty_block_self_link($params, $params['_text'], $smarty);
    } else {
        $params['_disabled'] = 'y';
        $html = smarty_block_self_link($params, $params['_text'], $smarty);
    }
    $type = isset($params['_type']) ? $params['_type'] : 'default';
    $auto_query_args = $auto_query_args_orig;
    $html = preg_replace('/<a /', '<a class="btn btn-' . $type . ' ' . $class . '" data-role="button" data-inline="true" ' . $id . ' ', $html);
    return $html;
}
            header("Location: {$fromUrl}");
            exit;
        }
    }
}
// remove image from an image field
if (isset($_REQUEST["removeImage"])) {
    $img_field = array('data' => array());
    $img_field['data'][] = array('fieldId' => $_REQUEST["fieldId"], 'type' => 'i', 'name' => $_REQUEST["fieldName"], 'value' => 'blank');
    $trklib->replace_item($_REQUEST["trackerId"], $_REQUEST["itemId"], $img_field);
    $_REQUEST['show'] = "mod";
}
// ************* return to list ***************************
if (isset($_REQUEST["returntracker"]) || isset($_REQUEST["save_return"])) {
    require_once 'lib/smarty_tiki/block.self_link.php';
    header('Location: ' . smarty_block_self_link(array('_script' => 'tiki-view_tracker.php', '_tag' => 'n', '_urlencode' => 'n', 'itemId' => 'NULL', 'trackerId' => $_REQUEST['trackerId']), '', $smarty));
    die;
}
// ********************************************************
if (isset($tracker_info['useRatings']) and $tracker_info['useRatings'] == 'y' and $tiki_p_tracker_vote_ratings == 'y') {
    if ($user and $tiki_p_tracker_vote_ratings == 'y' and isset($rateFieldId) and isset($_REQUEST['ins_' . $rateFieldId])) {
        $trklib->replace_rating($_REQUEST['trackerId'], $_REQUEST['itemId'], $rateFieldId, $user, $_REQUEST['ins_' . $rateFieldId]);
        header('Location: tiki-view_tracker_item.php?trackerId=' . $_REQUEST['trackerId'] . '&itemId=' . $_REQUEST['itemId']);
        die;
    }
}
if ($_REQUEST["itemId"]) {
    $info = $trklib->get_tracker_item($_REQUEST["itemId"]);
    $itemObject = Tracker_Item::fromInfo($info);
    if (!isset($info['trackerId'])) {
        $info['trackerId'] = $_REQUEST['trackerId'];
Beispiel #7
0
function smarty_block_textarea($params, $content, $smarty, $repeat)
{
    static $included = false;
    global $prefs, $headerlib, $smarty, $is_html;
    if ($repeat) {
        return;
    }
    if (!$included) {
        $headerlib->add_js(<<<JS
                function GetCurrentEditorAreaId(ob){
        var p;
        p=ob.parentNode;
        while(p.className != "edit-zone"){p=p.parentNode;}
        areaid=p.id.substring(10);
        //alert ("areaid="+areaid);
        return areaid;
    }
JS
);
    }
    // some defaults
    $params['_toolbars'] = isset($params['_toolbars']) ? $params['_toolbars'] : 'y';
    if ($prefs['mobile_feature'] === 'y' && $prefs['mobile_mode'] === 'y') {
        $params['_toolbars'] = 'n';
    }
    if ($prefs['javascript_enabled'] != 'y') {
        $params['_toolbars'] = 'n';
    }
    $params['_simple'] = isset($params['_simple']) ? $params['_simple'] : 'n';
    if (!isset($params['_wysiwyg'])) {
        if ($params['_simple'] === 'n') {
            // should not be set usually(?)
            include_once 'lib/setup/editmode.php';
            $params['_wysiwyg'] = $_SESSION['wysiwyg'];
        } else {
            $params['_wysiwyg'] = 'n';
        }
    }
    if ($is_html === null) {
        // sometimes $is_html has not been set, so take an educated guess
        if ($params['_wysiwyg'] === 'y' && $prefs['wysiwyg_htmltowiki'] !== 'y') {
            $is_html = true;
        }
    }
    $params['_is_html'] = isset($params['_is_html']) ? $params['_is_html'] : $is_html;
    $params['name'] = isset($params['name']) ? $params['name'] : 'edit';
    $params['id'] = isset($params['id']) ? $params['id'] : 'editwiki';
    $params['area_id'] = isset($params['area_id']) ? $params['area_id'] : $params['id'];
    // legacy param for toolbars?
    $params['class'] = isset($params['class']) ? $params['class'] : 'wikiedit';
    $params['comments'] = isset($params['comments']) ? $params['comments'] : 'n';
    $params['autosave'] = isset($params['autosave']) ? $params['autosave'] : 'y';
    //codemirror integration
    if ($prefs['feature_syntax_highlighter'] === 'y') {
        $params['data-codemirror'] = isset($params['codemirror']) ? $params['codemirror'] : '';
        $params['data-syntax'] = isset($params['syntax']) ? $params['syntax'] : '';
    }
    //keep params html5 friendly
    unset($params['codemirror']);
    unset($params['syntax']);
    // mainly for modules admin - preview is for the module, not the custom module so don;t need to confirmExit
    $params['_previewConfirmExit'] = isset($params['_previewConfirmExit']) ? $params['_previewConfirmExit'] : 'y';
    if (!isset($params['section'])) {
        global $section;
        $params['section'] = $section ? $section : 'wiki page';
    }
    if (!isset($params['style']) && !isset($params['cols'])) {
        $params['style'] = 'width:99%';
    }
    $html = '';
    if (!$included) {
        $html .= '<input type="hidden" name="mode_wysiwyg" value="" /><input type="hidden" name="mode_normal" value="" />';
    }
    $auto_save_referrer = '';
    $auto_save_warning = '';
    $as_id = $params['id'];
    $smarty->loadPlugin('smarty_block_remarksbox');
    $tmp_var = $smarty->getTemplateVars('page');
    $editWarning = $prefs['wiki_timeout_warning'] === 'y' && isset($tmp_var) && $tmp_var !== 'sandbox';
    if ($params['_simple'] === 'n' && $editWarning) {
        $remrepeat = false;
        $html .= smarty_block_remarksbox(array('type' => 'tip', 'title' => tra('Tip')), tra('This edit session will expire in') . ' <span id="edittimeout">' . ini_get('session.gc_maxlifetime') / 60 . '</span> ' . tra('minutes') . '. ' . tra('<strong>Preview</strong> (if available) or <strong>Save</strong> your work to restart the edit session timer'), $smarty, $remrepeat) . "\n";
        if ($prefs['javascript_enabled'] === 'y') {
            $html = str_replace('<div class="clearfix rbox tip">', '<div class="clearfix rbox tip" style="display:none;">', $html);
            // quickfix to stop this box appearing before doc.ready
        }
    }
    $smarty->assign('comments', $params['comments']);
    // 3 probably removable assigns
    $smarty->assign('switcheditor', isset($params['switcheditor']) ? $params['switcheditor'] : 'n');
    $smarty->assign('toolbar_section', $params['section']);
    if ($prefs['feature_ajax'] == 'y' && $prefs['ajax_autosave'] == 'y' && $params['_simple'] == 'n' && $params['autosave'] == 'y') {
        // retrieve autosaved content
        require_once "lib/ajax/autosave.php";
        $smarty->loadPlugin('smarty_block_self_link');
        $auto_save_referrer = ensureReferrer();
        if (empty($_REQUEST['autosave'])) {
            $_REQUEST['autosave'] = 'n';
        }
        if (has_autosave($as_id, $auto_save_referrer)) {
            //  and $params['preview'] == 0 -  why not?
            $auto_saved = str_replace("\n", "\r\n", get_autosave($as_id, $auto_save_referrer));
            if (strcmp($auto_saved, $content) === 0) {
                $auto_saved = '';
            }
            if (empty($auto_saved) || isset($_REQUEST['mode_wysiwyg']) && $_REQUEST['mode_wysiwyg'] === 'y') {
                // switching modes, ignore auto save
                remove_save($as_id, $auto_save_referrer);
            } else {
                $msg = '<div class="mandatory_star"><span class="autosave_message">' . tra('There is an autosaved draft of your recent edits, to use it instead of what is current displayed') . '</span>&nbsp;' . '<span class="autosave_message_2" style="display:none;">' . tra('If you want the original version instead of the autosaved draft of your edits') . '</span>' . smarty_block_self_link(array('_ajax' => 'n', '_onclick' => 'toggle_autosaved(\'' . $as_id . '\',\'' . $auto_save_referrer . '\');return false;'), tra('click here'), $smarty) . "</div>";
                $remrepeat = false;
                $auto_save_warning = smarty_block_remarksbox(array('type' => 'info', 'title' => tra('AutoSave')), $msg, $smarty, $remrepeat) . "\n";
            }
        }
        $headerlib->add_jq_onready("register_id('{$as_id}','" . addcslashes($auto_save_referrer, "'") . "');");
        $headerlib->add_js("var autoSaveId = '" . addcslashes($auto_save_referrer, "'") . "';");
    }
    if ($params['_wysiwyg'] == 'y' && $params['_simple'] == 'n') {
        // TODO cope with wysiwyg and simple
        if ($prefs['feature_jison_wiki_parser'] == 'y') {
            global $wysiwyglib;
            include_once 'lib/ckeditor_tiki/wysiwyglib.php';
            $html .= $wysiwyglib->setUpJisonEditor($params['_is_html'], $as_id, $params, $auto_save_referrer);
            if (!$included) {
                $html .= '<input name="jisonWyisywg" type="hidden" value="true" />';
            }
            $html .= '<div class="wikiedit ui-widget-content" name="' . $params['name'] . '" id="' . $as_id . '">' . $content . '</div>';
        } else {
            // set up ckeditor
            if (!isset($params['name'])) {
                $params['name'] = 'edit';
            }
            global $wysiwyglib;
            include_once 'lib/ckeditor_tiki/wysiwyglib.php';
            $ckoptions = $wysiwyglib->setUpEditor($params['_is_html'], $as_id, $params, $auto_save_referrer);
            if (!$included) {
                $html .= '<input type="hidden" name="wysiwyg" value="y" />';
            }
            $html .= '<textarea class="wikiedit" name="' . $params['name'] . '" id="' . $as_id . '" style="visibility:hidden;';
            // missing closing quotes, closed in condition
            if (empty($params['cols'])) {
                $html .= 'width:100%;' . (empty($params['rows']) ? 'height:500px;' : '') . '"';
            } else {
                $html .= '" cols="' . $params['cols'] . '"';
            }
            if (!empty($params['rows'])) {
                $html .= ' rows="' . $params['rows'] . '"';
            }
            $html .= '>' . htmlspecialchars($content) . '</textarea>';
            $headerlib->add_jq_onready('
CKEDITOR.replace( "' . $as_id . '",' . $ckoptions . ');
CKEDITOR.on("instanceReady", function(event) {
	if (typeof ajaxLoadingHide == "function") { ajaxLoadingHide(); }
	this.instances.' . $as_id . '.resetDirty();
});
', 20);
            // after dialog tools init (10)
        }
    } else {
        // end of if ( $params['_wysiwyg'] == 'y' && $params['_simple'] == 'n')
        // setup for wiki editor
        $params['rows'] = !empty($params['rows']) ? $params['rows'] : 20;
        $params['cols'] = !empty($params['cols']) ? $params['cols'] : 80;
        $textarea_attributes = '';
        foreach ($params as $k => $v) {
            if ($k[0] != '_' && !in_array($k, array('comments', 'switcheditor', 'section', 'area_id', 'autosave'))) {
                $textarea_attributes .= ' ' . $k . '="' . $v . '"';
            }
        }
        if (empty($textarea_id)) {
            $smarty->assign('textarea_id', $params['id']);
        }
        $smarty->assign('textarea__toolbars', $params['_toolbars']);
        if ($textarea_attributes != '') {
            $smarty->assign('textarea_attributes', $textarea_attributes);
        }
        $smarty->assignByRef('textareadata', $content);
        $html .= $smarty->fetch('wiki_edit.tpl');
        if (!$included) {
            $html .= "\n" . '<input type="hidden" name="wysiwyg" value="n" />';
        }
    }
    // wiki or wysiwyg
    $js_editconfirm = '';
    $js_editlock = '';
    if ($params['_simple'] == 'n' && $params['comments'] !== 'y') {
        // Display edit time out
        $js_editlock .= "\nvar editTimeoutSeconds = " . (int) ini_get('session.gc_maxlifetime') . ";\nvar editTimeElapsedSoFar = 0;\nvar editTimeoutIntervalId;\nvar editTimerWarnings = 0;\nvar editTimeoutTipIsDisplayed = false;\nvar minutes;\n\n// edit timeout warnings\nfunction editTimerTick() {\n\teditTimeElapsedSoFar++;\n\n\tvar seconds = editTimeoutSeconds - editTimeElapsedSoFar;\n\tvar edittimeout = \$('#edittimeout');\n\n\tif ( edittimeout && seconds <= 300 ) {\n\t\tif ( ! editTimeoutTipIsDisplayed ) {\n\t\t\tedittimeout.parents('.rbox:first').fadeIn();\n\t\t\teditTimeoutTipIsDisplayed = true;\n\t\t}\n\t\tif ( seconds > 0 && seconds % 60 == 0 ) {\n\t\t\tminutes = seconds / 60;\n\t\t\tedittimeout.text( minutes );\n\t\t} else if ( seconds <= 0 ) {\n\t\t\tedittimeout.parents('.rbox-data:first').text('" . addslashes(tra('Your edit session has expired')) . "');\n\t\t}\n\t}\n\n\tif (editTimerWarnings == 0 && seconds <= 60 && editorDirty) {\n\t\talert('" . addslashes(tra('Your edit session will expire in:')) . ' 1 ' . tra('minute') . '. ' . addslashes(tra('You must PREVIEW or SAVE your work now, to avoid losing your edits.')) . "');\n\t\teditTimerWarnings++;\n\t} else if (seconds <= 0) {\n\t\tclearInterval(editTimeoutIntervalId);\n\t\teditTimeoutIntervalId = 0;\n\t\twindow.status = '" . addslashes(tra('Your edit session has expired')) . "';\n\t} else if (seconds <= 300) {\t\t// don't bother until 5 minutes to go\n\t\twindow.status = '" . addslashes(tra('Your edit session will expire in:')) . "' + \" \" + minutes + ':' + ((seconds % 60 < 10) ? '0' : '') + (seconds % 60);\n\t}\n}\n\n\$('document').ready( function() {\n\teditTimeoutIntervalId = setInterval(editTimerTick, 1000);\n\t\$('#edittimeout').parents('.rbox:first').hide();\n} );\n\n// end edit timeout warnings\n\n";
        $js_editconfirm .= "\n\$(window).on('beforeunload', function(e) {\n\tif (window.needToConfirm) {\n\t\tif (typeof CKEDITOR === 'object') {\n\t\t\tfor(var ed in CKEDITOR.instances ) {\n\t\t\t\tif (CKEDITOR.instances.hasOwnProperty(ed)) {\n\t\t\t\t\tif ( CKEDITOR.instances[ed].checkDirty()) {\n\t\t\t\t\t\teditorDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (editorDirty) {\n\t\t\tvar msg = '" . addslashes(tra('You are about to leave this page. Changes since your last save may be lost. Are you sure you want to exit this page?')) . "';\n\t\t\tif (e) {\n\t\t\t\te.returnValue = msg;\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\t}\n});\n\n\n\$('document').ready( function() {\n\t// attach dirty function to all relevant inputs etc for wiki/newsletters, blog, article and trackers (trackers need {teaxtarea} implementing)\n\tif ('{$as_id}' === 'editwiki' || '{$as_id}' === 'blogedit' || '{$as_id}' === 'body' || '{$as_id}'.indexOf('area_') > -1) {\n\t\t\$(\$('#{$as_id}').prop('form')).find('input, textarea, select').change( function () { if (!editorDirty) { editorDirty = true; } });\n\t} else {\t// modules admin exception, only attach to this textarea, although these should be using _simple mode\n\t\t\$('#{$as_id}').change( function () { if (!editorDirty) { editorDirty = true; } });\n\t}\n});\n\nneedToConfirm = true;\neditorDirty = " . (isset($_REQUEST["preview"]) && $params['_previewConfirmExit'] == 'y' ? 'true' : 'false') . ";\n";
        if ($prefs['feature_wysiwyg'] == 'y' && $prefs['wysiwyg_optional'] == 'y') {
            $js_editconfirm .= '
function switchEditor(mode, form) {
	window.needToConfirm=false;
	var w;
	if (mode=="wysiwyg") {
		$(form).find("input[name=mode_wysiwyg]").val("y");
		$(form).find("input[name=wysiwyg]").val("y");
	} else {
		$(form).find("input[name=mode_normal]").val("y");
		$(form).find("input[name=wysiwyg]").val("n");
	}
	form.submit();
}';
        }
        if ($prefs['feature_jquery_ui'] == 'y' && $params['_wysiwyg'] != 'y') {
            // show hidden parent before applying resizable
            $js_editconfirm .= "\n\tvar hiddenParents = \$('#{$as_id}').parents('fieldset:hidden:last');\n\n\tif (hiddenParents.length) { hiddenParents.show(); }";
            if (!isset($_REQUEST['fullcalendar'])) {
                $js_editconfirm .= "\n\tif (typeof CodeMirror === 'undefined') { //so as not to conflict with CodeMirror resize\n\t\t\$('#{$as_id}')\n\t\t\t.resizable( {\n\t\t\t\tminWidth: \$('#{$as_id}').width(),\n\t\t\t\tminHeight: 50\n\t\t});\n\t}";
            }
            $js_editconfirm .= "\n\tif (hiddenParents.length) { hiddenParents.hide(); }\n";
        }
        if ($editWarning) {
            $headerlib->add_js($js_editlock);
        }
        $headerlib->add_js($js_editconfirm);
    }
    // end if ($params['_simple'] == 'n')
    $included = true;
    return $auto_save_warning . $html;
}
Beispiel #8
0
 function getTreeHTML($galleryIdentifier = NULL)
 {
     global $prefs, $smarty;
     require_once 'lib/tree/BrowseTreeMaker.php';
     $galleryIdentifier = is_null($galleryIdentifier) ? $prefs['fgal_root_id'] : $galleryIdentifier;
     $subGalleries = $this->getSubGalleries($galleryIdentifier);
     $smarty->loadPlugin('smarty_function_icon');
     $icon = '&nbsp;' . smarty_function_icon(array('_id' => 'folder'), $smarty) . '&nbsp;';
     $smarty->loadPlugin('smarty_block_self_link');
     $linkParameters = array('_script' => 'tiki-list_file_gallery.php', '_class' => 'fgalname');
     if (!empty($_REQUEST['filegals_manager'])) {
         $linkParameters['filegals_manager'] = $_REQUEST['filegals_manager'];
     }
     $nodes = array();
     foreach ($subGalleries['data'] as $subGallery) {
         $linkParameters['galleryId'] = $subGallery['id'];
         $nodes[] = array('id' => $subGallery['id'], 'parent' => $subGallery['parentId'], 'data' => smarty_block_self_link($linkParameters, $icon . htmlspecialchars($subGallery['name']), $smarty));
     }
     $browseTreeMaker = new BrowseTreeMaker('Galleries');
     return $browseTreeMaker->make_tree($this->getGallerySpecialRoot($galleryIdentifier), $nodes);
 }
Beispiel #9
0
function wikiplugin_snarf($data, $params)
{
    global $prefs;
    static $url = '';
    static $snarf;
    static $isFresh = true;
    static $iSnarf = 0;
    ++$iSnarf;
    if (empty($params['url'])) {
        return '';
    }
    $smarty = TikiLib::lib('smarty');
    $tikilib = TikiLib::lib('tiki');
    if (!empty($params['ajax'])) {
        $params['iSnarf'] = $iSnarf;
        $params['href'] = '';
        $params['link'] = '-';
        foreach ($params as $key => $value) {
            if ($key == 'ajax' || $key == 'href') {
                continue;
            }
            if (!empty($params['href'])) {
                $params['href'] .= '&amp;';
            }
            $params['href'] .= $key . '=' . urlencode($value);
        }
        $smarty->assign('snarfParams', $params);
        return $smarty->fetch('wiki-plugins/wikiplugin_snarf.tpl');
    }
    if ($url != $params['url']) {
        // already fetch in the page
        if (isset($_REQUEST['snarf_refresh']) && $_REQUEST['snarf_refresh'] == $params['url']) {
            $cachetime = 0;
            unset($_REQUEST['snarf_refresh']);
        } elseif (isset($params['cache']) && $params['cache'] >= 0) {
            $cachetime = $params['cache'] * 60;
        } else {
            $cachetime = $prefs['wikiplugin_snarf_cache'];
        }
        $info = $tikilib->get_cached_url($params['url'], $isFresh, $cachetime);
        $snarf = $info['data'];
        $url = $params['url'];
    }
    // If content is HTML, keep only the content of the body
    if (isset($params['ishtml']) && $params['ishtml'] == 1) {
        // Not using preg_replace due to its limitations to 100.000 characters
        $snarf = preg_replace('/^.*<\\s*body[^>]*>/i', '', $snarf);
        $snarf = preg_replace('/<\\s*\\/body[^>]*>.*$/i', '', $snarf);
    }
    // If the user specified a more specialized regex
    if (isset($params['regex']) && isset($params['regexres'])) {
        // fixes http://dev.tiki.org/item4059
        $params['regex'] = str_replace("", "", $params['regex']);
        if (preg_match('/^(.)(.)+\\1[^e]*$/', $params['regex'])) {
            $snarf = preg_replace($params['regex'], $params['regexres'], $snarf);
        }
    }
    if ($data == '') {
        $data = NULL;
    }
    $code_defaults = array('caption' => $data, 'wrap' => '1', 'colors' => NULL, 'wiki' => '0', 'ln' => NULL, 'rtl' => NULL, 'ishtml' => NULL);
    foreach ($code_defaults as $k => $v) {
        if (isset($params[$k])) {
            $code_defaults[$k] = $params[$k];
        }
        if ($code_defaults[$k] === NULL) {
            unset($code_defaults[$k]);
        }
    }
    include_once 'lib/wiki-plugins/wikiplugin_code.php';
    $ret = wikiplugin_code($snarf, $code_defaults);
    if (!$isFresh && empty($params['link'])) {
        include_once 'lib/smarty_tiki/block.self_link.php';
        $icon = '<div style="text-align:right">' . smarty_block_self_link(array('_icon' => 'arrow_refresh', 'snarf_refresh' => $params['url']), '', $smarty) . '</div>';
        $ret = $icon . $ret;
    }
    return $ret;
}
Beispiel #10
0
 function getSelfLink($click, $title, $class)
 {
     // {{{
     global $prefs;
     $smarty = TikiLib::lib('smarty');
     $params = array();
     $params['_onclick'] = $click . (substr($click, strlen($click) - 1) != ';' ? ';' : '') . 'return false;';
     $params['_class'] = 'toolbar btn btn-xs btn-link tips' . (!empty($class) ? ' ' . $class : '');
     $params['_ajax'] = 'n';
     $content = $title;
     if ($this->iconname) {
         $params['_icon_name'] = $this->iconname;
         $colon = $prefs['javascript_enabled'] === 'y' ? ':' : '';
         $params['_title'] = $colon . $title;
     } else {
         $params['_icon'] = $this->icon;
     }
     if (strpos($class, 'qt-plugin') !== false && ($this->iconname == 'plugin' || $this->icon == 'img/icons/plugin.png')) {
         $params['_menu_text'] = 'y';
         $params['_menu_icon'] = 'y';
     }
     return smarty_block_self_link($params, $content, $smarty);
 }
Beispiel #11
0
	function getWikiHtml( $areaId, $comments='' ) // {{{
	{
		global $tiki_p_admin, $tiki_p_admin_toolbars, $smarty, $section, $prefs, $headerlib;
		$html = '';

		// $.selection() is in jquery.autocomplete.min.js
		
		if ($prefs['feature_jquery_autocomplete'] != 'y') {
			$headerlib->add_jsfile('lib/jquery/jquery-autocomplete/jquery.autocomplete.min.js');
		}
		
		$c = 0;
		foreach ( $this->lines as $line ) {
			$lineHtml = '';
			$right = '';
			if (count($line) == 1) {
				$line[1] = array();
			}
			
			// $line[0] is left part, $line[1] right floated section
			for ($bitx = 0, $bitxcount_line = count($line); $bitx < $bitxcount_line; $bitx++ ) {
				$lineBit = '';
				
				if ($c == 0 && $bitx == 1 && ($tiki_p_admin == 'y' or $tiki_p_admin_toolbars == 'y')) {
					$params = array('_script' => 'tiki-admin_toolbars.php', '_onclick' => 'needToConfirm = true;', '_class' => 'toolbar', '_icon' => 'wrench', '_ajax' => 'n');
					if (isset($comments) && $comments == 'y')
						$params['comments'] = 'on';
					if (isset($section))
						$params['section'] = $section;
					$content = tra('Admin Toolbars');
					$right .= smarty_block_self_link($params, $content, $smarty);
				}
			
				foreach ( $line[$bitx] as $group ) {
					$groupHtml = '';
					foreach ( $group as $tag ) {
						$groupHtml .= $tag->getWikiHtml($areaId);
					}
					
					if ( !empty($groupHtml) ) {
						$param = empty($lineBit) ? '' : ' class="toolbar-list"';
						$lineBit .= "<span$param>$groupHtml</span>";
					}
					if ($bitx == 1) {
						if (!empty($right)) {
							$right = '<span class="toolbar-list">' . $right . '</span>';
						}
						$lineHtml = "<div class='helptool-admin'>$lineBit $right</div>" . $lineHtml;
					} else {
						$lineHtml = $lineBit;
					}
				}
				
				// adding admin icon if no right part - messy - TODO better
				if ($c == 0 && empty($lineBit) && !empty($right)) {
					$lineHtml .= "<div class='helptool-admin'>$right</div>";
				} 
			}
			if ( !empty($lineHtml) ) {
				$html .= "<div>$lineHtml</div>";
			}
			$c++;
		}

		return $html;
	} // }}}
Beispiel #12
0
 function getSelfLink($click, $title, $class)
 {
     // {{{
     global $smarty, $prefs;
     $params = array();
     $params['_onclick'] = $click . (substr($click, strlen($click) - 1) != ';' ? ';' : '') . 'return false;';
     $params['_class'] = 'toolbar ' . (!empty($class) ? ' ' . $class : '');
     $params['_ajax'] = 'n';
     $content = $title;
     $params['_icon'] = $this->icon;
     if (strpos($class, 'qt-plugin') !== false && $this->icon == 'img/icons/plugin.png') {
         $params['_menu_text'] = 'y';
         $params['_menu_icon'] = 'y';
     }
     if ($prefs['mobile_mode'] !== 'y') {
         return smarty_block_self_link($params, $content, $smarty);
     } else {
         return str_replace('<a ', '<a data-role="button" ', smarty_block_self_link($params, $content, $smarty));
     }
 }
Beispiel #13
0
function smarty_block_textarea($params, $content, $smarty, $repeat)
{
    global $prefs, $is_html, $tiki_p_admin;
    $headerlib = TikiLib::lib('header');
    if ($repeat) {
        return;
    }
    // some defaults
    $params['_toolbars'] = isset($params['_toolbars']) ? $params['_toolbars'] : 'y';
    if ($prefs['javascript_enabled'] != 'y') {
        $params['_toolbars'] = 'n';
    }
    $params['_simple'] = isset($params['_simple']) ? $params['_simple'] : 'n';
    if (!isset($params['_wysiwyg'])) {
        if ($params['_simple'] === 'n') {
            // should not be set usually(?)
            include_once 'lib/setup/editmode.php';
            $params['_wysiwyg'] = $_SESSION['wysiwyg'];
        } else {
            $params['_wysiwyg'] = 'n';
        }
    }
    if ($is_html === null) {
        // sometimes $is_html has not been set, so take an educated guess
        if ($params['_wysiwyg'] === 'y' && $prefs['wysiwyg_htmltowiki'] !== 'y') {
            $is_html = true;
        }
    }
    $params['_is_html'] = isset($params['_is_html']) ? $params['_is_html'] : $is_html;
    $params['name'] = isset($params['name']) ? $params['name'] : 'edit';
    $params['id'] = isset($params['id']) ? $params['id'] : 'editwiki';
    $params['area_id'] = isset($params['area_id']) ? $params['area_id'] : $params['id'];
    // legacy param for toolbars?
    $params['class'] = isset($params['class']) ? $params['class'] : 'wikiedit form-control';
    $params['comments'] = isset($params['comments']) ? $params['comments'] : 'n';
    $params['autosave'] = isset($params['autosave']) ? $params['autosave'] : 'y';
    //codemirror integration
    if ($prefs['feature_syntax_highlighter'] === 'y') {
        $params['data-codemirror'] = isset($params['codemirror']) ? $params['codemirror'] : '';
        $params['data-syntax'] = isset($params['syntax']) ? $params['syntax'] : '';
    }
    //keep params html5 friendly
    unset($params['codemirror']);
    unset($params['syntax']);
    // mainly for modules admin - preview is for the module, not the custom module so don;t need to confirmExit
    $params['_previewConfirmExit'] = isset($params['_previewConfirmExit']) ? $params['_previewConfirmExit'] : 'y';
    if (!isset($params['section'])) {
        global $section;
        $params['section'] = $section ? $section : 'wiki page';
    }
    $html = '';
    $html .= '<input type="hidden" name="mode_wysiwyg" value="" /><input type="hidden" name="mode_normal" value="" />';
    $auto_save_referrer = '';
    $auto_save_warning = '';
    $as_id = $params['id'];
    $smarty->loadPlugin('smarty_block_remarksbox');
    $tmp_var = $smarty->getTemplateVars('page');
    $editWarning = $prefs['wiki_timeout_warning'] === 'y' && isset($tmp_var) && $tmp_var !== 'sandbox';
    if ($params['_simple'] === 'n' && $editWarning) {
        $remrepeat = false;
        $html .= smarty_block_remarksbox(array('type' => 'warning', 'title' => tra('Warning')), '<p>' . tra('This edit session will expire in') . ' <span id="edittimeout">' . ini_get('session.gc_maxlifetime') / 60 . '</span> ' . tra('minutes') . '. ' . tra('<strong>Preview</strong> (if available) or <strong>Save</strong> your work to restart the edit session timer') . '</p>', $smarty, $remrepeat) . "\n";
        if ($prefs['javascript_enabled'] === 'y') {
            $html = str_replace('<div class="alert alert-warning alert-dismissable">', '<div class="alert alert-warning alert-dismissable" style="display:none;">', $html);
            // quickfix to stop this box appearing before doc.ready
        }
    }
    $params['switcheditor'] = isset($params['switcheditor']) ? $params['switcheditor'] : 'y';
    $smarty->assign('comments', $params['comments']);
    // 3 probably removable assigns
    $smarty->assign('switcheditor', $params['switcheditor']);
    $smarty->assign('toolbar_section', $params['section']);
    if ($prefs['feature_ajax'] == 'y' && $prefs['ajax_autosave'] == 'y' && $params['_simple'] == 'n' && $params['autosave'] == 'y') {
        // retrieve autosaved content
        $smarty->loadPlugin('smarty_block_self_link');
        $auto_save_referrer = TikiLib::lib('autosave')->ensureReferrer();
        if (empty($_REQUEST['autosave'])) {
            $_REQUEST['autosave'] = 'n';
        }
        if (TikiLib::lib('autosave')->has_autosave($as_id, $auto_save_referrer)) {
            //  and $params['preview'] == 0 -  why not?
            $auto_saved = str_replace("\n", "\r\n", TikiLib::lib('autosave')->get_autosave($as_id, $auto_save_referrer));
            if (strcmp($auto_saved, $content) === 0) {
                $auto_saved = '';
            }
            if (empty($auto_saved) || isset($_REQUEST['mode_wysiwyg']) && $_REQUEST['mode_wysiwyg'] === 'y') {
                // switching modes, ignore auto save
                TikiLib::lib('autosave')->remove_save($as_id, $auto_save_referrer);
            } else {
                $msg = '<div class="mandatory_star"><span class="autosave_message">' . tra('There is an autosaved draft of your recent edits, to use it instead ') . '</span>&nbsp;' . '<span class="autosave_message_2" style="display:none;">' . tra('If you want the original instead of the autosaved draft of your edits') . '</span>' . smarty_block_self_link(array('_ajax' => 'n', '_onclick' => 'toggle_autosaved(\'' . $as_id . '\',\'' . $auto_save_referrer . '\');return false;'), tra('click here'), $smarty) . "</div>";
                $remrepeat = false;
                $auto_save_warning = smarty_block_remarksbox(array('type' => 'info', 'title' => tra('AutoSave')), $msg, $smarty, $remrepeat) . "\n";
            }
        }
        $headerlib->add_jq_onready("register_id('{$as_id}','" . addcslashes($auto_save_referrer, "'") . "');");
        $headerlib->add_js("var autoSaveId = '" . addcslashes($auto_save_referrer, "'") . "';");
    }
    if ($params['_wysiwyg'] == 'y' && $params['_simple'] == 'n') {
        // TODO cope with wysiwyg and simple
        $wysiwyglib = TikiLib::lib('wysiwyg');
        // set up wikiLingo wysiwyg
        if ($prefs['feature_wikilingo'] != 'y' || $params['useWikiLingo'] != true) {
            if (!isset($params['name'])) {
                $params['name'] = 'edit';
            }
            $ckoptions = $wysiwyglib->setUpEditor($params['_is_html'], $as_id, $params, $auto_save_referrer);
            $html .= '<input type="hidden" name="wysiwyg" value="y" />';
            $html .= '<textarea class="wikiedit" name="' . $params['name'] . '" id="' . $as_id . '" style="visibility:hidden;';
            // missing closing quotes, closed in condition
            if (empty($params['cols'])) {
                $html .= 'width:100%;' . (empty($params['rows']) ? 'height:500px;' : '') . '"';
            } else {
                $html .= '" cols="' . $params['cols'] . '"';
            }
            if (!empty($params['rows'])) {
                $html .= ' rows="' . $params['rows'] . '"';
            }
            $html .= '>' . htmlspecialchars($content) . '</textarea>';
            $headerlib->add_jq_onready('
CKEDITOR.replace( "' . $as_id . '",' . $ckoptions . ');
CKEDITOR.on("instanceReady", function(event) {
if (typeof ajaxLoadingHide == "function") { ajaxLoadingHide(); }
this.instances.' . $as_id . '.resetDirty();
});
', 20);
            // after dialog tools init (10)
        } else {
            $scripts = new WikiLingo\Utilities\Scripts("vendor/wikilingo/wikilingo/editor/");
            $parserWYSIWYG = new WikiLingoWYSIWYG\Parser($scripts);
            require_once 'lib/wikiLingo_tiki/WikiLingoWYSIWYGEvents.php';
            new WikiLingoWYIWYGEvents($parserWYSIWYG);
            $contentSafe = $parserWYSIWYG->parse($content);
            $expressionSyntaxes = new WikiLingoWYSIWYG\ExpressionSyntaxes($scripts);
            //register expression types so that they can be turned into json and sent to browser
            $expressionSyntaxes->registerExpressionTypes();
            $expressionSyntaxesJson = json_encode($expressionSyntaxes->parsedExpressionSyntaxes);
            $wLPlugins = json_encode($parserWYSIWYG->plugins);
            $name = $params['name'];
            $parserWYSIWYG->scripts->addCssLocation("vendor/mediumjs/mediumjs/medium.css")->addCssLocation("vendor/wikilingo/wikilingo/editor/bubble.css")->addCssLocation("vendor/wikilingo/wikilingo/editor/pastLink.css")->addCssLocation("vendor/wikilingo/wikilingo/editor/IcoMoon/sprites/sprites.css")->addCss(".wikiedit.wikilingo{min-height:500px;}");
            $css = $parserWYSIWYG->scripts->renderCss();
            $html .= <<<HTML
{$css}
<div
    id="{$as_id}-ui"
    class="wikiedit wikilingo ui-widget-content"
    contenteditable="true"
    onchange="this.input.value = this.innerHTML">{$contentSafe}</div>
<input type="hidden" name="{$name}" id="{$as_id}"/>
<script>
var ui = document.getElementById('{$as_id}-ui'),
    input = document.getElementById('{$as_id}');

ui.input = input;
input.value = ui.innerHTML;

window.expressionSyntaxes = {$expressionSyntaxesJson};
window.wLPlugins = {$wLPlugins};
</script>
HTML;
            $headerlib->add_jsfile("vendor/undojs/undojs/undo.js")->add_jsfile("vendor/rangy/rangy/uncompressed/rangy-core.js")->add_jsfile("vendor/rangy/rangy/uncompressed/rangy-cssclassapplier.js")->add_jsfile("vendor/mediumjs/mediumjs/medium.js")->add_jsfile("vendor/wikilingo/wikilingo/editor/WLExpressionUI.js")->add_jsfile("vendor/wikilingo/wikilingo/editor/WLPluginEditor.js")->add_jsfile("vendor/wikilingo/wikilingo/editor/WLPluginAssistant.js")->add_jsfile("vendor/wikilingo/wikilingo/editor/bubble.js")->add_jsfile("lib/wikiLingo_tiki/tiki_wikiLingo_edit.js")->add_js(<<<JS
(new WikiLingoEdit(document.getElementById('{$as_id}-ui'), document.getElementById('{$as_id}')));
\$(function() {
    \$('#{$as_id}-ui').after(
        \$('<a class="ui-button" style="float:right;" href="' + document.location + '&wysiwyg=n">' + tr('Edit Source') + '</a>')
            .button()
    );
});
JS
);
            //join wikiLingo's scripts with tiki's
            foreach ($scripts->scriptLocations as $scriptLocation) {
                $headerlib->add_jsfile($scriptLocation);
            }
            foreach ($scripts->scripts as $script) {
                $headerlib->add_js($script);
            }
        }
    } else {
        // end of if ( $params['_wysiwyg'] == 'y' && $params['_simple'] == 'n')
        // setup for wiki editor
        //when wikiLingo enabled
        if ($prefs['feature_wikilingo'] === 'y') {
            $headerlib->add_jsfile("lib/wikiLingo_tiki/tiki_wikiLingo_edit.js");
        }
        $params['rows'] = !empty($params['rows']) ? $params['rows'] : 20;
        //		$params['cols'] = !empty($params['cols']) ? $params['cols'] : 80;
        $textarea_attributes = '';
        foreach ($params as $k => $v) {
            if ($k[0] != '_' && !in_array($k, array('comments', 'switcheditor', 'section', 'area_id', 'autosave'))) {
                $textarea_attributes .= ' ' . $k . '="' . $v . '"';
            }
        }
        if (empty($textarea_id)) {
            $smarty->assign('textarea_id', $params['id']);
        }
        $smarty->assign('textarea__toolbars', $params['_toolbars']);
        if ($textarea_attributes != '') {
            $smarty->assign('textarea_attributes', $textarea_attributes);
        }
        $smarty->assignByRef('textareadata', $content);
        $html .= $smarty->fetch('wiki_edit.tpl');
        $html .= "\n" . '<input type="hidden" name="wysiwyg" value="n" />';
    }
    // wiki or wysiwyg
    $js_editconfirm = '';
    $js_editlock = '';
    if ($params['_simple'] == 'n' && $params['comments'] !== 'y') {
        // Display edit time out
        $js_editlock .= "\nvar editTimeoutSeconds = " . (int) ini_get('session.gc_maxlifetime') . ";\nvar editTimeElapsedSoFar = 0;\nvar editTimeoutIntervalId;\nvar editTimerWarnings = 0;\nvar editTimeoutTipIsDisplayed = false;\nvar minutes;\n\n// edit timeout warnings\nfunction editTimerTick() {\n\teditTimeElapsedSoFar++;\n\n\tvar seconds = editTimeoutSeconds - editTimeElapsedSoFar;\n\tvar edittimeout = \$('#edittimeout');\n\n\tif ( edittimeout && seconds <= 300 ) {\n\t\tif ( ! editTimeoutTipIsDisplayed ) {\n\t\t\tedittimeout.parents('.alert:first').fadeIn();\n\t\t\teditTimeoutTipIsDisplayed = true;\n\t\t}\n\t\tif ( seconds > 0 && seconds % 60 == 0 ) {\n\t\t\tminutes = seconds / 60;\n\t\t\tedittimeout.text( minutes );\n\t\t} else if ( seconds <= 0 ) {\n\t\t\tedittimeout.parents('.alert:first p').text('" . addslashes(tra('Your edit session has expired')) . "');\n\t\t}\n\t}\n\n\tif (editTimerWarnings == 0 && seconds <= 60 && editorDirty) {\n\t\talert('" . addslashes(tra('Your edit session will expire in:')) . ' 1 ' . tra('minute') . '. ' . addslashes(tra('You must PREVIEW or SAVE your work now, to avoid losing your edits.')) . "');\n\t\teditTimerWarnings++;\n\t} else if (seconds <= 0) {\n\t\tclearInterval(editTimeoutIntervalId);\n\t\teditTimeoutIntervalId = 0;\n\t\twindow.status = '" . addslashes(tra('Your edit session has expired')) . "';\n\t} else if (seconds <= 300) {\t\t// don't bother until 5 minutes to go\n\t\twindow.status = '" . addslashes(tra('Your edit session will expire in:')) . "' + \" \" + minutes + ':' + ((seconds % 60 < 10) ? '0' : '') + (seconds % 60);\n\t}\n}\n\n\$('document').ready( function() {\n\teditTimeoutIntervalId = setInterval(editTimerTick, 1000);\n\t\$('#edittimeout').parents('.alert:first').hide();\n} );\n\n// end edit timeout warnings\n\n";
        $js_editconfirm .= "\n\$(window).on('beforeunload', function(e) {\n\tif (window.needToConfirm) {\n\t\tif (typeof CKEDITOR === 'object') {\n\t\t\tfor(var ed in CKEDITOR.instances ) {\n\t\t\t\tif (CKEDITOR.instances.hasOwnProperty(ed)) {\n\t\t\t\t\tif ( CKEDITOR.instances[ed].checkDirty()) {\n\t\t\t\t\t\teditorDirty = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (editorDirty) {\n\t\t\tvar msg = '" . addslashes(tra('You are about to leave this page. Changes since your last save may be lost. Are you sure you want to exit this page?')) . "';\n\t\t\tif (e) {\n\t\t\t\te.returnValue = msg;\n\t\t\t}\n\t\t\treturn msg;\n\t\t}\n\t}\n});\n\n\n\$('document').ready( function() {\n\t// attach dirty function to all relevant inputs etc for wiki/newsletters, blog, article and trackers (trackers need {teaxtarea} implementing)\n\tif ('{$as_id}' === 'editwiki' || '{$as_id}' === 'blogedit' || '{$as_id}' === 'body' || '{$as_id}'.indexOf('area_') > -1) {\n\t\t\$(\$('#{$as_id}').prop('form')).find('input, textarea, select').change( function (event, data) {\n\t\t\tif (!\$(this).is('textarea') && '{$as_id}'.indexOf('area_') > -1) {\t// tracker dynamic list and map inputs get change events on load\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!editorDirty) { editorDirty = true; }\n\t\t});\n\t} else {\t// modules admin exception, only attach to this textarea, although these should be using _simple mode\n\t\t\$('#{$as_id}').change( function () { if (!editorDirty) { editorDirty = true; } });\n\t}\n});\n\nneedToConfirm = true;\neditorDirty = " . (isset($_REQUEST["preview"]) && $params['_previewConfirmExit'] == 'y' ? 'true' : 'false') . ";\n";
        if ($prefs['feature_wysiwyg'] == 'y' && $prefs['wysiwyg_optional'] == 'y') {
            $js_editconfirm .= '
function switchEditor(mode, form) {
	window.needToConfirm=false;
	var w;
	if (mode=="wysiwyg") {
		$(form).find("input[name=mode_wysiwyg]").val("y");
		$(form).find("input[name=wysiwyg]").val("y");
	} else {
		$(form).find("input[name=mode_normal]").val("y");
		$(form).find("input[name=wysiwyg]").val("n");
	}
	form.submit();
}';
        }
        if ($tiki_p_admin) {
            $js_editconfirm .= '
function admintoolbar() {
	window.needToConfirm=false;
	window.location="tiki-admin_toolbars.php";
}';
        }
        if ($editWarning) {
            $headerlib->add_js($js_editlock);
        }
        $headerlib->add_js($js_editconfirm);
    }
    // end if ($params['_simple'] == 'n')
    return $auto_save_warning . $html;
}