includes/wikiengine/Tables.php
author Dan
Wed, 08 Jul 2009 18:50:17 -0400
changeset 1039 4226cedb3bc4
parent 1027 98c052fc3337
child 1073 b19a9bcb6a45
permissions -rw-r--r--
Fixed one unlocalized string in sidebar editor; fixed sidebar editor jQuery init race condition seen under Firefox and Chromium on 64-bit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
166
d53cc29308f4 Rebrand as 1.1.1; everything should now be bumped to "unstable" status
Dan
parents: 163
diff changeset
     3
/*
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
801
eb8b23f11744 Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents: 685
diff changeset
     5
 * Version 1.1.6 (Caoineag beta 1)
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 507
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
 * This script contains code originally found in MediaWiki (http://www.mediawiki.org). MediaWiki is also licensed under
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    15
 * the GPLv2 or later; see the file GPL included with this package for details.
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    16
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    17
 * We're using the MW parser because the Text_Wiki version simply refused to work under PHP 5.2.0. Porting this was
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
 * _not_ easy. <leaves to get cup of coffee>
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    19
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    20
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    21
global $mStripState, $wgRandomKey;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    22
$mStripState = Array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    23
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    24
/**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    25
 * emulate mediawiki parser, including stripping, etc.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    26
 *
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    27
 * @param string $text the text to parse
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    28
 * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    29
 * @access public
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    30
 */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    31
 
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    32
function process_tables( $text )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    33
{
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    34
  // include some globals, do some parser stuff that would normally be done in the parent parser function
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    35
  global $mStripState;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    36
  $x =& $mStripState;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    37
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    38
  // parse the text
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    39
  $text = doTableStuff($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    40
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    41
  return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    42
}
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    43
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    44
/**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    45
 * parse the wiki syntax used to render tables
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    46
 *
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    47
 * @param string $t the text to parse
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    48
 * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    49
 * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    50
 */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    51
function doTableStuff( $t ) {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    53
  $t = explode ( "\n" , $t ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    54
  $td = array () ; # Is currently a td tag open?
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    55
  $ltd = array () ; # Was it TD or TH?
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    56
  $tr = array () ; # Is currently a tr tag open?
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    57
  $ltr = array () ; # tr attributes
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    58
  $has_opened_tr = array(); # Did this table open a <tr> element?
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    59
  $indent_level = 0; # indent level of the table
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    60
  foreach ( $t AS $k => $x )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
  {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    62
    $x = trim ( $x ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    63
    $fc = substr ( $x , 0 , 1 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    64
    if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    65
      $indent_level = strlen( $matches[1] );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    66
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    67
      $attributes = unstripForHTML( $matches[2] );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    68
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    69
      $t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    70
        '<_paragraph_bypass><table' . fixTagAttributes( $attributes, 'table' ) . '>' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    71
      array_push ( $td , false ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    72
      array_push ( $ltd , '' ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    73
      array_push ( $tr , false ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    74
      array_push ( $ltr , '' ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    75
      array_push ( $has_opened_tr, false );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    76
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    77
    else if ( count ( $td ) == 0 ) { } # Don't do any of the following
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    78
    else if ( '|}' == substr ( $x , 0 , 2 ) ) {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    79
      $z = "</table></_paragraph_bypass>" . substr ( $x , 2);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    80
      $l = array_pop ( $ltd ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    81
      if ( !array_pop ( $has_opened_tr ) ) $z = "<tr><td></td></tr>" . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    82
      if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    83
      if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    84
      array_pop ( $ltr ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    85
      $t[$k] = $z . str_repeat( '</dd></dl>', $indent_level );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    86
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    87
    else if ( '|-' == substr ( $x , 0 , 2 ) ) { # Allows for |---------------
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    88
      $x = substr ( $x , 1 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    89
      while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    90
      $z = '' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    91
      $l = array_pop ( $ltd ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    92
      array_pop ( $has_opened_tr );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    93
      array_push ( $has_opened_tr , true ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    94
      if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    95
      if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    96
      array_pop ( $ltr ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    97
      $t[$k] = $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    98
      array_push ( $tr , false ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    99
      array_push ( $td , false ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   100
      array_push ( $ltd , '' ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   101
      $attributes = unstripForHTML( $x );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   102
      array_push ( $ltr , fixTagAttributes( $attributes, 'tr' ) ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   103
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   104
    else if ( '|' == $fc || '!' == $fc || '|+' == substr ( $x , 0 , 2 ) ) { # Caption
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   105
      # $x is a table row
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   106
      if ( '|+' == substr ( $x , 0 , 2 ) ) {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   107
        $fc = '+' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   108
        $x = substr ( $x , 1 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   109
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   110
      $after = substr ( $x , 1 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   111
      if ( $fc == '!' ) $after = str_replace ( '!!' , '||' , $after ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   112
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   113
      // Split up multiple cells on the same line.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   114
      // FIXME: This can result in improper nesting of tags processed
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   115
      // by earlier parser steps, but should avoid splitting up eg
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   116
      // attribute values containing literal "||".
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   117
      $after = wfExplodeMarkup( '||', $after );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   118
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   119
      $t[$k] = '' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   120
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   121
      # Loop through each table cell
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   122
      foreach ( $after AS $theline )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   123
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   124
        $z = '' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   125
        if ( $fc != '+' )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   126
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   127
          $tra = array_pop ( $ltr ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   128
          if ( !array_pop ( $tr ) ) $z = '<tr'.$tra.">\n" ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   129
          array_push ( $tr , true ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   130
          array_push ( $ltr , '' ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   131
          array_pop ( $has_opened_tr );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   132
          array_push ( $has_opened_tr , true ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   133
        }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   134
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   135
        $l = array_pop ( $ltd ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   136
        if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   137
        if ( $fc == '|' ) $l = 'td' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   138
        else if ( $fc == '!' ) $l = 'th' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   139
        else if ( $fc == '+' ) $l = 'caption' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   140
        else $l = '' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   141
        array_push ( $ltd , $l ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   142
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   143
        # Cell parameters
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   144
        $y = explode ( '|' , $theline , 2 ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   145
        # Note that a '|' inside an invalid link should not
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   146
        # be mistaken as delimiting cell parameters
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   147
        if ( strpos( $y[0], '[[' ) !== false ) {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   148
          $y = array ($theline);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   149
        }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   150
        if ( count ( $y ) == 1 )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   151
          $y = "{$z}<{$l}>{$y[0]}" ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   152
        else {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   153
          $attributes = unstripForHTML( $y[0] );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   154
          $y = "{$z}<{$l}".fixTagAttributes($attributes, $l).">{$y[1]}" ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   155
        }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   156
        $t[$k] .= $y ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   157
        array_push ( $td , true ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   158
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   159
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   160
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   161
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   162
  # Closing open td, tr && table
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   163
  while ( count ( $td ) > 0 )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   164
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   165
    $l = array_pop ( $ltd ) ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   166
    if ( array_pop ( $td ) ) $t[] = '</td>' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   167
    if ( array_pop ( $tr ) ) $t[] = '</tr>' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   168
    if ( !array_pop ( $has_opened_tr ) ) $t[] = "<tr><td></td></tr>" ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   169
    $t[] = '</table></_paragraph_bypass>' ;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   170
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   171
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   172
  $t = implode ( "\n" , $t ) ;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   173
  
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   174
  # special case: don't return empty table
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   175
  if($t == "<table>\n<tr><td></td></tr>\n</table>")
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   176
    $t = '';
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   177
  return $t ;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   178
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   179