// expects $pagehash and $html to be set // Set up inline links and images for ($i = 1; $i < (NUM_LINKS + 1); $i++) { if (! empty($pagehash['refs'][$i])) { if (preg_match("/png$/i", $pagehash['refs'][$i])) { // embed PNG images $embedded[$i] = ""; } else { // ordinary embedded link $embedded[$i] = "[$i]"; } } } $numlines = count($pagehash["content"]); // Loop over all lines of the page and apply transformation rules for ($index = 0; $index < $numlines; $index++) { unset($tokens); unset($replacements); $ntokens = 0; $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.
// match anything between brackets except only numbers
// trying:
$numBracketLinks = preg_match_all("/\[.+?\]/", $tmpline, $brktlinks);
/* On 12 Jul,2000 Jeff
$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);
// Link Wiki words
// Wikiwords preceeded by a '!' are not linked
if (preg_match_all("#!?\b(([A-Z][a-z]+){2,})\b#",
$tmpline, $link)) {
// uniq the list of matches
unset($hash);
for ($i = 0; $link[0][$i]; $i++) {
// $realfile = $link[0][$i];
$hash[$link[0][$i]]++;
}
// all '!WikiName' entries are sorted first
ksort($hash);
while (list($realfile, $val) = each($hash)) {
$token = $FieldSeparator . $FieldSeparator . ++$ntokens . $FieldSeparator;
$tmpline = str_replace($realfile, $token, $tmpline);
$tokens[] = $token;
if (strstr($realfile, '!')) {
$replacements[] = substr($realfile, 1);
}
elseif (IsWikiPage($dbi, $realfile)) {
$replacements[] = LinkExistingWikiWord($realfile);
} else {
$replacements[] = LinkUnknownWikiWord($realfile);
}
}
}
///////////////////////////////////////////////////////
// Replace tokens
for ($i = 0; $i < $ntokens; $i++)
$tmpline = str_replace($tokens[$i], $replacements[$i], $tmpline);
// match and replace all user-defined links ([1], [2], [3]...)
preg_match_all("|\[(\d+)\]|", $tmpline, $match);
if (count($match[0])) {
for ($k = 0; $k < count($match[0]); $k++) {
if (! empty($embedded[$match[1][$k]])) {
$linkpattern = preg_quote($match[0][$k]);
$tmpline = preg_replace("|$linkpattern|",
$embedded[$match[1][$k]],
$tmpline);
}
}
}
// HTML modes: pre, unordered/ordered lists, term/def
if (preg_match("/(^\t)(.*?)(:\t)(.*$)/", $tmpline, $matches)) {
// this is a dictionary list item
$html .= SetHTMLOutputMode("dl", SINGLE_DEPTH, 1);
$tmpline = " block
} elseif (preg_match("/^([*]+)/", $tmpline, $matches)) {
// this is part of an unordered list
$numtabs = strlen($matches[1]);
$listtag = "ul";
$tmpline = preg_replace("/^([*]+)/", "", $tmpline);
$html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs);
$html .= "
} elseif (preg_match("/^([#]+)/", $tmpline, $matches)) {
// this is part of an ordered list
$numtabs = strlen($matches[1]);
$listtag = "ol";
$tmpline = preg_replace("/^([#]+)/", "", $tmpline);
$html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs);
$html .= "
$html .= SetHTMLOutputMode("pre", ZERO_DEPTH, 0);
} elseif (preg_match("/^(!{1,3})[^!]/", $tmpline, $whichheading)) {
// lines starting with !,!!,!!! are headings
if($whichheading[1] == '!') $heading = "h3";
elseif($whichheading[1] == '!!') $heading = "h2";
elseif($whichheading[1] == '!!!') $heading = "h1";
$tmpline = preg_replace("/^!+/", "", $tmpline);
$html .= SetHTMLOutputMode($heading, ZERO_DEPTH, 0);
} else {
// it's ordinary output if nothing else
$html .= SetHTMLOutputMode("", ZERO_DEPTH, 0);
}
$tmpline = str_replace("%%Search%%", RenderQuickSearch(), $tmpline);
$tmpline = str_replace("%%Fullsearch%%", RenderFullSearch(), $tmpline);
$tmpline = str_replace("%%Mostpopular%%", RenderMostPopular(), $tmpline);
$html .= "$tmpline";
}
$html .= SetHTMLOutputMode("", ZERO_DEPTH, 0);
?>