// 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++) { $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); // sort instead of rsort or "[[link] [link]" will be rendered wrong. sort($brktlinks[0]); reset($brktlinks[0]); for ($i = 0; $i < $numBracketLinks; $i++) { $brktlink = preg_quote($brktlinks[0][$i]); $linktoken = "${FieldSeparator}brkt${i}brkt${FieldSeparator}"; $tmpline = preg_replace("|$brktlink|", $linktoken, $tmpline); } ////////////////////////////////////////////////////////// // replace all URL's with tokens, so we don't confuse them // with Wiki words later. Wiki words in URL's break things. $hasURLs = preg_match_all("/\b($AllowedProtocols):[^\s\<\>\[\]\"'\(\)]*[^\s\<\>\[\]\"'\(\)\,\.\?]/", $tmpline, $urls); // have to sort, otherwise errors creep in when the domain appears // in two consecutive URL's on the same line, but the second is // longer e.g. http://c2.com followed by http://c2.com/wiki rsort($urls[0]); reset($urls[0]); for ($i = 0; $i < $hasURLs; $i++) { $inplaceURL = preg_quote($urls[0][$i]); $URLtoken = "${FieldSeparator}${i}${FieldSeparator}"; $tmpline = preg_replace("|$inplaceURL|", $URLtoken, $tmpline); } // escape HTML metachars $tmpline = ereg_replace("[&]", "&", $tmpline); $tmpline = ereg_replace("[>]", ">", $tmpline); $tmpline = ereg_replace("[<]", "<", $tmpline); // four or more dashes to
$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"; // at last, emit the code } $html .= SetHTMLOutputMode("", ZERO_DEPTH, 0); ?>