1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
<?php
namespace Bitweaver\Liberty;
use Bitweaver\BitBase;
use Bitweaver\KernelTools;
use Bitweaver\BitSystem;
/**
* @version $Revision$
* @package liberty
* @subpackage plugins_format
*/
global $gLibertySystem;
/**
* definitions
*/
define( 'PLUGIN_GUID_TIKIWIKI', 'tikiwiki' );
$pluginParams = [
'auto_activate' => false,
'store_function' => 'tikiwiki_save_data',
'load_function' => 'tikiwiki_parse_data',
'verify_function' => 'tikiwiki_verify_data',
'description' => 'TikiWiki Syntax Format Parser',
'edit_label' => 'Tiki Wiki Syntax',
'edit_field' => PLUGIN_GUID_TIKIWIKI,
'help_page' => 'TikiWikiSyntax',
'plugin_type' => FORMAT_PLUGIN,
'linebreak' => "\r\n",
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_TIKIWIKI, $pluginParams );
/**
* tikiwiki_save_data
*/
function tikiwiki_save_data( &$pParamHash ) {
static $parser;
if( empty( $parser ) ) {
$parser = new TikiWikiParser();
}
}
function tikiwiki_verify_data( &$pParamHash ) {
$errorMsg = null;
$pParamHash['content_store']['data'] = $pParamHash['edit'];
return $errorMsg;
}
function tikiwiki_parse_data( &$pParseHash, &$pCommonObject ) {
global $gBitSystem;
$ret = '';
static $parser;
if( empty( $parser ) ) {
$parser = new TikiWikiParser();
}
$ret = $parser->parseData( $pParseHash, $pCommonObject );
return $ret;
}
/**
* TikiWikiParser
*
* @package kernel
*/
class TikiWikiParser extends BitBase {
function TikiWikiParser() {
parent::__construct();
}
// This function handles wiki codes for those special HTML characters
// that textarea won't leave alone.
function parseHtmlchar( &$pData ) {
// cleaning some user input
$pData = preg_replace( "/&(?!([a-z]{1,7};))/", "&", $pData );
// oft-used characters (case insensitive)
$patterns = [
"~bull~" => "•",
"~bs~" => "\",
"~hs~" => " ",
"~amp~" => "&",
"~ldq~" => "“",
"~rdq~" => "”",
"~lsq~" => "‘",
"~rsq~" => "’",
"~copy~" => "©",
"~c~" => "©",
"~--~" => "—",
" -- " => " — ",
"~lt~" => "<",
"~gt~" => ">",
"~euro~" => "€",
];
foreach( $patterns as $pattern => $replace ) {
$pData = str_ireplace( $pattern, $replace, $pData );
}
// add an easy method to clear floats
$pData = preg_replace( "/(\r|\n)?~clear~/i", '<br style="clear:both;" />', $pData );
// HTML numeric character entities
$pData = preg_replace( "/~([0-9]+)~/", "&#$1;", $pData );
}
function getLinks( $pData ) {
$links = [];
// Match things like [...], but ignore things like [[foo].
// -Robin
if( preg_match_all( "/(?<!\[)\[([^\[\|\]]+)(\||\])/", $pData, $r1 )) {
$links = array_unique( $r1[1] );
}
return $links;
}
function howManyAtStart($str, $car) {
$cant = 0;
$i = 0;
while (($i < strlen($str)) && isset($str[$i]) && ($str[$i]== $car)) {
$i++;
$cant++;
}
return $cant;
}
function parseMediawikiTables( $pData ) {
// Find all matches to {|...|} with no {| inside.
while( preg_match( '/\n?\{\|(.*?)\n\|\}/sm', $pData, $matches )) {
$table_data = str_replace( "\r", "", $matches[1] );
$table_data = str_replace( '||', "\n|", $table_data );
// get all instances where put in info like: background=blue and convert it to background="blue"
$xhtmlfix['pattern'] = "!=([^'\"][^\s]*)!";
$xhtmlfix['replace'] = '="$1"';
while( preg_match('/^![^!]+!!/m', $table_data )) {
/* Replace !! with \n! but ONLY in !-defined header rows. */
$table_data = preg_replace( '/^!([^!]+)!!/m', "!$1\n!", $table_data );
}
if( substr( $table_data, 0, 1 ) != "\n" ) {
// We have table parameters.
list( $table_params, $table_data ) = explode( "\n", $table_data, 2 );
$table_params = preg_replace( $xhtmlfix['pattern'], $xhtmlfix['replace'], trim( $table_params ));
/* TODO: This attempt to support foo:bar table params needs help!
if (strlen($table_params)) {
$table_params = preg_replace("/\b(\w+):/", '$1=', $table_params);
}
*/
} else {
$table_params = '';
}
// apply default class if no other class has been set
if( !empty( $table_params ) && strpos( 'class=', $table_params ) !== false ) {
$table_params .= ' class="table"';
}
$content = "<table $table_params>";
$lines = explode( "\n", str_replace( "\\n", "<br />", $table_data ));
$row = 0;
foreach( $lines as $line ) {
if(( substr( $line, 0, 1 ) == '|' ) || ( substr( $line, 0, 1 ) == '!' )) {
if( preg_match( '/^\|\+\s*(.+)$/', $line, $row_matches )) {
$content .= "<caption>$row_matches[1]</caption>";
} elseif( preg_match( '/^\|-\s*(.+)?$/', $line, $row_matches )) {
if( $row ) {
$content .= '</tr>';
$row++;
} else {
$row = 1;
}
if( !empty( $row_matches[1] )) {
$row_matches[1] = preg_replace( $xhtmlfix['pattern'], $xhtmlfix['replace'], trim( $row_matches[1] ));
$content .= "<tr {$row_matches[1]}>";
} else {
$content .= '<tr>';
}
} elseif( preg_match( '/^([\|!])\s*([^\|]+\s*\|)?\s*(.*)$/', $line, $row_matches )) {
if( !$row ) {
$content .= '<tr>';
$row = 1;
}
if( !empty( $row_matches[2] )) {
$row_matches[2] = preg_replace( $xhtmlfix['pattern'], $xhtmlfix['replace'], trim( $row_matches[2] ));
}
$td = 't'.(( $row_matches[1] == '!' ) ? 'h' : 'd' );
$content .= "<$td".(( !empty( $row_matches[2] )) ? ' '.trim( substr( $row_matches[2], 0, -1 )) : '' ).'>'.$row_matches[3]."</$td>";
} else {
$content .= "<!-- ERROR: Ignoring invalid line \"$line\" -->";
}
} else {
$content .= "<!-- ERROR: Ignoring invalid line \"$line\" -->";
}
}
$content .= '</tr></table>';
$pData = str_replace( $matches[0], $content, $pData );
}
return $pData;
}
function parseData( $pParseHash, &$pCommonObject ) {
global $gBitSystem, $gLibertySystem, $gBitUser, $page;
$data = $pParseHash['data'];
$contentId = $pParseHash['content_id'];
// this is used for setting the links when section editing is enabled
$section_count = 1;
if( $gBitSystem->isPackageActive( 'wiki' ) ) {
// force wiki page to load
global $gLibertySystem;
$gLibertySystem->getContentClassName( 'bitpage' );
}
// only strip out html if needed
if( $gBitSystem->isFeatureActive( 'content_allow_html' ) || $gBitSystem->isFeatureActive( 'content_force_allow_html' )) {
// we allow html unconditionally with this parser
} else {
// we are parsing this page and we either have no way of checking permissions or we have no need for html
$data = htmlspecialchars( $data, ENT_NOQUOTES, 'UTF-8' );
}
// Extract [link] sections (to be re-inserted later)
$noparsedlinks = [];
// This section matches [...].
// Added handling for [[foo] sections. -rlpowell
preg_match_all("/(?<!\[)\[([^\[][^\]]+)\]/", $data, $noparseurl);
foreach (array_unique($noparseurl[1])as $np) {
$key = md5(BitSystem::genPass());
$aux["key"] = $key;
$aux["data"] = $np;
$noparsedlinks[] = $aux;
$data = str_replace("$np", $key, $data);
}
// Replace special characters
//done after url catching because otherwise urls of dyn. sites will be modified
$this->parseHtmlchar( $data );
//$data = strip_tags($data);
// BiDi markers
$bidiCount = 0;
$bidiCount = preg_match_all("/(\{l2r\})/", $data, $pages);
$bidiCount += preg_match_all("/(\{r2l\})/", $data, $pages);
$data = preg_replace("/\{l2r\}/", "<div dir='ltr'>", $data);
$data = preg_replace("/\{r2l\}/", "<div dir='rtl'>", $data);
$data = preg_replace("/\{lm\}/", "‎", $data);
$data = preg_replace("/\{rm\}/", "‏", $data);
// Parse MediaWiki-style pipe syntax tables.
if(( strpos( $data, "{|" ) === 0 || strpos( $data, "\n{|" ) !== false ) && strpos( $data, "\n|}" ) !== false ) {
$data = $this->parseMediawikiTables($data);
}
// ============================================= this should go - xing
// Replace dynamic variables
// Dynamic variables are similar to dynamic content but they are editable
// from the page directly, intended for short data, not long text but text
// will work too
// Now won't match HTML-style '%nn' letter codes.
/*
if (preg_match_all("/%([^% 0-9][^% 0-9][^% ]*)%/",$data,$dvars)) {
// remove repeated elements
$dvars = array_unique($dvars[1]);
// Now replace each dynamic variable by a pair composed of the
// variable value and a text field to edit the variable. Each
foreach($dvars as $dvar) {
$query = "select `data` from `".BIT_DB_PREFIX."liberty_dynamic_variables` where `name`=?";
$result = $this->mDb->query($query,Array($dvar));
if($result->numRows()) {
$value = $result->fetchRow();
$value = $value["data"];
} else {
//Default value is null
$value = "NaV";
}
// Now build 2 divs
$id = 'dyn_'.$dvar;
if( $gBitUser->hasPermission( 'p_wiki_edit_dynvar' ) ) {
$span1 = "<span style='display:inline;' id='dyn_".$dvar."_display'><a class='dynavar' onclick='javascript:toggle_dynamic_var(\"$dvar\");' title='".KernelTools::tra('Click to edit dynamic variable').": $dvar'>$value</a></span>";
$span2 = "<span style='display:none;' id='dyn_".$dvar."_edit'><input type='text' name='dyn_".$dvar."' value='".$value."' /></span>";
} else {
$span1 = "<span class='dynavar' style='display:inline;' id='dyn_".$dvar."_display'>$value</span>";
$span2 = '';
}
$html = $span1.$span2;
//It's important to replace only once
$dvar_preg = preg_quote( $dvar );
$data = preg_replace("+%$dvar_preg%+",$html,$data,1);
//Further replacements only with the value
$data = str_replace("%$dvar%",$value,$data);
}
//At the end put an update button
//<br /><div style="text-align:center"><input type="submit" name="dyn_update" value="'.KernelTools::tra('Update variables').'"/></div>
$data='<form method="post" name="dyn_vars">'.$data.'<div style="display:none;"><input type="submit" name="_dyn_update" value="'.KernelTools::tra('Update variables').'"/></div></form>';
}
*/
// Replace boxes - add a new line that we can have something like: ^!heading^ without the need for a \n after the initial ^ - \n will be removed below
$data = preg_replace("/\^([^\^]+)\^/", "<div class=\"alert alert-info bitbox\"><!-- bitremovebr -->\n$1</div>", $data);
// Replace colors ~~color:text~~
$data = preg_replace("/\~\~([^\:]+):([^\~]+)\~\~/", "<span style=\"color:$1;\">$2</span>", $data);
// Replace background colors ++color:text++
$data = preg_replace("/\+\+([^\s][^\: ]+):([^\+]+)\+\+/", "<span style=\"background:$1;\">$2</span>", $data);
// Underlined text
$data = preg_replace("/===([^\=]+)===/", "<span style=\"text-decoration:underline;\">$1</span>", $data);
// Center text
$data = preg_replace("/::(.+?)::/", "<div style=\"text-align:center;\">$1</div>", $data);
// Line breaks
$data = preg_replace('/%%%/', '<br />', $data);
// reinsert hash-replaced links into page
foreach ($noparsedlinks as $np) {
$data = str_replace($np["key"], $np["data"], $data);
}
$links = $this->getLinks( $data );
// Note that there're links that are replaced
foreach( $links as $link ) {
$attributes = strstr( $link, $_SERVER["SERVER_NAME"] ) || !strstr( $link, '//' ) ? '' : 'class="external"';
// comments and anonymously created pages get nofollow
if( is_object( $pCommonObject ) && ( $pCommonObject::class == 'comments' || ( isset( $pCommonObject->mInfo['user_id'] ) && $pCommonObject->mInfo['user_id'] == ANONYMOUS_USER_ID ))) {
$attributes .= ' rel="nofollow" ';
}
// The (?<!\[) stuff below is to give users an easy way to
// enter square brackets in their output; things like [[foo]
// get rendered as [foo]. -rlpowell
// prepare link for pattern usage
$link2 = str_replace( "/", "\/", preg_quote( $link ));
$pattern = "/(?<!\[)\[$link2\|([^\]\|]+)([^\]])*\]/";
$data = preg_replace( $pattern, "<a $attributes href='$link'>$1</a>", $data );
$pattern = "/(?<!\[)\[$link2\]/";
$data = preg_replace( $pattern, "<a $attributes href='$link'>$link</a>", $data );
}
// Handle double square brackets. -rlpowell
$data = str_replace( "[[", "[", $data );
// now that all links have been taken care of, we can replace all email addresses with the encoded form
// this will also encode email addressed that have not been linked using []
$data = KernelTools::encode_email_addresses( $data );
if ($gBitSystem->getConfig('wiki_tables') != 'new') {
// New syntax for tables
if (preg_match_all("/\|\|(.*)\|\|/", $data, $tables)) {
$maxcols = 1;
$cols = [];
for ($i = 0; $i < count($tables[0]); $i++) {
$rows = explode('||', $tables[0][$i]);
$col[$i] = [];
for ($j = 0; $j < count($rows); $j++) {
$cols[$i][$j] = explode('|', $rows[$j]);
if (count($cols[$i][$j]) > $maxcols)
$maxcols = count($cols[$i][$j]);
}
}
for ($i = 0; $i < count($tables[0]); $i++) {
$repl = '<table class="table">';
for ($j = 0; $j < count($cols[$i]); $j++) {
$ncols = count($cols[$i][$j]);
if ($ncols == 1 && !$cols[$i][$j][0])
continue;
$repl .= '<tr class="'.( ( $j % 2 ) ? 'even' : 'odd' ).'">';
for ($k = 0; $k < $ncols; $k++) {
$repl .= '<td ';
if ($k == $ncols - 1 && $ncols < $maxcols)
$repl .= ' colspan="' . ($maxcols - $k).'"';
$repl .= '>' . $cols[$i][$j][$k] . '</td>';
}
$repl .= '</tr>';
}
$repl .= '</table>';
$data = str_replace($tables[0][$i], $repl, $data);
}
}
} else {
// New syntax for tables
// REWRITE THIS CODE
if( preg_match_all( "/\|\|(.*?)\|\|/s", $data, $tables ) ) {
$maxcols = 1;
$cols = [];
for( $i = 0; $i < count( $tables[0] ); $i++ ) {
$rows = preg_split( "/(\n|\<br\/\>)/", $tables[0][$i] );
$col[$i] = [];
for( $j = 0; $j < count( $rows ); $j++ ) {
$rows[$j] = str_replace( '||', '', $rows[$j] );
$cols[$i][$j] = explode( '|', $rows[$j] );
if( count( $cols[$i][$j] ) > $maxcols ) {
$maxcols = count( $cols[$i][$j] );
}
}
}
for( $i = 0; $i < count( $tables[0] ); $i++ ) {
$repl = '<table class="table table-striped">';
$th = preg_match( "#^~#", $cols[$i][0][0] ) && $cols[$i][0][0] = preg_replace( "#^~#", "", $cols[$i][0][0] ) ? true : false;
for( $j = 0; $j < count( $cols[$i] ); $j++ ) {
$ncols = count( $cols[$i][$j] );
if( $ncols == 1 && !$cols[$i][$j][0] ) {
continue;
}
if( $j == 0 && $th ) {
$repl .= '<tr>';
} else {
$repl .= '<tr class="'.( ( $j % 2 ) ? 'odd' : 'even' ).'">';
}
for( $k = 0; $k < $ncols; $k++ ) {
$thd = ( $j == 0 && $th ) ? 'th' : 'td';
$repl .= "<$thd";
if( $k == $ncols - 1 && $ncols < $maxcols ) {
$repl .= ' colspan="'.( $maxcols - $k ).'"';
}
$repl .= ">".( str_replace( "\\n", "<br />", $cols[$i][$j][$k] ) )."</$thd>";
}
$repl .= '</tr>';
}
$repl .= '</table>';
$data = str_replace($tables[0][$i], $repl, $data);
}
}
}
// Now tokenize the expression and process the tokens
// Use tab and newline as tokenizing characters as well ////
$lines = explode("\n", $data);
$data = '';
$listbeg = [];
$divdepth = [];
$inTable = 0;
// loop: process all lines
foreach ($lines as $line) {
// bitweaver now ignores leading space because it is *VERY* disturbing to unaware users - spiderr
// unless 'feature_wiki_preserve_leading_blanks is set'. This is used for sites that have
// migrated from TikiWiki and have lots of pages whose formatting depends on the presevation of leading spaces
if (!$gBitSystem->isFeatureActive('wiki_preserve_leading_blanks')) {
$line = trim( $line );
}
// check if we are inside a table, if so, ignore monospaced and do
// not insert <br/>
$inTable += substr_count($line, "<table");
$inTable -= substr_count($line, "</table");
// If the first character is ' ' and we are not in pre then we are in pre
// bitweaver now ignores leading space because it is *VERY* disturbing to unaware users - spiderr
if (substr($line, 0, 1) == ' ' && $gBitSystem->isFeatureActive('wiki_monosp') && $inTable == 0) {
// This is not list item -- must close lists currently opened
while (count($listbeg))
$data .= array_shift($listbeg);
// If the first character is space then
// change spaces for
$line = '<span style="font-family:monospace;">' . str_replace(' ', ' ', substr($line, 1)). '</span>';
}
// Title bars
$line = preg_replace( "/\-\=([^=]+)\=\-/", "<div class='bitbar'>$1</div><!-- bitremovebr -->", $line );
// Monospaced text
$line = preg_replace( "/-\+(.*?)\+-/", "<code>$1</code>", $line );
// Bold text
$line = preg_replace( "/__(.*?)__/", "<strong>$1</strong>", $line );
// Italics
$line = preg_replace( "/''(.*?)''/", "<em>$1</em>", $line );
// Definition lists
$line = preg_replace( "/^;([^:]+):(.+)/", "<dl><dt>$1</dt><dd>$2</dd></dl><!-- bitremovebr -->", $line );
// This line is parseable then we have to see what we have
if (substr($line, 0, 3) == '---') {
// This is not list item -- must close lists currently opened
while (count($listbeg))
$data .= array_shift($listbeg);
$line = '<hr/>';
} else {
$litype = substr($line, 0, 1);
if ($litype == '*' || $litype == '#') {
$listlevel = $this->howManyAtStart($line, $litype);
$liclose = '</li>';
$addremove = 0;
if ($listlevel < count($listbeg)) {
while ($listlevel != count($listbeg))
$data .= array_shift($listbeg);
if (substr(current($listbeg), 0, 5) != '</li>')
$liclose = '';
} elseif ($listlevel > count($listbeg)) {
$listyle = '';
while ($listlevel != count($listbeg)) {
array_unshift($listbeg, $litype == '*' ? '</ul>' : '</ol>' );
if ($listlevel == count($listbeg)) {
$listate = substr($line, $listlevel, 1);
if (($listate == '+' || $listate == '-') && !($litype == '*' && !strstr(current($listbeg), '</ul>') || $litype == '#' && !strstr(current($listbeg), '</ol>'))) {
$thisid = 'id' . (int) ( microtime(true) * 1000000 );
$data .= '<br /><a id="flipper' . $thisid . '" href="javascript:BitBase.flipWithSign(\'' . $thisid . '\',1)">[' . ($listate == '-' ? '+' : '-') . ']</a>';
$listyle = ' id="' . $thisid . '" style="display:' . ($listate == '+' ? 'block' : 'none') . ';"';
$addremove = 1;
}
}
$data .= $litype == '*' ? "<ul$listyle>" : "<ol$listyle>";
}
$liclose = '';
}
if ($litype == '*' && !strstr(current($listbeg), '</ul>') || $litype == '#' && !strstr(current($listbeg), '</ol>')) {
$data .= array_shift($listbeg);
$listyle = '';
$listate = substr($line, $listlevel, 1);
if (($listate == '+' || $listate == '-')) {
$thisid = 'id' . microtime() * 1000000;
$data .= '<br /><a id="flipper' . $thisid . '" href="javascript:BitBase.flipWithSign(\'' . $thisid . '\',1)">[' . ($listate == '-' ? '+' : '-') . ']</a>';
$listyle = ' id="' . $thisid . '" style="display:' . ($listate == '+' ? 'block' : 'none') . ';"';
$addremove = 1;
}
$data .= $litype == '*' ? "<ul$listyle>" : "<ol$listyle>";
$liclose = '';
array_unshift($listbeg, $litype == '*' ? '</li></ul>' : '</li></ol>');
}
$line = $liclose . '<li>' . substr($line, $listlevel + $addremove);
if (substr(current($listbeg), 0, 5) != '</li>')
array_unshift($listbeg, '</li>' . array_shift($listbeg));
} elseif ($litype == '+') {
// Must append paragraph for list item of given depth...
$listlevel = $this->howManyAtStart($line, $litype);
// Close lists down to requested level
while ($listlevel < count($listbeg))
$data .= array_shift($listbeg);
if (count($listbeg)) {
if (substr(current($listbeg), 0, 5) != '</li>') {
array_unshift($listbeg, '</li>' . array_shift($listbeg));
$liclose = '<li>';
} else
$liclose = '<br />';
} else
$liclose = '';
$line = $liclose . substr($line, count($listbeg));
} else {
// This is not list item -- must close lists currently opened
while (count($listbeg))
$data .= array_shift($listbeg);
// Get count of (possible) header signs at start
$hdrlevel = $this->howManyAtStart($line, '!');
// If 1st char on line is '!' and its count less than 6 (max in HTML)
if ($litype == '!' && $hdrlevel > 0 && $hdrlevel <= 6) {
// OK. Parse headers here...
$aclose = '';
$edit_link = '';
$addremove = 0;
// Close lower level divs if opened
for (;current($divdepth) >= $hdrlevel; array_shift($divdepth)) {
$data .= '</div>';
}
// May be spesial signs present after '!'s?
$divstate = substr($line, $hdrlevel, 1);
if ($divstate == '+' || $divstate == '-') {
// OK. Must insert flipper after HEADER, and then open new div...
$thisid = 'id' . microtime() * 1000000;
$aclose = '<a id="flipper' . $thisid . '" href="javascript:flipWithSign(\'' . $thisid . '\',1)">[' . ($divstate == '-' ? '+' : '-') . ']</a>';
$aclose .= '<div id="' . $thisid . '" style="display:' . ($divstate == '+' ? 'block' : 'none') . ';">';
array_unshift($divdepth, $hdrlevel);
$addremove = 1;
}
if( $gBitSystem->isFeatureActive( 'wiki_section_edit' ) && $gBitUser->hasPermission( 'p_wiki_update_page' ) ) {
if( $hdrlevel == $gBitSystem->getConfig( 'wiki_section_edit' ) ) {
$edit_url = WIKI_PKG_URL."edit.php?content_id=".$contentId."&section=".$section_count++;
$edit_link = '<span class="editsection" style="float:right;margin-left:5px;">[<a href="'.$edit_url.'">'.KernelTools::tra( "edit" ).'</a>]</span>';
}
}
$hTagLevel = $hdrlevel + 1; // there should only be 1 <h1> per html document
$line = $edit_link
. "<h$hTagLevel>"
. substr($line, $hdrlevel + $addremove)
. "</h$hTagLevel>"
. $aclose
;
} elseif (!strcmp($line, "...page...")) {
// Close lists and divs currently opened
while (count($listbeg)) {
$data .= array_shift($listbeg);
}
while (count($divdepth)) {
$data .= '</div>';
array_shift ($divdepth);
}
// Leave line unchanged... index.php will split wiki here
$line = "...page...";
} else {
// Usual paragraph.
if ($inTable == 0) {
$line .= '<br />';
}
}
}
}
$data .= $line;
}
// Close lists may remains opened
while (count($listbeg)) {
$data .= array_shift($listbeg);
}
// Close header divs may remains opened
for ($i = 1; $i <= count($divdepth); $i++) {
$data .= '</div>';
}
// Close BiDi DIVs if any
for ($i = 0; $i < $bidiCount; $i++) {
$data .= "</div>";
}
$data = str_replace( "<!-- bitremovebr --><br />", "", $data );
return $data;
}
}
|