From b4c4d643a45cb16f3c311cc3aa0f104541d6a4ca Mon Sep 17 00:00:00 2001 From: ahollosi Date: Thu, 4 Jan 2001 18:34:15 +0000 Subject: [PATCH] ZERO/SINGLE_DEPTH renamed into ZERO/NESTED_LEVEL empty lines are now treated as tag '' (i.e. no tag) instead of '

' normal text is now treated as '

' instead of tag '' added and corrected some comments, some code cleanup git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@364 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/transform.php | 128 ++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/lib/transform.php b/lib/transform.php index 9ed8e4028..70a30b6ea 100644 --- a/lib/transform.php +++ b/lib/transform.php @@ -1,14 +1,12 @@ - -[$i]"; + $embedded[$i] = LinkURL($pagehash['refs'][$i], "[$i]"); } } } - $numlines = count($pagehash["content"]); // only call these once, for efficiency $quick_search_box = RenderQuickSearch(); @@ -42,17 +39,19 @@ // Loop over all lines of the page and apply transformation rules + $numlines = count($pagehash["content"]); + for ($index = 0; $index < $numlines; $index++) { unset($tokens); unset($replacements); $ntokens = 0; $replacements = array(); - $tmpline = $pagehash["content"][$index]; + $tmpline = $pagehash['content'][$index]; if (!strlen($tmpline) || $tmpline == "\r") { // this is a blank line, send

- $html .= SetHTMLOutputMode("p", ZERO_DEPTH, 0); + $html .= SetHTMLOutputMode('', ZERO_LEVEL, 0); continue; } @@ -62,7 +61,7 @@ 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 .= SetHTMLOutputMode("", ZERO_LEVEL, 0); $html .= $matches[2]; continue; } @@ -75,15 +74,15 @@ your web server it is highly advised that you do not allow this. // First need to protect [[. $oldn = $ntokens; - $tmpline = tokenize($tmpline, "\[\[", $replacements, $ntokens); + $tmpline = tokenize($tmpline, '\[\[', $replacements, $ntokens); while ($oldn < $ntokens) - $replacements[$oldn++] = "["; + $replacements[$oldn++] = '['; // Now process the [\d+] links which are numeric references $oldn = $ntokens; - $tmpline = tokenize($tmpline, "\[\s*\d+\s*\]", $replacements ,$ntokens); + $tmpline = tokenize($tmpline, '\[\s*\d+\s*\]', $replacements, $ntokens); while ($oldn < $ntokens) { - $num = (int)substr($replacements[$oldn], 1); + $num = (int) substr($replacements[$oldn], 1); if (! empty($embedded[$num])) $replacements[$oldn] = $embedded[$num]; $oldn++; @@ -91,7 +90,7 @@ your web server it is highly advised that you do not allow this. // match anything else between brackets $oldn = $ntokens; - $tmpline = tokenize($tmpline, "\[.+?\]", $replacements, $ntokens); + $tmpline = tokenize($tmpline, '\[.+?\]', $replacements, $ntokens); while ($oldn < $ntokens) { $link = ParseAndLink($replacements[$oldn]); $replacements[$oldn] = $link['link']; @@ -101,6 +100,7 @@ your web server it is highly advised that you do not allow this. ////////////////////////////////////////////////////////// // 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); while ($oldn < $ntokens) { @@ -129,22 +129,24 @@ your web server it is highly advised that you do not allow this. $oldn++; } + + ////////////////////////////////////////////////////////// // escape HTML metachars - $tmpline = str_replace("&", "&", $tmpline); - $tmpline = str_replace(">", ">", $tmpline); - $tmpline = str_replace("<", "<", $tmpline); + $tmpline = str_replace('&', '&', $tmpline); + $tmpline = str_replace('>', '>', $tmpline); + $tmpline = str_replace('<', '<', $tmpline); // four or more dashes to


- $tmpline = ereg_replace("^-{4,}", "
", $tmpline); + $tmpline = ereg_replace("^-{4,}", '
', $tmpline); // %%% are linebreaks - $tmpline = str_replace("%%%", "
", $tmpline); + $tmpline = str_replace('%%%', '
', $tmpline); - // bold italics + // bold italics (old way) $tmpline = preg_replace("|(''''')(.*?)(''''')|", "\\2", $tmpline); - // bold + // bold (old way) $tmpline = preg_replace("|(''')(.*?)(''')|", "\\2", $tmpline); @@ -157,30 +159,34 @@ your web server it is highly advised that you do not allow this. "\\2", $tmpline); - // HTML modes: pre, unordered/ordered lists, term/def (using TAB) + ////////////////////////////////////////////////////////// + // unordered, ordered, and dictionary list (using TAB) + if (preg_match("/(^\t+)(.*?)(:\t)(.*$)/", $tmpline, $matches)) { - // this is a dictionary list item + // this is a dictionary list (
) item $numtabs = strlen($matches[1]); - $html .= SetHTMLOutputMode("dl", SINGLE_DEPTH, $numtabs); + $html .= SetHTMLOutputMode('dl', NESTED_LEVEL, $numtabs); $tmpline = ''; if(trim($matches[2])) - $tmpline = "
" . $matches[2]; - $tmpline .= "
" . $matches[4]; + $tmpline = '
' . $matches[2]; + $tmpline .= '
' . $matches[4]; } elseif (preg_match("/(^\t+)(\*|\d+|#)/", $tmpline, $matches)) { - // this is part of a list + // this is part of a list (
    ,
      ) $numtabs = strlen($matches[1]); - if ($matches[2] == "*") { - $listtag = "ul"; + if ($matches[2] == '*') { + $listtag = 'ul'; } else { - $listtag = "ol"; // a rather tacit assumption. oh well. + $listtag = 'ol'; // a rather tacit assumption. oh well. } $tmpline = preg_replace("/^(\t+)(\*|\d+|#)/", "", $tmpline); - $html .= SetHTMLOutputMode($listtag, SINGLE_DEPTH, $numtabs); - $html .= "
    1. "; + $html .= SetHTMLOutputMode($listtag, NESTED_LEVEL, $numtabs); + $html .= '
    2. '; + - // tabless markup for unordered and ordered lists - // list types can be mixed, so we only look at the last + ////////////////////////////////////////////////////////// + // 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. @@ -188,56 +194,56 @@ your web server it is highly advised that you do not allow this. } 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 .= "
    3. "; + $tmpline = preg_replace("/^([#*]*\*)/", '', $tmpline); + $html .= SetHTMLOutputMode('ul', NESTED_LEVEL, $numtabs); + $html .= '
    4. '; // ordered lists
        : "#" } 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 .= "
      1. "; + $html .= SetHTMLOutputMode('ol', NESTED_LEVEL, $numtabs); + $html .= '
      2. '; // definition lists
        : ";text:text" } elseif (preg_match("/(^;+)(.*?):(.*$)/", $tmpline, $matches)) { // this is a dictionary list item $numtabs = strlen($matches[1]); - $html .= SetHTMLOutputMode("dl", SINGLE_DEPTH, $numtabs); + $html .= SetHTMLOutputMode('dl', NESTED_LEVEL, $numtabs); $tmpline = ''; if(trim($matches[2])) - $tmpline = "
        " . $matches[2]; - $tmpline .= "
        " . $matches[3]; + $tmpline = '
        ' . $matches[2]; + $tmpline .= '
        ' . $matches[3]; + + ////////////////////////////////////////////////////////// + // remaining modes: preformatted text, headings, normal text } elseif (preg_match("/^\s+/", $tmpline)) { // this is preformatted text, i.e.
        -         $html .= SetHTMLOutputMode("pre", ZERO_DEPTH, 0);
        +         $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_DEPTH, 0);
        +	 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("", ZERO_DEPTH, 0);
        +         $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 = 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
         
        @@ -245,8 +251,8 @@ your web server it is highly advised that you do not allow this.
         	  $tmpline = str_replace($FieldSeparator.$FieldSeparator.$i.$FieldSeparator, $replacements[$i], $tmpline);
         
         
        -      $html .= "$tmpline\n";
        +      $html .= $tmpline . "\n";
            }
         
        -   $html .= SetHTMLOutputMode("", ZERO_DEPTH, 0);
        +   $html .= SetHTMLOutputMode('', ZERO_LEVEL, 0);
         ?>
        -- 
        2.45.0