[$i]"; } } } $numlines = count($pagehash["content"]); // only call these once, for efficiency $quick_search_box = RenderQuickSearch(); $full_search_box = RenderFullSearch(); $most_popular_list = RenderMostPopular(); // Loop over all lines of the page and apply transformation rules for ($index = 0; $index < $numlines; $index++) { unset($tokens); unset($replacements); $ntokens = 0; $replacements = array(); $tmpline = $pagehash["content"][$index]; if (!strlen($tmpline) || $tmpline == "\r") { // this is a blank line, send

$html .= SetHTMLOutputMode("p", ZERO_DEPTH, 0); continue; } /* If your web server is not accessble to the general public, you may allow this code below, which allows embedded HTML. If just anyone can reach your web server it is highly advised that you do not allow this. elseif (preg_match("/(^\|)(.*)/", $tmpline, $matches)) { // HTML mode $html .= SetHTMLOutputMode("", ZERO_DEPTH, 0); $html .= $matches[2]; continue; } */ ////////////////////////////////////////////////////////// // New linking scheme: links are in brackets. This will // emulate typical HTML linking as well as Wiki linking. // First need to protect [[. $oldn = $ntokens; $tmpline = tokenize($tmpline, "\[\[", $replacements, $ntokens); while ($oldn < $ntokens) $replacements[$oldn++] = "["; // Now process the [\d+] links which are numeric references $oldn = $ntokens; $tmpline = tokenize($tmpline, "\[\s*\d+\s*\]", $replacements ,$ntokens); while ($oldn < $ntokens) { $num = (int)substr($replacements[$oldn], 1); if (! empty($embedded[$num])) $replacements[$oldn] = $embedded[$num]; $oldn++; } // match anything else between brackets $oldn = $ntokens; $tmpline = tokenize($tmpline, "\[.+?\]", $replacements, $ntokens); while ($oldn < $ntokens) { $link = ParseAndLink($replacements[$oldn]); $replacements[$oldn] = $link['link']; $oldn++; } ////////////////////////////////////////////////////////// // replace all URL's with tokens, so we don't confuse them // with Wiki words later. Wiki words in URL's break things. $tmpline = tokenize($tmpline, "\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]", $replacements, $ntokens); while ($oldn < $ntokens) { $replacements[$oldn] = LinkURL($replacements[$oldn]); $oldn++; } ////////////////////////////////////////////////////////// // Link Wiki words // Wikiwords preceeded by a '!' are not linked $oldn = $ntokens; $tmpline = tokenize($tmpline, "!?$WikiNameRegexp", $replacements, $ntokens); while ($oldn < $ntokens) { $old = $replacements[$oldn]; if ($old[0] == '!') { $replacements[$oldn] = substr($old,1); } elseif (IsWikiPage($dbi, $old)) { $replacements[$oldn] = LinkExistingWikiWord($old); } else { $replacements[$oldn] = LinkUnknownWikiWord($old); } $oldn++; } // escape HTML metachars $tmpline = str_replace("&", "&", $tmpline); $tmpline = str_replace(">", ">", $tmpline); $tmpline = str_replace("<", "<", $tmpline); // four or more dashes to


$tmpline = ereg_replace("^-{4,}", "
", $tmpline); // %%% are linebreaks $tmpline = str_replace("%%%", "
", $tmpline); // bold italics $tmpline = preg_replace("|(''''')(.*?)(''''')|", "\\2", $tmpline); // bold $tmpline = preg_replace("|(''')(.*?)(''')|", "\\2", $tmpline); // bold $tmpline = preg_replace("|(__)(.*?)(__)|", "\\2", $tmpline); // italics $tmpline = preg_replace("|('')(.*?)('')|", "\\2", $tmpline); // HTML modes: pre, unordered/ordered lists, term/def (using TAB) if (preg_match("/(^\t+)(.*?)(:\t)(.*$)/", $tmpline, $matches)) { // this is a dictionary list item $numtabs = strlen($matches[1]); $html .= SetHTMLOutputMode("dl", SINGLE_DEPTH, $numtabs); $tmpline = ''; if(trim($matches[2])) $tmpline = "
" . $matches[2]; $tmpline .= "
" . $matches[4]; } elseif (preg_match("/(^\t+)(\*|\d+|#)/", $tmpline, $matches)) { // this is part of a list $numtabs = strlen($matches[1]); if ($matches[2] == "*") { $listtag = "ul"; } else { $listtag = "ol"; // a rather tacit assumption. oh well. } $tmpline = preg_replace("/^(\t+)(\*|\d+|#)/", "", $tmpline); $html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs); $html .= "
  • "; // tabless markup for unordered and ordered lists // list types can be mixed, so we only look at the last // character. Changes e.g. from "**#*" to "###*" go unnoticed. // and wouldn't make a difference to the HTML layout anyway. // unordered lists