public static function error($label, $message) { $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return new self('html', smarty_block_remarksbox(array('type' => 'error', 'title' => $label), $message, $smarty, $repeat)); }
function smarty_function_error_report($params, $smarty) { $errorreportlib = TikiLib::lib('errorreport'); $errors = $errorreportlib->get_errors(); $pre = '<div id="error_report">'; $post = '</div>'; TikiLib::lib('header')->add_js(' $("#error_report").ajaxComplete(function (e, jqxhr) { var error = jqxhr.getResponseHeader("X-Tiki-Error"); if (error) { if ($("ul", this).length === 0) { $(this).append($(error)[0].childNodes); } else { $("ul", this).append($(error).find("li")); } } }); $("#error_report .clear").live("click", function () { $("#error_report").empty(); return false; }); '); if (count($errors)) { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return $pre . smarty_block_remarksbox(array('type' => 'errors', 'title' => tra('Error(s)')), '<a class="clear" style="float: right;" href="#">' . tr('Clear errors') . '</a><ul><li>' . implode('</li><li>', $errors) . '</li></ul>', $smarty, $repeat) . $post; } else { return $pre . $post; } }
function smarty_function_service_inline($params, $smarty) { $servicelib = TikiLib::lib('service'); if (!isset($params['controller'])) { return 'missing-controller'; } if (!isset($params['action'])) { return 'missing-action'; } $controller = $params['controller']; $action = $params['action']; unset($params['controller']); unset($params['action']); try { $addonpackage = ''; if (strpos($controller, ".") !== false) { $parts = explode(".", $controller); if (count($parts) == 3) { $addonpackage = $parts[0] . "." . $parts[1]; $controller = $parts[2]; } } return $servicelib->render($controller, $action, $params, $addonpackage); } catch (Services_Exception $e) { if (empty($params['_silent'])) { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return smarty_block_remarksbox(['type' => 'warning', 'title' => tr('Unavailable')], $e->getMessage(), $smarty, $repeat); } } }
function smarty_function_attachments($params, $template) { if (!is_array($params) || !isset($params['_id']) || !isset($params['_type'])) { return; } global $smarty, $prefs, $tikilib, $userlib; global $filegallib; include_once 'lib/filegals/filegallib.php'; /*** For the moment, only wiki attachments are handled through file galleries ***/ if ($prefs['feature_wiki_attachments'] != 'y') { return; } $galleryId = $filegallib->get_attachment_gallery($params['_id'], $params['_type']); /*** If anything in this function is changed, please change lib/wiki-plugins/wikiplugin_attach.php as well. ***/ if (empty($galleryId) || !($gal_info = $filegallib->get_file_gallery($galleryId))) { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return smarty_block_remarksbox(array('type' => 'errors', 'title' => tra('Wrong attachments gallery')), tra('You are attempting to display a gallery that is not a valid attachment gallery') . ' (ID=' . $galleryId . ')', $smarty, $repeat) . "\n"; } //// if ( $this->showAttachments !== false ) //// $this->smartyassign('atts_show', $this->showAttachments); foreach ($params as $k => $v) { if ($k[0] == '_') { unset($params[$k]); } } // Get URL params specific to this smarty function that should be assigned in smarty $url_override_prefix = 's_f_attachments'; $url_overrided_arguments = array('sort_mode', 'remove', 'galleryId', 'comment', 'upload', 'page'); $smarty->set_request_overriders($url_override_prefix, $url_overrided_arguments); $params['sort_mode'] = isset($_REQUEST[$url_override_prefix . '-sort_mode']) ? $_REQUEST[$url_override_prefix . '-sort_mode'] : ''; // Get listing display config include_once 'fgal_listing_conf.php'; // Force some gallery display parameters $gal_info['show_checked'] = 'n'; // Get list of files in the gallery $files = $filegallib->get_files(0, -1, $params['sort_mode'], '', $galleryId); // Reajust perms using special wiki attachments perms global $tiki_p_wiki_admin_attachments, $tiki_p_wiki_attach_files, $tiki_p_wiki_view_attachments; foreach ($files['data'] as $k => $v) { $p =& $files['data'][$k]['perms']; // First disable file galleries "assign perms" & "admin" perms that allows too much actions on the list of files or that are related to subgalleries // (attachements display should be simple) $p['tiki_p_admin_file_galleries'] = 'n'; $p['tiki_p_assign_perm_file_gallery'] = 'n'; // Disabling permissions below should not be necessary because subgalleries in attachments galleries should not happen... // $p[ 'tiki_p_upload_files' ] = 'n'; // $p[ 'tiki_p_create_file_galleries' ] = 'n'; $p['tiki_p_download_files'] = $tiki_p_wiki_admin_attachments == 'y' || $tiki_p_wiki_view_attachments == 'y' ? 'y' : 'n'; $p['tiki_p_edit_gallery_file'] = $tiki_p_wiki_admin_attachments; } $params['gal_info'] = $gal_info; $params['files'] = $files['data']; $params['cant'] = $files['cant']; $return = "\n" . $smarty->plugin_fetch('fgal_attachments.tpl', $params) . "\n"; $smarty->remove_request_overriders($url_override_prefix, $url_overrided_arguments); return $return; }
function wikiplugin_remarksbox($data, $params) { global $smarty; require_once 'lib/smarty_tiki/block.remarksbox.php'; // there probably is a better way @todo this // but for now i'm escaping the html in ~np~s as the parser is adding odd <p> tags $ret = '~np~' . smarty_block_remarksbox($params, '~/np~' . tra($data) . '~np~', &$smarty) . '~/np~'; return $ret; }
function smarty_function_error_report($params, $smarty) { $errorreportlib = TikiLib::lib('errorreport'); $errors = $errorreportlib->get_errors(); $pre = '<div id="error_report">'; $post = '</div>'; $repeat = false; $legacy = $smarty->getTemplateVars('display_msg'); $type = $smarty->getTemplateVars('display_msgtype'); $type = empty($type) ? 'note' : $type; $titles = ['confirm' => tra('Success'), 'feedback' => tra('Success'), 'error' => tra('Error'), 'errors' => tra('Errors'), 'warning' => tra('Warning'), 'note' => tra('Notice')]; if ($legacy) { // Handle reporting ofthe display_msg smarty variable $smarty->loadPlugin('smarty_block_remarksbox'); $post .= smarty_block_remarksbox(array('type' => $type, 'title' => $titles[$type]), $legacy, $smarty, $repeat); } TikiLib::lib('header')->add_js(' $(document).ajaxComplete(function (e, jqxhr) { var error = jqxhr.getResponseHeader("X-Tiki-Error"); if (error) { if ($("ul", "#error_report").length === 0) { $("#error_report").append($(error)[0].childNodes); } else { $("ul", "#error_report").append($(error).find("li")); } } $("#error_report .clear").on("click", function () { $("#error_report").empty(); return false; }); }); '); if (count($errors)) { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return $pre . smarty_block_remarksbox(array('type' => 'errors', 'title' => tra('Error(s)')), '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>', $smarty, $repeat) . $post; } else { return $pre . $post; } }
/** * @param $mod_reference * @return bool|mixed|string */ function execute_module($mod_reference) { global $user, $prefs, $tiki_p_admin; $smarty = TikiLib::lib('smarty'); $tikilib = TikiLib::lib('tiki'); try { $defaults = array('style' => '', 'nonums' => 'n'); $module_params = isset($mod_reference['params']) ? (array) $mod_reference['params'] : array(); $module_params = array_merge($defaults, $module_params); // not sure why style doesn't get set sometime but is used in the tpl $mod_reference = array_merge(array('moduleId' => null, 'ord' => 0, 'position' => 0, 'rows' => 10), $mod_reference); $module_rows = $mod_reference["rows"]; $info = $this->get_module_info($mod_reference); $cachefile = $this->get_cache_file($mod_reference, $info); foreach ((array) $info['prefs'] as $preference) { if ($prefs[$preference] != 'y') { $smarty->loadPlugin('smarty_block_remarksbox'); return smarty_block_remarksbox(array('type' => 'warning', 'title' => tr('Failed to execute "%0" module', $mod_reference['name'])), tr('Missing dependencies'), $smarty, $repeat); } } if (!$cachefile || $this->require_cache_build($mod_reference, $cachefile) || $this->is_admin_mode()) { if ($this->is_admin_mode()) { require_once 'lib/setup/timer.class.php'; $timer = new timer('module'); $timer->start('module'); } if ($info['type'] == "function") { // Use the module name as default module title. This can be overriden later. A module can opt-out of this in favor of a dynamic default title set in the TPL using clear_assign in the main module function. It can also be overwritten in the main module function. $smarty->assign('tpl_module_title', tra($info['name'])); } $smarty->assign('nonums', $module_params['nonums']); if ($info['type'] == 'include') { $phpfile = 'modules/mod-' . $mod_reference['name'] . '.php'; if (file_exists($phpfile)) { include $phpfile; } } elseif ($info['type'] == 'function') { $function = 'module_' . $mod_reference['name']; $phpfuncfile = 'modules/mod-func-' . $mod_reference['name'] . '.php'; if (file_exists($phpfuncfile)) { include_once $phpfuncfile; } if (function_exists($function)) { $function($mod_reference, $module_params); } } $ck = getCookie('mod-' . $mod_reference['name'] . $mod_reference['position'] . $mod_reference['ord'], 'menu', 'o'); $smarty->assign('module_display', $prefs['javascript_enabled'] == 'n' || $ck == 'o'); $smarty->assign_by_ref('module_rows', $mod_reference['rows']); $smarty->assign_by_ref('module_params', $module_params); // module code can unassign this if it wants to hide params $smarty->assign('module_ord', $mod_reference['ord']); $smarty->assign('module_position', $mod_reference['position']); $smarty->assign('moduleId', $mod_reference['moduleId']); if (isset($module_params['title'])) { $smarty->assign('tpl_module_title', tra($module_params['title'])); } $smarty->assign('tpl_module_name', $mod_reference['name']); $tpl_module_style = empty($mod_reference['module_style']) ? '' : $mod_reference['module_style']; if ($tiki_p_admin == 'y' && $this->is_admin_mode() && (!$this->filter_active_module($mod_reference) || $prefs['modhideanonadmin'] == 'y' && (empty($mod_reference['groups']) || $mod_reference['groups'] == serialize(array('Anonymous'))))) { $tpl_module_style .= 'opacity: 0.5;'; } if (isset($module_params['overflow']) && $module_params['overflow'] === 'y') { $tpl_module_style .= 'overflow:visible !important;'; } $smarty->assign('tpl_module_style', $tpl_module_style); $template = 'modules/mod-' . $mod_reference['name'] . '.tpl'; if (file_exists('templates/' . $template)) { $data = $smarty->fetch($template); } else { $data = $this->get_user_module_content($mod_reference['name'], $module_params); } $smarty->clear_assign('module_params'); // ensure params not available outside current module $smarty->clear_assign('tpl_module_title'); $smarty->clear_assign('tpl_module_name'); $smarty->clear_assign('tpl_module_style'); if ($this->is_admin_mode() && $timer) { $elapsed = round($timer->stop('module'), 3); $data = preg_replace('/<div /', '<div title="Module Execution Time ' . $elapsed . 's" ', $data, 1); } if (!empty($cachefile) && !$this->is_admin_mode()) { file_put_contents($cachefile, $data); } } else { $data = file_get_contents($cachefile); } return $data; } catch (Exception $e) { $smarty->loadPlugin('smarty_block_remarksbox'); if ($tiki_p_admin == 'y') { $message = $e->getMessage(); } else { $message = tr('Contact the system administrator'); } $repeat = false; return smarty_block_remarksbox(array('type' => 'warning', 'title' => tr('Failed to execute "%0" module', $mod_reference['name'])), html_entity_decode($message), $smarty, $repeat); } }
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> ' . '<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; }
function wikiplugin_vimeo($data, $params) { global $prefs; static $instance = 0; $instance++; if (isset($params['url'])) { $params['vimeo'] = $params['url']; unset($params['url']); return wikiplugin_flash($data, $params); } elseif (isset($params['fileId'])) { $fileIds = preg_split('/\\D+/', $params['fileId'], -1, PREG_SPLIT_NO_EMPTY); unset($params['fileId']); $out = ''; foreach ($fileIds as $fileId) { $attributelib = TikiLib::lib('attribute'); $attributes = $attributelib->get_attributes('file', $fileId); if (!empty($attributes['tiki.content.url'])) { $params['vimeo'] = $attributes['tiki.content.url']; $out .= wikiplugin_flash($data, $params); } else { TikiLib::lib('errorreport')->report(tr('Vimeo video not found for file #%0', $fileId)); } } return $out; } else { global $page; $smarty = TikiLib::lib('smarty'); if ($prefs['vimeo_upload'] !== 'y') { $smarty->loadPlugin('smarty_block_remarksbox'); $repeat = false; return smarty_block_remarksbox(array('type' => 'error', 'title' => tra('Feature required')), tra('Feature "vimeo_upload" is required to be able to add videos here.'), $smarty, $repeat); } // old perms access to get "special" gallery perms to handle user gals etc $perms = TikiLib::lib('tiki')->get_perm_object(!empty($params['galleryId']) ? $params['galleryId'] : $prefs['vimeo_default_gallery'], 'file gallery', TikiLib::lib('filegal')->get_file_gallery_info($prefs['vimeo_default_gallery']), false); if ($perms['tiki_p_upload_files'] !== 'y') { return ''; //$permMessage = tra('You do not have permsission to add files here.'); } else { if (!empty($params['fromFieldId'])) { $fieldInfo = TikiLib::lib('trk')->get_tracker_field($params['fromFieldId']); if (empty($params['fromItemId'])) { $item = Tracker_Item::newItem($fieldInfo['trackerId']); } else { $item = Tracker_Item::fromId($params['fromItemId']); } if (!$item->canModify()) { return ''; //$permMessage = tra('You do not have permsission modify this tracker item.'); } } else { if ($page) { $pagePerms = Perms::get(array('type' => 'wiki page', 'object' => $page))->edit; if (!$pagePerms) { return ''; //$permMessage = tra('You do not have permsission modify this page.'); } } } } // set up for an upload $smarty->loadPlugin('smarty_function_button'); $smarty->loadPlugin('smarty_function_service'); $html = smarty_function_button(array('_keepall' => 'y', '_class' => 'vimeo dialog', 'href' => smarty_function_service(array('controller' => 'vimeo', 'action' => 'upload'), $smarty), '_text' => tra('Upload Video')), $smarty); $js = ' $(".vimeo.dialog").click(function () { var link = this; $(this).serviceDialog({ title: tr("Upload Video"), data: { controller: "vimeo", action: "upload"' . (!empty($params['galleryId']) ? ',galleryId:' . $params['galleryId'] : '') . (!empty($params['fromFieldId']) ? ',fieldId:' . $params['fromFieldId'] : '') . (!empty($params['fromItemId']) ? ',itemId:' . $params['fromItemId'] : '') . ' }, load: function(data) { var $dialog = $(".vimeo_upload").parents(".ui-dialog-content"); // odd its the content, not the outer div $(".vimeo_upload").on("vimeo_uploaded", function(event, data) {'; if (!empty($page) && empty($params['fromFieldId'])) { $js .= ' var params = { page: ' . json_encode($page) . ', content: "", index: ' . $instance . ', type: "vimeo", params: { url: data.url } }; $.post("tiki-wikiplugin_edit.php", params, function() { $("input[type=file]", $dialog).val(""); // webkit reloads the dialog as it destroys it for some reason $dialog.dialog("destroy").remove(); $.get($.service("wiki", "get_page", {page:' . json_encode($page) . '}), function (data) { if (data) { $("#page-data").html(data); } }); });'; } else { $js .= ' $dialog.dialog("destroy").remove(); handleVimeoFile(link, data); '; } $js .= ' }); } }); return false; });'; TikiLib::lib('header')->add_jq_onready($js); return $html; } }
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> ' . '<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; }