{tr}Roll back to this version{/tr} * so i had to "manually" replace the "url" params with 'url' before running the script. */ // just in case require_once('tiki-setup.php'); $access->check_permission('tiki_p_admin'); $access->check_feature('javascript_enabled'); $tpl = $_GET['tpl']; $count_r = 0; //if (empty($tpl)) { // $access->display_error('', 'no tpl'); //} /** * @param $original * @param $template_base * @return mixed */ function replace_with_self_links($original, $template_base) { global $count_r; preg_match_all('/]*?>(.*?)<\/a>/mi', $original, $phplinks); $replacements = []; $count_r = count($phplinks[0]); for ($j = 0; $j < $count_r; $j++) { $ahref = $phplinks[0][$j]; preg_match_all('/([^=\s]*?)="([^"]*?)"/i', $ahref, $attrs); $str = '{self_link '; for ($i = 0, $icount_attrs = count($attrs[1]); $i < $icount_attrs; $i++) { if (strtolower($attrs[1][$i]) == 'href') { $query = parse_url(urldecode(str_replace('&', '&', $attrs[2][$i]))); if ($query['path'] != $template_base . '.php') { $str .= ' _script="' . $query['path'] . '" '; } $vars = explode('&', $query['query']); foreach ($vars as &$var) { $ar = explode('=', $var); $var = $ar[0] . '=' . process_value($ar[1]); } $str .= implode(' ', $vars) . ' '; } else { $str .= '_' . $attrs[1][$i] . '=' . process_value($attrs[2][$i]) . ' '; } } $str = trim($str) . '}' . $phplinks[1][$j] . '{/self_link}'; $replacements[] = $str; } $replaced = str_replace($phplinks[0], $replacements, $original); return $replaced; } /** * @param $var * @return string */ function process_value($var) { if (strpos($var, '{$') === 0) { $var = trim($var, '{}'); $q = ''; } else { $q = '"'; } // comment out if's inside attributes for manual processing $var = preg_replace( ['/\{if\s([^\}]*)\}/i', '/\{else\}/i', '/\{\/if\}/i', '/\{elseif\s([^\}]*)\}/i'], ['{*if $1*}', '{*else*}', '{*/if*}', '/{*elseif $1*}/'], $var ); $var = "$q" . $var . "$q"; return $var; } $markup = file_get_contents('templates/' . $tpl . '.tpl'); $checked = ! empty($_REQUEST['toggle']) ? ' checked=\'checked\'' : ''; if (! empty($checked)) { $markup = replace_with_self_links($markup, $tpl); } $fp = opendir('templates/'); $tpl_sel = ''; // cheating - lazy ;) $form = str_replace( "\n", '', "
$tpl_sel
" ); $headerlib->add_jq_onready( <<assign('source', true); $smarty->assign('sourced', htmlentities($markup)); $smarty->assign('noHistory', true); $smarty->assign('info', ['version' => true]); // Display the template $smarty->assign('mid', 'tiki-pagehistory.tpl'); $smarty->display("tiki.tpl");