|
From: Arno H. <aho...@us...> - 2001-01-04 18:34:14
|
Update of /cvsroot/phpwiki/phpwiki/lib
In directory usw-pr-cvs1:/tmp/cvs-serv8448
Modified Files:
transform.php
Log Message:
ZERO/SINGLE_DEPTH renamed into ZERO/NESTED_LEVEL
empty lines are now treated as tag '' (i.e. no tag) instead of '<p>'
normal text is now treated as '<p>' instead of tag ''
added and corrected some comments, some code cleanup
Index: transform.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/transform.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** transform.php 2000/11/08 15:40:00 1.7
--- transform.php 2001/01/04 18:34:15 1.8
***************
*** 1,13 ****
! <!-- $Id$ -->
! <?php
// expects $pagehash and $html to be set
-
function tokenize($str, $pattern, &$orig, &$ntokens) {
global $FieldSeparator;
// Find any strings in $str that match $pattern and
! // store them in $tokens[], replacing them with a token
! // replaced strings are stored in $orig
! $new = "";
while (preg_match("/^(.*?)($pattern)/", $str, $matches)) {
$linktoken = $FieldSeparator . $FieldSeparator . ($ntokens++) . $FieldSeparator;
--- 1,11 ----
! <?php rcs_id('$Id$');
// expects $pagehash and $html to be set
function tokenize($str, $pattern, &$orig, &$ntokens) {
global $FieldSeparator;
// Find any strings in $str that match $pattern and
! // store them in $orig, replacing them with tokens
! // starting at number $ntokens - returns tokenized string
! $new = '';
while (preg_match("/^(.*?)($pattern)/", $str, $matches)) {
$linktoken = $FieldSeparator . $FieldSeparator . ($ntokens++) . $FieldSeparator;
***************
*** 29,38 ****
} else {
// ordinary link
! $embedded[$i] = "<a href=\"" . $pagehash['refs'][$i] . "\">[$i]</a>";
}
}
}
- $numlines = count($pagehash["content"]);
// only call these once, for efficiency
--- 27,35 ----
} else {
// ordinary link
! $embedded[$i] = LinkURL($pagehash['refs'][$i], "[$i]");
}
}
}
// only call these once, for efficiency
***************
*** 43,46 ****
--- 40,45 ----
// Loop over all lines of the page and apply transformation rules
+ $numlines = count($pagehash["content"]);
+
for ($index = 0; $index < $numlines; $index++) {
unset($tokens);
***************
*** 49,57 ****
$replacements = array();
! $tmpline = $pagehash["content"][$index];
if (!strlen($tmpline) || $tmpline == "\r") {
// this is a blank line, send <p>
! $html .= SetHTMLOutputMode("p", ZERO_DEPTH, 0);
continue;
}
--- 48,56 ----
$replacements = array();
! $tmpline = $pagehash['content'][$index];
if (!strlen($tmpline) || $tmpline == "\r") {
// this is a blank line, send <p>
! $html .= SetHTMLOutputMode('', ZERO_LEVEL, 0);
continue;
}
***************
*** 63,67 ****
elseif (preg_match("/(^\|)(.*)/", $tmpline, $matches)) {
// HTML mode
! $html .= SetHTMLOutputMode("", ZERO_DEPTH, 0);
$html .= $matches[2];
continue;
--- 62,66 ----
elseif (preg_match("/(^\|)(.*)/", $tmpline, $matches)) {
// HTML mode
! $html .= SetHTMLOutputMode("", ZERO_LEVEL, 0);
$html .= $matches[2];
continue;
***************
*** 76,88 ****
// 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];
--- 75,87 ----
// 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];
***************
*** 92,96 ****
// match anything else between brackets
$oldn = $ntokens;
! $tmpline = tokenize($tmpline, "\[.+?\]", $replacements, $ntokens);
while ($oldn < $ntokens) {
$link = ParseAndLink($replacements[$oldn]);
--- 91,95 ----
// match anything else between brackets
$oldn = $ntokens;
! $tmpline = tokenize($tmpline, '\[.+?\]', $replacements, $ntokens);
while ($oldn < $ntokens) {
$link = ParseAndLink($replacements[$oldn]);
***************
*** 102,105 ****
--- 101,105 ----
// replace all URL's with tokens, so we don't confuse them
// with Wiki words later. Wiki words in URL's break things.
+ // URLs preceeded by a '!' are not linked
$tmpline = tokenize($tmpline, "!?\b($AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]", $replacements, $ntokens);
***************
*** 130,149 ****
}
// escape HTML metachars
! $tmpline = str_replace("&", "&", $tmpline);
! $tmpline = str_replace(">", ">", $tmpline);
! $tmpline = str_replace("<", "<", $tmpline);
// four or more dashes to <hr>
! $tmpline = ereg_replace("^-{4,}", "<hr>", $tmpline);
// %%% are linebreaks
! $tmpline = str_replace("%%%", "<br>", $tmpline);
! // bold italics
$tmpline = preg_replace("|(''''')(.*?)(''''')|",
"<strong><em>\\2</em></strong>", $tmpline);
! // bold
$tmpline = preg_replace("|(''')(.*?)(''')|",
"<strong>\\2</strong>", $tmpline);
--- 130,151 ----
}
+
+ //////////////////////////////////////////////////////////
// escape HTML metachars
! $tmpline = str_replace('&', '&', $tmpline);
! $tmpline = str_replace('>', '>', $tmpline);
! $tmpline = str_replace('<', '<', $tmpline);
// four or more dashes to <hr>
! $tmpline = ereg_replace("^-{4,}", '<hr>', $tmpline);
// %%% are linebreaks
! $tmpline = str_replace('%%%', '<br>', $tmpline);
! // bold italics (old way)
$tmpline = preg_replace("|(''''')(.*?)(''''')|",
"<strong><em>\\2</em></strong>", $tmpline);
! // bold (old way)
$tmpline = preg_replace("|(''')(.*?)(''')|",
"<strong>\\2</strong>", $tmpline);
***************
*** 157,185 ****
"<em>\\2</em>", $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 = "<dt>" . $matches[2];
! $tmpline .= "<dd>" . $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 .= "<li>";
! // 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.
--- 159,191 ----
"<em>\\2</em>", $tmpline);
+
+ //////////////////////////////////////////////////////////
+ // unordered, ordered, and dictionary list (using TAB)
if (preg_match("/(^\t+)(.*?)(:\t)(.*$)/", $tmpline, $matches)) {
! // this is a dictionary list (<dl>) item
$numtabs = strlen($matches[1]);
! $html .= SetHTMLOutputMode('dl', NESTED_LEVEL, $numtabs);
$tmpline = '';
if(trim($matches[2]))
! $tmpline = '<dt>' . $matches[2];
! $tmpline .= '<dd>' . $matches[4];
} elseif (preg_match("/(^\t+)(\*|\d+|#)/", $tmpline, $matches)) {
! // this is part of a list (<ul>, <ol>)
$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, NESTED_LEVEL, $numtabs);
! $html .= '<li>';
!
! //////////////////////////////////////////////////////////
! // tabless markup for unordered, ordered, and dictionary lists
! // ul/ol 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.
***************
*** 189,197 ****
// this is part of an unordered list
$numtabs = strlen($matches[1]);
! $listtag = "ul";
!
! $tmpline = preg_replace("/^([#*]*\*)/", "", $tmpline);
! $html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs);
! $html .= "<li>";
// ordered lists <OL>: "#"
--- 195,201 ----
// this is part of an unordered list
$numtabs = strlen($matches[1]);
! $tmpline = preg_replace("/^([#*]*\*)/", '', $tmpline);
! $html .= SetHTMLOutputMode('ul', NESTED_LEVEL, $numtabs);
! $html .= '<li>';
// ordered lists <OL>: "#"
***************
*** 199,207 ****
// this is part of an ordered list
$numtabs = strlen($matches[1]);
- $listtag = "ol";
-
$tmpline = preg_replace("/^([#*]*\#)/", "", $tmpline);
! $html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs);
! $html .= "<li>";
// definition lists <DL>: ";text:text"
--- 203,209 ----
// this is part of an ordered list
$numtabs = strlen($matches[1]);
$tmpline = preg_replace("/^([#*]*\#)/", "", $tmpline);
! $html .= SetHTMLOutputMode('ol', NESTED_LEVEL, $numtabs);
! $html .= '<li>';
// definition lists <DL>: ";text:text"
***************
*** 209,242 ****
// this is a dictionary list item
$numtabs = strlen($matches[1]);
! $html .= SetHTMLOutputMode("dl", SINGLE_DEPTH, $numtabs);
$tmpline = '';
if(trim($matches[2]))
! $tmpline = "<dt>" . $matches[2];
! $tmpline .= "<dd>" . $matches[3];
} elseif (preg_match("/^\s+/", $tmpline)) {
// this is preformatted text, i.e. <pre>
! $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%%", $quick_search_box, $tmpline);
! $tmpline = str_replace("%%Fullsearch%%", $full_search_box, $tmpline);
! $tmpline = str_replace("%%Mostpopular%%", $most_popular_list, $tmpline);
! if(defined('WIKI_ADMIN') && strstr($tmpline, "%%ADMIN-"))
$tmpline = ParseAdminTokens($tmpline);
///////////////////////////////////////////////////////
// Replace tokens
--- 211,248 ----
// this is a dictionary list item
$numtabs = strlen($matches[1]);
! $html .= SetHTMLOutputMode('dl', NESTED_LEVEL, $numtabs);
$tmpline = '';
if(trim($matches[2]))
! $tmpline = '<dt>' . $matches[2];
! $tmpline .= '<dd>' . $matches[3];
!
+ //////////////////////////////////////////////////////////
+ // remaining modes: preformatted text, headings, normal text
} elseif (preg_match("/^\s+/", $tmpline)) {
// this is preformatted text, i.e. <pre>
! $html .= SetHTMLOutputMode('pre', ZERO_LEVEL, 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_LEVEL, 0);
} else {
// it's ordinary output if nothing else
! $html .= SetHTMLOutputMode('p', ZERO_LEVEL, 0);
}
! $tmpline = str_replace('%%Search%%', $quick_search_box, $tmpline);
! $tmpline = str_replace('%%Fullsearch%%', $full_search_box, $tmpline);
! $tmpline = str_replace('%%Mostpopular%%', $most_popular_list, $tmpline);
! if(defined('WIKI_ADMIN') && strstr($tmpline, '%%ADMIN-'))
$tmpline = ParseAdminTokens($tmpline);
+
///////////////////////////////////////////////////////
// Replace tokens
***************
*** 246,252 ****
! $html .= "$tmpline\n";
}
! $html .= SetHTMLOutputMode("", ZERO_DEPTH, 0);
?>
--- 252,258 ----
! $html .= $tmpline . "\n";
}
! $html .= SetHTMLOutputMode('', ZERO_LEVEL, 0);
?>
|