Subversion Repositories Applications.papyrus

Rev

Rev 172 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 172 Rev 173
Line 1... Line 1...
1
<?php
1
<?php
2
// $Id: Table.php,v 1.1 2004-11-24 19:43:09 jpm Exp $
2
// $Id: Table.php,v 1.2 2004-11-25 15:36:19 jpm Exp $
Line 3... Line 3...
3
 
3
 
4
 
4
 
5
/**
5
/**
Line 30... Line 30...
30
    * 
30
    * 
31
    * @see parse()
31
    * @see parse()
32
    * 
32
    * 
33
    */
33
    */
Line 34... Line 34...
34
    
34
    
Line 35... Line 35...
35
    var $regex = '/\n((\[\|).+?)(\|\])/ms';
35
    var $regex = '/\n(\[\|(.*)\n)(.+)(\n\|\])/Ums';
36
    
36
    
37
    
37
    
Line 76... Line 76...
76
        
76
        
77
        // the number of rows in the table
77
        // the number of rows in the table
Line 78... Line 78...
78
        $num_rows = 0;
78
        $num_rows = 0;
79
        
79
        
Line 80... Line 80...
80
        // rows are separated by newlines in the matched text
80
        // rows are separated by newlines in the matched text
81
        $rows = explode("\n", $matches[1]);
81
        $rows = explode("\n", $matches[3]);
Line 82... Line 82...
82
        
82
        
83
        // loop through each row
83
        // loop through each row
Line 84... Line -...
84
        foreach ($rows as $row) {
-
 
85
            
-
 
86
            // increase the row count
-
 
87
            $num_rows ++;
-
 
88
            
-
 
89
            // start a new row
-
 
90
            $return .= $this->wiki->addToken(
84
        foreach ($rows as $row) {
91
                $this->rule,
85
            
Line 92... Line 86...
92
                array('type' => 'row_start')
86
            // increase the row count
93
            );
87
            $num_rows ++;
Line 103... Line 97...
103
            if ($last - 1 > $num_cols) {
97
            if ($last - 1 > $num_cols) {
104
                // increase the column count
98
                // increase the column count
105
                $num_cols = $last - 1;
99
                $num_cols = $last - 1;
106
            }
100
            }
Line -... Line 101...
-
 
101
            
107
            
102
            // Les attributs de la ligne
-
 
103
            if (preg_match('/^!(.*)!$/U', $cell[0], $morceaux)) {
-
 
104
                $attr = $morceaux[1];
108
            // by default, cells span only one column (their own)
105
            } else {
-
 
106
                $attr = '';
-
 
107
            }
-
 
108
            
-
 
109
            // start a new row
-
 
110
            $return .= $this->wiki->addToken(
-
 
111
                $this->rule,
-
 
112
                array(  'type' => 'row_start',
-
 
113
                        'attr' => $attr,
-
 
114
                        'span' => 1)
Line 109... Line 115...
109
            $span = 1;
115
            );
110
            
116
            
111
            // ignore cell zero, and ignore the "last" cell; cell zero
117
            // ignore cell zero, and ignore the "last" cell; cell zero
112
            // is before the first double-pipe, and the "last" cell is
118
            // is before the first double-pipe, and the "last" cell is
113
            // after the last double-pipe. both are always empty.
119
            // after the last double-pipe. both are always empty.
114
            for ($i = 1; $i < $last; $i ++) {
120
            for ($i = 1; $i < $last; $i ++) {
115
                // if there is no content at all, then it's an instance
121
                // if there is no content at all, then it's an instance
116
                // of two sets of || next to each other, indicating a
122
                // of two sets of || next to each other, indicating a
117
                // span.
-
 
118
                if ($cell[$i] == '') {
-
 
119
                    
-
 
120
                    // add to the span and loop to the next cell
123
                // span.
121
                    $span += 1;
-
 
122
                    continue;
124
                if ($cell[$i] == '') {
123
                    
-
 
124
                } else {
125
                    continue;
125
                    
-
 
126
                    // this cell has content.
126
                } else {
127
                    
127
                    // this cell has content.
128
                    // find any special "attr"ibute cell markers
128
                    // find any special "attr"ibute cell markers
129
                    if (substr($cell[$i], 0, 2) == '> ') {
129
                    if (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) != ' ') {
130
                        // right-align
130
                        // right-align
131
                        $attr = 'right';
131
                        $attr = 'align="right"';
132
                        $cell[$i] = substr($cell[$i], 2);
132
                        $cell[$i] = substr($cell[$i], 1);
133
                    } elseif (substr($cell[$i], 0, 2) == '= ') {
133
                    } elseif (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) == ' ') {
134
                        // center-align
134
                        // center-align
135
                        $attr = 'center';
135
                        $attr = 'align="center"';
136
                        $cell[$i] = substr($cell[$i], 2);
136
                        $cell[$i] = substr(substr($cell[$i], 1), 0, -1);
137
                    } elseif (substr($cell[$i], 0, 2) == '< ') {
137
                    } elseif (substr($cell[$i], 0, 1) != ' ' && substr($cell[$i], -1, 1) == ' ') {
138
                        // left-align
-
 
139
                        $attr = 'left';
-
 
140
                        $cell[$i] = substr($cell[$i], 2);
-
 
141
                    } elseif (substr($cell[$i], 0, 2) == '~ ') {
138
                        // left-align
142
                        $attr = 'header';
139
                        $attr = 'align="left"';
143
                        $cell[$i] = substr($cell[$i], 2);
140
                        $cell[$i] = substr($cell[$i], 0, -1);
144
                    } else {
141
                    } else {
Line -... Line 142...
-
 
142
                        $attr = null;
-
 
143
                    }
-
 
144
                    
-
 
145
                    if (substr($cell[$i], 0, 1) == '!') {
-
 
146
                        // Les attributs de la cellule
-
 
147
                        preg_match('/^!(.*)!(.*)$/U', $cell[$i], $morceaux);
-
 
148
                        $attr .= ' '.$morceaux[1];
145
                        $attr = null;
149
                        $cell[$i] = $morceaux[2];
146
                    }
150
                    }
147
                    
151
                    
148
                    // start a new cell...
152
                    // start a new cell...
149
                    $return .= $this->wiki->addToken(
153
                    $return .= $this->wiki->addToken(
150
                        $this->rule, 
154
                        $this->rule, 
151
                        array (
155
                        array (
152
                            'type' => 'cell_start',
156
                            'type' => 'cell_start',
-
 
157
                            'attr' => $attr,
153
                            'attr' => $attr,
158
                            'span' => 1
Line 154... Line 159...
154
                            'span' => $span
159
                        ),
155
                        )
160
                        false
Line 156... Line 161...
156
                    );
161
                    );
157
                    
162
                    
158
                    // ...add the content...
163
                    // ...add the content...
159
                    $return .= trim($cell[$i]);
164
                    $return .= trim($cell[$i]);
160
                    
165
                    
161
                    // ...and end the cell.
166
                    // ...and end the cell.
162
                    $return .= $this->wiki->addToken(
167
                    $return .= $this->wiki->addToken(
163
                        $this->rule, 
168
                        $this->rule, 
164
                        array (
169
                        array (
165
                            'type' => 'cell_end',
-
 
166
                            'attr' => $attr,
-
 
167
                            'span' => $span
-
 
168
                        )
170
                            'type' => 'cell_end',
169
                    );
-
 
170
                    
171
                            'attr' => $attr
Line 171... Line 172...
171
                    // reset the span.
172
                        ),
172
                    $span = 1;
173
                        false
173
                }
174
                    );
Line 187... Line 188...
187
            $this->wiki->addToken(
188
            $this->wiki->addToken(
188
                $this->rule,
189
                $this->rule,
189
                array(
190
                array(
190
                    'type' => 'table_start',
191
                    'type' => 'table_start',
191
                    'rows' => $num_rows,
192
                    'rows' => $num_rows,
192
                    'cols' => $num_cols
193
                    'cols' => $num_cols,
-
 
194
                    'attr' => $matches[2]
193
                )
195
                )
194
            )
196
            )
195
            . $return .
197
            . $return .
196
            $this->wiki->addToken(
198
            $this->wiki->addToken(
197
                $this->rule,
199
                $this->rule,